jvs-ppt-ui 0.0.33 → 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/dist/lib/jvs-ppt-ui.es.js +19275 -19015
- package/dist/lib/jvs-ppt-ui.umd.js +112 -112
- package/dist/lib/style.css +1 -1
- package/package.json +1 -1
- package/src/components/CanvasArea.vue +77 -35
- package/src/components/QuickColorPopover.vue +2 -1
- 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/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 +7 -7
- package/src/utils/canvas/formatPainter.ts +177 -30
package/package.json
CHANGED
|
@@ -1010,13 +1010,19 @@ const getOverlayWidth = (el: any) => {
|
|
|
1010
1010
|
}
|
|
1011
1011
|
const isVerticalText = el.type === 'text' && !el.content?.includes('<table') && !el.latex && (el.style?.writingMode === 'vertical-rl' || el.style?.writingMode === 'vertical-lr')
|
|
1012
1012
|
if (isVerticalText && !isDragging.value) {
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1013
|
+
if (el.autoFit?.type === 'shape' || el.style?.width === 'auto' || el.style?.width === undefined) {
|
|
1014
|
+
const dom = document.getElementById(`editable-${el.id}`) || document.getElementById(`canvas-el-${el.id}`)
|
|
1015
|
+
if (dom) {
|
|
1016
|
+
const w = Math.max(dom.scrollWidth || 0, dom.offsetWidth || 0)
|
|
1017
|
+
if (w > 0) return `${w}px`
|
|
1018
|
+
}
|
|
1019
|
+
} else if (el.style?.width && el.style.width !== 'auto') {
|
|
1020
|
+
return `${getElementWidthHeight(el).width}px`
|
|
1021
|
+
} else if (el.width && el.width > 0) {
|
|
1022
|
+
return `${el.width}px`
|
|
1017
1023
|
}
|
|
1018
1024
|
}
|
|
1019
|
-
if (el.style?.width && el.style.width !== 'auto'
|
|
1025
|
+
if (el.style?.width && el.style.width !== 'auto') {
|
|
1020
1026
|
return `${getElementWidthHeight(el).width}px`
|
|
1021
1027
|
}
|
|
1022
1028
|
if (el.id === selectedElementId.value && !isResizing.value && selectedElementWidth.value && selectedElementWidth.value !== '0px') {
|
|
@@ -1208,7 +1214,8 @@ function syncSelectedElementDimensionsFromDom(id: string | null) {
|
|
|
1208
1214
|
const editableDom = document.getElementById(`editable-${id}`)
|
|
1209
1215
|
const selEl = activeSlide.value?.elements.find((x: any) => x.id === id)
|
|
1210
1216
|
const isVertical = selEl && (selEl.style?.writingMode === 'vertical-rl' || selEl.style?.writingMode === 'vertical-lr')
|
|
1211
|
-
const
|
|
1217
|
+
const isVerticalAutoW = isVertical && (selEl?.autoFit?.type === 'shape' || !selEl?.style?.width || selEl.style.width === 'auto')
|
|
1218
|
+
const initialW = isVerticalAutoW && editableDom ? Math.max(editableDom.scrollWidth, dom.offsetWidth) : dom.offsetWidth
|
|
1212
1219
|
const initialH = dom.offsetHeight > 0 ? dom.offsetHeight : (tableEl && tableEl.offsetHeight > 0 ? tableEl.offsetHeight : 0)
|
|
1213
1220
|
selectedElementWidth.value = `${initialW}px`
|
|
1214
1221
|
selectedElementHeight.value = `${initialH}px`
|
|
@@ -1237,7 +1244,8 @@ function observeSelectedElement() {
|
|
|
1237
1244
|
const editableDom = document.getElementById(`editable-${selectedElementId.value}`)
|
|
1238
1245
|
const selEl = activeSlide.value?.elements.find((x: any) => x.id === selectedElementId.value)
|
|
1239
1246
|
const isVertical = selEl && (selEl.style?.writingMode === 'vertical-rl' || selEl.style?.writingMode === 'vertical-lr')
|
|
1240
|
-
const
|
|
1247
|
+
const isVerticalAutoW = isVertical && (selEl?.autoFit?.type === 'shape' || !selEl?.style?.width || selEl.style.width === 'auto')
|
|
1248
|
+
const initialW = isVerticalAutoW && editableDom ? Math.max(editableDom.scrollWidth, dom.offsetWidth) : dom.offsetWidth
|
|
1241
1249
|
const initialH = dom.offsetHeight > 0 ? dom.offsetHeight : (tableEl && tableEl.offsetHeight > 0 ? tableEl.offsetHeight : 0)
|
|
1242
1250
|
selectedElementWidth.value = `${initialW}px`
|
|
1243
1251
|
selectedElementHeight.value = `${initialH}px`
|
|
@@ -1249,7 +1257,8 @@ function observeSelectedElement() {
|
|
|
1249
1257
|
const curEditableDom = document.getElementById(`editable-${selectedElementId.value}`)
|
|
1250
1258
|
const currentSelEl = activeSlide.value?.elements.find((x: any) => x.id === selectedElementId.value)
|
|
1251
1259
|
const curIsVertical = currentSelEl && (currentSelEl.style?.writingMode === 'vertical-rl' || currentSelEl.style?.writingMode === 'vertical-lr')
|
|
1252
|
-
const
|
|
1260
|
+
const curIsVerticalAutoW = curIsVertical && (currentSelEl?.autoFit?.type === 'shape' || !currentSelEl?.style?.width || currentSelEl.style.width === 'auto')
|
|
1261
|
+
const curW = curIsVerticalAutoW && curEditableDom
|
|
1253
1262
|
? Math.max(curEditableDom.scrollWidth, dom.offsetWidth)
|
|
1254
1263
|
: dom.offsetWidth
|
|
1255
1264
|
// 值相等守卫:避免 RO → 渲染 → RO 的无谓链路
|
|
@@ -1274,6 +1283,7 @@ watch(selectedElementId, observeSelectedElement)
|
|
|
1274
1283
|
watch(
|
|
1275
1284
|
() => [
|
|
1276
1285
|
selectedElement.value?.content,
|
|
1286
|
+
(selectedElement.value as any)?.text,
|
|
1277
1287
|
selectedElement.value?.style?.fontSize,
|
|
1278
1288
|
selectedElement.value?.style?.fontFamily,
|
|
1279
1289
|
selectedElement.value?.style?.lineHeight,
|
|
@@ -1284,9 +1294,15 @@ watch(
|
|
|
1284
1294
|
selectedElement.value?.autoFit?.type
|
|
1285
1295
|
],
|
|
1286
1296
|
() => {
|
|
1287
|
-
|
|
1297
|
+
const el = selectedElement.value
|
|
1298
|
+
if (!el) return
|
|
1299
|
+
if ((el.type === 'text' || el.type === 'shape') && el.autoFit?.type === 'text') {
|
|
1288
1300
|
nextTick(() => {
|
|
1289
|
-
updateTextFontScale(
|
|
1301
|
+
updateTextFontScale(el)
|
|
1302
|
+
})
|
|
1303
|
+
} else if (el.type === 'shape' && el.autoFit?.type === 'shape') {
|
|
1304
|
+
nextTick(() => {
|
|
1305
|
+
syncShapeAutoFitHeight(el)
|
|
1290
1306
|
})
|
|
1291
1307
|
}
|
|
1292
1308
|
},
|
|
@@ -2773,14 +2789,16 @@ function handleCanvasMouseDown(e: MouseEvent) {
|
|
|
2773
2789
|
const fontWeight = textCfg.fontWeight || typeConf.defaultFontWeight
|
|
2774
2790
|
const lineHeight = textCfg.lineHeight || typeConf.defaultLineHeight
|
|
2775
2791
|
const letterSpacing = textCfg.letterSpacing !== undefined ? `${textCfg.letterSpacing}px` : '0px'
|
|
2776
|
-
const
|
|
2792
|
+
const defaultWNum = typeConf.defaultWidth
|
|
2793
|
+
const defaultW = `${defaultWNum}px`
|
|
2794
|
+
const defaultHNum = Math.max(typeConf.defaultHeight || 36, Math.ceil((parseFloat(fontSize) || typeConf.defaultFontSize || 18) * (parseFloat(String(lineHeight)) || 1.2) + 12))
|
|
2777
2795
|
|
|
2778
2796
|
content = `<div style="color:${textColor}; font-family:${textFont};"><br></div>`
|
|
2779
2797
|
style = {
|
|
2780
2798
|
top: `${creationStartPctY.toFixed(2)}%`,
|
|
2781
2799
|
left: `${creationStartPctX.toFixed(2)}%`,
|
|
2782
2800
|
width: defaultW,
|
|
2783
|
-
height:
|
|
2801
|
+
height: `${defaultHNum}px`,
|
|
2784
2802
|
color: textColor,
|
|
2785
2803
|
textColor: textColor,
|
|
2786
2804
|
fontFamily: textFont,
|
|
@@ -2801,10 +2819,17 @@ function handleCanvasMouseDown(e: MouseEvent) {
|
|
|
2801
2819
|
name: typeConf.label,
|
|
2802
2820
|
content,
|
|
2803
2821
|
style,
|
|
2822
|
+
width: defaultWNum,
|
|
2823
|
+
height: defaultHNum,
|
|
2804
2824
|
color: textColor,
|
|
2805
2825
|
textColor: textColor,
|
|
2806
2826
|
fontFamily: textFont,
|
|
2807
|
-
verticalAlign: 'middle'
|
|
2827
|
+
verticalAlign: 'middle',
|
|
2828
|
+
autoFit: {
|
|
2829
|
+
type: 'none',
|
|
2830
|
+
fontScale: 100,
|
|
2831
|
+
lnSpcReduction: 0
|
|
2832
|
+
}
|
|
2808
2833
|
}
|
|
2809
2834
|
} else if (activeTool.value === 'text-vertical') {
|
|
2810
2835
|
type = 'text'
|
|
@@ -2822,12 +2847,13 @@ function handleCanvasMouseDown(e: MouseEvent) {
|
|
|
2822
2847
|
const fontWeight = textCfg.fontWeight || typeConf.defaultFontWeight
|
|
2823
2848
|
const lineHeight = textCfg.lineHeight || typeConf.defaultLineHeight
|
|
2824
2849
|
const letterSpacing = textCfg.letterSpacing !== undefined ? `${textCfg.letterSpacing}px` : '0px'
|
|
2850
|
+
const defaultVertW = Math.max(48, Math.ceil((parseFloat(fontSize) || typeConf.defaultFontSize || 18) * (parseFloat(String(lineHeight)) || 1.2) + 16))
|
|
2825
2851
|
|
|
2826
2852
|
content = `<div style="color:${textColor}; font-family:${textFont};"><br></div>`
|
|
2827
2853
|
style = {
|
|
2828
2854
|
top: `${creationStartPctY.toFixed(2)}%`,
|
|
2829
2855
|
left: `${creationStartPctX.toFixed(2)}%`,
|
|
2830
|
-
width:
|
|
2856
|
+
width: `${defaultVertW}px`,
|
|
2831
2857
|
height: '180px',
|
|
2832
2858
|
color: textColor,
|
|
2833
2859
|
textColor: textColor,
|
|
@@ -2849,10 +2875,17 @@ function handleCanvasMouseDown(e: MouseEvent) {
|
|
|
2849
2875
|
name: `竖排${typeConf.label}`,
|
|
2850
2876
|
content,
|
|
2851
2877
|
style,
|
|
2878
|
+
width: defaultVertW,
|
|
2879
|
+
height: 180,
|
|
2852
2880
|
color: textColor,
|
|
2853
2881
|
textColor: textColor,
|
|
2854
2882
|
fontFamily: textFont,
|
|
2855
|
-
verticalAlign: 'middle'
|
|
2883
|
+
verticalAlign: 'middle',
|
|
2884
|
+
autoFit: {
|
|
2885
|
+
type: 'none',
|
|
2886
|
+
fontScale: 100,
|
|
2887
|
+
lnSpcReduction: 0
|
|
2888
|
+
}
|
|
2856
2889
|
}
|
|
2857
2890
|
} else if (activeTool.value === 'shape-draw') {
|
|
2858
2891
|
type = 'shape'
|
|
@@ -3108,14 +3141,6 @@ function updateCreationPosition(e: MouseEvent) {
|
|
|
3108
3141
|
const midPoint = [(startRel[0] + endRel[0]) / 2, (startRel[1] + endRel[1]) / 2] as [number, number]
|
|
3109
3142
|
createdElement.cubic = [midPoint, midPoint]
|
|
3110
3143
|
}
|
|
3111
|
-
} else if (createdElement.type === 'text') {
|
|
3112
|
-
if (createdElement.style.writingMode === 'vertical-rl' || createdElement.style.writingMode === 'vertical-lr') {
|
|
3113
|
-
createdElement.style.height = `${heightPx.toFixed(0)}px`
|
|
3114
|
-
createdElement.style.width = 'auto'
|
|
3115
|
-
} else {
|
|
3116
|
-
createdElement.style.width = `${widthPx.toFixed(0)}px`
|
|
3117
|
-
createdElement.style.height = 'auto'
|
|
3118
|
-
}
|
|
3119
3144
|
}
|
|
3120
3145
|
}
|
|
3121
3146
|
|
|
@@ -3192,17 +3217,32 @@ function stopCreationDrag() {
|
|
|
3192
3217
|
}
|
|
3193
3218
|
}
|
|
3194
3219
|
} else if (createdElement.type === 'text') {
|
|
3220
|
+
const typeConf = TEXT_TYPE_CONFIGS[createdElement.textType as SlideTextType] || TEXT_TYPE_CONFIGS.normalText
|
|
3221
|
+
const fs = parseFloat(createdElement.style.fontSize) || typeConf.defaultFontSize || 18
|
|
3222
|
+
const lh = parseFloat(String(createdElement.style.lineHeight)) || typeConf.defaultLineHeight || 1.3
|
|
3223
|
+
const minVertW = Math.max(48, Math.ceil(fs * lh + 16))
|
|
3224
|
+
const minHorizH = Math.max(typeConf.defaultHeight || 36, Math.ceil(fs * lh + 12))
|
|
3195
3225
|
if (createdElement.style.writingMode === 'vertical-rl' || createdElement.style.writingMode === 'vertical-lr') {
|
|
3196
3226
|
if (heightVal < 15) {
|
|
3197
3227
|
createdElement.style.height = '180px'
|
|
3198
3228
|
}
|
|
3199
|
-
|
|
3229
|
+
if (widthVal < minVertW) {
|
|
3230
|
+
createdElement.style.width = `${minVertW}px`
|
|
3231
|
+
}
|
|
3200
3232
|
} else {
|
|
3201
3233
|
if (widthVal < 15) {
|
|
3202
|
-
const typeConf = TEXT_TYPE_CONFIGS[createdElement.textType as SlideTextType] || TEXT_TYPE_CONFIGS.normalText
|
|
3203
3234
|
createdElement.style.width = `${typeConf.defaultWidth}px`
|
|
3204
3235
|
}
|
|
3205
|
-
|
|
3236
|
+
if (heightVal < minHorizH) {
|
|
3237
|
+
createdElement.style.height = `${minHorizH}px`
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
createdElement.width = parseFloat(createdElement.style.width) || typeConf.defaultWidth
|
|
3241
|
+
createdElement.height = parseFloat(createdElement.style.height) || typeConf.defaultHeight
|
|
3242
|
+
createdElement.autoFit = {
|
|
3243
|
+
type: 'none',
|
|
3244
|
+
fontScale: 100,
|
|
3245
|
+
lnSpcReduction: 0
|
|
3206
3246
|
}
|
|
3207
3247
|
}
|
|
3208
3248
|
|
|
@@ -4381,10 +4421,12 @@ function getElementWidthHeight(el: any): { width: number; height: number } {
|
|
|
4381
4421
|
if (!isNaN(w) && !isNaN(h) && w > 0 && h > 0) {
|
|
4382
4422
|
if (el.type === 'text' && !el.content?.includes('<table') && !el.latex && !isDragging.value) {
|
|
4383
4423
|
if (el.style?.writingMode === 'vertical-rl' || el.style?.writingMode === 'vertical-lr') {
|
|
4384
|
-
|
|
4385
|
-
|
|
4386
|
-
|
|
4387
|
-
|
|
4424
|
+
if (el.autoFit?.type === 'shape') {
|
|
4425
|
+
const editableDom = document.getElementById(`editable-${el.id}`)
|
|
4426
|
+
const dom = document.getElementById(`canvas-el-${el.id}`)
|
|
4427
|
+
const actualW = Math.max(editableDom?.scrollWidth || 0, dom?.offsetWidth || 0, w)
|
|
4428
|
+
return { width: actualW, height: h }
|
|
4429
|
+
}
|
|
4388
4430
|
} else if (el.autoFit?.type === 'shape') {
|
|
4389
4431
|
const dom = document.getElementById(`canvas-el-${el.id}`) || document.getElementById(`canvas-content-${el.id}`)
|
|
4390
4432
|
if (dom && dom.offsetHeight > 0) {
|
|
@@ -4400,7 +4442,7 @@ function getElementWidthHeight(el: any): { width: number; height: number } {
|
|
|
4400
4442
|
return { width: el.width, height: el.height }
|
|
4401
4443
|
}
|
|
4402
4444
|
|
|
4403
|
-
const fitType = el.autoFit?.type ||
|
|
4445
|
+
const fitType = el.autoFit?.type || 'none'
|
|
4404
4446
|
const isWidthAuto = el.style?.width === 'auto' || (el.type === 'text' && fitType === 'shape' && (el.style?.writingMode === 'vertical-rl' || el.style?.writingMode === 'vertical-lr' || el.style?.whiteSpace === 'nowrap'))
|
|
4405
4447
|
const isHeightAuto = el.style?.height === 'auto' || el.style?.height === undefined || (el.type === 'text' && !el.content?.includes('<table') && !el.latex && fitType === 'shape' && (!(el.style?.writingMode === 'vertical-rl' || el.style?.writingMode === 'vertical-lr') || el.style?.whiteSpace === 'nowrap'))
|
|
4406
4448
|
|
|
@@ -4467,7 +4509,7 @@ function getElementWidthHeight(el: any): { width: number; height: number } {
|
|
|
4467
4509
|
}
|
|
4468
4510
|
}
|
|
4469
4511
|
|
|
4470
|
-
if (el.type === 'text' && !el.content?.includes('<table') && !el.latex && el.style?.writingMode !== 'vertical-rl' && el.style?.writingMode !== 'vertical-lr') {
|
|
4512
|
+
if (isHeightAuto && el.type === 'text' && !el.content?.includes('<table') && !el.latex && el.style?.writingMode !== 'vertical-rl' && el.style?.writingMode !== 'vertical-lr') {
|
|
4471
4513
|
if (dom && dom.offsetHeight > 0) {
|
|
4472
4514
|
height = Math.max(height, dom.offsetHeight)
|
|
4473
4515
|
}
|
|
@@ -7156,7 +7198,7 @@ function handleTextBlur(e: FocusEvent, el: any) {
|
|
|
7156
7198
|
el.style.height = `${el.height || 40}px`
|
|
7157
7199
|
}
|
|
7158
7200
|
} else {
|
|
7159
|
-
const fitType = el.autoFit?.type || '
|
|
7201
|
+
const fitType = el.autoFit?.type || 'none'
|
|
7160
7202
|
if (fitType === 'shape') {
|
|
7161
7203
|
el.style.height = 'auto'
|
|
7162
7204
|
if (container.offsetHeight > 0) {
|
|
@@ -8254,11 +8296,11 @@ async function handleGlobalPaste(e: ClipboardEvent) {
|
|
|
8254
8296
|
v-memo="[
|
|
8255
8297
|
(isDragging || isCanvasDragging)
|
|
8256
8298
|
? (selectedElementIds.includes(el.id)
|
|
8257
|
-
? `${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.style?.rotate}`
|
|
8299
|
+
? `${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.style?.rotate}_${(el as any).autoFit?.fontScale || ''}`
|
|
8258
8300
|
: (el.type === 'line'
|
|
8259
8301
|
? `${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.start?.join(',')}_${el.end?.join(',')}_${el.broken?.join(',')}_${el.broken2?.join(',')}_${el.curve?.join(',')}`
|
|
8260
8302
|
: 'frozen'))
|
|
8261
|
-
: `${el.id}_${el.type}_${el.content}_${(el as any).src}_${el.isPlaceholderReplaced}_${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.style?.rotate}_${el.type === 'line' ? `${el.start?.join(',')}_${el.end?.join(',')}_${el.broken?.join(',')}_${el.broken2?.join(',')}_${el.curve?.join(',')}_` : ''}${selectedElementIds.includes(el.id)}_${selectedElementId === el.id}_${isEditingText}_${activeTab}_${activeSlideVersion}_${(el.style as any)?.reflection?.enabled}_${(el.style as any)?.reflection?.distance}_${(el.style as any)?.reflection?.size}_${(el.style as any)?.reflection?.blur}_${(el.style as any)?.reflection?.opacity}`
|
|
8303
|
+
: `${el.id}_${el.type}_${el.content}_${typeof (el as any).text === 'string' ? (el as any).text : ((el as any).text?.content || '')}_${(el.style as any)?.textBackground || ''}_${(el as any).autoFit?.type || ''}_${(el as any).autoFit?.fontScale || ''}_${(el as any).src}_${el.isPlaceholderReplaced}_${el.style?.left}_${el.style?.top}_${el.style?.width}_${el.style?.height}_${el.style?.rotate}_${el.type === 'line' ? `${el.start?.join(',')}_${el.end?.join(',')}_${el.broken?.join(',')}_${el.broken2?.join(',')}_${el.curve?.join(',')}_` : ''}${selectedElementIds.includes(el.id)}_${selectedElementId === el.id}_${isEditingText}_${activeTab}_${activeSlideVersion}_${(el.style as any)?.reflection?.enabled}_${(el.style as any)?.reflection?.distance}_${(el.style as any)?.reflection?.size}_${(el.style as any)?.reflection?.blur}_${(el.style as any)?.reflection?.opacity}`
|
|
8262
8304
|
]"
|
|
8263
8305
|
:class="{
|
|
8264
8306
|
selected: selectedElementIds.includes(el.id),
|
|
@@ -36,6 +36,7 @@ const isCustomColorPickerShow = ref(false)
|
|
|
36
36
|
const referenceWrapperRef = ref<HTMLElement>()
|
|
37
37
|
|
|
38
38
|
const handleBodyBubble = (e: MouseEvent) => {
|
|
39
|
+
if (!popoverVisible.value && !isCustomColorPickerShow.value) return
|
|
39
40
|
const target = e.target as HTMLElement
|
|
40
41
|
if (!target) return
|
|
41
42
|
const isInsidePopover = target.closest('.quick-color-popover') ||
|
|
@@ -147,7 +148,7 @@ function getCurrentColor(): string {
|
|
|
147
148
|
col = props.color || '#000000'
|
|
148
149
|
}
|
|
149
150
|
if (!col || col === 'transparent' || col === 'none') {
|
|
150
|
-
return '
|
|
151
|
+
return '#FFFFFF'
|
|
151
152
|
}
|
|
152
153
|
if (props.alpha !== undefined && props.alpha >= 0 && props.alpha <= 100) {
|
|
153
154
|
const cleanHex = col.trim().replace('#', '')
|
|
@@ -375,63 +375,93 @@ function getStyleVal(prop: string, fallback: any = ''): any {
|
|
|
375
375
|
return val !== undefined ? val : fallback
|
|
376
376
|
}
|
|
377
377
|
|
|
378
|
-
function
|
|
379
|
-
if (!
|
|
380
|
-
const
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
378
|
+
function isTransparentColorVal(val: any): boolean {
|
|
379
|
+
if (!val || typeof val !== 'string') return true
|
|
380
|
+
const s = val.trim().toLowerCase()
|
|
381
|
+
if (s === 'transparent' || s === 'none' || s === 'initial' || s === 'inherit') return true
|
|
382
|
+
if (/^rgba\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*,\s*0(?:\.0+)?\s*\)$/.test(s)) return true
|
|
383
|
+
if (/^#[0-9a-f]{6}00$/.test(s) || /^#[0-9a-f]{3}0$/.test(s)) return true
|
|
384
|
+
return false
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
function applyTextStyleToHtml(html: string, styles: any) {
|
|
388
|
+
if (!html) return html
|
|
389
|
+
const div = document.createElement('div')
|
|
390
|
+
div.innerHTML = html
|
|
391
|
+
|
|
392
|
+
// 1. 保证所有块级元素(p, div, li 等)背景色透明,绝不被整行涂满
|
|
393
|
+
div.querySelectorAll('p, div, li, h1, h2, h3, h4, h5, h6, ul, ol').forEach((block: any) => {
|
|
394
|
+
block.style.backgroundColor = ''
|
|
395
|
+
block.style.removeProperty('background-color')
|
|
396
|
+
block.style.background = ''
|
|
397
|
+
block.style.removeProperty('background')
|
|
398
|
+
})
|
|
399
|
+
|
|
400
|
+
// 2. 如果处理文字高亮背景色 textBackground
|
|
401
|
+
if (styles.textBackground !== undefined) {
|
|
402
|
+
const isClear = isTransparentColorVal(styles.textBackground)
|
|
403
|
+
const bgVal = isClear ? '' : styles.textBackground
|
|
404
|
+
|
|
405
|
+
if (isClear) {
|
|
406
|
+
const tableCellTags = new Set(['TABLE', 'THEAD', 'TBODY', 'TFOOT', 'TR', 'TD', 'TH', 'COL', 'COLGROUP'])
|
|
407
|
+
div.querySelectorAll('*').forEach((elem: any) => {
|
|
408
|
+
if (elem.style && !tableCellTags.has(elem.tagName)) {
|
|
409
|
+
elem.style.backgroundColor = ''
|
|
410
|
+
elem.style.removeProperty('background-color')
|
|
411
|
+
elem.style.background = ''
|
|
412
|
+
elem.style.removeProperty('background')
|
|
413
|
+
}
|
|
414
|
+
if (elem.tagName === 'MARK' && elem.parentNode) {
|
|
415
|
+
while (elem.firstChild) {
|
|
416
|
+
elem.parentNode.insertBefore(elem.firstChild, elem)
|
|
417
|
+
}
|
|
418
|
+
elem.parentNode.removeChild(elem)
|
|
419
|
+
}
|
|
420
|
+
})
|
|
421
|
+
} else {
|
|
422
|
+
// 需要高亮文字
|
|
423
|
+
const leafBlocks = Array.from(
|
|
424
|
+
div.querySelectorAll('p, div, li, h1, h2, h3, h4, h5, h6, td, th')
|
|
425
|
+
).filter((b: Element) => !b.querySelector('p, div, li, h1, h2, h3, h4, h5, h6, ul, ol, table')) as HTMLElement[]
|
|
426
|
+
|
|
427
|
+
const applyBgToBlock = (block: HTMLElement) => {
|
|
428
|
+
const textContent = (block.textContent || '').replace(/\u200B/g, '').trim()
|
|
429
|
+
if (!textContent) return
|
|
430
|
+
|
|
431
|
+
block.querySelectorAll('*').forEach((child: any) => {
|
|
432
|
+
if (child.style) {
|
|
433
|
+
child.style.backgroundColor = ''
|
|
434
|
+
child.style.removeProperty('background-color')
|
|
435
|
+
child.style.background = ''
|
|
436
|
+
child.style.removeProperty('background')
|
|
437
|
+
}
|
|
438
|
+
})
|
|
439
|
+
|
|
440
|
+
const nonEmptyNodes = Array.from(block.childNodes).filter(
|
|
441
|
+
n => !(n.nodeType === Node.TEXT_NODE && !(n.textContent || '').trim())
|
|
442
|
+
)
|
|
443
|
+
if (
|
|
444
|
+
nonEmptyNodes.length === 1 &&
|
|
445
|
+
nonEmptyNodes[0].nodeType === Node.ELEMENT_NODE &&
|
|
446
|
+
(nonEmptyNodes[0] as HTMLElement).tagName === 'SPAN'
|
|
447
|
+
) {
|
|
448
|
+
;(nonEmptyNodes[0] as HTMLElement).style.backgroundColor = bgVal
|
|
449
|
+
} else if (block.childNodes.length > 0) {
|
|
450
|
+
const span = document.createElement('span')
|
|
451
|
+
span.style.backgroundColor = bgVal
|
|
452
|
+
while (block.firstChild) {
|
|
453
|
+
span.appendChild(block.firstChild)
|
|
454
|
+
}
|
|
455
|
+
block.appendChild(span)
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (leafBlocks.length > 0) {
|
|
460
|
+
leafBlocks.forEach(applyBgToBlock)
|
|
461
|
+
} else {
|
|
462
|
+
applyBgToBlock(div)
|
|
463
|
+
}
|
|
464
|
+
}
|
|
435
465
|
}
|
|
436
466
|
|
|
437
467
|
// 3. 处理字号、字体、颜色、加粗等其他文字样式
|
|
@@ -525,9 +555,10 @@ function applyTextStyleToHtml(html: string, styles: any) {
|
|
|
525
555
|
|
|
526
556
|
function setStyleVal(prop: string, val: any) {
|
|
527
557
|
if (!selectedElement.value) return
|
|
528
|
-
if (selectedElementIds.value.length > 1 && activeSlide.value) {
|
|
529
|
-
|
|
530
|
-
|
|
558
|
+
if (selectedElementIds.value.length > 1 && activeSlide.value) {
|
|
559
|
+
selectedElementIds.value.forEach((id: string) => {
|
|
560
|
+
const el = findElementInSlide(id)
|
|
561
|
+
if (el) {
|
|
531
562
|
if (!el.style) el.style = {}
|
|
532
563
|
if (el.type === 'line') {
|
|
533
564
|
if (prop === 'borderColor') {
|
|
@@ -616,36 +647,39 @@ function setStyleVal(prop: string, val: any) {
|
|
|
616
647
|
}
|
|
617
648
|
}
|
|
618
649
|
|
|
619
|
-
if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'fontWeight' || prop === 'fontStyle' || prop === 'textAlign') {
|
|
620
|
-
const container = document.getElementById(`editable-${el.id}`)
|
|
621
|
-
if (container && (!el.content || !el.content.includes('<table')) && !el.latex) {
|
|
622
|
-
if (prop === 'fontFamily') {
|
|
623
|
-
container.style.fontFamily = val
|
|
624
|
-
container.style.setProperty('--ppt-font-family', val)
|
|
625
|
-
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontFamily: val })
|
|
626
|
-
} else if (prop === 'fontSize') {
|
|
627
|
-
container.style.fontSize = val
|
|
628
|
-
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontSize: val })
|
|
629
|
-
} else if (prop === 'fontWeight') {
|
|
630
|
-
container.style.fontWeight = val
|
|
631
|
-
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontWeight: val })
|
|
632
|
-
} else if (prop === 'fontStyle') {
|
|
633
|
-
container.style.fontStyle = val
|
|
634
|
-
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontStyle: val })
|
|
635
|
-
} else if (prop === 'textAlign') {
|
|
636
|
-
container.style.textAlign = val
|
|
637
|
-
container.innerHTML = updateTextAlignInHtml(container.innerHTML, val)
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
650
|
+
if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'fontWeight' || prop === 'fontStyle' || prop === 'textAlign' || prop === 'textBackground') {
|
|
651
|
+
const container = document.getElementById(`editable-${el.id}`)
|
|
652
|
+
if (container && (!el.content || !el.content.includes('<table')) && !el.latex) {
|
|
653
|
+
if (prop === 'fontFamily') {
|
|
654
|
+
container.style.fontFamily = val
|
|
655
|
+
container.style.setProperty('--ppt-font-family', val)
|
|
656
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontFamily: val })
|
|
657
|
+
} else if (prop === 'fontSize') {
|
|
658
|
+
container.style.fontSize = val
|
|
659
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontSize: val })
|
|
660
|
+
} else if (prop === 'fontWeight') {
|
|
661
|
+
container.style.fontWeight = val
|
|
662
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontWeight: val })
|
|
663
|
+
} else if (prop === 'fontStyle') {
|
|
664
|
+
container.style.fontStyle = val
|
|
665
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontStyle: val })
|
|
666
|
+
} else if (prop === 'textAlign') {
|
|
667
|
+
container.style.textAlign = val
|
|
668
|
+
container.innerHTML = updateTextAlignInHtml(container.innerHTML, val)
|
|
669
|
+
} else if (prop === 'textBackground') {
|
|
670
|
+
container.style.backgroundColor = el.type === 'text' ? (el.style?.fill || 'transparent') : ''
|
|
671
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { textBackground: val })
|
|
672
|
+
}
|
|
673
|
+
if (el.type === 'shape') {
|
|
674
|
+
if (el.text && typeof el.text === 'object') {
|
|
675
|
+
el.text.content = container.innerHTML
|
|
676
|
+
} else {
|
|
677
|
+
el.text = container.innerHTML
|
|
678
|
+
}
|
|
679
|
+
} else {
|
|
680
|
+
el.content = container.innerHTML
|
|
681
|
+
}
|
|
682
|
+
}
|
|
649
683
|
}
|
|
650
684
|
}
|
|
651
685
|
})
|
|
@@ -739,36 +773,39 @@ function setStyleVal(prop: string, val: any) {
|
|
|
739
773
|
}
|
|
740
774
|
}
|
|
741
775
|
|
|
742
|
-
if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'fontWeight' || prop === 'fontStyle' || prop === 'textAlign') {
|
|
743
|
-
const container = document.getElementById(`editable-${el.id}`)
|
|
744
|
-
if (container && (!el.content || !el.content.includes('<table')) && !el.latex) {
|
|
745
|
-
if (prop === 'fontFamily') {
|
|
746
|
-
container.style.fontFamily = val
|
|
747
|
-
container.style.setProperty('--ppt-font-family', val)
|
|
748
|
-
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontFamily: val })
|
|
749
|
-
} else if (prop === 'fontSize') {
|
|
750
|
-
container.style.fontSize = val
|
|
751
|
-
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontSize: val })
|
|
752
|
-
} else if (prop === 'fontWeight') {
|
|
753
|
-
container.style.fontWeight = val
|
|
754
|
-
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontWeight: val })
|
|
755
|
-
} else if (prop === 'fontStyle') {
|
|
756
|
-
container.style.fontStyle = val
|
|
757
|
-
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontStyle: val })
|
|
758
|
-
} else if (prop === 'textAlign') {
|
|
759
|
-
container.style.textAlign = val
|
|
760
|
-
container.innerHTML = updateTextAlignInHtml(container.innerHTML, val)
|
|
761
|
-
}
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
776
|
+
if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'fontWeight' || prop === 'fontStyle' || prop === 'textAlign' || prop === 'textBackground') {
|
|
777
|
+
const container = document.getElementById(`editable-${el.id}`)
|
|
778
|
+
if (container && (!el.content || !el.content.includes('<table')) && !el.latex) {
|
|
779
|
+
if (prop === 'fontFamily') {
|
|
780
|
+
container.style.fontFamily = val
|
|
781
|
+
container.style.setProperty('--ppt-font-family', val)
|
|
782
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontFamily: val })
|
|
783
|
+
} else if (prop === 'fontSize') {
|
|
784
|
+
container.style.fontSize = val
|
|
785
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontSize: val })
|
|
786
|
+
} else if (prop === 'fontWeight') {
|
|
787
|
+
container.style.fontWeight = val
|
|
788
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontWeight: val })
|
|
789
|
+
} else if (prop === 'fontStyle') {
|
|
790
|
+
container.style.fontStyle = val
|
|
791
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { fontStyle: val })
|
|
792
|
+
} else if (prop === 'textAlign') {
|
|
793
|
+
container.style.textAlign = val
|
|
794
|
+
container.innerHTML = updateTextAlignInHtml(container.innerHTML, val)
|
|
795
|
+
} else if (prop === 'textBackground') {
|
|
796
|
+
container.style.backgroundColor = el.type === 'text' ? (el.style?.fill || 'transparent') : ''
|
|
797
|
+
container.innerHTML = applyTextStyleToHtml(container.innerHTML, { textBackground: val })
|
|
798
|
+
}
|
|
799
|
+
if (el.type === 'shape') {
|
|
800
|
+
if (el.text && typeof el.text === 'object') {
|
|
801
|
+
el.text.content = container.innerHTML
|
|
802
|
+
} else {
|
|
803
|
+
el.text = container.innerHTML
|
|
804
|
+
}
|
|
805
|
+
} else {
|
|
806
|
+
el.content = container.innerHTML
|
|
807
|
+
}
|
|
808
|
+
}
|
|
772
809
|
}
|
|
773
810
|
if (el.type === 'group' && Array.isArray(el.elements)) {
|
|
774
811
|
const allowedInheritProps = [
|
|
@@ -841,20 +878,32 @@ function setStyleVal(prop: string, val: any) {
|
|
|
841
878
|
child.text = updateTextAlignInHtml(child.text, val)
|
|
842
879
|
}
|
|
843
880
|
}
|
|
844
|
-
if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'textAlign') {
|
|
845
|
-
const childContainer = document.getElementById(`editable-${child.id}`)
|
|
846
|
-
if (childContainer && (!child.content || !child.content.includes('<table')) && !child.latex) {
|
|
847
|
-
if (prop === 'fontFamily') {
|
|
848
|
-
childContainer.style.fontFamily = val
|
|
849
|
-
childContainer.innerHTML = applyTextStyleToHtml(childContainer.innerHTML, { fontFamily: val })
|
|
850
|
-
} else if (prop === 'fontSize') {
|
|
851
|
-
childContainer.style.fontSize = val
|
|
852
|
-
childContainer.innerHTML = applyTextStyleToHtml(childContainer.innerHTML, { fontSize: val })
|
|
853
|
-
} else if (prop === 'textAlign') {
|
|
854
|
-
childContainer.style.textAlign = val
|
|
855
|
-
childContainer.innerHTML = updateTextAlignInHtml(childContainer.innerHTML, val)
|
|
856
|
-
}
|
|
857
|
-
|
|
881
|
+
if (prop === 'fontFamily' || prop === 'fontSize' || prop === 'textAlign' || prop === 'textBackground') {
|
|
882
|
+
const childContainer = document.getElementById(`editable-${child.id}`)
|
|
883
|
+
if (childContainer && (!child.content || !child.content.includes('<table')) && !child.latex) {
|
|
884
|
+
if (prop === 'fontFamily') {
|
|
885
|
+
childContainer.style.fontFamily = val
|
|
886
|
+
childContainer.innerHTML = applyTextStyleToHtml(childContainer.innerHTML, { fontFamily: val })
|
|
887
|
+
} else if (prop === 'fontSize') {
|
|
888
|
+
childContainer.style.fontSize = val
|
|
889
|
+
childContainer.innerHTML = applyTextStyleToHtml(childContainer.innerHTML, { fontSize: val })
|
|
890
|
+
} else if (prop === 'textAlign') {
|
|
891
|
+
childContainer.style.textAlign = val
|
|
892
|
+
childContainer.innerHTML = updateTextAlignInHtml(childContainer.innerHTML, val)
|
|
893
|
+
} else if (prop === 'textBackground') {
|
|
894
|
+
childContainer.style.backgroundColor = child.type === 'text' ? (child.style?.fill || 'transparent') : ''
|
|
895
|
+
childContainer.innerHTML = applyTextStyleToHtml(childContainer.innerHTML, { textBackground: val })
|
|
896
|
+
}
|
|
897
|
+
if (child.type === 'shape') {
|
|
898
|
+
if (child.text && typeof child.text === 'object') {
|
|
899
|
+
child.text.content = childContainer.innerHTML
|
|
900
|
+
} else {
|
|
901
|
+
child.text = childContainer.innerHTML
|
|
902
|
+
}
|
|
903
|
+
} else {
|
|
904
|
+
child.content = childContainer.innerHTML
|
|
905
|
+
}
|
|
906
|
+
}
|
|
858
907
|
}
|
|
859
908
|
if (child.type === 'group' && Array.isArray(child.elements)) {
|
|
860
909
|
child.elements.forEach(applyToGroupChild)
|