-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
ShikiMagicMove.vue
48 lines (40 loc) · 1.21 KB
/
ShikiMagicMove.vue
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
<script setup lang="ts">
import { ShikiMagicMovePrecompiled } from 'shiki-magic-move/vue'
import type { KeyedTokensInfo } from 'shiki-magic-move/types'
import { onMounted, onUnmounted, ref, watchEffect } from 'vue'
import { useSlideContext } from '../context'
import { makeId } from '../logic/utils'
import 'shiki-magic-move/style.css'
const props = defineProps<{
steps: KeyedTokensInfo[]
at?: string | number
}>()
const { $clicksContext: clicks, $scale: scale } = useSlideContext()
const id = makeId()
const index = ref(0)
onUnmounted(() => {
clicks!.unregister(id)
})
onMounted(() => {
if (!clicks || clicks.disabled)
return
const { start, end, delta } = clicks.resolve(props.at || '+1', props.steps.length - 1)
clicks.register(id, { max: end, delta })
watchEffect(() => {
if (clicks.disabled)
index.value = props.steps.length - 1
else
index.value = Math.min(Math.max(0, clicks.current - start + 1), props.steps.length - 1)
})
})
</script>
<template>
<div class="slidev-code-wrapper slidev-code-magic-move">
<ShikiMagicMovePrecompiled
class="slidev-code relative shiki"
:steps="steps"
:step="index"
:options="{ globalScale: scale }"
/>
</div>
</template>