vigor-moon 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/README.md +9 -0
  2. package/bin/vigor.js +2 -0
  3. package/dist/chunk-2M2XJKGT.js +607 -0
  4. package/dist/chunk-3EAR5BNQ.js +610 -0
  5. package/dist/chunk-3ZCIQMBL.js +608 -0
  6. package/dist/chunk-6SPQ2G5U.js +611 -0
  7. package/dist/chunk-7V4TYSIZ.mjs +619 -0
  8. package/dist/chunk-AT54N5D7.js +611 -0
  9. package/dist/chunk-BBRRUMIN.js +616 -0
  10. package/dist/chunk-BE2AQAQS.mjs +608 -0
  11. package/dist/chunk-BS6X4ZCI.js +608 -0
  12. package/dist/chunk-CG4W75R5.mjs +622 -0
  13. package/dist/chunk-D2WJMNSR.js +618 -0
  14. package/dist/chunk-DTA4ZJEQ.mjs +606 -0
  15. package/dist/chunk-ECPJL6H6.js +618 -0
  16. package/dist/chunk-EU5K7BUZ.mjs +612 -0
  17. package/dist/chunk-FAELXJ3Z.mjs +605 -0
  18. package/dist/chunk-GBGTGHKN.js +621 -0
  19. package/dist/chunk-HW7CAZGA.js +611 -0
  20. package/dist/chunk-IDQ7PFDG.mjs +619 -0
  21. package/dist/chunk-IPVDS3I7.mjs +609 -0
  22. package/dist/chunk-JHZIOXVJ.js +605 -0
  23. package/dist/chunk-KRBN43PO.js +606 -0
  24. package/dist/chunk-KTIICQHT.mjs +622 -0
  25. package/dist/chunk-KZQIA6WA.js +604 -0
  26. package/dist/chunk-L4MZ52TR.mjs +609 -0
  27. package/dist/chunk-LEOZIK2T.mjs +607 -0
  28. package/dist/chunk-LS3TOABU.js +61 -0
  29. package/dist/chunk-MHZT64KI.mjs +605 -0
  30. package/dist/chunk-NTJI6VKJ.mjs +619 -0
  31. package/dist/chunk-NWZZITYZ.mjs +606 -0
  32. package/dist/chunk-OS3F7QDD.js +606 -0
  33. package/dist/chunk-PJPXX4UA.mjs +605 -0
  34. package/dist/chunk-PW73M55D.mjs +611 -0
  35. package/dist/chunk-R6L6GYA4.mjs +607 -0
  36. package/dist/chunk-RNUPZ4CR.mjs +612 -0
  37. package/dist/chunk-SEIXDGYJ.mjs +615 -0
  38. package/dist/chunk-SO47EKIV.mjs +69 -0
  39. package/dist/chunk-SYCZ35ZW.js +604 -0
  40. package/dist/chunk-THZGRR4I.js +611 -0
  41. package/dist/chunk-TJ5NMLCW.js +614 -0
  42. package/dist/chunk-TYBNSCBA.mjs +611 -0
  43. package/dist/chunk-UGBCHWPA.js +621 -0
  44. package/dist/chunk-VD42YO6T.mjs +622 -0
  45. package/dist/chunk-VMNTKZYD.js +604 -0
  46. package/dist/chunk-W6MHPTGR.js +605 -0
  47. package/dist/chunk-WBSL45KV.mjs +617 -0
  48. package/dist/chunk-X5IY67V6.js +621 -0
  49. package/dist/chunk-XFGBQ3QD.mjs +612 -0
  50. package/dist/chunk-ZBAZASII.js +618 -0
  51. package/dist/chunk-ZGLENLKC.js +610 -0
  52. package/dist/chunk-ZN4CSBNG.mjs +612 -0
  53. package/dist/cli.d.ts +2 -0
  54. package/dist/cli.js +296 -0
  55. package/dist/cli.mjs +296 -0
  56. package/dist/dev.d.ts +5 -0
  57. package/dist/dev.js +7 -0
  58. package/dist/dev.mjs +7 -0
  59. package/dist/index.d.ts +40 -0
  60. package/dist/index.js +6 -0
  61. package/dist/index.mjs +6 -0
  62. package/package.json +97 -0
  63. package/src/core/cli.ts +0 -0
  64. package/src/runtime/App.tsx +38 -0
  65. package/src/runtime/Content.tsx +27 -0
  66. package/src/runtime/client-entry.tsx +30 -0
  67. package/src/runtime/hooks.ts +8 -0
  68. package/src/runtime/index.ts +2 -0
  69. package/src/runtime/ssr-entry.tsx +24 -0
  70. package/src/theme-default/Layout/doc/doc.tsx +46 -0
  71. package/src/theme-default/Layout/doc/index.module.scss +154 -0
  72. package/src/theme-default/Layout/home/home.tsx +16 -0
  73. package/src/theme-default/Layout/index.tsx +38 -0
  74. package/src/theme-default/Layout/notFound/index.module.scss +7 -0
  75. package/src/theme-default/Layout/notFound/index.tsx +30 -0
  76. package/src/theme-default/component/Button/index.module.scss +36 -0
  77. package/src/theme-default/component/Button/index.tsx +42 -0
  78. package/src/theme-default/component/Link/index.module.scss +10 -0
  79. package/src/theme-default/component/Link/index.tsx +28 -0
  80. package/src/theme-default/component/feature/index.module.scss +10 -0
  81. package/src/theme-default/component/feature/index.tsx +28 -0
  82. package/src/theme-default/component/footer/index.module.scss +4 -0
  83. package/src/theme-default/component/footer/index.tsx +13 -0
  84. package/src/theme-default/component/hero/index.module.scss +5 -0
  85. package/src/theme-default/component/hero/index.tsx +48 -0
  86. package/src/theme-default/component/nav/index.module.scss +24 -0
  87. package/src/theme-default/component/nav/index.tsx +43 -0
  88. package/src/theme-default/component/nextPage/index.module.scss +43 -0
  89. package/src/theme-default/component/nextPage/index.tsx +64 -0
  90. package/src/theme-default/component/sidebar/index.module.scss +22 -0
  91. package/src/theme-default/component/sidebar/index.tsx +52 -0
  92. package/src/theme-default/component/switchTheme/index.module.scss +0 -0
  93. package/src/theme-default/component/switchTheme/index.tsx +9 -0
  94. package/src/theme-default/component/toc/activeScroll.ts +37 -0
  95. package/src/theme-default/component/toc/index.module.scss +7 -0
  96. package/src/theme-default/component/toc/index.tsx +60 -0
  97. package/src/theme-default/styles/base.css +92 -0
  98. package/src/theme-default/styles/vars.css +111 -0
  99. package/src/types/attributify-shims.d.ts +5 -0
  100. package/src/types/index.ts +129 -0
  101. package/src/types/types.d.ts +16 -0
@@ -0,0 +1,605 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkLS3TOABUjs = require('./chunk-LS3TOABU.js');
4
+
5
+ // src/node/dev.ts
6
+ var _vite = require('vite');
7
+
8
+ // src/node/plugin/indexHtml.ts
9
+ var _promises = require('fs/promises');
10
+
11
+ // src/node/constants/index.ts
12
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
13
+ var PACKAGE_ROOT = _path.join.call(void 0, __dirname, "..");
14
+ var DEFAULT_HTML_PATH = _path.join.call(void 0, PACKAGE_ROOT, "template.html");
15
+ var CLIENT_ENTRY_PATH = _path.join.call(void 0, PACKAGE_ROOT, "src", "runtime", "client-entry.tsx");
16
+ var SERVER_ENTRY_PATH = _path.join.call(void 0, PACKAGE_ROOT, "src", "runtime", "ssr-entry.tsx");
17
+
18
+ // src/node/plugin/indexHtml.ts
19
+ function pluginIndexHtml() {
20
+ return {
21
+ name: "vigor: index-html",
22
+ apply: "serve",
23
+ transformIndexHtml(html) {
24
+ return {
25
+ html,
26
+ tags: [
27
+ {
28
+ tag: "script",
29
+ attrs: {
30
+ type: "module",
31
+ src: `/@fs/${CLIENT_ENTRY_PATH}`
32
+ },
33
+ injectTo: "body"
34
+ }
35
+ ]
36
+ };
37
+ },
38
+ configureServer(server) {
39
+ return () => {
40
+ server.middlewares.use(async (req, res, next) => {
41
+ let html = await _promises.readFile.call(void 0, DEFAULT_HTML_PATH, "utf-8");
42
+ try {
43
+ html = await server.transformIndexHtml(req.url, html, req.originalUrl);
44
+ res.statusCode = 200;
45
+ res.setHeader("Content-Type", "text/html");
46
+ res.end(html);
47
+ } catch (error) {
48
+ return next(error);
49
+ }
50
+ });
51
+ };
52
+ }
53
+ };
54
+ }
55
+
56
+ // src/node/dev.ts
57
+ var _pluginreact = require('@vitejs/plugin-react'); var _pluginreact2 = _interopRequireDefault(_pluginreact);
58
+
59
+ // src/node/plugin/config.ts
60
+
61
+ var _sirv = require('sirv'); var _sirv2 = _interopRequireDefault(_sirv);
62
+
63
+ var _fsextra = require('fs-extra'); var _fsextra2 = _interopRequireDefault(_fsextra);
64
+ var SITE_DATA_ID = "vigor:site-data";
65
+ function pluginConfig(config) {
66
+ return {
67
+ name: "vigor:site-data",
68
+ resolveId(id) {
69
+ if (id === SITE_DATA_ID) {
70
+ return "\0" + SITE_DATA_ID;
71
+ }
72
+ },
73
+ load(id) {
74
+ if (id === "\0" + SITE_DATA_ID) {
75
+ return `export default ${JSON.stringify(config.siteData)}`;
76
+ }
77
+ },
78
+ // 通过config钩子设置别名,此处设置的别名会自动与vite配置中的别名呼应
79
+ config() {
80
+ return {
81
+ root: PACKAGE_ROOT,
82
+ resolve: {
83
+ alias: {
84
+ "@runtime": _path.join.call(void 0, PACKAGE_ROOT, "src", "runtime", "index.ts"),
85
+ "@constants": _path.join.call(void 0, PACKAGE_ROOT, "src", "node", "constants", "index.ts"),
86
+ "@types": _path.join.call(void 0, PACKAGE_ROOT, "src", "types", "index.ts")
87
+ }
88
+ },
89
+ css: {
90
+ // 在scss中定义类名的时候使用 '-' 格式可以转换为小驼峰形式进行使用
91
+ // 比如:
92
+ // scss: .main-bg
93
+ // tsx: mainBg
94
+ modules: {
95
+ localsConvention: "camelCaseOnly"
96
+ }
97
+ }
98
+ };
99
+ },
100
+ // 构建一个配置服务器来加载docs文件夹下public中的静态资源
101
+ // sirv 是一个优化过的轻量级中间件,用来处理静态资源请求
102
+ configureServer(server) {
103
+ const publicDir = _path2.default.join(config.root, "public");
104
+ if (_fsextra2.default.pathExistsSync(publicDir)) {
105
+ server.middlewares.use(_sirv2.default.call(void 0, publicDir));
106
+ }
107
+ }
108
+ // 一个学习的内容,本身未实现,比较复杂的一个逻辑。
109
+ // 钩子函数:当配置文件发生改变时,达到热更新的效果
110
+ // async handleHotUpdate(ctx) {
111
+ // const customWatchedFiles = [config.configPath];
112
+ // const include = (id: string) => customWatchedFiles.some((file) => id.includes(file));
113
+ // if (include(ctx.file)) {
114
+ // `\n${relative(config.root, ctx.file)} has changed, restarting server...`;
115
+ // // 重启Dev Server的方案
116
+ // // 手动调用dev.ts中的createServer方法
117
+ // }
118
+ // },
119
+ };
120
+ }
121
+
122
+ // src/node/plugin/plugin-mdx/pluginMdxRollup.ts
123
+ var _rollup = require('@mdx-js/rollup'); var _rollup2 = _interopRequireDefault(_rollup);
124
+ var _remarkgfm = require('remark-gfm'); var _remarkgfm2 = _interopRequireDefault(_remarkgfm);
125
+ var _rehypeautolinkheadings = require('rehype-autolink-headings'); var _rehypeautolinkheadings2 = _interopRequireDefault(_rehypeautolinkheadings);
126
+ var _rehypeslug = require('rehype-slug'); var _rehypeslug2 = _interopRequireDefault(_rehypeslug);
127
+ var _remarkfrontmatter = require('remark-frontmatter'); var _remarkfrontmatter2 = _interopRequireDefault(_remarkfrontmatter);
128
+ var _remarkmdxfrontmatter = require('remark-mdx-frontmatter'); var _remarkmdxfrontmatter2 = _interopRequireDefault(_remarkmdxfrontmatter);
129
+
130
+ // node_modules/.pnpm/unist-util-is@5.2.1/node_modules/unist-util-is/lib/index.js
131
+ var convert = (
132
+ /**
133
+ * @type {(
134
+ * (<Kind extends Node>(test: PredicateTest<Kind>) => AssertPredicate<Kind>) &
135
+ * ((test?: Test) => AssertAnything)
136
+ * )}
137
+ */
138
+ /**
139
+ * @param {Test} [test]
140
+ * @returns {AssertAnything}
141
+ */
142
+ function(test) {
143
+ if (test === void 0 || test === null) {
144
+ return ok;
145
+ }
146
+ if (typeof test === "string") {
147
+ return typeFactory(test);
148
+ }
149
+ if (typeof test === "object") {
150
+ return Array.isArray(test) ? anyFactory(test) : propsFactory(test);
151
+ }
152
+ if (typeof test === "function") {
153
+ return castFactory(test);
154
+ }
155
+ throw new Error("Expected function, string, or object as test");
156
+ }
157
+ );
158
+ function anyFactory(tests) {
159
+ const checks = [];
160
+ let index = -1;
161
+ while (++index < tests.length) {
162
+ checks[index] = convert(tests[index]);
163
+ }
164
+ return castFactory(any);
165
+ function any(...parameters) {
166
+ let index2 = -1;
167
+ while (++index2 < checks.length) {
168
+ if (checks[index2].call(this, ...parameters))
169
+ return true;
170
+ }
171
+ return false;
172
+ }
173
+ }
174
+ function propsFactory(check) {
175
+ return castFactory(all);
176
+ function all(node) {
177
+ let key;
178
+ for (key in check) {
179
+ if (node[key] !== check[key])
180
+ return false;
181
+ }
182
+ return true;
183
+ }
184
+ }
185
+ function typeFactory(check) {
186
+ return castFactory(type);
187
+ function type(node) {
188
+ return node && node.type === check;
189
+ }
190
+ }
191
+ function castFactory(check) {
192
+ return assertion;
193
+ function assertion(node, ...parameters) {
194
+ return Boolean(
195
+ node && typeof node === "object" && "type" in node && // @ts-expect-error: fine.
196
+ Boolean(check.call(this, node, ...parameters))
197
+ );
198
+ }
199
+ }
200
+ function ok() {
201
+ return true;
202
+ }
203
+
204
+ // node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/color.js
205
+ function color(d) {
206
+ return "\x1B[33m" + d + "\x1B[39m";
207
+ }
208
+
209
+ // node_modules/.pnpm/unist-util-visit-parents@5.1.3/node_modules/unist-util-visit-parents/lib/index.js
210
+ var CONTINUE = true;
211
+ var EXIT = false;
212
+ var SKIP = "skip";
213
+ var visitParents = (
214
+ /**
215
+ * @type {(
216
+ * (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) &
217
+ * (<Tree extends Node>(tree: Tree, visitor: BuildVisitor<Tree>, reverse?: boolean | null | undefined) => void)
218
+ * )}
219
+ */
220
+ /**
221
+ * @param {Node} tree
222
+ * @param {Test} test
223
+ * @param {Visitor<Node>} visitor
224
+ * @param {boolean | null | undefined} [reverse]
225
+ * @returns {void}
226
+ */
227
+ function(tree, test, visitor, reverse) {
228
+ if (typeof test === "function" && typeof visitor !== "function") {
229
+ reverse = visitor;
230
+ visitor = test;
231
+ test = null;
232
+ }
233
+ const is2 = convert(test);
234
+ const step = reverse ? -1 : 1;
235
+ factory(tree, void 0, [])();
236
+ function factory(node, index, parents) {
237
+ const value = node && typeof node === "object" ? node : {};
238
+ if (typeof value.type === "string") {
239
+ const name = (
240
+ // `hast`
241
+ typeof value.tagName === "string" ? value.tagName : (
242
+ // `xast`
243
+ typeof value.name === "string" ? value.name : void 0
244
+ )
245
+ );
246
+ Object.defineProperty(visit2, "name", {
247
+ value: "node (" + color(node.type + (name ? "<" + name + ">" : "")) + ")"
248
+ });
249
+ }
250
+ return visit2;
251
+ function visit2() {
252
+ let result = [];
253
+ let subresult;
254
+ let offset;
255
+ let grandparents;
256
+ if (!test || is2(node, index, parents[parents.length - 1] || null)) {
257
+ result = toResult(visitor(node, parents));
258
+ if (result[0] === EXIT) {
259
+ return result;
260
+ }
261
+ }
262
+ if (node.children && result[0] !== SKIP) {
263
+ offset = (reverse ? node.children.length : -1) + step;
264
+ grandparents = parents.concat(node);
265
+ while (offset > -1 && offset < node.children.length) {
266
+ subresult = factory(node.children[offset], offset, grandparents)();
267
+ if (subresult[0] === EXIT) {
268
+ return subresult;
269
+ }
270
+ offset = typeof subresult[1] === "number" ? subresult[1] : offset + step;
271
+ }
272
+ }
273
+ return result;
274
+ }
275
+ }
276
+ }
277
+ );
278
+ function toResult(value) {
279
+ if (Array.isArray(value)) {
280
+ return value;
281
+ }
282
+ if (typeof value === "number") {
283
+ return [CONTINUE, value];
284
+ }
285
+ return [value];
286
+ }
287
+
288
+ // node_modules/.pnpm/unist-util-visit@4.1.2/node_modules/unist-util-visit/lib/index.js
289
+ var visit = (
290
+ /**
291
+ * @type {(
292
+ * (<Tree extends Node, Check extends Test>(tree: Tree, test: Check, visitor: BuildVisitor<Tree, Check>, reverse?: boolean | null | undefined) => void) &
293
+ * (<Tree extends Node>(tree: Tree, visitor: BuildVisitor<Tree>, reverse?: boolean | null | undefined) => void)
294
+ * )}
295
+ */
296
+ /**
297
+ * @param {Node} tree
298
+ * @param {Test} test
299
+ * @param {Visitor} visitor
300
+ * @param {boolean | null | undefined} [reverse]
301
+ * @returns {void}
302
+ */
303
+ function(tree, test, visitor, reverse) {
304
+ if (typeof test === "function" && typeof visitor !== "function") {
305
+ reverse = visitor;
306
+ visitor = test;
307
+ test = null;
308
+ }
309
+ visitParents(tree, test, overload, reverse);
310
+ function overload(node, parents) {
311
+ const parent = parents[parents.length - 1];
312
+ return visitor(
313
+ node,
314
+ parent ? parent.children.indexOf(node) : null,
315
+ parent
316
+ );
317
+ }
318
+ }
319
+ );
320
+
321
+ // src/node/plugin/plugin-mdx/rehypePlugins/preWrapper.ts
322
+ var preWrapperPlugin = () => {
323
+ return (tree) => {
324
+ visit(tree, "element", (node) => {
325
+ if (node.tagName === "pre" && _optionalChain([node, 'access', _ => _.children, 'access', _2 => _2[0], 'optionalAccess', _3 => _3.type]) === "element" && node.children[0].tagName === "code" && !_optionalChain([node, 'access', _4 => _4.data, 'optionalAccess', _5 => _5.isVisited])) {
326
+ const codeNode = node.children[0];
327
+ const codeClassName = _optionalChain([codeNode, 'access', _6 => _6.properties, 'optionalAccess', _7 => _7.className, 'optionalAccess', _8 => _8.toString, 'call', _9 => _9()]) || "";
328
+ const lang = codeClassName.split("-")[1];
329
+ const nodeClone = {
330
+ type: "element",
331
+ tagName: "pre",
332
+ children: node.children,
333
+ data: {
334
+ isVisited: true
335
+ }
336
+ };
337
+ node.tagName = "div";
338
+ node.properties = node.properties || {};
339
+ node.properties.className = codeClassName;
340
+ node.children = [
341
+ {
342
+ type: "element",
343
+ tagName: "span",
344
+ properties: {
345
+ className: "lang"
346
+ },
347
+ children: [
348
+ {
349
+ type: "text",
350
+ value: lang
351
+ }
352
+ ]
353
+ },
354
+ nodeClone
355
+ ];
356
+ }
357
+ });
358
+ };
359
+ };
360
+
361
+ // src/node/plugin/plugin-mdx/rehypePlugins/shiki.ts
362
+ var _hastutilfromhtml = require('hast-util-from-html');
363
+ var shikiPlugin = ({ highlighter }) => {
364
+ return (tree) => {
365
+ visit(tree, "element", (node, index, parent) => {
366
+ if (node.tagName === "pre" && _optionalChain([node, 'access', _10 => _10.children, 'access', _11 => _11[0], 'optionalAccess', _12 => _12.type]) === "element" && _optionalChain([node, 'access', _13 => _13.children, 'access', _14 => _14[0], 'optionalAccess', _15 => _15.tagName]) === "code") {
367
+ const codeNode = node.children[0];
368
+ const codeContent = codeNode.children[0].value;
369
+ const codeClassName = _optionalChain([codeNode, 'access', _16 => _16.properties, 'optionalAccess', _17 => _17.className, 'optionalAccess', _18 => _18.toString, 'call', _19 => _19()]) || "";
370
+ const lang = codeClassName.split("-")[1];
371
+ if (!lang)
372
+ return;
373
+ const highlightCode = highlighter.codeToHtml(codeContent, { lang });
374
+ const fragmentAST = _hastutilfromhtml.fromHtml.call(void 0, highlightCode, { fragment: true });
375
+ parent.children.splice(index, 1, ...fragmentAST.children);
376
+ }
377
+ });
378
+ };
379
+ };
380
+
381
+ // src/node/plugin/plugin-mdx/pluginMdxRollup.ts
382
+ var _shiki = require('shiki'); var _shiki2 = _interopRequireDefault(_shiki);
383
+
384
+ // src/node/plugin/plugin-mdx/remarkPlugins/toc.ts
385
+ var _githubslugger = require('github-slugger'); var _githubslugger2 = _interopRequireDefault(_githubslugger);
386
+ var _acorn = require('acorn');
387
+ var slugger = new (0, _githubslugger2.default)();
388
+ var TOCPlugin = () => {
389
+ return (tree) => {
390
+ const tocTree = [];
391
+ visit(tree, "heading", (node) => {
392
+ if (!node.depth || !node.children) {
393
+ return;
394
+ }
395
+ if (node.depth > 1 && node.depth < 5) {
396
+ const originText = node.children.map((child) => {
397
+ switch (child.type) {
398
+ case "link":
399
+ return _optionalChain([child, 'access', _20 => _20.children, 'optionalAccess', _21 => _21.map, 'call', _22 => _22((c) => c.value), 'access', _23 => _23.join, 'call', _24 => _24("")]) || "";
400
+ default:
401
+ return child.value;
402
+ }
403
+ }).join("");
404
+ const id = slugger.slug(originText);
405
+ tocTree.push({
406
+ id,
407
+ text: originText,
408
+ depth: node.depth
409
+ });
410
+ }
411
+ });
412
+ const insertCode = `export const toc = ${JSON.stringify(tocTree, null, 2)};`;
413
+ tree.children.push({
414
+ type: "mdxjsEsm",
415
+ value: insertCode,
416
+ data: {
417
+ estree: _acorn.parse.call(void 0, insertCode, {
418
+ ecmaVersion: 2020,
419
+ sourceType: "module"
420
+ })
421
+ }
422
+ });
423
+ };
424
+ };
425
+
426
+ // src/node/plugin/plugin-mdx/pluginMdxRollup.ts
427
+ async function pluginMdxRollup() {
428
+ return _rollup2.default.call(void 0, {
429
+ // 添加github的markdown标准-GFM语法
430
+ remarkPlugins: [
431
+ _remarkgfm2.default,
432
+ _remarkfrontmatter2.default,
433
+ [_remarkmdxfrontmatter2.default, { name: "frontmatter" }],
434
+ TOCPlugin
435
+ ],
436
+ // md文件解析插件
437
+ rehypePlugins: [
438
+ _rehypeslug2.default,
439
+ [
440
+ _rehypeautolinkheadings2.default,
441
+ {
442
+ properties: {
443
+ class: "header-anchor"
444
+ },
445
+ content: {
446
+ type: "text",
447
+ value: "#"
448
+ }
449
+ }
450
+ ],
451
+ preWrapperPlugin,
452
+ [shikiPlugin, { highlighter: await _shiki2.default.getHighlighter({ theme: "nord" }) }]
453
+ ]
454
+ });
455
+ }
456
+
457
+ // src/node/plugin/plugin-mdx/index.ts
458
+ async function pluginMdx2() {
459
+ return [await pluginMdxRollup()];
460
+ }
461
+
462
+ // src/node/plugin/plugin-routes/RouteService.ts
463
+ var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);
464
+
465
+
466
+ var RouteService = class {
467
+ // #scanDir是定义一个私有变量
468
+ #scanDir;
469
+ // 路由信息数组
470
+ #routeData = [];
471
+ constructor(scanDir) {
472
+ this.#scanDir = scanDir;
473
+ }
474
+ async init() {
475
+ const files = _fastglob2.default.sync(["**/*.{js,jsx,ts,tsx,md,mdx}"], {
476
+ cwd: this.#scanDir,
477
+ absolute: true,
478
+ ignore: ["**/build/**", "**/.vigor/**", "config.ts", "tsconfig.json"]
479
+ }).sort();
480
+ files.forEach((file) => {
481
+ const fileRelativePath = _vite.normalizePath.call(void 0, _path2.default.relative(this.#scanDir, file));
482
+ const routePath = this.getRoutePath(fileRelativePath);
483
+ this.#routeData.push({
484
+ routePath,
485
+ absolutePath: file
486
+ });
487
+ });
488
+ }
489
+ // 得到路由路径
490
+ getRoutePath(fileRelativePath) {
491
+ const routePath = fileRelativePath.replace(/\.(.*)?$/, "").replace(/index$/, "");
492
+ return routePath.startsWith("/") ? routePath : `/${routePath}`;
493
+ }
494
+ // 生成路由页面代码
495
+ generateRoutesPath(ssr) {
496
+ return `
497
+ import React from 'react';
498
+ ${ssr ? "" : 'import loadable from "@loadable/component";'}
499
+ ${this.#routeData.map((route, index) => {
500
+ return ssr ? `import Route${index} from "${_vite.normalizePath.call(void 0, route.absolutePath)}";` : `const Route${index} = loadable(() => import('${_vite.normalizePath.call(void 0,
501
+ route.absolutePath
502
+ )}')); `;
503
+ }).join("\n")}
504
+
505
+ export const routes = [
506
+ ${this.#routeData.map((route, index) => {
507
+ return `{ path: '${_vite.normalizePath.call(void 0,
508
+ route.routePath
509
+ )}', element: React.createElement(Route${index}), preload: () => import('${_vite.normalizePath.call(void 0,
510
+ route.absolutePath
511
+ )}') },`;
512
+ }).join("\n")}
513
+ ]
514
+ `;
515
+ }
516
+ // 设定一个访问私有变量的api,用来单元测试
517
+ getRouteData() {
518
+ return this.#routeData;
519
+ }
520
+ };
521
+
522
+ // src/node/plugin/plugin-routes/index.ts
523
+ var CONVENTIONAL_ROUTE_ID = "vigor:routes";
524
+ function pluginRoutes(options2) {
525
+ const rootService = new RouteService(options2.root);
526
+ return {
527
+ name: "vigor:routes",
528
+ async configResolved() {
529
+ await rootService.init();
530
+ },
531
+ resolveId(id) {
532
+ if (id === CONVENTIONAL_ROUTE_ID) {
533
+ return "\0" + id;
534
+ }
535
+ },
536
+ load(id) {
537
+ if (id === "\0" + CONVENTIONAL_ROUTE_ID) {
538
+ return rootService.generateRoutesPath(options2.isSSR || false);
539
+ }
540
+ }
541
+ };
542
+ }
543
+
544
+ // src/node/dev.ts
545
+ var _vite3 = require('unocss/vite'); var _vite4 = _interopRequireDefault(_vite3);
546
+
547
+ // src/node/unocssOptions.ts
548
+ var _unocss = require('unocss');
549
+ var options = {
550
+ presets: [_unocss.presetAttributify.call(void 0, ), _unocss.presetIcons.call(void 0, ), _unocss.presetWind.call(void 0, )],
551
+ rules: [
552
+ // 下面这种写法和此种写法是一样的,只不过用正则会更加灵活
553
+ // [
554
+ // "divider-bottom",
555
+ // {
556
+ // "border-bottom": "1px solid var(--island-c-divider-light)"
557
+ // }
558
+ // ]
559
+ [
560
+ /^divider-(\w+)$/,
561
+ ([, w]) => ({
562
+ [`border-${w}`]: "1px solid var(--vigor-c-divider-light)"
563
+ })
564
+ ]
565
+ ],
566
+ shortcuts: {
567
+ "flex-center": "flex justify-center items-center"
568
+ }
569
+ };
570
+ var unocssOptions_default = options;
571
+
572
+ // src/node/dev.ts
573
+ async function createDevServer(root, isSSR = false) {
574
+ const config = await _chunkLS3TOABUjs.resolveConfig.call(void 0, root, "serve", "development");
575
+ return _vite.createServer.call(void 0, {
576
+ root: PACKAGE_ROOT,
577
+ // 插件注册
578
+ plugins: [
579
+ _vite4.default.call(void 0, unocssOptions_default),
580
+ pluginIndexHtml(),
581
+ _pluginreact2.default.call(void 0, ),
582
+ pluginConfig(config),
583
+ pluginRoutes({ root: config.root, isSSR }),
584
+ await pluginMdx2()
585
+ ],
586
+ // 配置e2e的服务器检索目录外的项目的合法性
587
+ server: {
588
+ fs: {
589
+ allow: [PACKAGE_ROOT]
590
+ }
591
+ }
592
+ });
593
+ }
594
+
595
+
596
+
597
+
598
+
599
+
600
+
601
+
602
+
603
+
604
+
605
+ exports.PACKAGE_ROOT = PACKAGE_ROOT; exports.CLIENT_ENTRY_PATH = CLIENT_ENTRY_PATH; exports.SERVER_ENTRY_PATH = SERVER_ENTRY_PATH; exports.pluginIndexHtml = pluginIndexHtml; exports.pluginConfig = pluginConfig; exports.pluginMdx = pluginMdx2; exports.pluginRoutes = pluginRoutes; exports.unocssOptions_default = unocssOptions_default; exports.createDevServer = createDevServer;