blob: 51cb778db56f90d4622278b06e7e2daf8d03c0d9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
import { SvelteComponent as Component } from 'svelte';
export function __svelte_static(SvelteComponent: Component) {
return (attrs: Record<string, any>, ...children: any): string => {
// TODO include head and css stuff too...
const { html } = SvelteComponent.render(attrs);
return html;
};
}
export function __svelte_dynamic(SvelteComponent: Component, importUrl: string) {
const placeholderId = `placeholder_${String(Math.random())}`;
return (attrs: Record<string, string>, ...children: any) => {
return `<div id="${placeholderId}"></div><script type="module">
import Component from '${importUrl}';
new Component({
target: document.getElementById('${placeholderId}'),
props: ${JSON.stringify(attrs)}
});
</script>`;
};
}
|