@rspress/core 2.0.10 → 2.0.12

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 (115) hide show
  1. package/dist/0~execa.js +1 -1
  2. package/dist/3323.js +8 -0
  3. package/dist/{2240.js → 6162.js} +1 -4
  4. package/dist/8006.js +1 -1
  5. package/dist/8857.js +1 -1
  6. package/dist/common-Qw-RoVFD.js +25 -0
  7. package/dist/eject-theme/components/Llms/LlmsContainer.tsx +1 -2
  8. package/dist/eject-theme/components/Llms/LlmsCopyButton.tsx +1 -2
  9. package/dist/eject-theme/components/Llms/LlmsViewOptions.tsx +1 -2
  10. package/dist/eject-theme/components/PackageManagerTabs/index.tsx +16 -17
  11. package/dist/eject-theme/components/Prompt/icons.tsx +1 -1
  12. package/dist/eject-theme/components/Prompt/index.scss +325 -380
  13. package/dist/eject-theme/components/Search/SearchPanel.tsx +1 -6
  14. package/dist/eject-theme/components/Search/logic/search.ts +10 -5
  15. package/dist/eject-theme/components/Search/logic/util.test.ts +20 -1
  16. package/dist/eject-theme/components/Search/logic/util.ts +4 -1
  17. package/dist/eject-theme/components/Sidebar/SidebarItem.tsx +1 -1
  18. package/dist/eject-theme/components/Tabs/index.tsx +48 -41
  19. package/dist/entry/process.d.ts +1 -0
  20. package/dist/entry/process.js +65 -0
  21. package/dist/entry/utils.d.ts +7 -0
  22. package/dist/entry/utils.js +2 -0
  23. package/dist/entry/worker.d.ts +1 -0
  24. package/dist/entry/worker.js +74 -0
  25. package/dist/index.d.ts +1 -1
  26. package/dist/index.js +1 -0
  27. package/dist/node/PluginDriver.js +1 -1
  28. package/dist/node/auto-nav-sidebar/index.js +1 -1
  29. package/dist/node/auto-nav-sidebar/locales.js +1 -1
  30. package/dist/node/auto-nav-sidebar/normalize.d.ts +1 -1
  31. package/dist/node/auto-nav-sidebar/normalize.js +1 -1
  32. package/dist/node/auto-nav-sidebar/utils.js +1 -1
  33. package/dist/node/auto-nav-sidebar/walk.js +1 -1
  34. package/dist/node/index.d.ts +1 -0
  35. package/dist/node/initRsbuild.js +1 -1
  36. package/dist/node/mdx/options.js +2 -1
  37. package/dist/node/mdx/processor.js +1 -1
  38. package/dist/node/mdx/rehypePlugins/codeMeta.js +1 -1
  39. package/dist/node/mdx/rehypePlugins/headerAnchor.js +1 -1
  40. package/dist/node/mdx/rehypePlugins/shiki.js +1 -1
  41. package/dist/node/mdx/rehypePlugins/transformers/add-title.js +3 -6
  42. package/dist/node/mdx/rehypePlugins/transformers/index.d.ts +1 -1
  43. package/dist/node/mdx/remarkPlugins/builtin.js +1 -1
  44. package/dist/node/mdx/remarkPlugins/containerSyntax.d.ts +1 -1
  45. package/dist/node/mdx/remarkPlugins/fileCodeBlock.d.ts +1 -0
  46. package/dist/node/mdx/remarkPlugins/fileCodeBlock.js +9 -4
  47. package/dist/node/mdx/remarkPlugins/image.d.ts +1 -1
  48. package/dist/node/mdx/remarkPlugins/image.js +2 -1
  49. package/dist/node/mdx/remarkPlugins/link.d.ts +1 -1
  50. package/dist/node/mdx/remarkPlugins/link.js +1 -1
  51. package/dist/node/route/RoutePage.js +1 -1
  52. package/dist/node/route/RouteService.js +1 -1
  53. package/dist/node/route/extractPageData.js +1 -1
  54. package/dist/node/route/normalizeRoutePath.js +1 -1
  55. package/dist/node/runtimeModule/DEFAULT_I18N_TEXT.d.ts +140 -140
  56. package/dist/node/runtimeModule/i18n.js +1 -1
  57. package/dist/node/runtimeModule/pageData/createPageData.js +1 -1
  58. package/dist/node/runtimeModule/pageData/rsbuildPlugin.d.ts +1 -1
  59. package/dist/node/runtimeModule/pageData/rsbuildPlugin.js +1 -1
  60. package/dist/node/runtimeModule/searchHooks.js +1 -1
  61. package/dist/node/runtimeModule/siteData/createSiteData.js +1 -1
  62. package/dist/node/runtimeModule/siteData/normalizeThemeConfig.js +1 -1
  63. package/dist/node/runtimeModule/siteData/rsbuildPlugin.js +1 -1
  64. package/dist/node/serve.js +1 -1
  65. package/dist/node/ssg/renderPages.js +2 -2
  66. package/dist/node/ssg/rsbuildPluginSSG.js +1 -1
  67. package/dist/node/ssg/ssgEnv.js +1 -1
  68. package/dist/node/ssg-md/llms/emitLlmsTxt.js +1 -1
  69. package/dist/node/ssg-md/llms/llmsTxt.js +1 -1
  70. package/dist/node/ssg-md/remarkSplitMdx.js +1 -1
  71. package/dist/node/ssg-md/renderPage.js +1 -1
  72. package/dist/node/ssg-md/renderPages.js +1 -1
  73. package/dist/node/ssg-md/rsbuildPluginSSGMD.js +1 -1
  74. package/dist/node/utils/checkLanguageParity.js +1 -1
  75. package/dist/node/utils/createHash.js +1 -1
  76. package/dist/node/utils/flattenMdxContent.js +1 -1
  77. package/dist/node/utils/getPageKey.js +1 -1
  78. package/dist/node/utils/reactAlias.js +1 -1
  79. package/dist/runtime/BrowserOnly.d.ts +7 -0
  80. package/dist/runtime/BrowserOnly.js +40 -0
  81. package/dist/runtime/BrowserOnly.test.d.ts +1 -0
  82. package/dist/runtime/index.d.ts +1 -0
  83. package/dist/runtime/index.js +1 -0
  84. package/dist/theme/components/DocContent/docComponents/a.d.ts +1 -1
  85. package/dist/theme/components/DocContent/docComponents/hr.d.ts +1 -1
  86. package/dist/theme/components/DocContent/docComponents/img.d.ts +1 -1
  87. package/dist/theme/components/DocContent/docComponents/index.d.ts +18 -18
  88. package/dist/theme/components/DocContent/docComponents/list.d.ts +3 -3
  89. package/dist/theme/components/DocContent/docComponents/paragraph.d.ts +3 -3
  90. package/dist/theme/components/DocContent/docComponents/table.d.ts +3 -3
  91. package/dist/theme/components/DocContent/docComponents/title.d.ts +6 -6
  92. package/dist/theme/components/Nav/hooks.d.ts +1 -1
  93. package/dist/theme/components/PackageManagerTabs/index.js +17 -17
  94. package/dist/theme/components/Prompt/icons.js +1 -1
  95. package/dist/theme/components/Prompt/index.css +11 -37
  96. package/dist/theme/components/Search/SearchPanel.js +1 -2
  97. package/dist/theme/components/Search/logic/search.js +5 -3
  98. package/dist/theme/components/Search/logic/util.js +2 -1
  99. package/dist/theme/components/Sidebar/SidebarItem.js +1 -0
  100. package/dist/theme/components/Tabs/index.d.ts +8 -4
  101. package/dist/theme/components/Tabs/index.js +19 -19
  102. package/dist/theme/layout/DocLayout/index.css +4 -0
  103. package/dist/theme/layout/DocLayout/index.js +3 -2
  104. package/dist/theme/logic/useThemeState.d.ts +5 -10
  105. package/dist/theme/logic/useThemeState.js +15 -20
  106. package/dist/utils-B--2TaWv.js +34 -0
  107. package/dist/utils-De75vAgL.js +7 -0
  108. package/package.json +13 -13
  109. package/dist/3425.js +0 -6
  110. package/dist/runtime/getSidebarDataGroup.test.js +0 -68
  111. package/dist/runtime/hooks/useWindowSize.test.js +0 -36
  112. package/dist/runtime/route.test.js +0 -154
  113. package/dist/runtime/utils.test.js +0 -34
  114. package/dist/theme/components/Search/logic/util.test.js +0 -51
  115. /package/dist/{2287.js → 2235.js} +0 -0
@@ -388,15 +388,10 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
388
388
  );
389
389
  }
390
390
 
391
- const tabValues = result.map(item => {
392
- return item.group;
393
- });
394
-
395
391
  const renderKey = 'render' as const;
396
392
 
397
393
  return (
398
394
  <Tabs
399
- values={tabValues}
400
395
  className="rp-search-panel__tabs"
401
396
  onChange={index => {
402
397
  setResultTabIndex(index);
@@ -406,7 +401,7 @@ export function SearchPanel({ focused, setFocused }: SearchPanelProps) {
406
401
  ref={searchResultTabRef}
407
402
  >
408
403
  {result.map(item => (
409
- <Tab key={item.group}>
404
+ <Tab key={item.group} label={item.group}>
410
405
  {item.renderType === RenderType.Default &&
411
406
  renderSearchResultItem(item.result, query, isSearching)}
412
407
  {item.renderType === RenderType.Custom &&
@@ -248,15 +248,17 @@ export class PageSearcher {
248
248
  let statementStartIndex = content.slice(0, queryIndex).lastIndexOf('\n');
249
249
  statementStartIndex =
250
250
  statementStartIndex === -1 ? 0 : statementStartIndex;
251
- const statementEndIndex = content.indexOf(
251
+ let statementEndIndex = content.indexOf(
252
252
  '\n\n',
253
253
  queryIndex + query.length,
254
254
  );
255
+ statementEndIndex =
256
+ statementEndIndex === -1 ? content.length : statementEndIndex;
255
257
  let statement = content.slice(statementStartIndex, statementEndIndex);
256
- if (statement.length > THRESHOLD_CONTENT_LENGTH) {
257
- statement = this.#normalizeStatement(statement, query);
258
- }
259
- const highlightIndex = normalizeTextCase(statement).indexOf(query);
258
+ statement = this.#normalizeStatement(statement, query);
259
+ const highlightIndex = normalizeTextCase(statement).indexOf(
260
+ normalizeTextCase(query),
261
+ );
260
262
  const highlightInfoList = [
261
263
  {
262
264
  start: highlightIndex,
@@ -286,6 +288,9 @@ export class PageSearcher {
286
288
  }
287
289
 
288
290
  #normalizeStatement(statement: string, query: string) {
291
+ if (statement.length <= THRESHOLD_CONTENT_LENGTH) {
292
+ return statement;
293
+ }
289
294
  // If statement is too long, we will only show 120 characters
290
295
  const queryIndex = normalizeTextCase(statement).indexOf(
291
296
  normalizeTextCase(query),
@@ -1,6 +1,6 @@
1
1
  import type { Header } from '@rspress/core';
2
2
  import { describe, expect, test } from '@rstest/core';
3
- import { backTrackHeaders } from './util';
3
+ import { backTrackHeaders, normalizeTextCase } from './util';
4
4
 
5
5
  describe('utils logic', () => {
6
6
  test('back track the headers', () => {
@@ -19,3 +19,22 @@ describe('utils logic', () => {
19
19
  ]);
20
20
  });
21
21
  });
22
+
23
+ describe('normalizeTextCase', () => {
24
+ test('normalize latin text without accents for search', () => {
25
+ expect(normalizeTextCase('CAFÉ')).toBe('cafe');
26
+ });
27
+
28
+ test('normalize japanese text without accents for search', () => {
29
+ expect(normalizeTextCase('ご')).toBe('ご');
30
+ expect(normalizeTextCase('ガ')).toBe('ガ');
31
+ });
32
+
33
+ test('normalize cyrillic text without accents for search', () => {
34
+ expect(normalizeTextCase('ПРИВЕТ')).toBe('привет');
35
+ });
36
+
37
+ test('normalize korean text without accents for search', () => {
38
+ expect(normalizeTextCase('안녕하세요')).toBe('안녕하세요');
39
+ });
40
+ });
@@ -1,6 +1,7 @@
1
1
  import type { Header } from '@rspress/core';
2
2
 
3
3
  const MAX_TITLE_LENGTH = 20;
4
+ const jRegex = /[\u3040-\u309f\u30a0-\u30ff\u31f0-\u31ff]/u;
4
5
  const kRegex = /[\u3131-\u314e|\u314f-\u3163|\uac00-\ud7a3]/u;
5
6
  const cyrillicRegex = /[\u0400-\u04FF]/u;
6
7
 
@@ -46,9 +47,11 @@ export function normalizeTextCase(text: string | number) {
46
47
  }
47
48
 
48
49
  const resultWithoutAccents = textNormalized.replace(/[\u0300-\u036f]/g, '');
49
- if (kRegex.test(String(text))) {
50
+
51
+ if (jRegex.test(String(text)) || kRegex.test(String(text))) {
50
52
  return resultWithoutAccents.normalize('NFC');
51
53
  }
54
+
52
55
  return resultWithoutAccents;
53
56
  }
54
57
 
@@ -56,7 +56,7 @@ export function SidebarItemRaw({
56
56
  const innerContent = (
57
57
  <>
58
58
  <div className="rp-sidebar-item__left" ref={ref}>
59
- <span {...renderInlineMarkdown(text)}></span>
59
+ <span className="rp-doc" {...renderInlineMarkdown(text)}></span>
60
60
  {left}
61
61
  </div>
62
62
  <div className="rp-sidebar-item__right">
@@ -13,17 +13,25 @@ import {
13
13
  import './index.scss';
14
14
 
15
15
  type TabItem = {
16
- label?: string | ReactNode;
16
+ label: ReactNode;
17
+ value: string;
18
+ disabled?: boolean;
19
+ };
20
+
21
+ type ResolvedTabItem = {
22
+ label?: ReactNode;
23
+ value?: string;
17
24
  disabled?: boolean;
18
25
  content?: ReactNode;
19
26
  };
20
27
 
21
28
  export interface TabsProps {
22
- values?: ReactNode[] | ReadonlyArray<ReactNode> | TabItem[];
29
+ values?: ReadonlyArray<TabItem>;
23
30
  /**
24
31
  * @default 0
25
32
  */
26
33
  defaultIndex?: number;
34
+ defaultValue?: string;
27
35
  onChange?: (index: number) => void;
28
36
  children: ReactNode;
29
37
  /**
@@ -45,56 +53,41 @@ export interface TabsProps {
45
53
 
46
54
  function getTabValuesFromChildren(
47
55
  children: ReactElement<TabProps>[],
48
- defaultValues: ReactNode[] | ReadonlyArray<ReactNode> | TabItem[] | undefined,
49
- ): TabItem[] {
50
- // 0. only values, values contain label and content
51
- // <Tabs values={[{}, {}]}/>
52
- if (defaultValues?.every(item => isTabItem(item) && item.content)) {
53
- return defaultValues as TabItem[];
54
- }
55
-
56
- // 1. values only contain label
57
- // <Tabs values={['Tab1', 'Tab2']}><Tab label="Tab1"/></Tab><Tab label="Tab2"/></Tab></Tabs>
58
- if (defaultValues && defaultValues.length > 0) {
59
- return defaultValues.map((item, index) => {
60
- if (isTabItem(item)) {
61
- return item;
62
- }
56
+ values: ReadonlyArray<TabItem> | undefined,
57
+ ): ResolvedTabItem[] {
58
+ if (values && values.length > 0) {
59
+ return values.map((item, index) => {
60
+ const content =
61
+ children.find(child => child.props?.value === item.value) ??
62
+ children[index];
63
63
 
64
64
  return {
65
- label: item,
66
- content: children[index],
67
- } satisfies TabItem;
65
+ ...item,
66
+ content,
67
+ } satisfies ResolvedTabItem;
68
68
  });
69
69
  }
70
70
 
71
- // 2. no values
72
- // <Tabs><Tab label="Tab1"/></Tab><Tab label="Tab2"/></Tab></Tabs>
73
- return Children.map<TabItem, ReactElement<TabProps>>(
71
+ return Children.map<ResolvedTabItem, ReactElement<TabProps>>(
74
72
  children,
75
73
  (child, index) => {
76
74
  if (isValidElement(child)) {
77
75
  return {
78
76
  label: child.props?.label || undefined,
77
+ value: child.props?.value,
78
+ disabled: child.props?.disabled,
79
79
  content: children[index],
80
- } satisfies TabItem;
80
+ } satisfies ResolvedTabItem;
81
81
  }
82
82
 
83
83
  return {
84
84
  label: index,
85
85
  content: children[index],
86
- } satisfies TabItem;
86
+ } satisfies ResolvedTabItem;
87
87
  },
88
88
  );
89
89
  }
90
90
 
91
- function isTabItem(item: unknown): item is TabItem {
92
- if (item && typeof item === 'object' && 'label' in item) {
93
- return true;
94
- }
95
- return false;
96
- }
97
-
98
91
  const groupIdPrefix = 'rspress.tabs.';
99
92
 
100
93
  export const Tabs = forwardRef(
@@ -102,6 +95,7 @@ export const Tabs = forwardRef(
102
95
  const {
103
96
  values,
104
97
  defaultIndex,
98
+ defaultValue,
105
99
  onChange,
106
100
  children: rawChildren,
107
101
  groupId,
@@ -118,9 +112,9 @@ export const Tabs = forwardRef(
118
112
  isValidElement(child),
119
113
  ) as unknown as ReactElement<TabProps>[];
120
114
 
121
- const tabValues: TabItem[] = useMemo(() => {
115
+ const tabValues: ResolvedTabItem[] = useMemo(() => {
122
116
  return getTabValuesFromChildren(children, values);
123
- }, [values, children]);
117
+ }, [children, values]);
124
118
 
125
119
  if (process.env.__SSR_MD__) {
126
120
  return (
@@ -138,11 +132,18 @@ export const Tabs = forwardRef(
138
132
  );
139
133
  }
140
134
 
141
- const [activeIndex, setActiveIndex] = useState(defaultIndex ?? 0);
135
+ const defaultValueIndex =
136
+ defaultValue !== undefined
137
+ ? tabValues.findIndex(item => item.value === defaultValue)
138
+ : -1;
139
+ const initialActiveIndex =
140
+ defaultValueIndex === -1 ? (defaultIndex ?? 0) : defaultValueIndex;
141
+
142
+ const [activeIndex, setActiveIndex] = useState(initialActiveIndex);
142
143
 
143
144
  const [storageIndex, setStorageIndex] = useStorageValue<string>(
144
145
  `${groupIdPrefix}${groupId}`,
145
- activeIndex.toString(),
146
+ initialActiveIndex.toString(),
146
147
  );
147
148
 
148
149
  const currentIndex: number = groupId ? Number(storageIndex) : activeIndex;
@@ -157,11 +158,11 @@ export const Tabs = forwardRef(
157
158
  tabPosition === 'center' ? 'center' : 'flex-start',
158
159
  }}
159
160
  >
160
- {tabValues.map(({ label }, index) => {
161
+ {tabValues.map(({ label, value, disabled }, index) => {
161
162
  const isActive = index === currentIndex;
162
163
  return (
163
164
  <div
164
- key={typeof label === 'string' ? label : index}
165
+ key={value ?? index}
165
166
  className={clsx(
166
167
  'rp-tabs__label__item',
167
168
  isActive
@@ -171,6 +172,9 @@ export const Tabs = forwardRef(
171
172
  )}
172
173
  data-index={index}
173
174
  onClick={() => {
175
+ if (disabled) {
176
+ return;
177
+ }
174
178
  onChange?.(index);
175
179
  if (groupId) {
176
180
  setStorageIndex(index.toString());
@@ -186,7 +190,7 @@ export const Tabs = forwardRef(
186
190
  </div>
187
191
  ) : null}
188
192
  <div className="rp-tabs__content">
189
- {tabValues.map(({ label, content }, index) => {
193
+ {tabValues.map(({ value, content }, index) => {
190
194
  const isActive = index === currentIndex;
191
195
  if (!keepDOM && !isActive) {
192
196
  return null;
@@ -194,7 +198,7 @@ export const Tabs = forwardRef(
194
198
 
195
199
  return (
196
200
  <div
197
- key={typeof label === 'string' ? label : index}
201
+ key={value ?? index}
198
202
  className={clsx(
199
203
  'rp-tabs__content__item',
200
204
  isActive
@@ -217,7 +221,10 @@ export const Tabs = forwardRef(
217
221
 
218
222
  Tabs.displayName = 'Tabs';
219
223
 
220
- export type TabProps = Pick<TabItem, 'label' | 'disabled'> & {
224
+ export type TabProps = {
225
+ label?: ReactNode;
226
+ value?: string;
227
+ disabled?: boolean;
221
228
  children: ReactNode;
222
229
  };
223
230
 
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,65 @@
1
+ import { stderr, stdout } from "../utils-De75vAgL.js";
2
+ import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
3
+ process.__tinypool_state__ = {
4
+ isChildProcess: true,
5
+ isTinypoolWorker: true,
6
+ workerData: null,
7
+ workerId: Number(process.env.TINYPOOL_WORKER_ID)
8
+ };
9
+ const memoryUsage = process.memoryUsage.bind(process);
10
+ const send = process.send.bind(process);
11
+ process.on("message", (message)=>{
12
+ if (!message || !message.__tinypool_worker_message__) return;
13
+ if ("pool" === message.source) {
14
+ const { filename, name } = message;
15
+ (async function() {
16
+ if (null !== filename) await getHandler(filename, name);
17
+ send({
18
+ ready: true,
19
+ source: "pool",
20
+ __tinypool_worker_message__: true
21
+ }, ()=>{});
22
+ })().catch(throwInNextTick);
23
+ return;
24
+ }
25
+ if ("port" === message.source) return void onMessage(message).catch(throwInNextTick);
26
+ throw new Error(`Unexpected TinypoolWorkerMessage ${JSON.stringify(message)}`);
27
+ });
28
+ async function onMessage(message) {
29
+ const { taskId, task, filename, name } = message;
30
+ let response;
31
+ try {
32
+ const handler = await getHandler(filename, name);
33
+ if (null === handler) throw new Error(`No handler function "${name}" exported from "${filename}"`);
34
+ const result = await handler(task);
35
+ response = {
36
+ source: "port",
37
+ __tinypool_worker_message__: true,
38
+ taskId,
39
+ result,
40
+ error: null,
41
+ usedMemory: memoryUsage().heapUsed
42
+ };
43
+ if (stdout()?.writableLength > 0) await new Promise((resolve)=>process.stdout.write("", resolve));
44
+ if (stderr()?.writableLength > 0) await new Promise((resolve)=>process.stderr.write("", resolve));
45
+ } catch (error) {
46
+ response = {
47
+ source: "port",
48
+ __tinypool_worker_message__: true,
49
+ taskId,
50
+ result: null,
51
+ error: serializeError(error),
52
+ usedMemory: memoryUsage().heapUsed
53
+ };
54
+ }
55
+ send(response);
56
+ }
57
+ function serializeError(error) {
58
+ if (error instanceof Error) return {
59
+ ...error,
60
+ name: error.name,
61
+ stack: error.stack,
62
+ message: error.message
63
+ };
64
+ return String(error);
65
+ }
@@ -0,0 +1,7 @@
1
+ //#region src/entry/utils.d.ts
2
+ type Handler = Function;
3
+ declare function getHandler(filename: string, name: string): Promise<Handler | null>;
4
+ declare function throwInNextTick(error: Error): void;
5
+
6
+ //#endregion
7
+ export { getHandler, throwInNextTick };
@@ -0,0 +1,2 @@
1
+ import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
2
+ export { getHandler, throwInNextTick };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,74 @@
1
+ import { isMovable, kRequestCountField, kResponseCountField, kTransferable, kValue } from "../common-Qw-RoVFD.js";
2
+ import { stderr, stdout } from "../utils-De75vAgL.js";
3
+ import { getHandler, throwInNextTick } from "../utils-B--2TaWv.js";
4
+ import { parentPort, receiveMessageOnPort, workerData } from "node:worker_threads";
5
+ const [tinypoolPrivateData, workerData$1] = workerData;
6
+ process.__tinypool_state__ = {
7
+ isWorkerThread: true,
8
+ isTinypoolWorker: true,
9
+ workerData: workerData$1,
10
+ workerId: tinypoolPrivateData.workerId
11
+ };
12
+ const memoryUsage = process.memoryUsage.bind(process);
13
+ let useAtomics = "1" !== process.env.PISCINA_DISABLE_ATOMICS;
14
+ parentPort.on("message", (message)=>{
15
+ useAtomics = "1" === process.env.PISCINA_DISABLE_ATOMICS ? false : message.useAtomics;
16
+ const { port, sharedBuffer, filename, name } = message;
17
+ (async function() {
18
+ if (null !== filename) await getHandler(filename, name);
19
+ const readyMessage = {
20
+ ready: true
21
+ };
22
+ parentPort.postMessage(readyMessage);
23
+ port.start();
24
+ port.on("message", onMessage.bind(null, port, sharedBuffer));
25
+ atomicsWaitLoop(port, sharedBuffer);
26
+ })().catch(throwInNextTick);
27
+ });
28
+ let currentTasks = 0;
29
+ let lastSeenRequestCount = 0;
30
+ function atomicsWaitLoop(port, sharedBuffer) {
31
+ if (!useAtomics) return;
32
+ while(0 === currentTasks){
33
+ Atomics.wait(sharedBuffer, kRequestCountField, lastSeenRequestCount);
34
+ lastSeenRequestCount = Atomics.load(sharedBuffer, kRequestCountField);
35
+ let entry;
36
+ while(void 0 !== (entry = receiveMessageOnPort(port)))onMessage(port, sharedBuffer, entry.message);
37
+ }
38
+ }
39
+ function onMessage(port, sharedBuffer, message) {
40
+ currentTasks++;
41
+ const { taskId, task, filename, name } = message;
42
+ (async function() {
43
+ let response;
44
+ let transferList = [];
45
+ try {
46
+ const handler = await getHandler(filename, name);
47
+ if (null === handler) throw new Error(`No handler function "${name}" exported from "${filename}"`);
48
+ let result = await handler(task);
49
+ if (isMovable(result)) {
50
+ transferList = transferList.concat(result[kTransferable]);
51
+ result = result[kValue];
52
+ }
53
+ response = {
54
+ taskId,
55
+ result,
56
+ error: null,
57
+ usedMemory: memoryUsage().heapUsed
58
+ };
59
+ if (stdout()?.writableLength > 0) await new Promise((resolve)=>process.stdout.write("", resolve));
60
+ if (stderr()?.writableLength > 0) await new Promise((resolve)=>process.stderr.write("", resolve));
61
+ } catch (error) {
62
+ response = {
63
+ taskId,
64
+ result: null,
65
+ error,
66
+ usedMemory: memoryUsage().heapUsed
67
+ };
68
+ }
69
+ currentTasks--;
70
+ port.postMessage(response, transferList);
71
+ Atomics.add(sharedBuffer, kResponseCountField, 1);
72
+ atomicsWaitLoop(port, sharedBuffer);
73
+ })().catch(throwInNextTick);
74
+ }
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { getIconUrlPath, getNodeAttribute, mergeDocConfig, } from '@rspress/shar
5
5
  export { matchPath } from 'react-router-dom';
6
6
  export type { UserConfigAsyncFn } from './config/defineConfig.js';
7
7
  export { defineConfig } from './config/defineConfig.js';
8
- export { build, dev, remarkFileCodeBlock, remarkLink, serve } from './node/index.js';
8
+ export { build, dev, remarkFileCodeBlock, remarkImage, remarkLink, serve, } from './node/index.js';
9
9
  export type { CustomLinkMeta, DirSectionHeaderSideMeta, DirSideMeta, DividerSideMeta, FileSideMeta, MetaJson, NavJson, SectionHeaderMeta, SideMeta, SideMetaItem, } from './node/auto-nav-sidebar/type.js';
10
10
  export { PluginDriver } from './node/PluginDriver.js';
11
11
  export { RouteService } from './node/route/RouteService.js';
package/dist/index.js CHANGED
@@ -5,5 +5,6 @@ export { build } from "./node/build.js";
5
5
  export { defineConfig } from "./config/defineConfig.js";
6
6
  export { dev } from "./node/dev.js";
7
7
  export { remarkFileCodeBlock } from "./node/mdx/remarkPlugins/fileCodeBlock.js";
8
+ export { remarkImage } from "./node/mdx/remarkPlugins/image.js";
8
9
  export { remarkLink } from "./node/mdx/remarkPlugins/link.js";
9
10
  export { serve } from "./node/serve.js";
@@ -1,4 +1,4 @@
1
- import { addTrailingSlash, node_path, addLeadingSlash } from "../2287.js";
1
+ import { addTrailingSlash, node_path, addLeadingSlash } from "../2235.js";
2
2
  import { createError } from "./utils/error.js";
3
3
  import { haveNavSidebarConfig as auto_nav_sidebar_haveNavSidebarConfig } from "./auto-nav-sidebar/index.js";
4
4
  class PluginDriver {
@@ -1,4 +1,4 @@
1
- import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../2287.js";
1
+ import { DEFAULT_PAGE_EXTENSIONS, node_path } from "../../2235.js";
2
2
  import { processLocales, combineWalkResult } from "./locales.js";
3
3
  import { walk } from "./walk.js";
4
4
  async function runAutoNavSide(config, metaFileSet, mdFileSet) {
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../2287.js";
1
+ import { node_path } from "../../2235.js";
2
2
  import { walk } from "./walk.js";
3
3
  function combineWalkResult(walks, versions) {
4
4
  return walks.reduce((acc, cur, curIndex)=>({
@@ -1,3 +1,3 @@
1
1
  import { type SidebarDivider, type SidebarGroup, type SidebarItem, type SidebarSectionHeader } from '@rspress/shared';
2
- declare function scanSideMeta(workDir: string, docsDir: string, extensions: string[], metaFileSet: Set<string>, mdFileSet: Set<string>): Promise<(SidebarItem | SidebarGroup | SidebarDivider | SidebarSectionHeader)[]>;
2
+ declare function scanSideMeta(workDir: string, docsDir: string, extensions: string[], metaFileSet: Set<string>, mdFileSet: Set<string>): Promise<(SidebarDivider | SidebarGroup | SidebarItem | SidebarSectionHeader)[]>;
3
3
  export { scanSideMeta };
@@ -1,6 +1,6 @@
1
1
  import { __webpack_require__ } from "../../0~rslib-runtime.js";
2
2
  import "../../8006.js";
3
- import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../2287.js";
3
+ import { extname, logger, promises_readdir, external_node_path_relative, isExternalUrl, slash, promises_stat, join } from "../../2235.js";
4
4
  import { createError } from "../utils/error.js";
5
5
  import { PUBLIC_DIR } from "../constants.js";
6
6
  import { pathExists, extractInfoFromFrontmatterWithAbsolutePath, readJson } from "./utils.js";
@@ -1,4 +1,4 @@
1
- import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../2287.js";
1
+ import { node_path, extractTextAndId, promises, loadFrontMatter } from "../../2235.js";
2
2
  import { createError } from "../utils/error.js";
3
3
  async function pathExists(path) {
4
4
  try {
@@ -1,4 +1,4 @@
1
- import { isExternalUrl, node_path, promises } from "../../2287.js";
1
+ import { isExternalUrl, node_path, promises } from "../../2235.js";
2
2
  import { pathExists } from "../utils/fs.js";
3
3
  import { readJson } from "./utils.js";
4
4
  import { addRoutePrefix } from "../route/RoutePage.js";
@@ -1,5 +1,6 @@
1
1
  export { build } from './build.js';
2
2
  export { dev } from './dev.js';
3
3
  export { remarkFileCodeBlock } from './mdx/remarkPlugins/fileCodeBlock.js';
4
+ export { remarkImage } from './mdx/remarkPlugins/image.js';
4
5
  export { remarkLink } from './mdx/remarkPlugins/link.js';
5
6
  export { serve } from './serve.js';
@@ -1,4 +1,4 @@
1
- import { external_node_process_cwd, node_path, external_node_url_fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, external_node_module_createRequire, removeTrailingSlash, pluginVirtualModule, pluginReact, MDX_OR_MD_REGEXP } from "../2287.js";
1
+ import { external_node_process_cwd, node_path, external_node_url_fileURLToPath, addTrailingSlash, PLUGIN_REACT_NAME, external_node_module_createRequire, removeTrailingSlash, pluginVirtualModule, pluginReact, MDX_OR_MD_REGEXP } from "../2235.js";
2
2
  import { createError } from "./utils/error.js";
3
3
  import { PUBLIC_DIR, CSR_CLIENT_ENTRY, SSR_CLIENT_ENTRY, OUTPUT_DIR, SSG_MD_SERVER_ENTRY, inlineThemeScript, NODE_SSG_BUNDLE_FOLDER, isProduction, PACKAGE_ROOT, SSR_SERVER_ENTRY, TEMPLATE_PATH, NODE_SSG_MD_BUNDLE_FOLDER, DEFAULT_THEME, NODE_SSG_MD_BUNDLE_NAME, DEFAULT_TITLE, NODE_SSG_BUNDLE_NAME } from "./constants.js";
4
4
  import { hintBuilderPluginsBreakingChange, hintThemeBreakingChange } from "./logger/hint.js";
@@ -1,4 +1,4 @@
1
- import { node_path, rehype_external_links, rehype_raw, remark_cjk_friendly, nodeTypes, remark_gfm, rehype, remark_cjk_friendly_gfm_strikethrough } from "../../2240.js";
1
+ import { node_path, rehype_external_links, rehype_raw, remark_cjk_friendly, nodeTypes, remark_gfm, rehype, remark_cjk_friendly_gfm_strikethrough } from "../../6162.js";
2
2
  import { remarkToc } from "./remarkPlugins/toc.js";
3
3
  import { remarkContainerSyntax } from "./remarkPlugins/containerSyntax.js";
4
4
  import { remarkFileCodeBlock } from "./remarkPlugins/fileCodeBlock.js";
@@ -34,6 +34,7 @@ async function createMDXOptions(options) {
34
34
  remarkFileCodeBlock,
35
35
  {
36
36
  filepath,
37
+ docDirectory,
37
38
  addDependency
38
39
  }
39
40
  ],
@@ -1,4 +1,4 @@
1
- import { node_path, extractTextAndId, createProcessor, loadFrontMatter } from "../../2240.js";
1
+ import { node_path, extractTextAndId, createProcessor, loadFrontMatter } from "../../6162.js";
2
2
  import { createMDXOptions } from "./options.js";
3
3
  import { applyReplaceRules } from "../utils/applyReplaceRules.js";
4
4
  import { escapeMarkdownHeadingIds } from "../utils/escapeHeadingIds.js";
@@ -1,4 +1,4 @@
1
- import { visit } from "../../../2240.js";
1
+ import { visit } from "../../../6162.js";
2
2
  const rehypeCodeMeta = ()=>(tree)=>{
3
3
  visit(tree, 'element', (node)=>{
4
4
  if ('pre' === node.tagName && node.children[0]?.type === 'element' && 'code' === node.children[0].tagName) {
@@ -1,4 +1,4 @@
1
- import { visit, extractTextAndId, github_slugger, headingRank } from "../../../2240.js";
1
+ import { visit, extractTextAndId, github_slugger, headingRank } from "../../../6162.js";
2
2
  const rehypeHeaderAnchor = ()=>{
3
3
  const slugger = new github_slugger();
4
4
  return (tree)=>{
@@ -1,4 +1,4 @@
1
- import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddFold, createCssVariablesTheme, transformerAddWrapCode } from "../../../2240.js";
1
+ import { transformerAddLang, transformerAddLineNumbers, transformerAddTitle, transformerAddFold, createCssVariablesTheme, transformerAddWrapCode } from "../../../6162.js";
2
2
  const cssVariablesTheme = createCssVariablesTheme({
3
3
  name: 'css-variables',
4
4
  variablePrefix: '--shiki-',
@@ -1,12 +1,9 @@
1
1
  const SHIKI_TRANSFORMER_ADD_TITLE = 'shiki-transformer:add-title';
2
+ const TITLE_META_REGEX = /(?:^|\s)title=(?:"([^"]*)"|'([^']*)'|`([^`]*)`|([^\s]+))(?=\s|$)/;
2
3
  function parseTitleFromMeta(meta) {
3
4
  if (!meta) return '';
4
- const kvList = meta.split(' ').filter(Boolean);
5
- for (const item of kvList){
6
- const [k, v = ''] = item.split('=').filter(Boolean);
7
- if ('title' === k && v.length > 0) return v.replace(/["'`]/g, '');
8
- }
9
- return '';
5
+ const matched = meta.match(TITLE_META_REGEX);
6
+ return matched?.slice(1).find(Boolean) ?? '';
10
7
  }
11
8
  function transformerAddTitle() {
12
9
  return {
@@ -1,4 +1,4 @@
1
- export { SHIKI_TRANSFORMER_ADD_FOLD, transformerAddFold, } from './add-fold.js';
1
+ export { SHIKI_TRANSFORMER_ADD_FOLD, transformerAddFold } from './add-fold.js';
2
2
  export { SHIKI_TRANSFORMER_ADD_LANG, transformerAddLang } from './add-lang.js';
3
3
  export { SHIKI_TRANSFORMER_ADD_LINE_NUMBERS, transformerAddLineNumbers, } from './add-line-numbers.js';
4
4
  export { SHIKI_TRANSFORMER_ADD_TITLE, transformerAddTitle } from './add-title.js';
@@ -1,4 +1,4 @@
1
- import { node_path } from "../../../2240.js";
1
+ import { node_path } from "../../../6162.js";
2
2
  import { getDefaultImportAstNode } from "../../utils/getImportAstNode.js";
3
3
  const remarkBuiltin = ({ globalComponents })=>(tree)=>{
4
4
  const demos = globalComponents.map((componentPath)=>{
@@ -13,7 +13,7 @@
13
13
  */
14
14
  import type { Root } from 'mdast';
15
15
  import type { Plugin } from 'unified';
16
- export declare const DIRECTIVE_TYPES: readonly ["tip", "note", "warning", "caution", "danger", "info", "details"];
16
+ export declare const DIRECTIVE_TYPES: readonly ['tip', 'note', 'warning', 'caution', 'danger', 'info', 'details'];
17
17
  export declare const REGEX_BEGIN: RegExp;
18
18
  export declare const REGEX_END: RegExp;
19
19
  export declare const REGEX_GH_BEGIN: RegExp;