@rspress/plugin-playground 1.10.1 → 1.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli/cjs/index.js
CHANGED
|
@@ -314,7 +314,7 @@ var getNodeMeta = (node, metaName) => {
|
|
|
314
314
|
};
|
|
315
315
|
|
|
316
316
|
// src/cli/remarkPlugin.ts
|
|
317
|
-
var import_path2 =
|
|
317
|
+
var import_path2 = require("path");
|
|
318
318
|
init_unist_util_visit();
|
|
319
319
|
var import_fs_extra = __toESM(require("@rspress/shared/fs-extra"));
|
|
320
320
|
function createPlaygroundNode(currentNode, attrs) {
|
|
@@ -336,7 +336,7 @@ var remarkPlugin = ({
|
|
|
336
336
|
const routeMeta2 = getRouteMeta();
|
|
337
337
|
return (tree, vfile) => {
|
|
338
338
|
const route = routeMeta2.find(
|
|
339
|
-
(meta) => meta.absolutePath === (vfile.path || vfile.history[0])
|
|
339
|
+
(meta) => (0, import_path2.resolve)(meta.absolutePath) === (0, import_path2.resolve)(vfile.path || vfile.history[0])
|
|
340
340
|
);
|
|
341
341
|
if (!route) {
|
|
342
342
|
return;
|
|
@@ -347,7 +347,7 @@ var remarkPlugin = ({
|
|
|
347
347
|
if (!src) {
|
|
348
348
|
return;
|
|
349
349
|
}
|
|
350
|
-
const demoPath = (0, import_path2.join)(import_path2.
|
|
350
|
+
const demoPath = (0, import_path2.join)((0, import_path2.dirname)(route.absolutePath), src);
|
|
351
351
|
if (!import_fs_extra.default.existsSync(demoPath)) {
|
|
352
352
|
return;
|
|
353
353
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0MA,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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AAK,KAAK,YAAY,qBAAqB,gBAAgB;AAAA,MACjE;AAAA,IACF;AAAA,IACA,cAAc,aAAAA,QAAK,KAAK,YAAY,iBAAiB,SAAS;AAAA,EAChE;AACF","names":["index","init_lib","is","visit","import_path","path","oxc","routeMeta","fs","code"],"sources":["../../../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js","../../../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/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-parents@5.1.3/node_modules/unist-util-visit-parents/index.js","../../../../../node_modules/.pnpm/unist-util-visit@4.1.1/node_modules/unist-util-visit/index.js","../../../src/cli/index.ts","../../../src/cli/constant.ts","../../../src/cli/utils.ts","../../../src/cli/remarkPlugin.ts","../../../src/web/constant.ts","../../../src/web/utils.ts"],"sourcesContent":["/**\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 * @typedef {import('./lib/index.js').Test} Test\n * @typedef {import('./lib/index.js').TestFunctionAnything} TestFunctionAnything\n * @typedef {import('./lib/index.js').AssertAnything} AssertAnything\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').PredicateTest<Kind>} PredicateTest\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').TestFunctionPredicate<Kind>} TestFunctionPredicate\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').AssertPredicate<Kind>} AssertPredicate\n */\n\nexport {is, convert} from './lib/index.js'\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","// Note: types exported from `index.d.ts`\nexport {CONTINUE, EXIT, SKIP, visitParents} from './lib/index.js'\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","import path, { join } from 'path';\nimport { type RouteMeta, type RspressPlugin } from '@rspress/shared';\nimport { RspackVirtualModulePlugin } from 'rspack-plugin-virtual-module';\nimport type {\n loader,\n EditorProps as MonacoEditorProps,\n} from '@monaco-editor/react';\nimport { type Code } from 'mdast';\nimport { staticPath } from './constant';\nimport { getNodeAttribute, parseImports } from './utils';\nimport { remarkPlugin } from './remarkPlugin';\nimport { DEFAULT_BABEL_URL, DEFAULT_MONACO_URL } from '@/web/constant';\nimport { normalizeUrl } from '@/web/utils';\n\ninterface PlaygroundOptions {\n render: string;\n include: Array<string | [string, string]>;\n\n defaultDirection: 'horizontal' | 'vertical';\n editorPosition: 'left' | 'right';\n\n babelUrl: string;\n\n monacoLoader: Parameters<typeof loader.config>[0];\n monacoOptions: MonacoEditorProps['options'];\n /**\n * determine how to handle a internal code block without meta\n * @default 'playground'\n */\n defaultRenderMode?: 'pure' | 'playground';\n}\n\n// eslint-disable-next-line import/no-mutable-exports\nexport let routeMeta: RouteMeta[];\n\n/**\n * The plugin is used to preview component.\n */\nexport function pluginPlayground(\n options?: Partial<PlaygroundOptions>,\n): RspressPlugin {\n const {\n render = '',\n include,\n defaultDirection = 'horizontal',\n editorPosition = 'left',\n babelUrl = '',\n monacoLoader = {},\n monacoOptions = {},\n defaultRenderMode = 'playground',\n } = options || {};\n\n const playgroundVirtualModule = new RspackVirtualModulePlugin({});\n const getRouteMeta = () => routeMeta;\n\n if (render && !/Playground\\.(jsx?|tsx?)$/.test(render)) {\n throw new Error(\n '[Playground]: render should ends with Playground.(jsx?|tsx?)',\n );\n }\n\n const preloads: string[] = [];\n const monacoPrefix = monacoLoader.paths?.vs || DEFAULT_MONACO_URL;\n preloads.push(normalizeUrl(`${monacoPrefix}/loader.js`));\n preloads.push(normalizeUrl(`${monacoPrefix}/editor/editor.main.js`));\n\n return {\n name: '@rspress/plugin-playground',\n config(config, { removePlugin }) {\n config.markdown = config.markdown || {};\n config.markdown.mdxRs = false;\n // The preview and playground plugin are mutually conflicting.\n removePlugin('@rspress/plugin-preview');\n return config;\n },\n async routeGenerated(routes: RouteMeta[]) {\n const { default: fs } = await import('@rspress/shared/fs-extra');\n\n // init routeMeta\n routeMeta = routes;\n\n const files = routes.map(route => route.absolutePath);\n\n const imports: Record<string, string> = {};\n\n // scan all demos, and generate imports\n await Promise.all(\n files.map(async (filepath, _index) => {\n const isMdxFile = /\\.mdx?$/.test(filepath);\n if (!isMdxFile) {\n return;\n }\n const { createProcessor } = await import('@mdx-js/mdx');\n const { visit } = await import('unist-util-visit');\n const { default: remarkGFM } = await import('remark-gfm');\n try {\n const processor = createProcessor({\n format: path.extname(filepath).slice(1) as 'mdx' | 'md',\n remarkPlugins: [remarkGFM],\n });\n const source = await fs.readFile(filepath, 'utf-8');\n const ast = processor.parse(source);\n\n visit(ast, 'mdxJsxFlowElement', (node: any) => {\n if (node.name === 'code') {\n const src = getNodeAttribute(node, 'src');\n if (!src) {\n return;\n }\n const demoPath = join(path.dirname(filepath), src);\n if (!fs.existsSync(demoPath)) {\n return;\n }\n\n const code = fs.readFileSync(demoPath, {\n encoding: 'utf8',\n });\n\n const thisImports = parseImports(code, path.extname(demoPath));\n thisImports.forEach(x => {\n if (typeof imports[x] === 'undefined') {\n imports[x] = x;\n }\n });\n }\n });\n\n visit(ast, 'code', (node: Code) => {\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const { value, meta } = node;\n const hasPureMeta = meta?.includes('pure');\n const hasPlaygroundMeta = meta?.includes('playground');\n\n let noTransform;\n switch (defaultRenderMode) {\n case 'pure':\n noTransform = !hasPlaygroundMeta;\n break;\n case 'playground':\n noTransform = hasPureMeta;\n break;\n default:\n break;\n }\n\n // do not anything for pure mode\n if (noTransform) {\n return;\n }\n\n const thisImports = parseImports(value, node.lang);\n thisImports.forEach(x => {\n if (typeof imports[x] === 'undefined') {\n imports[x] = x;\n }\n });\n }\n });\n } catch (e) {\n console.error(e);\n throw e;\n }\n }),\n );\n\n if (include) {\n include.forEach(item => {\n if (typeof item === 'string') {\n imports[item] = item;\n } else {\n imports[item[0]] = item[1];\n }\n });\n }\n\n if (!('react' in imports)) {\n imports.react = 'react';\n }\n\n const importKeys = Object.keys(imports);\n const code = [\n ...importKeys.map(\n (x, index) => `import * as i_${index} from '${imports[x]}';`,\n ),\n 'const imports = new Map();',\n ...importKeys.map((x, index) => `imports.set('${x}', i_${index});`),\n 'function getImport(name, getDefault) {',\n ' if (!imports.has(name)) {',\n ' throw new Error(\"Module \" + name + \" not found\");',\n ' }',\n ' const result = imports.get(name);',\n ' if (getDefault && typeof result === \"object\") {',\n ' return result.default || result;',\n ' }',\n ' return result;',\n '}',\n 'export { imports };',\n 'export default getImport;',\n ].join('\\n');\n\n // console.log('playground-imports', code);\n\n playgroundVirtualModule.writeModule('_rspress_playground_imports', code);\n },\n builderConfig: {\n source: {\n define: {\n __PLAYGROUND_DIRECTION__: JSON.stringify(defaultDirection),\n __PLAYGROUND_MONACO_LOADER__: JSON.stringify(monacoLoader),\n __PLAYGROUND_MONACO_OPTIONS__: JSON.stringify(monacoOptions),\n },\n include: [join(__dirname, '..', '..', '..')],\n },\n html: {\n tags: [\n ...preloads.map(url => ({\n tag: 'link',\n head: true,\n attrs: {\n rel: 'preload',\n href: url,\n as: 'script',\n },\n })),\n {\n tag: 'script',\n head: true,\n attrs: {\n id: 'rspress-playground-babel',\n async: true,\n src: babelUrl || DEFAULT_BABEL_URL,\n },\n },\n ],\n },\n tools: {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error\n // @ts-ignore\n rspack: {\n plugins: [playgroundVirtualModule],\n },\n },\n },\n markdown: {\n remarkPlugins: [\n [remarkPlugin, { getRouteMeta, editorPosition, defaultRenderMode }],\n ],\n globalComponents: [\n render\n ? render\n : path.join(staticPath, 'global-components', 'Playground.tsx'),\n ],\n },\n globalStyles: path.join(staticPath, 'global-styles', 'web.css'),\n };\n}\n","import path from 'path';\n\nexport const staticPath = path.join(__dirname, '../../../static');\n","/* eslint-disable consistent-return */\nimport type { Program } from '@babel/types';\nimport oxc from '@oxidation-compiler/napi';\n\nexport const parseImports = (code: string, sourceExt: string) => {\n const parsed = oxc.parseSync(code, {\n sourceType: 'module',\n sourceFilename: `index.${sourceExt}`,\n });\n\n const ast = JSON.parse(parsed.program) as Program;\n\n const result: string[] = [];\n\n // oxc didn't have \"traverse\", so it currently only scans the first level\n // (generally, demos are not too complicated, right?)\n ast.body.forEach(statement => {\n if (statement.type === 'ImportDeclaration') {\n result.push(statement.source.value);\n }\n });\n\n return result;\n};\n\nexport const getNodeAttribute = (\n node: any,\n attrName: string,\n): string | undefined => {\n return node.attributes.find(\n (attr: { name: string; value: string }) => attr.name === attrName,\n )?.value;\n};\n\nexport const getNodeMeta = (\n node: any,\n metaName: string,\n): string | undefined => {\n if (!node.meta) {\n return;\n }\n const meta: string[] = node.meta.split(' ');\n const item: string | undefined = meta.find((x: string) =>\n x.startsWith(metaName),\n );\n if (item?.startsWith(`${metaName}=`)) {\n return item.substring(metaName.length + 1);\n }\n return item;\n};\n","import path, { join } from 'path';\nimport { visit } from 'unist-util-visit';\nimport fs from '@rspress/shared/fs-extra';\nimport type { RouteMeta } from '@rspress/shared';\nimport type { Plugin } from 'unified';\nimport type { Root } from 'mdast';\nimport { getNodeAttribute, getNodeMeta } from './utils';\n\nfunction createPlaygroundNode(\n currentNode: any,\n attrs: Array<[string, string]>,\n) {\n Object.assign(currentNode, {\n type: 'mdxJsxFlowElement',\n name: 'Playground',\n attributes: attrs.map(it => ({\n type: 'mdxJsxAttribute',\n name: it[0],\n value: it[1],\n })),\n });\n}\n\ninterface RemarkPluginProps {\n getRouteMeta: () => RouteMeta[];\n editorPosition: 'left' | 'right';\n defaultRenderMode: 'pure' | 'preview';\n}\n\n/**\n * remark plugin to transform code to demo\n */\nexport const remarkPlugin: Plugin<[RemarkPluginProps], Root> = ({\n getRouteMeta,\n editorPosition,\n defaultRenderMode,\n}) => {\n const routeMeta = getRouteMeta();\n\n return (tree, vfile) => {\n const route = routeMeta.find(\n meta => meta.absolutePath === (vfile.path || vfile.history[0]),\n );\n if (!route) {\n return;\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 = getNodeAttribute(node, 'src');\n if (!src) {\n return;\n }\n const demoPath = join(path.dirname(route.absolutePath), src);\n if (!fs.existsSync(demoPath)) {\n return;\n }\n const direction = getNodeAttribute(node, 'direction') || '';\n const code = fs.readFileSync(demoPath, {\n encoding: 'utf8',\n });\n const language = src.substr(src.lastIndexOf('.') + 1);\n createPlaygroundNode(node, [\n ['code', code],\n ['language', language],\n ['direction', direction],\n ['editorPosition', editorPosition],\n ]);\n }\n });\n\n // 2. Internal demo, use ```j/tsx to declare demo\n visit(tree, 'code', node => {\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const hasPureMeta = node?.meta?.includes('pure');\n const hasPreviewMeta = node?.meta?.includes('preview');\n\n let noTransform;\n switch (defaultRenderMode) {\n case 'pure':\n noTransform = !hasPreviewMeta;\n break;\n case 'preview':\n noTransform = hasPureMeta;\n break;\n default:\n break;\n }\n\n // do not anything for pure mode\n if (noTransform) {\n return;\n }\n\n const direction = getNodeMeta(node, 'direction') || '';\n\n createPlaygroundNode(node, [\n ['code', node.value],\n ['language', node.lang],\n ['direction', direction],\n ['editorPosition', editorPosition],\n ]);\n }\n });\n };\n};\n","export const DEFAULT_BABEL_URL =\n 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js';\n\nexport const DEFAULT_MONACO_URL =\n 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';\n","export function normalizeUrl(u: string) {\n return u.replace(/\\/\\//g, '/');\n}\n"]}
|
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0MA,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,QAAIA,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;AAQA,SAAS,aAAa,OAAO;AAC3B,SAAO,YAAY,GAAG;AAMtB,WAAS,IAAI,M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AK,IAAI;AAIX,8BAAwB,YAAY,+BAA+B,IAAI;AAAA,IACzE;AAAA,IACA,eAAe;AAAA,MACb,QAAQ;AAAA,QACN,QAAQ;AAAA,UACN,0BAA0B,KAAK,UAAU,gBAAgB;AAAA,UACzD,8BAA8B,KAAK,UAAU,YAAY;AAAA,UACzD,+BAA+B,KAAK,UAAU,aAAa;AAAA,QAC7D;AAAA,QACA,SAAS,KAAC,mBAAK,WAAW,MAAM,MAAM,IAAI,CAAC;AAAA,MAC7C;AAAA,MACA,MAAM;AAAA,QACJ,MAAM;AAAA,UACJ,GAAG,SAAS,IAAI,UAAQ;AAAA,YACtB,KAAK;AAAA,YACL,MAAM;AAAA,YACN,OAAO;AAAA,cACL,KAAK;AAAA,cACL,MAAM;AAAA,cACN,IAAI;AAAA,YACN;AAAA,UACF,EAAE;AAAA,UACF;AAAA,YACE,KAAK;AAAA,YACL,MAAM;AAAA,YACN,OAAO;AAAA,cACL,IAAI;AAAA,cACJ,OAAO;AAAA,cACP,KAAK,YAAY;AAAA,YACnB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA;AAAA,QAGL,QAAQ;AAAA,UACN,SAAS,CAAC,uBAAuB;AAAA,QACnC;AAAA,MACF;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,eAAe;AAAA,QACb,CAAC,cAAc,EAAE,cAAc,gBAAgB,kBAAkB,CAAC;AAAA,MACpE;AAAA,MACA,kBAAkB;AAAA,QAChB,SACI,SACA,aAAAE,QAAK,KAAK,YAAY,qBAAqB,gBAAgB;AAAA,MACjE;AAAA,IACF;AAAA,IACA,cAAc,aAAAA,QAAK,KAAK,YAAY,iBAAiB,SAAS;AAAA,EAChE;AACF","names":["index","init_lib","is","visit","import_path","path","oxc","routeMeta","fs","code"],"sources":["../../../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js","../../../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/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-parents@5.1.3/node_modules/unist-util-visit-parents/index.js","../../../../../node_modules/.pnpm/unist-util-visit@4.1.1/node_modules/unist-util-visit/index.js","../../../src/cli/index.ts","../../../src/cli/constant.ts","../../../src/cli/utils.ts","../../../src/cli/remarkPlugin.ts","../../../src/web/constant.ts","../../../src/web/utils.ts"],"sourcesContent":["/**\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 * @typedef {import('./lib/index.js').Test} Test\n * @typedef {import('./lib/index.js').TestFunctionAnything} TestFunctionAnything\n * @typedef {import('./lib/index.js').AssertAnything} AssertAnything\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').PredicateTest<Kind>} PredicateTest\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').TestFunctionPredicate<Kind>} TestFunctionPredicate\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').AssertPredicate<Kind>} AssertPredicate\n */\n\nexport {is, convert} from './lib/index.js'\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","// Note: types exported from `index.d.ts`\nexport {CONTINUE, EXIT, SKIP, visitParents} from './lib/index.js'\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","import path, { join } from 'path';\nimport { type RouteMeta, type RspressPlugin } from '@rspress/shared';\nimport { RspackVirtualModulePlugin } from 'rspack-plugin-virtual-module';\nimport type {\n loader,\n EditorProps as MonacoEditorProps,\n} from '@monaco-editor/react';\nimport { type Code } from 'mdast';\nimport { staticPath } from './constant';\nimport { getNodeAttribute, parseImports } from './utils';\nimport { remarkPlugin } from './remarkPlugin';\nimport { DEFAULT_BABEL_URL, DEFAULT_MONACO_URL } from '@/web/constant';\nimport { normalizeUrl } from '@/web/utils';\n\ninterface PlaygroundOptions {\n render: string;\n include: Array<string | [string, string]>;\n\n defaultDirection: 'horizontal' | 'vertical';\n editorPosition: 'left' | 'right';\n\n babelUrl: string;\n\n monacoLoader: Parameters<typeof loader.config>[0];\n monacoOptions: MonacoEditorProps['options'];\n /**\n * determine how to handle a internal code block without meta\n * @default 'playground'\n */\n defaultRenderMode?: 'pure' | 'playground';\n}\n\n// eslint-disable-next-line import/no-mutable-exports\nexport let routeMeta: RouteMeta[];\n\n/**\n * The plugin is used to preview component.\n */\nexport function pluginPlayground(\n options?: Partial<PlaygroundOptions>,\n): RspressPlugin {\n const {\n render = '',\n include,\n defaultDirection = 'horizontal',\n editorPosition = 'left',\n babelUrl = '',\n monacoLoader = {},\n monacoOptions = {},\n defaultRenderMode = 'playground',\n } = options || {};\n\n const playgroundVirtualModule = new RspackVirtualModulePlugin({});\n const getRouteMeta = () => routeMeta;\n\n if (render && !/Playground\\.(jsx?|tsx?)$/.test(render)) {\n throw new Error(\n '[Playground]: render should ends with Playground.(jsx?|tsx?)',\n );\n }\n\n const preloads: string[] = [];\n const monacoPrefix = monacoLoader.paths?.vs || DEFAULT_MONACO_URL;\n preloads.push(normalizeUrl(`${monacoPrefix}/loader.js`));\n preloads.push(normalizeUrl(`${monacoPrefix}/editor/editor.main.js`));\n\n return {\n name: '@rspress/plugin-playground',\n config(config, { removePlugin }) {\n config.markdown = config.markdown || {};\n config.markdown.mdxRs = false;\n // The preview and playground plugin are mutually conflicting.\n removePlugin('@rspress/plugin-preview');\n return config;\n },\n async routeGenerated(routes: RouteMeta[]) {\n const { default: fs } = await import('@rspress/shared/fs-extra');\n\n // init routeMeta\n routeMeta = routes;\n\n const files = routes.map(route => route.absolutePath);\n\n const imports: Record<string, string> = {};\n\n // scan all demos, and generate imports\n await Promise.all(\n files.map(async (filepath, _index) => {\n const isMdxFile = /\\.mdx?$/.test(filepath);\n if (!isMdxFile) {\n return;\n }\n const { createProcessor } = await import('@mdx-js/mdx');\n const { visit } = await import('unist-util-visit');\n const { default: remarkGFM } = await import('remark-gfm');\n try {\n const processor = createProcessor({\n format: path.extname(filepath).slice(1) as 'mdx' | 'md',\n remarkPlugins: [remarkGFM],\n });\n const source = await fs.readFile(filepath, 'utf-8');\n const ast = processor.parse(source);\n\n visit(ast, 'mdxJsxFlowElement', (node: any) => {\n if (node.name === 'code') {\n const src = getNodeAttribute(node, 'src');\n if (!src) {\n return;\n }\n const demoPath = join(path.dirname(filepath), src);\n if (!fs.existsSync(demoPath)) {\n return;\n }\n\n const code = fs.readFileSync(demoPath, {\n encoding: 'utf8',\n });\n\n const thisImports = parseImports(code, path.extname(demoPath));\n thisImports.forEach(x => {\n if (typeof imports[x] === 'undefined') {\n imports[x] = x;\n }\n });\n }\n });\n\n visit(ast, 'code', (node: Code) => {\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const { value, meta } = node;\n const hasPureMeta = meta?.includes('pure');\n const hasPlaygroundMeta = meta?.includes('playground');\n\n let noTransform;\n switch (defaultRenderMode) {\n case 'pure':\n noTransform = !hasPlaygroundMeta;\n break;\n case 'playground':\n noTransform = hasPureMeta;\n break;\n default:\n break;\n }\n\n // do not anything for pure mode\n if (noTransform) {\n return;\n }\n\n const thisImports = parseImports(value, node.lang);\n thisImports.forEach(x => {\n if (typeof imports[x] === 'undefined') {\n imports[x] = x;\n }\n });\n }\n });\n } catch (e) {\n console.error(e);\n throw e;\n }\n }),\n );\n\n if (include) {\n include.forEach(item => {\n if (typeof item === 'string') {\n imports[item] = item;\n } else {\n imports[item[0]] = item[1];\n }\n });\n }\n\n if (!('react' in imports)) {\n imports.react = 'react';\n }\n\n const importKeys = Object.keys(imports);\n const code = [\n ...importKeys.map(\n (x, index) => `import * as i_${index} from '${imports[x]}';`,\n ),\n 'const imports = new Map();',\n ...importKeys.map((x, index) => `imports.set('${x}', i_${index});`),\n 'function getImport(name, getDefault) {',\n ' if (!imports.has(name)) {',\n ' throw new Error(\"Module \" + name + \" not found\");',\n ' }',\n ' const result = imports.get(name);',\n ' if (getDefault && typeof result === \"object\") {',\n ' return result.default || result;',\n ' }',\n ' return result;',\n '}',\n 'export { imports };',\n 'export default getImport;',\n ].join('\\n');\n\n // console.log('playground-imports', code);\n\n playgroundVirtualModule.writeModule('_rspress_playground_imports', code);\n },\n builderConfig: {\n source: {\n define: {\n __PLAYGROUND_DIRECTION__: JSON.stringify(defaultDirection),\n __PLAYGROUND_MONACO_LOADER__: JSON.stringify(monacoLoader),\n __PLAYGROUND_MONACO_OPTIONS__: JSON.stringify(monacoOptions),\n },\n include: [join(__dirname, '..', '..', '..')],\n },\n html: {\n tags: [\n ...preloads.map(url => ({\n tag: 'link',\n head: true,\n attrs: {\n rel: 'preload',\n href: url,\n as: 'script',\n },\n })),\n {\n tag: 'script',\n head: true,\n attrs: {\n id: 'rspress-playground-babel',\n async: true,\n src: babelUrl || DEFAULT_BABEL_URL,\n },\n },\n ],\n },\n tools: {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error\n // @ts-ignore\n rspack: {\n plugins: [playgroundVirtualModule],\n },\n },\n },\n markdown: {\n remarkPlugins: [\n [remarkPlugin, { getRouteMeta, editorPosition, defaultRenderMode }],\n ],\n globalComponents: [\n render\n ? render\n : path.join(staticPath, 'global-components', 'Playground.tsx'),\n ],\n },\n globalStyles: path.join(staticPath, 'global-styles', 'web.css'),\n };\n}\n","import path from 'path';\n\nexport const staticPath = path.join(__dirname, '../../../static');\n","/* eslint-disable consistent-return */\nimport type { Program } from '@babel/types';\nimport oxc from '@oxidation-compiler/napi';\n\nexport const parseImports = (code: string, sourceExt: string) => {\n const parsed = oxc.parseSync(code, {\n sourceType: 'module',\n sourceFilename: `index.${sourceExt}`,\n });\n\n const ast = JSON.parse(parsed.program) as Program;\n\n const result: string[] = [];\n\n // oxc didn't have \"traverse\", so it currently only scans the first level\n // (generally, demos are not too complicated, right?)\n ast.body.forEach(statement => {\n if (statement.type === 'ImportDeclaration') {\n result.push(statement.source.value);\n }\n });\n\n return result;\n};\n\nexport const getNodeAttribute = (\n node: any,\n attrName: string,\n): string | undefined => {\n return node.attributes.find(\n (attr: { name: string; value: string }) => attr.name === attrName,\n )?.value;\n};\n\nexport const getNodeMeta = (\n node: any,\n metaName: string,\n): string | undefined => {\n if (!node.meta) {\n return;\n }\n const meta: string[] = node.meta.split(' ');\n const item: string | undefined = meta.find((x: string) =>\n x.startsWith(metaName),\n );\n if (item?.startsWith(`${metaName}=`)) {\n return item.substring(metaName.length + 1);\n }\n return item;\n};\n","import { dirname, join, resolve } from 'path';\nimport { visit } from 'unist-util-visit';\nimport fs from '@rspress/shared/fs-extra';\nimport type { RouteMeta } from '@rspress/shared';\nimport type { Plugin } from 'unified';\nimport type { Root } from 'mdast';\nimport { getNodeAttribute, getNodeMeta } from './utils';\n\nfunction createPlaygroundNode(\n currentNode: any,\n attrs: Array<[string, string]>,\n) {\n Object.assign(currentNode, {\n type: 'mdxJsxFlowElement',\n name: 'Playground',\n attributes: attrs.map(it => ({\n type: 'mdxJsxAttribute',\n name: it[0],\n value: it[1],\n })),\n });\n}\n\ninterface RemarkPluginProps {\n getRouteMeta: () => RouteMeta[];\n editorPosition: 'left' | 'right';\n defaultRenderMode: 'pure' | 'preview';\n}\n\n/**\n * remark plugin to transform code to demo\n */\nexport const remarkPlugin: Plugin<[RemarkPluginProps], Root> = ({\n getRouteMeta,\n editorPosition,\n defaultRenderMode,\n}) => {\n const routeMeta = getRouteMeta();\n\n return (tree, vfile) => {\n const route = routeMeta.find(\n meta => resolve(meta.absolutePath) === resolve((vfile.path || vfile.history[0])),\n );\n if (!route) {\n return;\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 = getNodeAttribute(node, 'src');\n if (!src) {\n return;\n }\n const demoPath = join(dirname(route.absolutePath), src);\n if (!fs.existsSync(demoPath)) {\n return;\n }\n const direction = getNodeAttribute(node, 'direction') || '';\n const code = fs.readFileSync(demoPath, {\n encoding: 'utf8',\n });\n const language = src.substr(src.lastIndexOf('.') + 1);\n createPlaygroundNode(node, [\n ['code', code],\n ['language', language],\n ['direction', direction],\n ['editorPosition', editorPosition],\n ]);\n }\n });\n\n // 2. Internal demo, use ```j/tsx to declare demo\n visit(tree, 'code', node => {\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const hasPureMeta = node?.meta?.includes('pure');\n const hasPreviewMeta = node?.meta?.includes('preview');\n\n let noTransform;\n switch (defaultRenderMode) {\n case 'pure':\n noTransform = !hasPreviewMeta;\n break;\n case 'preview':\n noTransform = hasPureMeta;\n break;\n default:\n break;\n }\n\n // do not anything for pure mode\n if (noTransform) {\n return;\n }\n\n const direction = getNodeMeta(node, 'direction') || '';\n\n createPlaygroundNode(node, [\n ['code', node.value],\n ['language', node.lang],\n ['direction', direction],\n ['editorPosition', editorPosition],\n ]);\n }\n });\n };\n};\n","export const DEFAULT_BABEL_URL =\n 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js';\n\nexport const DEFAULT_MONACO_URL =\n 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';\n","export function normalizeUrl(u: string) {\n return u.replace(/\\/\\//g, '/');\n}\n"]}
|
package/dist/cli/esm/index.js
CHANGED
|
@@ -243,7 +243,7 @@ var init_unist_util_visit = __esm({
|
|
|
243
243
|
});
|
|
244
244
|
|
|
245
245
|
// src/cli/index.ts
|
|
246
|
-
import
|
|
246
|
+
import path2, { join as join2 } from "path";
|
|
247
247
|
import { RspackVirtualModulePlugin } from "rspack-plugin-virtual-module";
|
|
248
248
|
|
|
249
249
|
// src/cli/constant.ts
|
|
@@ -287,7 +287,7 @@ var getNodeMeta = (node, metaName) => {
|
|
|
287
287
|
|
|
288
288
|
// src/cli/remarkPlugin.ts
|
|
289
289
|
init_unist_util_visit();
|
|
290
|
-
import
|
|
290
|
+
import { dirname, join, resolve } from "path";
|
|
291
291
|
import fs from "@rspress/shared/fs-extra";
|
|
292
292
|
function createPlaygroundNode(currentNode, attrs) {
|
|
293
293
|
Object.assign(currentNode, {
|
|
@@ -308,7 +308,7 @@ var remarkPlugin = ({
|
|
|
308
308
|
const routeMeta2 = getRouteMeta();
|
|
309
309
|
return (tree, vfile) => {
|
|
310
310
|
const route = routeMeta2.find(
|
|
311
|
-
(meta) => meta.absolutePath === (vfile.path || vfile.history[0])
|
|
311
|
+
(meta) => resolve(meta.absolutePath) === resolve(vfile.path || vfile.history[0])
|
|
312
312
|
);
|
|
313
313
|
if (!route) {
|
|
314
314
|
return;
|
|
@@ -319,7 +319,7 @@ var remarkPlugin = ({
|
|
|
319
319
|
if (!src) {
|
|
320
320
|
return;
|
|
321
321
|
}
|
|
322
|
-
const demoPath = join(
|
|
322
|
+
const demoPath = join(dirname(route.absolutePath), src);
|
|
323
323
|
if (!fs.existsSync(demoPath)) {
|
|
324
324
|
return;
|
|
325
325
|
}
|
|
@@ -423,7 +423,7 @@ function pluginPlayground(options) {
|
|
|
423
423
|
const { default: remarkGFM } = await import("remark-gfm");
|
|
424
424
|
try {
|
|
425
425
|
const processor = createProcessor({
|
|
426
|
-
format:
|
|
426
|
+
format: path2.extname(filepath).slice(1),
|
|
427
427
|
remarkPlugins: [remarkGFM]
|
|
428
428
|
});
|
|
429
429
|
const source = await fs2.readFile(filepath, "utf-8");
|
|
@@ -434,14 +434,14 @@ function pluginPlayground(options) {
|
|
|
434
434
|
if (!src) {
|
|
435
435
|
return;
|
|
436
436
|
}
|
|
437
|
-
const demoPath = join2(
|
|
437
|
+
const demoPath = join2(path2.dirname(filepath), src);
|
|
438
438
|
if (!fs2.existsSync(demoPath)) {
|
|
439
439
|
return;
|
|
440
440
|
}
|
|
441
441
|
const code2 = fs2.readFileSync(demoPath, {
|
|
442
442
|
encoding: "utf8"
|
|
443
443
|
});
|
|
444
|
-
const thisImports = parseImports(code2,
|
|
444
|
+
const thisImports = parseImports(code2, path2.extname(demoPath));
|
|
445
445
|
thisImports.forEach((x) => {
|
|
446
446
|
if (typeof imports[x] === "undefined") {
|
|
447
447
|
imports[x] = x;
|
|
@@ -560,10 +560,10 @@ function pluginPlayground(options) {
|
|
|
560
560
|
[remarkPlugin, { getRouteMeta, editorPosition, defaultRenderMode }]
|
|
561
561
|
],
|
|
562
562
|
globalComponents: [
|
|
563
|
-
render ? render :
|
|
563
|
+
render ? render : path2.join(staticPath, "global-components", "Playground.tsx")
|
|
564
564
|
]
|
|
565
565
|
},
|
|
566
|
-
globalStyles:
|
|
566
|
+
globalStyles: path2.join(staticPath, "global-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AAQ;AAAA,UACN,SAAS,CAAC,uBAAuB;AAAA,QACnC;AAAA,MACF;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,eAAe;AAAA,QACb,CAAC,cAAc,EAAE,cAAc,gBAAgB,kBAAkB,CAAC;AAAA,MACpE;AAAA,MACA,kBAAkB;AAAA,QAChB,SACI,SACAD,MAAK,KAAK,YAAY,qBAAqB,gBAAgB;AAAA,MACjE;AAAA,IACF;AAAA,IACA,cAAcA,MAAK,KAAK,YAAY,iBAAiB,SAAS;AAAA,EAChE;AACF","names":["index","init_lib","is","visit","path","join","routeMeta","fs","code"],"sources":["../../../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js","../../../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/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-parents@5.1.3/node_modules/unist-util-visit-parents/index.js","../../../../../node_modules/.pnpm/unist-util-visit@4.1.1/node_modules/unist-util-visit/index.js","../../../src/cli/index.ts","../../../src/cli/constant.ts","../../../src/cli/utils.ts","../../../src/cli/remarkPlugin.ts","../../../src/web/constant.ts","../../../src/web/utils.ts"],"sourcesContent":["/**\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 * @typedef {import('./lib/index.js').Test} Test\n * @typedef {import('./lib/index.js').TestFunctionAnything} TestFunctionAnything\n * @typedef {import('./lib/index.js').AssertAnything} AssertAnything\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').PredicateTest<Kind>} PredicateTest\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').TestFunctionPredicate<Kind>} TestFunctionPredicate\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').AssertPredicate<Kind>} AssertPredicate\n */\n\nexport {is, convert} from './lib/index.js'\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","// Note: types exported from `index.d.ts`\nexport {CONTINUE, EXIT, SKIP, visitParents} from './lib/index.js'\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","import path, { join } from 'path';\nimport { type RouteMeta, type RspressPlugin } from '@rspress/shared';\nimport { RspackVirtualModulePlugin } from 'rspack-plugin-virtual-module';\nimport type {\n loader,\n EditorProps as MonacoEditorProps,\n} from '@monaco-editor/react';\nimport { type Code } from 'mdast';\nimport { staticPath } from './constant';\nimport { getNodeAttribute, parseImports } from './utils';\nimport { remarkPlugin } from './remarkPlugin';\nimport { DEFAULT_BABEL_URL, DEFAULT_MONACO_URL } from '@/web/constant';\nimport { normalizeUrl } from '@/web/utils';\n\ninterface PlaygroundOptions {\n render: string;\n include: Array<string | [string, string]>;\n\n defaultDirection: 'horizontal' | 'vertical';\n editorPosition: 'left' | 'right';\n\n babelUrl: string;\n\n monacoLoader: Parameters<typeof loader.config>[0];\n monacoOptions: MonacoEditorProps['options'];\n /**\n * determine how to handle a internal code block without meta\n * @default 'playground'\n */\n defaultRenderMode?: 'pure' | 'playground';\n}\n\n// eslint-disable-next-line import/no-mutable-exports\nexport let routeMeta: RouteMeta[];\n\n/**\n * The plugin is used to preview component.\n */\nexport function pluginPlayground(\n options?: Partial<PlaygroundOptions>,\n): RspressPlugin {\n const {\n render = '',\n include,\n defaultDirection = 'horizontal',\n editorPosition = 'left',\n babelUrl = '',\n monacoLoader = {},\n monacoOptions = {},\n defaultRenderMode = 'playground',\n } = options || {};\n\n const playgroundVirtualModule = new RspackVirtualModulePlugin({});\n const getRouteMeta = () => routeMeta;\n\n if (render && !/Playground\\.(jsx?|tsx?)$/.test(render)) {\n throw new Error(\n '[Playground]: render should ends with Playground.(jsx?|tsx?)',\n );\n }\n\n const preloads: string[] = [];\n const monacoPrefix = monacoLoader.paths?.vs || DEFAULT_MONACO_URL;\n preloads.push(normalizeUrl(`${monacoPrefix}/loader.js`));\n preloads.push(normalizeUrl(`${monacoPrefix}/editor/editor.main.js`));\n\n return {\n name: '@rspress/plugin-playground',\n config(config, { removePlugin }) {\n config.markdown = config.markdown || {};\n config.markdown.mdxRs = false;\n // The preview and playground plugin are mutually conflicting.\n removePlugin('@rspress/plugin-preview');\n return config;\n },\n async routeGenerated(routes: RouteMeta[]) {\n const { default: fs } = await import('@rspress/shared/fs-extra');\n\n // init routeMeta\n routeMeta = routes;\n\n const files = routes.map(route => route.absolutePath);\n\n const imports: Record<string, string> = {};\n\n // scan all demos, and generate imports\n await Promise.all(\n files.map(async (filepath, _index) => {\n const isMdxFile = /\\.mdx?$/.test(filepath);\n if (!isMdxFile) {\n return;\n }\n const { createProcessor } = await import('@mdx-js/mdx');\n const { visit } = await import('unist-util-visit');\n const { default: remarkGFM } = await import('remark-gfm');\n try {\n const processor = createProcessor({\n format: path.extname(filepath).slice(1) as 'mdx' | 'md',\n remarkPlugins: [remarkGFM],\n });\n const source = await fs.readFile(filepath, 'utf-8');\n const ast = processor.parse(source);\n\n visit(ast, 'mdxJsxFlowElement', (node: any) => {\n if (node.name === 'code') {\n const src = getNodeAttribute(node, 'src');\n if (!src) {\n return;\n }\n const demoPath = join(path.dirname(filepath), src);\n if (!fs.existsSync(demoPath)) {\n return;\n }\n\n const code = fs.readFileSync(demoPath, {\n encoding: 'utf8',\n });\n\n const thisImports = parseImports(code, path.extname(demoPath));\n thisImports.forEach(x => {\n if (typeof imports[x] === 'undefined') {\n imports[x] = x;\n }\n });\n }\n });\n\n visit(ast, 'code', (node: Code) => {\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const { value, meta } = node;\n const hasPureMeta = meta?.includes('pure');\n const hasPlaygroundMeta = meta?.includes('playground');\n\n let noTransform;\n switch (defaultRenderMode) {\n case 'pure':\n noTransform = !hasPlaygroundMeta;\n break;\n case 'playground':\n noTransform = hasPureMeta;\n break;\n default:\n break;\n }\n\n // do not anything for pure mode\n if (noTransform) {\n return;\n }\n\n const thisImports = parseImports(value, node.lang);\n thisImports.forEach(x => {\n if (typeof imports[x] === 'undefined') {\n imports[x] = x;\n }\n });\n }\n });\n } catch (e) {\n console.error(e);\n throw e;\n }\n }),\n );\n\n if (include) {\n include.forEach(item => {\n if (typeof item === 'string') {\n imports[item] = item;\n } else {\n imports[item[0]] = item[1];\n }\n });\n }\n\n if (!('react' in imports)) {\n imports.react = 'react';\n }\n\n const importKeys = Object.keys(imports);\n const code = [\n ...importKeys.map(\n (x, index) => `import * as i_${index} from '${imports[x]}';`,\n ),\n 'const imports = new Map();',\n ...importKeys.map((x, index) => `imports.set('${x}', i_${index});`),\n 'function getImport(name, getDefault) {',\n ' if (!imports.has(name)) {',\n ' throw new Error(\"Module \" + name + \" not found\");',\n ' }',\n ' const result = imports.get(name);',\n ' if (getDefault && typeof result === \"object\") {',\n ' return result.default || result;',\n ' }',\n ' return result;',\n '}',\n 'export { imports };',\n 'export default getImport;',\n ].join('\\n');\n\n // console.log('playground-imports', code);\n\n playgroundVirtualModule.writeModule('_rspress_playground_imports', code);\n },\n builderConfig: {\n source: {\n define: {\n __PLAYGROUND_DIRECTION__: JSON.stringify(defaultDirection),\n __PLAYGROUND_MONACO_LOADER__: JSON.stringify(monacoLoader),\n __PLAYGROUND_MONACO_OPTIONS__: JSON.stringify(monacoOptions),\n },\n include: [join(__dirname, '..', '..', '..')],\n },\n html: {\n tags: [\n ...preloads.map(url => ({\n tag: 'link',\n head: true,\n attrs: {\n rel: 'preload',\n href: url,\n as: 'script',\n },\n })),\n {\n tag: 'script',\n head: true,\n attrs: {\n id: 'rspress-playground-babel',\n async: true,\n src: babelUrl || DEFAULT_BABEL_URL,\n },\n },\n ],\n },\n tools: {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error\n // @ts-ignore\n rspack: {\n plugins: [playgroundVirtualModule],\n },\n },\n },\n markdown: {\n remarkPlugins: [\n [remarkPlugin, { getRouteMeta, editorPosition, defaultRenderMode }],\n ],\n globalComponents: [\n render\n ? render\n : path.join(staticPath, 'global-components', 'Playground.tsx'),\n ],\n },\n globalStyles: path.join(staticPath, 'global-styles', 'web.css'),\n };\n}\n","import path from 'path';\n\nexport const staticPath = path.join(__dirname, '../../../static');\n","/* eslint-disable consistent-return */\nimport type { Program } from '@babel/types';\nimport oxc from '@oxidation-compiler/napi';\n\nexport const parseImports = (code: string, sourceExt: string) => {\n const parsed = oxc.parseSync(code, {\n sourceType: 'module',\n sourceFilename: `index.${sourceExt}`,\n });\n\n const ast = JSON.parse(parsed.program) as Program;\n\n const result: string[] = [];\n\n // oxc didn't have \"traverse\", so it currently only scans the first level\n // (generally, demos are not too complicated, right?)\n ast.body.forEach(statement => {\n if (statement.type === 'ImportDeclaration') {\n result.push(statement.source.value);\n }\n });\n\n return result;\n};\n\nexport const getNodeAttribute = (\n node: any,\n attrName: string,\n): string | undefined => {\n return node.attributes.find(\n (attr: { name: string; value: string }) => attr.name === attrName,\n )?.value;\n};\n\nexport const getNodeMeta = (\n node: any,\n metaName: string,\n): string | undefined => {\n if (!node.meta) {\n return;\n }\n const meta: string[] = node.meta.split(' ');\n const item: string | undefined = meta.find((x: string) =>\n x.startsWith(metaName),\n );\n if (item?.startsWith(`${metaName}=`)) {\n return item.substring(metaName.length + 1);\n }\n return item;\n};\n","import path, { join } from 'path';\nimport { visit } from 'unist-util-visit';\nimport fs from '@rspress/shared/fs-extra';\nimport type { RouteMeta } from '@rspress/shared';\nimport type { Plugin } from 'unified';\nimport type { Root } from 'mdast';\nimport { getNodeAttribute, getNodeMeta } from './utils';\n\nfunction createPlaygroundNode(\n currentNode: any,\n attrs: Array<[string, string]>,\n) {\n Object.assign(currentNode, {\n type: 'mdxJsxFlowElement',\n name: 'Playground',\n attributes: attrs.map(it => ({\n type: 'mdxJsxAttribute',\n name: it[0],\n value: it[1],\n })),\n });\n}\n\ninterface RemarkPluginProps {\n getRouteMeta: () => RouteMeta[];\n editorPosition: 'left' | 'right';\n defaultRenderMode: 'pure' | 'preview';\n}\n\n/**\n * remark plugin to transform code to demo\n */\nexport const remarkPlugin: Plugin<[RemarkPluginProps], Root> = ({\n getRouteMeta,\n editorPosition,\n defaultRenderMode,\n}) => {\n const routeMeta = getRouteMeta();\n\n return (tree, vfile) => {\n const route = routeMeta.find(\n meta => meta.absolutePath === (vfile.path || vfile.history[0]),\n );\n if (!route) {\n return;\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 = getNodeAttribute(node, 'src');\n if (!src) {\n return;\n }\n const demoPath = join(path.dirname(route.absolutePath), src);\n if (!fs.existsSync(demoPath)) {\n return;\n }\n const direction = getNodeAttribute(node, 'direction') || '';\n const code = fs.readFileSync(demoPath, {\n encoding: 'utf8',\n });\n const language = src.substr(src.lastIndexOf('.') + 1);\n createPlaygroundNode(node, [\n ['code', code],\n ['language', language],\n ['direction', direction],\n ['editorPosition', editorPosition],\n ]);\n }\n });\n\n // 2. Internal demo, use ```j/tsx to declare demo\n visit(tree, 'code', node => {\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const hasPureMeta = node?.meta?.includes('pure');\n const hasPreviewMeta = node?.meta?.includes('preview');\n\n let noTransform;\n switch (defaultRenderMode) {\n case 'pure':\n noTransform = !hasPreviewMeta;\n break;\n case 'preview':\n noTransform = hasPureMeta;\n break;\n default:\n break;\n }\n\n // do not anything for pure mode\n if (noTransform) {\n return;\n }\n\n const direction = getNodeMeta(node, 'direction') || '';\n\n createPlaygroundNode(node, [\n ['code', node.value],\n ['language', node.lang],\n ['direction', direction],\n ['editorPosition', editorPosition],\n ]);\n }\n });\n };\n};\n","export const DEFAULT_BABEL_URL =\n 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js';\n\nexport const DEFAULT_MONACO_URL =\n 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';\n","export function normalizeUrl(u: string) {\n return u.replace(/\\/\\//g, '/');\n}\n"]}
|
|
1
|
+
{"version":3,"mappings":";;;;;;;;;;;AA0MA,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,QAAIA,SAAQ;AAEZ,WAAO,EAAEA,SAAQ,OAAO,QAAQ;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ACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,EAAE,KAAK,IAAI;AAIX,8BAAwB,YAAY,+BAA+B,IAAI;AAAA,IACzE;AAAA,IACA,eAAe;AAAA,MACb,QAAQ;AAAA,QACN,QAAQ;AAAA,UACN,0BAA0B,KAAK,UAAU,gBAAgB;AAAA,UACzD,8BAA8B,KAAK,UAAU,YAAY;AAAA,UACzD,+BAA+B,KAAK,UAAU,aAAa;AAAA,QAC7D;AAAA,QACA,SAAS,CAACE,MAAK,WAAW,MAAM,MAAM,IAAI,CAAC;AAAA,MAC7C;AAAA,MACA,MAAM;AAAA,QACJ,MAAM;AAAA,UACJ,GAAG,SAAS,IAAI,UAAQ;AAAA,YACtB,KAAK;AAAA,YACL,MAAM;AAAA,YACN,OAAO;AAAA,cACL,KAAK;AAAA,cACL,MAAM;AAAA,cACN,IAAI;AAAA,YACN;AAAA,UACF,EAAE;AAAA,UACF;AAAA,YACE,KAAK;AAAA,YACL,MAAM;AAAA,YACN,OAAO;AAAA,cACL,IAAI;AAAA,cACJ,OAAO;AAAA,cACP,KAAK,YAAY;AAAA,YACnB;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,MACA,OAAO;AAAA;AAAA;AAAA,QAGL,QAAQ;AAAA,UACN,SAAS,CAAC,uBAAuB;AAAA,QACnC;AAAA,MACF;AAAA,IACF;AAAA,IACA,UAAU;AAAA,MACR,eAAe;AAAA,QACb,CAAC,cAAc,EAAE,cAAc,gBAAgB,kBAAkB,CAAC;AAAA,MACpE;AAAA,MACA,kBAAkB;AAAA,QAChB,SACI,SACAD,MAAK,KAAK,YAAY,qBAAqB,gBAAgB;AAAA,MACjE;AAAA,IACF;AAAA,IACA,cAAcA,MAAK,KAAK,YAAY,iBAAiB,SAAS;AAAA,EAChE;AACF","names":["index","init_lib","is","visit","path","join","routeMeta","fs","code"],"sources":["../../../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js","../../../../../node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/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-parents@5.1.3/node_modules/unist-util-visit-parents/index.js","../../../../../node_modules/.pnpm/unist-util-visit@4.1.1/node_modules/unist-util-visit/index.js","../../../src/cli/index.ts","../../../src/cli/constant.ts","../../../src/cli/utils.ts","../../../src/cli/remarkPlugin.ts","../../../src/web/constant.ts","../../../src/web/utils.ts"],"sourcesContent":["/**\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 * @typedef {import('./lib/index.js').Test} Test\n * @typedef {import('./lib/index.js').TestFunctionAnything} TestFunctionAnything\n * @typedef {import('./lib/index.js').AssertAnything} AssertAnything\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').PredicateTest<Kind>} PredicateTest\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').TestFunctionPredicate<Kind>} TestFunctionPredicate\n */\n\n/**\n * @template {import('unist').Node} Kind\n * @typedef {import('./lib/index.js').AssertPredicate<Kind>} AssertPredicate\n */\n\nexport {is, convert} from './lib/index.js'\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","// Note: types exported from `index.d.ts`\nexport {CONTINUE, EXIT, SKIP, visitParents} from './lib/index.js'\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","import path, { join } from 'path';\nimport { type RouteMeta, type RspressPlugin } from '@rspress/shared';\nimport { RspackVirtualModulePlugin } from 'rspack-plugin-virtual-module';\nimport type {\n loader,\n EditorProps as MonacoEditorProps,\n} from '@monaco-editor/react';\nimport { type Code } from 'mdast';\nimport { staticPath } from './constant';\nimport { getNodeAttribute, parseImports } from './utils';\nimport { remarkPlugin } from './remarkPlugin';\nimport { DEFAULT_BABEL_URL, DEFAULT_MONACO_URL } from '@/web/constant';\nimport { normalizeUrl } from '@/web/utils';\n\ninterface PlaygroundOptions {\n render: string;\n include: Array<string | [string, string]>;\n\n defaultDirection: 'horizontal' | 'vertical';\n editorPosition: 'left' | 'right';\n\n babelUrl: string;\n\n monacoLoader: Parameters<typeof loader.config>[0];\n monacoOptions: MonacoEditorProps['options'];\n /**\n * determine how to handle a internal code block without meta\n * @default 'playground'\n */\n defaultRenderMode?: 'pure' | 'playground';\n}\n\n// eslint-disable-next-line import/no-mutable-exports\nexport let routeMeta: RouteMeta[];\n\n/**\n * The plugin is used to preview component.\n */\nexport function pluginPlayground(\n options?: Partial<PlaygroundOptions>,\n): RspressPlugin {\n const {\n render = '',\n include,\n defaultDirection = 'horizontal',\n editorPosition = 'left',\n babelUrl = '',\n monacoLoader = {},\n monacoOptions = {},\n defaultRenderMode = 'playground',\n } = options || {};\n\n const playgroundVirtualModule = new RspackVirtualModulePlugin({});\n const getRouteMeta = () => routeMeta;\n\n if (render && !/Playground\\.(jsx?|tsx?)$/.test(render)) {\n throw new Error(\n '[Playground]: render should ends with Playground.(jsx?|tsx?)',\n );\n }\n\n const preloads: string[] = [];\n const monacoPrefix = monacoLoader.paths?.vs || DEFAULT_MONACO_URL;\n preloads.push(normalizeUrl(`${monacoPrefix}/loader.js`));\n preloads.push(normalizeUrl(`${monacoPrefix}/editor/editor.main.js`));\n\n return {\n name: '@rspress/plugin-playground',\n config(config, { removePlugin }) {\n config.markdown = config.markdown || {};\n config.markdown.mdxRs = false;\n // The preview and playground plugin are mutually conflicting.\n removePlugin('@rspress/plugin-preview');\n return config;\n },\n async routeGenerated(routes: RouteMeta[]) {\n const { default: fs } = await import('@rspress/shared/fs-extra');\n\n // init routeMeta\n routeMeta = routes;\n\n const files = routes.map(route => route.absolutePath);\n\n const imports: Record<string, string> = {};\n\n // scan all demos, and generate imports\n await Promise.all(\n files.map(async (filepath, _index) => {\n const isMdxFile = /\\.mdx?$/.test(filepath);\n if (!isMdxFile) {\n return;\n }\n const { createProcessor } = await import('@mdx-js/mdx');\n const { visit } = await import('unist-util-visit');\n const { default: remarkGFM } = await import('remark-gfm');\n try {\n const processor = createProcessor({\n format: path.extname(filepath).slice(1) as 'mdx' | 'md',\n remarkPlugins: [remarkGFM],\n });\n const source = await fs.readFile(filepath, 'utf-8');\n const ast = processor.parse(source);\n\n visit(ast, 'mdxJsxFlowElement', (node: any) => {\n if (node.name === 'code') {\n const src = getNodeAttribute(node, 'src');\n if (!src) {\n return;\n }\n const demoPath = join(path.dirname(filepath), src);\n if (!fs.existsSync(demoPath)) {\n return;\n }\n\n const code = fs.readFileSync(demoPath, {\n encoding: 'utf8',\n });\n\n const thisImports = parseImports(code, path.extname(demoPath));\n thisImports.forEach(x => {\n if (typeof imports[x] === 'undefined') {\n imports[x] = x;\n }\n });\n }\n });\n\n visit(ast, 'code', (node: Code) => {\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const { value, meta } = node;\n const hasPureMeta = meta?.includes('pure');\n const hasPlaygroundMeta = meta?.includes('playground');\n\n let noTransform;\n switch (defaultRenderMode) {\n case 'pure':\n noTransform = !hasPlaygroundMeta;\n break;\n case 'playground':\n noTransform = hasPureMeta;\n break;\n default:\n break;\n }\n\n // do not anything for pure mode\n if (noTransform) {\n return;\n }\n\n const thisImports = parseImports(value, node.lang);\n thisImports.forEach(x => {\n if (typeof imports[x] === 'undefined') {\n imports[x] = x;\n }\n });\n }\n });\n } catch (e) {\n console.error(e);\n throw e;\n }\n }),\n );\n\n if (include) {\n include.forEach(item => {\n if (typeof item === 'string') {\n imports[item] = item;\n } else {\n imports[item[0]] = item[1];\n }\n });\n }\n\n if (!('react' in imports)) {\n imports.react = 'react';\n }\n\n const importKeys = Object.keys(imports);\n const code = [\n ...importKeys.map(\n (x, index) => `import * as i_${index} from '${imports[x]}';`,\n ),\n 'const imports = new Map();',\n ...importKeys.map((x, index) => `imports.set('${x}', i_${index});`),\n 'function getImport(name, getDefault) {',\n ' if (!imports.has(name)) {',\n ' throw new Error(\"Module \" + name + \" not found\");',\n ' }',\n ' const result = imports.get(name);',\n ' if (getDefault && typeof result === \"object\") {',\n ' return result.default || result;',\n ' }',\n ' return result;',\n '}',\n 'export { imports };',\n 'export default getImport;',\n ].join('\\n');\n\n // console.log('playground-imports', code);\n\n playgroundVirtualModule.writeModule('_rspress_playground_imports', code);\n },\n builderConfig: {\n source: {\n define: {\n __PLAYGROUND_DIRECTION__: JSON.stringify(defaultDirection),\n __PLAYGROUND_MONACO_LOADER__: JSON.stringify(monacoLoader),\n __PLAYGROUND_MONACO_OPTIONS__: JSON.stringify(monacoOptions),\n },\n include: [join(__dirname, '..', '..', '..')],\n },\n html: {\n tags: [\n ...preloads.map(url => ({\n tag: 'link',\n head: true,\n attrs: {\n rel: 'preload',\n href: url,\n as: 'script',\n },\n })),\n {\n tag: 'script',\n head: true,\n attrs: {\n id: 'rspress-playground-babel',\n async: true,\n src: babelUrl || DEFAULT_BABEL_URL,\n },\n },\n ],\n },\n tools: {\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error\n // @ts-ignore\n rspack: {\n plugins: [playgroundVirtualModule],\n },\n },\n },\n markdown: {\n remarkPlugins: [\n [remarkPlugin, { getRouteMeta, editorPosition, defaultRenderMode }],\n ],\n globalComponents: [\n render\n ? render\n : path.join(staticPath, 'global-components', 'Playground.tsx'),\n ],\n },\n globalStyles: path.join(staticPath, 'global-styles', 'web.css'),\n };\n}\n","import path from 'path';\n\nexport const staticPath = path.join(__dirname, '../../../static');\n","/* eslint-disable consistent-return */\nimport type { Program } from '@babel/types';\nimport oxc from '@oxidation-compiler/napi';\n\nexport const parseImports = (code: string, sourceExt: string) => {\n const parsed = oxc.parseSync(code, {\n sourceType: 'module',\n sourceFilename: `index.${sourceExt}`,\n });\n\n const ast = JSON.parse(parsed.program) as Program;\n\n const result: string[] = [];\n\n // oxc didn't have \"traverse\", so it currently only scans the first level\n // (generally, demos are not too complicated, right?)\n ast.body.forEach(statement => {\n if (statement.type === 'ImportDeclaration') {\n result.push(statement.source.value);\n }\n });\n\n return result;\n};\n\nexport const getNodeAttribute = (\n node: any,\n attrName: string,\n): string | undefined => {\n return node.attributes.find(\n (attr: { name: string; value: string }) => attr.name === attrName,\n )?.value;\n};\n\nexport const getNodeMeta = (\n node: any,\n metaName: string,\n): string | undefined => {\n if (!node.meta) {\n return;\n }\n const meta: string[] = node.meta.split(' ');\n const item: string | undefined = meta.find((x: string) =>\n x.startsWith(metaName),\n );\n if (item?.startsWith(`${metaName}=`)) {\n return item.substring(metaName.length + 1);\n }\n return item;\n};\n","import { dirname, join, resolve } from 'path';\nimport { visit } from 'unist-util-visit';\nimport fs from '@rspress/shared/fs-extra';\nimport type { RouteMeta } from '@rspress/shared';\nimport type { Plugin } from 'unified';\nimport type { Root } from 'mdast';\nimport { getNodeAttribute, getNodeMeta } from './utils';\n\nfunction createPlaygroundNode(\n currentNode: any,\n attrs: Array<[string, string]>,\n) {\n Object.assign(currentNode, {\n type: 'mdxJsxFlowElement',\n name: 'Playground',\n attributes: attrs.map(it => ({\n type: 'mdxJsxAttribute',\n name: it[0],\n value: it[1],\n })),\n });\n}\n\ninterface RemarkPluginProps {\n getRouteMeta: () => RouteMeta[];\n editorPosition: 'left' | 'right';\n defaultRenderMode: 'pure' | 'preview';\n}\n\n/**\n * remark plugin to transform code to demo\n */\nexport const remarkPlugin: Plugin<[RemarkPluginProps], Root> = ({\n getRouteMeta,\n editorPosition,\n defaultRenderMode,\n}) => {\n const routeMeta = getRouteMeta();\n\n return (tree, vfile) => {\n const route = routeMeta.find(\n meta => resolve(meta.absolutePath) === resolve((vfile.path || vfile.history[0])),\n );\n if (!route) {\n return;\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 = getNodeAttribute(node, 'src');\n if (!src) {\n return;\n }\n const demoPath = join(dirname(route.absolutePath), src);\n if (!fs.existsSync(demoPath)) {\n return;\n }\n const direction = getNodeAttribute(node, 'direction') || '';\n const code = fs.readFileSync(demoPath, {\n encoding: 'utf8',\n });\n const language = src.substr(src.lastIndexOf('.') + 1);\n createPlaygroundNode(node, [\n ['code', code],\n ['language', language],\n ['direction', direction],\n ['editorPosition', editorPosition],\n ]);\n }\n });\n\n // 2. Internal demo, use ```j/tsx to declare demo\n visit(tree, 'code', node => {\n if (node.lang === 'jsx' || node.lang === 'tsx') {\n const hasPureMeta = node?.meta?.includes('pure');\n const hasPreviewMeta = node?.meta?.includes('preview');\n\n let noTransform;\n switch (defaultRenderMode) {\n case 'pure':\n noTransform = !hasPreviewMeta;\n break;\n case 'preview':\n noTransform = hasPureMeta;\n break;\n default:\n break;\n }\n\n // do not anything for pure mode\n if (noTransform) {\n return;\n }\n\n const direction = getNodeMeta(node, 'direction') || '';\n\n createPlaygroundNode(node, [\n ['code', node.value],\n ['language', node.lang],\n ['direction', direction],\n ['editorPosition', editorPosition],\n ]);\n }\n });\n };\n};\n","export const DEFAULT_BABEL_URL =\n 'https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/7.22.20/babel.min.js';\n\nexport const DEFAULT_MONACO_URL =\n 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.43.0/min/vs';\n","export function normalizeUrl(u: string) {\n return u.replace(/\\/\\//g, '/');\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/plugin-playground",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.1",
|
|
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": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@oxidation-compiler/napi": "^0.1.0",
|
|
38
38
|
"remark-gfm": "3.0.1",
|
|
39
39
|
"rspack-plugin-virtual-module": "0.1.12",
|
|
40
|
-
"@rspress/shared": "1.
|
|
40
|
+
"@rspress/shared": "1.11.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@babel/types": "^7.22.17",
|