@ox-content/vite-plugin-svelte 3.1.2-beta.0 → 3.1.3
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 +92 -0
- package/dist/html-host-client.d.mts +92 -0
- package/dist/html-host-client.mjs +2 -0
- package/dist/html-host-client2.cjs +293 -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 +266 -0
- package/dist/html-host-client2.mjs.map +1 -0
- package/dist/index.cjs +715 -64
- package/dist/index.d.cts +187 -4
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +187 -4
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +698 -65
- 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,92 @@
|
|
|
1
|
+
import { InitIslandsOptions } from "@ox-content/islands";
|
|
2
|
+
//#region src/html-host-client-types.d.ts
|
|
3
|
+
type SvelteHtmlHostClientDiagnosticCode = "missing-island-name" | "missing-module-id" | "unknown-module" | "module-load-failed" | "runtime-load-failed" | "missing-export" | "render-failed";
|
|
4
|
+
interface SvelteHtmlHostClientError {
|
|
5
|
+
code: SvelteHtmlHostClientDiagnosticCode;
|
|
6
|
+
message: string;
|
|
7
|
+
element: HTMLElement;
|
|
8
|
+
props: Record<string, unknown>;
|
|
9
|
+
componentName?: string;
|
|
10
|
+
moduleId?: string;
|
|
11
|
+
exportName?: string;
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
}
|
|
14
|
+
type SvelteHtmlHostClientComponentValue = unknown;
|
|
15
|
+
type SvelteHtmlHostClientModuleValue = SvelteHtmlHostClientComponentValue;
|
|
16
|
+
type SvelteHtmlHostClientModuleLoader<TModule = SvelteHtmlHostClientModuleValue> = () => TModule | PromiseLike<TModule>;
|
|
17
|
+
type SvelteHtmlHostClientModules = Readonly<Record<string, SvelteHtmlHostClientModuleLoader>> | ReadonlyMap<string, SvelteHtmlHostClientModuleLoader>;
|
|
18
|
+
interface SvelteHtmlHostClientContext<TRuntime = undefined> {
|
|
19
|
+
component: unknown;
|
|
20
|
+
componentName: string;
|
|
21
|
+
element: HTMLElement;
|
|
22
|
+
exportName: string;
|
|
23
|
+
moduleExports: unknown;
|
|
24
|
+
moduleId: string;
|
|
25
|
+
props: Record<string, unknown>;
|
|
26
|
+
runtime: TRuntime | undefined;
|
|
27
|
+
slotHtml: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
type SvelteHtmlHostClientRenderer<TRuntime = undefined> = (context: SvelteHtmlHostClientContext<TRuntime>) => void | (() => void) | PromiseLike<void | (() => void)>;
|
|
30
|
+
type SvelteHtmlHostClientRuntimeLoader<TRuntime = undefined> = () => TRuntime | Promise<TRuntime>;
|
|
31
|
+
type SvelteHtmlHostModuleIdResolver = (element: HTMLElement, context: {
|
|
32
|
+
componentName: string;
|
|
33
|
+
props: Record<string, unknown>;
|
|
34
|
+
}) => string | undefined;
|
|
35
|
+
type SvelteHtmlHostExportNameResolver = (element: HTMLElement, context: {
|
|
36
|
+
componentName: string;
|
|
37
|
+
moduleId: string;
|
|
38
|
+
props: Record<string, unknown>;
|
|
39
|
+
}) => string | undefined;
|
|
40
|
+
interface SvelteHtmlHostClientBaseInput<TRuntime = undefined> {
|
|
41
|
+
modules: SvelteHtmlHostClientModules;
|
|
42
|
+
loadRuntime?: SvelteHtmlHostClientRuntimeLoader<TRuntime>;
|
|
43
|
+
resolveModuleId?: SvelteHtmlHostModuleIdResolver;
|
|
44
|
+
resolveExportName?: SvelteHtmlHostExportNameResolver;
|
|
45
|
+
onError?: (error: SvelteHtmlHostClientError) => void;
|
|
46
|
+
}
|
|
47
|
+
interface CreateSvelteHtmlHostLazyHydrateRenderInput<TRuntime = undefined> extends SvelteHtmlHostClientBaseInput<TRuntime> {
|
|
48
|
+
render: SvelteHtmlHostClientRenderer<TRuntime>;
|
|
49
|
+
mount?: never;
|
|
50
|
+
}
|
|
51
|
+
interface CreateSvelteHtmlHostLazyHydrateMountInput extends SvelteHtmlHostClientBaseInput<SvelteHtmlHostDomRuntime> {
|
|
52
|
+
mount: SvelteHtmlHostDomRendererInput;
|
|
53
|
+
render?: never;
|
|
54
|
+
}
|
|
55
|
+
type CreateSvelteHtmlHostLazyHydrateInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateRenderInput<TRuntime> | CreateSvelteHtmlHostLazyHydrateMountInput;
|
|
56
|
+
type SvelteHtmlHostDomMode = "render" | "hydrate";
|
|
57
|
+
interface SvelteHtmlHostDomRendererInput {
|
|
58
|
+
mode: SvelteHtmlHostDomMode;
|
|
59
|
+
}
|
|
60
|
+
interface SvelteHtmlHostDomRuntime {
|
|
61
|
+
mount: (component: SvelteHtmlHostClientComponentValue, options: {
|
|
62
|
+
target: HTMLElement;
|
|
63
|
+
props?: Record<string, unknown>;
|
|
64
|
+
}) => unknown;
|
|
65
|
+
hydrate: (component: SvelteHtmlHostClientComponentValue, options: {
|
|
66
|
+
target: HTMLElement;
|
|
67
|
+
props?: Record<string, unknown>;
|
|
68
|
+
}) => unknown;
|
|
69
|
+
unmount: (instance: unknown) => void | Promise<void>;
|
|
70
|
+
createRawSnippet: (factory: () => {
|
|
71
|
+
render: () => string;
|
|
72
|
+
setup?: (element: Element) => void;
|
|
73
|
+
}) => unknown;
|
|
74
|
+
}
|
|
75
|
+
type SvelteHtmlHostInitIslands<TController = unknown> = (hydrate: (element: HTMLElement, props: Record<string, unknown>) => void | (() => void), options?: InitIslandsOptions) => TController;
|
|
76
|
+
type InitSvelteHtmlHostInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateInput<TRuntime> & {
|
|
77
|
+
initIslands: SvelteHtmlHostInitIslands;
|
|
78
|
+
options?: InitIslandsOptions;
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/html-host-dom-renderer.d.ts
|
|
82
|
+
type SvelteHtmlHostDomRenderer = SvelteHtmlHostClientRenderer<SvelteHtmlHostDomRuntime>;
|
|
83
|
+
declare function loadSvelteHtmlHostDomRuntime(): Promise<SvelteHtmlHostDomRuntime>;
|
|
84
|
+
declare function createSvelteHtmlHostDomRenderer(input: SvelteHtmlHostDomRendererInput): SvelteHtmlHostDomRenderer;
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/html-host-client.d.ts
|
|
87
|
+
declare function initSvelteHtmlHost<TRuntime = undefined>(input: InitSvelteHtmlHostInput<TRuntime>): ReturnType<InitSvelteHtmlHostInput<TRuntime>["initIslands"]>;
|
|
88
|
+
declare function createSvelteHtmlHostLazyHydrate<TRuntime = undefined>(input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>): (element: HTMLElement, props: Record<string, unknown>) => () => void;
|
|
89
|
+
declare function readSvelteHtmlHostSlot(element: Pick<HTMLElement, "dataset" | "innerHTML">): string | undefined;
|
|
90
|
+
//#endregion
|
|
91
|
+
export { initSvelteHtmlHost, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
|
|
92
|
+
export type { CreateSvelteHtmlHostLazyHydrateInput, InitSvelteHtmlHostInput, SvelteHtmlHostClientContext, SvelteHtmlHostClientDiagnosticCode, SvelteHtmlHostClientError, SvelteHtmlHostClientComponentValue, SvelteHtmlHostClientModuleLoader, SvelteHtmlHostClientModules, SvelteHtmlHostClientModuleValue, SvelteHtmlHostClientRenderer, SvelteHtmlHostClientRuntimeLoader, SvelteHtmlHostDomMode, SvelteHtmlHostDomRenderer, SvelteHtmlHostDomRendererInput, SvelteHtmlHostDomRuntime, SvelteHtmlHostExportNameResolver, SvelteHtmlHostInitIslands, SvelteHtmlHostModuleIdResolver };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { InitIslandsOptions } from "@ox-content/islands";
|
|
2
|
+
//#region src/html-host-client-types.d.ts
|
|
3
|
+
type SvelteHtmlHostClientDiagnosticCode = "missing-island-name" | "missing-module-id" | "unknown-module" | "module-load-failed" | "runtime-load-failed" | "missing-export" | "render-failed";
|
|
4
|
+
interface SvelteHtmlHostClientError {
|
|
5
|
+
code: SvelteHtmlHostClientDiagnosticCode;
|
|
6
|
+
message: string;
|
|
7
|
+
element: HTMLElement;
|
|
8
|
+
props: Record<string, unknown>;
|
|
9
|
+
componentName?: string;
|
|
10
|
+
moduleId?: string;
|
|
11
|
+
exportName?: string;
|
|
12
|
+
cause?: unknown;
|
|
13
|
+
}
|
|
14
|
+
type SvelteHtmlHostClientComponentValue = unknown;
|
|
15
|
+
type SvelteHtmlHostClientModuleValue = SvelteHtmlHostClientComponentValue;
|
|
16
|
+
type SvelteHtmlHostClientModuleLoader<TModule = SvelteHtmlHostClientModuleValue> = () => TModule | PromiseLike<TModule>;
|
|
17
|
+
type SvelteHtmlHostClientModules = Readonly<Record<string, SvelteHtmlHostClientModuleLoader>> | ReadonlyMap<string, SvelteHtmlHostClientModuleLoader>;
|
|
18
|
+
interface SvelteHtmlHostClientContext<TRuntime = undefined> {
|
|
19
|
+
component: unknown;
|
|
20
|
+
componentName: string;
|
|
21
|
+
element: HTMLElement;
|
|
22
|
+
exportName: string;
|
|
23
|
+
moduleExports: unknown;
|
|
24
|
+
moduleId: string;
|
|
25
|
+
props: Record<string, unknown>;
|
|
26
|
+
runtime: TRuntime | undefined;
|
|
27
|
+
slotHtml: string | undefined;
|
|
28
|
+
}
|
|
29
|
+
type SvelteHtmlHostClientRenderer<TRuntime = undefined> = (context: SvelteHtmlHostClientContext<TRuntime>) => void | (() => void) | PromiseLike<void | (() => void)>;
|
|
30
|
+
type SvelteHtmlHostClientRuntimeLoader<TRuntime = undefined> = () => TRuntime | Promise<TRuntime>;
|
|
31
|
+
type SvelteHtmlHostModuleIdResolver = (element: HTMLElement, context: {
|
|
32
|
+
componentName: string;
|
|
33
|
+
props: Record<string, unknown>;
|
|
34
|
+
}) => string | undefined;
|
|
35
|
+
type SvelteHtmlHostExportNameResolver = (element: HTMLElement, context: {
|
|
36
|
+
componentName: string;
|
|
37
|
+
moduleId: string;
|
|
38
|
+
props: Record<string, unknown>;
|
|
39
|
+
}) => string | undefined;
|
|
40
|
+
interface SvelteHtmlHostClientBaseInput<TRuntime = undefined> {
|
|
41
|
+
modules: SvelteHtmlHostClientModules;
|
|
42
|
+
loadRuntime?: SvelteHtmlHostClientRuntimeLoader<TRuntime>;
|
|
43
|
+
resolveModuleId?: SvelteHtmlHostModuleIdResolver;
|
|
44
|
+
resolveExportName?: SvelteHtmlHostExportNameResolver;
|
|
45
|
+
onError?: (error: SvelteHtmlHostClientError) => void;
|
|
46
|
+
}
|
|
47
|
+
interface CreateSvelteHtmlHostLazyHydrateRenderInput<TRuntime = undefined> extends SvelteHtmlHostClientBaseInput<TRuntime> {
|
|
48
|
+
render: SvelteHtmlHostClientRenderer<TRuntime>;
|
|
49
|
+
mount?: never;
|
|
50
|
+
}
|
|
51
|
+
interface CreateSvelteHtmlHostLazyHydrateMountInput extends SvelteHtmlHostClientBaseInput<SvelteHtmlHostDomRuntime> {
|
|
52
|
+
mount: SvelteHtmlHostDomRendererInput;
|
|
53
|
+
render?: never;
|
|
54
|
+
}
|
|
55
|
+
type CreateSvelteHtmlHostLazyHydrateInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateRenderInput<TRuntime> | CreateSvelteHtmlHostLazyHydrateMountInput;
|
|
56
|
+
type SvelteHtmlHostDomMode = "render" | "hydrate";
|
|
57
|
+
interface SvelteHtmlHostDomRendererInput {
|
|
58
|
+
mode: SvelteHtmlHostDomMode;
|
|
59
|
+
}
|
|
60
|
+
interface SvelteHtmlHostDomRuntime {
|
|
61
|
+
mount: (component: SvelteHtmlHostClientComponentValue, options: {
|
|
62
|
+
target: HTMLElement;
|
|
63
|
+
props?: Record<string, unknown>;
|
|
64
|
+
}) => unknown;
|
|
65
|
+
hydrate: (component: SvelteHtmlHostClientComponentValue, options: {
|
|
66
|
+
target: HTMLElement;
|
|
67
|
+
props?: Record<string, unknown>;
|
|
68
|
+
}) => unknown;
|
|
69
|
+
unmount: (instance: unknown) => void | Promise<void>;
|
|
70
|
+
createRawSnippet: (factory: () => {
|
|
71
|
+
render: () => string;
|
|
72
|
+
setup?: (element: Element) => void;
|
|
73
|
+
}) => unknown;
|
|
74
|
+
}
|
|
75
|
+
type SvelteHtmlHostInitIslands<TController = unknown> = (hydrate: (element: HTMLElement, props: Record<string, unknown>) => void | (() => void), options?: InitIslandsOptions) => TController;
|
|
76
|
+
type InitSvelteHtmlHostInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateInput<TRuntime> & {
|
|
77
|
+
initIslands: SvelteHtmlHostInitIslands;
|
|
78
|
+
options?: InitIslandsOptions;
|
|
79
|
+
};
|
|
80
|
+
//#endregion
|
|
81
|
+
//#region src/html-host-dom-renderer.d.ts
|
|
82
|
+
type SvelteHtmlHostDomRenderer = SvelteHtmlHostClientRenderer<SvelteHtmlHostDomRuntime>;
|
|
83
|
+
declare function loadSvelteHtmlHostDomRuntime(): Promise<SvelteHtmlHostDomRuntime>;
|
|
84
|
+
declare function createSvelteHtmlHostDomRenderer(input: SvelteHtmlHostDomRendererInput): SvelteHtmlHostDomRenderer;
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/html-host-client.d.ts
|
|
87
|
+
declare function initSvelteHtmlHost<TRuntime = undefined>(input: InitSvelteHtmlHostInput<TRuntime>): ReturnType<InitSvelteHtmlHostInput<TRuntime>["initIslands"]>;
|
|
88
|
+
declare function createSvelteHtmlHostLazyHydrate<TRuntime = undefined>(input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>): (element: HTMLElement, props: Record<string, unknown>) => () => void;
|
|
89
|
+
declare function readSvelteHtmlHostSlot(element: Pick<HTMLElement, "dataset" | "innerHTML">): string | undefined;
|
|
90
|
+
//#endregion
|
|
91
|
+
export { initSvelteHtmlHost, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
|
|
92
|
+
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,293 @@
|
|
|
1
|
+
//#region src/html-host-dom-renderer.ts
|
|
2
|
+
const DOM_RENDERER_MODE = Symbol("svelte-html-host-dom-renderer-mode");
|
|
3
|
+
async function loadSvelteHtmlHostDomRuntime() {
|
|
4
|
+
const { createRawSnippet, hydrate, mount, unmount } = await import("svelte");
|
|
5
|
+
return {
|
|
6
|
+
createRawSnippet,
|
|
7
|
+
hydrate,
|
|
8
|
+
mount,
|
|
9
|
+
unmount
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function createSvelteHtmlHostDomRenderer(input) {
|
|
13
|
+
const renderer = ((context) => {
|
|
14
|
+
const runtime = context.runtime;
|
|
15
|
+
if (!runtime) throw new Error("Svelte HTML host DOM renderer requires a Svelte runtime.");
|
|
16
|
+
const componentProps = componentPropsWithSlot(runtime, context.props, context.slotHtml);
|
|
17
|
+
const instance = input.mode === "hydrate" ? runtime.hydrate(context.component, {
|
|
18
|
+
target: context.element,
|
|
19
|
+
props: componentProps
|
|
20
|
+
}) : runtime.mount(context.component, {
|
|
21
|
+
target: context.element,
|
|
22
|
+
props: componentProps
|
|
23
|
+
});
|
|
24
|
+
return () => {
|
|
25
|
+
runtime.unmount(instance);
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(renderer, DOM_RENDERER_MODE, { value: input.mode });
|
|
29
|
+
return renderer;
|
|
30
|
+
}
|
|
31
|
+
function svelteHtmlHostDomRendererMode(renderer) {
|
|
32
|
+
return renderer[DOM_RENDERER_MODE];
|
|
33
|
+
}
|
|
34
|
+
function componentPropsWithSlot(runtime, props, slotHtml) {
|
|
35
|
+
if (!slotHtml) return props;
|
|
36
|
+
return {
|
|
37
|
+
...props,
|
|
38
|
+
children: runtime.createRawSnippet(() => ({
|
|
39
|
+
render: () => slotHtml,
|
|
40
|
+
setup: (element) => {
|
|
41
|
+
element.innerHTML = slotHtml;
|
|
42
|
+
}
|
|
43
|
+
}))
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//#endregion
|
|
47
|
+
//#region src/html-host-client-errors.ts
|
|
48
|
+
function reportError(input, error) {
|
|
49
|
+
error.element.classList?.add("ox-island-error");
|
|
50
|
+
error.element.dataset.oxError = error.message;
|
|
51
|
+
input.onError?.(error);
|
|
52
|
+
if (typeof CustomEvent === "function" && typeof error.element.dispatchEvent === "function") error.element.dispatchEvent(new CustomEvent("ox-content-svelte-html-host:error", { detail: error }));
|
|
53
|
+
}
|
|
54
|
+
function clientError(code, element, props, context = {}) {
|
|
55
|
+
return {
|
|
56
|
+
code,
|
|
57
|
+
element,
|
|
58
|
+
props,
|
|
59
|
+
...context,
|
|
60
|
+
message: clientErrorMessage(code, context)
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
function clientErrorMessage(code, context) {
|
|
64
|
+
const component = context.componentName ? `Svelte island "${context.componentName}"` : "Svelte island";
|
|
65
|
+
const reason = causeMessage(context.cause);
|
|
66
|
+
switch (code) {
|
|
67
|
+
case "missing-island-name": return "Svelte island element is missing data-ox-island.";
|
|
68
|
+
case "missing-module-id": return `${component} is missing data-ox-module.`;
|
|
69
|
+
case "unknown-module": return `${component} references unknown module "${context.moduleId ?? ""}".`;
|
|
70
|
+
case "module-load-failed": return `${component} module "${context.moduleId ?? ""}" failed to load: ${reason}`;
|
|
71
|
+
case "runtime-load-failed": return `Svelte runtime failed to load: ${reason}`;
|
|
72
|
+
case "missing-export": return `${component} module "${context.moduleId ?? ""}" is missing export "${context.exportName ?? "default"}".`;
|
|
73
|
+
case "render-failed": return `${component} failed to render: ${reason}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function causeMessage(cause) {
|
|
77
|
+
if (cause == null) return "";
|
|
78
|
+
if (cause instanceof Error) return cause.message;
|
|
79
|
+
if (typeof cause === "string") return cause;
|
|
80
|
+
if (typeof cause === "number" || typeof cause === "boolean") return cause.toString();
|
|
81
|
+
try {
|
|
82
|
+
return JSON.stringify(cause);
|
|
83
|
+
} catch {
|
|
84
|
+
return Object.prototype.toString.call(cause);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/html-host-client.ts
|
|
89
|
+
const ISLAND_JSON_SCRIPT = /^\s*<script type="application\/json">[\s\S]*?<\/script>/;
|
|
90
|
+
function initSvelteHtmlHost(input) {
|
|
91
|
+
return input.initIslands(createSvelteHtmlHostLazyHydrate(input), input.options);
|
|
92
|
+
}
|
|
93
|
+
function createSvelteHtmlHostLazyHydrate(input) {
|
|
94
|
+
const render = resolveRenderer(input);
|
|
95
|
+
const load = resolveRuntimeLoader(input, render);
|
|
96
|
+
const moduleCache = /* @__PURE__ */ new Map();
|
|
97
|
+
let runtimeCache;
|
|
98
|
+
return (element, props) => {
|
|
99
|
+
const componentName = element.dataset.oxIsland;
|
|
100
|
+
if (!componentName) {
|
|
101
|
+
reportError(input, clientError("missing-island-name", element, props));
|
|
102
|
+
return noop;
|
|
103
|
+
}
|
|
104
|
+
const moduleId = input.resolveModuleId?.(element, {
|
|
105
|
+
componentName,
|
|
106
|
+
props
|
|
107
|
+
}) ?? element.dataset.oxModule;
|
|
108
|
+
if (!moduleId) {
|
|
109
|
+
reportError(input, clientError("missing-module-id", element, props, { componentName }));
|
|
110
|
+
return noop;
|
|
111
|
+
}
|
|
112
|
+
if (!moduleLoader(input.modules, moduleId)) {
|
|
113
|
+
reportError(input, clientError("unknown-module", element, props, {
|
|
114
|
+
componentName,
|
|
115
|
+
moduleId
|
|
116
|
+
}));
|
|
117
|
+
return noop;
|
|
118
|
+
}
|
|
119
|
+
const exportName = input.resolveExportName?.(element, {
|
|
120
|
+
componentName,
|
|
121
|
+
moduleId,
|
|
122
|
+
props
|
|
123
|
+
}) ?? element.dataset.oxExport ?? "default";
|
|
124
|
+
const slotHtml = readSvelteHtmlHostSlot(element);
|
|
125
|
+
let disposed = false;
|
|
126
|
+
let disposeMounted;
|
|
127
|
+
const dispose = () => {
|
|
128
|
+
if (disposed) return;
|
|
129
|
+
disposed = true;
|
|
130
|
+
disposeMounted?.();
|
|
131
|
+
disposeMounted = void 0;
|
|
132
|
+
};
|
|
133
|
+
(async () => {
|
|
134
|
+
let moduleExports;
|
|
135
|
+
let runtime;
|
|
136
|
+
try {
|
|
137
|
+
moduleExports = await loadClientModule(input.modules, moduleId, moduleCache);
|
|
138
|
+
} catch (cause) {
|
|
139
|
+
if (!disposed) reportError(input, clientError("module-load-failed", element, props, {
|
|
140
|
+
componentName,
|
|
141
|
+
moduleId,
|
|
142
|
+
exportName,
|
|
143
|
+
cause
|
|
144
|
+
}));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (disposed) return;
|
|
148
|
+
try {
|
|
149
|
+
runtime = await loadRuntime(load, () => runtimeCache, (pending) => {
|
|
150
|
+
runtimeCache = pending;
|
|
151
|
+
});
|
|
152
|
+
} catch (cause) {
|
|
153
|
+
if (!disposed) reportError(input, clientError("runtime-load-failed", element, props, {
|
|
154
|
+
componentName,
|
|
155
|
+
moduleId,
|
|
156
|
+
exportName,
|
|
157
|
+
cause
|
|
158
|
+
}));
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (disposed) return;
|
|
162
|
+
const component = exportedValue(moduleExports, exportName);
|
|
163
|
+
if (component == null) {
|
|
164
|
+
reportError(input, clientError("missing-export", element, props, {
|
|
165
|
+
componentName,
|
|
166
|
+
moduleId,
|
|
167
|
+
exportName,
|
|
168
|
+
cause: /* @__PURE__ */ new Error(`Export "${exportName}" was not found.`)
|
|
169
|
+
}));
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
if (!preservesElementContents(input, render)) element.innerHTML = "";
|
|
173
|
+
try {
|
|
174
|
+
const cleanup = await render({
|
|
175
|
+
component,
|
|
176
|
+
componentName,
|
|
177
|
+
element,
|
|
178
|
+
exportName,
|
|
179
|
+
moduleExports,
|
|
180
|
+
moduleId,
|
|
181
|
+
props,
|
|
182
|
+
runtime,
|
|
183
|
+
slotHtml
|
|
184
|
+
});
|
|
185
|
+
disposeMounted = cleanup ? once(cleanup) : void 0;
|
|
186
|
+
if (disposed) {
|
|
187
|
+
disposeMounted?.();
|
|
188
|
+
disposeMounted = void 0;
|
|
189
|
+
}
|
|
190
|
+
} catch (cause) {
|
|
191
|
+
if (!disposed) reportError(input, clientError("render-failed", element, props, {
|
|
192
|
+
componentName,
|
|
193
|
+
moduleId,
|
|
194
|
+
exportName,
|
|
195
|
+
cause
|
|
196
|
+
}));
|
|
197
|
+
}
|
|
198
|
+
})();
|
|
199
|
+
return dispose;
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
function readSvelteHtmlHostSlot(element) {
|
|
203
|
+
const fromAttr = element.dataset.oxContent;
|
|
204
|
+
if (fromAttr) return fromAttr;
|
|
205
|
+
if (element.dataset.oxSsr === "true") return void 0;
|
|
206
|
+
return element.innerHTML.replace(ISLAND_JSON_SCRIPT, "") || void 0;
|
|
207
|
+
}
|
|
208
|
+
async function loadClientModule(modules, moduleId, cache) {
|
|
209
|
+
const cached = cache.get(moduleId);
|
|
210
|
+
if (cached) return cached;
|
|
211
|
+
const loader = moduleLoader(modules, moduleId);
|
|
212
|
+
if (!loader) throw new Error(`Unknown module "${moduleId}".`);
|
|
213
|
+
const pending = Promise.resolve().then(loader).catch((cause) => {
|
|
214
|
+
cache.delete(moduleId);
|
|
215
|
+
throw cause;
|
|
216
|
+
});
|
|
217
|
+
cache.set(moduleId, pending);
|
|
218
|
+
return pending;
|
|
219
|
+
}
|
|
220
|
+
async function loadRuntime(load, getCached, setCached) {
|
|
221
|
+
if (!load) return void 0;
|
|
222
|
+
const cached = getCached();
|
|
223
|
+
if (cached) return cached;
|
|
224
|
+
const pending = Promise.resolve().then(load).catch((cause) => {
|
|
225
|
+
setCached(void 0);
|
|
226
|
+
throw cause;
|
|
227
|
+
});
|
|
228
|
+
setCached(pending);
|
|
229
|
+
return pending;
|
|
230
|
+
}
|
|
231
|
+
function resolveRenderer(input) {
|
|
232
|
+
if (input.render) return input.render;
|
|
233
|
+
if (input.mount) return createSvelteHtmlHostDomRenderer(input.mount);
|
|
234
|
+
throw new Error("initSvelteHtmlHost requires either render or mount.");
|
|
235
|
+
}
|
|
236
|
+
function resolveRuntimeLoader(input, render) {
|
|
237
|
+
if (input.loadRuntime) return input.loadRuntime;
|
|
238
|
+
if (input.mount || svelteHtmlHostDomRendererMode(render)) return loadSvelteHtmlHostDomRuntime;
|
|
239
|
+
}
|
|
240
|
+
function preservesElementContents(input, render) {
|
|
241
|
+
return (input.mount?.mode ?? svelteHtmlHostDomRendererMode(render)) === "hydrate";
|
|
242
|
+
}
|
|
243
|
+
function moduleLoader(modules, moduleId) {
|
|
244
|
+
return isReadonlyMap(modules) ? modules.get(moduleId) : modules[moduleId];
|
|
245
|
+
}
|
|
246
|
+
function isReadonlyMap(value) {
|
|
247
|
+
return typeof value.get === "function";
|
|
248
|
+
}
|
|
249
|
+
function exportedValue(moduleExports, exportName) {
|
|
250
|
+
if (exportName === "default" && typeof moduleExports === "function") return moduleExports;
|
|
251
|
+
if (!moduleExports || typeof moduleExports !== "object") return;
|
|
252
|
+
return moduleExports[exportName];
|
|
253
|
+
}
|
|
254
|
+
function once(cleanup) {
|
|
255
|
+
let called = false;
|
|
256
|
+
return () => {
|
|
257
|
+
if (called) return;
|
|
258
|
+
called = true;
|
|
259
|
+
cleanup();
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
function noop() {}
|
|
263
|
+
//#endregion
|
|
264
|
+
Object.defineProperty(exports, "createSvelteHtmlHostDomRenderer", {
|
|
265
|
+
enumerable: true,
|
|
266
|
+
get: function() {
|
|
267
|
+
return createSvelteHtmlHostDomRenderer;
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
Object.defineProperty(exports, "createSvelteHtmlHostLazyHydrate", {
|
|
271
|
+
enumerable: true,
|
|
272
|
+
get: function() {
|
|
273
|
+
return createSvelteHtmlHostLazyHydrate;
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
Object.defineProperty(exports, "initSvelteHtmlHost", {
|
|
277
|
+
enumerable: true,
|
|
278
|
+
get: function() {
|
|
279
|
+
return initSvelteHtmlHost;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
Object.defineProperty(exports, "loadSvelteHtmlHostDomRuntime", {
|
|
283
|
+
enumerable: true,
|
|
284
|
+
get: function() {
|
|
285
|
+
return loadSvelteHtmlHostDomRuntime;
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
Object.defineProperty(exports, "readSvelteHtmlHostSlot", {
|
|
289
|
+
enumerable: true,
|
|
290
|
+
get: function() {
|
|
291
|
+
return readSvelteHtmlHostSlot;
|
|
292
|
+
}
|
|
293
|
+
});
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as SvelteHtmlHostModuleIdResolver, S as SvelteHtmlHostInitIslands, _ 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, 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 SvelteHtmlHostInitIslands, type SvelteHtmlHostModuleIdResolver, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, initSvelteHtmlHost, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { C as SvelteHtmlHostModuleIdResolver, S as SvelteHtmlHostInitIslands, _ 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, 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 SvelteHtmlHostInitIslands, type SvelteHtmlHostModuleIdResolver, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, initSvelteHtmlHost, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
|