@ox-content/vite-plugin-svelte 3.1.2 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/html-host-client.cjs +7 -0
- package/dist/html-host-client.d.cts +68 -0
- package/dist/html-host-client.d.mts +68 -0
- package/dist/html-host-client.mjs +2 -0
- package/dist/html-host-client2.cjs +111 -0
- package/dist/html-host-client2.d.cts +2 -0
- package/dist/html-host-client2.d.mts +2 -0
- package/dist/html-host-client2.mjs +84 -0
- package/dist/html-host-client2.mjs.map +1 -0
- package/dist/index.cjs +272 -61
- package/dist/index.d.cts +108 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +108 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +255 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_html_host_client = require("./html-host-client2.cjs");
|
|
3
|
+
exports.createSvelteHtmlHostDomRenderer = require_html_host_client.createSvelteHtmlHostDomRenderer;
|
|
4
|
+
exports.createSvelteHtmlHostLazyHydrate = require_html_host_client.createSvelteHtmlHostLazyHydrate;
|
|
5
|
+
exports.initSvelteHtmlHost = require_html_host_client.initSvelteHtmlHost;
|
|
6
|
+
exports.loadSvelteHtmlHostDomRuntime = require_html_host_client.loadSvelteHtmlHostDomRuntime;
|
|
7
|
+
exports.readSvelteHtmlHostSlot = require_html_host_client.readSvelteHtmlHostSlot;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { HtmlHostClientContext, HtmlHostClientDiagnosticCode, HtmlHostClientError, HtmlHostClientModuleLoader, HtmlHostClientRenderer, HtmlHostClientRuntimeLoader, HtmlHostExportNameResolver, HtmlHostHydrationHandle, HtmlHostLazyHydrateFunction, HtmlHostModuleIdResolver } from "@ox-content/islands/html-host";
|
|
2
|
+
import { HydrateFunction, InitIslandsOptions } from "@ox-content/islands";
|
|
3
|
+
//#region src/html-host-client-types.d.ts
|
|
4
|
+
type SvelteHtmlHostClientDiagnosticCode = HtmlHostClientDiagnosticCode;
|
|
5
|
+
type SvelteHtmlHostClientError = HtmlHostClientError;
|
|
6
|
+
type SvelteHtmlHostClientComponentValue = unknown;
|
|
7
|
+
type SvelteHtmlHostClientModuleValue = SvelteHtmlHostClientComponentValue;
|
|
8
|
+
type SvelteHtmlHostClientModuleLoader<TModule = SvelteHtmlHostClientModuleValue> = HtmlHostClientModuleLoader<TModule>;
|
|
9
|
+
type SvelteHtmlHostClientModules = Readonly<Record<string, SvelteHtmlHostClientModuleLoader>> | ReadonlyMap<string, SvelteHtmlHostClientModuleLoader>;
|
|
10
|
+
type SvelteHtmlHostClientContext<TRuntime = undefined> = HtmlHostClientContext<TRuntime>;
|
|
11
|
+
type SvelteHtmlHostClientRenderer<TRuntime = undefined> = HtmlHostClientRenderer<TRuntime>;
|
|
12
|
+
type SvelteHtmlHostClientRuntimeLoader<TRuntime = undefined> = HtmlHostClientRuntimeLoader<TRuntime>;
|
|
13
|
+
type SvelteHtmlHostModuleIdResolver = HtmlHostModuleIdResolver;
|
|
14
|
+
type SvelteHtmlHostExportNameResolver = HtmlHostExportNameResolver;
|
|
15
|
+
type SvelteHtmlHostHydrationHandle = HtmlHostHydrationHandle;
|
|
16
|
+
interface SvelteHtmlHostClientBaseInput<TRuntime = undefined> {
|
|
17
|
+
modules: SvelteHtmlHostClientModules;
|
|
18
|
+
loadRuntime?: SvelteHtmlHostClientRuntimeLoader<TRuntime>;
|
|
19
|
+
resolveModuleId?: SvelteHtmlHostModuleIdResolver;
|
|
20
|
+
resolveExportName?: SvelteHtmlHostExportNameResolver;
|
|
21
|
+
onError?: (error: SvelteHtmlHostClientError) => void;
|
|
22
|
+
}
|
|
23
|
+
interface CreateSvelteHtmlHostLazyHydrateRenderInput<TRuntime = undefined> extends SvelteHtmlHostClientBaseInput<TRuntime> {
|
|
24
|
+
render: SvelteHtmlHostClientRenderer<TRuntime>;
|
|
25
|
+
mount?: never;
|
|
26
|
+
}
|
|
27
|
+
interface CreateSvelteHtmlHostLazyHydrateMountInput extends SvelteHtmlHostClientBaseInput<SvelteHtmlHostDomRuntime> {
|
|
28
|
+
mount: SvelteHtmlHostDomRendererInput;
|
|
29
|
+
render?: never;
|
|
30
|
+
}
|
|
31
|
+
type CreateSvelteHtmlHostLazyHydrateInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateRenderInput<TRuntime> | CreateSvelteHtmlHostLazyHydrateMountInput;
|
|
32
|
+
type SvelteHtmlHostDomMode = "render" | "hydrate";
|
|
33
|
+
interface SvelteHtmlHostDomRendererInput {
|
|
34
|
+
mode: SvelteHtmlHostDomMode;
|
|
35
|
+
}
|
|
36
|
+
interface SvelteHtmlHostDomRuntime {
|
|
37
|
+
mount: (component: SvelteHtmlHostClientComponentValue, options: {
|
|
38
|
+
target: HTMLElement;
|
|
39
|
+
props?: Record<string, unknown>;
|
|
40
|
+
}) => unknown;
|
|
41
|
+
hydrate: (component: SvelteHtmlHostClientComponentValue, options: {
|
|
42
|
+
target: HTMLElement;
|
|
43
|
+
props?: Record<string, unknown>;
|
|
44
|
+
}) => unknown;
|
|
45
|
+
unmount: (instance: unknown) => void | Promise<void>;
|
|
46
|
+
createRawSnippet: (factory: () => {
|
|
47
|
+
render: () => string;
|
|
48
|
+
setup?: (element: Element) => void;
|
|
49
|
+
}) => unknown;
|
|
50
|
+
}
|
|
51
|
+
type SvelteHtmlHostInitIslands<TController = unknown> = (hydrate: HydrateFunction, options?: InitIslandsOptions) => TController;
|
|
52
|
+
type InitSvelteHtmlHostInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateInput<TRuntime> & {
|
|
53
|
+
initIslands: SvelteHtmlHostInitIslands;
|
|
54
|
+
options?: InitIslandsOptions;
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/html-host-dom-renderer.d.ts
|
|
58
|
+
type SvelteHtmlHostDomRenderer = SvelteHtmlHostClientRenderer<SvelteHtmlHostDomRuntime>;
|
|
59
|
+
declare function loadSvelteHtmlHostDomRuntime(): Promise<SvelteHtmlHostDomRuntime>;
|
|
60
|
+
declare function createSvelteHtmlHostDomRenderer(input: SvelteHtmlHostDomRendererInput): SvelteHtmlHostDomRenderer;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/html-host-client.d.ts
|
|
63
|
+
declare function initSvelteHtmlHost<TRuntime = undefined>(input: InitSvelteHtmlHostInput<TRuntime>): ReturnType<InitSvelteHtmlHostInput<TRuntime>["initIslands"]>;
|
|
64
|
+
declare function createSvelteHtmlHostLazyHydrate<TRuntime = undefined>(input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>): HtmlHostLazyHydrateFunction;
|
|
65
|
+
declare function readSvelteHtmlHostSlot(element: Pick<HTMLElement, "dataset" | "innerHTML">): string | undefined;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { initSvelteHtmlHost, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
|
|
68
|
+
export type { CreateSvelteHtmlHostLazyHydrateInput, InitSvelteHtmlHostInput, SvelteHtmlHostClientContext, SvelteHtmlHostClientDiagnosticCode, SvelteHtmlHostClientError, SvelteHtmlHostClientComponentValue, SvelteHtmlHostClientModuleLoader, SvelteHtmlHostClientModules, SvelteHtmlHostClientModuleValue, SvelteHtmlHostClientRenderer, SvelteHtmlHostClientRuntimeLoader, SvelteHtmlHostDomMode, SvelteHtmlHostDomRenderer, SvelteHtmlHostDomRendererInput, SvelteHtmlHostDomRuntime, SvelteHtmlHostExportNameResolver, SvelteHtmlHostInitIslands, SvelteHtmlHostModuleIdResolver };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { HtmlHostClientContext, HtmlHostClientDiagnosticCode, HtmlHostClientError, HtmlHostClientModuleLoader, HtmlHostClientRenderer, HtmlHostClientRuntimeLoader, HtmlHostExportNameResolver, HtmlHostHydrationHandle, HtmlHostLazyHydrateFunction, HtmlHostModuleIdResolver } from "@ox-content/islands/html-host";
|
|
2
|
+
import { HydrateFunction, InitIslandsOptions } from "@ox-content/islands";
|
|
3
|
+
//#region src/html-host-client-types.d.ts
|
|
4
|
+
type SvelteHtmlHostClientDiagnosticCode = HtmlHostClientDiagnosticCode;
|
|
5
|
+
type SvelteHtmlHostClientError = HtmlHostClientError;
|
|
6
|
+
type SvelteHtmlHostClientComponentValue = unknown;
|
|
7
|
+
type SvelteHtmlHostClientModuleValue = SvelteHtmlHostClientComponentValue;
|
|
8
|
+
type SvelteHtmlHostClientModuleLoader<TModule = SvelteHtmlHostClientModuleValue> = HtmlHostClientModuleLoader<TModule>;
|
|
9
|
+
type SvelteHtmlHostClientModules = Readonly<Record<string, SvelteHtmlHostClientModuleLoader>> | ReadonlyMap<string, SvelteHtmlHostClientModuleLoader>;
|
|
10
|
+
type SvelteHtmlHostClientContext<TRuntime = undefined> = HtmlHostClientContext<TRuntime>;
|
|
11
|
+
type SvelteHtmlHostClientRenderer<TRuntime = undefined> = HtmlHostClientRenderer<TRuntime>;
|
|
12
|
+
type SvelteHtmlHostClientRuntimeLoader<TRuntime = undefined> = HtmlHostClientRuntimeLoader<TRuntime>;
|
|
13
|
+
type SvelteHtmlHostModuleIdResolver = HtmlHostModuleIdResolver;
|
|
14
|
+
type SvelteHtmlHostExportNameResolver = HtmlHostExportNameResolver;
|
|
15
|
+
type SvelteHtmlHostHydrationHandle = HtmlHostHydrationHandle;
|
|
16
|
+
interface SvelteHtmlHostClientBaseInput<TRuntime = undefined> {
|
|
17
|
+
modules: SvelteHtmlHostClientModules;
|
|
18
|
+
loadRuntime?: SvelteHtmlHostClientRuntimeLoader<TRuntime>;
|
|
19
|
+
resolveModuleId?: SvelteHtmlHostModuleIdResolver;
|
|
20
|
+
resolveExportName?: SvelteHtmlHostExportNameResolver;
|
|
21
|
+
onError?: (error: SvelteHtmlHostClientError) => void;
|
|
22
|
+
}
|
|
23
|
+
interface CreateSvelteHtmlHostLazyHydrateRenderInput<TRuntime = undefined> extends SvelteHtmlHostClientBaseInput<TRuntime> {
|
|
24
|
+
render: SvelteHtmlHostClientRenderer<TRuntime>;
|
|
25
|
+
mount?: never;
|
|
26
|
+
}
|
|
27
|
+
interface CreateSvelteHtmlHostLazyHydrateMountInput extends SvelteHtmlHostClientBaseInput<SvelteHtmlHostDomRuntime> {
|
|
28
|
+
mount: SvelteHtmlHostDomRendererInput;
|
|
29
|
+
render?: never;
|
|
30
|
+
}
|
|
31
|
+
type CreateSvelteHtmlHostLazyHydrateInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateRenderInput<TRuntime> | CreateSvelteHtmlHostLazyHydrateMountInput;
|
|
32
|
+
type SvelteHtmlHostDomMode = "render" | "hydrate";
|
|
33
|
+
interface SvelteHtmlHostDomRendererInput {
|
|
34
|
+
mode: SvelteHtmlHostDomMode;
|
|
35
|
+
}
|
|
36
|
+
interface SvelteHtmlHostDomRuntime {
|
|
37
|
+
mount: (component: SvelteHtmlHostClientComponentValue, options: {
|
|
38
|
+
target: HTMLElement;
|
|
39
|
+
props?: Record<string, unknown>;
|
|
40
|
+
}) => unknown;
|
|
41
|
+
hydrate: (component: SvelteHtmlHostClientComponentValue, options: {
|
|
42
|
+
target: HTMLElement;
|
|
43
|
+
props?: Record<string, unknown>;
|
|
44
|
+
}) => unknown;
|
|
45
|
+
unmount: (instance: unknown) => void | Promise<void>;
|
|
46
|
+
createRawSnippet: (factory: () => {
|
|
47
|
+
render: () => string;
|
|
48
|
+
setup?: (element: Element) => void;
|
|
49
|
+
}) => unknown;
|
|
50
|
+
}
|
|
51
|
+
type SvelteHtmlHostInitIslands<TController = unknown> = (hydrate: HydrateFunction, options?: InitIslandsOptions) => TController;
|
|
52
|
+
type InitSvelteHtmlHostInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateInput<TRuntime> & {
|
|
53
|
+
initIslands: SvelteHtmlHostInitIslands;
|
|
54
|
+
options?: InitIslandsOptions;
|
|
55
|
+
};
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/html-host-dom-renderer.d.ts
|
|
58
|
+
type SvelteHtmlHostDomRenderer = SvelteHtmlHostClientRenderer<SvelteHtmlHostDomRuntime>;
|
|
59
|
+
declare function loadSvelteHtmlHostDomRuntime(): Promise<SvelteHtmlHostDomRuntime>;
|
|
60
|
+
declare function createSvelteHtmlHostDomRenderer(input: SvelteHtmlHostDomRendererInput): SvelteHtmlHostDomRenderer;
|
|
61
|
+
//#endregion
|
|
62
|
+
//#region src/html-host-client.d.ts
|
|
63
|
+
declare function initSvelteHtmlHost<TRuntime = undefined>(input: InitSvelteHtmlHostInput<TRuntime>): ReturnType<InitSvelteHtmlHostInput<TRuntime>["initIslands"]>;
|
|
64
|
+
declare function createSvelteHtmlHostLazyHydrate<TRuntime = undefined>(input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>): HtmlHostLazyHydrateFunction;
|
|
65
|
+
declare function readSvelteHtmlHostSlot(element: Pick<HTMLElement, "dataset" | "innerHTML">): string | undefined;
|
|
66
|
+
//#endregion
|
|
67
|
+
export { initSvelteHtmlHost, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
|
|
68
|
+
export type { CreateSvelteHtmlHostLazyHydrateInput, InitSvelteHtmlHostInput, SvelteHtmlHostClientContext, SvelteHtmlHostClientDiagnosticCode, SvelteHtmlHostClientError, SvelteHtmlHostClientComponentValue, SvelteHtmlHostClientModuleLoader, SvelteHtmlHostClientModules, SvelteHtmlHostClientModuleValue, SvelteHtmlHostClientRenderer, SvelteHtmlHostClientRuntimeLoader, SvelteHtmlHostDomMode, SvelteHtmlHostDomRenderer, SvelteHtmlHostDomRendererInput, SvelteHtmlHostDomRuntime, SvelteHtmlHostExportNameResolver, SvelteHtmlHostInitIslands, SvelteHtmlHostModuleIdResolver };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as loadSvelteHtmlHostDomRuntime, i as createSvelteHtmlHostDomRenderer, n as initSvelteHtmlHost, r as readSvelteHtmlHostSlot, t as createSvelteHtmlHostLazyHydrate } from "./html-host-client2.mjs";
|
|
2
|
+
export { createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, initSvelteHtmlHost, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
let _ox_content_islands_html_host = require("@ox-content/islands/html-host");
|
|
2
|
+
//#region src/html-host-dom-renderer.ts
|
|
3
|
+
const DOM_RENDERER_MODE = Symbol("svelte-html-host-dom-renderer-mode");
|
|
4
|
+
async function loadSvelteHtmlHostDomRuntime() {
|
|
5
|
+
const { createRawSnippet, hydrate, mount, unmount } = await import("svelte");
|
|
6
|
+
return {
|
|
7
|
+
createRawSnippet,
|
|
8
|
+
hydrate,
|
|
9
|
+
mount,
|
|
10
|
+
unmount
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function createSvelteHtmlHostDomRenderer(input) {
|
|
14
|
+
const renderer = ((context) => {
|
|
15
|
+
const runtime = context.runtime;
|
|
16
|
+
if (!runtime) throw new Error("Svelte HTML host DOM renderer requires a Svelte runtime.");
|
|
17
|
+
const componentProps = componentPropsWithSlot(runtime, context.props, context.slotHtml);
|
|
18
|
+
const instance = input.mode === "hydrate" ? runtime.hydrate(context.component, {
|
|
19
|
+
target: context.element,
|
|
20
|
+
props: componentProps
|
|
21
|
+
}) : runtime.mount(context.component, {
|
|
22
|
+
target: context.element,
|
|
23
|
+
props: componentProps
|
|
24
|
+
});
|
|
25
|
+
return () => {
|
|
26
|
+
runtime.unmount(instance);
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(renderer, DOM_RENDERER_MODE, { value: input.mode });
|
|
30
|
+
return renderer;
|
|
31
|
+
}
|
|
32
|
+
function svelteHtmlHostDomRendererMode(renderer) {
|
|
33
|
+
return renderer[DOM_RENDERER_MODE];
|
|
34
|
+
}
|
|
35
|
+
function componentPropsWithSlot(runtime, props, slotHtml) {
|
|
36
|
+
if (!slotHtml) return props;
|
|
37
|
+
return {
|
|
38
|
+
...props,
|
|
39
|
+
children: runtime.createRawSnippet(() => ({
|
|
40
|
+
render: () => slotHtml,
|
|
41
|
+
setup: (element) => {
|
|
42
|
+
element.innerHTML = slotHtml;
|
|
43
|
+
}
|
|
44
|
+
}))
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/html-host-client.ts
|
|
49
|
+
function initSvelteHtmlHost(input) {
|
|
50
|
+
return input.initIslands(createSvelteHtmlHostLazyHydrate(input), input.options);
|
|
51
|
+
}
|
|
52
|
+
function createSvelteHtmlHostLazyHydrate(input) {
|
|
53
|
+
const render = resolveRenderer(input);
|
|
54
|
+
return (0, _ox_content_islands_html_host.createHtmlHostLazyHydrate)({
|
|
55
|
+
modules: input.modules,
|
|
56
|
+
loadRuntime: resolveRuntimeLoader(input, render),
|
|
57
|
+
resolveModuleId: input.resolveModuleId,
|
|
58
|
+
resolveExportName: input.resolveExportName,
|
|
59
|
+
onError: input.onError,
|
|
60
|
+
render,
|
|
61
|
+
preserveElementContents: preservesElementContents(input, render),
|
|
62
|
+
frameworkName: "Svelte",
|
|
63
|
+
eventName: "ox-content-svelte-html-host:error"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function readSvelteHtmlHostSlot(element) {
|
|
67
|
+
return (0, _ox_content_islands_html_host.readHtmlHostSlot)(element);
|
|
68
|
+
}
|
|
69
|
+
function resolveRenderer(input) {
|
|
70
|
+
if (input.render) return input.render;
|
|
71
|
+
if (input.mount) return createSvelteHtmlHostDomRenderer(input.mount);
|
|
72
|
+
throw new Error("initSvelteHtmlHost requires either render or mount.");
|
|
73
|
+
}
|
|
74
|
+
function resolveRuntimeLoader(input, render) {
|
|
75
|
+
if (input.loadRuntime) return input.loadRuntime;
|
|
76
|
+
if (input.mount || svelteHtmlHostDomRendererMode(render)) return loadSvelteHtmlHostDomRuntime;
|
|
77
|
+
}
|
|
78
|
+
function preservesElementContents(input, render) {
|
|
79
|
+
return (input.mount?.mode ?? svelteHtmlHostDomRendererMode(render)) === "hydrate";
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
Object.defineProperty(exports, "createSvelteHtmlHostDomRenderer", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
get: function() {
|
|
85
|
+
return createSvelteHtmlHostDomRenderer;
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(exports, "createSvelteHtmlHostLazyHydrate", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
get: function() {
|
|
91
|
+
return createSvelteHtmlHostLazyHydrate;
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
Object.defineProperty(exports, "initSvelteHtmlHost", {
|
|
95
|
+
enumerable: true,
|
|
96
|
+
get: function() {
|
|
97
|
+
return initSvelteHtmlHost;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
Object.defineProperty(exports, "loadSvelteHtmlHostDomRuntime", {
|
|
101
|
+
enumerable: true,
|
|
102
|
+
get: function() {
|
|
103
|
+
return loadSvelteHtmlHostDomRuntime;
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
Object.defineProperty(exports, "readSvelteHtmlHostSlot", {
|
|
107
|
+
enumerable: true,
|
|
108
|
+
get: function() {
|
|
109
|
+
return readSvelteHtmlHostSlot;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as SvelteHtmlHostInitIslands, S as SvelteHtmlHostHydrationHandle, _ as SvelteHtmlHostClientRuntimeLoader, a as createSvelteHtmlHostDomRenderer, b as SvelteHtmlHostDomRuntime, c as InitSvelteHtmlHostInput, d as SvelteHtmlHostClientDiagnosticCode, f as SvelteHtmlHostClientError, g as SvelteHtmlHostClientRenderer, h as SvelteHtmlHostClientModules, i as SvelteHtmlHostDomRenderer, l as SvelteHtmlHostClientComponentValue, m as SvelteHtmlHostClientModuleValue, n as initSvelteHtmlHost, o as loadSvelteHtmlHostDomRuntime, p as SvelteHtmlHostClientModuleLoader, r as readSvelteHtmlHostSlot, s as CreateSvelteHtmlHostLazyHydrateInput, t as createSvelteHtmlHostLazyHydrate, u as SvelteHtmlHostClientContext, v as SvelteHtmlHostDomMode, w as SvelteHtmlHostModuleIdResolver, x as SvelteHtmlHostExportNameResolver, y as SvelteHtmlHostDomRendererInput } from "./html-host-client.cjs";
|
|
2
|
+
export { type CreateSvelteHtmlHostLazyHydrateInput, type InitSvelteHtmlHostInput, type SvelteHtmlHostClientComponentValue, type SvelteHtmlHostClientContext, type SvelteHtmlHostClientDiagnosticCode, type SvelteHtmlHostClientError, type SvelteHtmlHostClientModuleLoader, type SvelteHtmlHostClientModuleValue, type SvelteHtmlHostClientModules, type SvelteHtmlHostClientRenderer, type SvelteHtmlHostClientRuntimeLoader, type SvelteHtmlHostDomMode, type SvelteHtmlHostDomRenderer, type SvelteHtmlHostDomRendererInput, type SvelteHtmlHostDomRuntime, type SvelteHtmlHostExportNameResolver, type SvelteHtmlHostHydrationHandle, type SvelteHtmlHostInitIslands, type SvelteHtmlHostModuleIdResolver, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, initSvelteHtmlHost, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as SvelteHtmlHostInitIslands, S as SvelteHtmlHostHydrationHandle, _ as SvelteHtmlHostClientRuntimeLoader, a as createSvelteHtmlHostDomRenderer, b as SvelteHtmlHostDomRuntime, c as InitSvelteHtmlHostInput, d as SvelteHtmlHostClientDiagnosticCode, f as SvelteHtmlHostClientError, g as SvelteHtmlHostClientRenderer, h as SvelteHtmlHostClientModules, i as SvelteHtmlHostDomRenderer, l as SvelteHtmlHostClientComponentValue, m as SvelteHtmlHostClientModuleValue, n as initSvelteHtmlHost, o as loadSvelteHtmlHostDomRuntime, p as SvelteHtmlHostClientModuleLoader, r as readSvelteHtmlHostSlot, s as CreateSvelteHtmlHostLazyHydrateInput, t as createSvelteHtmlHostLazyHydrate, u as SvelteHtmlHostClientContext, v as SvelteHtmlHostDomMode, w as SvelteHtmlHostModuleIdResolver, x as SvelteHtmlHostExportNameResolver, y as SvelteHtmlHostDomRendererInput } from "./html-host-client.mjs";
|
|
2
|
+
export { type CreateSvelteHtmlHostLazyHydrateInput, type InitSvelteHtmlHostInput, type SvelteHtmlHostClientComponentValue, type SvelteHtmlHostClientContext, type SvelteHtmlHostClientDiagnosticCode, type SvelteHtmlHostClientError, type SvelteHtmlHostClientModuleLoader, type SvelteHtmlHostClientModuleValue, type SvelteHtmlHostClientModules, type SvelteHtmlHostClientRenderer, type SvelteHtmlHostClientRuntimeLoader, type SvelteHtmlHostDomMode, type SvelteHtmlHostDomRenderer, type SvelteHtmlHostDomRendererInput, type SvelteHtmlHostDomRuntime, type SvelteHtmlHostExportNameResolver, type SvelteHtmlHostHydrationHandle, type SvelteHtmlHostInitIslands, type SvelteHtmlHostModuleIdResolver, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, initSvelteHtmlHost, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { createHtmlHostLazyHydrate, readHtmlHostSlot } from "@ox-content/islands/html-host";
|
|
2
|
+
//#region src/html-host-dom-renderer.ts
|
|
3
|
+
const DOM_RENDERER_MODE = Symbol("svelte-html-host-dom-renderer-mode");
|
|
4
|
+
async function loadSvelteHtmlHostDomRuntime() {
|
|
5
|
+
const { createRawSnippet, hydrate, mount, unmount } = await import("svelte");
|
|
6
|
+
return {
|
|
7
|
+
createRawSnippet,
|
|
8
|
+
hydrate,
|
|
9
|
+
mount,
|
|
10
|
+
unmount
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function createSvelteHtmlHostDomRenderer(input) {
|
|
14
|
+
const renderer = ((context) => {
|
|
15
|
+
const runtime = context.runtime;
|
|
16
|
+
if (!runtime) throw new Error("Svelte HTML host DOM renderer requires a Svelte runtime.");
|
|
17
|
+
const componentProps = componentPropsWithSlot(runtime, context.props, context.slotHtml);
|
|
18
|
+
const instance = input.mode === "hydrate" ? runtime.hydrate(context.component, {
|
|
19
|
+
target: context.element,
|
|
20
|
+
props: componentProps
|
|
21
|
+
}) : runtime.mount(context.component, {
|
|
22
|
+
target: context.element,
|
|
23
|
+
props: componentProps
|
|
24
|
+
});
|
|
25
|
+
return () => {
|
|
26
|
+
runtime.unmount(instance);
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(renderer, DOM_RENDERER_MODE, { value: input.mode });
|
|
30
|
+
return renderer;
|
|
31
|
+
}
|
|
32
|
+
function svelteHtmlHostDomRendererMode(renderer) {
|
|
33
|
+
return renderer[DOM_RENDERER_MODE];
|
|
34
|
+
}
|
|
35
|
+
function componentPropsWithSlot(runtime, props, slotHtml) {
|
|
36
|
+
if (!slotHtml) return props;
|
|
37
|
+
return {
|
|
38
|
+
...props,
|
|
39
|
+
children: runtime.createRawSnippet(() => ({
|
|
40
|
+
render: () => slotHtml,
|
|
41
|
+
setup: (element) => {
|
|
42
|
+
element.innerHTML = slotHtml;
|
|
43
|
+
}
|
|
44
|
+
}))
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/html-host-client.ts
|
|
49
|
+
function initSvelteHtmlHost(input) {
|
|
50
|
+
return input.initIslands(createSvelteHtmlHostLazyHydrate(input), input.options);
|
|
51
|
+
}
|
|
52
|
+
function createSvelteHtmlHostLazyHydrate(input) {
|
|
53
|
+
const render = resolveRenderer(input);
|
|
54
|
+
return createHtmlHostLazyHydrate({
|
|
55
|
+
modules: input.modules,
|
|
56
|
+
loadRuntime: resolveRuntimeLoader(input, render),
|
|
57
|
+
resolveModuleId: input.resolveModuleId,
|
|
58
|
+
resolveExportName: input.resolveExportName,
|
|
59
|
+
onError: input.onError,
|
|
60
|
+
render,
|
|
61
|
+
preserveElementContents: preservesElementContents(input, render),
|
|
62
|
+
frameworkName: "Svelte",
|
|
63
|
+
eventName: "ox-content-svelte-html-host:error"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function readSvelteHtmlHostSlot(element) {
|
|
67
|
+
return readHtmlHostSlot(element);
|
|
68
|
+
}
|
|
69
|
+
function resolveRenderer(input) {
|
|
70
|
+
if (input.render) return input.render;
|
|
71
|
+
if (input.mount) return createSvelteHtmlHostDomRenderer(input.mount);
|
|
72
|
+
throw new Error("initSvelteHtmlHost requires either render or mount.");
|
|
73
|
+
}
|
|
74
|
+
function resolveRuntimeLoader(input, render) {
|
|
75
|
+
if (input.loadRuntime) return input.loadRuntime;
|
|
76
|
+
if (input.mount || svelteHtmlHostDomRendererMode(render)) return loadSvelteHtmlHostDomRuntime;
|
|
77
|
+
}
|
|
78
|
+
function preservesElementContents(input, render) {
|
|
79
|
+
return (input.mount?.mode ?? svelteHtmlHostDomRendererMode(render)) === "hydrate";
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
export { loadSvelteHtmlHostDomRuntime as a, createSvelteHtmlHostDomRenderer as i, initSvelteHtmlHost as n, readSvelteHtmlHostSlot as r, createSvelteHtmlHostLazyHydrate as t };
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=html-host-client2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-host-client2.mjs","names":[],"sources":["../src/html-host-dom-renderer.ts","../src/html-host-client.ts"],"sourcesContent":["import type {\n SvelteHtmlHostClientRenderer,\n SvelteHtmlHostDomMode,\n SvelteHtmlHostDomRendererInput,\n SvelteHtmlHostDomRuntime,\n} from \"./html-host-client-types\";\n\nconst DOM_RENDERER_MODE = Symbol(\"svelte-html-host-dom-renderer-mode\");\n\nexport type SvelteHtmlHostDomRenderer = SvelteHtmlHostClientRenderer<SvelteHtmlHostDomRuntime>;\n\ntype ModeTaggedSvelteHtmlHostDomRenderer = SvelteHtmlHostDomRenderer & {\n readonly [DOM_RENDERER_MODE]: SvelteHtmlHostDomMode;\n};\n\nexport async function loadSvelteHtmlHostDomRuntime(): Promise<SvelteHtmlHostDomRuntime> {\n const { createRawSnippet, hydrate, mount, unmount } = await import(\"svelte\");\n\n return {\n createRawSnippet: createRawSnippet as SvelteHtmlHostDomRuntime[\"createRawSnippet\"],\n hydrate: hydrate as SvelteHtmlHostDomRuntime[\"hydrate\"],\n mount: mount as SvelteHtmlHostDomRuntime[\"mount\"],\n unmount: unmount as SvelteHtmlHostDomRuntime[\"unmount\"],\n };\n}\n\nexport function createSvelteHtmlHostDomRenderer(\n input: SvelteHtmlHostDomRendererInput,\n): SvelteHtmlHostDomRenderer {\n const renderer = ((context) => {\n const runtime = context.runtime;\n if (!runtime) {\n throw new Error(\"Svelte HTML host DOM renderer requires a Svelte runtime.\");\n }\n const componentProps = componentPropsWithSlot(runtime, context.props, context.slotHtml);\n const instance =\n input.mode === \"hydrate\"\n ? runtime.hydrate(context.component, { target: context.element, props: componentProps })\n : runtime.mount(context.component, { target: context.element, props: componentProps });\n return () => {\n void runtime.unmount(instance);\n };\n }) as ModeTaggedSvelteHtmlHostDomRenderer;\n\n Object.defineProperty(renderer, DOM_RENDERER_MODE, { value: input.mode });\n return renderer;\n}\n\nexport function svelteHtmlHostDomRendererMode(\n renderer: SvelteHtmlHostClientRenderer<unknown>,\n): SvelteHtmlHostDomMode | undefined {\n return (renderer as Partial<ModeTaggedSvelteHtmlHostDomRenderer>)[DOM_RENDERER_MODE];\n}\n\nfunction componentPropsWithSlot(\n runtime: SvelteHtmlHostDomRuntime,\n props: Record<string, unknown>,\n slotHtml: string | undefined,\n): Record<string, unknown> {\n if (!slotHtml) return props;\n return {\n ...props,\n children: runtime.createRawSnippet(() => ({\n render: () => slotHtml,\n setup: (element) => {\n element.innerHTML = slotHtml;\n },\n })),\n };\n}\n","import {\n createHtmlHostLazyHydrate,\n readHtmlHostSlot,\n type HtmlHostLazyHydrateFunction,\n} from \"@ox-content/islands/html-host\";\nimport type {\n CreateSvelteHtmlHostLazyHydrateInput,\n InitSvelteHtmlHostInput,\n SvelteHtmlHostClientRenderer,\n SvelteHtmlHostClientRuntimeLoader,\n} from \"./html-host-client-types\";\nimport {\n createSvelteHtmlHostDomRenderer,\n loadSvelteHtmlHostDomRuntime,\n svelteHtmlHostDomRendererMode,\n} from \"./html-host-dom-renderer\";\n\nexport type {\n CreateSvelteHtmlHostLazyHydrateInput,\n InitSvelteHtmlHostInput,\n SvelteHtmlHostClientContext,\n SvelteHtmlHostClientDiagnosticCode,\n SvelteHtmlHostClientError,\n SvelteHtmlHostClientComponentValue,\n SvelteHtmlHostClientModuleLoader,\n SvelteHtmlHostClientModules,\n SvelteHtmlHostClientModuleValue,\n SvelteHtmlHostClientRenderer,\n SvelteHtmlHostClientRuntimeLoader,\n SvelteHtmlHostDomMode,\n SvelteHtmlHostDomRendererInput,\n SvelteHtmlHostDomRuntime,\n SvelteHtmlHostExportNameResolver,\n SvelteHtmlHostHydrationHandle,\n SvelteHtmlHostInitIslands,\n SvelteHtmlHostModuleIdResolver,\n} from \"./html-host-client-types\";\nexport {\n createSvelteHtmlHostDomRenderer,\n loadSvelteHtmlHostDomRuntime,\n type SvelteHtmlHostDomRenderer,\n} from \"./html-host-dom-renderer\";\n\nexport function initSvelteHtmlHost<TRuntime = undefined>(\n input: InitSvelteHtmlHostInput<TRuntime>,\n): ReturnType<InitSvelteHtmlHostInput<TRuntime>[\"initIslands\"]> {\n return input.initIslands(createSvelteHtmlHostLazyHydrate(input), input.options);\n}\n\nexport function createSvelteHtmlHostLazyHydrate<TRuntime = undefined>(\n input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>,\n): HtmlHostLazyHydrateFunction {\n const render = resolveRenderer(input);\n return createHtmlHostLazyHydrate({\n modules: input.modules,\n loadRuntime: resolveRuntimeLoader(input, render),\n resolveModuleId: input.resolveModuleId,\n resolveExportName: input.resolveExportName,\n onError: input.onError,\n render,\n preserveElementContents: preservesElementContents(input, render),\n frameworkName: \"Svelte\",\n eventName: \"ox-content-svelte-html-host:error\",\n });\n}\n\nexport function readSvelteHtmlHostSlot(\n element: Pick<HTMLElement, \"dataset\" | \"innerHTML\">,\n): string | undefined {\n return readHtmlHostSlot(element);\n}\n\nfunction resolveRenderer<TRuntime>(\n input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>,\n): SvelteHtmlHostClientRenderer<TRuntime> {\n if (input.render) return input.render;\n if (input.mount) {\n return createSvelteHtmlHostDomRenderer(input.mount) as SvelteHtmlHostClientRenderer<TRuntime>;\n }\n throw new Error(\"initSvelteHtmlHost requires either render or mount.\");\n}\n\nfunction resolveRuntimeLoader<TRuntime>(\n input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>,\n render: SvelteHtmlHostClientRenderer<TRuntime>,\n): SvelteHtmlHostClientRuntimeLoader<TRuntime> | undefined {\n if (input.loadRuntime) {\n return input.loadRuntime as SvelteHtmlHostClientRuntimeLoader<TRuntime>;\n }\n if (\n input.mount ||\n svelteHtmlHostDomRendererMode(render as SvelteHtmlHostClientRenderer<unknown>)\n ) {\n return loadSvelteHtmlHostDomRuntime as SvelteHtmlHostClientRuntimeLoader<TRuntime>;\n }\n return undefined;\n}\n\nfunction preservesElementContents<TRuntime>(\n input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>,\n render: SvelteHtmlHostClientRenderer<TRuntime>,\n): boolean {\n const mode =\n input.mount?.mode ??\n svelteHtmlHostDomRendererMode(render as unknown as SvelteHtmlHostClientRenderer<unknown>);\n return mode === \"hydrate\";\n}\n"],"mappings":";;AAOA,MAAM,oBAAoB,OAAO,oCAAoC;AAQrE,eAAsB,+BAAkE;CACtF,MAAM,EAAE,kBAAkB,SAAS,OAAO,YAAY,MAAM,OAAO;CAEnE,OAAO;EACa;EACT;EACF;EACE;CACX;AACF;AAEA,SAAgB,gCACd,OAC2B;CAC3B,MAAM,aAAa,YAAY;EAC7B,MAAM,UAAU,QAAQ;EACxB,IAAI,CAAC,SACH,MAAM,IAAI,MAAM,0DAA0D;EAE5E,MAAM,iBAAiB,uBAAuB,SAAS,QAAQ,OAAO,QAAQ,QAAQ;EACtF,MAAM,WACJ,MAAM,SAAS,YACX,QAAQ,QAAQ,QAAQ,WAAW;GAAE,QAAQ,QAAQ;GAAS,OAAO;EAAe,CAAC,IACrF,QAAQ,MAAM,QAAQ,WAAW;GAAE,QAAQ,QAAQ;GAAS,OAAO;EAAe,CAAC;EACzF,aAAa;GACX,QAAa,QAAQ,QAAQ;EAC/B;CACF;CAEA,OAAO,eAAe,UAAU,mBAAmB,EAAE,OAAO,MAAM,KAAK,CAAC;CACxE,OAAO;AACT;AAEA,SAAgB,8BACd,UACmC;CACnC,OAAQ,SAA0D;AACpE;AAEA,SAAS,uBACP,SACA,OACA,UACyB;CACzB,IAAI,CAAC,UAAU,OAAO;CACtB,OAAO;EACL,GAAG;EACH,UAAU,QAAQ,wBAAwB;GACxC,cAAc;GACd,QAAQ,YAAY;IAClB,QAAQ,YAAY;GACtB;EACF,EAAE;CACJ;AACF;;;AC1BA,SAAgB,mBACd,OAC8D;CAC9D,OAAO,MAAM,YAAY,gCAAgC,KAAK,GAAG,MAAM,OAAO;AAChF;AAEA,SAAgB,gCACd,OAC6B;CAC7B,MAAM,SAAS,gBAAgB,KAAK;CACpC,OAAO,0BAA0B;EAC/B,SAAS,MAAM;EACf,aAAa,qBAAqB,OAAO,MAAM;EAC/C,iBAAiB,MAAM;EACvB,mBAAmB,MAAM;EACzB,SAAS,MAAM;EACf;EACA,yBAAyB,yBAAyB,OAAO,MAAM;EAC/D,eAAe;EACf,WAAW;CACb,CAAC;AACH;AAEA,SAAgB,uBACd,SACoB;CACpB,OAAO,iBAAiB,OAAO;AACjC;AAEA,SAAS,gBACP,OACwC;CACxC,IAAI,MAAM,QAAQ,OAAO,MAAM;CAC/B,IAAI,MAAM,OACR,OAAO,gCAAgC,MAAM,KAAK;CAEpD,MAAM,IAAI,MAAM,qDAAqD;AACvE;AAEA,SAAS,qBACP,OACA,QACyD;CACzD,IAAI,MAAM,aACR,OAAO,MAAM;CAEf,IACE,MAAM,SACN,8BAA8B,MAA+C,GAE7E,OAAO;AAGX;AAEA,SAAS,yBACP,OACA,QACS;CAIT,QAFE,MAAM,OAAO,QACb,8BAA8B,MAA0D,OAC1E;AAClB"}
|