File size: 772 Bytes
a14f135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<script lang="ts">
	import { mount, unmount } from "svelte";

	interface Props {
		component: { default: any };
		runtime: false | typeof import("svelte");
		[key: string]: any;
	}

	let { component, runtime, ...rest }: Props = $props();
	let el: HTMLElement = $state(null);

	$effect(() => {
		if (!el || !component) return;

		const _component = component;
		const _runtime = runtime;
		const _rest = rest;

		if (_runtime) {
			const mounted = _runtime.mount(_component.default, {
				target: el,
				props: _rest
			});
			return () => {
				_runtime.unmount(mounted);
			};
		} else {
			const mounted = mount(_component.default, {
				target: el,
				props: _rest
			});
			return () => {
				unmount(mounted);
			};
		}
	});
</script>

<span bind:this={el}></span>