unplugin-docubook 1.0.1 → 1.0.2
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/astro.cjs +20 -20
- package/dist/astro.cjs.map +1 -1
- package/dist/astro.js +20 -20
- package/dist/astro.js.map +1 -1
- package/dist/bun.cjs +20 -20
- package/dist/bun.cjs.map +1 -1
- package/dist/bun.js +20 -20
- package/dist/bun.js.map +1 -1
- package/dist/esbuild.cjs +20 -20
- package/dist/esbuild.cjs.map +1 -1
- package/dist/esbuild.js +20 -20
- package/dist/esbuild.js.map +1 -1
- package/dist/farm.cjs +20 -20
- package/dist/farm.cjs.map +1 -1
- package/dist/farm.js +20 -20
- package/dist/farm.js.map +1 -1
- package/dist/index.cjs +20 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -20
- package/dist/index.js.map +1 -1
- package/dist/next.cjs +20 -20
- package/dist/next.cjs.map +1 -1
- package/dist/next.js +20 -20
- package/dist/next.js.map +1 -1
- package/dist/nuxt.cjs +20 -20
- package/dist/nuxt.cjs.map +1 -1
- package/dist/nuxt.js +20 -20
- package/dist/nuxt.js.map +1 -1
- package/dist/rolldown.cjs +20 -20
- package/dist/rolldown.cjs.map +1 -1
- package/dist/rolldown.js +20 -20
- package/dist/rolldown.js.map +1 -1
- package/dist/rollup.cjs +20 -20
- package/dist/rollup.cjs.map +1 -1
- package/dist/rollup.js +20 -20
- package/dist/rollup.js.map +1 -1
- package/dist/rspack.cjs +20 -20
- package/dist/rspack.cjs.map +1 -1
- package/dist/rspack.js +20 -20
- package/dist/rspack.js.map +1 -1
- package/dist/vite.cjs +20 -20
- package/dist/vite.cjs.map +1 -1
- package/dist/vite.js +20 -20
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +20 -20
- package/dist/webpack.cjs.map +1 -1
- package/dist/webpack.js +20 -20
- package/dist/webpack.js.map +1 -1
- package/package.json +1 -1
package/dist/astro.cjs
CHANGED
|
@@ -36,26 +36,26 @@ var FRAMEWORK_PATHS = {
|
|
|
36
36
|
function createRegistry(framework) {
|
|
37
37
|
const basePath = FRAMEWORK_PATHS[framework];
|
|
38
38
|
return {
|
|
39
|
-
Note: { exports: ["Note"], path:
|
|
40
|
-
Card: { exports: ["Card"], path:
|
|
41
|
-
CardGroup: { exports: ["CardGroup"], path:
|
|
42
|
-
Accordion: { exports: ["Accordion"], path:
|
|
43
|
-
AccordionGroup: { exports: ["AccordionGroup"], path:
|
|
44
|
-
Stepper: { exports: ["Stepper", "StepperItem"], path:
|
|
45
|
-
Kbd: { exports: ["Kbd"], path:
|
|
46
|
-
Tooltip: { exports: ["Tooltip"], path:
|
|
47
|
-
Youtube: { exports: ["Youtube"], path:
|
|
48
|
-
Button: { exports: ["Button"], path:
|
|
49
|
-
DocuLink: { exports: ["DocuLink"], path:
|
|
50
|
-
DocuImage: { exports: ["DocuImage"], path:
|
|
51
|
-
Files: { exports: ["Files"], path:
|
|
52
|
-
Folder: { exports: ["Folder"], path:
|
|
53
|
-
File: { exports: ["File"], path:
|
|
54
|
-
Release: { exports: ["Release"], path:
|
|
55
|
-
Changes: { exports: ["Changes"], path:
|
|
56
|
-
Pre: { exports: ["Pre"], path:
|
|
57
|
-
Copy: { exports: ["Copy"], path:
|
|
58
|
-
DocuBookProvider: { exports: ["DocuBookProvider"], path:
|
|
39
|
+
Note: { exports: ["Note"], path: basePath },
|
|
40
|
+
Card: { exports: ["Card"], path: basePath },
|
|
41
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
42
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
43
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
44
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
45
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
46
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
47
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
48
|
+
Button: { exports: ["Button"], path: basePath },
|
|
49
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
50
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
51
|
+
Files: { exports: ["Files"], path: basePath },
|
|
52
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
53
|
+
File: { exports: ["File"], path: basePath },
|
|
54
|
+
Release: { exports: ["Release"], path: basePath },
|
|
55
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
56
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
57
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
58
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function getComponentRegistry(framework = "react") {
|
package/dist/astro.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/astro.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import type { Options } from './types'\nimport unplugin from '.'\n\ninterface AstroConfig {\n config: {\n vite: {\n plugins: unknown[]\n }\n }\n}\n\nexport default function (options: Options) {\n return {\n name: 'unplugin-docubook',\n hooks: {\n 'astro:config:setup': async (astro: AstroConfig) => {\n astro.config.vite.plugins ||= []\n astro.config.vite.plugins.push(unplugin.vite(options))\n },\n },\n }\n}\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path:
|
|
1
|
+
{"version":3,"sources":["../src/astro.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import type { Options } from './types'\nimport unplugin from '.'\n\ninterface AstroConfig {\n config: {\n vite: {\n plugins: unknown[]\n }\n }\n}\n\nexport default function (options: Options) {\n return {\n name: 'unplugin-docubook',\n hooks: {\n 'astro:config:setup': async (astro: AstroConfig) => {\n astro.config.vite.plugins ||= []\n astro.config.vite.plugins.push(unplugin.vite(options))\n },\n },\n }\n}\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACEA,sBAA+B;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,GAAG,MAAM,SAAS;AAAA,IAC9D,SAAS,EAAE,SAAS,CAAC,WAAW,aAAa,GAAG,MAAM,SAAS;AAAA,IAC/D,KAAK,EAAE,SAAS,CAAC,KAAK,GAAG,MAAM,SAAS;AAAA,IACxC,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA,IAChD,SAAS,EAAE,SAAS,CAAC,SAAS,GAAG,MAAM,SAAS;AAAA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CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;AAEO,IAAM,WAA2B,oDAAe,eAAe;AAEtE,IAAO,gBAAQ;;;ADbA,SAAR,cAAkB,SAAkB;AACvC,SAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,MACH,sBAAsB,OAAO,UAAuB;AAfhE;AAgBgB,oBAAM,OAAO,MAAK,YAAlB,GAAkB,UAAY,CAAC;AAC/B,cAAM,OAAO,KAAK,QAAQ,KAAK,cAAS,KAAK,OAAO,CAAC;AAAA,MACzD;AAAA,IACJ;AAAA,EACJ;AACJ;","names":["exports"]}
|
package/dist/astro.js
CHANGED
|
@@ -10,26 +10,26 @@ var FRAMEWORK_PATHS = {
|
|
|
10
10
|
function createRegistry(framework) {
|
|
11
11
|
const basePath = FRAMEWORK_PATHS[framework];
|
|
12
12
|
return {
|
|
13
|
-
Note: { exports: ["Note"], path:
|
|
14
|
-
Card: { exports: ["Card"], path:
|
|
15
|
-
CardGroup: { exports: ["CardGroup"], path:
|
|
16
|
-
Accordion: { exports: ["Accordion"], path:
|
|
17
|
-
AccordionGroup: { exports: ["AccordionGroup"], path:
|
|
18
|
-
Stepper: { exports: ["Stepper", "StepperItem"], path:
|
|
19
|
-
Kbd: { exports: ["Kbd"], path:
|
|
20
|
-
Tooltip: { exports: ["Tooltip"], path:
|
|
21
|
-
Youtube: { exports: ["Youtube"], path:
|
|
22
|
-
Button: { exports: ["Button"], path:
|
|
23
|
-
DocuLink: { exports: ["DocuLink"], path:
|
|
24
|
-
DocuImage: { exports: ["DocuImage"], path:
|
|
25
|
-
Files: { exports: ["Files"], path:
|
|
26
|
-
Folder: { exports: ["Folder"], path:
|
|
27
|
-
File: { exports: ["File"], path:
|
|
28
|
-
Release: { exports: ["Release"], path:
|
|
29
|
-
Changes: { exports: ["Changes"], path:
|
|
30
|
-
Pre: { exports: ["Pre"], path:
|
|
31
|
-
Copy: { exports: ["Copy"], path:
|
|
32
|
-
DocuBookProvider: { exports: ["DocuBookProvider"], path:
|
|
13
|
+
Note: { exports: ["Note"], path: basePath },
|
|
14
|
+
Card: { exports: ["Card"], path: basePath },
|
|
15
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
16
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
17
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
18
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
19
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
20
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
21
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
22
|
+
Button: { exports: ["Button"], path: basePath },
|
|
23
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
24
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
25
|
+
Files: { exports: ["Files"], path: basePath },
|
|
26
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
27
|
+
File: { exports: ["File"], path: basePath },
|
|
28
|
+
Release: { exports: ["Release"], path: basePath },
|
|
29
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
30
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
31
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
32
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
function getComponentRegistry(framework = "react") {
|
package/dist/astro.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/core/registry.ts","../src/core/transform.ts","../src/astro.ts"],"sourcesContent":["import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path:
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/core/registry.ts","../src/core/transform.ts","../src/astro.ts"],"sourcesContent":["import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n","import type { Options } from './types'\nimport unplugin from '.'\n\ninterface AstroConfig {\n config: {\n vite: {\n plugins: unknown[]\n }\n }\n}\n\nexport default function (options: Options) {\n return {\n name: 'unplugin-docubook',\n hooks: {\n 'astro:config:setup': async (astro: AstroConfig) => {\n astro.config.vite.plugins ||= []\n astro.config.vite.plugins.push(unplugin.vite(options))\n },\n },\n }\n}\n"],"mappings":";AAEA,SAAS,sBAAsB;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eAAe,WAAqD;AACzE,QAAM,WAAW,gBAAgB,SAAS;AAE1C,SAAO;AAAA,IACH,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,SAAS;AAAA,IAC1C,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,SAAS;AAAA,IACpD,WAAW,EAAE,SAAS,CAAC,WAAW,GAAG,MAAM,S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iB,MAAM,SAAS;AAEvD,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,SAAS;AAEhF,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AFjEO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;AAEO,IAAM,WAA2B,+BAAe,eAAe;AAEtE,IAAO,gBAAQ;;;AGbA,SAAR,cAAkB,SAAkB;AACvC,SAAO;AAAA,IACH,MAAM;AAAA,IACN,OAAO;AAAA,MACH,sBAAsB,OAAO,UAAuB;AAfhE;AAgBgB,oBAAM,OAAO,MAAK,YAAlB,GAAkB,UAAY,CAAC;AAC/B,cAAM,OAAO,KAAK,QAAQ,KAAK,cAAS,KAAK,OAAO,CAAC;AAAA,MACzD;AAAA,IACJ;AAAA,EACJ;AACJ;","names":[]}
|
package/dist/bun.cjs
CHANGED
|
@@ -37,26 +37,26 @@ var FRAMEWORK_PATHS = {
|
|
|
37
37
|
function createRegistry(framework) {
|
|
38
38
|
const basePath = FRAMEWORK_PATHS[framework];
|
|
39
39
|
return {
|
|
40
|
-
Note: { exports: ["Note"], path:
|
|
41
|
-
Card: { exports: ["Card"], path:
|
|
42
|
-
CardGroup: { exports: ["CardGroup"], path:
|
|
43
|
-
Accordion: { exports: ["Accordion"], path:
|
|
44
|
-
AccordionGroup: { exports: ["AccordionGroup"], path:
|
|
45
|
-
Stepper: { exports: ["Stepper", "StepperItem"], path:
|
|
46
|
-
Kbd: { exports: ["Kbd"], path:
|
|
47
|
-
Tooltip: { exports: ["Tooltip"], path:
|
|
48
|
-
Youtube: { exports: ["Youtube"], path:
|
|
49
|
-
Button: { exports: ["Button"], path:
|
|
50
|
-
DocuLink: { exports: ["DocuLink"], path:
|
|
51
|
-
DocuImage: { exports: ["DocuImage"], path:
|
|
52
|
-
Files: { exports: ["Files"], path:
|
|
53
|
-
Folder: { exports: ["Folder"], path:
|
|
54
|
-
File: { exports: ["File"], path:
|
|
55
|
-
Release: { exports: ["Release"], path:
|
|
56
|
-
Changes: { exports: ["Changes"], path:
|
|
57
|
-
Pre: { exports: ["Pre"], path:
|
|
58
|
-
Copy: { exports: ["Copy"], path:
|
|
59
|
-
DocuBookProvider: { exports: ["DocuBookProvider"], path:
|
|
40
|
+
Note: { exports: ["Note"], path: basePath },
|
|
41
|
+
Card: { exports: ["Card"], path: basePath },
|
|
42
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
43
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
44
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
45
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
46
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
47
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
48
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
49
|
+
Button: { exports: ["Button"], path: basePath },
|
|
50
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
51
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
52
|
+
Files: { exports: ["Files"], path: basePath },
|
|
53
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
54
|
+
File: { exports: ["File"], path: basePath },
|
|
55
|
+
Release: { exports: ["Release"], path: basePath },
|
|
56
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
57
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
58
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
59
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
function getComponentRegistry(framework = "react") {
|
package/dist/bun.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bun.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createBunPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createBunPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path:
|
|
1
|
+
{"version":3,"sources":["../src/bun.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createBunPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createBunPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,mBAAgC;;;ACEhC,sBAA+B;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ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CAAC,MAAMC,QAAO,KAAK,eAAe;AACzC,UAAM,QAAQ,MAAM,KAAKA,QAAO,EAAE,KAAK,EAAE,KAAK,IAAI;AAClD,UAAM,KAAK,YAAY,KAAK,YAAY,IAAI,GAAG;AAAA,EACnD;AAEA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AAvD7C;AAwDI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,SAAS;AAEvD,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,SAAS;AAEhF,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AFjEO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,kBAAQ,kCAAgB,eAAe;","names":["import_unplugin","exports"]}
|
package/dist/bun.js
CHANGED
|
@@ -13,26 +13,26 @@ var FRAMEWORK_PATHS = {
|
|
|
13
13
|
function createRegistry(framework) {
|
|
14
14
|
const basePath = FRAMEWORK_PATHS[framework];
|
|
15
15
|
return {
|
|
16
|
-
Note: { exports: ["Note"], path:
|
|
17
|
-
Card: { exports: ["Card"], path:
|
|
18
|
-
CardGroup: { exports: ["CardGroup"], path:
|
|
19
|
-
Accordion: { exports: ["Accordion"], path:
|
|
20
|
-
AccordionGroup: { exports: ["AccordionGroup"], path:
|
|
21
|
-
Stepper: { exports: ["Stepper", "StepperItem"], path:
|
|
22
|
-
Kbd: { exports: ["Kbd"], path:
|
|
23
|
-
Tooltip: { exports: ["Tooltip"], path:
|
|
24
|
-
Youtube: { exports: ["Youtube"], path:
|
|
25
|
-
Button: { exports: ["Button"], path:
|
|
26
|
-
DocuLink: { exports: ["DocuLink"], path:
|
|
27
|
-
DocuImage: { exports: ["DocuImage"], path:
|
|
28
|
-
Files: { exports: ["Files"], path:
|
|
29
|
-
Folder: { exports: ["Folder"], path:
|
|
30
|
-
File: { exports: ["File"], path:
|
|
31
|
-
Release: { exports: ["Release"], path:
|
|
32
|
-
Changes: { exports: ["Changes"], path:
|
|
33
|
-
Pre: { exports: ["Pre"], path:
|
|
34
|
-
Copy: { exports: ["Copy"], path:
|
|
35
|
-
DocuBookProvider: { exports: ["DocuBookProvider"], path:
|
|
16
|
+
Note: { exports: ["Note"], path: basePath },
|
|
17
|
+
Card: { exports: ["Card"], path: basePath },
|
|
18
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
19
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
20
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
21
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
22
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
23
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
24
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
25
|
+
Button: { exports: ["Button"], path: basePath },
|
|
26
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
27
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
28
|
+
Files: { exports: ["Files"], path: basePath },
|
|
29
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
30
|
+
File: { exports: ["File"], path: basePath },
|
|
31
|
+
Release: { exports: ["Release"], path: basePath },
|
|
32
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
33
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
34
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
35
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
function getComponentRegistry(framework = "react") {
|
package/dist/bun.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/bun.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createBunPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createBunPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path:
|
|
1
|
+
{"version":3,"sources":["../src/bun.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createBunPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createBunPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n"],"mappings":";AAAA,SAAS,uBAAuB;;;ACEhC,SAAS,sBAAsB;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,KAAK;AAAA,EACL,QAAQ;AACZ;AAEA,SAAS,eA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,KAAK,eAAe;AACzC,UAAM,QAAQ,MAAM,KAAK,OAAO,EAAE,KAAK,EAAE,KAAK,IAAI;AAClD,UAAM,KAAK,YAAY,KAAK,YAAY,IAAI,GAAG;AAAA,EACnD;AAEA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AAvD7C;AAwDI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,SAAS;AAEvD,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,SAAS;AAEhF,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AFjEO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,cAAQ,gBAAgB,eAAe;","names":[]}
|
package/dist/esbuild.cjs
CHANGED
|
@@ -37,26 +37,26 @@ var FRAMEWORK_PATHS = {
|
|
|
37
37
|
function createRegistry(framework) {
|
|
38
38
|
const basePath = FRAMEWORK_PATHS[framework];
|
|
39
39
|
return {
|
|
40
|
-
Note: { exports: ["Note"], path:
|
|
41
|
-
Card: { exports: ["Card"], path:
|
|
42
|
-
CardGroup: { exports: ["CardGroup"], path:
|
|
43
|
-
Accordion: { exports: ["Accordion"], path:
|
|
44
|
-
AccordionGroup: { exports: ["AccordionGroup"], path:
|
|
45
|
-
Stepper: { exports: ["Stepper", "StepperItem"], path:
|
|
46
|
-
Kbd: { exports: ["Kbd"], path:
|
|
47
|
-
Tooltip: { exports: ["Tooltip"], path:
|
|
48
|
-
Youtube: { exports: ["Youtube"], path:
|
|
49
|
-
Button: { exports: ["Button"], path:
|
|
50
|
-
DocuLink: { exports: ["DocuLink"], path:
|
|
51
|
-
DocuImage: { exports: ["DocuImage"], path:
|
|
52
|
-
Files: { exports: ["Files"], path:
|
|
53
|
-
Folder: { exports: ["Folder"], path:
|
|
54
|
-
File: { exports: ["File"], path:
|
|
55
|
-
Release: { exports: ["Release"], path:
|
|
56
|
-
Changes: { exports: ["Changes"], path:
|
|
57
|
-
Pre: { exports: ["Pre"], path:
|
|
58
|
-
Copy: { exports: ["Copy"], path:
|
|
59
|
-
DocuBookProvider: { exports: ["DocuBookProvider"], path:
|
|
40
|
+
Note: { exports: ["Note"], path: basePath },
|
|
41
|
+
Card: { exports: ["Card"], path: basePath },
|
|
42
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
43
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
44
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
45
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
46
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
47
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
48
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
49
|
+
Button: { exports: ["Button"], path: basePath },
|
|
50
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
51
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
52
|
+
Files: { exports: ["Files"], path: basePath },
|
|
53
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
54
|
+
File: { exports: ["File"], path: basePath },
|
|
55
|
+
Release: { exports: ["Release"], path: basePath },
|
|
56
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
57
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
58
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
59
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
62
|
function getComponentRegistry(framework = "react") {
|
package/dist/esbuild.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/esbuild.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createEsbuildPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path:
|
|
1
|
+
{"version":3,"sources":["../src/esbuild.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createEsbuildPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,mBAAoC;;;ACEpC,sBAA+B;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAAA,EACP,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M,QAAkB,CAAC;AACzB,aAAW,CAAC,MAAMC,QAAO,KAAK,eAAe;AACzC,UAAM,QAAQ,MAAM,KAAKA,QAAO,EAAE,KAAK,EAAE,KAAK,IAAI;AAClD,UAAM,KAAK,YAAY,KAAK,YAAY,IAAI,GAAG;AAAA,EACnD;AAEA,SAAO,MAAM,KAAK,IAAI;AAC1B;AAEO,SAAS,aACZ,MACA,UAAmB,CAAC,GACqB;AAvD7C;AAwDI,QAAM,aAAY,aAAQ,cAAR,YAAqB;AACvC,QAAM,iBAAiB,iBAAiB,MAAM,SAAS;AAEvD,MAAI,eAAe,WAAW,GAAG;AAC7B,WAAO,EAAE,MAAM,gBAAgB,MAAM;AAAA,EACzC;AAEA,QAAM,gBAAe,aAAQ,iBAAR,YAAwB;AAC7C,QAAM,mBAAmB,gBAAgB,gBAAgB,cAAc,SAAS;AAEhF,SAAO;AAAA,IACH,MAAM,GAAG,gBAAgB;AAAA;AAAA,EAAO,IAAI;AAAA,IACpC,gBAAgB;AAAA,EACpB;AACJ;;;AFjEO,IAAM,kBAAwD,CACjE,aACE;AAAA,EACF,MAAM;AAAA,EAEN,iBAAiB,IAAI;AAEjB,WAAO,UAAU,KAAK,EAAE;AAAA,EAC5B;AAAA,EAEA,UAAU,MAAM,KAAK;AACjB,UAAM,SAAS,aAAa,MAAM,OAAO;AACzC,QAAI,CAAC,OAAO,eAAgB;AAC5B,WAAO,OAAO;AAAA,EAClB;AACJ;;;ADjBA,IAAO,sBAAQ,sCAAoB,eAAe;","names":["import_unplugin","exports"]}
|
package/dist/esbuild.js
CHANGED
|
@@ -13,26 +13,26 @@ var FRAMEWORK_PATHS = {
|
|
|
13
13
|
function createRegistry(framework) {
|
|
14
14
|
const basePath = FRAMEWORK_PATHS[framework];
|
|
15
15
|
return {
|
|
16
|
-
Note: { exports: ["Note"], path:
|
|
17
|
-
Card: { exports: ["Card"], path:
|
|
18
|
-
CardGroup: { exports: ["CardGroup"], path:
|
|
19
|
-
Accordion: { exports: ["Accordion"], path:
|
|
20
|
-
AccordionGroup: { exports: ["AccordionGroup"], path:
|
|
21
|
-
Stepper: { exports: ["Stepper", "StepperItem"], path:
|
|
22
|
-
Kbd: { exports: ["Kbd"], path:
|
|
23
|
-
Tooltip: { exports: ["Tooltip"], path:
|
|
24
|
-
Youtube: { exports: ["Youtube"], path:
|
|
25
|
-
Button: { exports: ["Button"], path:
|
|
26
|
-
DocuLink: { exports: ["DocuLink"], path:
|
|
27
|
-
DocuImage: { exports: ["DocuImage"], path:
|
|
28
|
-
Files: { exports: ["Files"], path:
|
|
29
|
-
Folder: { exports: ["Folder"], path:
|
|
30
|
-
File: { exports: ["File"], path:
|
|
31
|
-
Release: { exports: ["Release"], path:
|
|
32
|
-
Changes: { exports: ["Changes"], path:
|
|
33
|
-
Pre: { exports: ["Pre"], path:
|
|
34
|
-
Copy: { exports: ["Copy"], path:
|
|
35
|
-
DocuBookProvider: { exports: ["DocuBookProvider"], path:
|
|
16
|
+
Note: { exports: ["Note"], path: basePath },
|
|
17
|
+
Card: { exports: ["Card"], path: basePath },
|
|
18
|
+
CardGroup: { exports: ["CardGroup"], path: basePath },
|
|
19
|
+
Accordion: { exports: ["Accordion"], path: basePath },
|
|
20
|
+
AccordionGroup: { exports: ["AccordionGroup"], path: basePath },
|
|
21
|
+
Stepper: { exports: ["Stepper", "StepperItem"], path: basePath },
|
|
22
|
+
Kbd: { exports: ["Kbd"], path: basePath },
|
|
23
|
+
Tooltip: { exports: ["Tooltip"], path: basePath },
|
|
24
|
+
Youtube: { exports: ["Youtube"], path: basePath },
|
|
25
|
+
Button: { exports: ["Button"], path: basePath },
|
|
26
|
+
DocuLink: { exports: ["DocuLink"], path: basePath },
|
|
27
|
+
DocuImage: { exports: ["DocuImage"], path: basePath },
|
|
28
|
+
Files: { exports: ["Files"], path: basePath },
|
|
29
|
+
Folder: { exports: ["Folder"], path: basePath },
|
|
30
|
+
File: { exports: ["File"], path: basePath },
|
|
31
|
+
Release: { exports: ["Release"], path: basePath },
|
|
32
|
+
Changes: { exports: ["Changes"], path: basePath },
|
|
33
|
+
Pre: { exports: ["Pre"], path: basePath },
|
|
34
|
+
Copy: { exports: ["Copy"], path: basePath },
|
|
35
|
+
DocuBookProvider: { exports: ["DocuBookProvider"], path: basePath }
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
38
|
function getComponentRegistry(framework = "react") {
|
package/dist/esbuild.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/esbuild.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createEsbuildPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path:
|
|
1
|
+
{"version":3,"sources":["../src/esbuild.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createEsbuildPlugin(unpluginFactory)\n","import type { UnpluginFactory } from 'unplugin'\nimport type { Options } from './types'\nimport { createUnplugin } from 'unplugin'\nimport { transformMdx } from './core/transform'\n\nexport const unpluginFactory: UnpluginFactory<Options | undefined> = (\n options,\n) => ({\n name: 'unplugin-docubook',\n\n transformInclude(id) {\n // Only process .mdx and .md files\n return /\\.mdx?$/.test(id)\n },\n\n transform(code, _id) {\n const result = transformMdx(code, options)\n if (!result.hasTransformed) return\n return result.code\n },\n})\n\nexport const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory)\n\nexport default unplugin\n","import type { Framework } from '../types'\n\nexport interface ComponentMeta {\n exports: string[]\n path: string\n}\n\nconst FRAMEWORK_PATHS: Record<Framework, string> = {\n react: '/react',\n vue: '/vue',\n svelte: '/svelte',\n}\n\nfunction createRegistry(framework: Framework): Record<string, ComponentMeta> {\n const basePath = FRAMEWORK_PATHS[framework]\n\n return {\n Note: { exports: ['Note'], path: basePath },\n Card: { exports: ['Card'], path: basePath },\n CardGroup: { exports: ['CardGroup'], path: basePath },\n Accordion: { exports: ['Accordion'], path: basePath },\n AccordionGroup: { exports: ['AccordionGroup'], path: basePath },\n Stepper: { exports: ['Stepper', 'StepperItem'], path: basePath },\n Kbd: { exports: ['Kbd'], path: basePath },\n Tooltip: { exports: ['Tooltip'], path: basePath },\n Youtube: { exports: ['Youtube'], path: basePath },\n Button: { exports: ['Button'], path: basePath },\n DocuLink: { exports: ['DocuLink'], path: basePath },\n DocuImage: { exports: ['DocuImage'], path: basePath },\n Files: { exports: ['Files'], path: basePath },\n Folder: { exports: ['Folder'], path: basePath },\n File: { exports: ['File'], path: basePath },\n Release: { exports: ['Release'], path: basePath },\n Changes: { exports: ['Changes'], path: basePath },\n Pre: { exports: ['Pre'], path: basePath },\n Copy: { exports: ['Copy'], path: basePath },\n DocuBookProvider: { exports: ['DocuBookProvider'], path: basePath },\n }\n}\n\nexport function getComponentRegistry(framework: Framework = 'react'): Record<string, ComponentMeta> {\n return createRegistry(framework)\n}\n\nexport function buildComponentDetectionRegex(framework: Framework = 'react'): RegExp {\n const registry = getComponentRegistry(framework)\n const names = Object.keys(registry)\n return new RegExp(`<(${names.join('|')})(?=[\\\\s/>])`, 'g')\n}\n","import type { Options, Framework } from '../types'\nimport { getComponentRegistry, buildComponentDetectionRegex } from './registry'\n\nconst DEFAULT_IMPORT_SOURCE = 'unplugin-docubook/components'\nconst DEFAULT_FRAMEWORK: Framework = 'react'\n\nexport function detectComponents(code: string, framework: Framework = DEFAULT_FRAMEWORK): string[] {\n const regex = buildComponentDetectionRegex(framework)\n const registry = getComponentRegistry(framework)\n const found = new Set<string>()\n let match: RegExpExecArray | null\n\n while ((match = regex.exec(code)) !== null) {\n const name = match[1]\n if (name && registry[name]) {\n found.add(name)\n }\n }\n\n return Array.from(found)\n}\n\nexport function generateImports(\n componentNames: string[],\n importSource: string,\n framework: Framework = DEFAULT_FRAMEWORK,\n): string {\n const registry = getComponentRegistry(framework)\n const pathToExports = new Map<string, Set<string>>()\n\n for (const name of componentNames) {\n const meta = registry[name]\n if (!meta) continue\n\n const fullPath = `${importSource}${meta.path}`\n if (!pathToExports.has(fullPath)) {\n pathToExports.set(fullPath, new Set())\n }\n for (const exp of meta.exports) {\n pathToExports.get(fullPath)!.add(exp)\n }\n }\n\n const lines: string[] = []\n for (const [path, exports] of pathToExports) {\n const names = Array.from(exports).sort().join(', ')\n lines.push(`import { ${names} } from '${path}'`)\n }\n\n return lines.join('\\n')\n}\n\nexport function transformMdx(\n code: string,\n options: Options = {},\n): { code: string; hasTransformed: boolean } {\n const framework = options.framework ?? DEFAULT_FRAMEWORK\n const usedComponents = detectComponents(code, framework)\n\n if (usedComponents.length === 0) {\n return { code, hasTransformed: false }\n }\n\n const importSource = options.importSource ?? DEFAULT_IMPORT_SOURCE\n const importStatements = generateImports(usedComponents, importSource, framework)\n\n return {\n code: `${importStatements}\\n\\n${code}`,\n hasTransformed: true,\n }\n}\n"],"mappings":";AAAA,SAAS,2BAA2B;;;ACEpC,SAAS,sBAAsB;;;ACK/B,IAAM,kBAA6C;AAAA,EAC/C,OAAO;AAA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