@ox-content/vite-plugin-svelte 3.1.2 → 3.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/html-host-client.cjs +7 -0
- package/dist/html-host-client.d.cts +68 -0
- package/dist/html-host-client.d.mts +68 -0
- package/dist/html-host-client.mjs +2 -0
- package/dist/html-host-client2.cjs +111 -0
- package/dist/html-host-client2.d.cts +2 -0
- package/dist/html-host-client2.d.mts +2 -0
- package/dist/html-host-client2.mjs +84 -0
- package/dist/html-host-client2.mjs.map +1 -0
- package/dist/index.cjs +272 -61
- package/dist/index.d.cts +108 -3
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +108 -3
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +255 -59
- package/dist/index.mjs.map +1 -1
- package/package.json +16 -4
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import {
|
|
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.mjs";
|
|
2
|
+
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";
|
|
3
|
+
import { CompileOptions, Warning } from "svelte/compiler";
|
|
2
4
|
import { PluginOption } from "vite";
|
|
3
5
|
//#region src/types.d.ts
|
|
4
6
|
/**
|
|
@@ -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:
|
|
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.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/index.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","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"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { a as loadSvelteHtmlHostDomRuntime, i as createSvelteHtmlHostDomRenderer, n as initSvelteHtmlHost, r as readSvelteHtmlHostSlot, t as createSvelteHtmlHostLazyHydrate } from "./html-host-client2.mjs";
|
|
2
|
+
import { applyIslandSsrHtml, createHtmlHostHydrate, createHtmlHostIslandRegistry, discoverDocumentMdxIslands, formatHtmlHostDiagnostics, oxContent, oxContent as oxContent$1, renderHead, renderHtmlHost, renderIslandComponentImports, resolveContentRootPath, resolveHtmlHostCollectionDocuments, resolveHtmlHostIslandRegistry, resolveMdxForFilePath, toHtmlHostClientModuleId, toHtmlHostClientModuleId as toHtmlHostClientModuleId$1, transformMarkdown } from "@ox-content/vite-plugin";
|
|
3
|
+
import { compile } from "svelte/compiler";
|
|
1
4
|
import * as fs from "fs";
|
|
2
5
|
import * as path from "path";
|
|
3
|
-
import { applyIslandSsrHtml, discoverDocumentMdxIslands, oxContent, oxContent as oxContent$1, renderHead, renderIslandComponentImports, resolveContentRootPath, resolveMdxForFilePath, transformMarkdown } from "@ox-content/vite-plugin";
|
|
4
|
-
import { compile } from "svelte/compiler";
|
|
5
6
|
//#region src/transform.ts
|
|
6
7
|
const COMPONENT_REGEX = /<([A-Z][a-zA-Z0-9]*)\s*([^>]*?)\s*(?:\/>|>([\s\S]*?)<\/\1>)/g;
|
|
7
8
|
const PROP_REGEX = /([a-zA-Z0-9-]+)(?:=(?:"([^"]*)"|'([^']*)'|{([^}]*)}|\[([^\]]*)\]))?/g;
|
|
@@ -91,8 +92,8 @@ async function transformMarkdownWithSvelte(code, id, options) {
|
|
|
91
92
|
}),
|
|
92
93
|
srcDir: options.srcDir
|
|
93
94
|
});
|
|
94
|
-
if (options.mdxDocumentProps) return compileSvelteResult(generateMdxDocumentPropsSvelteModule(transformed.html, discovered.usedComponents, frontmatter, options, id, discovered.localBindings, documentExpressions.expressions), id, discovered.usedComponents, frontmatter, options
|
|
95
|
-
return compileSvelteResult(generateSvelteModule(options.renderIsland ? await applyIslandSsrHtml(transformed.html, options.renderIsland, id, discovered.usedComponents) : transformed.html, discovered.usedComponents, discovered.usedComponents, frontmatter, options, id, discovered.localBindings), id, discovered.usedComponents, frontmatter, options
|
|
95
|
+
if (options.mdxDocumentProps) return compileSvelteResult(generateMdxDocumentPropsSvelteModule(transformed.html, discovered.usedComponents, frontmatter, options, id, discovered.localBindings, documentExpressions.expressions), id, discovered.usedComponents, frontmatter, options);
|
|
96
|
+
return compileSvelteResult(generateSvelteModule(options.renderIsland ? await applyIslandSsrHtml(transformed.html, options.renderIsland, id, discovered.usedComponents) : transformed.html, discovered.usedComponents, discovered.usedComponents, frontmatter, options, id, discovered.localBindings), id, discovered.usedComponents, frontmatter, options);
|
|
96
97
|
}
|
|
97
98
|
const usedComponents = [];
|
|
98
99
|
const islands = [];
|
|
@@ -126,20 +127,63 @@ async function transformMarkdownWithSvelte(code, id, options) {
|
|
|
126
127
|
lastIndex = matchEnd;
|
|
127
128
|
}
|
|
128
129
|
processedContent += markdownContent.slice(lastIndex);
|
|
129
|
-
return compileSvelteResult(generateSvelteModule(injectIslandMarkers((await transformMarkdown(processedContent, id, baseOptions)).html, islands), usedComponents, islands, frontmatter, options, id), id, usedComponents, frontmatter, options
|
|
130
|
+
return compileSvelteResult(generateSvelteModule(injectIslandMarkers((await transformMarkdown(processedContent, id, baseOptions)).html, islands), usedComponents, islands, frontmatter, options, id), id, usedComponents, frontmatter, options);
|
|
130
131
|
}
|
|
131
|
-
function compileSvelteResult(svelteCode, id, usedComponents, frontmatter,
|
|
132
|
+
async function compileSvelteResult(svelteCode, id, usedComponents, frontmatter, options) {
|
|
133
|
+
const compiled = normalizeSvelteCompilerResult(await resolveSvelteCompiler(options.compiler)(svelteCode, {
|
|
134
|
+
filename: id,
|
|
135
|
+
generate: options.ssr ? "server" : "client",
|
|
136
|
+
runes: options.runes
|
|
137
|
+
}), id);
|
|
132
138
|
return {
|
|
133
|
-
code: `${
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
runes: true
|
|
137
|
-
}).js.code}\nexport const frontmatter = ${JSON.stringify(frontmatter)};`,
|
|
138
|
-
map: null,
|
|
139
|
+
code: `${compiled.code}\nexport const frontmatter = ${JSON.stringify(frontmatter)};`,
|
|
140
|
+
map: compiled.map,
|
|
141
|
+
warnings: compiled.warnings,
|
|
139
142
|
usedComponents,
|
|
140
143
|
frontmatter
|
|
141
144
|
};
|
|
142
145
|
}
|
|
146
|
+
function resolveSvelteCompiler(compiler) {
|
|
147
|
+
if (!compiler) return compile;
|
|
148
|
+
if (typeof compiler === "function") return compiler;
|
|
149
|
+
return compiler.compile;
|
|
150
|
+
}
|
|
151
|
+
function normalizeSvelteCompilerResult(result, id) {
|
|
152
|
+
let value = result;
|
|
153
|
+
if (typeof value === "string") {
|
|
154
|
+
const source = value;
|
|
155
|
+
try {
|
|
156
|
+
value = JSON.parse(source);
|
|
157
|
+
} catch {
|
|
158
|
+
return {
|
|
159
|
+
code: source,
|
|
160
|
+
map: null,
|
|
161
|
+
warnings: []
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (!value || typeof value !== "object") throwUnsupportedCompilerResult(id);
|
|
166
|
+
const output = value;
|
|
167
|
+
const js = output.js;
|
|
168
|
+
const warnings = Array.isArray(output.warnings) ? output.warnings : [];
|
|
169
|
+
if (typeof js === "string") return {
|
|
170
|
+
code: js,
|
|
171
|
+
map: null,
|
|
172
|
+
warnings
|
|
173
|
+
};
|
|
174
|
+
if (js && typeof js === "object") {
|
|
175
|
+
const jsOutput = js;
|
|
176
|
+
if (typeof jsOutput.code === "string") return {
|
|
177
|
+
code: jsOutput.code,
|
|
178
|
+
map: jsOutput.map ?? null,
|
|
179
|
+
warnings
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
throwUnsupportedCompilerResult(id);
|
|
183
|
+
}
|
|
184
|
+
function throwUnsupportedCompilerResult(id) {
|
|
185
|
+
throw new Error(`[ox-content-svelte] Compiler for ${id} returned an unsupported result. Expected { js: { code } } or a compatible JSON string.`);
|
|
186
|
+
}
|
|
143
187
|
function createIslandMarker(islandId) {
|
|
144
188
|
return `${ISLAND_MARKER_PREFIX}${islandId}${ISLAND_MARKER_SUFFIX}`;
|
|
145
189
|
}
|
|
@@ -940,12 +984,200 @@ function createSvelteMarkdownEnvironment(mode, options) {
|
|
|
940
984
|
};
|
|
941
985
|
}
|
|
942
986
|
//#endregion
|
|
943
|
-
//#region src/
|
|
987
|
+
//#region src/components.ts
|
|
944
988
|
/**
|
|
945
|
-
*
|
|
946
|
-
*
|
|
947
|
-
* Uses Vite's Environment API to enable embedding Svelte components in Markdown.
|
|
989
|
+
* Resolves the `components` option into a name → path map, expanding glob
|
|
990
|
+
* patterns against the Vite project root.
|
|
948
991
|
*/
|
|
992
|
+
async function resolveComponentsGlob(componentsOption, root) {
|
|
993
|
+
if (typeof componentsOption === "object" && !Array.isArray(componentsOption)) return componentsOption;
|
|
994
|
+
const patterns = Array.isArray(componentsOption) ? componentsOption : [componentsOption];
|
|
995
|
+
const result = {};
|
|
996
|
+
for (const pattern of patterns) for (const file of await globFiles(pattern, root)) {
|
|
997
|
+
const baseName = path.basename(file, path.extname(file));
|
|
998
|
+
const relativePath = "./" + path.relative(root, file).replace(/\\/g, "/");
|
|
999
|
+
result[toPascalCase(baseName)] = relativePath;
|
|
1000
|
+
}
|
|
1001
|
+
return result;
|
|
1002
|
+
}
|
|
1003
|
+
async function globFiles(pattern, root) {
|
|
1004
|
+
const files = [];
|
|
1005
|
+
const normalized = pattern.replace(/\\/g, "/").replace(/^\.\//, "");
|
|
1006
|
+
if (!hasWildcard(normalized)) {
|
|
1007
|
+
const fullPath = path.resolve(root, normalized);
|
|
1008
|
+
if (fs.existsSync(fullPath)) files.push(fullPath);
|
|
1009
|
+
return files;
|
|
1010
|
+
}
|
|
1011
|
+
const baseDir = path.resolve(root, staticPrefix(normalized));
|
|
1012
|
+
if (!fs.existsSync(baseDir)) return files;
|
|
1013
|
+
const segments = normalized.split("/");
|
|
1014
|
+
const crossesDirectories = normalized.includes("**") || segments.slice(0, -1).some(hasWildcard);
|
|
1015
|
+
const candidates = [];
|
|
1016
|
+
if (crossesDirectories) await walkDir(baseDir, candidates);
|
|
1017
|
+
else {
|
|
1018
|
+
const entries = await fs.promises.readdir(baseDir, { withFileTypes: true });
|
|
1019
|
+
for (const entry of entries) if (entry.isFile()) candidates.push(path.join(baseDir, entry.name));
|
|
1020
|
+
}
|
|
1021
|
+
const matcher = globToRegExp(normalized);
|
|
1022
|
+
for (const candidate of candidates) if (matcher.test(path.relative(root, candidate).replace(/\\/g, "/"))) files.push(candidate);
|
|
1023
|
+
return files;
|
|
1024
|
+
}
|
|
1025
|
+
/** Whether a pattern (or one segment of it) contains a wildcard `globToRegExp` expands. */
|
|
1026
|
+
function hasWildcard(pattern) {
|
|
1027
|
+
return pattern.includes("*") || pattern.includes("?");
|
|
1028
|
+
}
|
|
1029
|
+
/** Leading path segments of a pattern that contain no wildcard. */
|
|
1030
|
+
function staticPrefix(pattern) {
|
|
1031
|
+
const segments = [];
|
|
1032
|
+
for (const segment of pattern.split("/")) {
|
|
1033
|
+
if (hasWildcard(segment)) break;
|
|
1034
|
+
segments.push(segment);
|
|
1035
|
+
}
|
|
1036
|
+
return segments.join("/");
|
|
1037
|
+
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Translates a glob into an anchored `RegExp`: `**` crosses directory
|
|
1040
|
+
* boundaries, `*` and `?` stay within one segment.
|
|
1041
|
+
*/
|
|
1042
|
+
function globToRegExp(pattern) {
|
|
1043
|
+
let source = "";
|
|
1044
|
+
let index = 0;
|
|
1045
|
+
while (index < pattern.length) {
|
|
1046
|
+
const char = pattern[index];
|
|
1047
|
+
if (char === "*") {
|
|
1048
|
+
if (pattern[index + 1] === "*") {
|
|
1049
|
+
index += 2;
|
|
1050
|
+
if (pattern[index] === "/") {
|
|
1051
|
+
index += 1;
|
|
1052
|
+
source += "(?:[^/]+/)*";
|
|
1053
|
+
} else source += ".*";
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1056
|
+
source += "[^/]*";
|
|
1057
|
+
} else if (char === "?") source += "[^/]";
|
|
1058
|
+
else source += char.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1059
|
+
index += 1;
|
|
1060
|
+
}
|
|
1061
|
+
return new RegExp(`^${source}$`);
|
|
1062
|
+
}
|
|
1063
|
+
async function walkDir(dir, files) {
|
|
1064
|
+
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
1065
|
+
for (const entry of entries) {
|
|
1066
|
+
const fullPath = path.join(dir, entry.name);
|
|
1067
|
+
if (entry.isDirectory()) await walkDir(fullPath, files);
|
|
1068
|
+
else if (entry.isFile()) files.push(fullPath);
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
function toPascalCase(str) {
|
|
1072
|
+
return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c.toUpperCase());
|
|
1073
|
+
}
|
|
1074
|
+
//#endregion
|
|
1075
|
+
//#region src/html-host-default-renderer.ts
|
|
1076
|
+
const defaultRenderSvelteHtmlComponent = async (component, props, slotHtml) => {
|
|
1077
|
+
return renderWithSvelteRuntime(await loadDefaultSvelteRuntime(), component, props, slotHtml);
|
|
1078
|
+
};
|
|
1079
|
+
function createSvelteHtmlHostComponentRenderer(loadModule) {
|
|
1080
|
+
let pending;
|
|
1081
|
+
return async (component, props, slotHtml) => {
|
|
1082
|
+
pending ??= loadSvelteRuntimeFromHost(loadModule);
|
|
1083
|
+
return renderWithSvelteRuntime(await pending, component, props, slotHtml);
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
async function loadDefaultSvelteRuntime() {
|
|
1087
|
+
const [server, shared] = await Promise.all([import("svelte/server"), import("svelte")]);
|
|
1088
|
+
return resolveSvelteRuntime(server, shared);
|
|
1089
|
+
}
|
|
1090
|
+
async function loadSvelteRuntimeFromHost(loadModule) {
|
|
1091
|
+
const [server, shared] = await Promise.all([loadModule("svelte/server"), loadModule("svelte")]);
|
|
1092
|
+
return resolveSvelteRuntime(server, shared);
|
|
1093
|
+
}
|
|
1094
|
+
function renderWithSvelteRuntime(runtime, component, props, slotHtml) {
|
|
1095
|
+
const componentProps = slotHtml ? {
|
|
1096
|
+
...props,
|
|
1097
|
+
children: runtime.createRawSnippet(() => ({ render: () => slotHtml }))
|
|
1098
|
+
} : props;
|
|
1099
|
+
const rendered = runtime.render(component, { props: componentProps });
|
|
1100
|
+
return rendered.html ?? rendered.body ?? "";
|
|
1101
|
+
}
|
|
1102
|
+
function resolveSvelteRuntime(server, shared) {
|
|
1103
|
+
return {
|
|
1104
|
+
render: runtimeFunction(server, "render", "svelte/server"),
|
|
1105
|
+
createRawSnippet: runtimeFunction(shared, "createRawSnippet", "svelte")
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1108
|
+
function runtimeFunction(module, name, moduleId) {
|
|
1109
|
+
const value = module && typeof module === "object" ? module[name] : void 0;
|
|
1110
|
+
if (typeof value !== "function") throw new Error(`Svelte HTML host renderer could not load ${moduleId}.${name}.`);
|
|
1111
|
+
return value;
|
|
1112
|
+
}
|
|
1113
|
+
//#endregion
|
|
1114
|
+
//#region src/html-host.ts
|
|
1115
|
+
async function renderSvelteHtmlHost(input) {
|
|
1116
|
+
const resolveClientModule = input.resolveClientModule;
|
|
1117
|
+
return await renderHtmlHost({
|
|
1118
|
+
...input,
|
|
1119
|
+
frameworkName: "Svelte",
|
|
1120
|
+
renderComponent: input.renderComponent ?? defaultRenderSvelteHtmlComponent,
|
|
1121
|
+
resolveClientModule
|
|
1122
|
+
});
|
|
1123
|
+
}
|
|
1124
|
+
function createSvelteHtmlHostHydrate(input) {
|
|
1125
|
+
return createHtmlHostHydrate(input);
|
|
1126
|
+
}
|
|
1127
|
+
//#endregion
|
|
1128
|
+
//#region src/html-host-renderer.ts
|
|
1129
|
+
var SvelteHtmlHostRenderError = class extends Error {
|
|
1130
|
+
diagnostics;
|
|
1131
|
+
constructor(diagnostics) {
|
|
1132
|
+
super(formatHtmlHostDiagnostics(diagnostics));
|
|
1133
|
+
this.name = "SvelteHtmlHostRenderError";
|
|
1134
|
+
this.diagnostics = [...diagnostics];
|
|
1135
|
+
}
|
|
1136
|
+
};
|
|
1137
|
+
function createSvelteHtmlHostRenderer(input) {
|
|
1138
|
+
const policy = input.diagnostics ?? "throw";
|
|
1139
|
+
const defaultRenderComponent = createSvelteHtmlHostComponentRenderer(input.loadModule);
|
|
1140
|
+
return async (html, context) => {
|
|
1141
|
+
const root = context.root ?? input.root;
|
|
1142
|
+
const result = await renderSvelteHtmlHost({
|
|
1143
|
+
html,
|
|
1144
|
+
documentPath: context.documentPath,
|
|
1145
|
+
root,
|
|
1146
|
+
srcDir: context.srcDir ?? input.srcDir,
|
|
1147
|
+
contentRoot: context.contentRoot ?? input.contentRoot,
|
|
1148
|
+
imports: context.imports,
|
|
1149
|
+
components: context.components ?? input.components,
|
|
1150
|
+
loadModule: input.loadModule,
|
|
1151
|
+
renderComponent: context.renderComponent ?? input.renderComponent ?? defaultRenderComponent,
|
|
1152
|
+
resolveClientModule: context.resolveClientModule ?? input.resolveClientModule ?? ((module) => toHtmlHostClientModuleId$1(module.serverModuleId, root))
|
|
1153
|
+
});
|
|
1154
|
+
if (policy === "throw" && result.diagnostics.length > 0) throw new SvelteHtmlHostRenderError(result.diagnostics);
|
|
1155
|
+
return result;
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
//#endregion
|
|
1159
|
+
//#region src/html-host-registry.ts
|
|
1160
|
+
const SVELTE_HTML_HOST_MODULES_VIRTUAL_ID = "virtual:ox-content-svelte/html-host/modules";
|
|
1161
|
+
function createSvelteHtmlHostIslandRegistry(input = {}) {
|
|
1162
|
+
return createHtmlHostIslandRegistry({
|
|
1163
|
+
...input,
|
|
1164
|
+
virtualModuleId: input.virtualModuleId ?? "virtual:ox-content-svelte/html-host/modules",
|
|
1165
|
+
pluginName: input.pluginName ?? "ox-content:svelte-html-host-island-registry"
|
|
1166
|
+
});
|
|
1167
|
+
}
|
|
1168
|
+
function resolveSvelteHtmlHostIslandRegistry(input, context, resolvedComponents) {
|
|
1169
|
+
return resolveHtmlHostIslandRegistry(input, context, resolvedComponents);
|
|
1170
|
+
}
|
|
1171
|
+
//#endregion
|
|
1172
|
+
//#region src/html-host-collection-documents.ts
|
|
1173
|
+
function createSvelteHtmlHostCollectionDocuments(input = {}) {
|
|
1174
|
+
return (context) => resolveSvelteHtmlHostCollectionDocuments(input, context);
|
|
1175
|
+
}
|
|
1176
|
+
function resolveSvelteHtmlHostCollectionDocuments(input, context) {
|
|
1177
|
+
return resolveHtmlHostCollectionDocuments(input, context);
|
|
1178
|
+
}
|
|
1179
|
+
//#endregion
|
|
1180
|
+
//#region src/index.ts
|
|
949
1181
|
const DEFAULT_MARKDOWN_EXTENSIONS = [
|
|
950
1182
|
".md",
|
|
951
1183
|
".markdown",
|
|
@@ -1029,6 +1261,7 @@ function oxContentSvelte(options = {}) {
|
|
|
1029
1261
|
renderIsland: options.renderIsland,
|
|
1030
1262
|
ssr: transformOptions?.ssr
|
|
1031
1263
|
});
|
|
1264
|
+
for (const warning of result.warnings) this.warn(formatSvelteCompilerWarning(warning));
|
|
1032
1265
|
return {
|
|
1033
1266
|
code: result.code,
|
|
1034
1267
|
map: result.map
|
|
@@ -1101,11 +1334,16 @@ function resolveSvelteOptions(options) {
|
|
|
1101
1334
|
tocMaxDepth: options.tocMaxDepth ?? 3,
|
|
1102
1335
|
codeAnnotations: resolveCodeAnnotationsOptions(options.codeAnnotations),
|
|
1103
1336
|
runes: options.runes ?? true,
|
|
1337
|
+
compiler: options.compiler,
|
|
1104
1338
|
embeds: resolveBuiltinEmbedOptions(options.embeds),
|
|
1105
1339
|
mdx: options.mdx,
|
|
1106
1340
|
mdxDocumentProps: options.mdxDocumentProps ?? false
|
|
1107
1341
|
};
|
|
1108
1342
|
}
|
|
1343
|
+
function formatSvelteCompilerWarning(warning) {
|
|
1344
|
+
const message = `${warning.code ? `[${warning.code}] ` : ""}${warning.message}`;
|
|
1345
|
+
return warning.frame ? `${message}\n${warning.frame}` : message;
|
|
1346
|
+
}
|
|
1109
1347
|
function resolveCodeAnnotationsOptions(options) {
|
|
1110
1348
|
if (!options) return {
|
|
1111
1349
|
enabled: false,
|
|
@@ -1143,49 +1381,7 @@ ${exports.join("\n")}
|
|
|
1143
1381
|
export default components;
|
|
1144
1382
|
`;
|
|
1145
1383
|
}
|
|
1146
|
-
async function resolveComponentsGlob(componentsOption, root) {
|
|
1147
|
-
if (typeof componentsOption === "object" && !Array.isArray(componentsOption)) return componentsOption;
|
|
1148
|
-
const patterns = Array.isArray(componentsOption) ? componentsOption : [componentsOption];
|
|
1149
|
-
const result = {};
|
|
1150
|
-
for (const pattern of patterns) {
|
|
1151
|
-
const files = await globFiles(pattern, root);
|
|
1152
|
-
for (const file of files) {
|
|
1153
|
-
const componentName = toPascalCase(path.basename(file, path.extname(file)));
|
|
1154
|
-
result[componentName] = "./" + path.relative(root, file).replace(/\\/g, "/");
|
|
1155
|
-
}
|
|
1156
|
-
}
|
|
1157
|
-
return result;
|
|
1158
|
-
}
|
|
1159
|
-
async function globFiles(pattern, root) {
|
|
1160
|
-
const files = [];
|
|
1161
|
-
if (!pattern.includes("*")) {
|
|
1162
|
-
const fullPath = path.resolve(root, pattern);
|
|
1163
|
-
if (fs.existsSync(fullPath)) files.push(fullPath);
|
|
1164
|
-
return files;
|
|
1165
|
-
}
|
|
1166
|
-
const parts = pattern.split("*");
|
|
1167
|
-
const baseDir = path.resolve(root, parts[0]);
|
|
1168
|
-
const ext = parts[1] || "";
|
|
1169
|
-
if (!fs.existsSync(baseDir)) return files;
|
|
1170
|
-
if (pattern.includes("**")) await walkDir(baseDir, files, ext);
|
|
1171
|
-
else {
|
|
1172
|
-
const entries = await fs.promises.readdir(baseDir, { withFileTypes: true });
|
|
1173
|
-
for (const entry of entries) if (entry.isFile() && entry.name.endsWith(ext)) files.push(path.join(baseDir, entry.name));
|
|
1174
|
-
}
|
|
1175
|
-
return files;
|
|
1176
|
-
}
|
|
1177
|
-
async function walkDir(dir, files, ext) {
|
|
1178
|
-
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
1179
|
-
for (const entry of entries) {
|
|
1180
|
-
const fullPath = path.join(dir, entry.name);
|
|
1181
|
-
if (entry.isDirectory()) await walkDir(fullPath, files, ext);
|
|
1182
|
-
else if (entry.isFile() && entry.name.endsWith(ext)) files.push(fullPath);
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
function toPascalCase(str) {
|
|
1186
|
-
return str.replace(/[-_](\w)/g, (_, c) => c.toUpperCase()).replace(/^\w/, (c) => c.toUpperCase());
|
|
1187
|
-
}
|
|
1188
1384
|
//#endregion
|
|
1189
|
-
export { oxContent, oxContentSvelte, renderHead };
|
|
1385
|
+
export { SVELTE_HTML_HOST_MODULES_VIRTUAL_ID, SvelteHtmlHostRenderError, createSvelteHtmlHostCollectionDocuments, createSvelteHtmlHostDomRenderer, createSvelteHtmlHostHydrate, createSvelteHtmlHostIslandRegistry, createSvelteHtmlHostLazyHydrate, createSvelteHtmlHostRenderer, initSvelteHtmlHost, loadSvelteHtmlHostDomRuntime, oxContent, oxContentSvelte, readSvelteHtmlHostSlot, renderHead, renderSvelteHtmlHost, resolveSvelteHtmlHostCollectionDocuments, resolveSvelteHtmlHostIslandRegistry, toHtmlHostClientModuleId as toSvelteHtmlHostClientModuleId };
|
|
1190
1386
|
|
|
1191
1387
|
//# sourceMappingURL=index.mjs.map
|