@rspress/plugin-playground 1.40.1 → 1.40.3-cannary-20250126

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.
@@ -1,606 +1,494 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __esm = (fn, res) => function __init() {
9
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
- };
11
- var __export = (target, all) => {
12
- for (var name in all)
13
- __defProp(target, name, { get: all[name], enumerable: true });
14
- };
15
- var __copyProps = (to, from, except, desc) => {
16
- if (from && typeof from === "object" || typeof from === "function") {
17
- for (let key of __getOwnPropNames(from))
18
- if (!__hasOwnProp.call(to, key) && key !== except)
19
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
- }
21
- return to;
22
- };
23
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
- // If the importer is in node compatibility mode or this is not an ESM
25
- // file that has been converted to a CommonJS file using a Babel-
26
- // compatible transform (i.e. "__esModule" has not been set), then set
27
- // "default" to the CommonJS "module.exports" for node compatibility.
28
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
- mod
30
- ));
31
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
-
33
- // ../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js
34
- function anyFactory(tests) {
35
- const checks = [];
36
- let index = -1;
37
- while (++index < tests.length) {
38
- checks[index] = convert(tests[index]);
39
- }
40
- return castFactory(any);
41
- function any(...parameters) {
42
- let index2 = -1;
43
- while (++index2 < checks.length) {
44
- if (checks[index2].call(this, ...parameters))
45
- return true;
46
- }
47
- return false;
48
- }
49
- }
50
- function propsFactory(check) {
51
- return castFactory(all);
52
- function all(node) {
53
- let key;
54
- for (key in check) {
55
- if (node[key] !== check[key])
56
- return false;
57
- }
58
- return true;
59
- }
60
- }
61
- function typeFactory(check) {
62
- return castFactory(type);
63
- function type(node) {
64
- return node && node.type === check;
65
- }
66
- }
67
- function castFactory(check) {
68
- return assertion;
69
- function assertion(node, ...parameters) {
70
- return Boolean(
71
- node && typeof node === "object" && "type" in node && // @ts-expect-error: fine.
72
- Boolean(check.call(this, node, ...parameters))
73
- );
74
- }
75
- }
76
- function ok() {
77
- return true;
78
- }
79
- var convert;
80
- var init_lib = __esm({
81
- "../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js"() {
82
- "use strict";
83
- convert = /**
84
- * @type {(
85
- * (<Kind extends Node>(test: PredicateTest<Kind>) => AssertPredicate<Kind>) &
86
- * ((test?: Test) => AssertAnything)
87
- * )}
88
- */
89
- /**
90
- * @param {Test} [test]
91
- * @returns {AssertAnything}
92
- */
93
- function(test) {
94
- if (test === void 0 || test === null) {
95
- return ok;
96
- }
97
- if (typeof test === "string") {
98
- return typeFactory(test);
99
- }
100
- if (typeof test === "object") {
101
- return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
102
- }
103
- if (typeof test === "function") {
104
- return castFactory(test);
105
- }
106
- throw new Error("Expected function, string, or object as test");
107
- };
108
- }
109
- });
110
-
111
- // ../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/index.js
112
- var init_unist_util_is = __esm({
113
- "../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/index.js"() {
114
- "use strict";
115
- init_lib();
116
- }
117
- });
118
-
119
- // ../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/color.js
120
- function color(d) {
121
- return "\x1B[33m" + d + "\x1B[39m";
122
- }
123
- var init_color = __esm({
124
- "../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/color.js"() {
125
- "use strict";
126
- }
127
- });
128
-
129
- // ../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/index.js
130
- function toResult(value) {
131
- if (Array.isArray(value)) {
132
- return value;
133
- }
134
- if (typeof value === "number") {
135
- return [CONTINUE, value];
136
- }
137
- return [value];
138
- }
139
- var CONTINUE, EXIT, SKIP, visitParents;
140
- var init_lib2 = __esm({
141
- "../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/index.js"() {
142
- "use strict";
143
- init_unist_util_is();
144
- init_color();
145
- CONTINUE = true;
146
- EXIT = false;
147
- SKIP = "skip";
148
- visitParents = /**
149
- * @type {(
150
- * (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) &
151
- * (<Tree extends Node>(tree: Tree, visitor: BuildVisitor<Tree>, reverse?: boolean | null | undefined) => void)
152
- * )}
153
- */
154
- /**
155
- * @param {Node} tree
156
- * @param {Test} test
157
- * @param {Visitor<Node>} visitor
158
- * @param {boolean | null | undefined} [reverse]
159
- * @returns {void}
160
- */
161
- function(tree, test, visitor, reverse) {
162
- if (typeof test === "function" && typeof visitor !== "function") {
163
- reverse = visitor;
164
- visitor = test;
165
- test = null;
166
- }
167
- const is2 = convert(test);
168
- const step = reverse ? -1 : 1;
169
- factory(tree, void 0, [])();
170
- function factory(node, index, parents) {
171
- const value = node && typeof node === "object" ? node : {};
172
- if (typeof value.type === "string") {
173
- const name = (
174
- // `hast`
175
- typeof value.tagName === "string" ? value.tagName : (
176
- // `xast`
177
- typeof value.name === "string" ? value.name : void 0
178
- )
179
- );
180
- Object.defineProperty(visit2, "name", {
181
- value: "node (" + color(node.type + (name ? "<" + name + ">" : "")) + ")"
182
- });
2
+ var __webpack_modules__ = {
3
+ "@mdx-js/mdx": function(module) {
4
+ module.exports = import("@mdx-js/mdx");
5
+ },
6
+ "@rspress/shared/fs-extra": function(module) {
7
+ module.exports = import("@rspress/shared/fs-extra");
8
+ },
9
+ "remark-gfm": function(module) {
10
+ module.exports = import("remark-gfm");
11
+ },
12
+ "../../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__) {
13
+ __webpack_require__.d(__webpack_exports__, {
14
+ Vn: ()=>lib_visit
15
+ });
16
+ const convert = function(test) {
17
+ if (null == test) return ok;
18
+ if ('string' == typeof test) return typeFactory(test);
19
+ if ('object' == typeof test) return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
20
+ if ('function' == typeof test) return castFactory(test);
21
+ throw new Error('Expected function, string, or object as test');
22
+ };
23
+ function anyFactory(tests) {
24
+ const checks = [];
25
+ let index = -1;
26
+ while(++index < tests.length)checks[index] = convert(tests[index]);
27
+ return castFactory(any);
28
+ function any(...parameters) {
29
+ let index = -1;
30
+ while(++index < checks.length)if (checks[index].call(this, ...parameters)) return true;
31
+ return false;
32
+ }
183
33
  }
184
- return visit2;
185
- function visit2() {
186
- let result = [];
187
- let subresult;
188
- let offset;
189
- let grandparents;
190
- if (!test || is2(node, index, parents[parents.length - 1] || null)) {
191
- result = toResult(visitor(node, parents));
192
- if (result[0] === EXIT) {
193
- return result;
34
+ function propsFactory(check) {
35
+ return castFactory(all);
36
+ function all(node) {
37
+ let key;
38
+ for(key in check)if (node[key] !== check[key]) return false;
39
+ return true;
194
40
  }
195
- }
196
- if (node.children && result[0] !== SKIP) {
197
- offset = (reverse ? node.children.length : -1) + step;
198
- grandparents = parents.concat(node);
199
- while (offset > -1 && offset < node.children.length) {
200
- subresult = factory(node.children[offset], offset, grandparents)();
201
- if (subresult[0] === EXIT) {
202
- return subresult;
203
- }
204
- offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
41
+ }
42
+ function typeFactory(check) {
43
+ return castFactory(type);
44
+ function type(node) {
45
+ return node && node.type === check;
205
46
  }
206
- }
207
- return result;
208
47
  }
209
- }
210
- };
211
- }
212
- });
213
-
214
- // ../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/index.js
215
- var init_unist_util_visit_parents = __esm({
216
- "../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/index.js"() {
217
- "use strict";
218
- init_lib2();
219
- }
220
- });
221
-
222
- // ../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/lib/index.js
223
- var visit;
224
- var init_lib3 = __esm({
225
- "../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/lib/index.js"() {
226
- "use strict";
227
- init_unist_util_visit_parents();
228
- init_unist_util_visit_parents();
229
- visit = /**
230
- * @type {(
231
- * (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) &
232
- * (<Tree extends Node>(tree: Tree, visitor: BuildVisitor<Tree>, reverse?: boolean | null | undefined) => void)
233
- * )}
234
- */
235
- /**
236
- * @param {Node} tree
237
- * @param {Test} test
238
- * @param {Visitor} visitor
239
- * @param {boolean | null | undefined} [reverse]
240
- * @returns {void}
241
- */
242
- function(tree, test, visitor, reverse) {
243
- if (typeof test === "function" && typeof visitor !== "function") {
244
- reverse = visitor;
245
- visitor = test;
246
- test = null;
247
- }
248
- visitParents(tree, test, overload, reverse);
249
- function overload(node, parents) {
250
- const parent = parents[parents.length - 1];
251
- return visitor(
252
- node,
253
- parent ? parent.children.indexOf(node) : null,
254
- parent
255
- );
256
- }
257
- };
258
- }
259
- });
260
-
261
- // ../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/index.js
262
- var unist_util_visit_exports = {};
263
- __export(unist_util_visit_exports, {
264
- CONTINUE: () => CONTINUE,
265
- EXIT: () => EXIT,
266
- SKIP: () => SKIP,
267
- visit: () => visit
268
- });
269
- var init_unist_util_visit = __esm({
270
- "../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/index.js"() {
271
- "use strict";
272
- init_lib3();
273
- }
274
- });
275
-
276
- // src/cli/index.ts
277
- var cli_exports = {};
278
- __export(cli_exports, {
279
- pluginPlayground: () => pluginPlayground,
280
- routeMeta: () => routeMeta
281
- });
282
- module.exports = __toCommonJS(cli_exports);
283
- var import_node_path3 = __toESM(require("path"));
284
-
285
- // src/web/constant.ts
286
- var DEFAULT_BABEL_URL = "https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js";
287
- var DEFAULT_MONACO_URL = "https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs";
288
-
289
- // src/web/utils.ts
290
- function normalizeUrl(u) {
291
- return u.replace(/\/\//g, "/");
292
- }
293
-
294
- // src/cli/index.ts
295
- var import_rspack_plugin_virtual_module = require("rspack-plugin-virtual-module");
296
-
297
- // src/cli/constant.ts
298
- var import_node_path = __toESM(require("path"));
299
- var staticPath = import_node_path.default.join(__dirname, "../../../static");
300
-
301
- // src/cli/remarkPlugin.ts
302
- var import_node_path2 = require("path");
303
- var import_fs_extra = __toESM(require("@rspress/shared/fs-extra"));
304
- init_unist_util_visit();
305
-
306
- // src/cli/utils.ts
307
- var import_napi = __toESM(require("@oxidation-compiler/napi"));
308
- var parseImports = (code, sourceExt) => {
309
- const parsed = import_napi.default.parseSync(code, {
310
- sourceType: "module",
311
- sourceFilename: `index.${sourceExt}`
312
- });
313
- const ast = JSON.parse(parsed.program);
314
- const result = [];
315
- ast.body.forEach((statement) => {
316
- if (statement.type === "ImportDeclaration") {
317
- result.push(statement.source.value);
318
- }
319
- });
320
- return result;
321
- };
322
- var getNodeAttribute = (node, attrName) => {
323
- return node.attributes.find(
324
- (attr) => attr.name === attrName
325
- )?.value;
326
- };
327
- var getNodeMeta = (node, metaName) => {
328
- if (!node.meta) {
329
- return;
330
- }
331
- const meta = node.meta.split(" ");
332
- const item = meta.find(
333
- (x) => x.startsWith(metaName)
334
- );
335
- if (item?.startsWith(`${metaName}=`)) {
336
- return item.substring(metaName.length + 1);
337
- }
338
- return item;
339
- };
340
-
341
- // src/cli/remarkPlugin.ts
342
- function createPlaygroundNode(currentNode, attrs) {
343
- Object.assign(currentNode, {
344
- type: "mdxJsxFlowElement",
345
- name: "Playground",
346
- attributes: attrs.map((it) => ({
347
- type: "mdxJsxAttribute",
348
- name: it[0],
349
- value: it[1]
350
- }))
351
- });
352
- }
353
- var remarkPlugin = ({
354
- getRouteMeta,
355
- editorPosition,
356
- defaultRenderMode
357
- }) => {
358
- const routeMeta2 = getRouteMeta();
359
- return (tree, vfile) => {
360
- const route = routeMeta2.find(
361
- (meta) => (0, import_node_path2.resolve)(meta.absolutePath) === (0, import_node_path2.resolve)(vfile.path || vfile.history[0])
362
- );
363
- if (!route) {
364
- return;
365
- }
366
- visit(tree, "mdxJsxFlowElement", (node) => {
367
- if (node.name === "code") {
368
- const src = getNodeAttribute(node, "src");
369
- if (!src) {
370
- return;
48
+ function castFactory(check) {
49
+ return assertion;
50
+ function assertion(node, ...parameters) {
51
+ return Boolean(node && 'object' == typeof node && 'type' in node && Boolean(check.call(this, node, ...parameters)));
52
+ }
371
53
  }
372
- const demoPath = (0, import_node_path2.join)((0, import_node_path2.dirname)(route.absolutePath), src);
373
- if (!import_fs_extra.default.existsSync(demoPath)) {
374
- return;
54
+ function ok() {
55
+ return true;
375
56
  }
376
- const direction = getNodeAttribute(node, "direction") || "";
377
- const code = import_fs_extra.default.readFileSync(demoPath, {
378
- encoding: "utf8"
379
- });
380
- const language = src.substr(src.lastIndexOf(".") + 1);
381
- createPlaygroundNode(node, [
382
- ["code", code],
383
- ["language", language],
384
- ["direction", direction],
385
- ["editorPosition", editorPosition]
386
- ]);
387
- }
388
- });
389
- visit(tree, "code", (node) => {
390
- if (node.lang === "jsx" || node.lang === "tsx") {
391
- const hasPureMeta = node?.meta?.includes("pure");
392
- const hasPlaygroundMeta = node?.meta?.includes("playground");
393
- let noTransform;
394
- switch (defaultRenderMode) {
395
- case "pure":
396
- noTransform = !hasPlaygroundMeta;
397
- break;
398
- case "playground":
399
- noTransform = hasPureMeta;
400
- break;
401
- default:
402
- break;
57
+ function color(d) {
58
+ return '\u001B[33m' + d + '\u001B[39m';
403
59
  }
404
- if (noTransform) {
405
- return;
60
+ const CONTINUE = true;
61
+ const EXIT = false;
62
+ const SKIP = 'skip';
63
+ const visitParents = function(tree, test, visitor, reverse) {
64
+ if ('function' == typeof test && 'function' != typeof visitor) {
65
+ reverse = visitor;
66
+ visitor = test;
67
+ test = null;
68
+ }
69
+ const is = convert(test);
70
+ const step = reverse ? -1 : 1;
71
+ factory(tree, void 0, [])();
72
+ function factory(node, index, parents) {
73
+ const value = node && 'object' == typeof node ? node : {};
74
+ if ('string' == typeof value.type) {
75
+ const name = 'string' == typeof value.tagName ? value.tagName : 'string' == typeof value.name ? value.name : void 0;
76
+ Object.defineProperty(visit, 'name', {
77
+ value: 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'
78
+ });
79
+ }
80
+ return visit;
81
+ function visit() {
82
+ let result = [];
83
+ let subresult;
84
+ let offset;
85
+ let grandparents;
86
+ if (!test || is(node, index, parents[parents.length - 1] || null)) {
87
+ result = toResult(visitor(node, parents));
88
+ if (result[0] === EXIT) return result;
89
+ }
90
+ if (node.children && result[0] !== SKIP) {
91
+ offset = (reverse ? node.children.length : -1) + step;
92
+ grandparents = parents.concat(node);
93
+ while(offset > -1 && offset < node.children.length){
94
+ subresult = factory(node.children[offset], offset, grandparents)();
95
+ if (subresult[0] === EXIT) return subresult;
96
+ offset = 'number' == typeof subresult[1] ? subresult[1] : offset + step;
97
+ }
98
+ }
99
+ return result;
100
+ }
101
+ }
102
+ };
103
+ function toResult(value) {
104
+ if (Array.isArray(value)) return value;
105
+ if ('number' == typeof value) return [
106
+ CONTINUE,
107
+ value
108
+ ];
109
+ return [
110
+ value
111
+ ];
406
112
  }
407
- const direction = getNodeMeta(node, "direction") || "";
408
- createPlaygroundNode(node, [
409
- ["code", node.value],
410
- ["language", node.lang],
411
- ["direction", direction],
412
- ["editorPosition", editorPosition]
413
- ]);
414
- }
415
- });
416
- };
113
+ const lib_visit = function(tree, test, visitor, reverse) {
114
+ if ('function' == typeof test && 'function' != typeof visitor) {
115
+ reverse = visitor;
116
+ visitor = test;
117
+ test = null;
118
+ }
119
+ visitParents(tree, test, overload, reverse);
120
+ function overload(node, parents) {
121
+ const parent = parents[parents.length - 1];
122
+ return visitor(node, parent ? parent.children.indexOf(node) : null, parent);
123
+ }
124
+ };
125
+ }
417
126
  };
418
-
419
- // src/cli/index.ts
420
- var routeMeta;
421
- function pluginPlayground(options) {
422
- const {
423
- render = "",
424
- include,
425
- defaultDirection = "horizontal",
426
- editorPosition = "left",
427
- babelUrl = DEFAULT_BABEL_URL,
428
- monacoLoader = {},
429
- monacoOptions = {},
430
- defaultRenderMode = "playground"
431
- } = options || {};
432
- const playgroundVirtualModule = new import_rspack_plugin_virtual_module.RspackVirtualModulePlugin({});
433
- const getRouteMeta = () => routeMeta;
434
- if (render && !/Playground\.(jsx?|tsx?)$/.test(render)) {
435
- throw new Error(
436
- "[Playground]: render should ends with Playground.(jsx?|tsx?)"
437
- );
438
- }
439
- const preloads = [];
440
- const monacoPrefix = monacoLoader.paths?.vs || DEFAULT_MONACO_URL;
441
- preloads.push(normalizeUrl(`${monacoPrefix}/loader.js`));
442
- preloads.push(normalizeUrl(`${monacoPrefix}/editor/editor.main.js`));
443
- return {
444
- name: "@rspress/plugin-playground",
445
- config(config, { removePlugin }) {
446
- config.markdown = config.markdown || {};
447
- config.markdown.mdxRs = false;
448
- removePlugin("@rspress/plugin-preview");
449
- return config;
450
- },
451
- async routeGenerated(routes) {
452
- const { default: fs2 } = await import("@rspress/shared/fs-extra");
453
- routeMeta = routes;
454
- const files = routes.map((route) => route.absolutePath);
455
- const imports = {};
456
- await Promise.all(
457
- files.map(async (filepath, _index) => {
458
- const isMdxFile = /\.mdx?$/.test(filepath);
459
- if (!isMdxFile) {
460
- return;
461
- }
462
- const { createProcessor } = await import("@mdx-js/mdx");
463
- const { visit: visit2 } = await Promise.resolve().then(() => (init_unist_util_visit(), unist_util_visit_exports));
464
- const { default: remarkGFM } = await import("remark-gfm");
465
- try {
466
- const processor = createProcessor({
467
- format: import_node_path3.default.extname(filepath).slice(1),
468
- remarkPlugins: [remarkGFM]
469
- });
470
- const source = await fs2.readFile(filepath, "utf-8");
471
- const ast = processor.parse(source);
472
- visit2(ast, "mdxJsxFlowElement", (node) => {
473
- if (node.name === "code") {
474
- const src = getNodeAttribute(node, "src");
475
- if (!src) {
476
- return;
477
- }
478
- const demoPath = (0, import_node_path3.join)(import_node_path3.default.dirname(filepath), src);
479
- if (!fs2.existsSync(demoPath)) {
480
- return;
127
+ var __webpack_module_cache__ = {};
128
+ function __webpack_require__(moduleId) {
129
+ var cachedModule = __webpack_module_cache__[moduleId];
130
+ if (void 0 !== cachedModule) return cachedModule.exports;
131
+ var module = __webpack_module_cache__[moduleId] = {
132
+ exports: {}
133
+ };
134
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
135
+ return module.exports;
136
+ }
137
+ __webpack_require__.m = __webpack_modules__;
138
+ (()=>{
139
+ __webpack_require__.n = function(module) {
140
+ var getter = module && module.__esModule ? function() {
141
+ return module['default'];
142
+ } : function() {
143
+ return module;
144
+ };
145
+ __webpack_require__.d(getter, {
146
+ a: getter
147
+ });
148
+ return getter;
149
+ };
150
+ })();
151
+ (()=>{
152
+ __webpack_require__.d = function(exports1, definition) {
153
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
154
+ enumerable: true,
155
+ get: definition[key]
156
+ });
157
+ };
158
+ })();
159
+ (()=>{
160
+ __webpack_require__.f = {};
161
+ __webpack_require__.e = function(chunkId) {
162
+ return Promise.all(Object.keys(__webpack_require__.f).reduce(function(promises, key) {
163
+ __webpack_require__.f[key](chunkId, promises);
164
+ return promises;
165
+ }, []));
166
+ };
167
+ })();
168
+ (()=>{
169
+ __webpack_require__.u = function(chunkId) {
170
+ return "" + chunkId + ".js";
171
+ };
172
+ })();
173
+ (()=>{
174
+ __webpack_require__.o = function(obj, prop) {
175
+ return Object.prototype.hasOwnProperty.call(obj, prop);
176
+ };
177
+ })();
178
+ (()=>{
179
+ __webpack_require__.r = function(exports1) {
180
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
181
+ value: 'Module'
182
+ });
183
+ Object.defineProperty(exports1, '__esModule', {
184
+ value: true
185
+ });
186
+ };
187
+ })();
188
+ (()=>{
189
+ var installedChunks = {
190
+ 980: 1
191
+ };
192
+ var installChunk = function(chunk) {
193
+ var moreModules = chunk.modules, chunkIds = chunk.ids, runtime = chunk.runtime;
194
+ for(var moduleId in moreModules)if (__webpack_require__.o(moreModules, moduleId)) __webpack_require__.m[moduleId] = moreModules[moduleId];
195
+ if (runtime) runtime(__webpack_require__);
196
+ for(var i = 0; i < chunkIds.length; i++)installedChunks[chunkIds[i]] = 1;
197
+ };
198
+ __webpack_require__.f.require = function(chunkId, promises) {
199
+ if (!installedChunks[chunkId]) installChunk(require("./" + __webpack_require__.u(chunkId)));
200
+ };
201
+ })();
202
+ var __webpack_exports__ = {};
203
+ (()=>{
204
+ __webpack_require__.r(__webpack_exports__);
205
+ __webpack_require__.d(__webpack_exports__, {
206
+ pluginPlayground: ()=>pluginPlayground,
207
+ routeMeta: ()=>cli_rslib_entry_routeMeta
208
+ });
209
+ const external_node_path_namespaceObject = require("node:path");
210
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
211
+ const DEFAULT_BABEL_URL = 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js';
212
+ const DEFAULT_MONACO_URL = 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';
213
+ function normalizeUrl(u) {
214
+ return u.replace(/\/\//g, '/');
215
+ }
216
+ const external_rspack_plugin_virtual_module_namespaceObject = require("rspack-plugin-virtual-module");
217
+ const staticPath = external_node_path_default().join(__dirname, '../../../static');
218
+ const fs_extra_namespaceObject = require("@rspress/shared/fs-extra");
219
+ var fs_extra_default = /*#__PURE__*/ __webpack_require__.n(fs_extra_namespaceObject);
220
+ var lib = __webpack_require__("../../node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/lib/index.js");
221
+ const napi_namespaceObject = require("@oxidation-compiler/napi");
222
+ var napi_default = /*#__PURE__*/ __webpack_require__.n(napi_namespaceObject);
223
+ const parseImports = (code, sourceExt)=>{
224
+ const parsed = napi_default().parseSync(code, {
225
+ sourceType: 'module',
226
+ sourceFilename: `index.${sourceExt}`
227
+ });
228
+ const ast = JSON.parse(parsed.program);
229
+ const result = [];
230
+ ast.body.forEach((statement)=>{
231
+ if ('ImportDeclaration' === statement.type) result.push(statement.source.value);
232
+ });
233
+ return result;
234
+ };
235
+ const getNodeAttribute = (node, attrName)=>{
236
+ var _node_attributes_find;
237
+ return null === (_node_attributes_find = node.attributes.find((attr)=>attr.name === attrName)) || void 0 === _node_attributes_find ? void 0 : _node_attributes_find.value;
238
+ };
239
+ const getNodeMeta = (node, metaName)=>{
240
+ if (!node.meta) return;
241
+ const meta = node.meta.split(' ');
242
+ const item = meta.find((x)=>x.startsWith(metaName));
243
+ if (null == item ? void 0 : item.startsWith(`${metaName}=`)) return item.substring(metaName.length + 1);
244
+ return item;
245
+ };
246
+ function createPlaygroundNode(currentNode, attrs) {
247
+ Object.assign(currentNode, {
248
+ type: 'mdxJsxFlowElement',
249
+ name: 'Playground',
250
+ attributes: attrs.map((it)=>({
251
+ type: 'mdxJsxAttribute',
252
+ name: it[0],
253
+ value: it[1]
254
+ }))
255
+ });
256
+ }
257
+ const remarkPlugin = ({ getRouteMeta, editorPosition, defaultRenderMode })=>{
258
+ const routeMeta = getRouteMeta();
259
+ return (tree, vfile)=>{
260
+ const route = routeMeta.find((meta)=>(0, external_node_path_namespaceObject.resolve)(meta.absolutePath) === (0, external_node_path_namespaceObject.resolve)(vfile.path || vfile.history[0]));
261
+ if (!route) return;
262
+ (0, lib.Vn)(tree, 'mdxJsxFlowElement', (node)=>{
263
+ if ('code' === node.name) {
264
+ const src = getNodeAttribute(node, 'src');
265
+ if (!src) return;
266
+ const demoPath = (0, external_node_path_namespaceObject.join)((0, external_node_path_namespaceObject.dirname)(route.absolutePath), src);
267
+ if (!fs_extra_default().existsSync(demoPath)) return;
268
+ const direction = getNodeAttribute(node, 'direction') || '';
269
+ const code = fs_extra_default().readFileSync(demoPath, {
270
+ encoding: 'utf8'
271
+ });
272
+ const language = src.substr(src.lastIndexOf('.') + 1);
273
+ createPlaygroundNode(node, [
274
+ [
275
+ 'code',
276
+ code
277
+ ],
278
+ [
279
+ 'language',
280
+ language
281
+ ],
282
+ [
283
+ 'direction',
284
+ direction
285
+ ],
286
+ [
287
+ 'editorPosition',
288
+ editorPosition
289
+ ]
290
+ ]);
481
291
  }
482
- const code2 = fs2.readFileSync(demoPath, {
483
- encoding: "utf8"
484
- });
485
- const thisImports = parseImports(code2, import_node_path3.default.extname(demoPath));
486
- thisImports.forEach((x) => {
487
- if (typeof imports[x] === "undefined") {
488
- imports[x] = x;
489
- }
490
- });
491
- }
492
292
  });
493
- visit2(ast, "code", (node) => {
494
- if (node.lang === "jsx" || node.lang === "tsx") {
495
- const { value, meta } = node;
496
- const hasPureMeta = meta?.includes("pure");
497
- const hasPlaygroundMeta = meta?.includes("playground");
498
- let noTransform;
499
- switch (defaultRenderMode) {
500
- case "pure":
501
- noTransform = !hasPlaygroundMeta;
502
- break;
503
- case "playground":
504
- noTransform = hasPureMeta;
505
- break;
506
- default:
507
- break;
508
- }
509
- if (noTransform) {
510
- return;
293
+ (0, lib.Vn)(tree, 'code', (node)=>{
294
+ if ('jsx' === node.lang || 'tsx' === node.lang) {
295
+ var _node_meta, _node_meta1;
296
+ const hasPureMeta = null == node ? void 0 : null === (_node_meta = node.meta) || void 0 === _node_meta ? void 0 : _node_meta.includes('pure');
297
+ const hasPlaygroundMeta = null == node ? void 0 : null === (_node_meta1 = node.meta) || void 0 === _node_meta1 ? void 0 : _node_meta1.includes('playground');
298
+ let noTransform;
299
+ switch(defaultRenderMode){
300
+ case 'pure':
301
+ noTransform = !hasPlaygroundMeta;
302
+ break;
303
+ case 'playground':
304
+ noTransform = hasPureMeta;
305
+ break;
306
+ default:
307
+ break;
308
+ }
309
+ if (noTransform) return;
310
+ const direction = getNodeMeta(node, 'direction') || '';
311
+ createPlaygroundNode(node, [
312
+ [
313
+ 'code',
314
+ node.value
315
+ ],
316
+ [
317
+ 'language',
318
+ node.lang
319
+ ],
320
+ [
321
+ 'direction',
322
+ direction
323
+ ],
324
+ [
325
+ 'editorPosition',
326
+ editorPosition
327
+ ]
328
+ ]);
511
329
  }
512
- const thisImports = parseImports(value, node.lang);
513
- thisImports.forEach((x) => {
514
- if (typeof imports[x] === "undefined") {
515
- imports[x] = x;
516
- }
517
- });
518
- }
519
330
  });
520
- } catch (e) {
521
- console.error(e);
522
- throw e;
523
- }
524
- })
525
- );
526
- if (include) {
527
- include.forEach((item) => {
528
- if (typeof item === "string") {
529
- imports[item] = item;
530
- } else {
531
- imports[item[0]] = item[1];
532
- }
533
- });
534
- }
535
- if (!("react" in imports)) {
536
- imports.react = "react";
537
- }
538
- const importKeys = Object.keys(imports);
539
- const code = [
540
- ...importKeys.map(
541
- (x, index) => `import * as i_${index} from '${imports[x]}';`
542
- ),
543
- "const imports = new Map();",
544
- ...importKeys.map((x, index) => `imports.set('${x}', i_${index});`),
545
- "function getImport(name, getDefault) {",
546
- " if (!imports.has(name)) {",
547
- ' throw new Error("Module " + name + " not found");',
548
- " }",
549
- " const result = imports.get(name);",
550
- ' if (getDefault && typeof result === "object") {',
551
- " return result.default || result;",
552
- " }",
553
- " return result;",
554
- "}",
555
- "export { imports };",
556
- "export default getImport;"
557
- ].join("\n");
558
- playgroundVirtualModule.writeModule("_rspress_playground_imports", code);
559
- },
560
- builderConfig: {
561
- source: {
562
- define: {
563
- __PLAYGROUND_DIRECTION__: JSON.stringify(defaultDirection),
564
- __PLAYGROUND_MONACO_LOADER__: JSON.stringify(monacoLoader),
565
- __PLAYGROUND_MONACO_OPTIONS__: JSON.stringify(monacoOptions),
566
- __PLAYGROUND_BABEL_URL__: JSON.stringify(babelUrl)
567
- },
568
- include: [(0, import_node_path3.join)(__dirname, "..", "..", "..")]
569
- },
570
- html: {
571
- tags: preloads.map((url) => ({
572
- tag: "link",
573
- head: true,
574
- attrs: {
575
- rel: "preload",
576
- href: url,
577
- as: "script"
578
- }
579
- }))
580
- },
581
- tools: {
582
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
583
- // @ts-ignore
584
- rspack: {
585
- plugins: [playgroundVirtualModule]
586
- }
587
- }
588
- },
589
- markdown: {
590
- remarkPlugins: [
591
- [remarkPlugin, { getRouteMeta, editorPosition, defaultRenderMode }]
592
- ],
593
- globalComponents: [
594
- render ? render : import_node_path3.default.join(staticPath, "global-components", "Playground.tsx")
595
- ]
596
- },
597
- globalStyles: import_node_path3.default.join(staticPath, "global-styles", "web.css")
598
- };
599
- }
600
- // Annotate the CommonJS export names for ESM import in node:
601
- 0 && (module.exports = {
602
- pluginPlayground,
603
- routeMeta
331
+ };
332
+ };
333
+ let cli_rslib_entry_routeMeta;
334
+ function pluginPlayground(options) {
335
+ var _monacoLoader_paths;
336
+ const { render = '', include, defaultDirection = 'horizontal', editorPosition = 'left', babelUrl = DEFAULT_BABEL_URL, monacoLoader = {}, monacoOptions = {}, defaultRenderMode = 'playground' } = options || {};
337
+ const playgroundVirtualModule = new external_rspack_plugin_virtual_module_namespaceObject.RspackVirtualModulePlugin({});
338
+ const getRouteMeta = ()=>cli_rslib_entry_routeMeta;
339
+ if (render && !/Playground\.(jsx?|tsx?)$/.test(render)) throw new Error('[Playground]: render should ends with Playground.(jsx?|tsx?)');
340
+ const preloads = [];
341
+ const monacoPrefix = (null === (_monacoLoader_paths = monacoLoader.paths) || void 0 === _monacoLoader_paths ? void 0 : _monacoLoader_paths.vs) || DEFAULT_MONACO_URL;
342
+ preloads.push(normalizeUrl(`${monacoPrefix}/loader.js`));
343
+ preloads.push(normalizeUrl(`${monacoPrefix}/editor/editor.main.js`));
344
+ return {
345
+ name: '@rspress/plugin-playground',
346
+ config (config, { removePlugin }) {
347
+ config.markdown = config.markdown || {};
348
+ config.markdown.mdxRs = false;
349
+ removePlugin('@rspress/plugin-preview');
350
+ return config;
351
+ },
352
+ async routeGenerated (routes) {
353
+ const { default: fs } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rspress/shared/fs-extra"));
354
+ cli_rslib_entry_routeMeta = routes;
355
+ const files = routes.map((route)=>route.absolutePath);
356
+ const imports = {};
357
+ await Promise.all(files.map(async (filepath, _index)=>{
358
+ const isMdxFile = /\.mdx?$/.test(filepath);
359
+ if (!isMdxFile) return;
360
+ const { createProcessor } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@mdx-js/mdx"));
361
+ 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"));
362
+ const { default: remarkGFM } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "remark-gfm"));
363
+ try {
364
+ const processor = createProcessor({
365
+ format: external_node_path_default().extname(filepath).slice(1),
366
+ remarkPlugins: [
367
+ remarkGFM
368
+ ]
369
+ });
370
+ const source = await fs.readFile(filepath, 'utf-8');
371
+ const ast = processor.parse(source);
372
+ visit(ast, 'mdxJsxFlowElement', (node)=>{
373
+ if ('code' === node.name) {
374
+ const src = getNodeAttribute(node, 'src');
375
+ if (!src) return;
376
+ const demoPath = (0, external_node_path_namespaceObject.join)(external_node_path_default().dirname(filepath), src);
377
+ if (!fs.existsSync(demoPath)) return;
378
+ const code = fs.readFileSync(demoPath, {
379
+ encoding: 'utf8'
380
+ });
381
+ const thisImports = parseImports(code, external_node_path_default().extname(demoPath));
382
+ thisImports.forEach((x)=>{
383
+ if (void 0 === imports[x]) imports[x] = x;
384
+ });
385
+ }
386
+ });
387
+ visit(ast, 'code', (node)=>{
388
+ if ('jsx' === node.lang || 'tsx' === node.lang) {
389
+ const { value, meta } = node;
390
+ const hasPureMeta = null == meta ? void 0 : meta.includes('pure');
391
+ const hasPlaygroundMeta = null == meta ? void 0 : meta.includes('playground');
392
+ let noTransform;
393
+ switch(defaultRenderMode){
394
+ case 'pure':
395
+ noTransform = !hasPlaygroundMeta;
396
+ break;
397
+ case 'playground':
398
+ noTransform = hasPureMeta;
399
+ break;
400
+ default:
401
+ break;
402
+ }
403
+ if (noTransform) return;
404
+ const thisImports = parseImports(value, node.lang);
405
+ thisImports.forEach((x)=>{
406
+ if (void 0 === imports[x]) imports[x] = x;
407
+ });
408
+ }
409
+ });
410
+ } catch (e) {
411
+ console.error(e);
412
+ throw e;
413
+ }
414
+ }));
415
+ if (include) include.forEach((item)=>{
416
+ if ('string' == typeof item) imports[item] = item;
417
+ else imports[item[0]] = item[1];
418
+ });
419
+ if (!('react' in imports)) imports.react = 'react';
420
+ const importKeys = Object.keys(imports);
421
+ const code = [
422
+ ...importKeys.map((x, index)=>`import * as i_${index} from '${imports[x]}';`),
423
+ 'const imports = new Map();',
424
+ ...importKeys.map((x, index)=>`imports.set('${x}', i_${index});`),
425
+ 'function getImport(name, getDefault) {',
426
+ ' if (!imports.has(name)) {',
427
+ ' throw new Error("Module " + name + " not found");',
428
+ ' }',
429
+ ' const result = imports.get(name);',
430
+ ' if (getDefault && typeof result === "object") {',
431
+ ' return result.default || result;',
432
+ ' }',
433
+ ' return result;',
434
+ '}',
435
+ 'export { imports };',
436
+ 'export default getImport;'
437
+ ].join('\n');
438
+ playgroundVirtualModule.writeModule('_rspress_playground_imports', code);
439
+ },
440
+ builderConfig: {
441
+ source: {
442
+ define: {
443
+ __PLAYGROUND_DIRECTION__: JSON.stringify(defaultDirection),
444
+ __PLAYGROUND_MONACO_LOADER__: JSON.stringify(monacoLoader),
445
+ __PLAYGROUND_MONACO_OPTIONS__: JSON.stringify(monacoOptions),
446
+ __PLAYGROUND_BABEL_URL__: JSON.stringify(babelUrl)
447
+ },
448
+ include: [
449
+ (0, external_node_path_namespaceObject.join)(__dirname, '..', '..', '..')
450
+ ]
451
+ },
452
+ html: {
453
+ tags: preloads.map((url)=>({
454
+ tag: 'link',
455
+ head: true,
456
+ attrs: {
457
+ rel: 'preload',
458
+ href: url,
459
+ as: "script"
460
+ }
461
+ }))
462
+ },
463
+ tools: {
464
+ rspack: {
465
+ plugins: [
466
+ playgroundVirtualModule
467
+ ]
468
+ }
469
+ }
470
+ },
471
+ markdown: {
472
+ remarkPlugins: [
473
+ [
474
+ remarkPlugin,
475
+ {
476
+ getRouteMeta,
477
+ editorPosition,
478
+ defaultRenderMode
479
+ }
480
+ ]
481
+ ],
482
+ globalComponents: [
483
+ render ? render : external_node_path_default().join(staticPath, 'global-components', 'Playground.tsx')
484
+ ]
485
+ },
486
+ globalStyles: external_node_path_default().join(staticPath, 'global-styles', 'web.css')
487
+ };
488
+ }
489
+ })();
490
+ var __webpack_export_target__ = exports;
491
+ for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
492
+ if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
493
+ value: true
604
494
  });
605
-
606
- //# sourceMappingURL=index.js.map