@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 +1 @@
1
- {"version":3,"file":"html-host-client2.mjs","names":[],"sources":["../src/html-host-dom-renderer.ts","../src/html-host-client-errors.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 type {\n CreateSvelteHtmlHostLazyHydrateInput,\n SvelteHtmlHostClientDiagnosticCode,\n SvelteHtmlHostClientError,\n} from \"./html-host-client-types\";\n\nexport function reportError(\n input: Pick<CreateSvelteHtmlHostLazyHydrateInput, \"onError\">,\n error: SvelteHtmlHostClientError,\n): void {\n error.element.classList?.add(\"ox-island-error\");\n error.element.dataset.oxError = error.message;\n input.onError?.(error);\n\n if (typeof CustomEvent === \"function\" && typeof error.element.dispatchEvent === \"function\") {\n error.element.dispatchEvent(\n new CustomEvent(\"ox-content-svelte-html-host:error\", { detail: error }),\n );\n }\n}\n\nexport function clientError(\n code: SvelteHtmlHostClientDiagnosticCode,\n element: HTMLElement,\n props: Record<string, unknown>,\n context: {\n componentName?: string;\n moduleId?: string;\n exportName?: string;\n cause?: unknown;\n } = {},\n): SvelteHtmlHostClientError {\n return {\n code,\n element,\n props,\n ...context,\n message: clientErrorMessage(code, context),\n };\n}\n\nfunction clientErrorMessage(\n code: SvelteHtmlHostClientDiagnosticCode,\n context: { componentName?: string; moduleId?: string; exportName?: string; cause?: unknown },\n): string {\n const component = context.componentName\n ? `Svelte island \"${context.componentName}\"`\n : \"Svelte island\";\n const reason = causeMessage(context.cause);\n switch (code) {\n case \"missing-island-name\":\n return \"Svelte island element is missing data-ox-island.\";\n case \"missing-module-id\":\n return `${component} is missing data-ox-module.`;\n case \"unknown-module\":\n return `${component} references unknown module \"${context.moduleId ?? \"\"}\".`;\n case \"module-load-failed\":\n return `${component} module \"${context.moduleId ?? \"\"}\" failed to load: ${reason}`;\n case \"runtime-load-failed\":\n return `Svelte runtime failed to load: ${reason}`;\n case \"missing-export\":\n return `${component} module \"${context.moduleId ?? \"\"}\" is missing export \"${context.exportName ?? \"default\"}\".`;\n case \"render-failed\":\n return `${component} failed to render: ${reason}`;\n }\n}\n\nfunction causeMessage(cause: unknown): string {\n if (cause == null) return \"\";\n if (cause instanceof Error) return cause.message;\n if (typeof cause === \"string\") return cause;\n if (typeof cause === \"number\" || typeof cause === \"boolean\") return cause.toString();\n try {\n return JSON.stringify(cause);\n } catch {\n return Object.prototype.toString.call(cause);\n }\n}\n","import type {\n CreateSvelteHtmlHostLazyHydrateInput,\n InitSvelteHtmlHostInput,\n SvelteHtmlHostClientModuleLoader,\n SvelteHtmlHostClientModules,\n SvelteHtmlHostClientRenderer,\n SvelteHtmlHostClientRuntimeLoader,\n} from \"./html-host-client-types\";\nimport {\n createSvelteHtmlHostDomRenderer,\n loadSvelteHtmlHostDomRuntime,\n svelteHtmlHostDomRendererMode,\n} from \"./html-host-dom-renderer\";\nimport { clientError, reportError } from \"./html-host-client-errors\";\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 SvelteHtmlHostInitIslands,\n SvelteHtmlHostModuleIdResolver,\n} from \"./html-host-client-types\";\nexport {\n createSvelteHtmlHostDomRenderer,\n loadSvelteHtmlHostDomRuntime,\n type SvelteHtmlHostDomRenderer,\n} from \"./html-host-dom-renderer\";\n\nconst ISLAND_JSON_SCRIPT = /^\\s*<script type=\"application\\/json\">[\\s\\S]*?<\\/script>/;\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): (element: HTMLElement, props: Record<string, unknown>) => () => void {\n const render = resolveRenderer(input);\n const load = resolveRuntimeLoader(input, render);\n const moduleCache = new Map<string, Promise<unknown>>();\n let runtimeCache: Promise<TRuntime> | undefined;\n\n return (element, props) => {\n const componentName = element.dataset.oxIsland;\n if (!componentName) {\n reportError(input, clientError(\"missing-island-name\", element, props));\n return noop;\n }\n\n const moduleId =\n input.resolveModuleId?.(element, { componentName, props }) ?? element.dataset.oxModule;\n if (!moduleId) {\n reportError(input, clientError(\"missing-module-id\", element, props, { componentName }));\n return noop;\n }\n if (!moduleLoader(input.modules, moduleId)) {\n reportError(\n input,\n clientError(\"unknown-module\", element, props, {\n componentName,\n moduleId,\n }),\n );\n return noop;\n }\n\n const exportName =\n input.resolveExportName?.(element, { componentName, moduleId, props }) ??\n element.dataset.oxExport ??\n \"default\";\n const slotHtml = readSvelteHtmlHostSlot(element);\n let disposed = false;\n let disposeMounted: (() => void) | undefined;\n\n const dispose = () => {\n if (disposed) return;\n disposed = true;\n disposeMounted?.();\n disposeMounted = undefined;\n };\n\n void (async () => {\n let moduleExports: unknown;\n let runtime: TRuntime | undefined;\n try {\n moduleExports = await loadClientModule(input.modules, moduleId, moduleCache);\n } catch (cause) {\n if (!disposed) {\n reportError(\n input,\n clientError(\"module-load-failed\", element, props, {\n componentName,\n moduleId,\n exportName,\n cause,\n }),\n );\n }\n return;\n }\n\n if (disposed) return;\n\n try {\n runtime = await loadRuntime(\n load,\n () => runtimeCache,\n (pending) => {\n runtimeCache = pending;\n },\n );\n } catch (cause) {\n if (!disposed) {\n reportError(\n input,\n clientError(\"runtime-load-failed\", element, props, {\n componentName,\n moduleId,\n exportName,\n cause,\n }),\n );\n }\n return;\n }\n\n if (disposed) return;\n\n const component = exportedValue(moduleExports, exportName);\n if (component == null) {\n reportError(\n input,\n clientError(\"missing-export\", element, props, {\n componentName,\n moduleId,\n exportName,\n cause: new Error(`Export \"${exportName}\" was not found.`),\n }),\n );\n return;\n }\n\n if (!preservesElementContents(input, render)) {\n element.innerHTML = \"\";\n }\n try {\n const cleanup = await render({\n component,\n componentName,\n element,\n exportName,\n moduleExports,\n moduleId,\n props,\n runtime,\n slotHtml,\n });\n disposeMounted = cleanup ? once(cleanup) : undefined;\n if (disposed) {\n disposeMounted?.();\n disposeMounted = undefined;\n }\n } catch (cause) {\n if (!disposed) {\n reportError(\n input,\n clientError(\"render-failed\", element, props, {\n componentName,\n moduleId,\n exportName,\n cause,\n }),\n );\n }\n }\n })();\n\n return dispose;\n };\n}\n\nexport function readSvelteHtmlHostSlot(\n element: Pick<HTMLElement, \"dataset\" | \"innerHTML\">,\n): string | undefined {\n const fromAttr = element.dataset.oxContent;\n if (fromAttr) return fromAttr;\n if (element.dataset.oxSsr === \"true\") return undefined;\n\n const slotHtml = element.innerHTML.replace(ISLAND_JSON_SCRIPT, \"\");\n return slotHtml || undefined;\n}\n\nasync function loadClientModule(\n modules: SvelteHtmlHostClientModules,\n moduleId: string,\n cache: Map<string, Promise<unknown>>,\n): Promise<unknown> {\n const cached = cache.get(moduleId);\n if (cached) return cached;\n\n const loader = moduleLoader(modules, moduleId);\n if (!loader) {\n throw new Error(`Unknown module \"${moduleId}\".`);\n }\n\n const pending = Promise.resolve()\n .then(loader)\n .catch((cause: unknown) => {\n cache.delete(moduleId);\n throw cause;\n });\n cache.set(moduleId, pending);\n return pending;\n}\n\nasync function loadRuntime<TRuntime>(\n load: SvelteHtmlHostClientRuntimeLoader<TRuntime> | undefined,\n getCached: () => Promise<TRuntime> | undefined,\n setCached: (pending: Promise<TRuntime> | undefined) => void,\n): Promise<TRuntime | undefined> {\n if (!load) return undefined;\n\n const cached = getCached();\n if (cached) return cached;\n\n const pending = Promise.resolve()\n .then(load)\n .catch((cause: unknown) => {\n setCached(undefined);\n throw cause;\n });\n setCached(pending);\n return pending;\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\nfunction moduleLoader(\n modules: SvelteHtmlHostClientModules,\n moduleId: string,\n): SvelteHtmlHostClientModuleLoader | undefined {\n return isReadonlyMap(modules) ? modules.get(moduleId) : modules[moduleId];\n}\n\nfunction isReadonlyMap(\n value: SvelteHtmlHostClientModules,\n): value is ReadonlyMap<string, SvelteHtmlHostClientModuleLoader> {\n return typeof (value as ReadonlyMap<string, SvelteHtmlHostClientModuleLoader>).get === \"function\";\n}\n\nfunction exportedValue(moduleExports: unknown, exportName: string): unknown {\n if (exportName === \"default\" && typeof moduleExports === \"function\") {\n return moduleExports;\n }\n if (!moduleExports || typeof moduleExports !== \"object\") {\n return undefined;\n }\n return (moduleExports as Record<string, unknown>)[exportName];\n}\n\nfunction once(cleanup: () => void): () => void {\n let called = false;\n return () => {\n if (called) return;\n called = true;\n cleanup();\n };\n}\n\nfunction noop(): void {}\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,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AAO,kBAAkB,UAC7C;CAEF,OAAQ,cAA0C;AACpD;AAEA,SAAS,KAAK,SAAiC;CAC7C,IAAI,SAAS;CACb,aAAa;EACX,IAAI,QAAQ;EACZ,SAAS;EACT,QAAQ;CACV;AACF;AAEA,SAAS,OAAa,CAAC"}
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,mBAC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