fumadocs-core 16.4.6 → 16.4.7
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/advanced-tbtFDsHU.js.map +1 -1
- package/dist/{algolia-B9GvomyW.d.ts → algolia-BFVpYDZ_.d.ts} +1 -1
- package/dist/{algolia-B9GvomyW.d.ts.map → algolia-BFVpYDZ_.d.ts.map} +1 -1
- package/dist/algolia-Dbt0kj8j.js.map +1 -1
- package/dist/breadcrumb.js.map +1 -1
- package/dist/content/index.d.ts.map +1 -1
- package/dist/framework/index.d.ts +4 -4
- package/dist/framework/next.d.ts +2 -2
- package/dist/framework/react-router.d.ts +2 -2
- package/dist/framework/react-router.js.map +1 -1
- package/dist/framework/tanstack.d.ts +2 -2
- package/dist/framework/tanstack.js.map +1 -1
- package/dist/framework/waku.d.ts +2 -2
- package/dist/framework/waku.js.map +1 -1
- package/dist/highlight/client.js.map +1 -1
- package/dist/i18n/middleware.js.map +1 -1
- package/dist/index-BaMZ8PEK.d.ts +45 -0
- package/dist/index-BaMZ8PEK.d.ts.map +1 -0
- package/dist/index-CmGSoB4T.d.ts +18 -0
- package/dist/index-CmGSoB4T.d.ts.map +1 -0
- package/dist/{index-k5KwKJ_c.d.ts → index-aE27-b16.d.ts} +3 -2
- package/dist/index-aE27-b16.d.ts.map +1 -0
- package/dist/mdx-plugins/codeblock-utils.js.map +1 -1
- package/dist/mdx-plugins/remark-code-tab.js.map +1 -1
- package/dist/mdx-plugins/remark-directive-admonition.js.map +1 -1
- package/dist/mdx-plugins/remark-feedback-block.js.map +1 -1
- package/dist/mdx-plugins/remark-heading.js.map +1 -1
- package/dist/mdx-plugins/remark-image.js.map +1 -1
- package/dist/mdx-plugins/remark-mdx-files.js.map +1 -1
- package/dist/mdx-plugins/remark-npm.js.map +1 -1
- package/dist/mdx-plugins/remark-steps.js.map +1 -1
- package/dist/mdx-plugins/remark-structure.js.map +1 -1
- package/dist/{mixedbread-B0TvOHtt.js → mixedbread-CPGJEgwq.js} +2 -2
- package/dist/mixedbread-CPGJEgwq.js.map +1 -0
- package/dist/negotiation/index.js.map +1 -1
- package/dist/orama-cloud-legacy-NJTbB19B.js.map +1 -1
- package/dist/orama-cloud-yicpgD0c.js.map +1 -1
- package/dist/page-tree/index.d.ts +2 -44
- package/dist/rehype-code-Ct5Pb6BZ.js.map +1 -1
- package/dist/rehype-toc-CTG0x7La.js.map +1 -1
- package/dist/search/algolia.d.ts +1 -1
- package/dist/search/algolia.js.map +1 -1
- package/dist/search/client.d.ts +5 -3
- package/dist/search/client.d.ts.map +1 -1
- package/dist/search/client.js +1 -1
- package/dist/search/orama-cloud-legacy.js.map +1 -1
- package/dist/search/orama-cloud.js.map +1 -1
- package/dist/search/server.d.ts +4 -2
- package/dist/search/server.js.map +1 -1
- package/dist/search-DzqmOjzV.js.map +1 -1
- package/dist/{server-CjGgVKx_.d.ts → server-CLPpotS9.d.ts} +2 -2
- package/dist/{server-CjGgVKx_.d.ts.map → server-CLPpotS9.d.ts.map} +1 -1
- package/dist/shiki-B4NO99XD.js.map +1 -1
- package/dist/source/client/index.d.ts +4 -18
- package/dist/source/client/index.js +16 -9
- package/dist/source/client/index.js.map +1 -1
- package/dist/source/index.d.ts +3 -1
- package/dist/source/index.js +10 -7
- package/dist/source/index.js.map +1 -1
- package/dist/source/plugins/lucide-icons.d.ts +3 -1
- package/dist/source/plugins/lucide-icons.d.ts.map +1 -1
- package/dist/source/plugins/slugs.d.ts +3 -1
- package/dist/source/plugins/slugs.js.map +1 -1
- package/dist/static-C_WBOzek.js.map +1 -1
- package/dist/toc.js.map +1 -1
- package/dist/utils/use-effect-event.js.map +1 -1
- package/dist/utils-D10VxgVc.js.map +1 -1
- package/package.json +5 -5
- package/dist/index-k5KwKJ_c.d.ts.map +0 -1
- package/dist/mixedbread-B0TvOHtt.js.map +0 -1
- package/dist/page-tree/index.d.ts.map +0 -1
- package/dist/source/client/index.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-image.js","names":["path","importsToInject: { variableName: string; importPath: string }[]","promises: Promise<void>[]","attributes: MdxJsxAttribute[]","out: MdxJsxFlowElement"],"sources":["../../src/mdx-plugins/remark-image.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { Image, Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { MdxjsEsm } from 'mdast-util-mdxjs-esm';\nimport type { ISizeCalculationResult } from 'image-size/types/interface';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { fileURLToPath } from 'node:url';\n\nconst VALID_BLUR_EXT = ['.jpeg', '.png', '.webp', '.avif', '.jpg'];\nconst EXTERNAL_URL_REGEX = /^https?:\\/\\//;\n\ntype ExternalImageOptions =\n | {\n /**\n * timeout for fetching remote images (in milliseconds)\n */\n timeout?: number;\n }\n | boolean;\n\nexport interface RemarkImageOptions {\n /**\n * Directory or base URL to resolve absolute image paths\n */\n publicDir?: string;\n\n /**\n * Preferred placeholder type, only available with `useImport` + local images.\n *\n * @defaultValue 'blur'\n */\n placeholder?: 'blur' | 'none';\n\n /**\n * Define how to handle errors when fetching image size.\n *\n * - `error` (default): throw an error.\n * - `ignore`: do absolutely nothing (Next.js Image component may complain).\n * - `hide`: remove that image element.\n *\n * @defaultValue 'error'\n */\n onError?: 'error' | 'hide' | 'ignore' | ((error: Error) => void);\n\n /**\n * Import images in the file, and let bundlers handle it.\n *\n * ```tsx\n * import MyImage from \"./public/img.png\";\n *\n * <img src={MyImage} />\n * ```\n *\n * When disabled, `placeholder` will be ignored.\n *\n * @defaultValue true\n */\n useImport?: boolean;\n\n /**\n * Fetch image size of external URLs\n *\n * @defaultValue true\n */\n external?: ExternalImageOptions;\n}\n\ntype Source =\n | {\n type: 'url';\n url: URL;\n }\n | {\n type: 'file';\n file: string;\n };\n\n/**\n * Turn images into Next.js Image compatible usage.\n */\nexport function remarkImage({\n placeholder = 'blur',\n external = true,\n useImport = true,\n onError = 'error',\n publicDir = path.join(process.cwd(), 'public'),\n}: RemarkImageOptions = {}): Transformer<Root, Root> {\n return async (tree, file) => {\n const importsToInject: { variableName: string; importPath: string }[] = [];\n const promises: Promise<void>[] = [];\n\n async function onImage(src: Source, node: Image): Promise<MdxJsxFlowElement | undefined> {\n const attributes: MdxJsxAttribute[] = [\n {\n type: 'mdxJsxAttribute',\n name: 'alt',\n value: node.alt ?? 'image',\n },\n ];\n\n if (node.title) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'title',\n value: node.title,\n });\n }\n\n if (src.type === 'file' && useImport) {\n // Unique variable name for the given static image URL\n const variableName = `__img${importsToInject.length}`;\n const hasBlur =\n placeholder === 'blur' && VALID_BLUR_EXT.some((ext) => src.file.endsWith(ext));\n\n if (!file.dirname) {\n throw new Error(\n 'When `useImport` is enabled, you must specify `dirname` in the VFile passed to compiler.',\n );\n }\n\n importsToInject.push({\n variableName,\n importPath: getImportPath(src.file, file.dirname),\n });\n\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'src',\n value: {\n type: 'mdxJsxAttributeValueExpression',\n value: variableName,\n data: {\n estree: {\n body: [\n {\n type: 'ExpressionStatement',\n expression: { type: 'Identifier', name: variableName },\n },\n ],\n type: 'Program',\n sourceType: 'script',\n },\n },\n },\n });\n\n const out: MdxJsxFlowElement = {\n children: [],\n type: 'mdxJsxFlowElement',\n name: 'img',\n attributes,\n };\n\n if (hasBlur) {\n out.attributes.push({\n type: 'mdxJsxAttribute',\n name: 'placeholder',\n value: 'blur',\n });\n }\n\n return out;\n }\n\n const size = await getImageSize(src, external).catch((e) => {\n throw new Error(\n `[Remark Image] Failed obtain image size for ${node.url} (public directory configured as ${publicDir})`,\n {\n cause: e,\n },\n );\n });\n\n if (!size) return;\n\n attributes.push(\n {\n type: 'mdxJsxAttribute',\n name: 'src',\n // `src` doesn't support file paths, we can use `node.url` for files and let the underlying framework handle it\n value: src.type === 'url' ? src.url.toString() : node.url,\n },\n {\n type: 'mdxJsxAttribute',\n name: 'width',\n value: size.width.toString(),\n },\n {\n type: 'mdxJsxAttribute',\n name: 'height',\n value: size.height.toString(),\n },\n );\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'img',\n attributes,\n children: [],\n };\n }\n\n visit(tree, 'image', (node) => {\n const src = parseSrc(decodeURI(node.url), publicDir, file.dirname);\n if (!src) return;\n\n const task = onImage(src, node)\n .catch((e) => {\n // ignore SVG as it is not always needed\n if (onError === 'ignore' || node.url.endsWith('.svg')) {\n return;\n }\n\n if (onError === 'hide') {\n return {\n type: 'mdxJsxFlowElement',\n name: null,\n attributes: [],\n children: [],\n } satisfies MdxJsxFlowElement;\n }\n\n if (onError === 'error') throw e;\n onError(e);\n })\n .then((res) => {\n if (res) Object.assign(node, res);\n });\n\n promises.push(task);\n });\n\n await Promise.all(promises);\n if (importsToInject.length === 0) return;\n\n const imports = importsToInject.map(\n ({ variableName, importPath }) =>\n ({\n type: 'mdxjsEsm',\n data: {\n estree: {\n body: [\n {\n type: 'ImportDeclaration',\n source: { type: 'Literal', value: importPath },\n specifiers: [\n {\n type: 'ImportDefaultSpecifier',\n local: { type: 'Identifier', name: variableName },\n },\n ],\n },\n ],\n },\n },\n }) as MdxjsEsm,\n );\n\n tree.children.unshift(...imports);\n };\n}\n\nfunction getImportPath(file: string, dir: string): string {\n const relative = path.relative(dir, file).replaceAll(path.sep, '/');\n\n return relative.startsWith('../') ? relative : `./${relative}`;\n}\n\n/**\n * @param src - src href\n * @param publicDir - dir/url to resolve absolute paths\n * @param dir - dir to resolve relative paths\n */\nfunction parseSrc(src: string, publicDir: string, dir?: string): Source | undefined {\n if (src.startsWith('file:///')) return { type: 'file', file: fileURLToPath(src) };\n\n if (EXTERNAL_URL_REGEX.test(src)) {\n return {\n type: 'url',\n url: new URL(src),\n };\n }\n\n if (src.startsWith('/')) {\n if (EXTERNAL_URL_REGEX.test(publicDir)) {\n const url = new URL(publicDir);\n const segs = [...url.pathname.split('/'), ...src.split('/')].filter((v) => v.length > 0);\n\n url.pathname = `/${segs.join('/')}`;\n return { type: 'url', url };\n }\n\n return {\n type: 'file',\n file: path.join(publicDir, src),\n };\n }\n\n if (!dir) {\n console.warn(\n `[Remark Image] found relative path ${src} but missing 'dirname' in VFile, this image will be skipped for now.`,\n );\n return;\n }\n\n return {\n type: 'file',\n file: path.join(dir, src),\n };\n}\n\nasync function getImageSize(\n src: Source,\n onExternal: ExternalImageOptions,\n): Promise<ISizeCalculationResult | undefined> {\n if (src.type === 'file') {\n const { imageSizeFromFile } = await import('image-size/fromFile');\n return imageSizeFromFile(src.file);\n }\n if (onExternal === false) return;\n\n const { timeout } = typeof onExternal === 'object' ? onExternal : {};\n const res = await fetch(src.url, {\n signal: typeof timeout === 'number' ? AbortSignal.timeout(timeout) : undefined,\n });\n if (!res.ok) {\n throw new Error(\n `[Remark Image] Failed to fetch ${src.url} (${res.status}): ${await res.text()}`,\n );\n }\n\n const { imageSize } = await import('image-size');\n return imageSize(new Uint8Array(await res.arrayBuffer()));\n}\n"],"mappings":";;;;;AASA,MAAM,iBAAiB;CAAC;CAAS;CAAQ;CAAS;CAAS;CAAO;AAClE,MAAM,qBAAqB;;;;AAuE3B,SAAgB,YAAY,EAC1B,cAAc,QACd,WAAW,MACX,YAAY,MACZ,UAAU,SACV,YAAYA,OAAK,KAAK,QAAQ,KAAK,EAAE,SAAS,KACxB,EAAE,EAA2B;AACnD,QAAO,OAAO,MAAM,SAAS;EAC3B,MAAMC,kBAAkE,EAAE;EAC1E,MAAMC,WAA4B,EAAE;EAEpC,eAAe,QAAQ,KAAa,MAAqD;GACvF,MAAMC,aAAgC,CACpC;IACE,MAAM;IACN,MAAM;IACN,OAAO,KAAK,OAAO;IACpB,CACF;AAED,OAAI,KAAK,MACP,YAAW,KAAK;IACd,MAAM;IACN,MAAM;IACN,OAAO,KAAK;IACb,CAAC;AAGJ,OAAI,IAAI,SAAS,UAAU,WAAW;IAEpC,MAAM,eAAe,QAAQ,gB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SAAS,MAAM,IAAI,EAAE,GAAG,IAAI,MAAM,IAAI,CAAC,CAAC,QAAQ,MAAM,EAAE,SAAS,EAAE,CAEhE,KAAK,IAAI;AACjC,UAAO;IAAE,MAAM;IAAO;IAAK;;AAG7B,SAAO;GACL,MAAM;GACN,MAAMA,OAAK,KAAK,WAAW,IAAI;GAChC;;AAGH,KAAI,CAAC,KAAK;AACR,UAAQ,KACN,sCAAsC,IAAI,sEAC3C;AACD;;AAGF,QAAO;EACL,MAAM;EACN,MAAMA,OAAK,KAAK,KAAK,IAAI;EAC1B;;AAGH,eAAe,aACb,KACA,YAC6C;AAC7C,KAAI,IAAI,SAAS,QAAQ;EACvB,MAAM,EAAE,sBAAsB,MAAM,OAAO;AAC3C,SAAO,kBAAkB,IAAI,KAAK;;AAEpC,KAAI,eAAe,MAAO;CAE1B,MAAM,EAAE,YAAY,OAAO,eAAe,WAAW,aAAa,EAAE;CACpE,MAAM,MAAM,MAAM,MAAM,IAAI,KAAK,EAC/B,QAAQ,OAAO,YAAY,WAAW,YAAY,QAAQ,QAAQ,GAAG,QACtE,CAAC;AACF,KAAI,CAAC,IAAI,GACP,OAAM,IAAI,MACR,kCAAkC,IAAI,IAAI,IAAI,IAAI,OAAO,KAAK,MAAM,IAAI,MAAM,GAC/E;CAGH,MAAM,EAAE,cAAc,MAAM,OAAO;AACnC,QAAO,UAAU,IAAI,WAAW,MAAM,IAAI,aAAa,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"remark-image.js","names":["path"],"sources":["../../src/mdx-plugins/remark-image.ts"],"sourcesContent":["import * as path from 'node:path';\nimport type { Image, Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { MdxjsEsm } from 'mdast-util-mdxjs-esm';\nimport type { ISizeCalculationResult } from 'image-size/types/interface';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { fileURLToPath } from 'node:url';\n\nconst VALID_BLUR_EXT = ['.jpeg', '.png', '.webp', '.avif', '.jpg'];\nconst EXTERNAL_URL_REGEX = /^https?:\\/\\//;\n\ntype ExternalImageOptions =\n | {\n /**\n * timeout for fetching remote images (in milliseconds)\n */\n timeout?: number;\n }\n | boolean;\n\nexport interface RemarkImageOptions {\n /**\n * Directory or base URL to resolve absolute image paths\n */\n publicDir?: string;\n\n /**\n * Preferred placeholder type, only available with `useImport` + local images.\n *\n * @defaultValue 'blur'\n */\n placeholder?: 'blur' | 'none';\n\n /**\n * Define how to handle errors when fetching image size.\n *\n * - `error` (default): throw an error.\n * - `ignore`: do absolutely nothing (Next.js Image component may complain).\n * - `hide`: remove that image element.\n *\n * @defaultValue 'error'\n */\n onError?: 'error' | 'hide' | 'ignore' | ((error: Error) => void);\n\n /**\n * Import images in the file, and let bundlers handle it.\n *\n * ```tsx\n * import MyImage from \"./public/img.png\";\n *\n * <img src={MyImage} />\n * ```\n *\n * When disabled, `placeholder` will be ignored.\n *\n * @defaultValue true\n */\n useImport?: boolean;\n\n /**\n * Fetch image size of external URLs\n *\n * @defaultValue true\n */\n external?: ExternalImageOptions;\n}\n\ntype Source =\n | {\n type: 'url';\n url: URL;\n }\n | {\n type: 'file';\n file: string;\n };\n\n/**\n * Turn images into Next.js Image compatible usage.\n */\nexport function remarkImage({\n placeholder = 'blur',\n external = true,\n useImport = true,\n onError = 'error',\n publicDir = path.join(process.cwd(), 'public'),\n}: RemarkImageOptions = {}): Transformer<Root, Root> {\n return async (tree, file) => {\n const importsToInject: { variableName: string; importPath: string }[] = [];\n const promises: Promise<void>[] = [];\n\n async function onImage(src: Source, node: Image): Promise<MdxJsxFlowElement | undefined> {\n const attributes: MdxJsxAttribute[] = [\n {\n type: 'mdxJsxAttribute',\n name: 'alt',\n value: node.alt ?? 'image',\n },\n ];\n\n if (node.title) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'title',\n value: node.title,\n });\n }\n\n if (src.type === 'file' && useImport) {\n // Unique variable name for the given static image URL\n const variableName = `__img${importsToInject.length}`;\n const hasBlur =\n placeholder === 'blur' && VALID_BLUR_EXT.some((ext) => src.file.endsWith(ext));\n\n if (!file.dirname) {\n throw new Error(\n 'When `useImport` is enabled, you must specify `dirname` in the VFile passed to compiler.',\n );\n }\n\n importsToInject.push({\n variableName,\n importPath: getImportPath(src.file, file.dirname),\n });\n\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'src',\n value: {\n type: 'mdxJsxAttributeValueExpression',\n value: variableName,\n data: {\n estree: {\n body: [\n {\n type: 'ExpressionStatement',\n expression: { type: 'Identifier', name: variableName },\n },\n ],\n type: 'Program',\n sourceType: 'script',\n },\n },\n },\n });\n\n const out: MdxJsxFlowElement = {\n children: [],\n type: 'mdxJsxFlowElement',\n name: 'img',\n attributes,\n };\n\n if (hasBlur) {\n out.attributes.push({\n type: 'mdxJsxAttribute',\n name: 'placeholder',\n value: 'blur',\n });\n }\n\n return out;\n }\n\n const size = await getImageSize(src, external).catch((e) => {\n throw new Error(\n `[Remark Image] Failed obtain image size for ${node.url} (public directory configured as ${publicDir})`,\n {\n cause: e,\n },\n );\n });\n\n if (!size) return;\n\n attributes.push(\n {\n type: 'mdxJsxAttribute',\n name: 'src',\n // `src` doesn't support file paths, we can use `node.url` for files and let the underlying framework handle it\n value: src.type === 'url' ? src.url.toString() : node.url,\n },\n {\n type: 'mdxJsxAttribute',\n name: 'width',\n value: size.width.toString(),\n },\n {\n type: 'mdxJsxAttribute',\n name: 'height',\n value: size.height.toString(),\n },\n );\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'img',\n attributes,\n children: [],\n };\n }\n\n visit(tree, 'image', (node) => {\n const src = parseSrc(decodeURI(node.url), publicDir, file.dirname);\n if (!src) return;\n\n const task = onImage(src, node)\n .catch((e) => {\n // ignore SVG as it is not always needed\n if (onError === 'ignore' || node.url.endsWith('.svg')) {\n return;\n }\n\n if (onError === 'hide') {\n return {\n type: 'mdxJsxFlowElement',\n name: null,\n attributes: [],\n children: [],\n } satisfies MdxJsxFlowElement;\n }\n\n if (onError === 'error') throw e;\n onError(e);\n })\n .then((res) => {\n if (res) Object.assign(node, res);\n });\n\n promises.push(task);\n });\n\n await Promise.all(promises);\n if (importsToInject.length === 0) return;\n\n const imports = importsToInject.map(\n ({ variableName, importPath }) =>\n ({\n type: 'mdxjsEsm',\n data: {\n estree: {\n body: [\n {\n type: 'ImportDeclaration',\n source: { type: 'Literal', value: importPath },\n specifiers: [\n {\n type: 'ImportDefaultSpecifier',\n local: { type: 'Identifier', name: variableName },\n },\n ],\n },\n ],\n },\n },\n }) as MdxjsEsm,\n );\n\n tree.children.unshift(...imports);\n };\n}\n\nfunction getImportPath(file: string, dir: string): string {\n const relative = path.relative(dir, file).replaceAll(path.sep, '/');\n\n return relative.startsWith('../') ? relative : `./${relative}`;\n}\n\n/**\n * @param src - src href\n * @param publicDir - dir/url to resolve absolute paths\n * @param dir - dir to resolve relative paths\n */\nfunction parseSrc(src: string, publicDir: string, dir?: string): Source | undefined {\n if (src.startsWith('file:///')) return { type: 'file', file: fileURLToPath(src) };\n\n if (EXTERNAL_URL_REGEX.test(src)) {\n return {\n type: 'url',\n url: new URL(src),\n };\n }\n\n if (src.startsWith('/')) {\n if (EXTERNAL_URL_REGEX.test(publicDir)) {\n const url = new URL(publicDir);\n const segs = [...url.pathname.split('/'), ...src.split('/')].filter((v) => v.length > 0);\n\n url.pathname = `/${segs.join('/')}`;\n return { type: 'url', url };\n }\n\n return {\n type: 'file',\n file: path.join(publicDir, src),\n };\n }\n\n if (!dir) {\n console.warn(\n `[Remark Image] found relative path ${src} but missing 'dirname' in VFile, this image will be skipped for now.`,\n );\n return;\n }\n\n return {\n type: 'file',\n file: path.join(dir, src),\n };\n}\n\nasync function getImageSize(\n src: Source,\n onExternal: ExternalImageOptions,\n): Promise<ISizeCalculationResult | undefined> {\n if (src.type === 'file') {\n const { imageSizeFromFile } = await import('image-size/fromFile');\n return imageSizeFromFile(src.file);\n }\n if (onExternal === false) return;\n\n const { timeout } = typeof onExternal === 'object' ? onExternal : {};\n const res = await fetch(src.url, {\n signal: typeof timeout === 'number' ? AbortSignal.timeout(timeout) : undefined,\n });\n if (!res.ok) {\n throw new Error(\n `[Remark Image] Failed to fetch ${src.url} (${res.status}): ${await res.text()}`,\n );\n }\n\n const { imageSize } = await import('image-size');\n return imageSize(new Uint8Array(await res.arrayBuffer()));\n}\n"],"mappings":";;;;;AASA,MAAM,iBAAiB;CAAC;CAAS;CAAQ;CAAS;CAAS;CAAO;AAClE,MAAM,qBAAqB;;;;AAuE3B,SAAgB,YAAY,EAC1B,cAAc,QACd,WAAW,MACX,YAAY,MACZ,UAAU,SACV,YAAYA,OAAK,KAAK,QAAQ,KAAK,EAAE,SAAS,KACxB,EAAE,EAA2B;AACnD,QAAO,OAAO,MAAM,SAAS;EAC3B,MAAM,kBAAkE,EAAE;EAC1E,MAAM,WAA4B,EAAE;EAEpC,eAAe,QAAQ,KAAa,MAAqD;GACvF,MAAM,aAAgC,CACpC;IACE,MAAM;IACN,MAAM;IACN,OAAO,KAAK,OAAO;IACpB,CACF;AAED,OAAI,KAAK,MACP,YAAW,KAAK;IACd,MAAM;IACN,MAAM;IACN,OAAO,KAAK;IACb,CAAC;AAGJ,OAAI,IAAI,SAAS,UAAU,WAAW;IAEpC,MAAM,eAAe,QAAQ,gBAAgB;IAC7C,MAAM,UACJ,gBAAgB,UAAU,eAAe,MAAM,QAAQ,IAAI,KAAK,SAAS,IAAI,CAAC;AAEhF,QAAI,CAAC,KAAK,QACR,OAAM,IAAI,MACR,2FACD;AAGH,oBAAgB,KAAK;KACnB;KACA,YAAY,cAAc,IAAI,MAAM,KAAK,QAAQ;KAClD,CAAC;AAEF,eAAW,KAAK;KACd,MAAM;KACN,MAAM;KACN,OAAO;MACL,MAAM;MACN,OAAO;MACP,MAAM,EACJ,QAAQ;OACN,MAAM,CACJ;QACE,MAAM;QACN,YAAY;SAAE,MAAM;SAAc,MAAM;SAAc;QACvD,CACF;OACD,MAAM;OACN,YAAY;OAC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,EAAE,sBAAsB,MAAM,OAAO;AAC3C,SAAO,kBAAkB,IAAI,KAAK;;AAEpC,KAAI,eAAe,MAAO;CAE1B,MAAM,EAAE,YAAY,OAAO,eAAe,WAAW,aAAa,EAAE;CACpE,MAAM,MAAM,MAAM,MAAM,IAAI,KAAK,EAC/B,QAAQ,OAAO,YAAY,WAAW,YAAY,QAAQ,QAAQ,GAAG,QACtE,CAAC;AACF,KAAI,CAAC,IAAI,GACP,OAAM,IAAI,MACR,kCAAkC,IAAI,IAAI,IAAI,IAAI,OAAO,KAAK,MAAM,IAAI,MAAM,GAC/E;CAGH,MAAM,EAAE,cAAc,MAAM,OAAO;AACnC,QAAO,UAAU,IAAI,WAAW,MAAM,IAAI,aAAa,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-mdx-files.js","names":[
|
|
1
|
+
{"version":3,"file":"remark-mdx-files.js","names":[],"sources":["../../src/mdx-plugins/remark-mdx-files.ts"],"sourcesContent":["import type { Root } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport type { Transformer } from 'unified';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport type { VFile } from 'vfile';\nimport path from 'node:path';\n\nexport interface FileNode {\n depth: number;\n type: 'file';\n name: string;\n}\n\nexport interface FolderNode {\n depth: number;\n type: 'folder';\n name: string;\n children: Node[];\n}\n\nexport interface ToMdxOptions {\n defaultOpenAll: boolean;\n}\n\ntype Node = FileNode | FolderNode;\n\nexport interface RemarkMdxFilesOptions {\n /**\n * @defaultValue files\n */\n lang?: string;\n toMdx?: (node: Node, options: ToMdxOptions) => MdxJsxFlowElement;\n}\n\ninterface AutoFilesProps extends Partial<ToMdxOptions> {\n dir?: string;\n patterns?: string[];\n}\n\nfunction parseFileTree(code: string) {\n const lines = code.split(/\\r?\\n/);\n const stack = new Map<number, Node>();\n\n for (const line of lines) {\n let depth = 0;\n let name = line;\n let match: RegExpMatchArray | null;\n\n while ((match = /(?:├──|│|└──)\\s*/.exec(name))) {\n name = name.slice(match[0].length);\n depth++;\n }\n\n if (!name) continue;\n const node: Node = name.endsWith('/')\n ? { type: 'folder', name, children: [], depth }\n : { type: 'file', name, depth };\n\n let parent: Node | undefined;\n for (let i = depth - 1; i >= 0 && !parent; i--) {\n parent = stack.get(i);\n }\n\n stack.set(depth, node);\n if (!parent) continue;\n if (parent.type === 'file') {\n Object.assign(parent, {\n type: 'folder',\n children: [],\n });\n }\n\n (parent as FolderNode).children.push(node);\n }\n\n return stack.get(0);\n}\n\nfunction defaultToMDX(node: Node, options: ToMdxOptions, depth = 0): MdxJsxFlowElement {\n if (depth === 0) {\n return {\n type: 'mdxJsxFlowElement',\n name: 'Files',\n attributes: [],\n children: [defaultToMDX(node, options, depth + 1)],\n };\n }\n\n const attributes: MdxJsxAttribute[] = [\n { type: 'mdxJsxAttribute', name: 'name', value: node.name },\n ];\n\n if (node.type === 'file') {\n return {\n type: 'mdxJsxFlowElement',\n attributes,\n children: [],\n name: 'File',\n };\n }\n\n if (options.defaultOpenAll) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: 'defaultOpen',\n value: null,\n });\n }\n\n return {\n type: 'mdxJsxFlowElement',\n attributes,\n name: 'Folder',\n children: node.children.map((item) => defaultToMDX(item, options, depth + 1)),\n };\n}\n\n/**\n *\n * **Files CodeBlock:**\n *\n * Convert codeblocks with `files` as lang, like:\n *\n * ```files\n * project\n * ├── src\n * │ ├── index.js\n * │ └── utils\n * │ └── helper.js\n * ├── package.json\n * ```\n *\n * into MDX `<Files />` component.\n *\n * **Auto Files:**\n *\n * Generates MDX `<Files />` component from file system.\n *\n * ```mdx\n * <auto-files dir=\"scripts\" pattern=\"my-dir/*\" defaultOpenAll />\n * ```\n */\nexport function remarkMdxFiles(options: RemarkMdxFilesOptions = {}): Transformer<Root, Root> {\n const { lang = 'files', toMdx = defaultToMDX } = options;\n\n async function autoFiles(\n file: VFile,\n node: MdxJsxFlowElement,\n { patterns, dir, defaultOpenAll = false }: AutoFilesProps,\n ) {\n const { glob } = await import('tinyglobby');\n if (!patterns) {\n file.fail('Missing `pattern` prop in <auto-files>', {\n place: node.position,\n });\n }\n\n const baseDir = file.dirname ?? file.cwd;\n const cwd = dir ? path.join(baseDir, dir) : baseDir;\n const files = await glob(patterns, { cwd });\n Object.assign(node, toMdx(buildFileTreeFromGlob(cwd, files), { defaultOpenAll }));\n }\n\n return async (tree, file) => {\n const queue: Promise<void>[] = [];\n\n visit(tree, ['code', 'mdxJsxFlowElement'] as const, (node) => {\n if (node.type === 'code') {\n if (node.lang !== lang || !node.value) return;\n\n const fileTree = parseFileTree(node.value);\n if (!fileTree) return;\n\n Object.assign(\n node,\n toMdx(fileTree, {\n defaultOpenAll: true,\n }),\n );\n return 'skip';\n }\n\n if (node.type === 'mdxJsxFlowElement') {\n if (node.name !== 'auto-files') return;\n const parsed: AutoFilesProps = {};\n for (const attr of node.attributes) {\n if (attr.type !== 'mdxJsxAttribute') continue;\n const { name, value } = attr;\n\n switch (name) {\n case 'dir':\n if (typeof value === 'string') parsed.dir = value;\n break;\n case 'pattern':\n if (typeof value === 'string') {\n parsed.patterns ??= [];\n parsed.patterns.push(value);\n }\n break;\n case 'defaultOpenAll':\n parsed.defaultOpenAll = true;\n break;\n }\n }\n\n queue.push(autoFiles(file, node, parsed));\n return 'skip';\n }\n });\n\n await Promise.all(queue);\n };\n}\n\nfunction buildFileTreeFromGlob(dir: string, files: string[]): Node {\n const nodeMap = new Map<string, FolderNode>();\n const root: FolderNode = {\n depth: 0,\n type: 'folder',\n name: path.basename(dir),\n children: [],\n };\n nodeMap.set('', root);\n\n for (const file of files) {\n const parts = path\n .normalize(file)\n .split(path.sep)\n .filter((part) => part.length > 0);\n let currentPath = '';\n let current = root;\n\n for (let i = 0; i < parts.length; i++) {\n const name = parts[i];\n const nextPath = path.join(currentPath, name);\n\n if (i === parts.length - 1) {\n // Add file node.\n const fileNode: FileNode = { depth: i + 1, type: 'file', name };\n current.children.push(fileNode);\n } else {\n // Add or retrieve folder node using the map.\n let folder = nodeMap.get(nextPath);\n\n if (!folder) {\n folder = { depth: i + 1, type: 'folder', name, children: [] };\n nodeMap.set(nextPath, folder);\n current.children.push(folder);\n }\n\n current = folder;\n currentPath = nextPath;\n }\n }\n }\n\n return root;\n}\n"],"mappings":";;;;AAuCA,SAAS,cAAc,MAAc;CACnC,MAAM,QAAQ,KAAK,MAAM,QAAQ;CACjC,MAAM,wBAAQ,IAAI,KAAmB;AAErC,MAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,QAAQ;EACZ,IAAI,OAAO;EACX,IAAI;AAEJ,SAAQ,QAAQ,mBAAmB,KAAK,KAAK,EAAG;AAC9C,UAAO,KAAK,MAAM,MAAM,GAAG,OAAO;AAClC;;AAGF,MAAI,CAAC,KAAM;EACX,MAAM,OAAa,KAAK,SAAS,IAAI,GACjC;GAAE,MAAM;GAAU;GAAM,UAAU,EAAE;GAAE;GAAO,GAC7C;GAAE,MAAM;GAAQ;GAAM;GAAO;EAEjC,IAAI;AACJ,OAAK,IAAI,IAAI,QAAQ,GAAG,KAAK,KAAK,CAAC,QAAQ,IACzC,UAAS,MAAM,IAAI,EAAE;AAGvB,QAAM,IAAI,OAAO,KAAK;AACtB,MAAI,CAAC,OAAQ;AACb,MAAI,OAAO,SAAS,OAClB,QAAO,OAAO,QAAQ;GACpB,MAAM;GACN,UAAU,EAAE;GACb,CAAC;AAGJ,EAAC,OAAsB,SAAS,KAAK,KAAK;;AAG5C,QAAO,MAAM,IAAI,EAAE;;AAGrB,SAAS,aAAa,MAAY,SAAuB,QAAQ,GAAsB;AACrF,KAAI,UAAU,EACZ,QAAO;EACL,MAAM;EACN,MAAM;EACN,YAAY,EAAE;EACd,UAAU,CAAC,aAAa,MAAM,SAAS,QAAQ,EAAE,CAAC;EACnD;CAGH,MAAM,aAAgC,CACpC;EAAE,MAAM;EAAmB,MAAM;EAAQ,OAAO,KAAK;EAAM,CAC5D;AAED,KAAI,KA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kBAAc;;;;AAKpB,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-npm.js","names":[
|
|
1
|
+
{"version":3,"file":"remark-npm.js","names":[],"sources":["../../src/mdx-plugins/remark-npm.ts"],"sourcesContent":["import type { Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport convert from 'npm-to-yarn';\nimport { type CodeBlockTabsOptions, generateCodeBlockTabs } from '@/mdx-plugins/codeblock-utils';\n\ninterface PackageManager {\n name: string;\n\n /**\n * Default to `name`\n */\n value?: string;\n\n /**\n * Convert from npm to another package manager\n */\n command: (command: string) => string | undefined;\n}\n\nexport interface RemarkNpmOptions {\n /**\n * Persist Tab value (Fumadocs UI only)\n *\n * @defaultValue false\n */\n persist?:\n | {\n id: string;\n }\n | false;\n\n packageManagers?: PackageManager[];\n}\n\nconst aliases = ['npm', 'package-install'];\n\n/**\n * It generates multiple tabs of codeblocks for different package managers from a npm command codeblock.\n */\nexport function remarkNpm({\n persist = false,\n packageManagers = [\n { command: (cmd) => convert(cmd, 'npm'), name: 'npm' },\n { command: (cmd) => convert(cmd, 'pnpm'), name: 'pnpm' },\n { command: (cmd) => convert(cmd, 'yarn'), name: 'yarn' },\n { command: (cmd) => convert(cmd, 'bun'), name: 'bun' },\n ],\n}: RemarkNpmOptions = {}): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, 'code', (node) => {\n if (!node.lang || !aliases.includes(node.lang)) return;\n let code = node.value;\n\n if (node.lang === 'package-install' && !code.startsWith('npm') && !code.startsWith('npx')) {\n code = `npm install ${code}`;\n }\n const options: CodeBlockTabsOptions = {\n persist,\n tabs: [],\n triggers: [],\n };\n\n for (const manager of packageManagers) {\n const value = manager.value ?? manager.name;\n const command = manager.command(code);\n if (!command || command.length === 0) continue;\n\n options.defaultValue ??= value;\n options.triggers.push({\n value,\n children: [{ type: 'text', value: manager.name }],\n });\n options.tabs.push({\n value,\n children: [\n {\n type: 'code',\n lang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;AACnD,UAAO;IACP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-steps.js","names":[
|
|
1
|
+
{"version":3,"file":"remark-steps.js","names":[],"sources":["../../src/mdx-plugins/remark-steps.ts"],"sourcesContent":["import type { Transformer } from 'unified';\nimport type { BlockContent, Heading, Root, RootContent } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\n\nexport interface RemarkStepsOptions {\n /**\n * Class name for steps container\n *\n * @defaultValue fd-steps\n */\n steps?: string;\n\n /**\n * Class name for step container\n *\n * @defaultValue fd-step\n */\n step?: string;\n}\n\nconst StepRegex = /^(\\d+)\\.\\s(.+)$/;\n\n/**\n * Convert headings in the format of `1. Hello World` into steps.\n */\nexport function remarkSteps({\n steps = 'fd-steps',\n step = 'fd-step',\n}: RemarkStepsOptions = {}): Transformer<Root, Root> {\n function convertToSteps(nodes: RootContent[]): MdxJsxFlowElement {\n const depth = (nodes[0] as Heading).depth;\n const children: MdxJsxFlowElement[] = [];\n\n for (const node of nodes) {\n if (node.type === 'heading' && node.depth === depth) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: 'div',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'className',\n value: step,\n },\n ],\n children: [node],\n });\n } else {\n children[children.length - 1].children.push(node as BlockContent);\n }\n }\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'div',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'className',\n value: steps,\n },\n ],\n data: {\n _fd_step: true,\n } as object,\n children,\n };\n }\n\n return (tree) => {\n visit(tree, (parent) => {\n if (!('children' in parent) || parent.type === 'heading') return;\n if (parent.data && '_fd_step' in parent.data) return 'skip';\n\n let startIdx = -1;\n let i = 0;\n\n const onEnd = () => {\n if (startIdx === -1) return;\n // range: start index to i - 1\n const item = {};\n const nodes = parent.children.splice(startIdx, i - startIdx, item as RootContent);\n Object.assign(item, convertToSteps(nodes));\n i = startIdx + 1;\n startIdx = -1;\n };\n\n for (; i < parent.children.length; i++) {\n const node = parent.children[i];\n\n if (node.type !== 'heading') continue;\n if (startIdx !== -1) {\n const startDepth = (parent.children[startIdx] as Heading).depth;\n\n if (node.depth > startDepth) continue;\n else if (node.depth < startDepth) onEnd();\n }\n\n const head = node.children.filter((c) => c.type === 'text').at(0);\n if (!head) {\n onEnd();\n continue;\n }\n\n const match = StepRegex.exec(head.value);\n if (!match) {\n onEnd();\n continue;\n }\n\n head.value = match[2];\n if (startIdx === -1) startIdx = i;\n }\n\n onEnd();\n });\n };\n}\n"],"mappings":";;;AAqBA,MAAM,YAAY;;;;AAKlB,SAAgB,YAAY,EAC1B,QAAQ,YACR,OAAO,cACe,EAAE,EAA2B;CACnD,SAAS,eAAe,OAAyC;EAC/D,MAAM,QAAS,MAAM,GAAe;EACpC,MAAM,WAAgC,EAAE;AAExC,OAAK,MAAM,QAAQ,MACjB,KAAI,KAAK,SAAS,aAAa,KAAK,UAAU,MAC5C,UAAS,KAAK;GACZ,MAAM;GACN,MAAM;GACN,YAAY,CACV;IACE,MAAM;IACN,MAAM;IACN,OAAO;IACR,CACF;GACD,UAAU,CAAC,KAAK;GACjB,CAAC;MAEF,UAAS,SAAS,SAAS,GAAG,SAAS,KAAK,KAAqB;AAIrE,SAAO;GACL,MAAM;GACN,MAAM;GACN,YAAY,CACV;IACE,MAAM;IACN,MAAM;IACN,OAAO;IACR,CACF;GACD,MAAM,EACJ,UAAU,MACX;GACD;GACD;;AAGH,SAAQ,SAAS;AACf,QAAM,OAAO,WAAW;AACtB,OAAI,EAAE,cAAc,WAAW,OAAO,SAAS,UAAW;AAC1D,OAAI,OAAO,QAAQ,cAAc,OAAO,KAAM,QAAO;GAErD,IAAI,WAAW;GACf,IAAI,IAAI;GAER,MAAM,cAAc;AAClB,QAAI,aAAa,GAAI;IAErB,MAAM,OAAO,EAAE;IACf,MAAM,QAAQ,OAAO,SAAS,OAAO,UAAU,IAAI,UAAU,KAAoB;AACjF,WAAO,OAAO,MAAM,eAAe,MAAM,CAAC;AAC1C,QAAI,WAAW;AACf,eAAW;;AAGb,UAAO,IAAI,OAAO,SAAS,QAAQ,KAAK;IACtC,MAAM,OAAO,OAAO,SAAS;AAE7B,QAAI,KAAK,SAAS,UAAW;AAC7B,QAAI,aAAa,IAAI;KACnB,MAAM,aAAc,OAAO,SAAS,UAAsB;AAE1D,SAAI,KAAK,QAAQ,WAAY;cACpB,KAAK,QAAQ,WAAY,QAAO;;IAG3C,MAAM,OAAO,KAAK,SAAS,QAAQ,MAAM,EAAE,SAAS,OAAO,CAAC,GAAG,EAAE;AACjE,QAAI,CAAC,MAAM;AACT,YAAO;AACP;;IAGF,MAAM,QAAQ,UAAU,KAAK,KAAK,MAAM;AACxC,QAAI,CAAC,OAAO;AACV,YAAO;AACP;;AAGF,SAAK,QAAQ,MAAM;AACnB,QAAI,aAAa,GAAI,YAAW;;AAGlC,UAAO;IACP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remark-structure.js","names":["
|
|
1
|
+
{"version":3,"file":"remark-structure.js","names":["content"],"sources":["../../src/mdx-plugins/remark-structure.ts"],"sourcesContent":["import Slugger from 'github-slugger';\nimport type { Nodes, Root } from 'mdast';\nimport { remark } from 'remark';\nimport remarkGfm from 'remark-gfm';\nimport type { PluggableList, Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport { flattenNode, toMdxExport } from './mdast-utils';\nimport type {\n MdxJsxAttribute,\n MdxJsxExpressionAttribute,\n MdxJsxFlowElement,\n} from 'mdast-util-mdx-jsx';\n\ninterface Heading {\n id: string;\n content: string;\n}\n\ninterface Content {\n heading: string | undefined;\n content: string;\n}\n\nexport interface StructuredData {\n headings: Heading[];\n /**\n * Refer to paragraphs, a heading may contain multiple contents as well\n */\n contents: Content[];\n}\n\nexport interface StructureOptions {\n /**\n * Types to be scanned as content.\n *\n * @defaultValue ['heading', 'paragraph', 'blockquote', 'tableCell', 'mdxJsxFlowElement']\n */\n types?: string[] | ((node: Nodes) => boolean);\n\n /**\n * A list of indexable MDX attributes, either:\n *\n * - an array of attribute names.\n * - a function that determines if attribute should be indexed.\n */\n allowedMdxAttributes?:\n | string[]\n | ((\n node: MdxJsxFlowElement,\n attribute: MdxJsxAttribute | MdxJsxExpressionAttribute,\n ) => boolean);\n\n /**\n * export as `structuredData` or specified variable name.\n */\n exportAs?: string | boolean;\n}\n\ndeclare module 'mdast' {\n interface Data {\n /**\n * [Fumadocs] Get content of unserializable element, `remarkStructure` uses it to generate search index.\n */\n _string?: string[];\n }\n}\n\ndeclare module 'vfile' {\n interface DataMap {\n /**\n * [Fumadocs] injected by `remarkStructure`\n */\n structuredData: StructuredData;\n }\n}\n\nexport const remarkStructureDefaultOptions = {\n types: ['heading', 'paragraph', 'blockquote', 'tableCell', 'mdxJsxFlowElement'],\n allowedMdxAttributes: (node) => {\n if (!node.name) return false;\n\n return ['TypeTable', 'Callout'].includes(node.name);\n },\n exportAs: false,\n} satisfies Required<StructureOptions>;\n\n/**\n * Extract content into structured data.\n *\n * By default, the output is stored into VFile (`vfile.data.structuredData`), you can specify `exportAs` to export it.\n */\nexport function remarkStructure({\n types = remarkStructureDefaultOptions.types,\n allowedMdxAttributes = remarkStructureDefaultOptions.allowedMdxAttributes,\n exportAs = remarkStructureDefaultOptions.exportAs,\n}: StructureOptions = {}): Transformer<Root, Root> {\n const slugger = new Slugger();\n\n if (Array.isArray(allowedMdxAttributes)) {\n const arr = allowedMdxAttributes;\n allowedMdxAttributes = (_node, attribute) =>\n attribute.type === 'mdxJsxAttribute' && arr.includes(attribute.name);\n }\n\n if (Array.isArray(types)) {\n const arr = types;\n types = (node) => arr.includes(node.type);\n }\n\n return (tree, file) => {\n slugger.reset();\n const data: StructuredData = { contents: [], headings: [] };\n let lastHeading: string | undefined;\n\n // Fumadocs OpenAPI Generated Structured Data\n if (file.data.frontmatter) {\n const frontmatter = file.data.frontmatter as {\n _openapi?: {\n structuredData?: StructuredData;\n };\n };\n\n if (frontmatter._openapi?.structuredData) {\n data.headings.push(...frontmatter._openapi.structuredData.headings);\n data.contents.push(...frontmatter._openapi.structuredData.contents);\n }\n }\n\n visit(tree, (element) => {\n if (element.type === 'root' || !types(element)) return;\n\n if (element.type === 'heading') {\n element.data ||= {};\n element.data.hProperties ||= {};\n const properties = element.data.hProperties;\n const content = flattenNode(element).trim();\n const id = properties.id ?? slugger.slug(content);\n\n data.headings.push({\n id,\n content,\n });\n\n lastHeading = id;\n return 'skip';\n }\n\n if (element.data?._string) {\n for (const content of element.data._string) {\n data.contents.push({\n heading: lastHeading,\n content,\n });\n }\n\n return 'skip';\n }\n\n if (element.type === 'mdxJsxFlowElement' && element.name) {\n data.contents.push(\n ...element.attributes.flatMap((attribute) => {\n const value =\n typeof attribute.value === 'string' ? attribute.value : attribute.value?.value;\n if (!value || value.length === 0) return [];\n if (allowedMdxAttributes && !allowedMdxAttributes(element, attribute)) return [];\n\n return {\n heading: lastHeading,\n content: attribute.type === 'mdxJsxAttribute' ? `${attribute.name}: ${value}` : value,\n };\n }),\n );\n\n return;\n }\n\n const content = flattenNode(element).trim();\n if (content.length === 0) return;\n\n data.contents.push({\n heading: lastHeading,\n content,\n });\n\n return 'skip';\n });\n\n file.data.structuredData = data;\n if (exportAs) {\n tree.children.unshift(\n toMdxExport(typeof exportAs === 'string' ? exportAs : 'structuredData', data),\n );\n }\n };\n}\n\n/**\n * Extract data from markdown/mdx content\n */\nexport function structure(\n content: string,\n remarkPlugins: PluggableList = [],\n options: StructureOptions = {},\n): StructuredData {\n const result = remark()\n .use(remarkGfm)\n .use(remarkPlugins)\n .use(remarkStructure, options)\n .processSync(content);\n\n return result.data.structuredData!;\n}\n"],"mappings":";;;;;;;AA4EA,MAAa,gCAAgC;CAC3C,OAAO;EAAC;EAAW;EAAa;EAAc;EAAa;EAAoB;CAC/E,uBAAuB,SAAS;AAC9B,MAAI,CAAC,KAAK,KAAM,QAAO;AAEvB,SAAO,CAAC,aAAa,UAAU,CAAC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AAC;AAGJ,WAAO;;AAGT,OAAI,QAAQ,SAAS,uBAAuB,QAAQ,MAAM;AACxD,SAAK,SAAS,KACZ,GAAG,QAAQ,WAAW,SAAS,cAAc;KAC3C,MAAM,QACJ,OAAO,UAAU,UAAU,WAAW,UAAU,QAAQ,UAAU,OAAO;AAC3E,SAAI,CAAC,SAAS,MAAM,WAAW,EAAG,QAAO,EAAE;AAC3C,SAAI,wBAAwB,CAAC,qBAAqB,SAAS,UAAU,CAAE,QAAO,EAAE;AAEhF,YAAO;MACL,SAAS;MACT,SAAS,UAAU,SAAS,oBAAoB,GAAG,UAAU,KAAK,IAAI,UAAU;MACjF;MACD,CACH;AAED;;GAGF,MAAM,UAAU,YAAY,QAAQ,CAAC,MAAM;AAC3C,OAAI,QAAQ,WAAW,EAAG;AAE1B,QAAK,SAAS,KAAK;IACjB,SAAS;IACT;IACD,CAAC;AAEF,UAAO;IACP;AAEF,OAAK,KAAK,iBAAiB;AAC3B,MAAI,SACF,MAAK,SAAS,QACZ,YAAY,OAAO,aAAa,WAAW,WAAW,kBAAkB,KAAK,CAC9E;;;;;;AAQP,SAAgB,UACd,SACA,gBAA+B,EAAE,EACjC,UAA4B,EAAE,EACd;AAOhB,QANe,QAAQ,CACpB,IAAI,UAAU,CACd,IAAI,cAAc,CAClB,IAAI,iBAAiB,QAAQ,CAC7B,YAAY,QAAQ,CAET,KAAK"}
|
|
@@ -37,7 +37,7 @@ var require_remove_markdown = /* @__PURE__ */ __commonJSMin(((exports, module) =
|
|
|
37
37
|
|
|
38
38
|
//#endregion
|
|
39
39
|
//#region src/search/client/mixedbread.ts
|
|
40
|
-
var import_remove_markdown = /* @__PURE__ */ __toESM(require_remove_markdown());
|
|
40
|
+
var import_remove_markdown = /* @__PURE__ */ __toESM(require_remove_markdown(), 1);
|
|
41
41
|
const slugger = new Slugger();
|
|
42
42
|
function extractHeadingTitle(text) {
|
|
43
43
|
const trimmedText = text.trim();
|
|
@@ -85,4 +85,4 @@ async function search(query, options) {
|
|
|
85
85
|
|
|
86
86
|
//#endregion
|
|
87
87
|
export { search };
|
|
88
|
-
//# sourceMappingURL=mixedbread-
|
|
88
|
+
//# sourceMappingURL=mixedbread-CPGJEgwq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixedbread-CPGJEgwq.js","names":[],"sources":["../../../node_modules/.pnpm/remove-markdown@0.6.2/node_modules/remove-markdown/index.js","../src/search/client/mixedbread.ts"],"sourcesContent":["module.exports = function(md, options) {\n options = options || {};\n options.listUnicodeChar = options.hasOwnProperty('listUnicodeChar') ? options.listUnicodeChar : false;\n options.stripListLeaders = options.hasOwnProperty('stripListLeaders') ? options.stripListLeaders : true;\n options.gfm = options.hasOwnProperty('gfm') ? options.gfm : true;\n options.useImgAltText = options.hasOwnProperty('useImgAltText') ? options.useImgAltText : true;\n options.abbr = options.hasOwnProperty('abbr') ? options.abbr : false;\n options.replaceLinksWithURL = options.hasOwnProperty('replaceLinksWithURL') ? options.replaceLinksWithURL : false;\n options.htmlTagsToSkip = options.hasOwnProperty('htmlTagsToSkip') ? options.htmlTagsToSkip : [];\n options.throwError = options.hasOwnProperty('throwError') ? options.throwError : false;\n\n var output = md || '';\n\n // Remove horizontal rules (stripListHeaders conflict with this rule, which is why it has been moved to the top)\n output = output.replace(/^ {0,3}((?:-[\\t ]*){3,}|(?:_[ \\t]*){3,}|(?:\\*[ \\t]*){3,})(?:\\n+|$)/gm, '');\n\n try {\n if (options.stripListLeaders) {\n if (options.listUnicodeChar)\n output = output.replace(/^([\\s\\t]*)([\\*\\-\\+]|\\d+\\.)\\s+/gm, options.listUnicodeChar + ' $1');\n else\n output = output.replace(/^([\\s\\t]*)([\\*\\-\\+]|\\d+\\.)\\s+/gm, '$1');\n }\n if (options.gfm) {\n output = output\n // Header\n .replace(/\\n={2,}/g, '\\n')\n // Fenced codeblocks\n .replace(/~{3}.*\\n/g, '')\n // Strikethrough\n .replace(/~~/g, '')\n // Fenced codeblocks with backticks\n .replace(/```(?:.*)\\n([\\s\\S]*?)```/g, (_, code) => code.trim());\n }\n if (options.abbr) {\n // Remove abbreviations\n output = output.replace(/\\*\\[.*\\]:.*\\n/, '');\n }\n \n let htmlReplaceRegex = /<[^>]*>/g\n if (options.htmlTagsToSkip && options.htmlTagsToSkip.length > 0) {\n // Create a regex that matches tags not in htmlTagsToSkip\n const joinedHtmlTagsToSkip = options.htmlTagsToSkip.join('|')\n htmlReplaceRegex = new RegExp(\n `<(?!\\/?(${joinedHtmlTagsToSkip})(?=>|\\s[^>]*>))[^>]*>`,\n 'g',\n )\n }\n\n output = output\n // Remove HTML tags\n .replace(htmlReplaceRegex, '')\n // Remove setext-style headers\n .replace(/^[=\\-]{2,}\\s*$/g, '')\n // Remove footnotes?\n .replace(/\\[\\^.+?\\](\\: .*?$)?/g, '')\n .replace(/\\s{0,2}\\[.*?\\]: .*?$/g, '')\n // Remove images\n .replace(/\\!\\[(.*?)\\][\\[\\(].*?[\\]\\)]/g, options.useImgAltText ? '$1' : '')\n // Remove inline links\n .replace(/\\[([\\s\\S]*?)\\]\\s*[\\(\\[].*?[\\)\\]]/g, options.replaceLinksWithURL ? '$2' : '$1')\n // Remove blockquotes\n .replace(/^(\\n)?\\s{0,3}>\\s?/gm, '$1')\n // .replace(/(^|\\n)\\s{0,3}>\\s?/g, '\\n\\n')\n // Remove reference-style links?\n .replace(/^\\s{1,2}\\[(.*?)\\]: (\\S+)( \".*?\")?\\s*$/g, '')\n // Remove atx-style headers\n .replace(/^(\\n)?\\s{0,}#{1,6}\\s*( (.+))? +#+$|^(\\n)?\\s{0,}#{1,6}\\s*( (.+))?$/gm, '$1$3$4$6')\n // Remove * emphasis\n .replace(/([\\*]+)(\\S)(.*?\\S)??\\1/g, '$2$3')\n // Remove _ emphasis. Unlike *, _ emphasis gets rendered only if \n // 1. Either there is a whitespace character before opening _ and after closing _.\n // 2. Or _ is at the start/end of the string.\n .replace(/(^|\\W)([_]+)(\\S)(.*?\\S)??\\2($|\\W)/g, '$1$3$4$5')\n // Remove single-line code blocks (already handled multiline above in gfm section)\n .replace(/(`{3,})(.*?)\\1/gm, '$2')\n // Remove inline code\n .replace(/`(.+?)`/g, '$1')\n // // Replace two or more newlines with exactly two? Not entirely sure this belongs here...\n // .replace(/\\n{2,}/g, '\\n\\n')\n // // Remove newlines in a paragraph\n // .replace(/(\\S+)\\n\\s*(\\S+)/g, '$1 $2')\n // Replace strike through\n .replace(/~(.*?)~/g, '$1');\n } catch(e) {\n if (options.throwError) throw e;\n\n console.error(\"remove-markdown encountered error: %s\", e);\n return md;\n }\n return output;\n};\n","import type { SortedResult } from '@/search';\nimport type Mixedbread from '@mixedbread/sdk';\nimport removeMd from 'remove-markdown';\nimport Slugger from 'github-slugger';\nimport type { StoreSearchResponse } from '@mixedbread/sdk/resources/stores';\n\nexport interface MixedbreadOptions {\n /**\n * The identifier of the store to search in\n */\n storeIdentifier: string;\n\n /**\n * The Mixedbread SDK client instance\n */\n client: Mixedbread;\n\n /**\n * Filter results with specific tag.\n */\n tag?: string;\n\n /**\n * Filter by locale (unsupported at the moment)\n */\n locale?: string;\n}\n\nexport interface SearchMetadata {\n title?: string;\n description?: string;\n url?: string;\n tag?: string;\n}\n\ntype StoreSearchResult = StoreSearchResponse['data'][number] & {\n generated_metadata: SearchMetadata;\n};\n\nconst slugger = new Slugger();\n\nfunction extractHeadingTitle(text: string): string {\n const trimmedText = text.trim();\n\n if (!trimmedText.startsWith('#')) {\n return '';\n }\n\n const lines = trimmedText.split('\\n');\n const firstLine = lines[0]?.trim();\n\n if (firstLine) {\n // Use remove-markdown to convert to plain text and remove colons\n return removeMd(firstLine, {\n useImgAltText: false,\n });\n }\n\n return '';\n}\n\nexport async function search(query: string, options: MixedbreadOptions): Promise<SortedResult[]> {\n const { client, storeIdentifier, tag } = options;\n\n if (!query.trim()) {\n return [];\n }\n\n const res = await client.stores.search({\n query,\n store_identifiers: [storeIdentifier],\n top_k: 10,\n filters: {\n key: 'generated_metadata.tag',\n operator: 'eq',\n value: tag,\n },\n search_options: {\n return_metadata: true,\n },\n });\n\n return (res.data as StoreSearchResult[]).flatMap((item) => {\n const metadata = item.generated_metadata;\n\n const url = metadata.url || '#';\n const title = metadata.title || 'Untitled';\n\n const chunkResults: SortedResult[] = [\n {\n id: `${item.file_id}-${item.chunk_index}-page`,\n type: 'page',\n content: title,\n url,\n },\n ];\n\n const headingTitle = item.type === 'text' ? extractHeadingTitle(item.text) : '';\n\n if (headingTitle) {\n slugger.reset();\n\n chunkResults.push({\n id: `${item.file_id}-${item.chunk_index}-heading`,\n type: 'heading',\n content: headingTitle,\n url: `${url}#${slugger.slug(headingTitle)}`,\n });\n }\n\n return chunkResults;\n });\n}\n"],"x_google_ignoreList":[0],"mappings":";;;;;AAAA,QAAO,UAAU,SAAS,IAAI,SAAS;AACrC,YAAU,WAAW,EAAE;AACvB,UAAQ,kBAAkB,QAAQ,eAAe,kBAAkB,GAAG,QAAQ,kBAAkB;AAChG,UAAQ,mBAAmB,QAAQ,eAAe,mBAAmB,GAAG,QAAQ,mBAAmB;AACnG,UAAQ,MAAM,QAAQ,eAAe,MAAM,GAAG,QAAQ,MAAM;AAC5D,UAAQ,gBAAgB,QAAQ,eAAe,gBAAgB,GAAG,QAAQ,gBAAgB;AAC1F,UAAQ,OAAO,QAAQ,eAAe,OAAO,GAAG,QAAQ,OAAO;AAC/D,UAAQ,sBAAsB,QAAQ,eAAe,sBAAsB,GAAG,QAAQ,sBAAsB;AAC5G,UAAQ,iBAAiB,QAAQ,eAAe,iBAAiB,GAAG,QAAQ,iBAAiB,EAAE;AAC/F,UAAQ,aAAa,QAAQ,eAAe,aAAa,GAAG,QAAQ,aAAa;EAEjF,IAAI,SAAS,MAAM;AAGnB,WAAS,OAAO,QAAQ,wEAAwE,GAAG;AAEnG,MAAI;AACF,OAAI,QAAQ,iBACV,KAAI,QAAQ,gBACV,UAAS,OAAO,QAAQ,mCAAmC,QAAQ,kBAAkB,MAAM;OAE3F,UAAS,OAAO,QAAQ,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O;;AAGT,eAAsB,OAAO,OAAe,SAAqD;CAC/F,MAAM,EAAE,QAAQ,iBAAiB,QAAQ;AAEzC,KAAI,CAAC,MAAM,MAAM,CACf,QAAO,EAAE;AAiBX,SAdY,MAAM,OAAO,OAAO,OAAO;EACrC;EACA,mBAAmB,CAAC,gBAAgB;EACpC,OAAO;EACP,SAAS;GACP,KAAK;GACL,UAAU;GACV,OAAO;GACR;EACD,gBAAgB,EACd,iBAAiB,MAClB;EACF,CAAC,EAEU,KAA6B,SAAS,SAAS;EACzD,MAAM,WAAW,KAAK;EAEtB,MAAM,MAAM,SAAS,OAAO;EAC5B,MAAM,QAAQ,SAAS,SAAS;EAEhC,MAAM,eAA+B,CACnC;GACE,IAAI,GAAG,KAAK,QAAQ,GAAG,KAAK,YAAY;GACxC,MAAM;GACN,SAAS;GACT;GACD,CACF;EAED,MAAM,eAAe,KAAK,SAAS,SAAS,oBAAoB,KAAK,KAAK,GAAG;AAE7E,MAAI,cAAc;AAChB,WAAQ,OAAO;AAEf,gBAAa,KAAK;IAChB,IAAI,GAAG,KAAK,QAAQ,GAAG,KAAK,YAAY;IACxC,MAAM;IACN,SAAS;IACT,KAAK,GAAG,IAAI,GAAG,QAAQ,KAAK,aAAa;IAC1C,CAAC;;AAGJ,SAAO;GACP"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/negotiation/index.ts"],"sourcesContent":["import Negotiator from 'negotiator';\nimport { compile, match } from 'path-to-regexp';\n\nexport function getNegotiator(request: Request) {\n const headers: Record<string, string> = {};\n request.headers.forEach((value, key) => {\n headers[key] = value;\n });\n\n return new Negotiator({ headers });\n}\n\n/**\n * Rewrite incoming path matching the `source` pattern into the `destination` pattern.\n *\n * See [`path-to-regexp`](https://github.com/pillarjs/path-to-regexp) for accepted pattern formats.\n *\n * @param source - the original pattern of incoming paths\n * @param destination - the target pattern to convert into\n */\nexport function rewritePath(source: string, destination: string) {\n const matcher = match(source, { decode: false });\n const compiler = compile(destination, { encode: false });\n\n return {\n rewrite(pathname: string) {\n const result = matcher(pathname);\n if (!result) return false;\n\n return compiler(result.params);\n },\n };\n}\n\nexport function isMarkdownPreferred(\n request: Request,\n options?: {\n markdownMediaTypes?: string[];\n },\n) {\n const { markdownMediaTypes = ['text/plain', 'text/markdown', 'text/x-markdown'] } = options ?? {};\n\n const mediaTypes = getNegotiator(request).mediaTypes();\n return markdownMediaTypes.some((type) => mediaTypes.includes(type));\n}\n"],"mappings":";;;;AAGA,SAAgB,cAAc,SAAkB;CAC9C,MAAM,UAAkC,EAAE;AAC1C,SAAQ,QAAQ,SAAS,OAAO,QAAQ;AACtC,UAAQ,OAAO;GACf;AAEF,QAAO,IAAI,WAAW,EAAE,SAAS,CAAC;;;;;;;;;;AAWpC,SAAgB,YAAY,QAAgB,aAAqB;CAC/D,MAAM,UAAU,MAAM,QAAQ,EAAE,QAAQ,OAAO,CAAC;CAChD,MAAM,WAAW,QAAQ,aAAa,EAAE,QAAQ,OAAO,CAAC;AAExD,QAAO,EACL,QAAQ,UAAkB;EACxB,MAAM,SAAS,QAAQ,SAAS;AAChC,MAAI,CAAC,OAAQ,QAAO;AAEpB,SAAO,SAAS,OAAO,OAAO;IAEjC;;AAGH,SAAgB,oBACd,SACA,SAGA;CACA,MAAM,EAAE,qBAAqB;EAAC;EAAc;EAAiB;EAAkB,KAAK,WAAW,EAAE;CAEjG,MAAM,aAAa,cAAc,QAAQ,CAAC,YAAY;AACtD,QAAO,mBAAmB,MAAM,SAAS,WAAW,SAAS,KAAK,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orama-cloud-legacy-NJTbB19B.js","names":["
|
|
1
|
+
{"version":3,"file":"orama-cloud-legacy-NJTbB19B.js","names":["result"],"sources":["../src/search/client/orama-cloud-legacy.ts"],"sourcesContent":["import type { ClientSearchParams, OramaClient } from '@oramacloud/client';\nimport { removeUndefined } from '@/utils/remove-undefined';\nimport type { OramaIndex } from '@/search/orama-cloud-legacy';\nimport { createContentHighlighter, type SortedResult } from '@/search';\n\ninterface CrawlerIndex {\n path: string;\n title: string;\n content: string;\n section: string;\n category: string;\n}\n\nexport interface OramaCloudLegacyOptions {\n client: OramaClient;\n /**\n * The type of your index.\n *\n * You can set it to `crawler` if you use crawler instead of the JSON index with schema provided by Fumadocs\n */\n index?: 'default' | 'crawler';\n params?: ClientSearchParams;\n\n /**\n * Filter results with specific tag.\n */\n tag?: string;\n\n /**\n * Filter by locale (unsupported at the moment)\n */\n locale?: string;\n}\n\nexport async function searchDocs(\n query: string,\n options: OramaCloudLegacyOptions,\n): Promise<SortedResult[]> {\n const highlighter = createContentHighlighter(query);\n const list: SortedResult[] = [];\n const { index = 'default', client, params: extraParams = {}, tag } = options;\n\n if (index === 'crawler') {\n const result = await client.search({\n ...extraParams,\n term: query,\n where: {\n category: tag\n ? {\n eq: tag.slice(0, 1).toUpperCase() + tag.slice(1),\n }\n : undefined,\n ...extraParams.where,\n },\n limit: 10,\n });\n if (!result) return list;\n\n for (const hit of result.hits) {\n const doc = hit.document as unknown as CrawlerIndex;\n\n list.push(\n {\n id: hit.id,\n type: 'page',\n content: doc.title,\n contentWithHighlights: highlighter.highlight(doc.title),\n url: doc.path,\n },\n {\n id: 'page' + hit.id,\n type: 'text',\n content: doc.content,\n contentWithHighlights: highlighter.highlight(doc.content),\n url: doc.path,\n },\n );\n }\n\n return list;\n }\n\n const params: ClientSearchParams = {\n ...extraParams,\n term: query,\n where: removeUndefined({\n tag,\n ...extraParams.where,\n }),\n groupBy: {\n properties: ['page_id'],\n maxResult: 7,\n ...extraParams.groupBy,\n },\n };\n\n const result = await client.search(params);\n if (!result || !result.groups) return list;\n\n for (const item of result.groups) {\n let addedHead = false;\n\n for (const hit of item.result) {\n const doc = hit.document as unknown as OramaIndex;\n\n if (!addedHead) {\n list.push({\n id: doc.page_id,\n type: 'page',\n content: doc.title,\n breadcrumbs: doc.breadcrumbs,\n contentWithHighlights: highlighter.highlight(doc.title),\n url: doc.url,\n });\n addedHead = true;\n }\n\n list.push({\n id: doc.id,\n content: doc.content,\n contentWithHighlights: highlighter.highlight(doc.content),\n type: doc.content === doc.section ? 'heading' : 'text',\n url: doc.section_id ? `${doc.url}#${doc.section_id}` : doc.url,\n });\n }\n }\n\n return list;\n}\n"],"mappings":";;;;AAkCA,eAAsB,WACpB,OACA,SACyB;CACzB,MAAM,cAAc,yBAAyB,MAAM;CACnD,MAAM,OAAuB,EAAE;CAC/B,MAAM,EAAE,QAAQ,WAAW,QAAQ,QAAQ,cAAc,EAAE,EAAE,QAAQ;AAErE,KAAI,UAAU,WAAW;EACvB,MAAMA,WAAS,MAAM,OAAO,OAAO;GACjC,GAAG;GACH,MAAM;GACN,OAAO;IACL,UAAU,MACN,EACE,IAAI,IAAI,MAAM,GAAG,EAAE,CAAC,aAAa,GAAG,IAAI,MAAM,EAAE,EACjD,GACD;IACJ,GAAG,YAAY;IAChB;GACD,OAAO;GACR,CAAC;AACF,MAAI,CAACA,SAAQ,QAAO;AAEpB,OAAK,MAAM,OAAOA,SAAO,MAAM;GAC7B,MAAM,MAAM,IAAI;AAEhB,QAAK,KACH;IACE,IAAI,IAAI;IACR,MAAM;IACN,SAAS,IAAI;IACb,uBAAuB,YAAY,UAAU,IAAI,MAAM;IACvD,KAAK,IAAI;IACV,EACD;IACE,IAAI,SAAS,IAAI;IACjB,MAAM;IACN,SAAS,IAAI;IACb,uBAAuB,YAAY,UAAU,IAAI,QAAQ;IACzD,KAAK,IAAI;IACV,CACF;;AAGH,SAAO;;CAGT,MAAM,SAA6B;EACjC,GAAG;EACH,MAAM;EACN,OAAO,gBAAgB;GACrB;GACA,GAAG,YAAY;GAChB,CAAC;EACF,SAAS;GACP,YAAY,CAAC,UAAU;GACvB,WAAW;GACX,GAAG,YAAY;GAChB;EACF;CAED,MAAM,SAAS,MAAM,OAAO,OAAO,OAAO;AAC1C,KAAI,CAAC,UAAU,CAAC,OAAO,OAAQ,QAAO;AAEtC,MAAK,MAAM,QAAQ,OAAO,QAAQ;EAChC,IAAI,YAAY;AAEhB,OAAK,MAAM,OAAO,KAAK,QAAQ;GAC7B,MAAM,MAAM,IAAI;AAEhB,OAAI,CAAC,WAAW;AACd,SAAK,KAAK;KACR,IAAI,IAAI;KACR,MAAM;KACN,SAAS,IAAI;KACb,aAAa,IAAI;KACjB,uBAAuB,YAAY,UAAU,IAAI,MAAM;KACvD,KAAK,IAAI;KACV,CAAC;AACF,gBAAY;;AAGd,QAAK,KAAK;IACR,IAAI,IAAI;IACR,SAAS,IAAI;IACb,uBAAuB,YAAY,UAAU,IAAI,QAAQ;IACzD,MAAM,IAAI,YAAY,IAAI,UAAU,YAAY;IAChD,KAAK,IAAI,aAAa,GAAG,IAAI,IAAI,GAAG,IAAI,eAAe,IAAI;IAC5D,CAAC;;;AAIN,QAAO"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"orama-cloud-yicpgD0c.js","names":["
|
|
1
|
+
{"version":3,"file":"orama-cloud-yicpgD0c.js","names":["result"],"sources":["../src/search/client/orama-cloud.ts"],"sourcesContent":["import type { OramaCloud, OramaCloudSearchParams } from '@orama/core';\nimport { removeUndefined } from '@/utils/remove-undefined';\nimport type { OramaIndex } from '@/search/orama-cloud';\nimport { createContentHighlighter, type SortedResult } from '@/search';\n\ninterface CrawlerIndex {\n path: string;\n title: string;\n content: string;\n section: string;\n category: string;\n}\n\nexport interface OramaCloudOptions {\n client: OramaCloud;\n /**\n * The type of your index.\n *\n * You can set it to `crawler` if you use crawler instead of the JSON index with schema provided by Fumadocs\n */\n index?: 'default' | 'crawler';\n params?: Partial<OramaCloudSearchParams>;\n\n /**\n * Filter results with specific tag.\n */\n tag?: string;\n\n /**\n * Filter by locale (unsupported at the moment)\n */\n locale?: string;\n}\n\nexport async function searchDocs(\n query: string,\n options: OramaCloudOptions,\n): Promise<SortedResult[]> {\n const highlighter = createContentHighlighter(query);\n const list: SortedResult[] = [];\n const { index = 'default', client, params: extraParams, tag } = options;\n\n if (index === 'crawler') {\n const result = await client.search({\n datasources: [],\n ...extraParams,\n term: query,\n where: {\n category: tag\n ? {\n eq: tag.slice(0, 1).toUpperCase() + tag.slice(1),\n }\n : undefined,\n ...extraParams?.where,\n },\n limit: 10,\n });\n if (!result) return list;\n\n for (const hit of result.hits) {\n const doc = hit.document as unknown as CrawlerIndex;\n\n list.push(\n {\n id: hit.id,\n type: 'page',\n content: doc.title,\n contentWithHighlights: highlighter.highlight(doc.title),\n url: doc.path,\n },\n {\n id: 'page' + hit.id,\n type: 'text',\n content: doc.content,\n contentWithHighlights: highlighter.highlight(doc.content),\n url: doc.path,\n },\n );\n }\n\n return list;\n }\n\n const params: OramaCloudSearchParams = {\n datasources: [],\n ...extraParams,\n term: query,\n where: removeUndefined({\n tag,\n ...extraParams?.where,\n }),\n groupBy: {\n properties: ['page_id'],\n max_results: 7,\n ...extraParams?.groupBy,\n },\n };\n\n const result = await client.search(params);\n if (!result || !result.groups) return list;\n\n for (const item of result.groups) {\n let addedHead = false;\n\n for (const hit of item.result) {\n const doc = hit.document as unknown as OramaIndex;\n\n if (!addedHead) {\n list.push({\n id: doc.page_id,\n type: 'page',\n content: doc.title,\n breadcrumbs: doc.breadcrumbs,\n contentWithHighlights: highlighter.highlight(doc.title),\n url: doc.url,\n });\n addedHead = true;\n }\n\n list.push({\n id: doc.id,\n content: doc.content,\n contentWithHighlights: highlighter.highlight(doc.content),\n type: doc.content === doc.section ? 'heading' : 'text',\n url: doc.section_id ? `${doc.url}#${doc.section_id}` : doc.url,\n });\n }\n }\n\n return list;\n}\n"],"mappings":";;;;AAkCA,eAAsB,WACpB,OACA,SACyB;CACzB,MAAM,cAAc,yBAAyB,MAAM;CACnD,MAAM,OAAuB,EAAE;CAC/B,MAAM,EAAE,QAAQ,WAAW,QAAQ,QAAQ,aAAa,QAAQ;AAEhE,KAAI,UAAU,WAAW;EACvB,MAAMA,WAAS,MAAM,OAAO,OA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AAM,IAAI,YAAY,IAAI,UAAU,YAAY;IAChD,KAAK,IAAI,aAAa,GAAG,IAAI,IAAI,GAAG,IAAI,eAAe,IAAI;IAC5D,CAAC;;;AAIN,QAAO"}
|
|
@@ -1,45 +1,3 @@
|
|
|
1
1
|
import { a as Separator, i as Root, n as Item, r as Node, t as Folder } from "../definitions-Ca2P2viV.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Flatten tree to an array of page nodes
|
|
7
|
-
*/
|
|
8
|
-
declare function flattenTree(nodes: Node[]): Item[];
|
|
9
|
-
/**
|
|
10
|
-
* Get neighbours of a page, useful for implementing "previous & next" buttons
|
|
11
|
-
*/
|
|
12
|
-
declare function findNeighbour(tree: Root, url: string, options?: {
|
|
13
|
-
separateRoot?: boolean;
|
|
14
|
-
}): {
|
|
15
|
-
previous?: Item;
|
|
16
|
-
next?: Item;
|
|
17
|
-
};
|
|
18
|
-
declare function getPageTreeRoots(pageTree: Root | Folder): (Root | Folder)[];
|
|
19
|
-
/**
|
|
20
|
-
* Get other item nodes that lives under the same parent.
|
|
21
|
-
*/
|
|
22
|
-
declare function getPageTreePeers(treeOrTrees: Root | Record<string, Root>, url: string): Item[];
|
|
23
|
-
/**
|
|
24
|
-
* Get other tree nodes that lives under the same parent.
|
|
25
|
-
*/
|
|
26
|
-
declare function findSiblings(treeOrTrees: Root | Record<string, Root>, url: string): Node[];
|
|
27
|
-
declare function findParent(from: Root | Folder, url: string): Root | Folder | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Search the path of a node in the tree matched by the matcher.
|
|
30
|
-
*
|
|
31
|
-
* @returns The path to the target node (from starting root), or null if the page doesn't exist
|
|
32
|
-
*/
|
|
33
|
-
declare function findPath(nodes: Node[], matcher: (node: Node) => boolean, options?: {
|
|
34
|
-
includeSeparator?: boolean;
|
|
35
|
-
}): Node[] | null;
|
|
36
|
-
/**
|
|
37
|
-
* Perform a depth-first search on page tree visiting every node.
|
|
38
|
-
*
|
|
39
|
-
* @param root - the root of page tree to visit.
|
|
40
|
-
* @param visitor - function to receive nodes, return `skip` to skip the children of current node, `break` to stop the search entirely.
|
|
41
|
-
*/
|
|
42
|
-
declare function visit<Root$1 extends Node | Root>(root: Root$1, visitor: <T extends Node | Root>(node: T, parent?: Root | Folder) => 'skip' | 'break' | T | void): Root$1;
|
|
43
|
-
//#endregion
|
|
44
|
-
export { Folder, Item, Node, Root, Separator, findNeighbour, findParent, findPath, findSiblings, flattenTree, getPageTreePeers, getPageTreeRoots, visit };
|
|
45
|
-
//# sourceMappingURL=index.d.ts.map
|
|
2
|
+
import { a as flattenTree, c as visit, i as findSiblings, n as findParent, o as getPageTreePeers, r as findPath, s as getPageTreeRoots, t as findNeighbour } from "../index-BaMZ8PEK.js";
|
|
3
|
+
export { Folder, Item, Node, Root, Separator, findNeighbour, findParent, findPath, findSiblings, flattenTree, getPageTreePeers, getPageTreeRoots, visit };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-code-Ct5Pb6BZ.js","names":["defaultShortcuts: Record<string, string>","defaultIcons: Record<string, CodeBlockIcon>","rehypeCodeDefaultOptions: RehypeCodeOptions","data: Record<string, unknown>","options: RehypeCodeOptions"],"sources":["../src/mdx-plugins/transformer-icon.ts","../src/mdx-plugins/rehype-code.ts"],"sourcesContent":["import { type ShikiTransformer } from 'shiki';\n\nexport type CodeBlockIcon =\n | {\n viewBox: string;\n fill: string;\n d: string;\n }\n | string;\n\nconst defaultShortcuts: Record<string, string> = {\n js: 'javascript',\n jsx: 'react',\n ts: 'typescript',\n tsx: 'react',\n 'c#': 'csharp',\n cs: 'csharp',\n gql: 'graphql',\n py: 'python',\n bash: 'shellscript',\n sh: 'shellscript',\n shell: 'shellscript',\n zsh: 'shellscript',\n 'c++': 'cpp',\n};\n\n// From https://simpleicons.org\n// Java - Not supported, https://github.com/simple-icons/simple-icons/issues/7374\nconst defaultIcons: Record<string, CodeBlockIcon> = {\n react: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M14.23 12.004a2.236 2.236 0 0 1-2.235 2.236 2.236 2.236 0 0 1-2.236-2.236 2.236 2.236 0 0 1 2.235-2.236 2.236 2.236 0 0 1 2.236 2.236zm2.648-10.69c-1.346 0-3.107.96-4.888 2.622-1.78-1.653-3.542-2.602-4.887-2.602-.41 0-.783.093-1.106.278-1.375.793-1.683 3.264-.973 6.365C1.98 8.917 0 10.42 0 12.004c0 1.59 1.99 3.097 5.043 4.03-.704 3.113-.39 5.588.988 6.38.32.187.69.275 1.102.275 1.345 0 3.107-.96 4.888-2.624 1.78 1.654 3.542 2.603 4.887 2.603.41 0 .783-.09 1.106-.275 1.374-.792 1.683-3.263.973-6.365C22.02 15.096 24 13.59 24 12.004c0-1.59-1.99-3.097-5.043-4.032.704-3.11.39-5.587-.988-6.38-.318-.184-.688-.277-1.092-.278zm-.005 1.09v.006c.225 0 .406.044.558.127.666.382.955 1.835.73 3.704-.054.46-.142.945-.25 1.44-.96-.236-2.006-.417-3.107-.534-.66-.905-1.345-1.727-2.035-2.447 1.592-1.48 3.087-2.292 4.105-2.295zm-9.77.02c1.012 0 2.514.808 4.11 2.28-.686.72-1.37 1.537-2.02 2.442-1.107.117-2.154.298-3.113.538-.112-.49-.195-.964-.254-1.42-.23-1.868.054-3.32.714-3.707.19-.09.4-.127.563-.132zm4.882 3.05c.455.468.91.992 1.36 1.564-.44-.02-.89-.034-1.345-.034-.46 0-.915.01-1.36.034.44-.572.895-1.096 1.345-1.565zM12 8.1c.74 0 1.477.034 2.202.093.406.582.802 1.203 1.183 1.86.372.64.71 1.29 1.018 1.946-.308.655-.646 1.31-1.013 1.95-.38.66-.773 1.288-1.18 1.87-.728.063-1.466.098-2.21.098-.74 0-1.477-.035-2.202-.093-.406-.582-.802-1.204-1.183-1.86-.372-.64-.71-1.29-1.018-1.946.303-.657.646-1.313 1.013-1.954.38-.66.773-1.286 1.18-1.868.728-.064 1.466-.098 2.21-.098zm-3.635.254c-.24.377-.48.763-.704 1.16-.225.39-.435.782-.635 1.174-.265-.656-.49-1.31-.676-1.947.64-.15 1.315-.283 2.015-.386zm7.26 0c.695.103 1.365.23 2.006.387-.18.632-.405 1.282-.66 1.933-.2-.39-.41-.783-.64-1.174-.225-.392-.465-.774-.705-1.146zm3.063.675c.484.15.944.317 1.375.498 1.732.74 2.852 1.708 2.852 2.476-.005.768-1.125 1.74-2.857 2.475-.42.18-.88.342-1.355.493-.28-.958-.646-1.956-1.1-2.98.45-1.017.81-2.01 1.085-2.964zm-13.395.004c.278.96.645 1.957 1.1 2.98-.45 1.017-.812 2.01-1.086 2.964-.484-.15-.944-.318-1.37-.5-1.732-.737-2.852-1.706-2.852-2.474 0-.768 1.12-1.742 2.852-2.476.42-.18.88-.342 1.356-.494zm11.678 4.28c.265.657.49 1.312.676 1.948-.64.157-1.316.29-2.016.39.24-.375.48-.762.705-1.158.225-.39.435-.788.636-1.18zm-9.945.02c.2.392.41.783.64 1.175.23.39.465.772.705 1.143-.695-.102-1.365-.23-2.006-.386.18-.63.406-1.282.66-1.933zM17.92 16.32c.112.493.2.968.254 1.423.23 1.868-.054 3.32-.714 3.708-.147.09-.338.128-.563.128-1.012 0-2.514-.807-4.11-2.28.686-.72 1.37-1.536 2.02-2.44 1.107-.118 2.154-.3 3.113-.54zm-11.83.01c.96.234 2.006.415 3.107.532.66.905 1.345 1.727 2.035 2.446-1.595 1.483-3.092 2.295-4.11 2.295-.22-.005-.406-.05-.553-.132-.666-.38-.955-1.834-.73-3.703.054-.46.142-.944.25-1.438zm4.56.64c.44.02.89.034 1.345.034.46 0 .915-.01 1.36-.034-.44.572-.895 1.095-1.345 1.565-.455-.47-.91-.993-1.36-1.565z',\n },\n vue: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M24,1.61H14.06L12,5.16,9.94,1.61H0L12,22.39ZM12,14.08,5.16,2.23H9.59L12,6.41l2.41-4.18h4.43Z',\n },\n ruby: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M20.156.083c3.033.525 3.893 2.598 3.829 4.77L24 4.822 22.635 22.71 4.89 23.926h.016C3.433 23.864.15 23.729 0 19.139l1.645-3 2.819 6.586.503 1.172 2.805-9.144-.03.007.016-.03 9.255 2.956-1.396-5.431-.99-3.9 8.82-.569-.615-.51L16.5 2.114 20.159.073l-.003.01zM0 19.089zM5.13 5.073c3.561-3.533 8.157-5.621 9.922-3.84 1.762 1.777-.105 6.105-3.673 9.636-3.563 3.532-8.103 5.734-9.864 3.957-1.766-1.777.045-6.217 3.612-9.75l.003-.003z',\n },\n zig: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'm23.53 1.02-7.686 3.45h-7.06l-2.98 3.452h7.173L.47 22.98l7.681-3.607h7.065v-.002l2.978-3.45-7.148-.001 12.482-14.9zM0 4.47v14.901h1.883l2.98-3.45H3.451v-8h.942l2.824-3.45H0zm22.117 0-2.98 3.608h1.412v7.844h-.942l-2.98 3.45H24V4.47h-1.883z',\n },\n swift: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M7.508 0c-.287 0-.573 0-.86.002-.241.002-.483.003-.724.01-.132.003-.263.009-.395.015A9.154 9.154 0 0 0 4.348.15 5.492 5.492 0 0 0 2.85.645 5.04 5.04 0 0 0 .645 2.848c-.245.48-.4.972-.495 1.5-.093.52-.122 1.05-.136 1.576a35.2 35.2 0 0 0-.012.724C0 6.935 0 7.221 0 7.508v8.984c0 .287 0 .575.002.862.002.24.005.481.012.722.014.526.043 1.057.136 1.576.095.528.25 1.02.495 1.5a5.03 5.03 0 0 0 2.205 2.203c.48.244.97.4 1.498.495.52.093 1.05.124 1.576.138.241.007.483.009.724.01.287.002.573.002.86.002h8.984c.287 0 .573 0 .86-.002.241-.001.483-.003.724-.01a10.523 10.523 0 0 0 1.578-.138 5.322 5.322 0 0 0 1.498-.495 5.035 5.035 0 0 0 2.203-2.203c.245-.48.4-.972.495-1.5.093-.52.124-1.05.138-1.576.007-.241.009-.481.01-.722.002-.287.002-.575.002-.862V7.508c0-.287 0-.573-.002-.86a33.662 33.662 0 0 0-.01-.724 10.5 10.5 0 0 0-.138-1.576 5.328 5.328 0 0 0-.495-1.5A5.039 5.039 0 0 0 21.152.645 5.32 5.32 0 0 0 19.654.15a10.493 10.493 0 0 0-1.578-.138 34.98 34.98 0 0 0-.722-.01C17.067 0 16.779 0 16.492 0H7.508zm6.035 3.41c4.114 2.47 6.545 7.162 5.549 11.131-.024.093-.05.181-.076.272l.002.001c2.062 2.538 1.5 5.258 1.236 4.745-1.072-2.086-3.066-1.568-4.088-1.043a6.803 6.803 0 0 1-.281.158l-.02.012-.002.002c-2.115 1.123-4.957 1.205-7.812-.022a12.568 12.568 0 0 1-5.64-4.838c.649.48 1.35.902 2.097 1.252 3.019 1.414 6.051 1.311 8.197-.002C9.651 12.73 7.101 9.67 5.146 7.191a10.628 10.628 0 0 1-1.005-1.384c2.34 2.142 6.038 4.83 7.365 5.576C8.69 8.408 6.208 4.743 6.324 4.86c4.436 4.47 8.528 6.996 8.528 6.996.154.085.27.154.36.213.085-.215.16-.437.224-.668.708-2.588-.09-5.548-1.893-7.992z',\n },\n prisma: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M21.8068 18.2848L13.5528.7565c-.207-.4382-.639-.7273-1.1286-.7541-.5023-.0293-.9523.213-1.2062.6253L2.266 15.1271c-.2773.4518-.2718 1.0091.0158 1.4555l4.3759 6.7786c.2608.4046.7127.6388 1.1823.6388.1332 0 .267-.0188.3987-.0577l12.7019-3.7568c.3891-.1151.7072-.3904.8737-.7553s.1633-.7828-.0075-1.1454zm-1.8481.7519L9.1814 22.2242c-.3292.0975-.6448-.1873-.5756-.5194l3.8501-18.4386c.072-.3448.5486-.3996.699-.0803l7.1288 15.138c.1344.2856-.019.6224-.325.7128z',\n },\n typescript: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M1.125 0C.502 0 0 .502 0 1.125v21.75C0 23.498.502 24 1.125 24h21.75c.623 0 1.125-.502 1.125-1.125V1.125C24 .502 23.498 0 22.875 0zm17.363 9.75c.612 0 1.154.037 1.627.111a6.38 6.38 0 0 1 1.306.34v2.458a3.95 3.95 0 0 0-.643-.361 5.093 5.093 0 0 0-.717-.26 5.453 5.453 0 0 0-1.426-.2c-.3 0-.573.028-.819.086a2.1 2.1 0 0 0-.623.242c-.17.104-.3.229-.393.374a.888.888 0 0 0-.14.49c0 .196.053.373.156.529.104.156.252.304.443.444s.423.276.696.41c.273.135.582.274.926.416.47.197.892.407 1.266.628.374.222.695.473.963.753.268.279.472.598.614.957.142.359.214.776.214 1.253 0 .657-.125 1.21-.373 1.656a3.033 3.033 0 0 1-1.012 1.085 4.38 4.38 0 0 1-1.487.596c-.566.12-1.163.18-1.79.18a9.916 9.916 0 0 1-1.84-.164 5.544 5.544 0 0 1-1.512-.493v-2.63a5.033 5.033 0 0 0 3.237 1.2c.333 0 .624-.03.872-.09.249-.06.456-.144.623-.25.166-.108.29-.234.373-.38a1.023 1.023 0 0 0-.074-1.089 2.12 2.12 0 0 0-.537-.5 5.597 5.597 0 0 0-.807-.444 27.72 27.72 0 0 0-1.007-.436c-.918-.383-1.602-.852-2.053-1.405-.45-.553-.676-1.222-.676-2.005 0-.614.123-1.141.369-1.582.246-.441.58-.804 1.004-1.089a4.494 4.494 0 0 1 1.47-.629 7.536 7.536 0 0 1 1.77-.201zm-15.113.188h9.563v2.166H9.506v9.646H6.789v-9.646H3.375z',\n },\n javascript: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M0 0h24v24H0V0zm22.034 18.276c-.175-1.095-.888-2.015-3.003-2.873-.736-.345-1.554-.585-1.797-1.14-.091-.33-.105-.51-.046-.705.15-.646.915-.84 1.515-.66.39.12.75.42.976.9 1.034-.676 1.034-.676 1.755-1.125-.27-.42-.404-.601-.586-.78-.63-.705-1.469-1.065-2.834-1.034l-.705.089c-.676.165-1.32.525-1.71 1.005-1.14 1.291-.811 3.541.569 4.471 1.365 1.02 3.361 1.244 3.616 2.205.24 1.17-.87 1.545-1.966 1.41-.811-.18-1.26-.586-1.755-1.336l-1.83 1.051c.21.48.45.689.81 1.109 1.74 1.756 6.09 1.666 6.871-1.004.029-.09.24-.705.074-1.65l.046.067zm-8.983-7.245h-2.248c0 1.938-.009 3.864-.009 5.805 0 1.232.063 2.363-.138 2.711-.33.689-1.18.601-1.566.48-.396-.196-.597-.466-.83-.855-.063-.105-.11-.196-.127-.196l-1.825 1.125c.305.63.75 1.172 1.324 1.517.855.51 2.004.675 3.207.405.783-.226 1.458-.691 1.811-1.411.51-.93.402-2.07.397-3.346.012-2.054 0-4.109 0-6.179l.004-.056z',\n },\n php: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M7.01 10.207h-.944l-.515 2.648h.838c.556 0 .97-.105 1.242-.314.272-.21.455-.559.55-1.049.092-.47.05-.802-.124-.995-.175-.193-.523-.29-1.047-.29zM12 5.688C5.373 5.688 0 8.514 0 12s5.373 6.313 12 6.313S24 15.486 24 12c0-3.486-5.373-6.312-12-6.312zm-3.26 7.451c-.261.25-.575.438-.917.551-.336.108-.765.164-1.285.164H5.357l-.327 1.681H3.652l1.23-6.326h2.65c.797 0 1.378.209 1.744.628.366.418.476 1.002.33 1.752a2.836 2.836 0 0 1-.305.847c-.143.255-.33.49-.561.703zm4.024.715l.543-2.799c.063-.318.039-.536-.068-.651-.107-.116-.336-.174-.687-.174H11.46l-.704 3.625H9.388l1.23-6.327h1.367l-.327 1.682h1.218c.767 0 1.295.134 1.586.401s.378.7.263 1.299l-.572 2.944h-1.389zm7.597-2.265a2.782 2.782 0 0 1-.305.847c-.143.255-.33.49-.561.703a2.44 2.44 0 0 1-.917.551c-.336.108-.765.164-1.286.164h-1.18l-.327 1.682h-1.378l1.23-6.326h2.649c.797 0 1.378.209 1.744.628.366.417.477 1.001.331 1.751zM17.766 10.207h-.943l-.516 2.648h.838c.557 0 .971-.105 1.242-.314.272-.21.455-.559.551-1.049.092-.47.049-.802-.125-.995s-.524-.29-1.047-.29z',\n },\n shellscript: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'm 4,4 a 1,1 0 0 0 -0.7070312,0.2929687 1,1 0 0 0 0,1.4140625 L 8.5859375,11 3.2929688,16.292969 a 1,1 0 0 0 0,1.414062 1,1 0 0 0 1.4140624,0 l 5.9999998,-6 a 1.0001,1.0001 0 0 0 0,-1.414062 L 4.7070312,4.2929687 A 1,1 0 0 0 4,4 Z m 8,14 a 1,1 0 0 0 -1,1 1,1 0 0 0 1,1 h 8 a 1,1 0 0 0 1,-1 1,1 0 0 0 -1,-1 z',\n },\n c: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M16.5921 9.1962s-.354-3.298-3.627-3.39c-3.2741-.09-4.9552 2.474-4.9552 6.14 0 3.6651 1.858 6.5972 5.0451 6.5972 3.184 0 3.5381-3.665 3.5381-3.665l6.1041.365s.36 3.31-2.196 5.836c-2.552 2.5241-5.6901 2.9371-7.8762 2.9201-2.19-.017-5.2261.034-8.1602-2.97-2.938-3.0101-3.436-5.9302-3.436-8.8002 0-2.8701.556-6.6702 4.047-9.5502C7.444.72 9.849 0 12.254 0c10.0422 0 10.7172 9.2602 10.7172 9.2602z',\n },\n cpp: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M22.394 6c-.167-.29-.398-.543-.652-.69L12.926.22c-.509-.294-1.34-.294-1.848 0L2.26 5.31c-.508.293-.923 1.013-.923 1.6v10.18c0 .294.104.62.271.91.167.29.398.543.652.69l8.816 5.09c.508.293 1.34.293 1.848 0l8.816-5.09c.254-.147.485-.4.652-.69.167-.29.27-.616.27-.91V6.91c.003-.294-.1-.62-.268-.91zM12 19.11c-3.92 0-7.109-3.19-7.109-7.11 0-3.92 3.19-7.11 7.11-7.11a7.133 7.133 0 016.156 3.553l-3.076 1.78a3.567 3.567 0 00-3.08-1.78A3.56 3.56 0 008.444 12 3.56 3.56 0 0012 15.555a3.57 3.57 0 003.08-1.778l3.078 1.78A7.135 7.135 0 0112 19.11zm7.11-6.715h-.79v.79h-.79v-.79h-.79v-.79h.79v-.79h.79v.79h.79zm2.962 0h-.79v.79h-.79v-.79h-.79v-.79h.79v-.79h.79v.79h.79z',\n },\n go: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M1.811 10.231c-.047 0-.058-.023-.035-.059l.246-.315c.023-.035.081-.058.128-.058h4.172c.046 0 .058.035.035.07l-.199.303c-.023.036-.082.07-.117.07zM.047 11.306c-.047 0-.059-.023-.035-.058l.245-.316c.023-.035.082-.058.129-.058h5.328c.047 0 .07.035.058.07l-.093.28c-.012.047-.058.07-.105.07zm2.828 1.075c-.047 0-.059-.035-.035-.07l.163-.292c.023-.035.07-.07.117-.07h2.337c.047 0 .07.035.07.082l-.023.28c0 .047-.047.082-.082.082zm12.129-2.36c-.736.187-1.239.327-1.963.514-.176.046-.187.058-.34-.117-.174-.199-.303-.327-.548-.444-.737-.362-1.45-.257-2.115.175-.795.514-1.204 1.274-1.192 2.22.011.935.654 1.706 1.577 1.835.795.105 1.46-.175 1.987-.77.105-.13.198-.27.315-.434H10.47c-.245 0-.304-.152-.222-.35.152-.362.432-.97.596-1.274a.315.315 0 01.292-.187h4.253c-.023.316-.023.631-.07.947a4.983 4.983 0 01-.958 2.29c-.841 1.11-1.94 1.8-3.33 1.986-1.145.152-2.209-.07-3.143-.77-.865-.655-1.356-1.52-1.484-2.595-.152-1.274.222-2.419.993-3.424.83-1.086 1.928-1.776 3.272-2.02 1.098-.2 2.15-.07 3.096.571.62.41 1.063.97 1.356 1.648.07.105.023.164-.117.2m3.868 6.461c-1.064-.024-2.034-.328-2.852-1.029a3.665 3.665 0 01-1.262-2.255c-.21-1.32.152-2.489.947-3.529.853-1.122 1.881-1.706 3.272-1.95 1.192-.21 2.314-.095 3.33.595.923.63 1.496 1.484 1.648 2.605.198 1.578-.257 2.863-1.344 3.962-.771.783-1.718 1.273-2.805 1.495-.315.06-.63.07-.934.106zm2.78-4.72c-.011-.153-.011-.27-.034-.387-.21-1.157-1.274-1.81-2.384-1.554-1.087.245-1.788.935-2.045 2.033-.21.912.234 1.835 1.075 2.21.643.28 1.285.244 1.905-.07.923-.48 1.425-1.228 1.484-2.233z',\n },\n graphql: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M12.002 0a2.138 2.138 0 1 0 0 4.277 2.138 2.138 0 1 0 0-4.277zm8.54 4.931a2.138 2.138 0 1 0 0 4.277 2.138 2.138 0 1 0 0-4.277zm0 9.862a2.138 2.138 0 1 0 0 4.277 2.138 2.138 0 1 0 0-4.277zm-8.54 4.931a2.138 2.138 0 1 0 0 4.276 2.138 2.138 0 1 0 0-4.276zm-8.542-4.93a2.138 2.138 0 1 0 0 4.276 2.138 2.138 0 1 0 0-4.277zm0-9.863a2.138 2.138 0 1 0 0 4.277 2.138 2.138 0 1 0 0-4.277zm8.542-3.378L2.953 6.777v10.448l9.049 5.224 9.047-5.224V6.777zm0 1.601 7.66 13.27H4.34zm-1.387.371L3.97 15.037V7.363zm2.774 0 6.646 3.838v7.674zM5.355 17.44h13.293l-6.646 3.836z',\n },\n python: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.77l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.17l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05-.05-1.23.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.18l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09zm13.09 3.95l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08z',\n },\n md: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M22.27 19.385H1.73A1.73 1.73 0 010 17.655V6.345a1.73 1.73 0 011.73-1.73h20.54A1.73 1.73 0 0124 6.345v11.308a1.73 1.73 0 01-1.73 1.731zM5.769 15.923v-4.5l2.308 2.885 2.307-2.885v4.5h2.308V8.078h-2.308l-2.307 2.885-2.308-2.885H3.46v7.847zM21.232 12h-2.309V8.077h-2.307V12h-2.308l3.461 4.039z',\n },\n kotlin: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M24 24H0V0h24L12 12Z',\n },\n rust: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M23.8346 11.7033l-1.0073-.6236a13.7268 13.7268 0 00-.0283-.2936l.8656-.8069a.3483.3483 0 00-.1154-.578l-1.1066-.414a8.4958 8.4958 0 00-.087-.2856l.6904-.9587a.3462.3462 0 00-.2257-.5446l-1.1663-.1894a9.3574 9.3574 0 00-.1407-.2622l.49-1.0761a.3437.3437 0 00-.0274-.3361.3486.3486 0 00-.3006-.154l-1.1845.0416a6.7444 6.7444 0 00-.1873-.2268l.2723-1.153a.3472.3472 0 00-.417-.4172l-1.1532.2724a14.0183 14.0183 0 00-.2278-.1873l.0415-1.1845a.3442.3442 0 00-.49-.328l-1.076.491c-.0872-.0476-.1742-.0952-.2623-.1407l-.1903-1.1673A.3483.3483 0 0016.256.955l-.9597.6905a8.4867 8.4867 0 00-.2855-.086l-.414-1.1066a.3483.3483 0 00-.5781-.1154l-.8069.8666a9.2936 9.2936 0 00-.2936-.0284L12.2946.1683a.3462.3462 0 00-.5892 0l-.6236 1.0073a13.7383 13.7383 0 00-.2936.0284L9.9803.3374a.3462.3462 0 00-.578.1154l-.4141 1.1065c-.0962.0274-.1903.0567-.2855.086L7.744.955a.3483.3483 0 00-.5447.2258L7.009 2.348a9.3574 9.3574 0 00-.2622.1407l-1.0762-.491a.3462.3462 0 00-.49.328l.0416 1.1845a7.9826 7.9826 0 00-.2278.1873L3.8413 3.425a.3472.3472 0 00-.4171.4171l.2713 1.1531c-.0628.075-.1255.1509-.1863.2268l-1.1845-.0415a.3462.3462 0 00-.328.49l.491 1.0761a9.167 9.167 0 00-.1407.2622l-1.1662.1894a.3483.3483 0 00-.2258.5446l.6904.9587a13.303 13.303 0 00-.087.2855l-1.1065.414a.3483.3483 0 00-.1155.5781l.8656.807a9.2936 9.2936 0 00-.0283.2935l-1.0073.6236a.3442.3442 0 000 .5892l1.0073.6236c.008.0982.0182.1964.0283.2936l-.8656.8079a.3462.3462 0 00.1155.578l1.1065.4141c.0273.0962.0567.1914.087.2855l-.6904.9587a.3452.3452 0 00.2268.5447l1.1662.1893c.0456.088.0922.1751.1408.2622l-.491 1.0762a.3462.3462 0 00.328.49l1.1834-.0415c.0618.0769.1235.1528.1873.2277l-.2713 1.1541a.3462.3462 0 00.4171.4161l1.153-.2713c.075.0638.151.1255.2279.1863l-.0415 1.1845a.3442.3442 0 00.49.327l1.0761-.49c.087.0486.1741.0951.2622.1407l.1903 1.1662a.3483.3483 0 00.5447.2268l.9587-.6904a9.299 9.299 0 00.2855.087l.414 1.1066a.3452.3452 0 00.5781.1154l.8079-.8656c.0972.0111.1954.0203.2936.0294l.6236 1.0073a.3472.3472 0 00.5892 0l.6236-1.0073c.0982-.0091.1964-.0183.2936-.0294l.8069.8656a.3483.3483 0 00.578-.1154l.4141-1.1066a8.4626 8.4626 0 00.2855-.087l.9587.6904a.3452.3452 0 00.5447-.2268l.1903-1.1662c.088-.0456.1751-.0931.2622-.1407l1.0762.49a.3472.3472 0 00.49-.327l-.0415-1.1845a6.7267 6.7267 0 00.2267-.1863l1.1531.2713a.3472.3472 0 00.4171-.416l-.2713-1.1542c.0628-.0749.1255-.1508.1863-.2278l1.1845.0415a.3442.3442 0 00.328-.49l-.49-1.076c.0475-.0872.0951-.1742.1407-.2623l1.1662-.1893a.3483.3483 0 00.2258-.5447l-.6904-.9587.087-.2855 1.1066-.414a.3462.3462 0 00.1154-.5781l-.8656-.8079c.0101-.0972.0202-.1954.0283-.2936l1.0073-.6236a.3442.3442 0 000-.5892zm-6.7413 8.3551a.7138.7138 0 01.2986-1.396.714.714 0 11-.2997 1.396zm-.3422-2.3142a.649.649 0 00-.7715.5l-.3573 1.6685c-1.1035.501-2.3285.7795-3.6193.7795a8.7368 8.7368 0 01-3.6951-.814l-.3574-1.6684a.648.648 0 00-.7714-.499l-1.473.3158a8.7216 8.7216 0 01-.7613-.898h7.1676c.081 0 .1356-.0141.1356-.088v-2.536c0-.074-.0536-.0881-.1356-.0881h-2.0966v-1.6077h2.2677c.2065 0 1.1065.0587 1.394 1.2088.0901.3533.2875 1.5044.4232 1.8729.1346.413.6833 1.2381 1.2685 1.2381h3.5716a.7492.7492 0 00.1296-.0131 8.7874 8.7874 0 01-.8119.9526zM6.8369 20.024a.714.714 0 11-.2997-1.396.714.714 0 01.2997 1.396zM4.1177 8.9972a.7137.7137 0 11-1.304.5791.7137.7137 0 011.304-.579zm-.8352 1.9813l1.5347-.6824a.65.65 0 00.33-.8585l-.3158-.7147h1.2432v5.6025H3.5669a8.7753 8.7753 0 01-.2834-3.348zm6.7343-.5437V8.7836h2.9601c.153 0 1.0792.1772 1.0792.8697 0 .575-.7107.7815-1.2948.7815zm10.7574 1.4862c0 .2187-.008.4363-.0243.651h-.9c-.09 0-.1265.0586-.1265.1477v.413c0 .973-.5487 1.1846-1.0296 1.2382-.4576.0517-.9648-.1913-1.0275-.4717-.2704-1.5186-.7198-1.8436-1.4305-2.4034.8817-.5599 1.799-1.386 1.799-2.4915 0-1.1936-.819-1.9458-1.3769-2.3153-.7825-.5163-1.6491-.6195-1.883-.6195H5.4682a8.7651 8.7651 0 014.907-2.7699l1.0974 1.151a.648.648 0 00.9182.0213l1.227-1.1743a8.7753 8.7753 0 016.0044 4.2762l-.8403 1.8982a.652.652 0 00.33.8585l1.6178.7188c.0283.2875.0425.577.0425.8717zm-9.3006-9.5993a.7128.7128 0 11.984 1.0316.7137.7137 0 01-.984-1.0316zm8.3389 6.71a.7107.7107 0 01.9395-.3625.7137.7137 0 11-.9405.3635z',\n },\n csharp: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M1.194 7.543v8.913c0 1.103.588 2.122 1.544 2.674l7.718 4.456a3.086 3.086 0 0 0 3.088 0l7.718-4.456a3.087 3.087 0 0 0 1.544-2.674V7.543a3.084 3.084 0 0 0-1.544-2.673L13.544.414a3.086 3.086 0 0 0-3.088 0L2.738 4.87a3.085 3.085 0 0 0-1.544 2.673Zm5.403 2.914v3.087a.77.77 0 0 0 .772.772.773.773 0 0 0 .772-.772.773.773 0 0 1 1.317-.546.775.775 0 0 1 .226.546 2.314 2.314 0 1 1-4.631 0v-3.087c0-.615.244-1.203.679-1.637a2.312 2.312 0 0 1 3.274 0c.434.434.678 1.023.678 1.637a.769.769 0 0 1-.226.545.767.767 0 0 1-1.091 0 .77.77 0 0 1-.226-.545.77.77 0 0 0-.772-.772.771.771 0 0 0-.772.772Zm12.35 3.087a.77.77 0 0 1-.772.772h-.772v.772a.773.773 0 0 1-1.544 0v-.772h-1.544v.772a.773.773 0 0 1-1.317.546.775.775 0 0 1-.226-.546v-.772H12a.771.771 0 1 1 0-1.544h.772v-1.543H12a.77.77 0 1 1 0-1.544h.772v-.772a.773.773 0 0 1 1.317-.546.775.775 0 0 1 .226.546v.772h1.544v-.772a.773.773 0 0 1 1.544 0v.772h.772a.772.772 0 0 1 0 1.544h-.772v1.543h.772a.776.776 0 0 1 .772.772Zm-3.088-2.315h-1.544v1.543h1.544v-1.543Z',\n },\n default: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M 6,1 C 4.354992,1 3,2.354992 3,4 v 16 c 0,1.645008 1.354992,3 3,3 h 12 c 1.645008,0 3,-1.354992 3,-3 V 8 7 A 1.0001,1.0001 0 0 0 20.707031,6.2929687 l -5,-5 A 1.0001,1.0001 0 0 0 15,1 h -1 z m 0,2 h 7 v 3 c 0,1.645008 1.354992,3 3,3 h 3 v 11 c 0,0.564129 -0.435871,1 -1,1 H 6 C 5.4358712,21 5,20.564129 5,20 V 4 C 5,3.4358712 5.4358712,3 6,3 Z M 15,3.4140625 18.585937,7 H 16 C 15.435871,7 15,6.5641288 15,6 Z',\n },\n};\n\nexport interface IconOptions {\n shortcuts?: Record<string, string>;\n extend?: Record<string, CodeBlockIcon>;\n}\n\n/**\n * Inject icons to `icon` property (as HTML)\n */\nexport function transformerIcon(options: IconOptions = {}): ShikiTransformer {\n const shortcuts = {\n ...defaultShortcuts,\n ...options.shortcuts,\n };\n const icons = {\n ...defaultIcons,\n ...options.extend,\n };\n\n const defaultIcon = 'default' in icons ? icons.default : undefined;\n return {\n name: 'rehype-code:icon',\n pre(pre) {\n const lang = this.options.lang;\n if (!lang) return;\n\n const iconName = lang in shortcuts ? shortcuts[lang] : lang;\n const icon = iconName in icons ? icons[iconName] : defaultIcon;\n\n if (icon) {\n pre.properties.icon =\n typeof icon === 'string'\n ? icon\n : `<svg viewBox=\"${icon.viewBox}\"><path d=\"${icon.d}\" fill=\"${icon.fill}\" /></svg>`;\n }\n\n return pre;\n },\n };\n}\n","import type { Root } from 'hast';\nimport type { RehypeShikiOptions } from '@shikijs/rehype';\nimport rehypeShikiFromHighlighter from '@shikijs/rehype/core';\nimport {\n transformerNotationDiff,\n transformerNotationFocus,\n transformerNotationHighlight,\n transformerNotationWordHighlight,\n} from '@shikijs/transformers';\nimport type { Processor, Transformer } from 'unified';\nimport { type BuiltinTheme, bundledLanguages, type ShikiTransformer } from 'shiki';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport type { CodeBlockIcon, IconOptions } from './transformer-icon';\nimport { transformerIcon } from './transformer-icon';\nimport { defaultThemes, getHighlighter } from '@/highlight/shiki';\nimport { parseCodeBlockAttributes } from '@/mdx-plugins/codeblock-utils';\n\nexport const rehypeCodeDefaultOptions: RehypeCodeOptions = {\n lazy: true,\n themes: defaultThemes,\n defaultColor: false,\n defaultLanguage: 'plaintext',\n engine: 'js',\n transformers: [\n transformerNotationHighlight({\n matchAlgorithm: 'v3',\n }),\n transformerNotationWordHighlight({\n matchAlgorithm: 'v3',\n }),\n transformerNotationDiff({\n matchAlgorithm: 'v3',\n }),\n transformerNotationFocus({\n matchAlgorithm: 'v3',\n }),\n ],\n parseMetaString(meta) {\n const parsed = parseCodeBlockAttributes(meta, ['title', 'tab']);\n const data: Record<string, unknown> = parsed.attributes;\n parsed.rest = parseLineNumber(parsed.rest, data);\n\n data.__parsed_raw = parsed.rest;\n return data;\n },\n};\n\nfunction parseLineNumber(str: string, data: Record<string, unknown>) {\n return str.replace(/lineNumbers=(\\d+)|lineNumbers/, (_, ...args) => {\n data['data-line-numbers'] = true;\n\n if (args[0] !== undefined) data['data-line-numbers-start'] = Number(args[0]);\n\n return '';\n });\n}\n\ntype DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;\n\nexport type RehypeCodeOptions = DistributiveOmit<RehypeShikiOptions, 'lazy'> & {\n /**\n * Load languages and themes on-demand.\n * @defaultValue true\n */\n lazy?: boolean;\n\n /**\n * The regex engine to use.\n *\n * @defaultValue 'js'\n */\n engine?: 'js' | 'oniguruma';\n\n /**\n * Filter meta string before processing\n */\n filterMetaString?: (metaString: string) => string;\n\n /**\n * Add icon to code blocks\n */\n icon?: IconOptions | false;\n\n /**\n * Wrap code blocks in `<Tab>` component when \"tab\" meta string presents\n *\n * @defaultValue true\n */\n tab?: boolean;\n};\n\n/**\n * Handle codeblocks\n */\nexport function rehypeCode(\n this: Processor,\n _options: Partial<RehypeCodeOptions> = {},\n): Transformer<Root, Root> {\n const options: RehypeCodeOptions = {\n ...rehypeCodeDefaultOptions,\n ..._options,\n };\n\n const transformers = [...(options.transformers ?? [])];\n transformers.unshift({\n name: 'rehype-code:pre-process',\n preprocess(code, { meta }) {\n if (meta && '__parsed_raw' in meta) {\n meta.__raw = meta.__parsed_raw;\n delete meta.__parsed_raw;\n }\n\n if (meta && options.filterMetaString) {\n meta.__raw = options.filterMetaString(meta.__raw ?? '');\n }\n\n // Remove empty line at end\n return code.replace(/\\n$/, '');\n },\n });\n\n if (options.icon !== false) {\n transformers.push(transformerIcon(options.icon));\n }\n\n if (options.tab !== false) {\n transformers.push(transformerTab());\n }\n\n const highlighter = getHighlighter(options.engine ?? 'js', {\n themes:\n 'themes' in options\n ? (Object.values(options.themes).filter(Boolean) as BuiltinTheme[])\n : [options.theme],\n langs:\n options.langs ?? (options.lazy ? ['js', 'jsx', 'ts', 'tsx'] : Object.keys(bundledLanguages)),\n langAlias: options.langAlias,\n });\n\n const transformer = highlighter.then((loaded) =>\n rehypeShikiFromHighlighter(loaded, {\n ...options,\n transformers,\n }),\n );\n\n return async (tree, file) => {\n await (\n await transformer\n )(tree, file, () => {\n // nothing\n });\n };\n}\n\nfunction transformerTab(): ShikiTransformer {\n return {\n name: 'rehype-code:tab',\n // @ts-expect-error -- types not compatible with MDX\n root(root) {\n const value = this.options.meta?.tab;\n if (typeof value !== 'string') return root;\n console.warn(\n '[Fumadocs] For `tab=\"value\" in codeblocks, please use `remarkCodeTab` plugin instead.',\n );\n\n return {\n type: 'root',\n children: [\n {\n type: 'mdxJsxFlowElement',\n name: 'Tab',\n data: {\n _codeblock: true,\n },\n attributes: [{ type: 'mdxJsxAttribute', name: 'value', value }],\n children: root.children,\n } as MdxJsxFlowElement,\n ],\n };\n },\n };\n}\n\nexport { type CodeBlockIcon, transformerIcon, transformerTab };\n"],"mappings":";;;;;;;AAUA,MAAMA,mBAA2C;CAC/C,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,KAAK;CACL,MAAM;CACN,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,OAAO;CACP,KAAK;CACL,OAAO;CACR;AAID,MAAMC,eAA8C;CAClD,OAAO;EACL,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,KAAK;EACH,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,MAAM;EACJ,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,KAAK;EACH,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,OAAO;EACL,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,QAAQ;EACN,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,YAAY;EACV,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,YAAY;EACV,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,KAAK;EACH,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,aAAa;EACX,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,GAAG;EACD,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,KAAK;EACH,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AG;EACH;EACD,CAAC,CACH;AAED,QAAO,OAAO,MAAM,SAAS;AAC3B,SACE,MAAM,aACN,MAAM,YAAY,GAElB;;;AAIN,SAAS,iBAAmC;AAC1C,QAAO;EACL,MAAM;EAEN,KAAK,MAAM;GACT,MAAM,QAAQ,KAAK,QAAQ,MAAM;AACjC,OAAI,OAAO,UAAU,SAAU,QAAO;AACtC,WAAQ,KACN,0FACD;AAED,UAAO;IACL,MAAM;IACN,UAAU,CACR;KACE,MAAM;KACN,MAAM;KACN,MAAM,EACJ,YAAY,MACb;KACD,YAAY,CAAC;MAAE,MAAM;MAAmB,MAAM;MAAS;MAAO,CAAC;KAC/D,UAAU,KAAK;KAChB,CACF;IACF;;EAEJ"}
|
|
1
|
+
{"version":3,"file":"rehype-code-Ct5Pb6BZ.js","names":[],"sources":["../src/mdx-plugins/transformer-icon.ts","../src/mdx-plugins/rehype-code.ts"],"sourcesContent":["import { type ShikiTransformer } from 'shiki';\n\nexport type CodeBlockIcon =\n | {\n viewBox: string;\n fill: string;\n d: string;\n }\n | string;\n\nconst defaultShortcuts: Record<string, string> = {\n js: 'javascript',\n jsx: 'react',\n ts: 'typescript',\n tsx: 'react',\n 'c#': 'csharp',\n cs: 'csharp',\n gql: 'graphql',\n py: 'python',\n bash: 'shellscript',\n sh: 'shellscript',\n shell: 'shellscript',\n zsh: 'shellscript',\n 'c++': 'cpp',\n};\n\n// From https://simpleicons.org\n// Java - Not supported, https://github.com/simple-icons/simple-icons/issues/7374\nconst defaultIcons: Record<string, CodeBlockIcon> = {\n react: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M14.23 12.004a2.236 2.236 0 0 1-2.235 2.236 2.236 2.236 0 0 1-2.236-2.236 2.236 2.236 0 0 1 2.235-2.236 2.236 2.236 0 0 1 2.236 2.236zm2.648-10.69c-1.346 0-3.107.96-4.888 2.622-1.78-1.653-3.542-2.602-4.887-2.602-.41 0-.783.093-1.106.278-1.375.793-1.683 3.264-.973 6.365C1.98 8.917 0 10.42 0 12.004c0 1.59 1.99 3.097 5.043 4.03-.704 3.113-.39 5.588.988 6.38.32.187.69.275 1.102.275 1.345 0 3.107-.96 4.888-2.624 1.78 1.654 3.542 2.603 4.887 2.603.41 0 .783-.09 1.106-.275 1.374-.792 1.683-3.263.973-6.365C22.02 15.096 24 13.59 24 12.004c0-1.59-1.99-3.097-5.043-4.032.704-3.11.39-5.587-.988-6.38-.318-.184-.688-.277-1.092-.278zm-.005 1.09v.006c.225 0 .406.044.558.127.666.382.955 1.835.73 3.704-.054.46-.142.945-.25 1.44-.96-.236-2.006-.417-3.107-.534-.66-.905-1.345-1.727-2.035-2.447 1.592-1.48 3.087-2.292 4.105-2.295zm-9.77.02c1.012 0 2.514.808 4.11 2.28-.686.72-1.37 1.537-2.02 2.442-1.107.117-2.154.298-3.113.538-.112-.49-.195-.964-.254-1.42-.23-1.868.054-3.32.714-3.707.19-.09.4-.127.563-.132zm4.882 3.05c.455.468.91.992 1.36 1.564-.44-.02-.89-.034-1.345-.034-.46 0-.915.01-1.36.034.44-.572.895-1.096 1.345-1.565zM12 8.1c.74 0 1.477.034 2.202.093.406.582.802 1.203 1.183 1.86.372.64.71 1.29 1.018 1.946-.308.655-.646 1.31-1.013 1.95-.38.66-.773 1.288-1.18 1.87-.728.063-1.466.098-2.21.098-.74 0-1.477-.035-2.202-.093-.406-.582-.802-1.204-1.183-1.86-.372-.64-.71-1.29-1.018-1.946.303-.657.646-1.313 1.013-1.954.38-.66.773-1.286 1.18-1.868.728-.064 1.466-.098 2.21-.098zm-3.635.254c-.24.377-.48.763-.704 1.16-.225.39-.435.782-.635 1.174-.265-.656-.49-1.31-.676-1.947.64-.15 1.315-.283 2.015-.386zm7.26 0c.695.103 1.365.23 2.006.387-.18.632-.405 1.282-.66 1.933-.2-.39-.41-.783-.64-1.174-.225-.392-.465-.774-.705-1.146zm3.063.675c.484.15.944.317 1.375.498 1.732.74 2.852 1.708 2.852 2.476-.005.768-1.125 1.74-2.857 2.475-.42.18-.88.342-1.355.493-.28-.958-.646-1.956-1.1-2.98.45-1.017.81-2.01 1.085-2.964zm-13.395.004c.278.96.645 1.957 1.1 2.98-.45 1.017-.812 2.01-1.086 2.964-.484-.15-.944-.318-1.37-.5-1.732-.737-2.852-1.706-2.852-2.474 0-.768 1.12-1.742 2.852-2.476.42-.18.88-.342 1.356-.494zm11.678 4.28c.265.657.49 1.312.676 1.948-.64.157-1.316.29-2.016.39.24-.375.48-.762.705-1.158.225-.39.435-.788.636-1.18zm-9.945.02c.2.392.41.783.64 1.175.23.39.465.772.705 1.143-.695-.102-1.365-.23-2.006-.386.18-.63.406-1.282.66-1.933zM17.92 16.32c.112.493.2.968.254 1.423.23 1.868-.054 3.32-.714 3.708-.147.09-.338.128-.563.128-1.012 0-2.514-.807-4.11-2.28.686-.72 1.37-1.536 2.02-2.44 1.107-.118 2.154-.3 3.113-.54zm-11.83.01c.96.234 2.006.415 3.107.532.66.905 1.345 1.727 2.035 2.446-1.595 1.483-3.092 2.295-4.11 2.295-.22-.005-.406-.05-.553-.132-.666-.38-.955-1.834-.73-3.703.054-.46.142-.944.25-1.438zm4.56.64c.44.02.89.034 1.345.034.46 0 .915-.01 1.36-.034-.44.572-.895 1.095-1.345 1.565-.455-.47-.91-.993-1.36-1.565z',\n },\n vue: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M24,1.61H14.06L12,5.16,9.94,1.61H0L12,22.39ZM12,14.08,5.16,2.23H9.59L12,6.41l2.41-4.18h4.43Z',\n },\n ruby: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M20.156.083c3.033.525 3.893 2.598 3.829 4.77L24 4.822 22.635 22.71 4.89 23.926h.016C3.433 23.864.15 23.729 0 19.139l1.645-3 2.819 6.586.503 1.172 2.805-9.144-.03.007.016-.03 9.255 2.956-1.396-5.431-.99-3.9 8.82-.569-.615-.51L16.5 2.114 20.159.073l-.003.01zM0 19.089zM5.13 5.073c3.561-3.533 8.157-5.621 9.922-3.84 1.762 1.777-.105 6.105-3.673 9.636-3.563 3.532-8.103 5.734-9.864 3.957-1.766-1.777.045-6.217 3.612-9.75l.003-.003z',\n },\n zig: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'm23.53 1.02-7.686 3.45h-7.06l-2.98 3.452h7.173L.47 22.98l7.681-3.607h7.065v-.002l2.978-3.45-7.148-.001 12.482-14.9zM0 4.47v14.901h1.883l2.98-3.45H3.451v-8h.942l2.824-3.45H0zm22.117 0-2.98 3.608h1.412v7.844h-.942l-2.98 3.45H24V4.47h-1.883z',\n },\n swift: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M7.508 0c-.287 0-.573 0-.86.002-.241.002-.483.003-.724.01-.132.003-.263.009-.395.015A9.154 9.154 0 0 0 4.348.15 5.492 5.492 0 0 0 2.85.645 5.04 5.04 0 0 0 .645 2.848c-.245.48-.4.972-.495 1.5-.093.52-.122 1.05-.136 1.576a35.2 35.2 0 0 0-.012.724C0 6.935 0 7.221 0 7.508v8.984c0 .287 0 .575.002.862.002.24.005.481.012.722.014.526.043 1.057.136 1.576.095.528.25 1.02.495 1.5a5.03 5.03 0 0 0 2.205 2.203c.48.244.97.4 1.498.495.52.093 1.05.124 1.576.138.241.007.483.009.724.01.287.002.573.002.86.002h8.984c.287 0 .573 0 .86-.002.241-.001.483-.003.724-.01a10.523 10.523 0 0 0 1.578-.138 5.322 5.322 0 0 0 1.498-.495 5.035 5.035 0 0 0 2.203-2.203c.245-.48.4-.972.495-1.5.093-.52.124-1.05.138-1.576.007-.241.009-.481.01-.722.002-.287.002-.575.002-.862V7.508c0-.287 0-.573-.002-.86a33.662 33.662 0 0 0-.01-.724 10.5 10.5 0 0 0-.138-1.576 5.328 5.328 0 0 0-.495-1.5A5.039 5.039 0 0 0 21.152.645 5.32 5.32 0 0 0 19.654.15a10.493 10.493 0 0 0-1.578-.138 34.98 34.98 0 0 0-.722-.01C17.067 0 16.779 0 16.492 0H7.508zm6.035 3.41c4.114 2.47 6.545 7.162 5.549 11.131-.024.093-.05.181-.076.272l.002.001c2.062 2.538 1.5 5.258 1.236 4.745-1.072-2.086-3.066-1.568-4.088-1.043a6.803 6.803 0 0 1-.281.158l-.02.012-.002.002c-2.115 1.123-4.957 1.205-7.812-.022a12.568 12.568 0 0 1-5.64-4.838c.649.48 1.35.902 2.097 1.252 3.019 1.414 6.051 1.311 8.197-.002C9.651 12.73 7.101 9.67 5.146 7.191a10.628 10.628 0 0 1-1.005-1.384c2.34 2.142 6.038 4.83 7.365 5.576C8.69 8.408 6.208 4.743 6.324 4.86c4.436 4.47 8.528 6.996 8.528 6.996.154.085.27.154.36.213.085-.215.16-.437.224-.668.708-2.588-.09-5.548-1.893-7.992z',\n },\n prisma: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M21.8068 18.2848L13.5528.7565c-.207-.4382-.639-.7273-1.1286-.7541-.5023-.0293-.9523.213-1.2062.6253L2.266 15.1271c-.2773.4518-.2718 1.0091.0158 1.4555l4.3759 6.7786c.2608.4046.7127.6388 1.1823.6388.1332 0 .267-.0188.3987-.0577l12.7019-3.7568c.3891-.1151.7072-.3904.8737-.7553s.1633-.7828-.0075-1.1454zm-1.8481.7519L9.1814 22.2242c-.3292.0975-.6448-.1873-.5756-.5194l3.8501-18.4386c.072-.3448.5486-.3996.699-.0803l7.1288 15.138c.1344.2856-.019.6224-.325.7128z',\n },\n typescript: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M1.125 0C.502 0 0 .502 0 1.125v21.75C0 23.498.502 24 1.125 24h21.75c.623 0 1.125-.502 1.125-1.125V1.125C24 .502 23.498 0 22.875 0zm17.363 9.75c.612 0 1.154.037 1.627.111a6.38 6.38 0 0 1 1.306.34v2.458a3.95 3.95 0 0 0-.643-.361 5.093 5.093 0 0 0-.717-.26 5.453 5.453 0 0 0-1.426-.2c-.3 0-.573.028-.819.086a2.1 2.1 0 0 0-.623.242c-.17.104-.3.229-.393.374a.888.888 0 0 0-.14.49c0 .196.053.373.156.529.104.156.252.304.443.444s.423.276.696.41c.273.135.582.274.926.416.47.197.892.407 1.266.628.374.222.695.473.963.753.268.279.472.598.614.957.142.359.214.776.214 1.253 0 .657-.125 1.21-.373 1.656a3.033 3.033 0 0 1-1.012 1.085 4.38 4.38 0 0 1-1.487.596c-.566.12-1.163.18-1.79.18a9.916 9.916 0 0 1-1.84-.164 5.544 5.544 0 0 1-1.512-.493v-2.63a5.033 5.033 0 0 0 3.237 1.2c.333 0 .624-.03.872-.09.249-.06.456-.144.623-.25.166-.108.29-.234.373-.38a1.023 1.023 0 0 0-.074-1.089 2.12 2.12 0 0 0-.537-.5 5.597 5.597 0 0 0-.807-.444 27.72 27.72 0 0 0-1.007-.436c-.918-.383-1.602-.852-2.053-1.405-.45-.553-.676-1.222-.676-2.005 0-.614.123-1.141.369-1.582.246-.441.58-.804 1.004-1.089a4.494 4.494 0 0 1 1.47-.629 7.536 7.536 0 0 1 1.77-.201zm-15.113.188h9.563v2.166H9.506v9.646H6.789v-9.646H3.375z',\n },\n javascript: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M0 0h24v24H0V0zm22.034 18.276c-.175-1.095-.888-2.015-3.003-2.873-.736-.345-1.554-.585-1.797-1.14-.091-.33-.105-.51-.046-.705.15-.646.915-.84 1.515-.66.39.12.75.42.976.9 1.034-.676 1.034-.676 1.755-1.125-.27-.42-.404-.601-.586-.78-.63-.705-1.469-1.065-2.834-1.034l-.705.089c-.676.165-1.32.525-1.71 1.005-1.14 1.291-.811 3.541.569 4.471 1.365 1.02 3.361 1.244 3.616 2.205.24 1.17-.87 1.545-1.966 1.41-.811-.18-1.26-.586-1.755-1.336l-1.83 1.051c.21.48.45.689.81 1.109 1.74 1.756 6.09 1.666 6.871-1.004.029-.09.24-.705.074-1.65l.046.067zm-8.983-7.245h-2.248c0 1.938-.009 3.864-.009 5.805 0 1.232.063 2.363-.138 2.711-.33.689-1.18.601-1.566.48-.396-.196-.597-.466-.83-.855-.063-.105-.11-.196-.127-.196l-1.825 1.125c.305.63.75 1.172 1.324 1.517.855.51 2.004.675 3.207.405.783-.226 1.458-.691 1.811-1.411.51-.93.402-2.07.397-3.346.012-2.054 0-4.109 0-6.179l.004-.056z',\n },\n php: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M7.01 10.207h-.944l-.515 2.648h.838c.556 0 .97-.105 1.242-.314.272-.21.455-.559.55-1.049.092-.47.05-.802-.124-.995-.175-.193-.523-.29-1.047-.29zM12 5.688C5.373 5.688 0 8.514 0 12s5.373 6.313 12 6.313S24 15.486 24 12c0-3.486-5.373-6.312-12-6.312zm-3.26 7.451c-.261.25-.575.438-.917.551-.336.108-.765.164-1.285.164H5.357l-.327 1.681H3.652l1.23-6.326h2.65c.797 0 1.378.209 1.744.628.366.418.476 1.002.33 1.752a2.836 2.836 0 0 1-.305.847c-.143.255-.33.49-.561.703zm4.024.715l.543-2.799c.063-.318.039-.536-.068-.651-.107-.116-.336-.174-.687-.174H11.46l-.704 3.625H9.388l1.23-6.327h1.367l-.327 1.682h1.218c.767 0 1.295.134 1.586.401s.378.7.263 1.299l-.572 2.944h-1.389zm7.597-2.265a2.782 2.782 0 0 1-.305.847c-.143.255-.33.49-.561.703a2.44 2.44 0 0 1-.917.551c-.336.108-.765.164-1.286.164h-1.18l-.327 1.682h-1.378l1.23-6.326h2.649c.797 0 1.378.209 1.744.628.366.417.477 1.001.331 1.751zM17.766 10.207h-.943l-.516 2.648h.838c.557 0 .971-.105 1.242-.314.272-.21.455-.559.551-1.049.092-.47.049-.802-.125-.995s-.524-.29-1.047-.29z',\n },\n shellscript: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'm 4,4 a 1,1 0 0 0 -0.7070312,0.2929687 1,1 0 0 0 0,1.4140625 L 8.5859375,11 3.2929688,16.292969 a 1,1 0 0 0 0,1.414062 1,1 0 0 0 1.4140624,0 l 5.9999998,-6 a 1.0001,1.0001 0 0 0 0,-1.414062 L 4.7070312,4.2929687 A 1,1 0 0 0 4,4 Z m 8,14 a 1,1 0 0 0 -1,1 1,1 0 0 0 1,1 h 8 a 1,1 0 0 0 1,-1 1,1 0 0 0 -1,-1 z',\n },\n c: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M16.5921 9.1962s-.354-3.298-3.627-3.39c-3.2741-.09-4.9552 2.474-4.9552 6.14 0 3.6651 1.858 6.5972 5.0451 6.5972 3.184 0 3.5381-3.665 3.5381-3.665l6.1041.365s.36 3.31-2.196 5.836c-2.552 2.5241-5.6901 2.9371-7.8762 2.9201-2.19-.017-5.2261.034-8.1602-2.97-2.938-3.0101-3.436-5.9302-3.436-8.8002 0-2.8701.556-6.6702 4.047-9.5502C7.444.72 9.849 0 12.254 0c10.0422 0 10.7172 9.2602 10.7172 9.2602z',\n },\n cpp: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M22.394 6c-.167-.29-.398-.543-.652-.69L12.926.22c-.509-.294-1.34-.294-1.848 0L2.26 5.31c-.508.293-.923 1.013-.923 1.6v10.18c0 .294.104.62.271.91.167.29.398.543.652.69l8.816 5.09c.508.293 1.34.293 1.848 0l8.816-5.09c.254-.147.485-.4.652-.69.167-.29.27-.616.27-.91V6.91c.003-.294-.1-.62-.268-.91zM12 19.11c-3.92 0-7.109-3.19-7.109-7.11 0-3.92 3.19-7.11 7.11-7.11a7.133 7.133 0 016.156 3.553l-3.076 1.78a3.567 3.567 0 00-3.08-1.78A3.56 3.56 0 008.444 12 3.56 3.56 0 0012 15.555a3.57 3.57 0 003.08-1.778l3.078 1.78A7.135 7.135 0 0112 19.11zm7.11-6.715h-.79v.79h-.79v-.79h-.79v-.79h.79v-.79h.79v.79h.79zm2.962 0h-.79v.79h-.79v-.79h-.79v-.79h.79v-.79h.79v.79h.79z',\n },\n go: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M1.811 10.231c-.047 0-.058-.023-.035-.059l.246-.315c.023-.035.081-.058.128-.058h4.172c.046 0 .058.035.035.07l-.199.303c-.023.036-.082.07-.117.07zM.047 11.306c-.047 0-.059-.023-.035-.058l.245-.316c.023-.035.082-.058.129-.058h5.328c.047 0 .07.035.058.07l-.093.28c-.012.047-.058.07-.105.07zm2.828 1.075c-.047 0-.059-.035-.035-.07l.163-.292c.023-.035.07-.07.117-.07h2.337c.047 0 .07.035.07.082l-.023.28c0 .047-.047.082-.082.082zm12.129-2.36c-.736.187-1.239.327-1.963.514-.176.046-.187.058-.34-.117-.174-.199-.303-.327-.548-.444-.737-.362-1.45-.257-2.115.175-.795.514-1.204 1.274-1.192 2.22.011.935.654 1.706 1.577 1.835.795.105 1.46-.175 1.987-.77.105-.13.198-.27.315-.434H10.47c-.245 0-.304-.152-.222-.35.152-.362.432-.97.596-1.274a.315.315 0 01.292-.187h4.253c-.023.316-.023.631-.07.947a4.983 4.983 0 01-.958 2.29c-.841 1.11-1.94 1.8-3.33 1.986-1.145.152-2.209-.07-3.143-.77-.865-.655-1.356-1.52-1.484-2.595-.152-1.274.222-2.419.993-3.424.83-1.086 1.928-1.776 3.272-2.02 1.098-.2 2.15-.07 3.096.571.62.41 1.063.97 1.356 1.648.07.105.023.164-.117.2m3.868 6.461c-1.064-.024-2.034-.328-2.852-1.029a3.665 3.665 0 01-1.262-2.255c-.21-1.32.152-2.489.947-3.529.853-1.122 1.881-1.706 3.272-1.95 1.192-.21 2.314-.095 3.33.595.923.63 1.496 1.484 1.648 2.605.198 1.578-.257 2.863-1.344 3.962-.771.783-1.718 1.273-2.805 1.495-.315.06-.63.07-.934.106zm2.78-4.72c-.011-.153-.011-.27-.034-.387-.21-1.157-1.274-1.81-2.384-1.554-1.087.245-1.788.935-2.045 2.033-.21.912.234 1.835 1.075 2.21.643.28 1.285.244 1.905-.07.923-.48 1.425-1.228 1.484-2.233z',\n },\n graphql: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M12.002 0a2.138 2.138 0 1 0 0 4.277 2.138 2.138 0 1 0 0-4.277zm8.54 4.931a2.138 2.138 0 1 0 0 4.277 2.138 2.138 0 1 0 0-4.277zm0 9.862a2.138 2.138 0 1 0 0 4.277 2.138 2.138 0 1 0 0-4.277zm-8.54 4.931a2.138 2.138 0 1 0 0 4.276 2.138 2.138 0 1 0 0-4.276zm-8.542-4.93a2.138 2.138 0 1 0 0 4.276 2.138 2.138 0 1 0 0-4.277zm0-9.863a2.138 2.138 0 1 0 0 4.277 2.138 2.138 0 1 0 0-4.277zm8.542-3.378L2.953 6.777v10.448l9.049 5.224 9.047-5.224V6.777zm0 1.601 7.66 13.27H4.34zm-1.387.371L3.97 15.037V7.363zm2.774 0 6.646 3.838v7.674zM5.355 17.44h13.293l-6.646 3.836z',\n },\n python: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M14.25.18l.9.2.73.26.59.3.45.32.34.34.25.34.16.33.1.3.04.26.02.2-.01.13V8.5l-.05.63-.13.55-.21.46-.26.38-.3.31-.33.25-.35.19-.35.14-.33.1-.3.07-.26.04-.21.02H8.77l-.69.05-.59.14-.5.22-.41.27-.33.32-.27.35-.2.36-.15.37-.1.35-.07.32-.04.27-.02.21v3.06H3.17l-.21-.03-.28-.07-.32-.12-.35-.18-.36-.26-.36-.36-.35-.46-.32-.59-.28-.73-.21-.88-.14-1.05-.05-1.23.06-1.22.16-1.04.24-.87.32-.71.36-.57.4-.44.42-.33.42-.24.4-.16.36-.1.32-.05.24-.01h.16l.06.01h8.16v-.83H6.18l-.01-2.75-.02-.37.05-.34.11-.31.17-.28.25-.26.31-.23.38-.2.44-.18.51-.15.58-.12.64-.1.71-.06.77-.04.84-.02 1.27.05zm-6.3 1.98l-.23.33-.08.41.08.41.23.34.33.22.41.09.41-.09.33-.22.23-.34.08-.41-.08-.41-.23-.33-.33-.22-.41-.09-.41.09zm13.09 3.95l.28.06.32.12.35.18.36.27.36.35.35.47.32.59.28.73.21.88.14 1.04.05 1.23-.06 1.23-.16 1.04-.24.86-.32.71-.36.57-.4.45-.42.33-.42.24-.4.16-.36.09-.32.05-.24.02-.16-.01h-8.22v.82h5.84l.01 2.76.02.36-.05.34-.11.31-.17.29-.25.25-.31.24-.38.2-.44.17-.51.15-.58.13-.64.09-.71.07-.77.04-.84.01-1.27-.04-1.07-.14-.9-.2-.73-.25-.59-.3-.45-.33-.34-.34-.25-.34-.16-.33-.1-.3-.04-.25-.02-.2.01-.13v-5.34l.05-.64.13-.54.21-.46.26-.38.3-.32.33-.24.35-.2.35-.14.33-.1.3-.06.26-.04.21-.02.13-.01h5.84l.69-.05.59-.14.5-.21.41-.28.33-.32.27-.35.2-.36.15-.36.1-.35.07-.32.04-.28.02-.21V6.07h2.09l.14.01zm-6.47 14.25l-.23.33-.08.41.08.41.23.33.33.23.41.08.41-.08.33-.23.23-.33.08-.41-.08-.41-.23-.33-.33-.23-.41-.08-.41.08z',\n },\n md: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M22.27 19.385H1.73A1.73 1.73 0 010 17.655V6.345a1.73 1.73 0 011.73-1.73h20.54A1.73 1.73 0 0124 6.345v11.308a1.73 1.73 0 01-1.73 1.731zM5.769 15.923v-4.5l2.308 2.885 2.307-2.885v4.5h2.308V8.078h-2.308l-2.307 2.885-2.308-2.885H3.46v7.847zM21.232 12h-2.309V8.077h-2.307V12h-2.308l3.461 4.039z',\n },\n kotlin: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M24 24H0V0h24L12 12Z',\n },\n rust: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M23.8346 11.7033l-1.0073-.6236a13.7268 13.7268 0 00-.0283-.2936l.8656-.8069a.3483.3483 0 00-.1154-.578l-1.1066-.414a8.4958 8.4958 0 00-.087-.2856l.6904-.9587a.3462.3462 0 00-.2257-.5446l-1.1663-.1894a9.3574 9.3574 0 00-.1407-.2622l.49-1.0761a.3437.3437 0 00-.0274-.3361.3486.3486 0 00-.3006-.154l-1.1845.0416a6.7444 6.7444 0 00-.1873-.2268l.2723-1.153a.3472.3472 0 00-.417-.4172l-1.1532.2724a14.0183 14.0183 0 00-.2278-.1873l.0415-1.1845a.3442.3442 0 00-.49-.328l-1.076.491c-.0872-.0476-.1742-.0952-.2623-.1407l-.1903-1.1673A.3483.3483 0 0016.256.955l-.9597.6905a8.4867 8.4867 0 00-.2855-.086l-.414-1.1066a.3483.3483 0 00-.5781-.1154l-.8069.8666a9.2936 9.2936 0 00-.2936-.0284L12.2946.1683a.3462.3462 0 00-.5892 0l-.6236 1.0073a13.7383 13.7383 0 00-.2936.0284L9.9803.3374a.3462.3462 0 00-.578.1154l-.4141 1.1065c-.0962.0274-.1903.0567-.2855.086L7.744.955a.3483.3483 0 00-.5447.2258L7.009 2.348a9.3574 9.3574 0 00-.2622.1407l-1.0762-.491a.3462.3462 0 00-.49.328l.0416 1.1845a7.9826 7.9826 0 00-.2278.1873L3.8413 3.425a.3472.3472 0 00-.4171.4171l.2713 1.1531c-.0628.075-.1255.1509-.1863.2268l-1.1845-.0415a.3462.3462 0 00-.328.49l.491 1.0761a9.167 9.167 0 00-.1407.2622l-1.1662.1894a.3483.3483 0 00-.2258.5446l.6904.9587a13.303 13.303 0 00-.087.2855l-1.1065.414a.3483.3483 0 00-.1155.5781l.8656.807a9.2936 9.2936 0 00-.0283.2935l-1.0073.6236a.3442.3442 0 000 .5892l1.0073.6236c.008.0982.0182.1964.0283.2936l-.8656.8079a.3462.3462 0 00.1155.578l1.1065.4141c.0273.0962.0567.1914.087.2855l-.6904.9587a.3452.3452 0 00.2268.5447l1.1662.1893c.0456.088.0922.1751.1408.2622l-.491 1.0762a.3462.3462 0 00.328.49l1.1834-.0415c.0618.0769.1235.1528.1873.2277l-.2713 1.1541a.3462.3462 0 00.4171.4161l1.153-.2713c.075.0638.151.1255.2279.1863l-.0415 1.1845a.3442.3442 0 00.49.327l1.0761-.49c.087.0486.1741.0951.2622.1407l.1903 1.1662a.3483.3483 0 00.5447.2268l.9587-.6904a9.299 9.299 0 00.2855.087l.414 1.1066a.3452.3452 0 00.5781.1154l.8079-.8656c.0972.0111.1954.0203.2936.0294l.6236 1.0073a.3472.3472 0 00.5892 0l.6236-1.0073c.0982-.0091.1964-.0183.2936-.0294l.8069.8656a.3483.3483 0 00.578-.1154l.4141-1.1066a8.4626 8.4626 0 00.2855-.087l.9587.6904a.3452.3452 0 00.5447-.2268l.1903-1.1662c.088-.0456.1751-.0931.2622-.1407l1.0762.49a.3472.3472 0 00.49-.327l-.0415-1.1845a6.7267 6.7267 0 00.2267-.1863l1.1531.2713a.3472.3472 0 00.4171-.416l-.2713-1.1542c.0628-.0749.1255-.1508.1863-.2278l1.1845.0415a.3442.3442 0 00.328-.49l-.49-1.076c.0475-.0872.0951-.1742.1407-.2623l1.1662-.1893a.3483.3483 0 00.2258-.5447l-.6904-.9587.087-.2855 1.1066-.414a.3462.3462 0 00.1154-.5781l-.8656-.8079c.0101-.0972.0202-.1954.0283-.2936l1.0073-.6236a.3442.3442 0 000-.5892zm-6.7413 8.3551a.7138.7138 0 01.2986-1.396.714.714 0 11-.2997 1.396zm-.3422-2.3142a.649.649 0 00-.7715.5l-.3573 1.6685c-1.1035.501-2.3285.7795-3.6193.7795a8.7368 8.7368 0 01-3.6951-.814l-.3574-1.6684a.648.648 0 00-.7714-.499l-1.473.3158a8.7216 8.7216 0 01-.7613-.898h7.1676c.081 0 .1356-.0141.1356-.088v-2.536c0-.074-.0536-.0881-.1356-.0881h-2.0966v-1.6077h2.2677c.2065 0 1.1065.0587 1.394 1.2088.0901.3533.2875 1.5044.4232 1.8729.1346.413.6833 1.2381 1.2685 1.2381h3.5716a.7492.7492 0 00.1296-.0131 8.7874 8.7874 0 01-.8119.9526zM6.8369 20.024a.714.714 0 11-.2997-1.396.714.714 0 01.2997 1.396zM4.1177 8.9972a.7137.7137 0 11-1.304.5791.7137.7137 0 011.304-.579zm-.8352 1.9813l1.5347-.6824a.65.65 0 00.33-.8585l-.3158-.7147h1.2432v5.6025H3.5669a8.7753 8.7753 0 01-.2834-3.348zm6.7343-.5437V8.7836h2.9601c.153 0 1.0792.1772 1.0792.8697 0 .575-.7107.7815-1.2948.7815zm10.7574 1.4862c0 .2187-.008.4363-.0243.651h-.9c-.09 0-.1265.0586-.1265.1477v.413c0 .973-.5487 1.1846-1.0296 1.2382-.4576.0517-.9648-.1913-1.0275-.4717-.2704-1.5186-.7198-1.8436-1.4305-2.4034.8817-.5599 1.799-1.386 1.799-2.4915 0-1.1936-.819-1.9458-1.3769-2.3153-.7825-.5163-1.6491-.6195-1.883-.6195H5.4682a8.7651 8.7651 0 014.907-2.7699l1.0974 1.151a.648.648 0 00.9182.0213l1.227-1.1743a8.7753 8.7753 0 016.0044 4.2762l-.8403 1.8982a.652.652 0 00.33.8585l1.6178.7188c.0283.2875.0425.577.0425.8717zm-9.3006-9.5993a.7128.7128 0 11.984 1.0316.7137.7137 0 01-.984-1.0316zm8.3389 6.71a.7107.7107 0 01.9395-.3625.7137.7137 0 11-.9405.3635z',\n },\n csharp: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M1.194 7.543v8.913c0 1.103.588 2.122 1.544 2.674l7.718 4.456a3.086 3.086 0 0 0 3.088 0l7.718-4.456a3.087 3.087 0 0 0 1.544-2.674V7.543a3.084 3.084 0 0 0-1.544-2.673L13.544.414a3.086 3.086 0 0 0-3.088 0L2.738 4.87a3.085 3.085 0 0 0-1.544 2.673Zm5.403 2.914v3.087a.77.77 0 0 0 .772.772.773.773 0 0 0 .772-.772.773.773 0 0 1 1.317-.546.775.775 0 0 1 .226.546 2.314 2.314 0 1 1-4.631 0v-3.087c0-.615.244-1.203.679-1.637a2.312 2.312 0 0 1 3.274 0c.434.434.678 1.023.678 1.637a.769.769 0 0 1-.226.545.767.767 0 0 1-1.091 0 .77.77 0 0 1-.226-.545.77.77 0 0 0-.772-.772.771.771 0 0 0-.772.772Zm12.35 3.087a.77.77 0 0 1-.772.772h-.772v.772a.773.773 0 0 1-1.544 0v-.772h-1.544v.772a.773.773 0 0 1-1.317.546.775.775 0 0 1-.226-.546v-.772H12a.771.771 0 1 1 0-1.544h.772v-1.543H12a.77.77 0 1 1 0-1.544h.772v-.772a.773.773 0 0 1 1.317-.546.775.775 0 0 1 .226.546v.772h1.544v-.772a.773.773 0 0 1 1.544 0v.772h.772a.772.772 0 0 1 0 1.544h-.772v1.543h.772a.776.776 0 0 1 .772.772Zm-3.088-2.315h-1.544v1.543h1.544v-1.543Z',\n },\n default: {\n viewBox: '0 0 24 24',\n fill: 'currentColor',\n d: 'M 6,1 C 4.354992,1 3,2.354992 3,4 v 16 c 0,1.645008 1.354992,3 3,3 h 12 c 1.645008,0 3,-1.354992 3,-3 V 8 7 A 1.0001,1.0001 0 0 0 20.707031,6.2929687 l -5,-5 A 1.0001,1.0001 0 0 0 15,1 h -1 z m 0,2 h 7 v 3 c 0,1.645008 1.354992,3 3,3 h 3 v 11 c 0,0.564129 -0.435871,1 -1,1 H 6 C 5.4358712,21 5,20.564129 5,20 V 4 C 5,3.4358712 5.4358712,3 6,3 Z M 15,3.4140625 18.585937,7 H 16 C 15.435871,7 15,6.5641288 15,6 Z',\n },\n};\n\nexport interface IconOptions {\n shortcuts?: Record<string, string>;\n extend?: Record<string, CodeBlockIcon>;\n}\n\n/**\n * Inject icons to `icon` property (as HTML)\n */\nexport function transformerIcon(options: IconOptions = {}): ShikiTransformer {\n const shortcuts = {\n ...defaultShortcuts,\n ...options.shortcuts,\n };\n const icons = {\n ...defaultIcons,\n ...options.extend,\n };\n\n const defaultIcon = 'default' in icons ? icons.default : undefined;\n return {\n name: 'rehype-code:icon',\n pre(pre) {\n const lang = this.options.lang;\n if (!lang) return;\n\n const iconName = lang in shortcuts ? shortcuts[lang] : lang;\n const icon = iconName in icons ? icons[iconName] : defaultIcon;\n\n if (icon) {\n pre.properties.icon =\n typeof icon === 'string'\n ? icon\n : `<svg viewBox=\"${icon.viewBox}\"><path d=\"${icon.d}\" fill=\"${icon.fill}\" /></svg>`;\n }\n\n return pre;\n },\n };\n}\n","import type { Root } from 'hast';\nimport type { RehypeShikiOptions } from '@shikijs/rehype';\nimport rehypeShikiFromHighlighter from '@shikijs/rehype/core';\nimport {\n transformerNotationDiff,\n transformerNotationFocus,\n transformerNotationHighlight,\n transformerNotationWordHighlight,\n} from '@shikijs/transformers';\nimport type { Processor, Transformer } from 'unified';\nimport { type BuiltinTheme, bundledLanguages, type ShikiTransformer } from 'shiki';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport type { CodeBlockIcon, IconOptions } from './transformer-icon';\nimport { transformerIcon } from './transformer-icon';\nimport { defaultThemes, getHighlighter } from '@/highlight/shiki';\nimport { parseCodeBlockAttributes } from '@/mdx-plugins/codeblock-utils';\n\nexport const rehypeCodeDefaultOptions: RehypeCodeOptions = {\n lazy: true,\n themes: defaultThemes,\n defaultColor: false,\n defaultLanguage: 'plaintext',\n engine: 'js',\n transformers: [\n transformerNotationHighlight({\n matchAlgorithm: 'v3',\n }),\n transformerNotationWordHighlight({\n matchAlgorithm: 'v3',\n }),\n transformerNotationDiff({\n matchAlgorithm: 'v3',\n }),\n transformerNotationFocus({\n matchAlgorithm: 'v3',\n }),\n ],\n parseMetaString(meta) {\n const parsed = parseCodeBlockAttributes(meta, ['title', 'tab']);\n const data: Record<string, unknown> = parsed.attributes;\n parsed.rest = parseLineNumber(parsed.rest, data);\n\n data.__parsed_raw = parsed.rest;\n return data;\n },\n};\n\nfunction parseLineNumber(str: string, data: Record<string, unknown>) {\n return str.replace(/lineNumbers=(\\d+)|lineNumbers/, (_, ...args) => {\n data['data-line-numbers'] = true;\n\n if (args[0] !== undefined) data['data-line-numbers-start'] = Number(args[0]);\n\n return '';\n });\n}\n\ntype DistributiveOmit<T, K extends keyof T> = T extends unknown ? Omit<T, K> : never;\n\nexport type RehypeCodeOptions = DistributiveOmit<RehypeShikiOptions, 'lazy'> & {\n /**\n * Load languages and themes on-demand.\n * @defaultValue true\n */\n lazy?: boolean;\n\n /**\n * The regex engine to use.\n *\n * @defaultValue 'js'\n */\n engine?: 'js' | 'oniguruma';\n\n /**\n * Filter meta string before processing\n */\n filterMetaString?: (metaString: string) => string;\n\n /**\n * Add icon to code blocks\n */\n icon?: IconOptions | false;\n\n /**\n * Wrap code blocks in `<Tab>` component when \"tab\" meta string presents\n *\n * @defaultValue true\n */\n tab?: boolean;\n};\n\n/**\n * Handle codeblocks\n */\nexport function rehypeCode(\n this: Processor,\n _options: Partial<RehypeCodeOptions> = {},\n): Transformer<Root, Root> {\n const options: RehypeCodeOptions = {\n ...rehypeCodeDefaultOptions,\n ..._options,\n };\n\n const transformers = [...(options.transformers ?? [])];\n transformers.unshift({\n name: 'rehype-code:pre-process',\n preprocess(code, { meta }) {\n if (meta && '__parsed_raw' in meta) {\n meta.__raw = meta.__parsed_raw;\n delete meta.__parsed_raw;\n }\n\n if (meta && options.filterMetaString) {\n meta.__raw = options.filterMetaString(meta.__raw ?? '');\n }\n\n // Remove empty line at end\n return code.replace(/\\n$/, '');\n },\n });\n\n if (options.icon !== false) {\n transformers.push(transformerIcon(options.icon));\n }\n\n if (options.tab !== false) {\n transformers.push(transformerTab());\n }\n\n const highlighter = getHighlighter(options.engine ?? 'js', {\n themes:\n 'themes' in options\n ? (Object.values(options.themes).filter(Boolean) as BuiltinTheme[])\n : [options.theme],\n langs:\n options.langs ?? (options.lazy ? ['js', 'jsx', 'ts', 'tsx'] : Object.keys(bundledLanguages)),\n langAlias: options.langAlias,\n });\n\n const transformer = highlighter.then((loaded) =>\n rehypeShikiFromHighlighter(loaded, {\n ...options,\n transformers,\n }),\n );\n\n return async (tree, file) => {\n await (\n await transformer\n )(tree, file, () => {\n // nothing\n });\n };\n}\n\nfunction transformerTab(): ShikiTransformer {\n return {\n name: 'rehype-code:tab',\n // @ts-expect-error -- types not compatible with MDX\n root(root) {\n const value = this.options.meta?.tab;\n if (typeof value !== 'string') return root;\n console.warn(\n '[Fumadocs] For `tab=\"value\" in codeblocks, please use `remarkCodeTab` plugin instead.',\n );\n\n return {\n type: 'root',\n children: [\n {\n type: 'mdxJsxFlowElement',\n name: 'Tab',\n data: {\n _codeblock: true,\n },\n attributes: [{ type: 'mdxJsxAttribute', name: 'value', value }],\n children: root.children,\n } as MdxJsxFlowElement,\n ],\n };\n },\n };\n}\n\nexport { type CodeBlockIcon, transformerIcon, transformerTab };\n"],"mappings":";;;;;;;AAUA,MAAM,mBAA2C;CAC/C,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,KAAK;CACL,MAAM;CACN,IAAI;CACJ,KAAK;CACL,IAAI;CACJ,MAAM;CACN,IAAI;CACJ,OAAO;CACP,KAAK;CACL,OAAO;CACR;AAID,MAAM,eAA8C;CAClD,OAAO;EACL,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,KAAK;EACH,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,MAAM;EACJ,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,KAAK;EACH,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,OAAO;EACL,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,QAAQ;EACN,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,YAAY;EACV,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,YAAY;EACV,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,KAAK;EACH,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,aAAa;EACX,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,GAAG;EACD,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,KAAK;EACH,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,IAAI;EACF,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,SAAS;EACP,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,QAAQ;EACN,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,IAAI;EACF,SAAS;EACT,MAAM;EACN,GAAG;EACJ;CACD,QAAQ;EACN,SAAS;EACT,MAAM;EACN,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AM;IACN,UAAU,CACR;KACE,MAAM;KACN,MAAM;KACN,MAAM,EACJ,YAAY,MACb;KACD,YAAY,CAAC;MAAE,MAAM;MAAmB,MAAM;MAAS;MAAO,CAAC;KAC/D,UAAU,KAAK;KAChB,CACF;IACF;;EAEJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rehype-toc-CTG0x7La.js","names":[
|
|
1
|
+
{"version":3,"file":"rehype-toc-CTG0x7La.js","names":[],"sources":["../src/mdx-plugins/hast-utils.ts","../src/mdx-plugins/rehype-toc.ts"],"sourcesContent":["import type { Element, Root, RootContent } from 'hast';\n\n/**\n * Visit a node with filtered tag names\n */\nexport function visit(\n node: RootContent | Root,\n tagNames: string[],\n handler: (node: Element) => 'skip' | undefined,\n): void {\n if (node.type === 'element' && tagNames.includes(node.tagName)) {\n const result = handler(node);\n if (result === 'skip') return;\n }\n\n if ('children' in node)\n node.children.forEach((n) => {\n visit(n, tagNames, handler);\n });\n}\n","import type { Processor, Transformer } from 'unified';\nimport type { Root, RootContent } from 'hast';\nimport { toEstree } from 'hast-util-to-estree';\nimport type { Declaration, JSXElement } from 'estree-jsx';\nimport { visit } from '@/mdx-plugins/hast-utils';\n\nexport interface RehypeTocOptions {\n /**\n * Export generated toc as a variable\n *\n * @defaultValue true\n */\n exportToc?: boolean;\n}\n\nconst TocOnlyTag = '[toc]';\nconst NoTocTag = '[!toc]';\n\nexport function rehypeToc(\n this: Processor,\n { exportToc = true }: RehypeTocOptions = {},\n): Transformer<Root, Root> {\n return (tree) => {\n const output: {\n title: JSXElement;\n url: string;\n depth: number;\n }[] = [];\n\n visit(tree, ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'], (element) => {\n const id = element.properties.id;\n if (typeof id !== 'string') return 'skip';\n let isTocOnly = false;\n\n const last = element.children.at(-1);\n if (last?.type === 'text' && last.value.endsWith(TocOnlyTag)) {\n isTocOnly = true;\n last.value = last.value.substring(0, last.value.length - TocOnlyTag.length).trimEnd();\n } else if (last?.type === 'text' && last.value.endsWith(NoTocTag)) {\n last.value = last.value.substring(0, last.value.length - NoTocTag.length).trimEnd();\n return 'skip';\n }\n\n const estree = toEstree(element, {\n elementAttributeNameCase: 'react',\n stylePropertyNameCase: 'dom',\n });\n\n if (estree.body[0].type === 'ExpressionStatement')\n output.push({\n title: estree.body[0].expression as unknown as JSXElement,\n depth: Number(element.tagName.slice(1)),\n url: `#${id}`,\n });\n\n if (isTocOnly) {\n Object.assign(element, {\n type: 'comment',\n value: '',\n } satisfies RootContent);\n }\n\n return 'skip';\n });\n\n const declaration: Declaration = {\n type: 'VariableDeclaration',\n kind: 'const',\n declarations: [\n {\n type: 'VariableDeclarator',\n id: {\n type: 'Identifier',\n name: 'toc',\n },\n init: {\n type: 'ArrayExpression',\n elements: output.map((item) => ({\n type: 'ObjectExpression',\n properties: [\n {\n type: 'Property',\n method: false,\n shorthand: false,\n computed: false,\n key: {\n type: 'Identifier',\n name: 'depth',\n },\n value: {\n type: 'Literal',\n value: item.depth,\n },\n kind: 'init',\n },\n {\n type: 'Property',\n method: false,\n shorthand: false,\n computed: false,\n key: {\n type: 'Identifier',\n name: 'url',\n },\n value: {\n type: 'Literal',\n value: item.url,\n },\n kind: 'init',\n },\n {\n type: 'Property',\n method: false,\n shorthand: false,\n computed: false,\n key: {\n type: 'Identifier',\n name: 'title',\n },\n value: {\n type: 'JSXFragment',\n openingFragment: { type: 'JSXOpeningFragment' },\n closingFragment: { type: 'JSXClosingFragment' },\n children: item.title.children,\n },\n kind: 'init',\n },\n ],\n })),\n },\n },\n ],\n };\n\n tree.children.push({\n type: 'mdxjsEsm',\n value: '',\n data: {\n estree: {\n type: 'Program',\n body: [\n exportToc\n ? {\n type: 'ExportNamedDeclaration',\n declaration,\n attributes: [],\n specifiers: [],\n }\n : declaration,\n ],\n sourceType: 'module',\n comments: [],\n },\n },\n } satisfies RootContent);\n };\n}\n"],"mappings":";;;;;;AAKA,SAAgB,MACd,MACA,UACA,SACM;AACN,KAAI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M;KACN,MAAM;KACP;IACD,MAAM;KACJ,MAAM;KACN,UAAU,OAAO,KAAK,UAAU;MAC9B,MAAM;MACN,YAAY;OACV;QACE,MAAM;QACN,QAAQ;QACR,WAAW;QACX,UAAU;QACV,KAAK;SACH,MAAM;SACN,MAAM;SACP;QACD,OAAO;SACL,MAAM;SACN,OAAO,KAAK;SACb;QACD,MAAM;QACP;OACD;QACE,MAAM;QACN,QAAQ;QACR,WAAW;QACX,UAAU;QACV,KAAK;SACH,MAAM;SACN,MAAM;SACP;QACD,OAAO;SACL,MAAM;SACN,OAAO,KAAK;SACb;QACD,MAAM;QACP;OACD;QACE,MAAM;QACN,QAAQ;QACR,WAAW;QACX,UAAU;QACV,KAAK;SACH,MAAM;SACN,MAAM;SACP;QACD,OAAO;SACL,MAAM;SACN,iBAAiB,EAAE,MAAM,sBAAsB;SAC/C,iBAAiB,EAAE,MAAM,sBAAsB;SAC/C,UAAU,KAAK,MAAM;SACtB;QACD,MAAM;QACP;OACF;MACF,EAAE;KACJ;IACF,CACF;GACF;AAED,OAAK,SAAS,KAAK;GACjB,MAAM;GACN,OAAO;GACP,MAAM,EACJ,QAAQ;IACN,MAAM;IACN,MAAM,CACJ,YACI;KACE,MAAM;KACN;KACA,YAAY,EAAE;KACd,YAAY,EAAE;KACf,GACD,YACL;IACD,YAAY;IACZ,UAAU,EAAE;IACb,EACF;GACF,CAAuB"}
|
package/dist/search/algolia.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "../remark-structure-ChKxMXnK.js";
|
|
2
|
-
import { a as sync, i as setIndexSettings, n as DocumentRecord, o as updateDocuments, r as SyncOptions, t as BaseIndex } from "../algolia-
|
|
2
|
+
import { a as sync, i as setIndexSettings, n as DocumentRecord, o as updateDocuments, r as SyncOptions, t as BaseIndex } from "../algolia-BFVpYDZ_.js";
|
|
3
3
|
export { BaseIndex, DocumentRecord, SyncOptions, setIndexSettings, sync, updateDocuments };
|