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.
- package/README.md +142 -2
- package/dist/astro.cjs +152 -0
- package/dist/astro.cjs.map +1 -0
- package/dist/astro.js +125 -12
- package/dist/astro.js.map +1 -1
- package/dist/bun.cjs +140 -0
- package/dist/bun.cjs.map +1 -0
- package/dist/bun.js +115 -5
- package/dist/bun.js.map +1 -1
- package/dist/components/index.cjs +829 -0
- package/dist/components/index.cjs.map +1 -0
- package/dist/components/index.js +720 -512
- package/dist/components/index.js.map +1 -1
- package/dist/esbuild.cjs +140 -0
- package/dist/esbuild.cjs.map +1 -0
- package/dist/esbuild.js +115 -5
- package/dist/esbuild.js.map +1 -1
- package/dist/farm.cjs +140 -0
- package/dist/farm.cjs.map +1 -0
- package/dist/farm.js +115 -5
- package/dist/farm.js.map +1 -1
- package/dist/index.cjs +143 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.js +116 -2
- package/dist/index.js.map +1 -0
- package/dist/next.cjs +140 -0
- package/dist/next.cjs.map +1 -0
- package/dist/next.js +119 -0
- package/dist/next.js.map +1 -0
- package/dist/nuxt.cjs +160 -0
- package/dist/nuxt.cjs.map +1 -0
- package/dist/nuxt.js +134 -16
- package/dist/nuxt.js.map +1 -1
- package/dist/rolldown.cjs +140 -0
- package/dist/rolldown.cjs.map +1 -0
- package/dist/rolldown.js +115 -5
- package/dist/rolldown.js.map +1 -1
- package/dist/rollup.cjs +140 -0
- package/dist/rollup.cjs.map +1 -0
- package/dist/rollup.js +115 -5
- package/dist/rollup.js.map +1 -1
- package/dist/rspack.cjs +140 -0
- package/dist/rspack.cjs.map +1 -0
- package/dist/rspack.js +115 -5
- package/dist/rspack.js.map +1 -1
- package/dist/types.cjs +19 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -0
- package/dist/vite.cjs +140 -0
- package/dist/vite.cjs.map +1 -0
- package/dist/vite.js +115 -5
- package/dist/vite.js.map +1 -1
- package/dist/webpack.cjs +140 -0
- package/dist/webpack.cjs.map +1 -0
- package/dist/webpack.js +115 -5
- package/dist/webpack.js.map +1 -1
- package/package.json +92 -33
- package/dist/adapters/next-DNQX7_ln.d.ts +0 -24
- package/dist/adapters/next-DNQX7_ln.d.ts.map +0 -1
- package/dist/adapters/next.js +0 -38
- package/dist/adapters/next.js.map +0 -1
- package/dist/adapters/react-C9Vk6aTD.d.ts +0 -24
- package/dist/adapters/react-C9Vk6aTD.d.ts.map +0 -1
- package/dist/adapters/react.js +0 -39
- package/dist/adapters/react.js.map +0 -1
- package/dist/adapters/svelte-C-dhzdmU.d.ts +0 -19
- package/dist/adapters/svelte-C-dhzdmU.d.ts.map +0 -1
- package/dist/adapters/svelte.js +0 -43
- package/dist/adapters/svelte.js.map +0 -1
- package/dist/adapters/vue-BWv1EZit.d.ts +0 -22
- package/dist/adapters/vue-BWv1EZit.d.ts.map +0 -1
- package/dist/adapters/vue.js +0 -41
- package/dist/adapters/vue.js.map +0 -1
- package/dist/astro-BcckVQ-2.d.ts +0 -19
- package/dist/astro-BcckVQ-2.d.ts.map +0 -1
- package/dist/bun-DYPhytPs.d.ts +0 -7
- package/dist/bun-DYPhytPs.d.ts.map +0 -1
- package/dist/components/index-LWFtIGRd.d.ts +0 -265
- package/dist/components/index-LWFtIGRd.d.ts.map +0 -1
- package/dist/context-BKx0jIwX.js +0 -49
- package/dist/context-BKx0jIwX.js.map +0 -1
- package/dist/esbuild-BD42nX0_.d.ts +0 -8
- package/dist/esbuild-BD42nX0_.d.ts.map +0 -1
- package/dist/farm-C3XYk4nf.d.ts +0 -7
- package/dist/farm-C3XYk4nf.d.ts.map +0 -1
- package/dist/framework/index-98dEoo0g.d.ts +0 -11
- package/dist/framework/index-98dEoo0g.d.ts.map +0 -1
- package/dist/framework/index.js +0 -29
- package/dist/framework/index.js.map +0 -1
- package/dist/index-2f48-Fxc.d.ts +0 -10
- package/dist/index-2f48-Fxc.d.ts.map +0 -1
- package/dist/nuxt-BidHgMAG.d.ts +0 -5
- package/dist/nuxt-BidHgMAG.d.ts.map +0 -1
- package/dist/rolldown-CrcgSKP1.d.ts +0 -8
- package/dist/rolldown-CrcgSKP1.d.ts.map +0 -1
- package/dist/rollup-DDEc1C_K.d.ts +0 -8
- package/dist/rollup-DDEc1C_K.d.ts.map +0 -1
- package/dist/rspack-QbbymFlY.d.ts +0 -7
- package/dist/rspack-QbbymFlY.d.ts.map +0 -1
- package/dist/src-KZV_M01u.js +0 -165
- package/dist/src-KZV_M01u.js.map +0 -1
- package/dist/types-BQhWL5Qs.d.ts +0 -34
- package/dist/types-BQhWL5Qs.d.ts.map +0 -1
- package/dist/types-uxY1cMXO.d.ts +0 -28
- package/dist/types-uxY1cMXO.d.ts.map +0 -1
- package/dist/vite-9CqZQPO-.d.ts +0 -8
- package/dist/vite-9CqZQPO-.d.ts.map +0 -1
- package/dist/webpack-CBuuXltg.d.ts +0 -7
- package/dist/webpack-CBuuXltg.d.ts.map +0 -1
package/dist/webpack.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/webpack.ts
|
|
21
|
+
var webpack_exports = {};
|
|
22
|
+
__export(webpack_exports, {
|
|
23
|
+
default: () => webpack_default
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(webpack_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/webpack.ts
|
|
139
|
+
var webpack_default = (0, import_unplugin2.createWebpackPlugin)(unpluginFactory);
|
|
140
|
+
//# sourceMappingURL=webpack.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/webpack.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createWebpackPlugin(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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
-
|
|
1
|
+
// src/webpack.ts
|
|
2
2
|
import { createWebpackPlugin } from "unplugin";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
// src/index.ts
|
|
5
|
+
import { createUnplugin } from "unplugin";
|
|
6
|
+
|
|
7
|
+
// src/core/registry.ts
|
|
8
|
+
var FRAMEWORK_PATHS = {
|
|
9
|
+
react: "/react",
|
|
10
|
+
vue: "/vue",
|
|
11
|
+
svelte: "/svelte"
|
|
12
|
+
};
|
|
13
|
+
function createRegistry(framework) {
|
|
14
|
+
const basePath = FRAMEWORK_PATHS[framework];
|
|
15
|
+
return {
|
|
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
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function getComponentRegistry(framework = "react") {
|
|
39
|
+
return createRegistry(framework);
|
|
40
|
+
}
|
|
41
|
+
function buildComponentDetectionRegex(framework = "react") {
|
|
42
|
+
const registry = getComponentRegistry(framework);
|
|
43
|
+
const names = Object.keys(registry);
|
|
44
|
+
return new RegExp(`<(${names.join("|")})(?=[\\s/>])`, "g");
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// src/core/transform.ts
|
|
48
|
+
var DEFAULT_IMPORT_SOURCE = "unplugin-docubook/components";
|
|
49
|
+
var DEFAULT_FRAMEWORK = "react";
|
|
50
|
+
function detectComponents(code, framework = DEFAULT_FRAMEWORK) {
|
|
51
|
+
const regex = buildComponentDetectionRegex(framework);
|
|
52
|
+
const registry = getComponentRegistry(framework);
|
|
53
|
+
const found = /* @__PURE__ */ new Set();
|
|
54
|
+
let match;
|
|
55
|
+
while ((match = regex.exec(code)) !== null) {
|
|
56
|
+
const name = match[1];
|
|
57
|
+
if (name && registry[name]) {
|
|
58
|
+
found.add(name);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return Array.from(found);
|
|
62
|
+
}
|
|
63
|
+
function generateImports(componentNames, importSource, framework = DEFAULT_FRAMEWORK) {
|
|
64
|
+
const registry = getComponentRegistry(framework);
|
|
65
|
+
const pathToExports = /* @__PURE__ */ new Map();
|
|
66
|
+
for (const name of componentNames) {
|
|
67
|
+
const meta = registry[name];
|
|
68
|
+
if (!meta) continue;
|
|
69
|
+
const fullPath = `${importSource}${meta.path}`;
|
|
70
|
+
if (!pathToExports.has(fullPath)) {
|
|
71
|
+
pathToExports.set(fullPath, /* @__PURE__ */ new Set());
|
|
72
|
+
}
|
|
73
|
+
for (const exp of meta.exports) {
|
|
74
|
+
pathToExports.get(fullPath).add(exp);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const lines = [];
|
|
78
|
+
for (const [path, exports] of pathToExports) {
|
|
79
|
+
const names = Array.from(exports).sort().join(", ");
|
|
80
|
+
lines.push(`import { ${names} } from '${path}'`);
|
|
81
|
+
}
|
|
82
|
+
return lines.join("\n");
|
|
83
|
+
}
|
|
84
|
+
function transformMdx(code, options = {}) {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const framework = (_a = options.framework) != null ? _a : DEFAULT_FRAMEWORK;
|
|
87
|
+
const usedComponents = detectComponents(code, framework);
|
|
88
|
+
if (usedComponents.length === 0) {
|
|
89
|
+
return { code, hasTransformed: false };
|
|
90
|
+
}
|
|
91
|
+
const importSource = (_b = options.importSource) != null ? _b : DEFAULT_IMPORT_SOURCE;
|
|
92
|
+
const importStatements = generateImports(usedComponents, importSource, framework);
|
|
93
|
+
return {
|
|
94
|
+
code: `${importStatements}
|
|
6
95
|
|
|
7
|
-
|
|
8
|
-
|
|
96
|
+
${code}`,
|
|
97
|
+
hasTransformed: true
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/index.ts
|
|
102
|
+
var unpluginFactory = (options) => ({
|
|
103
|
+
name: "unplugin-docubook",
|
|
104
|
+
transformInclude(id) {
|
|
105
|
+
return /\.mdx?$/.test(id);
|
|
106
|
+
},
|
|
107
|
+
transform(code, _id) {
|
|
108
|
+
const result = transformMdx(code, options);
|
|
109
|
+
if (!result.hasTransformed) return;
|
|
110
|
+
return result.code;
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// src/webpack.ts
|
|
115
|
+
var webpack_default = createWebpackPlugin(unpluginFactory);
|
|
116
|
+
export {
|
|
117
|
+
webpack_default as default
|
|
118
|
+
};
|
|
9
119
|
//# sourceMappingURL=webpack.js.map
|
package/dist/webpack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/webpack.ts","../src/index.ts","../src/core/registry.ts","../src/core/transform.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { unpluginFactory } from '.'\n\nexport default createWebpackPlugin(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,SA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,IAAI,QAAQ,EAAG,IAAI,GAAG;AAAA,IACxC;AAAA,EACJ;AAEA,QAAM,QAAkB,CAAC;AACzB,aAAW,CAAC,MAAM,OAAO,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,kBAAQ,oBAAoB,eAAe;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-docubook",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.2",
|
|
5
5
|
"description": "Write with MDX — works with pretty much any JS framework: Vite, React, Vue, Svelte, you name it",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"keywords": [
|
|
@@ -18,46 +18,104 @@
|
|
|
18
18
|
"repository": "github:DocuBook/content",
|
|
19
19
|
"author": "wildan.nrs",
|
|
20
20
|
"exports": {
|
|
21
|
-
".":
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"./
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
"./
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"./
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"./
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"./
|
|
42
|
-
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"require": "./dist/index.cjs"
|
|
24
|
+
},
|
|
25
|
+
"./next": {
|
|
26
|
+
"import": "./dist/next.js",
|
|
27
|
+
"require": "./dist/next.cjs"
|
|
28
|
+
},
|
|
29
|
+
"./bun": {
|
|
30
|
+
"import": "./dist/bun.js",
|
|
31
|
+
"require": "./dist/bun.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./astro": {
|
|
34
|
+
"import": "./dist/astro.js",
|
|
35
|
+
"require": "./dist/astro.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./esbuild": {
|
|
38
|
+
"import": "./dist/esbuild.js",
|
|
39
|
+
"require": "./dist/esbuild.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./farm": {
|
|
42
|
+
"import": "./dist/farm.js",
|
|
43
|
+
"require": "./dist/farm.cjs"
|
|
44
|
+
},
|
|
45
|
+
"./rolldown": {
|
|
46
|
+
"import": "./dist/rolldown.js",
|
|
47
|
+
"require": "./dist/rolldown.cjs"
|
|
48
|
+
},
|
|
49
|
+
"./nuxt": {
|
|
50
|
+
"import": "./dist/nuxt.js",
|
|
51
|
+
"require": "./dist/nuxt.cjs"
|
|
52
|
+
},
|
|
53
|
+
"./rollup": {
|
|
54
|
+
"import": "./dist/rollup.js",
|
|
55
|
+
"require": "./dist/rollup.cjs"
|
|
56
|
+
},
|
|
57
|
+
"./rspack": {
|
|
58
|
+
"import": "./dist/rspack.js",
|
|
59
|
+
"require": "./dist/rspack.cjs"
|
|
60
|
+
},
|
|
61
|
+
"./types": {
|
|
62
|
+
"import": "./dist/types.js",
|
|
63
|
+
"require": "./dist/types.cjs"
|
|
64
|
+
},
|
|
65
|
+
"./vite": {
|
|
66
|
+
"import": "./dist/vite.js",
|
|
67
|
+
"require": "./dist/vite.cjs"
|
|
68
|
+
},
|
|
69
|
+
"./webpack": {
|
|
70
|
+
"import": "./dist/webpack.js",
|
|
71
|
+
"require": "./dist/webpack.cjs"
|
|
72
|
+
},
|
|
73
|
+
"./components": {
|
|
74
|
+
"import": "./dist/components/index.js",
|
|
75
|
+
"require": "./dist/components/index.cjs"
|
|
76
|
+
},
|
|
77
|
+
"./components/react": {
|
|
78
|
+
"import": "./dist/components/index.js",
|
|
79
|
+
"require": "./dist/components/index.cjs"
|
|
80
|
+
},
|
|
81
|
+
"./components/vue": {
|
|
82
|
+
"import": "./dist/components/index.js",
|
|
83
|
+
"require": "./dist/components/index.cjs"
|
|
84
|
+
},
|
|
85
|
+
"./components/svelte": {
|
|
86
|
+
"import": "./dist/components/index.js",
|
|
87
|
+
"require": "./dist/components/index.cjs"
|
|
88
|
+
},
|
|
89
|
+
"./adapters/next": {
|
|
90
|
+
"import": "./dist/adapters/next.js",
|
|
91
|
+
"require": "./dist/adapters/next.cjs"
|
|
92
|
+
},
|
|
93
|
+
"./adapters/react": {
|
|
94
|
+
"import": "./dist/adapters/react.js",
|
|
95
|
+
"require": "./dist/adapters/react.cjs"
|
|
96
|
+
},
|
|
97
|
+
"./adapters/vue": {
|
|
98
|
+
"import": "./dist/adapters/vue.js",
|
|
99
|
+
"require": "./dist/adapters/vue.cjs"
|
|
100
|
+
},
|
|
101
|
+
"./adapters/svelte": {
|
|
102
|
+
"import": "./dist/adapters/svelte.js",
|
|
103
|
+
"require": "./dist/adapters/svelte.cjs"
|
|
104
|
+
},
|
|
105
|
+
"./framework": {
|
|
106
|
+
"import": "./dist/framework/index.js",
|
|
107
|
+
"require": "./dist/framework/index.cjs"
|
|
108
|
+
},
|
|
43
109
|
"./package.json": "./package.json"
|
|
44
110
|
},
|
|
45
|
-
"main": "./dist/index.
|
|
111
|
+
"main": "./dist/index.cjs",
|
|
46
112
|
"module": "./dist/index.js",
|
|
47
113
|
"types": "./dist/index.d.ts",
|
|
48
|
-
"typesVersions": {
|
|
49
|
-
"*": {
|
|
50
|
-
"*": [
|
|
51
|
-
"./dist/*",
|
|
52
|
-
"./*"
|
|
53
|
-
]
|
|
54
|
-
}
|
|
55
|
-
},
|
|
56
114
|
"files": [
|
|
57
115
|
"dist"
|
|
58
116
|
],
|
|
59
117
|
"scripts": {
|
|
60
|
-
"build": "
|
|
118
|
+
"build": "tsup",
|
|
61
119
|
"dev": "tsdown -w",
|
|
62
120
|
"lint": "eslint .",
|
|
63
121
|
"prepublishOnly": "npm run build",
|
|
@@ -143,6 +201,7 @@
|
|
|
143
201
|
"react": "^19.0.0",
|
|
144
202
|
"react-dom": "^19.0.0",
|
|
145
203
|
"tsdown": "^0.12.0",
|
|
204
|
+
"tsup": "^8.5.1",
|
|
146
205
|
"tsx": "^4.19.4",
|
|
147
206
|
"typescript": "^5.8.3",
|
|
148
207
|
"typescript-eslint": "^8.56.1",
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
//#region src/adapters/next.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Next.js adapter — wraps children with DocuBookProvider
|
|
8
|
-
* configured to use next/link and next/image.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* import { NextAdapter } from 'unplugin-docubook/adapters/next'
|
|
12
|
-
*
|
|
13
|
-
* export default function Layout({ children }) {
|
|
14
|
-
* return <NextAdapter>{children}</NextAdapter>
|
|
15
|
-
* }
|
|
16
|
-
*/
|
|
17
|
-
declare function NextAdapter({
|
|
18
|
-
children
|
|
19
|
-
}: {
|
|
20
|
-
children: React.ReactNode;
|
|
21
|
-
}): react_jsx_runtime0.JSX.Element;
|
|
22
|
-
//#endregion
|
|
23
|
-
export { NextAdapter, NextAdapter as default };
|
|
24
|
-
//# sourceMappingURL=next-DNQX7_ln.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"next-DNQX7_ln.d.ts","names":[],"sources":["../../src/adapters/next.tsx"],"sourcesContent":[],"mappings":";;;;;;;;AAgBA;;;;;;;;iBAAgB,WAAA;;;YAAsC,KAAA,CAAM;IAAW,kBAAA,CAAA,GAAA,CAAA"}
|
package/dist/adapters/next.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { t as DocuBookProvider } from "../context-BKx0jIwX.js";
|
|
4
|
-
import { createRequire } from "node:module";
|
|
5
|
-
import React from "react";
|
|
6
|
-
import { jsx } from "react/jsx-runtime";
|
|
7
|
-
|
|
8
|
-
//#region \0rolldown/runtime.js
|
|
9
|
-
var __require = /* @__PURE__ */ createRequire(import.meta.url);
|
|
10
|
-
|
|
11
|
-
//#endregion
|
|
12
|
-
//#region src/adapters/next.tsx
|
|
13
|
-
/**
|
|
14
|
-
* Next.js adapter — wraps children with DocuBookProvider
|
|
15
|
-
* configured to use next/link and next/image.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* import { NextAdapter } from 'unplugin-docubook/adapters/next'
|
|
19
|
-
*
|
|
20
|
-
* export default function Layout({ children }) {
|
|
21
|
-
* return <NextAdapter>{children}</NextAdapter>
|
|
22
|
-
* }
|
|
23
|
-
*/
|
|
24
|
-
function NextAdapter({ children }) {
|
|
25
|
-
const NextLink = __require("next/link").default;
|
|
26
|
-
const NextImage = __require("next/image").default;
|
|
27
|
-
return /* @__PURE__ */ jsx(DocuBookProvider, {
|
|
28
|
-
value: {
|
|
29
|
-
Link: NextLink,
|
|
30
|
-
Image: NextImage
|
|
31
|
-
},
|
|
32
|
-
children
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
//#endregion
|
|
37
|
-
export { NextAdapter, NextAdapter as default };
|
|
38
|
-
//# sourceMappingURL=next.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"next.js","names":[],"sources":["../../src/adapters/next.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport { DocuBookProvider } from '../components/react/context'\n\n/**\n * Next.js adapter — wraps children with DocuBookProvider\n * configured to use next/link and next/image.\n *\n * @example\n * import { NextAdapter } from 'unplugin-docubook/adapters/next'\n *\n * export default function Layout({ children }) {\n * return <NextAdapter>{children}</NextAdapter>\n * }\n */\nexport function NextAdapter({ children }: { children: React.ReactNode }) {\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const NextLink = require('next/link').default\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const NextImage = require('next/image').default\n\n return (\n <DocuBookProvider value={{ Link: NextLink, Image: NextImage }}>\n {children}\n </DocuBookProvider>\n )\n}\n\nexport default NextAdapter\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAgBA,SAAgB,YAAY,EAAE,YAA2C;CAErE,MAAM,qBAAmB,YAAY,CAAC;CAEtC,MAAM,sBAAoB,aAAa,CAAC;AAExC,QACI,oBAAC,kBAAD;EAAkB,OAAO;GAAE,MAAM;GAAU,OAAO;GAAW;EACxD;EACc"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
-
|
|
4
|
-
//#region src/adapters/react.d.ts
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Default React adapter — uses native HTML elements for Link/Image.
|
|
8
|
-
* Works with any React setup (Vite, CRA, Remix, etc).
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* import { ReactAdapter } from 'unplugin-docubook/adapters/react'
|
|
12
|
-
*
|
|
13
|
-
* <ReactAdapter>
|
|
14
|
-
* <MDXContent />
|
|
15
|
-
* </ReactAdapter>
|
|
16
|
-
*/
|
|
17
|
-
declare function ReactAdapter({
|
|
18
|
-
children
|
|
19
|
-
}: {
|
|
20
|
-
children: React.ReactNode;
|
|
21
|
-
}): react_jsx_runtime0.JSX.Element;
|
|
22
|
-
//#endregion
|
|
23
|
-
export { ReactAdapter, ReactAdapter as default };
|
|
24
|
-
//# sourceMappingURL=react-C9Vk6aTD.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react-C9Vk6aTD.d.ts","names":[],"sources":["../../src/adapters/react.tsx"],"sourcesContent":[],"mappings":";;;;;;;;AAgBA;;;;;;;;iBAAgB,YAAA;;;YAAuC,KAAA,CAAM;IAAW,kBAAA,CAAA,GAAA,CAAA"}
|
package/dist/adapters/react.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import { t as DocuBookProvider } from "../context-BKx0jIwX.js";
|
|
4
|
-
import React from "react";
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
6
|
-
|
|
7
|
-
//#region src/adapters/react.tsx
|
|
8
|
-
/**
|
|
9
|
-
* Default React adapter — uses native HTML elements for Link/Image.
|
|
10
|
-
* Works with any React setup (Vite, CRA, Remix, etc).
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* import { ReactAdapter } from 'unplugin-docubook/adapters/react'
|
|
14
|
-
*
|
|
15
|
-
* <ReactAdapter>
|
|
16
|
-
* <MDXContent />
|
|
17
|
-
* </ReactAdapter>
|
|
18
|
-
*/
|
|
19
|
-
function ReactAdapter({ children }) {
|
|
20
|
-
return /* @__PURE__ */ jsx(DocuBookProvider, {
|
|
21
|
-
value: {
|
|
22
|
-
Link: ({ href, children: c, ...props }) => /* @__PURE__ */ jsx("a", {
|
|
23
|
-
href,
|
|
24
|
-
...props,
|
|
25
|
-
children: c
|
|
26
|
-
}),
|
|
27
|
-
Image: ({ src, alt, ...props }) => /* @__PURE__ */ jsx("img", {
|
|
28
|
-
src,
|
|
29
|
-
alt,
|
|
30
|
-
...props
|
|
31
|
-
})
|
|
32
|
-
},
|
|
33
|
-
children
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
export { ReactAdapter, ReactAdapter as default };
|
|
39
|
-
//# sourceMappingURL=react.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"react.js","names":[],"sources":["../../src/adapters/react.tsx"],"sourcesContent":["'use client'\n\nimport React from 'react'\nimport { DocuBookProvider } from '../components/react/context'\n\n/**\n * Default React adapter — uses native HTML elements for Link/Image.\n * Works with any React setup (Vite, CRA, Remix, etc).\n *\n * @example\n * import { ReactAdapter } from 'unplugin-docubook/adapters/react'\n *\n * <ReactAdapter>\n * <MDXContent />\n * </ReactAdapter>\n */\nexport function ReactAdapter({ children }: { children: React.ReactNode }) {\n return (\n <DocuBookProvider\n value={{\n Link: ({ href, children: c, ...props }) => (\n <a href={href} {...props}>\n {c}\n </a>\n ),\n Image: ({ src, alt, ...props }) => <img src={src} alt={alt} {...props} />,\n }}\n >\n {children}\n </DocuBookProvider>\n )\n}\n\nexport default ReactAdapter\n"],"mappings":";;;;;;;;;;;;;;;;;;AAgBA,SAAgB,aAAa,EAAE,YAA2C;AACtE,QACI,oBAAC,kBAAD;EACI,OAAO;GACH,OAAO,EAAE,MAAM,UAAU,GAAG,GAAG,YAC3B,oBAAC,KAAD;IAAS;IAAM,GAAI;cACd;IACD;GAER,QAAQ,EAAE,KAAK,KAAK,GAAG,YAAY,oBAAC,OAAD;IAAU;IAAU;IAAK,GAAI;IAAS;GAC5E;EAEA;EACc"}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { a as FrameworkLinkProps, i as FrameworkImageProps } from "../types-BQhWL5Qs.js";
|
|
2
|
-
import { Readable } from "svelte/store";
|
|
3
|
-
import { SvelteComponent } from "svelte";
|
|
4
|
-
|
|
5
|
-
//#region src/adapters/svelte.d.ts
|
|
6
|
-
interface SvelteFrameworkConfig {
|
|
7
|
-
Link: new (props: FrameworkLinkProps) => SvelteComponent;
|
|
8
|
-
Image: new (props: FrameworkImageProps) => SvelteComponent;
|
|
9
|
-
}
|
|
10
|
-
declare function setDocuBook(config: Partial<SvelteFrameworkConfig>): void;
|
|
11
|
-
declare function getDocuBook(): SvelteFrameworkConfig;
|
|
12
|
-
declare function useDocuBook(): Readable<SvelteFrameworkConfig>;
|
|
13
|
-
declare function useLink(): SvelteFrameworkConfig['Link'];
|
|
14
|
-
declare function useImage(): SvelteFrameworkConfig['Image'];
|
|
15
|
-
//# sourceMappingURL=svelte.d.ts.map
|
|
16
|
-
|
|
17
|
-
//#endregion
|
|
18
|
-
export { SvelteFrameworkConfig, getDocuBook, setDocuBook, useDocuBook, useImage, useLink };
|
|
19
|
-
//# sourceMappingURL=svelte-C-dhzdmU.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"svelte-C-dhzdmU.d.ts","names":[],"sources":["../../src/adapters/svelte.tsx"],"sourcesContent":[],"mappings":";;;;;UAIiB,qBAAA;oBACG,uBAAuB;EAD1B,KAAA,EAAA,KAAA,KAAA,EAEI,mBAFiB,EAAA,GAEO,eAFP;;AAClB,iBAmBJ,WAAA,CAnBI,MAAA,EAmBgB,OAnBhB,CAmBwB,qBAnBxB,CAAA,CAAA,EAAA,IAAA;AAAuB,iBAuB3B,WAAA,CAAA,CAvB2B,EAuBZ,qBAvBY;AACtB,iBA0BL,WAAA,CAAA,CA1BK,EA0BU,QA1BV,CA0BmB,qBA1BnB,CAAA;AAAwB,iBA8B7B,OAAA,CAAA,CA9B6B,EA8BlB,qBA9BkB,CAAA,MAAA,CAAA;AAAe,iBAkC5C,QAAA,CAAA,CAlC4C,EAkChC,qBAlCgC,CAAA,OAAA,CAAA;AAkB5D"}
|