fumadocs-core 14.5.6 → 14.6.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.
- package/dist/{chunk-SNREABER.js → chunk-775SHR3E.js} +0 -1
- package/dist/{chunk-7CSWJQ5H.js → chunk-VD7J34CI.js} +19 -10
- package/dist/mdx-plugins/index.js +20 -19
- package/dist/search/client.js +3 -3
- package/dist/search/server.d.ts +6 -7
- package/dist/search/server.js +25 -22
- package/dist/server/index.d.ts +1 -1
- package/dist/server/index.js +1 -3
- package/dist/{shiki-FJwEmGMA.d.ts → shiki-fdNJu0Yj.d.ts} +1 -5
- package/dist/{static-FSUPSGDU.js → static-HJNGYVTY.js} +1 -1
- package/dist/toc.d.ts +1 -1
- package/dist/toc.js +3 -1
- package/dist/utils/use-shiki.d.ts +16 -3
- package/dist/utils/use-shiki.js +76 -18
- package/package.json +10 -10
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import {
|
|
3
|
-
getSingletonHighlighter
|
|
4
|
-
} from "shiki";
|
|
1
|
+
// src/utils/shiki.ts
|
|
5
2
|
import { toJsxRuntime } from "hast-util-to-jsx-runtime";
|
|
6
3
|
import { Fragment } from "react";
|
|
7
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
-
import { createOnigurumaEngine } from "shiki/engine/oniguruma";
|
|
9
5
|
function createStyleTransformer() {
|
|
10
6
|
return {
|
|
11
7
|
name: "rehype-code:styles",
|
|
@@ -23,37 +19,50 @@ var defaultThemes = {
|
|
|
23
19
|
light: "github-light",
|
|
24
20
|
dark: "github-dark"
|
|
25
21
|
};
|
|
26
|
-
async function
|
|
27
|
-
const {
|
|
22
|
+
async function _highlight(code, options) {
|
|
23
|
+
const { getSingletonHighlighter } = await import("shiki");
|
|
24
|
+
const { lang, components: _, engine: defaultEngine, ...rest } = options;
|
|
28
25
|
let themes = { themes: defaultThemes };
|
|
29
26
|
if ("theme" in options && options.theme) {
|
|
30
27
|
themes = { theme: options.theme };
|
|
31
28
|
} else if ("themes" in options && options.themes) {
|
|
32
29
|
themes = { themes: options.themes };
|
|
33
30
|
}
|
|
31
|
+
let engine = defaultEngine;
|
|
32
|
+
if (!engine) {
|
|
33
|
+
const { createOnigurumaEngine } = await import("shiki/engine/oniguruma");
|
|
34
|
+
engine = await createOnigurumaEngine(await import("shiki/wasm"));
|
|
35
|
+
}
|
|
34
36
|
const highlighter = await getSingletonHighlighter({
|
|
35
37
|
langs: [lang],
|
|
36
|
-
engine
|
|
38
|
+
engine,
|
|
37
39
|
themes: "theme" in themes ? [themes.theme] : Object.values(themes.themes).filter((v) => v !== void 0)
|
|
38
40
|
});
|
|
39
|
-
|
|
41
|
+
return highlighter.codeToHast(code, {
|
|
40
42
|
lang,
|
|
41
43
|
...rest,
|
|
42
44
|
...themes,
|
|
43
45
|
transformers: [createStyleTransformer(), ...rest.transformers ?? []],
|
|
44
46
|
defaultColor: "themes" in themes ? false : void 0
|
|
45
47
|
});
|
|
48
|
+
}
|
|
49
|
+
function _renderHighlight(hast, options) {
|
|
46
50
|
return toJsxRuntime(hast, {
|
|
47
51
|
jsx,
|
|
48
52
|
jsxs,
|
|
49
53
|
development: false,
|
|
50
|
-
components,
|
|
54
|
+
components: options?.components,
|
|
51
55
|
Fragment
|
|
52
56
|
});
|
|
53
57
|
}
|
|
58
|
+
async function highlight(code, options) {
|
|
59
|
+
return _renderHighlight(await _highlight(code, options), options);
|
|
60
|
+
}
|
|
54
61
|
|
|
55
62
|
export {
|
|
56
63
|
createStyleTransformer,
|
|
57
64
|
defaultThemes,
|
|
65
|
+
_highlight,
|
|
66
|
+
_renderHighlight,
|
|
58
67
|
highlight
|
|
59
68
|
};
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import {
|
|
10
10
|
createStyleTransformer,
|
|
11
11
|
defaultThemes
|
|
12
|
-
} from "../chunk-
|
|
12
|
+
} from "../chunk-VD7J34CI.js";
|
|
13
13
|
import "../chunk-MLKGABMK.js";
|
|
14
14
|
|
|
15
15
|
// src/mdx-plugins/index.ts
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
// src/mdx-plugins/rehype-code.ts
|
|
21
21
|
import rehypeShikiFromHighlighter from "@shikijs/rehype/core";
|
|
22
22
|
|
|
23
|
-
// ../../node_modules/.pnpm/shiki-transformers@1.0.1_shiki@1.24.
|
|
23
|
+
// ../../node_modules/.pnpm/shiki-transformers@1.0.1_shiki@1.24.2/node_modules/shiki-transformers/dist/index.js
|
|
24
24
|
var matchers = [
|
|
25
25
|
[/^(<!--)(.+)(-->)$/, false],
|
|
26
26
|
[/^(\/\*)(.+)(\*\/)$/, false],
|
|
@@ -437,6 +437,10 @@ var metaValues = [
|
|
|
437
437
|
{
|
|
438
438
|
name: "tab",
|
|
439
439
|
regex: /tab="(?<value>[^"]+)"/
|
|
440
|
+
},
|
|
441
|
+
{
|
|
442
|
+
name: "tab",
|
|
443
|
+
regex: /tab/
|
|
440
444
|
}
|
|
441
445
|
];
|
|
442
446
|
var rehypeCodeDefaultOptions = {
|
|
@@ -453,19 +457,14 @@ var rehypeCodeDefaultOptions = {
|
|
|
453
457
|
parseMetaString(meta) {
|
|
454
458
|
const map = {};
|
|
455
459
|
for (const value of metaValues) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
map[value.name] =
|
|
459
|
-
|
|
460
|
+
meta = meta.replace(value.regex, (_, ...args) => {
|
|
461
|
+
const first = args.at(0);
|
|
462
|
+
map[value.name] = typeof first === "string" ? first : "";
|
|
463
|
+
return "";
|
|
464
|
+
});
|
|
460
465
|
}
|
|
466
|
+
map.__parsed_raw = meta;
|
|
461
467
|
return map;
|
|
462
|
-
},
|
|
463
|
-
filterMetaString(meta) {
|
|
464
|
-
let replaced = meta;
|
|
465
|
-
for (const value of metaValues) {
|
|
466
|
-
replaced = replaced.replace(value.regex, "");
|
|
467
|
-
}
|
|
468
|
-
return replaced;
|
|
469
468
|
}
|
|
470
469
|
};
|
|
471
470
|
function rehypeCode(options = {}) {
|
|
@@ -478,6 +477,10 @@ function rehypeCode(options = {}) {
|
|
|
478
477
|
{
|
|
479
478
|
name: "rehype-code:pre-process",
|
|
480
479
|
preprocess(code, { meta }) {
|
|
480
|
+
if (meta && "__parsed_raw" in meta) {
|
|
481
|
+
meta.__raw = meta.__parsed_raw;
|
|
482
|
+
delete meta.__parsed_raw;
|
|
483
|
+
}
|
|
481
484
|
if (meta && codeOptions.filterMetaString) {
|
|
482
485
|
meta.__raw = codeOptions.filterMetaString(meta.__raw ?? "");
|
|
483
486
|
}
|
|
@@ -510,7 +513,7 @@ function rehypeCode(options = {}) {
|
|
|
510
513
|
(instance) => rehypeShikiFromHighlighter(instance, codeOptions)
|
|
511
514
|
);
|
|
512
515
|
return async (tree, file) => {
|
|
513
|
-
|
|
516
|
+
(await transformer)(tree, file, () => {
|
|
514
517
|
});
|
|
515
518
|
};
|
|
516
519
|
}
|
|
@@ -519,8 +522,8 @@ function transformerTab() {
|
|
|
519
522
|
name: "rehype-code:tab",
|
|
520
523
|
// @ts-expect-error -- types not compatible with MDX
|
|
521
524
|
root(root) {
|
|
522
|
-
const
|
|
523
|
-
if (typeof
|
|
525
|
+
const value = this.options.meta?.tab;
|
|
526
|
+
if (typeof value !== "string") return root;
|
|
524
527
|
return {
|
|
525
528
|
type: "root",
|
|
526
529
|
children: [
|
|
@@ -530,9 +533,7 @@ function transformerTab() {
|
|
|
530
533
|
data: {
|
|
531
534
|
_codeblock: true
|
|
532
535
|
},
|
|
533
|
-
attributes: [
|
|
534
|
-
{ type: "mdxJsxAttribute", name: "value", value: meta.tab }
|
|
535
|
-
],
|
|
536
|
+
attributes: value !== "" ? [{ type: "mdxJsxAttribute", name: "value", value }] : [],
|
|
536
537
|
children: root.children
|
|
537
538
|
}
|
|
538
539
|
]
|
package/dist/search/client.js
CHANGED
|
@@ -10,7 +10,7 @@ import { useMemo, useRef as useRef2, useState as useState2 } from "react";
|
|
|
10
10
|
import { useRef, useState } from "react";
|
|
11
11
|
function useDebounce(value, delayMs = 1e3) {
|
|
12
12
|
const [debouncedValue, setDebouncedValue] = useState(value);
|
|
13
|
-
const timer = useRef();
|
|
13
|
+
const timer = useRef(void 0);
|
|
14
14
|
if (delayMs === 0) return value;
|
|
15
15
|
if (value !== debouncedValue && timer.current?.value !== value) {
|
|
16
16
|
if (timer.current) clearTimeout(timer.current.handler);
|
|
@@ -31,7 +31,7 @@ function useDocsSearch(client, locale, tag, delayMs = 100, allowEmpty = false, k
|
|
|
31
31
|
const [error, setError] = useState2();
|
|
32
32
|
const [isLoading, setIsLoading] = useState2(false);
|
|
33
33
|
const debouncedValue = useDebounce(search, delayMs);
|
|
34
|
-
const onStart = useRef2();
|
|
34
|
+
const onStart = useRef2(void 0);
|
|
35
35
|
const cacheKey = useMemo(() => {
|
|
36
36
|
return key ?? JSON.stringify([client.type, debouncedValue, locale, tag]);
|
|
37
37
|
}, [client.type, debouncedValue, locale, tag, key]);
|
|
@@ -67,7 +67,7 @@ function useDocsSearch(client, locale, tag, delayMs = 100, allowEmpty = false, k
|
|
|
67
67
|
const { searchDocs } = await import("../orama-cloud-QNHGN6SO.js");
|
|
68
68
|
return searchDocs(debouncedValue, tag, client);
|
|
69
69
|
}
|
|
70
|
-
const { createStaticClient } = await import("../static-
|
|
70
|
+
const { createStaticClient } = await import("../static-HJNGYVTY.js");
|
|
71
71
|
if (!staticClient) staticClient = createStaticClient(client);
|
|
72
72
|
return staticClient.search(debouncedValue, locale, tag);
|
|
73
73
|
}
|
package/dist/search/server.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TypedDocument, Orama, Language, SearchParams,
|
|
1
|
+
import { TypedDocument, Orama, Language, SearchParams, create } from '@orama/orama';
|
|
2
2
|
import { NextRequest } from 'next/server';
|
|
3
3
|
import { S as StructuredData } from '../remark-structure-mP51W1AN.js';
|
|
4
4
|
import { S as SortedResult } from '../types-Ch8gnVgO.js';
|
|
@@ -48,7 +48,7 @@ declare function createI18nSearchAPI<T extends 'simple' | 'advanced'>(type: T, o
|
|
|
48
48
|
type Options = Omit<AdvancedOptions, 'language' | 'indexes'> & {
|
|
49
49
|
localeMap?: LocaleMap<Partial<AdvancedOptions>>;
|
|
50
50
|
};
|
|
51
|
-
declare function createFromSource<S extends LoaderOutput<LoaderConfig>>(source: S,
|
|
51
|
+
declare function createFromSource<S extends LoaderOutput<LoaderConfig>>(source: S, pageToIndexFn?: (page: InferPageType<S>) => AdvancedIndex, options?: Options): SearchAPI;
|
|
52
52
|
|
|
53
53
|
interface SearchServer {
|
|
54
54
|
search: (query: string, options?: {
|
|
@@ -73,12 +73,11 @@ interface SearchAPI extends SearchServer {
|
|
|
73
73
|
* Resolve indexes dynamically
|
|
74
74
|
*/
|
|
75
75
|
type Dynamic<T> = () => T[] | Promise<T[]>;
|
|
76
|
-
|
|
76
|
+
type OramaInput = Parameters<typeof create>[0];
|
|
77
|
+
type SharedOptions = Pick<OramaInput, 'sort' | 'components' | 'plugins'> & {
|
|
77
78
|
language?: string;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
plugins?: OramaPlugin[];
|
|
81
|
-
}
|
|
79
|
+
tokenizer?: Required<OramaInput>['components']['tokenizer'];
|
|
80
|
+
};
|
|
82
81
|
interface SimpleOptions extends SharedOptions {
|
|
83
82
|
indexes: Index[] | Dynamic<Index>;
|
|
84
83
|
/**
|
package/dist/search/server.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
searchAdvanced,
|
|
3
3
|
searchSimple
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-775SHR3E.js";
|
|
5
5
|
import "../chunk-2V6SCS43.js";
|
|
6
6
|
import "../chunk-MLKGABMK.js";
|
|
7
7
|
|
|
8
8
|
// src/search/server.ts
|
|
9
|
-
import {
|
|
10
|
-
save
|
|
11
|
-
} from "@orama/orama";
|
|
9
|
+
import { save } from "@orama/orama";
|
|
12
10
|
|
|
13
11
|
// src/search/create-endpoint.ts
|
|
14
12
|
function createEndpoint(server) {
|
|
@@ -52,11 +50,11 @@ async function createDB({
|
|
|
52
50
|
}) {
|
|
53
51
|
const items = typeof indexes === "function" ? await indexes() : indexes;
|
|
54
52
|
const db = await create({
|
|
55
|
-
...rest,
|
|
56
53
|
schema: advancedSchema,
|
|
57
54
|
components: {
|
|
58
55
|
tokenizer
|
|
59
|
-
}
|
|
56
|
+
},
|
|
57
|
+
...rest
|
|
60
58
|
});
|
|
61
59
|
const mapTo = [];
|
|
62
60
|
items.forEach((page) => {
|
|
@@ -111,20 +109,25 @@ import {
|
|
|
111
109
|
create as create2,
|
|
112
110
|
insertMultiple as insertMultiple2
|
|
113
111
|
} from "@orama/orama";
|
|
112
|
+
var schema = {
|
|
113
|
+
url: "string",
|
|
114
|
+
title: "string",
|
|
115
|
+
description: "string",
|
|
116
|
+
content: "string",
|
|
117
|
+
keywords: "string"
|
|
118
|
+
};
|
|
114
119
|
async function createDBSimple({
|
|
115
120
|
indexes,
|
|
116
|
-
|
|
121
|
+
tokenizer,
|
|
122
|
+
...rest
|
|
117
123
|
}) {
|
|
118
124
|
const items = typeof indexes === "function" ? await indexes() : indexes;
|
|
119
125
|
const db = await create2({
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
content: "string",
|
|
126
|
-
keywords: "string"
|
|
127
|
-
}
|
|
126
|
+
schema,
|
|
127
|
+
components: {
|
|
128
|
+
tokenizer
|
|
129
|
+
},
|
|
130
|
+
...rest
|
|
128
131
|
});
|
|
129
132
|
await insertMultiple2(
|
|
130
133
|
db,
|
|
@@ -140,7 +143,7 @@ async function createDBSimple({
|
|
|
140
143
|
}
|
|
141
144
|
|
|
142
145
|
// src/search/create-from-source.ts
|
|
143
|
-
function
|
|
146
|
+
function pageToIndex(page) {
|
|
144
147
|
if (!("structuredData" in page.data)) {
|
|
145
148
|
throw new Error(
|
|
146
149
|
"Cannot find structured data from page, please define the page to index function."
|
|
@@ -154,7 +157,7 @@ function defaultToIndex(page) {
|
|
|
154
157
|
structuredData: page.data.structuredData
|
|
155
158
|
};
|
|
156
159
|
}
|
|
157
|
-
function createFromSource(source,
|
|
160
|
+
function createFromSource(source, pageToIndexFn = pageToIndex, options = {}) {
|
|
158
161
|
if (source._i18n) {
|
|
159
162
|
return createI18nSearchAPI("advanced", {
|
|
160
163
|
...options,
|
|
@@ -162,7 +165,7 @@ function createFromSource(source, pageToIndex = defaultToIndex, options = {}) {
|
|
|
162
165
|
indexes: source.getLanguages().flatMap((entry) => {
|
|
163
166
|
return entry.pages.map((page) => {
|
|
164
167
|
return {
|
|
165
|
-
...
|
|
168
|
+
...pageToIndexFn(page),
|
|
166
169
|
locale: entry.language
|
|
167
170
|
};
|
|
168
171
|
});
|
|
@@ -172,7 +175,7 @@ function createFromSource(source, pageToIndex = defaultToIndex, options = {}) {
|
|
|
172
175
|
return createSearchAPI("advanced", {
|
|
173
176
|
...options,
|
|
174
177
|
indexes: source.getPages().map((page) => {
|
|
175
|
-
return
|
|
178
|
+
return pageToIndexFn(page);
|
|
176
179
|
})
|
|
177
180
|
});
|
|
178
181
|
}
|
|
@@ -277,7 +280,7 @@ function createI18nSearchAPI(type, options) {
|
|
|
277
280
|
data: Object.fromEntries(await Promise.all(entries))
|
|
278
281
|
};
|
|
279
282
|
},
|
|
280
|
-
|
|
283
|
+
async search(query, searchOptions) {
|
|
281
284
|
const map = await get;
|
|
282
285
|
const locale = searchOptions?.locale ?? options.i18n.defaultLanguage;
|
|
283
286
|
const handler = map.get(locale);
|
|
@@ -303,7 +306,7 @@ function initSimpleSearch(options) {
|
|
|
303
306
|
...save(await doc)
|
|
304
307
|
};
|
|
305
308
|
},
|
|
306
|
-
|
|
309
|
+
async search(query) {
|
|
307
310
|
const db = await doc;
|
|
308
311
|
return searchSimple(db, query, options.search);
|
|
309
312
|
}
|
|
@@ -318,7 +321,7 @@ function initAdvancedSearch(options) {
|
|
|
318
321
|
...save(await get)
|
|
319
322
|
};
|
|
320
323
|
},
|
|
321
|
-
|
|
324
|
+
async search(query, searchOptions) {
|
|
322
325
|
const db = await get;
|
|
323
326
|
return searchAdvanced(db, query, searchOptions?.tag, options.search);
|
|
324
327
|
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { S as SortedResult } from '../types-Ch8gnVgO.js';
|
|
|
5
5
|
import { Metadata } from 'next';
|
|
6
6
|
import { NextRequest } from 'next/server';
|
|
7
7
|
import { LoaderOutput, LoaderConfig, InferPageType } from '../source/index.js';
|
|
8
|
-
export { H as HighlightOptions, c as createStyleTransformer,
|
|
8
|
+
export { H as HighlightOptions, c as createStyleTransformer, h as highlight } from '../shiki-fdNJu0Yj.js';
|
|
9
9
|
import 'react';
|
|
10
10
|
import '../config-inq6kP6y.js';
|
|
11
11
|
import 'shiki';
|
package/dist/server/index.js
CHANGED
|
@@ -3,9 +3,8 @@ import {
|
|
|
3
3
|
} from "../chunk-4MNUWZIW.js";
|
|
4
4
|
import {
|
|
5
5
|
createStyleTransformer,
|
|
6
|
-
defaultThemes,
|
|
7
6
|
highlight
|
|
8
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-VD7J34CI.js";
|
|
9
8
|
import "../chunk-MLKGABMK.js";
|
|
10
9
|
|
|
11
10
|
// src/server/get-toc.ts
|
|
@@ -153,7 +152,6 @@ export {
|
|
|
153
152
|
page_tree_exports as PageTree,
|
|
154
153
|
createMetadataImage,
|
|
155
154
|
createStyleTransformer,
|
|
156
|
-
defaultThemes,
|
|
157
155
|
findNeighbour,
|
|
158
156
|
flattenTree,
|
|
159
157
|
getGithubLastEdit,
|
|
@@ -4,13 +4,9 @@ import { Components } from 'hast-util-to-jsx-runtime';
|
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
|
6
6
|
declare function createStyleTransformer(): ShikiTransformer;
|
|
7
|
-
declare const defaultThemes: {
|
|
8
|
-
light: string;
|
|
9
|
-
dark: string;
|
|
10
|
-
};
|
|
11
7
|
type HighlightOptions = CodeToHastOptionsCommon<BundledLanguage> & Pick<HighlighterCoreOptions, 'engine'> & Partial<CodeOptionsThemes<BundledTheme>> & CodeOptionsMeta & {
|
|
12
8
|
components?: Partial<Components>;
|
|
13
9
|
};
|
|
14
10
|
declare function highlight(code: string, options: HighlightOptions): Promise<ReactNode>;
|
|
15
11
|
|
|
16
|
-
export { type HighlightOptions as H, createStyleTransformer as c,
|
|
12
|
+
export { type HighlightOptions as H, createStyleTransformer as c, highlight as h };
|
package/dist/toc.d.ts
CHANGED
|
@@ -24,7 +24,7 @@ interface ScrollProviderProps {
|
|
|
24
24
|
/**
|
|
25
25
|
* Scroll into the view of container when active
|
|
26
26
|
*/
|
|
27
|
-
containerRef: RefObject<HTMLElement>;
|
|
27
|
+
containerRef: RefObject<HTMLElement | null>;
|
|
28
28
|
children?: ReactNode;
|
|
29
29
|
}
|
|
30
30
|
declare function ScrollProvider({ containerRef, children, }: ScrollProviderProps): React.ReactElement;
|
package/dist/toc.js
CHANGED
|
@@ -70,7 +70,9 @@ function useAnchorObserver(watch, single) {
|
|
|
70
70
|
// src/toc.tsx
|
|
71
71
|
import { jsx } from "react/jsx-runtime";
|
|
72
72
|
var ActiveAnchorContext = createContext([]);
|
|
73
|
-
var ScrollContext = createContext({
|
|
73
|
+
var ScrollContext = createContext({
|
|
74
|
+
current: null
|
|
75
|
+
});
|
|
74
76
|
function useActiveAnchor() {
|
|
75
77
|
return useContext(ActiveAnchorContext).at(-1);
|
|
76
78
|
}
|
|
@@ -1,11 +1,24 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
1
2
|
import { ReactNode, DependencyList } from 'react';
|
|
2
|
-
import { H as HighlightOptions } from '../shiki-
|
|
3
|
+
import { H as HighlightOptions } from '../shiki-fdNJu0Yj.js';
|
|
4
|
+
import { Root } from 'hast';
|
|
3
5
|
import 'shiki';
|
|
4
6
|
import 'shiki/themes';
|
|
5
7
|
import 'hast-util-to-jsx-runtime';
|
|
6
8
|
|
|
7
|
-
declare
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
_use_shiki?: Map<string, Root>;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
declare function useShiki(code: string, { defaultValue, scriptKey, ...options }: HighlightOptions & {
|
|
8
15
|
defaultValue?: ReactNode;
|
|
16
|
+
scriptKey?: string;
|
|
9
17
|
}, deps?: DependencyList): ReactNode;
|
|
18
|
+
declare function PrerenderScript({ scriptKey, code, options, }: {
|
|
19
|
+
scriptKey: string;
|
|
20
|
+
code: string;
|
|
21
|
+
options: HighlightOptions;
|
|
22
|
+
}): react_jsx_runtime.JSX.Element | null;
|
|
10
23
|
|
|
11
|
-
export { useShiki };
|
|
24
|
+
export { PrerenderScript, useShiki };
|
package/dist/utils/use-shiki.js
CHANGED
|
@@ -1,38 +1,96 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import {
|
|
3
|
+
_highlight,
|
|
4
|
+
_renderHighlight,
|
|
3
5
|
highlight
|
|
4
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-VD7J34CI.js";
|
|
5
7
|
import "../chunk-MLKGABMK.js";
|
|
6
8
|
|
|
7
9
|
// src/utils/use-shiki.tsx
|
|
8
10
|
import {
|
|
11
|
+
use,
|
|
9
12
|
useEffect,
|
|
13
|
+
useRef,
|
|
10
14
|
useState
|
|
11
15
|
} from "react";
|
|
12
|
-
import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
|
|
13
16
|
import { jsx } from "react/jsx-runtime";
|
|
14
17
|
var jsEngine;
|
|
15
|
-
function
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
function getHighlightOptions(from) {
|
|
19
|
+
if (from.engine) return from;
|
|
20
|
+
if (!jsEngine) {
|
|
21
|
+
jsEngine = import("shiki/engine/javascript").then(
|
|
22
|
+
(res) => res.createJavaScriptRegexEngine()
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
...from,
|
|
27
|
+
engine: jsEngine
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
var cache = /* @__PURE__ */ new Map();
|
|
31
|
+
function useShiki(code, {
|
|
32
|
+
defaultValue,
|
|
33
|
+
scriptKey,
|
|
34
|
+
...options
|
|
35
|
+
}, deps) {
|
|
36
|
+
const key = deps ? JSON.stringify(deps) : `${options.lang}:${code}`;
|
|
37
|
+
const shikiOptions = getHighlightOptions(options);
|
|
38
|
+
const currentTask = useRef({
|
|
39
|
+
key,
|
|
40
|
+
aborted: false
|
|
41
|
+
});
|
|
42
|
+
const [rendered, setRendered] = useState(() => {
|
|
43
|
+
if (defaultValue) return defaultValue;
|
|
44
|
+
const cached = cache.get(key);
|
|
45
|
+
if (cached) return cached;
|
|
46
|
+
const hast = globalThis._use_shiki?.get(scriptKey);
|
|
47
|
+
if (hast) {
|
|
48
|
+
const node = _renderHighlight(hast, shikiOptions);
|
|
49
|
+
cache.set(key, node);
|
|
50
|
+
return node;
|
|
51
|
+
}
|
|
52
|
+
currentTask.current = void 0;
|
|
53
|
+
const Pre = options.components?.pre ?? "pre";
|
|
54
|
+
const Code = options.components?.code ?? "code";
|
|
19
55
|
return /* @__PURE__ */ jsx(Pre, { children: /* @__PURE__ */ jsx(Code, { children: code }) });
|
|
20
56
|
});
|
|
21
|
-
if (
|
|
22
|
-
|
|
57
|
+
if (typeof window === "undefined") {
|
|
58
|
+
return use(highlight(code, shikiOptions));
|
|
23
59
|
}
|
|
24
|
-
|
|
25
|
-
()
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
60
|
+
if (!currentTask.current || currentTask.current.key !== key) {
|
|
61
|
+
if (currentTask.current) {
|
|
62
|
+
currentTask.current.aborted = true;
|
|
63
|
+
}
|
|
64
|
+
const task = {
|
|
65
|
+
key,
|
|
66
|
+
aborted: false
|
|
67
|
+
};
|
|
68
|
+
currentTask.current = task;
|
|
69
|
+
highlight(code, shikiOptions).then((result) => {
|
|
70
|
+
cache.set(key, result);
|
|
71
|
+
if (!task.aborted) setRendered(result);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return rendered;
|
|
75
|
+
}
|
|
76
|
+
function PrerenderScript({
|
|
77
|
+
scriptKey,
|
|
78
|
+
code,
|
|
79
|
+
options
|
|
80
|
+
}) {
|
|
81
|
+
const [mounted, setMounted] = useState(false);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
setMounted(true);
|
|
84
|
+
}, []);
|
|
85
|
+
const tree = typeof window === "undefined" ? use(_highlight(code, getHighlightOptions(options))) : (
|
|
86
|
+
// @ts-expect-error -- typed
|
|
87
|
+
globalThis._use_shiki?.get(scriptKey)
|
|
33
88
|
);
|
|
34
|
-
return
|
|
89
|
+
if (mounted || !tree) return null;
|
|
90
|
+
return /* @__PURE__ */ jsx("script", { children: `if (typeof globalThis._use_shiki === "undefined") globalThis._use_shiki = new Map()
|
|
91
|
+
globalThis._use_shiki.set(${JSON.stringify(scriptKey)}, ${JSON.stringify(tree)})` });
|
|
35
92
|
}
|
|
36
93
|
export {
|
|
94
|
+
PrerenderScript,
|
|
37
95
|
useShiki
|
|
38
96
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-core",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.6.0",
|
|
4
4
|
"description": "The library for building a documentation website in Next.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"dist/*"
|
|
74
74
|
],
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"@formatjs/intl-localematcher": "^0.5.
|
|
76
|
+
"@formatjs/intl-localematcher": "^0.5.9",
|
|
77
77
|
"@orama/orama": "^2.1.1",
|
|
78
|
-
"@shikijs/rehype": "^1.24.
|
|
78
|
+
"@shikijs/rehype": "^1.24.2",
|
|
79
79
|
"github-slugger": "^2.0.0",
|
|
80
80
|
"hast-util-to-estree": "^3.1.0",
|
|
81
81
|
"hast-util-to-jsx-runtime": "^2.3.2",
|
|
@@ -85,11 +85,10 @@
|
|
|
85
85
|
"remark": "^15.0.0",
|
|
86
86
|
"remark-gfm": "^4.0.0",
|
|
87
87
|
"scroll-into-view-if-needed": "^3.1.0",
|
|
88
|
-
"shiki": "^1.24.
|
|
88
|
+
"shiki": "^1.24.2",
|
|
89
89
|
"unist-util-visit": "^5.0.0"
|
|
90
90
|
},
|
|
91
91
|
"devDependencies": {
|
|
92
|
-
"typescript": "^5.7.2",
|
|
93
92
|
"@algolia/client-search": "4.24.0",
|
|
94
93
|
"@mdx-js/mdx": "^3.1.0",
|
|
95
94
|
"@oramacloud/client": "^2.1.4",
|
|
@@ -98,15 +97,16 @@
|
|
|
98
97
|
"@types/mdast": "^4.0.3",
|
|
99
98
|
"@types/negotiator": "^0.6.3",
|
|
100
99
|
"@types/node": "22.10.1",
|
|
101
|
-
"@types/react": "^
|
|
102
|
-
"@types/react-dom": "^
|
|
100
|
+
"@types/react": "^19.0.1",
|
|
101
|
+
"@types/react-dom": "^19.0.2",
|
|
103
102
|
"algoliasearch": "4.24.0",
|
|
104
103
|
"mdast-util-mdx-jsx": "^3.1.3",
|
|
105
104
|
"mdast-util-mdxjs-esm": "^2.0.1",
|
|
106
|
-
"next": "^15.0.
|
|
105
|
+
"next": "^15.0.4",
|
|
107
106
|
"remark-mdx": "^3.1.0",
|
|
108
107
|
"remark-rehype": "^11.1.1",
|
|
109
108
|
"shiki-transformers": "^1.0.1",
|
|
109
|
+
"typescript": "^5.7.2",
|
|
110
110
|
"unified": "^11.0.5",
|
|
111
111
|
"eslint-config-custom": "0.0.0",
|
|
112
112
|
"tsconfig": "0.0.0"
|
|
@@ -115,8 +115,8 @@
|
|
|
115
115
|
"@oramacloud/client": "1.x.x || 2.x.x",
|
|
116
116
|
"algoliasearch": "4.24.0",
|
|
117
117
|
"next": "14.x.x || 15.x.x",
|
|
118
|
-
"react": "
|
|
119
|
-
"react-dom": "
|
|
118
|
+
"react": "18.x.x || 19.x.x",
|
|
119
|
+
"react-dom": "18.x.x || 19.x.x"
|
|
120
120
|
},
|
|
121
121
|
"peerDependenciesMeta": {
|
|
122
122
|
"@oramacloud/client": {
|