-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathTypstRenderer.vue
More file actions
75 lines (65 loc) · 1.33 KB
/
TypstRenderer.vue
File metadata and controls
75 lines (65 loc) · 1.33 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<!--
Typst formula renderer component
-->
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { renderTypstFormula } from '../setup/typst'
const props = defineProps({
formula: {
type: String,
required: true,
},
displayMode: {
type: Boolean,
default: false,
},
})
const svgContent = ref('')
const loading = ref(true)
const error = ref(false)
onMounted(async () => {
try {
loading.value = true
svgContent.value = await renderTypstFormula(props.formula, props.displayMode)
loading.value = false
}
catch (e) {
console.error('Failed to render Typst formula:', e)
error.value = true
loading.value = false
}
})
</script>
<template>
<div
:class="[
'typst-renderer',
{ 'typst-display': displayMode, 'typst-inline': !displayMode }
]"
>
<div v-if="loading" class="typst-loading">Loading...</div>
<div v-else-if="error" class="typst-error">{{ formula }}</div>
<div v-else v-html="svgContent" class="typst-content"></div>
</div>
</template>
<style>
.typst-renderer {
display: inline-block;
}
.typst-display {
display: block;
margin: 1em 0;
text-align: center;
}
.typst-error {
color: red;
font-family: var(--slidev-font-mono);
}
.typst-loading {
color: #888;
font-style: italic;
}
.typst-content svg {
vertical-align: middle;
}
</style>