@rspress/core 2.0.0-beta.20 → 2.0.0-beta.21
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/208.js +39 -0
- package/dist/309.js +27 -0
- package/dist/94.js +1787 -0
- package/dist/index.d.ts +66 -6
- package/dist/index.js +388 -178
- package/dist/loader.d.ts +1 -1
- package/dist/processor.d.ts +1 -1
- package/dist/processor.js +59 -7
- package/dist/runtime.d.ts +8 -0
- package/dist/runtime.js +3 -0
- package/dist/shiki-transformers.js +6 -6
- package/dist/theme.d.ts +4 -0
- package/dist/theme.js +1 -0
- package/package.json +17 -16
- package/static/MediumZoom.css +5 -0
- package/static/MediumZoom.tsx +29 -0
- package/runtime.ts +0 -1
- package/theme.ts +0 -1
package/dist/loader.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ declare class RouteService {
|
|
|
75
75
|
getRoutePages(): RoutePage[];
|
|
76
76
|
isExistRoute(routePath: string): boolean;
|
|
77
77
|
generateRoutesCode(): string;
|
|
78
|
-
generateRoutesCodeByRouteMeta
|
|
78
|
+
private generateRoutesCodeByRouteMeta;
|
|
79
79
|
getRoutePathParts(relativePath: string): readonly [string, string, string];
|
|
80
80
|
normalizeRoutePath(relativePath: string): {
|
|
81
81
|
pureRoutePath: string;
|
package/dist/processor.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ declare class RouteService {
|
|
|
77
77
|
getRoutePages(): RoutePage[];
|
|
78
78
|
isExistRoute(routePath: string): boolean;
|
|
79
79
|
generateRoutesCode(): string;
|
|
80
|
-
generateRoutesCodeByRouteMeta
|
|
80
|
+
private generateRoutesCodeByRouteMeta;
|
|
81
81
|
getRoutePathParts(relativePath: string): readonly [string, string, string];
|
|
82
82
|
normalizeRoutePath(relativePath: string): {
|
|
83
83
|
pureRoutePath: string;
|
package/dist/processor.js
CHANGED
|
@@ -13,7 +13,7 @@ import { visit } from "unist-util-visit";
|
|
|
13
13
|
import { addTrailingSlash, isExternalUrl, isProduction, normalizeHref, parseUrl, removeTrailingSlash, withBase } from "@rspress/shared";
|
|
14
14
|
import { logger as logger_logger } from "@rspress/shared/logger";
|
|
15
15
|
import picocolors_0 from "picocolors";
|
|
16
|
-
import "node:fs/promises";
|
|
16
|
+
import { readFile as promises_readFile } from "node:fs/promises";
|
|
17
17
|
import { visitChildren } from "unist-util-visit-children";
|
|
18
18
|
import rehype from "@shikijs/rehype";
|
|
19
19
|
import { createCssVariablesTheme } from "shiki";
|
|
@@ -317,12 +317,12 @@ function transformerLineNumber(options = {}) {
|
|
|
317
317
|
const SHIKI_TRANSFORMER_ADD_TITLE = 'shiki-transformer:add-title';
|
|
318
318
|
function parseTitleFromMeta(meta) {
|
|
319
319
|
if (!meta) return '';
|
|
320
|
-
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return
|
|
320
|
+
const kvList = meta.split(' ').filter(Boolean);
|
|
321
|
+
for (const item of kvList){
|
|
322
|
+
const [k, v] = item.split('=');
|
|
323
|
+
if ('title' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
324
|
+
}
|
|
325
|
+
return '';
|
|
326
326
|
}
|
|
327
327
|
function transformerAddTitle() {
|
|
328
328
|
return {
|
|
@@ -562,6 +562,52 @@ function transformer(tree) {
|
|
|
562
562
|
}
|
|
563
563
|
}
|
|
564
564
|
const remarkContainerSyntax = ()=>transformer;
|
|
565
|
+
const ERROR_PREFIX = '[remarkFileCodeBlock]';
|
|
566
|
+
function parseFileFromMeta(meta) {
|
|
567
|
+
if (!meta) return '';
|
|
568
|
+
const kvList = meta.split(' ').filter(Boolean);
|
|
569
|
+
for (const item of kvList){
|
|
570
|
+
const [k, v] = item.split('=');
|
|
571
|
+
if ('file' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
572
|
+
}
|
|
573
|
+
return '';
|
|
574
|
+
}
|
|
575
|
+
const remarkFileCodeBlock = ({ filepath })=>async (tree)=>{
|
|
576
|
+
const promiseList = [];
|
|
577
|
+
visit(tree, 'code', (node)=>{
|
|
578
|
+
const { meta, value } = node;
|
|
579
|
+
const file = parseFileFromMeta(meta ?? '');
|
|
580
|
+
if (!file) return;
|
|
581
|
+
if (file.startsWith('./') || file.startsWith('../')) {
|
|
582
|
+
const resolvedFilePath = node_path.join(node_path.dirname(filepath), file);
|
|
583
|
+
if ('' !== value.trim()) {
|
|
584
|
+
logger_logger.error(`${ERROR_PREFIX} The content of file code block should be empty.
|
|
585
|
+
|
|
586
|
+
\`\`\`tsx file="./filename"
|
|
587
|
+
content
|
|
588
|
+
\`\`\`
|
|
589
|
+
|
|
590
|
+
this usage is not allowed, please use below:
|
|
591
|
+
|
|
592
|
+
\`\`\`tsx file="./filename"
|
|
593
|
+
\`\`\`
|
|
594
|
+
`);
|
|
595
|
+
throw new Error(`${ERROR_PREFIX} The content of file code block should be empty.`);
|
|
596
|
+
}
|
|
597
|
+
const promise = promises_readFile(resolvedFilePath, 'utf-8').then((fileContent)=>{
|
|
598
|
+
node.value = fileContent;
|
|
599
|
+
}).catch((e)=>{
|
|
600
|
+
logger_logger.error(`${ERROR_PREFIX} The file does not exist.
|
|
601
|
+
\`file="${file}"\` is resolved to ${resolvedFilePath}"`);
|
|
602
|
+
throw e;
|
|
603
|
+
});
|
|
604
|
+
promiseList.push(promise);
|
|
605
|
+
return;
|
|
606
|
+
}
|
|
607
|
+
throw new Error(`${ERROR_PREFIX} The file path should use relative path "./" or "../"`);
|
|
608
|
+
});
|
|
609
|
+
await Promise.all(promiseList);
|
|
610
|
+
};
|
|
565
611
|
async function createMDXOptions(options) {
|
|
566
612
|
const { docDirectory, config, checkDeadLinks, routeService, filepath, pluginDriver } = options;
|
|
567
613
|
const format = node_path.extname(filepath).slice(1);
|
|
@@ -581,6 +627,12 @@ async function createMDXOptions(options) {
|
|
|
581
627
|
remark_gfm,
|
|
582
628
|
remarkPluginToc,
|
|
583
629
|
remarkContainerSyntax,
|
|
630
|
+
[
|
|
631
|
+
remarkFileCodeBlock,
|
|
632
|
+
{
|
|
633
|
+
filepath
|
|
634
|
+
}
|
|
635
|
+
],
|
|
584
636
|
[
|
|
585
637
|
remarkPluginNormalizeLink,
|
|
586
638
|
{
|
package/dist/runtime.js
ADDED
|
@@ -15,12 +15,12 @@ function transformerLineNumber(options = {}) {
|
|
|
15
15
|
const SHIKI_TRANSFORMER_ADD_TITLE = 'shiki-transformer:add-title';
|
|
16
16
|
function parseTitleFromMeta(meta) {
|
|
17
17
|
if (!meta) return '';
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return
|
|
18
|
+
const kvList = meta.split(' ').filter(Boolean);
|
|
19
|
+
for (const item of kvList){
|
|
20
|
+
const [k, v] = item.split('=');
|
|
21
|
+
if ('title' === k && v.length > 0) return v.replace(/["'`]/g, '');
|
|
22
|
+
}
|
|
23
|
+
return '';
|
|
24
24
|
}
|
|
25
25
|
function transformerAddTitle() {
|
|
26
26
|
return {
|
package/dist/theme.d.ts
ADDED
package/dist/theme.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@rspress/theme-default";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rspress/core",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.21",
|
|
4
4
|
"description": "The Rspress Documentation Framework",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
|
6
6
|
"repository": {
|
|
@@ -24,14 +24,16 @@
|
|
|
24
24
|
"./dist/*": "./dist/*",
|
|
25
25
|
"./package.json": "./package.json",
|
|
26
26
|
"./theme": {
|
|
27
|
-
"
|
|
27
|
+
"types": "./dist/theme.d.ts",
|
|
28
|
+
"default": "./dist/theme.js"
|
|
29
|
+
},
|
|
30
|
+
"./runtime": {
|
|
31
|
+
"types": "./dist/runtime.d.ts",
|
|
32
|
+
"default": "./dist/runtime.js"
|
|
28
33
|
},
|
|
29
34
|
"./shiki-transformers": {
|
|
30
35
|
"types": "./dist/shiki-transformers.d.ts",
|
|
31
36
|
"default": "./dist/shiki-transformers.js"
|
|
32
|
-
},
|
|
33
|
-
"./runtime": {
|
|
34
|
-
"default": "./runtime.ts"
|
|
35
37
|
}
|
|
36
38
|
},
|
|
37
39
|
"main": "./dist/index.js",
|
|
@@ -39,16 +41,15 @@
|
|
|
39
41
|
"types": "./dist/index.d.ts",
|
|
40
42
|
"files": [
|
|
41
43
|
"dist",
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"theme.ts"
|
|
44
|
+
"static",
|
|
45
|
+
"index.html"
|
|
45
46
|
],
|
|
46
47
|
"dependencies": {
|
|
47
48
|
"@mdx-js/loader": "^3.1.0",
|
|
48
49
|
"@mdx-js/mdx": "^3.1.0",
|
|
49
50
|
"@mdx-js/react": "^3.1.0",
|
|
50
|
-
"@rsbuild/core": "~1.4.
|
|
51
|
-
"@rsbuild/plugin-react": "~1.3.
|
|
51
|
+
"@rsbuild/core": "~1.4.6",
|
|
52
|
+
"@rsbuild/plugin-react": "~1.3.4",
|
|
52
53
|
"@rspress/mdx-rs": "0.6.6",
|
|
53
54
|
"@shikijs/rehype": "^3.4.2",
|
|
54
55
|
"@types/unist": "^3.0.3",
|
|
@@ -60,6 +61,7 @@
|
|
|
60
61
|
"html-to-text": "^9.0.5",
|
|
61
62
|
"lodash-es": "^4.17.21",
|
|
62
63
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
64
|
+
"medium-zoom": "1.1.0",
|
|
63
65
|
"picocolors": "^1.1.1",
|
|
64
66
|
"react": "^19.1.0",
|
|
65
67
|
"react-dom": "^19.1.0",
|
|
@@ -75,15 +77,13 @@
|
|
|
75
77
|
"unified": "^11.0.5",
|
|
76
78
|
"unist-util-visit": "^5.0.0",
|
|
77
79
|
"unist-util-visit-children": "^3.0.0",
|
|
78
|
-
"@rspress/
|
|
79
|
-
"@rspress/
|
|
80
|
-
"@rspress/
|
|
81
|
-
"@rspress/shared": "2.0.0-beta.20",
|
|
82
|
-
"@rspress/theme-default": "2.0.0-beta.20"
|
|
80
|
+
"@rspress/runtime": "2.0.0-beta.21",
|
|
81
|
+
"@rspress/shared": "2.0.0-beta.21",
|
|
82
|
+
"@rspress/theme-default": "2.0.0-beta.21"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@microsoft/api-extractor": "^7.52.8",
|
|
86
|
-
"@rslib/core": "0.10.
|
|
86
|
+
"@rslib/core": "0.10.5",
|
|
87
87
|
"@rspress-dev/plugin-preview": "link:../plugin-preview",
|
|
88
88
|
"@types/hast": "^3.0.4",
|
|
89
89
|
"@types/html-to-text": "^9.0.4",
|
|
@@ -93,6 +93,7 @@
|
|
|
93
93
|
"@types/node": "^22.8.1",
|
|
94
94
|
"@types/react": "^19.1.8",
|
|
95
95
|
"@types/react-dom": "^19.1.6",
|
|
96
|
+
"execa": "8.0.1",
|
|
96
97
|
"mdast-util-mdx-expression": "^2.0.1",
|
|
97
98
|
"memfs": "^4.17.2",
|
|
98
99
|
"p-map": "^7.0.3",
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { useLocation } from '@rspress/runtime';
|
|
2
|
+
import mediumZoom, { type Zoom, type ZoomOptions } from 'medium-zoom';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import './MediumZoom.css';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
selector?: string;
|
|
8
|
+
options?: ZoomOptions;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function MediumZoom(props: Props) {
|
|
12
|
+
const { pathname } = useLocation();
|
|
13
|
+
const { selector = '.rspress-doc img', options = {} } = props;
|
|
14
|
+
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
let zoom: Zoom | undefined;
|
|
17
|
+
const timeout = setTimeout(() => {
|
|
18
|
+
const images = document.querySelectorAll(selector);
|
|
19
|
+
zoom = mediumZoom(images, { ...options, background: 'var(--rp-c-bg)' });
|
|
20
|
+
}, 100);
|
|
21
|
+
return () => {
|
|
22
|
+
clearTimeout(timeout);
|
|
23
|
+
zoom?.detach();
|
|
24
|
+
zoom?.close();
|
|
25
|
+
};
|
|
26
|
+
}, [pathname]);
|
|
27
|
+
|
|
28
|
+
return null;
|
|
29
|
+
}
|
package/runtime.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@rspress/runtime';
|
package/theme.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from '@rspress/theme-default';
|