@ox-content/vite-plugin-svelte 3.1.3 → 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.
@@ -1,42 +1,18 @@
1
- import { InitIslandsOptions } from "@ox-content/islands";
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";
2
3
  //#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
- }
4
+ type SvelteHtmlHostClientDiagnosticCode = HtmlHostClientDiagnosticCode;
5
+ type SvelteHtmlHostClientError = HtmlHostClientError;
14
6
  type SvelteHtmlHostClientComponentValue = unknown;
15
7
  type SvelteHtmlHostClientModuleValue = SvelteHtmlHostClientComponentValue;
16
- type SvelteHtmlHostClientModuleLoader<TModule = SvelteHtmlHostClientModuleValue> = () => TModule | PromiseLike<TModule>;
8
+ type SvelteHtmlHostClientModuleLoader<TModule = SvelteHtmlHostClientModuleValue> = HtmlHostClientModuleLoader<TModule>;
17
9
  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;
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;
40
16
  interface SvelteHtmlHostClientBaseInput<TRuntime = undefined> {
41
17
  modules: SvelteHtmlHostClientModules;
42
18
  loadRuntime?: SvelteHtmlHostClientRuntimeLoader<TRuntime>;
@@ -72,7 +48,7 @@ interface SvelteHtmlHostDomRuntime {
72
48
  setup?: (element: Element) => void;
73
49
  }) => unknown;
74
50
  }
75
- type SvelteHtmlHostInitIslands<TController = unknown> = (hydrate: (element: HTMLElement, props: Record<string, unknown>) => void | (() => void), options?: InitIslandsOptions) => TController;
51
+ type SvelteHtmlHostInitIslands<TController = unknown> = (hydrate: HydrateFunction, options?: InitIslandsOptions) => TController;
76
52
  type InitSvelteHtmlHostInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateInput<TRuntime> & {
77
53
  initIslands: SvelteHtmlHostInitIslands;
78
54
  options?: InitIslandsOptions;
@@ -85,7 +61,7 @@ declare function createSvelteHtmlHostDomRenderer(input: SvelteHtmlHostDomRendere
85
61
  //#endregion
86
62
  //#region src/html-host-client.d.ts
87
63
  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;
64
+ declare function createSvelteHtmlHostLazyHydrate<TRuntime = undefined>(input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>): HtmlHostLazyHydrateFunction;
89
65
  declare function readSvelteHtmlHostSlot(element: Pick<HTMLElement, "dataset" | "innerHTML">): string | undefined;
90
66
  //#endregion
91
67
  export { initSvelteHtmlHost, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
@@ -1,42 +1,18 @@
1
- import { InitIslandsOptions } from "@ox-content/islands";
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";
2
3
  //#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
- }
4
+ type SvelteHtmlHostClientDiagnosticCode = HtmlHostClientDiagnosticCode;
5
+ type SvelteHtmlHostClientError = HtmlHostClientError;
14
6
  type SvelteHtmlHostClientComponentValue = unknown;
15
7
  type SvelteHtmlHostClientModuleValue = SvelteHtmlHostClientComponentValue;
16
- type SvelteHtmlHostClientModuleLoader<TModule = SvelteHtmlHostClientModuleValue> = () => TModule | PromiseLike<TModule>;
8
+ type SvelteHtmlHostClientModuleLoader<TModule = SvelteHtmlHostClientModuleValue> = HtmlHostClientModuleLoader<TModule>;
17
9
  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;
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;
40
16
  interface SvelteHtmlHostClientBaseInput<TRuntime = undefined> {
41
17
  modules: SvelteHtmlHostClientModules;
42
18
  loadRuntime?: SvelteHtmlHostClientRuntimeLoader<TRuntime>;
@@ -72,7 +48,7 @@ interface SvelteHtmlHostDomRuntime {
72
48
  setup?: (element: Element) => void;
73
49
  }) => unknown;
74
50
  }
75
- type SvelteHtmlHostInitIslands<TController = unknown> = (hydrate: (element: HTMLElement, props: Record<string, unknown>) => void | (() => void), options?: InitIslandsOptions) => TController;
51
+ type SvelteHtmlHostInitIslands<TController = unknown> = (hydrate: HydrateFunction, options?: InitIslandsOptions) => TController;
76
52
  type InitSvelteHtmlHostInput<TRuntime = undefined> = CreateSvelteHtmlHostLazyHydrateInput<TRuntime> & {
77
53
  initIslands: SvelteHtmlHostInitIslands;
78
54
  options?: InitIslandsOptions;
@@ -85,7 +61,7 @@ declare function createSvelteHtmlHostDomRenderer(input: SvelteHtmlHostDomRendere
85
61
  //#endregion
86
62
  //#region src/html-host-client.d.ts
87
63
  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;
64
+ declare function createSvelteHtmlHostLazyHydrate<TRuntime = undefined>(input: CreateSvelteHtmlHostLazyHydrateInput<TRuntime>): HtmlHostLazyHydrateFunction;
89
65
  declare function readSvelteHtmlHostSlot(element: Pick<HTMLElement, "dataset" | "innerHTML">): string | undefined;
90
66
  //#endregion
91
67
  export { initSvelteHtmlHost, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostLazyHydrate, loadSvelteHtmlHostDomRuntime, readSvelteHtmlHostSlot };
@@ -1,3 +1,4 @@
1
+ let _ox_content_islands_html_host = require("@ox-content/islands/html-host");
1
2
  //#region src/html-host-dom-renderer.ts
2
3
  const DOM_RENDERER_MODE = Symbol("svelte-html-host-dom-renderer-mode");
3
4
  async function loadSvelteHtmlHostDomRuntime() {
@@ -44,189 +45,26 @@ function componentPropsWithSlot(runtime, props, slotHtml) {
44
45
  };
45
46
  }
46
47
  //#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
48
  //#region src/html-host-client.ts
89
- const ISLAND_JSON_SCRIPT = /^\s*<script type="application\/json">[\s\S]*?<\/script>/;
90
49
  function initSvelteHtmlHost(input) {
91
50
  return input.initIslands(createSvelteHtmlHostLazyHydrate(input), input.options);
92
51
  }
93
52
  function createSvelteHtmlHostLazyHydrate(input) {
94
53
  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;
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"
216
64
  });
217
- cache.set(moduleId, pending);
218
- return pending;
219
65
  }
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;
66
+ function readSvelteHtmlHostSlot(element) {
67
+ return (0, _ox_content_islands_html_host.readHtmlHostSlot)(element);
230
68
  }
231
69
  function resolveRenderer(input) {
232
70
  if (input.render) return input.render;
@@ -240,26 +78,6 @@ function resolveRuntimeLoader(input, render) {
240
78
  function preservesElementContents(input, render) {
241
79
  return (input.mount?.mode ?? svelteHtmlHostDomRendererMode(render)) === "hydrate";
242
80
  }
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
81
  //#endregion
264
82
  Object.defineProperty(exports, "createSvelteHtmlHostDomRenderer", {
265
83
  enumerable: true,
@@ -1,2 +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 };
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 };
@@ -1,2 +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 };
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 };
@@ -1,3 +1,4 @@
1
+ import { createHtmlHostLazyHydrate, readHtmlHostSlot } from "@ox-content/islands/html-host";
1
2
  //#region src/html-host-dom-renderer.ts
2
3
  const DOM_RENDERER_MODE = Symbol("svelte-html-host-dom-renderer-mode");
3
4
  async function loadSvelteHtmlHostDomRuntime() {
@@ -44,189 +45,26 @@ function componentPropsWithSlot(runtime, props, slotHtml) {
44
45
  };
45
46
  }
46
47
  //#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
48
  //#region src/html-host-client.ts
89
- const ISLAND_JSON_SCRIPT = /^\s*<script type="application\/json">[\s\S]*?<\/script>/;
90
49
  function initSvelteHtmlHost(input) {
91
50
  return input.initIslands(createSvelteHtmlHostLazyHydrate(input), input.options);
92
51
  }
93
52
  function createSvelteHtmlHostLazyHydrate(input) {
94
53
  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;
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"
216
64
  });
217
- cache.set(moduleId, pending);
218
- return pending;
219
65
  }
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;
66
+ function readSvelteHtmlHostSlot(element) {
67
+ return readHtmlHostSlot(element);
230
68
  }
231
69
  function resolveRenderer(input) {
232
70
  if (input.render) return input.render;
@@ -240,26 +78,6 @@ function resolveRuntimeLoader(input, render) {
240
78
  function preservesElementContents(input, render) {
241
79
  return (input.mount?.mode ?? svelteHtmlHostDomRendererMode(render)) === "hydrate";
242
80
  }
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
81
  //#endregion
264
82
  export { loadSvelteHtmlHostDomRuntime as a, createSvelteHtmlHostDomRenderer as i, initSvelteHtmlHost as n, readSvelteHtmlHostSlot as r, createSvelteHtmlHostLazyHydrate as t };
265
83