@rspress/plugin-preview 0.0.0-next-20240306032153 → 0.0.0-next-20240319081819
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 +28 -32
- package/dist/index.js.map +1 -1
- package/dist/utils.js +1 -2
- package/dist/utils.js.map +1 -1
- package/package.json +8 -9
- package/static/global-components/Device.tsx +11 -9
package/dist/index.js
CHANGED
@@ -35,6 +35,7 @@ __export(src_exports, {
|
|
35
35
|
module.exports = __toCommonJS(src_exports);
|
36
36
|
var import_path4 = require("path");
|
37
37
|
var import_node_net = __toESM(require("net"));
|
38
|
+
var import_shared3 = require("@rspress/shared");
|
38
39
|
var import_core = require("@rsbuild/core");
|
39
40
|
var import_plugin_solid = require("@rsbuild/plugin-solid");
|
40
41
|
var import_plugin_babel = require("@rsbuild/plugin-babel");
|
@@ -242,9 +243,8 @@ var import_fs_extra = __toESM(require("@rspress/shared/fs-extra"));
|
|
242
243
|
var toValidVarName = (str) => {
|
243
244
|
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) {
|
244
245
|
return str;
|
245
|
-
} else {
|
246
|
-
return str.replace(/[^0-9a-zA-Z_$]/g, "_").replace(/^([0-9])/, "_$1");
|
247
246
|
}
|
247
|
+
return str.replace(/[^0-9a-zA-Z_$]/g, "_").replace(/^([0-9])/, "_$1");
|
248
248
|
};
|
249
249
|
var generateId = (pageName, index) => {
|
250
250
|
return `_${toValidVarName(pageName)}_${index}`;
|
@@ -272,26 +272,21 @@ var virtualDir = import_path.default.join(
|
|
272
272
|
"virtual-demo"
|
273
273
|
);
|
274
274
|
|
275
|
-
// src/virtual-module.ts
|
276
|
-
var import_rspack_plugin_virtual_module = __toESM(require("rspack-plugin-virtual-module"));
|
277
|
-
var demos = {};
|
278
|
-
var demoRuntimeModule = new import_rspack_plugin_virtual_module.default({
|
279
|
-
"virtual-meta": "export const demos = {}"
|
280
|
-
});
|
281
|
-
|
282
275
|
// src/remarkPlugin.ts
|
283
|
-
var
|
276
|
+
var demos = {};
|
277
|
+
var remarkCodeToDemo = function({
|
284
278
|
getRouteMeta,
|
285
279
|
previewMode,
|
286
280
|
defaultRenderMode,
|
287
281
|
position
|
288
|
-
})
|
282
|
+
}) {
|
289
283
|
const routeMeta2 = getRouteMeta();
|
290
284
|
import_fs_extra.default.ensureDirSync(virtualDir);
|
285
|
+
const data = this.data();
|
291
286
|
return (tree, vfile) => {
|
292
287
|
const demoMdx = [];
|
293
288
|
const route = routeMeta2.find(
|
294
|
-
(
|
289
|
+
(meta) => (0, import_shared2.normalizePosixPath)(meta.absolutePath) === (0, import_shared2.normalizePosixPath)(vfile.path || vfile.history[0])
|
295
290
|
);
|
296
291
|
if (!route) {
|
297
292
|
return;
|
@@ -407,10 +402,9 @@ var remarkCodeToDemo = ({
|
|
407
402
|
}
|
408
403
|
});
|
409
404
|
tree.children.unshift(...demoMdx);
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
demoRuntimeModule.writeModule("virtual-meta", meta);
|
405
|
+
if (demos[pageName].length > 0) {
|
406
|
+
data.pageMeta.haveDemos = true;
|
407
|
+
}
|
414
408
|
};
|
415
409
|
};
|
416
410
|
var getASTNodeImport = (name, from) => ({
|
@@ -589,6 +583,7 @@ function pluginPreview(options) {
|
|
589
583
|
const getRouteMeta = () => routeMeta;
|
590
584
|
let lastDemos;
|
591
585
|
let devServer;
|
586
|
+
let clientConfig;
|
592
587
|
const port = devPort;
|
593
588
|
return {
|
594
589
|
name: "@rspress/plugin-preview",
|
@@ -614,11 +609,10 @@ function pluginPreview(options) {
|
|
614
609
|
} catch (e) {
|
615
610
|
if (e.code !== "EADDRINUSE") {
|
616
611
|
throw e;
|
617
|
-
} else {
|
618
|
-
throw new Error(
|
619
|
-
`Port "${port}" is occupied, please choose another one.`
|
620
|
-
);
|
621
612
|
}
|
613
|
+
throw new Error(
|
614
|
+
`Port "${port}" is occupied, please choose another one.`
|
615
|
+
);
|
622
616
|
}
|
623
617
|
}
|
624
618
|
},
|
@@ -633,6 +627,7 @@ function pluginPreview(options) {
|
|
633
627
|
if (Object.keys(sourceEntry).length === 0) {
|
634
628
|
return;
|
635
629
|
}
|
630
|
+
const { html, source, output, performance } = clientConfig ?? {};
|
636
631
|
const rsbuildConfig = (0, import_core.mergeRsbuildConfig)(
|
637
632
|
{
|
638
633
|
dev: {
|
@@ -644,23 +639,22 @@ function pluginPreview(options) {
|
|
644
639
|
strictPort: true
|
645
640
|
},
|
646
641
|
performance: {
|
642
|
+
...performance,
|
647
643
|
printFileSize: false
|
648
644
|
},
|
645
|
+
html,
|
649
646
|
source: {
|
650
|
-
|
647
|
+
...source,
|
651
648
|
entry: sourceEntry
|
652
649
|
},
|
653
650
|
output: {
|
651
|
+
...output,
|
652
|
+
assetPrefix: output?.assetPrefix ? `${(0, import_shared3.removeTrailingSlash)(output.assetPrefix)}/~demo` : "/~demo",
|
654
653
|
distPath: {
|
655
654
|
root: outDir
|
656
|
-
}
|
657
|
-
|
658
|
-
|
659
|
-
rspack: {
|
660
|
-
output: {
|
661
|
-
publicPath: "/~demo"
|
662
|
-
}
|
663
|
-
}
|
655
|
+
},
|
656
|
+
// not copy files again
|
657
|
+
copy: void 0
|
664
658
|
}
|
665
659
|
},
|
666
660
|
builderConfig
|
@@ -690,9 +684,6 @@ function pluginPreview(options) {
|
|
690
684
|
include: [(0, import_path4.join)(__dirname, "..")]
|
691
685
|
},
|
692
686
|
tools: {
|
693
|
-
rspack: {
|
694
|
-
plugins: [demoRuntimeModule]
|
695
|
-
},
|
696
687
|
bundlerChain(chain) {
|
697
688
|
chain.module.rule("Raw").resourceQuery(/raw/).type("asset/source").end();
|
698
689
|
chain.resolve.extensions.prepend(".md").prepend(".mdx");
|
@@ -702,6 +693,11 @@ function pluginPreview(options) {
|
|
702
693
|
{
|
703
694
|
name: "close-demo-server",
|
704
695
|
setup: (api) => {
|
696
|
+
api.modifyRsbuildConfig((config) => {
|
697
|
+
if (config.output?.targets?.every((target) => target === "web")) {
|
698
|
+
clientConfig = config;
|
699
|
+
}
|
700
|
+
});
|
705
701
|
api.onCloseDevServer(async () => {
|
706
702
|
await devServer?.server?.close();
|
707
703
|
});
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,eAAqB;AACrB,sBAAgB;AAEhB,kBAAkD;AAClD,0BAA4B;AAC5B,0BAA4B;AAC5B,0BAA4B;AAC5B,oBAAmC;;;ACPnC,IAAAA,eAAuC;;;ACqKhC,IAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYT,SAAU,MAAM;AACd,QAAI,SAAS,UAAa,SAAS,MAAM;AACvC,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,SAAS,UAAU;AAC5B,aAAO,YAAY,IAAI;AAAA,IACzB;AAEA,QAAI,OAAO,SAAS,UAAU;AAC5B,aAAO,MAAM,QAAQ,IAAI,IAAI,WAAW,IAAI,IAAI,aAAa,IAAI;AAAA,IACnE;AAEA,QAAI,OAAO,SAAS,YAAY;AAC9B,aAAO,YAAY,IAAI;AAAA,IACzB;AAEA,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AAAA;AAOJ,SAAS,WAAW,OAAO;AAEzB,QAAM,SAAS,CAAC;AAChB,MAAI,QAAQ;AAEZ,SAAO,EAAE,QAAQ,MAAM,QAAQ;AAC7B,WAAO,KAAK,IAAI,QAAQ,MAAM,KAAK,CAAC;AAAA,EACtC;AAEA,SAAO,YAAY,GAAG;AAOtB,WAAS,OAAO,YAAY;AAC1B,QAAIC,SAAQ;AAEZ,WAAO,EAAEA,SAAQ,OAAO,QAAQ;AAC9B,UAAI,OAAOA,MAAK,EAAE,KAAK,MAAM,GAAG,UAAU;AAAG,eAAO;AAAA,IACtD;AAEA,WAAO;AAAA,EACT;AACF;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A,cACD,iCAAY;AAAA,QACd,CAAC;AAAA,MACH;AACA,UAAI,cAAc,SAAS;AACzB,wBAAgB,WAAW,KAAC,iCAAY,CAAC,CAAC;AAAA,MAC5C;AACA,UAAI,QAAQ;AACV,wBAAgB,MAAM;AAAA,MACxB,OAAO;AACL,oBAAY,MAAM,gBAAgB,eAAe;AAAA,MACnD;AAAA,IACF;AAAA,IACA,eAAe;AAAA,MACb,QAAQ;AAAA,QACN,SAAS,KAAC,mBAAK,WAAW,IAAI,CAAC;AAAA,MACjC;AAAA,MACA,OAAO;AAAA,QACL,QAAQ;AAAA,UACN,SAAS,CAAC,iBAAiB;AAAA,QAC7B;AAAA,QACA,aAAa,OAAO;AAClB,gBAAM,OACH,KAAK,KAAK,EACV,cAAc,KAAK,EACnB,KAAK,cAAc,EACnB,IAAI;AAEP,gBAAM,QAAQ,WAAW,QAAQ,KAAK,EAAE,QAAQ,MAAM;AAAA,QACxD;AAAA,MACF;AAAA,MACA,SAAS;AAAA,QACP;AAAA,UACE,MAAM;AAAA,UACN,OAAO,SAAO;AACZ,gBAAI,iBAAiB,YAAY;AAC/B,oBAAM,WAAW,QAAQ,MAAM;AAAA,YACjC,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IACA,eAAe,UAAU,QAAQ;AAC/B,UAAI,CAAC,QAAQ;AACX,iBAAS,UAAU;AAAA,MACrB;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,eAAe;AAAA,QACb;AAAA,UACE;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,kBAAkB;AAAA,YAChB,mBAAK,YAAY,qBAAqB,eAAe;AAAA,MACvD;AAAA,IACF;AAAA,IACA;AAAA,IACA,kBAAc,mBAAK,YAAY,iBAAiB,GAAG,WAAW,MAAM;AAAA,EACtE;AACF","names":["import_path","index","is","visit","import_shared","path","RspackVirtualModulePlugin","routeMeta","fs","meta","externalDemoIndex","demos","resolve","net"],"sources":["../src/index.ts","../src/remarkPlugin.ts","../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js","../../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/color.js","../../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/index.js","../../../node_modules/.pnpm/unist-util-visit@4.1.1/node_modules/unist-util-visit/index.js","../src/utils.ts","../src/constant.ts","../src/virtual-module.ts","../src/generate-entry.ts"],"sourcesContent":["import { join } from 'path';\nimport net from 'node:net';\nimport { type RouteMeta, type RspressPlugin } from '@rspress/shared';\nimport { createRsbuild, mergeRsbuildConfig } from '@rsbuild/core';\nimport { pluginSolid } from '@rsbuild/plugin-solid';\nimport { pluginBabel } from '@rsbuild/plugin-babel';\nimport { pluginReact } from '@rsbuild/plugin-react';\nimport { isEqual, cloneDeep } from 'lodash';\nimport { remarkCodeToDemo } from './remarkPlugin';\nimport { staticPath } from './constant';\nimport type { Options, StartServerResult } from './types';\nimport { generateEntry } from './generate-entry';\nimport { demoRuntimeModule, demos } from './virtual-module';\n\n// global variables which need to be initialized in plugin\nlet routeMeta: RouteMeta[];\n\n/**\n * The plugin is used to preview component.\n */\nexport function pluginPreview(options?: Options): RspressPlugin {\n const {\n isMobile = false,\n iframeOptions = {},\n iframePosition = 'follow',\n defaultRenderMode = 'preview',\n } = options ?? {};\n const previewMode = options?.previewMode ?? isMobile ? 'iframe' : 'internal';\n const {\n devPort = 7890,\n framework = 'react',\n position = iframePosition,\n builderConfig = {},\n } = iframeOptions;\n const globalUIComponents =\n iframePosition === 'fixed'\n ? [join(staticPath, 'global-components', 'Device.tsx')]\n : [];\n const getRouteMeta = () => routeMeta;\n let lastDemos: typeof demos;\n let devServer: StartServerResult;\n const port = devPort;\n return {\n name: '@rspress/plugin-preview',\n config(config) {\n config.markdown = config.markdown || {};\n config.markdown.mdxRs = false;\n return config;\n },\n routeGenerated(routes: RouteMeta[]) {\n // init routeMeta\n routeMeta = routes;\n },\n async beforeBuild(_, isProd) {\n if (!isProd) {\n try {\n await new Promise((resolve, reject) => {\n const server = net.createServer();\n server.unref();\n server.on('error', reject);\n server.listen({ port, host: '0.0.0.0' }, () => {\n server.close(resolve);\n });\n });\n } catch (e: any) {\n if (e.code !== 'EADDRINUSE') {\n throw e;\n } else {\n throw new Error(\n `Port \"${port}\" is occupied, please choose another one.`,\n );\n }\n }\n }\n },\n async afterBuild(config, isProd) {\n if (isEqual(demos, lastDemos)) {\n return;\n }\n lastDemos = cloneDeep(demos);\n await devServer?.server?.close();\n const sourceEntry = generateEntry(demos, framework, position);\n const outDir = join(config.outDir ?? 'doc_build', '~demo');\n if (Object.keys(sourceEntry).length === 0) {\n return;\n }\n const rsbuildConfig = mergeRsbuildConfig(\n {\n dev: {\n progressBar: false,\n },\n server: {\n port: devPort,\n printUrls: () => undefined,\n strictPort: true,\n },\n performance: {\n printFileSize: false,\n },\n source: {\n alias: config?.builderConfig?.source?.alias,\n entry: sourceEntry,\n },\n output: {\n distPath: {\n root: outDir,\n },\n },\n tools: {\n rspack: {\n output: {\n publicPath: '/~demo',\n },\n },\n },\n },\n builderConfig,\n );\n const rsbuildInstance = await createRsbuild({\n rsbuildConfig,\n });\n if (framework === 'solid') {\n rsbuildInstance.addPlugins([\n pluginBabel({\n include: /\\.(?:jsx|tsx)$/,\n }),\n pluginSolid(),\n ]);\n }\n if (framework === 'react') {\n rsbuildInstance.addPlugins([pluginReact()]);\n }\n if (isProd) {\n rsbuildInstance.build();\n } else {\n devServer = await rsbuildInstance.startDevServer();\n }\n },\n builderConfig: {\n source: {\n include: [join(__dirname, '..')],\n },\n tools: {\n rspack: {\n plugins: [demoRuntimeModule],\n },\n bundlerChain(chain) {\n chain.module\n .rule('Raw')\n .resourceQuery(/raw/)\n .type('asset/source')\n .end();\n\n chain.resolve.extensions.prepend('.md').prepend('.mdx');\n },\n },\n plugins: [\n {\n name: 'close-demo-server',\n setup: api => {\n api.onCloseDevServer(async () => {\n await devServer?.server?.close();\n });\n },\n },\n ],\n },\n extendPageData(pageData, isProd) {\n if (!isProd) {\n pageData.devPort = port;\n }\n },\n markdown: {\n remarkPlugins: [\n [\n remarkCodeToDemo,\n {\n getRouteMeta,\n position,\n previewMode,\n defaultRenderMode,\n },\n ],\n ],\n globalComponents: [\n join(staticPath, 'global-components', 'Container.tsx'),\n ],\n },\n globalUIComponents,\n globalStyles: join(staticPath, 'global-styles', `${previewMode}.css`),\n };\n}\n\nexport type { Options };\n","import { join, resolve, dirname } from 'path';\nimport { visit } from 'unist-util-visit';\nimport { normalizePosixPath } from '@rspress/shared';\nimport fs from '@rspress/shared/fs-extra';\nimport type { Plugin } from 'unified';\nimport type { Root } from 'mdast';\nimport type { MdxjsEsm } from 'mdast-util-mdxjs-esm';\nimport type { RemarkPluginOptions } from './types';\nimport { injectDemoBlockImport, generateId } from './utils';\nimport { demoBlockComponentPath, virtualDir } from './constant';\nimport { demoRuntimeModule, demos } from './virtual-module';\n\n/**\n * remark plugin to transform code to demo\n */\nexport const remarkCodeToDemo: Plugin<[RemarkPluginOptions], Root> = ({\n getRouteMeta,\n previewMode,\n defaultRenderMode,\n position,\n}) => {\n const routeMeta = getRouteMeta();\n fs.ensureDirSync(virtualDir);\n return (tree, vfile) => {\n const demoMdx: MdxjsEsm[] = [];\n const route = routeMeta.find(\n meta =>\n normalizePosixPath(meta.absolutePath) ===\n normalizePosixPath(vfile.path || vfile.history[0]),\n );\n if (!route) {\n return;\n }\n const { pageName } = route;\n // clear all demo in this pageName and recollect, bacause we may delete the demo\n demos[pageName] = [];\n let title = pageName;\n let index = 1;\n let externalDemoIndex = 0;\n\n function constructDemoNode(\n demoId: string,\n demoPath: string,\n currentNode: any,\n isMobileMode: boolean,\n // Only for external demo\n externalDemoIndex?: number,\n ) {\n if (isMobileMode) {\n const relativePathReg = new RegExp(/^\\.\\.?\\/.*$/);\n demos[pageName].push({\n title,\n id: demoId,\n path: relativePathReg.test(demoPath)\n ? resolve(vfile.dirname || dirname(vfile.path), demoPath)\n : demoPath,\n });\n } else {\n demoMdx.push(getASTNodeImport(`Demo${demoId}`, demoPath));\n }\n\n // get external demo content\n const tempVar = `externalDemoContent${externalDemoIndex}`;\n if (externalDemoIndex !== undefined) {\n // Such as `import externalDemoContent0 from '!!xxx?raw'`\n // `!!` prefix is used to avoid other loaders in rspack\n demoMdx.push(getASTNodeImport(tempVar, `!!${demoPath}?raw`));\n }\n\n if (isMobileMode && position === 'fixed') {\n // Only show the code block\n externalDemoIndex !== undefined &&\n Object.assign(currentNode, getExternalDemoContent(tempVar));\n } else {\n // Use container to show the code and view\n Object.assign(currentNode, {\n type: 'mdxJsxFlowElement',\n name: 'Container',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'isMobile',\n value: isMobileMode,\n },\n {\n type: 'mdxJsxAttribute',\n name: 'demoId',\n value: demoId,\n },\n ],\n children: [\n externalDemoIndex === undefined\n ? {\n ...currentNode,\n hasVisited: true,\n }\n : getExternalDemoContent(tempVar),\n isMobileMode\n ? {\n type: 'mdxJsxFlowElement',\n name: null,\n }\n : {\n type: 'mdxJsxFlowElement',\n name: `Demo${demoId}`,\n },\n ],\n });\n }\n }\n visit(tree, 'heading', node => {\n if (node.depth === 1) {\n if (node.children) {\n title = (node.children[0] as any)?.value || title;\n }\n }\n });\n\n // 1. External demo , use <code src=\"xxx\" /> to declare demo\n visit(tree, 'mdxJsxFlowElement', (node: any) => {\n if (node.name === 'code') {\n const src = node.attributes.find(\n (attr: { name: string; value: string }) => attr.name === 'src',\n )?.value;\n if (!src) {\n return;\n }\n\n // don't support expression syntax\n const currtentMode =\n node.attributes.find(\n (attr: { name: string; value: boolean }) =>\n attr.name === 'previewMode',\n )?.value ?? previewMode;\n\n // TODO: remove isMobileAttribute\n let isMobileMode = node.attributes.find(\n (attr: { name: string; value: boolean }) => attr.name === 'isMobile',\n )?.value;\n if (isMobileMode === undefined) {\n // isMobile is not specified, eg: <code />\n isMobileMode = currtentMode === 'iframe';\n } else if (isMobileMode === null) {\n // true by default, eg: <code isMobile />\n isMobileMode = true;\n } else if (typeof isMobileMode === 'object') {\n // jsx value, isMobileMode.value now must be string, even if input is\n // any complex struct rather than primitive type\n // eg: <code isMobile={ anyOfOrOther([true, false, 'true', 'false', {}]) } />\n isMobileMode = isMobileMode.value !== 'false';\n } else {\n // string value, eg: <code isMobile=\"true\" />\n isMobileMode = isMobileMode !== 'false';\n }\n\n const id = generateId(pageName, index++);\n constructDemoNode(id, src, node, isMobileMode, externalDemoIndex++);\n }\n });\n\n // 2. Internal demo, use ```j/tsx to declare demo\n visit(tree, 'code', node => {\n // hasVisited is a custom property\n if ('hasVisited' in node) {\n return;\n }\n\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const value = injectDemoBlockImport(node.value, demoBlockComponentPath);\n\n // do not anything for pure mode\n if (\n node?.meta?.includes('pure') ||\n (!node?.meta?.includes('preview') && defaultRenderMode === 'pure')\n ) {\n return;\n }\n\n // every code block can change their preview mode by meta\n const isMobileMode =\n node?.meta?.includes('mobile') ||\n node?.meta?.includes('iframe') ||\n (!node?.meta?.includes('web') &&\n !node?.meta?.includes('internal') &&\n previewMode === 'iframe');\n\n const id = generateId(pageName, index++);\n const virtualModulePath = join(virtualDir, `${id}.tsx`);\n constructDemoNode(id, virtualModulePath, node, isMobileMode);\n // Only when the content of the file changes, the file will be written\n // Avoid to trigger the hmr indefinitely\n if (fs.existsSync(virtualModulePath)) {\n const content = fs.readFileSync(virtualModulePath, 'utf-8');\n if (content === value) {\n return;\n }\n }\n fs.writeFileSync(virtualModulePath, value);\n }\n });\n\n tree.children.unshift(...demoMdx);\n\n // maybe rewrite, but it is necessary\n const meta = `\n export const demos = ${JSON.stringify(demos)}\n `;\n demoRuntimeModule.writeModule('virtual-meta', meta);\n };\n};\n\nconst getASTNodeImport = (name: string, from: string) =>\n ({\n type: 'mdxjsEsm',\n value: `import ${name} from ${JSON.stringify(from)}`,\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ImportDeclaration',\n specifiers: [\n {\n type: 'ImportDefaultSpecifier',\n local: { type: 'Identifier', name },\n },\n ],\n source: {\n type: 'Literal',\n value: from,\n raw: `${JSON.stringify(from)}`,\n },\n },\n ],\n },\n },\n } as MdxjsEsm);\n\nconst getExternalDemoContent = (tempVar: string) => ({\n /**\n * We create a empty parent node here. If we don't do this, the `pre` tag won't be rendered as our custom mdx component and will be rendered as a normal `pre` tag, which will cause the code block to be displayed incorrectly.\n */\n type: 'mdxJsxFlowElement',\n name: '',\n attributes: [],\n children: [\n {\n type: 'mdxJsxFlowElement',\n name: 'pre',\n attributes: [],\n children: [\n {\n type: 'mdxJsxFlowElement',\n name: 'code',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'className',\n value: 'language-tsx',\n },\n {\n type: 'mdxJsxAttribute',\n name: 'children',\n value: {\n type: 'mdxJsxExpressionAttribute',\n value: tempVar,\n data: {\n estree: {\n type: 'Program',\n body: [\n {\n type: 'ExpressionStatement',\n expression: {\n type: 'Identifier',\n name: tempVar,\n },\n },\n ],\n },\n },\n },\n },\n ],\n },\n ],\n },\n ],\n});\n","/**\n * @typedef {import('unist').Node} Node\n * @typedef {import('unist').Parent} Parent\n */\n\n/**\n * @typedef {Record<string, unknown>} Props\n * @typedef {null | undefined | string | Props | TestFunctionAnything | Array<string | Props | TestFunctionAnything>} Test\n * Check for an arbitrary node, unaware of TypeScript inferral.\n *\n * @callback TestFunctionAnything\n * Check if a node passes a test, unaware of TypeScript inferral.\n * @param {unknown} this\n * The given context.\n * @param {Node} node\n * A node.\n * @param {number | null | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | null | undefined} [parent]\n * The node’s parent.\n * @returns {boolean | void}\n * Whether this node passes the test.\n */\n\n/**\n * @template {Node} Kind\n * Node type.\n * @typedef {Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind> | Array<Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind>>} PredicateTest\n * Check for a node that can be inferred by TypeScript.\n */\n\n/**\n * Check if a node passes a certain test.\n *\n * @template {Node} Kind\n * Node type.\n * @callback TestFunctionPredicate\n * Complex test function for a node that can be inferred by TypeScript.\n * @param {Node} node\n * A node.\n * @param {number | null | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | null | undefined} [parent]\n * The node’s parent.\n * @returns {node is Kind}\n * Whether this node passes the test.\n */\n\n/**\n * @callback AssertAnything\n * Check that an arbitrary value is a node, unaware of TypeScript inferral.\n * @param {unknown} [node]\n * Anything (typically a node).\n * @param {number | null | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | null | undefined} [parent]\n * The node’s parent.\n * @returns {boolean}\n * Whether this is a node and passes a test.\n */\n\n/**\n * Check if a node is a node and passes a certain node test.\n *\n * @template {Node} Kind\n * Node type.\n * @callback AssertPredicate\n * Check that an arbitrary value is a specific node, aware of TypeScript.\n * @param {unknown} [node]\n * Anything (typically a node).\n * @param {number | null | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | null | undefined} [parent]\n * The node’s parent.\n * @returns {node is Kind}\n * Whether this is a node and passes a test.\n */\n\n/**\n * Check if `node` is a `Node` and whether it passes the given test.\n *\n * @param node\n * Thing to check, typically `Node`.\n * @param test\n * A check for a specific node.\n * @param index\n * The node’s position in its parent.\n * @param parent\n * The node’s parent.\n * @returns\n * Whether `node` is a node and passes a test.\n */\nexport const is =\n /**\n * @type {(\n * (() => false) &\n * (<Kind extends Node = Node>(node: unknown, test: PredicateTest<Kind>, index: number, parent: Parent, context?: unknown) => node is Kind) &\n * (<Kind extends Node = Node>(node: unknown, test: PredicateTest<Kind>, index?: null | undefined, parent?: null | undefined, context?: unknown) => node is Kind) &\n * ((node: unknown, test: Test, index: number, parent: Parent, context?: unknown) => boolean) &\n * ((node: unknown, test?: Test, index?: null | undefined, parent?: null | undefined, context?: unknown) => boolean)\n * )}\n */\n (\n /**\n * @param {unknown} [node]\n * @param {Test} [test]\n * @param {number | null | undefined} [index]\n * @param {Parent | null | undefined} [parent]\n * @param {unknown} [context]\n * @returns {boolean}\n */\n // eslint-disable-next-line max-params\n function is(node, test, index, parent, context) {\n const check = convert(test)\n\n if (\n index !== undefined &&\n index !== null &&\n (typeof index !== 'number' ||\n index < 0 ||\n index === Number.POSITIVE_INFINITY)\n ) {\n throw new Error('Expected positive finite index')\n }\n\n if (\n parent !== undefined &&\n parent !== null &&\n (!is(parent) || !parent.children)\n ) {\n throw new Error('Expected parent node')\n }\n\n if (\n (parent === undefined || parent === null) !==\n (index === undefined || index === null)\n ) {\n throw new Error('Expected both parent and index')\n }\n\n // @ts-expect-error Looks like a node.\n return node && node.type && typeof node.type === 'string'\n ? Boolean(check.call(context, node, index, parent))\n : false\n }\n )\n\n/**\n * Generate an assertion from a test.\n *\n * Useful if you’re going to test many nodes, for example when creating a\n * utility where something else passes a compatible test.\n *\n * The created function is a bit faster because it expects valid input only:\n * a `node`, `index`, and `parent`.\n *\n * @param test\n * * when nullish, checks if `node` is a `Node`.\n * * when `string`, works like passing `(node) => node.type === test`.\n * * when `function` checks if function passed the node is true.\n * * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.\n * * when `array`, checks if any one of the subtests pass.\n * @returns\n * An assertion.\n */\nexport const convert =\n /**\n * @type {(\n * (<Kind extends Node>(test: PredicateTest<Kind>) => AssertPredicate<Kind>) &\n * ((test?: Test) => AssertAnything)\n * )}\n */\n (\n /**\n * @param {Test} [test]\n * @returns {AssertAnything}\n */\n function (test) {\n if (test === undefined || test === null) {\n return ok\n }\n\n if (typeof test === 'string') {\n return typeFactory(test)\n }\n\n if (typeof test === 'object') {\n return Array.isArray(test) ? anyFactory(test) : propsFactory(test)\n }\n\n if (typeof test === 'function') {\n return castFactory(test)\n }\n\n throw new Error('Expected function, string, or object as test')\n }\n )\n\n/**\n * @param {Array<string | Props | TestFunctionAnything>} tests\n * @returns {AssertAnything}\n */\nfunction anyFactory(tests) {\n /** @type {Array<AssertAnything>} */\n const checks = []\n let index = -1\n\n while (++index < tests.length) {\n checks[index] = convert(tests[index])\n }\n\n return castFactory(any)\n\n /**\n * @this {unknown}\n * @param {Array<unknown>} parameters\n * @returns {boolean}\n */\n function any(...parameters) {\n let index = -1\n\n while (++index < checks.length) {\n if (checks[index].call(this, ...parameters)) return true\n }\n\n return false\n }\n}\n\n/**\n * Turn an object into a test for a node with a certain fields.\n *\n * @param {Props} check\n * @returns {AssertAnything}\n */\nfunction propsFactory(check) {\n return castFactory(all)\n\n /**\n * @param {Node} node\n * @returns {boolean}\n */\n function all(node) {\n /** @type {string} */\n let key\n\n for (key in check) {\n // @ts-expect-error: hush, it sure works as an index.\n if (node[key] !== check[key]) return false\n }\n\n return true\n }\n}\n\n/**\n * Turn a string into a test for a node with a certain type.\n *\n * @param {string} check\n * @returns {AssertAnything}\n */\nfunction typeFactory(check) {\n return castFactory(type)\n\n /**\n * @param {Node} node\n */\n function type(node) {\n return node && node.type === check\n }\n}\n\n/**\n * Turn a custom test into a test for a node that passes that test.\n *\n * @param {TestFunctionAnything} check\n * @returns {AssertAnything}\n */\nfunction castFactory(check) {\n return assertion\n\n /**\n * @this {unknown}\n * @param {unknown} node\n * @param {Array<unknown>} parameters\n * @returns {boolean}\n */\n function assertion(node, ...parameters) {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n // @ts-expect-error: fine.\n Boolean(check.call(this, node, ...parameters))\n )\n }\n}\n\nfunction ok() {\n return true\n}\n","/**\n * @param {string} d\n * @returns {string}\n */\nexport function color(d) {\n return '\\u001B[33m' + d + '\\u001B[39m'\n}\n","/**\n * @typedef {import('unist').Node} Node\n * @typedef {import('unist').Parent} Parent\n * @typedef {import('unist-util-is').Test} Test\n */\n\n/**\n * @typedef {boolean | 'skip'} Action\n * Union of the action types.\n *\n * @typedef {number} Index\n * Move to the sibling at `index` next (after node itself is completely\n * traversed).\n *\n * Useful if mutating the tree, such as removing the node the visitor is\n * currently on, or any of its previous siblings.\n * Results less than 0 or greater than or equal to `children.length` stop\n * traversing the parent.\n *\n * @typedef {[(Action | null | undefined | void)?, (Index | null | undefined)?]} ActionTuple\n * List with one or two values, the first an action, the second an index.\n *\n * @typedef {Action | ActionTuple | Index | null | undefined | void} VisitorResult\n * Any value that can be returned from a visitor.\n */\n\n/**\n * @template {Node} [Visited=Node]\n * Visited node type.\n * @template {Parent} [Ancestor=Parent]\n * Ancestor type.\n * @callback Visitor\n * Handle a node (matching `test`, if given).\n *\n * Visitors are free to transform `node`.\n * They can also transform the parent of node (the last of `ancestors`).\n *\n * Replacing `node` itself, if `SKIP` is not returned, still causes its\n * descendants to be walked (which is a bug).\n *\n * When adding or removing previous siblings of `node` (or next siblings, in\n * case of reverse), the `Visitor` should return a new `Index` to specify the\n * sibling to traverse after `node` is traversed.\n * Adding or removing next siblings of `node` (or previous siblings, in case\n * of reverse) is handled as expected without needing to return a new `Index`.\n *\n * Removing the children property of an ancestor still results in them being\n * traversed.\n * @param {Visited} node\n * Found node.\n * @param {Array<Ancestor>} ancestors\n * Ancestors of `node`.\n * @returns {VisitorResult}\n * What to do next.\n *\n * An `Index` is treated as a tuple of `[CONTINUE, Index]`.\n * An `Action` is treated as a tuple of `[Action]`.\n *\n * Passing a tuple back only makes sense if the `Action` is `SKIP`.\n * When the `Action` is `EXIT`, that action can be returned.\n * When the `Action` is `CONTINUE`, `Index` can be returned.\n */\n\n/**\n * @template {Node} [Tree=Node]\n * Tree type.\n * @template {Test} [Check=string]\n * Test type.\n * @typedef {Visitor<import('./complex-types.js').Matches<import('./complex-types.js').InclusiveDescendant<Tree>, Check>, Extract<import('./complex-types.js').InclusiveDescendant<Tree>, Parent>>} BuildVisitor\n * Build a typed `Visitor` function from a tree and a test.\n *\n * It will infer which values are passed as `node` and which as `parents`.\n */\n\nimport {convert} from 'unist-util-is'\nimport {color} from './color.js'\n\n/**\n * Continue traversing as normal.\n */\nexport const CONTINUE = true\n\n/**\n * Stop traversing immediately.\n */\nexport const EXIT = false\n\n/**\n * Do not traverse this node’s children.\n */\nexport const SKIP = 'skip'\n\n/**\n * Visit nodes, with ancestral information.\n *\n * This algorithm performs *depth-first* *tree traversal* in *preorder*\n * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).\n *\n * You can choose for which nodes `visitor` is called by passing a `test`.\n * For complex tests, you should test yourself in `visitor`, as it will be\n * faster and will have improved type information.\n *\n * Walking the tree is an intensive task.\n * Make use of the return values of the visitor when possible.\n * Instead of walking a tree multiple times, walk it once, use `unist-util-is`\n * to check if a node matches, and then perform different operations.\n *\n * You can change the tree.\n * See `Visitor` for more info.\n *\n * @param tree\n * Tree to traverse.\n * @param test\n * `unist-util-is`-compatible test\n * @param visitor\n * Handle each node.\n * @param reverse\n * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).\n * @returns\n * Nothing.\n */\nexport const visitParents =\n /**\n * @type {(\n * (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) &\n * (<Tree extends Node>(tree: Tree, visitor: BuildVisitor<Tree>, reverse?: boolean | null | undefined) => void)\n * )}\n */\n (\n /**\n * @param {Node} tree\n * @param {Test} test\n * @param {Visitor<Node>} visitor\n * @param {boolean | null | undefined} [reverse]\n * @returns {void}\n */\n function (tree, test, visitor, reverse) {\n if (typeof test === 'function' && typeof visitor !== 'function') {\n reverse = visitor\n // @ts-expect-error no visitor given, so `visitor` is test.\n visitor = test\n test = null\n }\n\n const is = convert(test)\n const step = reverse ? -1 : 1\n\n factory(tree, undefined, [])()\n\n /**\n * @param {Node} node\n * @param {number | undefined} index\n * @param {Array<Parent>} parents\n */\n function factory(node, index, parents) {\n /** @type {Record<string, unknown>} */\n // @ts-expect-error: hush\n const value = node && typeof node === 'object' ? node : {}\n\n if (typeof value.type === 'string') {\n const name =\n // `hast`\n typeof value.tagName === 'string'\n ? value.tagName\n : // `xast`\n typeof value.name === 'string'\n ? value.name\n : undefined\n\n Object.defineProperty(visit, 'name', {\n value:\n 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'\n })\n }\n\n return visit\n\n function visit() {\n /** @type {ActionTuple} */\n let result = []\n /** @type {ActionTuple} */\n let subresult\n /** @type {number} */\n let offset\n /** @type {Array<Parent>} */\n let grandparents\n\n if (!test || is(node, index, parents[parents.length - 1] || null)) {\n result = toResult(visitor(node, parents))\n\n if (result[0] === EXIT) {\n return result\n }\n }\n\n // @ts-expect-error looks like a parent.\n if (node.children && result[0] !== SKIP) {\n // @ts-expect-error looks like a parent.\n offset = (reverse ? node.children.length : -1) + step\n // @ts-expect-error looks like a parent.\n grandparents = parents.concat(node)\n\n // @ts-expect-error looks like a parent.\n while (offset > -1 && offset < node.children.length) {\n // @ts-expect-error looks like a parent.\n subresult = factory(node.children[offset], offset, grandparents)()\n\n if (subresult[0] === EXIT) {\n return subresult\n }\n\n offset =\n typeof subresult[1] === 'number' ? subresult[1] : offset + step\n }\n }\n\n return result\n }\n }\n }\n )\n\n/**\n * Turn a return value into a clean result.\n *\n * @param {VisitorResult} value\n * Valid return values from visitors.\n * @returns {ActionTuple}\n * Clean result.\n */\nfunction toResult(value) {\n if (Array.isArray(value)) {\n return value\n }\n\n if (typeof value === 'number') {\n return [CONTINUE, value]\n }\n\n return [value]\n}\n","/**\n * @typedef {import('unist').Node} Node\n * @typedef {import('unist').Parent} Parent\n * @typedef {import('unist-util-is').Test} Test\n * @typedef {import('unist-util-visit-parents').VisitorResult} VisitorResult\n * @typedef {import('./complex-types.js').Visitor} Visitor\n */\n\nimport {visitParents} from 'unist-util-visit-parents'\n\n/**\n * Visit children of tree which pass test.\n *\n * @param tree\n * Tree to walk\n * @param [test]\n * `unist-util-is`-compatible test\n * @param visitor\n * Function called for nodes that pass `test`.\n * @param reverse\n * Traverse in reverse preorder (NRL) instead of preorder (NLR) (default).\n */\nexport const visit =\n /**\n * @type {(\n * (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: import('./complex-types.js').BuildVisitor<Tree, Check>, reverse?: boolean) => void) &\n * (<Tree extends Node>(tree: Tree, visitor: import('./complex-types.js').BuildVisitor<Tree>, reverse?: boolean) => void)\n * )}\n */\n (\n /**\n * @param {Node} tree\n * @param {Test} test\n * @param {import('./complex-types.js').Visitor} visitor\n * @param {boolean} [reverse]\n */\n function (tree, test, visitor, reverse) {\n if (typeof test === 'function' && typeof visitor !== 'function') {\n reverse = visitor\n visitor = test\n test = null\n }\n\n visitParents(tree, test, overload, reverse)\n\n /**\n * @param {Node} node\n * @param {Array<Parent>} parents\n */\n function overload(node, parents) {\n const parent = parents[parents.length - 1]\n return visitor(\n node,\n parent ? parent.children.indexOf(node) : null,\n parent\n )\n }\n }\n )\n\nexport {CONTINUE, EXIT, SKIP} from 'unist-util-visit-parents'\n","/**\n * Converts a string to a valid variable name. If the string is already a valid variable name, returns the original string.\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport const toValidVarName = (str: string): string => {\n // Check if the string is a valid variable name\n if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) {\n return str; // If it is a valid variable name, return the original string\n } else {\n // If it is not a valid variable name, convert it to a valid variable name\n return str.replace(/[^0-9a-zA-Z_$]/g, '_').replace(/^([0-9])/, '_$1');\n }\n};\n\nexport const generateId = (pageName: string, index: number) => {\n return `_${toValidVarName(pageName)}_${index}`;\n};\n\n/**\n * remove .html extension and validate\n * @param routePath id from pathname\n * @returns normalized id\n */\nexport const normalizeId = (routePath: string) => {\n const result = routePath.replace(/\\.(.*)?$/, '');\n return toValidVarName(result);\n};\n\nexport const injectDemoBlockImport = (str: string, path: string): string => {\n return `\n import DemoBlock from ${JSON.stringify(path)};\n ${str}\n `;\n};\n","import path from 'path';\nimport { RSPRESS_TEMP_DIR } from '@rspress/shared';\n\nexport const staticPath = path.join(__dirname, '..', 'static');\n\nexport const demoBlockComponentPath = path.join(\n staticPath,\n 'global-components',\n 'DemoBlock.tsx',\n);\n\nexport const virtualDir = path.join(\n process.cwd(),\n 'node_modules',\n RSPRESS_TEMP_DIR,\n 'virtual-demo',\n);\n","import RspackVirtualModulePlugin from 'rspack-plugin-virtual-module';\nimport type { DemoInfo } from './types';\n\nexport const demos: DemoInfo = {};\n\nexport const demoRuntimeModule = new RspackVirtualModulePlugin({\n 'virtual-meta': 'export const demos = {}',\n});\n","import { join } from 'path';\nimport { writeFileSync } from 'fs';\nimport { virtualDir, staticPath } from './constant';\nimport type { DemoInfo } from './types';\nimport { toValidVarName } from './utils';\n\n// TODO: Support custom entry template files\nexport function generateEntry(\n demos: DemoInfo,\n framework: 'react' | 'solid',\n position: 'follow' | 'fixed',\n) {\n const sourceEntry: Record<string, string> = {};\n const entryCssPath = join(staticPath, 'global-styles', 'entry.css');\n if (position === 'follow') {\n Object.values(demos).forEach(routes => {\n routes.forEach(route => {\n const { id, path: demoPath } = route;\n const entry = join(virtualDir, `${id}.entry.tsx`);\n const solidEntry = `\n import { render } from 'solid-js/web';\n import ${JSON.stringify(entryCssPath)};\n import Demo from ${JSON.stringify(demoPath)};\n render(() => <Demo />, document.getElementById('root'));\n `;\n\n const reactEntry = `\n import { render } from 'react-dom';\n import ${JSON.stringify(entryCssPath)};\n import Demo from ${JSON.stringify(demoPath)};\n render(<Demo />, document.getElementById('root'));\n `;\n const entryContent = framework === 'react' ? reactEntry : solidEntry;\n writeFileSync(entry, entryContent);\n sourceEntry[id] = entry;\n });\n });\n } else {\n Object.entries(demos).forEach(([key, routes]) => {\n if (routes.length === 0) {\n return;\n }\n const reactContent = `\n import { render } from 'react-dom';\n import ${JSON.stringify(entryCssPath)};\n ${routes\n .map((demo, index) => {\n return `import Demo_${index} from ${JSON.stringify(demo.path)}`;\n })\n .join('\\n')}\n function App() {\n return (\n <div className=\"preview-container\">\n <div className=\"preview-nav\">{\"${routes[0].title}\"}</div>\n ${routes\n .map((demo, index) => {\n return `<Demo_${index} />`;\n })\n .join('\\n')}\n </div>\n )\n }\n render(<App /> , document.getElementById('root'));\n `;\n const solidContent = `\n import { render } from 'solid-js/web';\n import ${JSON.stringify(entryCssPath)};\n ${routes\n .map((demo, index) => {\n return `import Demo_${index} from ${JSON.stringify(demo.path)}`;\n })\n .join('\\n')}\n function App() {\n return (\n <div class=\"preview-container\">\n <div class=\"preview-nav\">{\"${routes[0].title}\"}</div>\n ${routes\n .map((_, index) => {\n return `<Demo_${index} />`;\n })\n .join('\\n')}\n </div>\n )\n }\n render(() => <App /> , document.getElementById('root'));\n `;\n const renderContent = framework === 'solid' ? solidContent : reactContent;\n const id = `_${toValidVarName(key)}`;\n const entry = join(virtualDir, `${id}.entry.tsx`);\n writeFileSync(entry, renderContent);\n sourceEntry[id] = entry;\n });\n }\n return sourceEntry;\n}\n"]}
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,eAAqB;AACrB,sBAAgB;AAChB,IAAAC,iBAIO;AACP,kBAIO;AACP,0BAA4B;AAC5B,0BAA4B;AAC5B,0BAA4B;AAC5B,oBAAmC;;;ACfnC,IAAAD,eAAuC;;;ACqKhC,IAAM;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYT,SAAU,MAAM;AACd,QAAI,SAAS,UAAa,SAAS,MAAM;AACvC,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,SAAS,UAAU;AAC5B,aAAO,YAAY,IAAI;AAAA,IACzB;AAEA,QAAI,OAAO,SAAS,UAAU;AAC5B,aAAO,MAAM,QAAQ,IAAI,IAAI,WAAW,IAAI,IAAI,aAAa,IAAI;AAAA,IACnE;AAEA,QAAI,OAAO,SAAS,YAAY;AAC9B,aAAO,YAAY,IAAI;AAAA,IACzB;AAEA,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AAAA;AAOJ,SAAS,WAAW,OAAO;AAEzB,QAAM,SAAS,CAAC;AAChB,MAAI,QAAQ;AAEZ,SAAO,EAAE,QAAQ,MAAM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AAA,MACR,eAAe;AAAA,QACb;AAAA,UACE;AAAA,UACA;AAAA,YACE;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,kBAAkB;AAAA,YAChB,mBAAK,YAAY,qBAAqB,eAAe;AAAA,MACvD;AAAA,IACF;AAAA,IACA;AAAA,IACA,kBAAc,mBAAK,YAAY,iBAAiB,GAAG,WAAW,MAAM;AAAA,EACtE;AACF","names":["import_path","import_shared","index","is","visit","path","routeMeta","fs","externalDemoIndex","demos","resolve","net"],"sources":["../src/index.ts","../src/remarkPlugin.ts","../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js","../../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/color.js","../../../node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/index.js","../../../node_modules/.pnpm/unist-util-visit@4.1.1/node_modules/unist-util-visit/index.js","../src/utils.ts","../src/constant.ts","../src/generate-entry.ts"],"sourcesContent":["import { join } from 'path';\nimport net from 'node:net';\nimport {\n type RouteMeta,\n type RspressPlugin,\n removeTrailingSlash,\n} from '@rspress/shared';\nimport {\n type RsbuildConfig,\n createRsbuild,\n mergeRsbuildConfig,\n} from '@rsbuild/core';\nimport { pluginSolid } from '@rsbuild/plugin-solid';\nimport { pluginBabel } from '@rsbuild/plugin-babel';\nimport { pluginReact } from '@rsbuild/plugin-react';\nimport { isEqual, cloneDeep } from 'lodash';\nimport { remarkCodeToDemo, demos } from './remarkPlugin';\nimport { staticPath } from './constant';\nimport type { Options, StartServerResult } from './types';\nimport { generateEntry } from './generate-entry';\n\n// global variables which need to be initialized in plugin\nlet routeMeta: RouteMeta[];\n\n/**\n * The plugin is used to preview component.\n */\nexport function pluginPreview(options?: Options): RspressPlugin {\n const {\n isMobile = false,\n iframeOptions = {},\n iframePosition = 'follow',\n defaultRenderMode = 'preview',\n } = options ?? {};\n const previewMode = options?.previewMode ?? isMobile ? 'iframe' : 'internal';\n const {\n devPort = 7890,\n framework = 'react',\n position = iframePosition,\n builderConfig = {},\n } = iframeOptions;\n const globalUIComponents =\n iframePosition === 'fixed'\n ? [join(staticPath, 'global-components', 'Device.tsx')]\n : [];\n const getRouteMeta = () => routeMeta;\n let lastDemos: typeof demos;\n let devServer: StartServerResult;\n let clientConfig: RsbuildConfig;\n const port = devPort;\n return {\n name: '@rspress/plugin-preview',\n config(config) {\n config.markdown = config.markdown || {};\n config.markdown.mdxRs = false;\n return config;\n },\n routeGenerated(routes: RouteMeta[]) {\n // init routeMeta\n routeMeta = routes;\n },\n async beforeBuild(_, isProd) {\n if (!isProd) {\n try {\n await new Promise((resolve, reject) => {\n const server = net.createServer();\n server.unref();\n server.on('error', reject);\n server.listen({ port, host: '0.0.0.0' }, () => {\n server.close(resolve);\n });\n });\n } catch (e: any) {\n if (e.code !== 'EADDRINUSE') {\n throw e;\n }\n\n throw new Error(\n `Port \"${port}\" is occupied, please choose another one.`,\n );\n }\n }\n },\n async afterBuild(config, isProd) {\n if (isEqual(demos, lastDemos)) {\n return;\n }\n lastDemos = cloneDeep(demos);\n await devServer?.server?.close();\n const sourceEntry = generateEntry(demos, framework, position);\n const outDir = join(config.outDir ?? 'doc_build', '~demo');\n if (Object.keys(sourceEntry).length === 0) {\n return;\n }\n const { html, source, output, performance } = clientConfig ?? {};\n const rsbuildConfig = mergeRsbuildConfig(\n {\n dev: {\n progressBar: false,\n },\n server: {\n port: devPort,\n printUrls: () => undefined,\n strictPort: true,\n },\n performance: {\n ...performance,\n printFileSize: false,\n },\n html,\n source: {\n ...source,\n entry: sourceEntry,\n },\n output: {\n ...output,\n assetPrefix: output?.assetPrefix\n ? `${removeTrailingSlash(output.assetPrefix)}/~demo`\n : '/~demo',\n distPath: {\n root: outDir,\n },\n // not copy files again\n copy: undefined,\n },\n },\n builderConfig,\n );\n const rsbuildInstance = await createRsbuild({\n rsbuildConfig,\n });\n if (framework === 'solid') {\n rsbuildInstance.addPlugins([\n pluginBabel({\n include: /\\.(?:jsx|tsx)$/,\n }),\n pluginSolid(),\n ]);\n }\n if (framework === 'react') {\n rsbuildInstance.addPlugins([pluginReact()]);\n }\n if (isProd) {\n rsbuildInstance.build();\n } else {\n devServer = await rsbuildInstance.startDevServer();\n }\n },\n builderConfig: {\n source: {\n include: [join(__dirname, '..')],\n },\n tools: {\n bundlerChain(chain) {\n chain.module\n .rule('Raw')\n .resourceQuery(/raw/)\n .type('asset/source')\n .end();\n\n chain.resolve.extensions.prepend('.md').prepend('.mdx');\n },\n },\n plugins: [\n {\n name: 'close-demo-server',\n setup: api => {\n api.modifyRsbuildConfig(config => {\n if (config.output?.targets?.every(target => target === 'web')) {\n // client build config\n clientConfig = config;\n }\n });\n api.onCloseDevServer(async () => {\n await devServer?.server?.close();\n });\n },\n },\n ],\n },\n extendPageData(pageData, isProd) {\n if (!isProd) {\n pageData.devPort = port;\n }\n },\n markdown: {\n remarkPlugins: [\n [\n remarkCodeToDemo,\n {\n getRouteMeta,\n position,\n previewMode,\n defaultRenderMode,\n },\n ],\n ],\n globalComponents: [\n join(staticPath, 'global-components', 'Container.tsx'),\n ],\n },\n globalUIComponents,\n globalStyles: join(staticPath, 'global-styles', `${previewMode}.css`),\n };\n}\n\nexport type { Options };\n","import { join, resolve, dirname } from 'path';\nimport { visit } from 'unist-util-visit';\nimport { normalizePosixPath } from '@rspress/shared';\nimport fs from '@rspress/shared/fs-extra';\nimport type { Plugin } from 'unified';\nimport type { Root } from 'mdast';\nimport type { MdxjsEsm } from 'mdast-util-mdxjs-esm';\nimport type { RemarkPluginOptions, DemoInfo } from './types';\nimport { injectDemoBlockImport, generateId } from './utils';\nimport { demoBlockComponentPath, virtualDir } from './constant';\n\nexport const demos: DemoInfo = {};\n\n/**\n * remark plugin to transform code to demo\n */\nexport const remarkCodeToDemo: Plugin<[RemarkPluginOptions], Root> = function ({\n getRouteMeta,\n previewMode,\n defaultRenderMode,\n position,\n}) {\n const routeMeta = getRouteMeta();\n fs.ensureDirSync(virtualDir);\n const data = this.data() as {\n pageMeta: Record<string, any>;\n };\n return (tree, vfile) => {\n const demoMdx: MdxjsEsm[] = [];\n const route = routeMeta.find(\n meta =>\n normalizePosixPath(meta.absolutePath) ===\n normalizePosixPath(vfile.path || vfile.history[0]),\n );\n if (!route) {\n return;\n }\n const { pageName } = route;\n // clear all demo in this pageName and recollect, bacause we may delete the demo\n demos[pageName] = [];\n let title = pageName;\n let index = 1;\n let externalDemoIndex = 0;\n\n function constructDemoNode(\n demoId: string,\n demoPath: string,\n currentNode: any,\n isMobileMode: boolean,\n // Only for external demo\n externalDemoIndex?: number,\n ) {\n if (isMobileMode) {\n const relativePathReg = new RegExp(/^\\.\\.?\\/.*$/);\n demos[pageName].push({\n title,\n id: demoId,\n path: relativePathReg.test(demoPath)\n ? resolve(vfile.dirname || dirname(vfile.path), demoPath)\n : demoPath,\n });\n } else {\n demoMdx.push(getASTNodeImport(`Demo${demoId}`, demoPath));\n }\n\n // get external demo content\n const tempVar = `externalDemoContent${externalDemoIndex}`;\n if (externalDemoIndex !== undefined) {\n // Such as `import externalDemoContent0 from '!!xxx?raw'`\n // `!!` prefix is used to avoid other loaders in rspack\n demoMdx.push(getASTNodeImport(tempVar, `!!${demoPath}?raw`));\n }\n\n if (isMobileMode && position === 'fixed') {\n // Only show the code block\n externalDemoIndex !== undefined &&\n Object.assign(currentNode, getExternalDemoContent(tempVar));\n } else {\n // Use container to show the code and view\n Object.assign(currentNode, {\n type: 'mdxJsxFlowElement',\n name: 'Container',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'isMobile',\n value: isMobileMode,\n },\n {\n type: 'mdxJsxAttribute',\n name: 'demoId',\n value: demoId,\n },\n ],\n children: [\n externalDemoIndex === undefined\n ? {\n ...currentNode,\n hasVisited: true,\n }\n : getExternalDemoContent(tempVar),\n isMobileMode\n ? {\n type: 'mdxJsxFlowElement',\n name: null,\n }\n : {\n type: 'mdxJsxFlowElement',\n name: `Demo${demoId}`,\n },\n ],\n });\n }\n }\n visit(tree, 'heading', node => {\n if (node.depth === 1) {\n if (node.children) {\n title = (node.children[0] as any)?.value || title;\n }\n }\n });\n\n // 1. External demo , use <code src=\"xxx\" /> to declare demo\n visit(tree, 'mdxJsxFlowElement', (node: any) => {\n if (node.name === 'code') {\n const src = node.attributes.find(\n (attr: { name: string; value: string }) => attr.name === 'src',\n )?.value;\n if (!src) {\n return;\n }\n\n // don't support expression syntax\n const currtentMode =\n node.attributes.find(\n (attr: { name: string; value: boolean }) =>\n attr.name === 'previewMode',\n )?.value ?? previewMode;\n\n // TODO: remove isMobileAttribute\n let isMobileMode = node.attributes.find(\n (attr: { name: string; value: boolean }) => attr.name === 'isMobile',\n )?.value;\n if (isMobileMode === undefined) {\n // isMobile is not specified, eg: <code />\n isMobileMode = currtentMode === 'iframe';\n } else if (isMobileMode === null) {\n // true by default, eg: <code isMobile />\n isMobileMode = true;\n } else if (typeof isMobileMode === 'object') {\n // jsx value, isMobileMode.value now must be string, even if input is\n // any complex struct rather than primitive type\n // eg: <code isMobile={ anyOfOrOther([true, false, 'true', 'false', {}]) } />\n isMobileMode = isMobileMode.value !== 'false';\n } else {\n // string value, eg: <code isMobile=\"true\" />\n isMobileMode = isMobileMode !== 'false';\n }\n\n const id = generateId(pageName, index++);\n constructDemoNode(id, src, node, isMobileMode, externalDemoIndex++);\n }\n });\n\n // 2. Internal demo, use ```j/tsx to declare demo\n visit(tree, 'code', node => {\n // hasVisited is a custom property\n if ('hasVisited' in node) {\n return;\n }\n\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const value = injectDemoBlockImport(node.value, demoBlockComponentPath);\n\n // do not anything for pure mode\n if (\n node?.meta?.includes('pure') ||\n (!node?.meta?.includes('preview') && defaultRenderMode === 'pure')\n ) {\n return;\n }\n\n // every code block can change their preview mode by meta\n const isMobileMode =\n node?.meta?.includes('mobile') ||\n node?.meta?.includes('iframe') ||\n (!node?.meta?.includes('web') &&\n !node?.meta?.includes('internal') &&\n previewMode === 'iframe');\n\n const id = generateId(pageName, index++);\n const virtualModulePath = join(virtualDir, `${id}.tsx`);\n constructDemoNode(id, virtualModulePath, node, isMobileMode);\n // Only when the content of the file changes, the file will be written\n // Avoid to trigger the hmr indefinitely\n if (fs.existsSync(virtualModulePath)) {\n const content = fs.readFileSync(virtualModulePath, 'utf-8');\n if (content === value) {\n return;\n }\n }\n fs.writeFileSync(virtualModulePath, value);\n }\n });\n\n tree.children.unshift(...demoMdx);\n\n if (demos[pageName].length > 0) {\n data.pageMeta.haveDemos = true;\n }\n };\n};\n\nconst getASTNodeImport = (name: string, from: string) =>\n ({\n type: 'mdxjsEsm',\n value: `import ${name} from ${JSON.stringify(from)}`,\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n body: [\n {\n type: 'ImportDeclaration',\n specifiers: [\n {\n type: 'ImportDefaultSpecifier',\n local: { type: 'Identifier', name },\n },\n ],\n source: {\n type: 'Literal',\n value: from,\n raw: `${JSON.stringify(from)}`,\n },\n },\n ],\n },\n },\n }) as MdxjsEsm;\n\nconst getExternalDemoContent = (tempVar: string) => ({\n /**\n * We create a empty parent node here. If we don't do this, the `pre` tag won't be rendered as our custom mdx component and will be rendered as a normal `pre` tag, which will cause the code block to be displayed incorrectly.\n */\n type: 'mdxJsxFlowElement',\n name: '',\n attributes: [],\n children: [\n {\n type: 'mdxJsxFlowElement',\n name: 'pre',\n attributes: [],\n children: [\n {\n type: 'mdxJsxFlowElement',\n name: 'code',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'className',\n value: 'language-tsx',\n },\n {\n type: 'mdxJsxAttribute',\n name: 'children',\n value: {\n type: 'mdxJsxExpressionAttribute',\n value: tempVar,\n data: {\n estree: {\n type: 'Program',\n body: [\n {\n type: 'ExpressionStatement',\n expression: {\n type: 'Identifier',\n name: tempVar,\n },\n },\n ],\n },\n },\n },\n },\n ],\n },\n ],\n },\n ],\n});\n","/**\n * @typedef {import('unist').Node} Node\n * @typedef {import('unist').Parent} Parent\n */\n\n/**\n * @typedef {Record<string, unknown>} Props\n * @typedef {null | undefined | string | Props | TestFunctionAnything | Array<string | Props | TestFunctionAnything>} Test\n * Check for an arbitrary node, unaware of TypeScript inferral.\n *\n * @callback TestFunctionAnything\n * Check if a node passes a test, unaware of TypeScript inferral.\n * @param {unknown} this\n * The given context.\n * @param {Node} node\n * A node.\n * @param {number | null | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | null | undefined} [parent]\n * The node’s parent.\n * @returns {boolean | void}\n * Whether this node passes the test.\n */\n\n/**\n * @template {Node} Kind\n * Node type.\n * @typedef {Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind> | Array<Kind['type'] | Partial<Kind> | TestFunctionPredicate<Kind>>} PredicateTest\n * Check for a node that can be inferred by TypeScript.\n */\n\n/**\n * Check if a node passes a certain test.\n *\n * @template {Node} Kind\n * Node type.\n * @callback TestFunctionPredicate\n * Complex test function for a node that can be inferred by TypeScript.\n * @param {Node} node\n * A node.\n * @param {number | null | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | null | undefined} [parent]\n * The node’s parent.\n * @returns {node is Kind}\n * Whether this node passes the test.\n */\n\n/**\n * @callback AssertAnything\n * Check that an arbitrary value is a node, unaware of TypeScript inferral.\n * @param {unknown} [node]\n * Anything (typically a node).\n * @param {number | null | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | null | undefined} [parent]\n * The node’s parent.\n * @returns {boolean}\n * Whether this is a node and passes a test.\n */\n\n/**\n * Check if a node is a node and passes a certain node test.\n *\n * @template {Node} Kind\n * Node type.\n * @callback AssertPredicate\n * Check that an arbitrary value is a specific node, aware of TypeScript.\n * @param {unknown} [node]\n * Anything (typically a node).\n * @param {number | null | undefined} [index]\n * The node’s position in its parent.\n * @param {Parent | null | undefined} [parent]\n * The node’s parent.\n * @returns {node is Kind}\n * Whether this is a node and passes a test.\n */\n\n/**\n * Check if `node` is a `Node` and whether it passes the given test.\n *\n * @param node\n * Thing to check, typically `Node`.\n * @param test\n * A check for a specific node.\n * @param index\n * The node’s position in its parent.\n * @param parent\n * The node’s parent.\n * @returns\n * Whether `node` is a node and passes a test.\n */\nexport const is =\n /**\n * @type {(\n * (() => false) &\n * (<Kind extends Node = Node>(node: unknown, test: PredicateTest<Kind>, index: number, parent: Parent, context?: unknown) => node is Kind) &\n * (<Kind extends Node = Node>(node: unknown, test: PredicateTest<Kind>, index?: null | undefined, parent?: null | undefined, context?: unknown) => node is Kind) &\n * ((node: unknown, test: Test, index: number, parent: Parent, context?: unknown) => boolean) &\n * ((node: unknown, test?: Test, index?: null | undefined, parent?: null | undefined, context?: unknown) => boolean)\n * )}\n */\n (\n /**\n * @param {unknown} [node]\n * @param {Test} [test]\n * @param {number | null | undefined} [index]\n * @param {Parent | null | undefined} [parent]\n * @param {unknown} [context]\n * @returns {boolean}\n */\n // eslint-disable-next-line max-params\n function is(node, test, index, parent, context) {\n const check = convert(test)\n\n if (\n index !== undefined &&\n index !== null &&\n (typeof index !== 'number' ||\n index < 0 ||\n index === Number.POSITIVE_INFINITY)\n ) {\n throw new Error('Expected positive finite index')\n }\n\n if (\n parent !== undefined &&\n parent !== null &&\n (!is(parent) || !parent.children)\n ) {\n throw new Error('Expected parent node')\n }\n\n if (\n (parent === undefined || parent === null) !==\n (index === undefined || index === null)\n ) {\n throw new Error('Expected both parent and index')\n }\n\n // @ts-expect-error Looks like a node.\n return node && node.type && typeof node.type === 'string'\n ? Boolean(check.call(context, node, index, parent))\n : false\n }\n )\n\n/**\n * Generate an assertion from a test.\n *\n * Useful if you’re going to test many nodes, for example when creating a\n * utility where something else passes a compatible test.\n *\n * The created function is a bit faster because it expects valid input only:\n * a `node`, `index`, and `parent`.\n *\n * @param test\n * * when nullish, checks if `node` is a `Node`.\n * * when `string`, works like passing `(node) => node.type === test`.\n * * when `function` checks if function passed the node is true.\n * * when `object`, checks that all keys in test are in node, and that they have (strictly) equal values.\n * * when `array`, checks if any one of the subtests pass.\n * @returns\n * An assertion.\n */\nexport const convert =\n /**\n * @type {(\n * (<Kind extends Node>(test: PredicateTest<Kind>) => AssertPredicate<Kind>) &\n * ((test?: Test) => AssertAnything)\n * )}\n */\n (\n /**\n * @param {Test} [test]\n * @returns {AssertAnything}\n */\n function (test) {\n if (test === undefined || test === null) {\n return ok\n }\n\n if (typeof test === 'string') {\n return typeFactory(test)\n }\n\n if (typeof test === 'object') {\n return Array.isArray(test) ? anyFactory(test) : propsFactory(test)\n }\n\n if (typeof test === 'function') {\n return castFactory(test)\n }\n\n throw new Error('Expected function, string, or object as test')\n }\n )\n\n/**\n * @param {Array<string | Props | TestFunctionAnything>} tests\n * @returns {AssertAnything}\n */\nfunction anyFactory(tests) {\n /** @type {Array<AssertAnything>} */\n const checks = []\n let index = -1\n\n while (++index < tests.length) {\n checks[index] = convert(tests[index])\n }\n\n return castFactory(any)\n\n /**\n * @this {unknown}\n * @param {Array<unknown>} parameters\n * @returns {boolean}\n */\n function any(...parameters) {\n let index = -1\n\n while (++index < checks.length) {\n if (checks[index].call(this, ...parameters)) return true\n }\n\n return false\n }\n}\n\n/**\n * Turn an object into a test for a node with a certain fields.\n *\n * @param {Props} check\n * @returns {AssertAnything}\n */\nfunction propsFactory(check) {\n return castFactory(all)\n\n /**\n * @param {Node} node\n * @returns {boolean}\n */\n function all(node) {\n /** @type {string} */\n let key\n\n for (key in check) {\n // @ts-expect-error: hush, it sure works as an index.\n if (node[key] !== check[key]) return false\n }\n\n return true\n }\n}\n\n/**\n * Turn a string into a test for a node with a certain type.\n *\n * @param {string} check\n * @returns {AssertAnything}\n */\nfunction typeFactory(check) {\n return castFactory(type)\n\n /**\n * @param {Node} node\n */\n function type(node) {\n return node && node.type === check\n }\n}\n\n/**\n * Turn a custom test into a test for a node that passes that test.\n *\n * @param {TestFunctionAnything} check\n * @returns {AssertAnything}\n */\nfunction castFactory(check) {\n return assertion\n\n /**\n * @this {unknown}\n * @param {unknown} node\n * @param {Array<unknown>} parameters\n * @returns {boolean}\n */\n function assertion(node, ...parameters) {\n return Boolean(\n node &&\n typeof node === 'object' &&\n 'type' in node &&\n // @ts-expect-error: fine.\n Boolean(check.call(this, node, ...parameters))\n )\n }\n}\n\nfunction ok() {\n return true\n}\n","/**\n * @param {string} d\n * @returns {string}\n */\nexport function color(d) {\n return '\\u001B[33m' + d + '\\u001B[39m'\n}\n","/**\n * @typedef {import('unist').Node} Node\n * @typedef {import('unist').Parent} Parent\n * @typedef {import('unist-util-is').Test} Test\n */\n\n/**\n * @typedef {boolean | 'skip'} Action\n * Union of the action types.\n *\n * @typedef {number} Index\n * Move to the sibling at `index` next (after node itself is completely\n * traversed).\n *\n * Useful if mutating the tree, such as removing the node the visitor is\n * currently on, or any of its previous siblings.\n * Results less than 0 or greater than or equal to `children.length` stop\n * traversing the parent.\n *\n * @typedef {[(Action | null | undefined | void)?, (Index | null | undefined)?]} ActionTuple\n * List with one or two values, the first an action, the second an index.\n *\n * @typedef {Action | ActionTuple | Index | null | undefined | void} VisitorResult\n * Any value that can be returned from a visitor.\n */\n\n/**\n * @template {Node} [Visited=Node]\n * Visited node type.\n * @template {Parent} [Ancestor=Parent]\n * Ancestor type.\n * @callback Visitor\n * Handle a node (matching `test`, if given).\n *\n * Visitors are free to transform `node`.\n * They can also transform the parent of node (the last of `ancestors`).\n *\n * Replacing `node` itself, if `SKIP` is not returned, still causes its\n * descendants to be walked (which is a bug).\n *\n * When adding or removing previous siblings of `node` (or next siblings, in\n * case of reverse), the `Visitor` should return a new `Index` to specify the\n * sibling to traverse after `node` is traversed.\n * Adding or removing next siblings of `node` (or previous siblings, in case\n * of reverse) is handled as expected without needing to return a new `Index`.\n *\n * Removing the children property of an ancestor still results in them being\n * traversed.\n * @param {Visited} node\n * Found node.\n * @param {Array<Ancestor>} ancestors\n * Ancestors of `node`.\n * @returns {VisitorResult}\n * What to do next.\n *\n * An `Index` is treated as a tuple of `[CONTINUE, Index]`.\n * An `Action` is treated as a tuple of `[Action]`.\n *\n * Passing a tuple back only makes sense if the `Action` is `SKIP`.\n * When the `Action` is `EXIT`, that action can be returned.\n * When the `Action` is `CONTINUE`, `Index` can be returned.\n */\n\n/**\n * @template {Node} [Tree=Node]\n * Tree type.\n * @template {Test} [Check=string]\n * Test type.\n * @typedef {Visitor<import('./complex-types.js').Matches<import('./complex-types.js').InclusiveDescendant<Tree>, Check>, Extract<import('./complex-types.js').InclusiveDescendant<Tree>, Parent>>} BuildVisitor\n * Build a typed `Visitor` function from a tree and a test.\n *\n * It will infer which values are passed as `node` and which as `parents`.\n */\n\nimport {convert} from 'unist-util-is'\nimport {color} from './color.js'\n\n/**\n * Continue traversing as normal.\n */\nexport const CONTINUE = true\n\n/**\n * Stop traversing immediately.\n */\nexport const EXIT = false\n\n/**\n * Do not traverse this node’s children.\n */\nexport const SKIP = 'skip'\n\n/**\n * Visit nodes, with ancestral information.\n *\n * This algorithm performs *depth-first* *tree traversal* in *preorder*\n * (**NLR**) or if `reverse` is given, in *reverse preorder* (**NRL**).\n *\n * You can choose for which nodes `visitor` is called by passing a `test`.\n * For complex tests, you should test yourself in `visitor`, as it will be\n * faster and will have improved type information.\n *\n * Walking the tree is an intensive task.\n * Make use of the return values of the visitor when possible.\n * Instead of walking a tree multiple times, walk it once, use `unist-util-is`\n * to check if a node matches, and then perform different operations.\n *\n * You can change the tree.\n * See `Visitor` for more info.\n *\n * @param tree\n * Tree to traverse.\n * @param test\n * `unist-util-is`-compatible test\n * @param visitor\n * Handle each node.\n * @param reverse\n * Traverse in reverse preorder (NRL) instead of the default preorder (NLR).\n * @returns\n * Nothing.\n */\nexport const visitParents =\n /**\n * @type {(\n * (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) &\n * (<Tree extends Node>(tree: Tree, visitor: BuildVisitor<Tree>, reverse?: boolean | null | undefined) => void)\n * )}\n */\n (\n /**\n * @param {Node} tree\n * @param {Test} test\n * @param {Visitor<Node>} visitor\n * @param {boolean | null | undefined} [reverse]\n * @returns {void}\n */\n function (tree, test, visitor, reverse) {\n if (typeof test === 'function' && typeof visitor !== 'function') {\n reverse = visitor\n // @ts-expect-error no visitor given, so `visitor` is test.\n visitor = test\n test = null\n }\n\n const is = convert(test)\n const step = reverse ? -1 : 1\n\n factory(tree, undefined, [])()\n\n /**\n * @param {Node} node\n * @param {number | undefined} index\n * @param {Array<Parent>} parents\n */\n function factory(node, index, parents) {\n /** @type {Record<string, unknown>} */\n // @ts-expect-error: hush\n const value = node && typeof node === 'object' ? node : {}\n\n if (typeof value.type === 'string') {\n const name =\n // `hast`\n typeof value.tagName === 'string'\n ? value.tagName\n : // `xast`\n typeof value.name === 'string'\n ? value.name\n : undefined\n\n Object.defineProperty(visit, 'name', {\n value:\n 'node (' + color(node.type + (name ? '<' + name + '>' : '')) + ')'\n })\n }\n\n return visit\n\n function visit() {\n /** @type {ActionTuple} */\n let result = []\n /** @type {ActionTuple} */\n let subresult\n /** @type {number} */\n let offset\n /** @type {Array<Parent>} */\n let grandparents\n\n if (!test || is(node, index, parents[parents.length - 1] || null)) {\n result = toResult(visitor(node, parents))\n\n if (result[0] === EXIT) {\n return result\n }\n }\n\n // @ts-expect-error looks like a parent.\n if (node.children && result[0] !== SKIP) {\n // @ts-expect-error looks like a parent.\n offset = (reverse ? node.children.length : -1) + step\n // @ts-expect-error looks like a parent.\n grandparents = parents.concat(node)\n\n // @ts-expect-error looks like a parent.\n while (offset > -1 && offset < node.children.length) {\n // @ts-expect-error looks like a parent.\n subresult = factory(node.children[offset], offset, grandparents)()\n\n if (subresult[0] === EXIT) {\n return subresult\n }\n\n offset =\n typeof subresult[1] === 'number' ? subresult[1] : offset + step\n }\n }\n\n return result\n }\n }\n }\n )\n\n/**\n * Turn a return value into a clean result.\n *\n * @param {VisitorResult} value\n * Valid return values from visitors.\n * @returns {ActionTuple}\n * Clean result.\n */\nfunction toResult(value) {\n if (Array.isArray(value)) {\n return value\n }\n\n if (typeof value === 'number') {\n return [CONTINUE, value]\n }\n\n return [value]\n}\n","/**\n * @typedef {import('unist').Node} Node\n * @typedef {import('unist').Parent} Parent\n * @typedef {import('unist-util-is').Test} Test\n * @typedef {import('unist-util-visit-parents').VisitorResult} VisitorResult\n * @typedef {import('./complex-types.js').Visitor} Visitor\n */\n\nimport {visitParents} from 'unist-util-visit-parents'\n\n/**\n * Visit children of tree which pass test.\n *\n * @param tree\n * Tree to walk\n * @param [test]\n * `unist-util-is`-compatible test\n * @param visitor\n * Function called for nodes that pass `test`.\n * @param reverse\n * Traverse in reverse preorder (NRL) instead of preorder (NLR) (default).\n */\nexport const visit =\n /**\n * @type {(\n * (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: import('./complex-types.js').BuildVisitor<Tree, Check>, reverse?: boolean) => void) &\n * (<Tree extends Node>(tree: Tree, visitor: import('./complex-types.js').BuildVisitor<Tree>, reverse?: boolean) => void)\n * )}\n */\n (\n /**\n * @param {Node} tree\n * @param {Test} test\n * @param {import('./complex-types.js').Visitor} visitor\n * @param {boolean} [reverse]\n */\n function (tree, test, visitor, reverse) {\n if (typeof test === 'function' && typeof visitor !== 'function') {\n reverse = visitor\n visitor = test\n test = null\n }\n\n visitParents(tree, test, overload, reverse)\n\n /**\n * @param {Node} node\n * @param {Array<Parent>} parents\n */\n function overload(node, parents) {\n const parent = parents[parents.length - 1]\n return visitor(\n node,\n parent ? parent.children.indexOf(node) : null,\n parent\n )\n }\n }\n )\n\nexport {CONTINUE, EXIT, SKIP} from 'unist-util-visit-parents'\n","/**\n * Converts a string to a valid variable name. If the string is already a valid variable name, returns the original string.\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport const toValidVarName = (str: string): string => {\n // Check if the string is a valid variable name\n if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) {\n return str; // If it is a valid variable name, return the original string\n }\n\n // If it is not a valid variable name, convert it to a valid variable name\n return str.replace(/[^0-9a-zA-Z_$]/g, '_').replace(/^([0-9])/, '_$1');\n};\n\nexport const generateId = (pageName: string, index: number) => {\n return `_${toValidVarName(pageName)}_${index}`;\n};\n\n/**\n * remove .html extension and validate\n * @param routePath id from pathname\n * @returns normalized id\n */\nexport const normalizeId = (routePath: string) => {\n const result = routePath.replace(/\\.(.*)?$/, '');\n return toValidVarName(result);\n};\n\nexport const injectDemoBlockImport = (str: string, path: string): string => {\n return `\n import DemoBlock from ${JSON.stringify(path)};\n ${str}\n `;\n};\n","import path from 'path';\nimport { RSPRESS_TEMP_DIR } from '@rspress/shared';\n\nexport const staticPath = path.join(__dirname, '..', 'static');\n\nexport const demoBlockComponentPath = path.join(\n staticPath,\n 'global-components',\n 'DemoBlock.tsx',\n);\n\nexport const virtualDir = path.join(\n process.cwd(),\n 'node_modules',\n RSPRESS_TEMP_DIR,\n 'virtual-demo',\n);\n","import { join } from 'path';\nimport { writeFileSync } from 'fs';\nimport { virtualDir, staticPath } from './constant';\nimport type { DemoInfo } from './types';\nimport { toValidVarName } from './utils';\n\n// TODO: Support custom entry template files\nexport function generateEntry(\n demos: DemoInfo,\n framework: 'react' | 'solid',\n position: 'follow' | 'fixed',\n) {\n const sourceEntry: Record<string, string> = {};\n const entryCssPath = join(staticPath, 'global-styles', 'entry.css');\n if (position === 'follow') {\n Object.values(demos).forEach(routes => {\n routes.forEach(route => {\n const { id, path: demoPath } = route;\n const entry = join(virtualDir, `${id}.entry.tsx`);\n const solidEntry = `\n import { render } from 'solid-js/web';\n import ${JSON.stringify(entryCssPath)};\n import Demo from ${JSON.stringify(demoPath)};\n render(() => <Demo />, document.getElementById('root'));\n `;\n\n const reactEntry = `\n import { render } from 'react-dom';\n import ${JSON.stringify(entryCssPath)};\n import Demo from ${JSON.stringify(demoPath)};\n render(<Demo />, document.getElementById('root'));\n `;\n const entryContent = framework === 'react' ? reactEntry : solidEntry;\n writeFileSync(entry, entryContent);\n sourceEntry[id] = entry;\n });\n });\n } else {\n Object.entries(demos).forEach(([key, routes]) => {\n if (routes.length === 0) {\n return;\n }\n const reactContent = `\n import { render } from 'react-dom';\n import ${JSON.stringify(entryCssPath)};\n ${routes\n .map((demo, index) => {\n return `import Demo_${index} from ${JSON.stringify(demo.path)}`;\n })\n .join('\\n')}\n function App() {\n return (\n <div className=\"preview-container\">\n <div className=\"preview-nav\">{\"${routes[0].title}\"}</div>\n ${routes\n .map((demo, index) => {\n return `<Demo_${index} />`;\n })\n .join('\\n')}\n </div>\n )\n }\n render(<App /> , document.getElementById('root'));\n `;\n const solidContent = `\n import { render } from 'solid-js/web';\n import ${JSON.stringify(entryCssPath)};\n ${routes\n .map((demo, index) => {\n return `import Demo_${index} from ${JSON.stringify(demo.path)}`;\n })\n .join('\\n')}\n function App() {\n return (\n <div class=\"preview-container\">\n <div class=\"preview-nav\">{\"${routes[0].title}\"}</div>\n ${routes\n .map((_, index) => {\n return `<Demo_${index} />`;\n })\n .join('\\n')}\n </div>\n )\n }\n render(() => <App /> , document.getElementById('root'));\n `;\n const renderContent = framework === 'solid' ? solidContent : reactContent;\n const id = `_${toValidVarName(key)}`;\n const entry = join(virtualDir, `${id}.entry.tsx`);\n writeFileSync(entry, renderContent);\n sourceEntry[id] = entry;\n });\n }\n return sourceEntry;\n}\n"]}
|
package/dist/utils.js
CHANGED
@@ -29,9 +29,8 @@ module.exports = __toCommonJS(utils_exports);
|
|
29
29
|
var toValidVarName = (str) => {
|
30
30
|
if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) {
|
31
31
|
return str;
|
32
|
-
} else {
|
33
|
-
return str.replace(/[^0-9a-zA-Z_$]/g, "_").replace(/^([0-9])/, "_$1");
|
34
32
|
}
|
33
|
+
return str.replace(/[^0-9a-zA-Z_$]/g, "_").replace(/^([0-9])/, "_$1");
|
35
34
|
};
|
36
35
|
var generateId = (pageName, index) => {
|
37
36
|
return `_${toValidVarName(pageName)}_${index}`;
|
package/dist/utils.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,iBAAiB,CAAC,QAAwB;AAErD,MAAI,6BAA6B,KAAK,GAAG,GAAG;AAC1C,WAAO;AAAA,EACT
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAKO,IAAM,iBAAiB,CAAC,QAAwB;AAErD,MAAI,6BAA6B,KAAK,GAAG,GAAG;AAC1C,WAAO;AAAA,EACT;AAGA,SAAO,IAAI,QAAQ,mBAAmB,GAAG,EAAE,QAAQ,YAAY,KAAK;AACtE;AAEO,IAAM,aAAa,CAAC,UAAkB,UAAkB;AAC7D,SAAO,IAAI,eAAe,QAAQ,CAAC,IAAI,KAAK;AAC9C;AAOO,IAAM,cAAc,CAAC,cAAsB;AAChD,QAAM,SAAS,UAAU,QAAQ,YAAY,EAAE;AAC/C,SAAO,eAAe,MAAM;AAC9B;AAEO,IAAM,wBAAwB,CAAC,KAAa,SAAyB;AAC1E,SAAO;AAAA,4BACmB,KAAK,UAAU,IAAI,CAAC;AAAA,MAC1C,GAAG;AAAA;AAET","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/**\n * Converts a string to a valid variable name. If the string is already a valid variable name, returns the original string.\n * @param str - The string to convert.\n * @returns The converted string.\n */\nexport const toValidVarName = (str: string): string => {\n // Check if the string is a valid variable name\n if (/^[a-zA-Z_$][0-9a-zA-Z_$]*$/.test(str)) {\n return str; // If it is a valid variable name, return the original string\n }\n\n // If it is not a valid variable name, convert it to a valid variable name\n return str.replace(/[^0-9a-zA-Z_$]/g, '_').replace(/^([0-9])/, '_$1');\n};\n\nexport const generateId = (pageName: string, index: number) => {\n return `_${toValidVarName(pageName)}_${index}`;\n};\n\n/**\n * remove .html extension and validate\n * @param routePath id from pathname\n * @returns normalized id\n */\nexport const normalizeId = (routePath: string) => {\n const result = routePath.replace(/\\.(.*)?$/, '');\n return toValidVarName(result);\n};\n\nexport const injectDemoBlockImport = (str: string, path: string): string => {\n return `\n import DemoBlock from ${JSON.stringify(path)};\n ${str}\n `;\n};\n"]}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspress/plugin-preview",
|
3
|
-
"version": "0.0.0-next-
|
3
|
+
"version": "0.0.0-next-20240319081819",
|
4
4
|
"description": "A plugin for rspress to preview the code block in markdown/mdx file.",
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
6
6
|
"repository": {
|
@@ -17,17 +17,16 @@
|
|
17
17
|
},
|
18
18
|
"dependencies": {
|
19
19
|
"@mdx-js/mdx": "2.2.1",
|
20
|
-
"@rsbuild/core": "0.4.
|
21
|
-
"@rsbuild/plugin-solid": "0.4.
|
22
|
-
"@rsbuild/plugin-babel": "0.4.
|
23
|
-
"@rsbuild/plugin-react": "0.4.
|
20
|
+
"@rsbuild/core": "0.4.15",
|
21
|
+
"@rsbuild/plugin-solid": "0.4.15",
|
22
|
+
"@rsbuild/plugin-babel": "0.4.15",
|
23
|
+
"@rsbuild/plugin-react": "0.4.15",
|
24
24
|
"get-port": "6.1.2",
|
25
25
|
"qrcode.react": "^3.1.0",
|
26
26
|
"remark-gfm": "3.0.1",
|
27
|
-
"rspack-plugin-virtual-module": "0.1.12",
|
28
27
|
"lodash": "4.17.21",
|
29
|
-
"@rspress/
|
30
|
-
"@rspress/
|
28
|
+
"@rspress/theme-default": "0.0.0-next-20240319081819",
|
29
|
+
"@rspress/shared": "0.0.0-next-20240319081819"
|
31
30
|
},
|
32
31
|
"devDependencies": {
|
33
32
|
"@types/mdast": "^3.0.10",
|
@@ -46,7 +45,7 @@
|
|
46
45
|
"peerDependencies": {
|
47
46
|
"react": ">=17",
|
48
47
|
"react-router-dom": "^6.8.1",
|
49
|
-
"@rspress/core": "0.0.0-next-
|
48
|
+
"@rspress/core": "0.0.0-next-20240319081819"
|
50
49
|
},
|
51
50
|
"files": [
|
52
51
|
"dist",
|
@@ -1,6 +1,5 @@
|
|
1
|
-
import { usePageData, withBase } from '@rspress/core/runtime';
|
2
|
-
import { useCallback, useEffect, useState } from 'react';
|
3
|
-
import { demos } from 'virtual-meta';
|
1
|
+
import { usePageData, withBase, NoSSR } from '@rspress/core/runtime';
|
2
|
+
import { useCallback, useEffect, useState, useMemo } from 'react';
|
4
3
|
import { normalizeId } from '../../dist/utils';
|
5
4
|
import MobileOperation from './common/mobile-operation';
|
6
5
|
import './Device.scss';
|
@@ -10,7 +9,7 @@ export default () => {
|
|
10
9
|
const pageName = `${normalizeId(page.pagePath)}`;
|
11
10
|
const demoId = `_${pageName}`;
|
12
11
|
const url = `~demo/${demoId}`;
|
13
|
-
const haveDemos =
|
12
|
+
const { haveDemos } = page;
|
14
13
|
|
15
14
|
const getPageUrl = (url: string) => {
|
16
15
|
if (page?.devPort) {
|
@@ -75,11 +74,14 @@ export default () => {
|
|
75
74
|
|
76
75
|
return haveDemos ? (
|
77
76
|
<div className="fixed-device">
|
78
|
-
<
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
77
|
+
<NoSSR>
|
78
|
+
<iframe
|
79
|
+
// refresh when load the iframe, then remove NoSSR
|
80
|
+
src={getPageUrl(url)}
|
81
|
+
className="fixed-iframe"
|
82
|
+
key={iframeKey}
|
83
|
+
></iframe>
|
84
|
+
</NoSSR>
|
83
85
|
<MobileOperation
|
84
86
|
url={getPageUrl(url)}
|
85
87
|
className="fixed-operation"
|