@hanzo/mdx-runtime 1.5.2 → 1.6.1
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.d.ts +3 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/render-DHnSPAbU.js.map +1 -1
- package/package.json +10 -10
package/dist/index.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ declare function parseFrontmatter(content: string): {
|
|
|
19
19
|
};
|
|
20
20
|
//#endregion
|
|
21
21
|
//#region src/compile.d.ts
|
|
22
|
-
type
|
|
22
|
+
type DocsPresetOptions = Omit<CompileOptions, 'remarkPlugins' | 'rehypePlugins'> & {
|
|
23
23
|
preset?: 'hanzo-docs';
|
|
24
24
|
remarkPlugins?: ResolvePlugins;
|
|
25
25
|
rehypePlugins?: ResolvePlugins;
|
|
@@ -39,7 +39,7 @@ type FumadocsPresetOptions = Omit<CompileOptions, 'remarkPlugins' | 'rehypePlugi
|
|
|
39
39
|
};
|
|
40
40
|
type CompilerOptions = (CompileOptions & {
|
|
41
41
|
preset: 'minimal';
|
|
42
|
-
}) |
|
|
42
|
+
}) | DocsPresetOptions;
|
|
43
43
|
interface CompileMDXOptions {
|
|
44
44
|
source: string;
|
|
45
45
|
/**
|
|
@@ -88,5 +88,5 @@ declare function executeMdx(compiled: string, scope: object, baseUrl?: string |
|
|
|
88
88
|
toc?: TableOfContents;
|
|
89
89
|
}>;
|
|
90
90
|
//#endregion
|
|
91
|
-
export { CompileMDXOptions, CompileMDXResult, CompilerOptions, type CompilerOptions as MDXOptions,
|
|
91
|
+
export { CompileMDXOptions, CompileMDXResult, CompilerOptions, type CompilerOptions as MDXOptions, DocsPresetOptions, compileMDX, createCompiler, executeMdx, parseFrontmatter };
|
|
92
92
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/utils.ts","../src/compile.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAGY,cAAA,GAAiB,mBAAmB,gBAAgB;;;;iBAkBhD,gBAAA;;;EAlBJ,CAAA;EAAiB,OAAA,EAAA,MAAA;CAAmB;;;KCMpC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/utils.ts","../src/compile.ts","../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;;;;KAGY,cAAA,GAAiB,mBAAmB,gBAAgB;;;;iBAkBhD,gBAAA;;;EAlBJ,CAAA;EAAiB,OAAA,EAAA,MAAA;CAAmB;;;KCMpC,iBAAA,GAAoB,KAAK;;EDNzB,aAAA,CAAA,ECQM,cDRQ;EAAG,aAAA,CAAA,ECSX,cDTW;EAAmB,oBAAA,CAAA,ECWvB,OAAA,CAAQ,oBDXe,GAAA,KAAA;EAAgB,iBAAA,CAAA,ECY1C,OAAA,CAAQ,iBDZkC,GAAA,KAAA;EAAS,gBAAA,CAAA,ECapD,OAAA,CAAQ,gBDb4C,GAAA,KAAA;EAkBzD,oBAAgB,CAAA,ECJP,OAAA,CAAQ,oBDID,GAAA,KAAA;qBCHX,OAAA,CAAQ;;;AAT7B;;;;EAGkB,QAAA,CAAA,EAAA,MAAA;EAEO,kBAAQ,CAAA,EAcV,OAAA,CAAQ,kBAdE,GAAA,KAAA;CACX;AACD,KAeT,eAAA,GAfiB,CAeE,cAfF,GAAA;EACJ,MAAQ,EAAA,SAAA;CACZ,CAAA,GAaoD,iBAb5C;AAUN,UAKN,iBAAA,CALc;EAAkB,MAAA,EAAA,MAAA;EAGrC;AAEZ;AAgBA;EAAiD,QAAA,CAAA,EAAA,MAAA;EACzC,UAAA,CAAA,EAVO,aAUP;EACO,KAAA,CAAA,EAVL,MAUK,CAAA,MAAA,EAAA,OAAA,CAAA;EACR;;;EAIU,UAAA,CAAA,EAAA,OAAA;AAGjB;AAA4C,UAV3B,gBAU2B,CAAA,eAVK,MAUL,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA;EAgBD,IAAA,EAzBnC,UAyBmC;eAxB5B;OACR;EAuB8E,KAAA,EAtB5E,KAsB4E;EAUzD,QAAA,EAAA,MAAA;EAAqB,OAAA,EA7BtC,MA6BsC,CAAA,MAAA,EAAA,OAAA,CAAA,GAAA,IAAA;;AAGL,iBA7B5B,cAAA,CA6B4B,UAAA,CAAA,EA7BA,eA6BA,CAAA,EAAA;EAC7B,MAAA,CAAA,QAAA,EAAA,MAAA,EAAA,KAAA,CAAA,EAd4B,MAc5B,CAAA,MAAA,EAAA,OAAA,CAAA,EAAA,QAAA,CAAA,EAAA,MAAA,CAAA,EAdsE,OActE,CAAA;IACiB,OAAA,YAAA;IAAjB,GAAA,CAAA,iBAAA;EAAR,CAAA,CAAA;EAAO;AAmCd;;EACW,WAAA,CAAA,IAAA,EAzCiB,UAyCjB,CAAA,EAzC8B,OAyC9B,CAzCsC,KAyCtC,CAAA;EACM,OAAA,CAAA,oBAAA,MAAA,GAvC2B,MAuC3B,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA,OAAA,EAtCF,iBAsCE,CAAA,EArCV,OAqCU,CArCF,gBAqCE,CArCe,WAqCf,CAAA,CAAA;CAEW;;;;iBAJN,wCAAwC,kCACnD;eACM;IAEd,QAAQ,iBAAiB;;;;;;iBCxHN,UAAA,qDAA+D,MAAG;WAuB3E;EF7BD,GAAA,CAAA,EE8BF,eF9BgB;CAAG,CAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["instance: ReturnType<typeof createProcessor> | undefined","executeMdx"],"sources":["../src/utils.ts","../src/compile.ts","../src/index.ts"],"sourcesContent":["import type { Pluggable } from 'unified';\nimport matter from 'gray-matter';\n\nexport type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);\n\nexport function pluginOption(\n def: (v: Pluggable[]) => (Pluggable | false | null)[],\n options: ResolvePlugins = [],\n): Pluggable[] {\n const list = def(Array.isArray(options) ? options : []).filter(Boolean) as Pluggable[];\n\n if (typeof options === 'function') {\n return options(list);\n }\n\n return list;\n}\n\n/**\n * Parse frontmatter, currently powered by `gray-matter`\n */\nexport function parseFrontmatter(content: string) {\n const out = matter(content);\n\n return {\n frontmatter: out.data,\n content: out.content,\n };\n}\n","import * as Plugins from '@hanzo/docs-core/mdx-plugins';\nimport { type CompileOptions, createProcessor } from '@mdx-js/mdx';\nimport type { MDXComponents } from 'mdx/types';\nimport { parseFrontmatter, pluginOption, type ResolvePlugins } from './utils';\nimport type { Compatible, VFile } from 'vfile';\nimport type { TableOfContents } from '@hanzo/docs-core/toc';\nimport { executeMdx, type MdxContent } from '@/render';\nimport { pathToFileURL } from 'node:url';\n\nexport type FumadocsPresetOptions = Omit<CompileOptions, 'remarkPlugins' | 'rehypePlugins'> & {\n preset?: 'hanzo-docs';\n remarkPlugins?: ResolvePlugins;\n rehypePlugins?: ResolvePlugins;\n\n remarkHeadingOptions?: Plugins.RemarkHeadingOptions | false;\n rehypeCodeOptions?: Plugins.RehypeCodeOptions | false;\n rehypeTocOptions?: Plugins.RehypeTocOptions | false;\n remarkCodeTabOptions?: Plugins.RemarkCodeTabOptions | false;\n remarkNpmOptions?: Plugins.RemarkNpmOptions | false;\n\n /**\n * The directory to find image sizes\n *\n * @defaultValue './public'\n * @deprecated Use `remarkImageOptions.publicDir` instead\n */\n imageDir?: string;\n\n remarkImageOptions?: Plugins.RemarkImageOptions | false;\n};\n\nexport type CompilerOptions = (CompileOptions & { preset: 'minimal' }) | FumadocsPresetOptions;\n\nexport interface CompileMDXOptions {\n source: string;\n /**\n * File path of source content\n */\n filePath?: string;\n\n components?: MDXComponents;\n scope?: Record<string, unknown>;\n\n /**\n * @deprecated Use `compiler.compileFile` instead if you doesn't need to execute output JavaScript code.\n */\n skipRender?: boolean;\n}\n\nexport interface CompileMDXResult<TFrontmatter = Record<string, unknown>> {\n body: MdxContent;\n frontmatter: TFrontmatter;\n toc: TableOfContents;\n vfile: VFile;\n\n compiled: string;\n exports: Record<string, unknown> | null;\n}\n\nexport function createCompiler(mdxOptions?: CompilerOptions) {\n let instance: ReturnType<typeof createProcessor> | undefined;\n\n function getProcessor() {\n if (instance) return instance;\n\n let format = mdxOptions?.format;\n if (!format || format === 'detect') format = 'mdx';\n\n return (instance = createProcessor({\n ...(mdxOptions?.preset === 'minimal' ? mdxOptions : getCompileOptions(mdxOptions)),\n format,\n }));\n }\n\n return {\n async render(compiled: string, scope?: Record<string, unknown>, filePath?: string) {\n return executeMdx(compiled, {\n scope,\n baseUrl: filePath ? pathToFileURL(filePath) : undefined,\n jsxRuntime: mdxOptions?.development ? await import('react/jsx-dev-runtime') : undefined,\n });\n },\n /**\n * Compile VFile\n */\n async compileFile(from: Compatible): Promise<VFile> {\n return getProcessor().process(from);\n },\n async compile<Frontmatter extends object = Record<string, unknown>>(\n options: CompileMDXOptions,\n ): Promise<CompileMDXResult<Frontmatter>> {\n const { scope = {}, skipRender } = options;\n const { frontmatter, content } = parseFrontmatter(options.source);\n\n const file = await this.compileFile({\n value: content,\n path: options.filePath,\n data: {\n frontmatter,\n },\n });\n const compiled = String(file);\n const exports = !skipRender ? await this.render(compiled, scope, options.filePath) : null;\n\n return {\n vfile: file,\n compiled,\n frontmatter: frontmatter as Frontmatter,\n async body(props) {\n if (!exports) throw new Error('Body cannot be rendered when `skipRender` is set to true');\n\n return exports.default({\n components: { ...options.components, ...props.components },\n });\n },\n toc: exports?.toc ?? (file.data.toc as TableOfContents),\n exports,\n };\n },\n };\n}\n\n/**\n * @deprecated Use `createCompiler()` API instead, this function will always create a new compiler instance.\n */\nexport async function compileMDX<Frontmatter extends object = Record<string, unknown>>(\n options: CompileMDXOptions & {\n mdxOptions?: CompilerOptions;\n },\n): Promise<CompileMDXResult<Frontmatter>> {\n const compiler = createCompiler(options.mdxOptions);\n\n return compiler.compile(options);\n}\n\nfunction getCompileOptions({\n preset: _,\n rehypeCodeOptions,\n remarkImageOptions,\n rehypeTocOptions,\n remarkHeadingOptions,\n remarkCodeTabOptions,\n remarkNpmOptions,\n imageDir = './public',\n ...options\n}: FumadocsPresetOptions = {}): CompileOptions {\n function getPlugin<K extends keyof typeof Plugins>(name: K): (typeof Plugins)[K] | null {\n return name in Plugins ? Plugins[name] : null;\n }\n const remarkGfm = getPlugin('remarkGfm');\n const remarkHeading = getPlugin('remarkHeading');\n const remarkCodeTab = getPlugin('remarkCodeTab');\n const remarkNpm = getPlugin('remarkNpm');\n const remarkImage = getPlugin('remarkImage');\n const rehypeCode = getPlugin('rehypeCode');\n const rehypeToc = getPlugin('rehypeToc');\n\n return {\n ...options,\n outputFormat: 'function-body',\n remarkPlugins: pluginOption(\n (v) => [\n remarkGfm,\n remarkHeading && remarkHeadingOptions !== false\n ? [remarkHeading, remarkHeadingOptions]\n : null,\n remarkImage && remarkImageOptions !== false\n ? [\n remarkImage,\n {\n useImport: false,\n publicDir: imageDir,\n ...remarkImageOptions,\n } satisfies Plugins.RemarkImageOptions,\n ]\n : null,\n remarkCodeTab && remarkCodeTabOptions !== false\n ? [remarkCodeTab, remarkCodeTabOptions]\n : null,\n remarkNpm && remarkNpmOptions !== false ? [remarkNpm, remarkNpmOptions] : null,\n ...v,\n ],\n options.remarkPlugins,\n ),\n rehypePlugins: pluginOption(\n (v) => [\n rehypeCode && rehypeCodeOptions !== false ? [rehypeCode, rehypeCodeOptions] : null,\n rehypeToc && rehypeTocOptions !== false ? [rehypeToc, rehypeTocOptions] : null,\n ...v,\n ],\n options.rehypePlugins,\n ),\n };\n}\n\n// backward compatible\nexport type { CompilerOptions as MDXOptions };\n","import type { TableOfContents } from '@hanzo/docs-core/toc';\nimport type { MdxContent } from '@/render';\n\nexport * from './compile';\nexport { parseFrontmatter } from './utils';\n\n/**\n * @deprecated Use `compiler.render` instead\n */\nexport async function executeMdx(compiled: string, scope: object, baseUrl?: string | URL) {\n let jsxRuntime;\n\n if (process.env.NODE_ENV === 'production') {\n jsxRuntime = await import('react/jsx-runtime');\n } else {\n jsxRuntime = await import('react/jsx-dev-runtime');\n }\n\n const fullScope = {\n opts: {\n ...jsxRuntime,\n baseUrl,\n },\n ...scope,\n };\n\n const values = Object.values(fullScope);\n const params = Object.keys(fullScope);\n params.push(`return (async () => { ${compiled} })()`);\n const hydrateFn = new Function(...params);\n\n return (await hydrateFn.apply(hydrateFn, values)) as {\n default: MdxContent;\n toc?: TableOfContents;\n };\n}\n"],"mappings":";;;;;;;AAKA,SAAgB,aACd,KACA,UAA0B,EAAE,EACf;CACb,MAAM,OAAO,IAAI,MAAM,QAAQ,QAAQ,GAAG,UAAU,EAAE,CAAC,CAAC,OAAO,QAAQ;AAEvE,KAAI,OAAO,YAAY,WACrB,QAAO,QAAQ,KAAK;AAGtB,QAAO;;;;;AAMT,SAAgB,iBAAiB,SAAiB;CAChD,MAAM,MAAM,OAAO,QAAQ;AAE3B,QAAO;EACL,aAAa,IAAI;EACjB,SAAS,IAAI;EACd;;;;;ACgCH,SAAgB,eAAe,YAA8B;CAC3D,IAAIA;CAEJ,SAAS,eAAe;AACtB,MAAI,SAAU,QAAO;EAErB,IAAI,SAAS,YAAY;AACzB,MAAI,CAAC,UAAU,WAAW,SAAU,UAAS;AAE7C,SAAQ,WAAW,gBAAgB;GACjC,GAAI,YAAY,WAAW,YAAY,aAAa,kBAAkB,WAAW;GACjF;GACD,CAAC;;AAGJ,QAAO;EACL,MAAM,OAAO,UAAkB,OAAiC,UAAmB;AACjF,UAAOC,aAAW,UAAU;IAC1B;IACA,SAAS,WAAW,cAAc,SAAS,GAAG;IAC9C,YAAY,YAAY,cAAc,MAAM,OAAO,2BAA2B;IAC/E,CAAC;;EAKJ,MAAM,YAAY,MAAkC;AAClD,UAAO,cAAc,CAAC,QAAQ,KAAK;;EAErC,MAAM,QACJ,SACwC;GACxC,MAAM,EAAE,QAAQ,EAAE,EAAE,eAAe;GACnC,MAAM,EAAE,aAAa,YAAY,iBAAiB,QAAQ,OAAO;GAEjE,MAAM,OA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AC,WAAW,iBAAiB,GAAG;GAC1E,GAAG;GACJ,EACD,QAAQ,cACT;EACD,eAAe,cACZ,MAAM;GACL,cAAc,sBAAsB,QAAQ,CAAC,YAAY,kBAAkB,GAAG;GAC9E,aAAa,qBAAqB,QAAQ,CAAC,WAAW,iBAAiB,GAAG;GAC1E,GAAG;GACJ,EACD,QAAQ,cACT;EACF;;;;;;;;ACvLH,eAAsB,WAAW,UAAkB,OAAe,SAAwB;CACxF,IAAI;AAEJ,KAAI,QAAQ,IAAI,aAAa,aAC3B,cAAa,MAAM,OAAO;KAE1B,cAAa,MAAM,OAAO;CAG5B,MAAM,YAAY;EAChB,MAAM;GACJ,GAAG;GACH;GACD;EACD,GAAG;EACJ;CAED,MAAM,SAAS,OAAO,OAAO,UAAU;CACvC,MAAM,SAAS,OAAO,KAAK,UAAU;AACrC,QAAO,KAAK,yBAAyB,SAAS,OAAO;CACrD,MAAM,YAAY,IAAI,SAAS,GAAG,OAAO;AAEzC,QAAQ,MAAM,UAAU,MAAM,WAAW,OAAO"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["executeMdx"],"sources":["../src/utils.ts","../src/compile.ts","../src/index.ts"],"sourcesContent":["import type { Pluggable } from 'unified';\nimport matter from 'gray-matter';\n\nexport type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);\n\nexport function pluginOption(\n def: (v: Pluggable[]) => (Pluggable | false | null)[],\n options: ResolvePlugins = [],\n): Pluggable[] {\n const list = def(Array.isArray(options) ? options : []).filter(Boolean) as Pluggable[];\n\n if (typeof options === 'function') {\n return options(list);\n }\n\n return list;\n}\n\n/**\n * Parse frontmatter, currently powered by `gray-matter`\n */\nexport function parseFrontmatter(content: string) {\n const out = matter(content);\n\n return {\n frontmatter: out.data,\n content: out.content,\n };\n}\n","import * as Plugins from '@hanzo/docs-core/mdx-plugins';\nimport { type CompileOptions, createProcessor } from '@mdx-js/mdx';\nimport type { MDXComponents } from 'mdx/types';\nimport { parseFrontmatter, pluginOption, type ResolvePlugins } from './utils';\nimport type { Compatible, VFile } from 'vfile';\nimport type { TableOfContents } from '@hanzo/docs-core/toc';\nimport { executeMdx, type MdxContent } from '@/render';\nimport { pathToFileURL } from 'node:url';\n\nexport type DocsPresetOptions = Omit<CompileOptions, 'remarkPlugins' | 'rehypePlugins'> & {\n preset?: 'hanzo-docs';\n remarkPlugins?: ResolvePlugins;\n rehypePlugins?: ResolvePlugins;\n\n remarkHeadingOptions?: Plugins.RemarkHeadingOptions | false;\n rehypeCodeOptions?: Plugins.RehypeCodeOptions | false;\n rehypeTocOptions?: Plugins.RehypeTocOptions | false;\n remarkCodeTabOptions?: Plugins.RemarkCodeTabOptions | false;\n remarkNpmOptions?: Plugins.RemarkNpmOptions | false;\n\n /**\n * The directory to find image sizes\n *\n * @defaultValue './public'\n * @deprecated Use `remarkImageOptions.publicDir` instead\n */\n imageDir?: string;\n\n remarkImageOptions?: Plugins.RemarkImageOptions | false;\n};\n\nexport type CompilerOptions = (CompileOptions & { preset: 'minimal' }) | DocsPresetOptions;\n\nexport interface CompileMDXOptions {\n source: string;\n /**\n * File path of source content\n */\n filePath?: string;\n\n components?: MDXComponents;\n scope?: Record<string, unknown>;\n\n /**\n * @deprecated Use `compiler.compileFile` instead if you doesn't need to execute output JavaScript code.\n */\n skipRender?: boolean;\n}\n\nexport interface CompileMDXResult<TFrontmatter = Record<string, unknown>> {\n body: MdxContent;\n frontmatter: TFrontmatter;\n toc: TableOfContents;\n vfile: VFile;\n\n compiled: string;\n exports: Record<string, unknown> | null;\n}\n\nexport function createCompiler(mdxOptions?: CompilerOptions) {\n let instance: ReturnType<typeof createProcessor> | undefined;\n\n function getProcessor() {\n if (instance) return instance;\n\n let format = mdxOptions?.format;\n if (!format || format === 'detect') format = 'mdx';\n\n return (instance = createProcessor({\n ...(mdxOptions?.preset === 'minimal' ? mdxOptions : getCompileOptions(mdxOptions)),\n format,\n }));\n }\n\n return {\n async render(compiled: string, scope?: Record<string, unknown>, filePath?: string) {\n return executeMdx(compiled, {\n scope,\n baseUrl: filePath ? pathToFileURL(filePath) : undefined,\n jsxRuntime: mdxOptions?.development ? await import('react/jsx-dev-runtime') : undefined,\n });\n },\n /**\n * Compile VFile\n */\n async compileFile(from: Compatible): Promise<VFile> {\n return getProcessor().process(from);\n },\n async compile<Frontmatter extends object = Record<string, unknown>>(\n options: CompileMDXOptions,\n ): Promise<CompileMDXResult<Frontmatter>> {\n const { scope = {}, skipRender } = options;\n const { frontmatter, content } = parseFrontmatter(options.source);\n\n const file = await this.compileFile({\n value: content,\n path: options.filePath,\n data: {\n frontmatter,\n },\n });\n const compiled = String(file);\n const exports = !skipRender ? await this.render(compiled, scope, options.filePath) : null;\n\n return {\n vfile: file,\n compiled,\n frontmatter: frontmatter as Frontmatter,\n async body(props) {\n if (!exports) throw new Error('Body cannot be rendered when `skipRender` is set to true');\n\n return exports.default({\n components: { ...options.components, ...props.components },\n });\n },\n toc: exports?.toc ?? (file.data.toc as TableOfContents),\n exports,\n };\n },\n };\n}\n\n/**\n * @deprecated Use `createCompiler()` API instead, this function will always create a new compiler instance.\n */\nexport async function compileMDX<Frontmatter extends object = Record<string, unknown>>(\n options: CompileMDXOptions & {\n mdxOptions?: CompilerOptions;\n },\n): Promise<CompileMDXResult<Frontmatter>> {\n const compiler = createCompiler(options.mdxOptions);\n\n return compiler.compile(options);\n}\n\nfunction getCompileOptions({\n preset: _,\n rehypeCodeOptions,\n remarkImageOptions,\n rehypeTocOptions,\n remarkHeadingOptions,\n remarkCodeTabOptions,\n remarkNpmOptions,\n imageDir = './public',\n ...options\n}: DocsPresetOptions = {}): CompileOptions {\n function getPlugin<K extends keyof typeof Plugins>(name: K): (typeof Plugins)[K] | null {\n return name in Plugins ? Plugins[name] : null;\n }\n const remarkGfm = getPlugin('remarkGfm');\n const remarkHeading = getPlugin('remarkHeading');\n const remarkCodeTab = getPlugin('remarkCodeTab');\n const remarkNpm = getPlugin('remarkNpm');\n const remarkImage = getPlugin('remarkImage');\n const rehypeCode = getPlugin('rehypeCode');\n const rehypeToc = getPlugin('rehypeToc');\n\n return {\n ...options,\n outputFormat: 'function-body',\n remarkPlugins: pluginOption(\n (v) => [\n remarkGfm,\n remarkHeading && remarkHeadingOptions !== false\n ? [remarkHeading, remarkHeadingOptions]\n : null,\n remarkImage && remarkImageOptions !== false\n ? [\n remarkImage,\n {\n useImport: false,\n publicDir: imageDir,\n ...remarkImageOptions,\n } satisfies Plugins.RemarkImageOptions,\n ]\n : null,\n remarkCodeTab && remarkCodeTabOptions !== false\n ? [remarkCodeTab, remarkCodeTabOptions]\n : null,\n remarkNpm && remarkNpmOptions !== false ? [remarkNpm, remarkNpmOptions] : null,\n ...v,\n ],\n options.remarkPlugins,\n ),\n rehypePlugins: pluginOption(\n (v) => [\n rehypeCode && rehypeCodeOptions !== false ? [rehypeCode, rehypeCodeOptions] : null,\n rehypeToc && rehypeTocOptions !== false ? [rehypeToc, rehypeTocOptions] : null,\n ...v,\n ],\n options.rehypePlugins,\n ),\n };\n}\n\n// backward compatible\nexport type { CompilerOptions as MDXOptions };\n","import type { TableOfContents } from '@hanzo/docs-core/toc';\nimport type { MdxContent } from '@/render';\n\nexport * from './compile';\nexport { parseFrontmatter } from './utils';\n\n/**\n * @deprecated Use `compiler.render` instead\n */\nexport async function executeMdx(compiled: string, scope: object, baseUrl?: string | URL) {\n let jsxRuntime;\n\n if (process.env.NODE_ENV === 'production') {\n jsxRuntime = await import('react/jsx-runtime');\n } else {\n jsxRuntime = await import('react/jsx-dev-runtime');\n }\n\n const fullScope = {\n opts: {\n ...jsxRuntime,\n baseUrl,\n },\n ...scope,\n };\n\n const values = Object.values(fullScope);\n const params = Object.keys(fullScope);\n params.push(`return (async () => { ${compiled} })()`);\n const hydrateFn = new Function(...params);\n\n return (await hydrateFn.apply(hydrateFn, values)) as {\n default: MdxContent;\n toc?: TableOfContents;\n };\n}\n"],"mappings":";;;;;;;AAKA,SAAgB,aACd,KACA,UAA0B,EAAE,EACf;CACb,MAAM,OA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AAO;KAE1B,cAAa,MAAM,OAAO;CAG5B,MAAM,YAAY;EAChB,MAAM;GACJ,GAAG;GACH;GACD;EACD,GAAG;EACJ;CAED,MAAM,SAAS,OAAO,OAAO,UAAU;CACvC,MAAM,SAAS,OAAO,KAAK,UAAU;AACrC,QAAO,KAAK,yBAAyB,SAAS,OAAO;CACrD,MAAM,YAAY,IAAI,SAAS,GAAG,OAAO;AAEzC,QAAQ,MAAM,UAAU,MAAM,WAAW,OAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render-DHnSPAbU.js","names":[
|
|
1
|
+
{"version":3,"file":"render-DHnSPAbU.js","names":[],"sources":["../src/render.ts"],"sourcesContent":["import type { MDXComponents } from 'mdx/types';\nimport type { TableOfContents } from '@hanzo/docs-core/toc';\nimport type { FC } from 'react';\nimport jsxRuntimeDefault from 'react/jsx-runtime';\n\nexport type MdxContent = FC<{ components?: MDXComponents }>;\n\ninterface Options {\n scope?: Record<string, unknown>;\n baseUrl?: string | URL;\n jsxRuntime?: unknown;\n}\n\nconst AsyncFunction: new (...args: string[]) => (...args: unknown[]) => Promise<unknown> =\n Object.getPrototypeOf(executeMdx).constructor;\n\nexport async function executeMdx(compiled: string, options: Options = {}) {\n const { opts: scopeOpts, ...scope } = options.scope ?? {};\n const fullScope = {\n opts: {\n ...(scopeOpts as object),\n ...(options.jsxRuntime ?? jsxRuntimeDefault),\n baseUrl: options.baseUrl,\n },\n ...scope,\n };\n\n const hydrateFn = new AsyncFunction(...Object.keys(fullScope), compiled);\n return (await hydrateFn.apply(hydrateFn, Object.values(fullScope))) as {\n default: MdxContent;\n toc?: TableOfContents;\n };\n}\n\nexport function executeMdxSync(compiled: string, options: Options = {}) {\n const { opts: scopeOpts, ...scope } = options.scope ?? {};\n const fullScope = {\n opts: {\n ...(scopeOpts as object),\n ...(options.jsxRuntime ?? jsxRuntimeDefault),\n baseUrl: options.baseUrl,\n },\n ...scope,\n };\n\n const hydrateFn = new Function(...Object.keys(fullScope), compiled);\n\n return hydrateFn.apply(hydrateFn, Object.values(fullScope)) as {\n default: MdxContent;\n toc?: TableOfContents;\n };\n}\n"],"mappings":";;;AAaA,MAAM,gBACJ,OAAO,eAAe,WAAW,CAAC;AAEpC,eAAsB,WAAW,UAAkB,UAAmB,EAAE,EAAE;CACxE,MAAM,EAAE,MAAM,WAAW,GAAG,UAAU,QAAQ,SAAS,EAAE;CACzD,MAAM,YAAY;EAChB,MAAM;GACJ,GAAI;GACJ,GAAI,QAAQ,cAAc;GAC1B,SAAS,QAAQ;GAClB;EACD,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,cAAc,GAAG,OAAO,KAAK,UAAU,EAAE,SAAS;AACxE,QAAQ,MAAM,UAAU,MAAM,WAAW,OAAO,OAAO,UAAU,CAAC;;AAMpE,SAAgB,eAAe,UAAkB,UAAmB,EAAE,EAAE;CACtE,MAAM,EAAE,MAAM,WAAW,GAAG,UAAU,QAAQ,SAAS,EAAE;CACzD,MAAM,YAAY;EAChB,MAAM;GACJ,GAAI;GACJ,GAAI,QAAQ,cAAc;GAC1B,SAAS,QAAQ;GAClB;EACD,GAAG;EACJ;CAED,MAAM,YAAY,IAAI,SAAS,GAAG,OAAO,KAAK,UAAU,EAAE,SAAS;AAEnE,QAAO,UAAU,MAAM,WAAW,OAAO,OAAO,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzo/mdx-runtime",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.1",
|
|
4
4
|
"description": "Runtime MDX compilation and execution for Hanzo Docs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
],
|
|
11
11
|
"homepage": "https://hanzo.ai/docs",
|
|
12
12
|
"license": "MIT",
|
|
13
|
-
"author": "
|
|
13
|
+
"author": "Hanzo AI",
|
|
14
14
|
"repository": "github:hanzoai/docs",
|
|
15
15
|
"files": [
|
|
16
16
|
"dist/*"
|
|
@@ -34,20 +34,20 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@mdx-js/mdx": "^3.1.1",
|
|
36
36
|
"gray-matter": "^4.0.3",
|
|
37
|
-
"
|
|
37
|
+
"unified": "^11.0.5",
|
|
38
|
+
"vfile": "^6.0.3",
|
|
39
|
+
"zod": "^4.3.6"
|
|
38
40
|
},
|
|
39
41
|
"devDependencies": {
|
|
40
42
|
"@types/mdx": "^2.0.13",
|
|
41
|
-
"@types/node": "
|
|
42
|
-
"@types/react": "^19.2.
|
|
43
|
+
"@types/node": "25.0.10",
|
|
44
|
+
"@types/react": "^19.2.9",
|
|
43
45
|
"react": "^19.2.3",
|
|
44
46
|
"tinyglobby": "^0.2.15",
|
|
45
|
-
"tsdown": "^0.
|
|
46
|
-
"unified": "^11.0.5",
|
|
47
|
-
"vfile": "^6.0.3",
|
|
47
|
+
"tsdown": "^0.19.0",
|
|
48
48
|
"eslint-config-custom": "0.0.0",
|
|
49
|
-
"
|
|
50
|
-
"
|
|
49
|
+
"@hanzo/docs-core": "16.5.3",
|
|
50
|
+
"tsconfig": "0.0.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"@types/react": "*",
|