@@ -21,32 +21,38 @@ export interface ShikiMagicMoveRendererProps {
21
21
* A wrapper component to `MagicMoveRenderer`
22
22
*/
23
23
export function ShikiMagicMoveRenderer ( props : ShikiMagicMoveRendererProps ) {
24
- let container : HTMLPreElement
25
- let renderer : Renderer
24
+ // eslint-disable-next-line no-undef-init, prefer-const
25
+ let container : HTMLPreElement | undefined = undefined
26
+ // eslint-disable-next-line no-undef-init
27
+ let renderer : Renderer | undefined = undefined
26
28
const [ isMounted , setIsMounted ] = createSignal ( false )
27
29
28
30
createEffect ( ( ) => {
29
- if ( ! container ) return
30
- if ( ! isMounted ( ) ) {
31
+ if ( container !== undefined && ! isMounted ( ) ) {
31
32
// Remove previous content
32
- container . innerHTML = ''
33
+ ; ( container as HTMLPreElement ) . innerHTML = ''
33
34
setIsMounted ( true )
34
35
renderer = new Renderer ( container )
35
36
}
36
37
} )
37
38
38
39
createEffect ( ( ) => {
39
40
async function render ( ) {
40
- if ( ! renderer ) return
41
+ if ( ! renderer ) {
42
+ return
43
+ }
41
44
42
45
Object . assign ( renderer . options , props . options )
43
46
44
47
if ( props . animate === undefined || props . animate === true ) {
45
- if ( props . previous ) renderer . replace ( props . previous )
48
+ if ( props . previous ) {
49
+ renderer . replace ( props . previous )
50
+ }
46
51
47
52
props . onStart ?.( )
48
53
await renderer . render ( props . tokens )
49
54
props . onEnd ?.( )
55
+ // eslint-disable-next-line style/brace-style
50
56
} else {
51
57
renderer . replace ( props . tokens )
52
58
}
@@ -57,7 +63,6 @@ export function ShikiMagicMoveRenderer(props: ShikiMagicMoveRendererProps) {
57
63
58
64
return (
59
65
< pre
60
- // @ts -expect-error - TS doesn't know that `container` is a ref
61
66
ref = { container }
62
67
class = { `shiki-magic-move-container ${ props . class || '' } ` . trim ( ) }
63
68
style = { props . style }
0 commit comments