fumadocs-core 15.0.11 → 15.0.13

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.
@@ -1,5 +1,5 @@
1
1
  import { ReactNode } from 'react';
2
- import { R as Root, N as Node } from './page-tree-B1oLifVu.js';
2
+ import { R as Root, N as Node } from './page-tree-CfT5zlWh.js';
3
3
 
4
4
  interface BreadcrumbItem {
5
5
  name: ReactNode;
@@ -1,4 +1,4 @@
1
- // src/utils/shiki.ts
1
+ // src/highlight/shiki.ts
2
2
  import { toJsxRuntime } from "hast-util-to-jsx-runtime";
3
3
  import { Fragment } from "react";
4
4
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -0,0 +1,17 @@
1
+ // src/utils/remove-undefined.ts
2
+ function removeUndefined(value, deep = false) {
3
+ const obj = value;
4
+ for (const key of Object.keys(obj)) {
5
+ if (obj[key] === void 0) delete obj[key];
6
+ if (deep && typeof obj[key] === "object" && obj[key] !== null) {
7
+ removeUndefined(obj[key], deep);
8
+ } else if (deep && Array.isArray(obj[key])) {
9
+ obj[key].forEach((v) => removeUndefined(v, deep));
10
+ }
11
+ }
12
+ return value;
13
+ }
14
+
15
+ export {
16
+ removeUndefined
17
+ };
@@ -0,0 +1,90 @@
1
+ import {
2
+ _highlight,
3
+ _renderHighlight,
4
+ highlight
5
+ } from "./chunk-E7AASGCN.js";
6
+
7
+ // src/highlight/client.tsx
8
+ import {
9
+ useId,
10
+ useMemo,
11
+ useRef,
12
+ useState
13
+ } from "react";
14
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
15
+ var jsEngine;
16
+ function getHighlightOptions(from) {
17
+ if (from.engine) return from;
18
+ if (!jsEngine) {
19
+ jsEngine = import("shiki/engine/javascript").then(
20
+ (res) => res.createJavaScriptRegexEngine()
21
+ );
22
+ }
23
+ return {
24
+ ...from,
25
+ engine: jsEngine
26
+ };
27
+ }
28
+ function useShiki(code, {
29
+ defaultValue,
30
+ withPrerenderScript = false,
31
+ ...options
32
+ }, deps) {
33
+ const scriptKey = useId();
34
+ const key = useMemo(
35
+ () => deps ? JSON.stringify(deps) : `${options.lang}:${code}`,
36
+ [code, deps, options.lang]
37
+ );
38
+ const shikiOptions = getHighlightOptions(options);
39
+ const currentTask = useRef({
40
+ key,
41
+ aborted: false
42
+ });
43
+ const [rendered, setRendered] = useState(() => {
44
+ if (defaultValue) return defaultValue;
45
+ const hast = globalThis._use_shiki?.get(scriptKey);
46
+ if (hast && withPrerenderScript) {
47
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
48
+ /* @__PURE__ */ jsx(PrerenderScript, { scriptKey, tree: hast }),
49
+ _renderHighlight(hast, shikiOptions)
50
+ ] });
51
+ }
52
+ currentTask.current = void 0;
53
+ const Pre = options.components?.pre ?? "pre";
54
+ const Code = options.components?.code ?? "code";
55
+ return /* @__PURE__ */ jsx(Pre, { children: /* @__PURE__ */ jsx(Code, { children: code }) });
56
+ });
57
+ if (typeof window === "undefined") {
58
+ return _highlight(code, shikiOptions).then((tree) => {
59
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
60
+ withPrerenderScript && /* @__PURE__ */ jsx(PrerenderScript, { scriptKey, tree }),
61
+ _renderHighlight(tree, shikiOptions)
62
+ ] });
63
+ });
64
+ }
65
+ if (!currentTask.current || currentTask.current.key !== key) {
66
+ if (currentTask.current) {
67
+ currentTask.current.aborted = true;
68
+ }
69
+ const task = {
70
+ key,
71
+ aborted: false
72
+ };
73
+ currentTask.current = task;
74
+ void highlight(code, shikiOptions).then((result) => {
75
+ if (!task.aborted) setRendered(result);
76
+ });
77
+ }
78
+ return rendered;
79
+ }
80
+ function PrerenderScript({
81
+ scriptKey,
82
+ tree
83
+ }) {
84
+ return /* @__PURE__ */ jsx("script", { children: `if (typeof globalThis._use_shiki === "undefined") globalThis._use_shiki = new Map()
85
+ globalThis._use_shiki.set(${JSON.stringify(scriptKey)}, ${JSON.stringify(tree)})` });
86
+ }
87
+
88
+ export {
89
+ useShiki
90
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  removeUndefined
3
- } from "./chunk-DELA6Z2I.js";
3
+ } from "./chunk-KAOEMCTI.js";
4
4
 
5
5
  // src/search/orama/search/simple.ts
6
6
  import { search } from "@orama/orama";
File without changes
@@ -0,0 +1,18 @@
1
+ import { ReactNode, DependencyList } from 'react';
2
+ import { HighlightOptions } from './index.js';
3
+ import { Root } from 'hast';
4
+ import 'shiki';
5
+ import 'shiki/themes';
6
+ import 'hast-util-to-jsx-runtime';
7
+
8
+ declare global {
9
+ interface Window {
10
+ _use_shiki?: Map<string, Root>;
11
+ }
12
+ }
13
+ declare function useShiki(code: string, { defaultValue, withPrerenderScript, ...options }: HighlightOptions & {
14
+ withPrerenderScript?: boolean;
15
+ defaultValue?: ReactNode;
16
+ }, deps?: DependencyList): ReactNode;
17
+
18
+ export { useShiki };
@@ -0,0 +1,9 @@
1
+ "use client";
2
+ import {
3
+ useShiki
4
+ } from "../chunk-QWBSUU36.js";
5
+ import "../chunk-E7AASGCN.js";
6
+ import "../chunk-MLKGABMK.js";
7
+ export {
8
+ useShiki
9
+ };
@@ -10,4 +10,4 @@ type HighlightOptions = CodeToHastOptionsCommon<BundledLanguage> & (CodeOptionsT
10
10
  };
11
11
  declare function highlight(code: string, options: HighlightOptions): Promise<ReactNode>;
12
12
 
13
- export { type HighlightOptions as H, createStyleTransformer as c, highlight as h };
13
+ export { type HighlightOptions, createStyleTransformer, highlight };
@@ -0,0 +1,10 @@
1
+ import "../chunk-WQMD6AUR.js";
2
+ import {
3
+ createStyleTransformer,
4
+ highlight
5
+ } from "../chunk-E7AASGCN.js";
6
+ import "../chunk-MLKGABMK.js";
7
+ export {
8
+ createStyleTransformer,
9
+ highlight
10
+ };
@@ -9,7 +9,7 @@ import {
9
9
  import {
10
10
  createStyleTransformer,
11
11
  defaultThemes
12
- } from "../chunk-SCQ5QN2V.js";
12
+ } from "../chunk-E7AASGCN.js";
13
13
  import "../chunk-MLKGABMK.js";
14
14
 
15
15
  // src/mdx-plugins/index.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  removeUndefined
3
- } from "./chunk-DELA6Z2I.js";
3
+ } from "./chunk-KAOEMCTI.js";
4
4
  import "./chunk-MLKGABMK.js";
5
5
 
6
6
  // src/search/client/orama-cloud.ts
@@ -1,26 +1,30 @@
1
1
  import { ReactNode, ReactElement } from 'react';
2
2
 
3
3
  interface Root {
4
+ $id?: string;
4
5
  name: ReactNode;
5
6
  children: Node[];
6
7
  }
7
8
  type Node = Item | Separator | Folder;
8
9
  interface Item {
10
+ $id?: string;
11
+ $ref?: {
12
+ file: string;
13
+ };
9
14
  type: 'page';
10
15
  name: ReactNode;
11
16
  url: string;
12
17
  external?: boolean;
13
18
  icon?: ReactElement;
14
- $ref?: {
15
- file: string;
16
- };
17
19
  }
18
20
  interface Separator {
21
+ $id?: string;
19
22
  type: 'separator';
20
23
  name: ReactNode;
21
24
  icon?: ReactElement;
22
25
  }
23
26
  interface Folder {
27
+ $id?: string;
24
28
  $ref?: {
25
29
  metaFile?: string;
26
30
  };
@@ -64,10 +64,10 @@ function useDocsSearch(client, locale, tag, delayMs = 100, allowEmpty = false, k
64
64
  return searchDocs(index, debouncedValue, tag, rest);
65
65
  }
66
66
  if (client.type === "orama-cloud") {
67
- const { searchDocs } = await import("../orama-cloud-HAZVD2ZO.js");
67
+ const { searchDocs } = await import("../orama-cloud-NHMXDFR2.js");
68
68
  return searchDocs(debouncedValue, tag, client);
69
69
  }
70
- const { createStaticClient } = await import("../static-R3CYGT5R.js");
70
+ const { createStaticClient } = await import("../static-JUVZRRCD.js");
71
71
  if (!staticClient) staticClient = createStaticClient(client);
72
72
  return staticClient.search(debouncedValue, locale, tag);
73
73
  }
@@ -8,7 +8,7 @@ import 'mdast';
8
8
  import 'unified';
9
9
  import 'unist-util-visit';
10
10
  import 'react';
11
- import '../page-tree-B1oLifVu.js';
11
+ import '../page-tree-CfT5zlWh.js';
12
12
 
13
13
  type AdvancedDocument = TypedDocument<Orama<typeof advancedSchema>>;
14
14
  declare const advancedSchema: {
@@ -29,7 +29,7 @@ declare const simpleSchema: {
29
29
  };
30
30
 
31
31
  type LocaleMap<O> = Record<string, Language | O>;
32
- type Options$1<O extends SimpleOptions | AdvancedOptions, Idx> = Omit<O, 'language' | 'indexes'> & {
32
+ type I18nOptions<O extends SimpleOptions | AdvancedOptions, Idx> = Omit<O, 'language' | 'indexes'> & {
33
33
  i18n: I18nConfig;
34
34
  /**
35
35
  * Map locale name from i18n config to Orama compatible `language` or options
@@ -37,8 +37,8 @@ type Options$1<O extends SimpleOptions | AdvancedOptions, Idx> = Omit<O, 'langua
37
37
  localeMap?: LocaleMap<Partial<O>>;
38
38
  indexes: WithLocale<Idx>[] | Dynamic<WithLocale<Idx>>;
39
39
  };
40
- type I18nSimpleOptions = Options$1<SimpleOptions, Index>;
41
- type I18nAdvancedOptions = Options$1<AdvancedOptions, AdvancedIndex>;
40
+ type I18nSimpleOptions = I18nOptions<SimpleOptions, Index>;
41
+ type I18nAdvancedOptions = I18nOptions<AdvancedOptions, AdvancedIndex>;
42
42
  type WithLocale<T> = T & {
43
43
  locale: string;
44
44
  };
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  searchAdvanced,
3
3
  searchSimple
4
- } from "../chunk-GIPLMX5F.js";
5
- import "../chunk-DELA6Z2I.js";
4
+ } from "../chunk-WFUH5VBX.js";
5
+ import "../chunk-KAOEMCTI.js";
6
6
  import "../chunk-MLKGABMK.js";
7
7
 
8
8
  // src/search/server.ts
@@ -53,10 +53,11 @@ async function createDB({
53
53
  const items = typeof indexes === "function" ? await indexes() : indexes;
54
54
  const db = await create({
55
55
  schema: advancedSchema,
56
+ ...rest,
56
57
  components: {
57
- tokenizer
58
- },
59
- ...rest
58
+ ...rest.components,
59
+ tokenizer: tokenizer ?? rest.components?.tokenizer
60
+ }
60
61
  });
61
62
  const mapTo = [];
62
63
  items.forEach((page) => {
@@ -120,10 +121,11 @@ async function createDBSimple({
120
121
  const items = typeof indexes === "function" ? await indexes() : indexes;
121
122
  const db = await create({
122
123
  schema: simpleSchema,
124
+ ...rest,
123
125
  components: {
124
- tokenizer
125
- },
126
- ...rest
126
+ ...rest.components,
127
+ tokenizer: tokenizer ?? rest.components?.tokenizer
128
+ }
127
129
  });
128
130
  await insertMultiple(
129
131
  db,
@@ -224,16 +226,16 @@ async function initSimple(options) {
224
226
  const indexes = typeof options.indexes === "function" ? await options.indexes() : options.indexes;
225
227
  for (const locale of options.i18n.languages) {
226
228
  const localeIndexes = indexes.filter((index) => index.locale === locale);
227
- const searchLocale = options.localeMap?.[locale] ?? await getTokenizer(locale);
229
+ const mapped = options.localeMap?.[locale] ?? await getTokenizer(locale);
228
230
  map.set(
229
231
  locale,
230
- typeof searchLocale === "object" ? initSimpleSearch({
232
+ typeof mapped === "object" ? initSimpleSearch({
231
233
  ...options,
232
- ...searchLocale,
234
+ ...mapped,
233
235
  indexes: localeIndexes
234
236
  }) : initSimpleSearch({
235
237
  ...options,
236
- language: searchLocale,
238
+ language: mapped,
237
239
  indexes: localeIndexes
238
240
  })
239
241
  );
@@ -248,16 +250,16 @@ async function initAdvanced(options) {
248
250
  const indexes = typeof options.indexes === "function" ? await options.indexes() : options.indexes;
249
251
  for (const locale of options.i18n.languages) {
250
252
  const localeIndexes = indexes.filter((index) => index.locale === locale);
251
- const searchLocale = options.localeMap?.[locale] ?? await getTokenizer(locale);
253
+ const mapped = options.localeMap?.[locale] ?? await getTokenizer(locale);
252
254
  map.set(
253
255
  locale,
254
- typeof searchLocale === "object" ? initAdvancedSearch({
256
+ typeof mapped === "object" ? initAdvancedSearch({
255
257
  ...options,
256
258
  indexes: localeIndexes,
257
- ...searchLocale
259
+ ...mapped
258
260
  }) : initAdvancedSearch({
259
261
  ...options,
260
- language: searchLocale,
262
+ language: mapped,
261
263
  indexes: localeIndexes
262
264
  })
263
265
  );
@@ -1,11 +1,11 @@
1
1
  export { a as TOCItemType, T as TableOfContents, g as getTableOfContents } from '../get-toc-Cr2URuiP.js';
2
- import { N as Node, I as Item, R as Root } from '../page-tree-B1oLifVu.js';
3
- export { p as PageTree } from '../page-tree-B1oLifVu.js';
2
+ import { N as Node, I as Item, R as Root } from '../page-tree-CfT5zlWh.js';
3
+ export { p as PageTree } from '../page-tree-CfT5zlWh.js';
4
4
  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, h as highlight } from '../shiki-D8ui5x1Y.js';
8
+ export { HighlightOptions, createStyleTransformer, highlight } from '../highlight/index.js';
9
9
  import 'react';
10
10
  import 'unified';
11
11
  import 'vfile';
@@ -1,10 +1,11 @@
1
1
  import {
2
2
  remarkHeading
3
3
  } from "../chunk-IYQ35KI2.js";
4
+ import "../chunk-WQMD6AUR.js";
4
5
  import {
5
6
  createStyleTransformer,
6
7
  highlight
7
- } from "../chunk-SCQ5QN2V.js";
8
+ } from "../chunk-E7AASGCN.js";
8
9
  import "../chunk-MLKGABMK.js";
9
10
 
10
11
  // src/server/get-toc.ts
@@ -1,6 +1,6 @@
1
1
  import { ReactElement } from 'react';
2
2
  import { I as I18nConfig } from '../config-inq6kP6y.js';
3
- import { R as Root, I as Item, F as Folder$1, S as Separator } from '../page-tree-B1oLifVu.js';
3
+ import { R as Root, I as Item, F as Folder$1, S as Separator } from '../page-tree-CfT5zlWh.js';
4
4
 
5
5
  interface FileInfo {
6
6
  /**
@@ -1,6 +1,3 @@
1
- import {
2
- removeUndefined
3
- } from "../chunk-DELA6Z2I.js";
4
1
  import {
5
2
  resolvePath,
6
3
  slash,
@@ -46,16 +43,17 @@ function buildAll(nodes, ctx, skipIndex) {
46
43
  output.push(...folders);
47
44
  return output;
48
45
  }
49
- function resolveFolderItem(folder, item, ctx, addedNodePaths) {
46
+ function resolveFolderItem(folder, item, ctx, idx, addedNodePaths) {
50
47
  if (item === rest || item === restReversed) return item;
51
48
  let match = separator.exec(item);
52
49
  if (match?.groups) {
53
50
  const node = {
51
+ $id: `${folder.file.path}#${idx}`,
54
52
  type: "separator",
55
53
  icon: ctx.options.resolveIcon?.(match.groups.icon),
56
54
  name: match.groups.name
57
55
  };
58
- return [removeUndefined(ctx.options.attachSeparator?.(node) ?? node)];
56
+ return [ctx.options.attachSeparator?.(node) ?? node];
59
57
  }
60
58
  match = link.exec(item);
61
59
  if (match?.groups) {
@@ -68,7 +66,7 @@ function resolveFolderItem(folder, item, ctx, addedNodePaths) {
68
66
  url,
69
67
  external: !isRelative
70
68
  };
71
- return [removeUndefined(ctx.options.attachFile?.(node) ?? node)];
69
+ return [ctx.options.attachFile?.(node) ?? node];
72
70
  }
73
71
  const isExcept = item.startsWith(excludePrefix), isExtract = item.startsWith(extractPrefix);
74
72
  let filename = item;
@@ -96,15 +94,15 @@ function buildFolderNode(folder, isGlobalRoot, ctx) {
96
94
  "page"
97
95
  );
98
96
  const metadata = meta?.data;
97
+ const isRoot = metadata?.root ?? isGlobalRoot;
99
98
  const index = indexFile ? buildFileNode(indexFile, ctx) : void 0;
100
99
  let children;
101
- if (!meta) {
102
- children = buildAll(folder.children, ctx, !isGlobalRoot);
100
+ if (!metadata?.pages) {
101
+ children = buildAll(folder.children, ctx, !isRoot);
103
102
  } else {
104
- const isRoot = metadata?.root ?? isGlobalRoot;
105
103
  const addedNodePaths = /* @__PURE__ */ new Set();
106
- const resolved = metadata?.pages?.flatMap((item) => {
107
- return resolveFolderItem(folder, item, ctx, addedNodePaths);
104
+ const resolved = metadata?.pages?.flatMap((item, i) => {
105
+ return resolveFolderItem(folder, item, ctx, i, addedNodePaths);
108
106
  });
109
107
  const restNodes = buildAll(
110
108
  folder.children.filter((node2) => !addedNodePaths.has(node2.file.path)),
@@ -131,17 +129,17 @@ function buildFolderNode(folder, isGlobalRoot, ctx) {
131
129
  description: metadata?.description,
132
130
  index,
133
131
  children,
132
+ $id: folder.file.path,
134
133
  $ref: !ctx.options.noRef ? {
135
134
  metaFile: meta?.file.path
136
135
  } : void 0
137
136
  };
138
- return removeUndefined(
139
- ctx.options.attachFolder?.(node, folder, meta) ?? node
140
- );
137
+ return ctx.options.attachFolder?.(node, folder, meta) ?? node;
141
138
  }
142
139
  function buildFileNode(file, ctx) {
143
140
  const localized = findLocalizedFile(file.file.flattenedPath, "page", ctx) ?? file;
144
141
  const item = {
142
+ $id: localized.file.path,
145
143
  type: "page",
146
144
  name: localized.data.data.title ?? pathToName(localized.file.name),
147
145
  icon: ctx.options.resolveIcon?.(localized.data.data.icon),
@@ -150,7 +148,7 @@ function buildFileNode(file, ctx) {
150
148
  file: localized.file.path
151
149
  } : void 0
152
150
  };
153
- return removeUndefined(ctx.options.attachFile?.(item, file) ?? item);
151
+ return ctx.options.attachFile?.(item, file) ?? item;
154
152
  }
155
153
  function build(ctx) {
156
154
  const root = ctx.storage.root();
@@ -331,13 +329,13 @@ function loadFiles(files, options) {
331
329
  function indexPages(storage, getUrl, i18n) {
332
330
  const defaultLanguage = i18n?.defaultLanguage ?? "";
333
331
  const map = /* @__PURE__ */ new Map();
334
- const pages = /* @__PURE__ */ new Map();
335
- const metas = /* @__PURE__ */ new Map();
332
+ const pathToFile = /* @__PURE__ */ new Map();
336
333
  for (const item of storage.list()) {
337
- if (item.format === "meta") metas.set(item.file.path, fileToMeta(item));
334
+ if (item.format === "meta")
335
+ pathToFile.set(item.file.path, fileToMeta(item));
338
336
  if (item.format === "page") {
339
337
  const page = fileToPage(item, getUrl, item.file.locale);
340
- pages.set(item.file.path, page);
338
+ pathToFile.set(item.file.path, page);
341
339
  if (item.file.locale) continue;
342
340
  map.set(`${defaultLanguage}.${page.slugs.join("/")}`, page);
343
341
  if (!i18n) continue;
@@ -353,8 +351,7 @@ function indexPages(storage, getUrl, i18n) {
353
351
  }
354
352
  return {
355
353
  pages: map,
356
- pathToPage: pages,
357
- pathToMeta: metas
354
+ pathToFile
358
355
  };
359
356
  }
360
357
  function createGetUrl(baseUrl, i18n) {
@@ -436,7 +433,7 @@ function createOutput(options) {
436
433
  },
437
434
  getNodeMeta(node) {
438
435
  if (!node.$ref?.metaFile) return;
439
- return walker.pathToMeta.get(node.$ref.metaFile);
436
+ return walker.pathToFile.get(node.$ref.metaFile);
440
437
  },
441
438
  getPageTree(locale) {
442
439
  if (options.i18n) {
@@ -445,8 +442,9 @@ function createOutput(options) {
445
442
  return pageTree;
446
443
  },
447
444
  getNodePage(node) {
448
- if (!node.$ref?.file) return;
449
- return walker.pathToPage.get(node.$ref.file);
445
+ const ref = node.$ref?.file ?? node.$id;
446
+ if (!ref) return;
447
+ return walker.pathToFile.get(ref);
450
448
  },
451
449
  // @ts-expect-error -- ignore this
452
450
  generateParams(slug, lang) {
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  searchAdvanced,
3
3
  searchSimple
4
- } from "./chunk-GIPLMX5F.js";
5
- import "./chunk-DELA6Z2I.js";
4
+ } from "./chunk-WFUH5VBX.js";
5
+ import "./chunk-KAOEMCTI.js";
6
6
  import "./chunk-MLKGABMK.js";
7
7
 
8
8
  // src/search/client/static.ts
@@ -1,24 +1,7 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { ReactNode, DependencyList } from 'react';
3
- import { H as HighlightOptions } from '../shiki-D8ui5x1Y.js';
4
- import { Root } from 'hast';
1
+ export { useShiki } from '../highlight/client.js';
2
+ import 'react';
3
+ import '../highlight/index.js';
5
4
  import 'shiki';
6
5
  import 'shiki/themes';
7
6
  import 'hast-util-to-jsx-runtime';
8
-
9
- declare global {
10
- interface Window {
11
- _use_shiki?: Map<string, Root>;
12
- }
13
- }
14
- declare function useShiki(code: string, { defaultValue, scriptKey, ...options }: HighlightOptions & {
15
- defaultValue?: ReactNode;
16
- scriptKey?: string;
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;
23
-
24
- export { PrerenderScript, useShiki };
7
+ import 'hast';
@@ -1,94 +1,8 @@
1
- "use client";
2
1
  import {
3
- _highlight,
4
- _renderHighlight,
5
- highlight
6
- } from "../chunk-SCQ5QN2V.js";
2
+ useShiki
3
+ } from "../chunk-QWBSUU36.js";
4
+ import "../chunk-E7AASGCN.js";
7
5
  import "../chunk-MLKGABMK.js";
8
-
9
- // src/utils/use-shiki.tsx
10
- import {
11
- use,
12
- useEffect,
13
- useMemo,
14
- useRef,
15
- useState
16
- } from "react";
17
- import { jsx } from "react/jsx-runtime";
18
- var jsEngine;
19
- function getHighlightOptions(from) {
20
- if (from.engine) return from;
21
- if (!jsEngine) {
22
- jsEngine = import("shiki/engine/javascript").then(
23
- (res) => res.createJavaScriptRegexEngine()
24
- );
25
- }
26
- return {
27
- ...from,
28
- engine: jsEngine
29
- };
30
- }
31
- function useShiki(code, {
32
- defaultValue,
33
- scriptKey,
34
- ...options
35
- }, deps) {
36
- const key = useMemo(
37
- () => deps ? JSON.stringify(deps) : `${options.lang}:${code}`,
38
- [code, deps, options.lang]
39
- );
40
- const shikiOptions = getHighlightOptions(options);
41
- const currentTask = useRef({
42
- key,
43
- aborted: false
44
- });
45
- const [rendered, setRendered] = useState(() => {
46
- if (defaultValue) return defaultValue;
47
- const hast = globalThis._use_shiki?.get(scriptKey);
48
- if (hast) {
49
- return _renderHighlight(hast, shikiOptions);
50
- }
51
- currentTask.current = void 0;
52
- const Pre = options.components?.pre ?? "pre";
53
- const Code = options.components?.code ?? "code";
54
- return /* @__PURE__ */ jsx(Pre, { children: /* @__PURE__ */ jsx(Code, { children: code }) });
55
- });
56
- if (typeof window === "undefined") {
57
- return highlight(code, shikiOptions);
58
- }
59
- if (!currentTask.current || currentTask.current.key !== key) {
60
- if (currentTask.current) {
61
- currentTask.current.aborted = true;
62
- }
63
- const task = {
64
- key,
65
- aborted: false
66
- };
67
- currentTask.current = task;
68
- highlight(code, shikiOptions).then((result) => {
69
- if (!task.aborted) setRendered(result);
70
- });
71
- }
72
- return rendered;
73
- }
74
- function PrerenderScript({
75
- scriptKey,
76
- code,
77
- options
78
- }) {
79
- const [mounted, setMounted] = useState(false);
80
- useEffect(() => {
81
- setMounted(true);
82
- }, []);
83
- const tree = typeof window === "undefined" ? use(_highlight(code, getHighlightOptions(options))) : (
84
- // @ts-expect-error -- typed
85
- globalThis._use_shiki?.get(scriptKey)
86
- );
87
- if (mounted || !tree) return null;
88
- return /* @__PURE__ */ jsx("script", { children: `if (typeof globalThis._use_shiki === "undefined") globalThis._use_shiki = new Map()
89
- globalThis._use_shiki.set(${JSON.stringify(scriptKey)}, ${JSON.stringify(tree)})` });
90
- }
91
6
  export {
92
- PrerenderScript,
93
7
  useShiki
94
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "15.0.11",
3
+ "version": "15.0.13",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -75,6 +75,14 @@
75
75
  "./i18n": {
76
76
  "import": "./dist/i18n/index.js",
77
77
  "types": "./dist/i18n/index.d.ts"
78
+ },
79
+ "./highlight": {
80
+ "import": "./dist/highlight/index.js",
81
+ "types": "./dist/highlight/index.d.ts"
82
+ },
83
+ "./highlight/client": {
84
+ "import": "./dist/highlight/client.js",
85
+ "types": "./dist/highlight/client.d.ts"
78
86
  }
79
87
  },
80
88
  "files": [
@@ -1,12 +0,0 @@
1
- // src/utils/remove-undefined.ts
2
- function removeUndefined(value) {
3
- const obj = value;
4
- for (const key of Object.keys(obj)) {
5
- if (obj[key] === void 0) delete obj[key];
6
- }
7
- return value;
8
- }
9
-
10
- export {
11
- removeUndefined
12
- };