@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/index.cjs CHANGED
@@ -21,12 +21,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
21
21
  enumerable: true
22
22
  }) : target, mod));
23
23
  //#endregion
24
+ const require_html_host_client = require("./html-host-client2.cjs");
25
+ let _ox_content_vite_plugin = require("@ox-content/vite-plugin");
26
+ let svelte_compiler = require("svelte/compiler");
24
27
  let fs = require("fs");
25
28
  fs = __toESM(fs, 1);
26
29
  let path = require("path");
27
30
  path = __toESM(path, 1);
28
- let _ox_content_vite_plugin = require("@ox-content/vite-plugin");
29
- let svelte_compiler = require("svelte/compiler");
30
31
  //#region src/transform.ts
31
32
  const COMPONENT_REGEX = /<([A-Z][a-zA-Z0-9]*)\s*([^>]*?)\s*(?:\/>|>([\s\S]*?)<\/\1>)/g;
32
33
  const PROP_REGEX = /([a-zA-Z0-9-]+)(?:=(?:"([^"]*)"|'([^']*)'|{([^}]*)}|\[([^\]]*)\]))?/g;
@@ -116,8 +117,8 @@ async function transformMarkdownWithSvelte(code, id, options) {
116
117
  }),
117
118
  srcDir: options.srcDir
118
119
  });
119
- if (options.mdxDocumentProps) return compileSvelteResult(generateMdxDocumentPropsSvelteModule(transformed.html, discovered.usedComponents, frontmatter, options, id, discovered.localBindings, documentExpressions.expressions), id, discovered.usedComponents, frontmatter, options.ssr);
120
- return compileSvelteResult(generateSvelteModule(options.renderIsland ? await (0, _ox_content_vite_plugin.applyIslandSsrHtml)(transformed.html, options.renderIsland, id, discovered.usedComponents) : transformed.html, discovered.usedComponents, discovered.usedComponents, frontmatter, options, id, discovered.localBindings), id, discovered.usedComponents, frontmatter, options.ssr);
120
+ if (options.mdxDocumentProps) return compileSvelteResult(generateMdxDocumentPropsSvelteModule(transformed.html, discovered.usedComponents, frontmatter, options, id, discovered.localBindings, documentExpressions.expressions), id, discovered.usedComponents, frontmatter, options);
121
+ return compileSvelteResult(generateSvelteModule(options.renderIsland ? await (0, _ox_content_vite_plugin.applyIslandSsrHtml)(transformed.html, options.renderIsland, id, discovered.usedComponents) : transformed.html, discovered.usedComponents, discovered.usedComponents, frontmatter, options, id, discovered.localBindings), id, discovered.usedComponents, frontmatter, options);
121
122
  }
122
123
  const usedComponents = [];
123
124
  const islands = [];
@@ -151,20 +152,63 @@ async function transformMarkdownWithSvelte(code, id, options) {
151
152
  lastIndex = matchEnd;
152
153
  }
153
154
  processedContent += markdownContent.slice(lastIndex);
154
- return compileSvelteResult(generateSvelteModule(injectIslandMarkers((await (0, _ox_content_vite_plugin.transformMarkdown)(processedContent, id, baseOptions)).html, islands), usedComponents, islands, frontmatter, options, id), id, usedComponents, frontmatter, options.ssr);
155
+ return compileSvelteResult(generateSvelteModule(injectIslandMarkers((await (0, _ox_content_vite_plugin.transformMarkdown)(processedContent, id, baseOptions)).html, islands), usedComponents, islands, frontmatter, options, id), id, usedComponents, frontmatter, options);
155
156
  }
156
- function compileSvelteResult(svelteCode, id, usedComponents, frontmatter, ssr = false) {
157
+ async function compileSvelteResult(svelteCode, id, usedComponents, frontmatter, options) {
158
+ const compiled = normalizeSvelteCompilerResult(await resolveSvelteCompiler(options.compiler)(svelteCode, {
159
+ filename: id,
160
+ generate: options.ssr ? "server" : "client",
161
+ runes: options.runes
162
+ }), id);
157
163
  return {
158
- code: `${(0, svelte_compiler.compile)(svelteCode, {
159
- filename: id,
160
- generate: ssr ? "server" : "client",
161
- runes: true
162
- }).js.code}\nexport const frontmatter = ${JSON.stringify(frontmatter)};`,
163
- map: null,
164
+ code: `${compiled.code}\nexport const frontmatter = ${JSON.stringify(frontmatter)};`,
165
+ map: compiled.map,
166
+ warnings: compiled.warnings,
164
167
  usedComponents,
165
168
  frontmatter
166
169
  };
167
170
  }
171
+ function resolveSvelteCompiler(compiler) {
172
+ if (!compiler) return svelte_compiler.compile;
173
+ if (typeof compiler === "function") return compiler;
174
+ return compiler.compile;
175
+ }
176
+ function normalizeSvelteCompilerResult(result, id) {
177
+ let value = result;
178
+ if (typeof value === "string") {
179
+ const source = value;
180
+ try {
181
+ value = JSON.parse(source);
182
+ } catch {
183
+ return {
184
+ code: source,
185
+ map: null,
186
+ warnings: []
187
+ };
188
+ }
189
+ }
190
+ if (!value || typeof value !== "object") throwUnsupportedCompilerResult(id);
191
+ const output = value;
192
+ const js = output.js;
193
+ const warnings = Array.isArray(output.warnings) ? output.warnings : [];
194
+ if (typeof js === "string") return {
195
+ code: js,
196
+ map: null,
197
+ warnings
198
+ };
199
+ if (js && typeof js === "object") {
200
+ const jsOutput = js;
201
+ if (typeof jsOutput.code === "string") return {
202
+ code: jsOutput.code,
203
+ map: jsOutput.map ?? null,
204
+ warnings
205
+ };
206
+ }
207
+ throwUnsupportedCompilerResult(id);
208
+ }
209
+ function throwUnsupportedCompilerResult(id) {
210
+ throw new Error(`[ox-content-svelte] Compiler for ${id} returned an unsupported result. Expected { js: { code } } or a compatible JSON string.`);
211
+ }
168
212
  function createIslandMarker(islandId) {
169
213
  return `${ISLAND_MARKER_PREFIX}${islandId}${ISLAND_MARKER_SUFFIX}`;
170
214
  }
@@ -965,12 +1009,200 @@ function createSvelteMarkdownEnvironment(mode, options) {
965
1009
  };
966
1010
  }
967
1011
  //#endregion
968
- //#region src/index.ts
1012
+ //#region src/components.ts
969
1013
  /**
970
- * Vite Plugin for Ox Content Svelte Integration
971
- *
972
- * Uses Vite's Environment API to enable embedding Svelte components in Markdown.
1014
+ * Resolves the `components` option into a name → path map, expanding glob
1015
+ * patterns against the Vite project root.
1016
+ */
1017
+ async function resolveComponentsGlob(componentsOption, root) {
1018
+ if (typeof componentsOption === "object" && !Array.isArray(componentsOption)) return componentsOption;
1019
+ const patterns = Array.isArray(componentsOption) ? componentsOption : [componentsOption];
1020
+ const result = {};
1021
+ for (const pattern of patterns) for (const file of await globFiles(pattern, root)) {
1022
+ const baseName = path.basename(file, path.extname(file));
1023
+ const relativePath = "./" + path.relative(root, file).replace(/\\/g, "/");
1024
+ result[toPascalCase(baseName)] = relativePath;
1025
+ }
1026
+ return result;
1027
+ }
1028
+ async function globFiles(pattern, root) {
1029
+ const files = [];
1030
+ const normalized = pattern.replace(/\\/g, "/").replace(/^\.\//, "");
1031
+ if (!hasWildcard(normalized)) {
1032
+ const fullPath = path.resolve(root, normalized);
1033
+ if (fs.existsSync(fullPath)) files.push(fullPath);
1034
+ return files;
1035
+ }
1036
+ const baseDir = path.resolve(root, staticPrefix(normalized));
1037
+ if (!fs.existsSync(baseDir)) return files;
1038
+ const segments = normalized.split("/");
1039
+ const crossesDirectories = normalized.includes("**") || segments.slice(0, -1).some(hasWildcard);
1040
+ const candidates = [];
1041
+ if (crossesDirectories) await walkDir(baseDir, candidates);
1042
+ else {
1043
+ const entries = await fs.promises.readdir(baseDir, { withFileTypes: true });
1044
+ for (const entry of entries) if (entry.isFile()) candidates.push(path.join(baseDir, entry.name));
1045
+ }
1046
+ const matcher = globToRegExp(normalized);
1047
+ for (const candidate of candidates) if (matcher.test(path.relative(root, candidate).replace(/\\/g, "/"))) files.push(candidate);
1048
+ return files;
1049
+ }
1050
+ /** Whether a pattern (or one segment of it) contains a wildcard `globToRegExp` expands. */
1051
+ function hasWildcard(pattern) {
1052
+ return pattern.includes("*") || pattern.includes("?");
1053
+ }
1054
+ /** Leading path segments of a pattern that contain no wildcard. */
1055
+ function staticPrefix(pattern) {
1056
+ const segments = [];
1057
+ for (const segment of pattern.split("/")) {
1058
+ if (hasWildcard(segment)) break;
1059
+ segments.push(segment);
1060
+ }
1061
+ return segments.join("/");
1062
+ }
1063
+ /**
1064
+ * Translates a glob into an anchored `RegExp`: `**` crosses directory
1065
+ * boundaries, `*` and `?` stay within one segment.
973
1066
  */
1067
+ function globToRegExp(pattern) {
1068
+ let source = "";
1069
+ let index = 0;
1070
+ while (index < pattern.length) {
1071
+ const char = pattern[index];
1072
+ if (char === "*") {
1073
+ if (pattern[index + 1] === "*") {
1074
+ index += 2;
1075
+ if (pattern[index] === "/") {
1076
+ index += 1;
1077
+ source += "(?:[^/]+/)*";
1078
+ } else source += ".*";
1079
+ continue;
1080
+ }
1081
+ source += "[^/]*";
1082
+ } else if (char === "?") source += "[^/]";
1083
+ else source += char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1084
+ index += 1;
1085
+ }
1086
+ return new RegExp(`^${source}$`);
1087
+ }
1088
+ async function walkDir(dir, files) {
1089
+ const entries = await fs.promises.readdir(dir, { withFileTypes: true });
1090
+ for (const entry of entries) {
1091
+ const fullPath = path.join(dir, entry.name);
1092
+ if (entry.isDirectory()) await walkDir(fullPath, files);
1093
+ else if (entry.isFile()) files.push(fullPath);
1094
+ }
1095
+ }
1096
+ function toPascalCase(str) {
1097
+ return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c.toUpperCase());
1098
+ }
1099
+ //#endregion
1100
+ //#region src/html-host-default-renderer.ts
1101
+ const defaultRenderSvelteHtmlComponent = async (component, props, slotHtml) => {
1102
+ return renderWithSvelteRuntime(await loadDefaultSvelteRuntime(), component, props, slotHtml);
1103
+ };
1104
+ function createSvelteHtmlHostComponentRenderer(loadModule) {
1105
+ let pending;
1106
+ return async (component, props, slotHtml) => {
1107
+ pending ??= loadSvelteRuntimeFromHost(loadModule);
1108
+ return renderWithSvelteRuntime(await pending, component, props, slotHtml);
1109
+ };
1110
+ }
1111
+ async function loadDefaultSvelteRuntime() {
1112
+ const [server, shared] = await Promise.all([import("svelte/server"), import("svelte")]);
1113
+ return resolveSvelteRuntime(server, shared);
1114
+ }
1115
+ async function loadSvelteRuntimeFromHost(loadModule) {
1116
+ const [server, shared] = await Promise.all([loadModule("svelte/server"), loadModule("svelte")]);
1117
+ return resolveSvelteRuntime(server, shared);
1118
+ }
1119
+ function renderWithSvelteRuntime(runtime, component, props, slotHtml) {
1120
+ const componentProps = slotHtml ? {
1121
+ ...props,
1122
+ children: runtime.createRawSnippet(() => ({ render: () => slotHtml }))
1123
+ } : props;
1124
+ const rendered = runtime.render(component, { props: componentProps });
1125
+ return rendered.html ?? rendered.body ?? "";
1126
+ }
1127
+ function resolveSvelteRuntime(server, shared) {
1128
+ return {
1129
+ render: runtimeFunction(server, "render", "svelte/server"),
1130
+ createRawSnippet: runtimeFunction(shared, "createRawSnippet", "svelte")
1131
+ };
1132
+ }
1133
+ function runtimeFunction(module, name, moduleId) {
1134
+ const value = module && typeof module === "object" ? module[name] : void 0;
1135
+ if (typeof value !== "function") throw new Error(`Svelte HTML host renderer could not load ${moduleId}.${name}.`);
1136
+ return value;
1137
+ }
1138
+ //#endregion
1139
+ //#region src/html-host.ts
1140
+ async function renderSvelteHtmlHost(input) {
1141
+ const resolveClientModule = input.resolveClientModule;
1142
+ return await (0, _ox_content_vite_plugin.renderHtmlHost)({
1143
+ ...input,
1144
+ frameworkName: "Svelte",
1145
+ renderComponent: input.renderComponent ?? defaultRenderSvelteHtmlComponent,
1146
+ resolveClientModule
1147
+ });
1148
+ }
1149
+ function createSvelteHtmlHostHydrate(input) {
1150
+ return (0, _ox_content_vite_plugin.createHtmlHostHydrate)(input);
1151
+ }
1152
+ //#endregion
1153
+ //#region src/html-host-renderer.ts
1154
+ var SvelteHtmlHostRenderError = class extends Error {
1155
+ diagnostics;
1156
+ constructor(diagnostics) {
1157
+ super((0, _ox_content_vite_plugin.formatHtmlHostDiagnostics)(diagnostics));
1158
+ this.name = "SvelteHtmlHostRenderError";
1159
+ this.diagnostics = [...diagnostics];
1160
+ }
1161
+ };
1162
+ function createSvelteHtmlHostRenderer(input) {
1163
+ const policy = input.diagnostics ?? "throw";
1164
+ const defaultRenderComponent = createSvelteHtmlHostComponentRenderer(input.loadModule);
1165
+ return async (html, context) => {
1166
+ const root = context.root ?? input.root;
1167
+ const result = await renderSvelteHtmlHost({
1168
+ html,
1169
+ documentPath: context.documentPath,
1170
+ root,
1171
+ srcDir: context.srcDir ?? input.srcDir,
1172
+ contentRoot: context.contentRoot ?? input.contentRoot,
1173
+ imports: context.imports,
1174
+ components: context.components ?? input.components,
1175
+ loadModule: input.loadModule,
1176
+ renderComponent: context.renderComponent ?? input.renderComponent ?? defaultRenderComponent,
1177
+ resolveClientModule: context.resolveClientModule ?? input.resolveClientModule ?? ((module) => (0, _ox_content_vite_plugin.toHtmlHostClientModuleId)(module.serverModuleId, root))
1178
+ });
1179
+ if (policy === "throw" && result.diagnostics.length > 0) throw new SvelteHtmlHostRenderError(result.diagnostics);
1180
+ return result;
1181
+ };
1182
+ }
1183
+ //#endregion
1184
+ //#region src/html-host-registry.ts
1185
+ const SVELTE_HTML_HOST_MODULES_VIRTUAL_ID = "virtual:ox-content-svelte/html-host/modules";
1186
+ function createSvelteHtmlHostIslandRegistry(input = {}) {
1187
+ return (0, _ox_content_vite_plugin.createHtmlHostIslandRegistry)({
1188
+ ...input,
1189
+ virtualModuleId: input.virtualModuleId ?? "virtual:ox-content-svelte/html-host/modules",
1190
+ pluginName: input.pluginName ?? "ox-content:svelte-html-host-island-registry"
1191
+ });
1192
+ }
1193
+ function resolveSvelteHtmlHostIslandRegistry(input, context, resolvedComponents) {
1194
+ return (0, _ox_content_vite_plugin.resolveHtmlHostIslandRegistry)(input, context, resolvedComponents);
1195
+ }
1196
+ //#endregion
1197
+ //#region src/html-host-collection-documents.ts
1198
+ function createSvelteHtmlHostCollectionDocuments(input = {}) {
1199
+ return (context) => resolveSvelteHtmlHostCollectionDocuments(input, context);
1200
+ }
1201
+ function resolveSvelteHtmlHostCollectionDocuments(input, context) {
1202
+ return (0, _ox_content_vite_plugin.resolveHtmlHostCollectionDocuments)(input, context);
1203
+ }
1204
+ //#endregion
1205
+ //#region src/index.ts
974
1206
  const DEFAULT_MARKDOWN_EXTENSIONS = [
975
1207
  ".md",
976
1208
  ".markdown",
@@ -1054,6 +1286,7 @@ function oxContentSvelte(options = {}) {
1054
1286
  renderIsland: options.renderIsland,
1055
1287
  ssr: transformOptions?.ssr
1056
1288
  });
1289
+ for (const warning of result.warnings) this.warn(formatSvelteCompilerWarning(warning));
1057
1290
  return {
1058
1291
  code: result.code,
1059
1292
  map: result.map
@@ -1091,7 +1324,7 @@ function oxContentSvelte(options = {}) {
1091
1324
  name: "ox-content:svelte-hmr",
1092
1325
  apply: "serve",
1093
1326
  handleHotUpdate({ file, server, modules }) {
1094
- if (Array.from(componentMap.values()).some((path$1) => file.endsWith(path$1.replace(/^\.\//, "")))) {
1327
+ if (Array.from(componentMap.values()).some((path) => file.endsWith(path.replace(/^\.\//, "")))) {
1095
1328
  const mdModules = Array.from(server.moduleGraph.idToModuleMap.values()).filter((mod) => mod.file && isMarkdownFilePath(mod.file, resolved.extensions));
1096
1329
  if (mdModules.length > 0) {
1097
1330
  server.ws.send({
@@ -1126,11 +1359,16 @@ function resolveSvelteOptions(options) {
1126
1359
  tocMaxDepth: options.tocMaxDepth ?? 3,
1127
1360
  codeAnnotations: resolveCodeAnnotationsOptions(options.codeAnnotations),
1128
1361
  runes: options.runes ?? true,
1362
+ compiler: options.compiler,
1129
1363
  embeds: resolveBuiltinEmbedOptions(options.embeds),
1130
1364
  mdx: options.mdx,
1131
1365
  mdxDocumentProps: options.mdxDocumentProps ?? false
1132
1366
  };
1133
1367
  }
1368
+ function formatSvelteCompilerWarning(warning) {
1369
+ const message = `${warning.code ? `[${warning.code}] ` : ""}${warning.message}`;
1370
+ return warning.frame ? `${message}\n${warning.frame}` : message;
1371
+ }
1134
1372
  function resolveCodeAnnotationsOptions(options) {
1135
1373
  if (!options) return {
1136
1374
  enabled: false,
@@ -1154,8 +1392,8 @@ export { mount, unmount } from 'svelte';
1154
1392
  function generateComponentsModule(componentMap) {
1155
1393
  const imports = [];
1156
1394
  const exports = [];
1157
- componentMap.forEach((path$2, name) => {
1158
- imports.push(`import ${name} from '${path$2}';`);
1395
+ componentMap.forEach((path, name) => {
1396
+ imports.push(`import ${name} from '${path}';`);
1159
1397
  exports.push(` ${name},`);
1160
1398
  });
1161
1399
  return `
@@ -1168,49 +1406,17 @@ ${exports.join("\n")}
1168
1406
  export default components;
1169
1407
  `;
1170
1408
  }
1171
- async function resolveComponentsGlob(componentsOption, root) {
1172
- if (typeof componentsOption === "object" && !Array.isArray(componentsOption)) return componentsOption;
1173
- const patterns = Array.isArray(componentsOption) ? componentsOption : [componentsOption];
1174
- const result = {};
1175
- for (const pattern of patterns) {
1176
- const files = await globFiles(pattern, root);
1177
- for (const file of files) {
1178
- const componentName = toPascalCase(path.basename(file, path.extname(file)));
1179
- result[componentName] = "./" + path.relative(root, file).replace(/\\/g, "/");
1180
- }
1181
- }
1182
- return result;
1183
- }
1184
- async function globFiles(pattern, root) {
1185
- const files = [];
1186
- if (!pattern.includes("*")) {
1187
- const fullPath = path.resolve(root, pattern);
1188
- if (fs.existsSync(fullPath)) files.push(fullPath);
1189
- return files;
1190
- }
1191
- const parts = pattern.split("*");
1192
- const baseDir = path.resolve(root, parts[0]);
1193
- const ext = parts[1] || "";
1194
- if (!fs.existsSync(baseDir)) return files;
1195
- if (pattern.includes("**")) await walkDir(baseDir, files, ext);
1196
- else {
1197
- const entries = await fs.promises.readdir(baseDir, { withFileTypes: true });
1198
- for (const entry of entries) if (entry.isFile() && entry.name.endsWith(ext)) files.push(path.join(baseDir, entry.name));
1199
- }
1200
- return files;
1201
- }
1202
- async function walkDir(dir, files, ext) {
1203
- const entries = await fs.promises.readdir(dir, { withFileTypes: true });
1204
- for (const entry of entries) {
1205
- const fullPath = path.join(dir, entry.name);
1206
- if (entry.isDirectory()) await walkDir(fullPath, files, ext);
1207
- else if (entry.isFile() && entry.name.endsWith(ext)) files.push(fullPath);
1208
- }
1209
- }
1210
- function toPascalCase(str) {
1211
- return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c.toUpperCase());
1212
- }
1213
1409
  //#endregion
1410
+ exports.SVELTE_HTML_HOST_MODULES_VIRTUAL_ID = SVELTE_HTML_HOST_MODULES_VIRTUAL_ID;
1411
+ exports.SvelteHtmlHostRenderError = SvelteHtmlHostRenderError;
1412
+ exports.createSvelteHtmlHostCollectionDocuments = createSvelteHtmlHostCollectionDocuments;
1413
+ exports.createSvelteHtmlHostDomRenderer = require_html_host_client.createSvelteHtmlHostDomRenderer;
1414
+ exports.createSvelteHtmlHostHydrate = createSvelteHtmlHostHydrate;
1415
+ exports.createSvelteHtmlHostIslandRegistry = createSvelteHtmlHostIslandRegistry;
1416
+ exports.createSvelteHtmlHostLazyHydrate = require_html_host_client.createSvelteHtmlHostLazyHydrate;
1417
+ exports.createSvelteHtmlHostRenderer = createSvelteHtmlHostRenderer;
1418
+ exports.initSvelteHtmlHost = require_html_host_client.initSvelteHtmlHost;
1419
+ exports.loadSvelteHtmlHostDomRuntime = require_html_host_client.loadSvelteHtmlHostDomRuntime;
1214
1420
  Object.defineProperty(exports, "oxContent", {
1215
1421
  enumerable: true,
1216
1422
  get: function() {
@@ -1218,9 +1424,14 @@ Object.defineProperty(exports, "oxContent", {
1218
1424
  }
1219
1425
  });
1220
1426
  exports.oxContentSvelte = oxContentSvelte;
1427
+ exports.readSvelteHtmlHostSlot = require_html_host_client.readSvelteHtmlHostSlot;
1221
1428
  Object.defineProperty(exports, "renderHead", {
1222
1429
  enumerable: true,
1223
1430
  get: function() {
1224
1431
  return _ox_content_vite_plugin.renderHead;
1225
1432
  }
1226
1433
  });
1434
+ exports.renderSvelteHtmlHost = renderSvelteHtmlHost;
1435
+ exports.resolveSvelteHtmlHostCollectionDocuments = resolveSvelteHtmlHostCollectionDocuments;
1436
+ exports.resolveSvelteHtmlHostIslandRegistry = resolveSvelteHtmlHostIslandRegistry;
1437
+ exports.toSvelteHtmlHostClientModuleId = _ox_content_vite_plugin.toHtmlHostClientModuleId;
package/dist/index.d.cts CHANGED
@@ -1,5 +1,7 @@
1
+ import { C 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, w as SvelteHtmlHostModuleIdResolver, x as SvelteHtmlHostExportNameResolver, y as SvelteHtmlHostDomRendererInput } from "./html-host-client.cjs";
1
2
  import { PluginOption } from "vite";
2
- import { HeadInput, OxContentOptions, RenderIslandFn, RenderedHead, oxContent, renderHead } from "@ox-content/vite-plugin";
3
+ import { CreateHtmlHostHydrateInput, CreateHtmlHostIslandRegistryInput, HeadInput, HtmlHostClientModule, HtmlHostCollectionDocument, HtmlHostCollectionDocumentsOptions, HtmlHostComponentRenderer, HtmlHostDiagnostic, HtmlHostDiagnosticCode, HtmlHostHydrateRenderer, HtmlHostIslandDocument, HtmlHostIslandEntry, HtmlHostIslandRegistry, HtmlHostIslandRegistryContext, HtmlHostModule, HtmlHostServerModuleLoader, MdxImport, MdxImport as MdxImport$1, MdxImportSpecifier, MdxImportSpecifierKind, OxContentOptions, RenderHtmlHostInput, RenderIslandFn, RenderedHead, ResolvedHtmlHostIslandRegistry, oxContent, renderHead, toHtmlHostClientModuleId } from "@ox-content/vite-plugin";
4
+ import { CompileOptions, Warning } from "svelte/compiler";
3
5
  //#region src/types.d.ts
4
6
  /**
5
7
  * Code annotation options for the Svelte integration.
@@ -31,6 +33,25 @@ type ComponentsMap = Record<string, string>;
31
33
  * `configResolved`.
32
34
  */
33
35
  type ComponentsOption = ComponentsMap | string | string[];
36
+ type SvelteCompilerWarning = Warning;
37
+ interface SvelteCompilerOptions extends Omit<CompileOptions, "filename" | "generate" | "runes"> {
38
+ filename: string;
39
+ generate: "client" | "server";
40
+ runes: boolean;
41
+ }
42
+ interface SvelteCompilerJsOutput {
43
+ code: string;
44
+ map?: unknown;
45
+ }
46
+ interface SvelteCompilerObjectResult {
47
+ js: SvelteCompilerJsOutput | string;
48
+ warnings?: readonly SvelteCompilerWarning[];
49
+ }
50
+ type SvelteCompilerResult = SvelteCompilerObjectResult | string;
51
+ type SvelteCompileFunction = (source: string, options: SvelteCompilerOptions) => SvelteCompilerResult | Promise<SvelteCompilerResult>;
52
+ type SvelteCompilerOption = SvelteCompileFunction | {
53
+ compile: SvelteCompileFunction;
54
+ };
34
55
  /**
35
56
  * Opt-in build-time props for MDX documents imported as Svelte components.
36
57
  *
@@ -90,6 +111,16 @@ interface SvelteIntegrationOptions extends OxContentOptions {
90
111
  * @default true
91
112
  */
92
113
  runes?: boolean;
114
+ /**
115
+ * Compiler used for Markdown/MDX-generated Svelte modules.
116
+ *
117
+ * The default is `svelte/compiler`. Pass the same compiler used by an
118
+ * alternative Svelte Vite integration to keep ordinary `.svelte` files and
119
+ * Ox Content-generated document modules on the same compiler implementation.
120
+ *
121
+ * @default `svelte/compiler`
122
+ */
123
+ compiler?: SvelteCompilerOption;
93
124
  /**
94
125
  * Built-in static embeds rendered during Markdown transformation.
95
126
  *
@@ -206,6 +237,7 @@ interface ResolvedSvelteOptions {
206
237
  codeAnnotations: ResolvedCodeAnnotationsOptions;
207
238
  components: ComponentsMap;
208
239
  runes: boolean;
240
+ compiler?: SvelteCompilerOption;
209
241
  embeds: ResolvedBuiltinEmbedOptions;
210
242
  mdx?: boolean;
211
243
  root?: string;
@@ -215,7 +247,8 @@ interface ResolvedSvelteOptions {
215
247
  }
216
248
  interface SvelteTransformResult {
217
249
  code: string;
218
- map: null;
250
+ map: unknown;
251
+ warnings: SvelteCompilerWarning[];
219
252
  usedComponents: string[];
220
253
  frontmatter: Record<string, unknown>;
221
254
  }
@@ -227,6 +260,78 @@ interface ComponentIsland {
227
260
  content?: string;
228
261
  }
229
262
  //#endregion
263
+ //#region src/html-host.d.ts
264
+ interface SvelteHtmlHostModule extends HtmlHostModule {}
265
+ interface SvelteHtmlHostClientModule extends HtmlHostClientModule {}
266
+ type SvelteHtmlHostDiagnosticCode = HtmlHostDiagnosticCode;
267
+ interface SvelteHtmlHostDiagnostic extends HtmlHostDiagnostic {}
268
+ type SvelteServerModuleLoader = HtmlHostServerModuleLoader;
269
+ type SvelteHtmlComponentRenderer = HtmlHostComponentRenderer;
270
+ type SvelteClientModuleResolver = (module: SvelteHtmlHostModule, context: {
271
+ documentPath: string;
272
+ }) => string | undefined;
273
+ interface RenderSvelteHtmlHostInput extends Omit<RenderHtmlHostInput, "components" | "frameworkName" | "adapter" | "renderComponent" | "resolveClientModule"> {
274
+ components?: ComponentsMap;
275
+ renderComponent?: SvelteHtmlComponentRenderer;
276
+ resolveClientModule?: SvelteClientModuleResolver;
277
+ }
278
+ interface RenderSvelteHtmlHostResult {
279
+ html: string;
280
+ modules: SvelteHtmlHostModule[];
281
+ clientModules: SvelteHtmlHostClientModule[];
282
+ diagnostics: SvelteHtmlHostDiagnostic[];
283
+ }
284
+ type SvelteHostHydrateRenderer = HtmlHostHydrateRenderer;
285
+ type CreateSvelteHtmlHostHydrateInput = CreateHtmlHostHydrateInput;
286
+ declare function renderSvelteHtmlHost(input: RenderSvelteHtmlHostInput): Promise<RenderSvelteHtmlHostResult>;
287
+ declare function createSvelteHtmlHostHydrate(input: CreateSvelteHtmlHostHydrateInput): (element: HTMLElement, props: Record<string, unknown>) => void | (() => void);
288
+ //#endregion
289
+ //#region src/html-host-renderer.d.ts
290
+ type SvelteHtmlHostRendererDiagnosticPolicy = "throw" | "collect";
291
+ interface CreateSvelteHtmlHostRendererInput {
292
+ root?: string;
293
+ srcDir?: string;
294
+ contentRoot?: string;
295
+ components?: ComponentsMap;
296
+ loadModule: SvelteServerModuleLoader;
297
+ renderComponent?: SvelteHtmlComponentRenderer;
298
+ resolveClientModule?: SvelteClientModuleResolver;
299
+ diagnostics?: SvelteHtmlHostRendererDiagnosticPolicy;
300
+ }
301
+ interface SvelteHtmlHostRendererContext {
302
+ documentPath: string;
303
+ imports?: readonly MdxImport$1[];
304
+ root?: string;
305
+ srcDir?: string;
306
+ contentRoot?: string;
307
+ components?: ComponentsMap;
308
+ renderComponent?: SvelteHtmlComponentRenderer;
309
+ resolveClientModule?: SvelteClientModuleResolver;
310
+ }
311
+ type SvelteHtmlHostRenderer = (html: string, context: SvelteHtmlHostRendererContext) => Promise<RenderSvelteHtmlHostResult>;
312
+ declare class SvelteHtmlHostRenderError extends Error {
313
+ readonly diagnostics: SvelteHtmlHostDiagnostic[];
314
+ constructor(diagnostics: readonly SvelteHtmlHostDiagnostic[]);
315
+ }
316
+ declare function createSvelteHtmlHostRenderer(input: CreateSvelteHtmlHostRendererInput): SvelteHtmlHostRenderer;
317
+ //#endregion
318
+ //#region src/html-host-registry.d.ts
319
+ declare const SVELTE_HTML_HOST_MODULES_VIRTUAL_ID = "virtual:ox-content-svelte/html-host/modules";
320
+ type SvelteHtmlHostIslandDocument = HtmlHostIslandDocument;
321
+ type SvelteHtmlHostIslandEntry = HtmlHostIslandEntry;
322
+ type SvelteHtmlHostIslandRegistryContext = HtmlHostIslandRegistryContext;
323
+ type CreateSvelteHtmlHostIslandRegistryInput = CreateHtmlHostIslandRegistryInput;
324
+ type ResolvedSvelteHtmlHostIslandRegistry = ResolvedHtmlHostIslandRegistry;
325
+ type SvelteHtmlHostIslandRegistry = HtmlHostIslandRegistry;
326
+ declare function createSvelteHtmlHostIslandRegistry(input?: CreateSvelteHtmlHostIslandRegistryInput): SvelteHtmlHostIslandRegistry;
327
+ declare function resolveSvelteHtmlHostIslandRegistry(input: CreateSvelteHtmlHostIslandRegistryInput, context: SvelteHtmlHostIslandRegistryContext, resolvedComponents?: Record<string, string>): Promise<ResolvedSvelteHtmlHostIslandRegistry>;
328
+ //#endregion
329
+ //#region src/html-host-collection-documents.d.ts
330
+ type SvelteHtmlHostCollectionDocument = HtmlHostCollectionDocument;
331
+ type SvelteHtmlHostCollectionDocumentsOptions = HtmlHostCollectionDocumentsOptions;
332
+ declare function createSvelteHtmlHostCollectionDocuments(input?: SvelteHtmlHostCollectionDocumentsOptions): (context: HtmlHostIslandRegistryContext) => Promise<readonly SvelteHtmlHostCollectionDocument[]>;
333
+ declare function resolveSvelteHtmlHostCollectionDocuments(input: SvelteHtmlHostCollectionDocumentsOptions, context: HtmlHostIslandRegistryContext): Promise<readonly SvelteHtmlHostCollectionDocument[]>;
334
+ //#endregion
230
335
  //#region src/index.d.ts
231
336
  /**
232
337
  * Creates the Ox Content Svelte integration plugin.
@@ -257,5 +362,5 @@ interface ComponentIsland {
257
362
  */
258
363
  declare function oxContentSvelte(options?: SvelteIntegrationOptions): PluginOption[];
259
364
  //#endregion
260
- export { type BuiltinEmbedOptions, type ComponentIsland, type ComponentsMap, type ComponentsOption, type GitHubEmbedOptions, type HeadInput, type MdxDocumentPropsOption, type OpenGraphEmbedOptions, type RenderedHead, type ResolvedBuiltinEmbedOptions, type ResolvedSvelteOptions, type SvelteIntegrationOptions, type SvelteTransformResult, oxContent, oxContentSvelte, renderHead };
365
+ export { type BuiltinEmbedOptions, type ComponentIsland, type ComponentsMap, type ComponentsOption, type CreateSvelteHtmlHostHydrateInput, type CreateSvelteHtmlHostIslandRegistryInput, type CreateSvelteHtmlHostLazyHydrateInput, type CreateSvelteHtmlHostRendererInput, type GitHubEmbedOptions, type HeadInput, type InitSvelteHtmlHostInput, type MdxDocumentPropsOption, type MdxImport, type MdxImportSpecifier, type MdxImportSpecifierKind, type OpenGraphEmbedOptions, type RenderSvelteHtmlHostInput, type RenderSvelteHtmlHostResult, type RenderedHead, type ResolvedBuiltinEmbedOptions, type ResolvedSvelteHtmlHostIslandRegistry, type ResolvedSvelteOptions, SVELTE_HTML_HOST_MODULES_VIRTUAL_ID, type SvelteClientModuleResolver, type SvelteCompileFunction, type SvelteCompilerOption, type SvelteCompilerOptions, type SvelteCompilerResult, type SvelteCompilerWarning, type SvelteHostHydrateRenderer, type SvelteHtmlComponentRenderer, type SvelteHtmlHostClientComponentValue, type SvelteHtmlHostClientContext, type SvelteHtmlHostClientDiagnosticCode, type SvelteHtmlHostClientError, type SvelteHtmlHostClientModule, type SvelteHtmlHostClientModuleLoader, type SvelteHtmlHostClientModuleValue, type SvelteHtmlHostClientModules, type SvelteHtmlHostClientRenderer, type SvelteHtmlHostClientRuntimeLoader, type SvelteHtmlHostCollectionDocument, type SvelteHtmlHostCollectionDocumentsOptions, type SvelteHtmlHostDiagnostic, type SvelteHtmlHostDiagnosticCode, type SvelteHtmlHostDomMode, type SvelteHtmlHostDomRenderer, type SvelteHtmlHostDomRendererInput, type SvelteHtmlHostDomRuntime, type SvelteHtmlHostExportNameResolver, type SvelteHtmlHostInitIslands, type SvelteHtmlHostIslandDocument, type SvelteHtmlHostIslandEntry, type SvelteHtmlHostIslandRegistry, type SvelteHtmlHostIslandRegistryContext, type SvelteHtmlHostModule, type SvelteHtmlHostModuleIdResolver, SvelteHtmlHostRenderError, type SvelteHtmlHostRenderer, type SvelteHtmlHostRendererContext, type SvelteHtmlHostRendererDiagnosticPolicy, type SvelteIntegrationOptions, type SvelteServerModuleLoader, type SvelteTransformResult, createSvelteHtmlHostCollectionDocuments, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostHydrate, createSvelteHtmlHostIslandRegistry, createSvelteHtmlHostLazyHydrate, createSvelteHtmlHostRenderer, initSvelteHtmlHost, loadSvelteHtmlHostDomRuntime, oxContent, oxContentSvelte, readSvelteHtmlHostSlot, renderHead, renderSvelteHtmlHost, resolveSvelteHtmlHostCollectionDocuments, resolveSvelteHtmlHostIslandRegistry, toHtmlHostClientModuleId as toSvelteHtmlHostClientModuleId };
261
366
  //# sourceMappingURL=index.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/index.ts"],"mappings":";;;;;;;;;UAQiB;;;;;;EAMf;;UAGe;EACf;EACA;;;;;KAMU,gBAAgB;;;;;;;;KAShB,mBAAmB;;;;;;;;KASnB;;;;;;;;UASK,iCAAiC;;;;;;;;EAQhD;;;;;;;;;;;;;;;;;;EAmBA,aAAa;;;;;;;;EASb,4BAA4B;;;;;;;;;EAU5B;;;;;;;;;EAUA,SAAS;;;;;;;EAQT,eAAe;;;;;;;;;;;;EAaf,mBAAmB;;;;;UAMJ;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;UAMe;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;UAMe;;;;;EAKf,mBAAmB;;;;;EAMnB,sBAAsB;;UAGP;EACf,QAAQ;EACR,WAAW;;UAGI;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB,YAAY;EACZ;EACA,QAAQ;EACR;EACA;EACA,eAAe;EACf;EACA;;UAGe;EACf;EACA;EACA;EACA,aAAa;;UAGE;EACf;EACA,OAAO;EACP;EACA;EACA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBC3Jc,gBAAgB,UAAS,2BAAgC"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/types.ts","../src/html-host.ts","../src/html-host-renderer.ts","../src/html-host-registry.ts","../src/html-host-collection-documents.ts","../src/index.ts"],"mappings":";;;;;;;;;;;UASiB;;;;;;EAMf;;UAGe;EACf;EACA;;;;;KAMU,gBAAgB;;;;;;;;KAShB,mBAAmB;KAEnB,wBAAwB;UAEnB,8BAA8B,KAC7C;EAGA;EACA;EACA;;UAGe;EACf;EACA;;UAGe;EACf,IAAI;EACJ,oBAAoB;;KAGV,uBAAuB;KAEvB,yBACV,gBACA,SAAS,0BACN,uBAAuB,QAAQ;KAExB,uBACR;EAEE,SAAS;;;;;;;;;KAUH;;;;;;;;UASK,iCAAiC;;;;;;;;EAQhD;;;;;;;;;;;;;;;;;;EAmBA,aAAa;;;;;;;;EASb,4BAA4B;;;;;;;;;EAU5B;;;;;;;;;;EAWA,WAAW;;;;;;;;;EAUX,SAAS;;;;;;;EAQT,eAAe;;;;;;;;;;;;EAaf,mBAAmB;;;;;UAMJ;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;UAMe;;;;;EAKf;;;;;EAMA;;;;;EAMA;;;;;EAMA;;;;;UAMe;;;;;EAKf,mBAAmB;;;;;EAMnB,sBAAsB;;UAGP;EACf,QAAQ;EACR,WAAW;;UAGI;EACf;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,iBAAiB;EACjB,YAAY;EACZ;EACA,WAAW;EACX,QAAQ;EACR;EACA;EACA,eAAe;EACf;EACA;;UAGe;EACf;EACA;EACA,UAAU;EACV;EACA,aAAa;;UAGE;EACf;EACA,OAAO;EACP;EACA;EACA;;;;UC3Re,6BAA6B;UAC7B,mCAAmC;KACxC,+BAA+B;UAC1B,iCAAiC;KACtC,2BAA2B;KAC3B,8BAA8B;KAC9B,8BACV,QAAQ,sBACR;EAAW;;UAGI,kCAAkC,KACjD;EAGA,aAAa;EACb,kBAAkB;EAClB,sBAAsB;;UAGP;EACf;EACA,SAAS;EACT,eAAe;EACf,aAAa;;KAGH,4BAA4B;KAC5B,mCAAmC;iBAEzB,qBACpB,OAAO,4BACN,QAAQ;iBAUK,4BACd,OAAO,oCACL,SAAS,aAAa,OAAO;;;KC/CrB;UAEK;EACf;EACA;EACA;EACA,aAAa;EACb,YAAY;EACZ,kBAAkB;EAClB,sBAAsB;EACtB,cAAc;;UAGC;EACf;EACA,mBAAmB;EACnB;EACA;EACA;EACA,aAAa;EACb,kBAAkB;EAClB,sBAAsB;;KAGZ,0BACV,cACA,SAAS,kCACN,QAAQ;cAEA,kCAAkC;WACpC,aAAa;EAEtB,YAAY,sBAAsB;;iBAOpB,6BACd,OAAO,oCACN;;;cCxCU;KAED,+BAA+B;KAC/B,4BAA4B;KAC5B,sCAAsC;KACtC,0CAA0C;KAC1C,uCAAuC;KACvC,+BAA+B;iBAE3B,mCACd,QAAO,0CACN;iBAQa,oCACd,OAAO,yCACP,SAAS,qCACT,qBAAqB,yBACpB,QAAQ;;;KC9BC,mCAAmC;KACnC,2CAA2C;iBAEvC,wCACd,QAAO,4CAEP,SAAS,kCACN,iBAAiB;iBAIN,yCACd,OAAO,0CACP,SAAS,gCACR,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBCqJJ,gBAAgB,UAAS,2BAAgC"}