@rspress/plugin-playground 1.40.2 → 1.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cjs/301.js +12 -0
- package/dist/cli/cjs/index.js +475 -591
- package/dist/cli/esm/301.mjs +11 -0
- package/dist/cli/esm/index.d.ts +28 -24
- package/dist/cli/esm/index.mjs +470 -0
- package/dist/web/cjs/index.js +289 -355
- package/dist/web/esm/index.d.ts +45 -37
- package/dist/web/esm/index.mjs +269 -0
- package/package.json +10 -9
- package/dist/cli/cjs/index.js.map +0 -1
- package/dist/cli/esm/index.js +0 -577
- package/dist/cli/esm/index.js.map +0 -1
- package/dist/web/cjs/index.js.map +0 -1
- package/dist/web/esm/index.js +0 -354
- package/dist/web/esm/index.js.map +0 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const ids = [
|
|
2
|
+
'301'
|
|
3
|
+
];
|
|
4
|
+
export const modules = {
|
|
5
|
+
"../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/index.js": function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
6
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
7
|
+
visit: ()=>_lib_index_js__WEBPACK_IMPORTED_MODULE_0__.Vn
|
|
8
|
+
});
|
|
9
|
+
var _lib_index_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/lib/index.js");
|
|
10
|
+
}
|
|
11
|
+
};
|
package/dist/cli/esm/index.d.ts
CHANGED
|
@@ -1,24 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export
|
|
1
|
+
import type { EditorProps } from '@monaco-editor/react';
|
|
2
|
+
import type { loader } from '@monaco-editor/react';
|
|
3
|
+
import type { RouteMeta } from '@rspress/shared';
|
|
4
|
+
import type { RspressPlugin } from '@rspress/shared';
|
|
5
|
+
|
|
6
|
+
declare interface PlaygroundOptions {
|
|
7
|
+
render: string;
|
|
8
|
+
include: Array<string | [string, string]>;
|
|
9
|
+
defaultDirection: 'horizontal' | 'vertical';
|
|
10
|
+
editorPosition: 'left' | 'right';
|
|
11
|
+
babelUrl: string;
|
|
12
|
+
monacoLoader: Parameters<typeof loader.config>[0];
|
|
13
|
+
monacoOptions: EditorProps['options'];
|
|
14
|
+
/**
|
|
15
|
+
* determine how to handle a internal code block without meta
|
|
16
|
+
* @default 'playground'
|
|
17
|
+
*/
|
|
18
|
+
defaultRenderMode?: 'pure' | 'playground';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The plugin is used to preview component.
|
|
23
|
+
*/
|
|
24
|
+
export declare function pluginPlayground(options?: Partial<PlaygroundOptions>): RspressPlugin;
|
|
25
|
+
|
|
26
|
+
export declare let routeMeta: RouteMeta[];
|
|
27
|
+
|
|
28
|
+
export { }
|
|
@@ -0,0 +1,470 @@
|
|
|
1
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__ from "node:fs";
|
|
2
|
+
import * as __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__ from "node:path";
|
|
3
|
+
import * as __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__ from "rspack-plugin-virtual-module";
|
|
4
|
+
import * as __WEBPACK_EXTERNAL_MODULE__oxidation_compiler_napi_5e24345a__ from "@oxidation-compiler/napi";
|
|
5
|
+
var __webpack_modules__ = {
|
|
6
|
+
"../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/lib/index.js": function(__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
|
|
7
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
8
|
+
Vn: ()=>lib_visit
|
|
9
|
+
});
|
|
10
|
+
const convert = function(test) {
|
|
11
|
+
if (null == test) return ok;
|
|
12
|
+
if ('string' == typeof test) return typeFactory(test);
|
|
13
|
+
if ('object' == typeof test) return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
|
|
14
|
+
if ('function' == typeof test) return castFactory(test);
|
|
15
|
+
throw new Error('Expected function, string, or object as test');
|
|
16
|
+
};
|
|
17
|
+
function anyFactory(tests) {
|
|
18
|
+
const checks = [];
|
|
19
|
+
let index = -1;
|
|
20
|
+
while(++index < tests.length)checks[index] = convert(tests[index]);
|
|
21
|
+
return castFactory(any);
|
|
22
|
+
function any(...parameters) {
|
|
23
|
+
let index = -1;
|
|
24
|
+
while(++index < checks.length)if (checks[index].call(this, ...parameters)) return true;
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function propsFactory(check) {
|
|
29
|
+
return castFactory(all);
|
|
30
|
+
function all(node) {
|
|
31
|
+
let key;
|
|
32
|
+
for(key in check)if (node[key] !== check[key]) return false;
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function typeFactory(check) {
|
|
37
|
+
return castFactory(type);
|
|
38
|
+
function type(node) {
|
|
39
|
+
return node && node.type === check;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function castFactory(check) {
|
|
43
|
+
return assertion;
|
|
44
|
+
function assertion(node, ...parameters) {
|
|
45
|
+
return Boolean(node && 'object' == typeof node && 'type' in node && Boolean(check.call(this, node, ...parameters)));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function ok() {
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
function color(d) {
|
|
52
|
+
return '\u001B[33m' + d + '\u001B[39m';
|
|
53
|
+
}
|
|
54
|
+
const CONTINUE = true;
|
|
55
|
+
const EXIT = false;
|
|
56
|
+
const SKIP = 'skip';
|
|
57
|
+
const visitParents = function(tree, test, visitor, reverse) {
|
|
58
|
+
if ('function' == typeof test && 'function' != typeof visitor) {
|
|
59
|
+
reverse = visitor;
|
|
60
|
+
visitor = test;
|
|
61
|
+
test = null;
|
|
62
|
+
}
|
|
63
|
+
const is = convert(test);
|
|
64
|
+
const step = reverse ? -1 : 1;
|
|
65
|
+
factory(tree, void 0, [])();
|
|
66
|
+
function factory(node, index, parents) {
|
|
67
|
+
const value = node && 'object' == typeof node ? node : {};
|
|
68
|
+
if ('string' == typeof value.type) {
|
|
69
|
+
const name = 'string' == typeof value.tagName ? value.tagName : 'string' == typeof value.name ? value.name : void 0;
|
|
70
|
+
Object.defineProperty(visit, 'name', {
|
|
71
|
+
value: 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return visit;
|
|
75
|
+
function visit() {
|
|
76
|
+
let result = [];
|
|
77
|
+
let subresult;
|
|
78
|
+
let offset;
|
|
79
|
+
let grandparents;
|
|
80
|
+
if (!test || is(node, index, parents[parents.length - 1] || null)) {
|
|
81
|
+
result = toResult(visitor(node, parents));
|
|
82
|
+
if (result[0] === EXIT) return result;
|
|
83
|
+
}
|
|
84
|
+
if (node.children && result[0] !== SKIP) {
|
|
85
|
+
offset = (reverse ? node.children.length : -1) + step;
|
|
86
|
+
grandparents = parents.concat(node);
|
|
87
|
+
while(offset > -1 && offset < node.children.length){
|
|
88
|
+
subresult = factory(node.children[offset], offset, grandparents)();
|
|
89
|
+
if (subresult[0] === EXIT) return subresult;
|
|
90
|
+
offset = 'number' == typeof subresult[1] ? subresult[1] : offset + step;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
function toResult(value) {
|
|
98
|
+
if (Array.isArray(value)) return value;
|
|
99
|
+
if ('number' == typeof value) return [
|
|
100
|
+
CONTINUE,
|
|
101
|
+
value
|
|
102
|
+
];
|
|
103
|
+
return [
|
|
104
|
+
value
|
|
105
|
+
];
|
|
106
|
+
}
|
|
107
|
+
const lib_visit = function(tree, test, visitor, reverse) {
|
|
108
|
+
if ('function' == typeof test && 'function' != typeof visitor) {
|
|
109
|
+
reverse = visitor;
|
|
110
|
+
visitor = test;
|
|
111
|
+
test = null;
|
|
112
|
+
}
|
|
113
|
+
visitParents(tree, test, overload, reverse);
|
|
114
|
+
function overload(node, parents) {
|
|
115
|
+
const parent = parents[parents.length - 1];
|
|
116
|
+
return visitor(node, parent ? parent.children.indexOf(node) : null, parent);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var __webpack_module_cache__ = {};
|
|
122
|
+
function __webpack_require__(moduleId) {
|
|
123
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
124
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
125
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
126
|
+
exports: {}
|
|
127
|
+
};
|
|
128
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
129
|
+
return module.exports;
|
|
130
|
+
}
|
|
131
|
+
__webpack_require__.m = __webpack_modules__;
|
|
132
|
+
(()=>{
|
|
133
|
+
__webpack_require__.d = function(exports, definition) {
|
|
134
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: definition[key]
|
|
137
|
+
});
|
|
138
|
+
};
|
|
139
|
+
})();
|
|
140
|
+
(()=>{
|
|
141
|
+
__webpack_require__.f = {};
|
|
142
|
+
__webpack_require__.e = function(chunkId) {
|
|
143
|
+
return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
|
|
144
|
+
__webpack_require__.f[key](chunkId, promises);
|
|
145
|
+
return promises;
|
|
146
|
+
}, []));
|
|
147
|
+
};
|
|
148
|
+
})();
|
|
149
|
+
(()=>{
|
|
150
|
+
__webpack_require__.u = function(chunkId) {
|
|
151
|
+
return "" + chunkId + ".mjs";
|
|
152
|
+
};
|
|
153
|
+
})();
|
|
154
|
+
(()=>{
|
|
155
|
+
__webpack_require__.o = function(obj, prop) {
|
|
156
|
+
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
157
|
+
};
|
|
158
|
+
})();
|
|
159
|
+
(()=>{
|
|
160
|
+
var installedChunks = {
|
|
161
|
+
980: 0
|
|
162
|
+
};
|
|
163
|
+
var installChunk = function(data) {
|
|
164
|
+
var ids = data.ids;
|
|
165
|
+
var modules = data.modules;
|
|
166
|
+
var runtime = data.runtime;
|
|
167
|
+
var moduleId, chunkId, i = 0;
|
|
168
|
+
for(moduleId in modules)if (__webpack_require__.o(modules, moduleId)) __webpack_require__.m[moduleId] = modules[moduleId];
|
|
169
|
+
if (runtime) runtime(__webpack_require__);
|
|
170
|
+
for(; i < ids.length; i++){
|
|
171
|
+
chunkId = ids[i];
|
|
172
|
+
if (__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) installedChunks[chunkId][0]();
|
|
173
|
+
installedChunks[ids[i]] = 0;
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
__webpack_require__.f.j = function(chunkId, promises) {
|
|
177
|
+
var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : void 0;
|
|
178
|
+
if (0 !== installedChunkData) {
|
|
179
|
+
if (installedChunkData) promises.push(installedChunkData[1]);
|
|
180
|
+
else {
|
|
181
|
+
var promise = import("./" + __webpack_require__.u(chunkId)).then(installChunk, function(e) {
|
|
182
|
+
if (0 !== installedChunks[chunkId]) installedChunks[chunkId] = void 0;
|
|
183
|
+
throw e;
|
|
184
|
+
});
|
|
185
|
+
var promise = Promise.race([
|
|
186
|
+
promise,
|
|
187
|
+
new Promise(function(resolve) {
|
|
188
|
+
installedChunkData = installedChunks[chunkId] = [
|
|
189
|
+
resolve
|
|
190
|
+
];
|
|
191
|
+
})
|
|
192
|
+
]);
|
|
193
|
+
promises.push(installedChunkData[1] = promise);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
})();
|
|
198
|
+
const DEFAULT_BABEL_URL = 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js';
|
|
199
|
+
const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';
|
|
200
|
+
function normalizeUrl(u) {
|
|
201
|
+
return u.replace(/\/\//g, '/');
|
|
202
|
+
}
|
|
203
|
+
const staticPath = __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__dirname, '../../../static');
|
|
204
|
+
var lib = __webpack_require__("../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/lib/index.js");
|
|
205
|
+
const parseImports = (code, sourceExt)=>{
|
|
206
|
+
const parsed = __WEBPACK_EXTERNAL_MODULE__oxidation_compiler_napi_5e24345a__["default"].parseSync(code, {
|
|
207
|
+
sourceType: 'module',
|
|
208
|
+
sourceFilename: `index.${sourceExt}`
|
|
209
|
+
});
|
|
210
|
+
const ast = JSON.parse(parsed.program);
|
|
211
|
+
const result = [];
|
|
212
|
+
ast.body.forEach((statement)=>{
|
|
213
|
+
if ('ImportDeclaration' === statement.type) result.push(statement.source.value);
|
|
214
|
+
});
|
|
215
|
+
return result;
|
|
216
|
+
};
|
|
217
|
+
const getNodeAttribute = (node, attrName)=>{
|
|
218
|
+
var _node_attributes_find;
|
|
219
|
+
return null === (_node_attributes_find = node.attributes.find((attr)=>attr.name === attrName)) || void 0 === _node_attributes_find ? void 0 : _node_attributes_find.value;
|
|
220
|
+
};
|
|
221
|
+
const getNodeMeta = (node, metaName)=>{
|
|
222
|
+
if (!node.meta) return;
|
|
223
|
+
const meta = node.meta.split(' ');
|
|
224
|
+
const item = meta.find((x)=>x.startsWith(metaName));
|
|
225
|
+
if (null == item ? void 0 : item.startsWith(`${metaName}=`)) return item.substring(metaName.length + 1);
|
|
226
|
+
return item;
|
|
227
|
+
};
|
|
228
|
+
function createPlaygroundNode(currentNode, attrs) {
|
|
229
|
+
Object.assign(currentNode, {
|
|
230
|
+
type: 'mdxJsxFlowElement',
|
|
231
|
+
name: 'Playground',
|
|
232
|
+
attributes: attrs.map((it)=>({
|
|
233
|
+
type: 'mdxJsxAttribute',
|
|
234
|
+
name: it[0],
|
|
235
|
+
value: it[1]
|
|
236
|
+
}))
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
const remarkPlugin = ({ getRouteMeta, editorPosition, defaultRenderMode })=>{
|
|
240
|
+
const routeMeta = getRouteMeta();
|
|
241
|
+
return (tree, vfile)=>{
|
|
242
|
+
const route = routeMeta.find((meta)=>(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.resolve)(meta.absolutePath) === (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.resolve)(vfile.path || vfile.history[0]));
|
|
243
|
+
if (!route) return;
|
|
244
|
+
(0, lib.Vn)(tree, 'mdxJsxFlowElement', (node)=>{
|
|
245
|
+
if ('code' === node.name) {
|
|
246
|
+
const src = getNodeAttribute(node, 'src');
|
|
247
|
+
if (!src) return;
|
|
248
|
+
const demoPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)((0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.dirname)(route.absolutePath), src);
|
|
249
|
+
if (!__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(demoPath)) return;
|
|
250
|
+
const direction = getNodeAttribute(node, 'direction') || '';
|
|
251
|
+
const code = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(demoPath, {
|
|
252
|
+
encoding: 'utf8'
|
|
253
|
+
});
|
|
254
|
+
const language = src.substr(src.lastIndexOf('.') + 1);
|
|
255
|
+
createPlaygroundNode(node, [
|
|
256
|
+
[
|
|
257
|
+
'code',
|
|
258
|
+
code
|
|
259
|
+
],
|
|
260
|
+
[
|
|
261
|
+
'language',
|
|
262
|
+
language
|
|
263
|
+
],
|
|
264
|
+
[
|
|
265
|
+
'direction',
|
|
266
|
+
direction
|
|
267
|
+
],
|
|
268
|
+
[
|
|
269
|
+
'editorPosition',
|
|
270
|
+
editorPosition
|
|
271
|
+
]
|
|
272
|
+
]);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
(0, lib.Vn)(tree, 'code', (node)=>{
|
|
276
|
+
if ('jsx' === node.lang || 'tsx' === node.lang) {
|
|
277
|
+
var _node_meta, _node_meta1;
|
|
278
|
+
const hasPureMeta = null == node ? void 0 : null === (_node_meta = node.meta) || void 0 === _node_meta ? void 0 : _node_meta.includes('pure');
|
|
279
|
+
const hasPlaygroundMeta = null == node ? void 0 : null === (_node_meta1 = node.meta) || void 0 === _node_meta1 ? void 0 : _node_meta1.includes('playground');
|
|
280
|
+
let noTransform;
|
|
281
|
+
switch(defaultRenderMode){
|
|
282
|
+
case 'pure':
|
|
283
|
+
noTransform = !hasPlaygroundMeta;
|
|
284
|
+
break;
|
|
285
|
+
case 'playground':
|
|
286
|
+
noTransform = hasPureMeta;
|
|
287
|
+
break;
|
|
288
|
+
default:
|
|
289
|
+
break;
|
|
290
|
+
}
|
|
291
|
+
if (noTransform) return;
|
|
292
|
+
const direction = getNodeMeta(node, 'direction') || '';
|
|
293
|
+
createPlaygroundNode(node, [
|
|
294
|
+
[
|
|
295
|
+
'code',
|
|
296
|
+
node.value
|
|
297
|
+
],
|
|
298
|
+
[
|
|
299
|
+
'language',
|
|
300
|
+
node.lang
|
|
301
|
+
],
|
|
302
|
+
[
|
|
303
|
+
'direction',
|
|
304
|
+
direction
|
|
305
|
+
],
|
|
306
|
+
[
|
|
307
|
+
'editorPosition',
|
|
308
|
+
editorPosition
|
|
309
|
+
]
|
|
310
|
+
]);
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
};
|
|
314
|
+
};
|
|
315
|
+
let cli_rslib_entry_routeMeta;
|
|
316
|
+
function pluginPlayground(options) {
|
|
317
|
+
var _monacoLoader_paths;
|
|
318
|
+
const { render = '', include, defaultDirection = 'horizontal', editorPosition = 'left', babelUrl = DEFAULT_BABEL_URL, monacoLoader = {}, monacoOptions = {}, defaultRenderMode = 'playground' } = options || {};
|
|
319
|
+
const playgroundVirtualModule = new __WEBPACK_EXTERNAL_MODULE_rspack_plugin_virtual_module_609978fd__.RspackVirtualModulePlugin({});
|
|
320
|
+
const getRouteMeta = ()=>cli_rslib_entry_routeMeta;
|
|
321
|
+
if (render && !/Playground\.(jsx?|tsx?)$/.test(render)) throw new Error('[Playground]: render should ends with Playground.(jsx?|tsx?)');
|
|
322
|
+
const preloads = [];
|
|
323
|
+
const monacoPrefix = (null === (_monacoLoader_paths = monacoLoader.paths) || void 0 === _monacoLoader_paths ? void 0 : _monacoLoader_paths.vs) || DEFAULT_MONACO_URL;
|
|
324
|
+
preloads.push(normalizeUrl(`${monacoPrefix}/loader.js`));
|
|
325
|
+
preloads.push(normalizeUrl(`${monacoPrefix}/editor/editor.main.js`));
|
|
326
|
+
return {
|
|
327
|
+
name: '@rspress/plugin-playground',
|
|
328
|
+
config (config, { removePlugin }) {
|
|
329
|
+
config.markdown = config.markdown || {};
|
|
330
|
+
config.markdown.mdxRs = false;
|
|
331
|
+
removePlugin('@rspress/plugin-preview');
|
|
332
|
+
return config;
|
|
333
|
+
},
|
|
334
|
+
async routeGenerated (routes) {
|
|
335
|
+
cli_rslib_entry_routeMeta = routes;
|
|
336
|
+
const files = routes.map((route)=>route.absolutePath);
|
|
337
|
+
const imports = {};
|
|
338
|
+
await Promise.all(files.map(async (filepath, _index)=>{
|
|
339
|
+
const isMdxFile = /\.mdx?$/.test(filepath);
|
|
340
|
+
if (!isMdxFile) return;
|
|
341
|
+
const { createProcessor } = await import("@mdx-js/mdx");
|
|
342
|
+
const { visit } = await __webpack_require__.e("301").then(__webpack_require__.bind(__webpack_require__, "../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/index.js"));
|
|
343
|
+
const { default: remarkGFM } = await import("remark-gfm");
|
|
344
|
+
try {
|
|
345
|
+
const processor = createProcessor({
|
|
346
|
+
format: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(filepath).slice(1),
|
|
347
|
+
remarkPlugins: [
|
|
348
|
+
remarkGFM
|
|
349
|
+
]
|
|
350
|
+
});
|
|
351
|
+
const source = await __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].promises.readFile(filepath, 'utf-8');
|
|
352
|
+
const ast = processor.parse(source);
|
|
353
|
+
visit(ast, 'mdxJsxFlowElement', (node)=>{
|
|
354
|
+
if ('code' === node.name) {
|
|
355
|
+
const src = getNodeAttribute(node, 'src');
|
|
356
|
+
if (!src) return;
|
|
357
|
+
const demoPath = (0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(__WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].dirname(filepath), src);
|
|
358
|
+
if (!__WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].existsSync(demoPath)) return;
|
|
359
|
+
const code = __WEBPACK_EXTERNAL_MODULE_node_fs_5ea92f0c__["default"].readFileSync(demoPath, {
|
|
360
|
+
encoding: 'utf8'
|
|
361
|
+
});
|
|
362
|
+
const thisImports = parseImports(code, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].extname(demoPath));
|
|
363
|
+
thisImports.forEach((x)=>{
|
|
364
|
+
if (void 0 === imports[x]) imports[x] = x;
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
visit(ast, 'code', (node)=>{
|
|
369
|
+
if ('jsx' === node.lang || 'tsx' === node.lang) {
|
|
370
|
+
const { value, meta } = node;
|
|
371
|
+
const hasPureMeta = null == meta ? void 0 : meta.includes('pure');
|
|
372
|
+
const hasPlaygroundMeta = null == meta ? void 0 : meta.includes('playground');
|
|
373
|
+
let noTransform;
|
|
374
|
+
switch(defaultRenderMode){
|
|
375
|
+
case 'pure':
|
|
376
|
+
noTransform = !hasPlaygroundMeta;
|
|
377
|
+
break;
|
|
378
|
+
case 'playground':
|
|
379
|
+
noTransform = hasPureMeta;
|
|
380
|
+
break;
|
|
381
|
+
default:
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
if (noTransform) return;
|
|
385
|
+
const thisImports = parseImports(value, node.lang);
|
|
386
|
+
thisImports.forEach((x)=>{
|
|
387
|
+
if (void 0 === imports[x]) imports[x] = x;
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
} catch (e) {
|
|
392
|
+
console.error(e);
|
|
393
|
+
throw e;
|
|
394
|
+
}
|
|
395
|
+
}));
|
|
396
|
+
if (include) include.forEach((item)=>{
|
|
397
|
+
if ('string' == typeof item) imports[item] = item;
|
|
398
|
+
else imports[item[0]] = item[1];
|
|
399
|
+
});
|
|
400
|
+
if (!('react' in imports)) imports.react = 'react';
|
|
401
|
+
const importKeys = Object.keys(imports);
|
|
402
|
+
const code = [
|
|
403
|
+
...importKeys.map((x, index)=>`import * as i_${index} from '${imports[x]}';`),
|
|
404
|
+
'const imports = new Map();',
|
|
405
|
+
...importKeys.map((x, index)=>`imports.set('${x}', i_${index});`),
|
|
406
|
+
'function getImport(name, getDefault) {',
|
|
407
|
+
' if (!imports.has(name)) {',
|
|
408
|
+
' throw new Error("Module " + name + " not found");',
|
|
409
|
+
' }',
|
|
410
|
+
' const result = imports.get(name);',
|
|
411
|
+
' if (getDefault && typeof result === "object") {',
|
|
412
|
+
' return result.default || result;',
|
|
413
|
+
' }',
|
|
414
|
+
' return result;',
|
|
415
|
+
'}',
|
|
416
|
+
'export { imports };',
|
|
417
|
+
'export default getImport;'
|
|
418
|
+
].join('\n');
|
|
419
|
+
playgroundVirtualModule.writeModule('_rspress_playground_imports', code);
|
|
420
|
+
},
|
|
421
|
+
builderConfig: {
|
|
422
|
+
source: {
|
|
423
|
+
define: {
|
|
424
|
+
__PLAYGROUND_DIRECTION__: JSON.stringify(defaultDirection),
|
|
425
|
+
__PLAYGROUND_MONACO_LOADER__: JSON.stringify(monacoLoader),
|
|
426
|
+
__PLAYGROUND_MONACO_OPTIONS__: JSON.stringify(monacoOptions),
|
|
427
|
+
__PLAYGROUND_BABEL_URL__: JSON.stringify(babelUrl)
|
|
428
|
+
},
|
|
429
|
+
include: [
|
|
430
|
+
(0, __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__.join)(__dirname, '..', '..', '..')
|
|
431
|
+
]
|
|
432
|
+
},
|
|
433
|
+
html: {
|
|
434
|
+
tags: preloads.map((url)=>({
|
|
435
|
+
tag: 'link',
|
|
436
|
+
head: true,
|
|
437
|
+
attrs: {
|
|
438
|
+
rel: 'preload',
|
|
439
|
+
href: url,
|
|
440
|
+
as: "script"
|
|
441
|
+
}
|
|
442
|
+
}))
|
|
443
|
+
},
|
|
444
|
+
tools: {
|
|
445
|
+
rspack: {
|
|
446
|
+
plugins: [
|
|
447
|
+
playgroundVirtualModule
|
|
448
|
+
]
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
},
|
|
452
|
+
markdown: {
|
|
453
|
+
remarkPlugins: [
|
|
454
|
+
[
|
|
455
|
+
remarkPlugin,
|
|
456
|
+
{
|
|
457
|
+
getRouteMeta,
|
|
458
|
+
editorPosition,
|
|
459
|
+
defaultRenderMode
|
|
460
|
+
}
|
|
461
|
+
]
|
|
462
|
+
],
|
|
463
|
+
globalComponents: [
|
|
464
|
+
render ? render : __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(staticPath, 'global-components', 'Playground.tsx')
|
|
465
|
+
]
|
|
466
|
+
},
|
|
467
|
+
globalStyles: __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(staticPath, 'global-styles', 'web.css')
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
export { pluginPlayground, cli_rslib_entry_routeMeta as routeMeta };
|