-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathShikiMagicMove.svelte
34 lines (31 loc) · 1.02 KB
/
ShikiMagicMove.svelte
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
<script lang='ts'>
import type { MagicMoveDifferOptions, MagicMoveRenderOptions } from 'shiki-magic-move/types'
import type { HighlighterCore } from 'shiki/core'
import { codeToKeyedTokens, createMagicMoveMachine } from 'shiki-magic-move/core'
import ShikiMagicMoveRenderer from './ShikiMagicMoveRenderer.svelte'
interface ShikiMagicMoveProps {
highlighter: HighlighterCore
lang: string
theme: string
code: string
options?: MagicMoveRenderOptions & MagicMoveDifferOptions
onStart?: () => void
onEnd?: () => void
class?: string
tabindex?: number
}
const { highlighter, lang, theme, code, options, onStart, onEnd, ...props }: ShikiMagicMoveProps = $props()
const machine = createMagicMoveMachine(
code => codeToKeyedTokens(highlighter, code, { lang, theme }, options?.lineNumbers),
options,
)
const result = $derived(machine.commit(code))
</script>
<ShikiMagicMoveRenderer
tokens={result.current}
previous={result.previous}
{options}
{onStart}
{onEnd}
{...props}
/>