@rspress/core 2.1.0 → 2.1.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/b~0.js ADDED
@@ -0,0 +1 @@
1
+ export { transformerNotationDiff, transformerNotationErrorLevel, transformerNotationFocus, transformerNotationHighlight, transformerNotationWordHighlight, transformerRemoveNotationEscape } from "@shikijs/transformers";
@@ -1,3 +1,4 @@
1
+ import { getShikiTransformers } from '@rspress/core/shiki-transformers';
1
2
  import type { CodeBlockProps } from '@rspress/core/theme';
2
3
  import { getCustomMDXComponent } from '@rspress/core/theme';
3
4
  import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
@@ -99,6 +100,7 @@ export function CodeBlockRuntime({
99
100
  lang,
100
101
  theme: cssVariablesTheme,
101
102
  ...shikiOptions,
103
+ transformers: getShikiTransformers(shikiOptions?.transformers),
102
104
  });
103
105
 
104
106
  // 1. for async race condition, only set child if the code is still the same
@@ -85,6 +85,10 @@
85
85
  gap: 1rem;
86
86
  align-items: flex-start;
87
87
  justify-content: space-between;
88
+
89
+ @media (max-width: 768px) {
90
+ flex-direction: column;
91
+ }
88
92
  }
89
93
 
90
94
  &__header-left {
@@ -164,6 +168,10 @@
164
168
  gap: 0.5rem;
165
169
  align-items: center;
166
170
  flex-shrink: 0;
171
+
172
+ @media (max-width: 768px) {
173
+ align-self: flex-end;
174
+ }
167
175
  }
168
176
 
169
177
  &__title {
@@ -31,3 +31,29 @@ html.rp-appearance-transition .rspress-doc {
31
31
  .dark::view-transition-old(root) {
32
32
  z-index: 9999;
33
33
  }
34
+
35
+ /* Keep clip-path sampling on the main thread in Chromium, including the
36
+ boundary frames. */
37
+ html.rp-appearance-transition::view-transition-old(root),
38
+ html.rp-appearance-transition::view-transition-new(root) {
39
+ will-change: contents;
40
+ }
41
+
42
+ /* CSS starts clipping when the snapshots are created, without waiting for a
43
+ ready callback to attach an animation. Always animate the light snapshot. */
44
+ html.rp-appearance-transition:not(.dark)::view-transition-new(root) {
45
+ animation: rp-appearance 400ms ease-in both;
46
+ }
47
+
48
+ html.rp-appearance-transition.dark::view-transition-old(root) {
49
+ animation: rp-appearance 400ms ease-in reverse both;
50
+ }
51
+
52
+ @keyframes rp-appearance {
53
+ from {
54
+ clip-path: var(--rp-vt-clip-start);
55
+ }
56
+ to {
57
+ clip-path: var(--rp-vt-clip-end);
58
+ }
59
+ }
@@ -13,62 +13,73 @@ const supportAppearanceTransition = () => {
13
13
  );
14
14
  };
15
15
 
16
- // Toggles the `html.rp-appearance-transition` rule in global.scss — see the
17
- // comment there and https://github.com/web-infra-dev/rspress/pull/1272
18
- const removeClipViewTransition = () => {
19
- document.documentElement.classList.add('rp-appearance-transition');
20
- return () => {
21
- document.documentElement.classList.remove('rp-appearance-transition');
22
- };
23
- };
16
+ // Shared by all appearance switches, including the desktop and mobile menus.
17
+ let isAppearanceTransitioning = false;
24
18
 
25
19
  export function SwitchAppearance({ onClick }: { onClick?: () => void }) {
26
20
  const { theme, setTheme = () => {} } = useContext(ThemeContext);
27
21
  const { site } = useSite();
28
22
 
29
23
  const handleClick = (event: MouseEvent) => {
24
+ if (isAppearanceTransitioning) {
25
+ return;
26
+ }
27
+
30
28
  const supported = supportAppearanceTransition();
31
29
  const enabled = site?.themeConfig?.enableAppearanceAnimation;
32
30
 
33
31
  const nextTheme = theme === 'dark' ? 'light' : 'dark';
34
- const isDark = nextTheme === 'dark';
35
32
 
36
33
  if (supported && enabled) {
34
+ isAppearanceTransitioning = true;
37
35
  const x = event.clientX;
38
36
  const y = event.clientY;
39
-
40
- const dispose = removeClipViewTransition();
41
- const transition = document.startViewTransition(async () => {
42
- flushSync(() => {
43
- setTheme(nextTheme);
44
- onClick?.();
45
- });
46
- });
47
-
48
37
  const clipPath = getClipPath({
49
38
  height: innerHeight,
50
39
  width: innerWidth,
51
40
  x,
52
41
  y,
53
42
  });
54
- transition.ready.then(() => {
55
- document.documentElement.animate(
56
- {
57
- clipPath: isDark ? [...clipPath].reverse() : clipPath,
58
- },
59
- {
60
- duration: 400,
61
- easing: 'ease-in',
62
- fill: 'both',
63
- pseudoElement: isDark
64
- ? '::view-transition-old(root)'
65
- : '::view-transition-new(root)',
43
+ const root = document.documentElement;
44
+ root.style.setProperty('--rp-vt-clip-start', clipPath[0]);
45
+ root.style.setProperty('--rp-vt-clip-end', clipPath[1]);
46
+ root.classList.add('rp-appearance-transition');
66
47
 
67
- id: '',
68
- },
69
- );
70
- });
71
- transition.finished.then(dispose, dispose);
48
+ const cleanup = () => {
49
+ root.classList.remove('rp-appearance-transition');
50
+ root.style.removeProperty('--rp-vt-clip-start');
51
+ root.style.removeProperty('--rp-vt-clip-end');
52
+ isAppearanceTransitioning = false;
53
+ };
54
+
55
+ let updated = false;
56
+ const updateTheme = () => {
57
+ updated = true;
58
+ flushSync(() => {
59
+ setTheme(nextTheme);
60
+ onClick?.();
61
+ });
62
+ };
63
+
64
+ try {
65
+ const transition = document.startViewTransition(async () => {
66
+ updateTheme();
67
+ });
68
+ transition.updateCallbackDone.catch(() => {
69
+ transition.skipTransition();
70
+ });
71
+ transition.ready.catch(() => {
72
+ // Skipping still runs the update callback. Keep ownership until
73
+ // finished settles so a late callback cannot race another switch.
74
+ transition.skipTransition();
75
+ });
76
+ transition.finished.then(cleanup, cleanup);
77
+ } catch {
78
+ cleanup();
79
+ if (!updated) {
80
+ updateTheme();
81
+ }
82
+ }
72
83
  } else {
73
84
  setTheme(nextTheme);
74
85
  onClick?.();
@@ -1,4 +1,4 @@
1
- import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddFold, createCssVariablesTheme, transformerAddWrapCode } from "../../../tx~0.js";
1
+ import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddFold, getShikiTransformers, transformerAddWrapCode, createCssVariablesTheme } from "../../../tx~0.js";
2
2
  const cssVariablesTheme = createCssVariablesTheme({
3
3
  name: 'css-variables',
4
4
  variablePrefix: '--shiki-',
@@ -19,7 +19,7 @@ function createRehypeShikiOptions(showLineNumbers, defaultWrapCode, defaultCodeO
19
19
  transformerAddFold({
20
20
  defaultCodeOverflow
21
21
  }),
22
- ...transformers
22
+ ...getShikiTransformers(transformers)
23
23
  ];
24
24
  return {
25
25
  theme: cssVariablesTheme,
@@ -20,6 +20,6 @@ export interface TransformerMetaHighlightOptions {
20
20
  export declare const SHIKI_TRANSFORMER_META_HIGHLIGHT = "shiki-transformer:compatible-meta-highlight";
21
21
  /**
22
22
  * Allow using `{1,3-5}` in the code snippet meta to mark highlighted lines.
23
- * @deprecated This is a workaround when migrating to Rspress 2.0, you should migrate to `import { transformerNotationHighlight } from '@shikijs/transformers'` instead.
23
+ * @deprecated This is a workaround when migrating to Rspress 2.0, you should migrate to `import { transformerNotationHighlight } from '@rspress/core/shiki-transformers'` instead.
24
24
  */
25
25
  export declare function transformerCompatibleMetaHighlight(options?: TransformerMetaHighlightOptions): ShikiTransformer;
@@ -1 +1,5 @@
1
+ import type { ShikiTransformer } from 'shiki';
2
+ export * from '@shikijs/transformers';
1
3
  export * from './node/mdx/rehypePlugins/transformers/index.js';
4
+ /** @internal */
5
+ export declare function getShikiTransformers(transformers?: ShikiTransformer[]): ShikiTransformer[];
@@ -1,7 +1,25 @@
1
+ import { transformerNotationDiff, transformerNotationWordHighlight, transformerNotationFocus, transformerNotationErrorLevel, transformerRemoveNotationEscape, transformerNotationHighlight } from "./b~0.js";
1
2
  import "./node/mdx/rehypePlugins/transformers/index.js";
3
+ export * from "@shikijs/transformers";
4
+ function getShikiTransformers(transformers = []) {
5
+ const customNames = new Set(transformers.map((transformer)=>transformer.name));
6
+ const defaults = [
7
+ transformerNotationHighlight(),
8
+ transformerNotationWordHighlight(),
9
+ transformerNotationDiff(),
10
+ transformerNotationFocus(),
11
+ transformerNotationErrorLevel(),
12
+ transformerRemoveNotationEscape()
13
+ ];
14
+ return [
15
+ ...transformers,
16
+ ...defaults.filter((transformer)=>!customNames.has(transformer.name))
17
+ ];
18
+ }
2
19
  export { SHIKI_TRANSFORMER_ADD_FOLD, transformerAddFold } from "./node/mdx/rehypePlugins/transformers/add-fold.js";
3
20
  export { SHIKI_TRANSFORMER_ADD_LANG, transformerAddLang } from "./node/mdx/rehypePlugins/transformers/add-lang.js";
4
21
  export { SHIKI_TRANSFORMER_ADD_LINE_NUMBERS, transformerAddLineNumbers } from "./node/mdx/rehypePlugins/transformers/add-line-numbers.js";
5
22
  export { SHIKI_TRANSFORMER_ADD_TITLE, transformerAddTitle } from "./node/mdx/rehypePlugins/transformers/add-title.js";
6
23
  export { SHIKI_TRANSFORMER_ADD_WRAP_CODE, transformerAddWrapCode } from "./node/mdx/rehypePlugins/transformers/add-wrap-code.js";
7
24
  export { SHIKI_TRANSFORMER_META_HIGHLIGHT, transformerCompatibleMetaHighlight } from "./node/mdx/rehypePlugins/transformers/meta-highlight.js";
25
+ export { getShikiTransformers };
@@ -1,4 +1,5 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { getShikiTransformers } from "@rspress/core/shiki-transformers";
2
3
  import { getCustomMDXComponent } from "@rspress/core/theme";
3
4
  import { toJsxRuntime } from "hast-util-to-jsx-runtime";
4
5
  import { Fragment, useEffect, useMemo, useRef, useState } from "react";
@@ -51,7 +52,8 @@ function CodeBlockRuntime({ lang, title, code, shikiOptions, codeButtonGroupProp
51
52
  const hast = await codeToHast(code, {
52
53
  lang,
53
54
  theme: cssVariablesTheme,
54
- ...shikiOptions
55
+ ...shikiOptions,
56
+ transformers: getShikiTransformers(shikiOptions?.transformers)
55
57
  });
56
58
  if (codeRef.current.length !== code.length) return;
57
59
  const reactNode = toJsxRuntime(hast, {
@@ -65,6 +65,12 @@
65
65
  display: flex;
66
66
  }
67
67
 
68
+ @media (width <= 768px) {
69
+ .rp-prompt__header-row {
70
+ flex-direction: column;
71
+ }
72
+ }
73
+
68
74
  .rp-prompt__header-left {
69
75
  flex-direction: column;
70
76
  gap: .375rem;
@@ -132,6 +138,12 @@
132
138
  display: flex;
133
139
  }
134
140
 
141
+ @media (width <= 768px) {
142
+ .rp-prompt__header-actions {
143
+ align-self: flex-end;
144
+ }
145
+ }
146
+
135
147
  .rp-prompt__title {
136
148
  color: var(--rp-c-text-0);
137
149
  font-size: 1.125rem;
@@ -23,3 +23,25 @@ html.rp-appearance-transition .rspress-doc {
23
23
  z-index: 9999;
24
24
  }
25
25
 
26
+ html.rp-appearance-transition::view-transition-old(root), html.rp-appearance-transition::view-transition-new(root) {
27
+ will-change: contents;
28
+ }
29
+
30
+ html.rp-appearance-transition:not(.dark)::view-transition-new(root) {
31
+ animation: .4s ease-in both rp-appearance;
32
+ }
33
+
34
+ html.rp-appearance-transition.dark::view-transition-old(root) {
35
+ animation: .4s ease-in reverse both rp-appearance;
36
+ }
37
+
38
+ @keyframes rp-appearance {
39
+ from {
40
+ clip-path: var(--rp-vt-clip-start);
41
+ }
42
+
43
+ to {
44
+ clip-path: var(--rp-vt-clip-end);
45
+ }
46
+ }
47
+
@@ -7,50 +7,58 @@ import "./index.css";
7
7
  import { flushSync } from "react-dom";
8
8
  import { getClipPath } from "./getClipPath.js";
9
9
  const supportAppearanceTransition = ()=>'function' == typeof document?.startViewTransition && !window.matchMedia('(prefers-reduced-motion: reduce)').matches;
10
- const removeClipViewTransition = ()=>{
11
- document.documentElement.classList.add('rp-appearance-transition');
12
- return ()=>{
13
- document.documentElement.classList.remove('rp-appearance-transition');
14
- };
15
- };
10
+ let isAppearanceTransitioning = false;
16
11
  function SwitchAppearance({ onClick }) {
17
12
  const { theme, setTheme = ()=>{} } = useContext(ThemeContext);
18
13
  const { site } = useSite();
19
14
  const handleClick = (event)=>{
15
+ if (isAppearanceTransitioning) return;
20
16
  const supported = supportAppearanceTransition();
21
17
  const enabled = site?.themeConfig?.enableAppearanceAnimation;
22
18
  const nextTheme = 'dark' === theme ? 'light' : 'dark';
23
- const isDark = 'dark' === nextTheme;
24
19
  if (supported && enabled) {
20
+ isAppearanceTransitioning = true;
25
21
  const x = event.clientX;
26
22
  const y = event.clientY;
27
- const dispose = removeClipViewTransition();
28
- const transition = document.startViewTransition(async ()=>{
29
- flushSync(()=>{
30
- setTheme(nextTheme);
31
- onClick?.();
32
- });
33
- });
34
23
  const clipPath = getClipPath({
35
24
  height: innerHeight,
36
25
  width: innerWidth,
37
26
  x,
38
27
  y
39
28
  });
40
- transition.ready.then(()=>{
41
- document.documentElement.animate({
42
- clipPath: isDark ? [
43
- ...clipPath
44
- ].reverse() : clipPath
45
- }, {
46
- duration: 400,
47
- easing: 'ease-in',
48
- fill: 'both',
49
- pseudoElement: isDark ? '::view-transition-old(root)' : '::view-transition-new(root)',
50
- id: ''
29
+ const root = document.documentElement;
30
+ root.style.setProperty('--rp-vt-clip-start', clipPath[0]);
31
+ root.style.setProperty('--rp-vt-clip-end', clipPath[1]);
32
+ root.classList.add('rp-appearance-transition');
33
+ const cleanup = ()=>{
34
+ root.classList.remove('rp-appearance-transition');
35
+ root.style.removeProperty('--rp-vt-clip-start');
36
+ root.style.removeProperty('--rp-vt-clip-end');
37
+ isAppearanceTransitioning = false;
38
+ };
39
+ let updated = false;
40
+ const updateTheme = ()=>{
41
+ updated = true;
42
+ flushSync(()=>{
43
+ setTheme(nextTheme);
44
+ onClick?.();
51
45
  });
52
- });
53
- transition.finished.then(dispose, dispose);
46
+ };
47
+ try {
48
+ const transition = document.startViewTransition(async ()=>{
49
+ updateTheme();
50
+ });
51
+ transition.updateCallbackDone.catch(()=>{
52
+ transition.skipTransition();
53
+ });
54
+ transition.ready.catch(()=>{
55
+ transition.skipTransition();
56
+ });
57
+ transition.finished.then(cleanup, cleanup);
58
+ } catch {
59
+ cleanup();
60
+ if (!updated) updateTheme();
61
+ }
54
62
  } else {
55
63
  setTheme(nextTheme);
56
64
  onClick?.();
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Registers `rspress_navigate` for known internal routes. Waits for committed
2
+ * Registers `navigate` for known internal routes. Waits for committed
3
3
  * page context before returning metadata, section routes, and adjacent pages.
4
4
  * @unstable
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Registers `rspress_list_pages` for filtered, paginated page discovery,
2
+ * Registers `list_pages` for filtered, paginated page discovery,
3
3
  * defaulting to the active language and version without requiring search.
4
4
  * @unstable
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Registers `rspress_get_page` and `rspress_get_current_page` to read page
2
+ * Registers `get_page` and `get_current_page` to read page
3
3
  * metadata and generated SSG-MD without navigating. The app registers these
4
4
  * tools when Markdown generation is enabled, independently of the theme UI.
5
5
  * @unstable
@@ -4,7 +4,7 @@ function useWebMcpPageReading() {
4
4
  const { page } = usePage();
5
5
  const { site } = useSite();
6
6
  const { pages } = usePages();
7
- useWebMcp(defineTool('get_page', 'Read metadata and generated Markdown for a known documentation route without navigating. Paths are relative to the site base.', {
7
+ useWebMcp(defineTool('get_page', 'Read metadata, frontmatter, table of contents and generated Markdown for the documentation page specified by routePath, without navigating. Paths are relative to the site base.', {
8
8
  routePath: routePathField
9
9
  }, [
10
10
  'routePath'
@@ -18,6 +18,6 @@ function useWebMcpPageReading() {
18
18
  if (!targetPage) throw new TypeError(`Unknown internal route: ${path}`);
19
19
  return readPage(targetPage, site.base, signal);
20
20
  }));
21
- useWebMcp(defineTool('get_current_page', 'Read metadata, frontmatter, table of contents and generated Markdown for the current documentation page.', {}, [], (_args, signal)=>readPage(page, site.base, signal)));
21
+ useWebMcp(defineTool('get_current_page', 'Read metadata, frontmatter, table of contents and generated Markdown for the documentation page currently open in the browser.', {}, [], (_args, signal)=>readPage(page, site.base, signal)));
22
22
  }
23
23
  export { useWebMcpPageReading };
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Registers `rspress_get_site_info` to expose site metadata, locales, versions,
2
+ * Registers `get_site_info` to expose site metadata, locales, versions,
3
3
  * navigation, and the active sidebar from the current page context.
4
4
  * @unstable
5
5
  */
@@ -73,3 +73,11 @@
73
73
  opacity: 1;
74
74
  }
75
75
 
76
+ .shiki .highlighted-word {
77
+ background-color: #3b82f61a;
78
+ border: 1px solid #3b82f64d;
79
+ border-radius: 4px;
80
+ margin: -1px -3px;
81
+ padding: 1px 3px;
82
+ }
83
+
@@ -103,7 +103,7 @@ function listPages(pages, current, args) {
103
103
  }
104
104
  function defineTool(name, description, fields, required, execute) {
105
105
  return {
106
- name: `rspress_${name}`,
106
+ name,
107
107
  description,
108
108
  inputSchema: {
109
109
  type: 'object',
package/dist/tx~0.js CHANGED
@@ -13,5 +13,5 @@ export { unified } from "unified";
13
13
  export { visit } from "unist-util-visit";
14
14
  export { default as github_slugger } from "@rspress/shared/github-slugger";
15
15
  export { headingRank } from "hast-util-heading-rank";
16
- export { transformerAddFold, transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddWrapCode } from "@rspress/core/shiki-transformers";
16
+ export { getShikiTransformers, transformerAddFold, transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddWrapCode } from "@rspress/core/shiki-transformers";
17
17
  export { createCssVariablesTheme } from "shiki";
package/dist/y~0.js CHANGED
@@ -1,5 +1,5 @@
1
1
  var package_namespaceObject = {
2
- rE: "2.1.0"
2
+ rE: "2.1.1"
3
3
  };
4
4
  function pMap(iterable, mapper, options) {
5
5
  return mapConcurrently(iterable, mapper, options, false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/core",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "The Rspress Documentation Framework",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -62,8 +62,9 @@
62
62
  "@mdx-js/react": "^3.1.1",
63
63
  "@rsbuild/core": "^2.2.14",
64
64
  "@rsbuild/plugin-react": "~2.1.1",
65
- "@rspress/shared": "2.1.0",
65
+ "@rspress/shared": "2.1.1",
66
66
  "@shikijs/rehype": "^4.2.0",
67
+ "@shikijs/transformers": "^4.2.0",
67
68
  "@types/mdast": "^4.0.4",
68
69
  "@types/react": "^19.3.0",
69
70
  "@unhead/react": "^2.1.17",