fumadocs-core 15.2.8 → 16.0.3

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 (92) hide show
  1. package/README.md +1 -1
  2. package/dist/algolia-IZEDLPHE.js +58 -0
  3. package/dist/breadcrumb.d.ts +7 -5
  4. package/dist/breadcrumb.js +46 -52
  5. package/dist/builder-feW_xVjc.d.ts +296 -0
  6. package/dist/{chunk-FVY6EZ3N.js → chunk-BBP7MIO4.js} +12 -14
  7. package/dist/{chunk-ORHEEQVY.js → chunk-EMWGTXSW.js} +0 -7
  8. package/dist/chunk-FAEPKD7U.js +20 -0
  9. package/dist/{chunk-NNKVN7WA.js → chunk-H2GMUTQG.js} +4 -2
  10. package/dist/chunk-IZPLHEX4.js +113 -0
  11. package/dist/chunk-OTD7MV33.js +53 -0
  12. package/dist/chunk-PFNP6PEB.js +11 -0
  13. package/dist/{chunk-Y2774T3B.js → chunk-QMATWJ5F.js} +6 -7
  14. package/dist/chunk-U67V476Y.js +35 -0
  15. package/dist/{chunk-BUCUQ3WX.js → chunk-XN2LKXFZ.js} +39 -34
  16. package/dist/{chunk-WFUH5VBX.js → chunk-XOFXGHS4.js} +26 -10
  17. package/dist/chunk-XZSI7AHE.js +67 -0
  18. package/dist/chunk-YVVDKJ2H.js +34 -0
  19. package/dist/chunk-ZMWYLUDP.js +21 -0
  20. package/dist/content/github.d.ts +34 -0
  21. package/dist/content/github.js +43 -0
  22. package/dist/content/index.d.ts +16 -0
  23. package/dist/content/index.js +30 -0
  24. package/dist/{get-toc-Cr2URuiP.d.ts → content/toc.d.ts} +6 -10
  25. package/dist/content/toc.js +21 -0
  26. package/dist/{page-tree-BG3wP0gU.d.ts → definitions-BRsJlZ6m.d.ts} +10 -15
  27. package/dist/dynamic-link.js +3 -3
  28. package/dist/fetch-2XFMBLBA.js +22 -0
  29. package/dist/framework/index.d.ts +1 -1
  30. package/dist/framework/index.js +2 -2
  31. package/dist/framework/next.js +2 -2
  32. package/dist/framework/react-router.js +2 -2
  33. package/dist/framework/tanstack.js +2 -2
  34. package/dist/framework/waku.d.ts +8 -0
  35. package/dist/framework/waku.js +51 -0
  36. package/dist/hide-if-empty.d.ts +18 -0
  37. package/dist/hide-if-empty.js +83 -0
  38. package/dist/highlight/client.d.ts +8 -5
  39. package/dist/highlight/client.js +9 -93
  40. package/dist/highlight/index.d.ts +20 -5
  41. package/dist/highlight/index.js +10 -6
  42. package/dist/i18n/index.d.ts +35 -8
  43. package/dist/i18n/index.js +5 -69
  44. package/dist/i18n/middleware.d.ts +12 -0
  45. package/dist/i18n/middleware.js +63 -0
  46. package/dist/link.js +3 -3
  47. package/dist/mdx-plugins/index.d.ts +124 -18
  48. package/dist/mdx-plugins/index.js +605 -203
  49. package/dist/mixedbread-RAHDVXGJ.js +118 -0
  50. package/dist/negotiation/index.d.ts +19 -0
  51. package/dist/negotiation/index.js +11 -0
  52. package/dist/{orama-cloud-USLSOSXS.js → orama-cloud-WEGQE5A6.js} +37 -27
  53. package/dist/page-tree/index.d.ts +32 -0
  54. package/dist/page-tree/index.js +15 -0
  55. package/dist/remark-code-tab-DmyIyi6m.d.ts +57 -0
  56. package/dist/{remark-structure-FIjTA11P.d.ts → remark-structure-DkCXCzpD.d.ts} +13 -2
  57. package/dist/search/algolia.d.ts +9 -7
  58. package/dist/search/algolia.js +31 -17
  59. package/dist/search/client.d.ts +88 -17
  60. package/dist/search/client.js +71 -50
  61. package/dist/search/index.d.ts +26 -0
  62. package/dist/search/index.js +7 -0
  63. package/dist/search/orama-cloud.d.ts +7 -5
  64. package/dist/search/orama-cloud.js +18 -10
  65. package/dist/search/server.d.ts +33 -25
  66. package/dist/search/server.js +109 -47
  67. package/dist/source/index.d.ts +33 -254
  68. package/dist/source/index.js +532 -353
  69. package/dist/source/plugins/lucide-icons.d.ts +14 -0
  70. package/dist/source/plugins/lucide-icons.js +23 -0
  71. package/dist/static-A2YJ5TXV.js +62 -0
  72. package/dist/toc.d.ts +11 -7
  73. package/dist/toc.js +6 -5
  74. package/dist/utils/use-effect-event.d.ts +4 -3
  75. package/dist/utils/use-effect-event.js +9 -6
  76. package/dist/utils/use-media-query.d.ts +3 -0
  77. package/dist/utils/use-media-query.js +23 -0
  78. package/dist/utils/use-on-change.js +2 -2
  79. package/package.json +92 -40
  80. package/dist/algolia-NTWLS6J3.js +0 -49
  81. package/dist/chunk-KAOEMCTI.js +0 -17
  82. package/dist/chunk-MLKGABMK.js +0 -9
  83. package/dist/chunk-XMCPKVJQ.js +0 -34
  84. package/dist/config-inq6kP6y.d.ts +0 -26
  85. package/dist/fetch-W5EHIBOE.js +0 -21
  86. package/dist/remark-heading-BPCoYwjn.d.ts +0 -31
  87. package/dist/server/index.d.ts +0 -117
  88. package/dist/server/index.js +0 -202
  89. package/dist/sidebar.d.ts +0 -33
  90. package/dist/sidebar.js +0 -89
  91. package/dist/static-VESU2S64.js +0 -61
  92. package/dist/types-Ch8gnVgO.d.ts +0 -8
@@ -0,0 +1,30 @@
1
+ import "../chunk-U67V476Y.js";
2
+
3
+ // src/content/index.ts
4
+ import { remark } from "remark";
5
+ import remarkGfm from "remark-gfm";
6
+ import remarkRehype from "remark-rehype";
7
+ import { toJsxRuntime } from "hast-util-to-jsx-runtime";
8
+ import * as JsxRuntime from "react/jsx-runtime";
9
+ function rehypeReact(options = {}) {
10
+ this.compiler = (tree, file) => {
11
+ return toJsxRuntime(tree, {
12
+ development: false,
13
+ filePath: file.path,
14
+ ...JsxRuntime,
15
+ ...options
16
+ });
17
+ };
18
+ }
19
+ async function Markdown({
20
+ children: content,
21
+ remarkPlugins = [],
22
+ rehypePlugins = [],
23
+ ...options
24
+ }) {
25
+ const processor = remark().use(remarkGfm).use(remarkPlugins).use(remarkRehype).use(rehypePlugins).use(rehypeReact, options);
26
+ return (await processor.process(content)).result;
27
+ }
28
+ export {
29
+ Markdown
30
+ };
@@ -1,25 +1,21 @@
1
- import { ReactNode } from 'react';
2
1
  import { PluggableList } from 'unified';
3
2
  import { Compatible } from 'vfile';
3
+ import { TOCItemType } from '../toc.js';
4
+ import 'react';
5
+ import 'react/jsx-runtime';
4
6
 
5
- interface TOCItemType {
6
- title: ReactNode;
7
- url: string;
8
- depth: number;
9
- }
10
- type TableOfContents = TOCItemType[];
11
7
  /**
12
8
  * Get Table of Contents from markdown/mdx document (using remark)
13
9
  *
14
10
  * @param content - Markdown content or file
15
11
  */
16
- declare function getTableOfContents(content: Compatible): TableOfContents;
12
+ declare function getTableOfContents(content: Compatible): TOCItemType[];
17
13
  /**
18
14
  * Get Table of Contents from markdown/mdx document (using remark)
19
15
  *
20
16
  * @param content - Markdown content or file
21
17
  * @param remarkPlugins - remark plugins to be applied first
22
18
  */
23
- declare function getTableOfContents(content: Compatible, remarkPlugins: PluggableList): Promise<TableOfContents>;
19
+ declare function getTableOfContents(content: Compatible, remarkPlugins: PluggableList): Promise<TOCItemType[]>;
24
20
 
25
- export { type TableOfContents as T, type TOCItemType as a, getTableOfContents as g };
21
+ export { getTableOfContents };
@@ -0,0 +1,21 @@
1
+ import {
2
+ remarkHeading
3
+ } from "../chunk-QMATWJ5F.js";
4
+ import "../chunk-U67V476Y.js";
5
+
6
+ // src/content/toc.ts
7
+ import { remark } from "remark";
8
+ function getTableOfContents(content, remarkPlugins) {
9
+ if (remarkPlugins) {
10
+ return remark().use(remarkPlugins).use(remarkHeading).process(content).then((result2) => {
11
+ if ("toc" in result2.data) return result2.data.toc;
12
+ return [];
13
+ });
14
+ }
15
+ const result = remark().use(remarkHeading).processSync(content);
16
+ if ("toc" in result.data) return result.data.toc;
17
+ return [];
18
+ }
19
+ export {
20
+ getTableOfContents
21
+ };
@@ -1,9 +1,13 @@
1
- import { ReactNode, ReactElement } from 'react';
1
+ import { ReactNode } from 'react';
2
2
 
3
3
  interface Root {
4
4
  $id?: string;
5
5
  name: ReactNode;
6
6
  children: Node[];
7
+ /**
8
+ * Another page tree that won't be displayed unless being opened.
9
+ */
10
+ fallback?: Root;
7
11
  }
8
12
  type Node = Item | Separator | Folder;
9
13
  interface Item {
@@ -19,13 +23,13 @@ interface Item {
19
23
  url: string;
20
24
  external?: boolean;
21
25
  description?: ReactNode;
22
- icon?: ReactElement;
26
+ icon?: ReactNode;
23
27
  }
24
28
  interface Separator {
25
29
  $id?: string;
26
30
  type: 'separator';
27
- name: ReactNode;
28
- icon?: ReactElement;
31
+ name?: ReactNode;
32
+ icon?: ReactNode;
29
33
  }
30
34
  interface Folder {
31
35
  $id?: string;
@@ -41,17 +45,8 @@ interface Folder {
41
45
  root?: boolean;
42
46
  defaultOpen?: boolean;
43
47
  index?: Item;
44
- icon?: ReactElement;
48
+ icon?: ReactNode;
45
49
  children: Node[];
46
50
  }
47
51
 
48
- type pageTree_Folder = Folder;
49
- type pageTree_Item = Item;
50
- type pageTree_Node = Node;
51
- type pageTree_Root = Root;
52
- type pageTree_Separator = Separator;
53
- declare namespace pageTree {
54
- export type { pageTree_Folder as Folder, pageTree_Item as Item, pageTree_Node as Node, pageTree_Root as Root, pageTree_Separator as Separator };
55
- }
56
-
57
- export { type Folder as F, type Item as I, type Node as N, type Root as R, type Separator as S, pageTree as p };
52
+ export type { Folder as F, Item as I, Node as N, Root as R, Separator as S };
@@ -1,11 +1,11 @@
1
1
  "use client";
2
2
  import {
3
3
  Link
4
- } from "./chunk-NNKVN7WA.js";
4
+ } from "./chunk-H2GMUTQG.js";
5
5
  import {
6
6
  useParams
7
- } from "./chunk-FVY6EZ3N.js";
8
- import "./chunk-MLKGABMK.js";
7
+ } from "./chunk-BBP7MIO4.js";
8
+ import "./chunk-U67V476Y.js";
9
9
 
10
10
  // src/dynamic-link.tsx
11
11
  import { forwardRef, useMemo } from "react";
@@ -0,0 +1,22 @@
1
+ import "./chunk-U67V476Y.js";
2
+
3
+ // src/search/client/fetch.ts
4
+ var cache = /* @__PURE__ */ new Map();
5
+ async function fetchDocs(query, { api = "/api/search", locale, tag }) {
6
+ const url = new URL(api, window.location.origin);
7
+ url.searchParams.set("query", query);
8
+ if (locale) url.searchParams.set("locale", locale);
9
+ if (tag)
10
+ url.searchParams.set("tag", Array.isArray(tag) ? tag.join(",") : tag);
11
+ const key = `${url.pathname}?${url.searchParams}`;
12
+ const cached = cache.get(key);
13
+ if (cached) return cached;
14
+ const res = await fetch(key);
15
+ if (!res.ok) throw new Error(await res.text());
16
+ const result = await res.json();
17
+ cache.set(key, result);
18
+ return result;
19
+ }
20
+ export {
21
+ fetchDocs
22
+ };
@@ -29,7 +29,7 @@ interface Framework {
29
29
  }>;
30
30
  Image?: FC<ImageProps>;
31
31
  }
32
- declare function FrameworkProvider({ children, ...props }: Framework & {
32
+ declare function FrameworkProvider({ Link, useRouter, useParams, usePathname, Image, children, }: Framework & {
33
33
  children: ReactNode;
34
34
  }): react_jsx_runtime.JSX.Element;
35
35
  declare function usePathname(): string;
@@ -7,8 +7,8 @@ import {
7
7
  useParams,
8
8
  usePathname,
9
9
  useRouter
10
- } from "../chunk-FVY6EZ3N.js";
11
- import "../chunk-MLKGABMK.js";
10
+ } from "../chunk-BBP7MIO4.js";
11
+ import "../chunk-U67V476Y.js";
12
12
  export {
13
13
  FrameworkProvider,
14
14
  Image,
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import {
3
3
  FrameworkProvider
4
- } from "../chunk-FVY6EZ3N.js";
5
- import "../chunk-MLKGABMK.js";
4
+ } from "../chunk-BBP7MIO4.js";
5
+ import "../chunk-U67V476Y.js";
6
6
 
7
7
  // src/framework/next.tsx
8
8
  import { useParams, usePathname, useRouter } from "next/navigation";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FrameworkProvider
3
- } from "../chunk-FVY6EZ3N.js";
4
- import "../chunk-MLKGABMK.js";
3
+ } from "../chunk-BBP7MIO4.js";
4
+ import "../chunk-U67V476Y.js";
5
5
 
6
6
  // src/framework/react-router.tsx
7
7
  import { useMemo } from "react";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  FrameworkProvider
3
- } from "../chunk-FVY6EZ3N.js";
4
- import "../chunk-MLKGABMK.js";
3
+ } from "../chunk-BBP7MIO4.js";
4
+ import "../chunk-U67V476Y.js";
5
5
 
6
6
  // src/framework/tanstack.tsx
7
7
  import { useMemo } from "react";
@@ -0,0 +1,8 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode } from 'react';
3
+
4
+ declare function WakuProvider({ children }: {
5
+ children: ReactNode;
6
+ }): react_jsx_runtime.JSX.Element;
7
+
8
+ export { WakuProvider };
@@ -0,0 +1,51 @@
1
+ "use client";
2
+ import {
3
+ FrameworkProvider
4
+ } from "../chunk-BBP7MIO4.js";
5
+ import "../chunk-U67V476Y.js";
6
+
7
+ // src/framework/waku.tsx
8
+ import { useMemo } from "react";
9
+ import { Link as WakuLink, useRouter } from "waku";
10
+ import { jsx } from "react/jsx-runtime";
11
+ var framework = {
12
+ usePathname() {
13
+ const { path } = useRouter();
14
+ return path;
15
+ },
16
+ useParams() {
17
+ const { query } = useRouter();
18
+ return useMemo(() => {
19
+ const params = new URLSearchParams(query);
20
+ return Object.fromEntries(
21
+ Array.from(params.entries()).map(([key, value]) => [
22
+ key,
23
+ Array.isArray(value) ? value[0] : value
24
+ ])
25
+ );
26
+ }, [query]);
27
+ },
28
+ useRouter() {
29
+ const router = useRouter();
30
+ return useMemo(
31
+ () => ({
32
+ push(url) {
33
+ void router.push(url);
34
+ },
35
+ refresh() {
36
+ void router.push(router.path);
37
+ }
38
+ }),
39
+ [router]
40
+ );
41
+ },
42
+ Link({ href, prefetch: _prefetch, ...props }) {
43
+ return /* @__PURE__ */ jsx(WakuLink, { to: href, ...props, children: props.children });
44
+ }
45
+ };
46
+ function WakuProvider({ children }) {
47
+ return /* @__PURE__ */ jsx(FrameworkProvider, { ...framework, children });
48
+ }
49
+ export {
50
+ WakuProvider
51
+ };
@@ -0,0 +1,18 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { ReactNode, HTMLAttributes, FC } from 'react';
3
+
4
+ declare function HideIfEmptyProvider({ nonce, children, }: {
5
+ nonce?: string;
6
+ children: ReactNode;
7
+ }): react_jsx_runtime.JSX.Element;
8
+ /**
9
+ * The built-in CSS `:empty` selector cannot detect if the children is hidden, classes such as `md:hidden` causes it to fail.
10
+ * This component is an enhancement to `empty:hidden` to fix the issue described above.
11
+ *
12
+ * This can be expensive, please avoid this whenever possible.
13
+ */
14
+ declare function HideIfEmpty<Props extends HTMLAttributes<HTMLElement>>({ as: Comp, ...props }: Props & {
15
+ as: FC<Props>;
16
+ }): react_jsx_runtime.JSX.Element;
17
+
18
+ export { HideIfEmpty, HideIfEmptyProvider };
@@ -0,0 +1,83 @@
1
+ "use client";
2
+ import "./chunk-U67V476Y.js";
3
+
4
+ // src/hide-if-empty.tsx
5
+ import {
6
+ createContext,
7
+ useContext,
8
+ useEffect,
9
+ useId,
10
+ useMemo,
11
+ useState
12
+ } from "react";
13
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
14
+ var Context = createContext({
15
+ nonce: void 0
16
+ });
17
+ function HideIfEmptyProvider({
18
+ nonce,
19
+ children
20
+ }) {
21
+ return /* @__PURE__ */ jsx(Context.Provider, { value: useMemo(() => ({ nonce }), [nonce]), children });
22
+ }
23
+ function getElement(id) {
24
+ return document.querySelector(`[data-fd-if-empty="${id}"]`);
25
+ }
26
+ function isEmpty(node) {
27
+ for (let i = 0; i < node.childNodes.length; i++) {
28
+ const child = node.childNodes.item(i);
29
+ if (child.nodeType === Node.TEXT_NODE || child.nodeType === Node.ELEMENT_NODE && window.getComputedStyle(child).display !== "none") {
30
+ return false;
31
+ }
32
+ }
33
+ return true;
34
+ }
35
+ function HideIfEmpty({
36
+ as: Comp,
37
+ ...props
38
+ }) {
39
+ const id = useId();
40
+ const { nonce } = useContext(Context);
41
+ const [empty, setEmpty] = useState(() => {
42
+ const element = typeof window !== "undefined" ? getElement(id) : null;
43
+ if (element) return isEmpty(element);
44
+ });
45
+ useEffect(() => {
46
+ const handleResize = () => {
47
+ const element = getElement(id);
48
+ if (element) setEmpty(isEmpty(element));
49
+ };
50
+ window.addEventListener("resize", handleResize);
51
+ return () => window.removeEventListener("resize", handleResize);
52
+ }, [id]);
53
+ const init = (id2) => {
54
+ const element = getElement(id2);
55
+ if (element) {
56
+ element.hidden = isEmpty(element);
57
+ }
58
+ };
59
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
60
+ /* @__PURE__ */ jsx(
61
+ Comp,
62
+ {
63
+ ...props,
64
+ "data-fd-if-empty": id,
65
+ hidden: empty ?? false
66
+ }
67
+ ),
68
+ /* @__PURE__ */ jsx(
69
+ "script",
70
+ {
71
+ suppressHydrationWarning: true,
72
+ nonce,
73
+ dangerouslySetInnerHTML: {
74
+ __html: `{${getElement};${isEmpty};(${init})("${id}")}`
75
+ }
76
+ }
77
+ )
78
+ ] });
79
+ }
80
+ export {
81
+ HideIfEmpty,
82
+ HideIfEmptyProvider
83
+ };
@@ -1,12 +1,15 @@
1
- import { ReactNode, DependencyList } from 'react';
1
+ import { DependencyList, ReactNode } from 'react';
2
2
  import { HighlightOptions } from './index.js';
3
3
  import 'shiki';
4
4
  import 'shiki/themes';
5
5
  import 'hast-util-to-jsx-runtime';
6
+ import 'hast';
6
7
 
7
- declare function useShiki(code: string, { defaultValue, withPrerenderScript, ...options }: HighlightOptions & {
8
- withPrerenderScript?: boolean;
9
- defaultValue?: ReactNode;
10
- }, deps?: DependencyList): ReactNode;
8
+ /**
9
+ * get highlighted results, should be used with React Suspense API.
10
+ *
11
+ * note: results are cached with (lang, code) as keys, if this is not the desired behaviour, pass a `deps` instead.
12
+ */
13
+ declare function useShiki(code: string, options: HighlightOptions, deps?: DependencyList): ReactNode;
11
14
 
12
15
  export { useShiki };
@@ -1,101 +1,17 @@
1
1
  "use client";
2
2
  import {
3
- _highlight,
4
- _renderHighlight,
5
3
  highlight
6
- } from "../chunk-BUCUQ3WX.js";
7
- import "../chunk-MLKGABMK.js";
4
+ } from "../chunk-XN2LKXFZ.js";
5
+ import "../chunk-U67V476Y.js";
8
6
 
9
7
  // src/highlight/client.tsx
10
- import {
11
- useId,
12
- useMemo,
13
- useRef,
14
- use,
15
- useState,
16
- useLayoutEffect
17
- } from "react";
18
- import { jsx } from "react/jsx-runtime";
19
- var jsEngine;
20
- function getHighlightOptions(from) {
21
- if (from.engine) return from;
22
- if (!jsEngine) {
23
- jsEngine = import("shiki/engine/javascript").then(
24
- (res) => res.createJavaScriptRegexEngine()
25
- );
26
- }
27
- return {
28
- ...from,
29
- engine: jsEngine
30
- };
31
- }
32
- function useShiki(code, {
33
- defaultValue,
34
- withPrerenderScript = false,
35
- ...options
36
- }, deps) {
37
- const markupId = useId();
38
- const key = useMemo(
39
- () => deps ? JSON.stringify(deps) : `${options.lang}:${code}`,
40
- [code, deps, options.lang]
41
- );
42
- const shikiOptions = getHighlightOptions(options);
43
- const currentTask = useRef({
44
- key,
45
- aborted: false
46
- });
47
- const [rendered, setRendered] = useState(() => {
48
- if (defaultValue) return defaultValue;
49
- const element = withPrerenderScript && typeof document !== "undefined" ? document.querySelector(`[data-markup-id="${markupId}"]`) : null;
50
- const attr = element?.getAttribute("data-markup");
51
- if (attr) {
52
- const hast = JSON.parse(attr);
53
- return renderHighlightWithMarkup(markupId, hast, shikiOptions, attr);
54
- }
55
- currentTask.current = void 0;
56
- const Pre = options.components?.pre ?? "pre";
57
- const Code = options.components?.code ?? "code";
58
- return /* @__PURE__ */ jsx(Pre, { children: /* @__PURE__ */ jsx(Code, { children: code }) });
59
- });
60
- useLayoutEffect(() => {
61
- if (currentTask.current?.key === key) return;
62
- if (currentTask.current) {
63
- currentTask.current.aborted = true;
64
- }
65
- const task = {
66
- key,
67
- aborted: false
68
- };
69
- currentTask.current = task;
70
- void highlight(code, shikiOptions).then((result) => {
71
- if (!task.aborted) setRendered(result);
72
- });
73
- }, [key]);
74
- if (typeof window === "undefined") {
75
- return use(
76
- _highlight(code, shikiOptions).then(
77
- (tree) => renderHighlightWithMarkup(markupId, tree, shikiOptions)
78
- )
79
- );
80
- }
81
- return rendered;
82
- }
83
- function renderHighlightWithMarkup(id, tree, shikiOptions, rawAttr) {
84
- const Pre = shikiOptions.components?.pre ?? "pre";
85
- return _renderHighlight(tree, {
86
- ...shikiOptions,
87
- components: {
88
- ...shikiOptions.components,
89
- pre: (props) => /* @__PURE__ */ jsx(
90
- Pre,
91
- {
92
- ...props,
93
- "data-markup-id": id,
94
- "data-markup": rawAttr ?? JSON.stringify(tree)
95
- }
96
- )
97
- }
98
- });
8
+ import { use, useMemo } from "react";
9
+ var promises = {};
10
+ function useShiki(code, options, deps) {
11
+ const key = useMemo(() => {
12
+ return deps ? JSON.stringify(deps) : `${options.lang}:${code}`;
13
+ }, [code, deps, options.lang]);
14
+ return use(promises[key] ??= highlight(code, options));
99
15
  }
100
16
  export {
101
17
  useShiki
@@ -1,15 +1,30 @@
1
- import { CodeToHastOptionsCommon, BundledLanguage, CodeOptionsMeta, Awaitable, RegexEngine, CodeOptionsThemes, ShikiTransformer } from 'shiki';
1
+ import { CodeToHastOptionsCommon, BundledLanguage, CodeOptionsMeta, CodeOptionsThemes, BundledHighlighterOptions, Highlighter } from 'shiki';
2
2
  import { BundledTheme } from 'shiki/themes';
3
- import { Components } from 'hast-util-to-jsx-runtime';
3
+ import { Components, Options } from 'hast-util-to-jsx-runtime';
4
4
  import { ReactNode } from 'react';
5
+ import { Root } from 'hast';
5
6
 
6
- declare function createStyleTransformer(): ShikiTransformer;
7
7
  type HighlightOptionsCommon = CodeToHastOptionsCommon<BundledLanguage> & CodeOptionsMeta & {
8
- engine?: Awaitable<RegexEngine>;
8
+ /**
9
+ * The Regex Engine for Shiki
10
+ *
11
+ * @defaultValue 'js'
12
+ */
13
+ engine?: 'js' | 'oniguruma';
9
14
  components?: Partial<Components>;
15
+ fallbackLanguage?: BundledLanguage;
10
16
  };
11
17
  type HighlightOptionsThemes = CodeOptionsThemes<BundledTheme>;
12
18
  type HighlightOptions = HighlightOptionsCommon & (HighlightOptionsThemes | Record<never, never>);
19
+ declare function highlightHast(code: string, options: HighlightOptions): Promise<Root>;
20
+ declare function hastToJsx(hast: Root, options?: Partial<Options>): JSX.Element;
21
+ /**
22
+ * Get Shiki highlighter instance of Fumadocs (mostly for internal use, you should use Shiki directly over this).
23
+ *
24
+ * @param engineType - Shiki Regex engine to use.
25
+ * @param options - Shiki options.
26
+ */
27
+ declare function getHighlighter(engineType: 'js' | 'oniguruma', options: Omit<BundledHighlighterOptions<BundledLanguage, BundledTheme>, 'engine'>): Promise<Highlighter>;
13
28
  declare function highlight(code: string, options: HighlightOptions): Promise<ReactNode>;
14
29
 
15
- export { type HighlightOptions, type HighlightOptionsCommon, type HighlightOptionsThemes, createStyleTransformer, highlight };
30
+ export { type HighlightOptions, type HighlightOptionsCommon, type HighlightOptionsThemes, getHighlighter, hastToJsx, highlight, highlightHast };
@@ -1,9 +1,13 @@
1
1
  import {
2
- createStyleTransformer,
3
- highlight
4
- } from "../chunk-BUCUQ3WX.js";
5
- import "../chunk-MLKGABMK.js";
2
+ getHighlighter,
3
+ hastToJsx,
4
+ highlight,
5
+ highlightHast
6
+ } from "../chunk-XN2LKXFZ.js";
7
+ import "../chunk-U67V476Y.js";
6
8
  export {
7
- createStyleTransformer,
8
- highlight
9
+ getHighlighter,
10
+ hastToJsx,
11
+ highlight,
12
+ highlightHast
9
13
  };
@@ -1,12 +1,39 @@
1
- import { I as I18nConfig } from '../config-inq6kP6y.js';
2
- import { NextMiddleware } from 'next/dist/server/web/types';
3
-
4
- interface MiddlewareOptions extends I18nConfig {
1
+ interface I18nConfig<Languages extends string = string> {
2
+ /**
3
+ * Supported locale codes.
4
+ *
5
+ * A page tree will be built for each language.
6
+ */
7
+ languages: Languages[];
8
+ /**
9
+ * Default locale if not specified
10
+ */
11
+ defaultLanguage: Languages;
12
+ /**
13
+ * Don't show the locale prefix on URL.
14
+ *
15
+ * - `always`: Always hide the prefix
16
+ * - `default-locale`: Only hide the default locale
17
+ * - `never`: Never hide the prefix
18
+ *
19
+ * This API uses `NextResponse.rewrite`.
20
+ *
21
+ * @defaultValue 'never'
22
+ */
23
+ hideLocale?: 'always' | 'default-locale' | 'never';
24
+ /**
25
+ * Used by `loader()`, specify the way to parse i18n file structure.
26
+ *
27
+ * @defaultValue 'dot'
28
+ */
29
+ parser?: 'dot' | 'dir' | 'none';
5
30
  /**
6
- * A function that adds the locale prefix to path name
31
+ * the fallback language when the page has no translations available for a given locale.
32
+ *
33
+ * Default to ``defaultLanguage`, no fallback when set to `null`.
7
34
  */
8
- format?: (locale: string, path: string) => string;
35
+ fallbackLanguage?: Languages | null;
9
36
  }
10
- declare function createI18nMiddleware({ languages, defaultLanguage, format, hideLocale, }: MiddlewareOptions): NextMiddleware;
37
+ declare function defineI18n<Languages extends string>(config: I18nConfig<Languages>): I18nConfig<Languages>;
11
38
 
12
- export { I18nConfig, createI18nMiddleware };
39
+ export { type I18nConfig, defineI18n };