-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
EPreview.ts
39 lines (31 loc) 路 1.01 KB
/
EPreview.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { computed, defineComponent, h } from 'vue'
const PREVIEW_MAX_LENGTH = 150
export default defineComponent({
name: 'EPreview',
setup(_, { slots }) {
const text = computed(() => {
if (slots.default !== undefined) {
const children = slots.default()[0].children as string
const newText = Array.isArray(children) ? children.join('') : children
return newText?.substring(0, PREVIEW_MAX_LENGTH)
}
return ''
})
function renderWhiteSpace(text: string) {
if (text.length >= PREVIEW_MAX_LENGTH)
return null
const whiteSpaceCodes = '\xA0\u200C\u200B\u200D\u200E\u200F\uFEFF'
return whiteSpaceCodes.repeat(PREVIEW_MAX_LENGTH - text.length)
}
return () => {
return h(
'div',
{
id: '__vue-email-preview',
style: 'display: none; overflow: hidden; line-height: 1px; opacity: 0; max-height: 0; max-width: 0',
},
[text.value, h('div', [renderWhiteSpace(text.value)])],
)
}
},
})