unplugin-docubook 1.0.0 → 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.
Files changed (110) hide show
  1. package/README.md +142 -2
  2. package/dist/astro.cjs +152 -0
  3. package/dist/astro.cjs.map +1 -0
  4. package/dist/astro.js +125 -12
  5. package/dist/astro.js.map +1 -1
  6. package/dist/bun.cjs +140 -0
  7. package/dist/bun.cjs.map +1 -0
  8. package/dist/bun.js +115 -5
  9. package/dist/bun.js.map +1 -1
  10. package/dist/components/index.cjs +829 -0
  11. package/dist/components/index.cjs.map +1 -0
  12. package/dist/components/index.js +720 -512
  13. package/dist/components/index.js.map +1 -1
  14. package/dist/esbuild.cjs +140 -0
  15. package/dist/esbuild.cjs.map +1 -0
  16. package/dist/esbuild.js +115 -5
  17. package/dist/esbuild.js.map +1 -1
  18. package/dist/farm.cjs +140 -0
  19. package/dist/farm.cjs.map +1 -0
  20. package/dist/farm.js +115 -5
  21. package/dist/farm.js.map +1 -1
  22. package/dist/index.cjs +143 -0
  23. package/dist/index.cjs.map +1 -0
  24. package/dist/index.js +116 -2
  25. package/dist/index.js.map +1 -0
  26. package/dist/next.cjs +140 -0
  27. package/dist/next.cjs.map +1 -0
  28. package/dist/next.js +119 -0
  29. package/dist/next.js.map +1 -0
  30. package/dist/nuxt.cjs +160 -0
  31. package/dist/nuxt.cjs.map +1 -0
  32. package/dist/nuxt.js +134 -16
  33. package/dist/nuxt.js.map +1 -1
  34. package/dist/rolldown.cjs +140 -0
  35. package/dist/rolldown.cjs.map +1 -0
  36. package/dist/rolldown.js +115 -5
  37. package/dist/rolldown.js.map +1 -1
  38. package/dist/rollup.cjs +140 -0
  39. package/dist/rollup.cjs.map +1 -0
  40. package/dist/rollup.js +115 -5
  41. package/dist/rollup.js.map +1 -1
  42. package/dist/rspack.cjs +140 -0
  43. package/dist/rspack.cjs.map +1 -0
  44. package/dist/rspack.js +115 -5
  45. package/dist/rspack.js.map +1 -1
  46. package/dist/types.cjs +19 -0
  47. package/dist/types.cjs.map +1 -0
  48. package/dist/types.js +1 -1
  49. package/dist/types.js.map +1 -0
  50. package/dist/vite.cjs +140 -0
  51. package/dist/vite.cjs.map +1 -0
  52. package/dist/vite.js +115 -5
  53. package/dist/vite.js.map +1 -1
  54. package/dist/webpack.cjs +140 -0
  55. package/dist/webpack.cjs.map +1 -0
  56. package/dist/webpack.js +115 -5
  57. package/dist/webpack.js.map +1 -1
  58. package/package.json +92 -33
  59. package/dist/adapters/next-DNQX7_ln.d.ts +0 -24
  60. package/dist/adapters/next-DNQX7_ln.d.ts.map +0 -1
  61. package/dist/adapters/next.js +0 -38
  62. package/dist/adapters/next.js.map +0 -1
  63. package/dist/adapters/react-C9Vk6aTD.d.ts +0 -24
  64. package/dist/adapters/react-C9Vk6aTD.d.ts.map +0 -1
  65. package/dist/adapters/react.js +0 -39
  66. package/dist/adapters/react.js.map +0 -1
  67. package/dist/adapters/svelte-C-dhzdmU.d.ts +0 -19
  68. package/dist/adapters/svelte-C-dhzdmU.d.ts.map +0 -1
  69. package/dist/adapters/svelte.js +0 -43
  70. package/dist/adapters/svelte.js.map +0 -1
  71. package/dist/adapters/vue-BWv1EZit.d.ts +0 -22
  72. package/dist/adapters/vue-BWv1EZit.d.ts.map +0 -1
  73. package/dist/adapters/vue.js +0 -41
  74. package/dist/adapters/vue.js.map +0 -1
  75. package/dist/astro-BcckVQ-2.d.ts +0 -19
  76. package/dist/astro-BcckVQ-2.d.ts.map +0 -1
  77. package/dist/bun-DYPhytPs.d.ts +0 -7
  78. package/dist/bun-DYPhytPs.d.ts.map +0 -1
  79. package/dist/components/index-LWFtIGRd.d.ts +0 -265
  80. package/dist/components/index-LWFtIGRd.d.ts.map +0 -1
  81. package/dist/context-BKx0jIwX.js +0 -49
  82. package/dist/context-BKx0jIwX.js.map +0 -1
  83. package/dist/esbuild-BD42nX0_.d.ts +0 -8
  84. package/dist/esbuild-BD42nX0_.d.ts.map +0 -1
  85. package/dist/farm-C3XYk4nf.d.ts +0 -7
  86. package/dist/farm-C3XYk4nf.d.ts.map +0 -1
  87. package/dist/framework/index-98dEoo0g.d.ts +0 -11
  88. package/dist/framework/index-98dEoo0g.d.ts.map +0 -1
  89. package/dist/framework/index.js +0 -29
  90. package/dist/framework/index.js.map +0 -1
  91. package/dist/index-2f48-Fxc.d.ts +0 -10
  92. package/dist/index-2f48-Fxc.d.ts.map +0 -1
  93. package/dist/nuxt-BidHgMAG.d.ts +0 -5
  94. package/dist/nuxt-BidHgMAG.d.ts.map +0 -1
  95. package/dist/rolldown-CrcgSKP1.d.ts +0 -8
  96. package/dist/rolldown-CrcgSKP1.d.ts.map +0 -1
  97. package/dist/rollup-DDEc1C_K.d.ts +0 -8
  98. package/dist/rollup-DDEc1C_K.d.ts.map +0 -1
  99. package/dist/rspack-QbbymFlY.d.ts +0 -7
  100. package/dist/rspack-QbbymFlY.d.ts.map +0 -1
  101. package/dist/src-KZV_M01u.js +0 -165
  102. package/dist/src-KZV_M01u.js.map +0 -1
  103. package/dist/types-BQhWL5Qs.d.ts +0 -34
  104. package/dist/types-BQhWL5Qs.d.ts.map +0 -1
  105. package/dist/types-uxY1cMXO.d.ts +0 -28
  106. package/dist/types-uxY1cMXO.d.ts.map +0 -1
  107. package/dist/vite-9CqZQPO-.d.ts +0 -8
  108. package/dist/vite-9CqZQPO-.d.ts.map +0 -1
  109. package/dist/webpack-CBuuXltg.d.ts +0 -7
  110. package/dist/webpack-CBuuXltg.d.ts.map +0 -1
package/README.md CHANGED
@@ -12,5 +12,145 @@ The Universal Documentation Engine for any JavaScript Framework.
12
12
  ## Install
13
13
 
14
14
  ```bash
15
- npm i unplugin-docubook
16
- ```
15
+ npm install unplugin-docubook
16
+ ```
17
+
18
+ ## Bundler & Framework Integration
19
+
20
+ ### Vite
21
+
22
+ ```ts
23
+ // vite.config.ts
24
+ import DocuBook from 'unplugin-docubook/vite'
25
+ import { defineConfig } from 'vite'
26
+
27
+ export default defineConfig({
28
+ plugins: [
29
+ DocuBook({ /* options */ }),
30
+ ],
31
+ })
32
+ ```
33
+
34
+ ### Rollup
35
+
36
+ ```ts
37
+ // rollup.config.ts
38
+ import DocuBook from 'unplugin-docubook/rollup'
39
+
40
+ export default {
41
+ plugins: [
42
+ DocuBook({ /* options */ }),
43
+ ],
44
+ }
45
+ ```
46
+
47
+ ### webpack
48
+
49
+ ```js
50
+ // webpack.config.js
51
+ module.exports = {
52
+ /* ... */
53
+ plugins: [
54
+ require('unplugin-docubook/webpack')({ /* options */ }),
55
+ ],
56
+ }
57
+ ```
58
+
59
+ ### Rspack
60
+
61
+ ```js
62
+ // rspack.config.js
63
+ module.exports = {
64
+ /* ... */
65
+ plugins: [
66
+ require('unplugin-docubook/rspack')({ /* options */ }),
67
+ ],
68
+ }
69
+ ```
70
+
71
+ ### esbuild
72
+
73
+ ```ts
74
+ // esbuild.config.ts
75
+ import { build } from 'esbuild'
76
+ import DocuBook from 'unplugin-docubook/esbuild'
77
+
78
+ build({
79
+ plugins: [DocuBook()],
80
+ })
81
+ ```
82
+
83
+ ### Farm
84
+
85
+ ```ts
86
+ // farm.config.ts
87
+ import DocuBook from 'unplugin-docubook/farm'
88
+ import { defineConfig } from '@farmfe/core'
89
+
90
+ export default defineConfig({
91
+ plugins: [
92
+ DocuBook({ /* options */ }),
93
+ ],
94
+ })
95
+ ```
96
+
97
+ ### Bun
98
+
99
+ ```ts
100
+ // bun.config.ts
101
+ import DocuBook from 'unplugin-docubook/bun'
102
+
103
+ await Bun.build({
104
+ entrypoints: ['./src/index.ts'],
105
+ outdir: './dist',
106
+ plugins: [
107
+ DocuBook({ /* options */ }),
108
+ ],
109
+ })
110
+ ```
111
+
112
+ ### Nuxt
113
+
114
+ ```ts
115
+ // nuxt.config.ts
116
+ export default defineNuxtConfig({
117
+ modules: [
118
+ ['unplugin-docubook/nuxt', { /* options */ }],
119
+ ],
120
+ })
121
+ ```
122
+
123
+ ### Astro
124
+
125
+ ```js
126
+ // astro.config.mjs
127
+ import { defineConfig } from 'astro/config'
128
+ import DocuBook from 'unplugin-docubook/astro'
129
+
130
+ export default defineConfig({
131
+ integrations: [DocuBook()],
132
+ })
133
+ ```
134
+
135
+ ## Options
136
+
137
+ | Option | Type | Default | Description |
138
+ |--------|------|---------|-------------|
139
+ | `framework` | `'react' \| 'vue' \| 'svelte'` | `'react'` | Target framework |
140
+ | `include` | `string[]` | `['**/*.mdx', '**/*.md']` | Files to include |
141
+ | `exclude` | `string[]` | - | Files to exclude |
142
+ | `importSource` | `string` | `'unplugin-docubook/components'` | Import source for components |
143
+
144
+ ## Usage
145
+
146
+ ```mdx
147
+ # My Documentation
148
+
149
+ <Accordion title="What is DocuBook?">
150
+ DocuBook is awesome!
151
+ </Accordion>
152
+ ```
153
+
154
+ ## License
155
+
156
+ MIT
package/dist/astro.cjs ADDED
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/astro.ts
21
+ var astro_exports = {};
22
+ __export(astro_exports, {
23
+ default: () => astro_default
24
+ });
25
+ module.exports = __toCommonJS(astro_exports);
26
+
27
+ // src/index.ts
28
+ var import_unplugin = require("unplugin");
29
+
30
+ // src/core/registry.ts
31
+ var FRAMEWORK_PATHS = {
32
+ react: "/react",
33
+ vue: "/vue",
34
+ svelte: "/svelte"
35
+ };
36
+ function createRegistry(framework) {
37
+ const basePath = FRAMEWORK_PATHS[framework];
38
+ return {
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
+ };
60
+ }
61
+ function getComponentRegistry(framework = "react") {
62
+ return createRegistry(framework);
63
+ }
64
+ function buildComponentDetectionRegex(framework = "react") {
65
+ const registry = getComponentRegistry(framework);
66
+ const names = Object.keys(registry);
67
+ return new RegExp(`<(${names.join("|")})(?=[\\s/>])`, "g");
68
+ }
69
+
70
+ // src/core/transform.ts
71
+ var DEFAULT_IMPORT_SOURCE = "unplugin-docubook/components";
72
+ var DEFAULT_FRAMEWORK = "react";
73
+ function detectComponents(code, framework = DEFAULT_FRAMEWORK) {
74
+ const regex = buildComponentDetectionRegex(framework);
75
+ const registry = getComponentRegistry(framework);
76
+ const found = /* @__PURE__ */ new Set();
77
+ let match;
78
+ while ((match = regex.exec(code)) !== null) {
79
+ const name = match[1];
80
+ if (name && registry[name]) {
81
+ found.add(name);
82
+ }
83
+ }
84
+ return Array.from(found);
85
+ }
86
+ function generateImports(componentNames, importSource, framework = DEFAULT_FRAMEWORK) {
87
+ const registry = getComponentRegistry(framework);
88
+ const pathToExports = /* @__PURE__ */ new Map();
89
+ for (const name of componentNames) {
90
+ const meta = registry[name];
91
+ if (!meta) continue;
92
+ const fullPath = `${importSource}${meta.path}`;
93
+ if (!pathToExports.has(fullPath)) {
94
+ pathToExports.set(fullPath, /* @__PURE__ */ new Set());
95
+ }
96
+ for (const exp of meta.exports) {
97
+ pathToExports.get(fullPath).add(exp);
98
+ }
99
+ }
100
+ const lines = [];
101
+ for (const [path, exports2] of pathToExports) {
102
+ const names = Array.from(exports2).sort().join(", ");
103
+ lines.push(`import { ${names} } from '${path}'`);
104
+ }
105
+ return lines.join("\n");
106
+ }
107
+ function transformMdx(code, options = {}) {
108
+ var _a, _b;
109
+ const framework = (_a = options.framework) != null ? _a : DEFAULT_FRAMEWORK;
110
+ const usedComponents = detectComponents(code, framework);
111
+ if (usedComponents.length === 0) {
112
+ return { code, hasTransformed: false };
113
+ }
114
+ const importSource = (_b = options.importSource) != null ? _b : DEFAULT_IMPORT_SOURCE;
115
+ const importStatements = generateImports(usedComponents, importSource, framework);
116
+ return {
117
+ code: `${importStatements}
118
+
119
+ ${code}`,
120
+ hasTransformed: true
121
+ };
122
+ }
123
+
124
+ // src/index.ts
125
+ var unpluginFactory = (options) => ({
126
+ name: "unplugin-docubook",
127
+ transformInclude(id) {
128
+ return /\.mdx?$/.test(id);
129
+ },
130
+ transform(code, _id) {
131
+ const result = transformMdx(code, options);
132
+ if (!result.hasTransformed) return;
133
+ return result.code;
134
+ }
135
+ });
136
+ var unplugin = /* @__PURE__ */ (0, import_unplugin.createUnplugin)(unpluginFactory);
137
+ var index_default = unplugin;
138
+
139
+ // src/astro.ts
140
+ function astro_default(options) {
141
+ return {
142
+ name: "unplugin-docubook",
143
+ hooks: {
144
+ "astro:config:setup": async (astro) => {
145
+ var _a;
146
+ (_a = astro.config.vite).plugins || (_a.plugins = []);
147
+ astro.config.vite.plugins.push(index_default.vite(options));
148
+ }
149
+ }
150
+ };
151
+ }
152
+ //# sourceMappingURL=astro.cjs.map
@@ -0,0 +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: 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,SA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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,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
@@ -1,16 +1,129 @@
1
- import { t as unplugin } from "./src-KZV_M01u.js";
1
+ // src/index.ts
2
+ import { createUnplugin } from "unplugin";
2
3
 
3
- //#region src/astro.ts
4
- function astro_default(options) {
5
- return {
6
- name: "unplugin-docubook",
7
- hooks: { "astro:config:setup": async (astro) => {
8
- astro.config.vite.plugins ||= [];
9
- astro.config.vite.plugins.push(unplugin.vite(options));
10
- } }
11
- };
4
+ // src/core/registry.ts
5
+ var FRAMEWORK_PATHS = {
6
+ react: "/react",
7
+ vue: "/vue",
8
+ svelte: "/svelte"
9
+ };
10
+ function createRegistry(framework) {
11
+ const basePath = FRAMEWORK_PATHS[framework];
12
+ return {
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
+ };
34
+ }
35
+ function getComponentRegistry(framework = "react") {
36
+ return createRegistry(framework);
37
+ }
38
+ function buildComponentDetectionRegex(framework = "react") {
39
+ const registry = getComponentRegistry(framework);
40
+ const names = Object.keys(registry);
41
+ return new RegExp(`<(${names.join("|")})(?=[\\s/>])`, "g");
42
+ }
43
+
44
+ // src/core/transform.ts
45
+ var DEFAULT_IMPORT_SOURCE = "unplugin-docubook/components";
46
+ var DEFAULT_FRAMEWORK = "react";
47
+ function detectComponents(code, framework = DEFAULT_FRAMEWORK) {
48
+ const regex = buildComponentDetectionRegex(framework);
49
+ const registry = getComponentRegistry(framework);
50
+ const found = /* @__PURE__ */ new Set();
51
+ let match;
52
+ while ((match = regex.exec(code)) !== null) {
53
+ const name = match[1];
54
+ if (name && registry[name]) {
55
+ found.add(name);
56
+ }
57
+ }
58
+ return Array.from(found);
59
+ }
60
+ function generateImports(componentNames, importSource, framework = DEFAULT_FRAMEWORK) {
61
+ const registry = getComponentRegistry(framework);
62
+ const pathToExports = /* @__PURE__ */ new Map();
63
+ for (const name of componentNames) {
64
+ const meta = registry[name];
65
+ if (!meta) continue;
66
+ const fullPath = `${importSource}${meta.path}`;
67
+ if (!pathToExports.has(fullPath)) {
68
+ pathToExports.set(fullPath, /* @__PURE__ */ new Set());
69
+ }
70
+ for (const exp of meta.exports) {
71
+ pathToExports.get(fullPath).add(exp);
72
+ }
73
+ }
74
+ const lines = [];
75
+ for (const [path, exports] of pathToExports) {
76
+ const names = Array.from(exports).sort().join(", ");
77
+ lines.push(`import { ${names} } from '${path}'`);
78
+ }
79
+ return lines.join("\n");
12
80
  }
81
+ function transformMdx(code, options = {}) {
82
+ var _a, _b;
83
+ const framework = (_a = options.framework) != null ? _a : DEFAULT_FRAMEWORK;
84
+ const usedComponents = detectComponents(code, framework);
85
+ if (usedComponents.length === 0) {
86
+ return { code, hasTransformed: false };
87
+ }
88
+ const importSource = (_b = options.importSource) != null ? _b : DEFAULT_IMPORT_SOURCE;
89
+ const importStatements = generateImports(usedComponents, importSource, framework);
90
+ return {
91
+ code: `${importStatements}
13
92
 
14
- //#endregion
15
- export { astro_default as default };
93
+ ${code}`,
94
+ hasTransformed: true
95
+ };
96
+ }
97
+
98
+ // src/index.ts
99
+ var unpluginFactory = (options) => ({
100
+ name: "unplugin-docubook",
101
+ transformInclude(id) {
102
+ return /\.mdx?$/.test(id);
103
+ },
104
+ transform(code, _id) {
105
+ const result = transformMdx(code, options);
106
+ if (!result.hasTransformed) return;
107
+ return result.code;
108
+ }
109
+ });
110
+ var unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
111
+ var index_default = unplugin;
112
+
113
+ // src/astro.ts
114
+ function astro_default(options) {
115
+ return {
116
+ name: "unplugin-docubook",
117
+ hooks: {
118
+ "astro:config:setup": async (astro) => {
119
+ var _a;
120
+ (_a = astro.config.vite).plugins || (_a.plugins = []);
121
+ astro.config.vite.plugins.push(index_default.vite(options));
122
+ }
123
+ }
124
+ };
125
+ }
126
+ export {
127
+ astro_default as default
128
+ };
16
129
  //# sourceMappingURL=astro.js.map
package/dist/astro.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"astro.js","names":[],"sources":["../src/astro.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"],"mappings":";;;AAWA,uBAAyB,SAAkB;AACvC,QAAO;EACH,MAAM;EACN,OAAO,EACH,sBAAsB,OAAO,UAAuB;AAChD,SAAM,OAAO,KAAK,YAAY,EAAE;AAChC,SAAM,OAAO,KAAK,QAAQ,KAAK,SAAS,KAAK,QAAQ,CAAC;KAE7D;EACJ"}
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,SAAS;AAAA,IACpD,gBAAgB,EAAE,SAAS,CAAC,gBAAgB,GAAG,MAAM,SAAS;AAAA,IAC9D,SAAS,EAAE,SAAS,CAAC,WAAW,aAAa,GAAG,MAAM,SAAS;AAAA,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7C,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 ADDED
@@ -0,0 +1,140 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/bun.ts
21
+ var bun_exports = {};
22
+ __export(bun_exports, {
23
+ default: () => bun_default
24
+ });
25
+ module.exports = __toCommonJS(bun_exports);
26
+ var import_unplugin2 = require("unplugin");
27
+
28
+ // src/index.ts
29
+ var import_unplugin = require("unplugin");
30
+
31
+ // src/core/registry.ts
32
+ var FRAMEWORK_PATHS = {
33
+ react: "/react",
34
+ vue: "/vue",
35
+ svelte: "/svelte"
36
+ };
37
+ function createRegistry(framework) {
38
+ const basePath = FRAMEWORK_PATHS[framework];
39
+ return {
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
+ };
61
+ }
62
+ function getComponentRegistry(framework = "react") {
63
+ return createRegistry(framework);
64
+ }
65
+ function buildComponentDetectionRegex(framework = "react") {
66
+ const registry = getComponentRegistry(framework);
67
+ const names = Object.keys(registry);
68
+ return new RegExp(`<(${names.join("|")})(?=[\\s/>])`, "g");
69
+ }
70
+
71
+ // src/core/transform.ts
72
+ var DEFAULT_IMPORT_SOURCE = "unplugin-docubook/components";
73
+ var DEFAULT_FRAMEWORK = "react";
74
+ function detectComponents(code, framework = DEFAULT_FRAMEWORK) {
75
+ const regex = buildComponentDetectionRegex(framework);
76
+ const registry = getComponentRegistry(framework);
77
+ const found = /* @__PURE__ */ new Set();
78
+ let match;
79
+ while ((match = regex.exec(code)) !== null) {
80
+ const name = match[1];
81
+ if (name && registry[name]) {
82
+ found.add(name);
83
+ }
84
+ }
85
+ return Array.from(found);
86
+ }
87
+ function generateImports(componentNames, importSource, framework = DEFAULT_FRAMEWORK) {
88
+ const registry = getComponentRegistry(framework);
89
+ const pathToExports = /* @__PURE__ */ new Map();
90
+ for (const name of componentNames) {
91
+ const meta = registry[name];
92
+ if (!meta) continue;
93
+ const fullPath = `${importSource}${meta.path}`;
94
+ if (!pathToExports.has(fullPath)) {
95
+ pathToExports.set(fullPath, /* @__PURE__ */ new Set());
96
+ }
97
+ for (const exp of meta.exports) {
98
+ pathToExports.get(fullPath).add(exp);
99
+ }
100
+ }
101
+ const lines = [];
102
+ for (const [path, exports2] of pathToExports) {
103
+ const names = Array.from(exports2).sort().join(", ");
104
+ lines.push(`import { ${names} } from '${path}'`);
105
+ }
106
+ return lines.join("\n");
107
+ }
108
+ function transformMdx(code, options = {}) {
109
+ var _a, _b;
110
+ const framework = (_a = options.framework) != null ? _a : DEFAULT_FRAMEWORK;
111
+ const usedComponents = detectComponents(code, framework);
112
+ if (usedComponents.length === 0) {
113
+ return { code, hasTransformed: false };
114
+ }
115
+ const importSource = (_b = options.importSource) != null ? _b : DEFAULT_IMPORT_SOURCE;
116
+ const importStatements = generateImports(usedComponents, importSource, framework);
117
+ return {
118
+ code: `${importStatements}
119
+
120
+ ${code}`,
121
+ hasTransformed: true
122
+ };
123
+ }
124
+
125
+ // src/index.ts
126
+ var unpluginFactory = (options) => ({
127
+ name: "unplugin-docubook",
128
+ transformInclude(id) {
129
+ return /\.mdx?$/.test(id);
130
+ },
131
+ transform(code, _id) {
132
+ const result = transformMdx(code, options);
133
+ if (!result.hasTransformed) return;
134
+ return result.code;
135
+ }
136
+ });
137
+
138
+ // src/bun.ts
139
+ var bun_default = (0, import_unplugin2.createBunPlugin)(unpluginFactory);
140
+ //# sourceMappingURL=bun.cjs.map
@@ -0,0 +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: 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;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,IAChD,QAAQ,EAAE,SAAS,CAAC,QAAQ,GAAG,MAAM,SAAS;AAAA,IAC9C,UAA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