@rspress/plugin-preview 0.0.0-canary-20250521

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/index.js ADDED
@@ -0,0 +1,626 @@
1
+ "use strict";
2
+ var __webpack_modules__ = {
3
+ "@rsbuild/plugin-less": function(module) {
4
+ module.exports = import("@rsbuild/plugin-less").then(function(module) {
5
+ return module;
6
+ });
7
+ },
8
+ "@rsbuild/plugin-sass": function(module) {
9
+ module.exports = import("@rsbuild/plugin-sass").then(function(module) {
10
+ return module;
11
+ });
12
+ }
13
+ };
14
+ var __webpack_module_cache__ = {};
15
+ function __webpack_require__(moduleId) {
16
+ var cachedModule = __webpack_module_cache__[moduleId];
17
+ if (void 0 !== cachedModule) return cachedModule.exports;
18
+ var module = __webpack_module_cache__[moduleId] = {
19
+ exports: {}
20
+ };
21
+ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
22
+ return module.exports;
23
+ }
24
+ (()=>{
25
+ __webpack_require__.n = (module)=>{
26
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
27
+ __webpack_require__.d(getter, {
28
+ a: getter
29
+ });
30
+ return getter;
31
+ };
32
+ })();
33
+ (()=>{
34
+ __webpack_require__.d = (exports1, definition)=>{
35
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
36
+ enumerable: true,
37
+ get: definition[key]
38
+ });
39
+ };
40
+ })();
41
+ (()=>{
42
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
43
+ })();
44
+ (()=>{
45
+ __webpack_require__.r = (exports1)=>{
46
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
47
+ value: 'Module'
48
+ });
49
+ Object.defineProperty(exports1, '__esModule', {
50
+ value: true
51
+ });
52
+ };
53
+ })();
54
+ var __webpack_exports__ = {};
55
+ (()=>{
56
+ __webpack_require__.r(__webpack_exports__);
57
+ __webpack_require__.d(__webpack_exports__, {
58
+ pluginPreview: ()=>pluginPreview
59
+ });
60
+ const external_node_net_namespaceObject = require("node:net");
61
+ var external_node_net_default = /*#__PURE__*/ __webpack_require__.n(external_node_net_namespaceObject);
62
+ const external_node_path_namespaceObject = require("node:path");
63
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
64
+ const core_namespaceObject = require("@rsbuild/core");
65
+ const plugin_babel_namespaceObject = require("@rsbuild/plugin-babel");
66
+ const plugin_react_namespaceObject = require("@rsbuild/plugin-react");
67
+ const plugin_solid_namespaceObject = require("@rsbuild/plugin-solid");
68
+ const shared_namespaceObject = require("@rspress/shared");
69
+ const external_lodash_namespaceObject = require("lodash");
70
+ const staticPath = external_node_path_default().join(__dirname, '..', 'static');
71
+ const demoBlockComponentPath = external_node_path_default().join(staticPath, 'global-components', 'DemoBlock.tsx');
72
+ const virtualDir = external_node_path_default().join(process.cwd(), 'node_modules', shared_namespaceObject.RSPRESS_TEMP_DIR, 'virtual-demo');
73
+ const external_node_fs_namespaceObject = require("node:fs");
74
+ var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
75
+ const toValidVarName = (str)=>{
76
+ if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) return str;
77
+ return str.replace(/[^0-9a-zA-Z_$]/g, '_').replace(/^([0-9])/, '_$1');
78
+ };
79
+ const generateId = (pageName, index)=>`_${toValidVarName(pageName)}_${index}`;
80
+ const injectDemoBlockImport = (str, path)=>`
81
+ import DemoBlock from ${JSON.stringify(path)};
82
+ ${str}
83
+ `;
84
+ function generateEntryForPerComponent(demos, entryCssPath, framework) {
85
+ const sourceEntry = {};
86
+ Object.values(demos).forEach((routes)=>{
87
+ routes.forEach((route)=>{
88
+ const { id, path: demoPath } = route;
89
+ const entry = (0, external_node_path_namespaceObject.join)(virtualDir, `${id}.entry.tsx`);
90
+ const solidEntry = `
91
+ import { render } from 'solid-js/web';
92
+ import ${JSON.stringify(entryCssPath)};
93
+ import Demo from ${JSON.stringify(demoPath)};
94
+ render(() => <Demo />, document.getElementById('root'));
95
+ `;
96
+ const reactEntry = `
97
+ import { render } from 'react-dom';
98
+ import ${JSON.stringify(entryCssPath)};
99
+ import Demo from ${JSON.stringify(demoPath)};
100
+ render(<Demo />, document.getElementById('root'));
101
+ `;
102
+ const entryContent = 'react' === framework ? reactEntry : solidEntry;
103
+ (0, external_node_fs_namespaceObject.writeFileSync)(entry, entryContent);
104
+ sourceEntry[id] = entry;
105
+ });
106
+ });
107
+ return sourceEntry;
108
+ }
109
+ function generateEntryForPage(demos, entryCssPath, framework) {
110
+ const sourceEntry = {};
111
+ Object.entries(demos).forEach(([key, routes])=>{
112
+ if (0 === routes.length) return;
113
+ const reactContent = `
114
+ import { render } from 'react-dom';
115
+ import ${JSON.stringify(entryCssPath)};
116
+ ${routes.map((demo, index)=>`import Demo_${index} from ${JSON.stringify(demo.path)}`).join('\n')}
117
+ function App() {
118
+ return (
119
+ <div className="preview-container">
120
+ <div className="preview-nav">{"${routes[0].title}"}</div>
121
+ ${routes.map((_demo, index)=>`<Demo_${index} />`).join('\n')}
122
+ </div>
123
+ )
124
+ }
125
+ render(<App /> , document.getElementById('root'));
126
+ `;
127
+ const solidContent = `
128
+ import { render } from 'solid-js/web';
129
+ import ${JSON.stringify(entryCssPath)};
130
+ ${routes.map((demo, index)=>`import Demo_${index} from ${JSON.stringify(demo.path)}`).join('\n')}
131
+ function App() {
132
+ return (
133
+ <div class="preview-container">
134
+ <div class="preview-nav">{"${routes[0].title}"}</div>
135
+ ${routes.map((_, index)=>`<Demo_${index} />`).join('\n')}
136
+ </div>
137
+ )
138
+ }
139
+ render(() => <App /> , document.getElementById('root'));
140
+ `;
141
+ const renderContent = 'solid' === framework ? solidContent : reactContent;
142
+ const id = `_${toValidVarName(key)}`;
143
+ const entry = (0, external_node_path_namespaceObject.join)(virtualDir, `${id}.entry.tsx`);
144
+ (0, external_node_fs_namespaceObject.writeFileSync)(entry, renderContent);
145
+ sourceEntry[id] = entry;
146
+ });
147
+ return sourceEntry;
148
+ }
149
+ function generateEntry(demos, framework, position) {
150
+ const sourceEntry = {};
151
+ const entryCssPath = (0, external_node_path_namespaceObject.join)(staticPath, 'global-styles', 'entry.css');
152
+ if ('follow' === position) {
153
+ const entries = generateEntryForPerComponent(demos, entryCssPath, framework);
154
+ Object.assign(sourceEntry, entries);
155
+ } else if ('fixed' === position) {
156
+ const entries = generateEntryForPage(demos, entryCssPath, framework);
157
+ Object.assign(sourceEntry, entries);
158
+ } else if ('fixed-with-per-comp' === position) {
159
+ const entries = generateEntryForPerComponent(demos, entryCssPath, framework);
160
+ Object.assign(sourceEntry, entries);
161
+ const perPageEntries = generateEntryForPage(demos, entryCssPath, framework);
162
+ Object.assign(sourceEntry, perPageEntries);
163
+ }
164
+ return sourceEntry;
165
+ }
166
+ const node_utils_namespaceObject = require("@rspress/shared/node-utils");
167
+ const convert = function(test) {
168
+ if (null == test) return ok;
169
+ if ('string' == typeof test) return typeFactory(test);
170
+ if ('object' == typeof test) return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
171
+ if ('function' == typeof test) return castFactory(test);
172
+ throw new Error('Expected function, string, or object as test');
173
+ };
174
+ function anyFactory(tests) {
175
+ const checks = [];
176
+ let index = -1;
177
+ while(++index < tests.length)checks[index] = convert(tests[index]);
178
+ return castFactory(any);
179
+ function any(...parameters) {
180
+ let index = -1;
181
+ while(++index < checks.length)if (checks[index].call(this, ...parameters)) return true;
182
+ return false;
183
+ }
184
+ }
185
+ function propsFactory(check) {
186
+ return castFactory(all);
187
+ function all(node) {
188
+ let key;
189
+ for(key in check)if (node[key] !== check[key]) return false;
190
+ return true;
191
+ }
192
+ }
193
+ function typeFactory(check) {
194
+ return castFactory(type);
195
+ function type(node) {
196
+ return node && node.type === check;
197
+ }
198
+ }
199
+ function castFactory(check) {
200
+ return assertion;
201
+ function assertion(node, ...parameters) {
202
+ return Boolean(node && 'object' == typeof node && 'type' in node && Boolean(check.call(this, node, ...parameters)));
203
+ }
204
+ }
205
+ function ok() {
206
+ return true;
207
+ }
208
+ function color(d) {
209
+ return '\u001B[33m' + d + '\u001B[39m';
210
+ }
211
+ const CONTINUE = true;
212
+ const EXIT = false;
213
+ const SKIP = 'skip';
214
+ const visitParents = function(tree, test, visitor, reverse) {
215
+ if ('function' == typeof test && 'function' != typeof visitor) {
216
+ reverse = visitor;
217
+ visitor = test;
218
+ test = null;
219
+ }
220
+ const is = convert(test);
221
+ const step = reverse ? -1 : 1;
222
+ factory(tree, void 0, [])();
223
+ function factory(node, index, parents) {
224
+ const value = node && 'object' == typeof node ? node : {};
225
+ if ('string' == typeof value.type) {
226
+ const name = 'string' == typeof value.tagName ? value.tagName : 'string' == typeof value.name ? value.name : void 0;
227
+ Object.defineProperty(visit, 'name', {
228
+ value: 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'
229
+ });
230
+ }
231
+ return visit;
232
+ function visit() {
233
+ let result = [];
234
+ let subresult;
235
+ let offset;
236
+ let grandparents;
237
+ if (!test || is(node, index, parents[parents.length - 1] || null)) {
238
+ result = toResult(visitor(node, parents));
239
+ if (result[0] === EXIT) return result;
240
+ }
241
+ if (node.children && result[0] !== SKIP) {
242
+ offset = (reverse ? node.children.length : -1) + step;
243
+ grandparents = parents.concat(node);
244
+ while(offset > -1 && offset < node.children.length){
245
+ subresult = factory(node.children[offset], offset, grandparents)();
246
+ if (subresult[0] === EXIT) return subresult;
247
+ offset = 'number' == typeof subresult[1] ? subresult[1] : offset + step;
248
+ }
249
+ }
250
+ return result;
251
+ }
252
+ }
253
+ };
254
+ function toResult(value) {
255
+ if (Array.isArray(value)) return value;
256
+ if ('number' == typeof value) return [
257
+ CONTINUE,
258
+ value
259
+ ];
260
+ return [
261
+ value
262
+ ];
263
+ }
264
+ const lib_visit = function(tree, test, visitor, reverse) {
265
+ if ('function' == typeof test && 'function' != typeof visitor) {
266
+ reverse = visitor;
267
+ visitor = test;
268
+ test = null;
269
+ }
270
+ visitParents(tree, test, overload, reverse);
271
+ function overload(node, parents) {
272
+ const parent = parents[parents.length - 1];
273
+ return visitor(node, parent ? parent.children.indexOf(node) : null, parent);
274
+ }
275
+ };
276
+ const getASTNodeImport = (name, from)=>({
277
+ type: 'mdxjsEsm',
278
+ value: `import ${name} from ${JSON.stringify(from)}`,
279
+ data: {
280
+ estree: {
281
+ type: 'Program',
282
+ sourceType: 'module',
283
+ body: [
284
+ {
285
+ type: 'ImportDeclaration',
286
+ specifiers: [
287
+ {
288
+ type: 'ImportDefaultSpecifier',
289
+ local: {
290
+ type: 'Identifier',
291
+ name
292
+ }
293
+ }
294
+ ],
295
+ source: {
296
+ type: 'Literal',
297
+ value: from,
298
+ raw: `${JSON.stringify(from)}`
299
+ }
300
+ }
301
+ ]
302
+ }
303
+ }
304
+ });
305
+ const getExternalDemoContent = (tempVar)=>({
306
+ type: 'mdxJsxFlowElement',
307
+ name: '',
308
+ attributes: [],
309
+ children: [
310
+ {
311
+ type: 'mdxJsxFlowElement',
312
+ name: 'pre',
313
+ attributes: [],
314
+ children: [
315
+ {
316
+ type: 'mdxJsxFlowElement',
317
+ name: 'code',
318
+ attributes: [
319
+ {
320
+ type: 'mdxJsxAttribute',
321
+ name: 'className',
322
+ value: 'language-tsx'
323
+ },
324
+ {
325
+ type: 'mdxJsxAttribute',
326
+ name: 'children',
327
+ value: {
328
+ type: 'mdxJsxExpressionAttribute',
329
+ value: tempVar,
330
+ data: {
331
+ estree: {
332
+ type: 'Program',
333
+ body: [
334
+ {
335
+ type: 'ExpressionStatement',
336
+ expression: {
337
+ type: 'Identifier',
338
+ name: tempVar
339
+ }
340
+ }
341
+ ]
342
+ }
343
+ }
344
+ }
345
+ }
346
+ ]
347
+ }
348
+ ]
349
+ }
350
+ ]
351
+ });
352
+ const remarkPlugin_demos = {};
353
+ const remarkCodeToDemo = function({ getRouteMeta, previewMode, defaultRenderMode, position, previewLanguages, previewCodeTransform }) {
354
+ const routeMeta = getRouteMeta();
355
+ external_node_fs_default().mkdirSync(virtualDir, {
356
+ recursive: true
357
+ });
358
+ const data = this.data();
359
+ return (tree, vfile)=>{
360
+ const demoMdx = [];
361
+ const route = routeMeta.find((meta)=>(0, shared_namespaceObject.normalizePosixPath)(meta.absolutePath) === (0, shared_namespaceObject.normalizePosixPath)(vfile.path || vfile.history[0]));
362
+ if (!route) return;
363
+ const { pageName } = route;
364
+ remarkPlugin_demos[pageName] = [];
365
+ let title = pageName;
366
+ let index = 1;
367
+ let externalDemoIndex = 0;
368
+ function constructDemoNode(demoId, demoPath, currentNode, isMobileMode, externalDemoIndex) {
369
+ if (isMobileMode) {
370
+ const relativePathReg = new RegExp(/^\.\.?\/.*$/);
371
+ remarkPlugin_demos[pageName].push({
372
+ title,
373
+ id: demoId,
374
+ path: relativePathReg.test(demoPath) ? (0, external_node_path_namespaceObject.resolve)(vfile.dirname || (0, external_node_path_namespaceObject.dirname)(vfile.path), demoPath) : demoPath
375
+ });
376
+ } else demoMdx.push(getASTNodeImport(`Demo${demoId}`, demoPath));
377
+ const tempVar = `externalDemoContent${externalDemoIndex}`;
378
+ if (void 0 !== externalDemoIndex) demoMdx.push(getASTNodeImport(tempVar, `!!${demoPath}?raw`));
379
+ if (isMobileMode && 'fixed' === position) void 0 !== externalDemoIndex && Object.assign(currentNode, getExternalDemoContent(tempVar));
380
+ else Object.assign(currentNode, {
381
+ type: 'mdxJsxFlowElement',
382
+ name: 'fixed-with-per-comp' === position ? 'ContainerFixedPerComp' : 'Container',
383
+ attributes: [
384
+ {
385
+ type: 'mdxJsxAttribute',
386
+ name: 'isMobile',
387
+ value: isMobileMode
388
+ },
389
+ {
390
+ type: 'mdxJsxAttribute',
391
+ name: 'demoId',
392
+ value: demoId
393
+ }
394
+ ],
395
+ children: [
396
+ void 0 === externalDemoIndex ? {
397
+ ...currentNode,
398
+ hasVisited: true
399
+ } : getExternalDemoContent(tempVar),
400
+ isMobileMode ? {
401
+ type: 'mdxJsxFlowElement',
402
+ name: null
403
+ } : {
404
+ type: 'mdxJsxFlowElement',
405
+ name: `Demo${demoId}`
406
+ }
407
+ ]
408
+ });
409
+ }
410
+ lib_visit(tree, 'heading', (node)=>{
411
+ if (1 === node.depth) {
412
+ const firstChild = node.children[0];
413
+ title = firstChild && 'value' in firstChild && firstChild.value || title;
414
+ }
415
+ });
416
+ lib_visit(tree, 'mdxJsxFlowElement', (node)=>{
417
+ if ('code' === node.name) {
418
+ const src = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'src');
419
+ if ('string' != typeof src) return;
420
+ const currentMode = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'previewMode') ?? previewMode;
421
+ const isMobileAttr = (0, node_utils_namespaceObject.getNodeAttribute)(node, 'isMobile');
422
+ let isMobileMode = false;
423
+ isMobileMode = void 0 === isMobileAttr ? 'iframe' === currentMode : null === isMobileAttr ? true : 'object' == typeof isMobileAttr ? 'false' !== isMobileAttr.value : 'false' !== isMobileAttr;
424
+ const id = generateId(pageName, index++);
425
+ constructDemoNode(id, src, node, isMobileMode, externalDemoIndex++);
426
+ }
427
+ });
428
+ lib_visit(tree, 'code', (node)=>{
429
+ if ('hasVisited' in node) return;
430
+ if (node.lang && previewLanguages.includes(node.lang)) {
431
+ var _node_meta, _node_meta1, _node_meta2, _node_meta3, _node_meta4, _node_meta5;
432
+ if ((null == (_node_meta = node.meta) ? void 0 : _node_meta.includes('pure')) || !(null == (_node_meta1 = node.meta) ? void 0 : _node_meta1.includes('preview')) && 'pure' === defaultRenderMode) return;
433
+ const value = injectDemoBlockImport(previewCodeTransform({
434
+ language: node.lang,
435
+ code: node.value
436
+ }), demoBlockComponentPath);
437
+ const isMobileMode = (null == (_node_meta2 = node.meta) ? void 0 : _node_meta2.includes('mobile')) || (null == (_node_meta3 = node.meta) ? void 0 : _node_meta3.includes('iframe')) || !(null == (_node_meta4 = node.meta) ? void 0 : _node_meta4.includes('web')) && !(null == (_node_meta5 = node.meta) ? void 0 : _node_meta5.includes('internal')) && 'iframe' === previewMode;
438
+ const id = generateId(pageName, index++);
439
+ const virtualModulePath = (0, external_node_path_namespaceObject.join)(virtualDir, `${id}.tsx`);
440
+ constructDemoNode(id, virtualModulePath, node, isMobileMode);
441
+ if (external_node_fs_default().existsSync(virtualModulePath)) {
442
+ const content = external_node_fs_default().readFileSync(virtualModulePath, 'utf-8');
443
+ if (content === value) return;
444
+ }
445
+ external_node_fs_default().writeFileSync(virtualModulePath, value);
446
+ }
447
+ });
448
+ tree.children.unshift(...demoMdx);
449
+ if (remarkPlugin_demos[pageName].length > 0) data.pageMeta.haveDemos = true;
450
+ };
451
+ };
452
+ let src_routeMeta;
453
+ const DEFAULT_PREVIEW_LANGUAGES = [
454
+ 'jsx',
455
+ 'tsx'
456
+ ];
457
+ function pluginPreview(options) {
458
+ const { isMobile = false, iframeOptions = {}, iframePosition = 'follow', defaultRenderMode = 'preview', previewLanguages = DEFAULT_PREVIEW_LANGUAGES, previewCodeTransform = ({ code })=>code } = options ?? {};
459
+ const previewMode = (null == options ? void 0 : options.previewMode) ?? (isMobile ? 'iframe' : 'internal');
460
+ const { devPort = 7890, framework = 'react', position = iframePosition, builderConfig = {} } = iframeOptions;
461
+ const getRouteMeta = ()=>src_routeMeta;
462
+ let lastDemos;
463
+ let devServer;
464
+ let clientConfig;
465
+ const port = devPort;
466
+ return {
467
+ name: '@rspress/plugin-preview',
468
+ config (config) {
469
+ config.markdown = config.markdown || {};
470
+ config.markdown.mdxRs = false;
471
+ return config;
472
+ },
473
+ routeGenerated (routes) {
474
+ src_routeMeta = routes;
475
+ },
476
+ async beforeBuild (_, isProd) {
477
+ if (!isProd) try {
478
+ await new Promise((resolve, reject)=>{
479
+ const server = external_node_net_default().createServer();
480
+ server.unref();
481
+ server.on('error', reject);
482
+ server.listen({
483
+ port,
484
+ host: '0.0.0.0'
485
+ }, ()=>{
486
+ server.close(resolve);
487
+ });
488
+ });
489
+ } catch (e) {
490
+ if (!!e && 'object' == typeof e && 'code' in e && 'EADDRINUSE' !== e.code) throw e;
491
+ throw new Error(`Port "${port}" is occupied, please choose another one.`);
492
+ }
493
+ },
494
+ async afterBuild (config, isProd) {
495
+ var _devServer_server;
496
+ if ((0, external_lodash_namespaceObject.isEqual)(remarkPlugin_demos, lastDemos)) return;
497
+ lastDemos = (0, external_lodash_namespaceObject.cloneDeep)(remarkPlugin_demos);
498
+ await (null == devServer ? void 0 : null == (_devServer_server = devServer.server) ? void 0 : _devServer_server.close());
499
+ devServer = void 0;
500
+ const sourceEntry = generateEntry(remarkPlugin_demos, framework, position);
501
+ const outDir = (0, external_node_path_namespaceObject.join)(config.outDir ?? 'doc_build', '~demo');
502
+ if (0 === Object.keys(sourceEntry).length) return;
503
+ const { html, source, output, performance } = clientConfig ?? {};
504
+ const rsbuildConfig = (0, core_namespaceObject.mergeRsbuildConfig)({
505
+ dev: {
506
+ progressBar: false
507
+ },
508
+ server: {
509
+ port: devPort,
510
+ printUrls: ()=>void 0,
511
+ strictPort: true
512
+ },
513
+ performance: {
514
+ ...performance,
515
+ printFileSize: false
516
+ },
517
+ html,
518
+ source: {
519
+ ...source,
520
+ entry: sourceEntry
521
+ },
522
+ output: {
523
+ ...output,
524
+ assetPrefix: (null == output ? void 0 : output.assetPrefix) ? `${(0, shared_namespaceObject.removeTrailingSlash)(output.assetPrefix)}/~demo` : '/~demo',
525
+ distPath: {
526
+ root: outDir
527
+ },
528
+ copy: void 0
529
+ },
530
+ plugins: null == config ? void 0 : config.builderPlugins
531
+ }, builderConfig);
532
+ const rsbuildInstance = await (0, core_namespaceObject.createRsbuild)({
533
+ callerName: 'rspress',
534
+ rsbuildConfig
535
+ });
536
+ const { pluginSass } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rsbuild/plugin-sass"));
537
+ const { pluginLess } = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "@rsbuild/plugin-less"));
538
+ rsbuildInstance.addPlugins([
539
+ pluginSass(),
540
+ pluginLess()
541
+ ]);
542
+ if ('solid' === framework) rsbuildInstance.addPlugins([
543
+ (0, plugin_babel_namespaceObject.pluginBabel)({
544
+ include: /\.(?:jsx|tsx)$/
545
+ }),
546
+ (0, plugin_solid_namespaceObject.pluginSolid)()
547
+ ]);
548
+ if ('react' === framework) rsbuildInstance.addPlugins([
549
+ (0, plugin_react_namespaceObject.pluginReact)()
550
+ ]);
551
+ if (isProd) rsbuildInstance.build();
552
+ else devServer = await rsbuildInstance.startDevServer();
553
+ },
554
+ builderConfig: {
555
+ source: {
556
+ include: [
557
+ (0, external_node_path_namespaceObject.join)(__dirname, '..')
558
+ ]
559
+ },
560
+ tools: {
561
+ bundlerChain (chain) {
562
+ chain.module.rule('Raw').resourceQuery(/raw/).type('asset/source').end();
563
+ chain.resolve.extensions.prepend('.md').prepend('.mdx');
564
+ },
565
+ rspack: {
566
+ watchOptions: {
567
+ ignored: /\.git/
568
+ }
569
+ }
570
+ },
571
+ plugins: [
572
+ {
573
+ name: 'close-demo-server',
574
+ setup: (api)=>{
575
+ api.modifyRsbuildConfig((config)=>{
576
+ var _config_output;
577
+ if ((null == (_config_output = config.output) ? void 0 : _config_output.target) === 'web') clientConfig = config;
578
+ });
579
+ api.onCloseDevServer(async ()=>{
580
+ var _devServer_server;
581
+ await (null == devServer ? void 0 : null == (_devServer_server = devServer.server) ? void 0 : _devServer_server.close());
582
+ devServer = void 0;
583
+ });
584
+ }
585
+ }
586
+ ]
587
+ },
588
+ extendPageData (pageData, isProd) {
589
+ if (!isProd) pageData.devPort = port;
590
+ pageData.extraHighlightLanguages = previewLanguages;
591
+ },
592
+ markdown: {
593
+ remarkPlugins: [
594
+ [
595
+ remarkCodeToDemo,
596
+ {
597
+ getRouteMeta,
598
+ position,
599
+ previewMode,
600
+ defaultRenderMode,
601
+ previewLanguages,
602
+ previewCodeTransform
603
+ }
604
+ ]
605
+ ],
606
+ globalComponents: [
607
+ (0, external_node_path_namespaceObject.join)(staticPath, 'global-components', 'Container.tsx'),
608
+ (0, external_node_path_namespaceObject.join)(staticPath, 'global-components', 'ContainerFixedPerComp.tsx')
609
+ ]
610
+ },
611
+ globalUIComponents: 'fixed-with-per-comp' === position ? [
612
+ (0, external_node_path_namespaceObject.join)(staticPath, 'global-components', 'DeviceFixedPerComp.tsx')
613
+ ] : 'fixed' === position ? [
614
+ (0, external_node_path_namespaceObject.join)(staticPath, 'global-components', 'Device.tsx')
615
+ ] : [],
616
+ globalStyles: (0, external_node_path_namespaceObject.join)(staticPath, 'global-styles', `${previewMode}.css`)
617
+ };
618
+ }
619
+ })();
620
+ exports.pluginPreview = __webpack_exports__.pluginPreview;
621
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
622
+ "pluginPreview"
623
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
624
+ Object.defineProperty(exports, '__esModule', {
625
+ value: true
626
+ });
@@ -0,0 +1,19 @@
1
+ export declare const generateId: (pageName: string, index: number) => string;
2
+
3
+ export declare const injectDemoBlockImport: (str: string, path: string) => string;
4
+
5
+ /**
6
+ * remove .html extension and validate
7
+ * @param routePath id from pathname
8
+ * @returns normalized id
9
+ */
10
+ export declare const normalizeId: (routePath: string) => string;
11
+
12
+ /**
13
+ * Converts a string to a valid variable name. If the string is already a valid variable name, returns the original string.
14
+ * @param str - The string to convert.
15
+ * @returns The converted string.
16
+ */
17
+ export declare const toValidVarName: (str: string) => string;
18
+
19
+ export { }