@rspress/plugin-preview 1.23.0 → 1.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -33,7 +33,7 @@ __export(src_exports, {
33
33
  pluginPreview: () => pluginPreview
34
34
  });
35
35
  module.exports = __toCommonJS(src_exports);
36
- var import_path4 = require("path");
36
+ var import_node_path4 = require("path");
37
37
  var import_node_net = __toESM(require("net"));
38
38
  var import_shared3 = require("@rspress/shared");
39
39
  var import_core = require("@rsbuild/core");
@@ -43,7 +43,7 @@ var import_plugin_react = require("@rsbuild/plugin-react");
43
43
  var import_lodash = require("lodash");
44
44
 
45
45
  // src/remarkPlugin.ts
46
- var import_path2 = require("path");
46
+ var import_node_path2 = require("path");
47
47
 
48
48
  // ../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js
49
49
  var convert = (
@@ -257,15 +257,15 @@ var injectDemoBlockImport = (str, path2) => {
257
257
  };
258
258
 
259
259
  // src/constant.ts
260
- var import_path = __toESM(require("path"));
260
+ var import_node_path = __toESM(require("path"));
261
261
  var import_shared = require("@rspress/shared");
262
- var staticPath = import_path.default.join(__dirname, "..", "static");
263
- var demoBlockComponentPath = import_path.default.join(
262
+ var staticPath = import_node_path.default.join(__dirname, "..", "static");
263
+ var demoBlockComponentPath = import_node_path.default.join(
264
264
  staticPath,
265
265
  "global-components",
266
266
  "DemoBlock.tsx"
267
267
  );
268
- var virtualDir = import_path.default.join(
268
+ var virtualDir = import_node_path.default.join(
269
269
  process.cwd(),
270
270
  "node_modules",
271
271
  import_shared.RSPRESS_TEMP_DIR,
@@ -382,7 +382,7 @@ var remarkCodeToDemo = function({
382
382
  demos[pageName].push({
383
383
  title,
384
384
  id: demoId,
385
- path: relativePathReg.test(demoPath) ? (0, import_path2.resolve)(vfile.dirname || (0, import_path2.dirname)(vfile.path), demoPath) : demoPath
385
+ path: relativePathReg.test(demoPath) ? (0, import_node_path2.resolve)(vfile.dirname || (0, import_node_path2.dirname)(vfile.path), demoPath) : demoPath
386
386
  });
387
387
  } else {
388
388
  demoMdx.push(getASTNodeImport(`Demo${demoId}`, demoPath));
@@ -476,7 +476,7 @@ var remarkCodeToDemo = function({
476
476
  );
477
477
  const isMobileMode = node?.meta?.includes("mobile") || node?.meta?.includes("iframe") || !node?.meta?.includes("web") && !node?.meta?.includes("internal") && previewMode === "iframe";
478
478
  const id = generateId(pageName, index++);
479
- const virtualModulePath = (0, import_path2.join)(virtualDir, `${id}.tsx`);
479
+ const virtualModulePath = (0, import_node_path2.join)(virtualDir, `${id}.tsx`);
480
480
  constructDemoNode(id, virtualModulePath, node, isMobileMode);
481
481
  if (import_fs_extra.default.existsSync(virtualModulePath)) {
482
482
  const content = import_fs_extra.default.readFileSync(virtualModulePath, "utf-8");
@@ -495,16 +495,16 @@ var remarkCodeToDemo = function({
495
495
  };
496
496
 
497
497
  // src/generate-entry.ts
498
- var import_path3 = require("path");
499
- var import_fs = require("fs");
498
+ var import_node_path3 = require("path");
499
+ var import_node_fs = require("fs");
500
500
  function generateEntry(demos2, framework, position) {
501
501
  const sourceEntry = {};
502
- const entryCssPath = (0, import_path3.join)(staticPath, "global-styles", "entry.css");
502
+ const entryCssPath = (0, import_node_path3.join)(staticPath, "global-styles", "entry.css");
503
503
  if (position === "follow") {
504
504
  Object.values(demos2).forEach((routes) => {
505
505
  routes.forEach((route) => {
506
506
  const { id, path: demoPath } = route;
507
- const entry = (0, import_path3.join)(virtualDir, `${id}.entry.tsx`);
507
+ const entry = (0, import_node_path3.join)(virtualDir, `${id}.entry.tsx`);
508
508
  const solidEntry = `
509
509
  import { render } from 'solid-js/web';
510
510
  import ${JSON.stringify(entryCssPath)};
@@ -518,7 +518,7 @@ function generateEntry(demos2, framework, position) {
518
518
  render(<Demo />, document.getElementById('root'));
519
519
  `;
520
520
  const entryContent = framework === "react" ? reactEntry : solidEntry;
521
- (0, import_fs.writeFileSync)(entry, entryContent);
521
+ (0, import_node_fs.writeFileSync)(entry, entryContent);
522
522
  sourceEntry[id] = entry;
523
523
  });
524
524
  });
@@ -565,8 +565,8 @@ function generateEntry(demos2, framework, position) {
565
565
  `;
566
566
  const renderContent = framework === "solid" ? solidContent : reactContent;
567
567
  const id = `_${toValidVarName(key)}`;
568
- const entry = (0, import_path3.join)(virtualDir, `${id}.entry.tsx`);
569
- (0, import_fs.writeFileSync)(entry, renderContent);
568
+ const entry = (0, import_node_path3.join)(virtualDir, `${id}.entry.tsx`);
569
+ (0, import_node_fs.writeFileSync)(entry, renderContent);
570
570
  sourceEntry[id] = entry;
571
571
  });
572
572
  }
@@ -592,7 +592,7 @@ function pluginPreview(options) {
592
592
  position = iframePosition,
593
593
  builderConfig = {}
594
594
  } = iframeOptions;
595
- const globalUIComponents = position === "fixed" ? [(0, import_path4.join)(staticPath, "global-components", "Device.tsx")] : [];
595
+ const globalUIComponents = position === "fixed" ? [(0, import_node_path4.join)(staticPath, "global-components", "Device.tsx")] : [];
596
596
  const getRouteMeta = () => routeMeta;
597
597
  let lastDemos;
598
598
  let devServer;
@@ -636,7 +636,7 @@ function pluginPreview(options) {
636
636
  lastDemos = (0, import_lodash.cloneDeep)(demos);
637
637
  await devServer?.server?.close();
638
638
  const sourceEntry = generateEntry(demos, framework, position);
639
- const outDir = (0, import_path4.join)(config.outDir ?? "doc_build", "~demo");
639
+ const outDir = (0, import_node_path4.join)(config.outDir ?? "doc_build", "~demo");
640
640
  if (Object.keys(sourceEntry).length === 0) {
641
641
  return;
642
642
  }
@@ -698,7 +698,7 @@ function pluginPreview(options) {
698
698
  },
699
699
  builderConfig: {
700
700
  source: {
701
- include: [(0, import_path4.join)(__dirname, "..")]
701
+ include: [(0, import_node_path4.join)(__dirname, "..")]
702
702
  },
703
703
  tools: {
704
704
  bundlerChain(chain) {
@@ -742,11 +742,11 @@ function pluginPreview(options) {
742
742
  ]
743
743
  ],
744
744
  globalComponents: [
745
- (0, import_path4.join)(staticPath, "global-components", "Container.tsx")
745
+ (0, import_node_path4.join)(staticPath, "global-components", "Container.tsx")
746
746
  ]
747
747
  },
748
748
  globalUIComponents,
749
- globalStyles: (0, import_path4.join)(staticPath, "global-styles", `${previewMode}.css`)
749
+ globalStyles: (0, import_node_path4.join)(staticPath, "global-styles", `${previewMode}.css`)
750
750
  };
751
751
  }
752
752
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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,QAAQ;AAC7B,WAAO,KAAK,IAAI,QAAQ,MAAM,KAAK,CAAC;AAAA,EACtC;AAEA,SAAO,YAAY,GAAG;AAOtB,WAAS,OAAO,YAAY;AAC1B,QAAIE,SAAQ;AAEZ,WAAO,EAAEA,SAAQ,O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AAI,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,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"],"ignoreList":[],"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/ast-helpers.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\nconst DEFAULT_PREVIEW_LANGUAGES = ['jsx', 'tsx'];\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 previewLanguages = DEFAULT_PREVIEW_LANGUAGES,\n previewCodeTransform = ({ code }: { code: string }) => code,\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 position === '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 plugins: config?.builderPlugins,\n },\n builderConfig,\n );\n const rsbuildInstance = await createRsbuild({\n rsbuildConfig,\n });\n\n const { pluginSass } = await import('@rsbuild/plugin-sass');\n const { pluginLess } = await import('@rsbuild/plugin-less');\n\n rsbuildInstance.addPlugins([pluginSass(), pluginLess()]);\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 previewLanguages,\n previewCodeTransform,\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';\nimport { getASTNodeImport, getExternalDemoContent } from './ast-helpers';\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 previewLanguages,\n previewCodeTransform,\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 '!!foo?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=\"foo\" /> 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, such as using ```jsx to declare demo\n visit(tree, 'code', node => {\n // hasVisited is a custom property\n if ('hasVisited' in node) {\n return;\n }\n if (node.lang && previewLanguages.includes(node.lang)) {\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 const value = injectDemoBlockImport(\n previewCodeTransform({\n language: node.lang,\n code: node.value,\n }),\n demoBlockComponentPath,\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","/**\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 { MdxjsEsm } from 'mdast-util-mdxjs-esm';\n\nexport const 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\nexport const 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","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,oBAAqB;AACrB,sBAAgB;AAChB,IAAAC,iBAIO;AACP,kBAIO;AACP,0BAA4B;AAC5B,0BAA4B;AAC5B,0BAA4B;AAC5B,oBAAmC;;;ACfnC,IAAAD,oBAAuC;;;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,QAAIE,SAAQ;AAEZ,WAAO,EAAEA,SAAQ,OAAO,QAAQ;AAC9B,UAAI,OAAOA,MAAK,EAAE,KAAK,MAAM,GAAG,UAAU;AAAG,eAAO;AAAA,IAC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AA,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,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,kBAAkB;AAAA,YAChB,wBAAK,YAAY,qBAAqB,eAAe;AAAA,MACvD;AAAA,IACF;AAAA,IACA;AAAA,IACA,kBAAc,wBAAK,YAAY,iBAAiB,GAAG,WAAW,MAAM;AAAA,EACtE;AACF","names":["import_node_path","import_shared","index","is","visit","path","routeMeta","fs","externalDemoIndex","demos","resolve","net"],"ignoreList":[],"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/ast-helpers.ts","../src/generate-entry.ts"],"sourcesContent":["import { join } from 'node: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\nconst DEFAULT_PREVIEW_LANGUAGES = ['jsx', 'tsx'];\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 previewLanguages = DEFAULT_PREVIEW_LANGUAGES,\n previewCodeTransform = ({ code }: { code: string }) => code,\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 position === '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 plugins: config?.builderPlugins,\n },\n builderConfig,\n );\n const rsbuildInstance = await createRsbuild({\n rsbuildConfig,\n });\n\n const { pluginSass } = await import('@rsbuild/plugin-sass');\n const { pluginLess } = await import('@rsbuild/plugin-less');\n\n rsbuildInstance.addPlugins([pluginSass(), pluginLess()]);\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 previewLanguages,\n previewCodeTransform,\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 'node: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';\nimport { getASTNodeImport, getExternalDemoContent } from './ast-helpers';\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 previewLanguages,\n previewCodeTransform,\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 '!!foo?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=\"foo\" /> 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, such as using ```jsx to declare demo\n visit(tree, 'code', node => {\n // hasVisited is a custom property\n if ('hasVisited' in node) {\n return;\n }\n if (node.lang && previewLanguages.includes(node.lang)) {\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 const value = injectDemoBlockImport(\n previewCodeTransform({\n language: node.lang,\n code: node.value,\n }),\n demoBlockComponentPath,\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","/**\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 'node: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 type { MdxjsEsm } from 'mdast-util-mdxjs-esm';\n\nexport const 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\nexport const 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","import { join } from 'node:path';\nimport { writeFileSync } from 'node: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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-preview",
3
- "version": "1.23.0",
3
+ "version": "1.24.0",
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,22 +17,22 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "@mdx-js/mdx": "2.3.0",
20
- "@rsbuild/core": "0.7.0",
21
- "@rsbuild/plugin-less": "0.7.0",
22
- "@rsbuild/plugin-sass": "0.7.0",
23
- "@rsbuild/plugin-solid": "0.7.0",
24
- "@rsbuild/plugin-babel": "0.7.0",
25
- "@rsbuild/plugin-react": "0.7.0",
20
+ "@rsbuild/core": "0.7.3",
21
+ "@rsbuild/plugin-babel": "0.7.3",
22
+ "@rsbuild/plugin-less": "0.7.3",
23
+ "@rsbuild/plugin-react": "0.7.3",
24
+ "@rsbuild/plugin-sass": "0.7.3",
25
+ "@rsbuild/plugin-solid": "0.7.3",
26
+ "lodash": "4.17.21",
26
27
  "qrcode.react": "^3.1.0",
27
28
  "remark-gfm": "3.0.1",
28
- "lodash": "4.17.21",
29
- "@rspress/shared": "1.23.0",
30
- "@rspress/theme-default": "1.23.0"
29
+ "@rspress/shared": "1.24.0",
30
+ "@rspress/theme-default": "1.24.0"
31
31
  },
32
32
  "devDependencies": {
33
+ "@types/lodash": "^4.17.0",
33
34
  "@types/mdast": "^3.0.10",
34
35
  "@types/node": "^18.11.17",
35
- "@types/lodash": "^4.17.0",
36
36
  "@types/react": "^18",
37
37
  "@types/react-dom": "^18",
38
38
  "mdast-util-mdxjs-esm": "^1.3.0",