@hanzo/mdx-runtime 1.5.2 → 1.6.0

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 CHANGED
@@ -19,7 +19,7 @@ declare function parseFrontmatter(content: string): {
19
19
  };
20
20
  //#endregion
21
21
  //#region src/compile.d.ts
22
- type FumadocsPresetOptions = Omit<CompileOptions, 'remarkPlugins' | 'rehypePlugins'> & {
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
- }) | FumadocsPresetOptions;
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, FumadocsPresetOptions, compileMDX, createCompiler, executeMdx, parseFrontmatter };
91
+ export { CompileMDXOptions, CompileMDXResult, CompilerOptions, type CompilerOptions as MDXOptions, DocsPresetOptions, compileMDX, createCompiler, executeMdx, parseFrontmatter };
92
92
  //# sourceMappingURL=index.d.ts.map
@@ -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,qBAAA,GAAwB,KAAK;;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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;IAC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,YAAY;AAExC,QAAO;EACL,GAAG;EACH,cAAc;EACd,eAAe,cACZ,MAAM;GACL;GACA,iBAAiB,yBAAyB,QACtC,CAAC,eAAe,qBAAqB,GACrC;GACJ,eAAe,uBAAuB,QAClC,CACE,aACA;IACE,WAAW;IACX,WAAW;IACX,GAAG;IACJ,CACF,GACD;GACJ,iBAAiB,yBAAyB,QACtC,CAAC,eAAe,qBAAqB,GACrC;GACJ,aAAa,qBAAqB,QAAQ,CAAC,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":["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 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,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,OAAO,MAAM,KAAK,YAAY;IAClC,OAA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AAG;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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hanzo/mdx-runtime",
3
- "version": "1.5.2",
3
+ "version": "1.6.0",
4
4
  "description": "Runtime MDX compilation and execution for Hanzo Docs",
5
5
  "keywords": [
6
6
  "Docs",
@@ -31,6 +31,13 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
+ "scripts": {
35
+ "build": "tsdown",
36
+ "clean": "rimraf dist",
37
+ "dev": "tsdown --watch",
38
+ "lint": "eslint .",
39
+ "types:check": "tsc --noEmit"
40
+ },
34
41
  "dependencies": {
35
42
  "@mdx-js/mdx": "^3.1.1",
36
43
  "gray-matter": "^4.0.3",
@@ -40,14 +47,14 @@
40
47
  "@types/mdx": "^2.0.13",
41
48
  "@types/node": "24.10.2",
42
49
  "@types/react": "^19.2.7",
50
+ "eslint-config-custom": "workspace:*",
51
+ "@hanzo/docs-core": "workspace:*",
43
52
  "react": "^19.2.3",
44
53
  "tinyglobby": "^0.2.15",
54
+ "tsconfig": "workspace:*",
45
55
  "tsdown": "^0.18.3",
46
56
  "unified": "^11.0.5",
47
- "vfile": "^6.0.3",
48
- "eslint-config-custom": "0.0.0",
49
- "tsconfig": "0.0.0",
50
- "@hanzo/docs-core": "16.4.3"
57
+ "vfile": "^6.0.3"
51
58
  },
52
59
  "peerDependencies": {
53
60
  "@types/react": "*",
@@ -58,12 +65,5 @@
58
65
  "@types/react": {
59
66
  "optional": true
60
67
  }
61
- },
62
- "scripts": {
63
- "build": "tsdown",
64
- "clean": "rimraf dist",
65
- "dev": "tsdown --watch",
66
- "lint": "eslint .",
67
- "types:check": "tsc --noEmit"
68
68
  }
69
- }
69
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Fuma
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.