fumadocs-core 16.17.10 → 16.18.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.
Files changed (51) hide show
  1. package/dist/{algolia-DnAe2syq.d.ts → algolia-B36wJl6E.d.ts} +1 -1
  2. package/dist/{client-DnKr8e39.d.ts → client-LE_6Q0xR.d.ts} +2 -2
  3. package/dist/content/mdx/preset-bundler.d.ts +2 -2
  4. package/dist/content/mdx/preset-runtime.d.ts +2 -2
  5. package/dist/content/toc.d.ts +1 -1
  6. package/dist/framework/plugin.d.ts +69 -0
  7. package/dist/framework/plugin.js +1 -0
  8. package/dist/i18n/index.d.ts +1 -1
  9. package/dist/i18n/index.js +1 -1
  10. package/dist/i18n/middleware.d.ts +1 -1
  11. package/dist/{index-C0yDf9A2.d.ts → index-BFnMPJLk.d.ts} +1 -1
  12. package/dist/{index-BIhpw5_j.d.ts → index-DFrWGSeW.d.ts} +3 -5
  13. package/dist/{index-DAbFAfHX.d.ts → index-DWVer6sb.d.ts} +4 -3
  14. package/dist/mcp.d.ts +2 -2
  15. package/dist/mdx-plugins/index.d.ts +2 -2
  16. package/dist/mdx-plugins/remark-heading.d.ts +1 -1
  17. package/dist/{meilisearch-DLgT0_3G.d.ts → meilisearch-CsyDr1xA.d.ts} +1 -1
  18. package/dist/{mixedbread-DWeuz1Xb.d.ts → mixedbread-CyM4na_-.d.ts} +2 -2
  19. package/dist/{remark-heading-Dr13q5Om.d.ts → remark-heading-Dhiig5Fv.d.ts} +1 -1
  20. package/dist/search/algolia.d.ts +1 -1
  21. package/dist/search/client/algolia.d.ts +1 -1
  22. package/dist/search/client/docs-search.d.ts +1 -1
  23. package/dist/search/client/fetch.d.ts +1 -1
  24. package/dist/search/client/flexsearch-static.d.ts +1 -1
  25. package/dist/search/client/flexsearch-static.js +2 -2
  26. package/dist/search/client/meilisearch.d.ts +1 -1
  27. package/dist/search/client/mixedbread.d.ts +2 -2
  28. package/dist/search/client/orama-cloud-legacy.d.ts +1 -1
  29. package/dist/search/client/orama-cloud.d.ts +1 -1
  30. package/dist/search/client/orama-static.d.ts +1 -1
  31. package/dist/search/client.d.ts +1 -1
  32. package/dist/search/flexsearch.d.ts +3 -3
  33. package/dist/search/flexsearch.js +6 -5
  34. package/dist/search/meilisearch.d.ts +1 -1
  35. package/dist/search/mixedbread.d.ts +2 -2
  36. package/dist/search/orama-cloud-legacy.d.ts +1 -1
  37. package/dist/search/orama-cloud.d.ts +2 -2
  38. package/dist/search/server.d.ts +1 -1
  39. package/dist/{server-k8QJZEib.d.ts → server-BUYLz3H4.d.ts} +2 -2
  40. package/dist/source/dynamic.d.ts +1 -1
  41. package/dist/source/index.d.ts +1 -1
  42. package/dist/source/llms.d.ts +1 -1
  43. package/dist/source/llms.js +1 -1
  44. package/dist/source/plugins/lucide-icons.d.ts +1 -1
  45. package/dist/source/plugins/slugs.d.ts +1 -1
  46. package/dist/source/plugins/status-badges.d.ts +1 -1
  47. package/dist/{toc-BPaCQkFr.d.ts → toc-BuHOTlzj.d.ts} +2 -2
  48. package/dist/toc.d.ts +1 -1
  49. package/dist/toc.js +50 -49
  50. package/dist/{utils-BYuB2fyY.js → utils-BQW8csGG.js} +14 -6
  51. package/package.json +2 -1
@@ -1,6 +1,6 @@
1
1
  import { t as Awaitable } from "./types-Dvkw0Kd0.js";
2
2
  import { n as StructuredData } from "./remark-structure-50nmY6sX.js";
3
- import { S as LoaderOutput, b as LoaderConfig } from "./index-DAbFAfHX.js";
3
+ import { S as LoaderOutput, b as LoaderConfig } from "./index-DWVer6sb.js";
4
4
  import { Algoliasearch } from "algoliasearch";
5
5
  interface DocumentRecord {
6
6
  /**
@@ -1,7 +1,7 @@
1
1
  import { t as Awaitable } from "./types-Dvkw0Kd0.js";
2
2
  import { r as SortedResult } from "./index-CE1OSGGq.js";
3
- import { t as BaseIndex } from "./algolia-DnAe2syq.js";
4
- import "./mixedbread-DWeuz1Xb.js";
3
+ import { t as BaseIndex } from "./algolia-B36wJl6E.js";
4
+ import "./mixedbread-CyM4na_-.js";
5
5
  import { DependencyList } from "react";
6
6
  import { AnyZBSearch, SearchParams } from "zbsearch";
7
7
  import { Root } from "hast";
@@ -1,10 +1,10 @@
1
1
  import { t as RehypeCodeOptions } from "../../rehype-code-CPNaiqAY.js";
2
2
  import { t as RemarkImageOptions } from "../../remark-image-BwyGdFld.js";
3
3
  import { t as StructureOptions } from "../../remark-structure-50nmY6sX.js";
4
- import { t as RemarkHeadingOptions } from "../../remark-heading-Dr13q5Om.js";
4
+ import { t as RemarkHeadingOptions } from "../../remark-heading-Dhiig5Fv.js";
5
5
  import { t as RemarkCodeTabOptions } from "../../remark-code-tab-Dj_--R3y.js";
6
6
  import { t as RemarkNpmOptions } from "../../remark-npm-IH35Vls_.js";
7
- import "../../index-C0yDf9A2.js";
7
+ import "../../index-BFnMPJLk.js";
8
8
  import { t as ResolvePlugins } from "../../util-YfkucgkA.js";
9
9
  import { Pluggable } from "unified";
10
10
  import { ProcessorOptions } from "@mdx-js/mdx";
@@ -1,10 +1,10 @@
1
1
  import { t as RehypeCodeOptions } from "../../rehype-code-CPNaiqAY.js";
2
2
  import { t as RemarkImageOptions } from "../../remark-image-BwyGdFld.js";
3
3
  import { t as StructureOptions } from "../../remark-structure-50nmY6sX.js";
4
- import { t as RemarkHeadingOptions } from "../../remark-heading-Dr13q5Om.js";
4
+ import { t as RemarkHeadingOptions } from "../../remark-heading-Dhiig5Fv.js";
5
5
  import { t as RemarkCodeTabOptions } from "../../remark-code-tab-Dj_--R3y.js";
6
6
  import { t as RemarkNpmOptions } from "../../remark-npm-IH35Vls_.js";
7
- import "../../index-C0yDf9A2.js";
7
+ import "../../index-BFnMPJLk.js";
8
8
  import { t as ResolvePlugins } from "../../util-YfkucgkA.js";
9
9
  import { ProcessorOptions } from "@mdx-js/mdx";
10
10
  export type MDXRuntimePresetOptions = Omit<NonNullable<ProcessorOptions>, 'rehypePlugins' | 'remarkPlugins'> & {
@@ -1,4 +1,4 @@
1
- import { c as TOCItemType } from "../toc-BPaCQkFr.js";
1
+ import { c as TOCItemType } from "../toc-BuHOTlzj.js";
2
2
  import { Compatible } from "vfile";
3
3
  import { PluggableList } from "unified";
4
4
  /**
@@ -0,0 +1,69 @@
1
+ import { n as StructuredData } from "../remark-structure-50nmY6sX.js";
2
+ import { c as TOCItemType } from "../toc-BuHOTlzj.js";
3
+ import { i as TranslationExtension } from "../index-DFrWGSeW.js";
4
+ import { S as LoaderOutput, b as LoaderConfig, w as LoaderPluginOption, x as LoaderOptions } from "../index-DWVer6sb.js";
5
+ import { ReactNode } from "react";
6
+ type Awaitable<T> = T | Promise<T>;
7
+ /** the site, `this` in plugin hooks; frameworks extend it */
8
+ export interface PluginContext<out Config extends LoaderConfig = LoaderConfig> {
9
+ /** prefix `pathname` with the base path of the site, a route of `path` is served at `withBase(path)` */
10
+ withBase(pathname: string): string;
11
+ /** the content loader, created from the results of `configureLoader` */
12
+ getLoader(): Awaitable<LoaderOutput<Config>>;
13
+ }
14
+ /** options of the content loader, with `plugins` as an array */
15
+ export interface PluginLoaderOptions extends Omit<LoaderOptions, 'plugins'> {
16
+ plugins?: LoaderPluginOption[];
17
+ }
18
+ /** what plugins create in `routes`; frameworks extend it */
19
+ export interface RouteFns {
20
+ createApi(route: ApiRoute): void;
21
+ }
22
+ /**
23
+ * A plugin of a framework: the routes and content hooks of an integration like OpenAPI, written once for every framework.
24
+ *
25
+ * Hooks run with the site as `this`, in the order of the framework, and combine in one of three ways:
26
+ *
27
+ * - contribute (`configureLoader`): each plugin receives the options of the site, frameworks merge the fields each result changes.
28
+ * - resolve (`getPage*`): the first plugin returning a value other than `undefined` wins.
29
+ * - collect (`routes`): what every plugin creates, in order.
30
+ *
31
+ * Frameworks run every hook, with their site as `Context`, and may extend the contract with their own.
32
+ *
33
+ * Hooks are properties, so their `this` and page are checked strictly: a plugin for any site fits every site, not the other way round.
34
+ */
35
+ export interface Plugin<in Config extends LoaderConfig = LoaderConfig, in Context extends PluginContext<Config> = PluginContext<Config>, in Routes extends RouteFns = RouteFns> {
36
+ name?: string;
37
+ /** UI translations of the plugin */
38
+ translations?: TranslationExtension;
39
+ /**
40
+ * Contribute options to the content loader, given the options of the site.
41
+ *
42
+ * Frameworks collect the `plugins` of every result, other options have one writer.
43
+ */
44
+ configureLoader?: (this: Context, options: Readonly<PluginLoaderOptions>) => Awaitable<Partial<PluginLoaderOptions> | undefined>;
45
+ /** the rendered content of a page, implemented by content sources */
46
+ getPageBody?: (this: Context, page: Config['page']) => Awaitable<PageBody | undefined>;
47
+ /** the Markdown of a page, for LLMs */
48
+ getPageText?: (this: Context, page: Config['page']) => Awaitable<string | undefined>;
49
+ getPageToc?: (this: Context, page: Config['page']) => Awaitable<TOCItemType[] | undefined>;
50
+ /** the text of a page for search indexes */
51
+ getPageStructuredData?: (this: Context, page: Config['page']) => Awaitable<StructuredData | undefined>;
52
+ getPageCreatedAt?: (this: Context, page: Config['page']) => Awaitable<Date | undefined>;
53
+ getPageLastModified?: (this: Context, page: Config['page']) => Awaitable<Date | undefined>;
54
+ /** create the routes of the plugin */
55
+ routes?: (this: Context, fns: Routes) => Awaitable<void>;
56
+ }
57
+ /** the rendered content of a page */
58
+ export interface PageBody {
59
+ node: ReactNode;
60
+ }
61
+ export type Method = 'GET' | 'HEAD' | 'POST' | 'PUT' | 'PATCH' | 'DELETE' | 'OPTIONS';
62
+ /** a web-standard handler */
63
+ export type RouteHandler = (request: Request) => Awaitable<Response>;
64
+ /** a route handled on the server, its handlers are named by method, `ALL` handles every method */
65
+ export interface ApiRoute extends Partial<Record<Method | 'ALL', RouteHandler>> {
66
+ /** the pathname without the base path, like `/api/proxy` */
67
+ path: string;
68
+ }
69
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,2 +1,2 @@
1
- import { a as TranslationPreset, c as defineTranslations, i as TranslationExtension, n as I18nConfig, o as TranslationsAPI, r as SingularTranslationsAPI, s as defineI18n, t as I18nAPI } from "../index-BIhpw5_j.js";
1
+ import { a as TranslationPreset, c as defineTranslations, i as TranslationExtension, n as I18nConfig, o as TranslationsAPI, r as SingularTranslationsAPI, s as defineI18n, t as I18nAPI } from "../index-DFrWGSeW.js";
2
2
  export { I18nAPI, I18nConfig, SingularTranslationsAPI, TranslationExtension, TranslationPreset, TranslationsAPI, defineI18n, defineTranslations };
@@ -29,7 +29,7 @@ function defineI18n(config) {
29
29
  return this;
30
30
  },
31
31
  preset(lang, preset) {
32
- Object.assign(translations[lang], preset.value);
32
+ Object.assign(translations[lang] ??= {}, preset.value);
33
33
  return this;
34
34
  }
35
35
  };
@@ -1,4 +1,4 @@
1
- import { n as I18nConfig } from "../index-BIhpw5_j.js";
1
+ import { n as I18nConfig } from "../index-DFrWGSeW.js";
2
2
  import { NextProxy } from "next/server";
3
3
  import { NextURL } from "next/dist/server/web/next-url";
4
4
  interface MiddlewareOptions extends I18nConfig {
@@ -3,7 +3,7 @@ import "./rehype-code-CPNaiqAY.js";
3
3
  import "./remark-image-BwyGdFld.js";
4
4
  import "./remark-include-D_FmDdtI.js";
5
5
  import "./remark-structure-50nmY6sX.js";
6
- import "./remark-heading-Dr13q5Om.js";
6
+ import "./remark-heading-Dhiig5Fv.js";
7
7
  import "./remark-admonition-BxacgP6i.js";
8
8
  import "./remark-directive-admonition-BT_PH6hL.js";
9
9
  import "./rehype-toc-BBnmTg-x.js";
@@ -47,10 +47,8 @@ interface TranslationsAPI<Languages extends string = string, Keys extends string
47
47
  /** for type inference only, always `undefined` in runtime */
48
48
  $inferKeys: Keys;
49
49
  config: I18nConfig<Languages>;
50
- get: {
51
- (lang: Languages): Partial<Record<Keys, string>>;
52
- (lang: string): Partial<Record<Keys, string>> | undefined;
53
- };
50
+ get(lang: Languages): Partial<Record<Keys, string>>;
51
+ get(lang: string): Partial<Record<Keys, string>> | undefined;
54
52
  /** register allowed translation keys */
55
53
  extend<const NewKeys extends string>(extension: TranslationExtension<NewKeys>): TranslationsAPI<Languages, Keys | NewKeys>;
56
54
  /** add translations */
@@ -61,7 +59,7 @@ interface TranslationsAPI<Languages extends string = string, Keys extends string
61
59
  [key: string]: string;
62
60
  }; }): TranslationsAPI<Languages, Keys>;
63
61
  /** add language pack */
64
- preset: (lang: Languages, preset: TranslationPreset<Keys>) => TranslationsAPI<Languages, Keys>;
62
+ preset(lang: Languages, preset: TranslationPreset<Keys>): TranslationsAPI<Languages, Keys>;
65
63
  }
66
64
  interface I18nAPI<Languages extends string = string> extends I18nConfig<Languages> {
67
65
  translations: () => TranslationsAPI<Languages, never>;
@@ -1,8 +1,8 @@
1
1
  import { a as Separator, i as Root, n as Item, r as Node, t as Folder } from "./definitions-BQVehOBz.js";
2
2
  import { t as Awaitable } from "./types-Dvkw0Kd0.js";
3
3
  import { n as StructuredData } from "./remark-structure-50nmY6sX.js";
4
- import "./index-C0yDf9A2.js";
5
- import { n as I18nConfig } from "./index-BIhpw5_j.js";
4
+ import "./index-BFnMPJLk.js";
5
+ import { n as I18nConfig } from "./index-DFrWGSeW.js";
6
6
  import "./index-DMxrC6WS.js";
7
7
  import { n as SerializedPageTree } from "./index-B2EN5xn0.js";
8
8
  import { ReactNode } from "react";
@@ -215,7 +215,7 @@ interface LoaderOutput<Config extends LoaderConfig = LoaderConfig> {
215
215
  *
216
216
  * - relative file paths, like `./my/page.mdx`.
217
217
  */
218
- resolveHref: (href: string, parent: Config['page']) => string;
218
+ resolveHref(href: string, parent: Config['page']): string;
219
219
  /**
220
220
  * @internal
221
221
  */
@@ -491,6 +491,7 @@ interface LLMsConfig<Page = unknown> {
491
491
  TAB?: string;
492
492
  renderName?: (item: Node | Root, ctx: Context) => string;
493
493
  renderDescription?: (item: Root | Item | Folder, ctx: Context) => string;
494
+ renderUrl?: (item: Item, ctx: Context) => string;
494
495
  /**
495
496
  * Render a page as Markdown, required by `page()` and `full()`.
496
497
  */
package/dist/mcp.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { t as Awaitable } from "./types-Dvkw0Kd0.js";
2
- import { r as SearchServer } from "./server-k8QJZEib.js";
3
- import { S as LoaderOutput, b as LoaderConfig, r as LLMsWithPages } from "./index-DAbFAfHX.js";
2
+ import { S as LoaderOutput, b as LoaderConfig, r as LLMsWithPages } from "./index-DWVer6sb.js";
3
+ import { r as SearchServer } from "./server-BUYLz3H4.js";
4
4
  import { McpServer } from "@modelcontextprotocol/server";
5
5
  /**
6
6
  * Register a `search` tool, backed by a search server from `fumadocs-core/search/server`.
@@ -5,7 +5,7 @@ import { n as rehypeCode, r as rehypeCodeDefaultOptions, t as RehypeCodeOptions
5
5
  import { n as remarkImage, t as RemarkImageOptions } from "../remark-image-BwyGdFld.js";
6
6
  import { n as extractCodeRegion, r as remarkInclude, t as RemarkIncludeOptions } from "../remark-include-D_FmDdtI.js";
7
7
  import { a as remarkStructureDefaultOptions, i as remarkStructure, n as StructuredData, o as structure, r as StructuredDataContent, t as StructureOptions } from "../remark-structure-50nmY6sX.js";
8
- import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-Dr13q5Om.js";
8
+ import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-Dhiig5Fv.js";
9
9
  import { n as remarkAdmonition, t as RemarkAdmonitionOptions } from "../remark-admonition-BxacgP6i.js";
10
10
  import { n as remarkDirectiveAdmonition, t as RemarkDirectiveAdmonitionOptions } from "../remark-directive-admonition-BT_PH6hL.js";
11
11
  import { n as RehypeTocOptions, r as rehypeToc, t as RehypeTOCItemType } from "../rehype-toc-BBnmTg-x.js";
@@ -17,5 +17,5 @@ import { a as remarkMdxFiles, r as RemarkMdxFilesOptions } from "../remark-mdx-f
17
17
  import { n as remarkMdxMermaid, t as RemarkMdxMermaidOptions } from "../remark-mdx-mermaid-BrK4YVTJ.js";
18
18
  import { n as RemarkFeedbackBlockOptions, r as remarkFeedbackBlock, t as FeedbackBlockProps } from "../remark-feedback-block-2Ei4IDr4.js";
19
19
  import { t as LLMsOptions } from "../remark-llms-eA0WMw4X.js";
20
- import "../index-C0yDf9A2.js";
20
+ import "../index-BFnMPJLk.js";
21
21
  export { CodeBlockAttributes, type CodeBlockIcon, CodeBlockTabsOptions, FeedbackBlockProps, type LLMsOptions, RehypeCodeOptions, RehypeTOCItemType, RehypeTocOptions, RemarkAdmonitionOptions, RemarkCodeTabOptions, RemarkDirectiveAdmonitionOptions, RemarkFeedbackBlockOptions, type RemarkGfmOptions, RemarkHeadingOptions, RemarkImageOptions, RemarkIncludeOptions, type RemarkMdxFilesOptions, RemarkMdxMermaidOptions, RemarkNpmOptions, RemarkStepsOptions, StructureOptions, StructuredData, StructuredDataContent, extractCodeRegion, generateCodeBlockTabs, parseCodeBlockAttributes, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkCodeTab, remarkDirectiveAdmonition, remarkFeedbackBlock, remarkGfm, remarkHeading, remarkImage, remarkInclude, remarkMdxFiles, remarkMdxMermaid, remarkNpm, remarkSteps, remarkStructure, remarkStructureDefaultOptions, structure, transformerIcon, transformerTab };
@@ -1,2 +1,2 @@
1
- import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-Dr13q5Om.js";
1
+ import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-Dhiig5Fv.js";
2
2
  export { RemarkHeadingOptions, remarkHeading };
@@ -1,6 +1,6 @@
1
1
  import { t as Awaitable } from "./types-Dvkw0Kd0.js";
2
2
  import { n as StructuredData } from "./remark-structure-50nmY6sX.js";
3
- import { S as LoaderOutput, b as LoaderConfig } from "./index-DAbFAfHX.js";
3
+ import { S as LoaderOutput, b as LoaderConfig } from "./index-DWVer6sb.js";
4
4
  import { Meilisearch } from "meilisearch";
5
5
  interface DocumentRecord {
6
6
  title: string;
@@ -1,6 +1,6 @@
1
- import { n as SearchAPI } from "./server-k8QJZEib.js";
1
+ import { n as SearchAPI } from "./server-BUYLz3H4.js";
2
2
  import { r as SortedResult } from "./index-CE1OSGGq.js";
3
- import { t as DocumentRecord } from "./meilisearch-DLgT0_3G.js";
3
+ import { t as DocumentRecord } from "./meilisearch-CsyDr1xA.js";
4
4
  import Mixedbread from "@mixedbread/sdk";
5
5
  import { ScoredTextInputChunk } from "@mixedbread/sdk/resources/stores";
6
6
  /**
@@ -1,4 +1,4 @@
1
- import { c as TOCItemType } from "./toc-BPaCQkFr.js";
1
+ import { c as TOCItemType } from "./toc-BuHOTlzj.js";
2
2
  import { Transformer } from "unified";
3
3
  import { Heading, Root } from "mdast";
4
4
  interface RemarkHeadingOptions {
@@ -1,2 +1,2 @@
1
- import { a as sync, i as setIndexSettings, n as DocumentRecord, o as toDocuments, r as SyncOptions, s as updateDocuments, t as BaseIndex } from "../algolia-DnAe2syq.js";
1
+ import { a as sync, i as setIndexSettings, n as DocumentRecord, o as toDocuments, r as SyncOptions, s as updateDocuments, t as BaseIndex } from "../algolia-B36wJl6E.js";
2
2
  export { BaseIndex, DocumentRecord, SyncOptions, setIndexSettings, sync, toDocuments, updateDocuments };
@@ -1,2 +1,2 @@
1
- import { b as useAlgoliaSearch, v as AlgoliaOptions, y as algoliaClient } from "../../client-DnKr8e39.js";
1
+ import { b as useAlgoliaSearch, v as AlgoliaOptions, y as algoliaClient } from "../../client-LE_6Q0xR.js";
2
2
  export { AlgoliaOptions, algoliaClient, useAlgoliaSearch };
@@ -1,2 +1,2 @@
1
- import { n as SearchClient, r as useDocsSearch, t as ClientPreset } from "../../client-DnKr8e39.js";
1
+ import { n as SearchClient, r as useDocsSearch, t as ClientPreset } from "../../client-LE_6Q0xR.js";
2
2
  export { ClientPreset, SearchClient, useDocsSearch };
@@ -1,2 +1,2 @@
1
- import { D as useFetchSearch, E as fetchClient, T as FetchOptions } from "../../client-DnKr8e39.js";
1
+ import { D as useFetchSearch, E as fetchClient, T as FetchOptions } from "../../client-LE_6Q0xR.js";
2
2
  export { FetchOptions, fetchClient, useFetchSearch };
@@ -1,2 +1,2 @@
1
- import { a as flexsearchStaticClient, i as FlexsearchStaticOptions, o as useFlexsearchStatic } from "../../client-DnKr8e39.js";
1
+ import { a as flexsearchStaticClient, i as FlexsearchStaticOptions, o as useFlexsearchStatic } from "../../client-LE_6Q0xR.js";
2
2
  export { FlexsearchStaticOptions, flexsearchStaticClient, useFlexsearchStatic };
@@ -1,12 +1,12 @@
1
1
  import { n as join, t as BASE_PATH } from "../../url-BF81yL4m.js";
2
2
  import { n as useSearch } from "../../use-search-eSAjMJVB.js";
3
- import { n as search, t as createDocument } from "../../utils-BYuB2fyY.js";
3
+ import { n as search, r as toSearchIndex, t as createDocument } from "../../utils-BQW8csGG.js";
4
4
  import { useCallback } from "react";
5
5
  // src/search/client/flexsearch-static.ts
6
6
  function initDocument(data) {
7
7
  const document = createDocument();
8
8
  for (const [k, v] of Object.entries(data)) document.import(k, v);
9
- return document;
9
+ return toSearchIndex(document);
10
10
  }
11
11
  const cacheMap = /* @__PURE__ */ new Map();
12
12
  async function searchFlexsearchStatic({ from = join(BASE_PATH, "/api/search"), locale = "", tag }, query) {
@@ -1,2 +1,2 @@
1
- import { f as MeilisearchOptions, m as useMeilisearch, p as meilisearchClient } from "../../client-DnKr8e39.js";
1
+ import { f as MeilisearchOptions, m as useMeilisearch, p as meilisearchClient } from "../../client-LE_6Q0xR.js";
2
2
  export { MeilisearchOptions, meilisearchClient, useMeilisearch };
@@ -1,3 +1,3 @@
1
- import { c as mixedbreadClient, s as MixedbreadOptions } from "../../client-DnKr8e39.js";
2
- import { n as SearchMetadata } from "../../mixedbread-DWeuz1Xb.js";
1
+ import { c as mixedbreadClient, s as MixedbreadOptions } from "../../client-LE_6Q0xR.js";
2
+ import { n as SearchMetadata } from "../../mixedbread-CyM4na_-.js";
3
3
  export { MixedbreadOptions, type SearchMetadata, mixedbreadClient };
@@ -1,2 +1,2 @@
1
- import { d as useOramaCloudLegacySearch, l as OramaCloudLegacyOptions, u as oramaCloudLegacyClient } from "../../client-DnKr8e39.js";
1
+ import { d as useOramaCloudLegacySearch, l as OramaCloudLegacyOptions, u as oramaCloudLegacyClient } from "../../client-LE_6Q0xR.js";
2
2
  export { OramaCloudLegacyOptions, oramaCloudLegacyClient, useOramaCloudLegacySearch };
@@ -1,2 +1,2 @@
1
- import { _ as useOramaCloudSearch, g as oramaCloudClient, h as OramaCloudOptions } from "../../client-DnKr8e39.js";
1
+ import { _ as useOramaCloudSearch, g as oramaCloudClient, h as OramaCloudOptions } from "../../client-LE_6Q0xR.js";
2
2
  export { OramaCloudOptions, oramaCloudClient, useOramaCloudSearch };
@@ -1,2 +1,2 @@
1
- import { C as staticClient, S as oramaStaticClient, w as useStaticSearch, x as StaticOptions } from "../../client-DnKr8e39.js";
1
+ import { C as staticClient, S as oramaStaticClient, w as useStaticSearch, x as StaticOptions } from "../../client-LE_6Q0xR.js";
2
2
  export { StaticOptions, oramaStaticClient, staticClient, useStaticSearch };
@@ -1,2 +1,2 @@
1
- import { A as SearchResultRecord, D as useFetchSearch, F as useSearch, M as UseSearchOptions, N as UseSearchReturn, O as SearchResult, P as useHighlightQuery, T as FetchOptions, _ as useOramaCloudSearch, b as useAlgoliaSearch, f as MeilisearchOptions, h as OramaCloudOptions, j as SearchResultTable, k as SearchResultItem, m as useMeilisearch, n as SearchClient, r as useDocsSearch, t as ClientPreset, v as AlgoliaOptions, w as useStaticSearch, x as StaticOptions } from "../client-DnKr8e39.js";
1
+ import { A as SearchResultRecord, D as useFetchSearch, F as useSearch, M as UseSearchOptions, N as UseSearchReturn, O as SearchResult, P as useHighlightQuery, T as FetchOptions, _ as useOramaCloudSearch, b as useAlgoliaSearch, f as MeilisearchOptions, h as OramaCloudOptions, j as SearchResultTable, k as SearchResultItem, m as useMeilisearch, n as SearchClient, r as useDocsSearch, t as ClientPreset, v as AlgoliaOptions, w as useStaticSearch, x as StaticOptions } from "../client-LE_6Q0xR.js";
2
2
  export { type AlgoliaOptions, type ClientPreset, type FetchOptions, type MeilisearchOptions, type OramaCloudOptions, type SearchClient, type SearchResult, type SearchResultItem, type SearchResultRecord, type SearchResultTable, type StaticOptions, type UseSearchOptions, type UseSearchReturn, useSearch as experimental_useSearch, useAlgoliaSearch, useDocsSearch, useFetchSearch, useHighlightQuery, useMeilisearch, useOramaCloudSearch, useStaticSearch };
@@ -1,7 +1,7 @@
1
1
  import { t as Awaitable } from "../types-Dvkw0Kd0.js";
2
- import { n as I18nConfig } from "../index-BIhpw5_j.js";
3
- import { m as SharedIndex, n as SearchAPI, t as QueryOptions } from "../server-k8QJZEib.js";
4
- import { S as LoaderOutput, b as LoaderConfig } from "../index-DAbFAfHX.js";
2
+ import { n as I18nConfig } from "../index-DFrWGSeW.js";
3
+ import { S as LoaderOutput, b as LoaderConfig } from "../index-DWVer6sb.js";
4
+ import { m as SharedIndex, n as SearchAPI, t as QueryOptions } from "../server-BUYLz3H4.js";
5
5
  import "../index-CE1OSGGq.js";
6
6
  import { DocumentData, DocumentOptions } from "flexsearch";
7
7
  interface SharedDocument {
@@ -1,21 +1,22 @@
1
1
  import { n as buildIndexDefault, r as createBreadcrumbs } from "../build-index-CqctTvug.js";
2
2
  import { t as createEndpoint } from "../endpoint-H7rb4eeq.js";
3
3
  import { t as buildDocuments } from "../build-doc-CHLmZvHA.js";
4
- import { n as search, t as createDocument } from "../utils-BYuB2fyY.js";
4
+ import { n as search, r as toSearchIndex, t as createDocument } from "../utils-BQW8csGG.js";
5
5
  import Search from "flexsearch";
6
6
  // src/search/flexsearch.ts
7
7
  function server(options) {
8
8
  function initIndex(indexes) {
9
- const index = createDocument(options.document);
10
- for (const doc of buildDocuments(indexes)) index.add(doc.id, doc);
11
- return index;
9
+ const document = createDocument(options.document);
10
+ const docs = buildDocuments(indexes);
11
+ for (let key = 0; key < docs.length; key++) document.add(key, docs[key]);
12
+ return toSearchIndex(document);
12
13
  }
13
14
  const indexPromise = typeof options.indexes === "function" ? Promise.resolve(options.indexes()).then(initIndex) : initIndex(options.indexes);
14
15
  return {
15
16
  async export() {
16
17
  const index = await indexPromise;
17
18
  const raw = {};
18
- index.export((key, data) => {
19
+ index.document.export((key, data) => {
19
20
  raw[key] = data;
20
21
  });
21
22
  return {
@@ -1,2 +1,2 @@
1
- import { a as toDocuments, i as sync, n as MeilisearchDocument, r as SyncOptions, t as DocumentRecord } from "../meilisearch-DLgT0_3G.js";
1
+ import { a as toDocuments, i as sync, n as MeilisearchDocument, r as SyncOptions, t as DocumentRecord } from "../meilisearch-CsyDr1xA.js";
2
2
  export { DocumentRecord, MeilisearchDocument, SyncOptions, sync, toDocuments };
@@ -1,3 +1,3 @@
1
- import { a as toDocuments, t as DocumentRecord } from "../meilisearch-DLgT0_3G.js";
2
- import { a as sync, i as createMixedbreadSearchAPI, n as SearchMetadata, r as SyncOptions, t as MixedbreadSearchOptions } from "../mixedbread-DWeuz1Xb.js";
1
+ import { a as toDocuments, t as DocumentRecord } from "../meilisearch-CsyDr1xA.js";
2
+ import { a as sync, i as createMixedbreadSearchAPI, n as SearchMetadata, r as SyncOptions, t as MixedbreadSearchOptions } from "../mixedbread-CyM4na_-.js";
3
3
  export { type DocumentRecord, MixedbreadSearchOptions, SearchMetadata, SyncOptions, createMixedbreadSearchAPI, sync, toDocuments };
@@ -1,5 +1,5 @@
1
1
  import { n as StructuredData } from "../remark-structure-50nmY6sX.js";
2
- import "../index-C0yDf9A2.js";
2
+ import "../index-BFnMPJLk.js";
3
3
  import { CloudManager } from "@oramacloud/client";
4
4
  export interface SyncOptions {
5
5
  /**
@@ -1,7 +1,7 @@
1
1
  import { t as Awaitable } from "../types-Dvkw0Kd0.js";
2
2
  import { n as StructuredData } from "../remark-structure-50nmY6sX.js";
3
- import "../index-C0yDf9A2.js";
4
- import { S as LoaderOutput, b as LoaderConfig } from "../index-DAbFAfHX.js";
3
+ import "../index-BFnMPJLk.js";
4
+ import { S as LoaderOutput, b as LoaderConfig } from "../index-DWVer6sb.js";
5
5
  import { OramaCloud } from "@orama/core";
6
6
  export interface SyncOptions {
7
7
  /**
@@ -1,2 +1,2 @@
1
- import { a as AdvancedOptions, c as SimpleOptions, d as createSearchAPI, f as initAdvancedSearch, i as AdvancedIndex, l as createFromSource, n as SearchAPI, o as ExportedData, p as initSimpleSearch, r as SearchServer, s as Index, t as QueryOptions, u as createI18nSearchAPI } from "../server-k8QJZEib.js";
1
+ import { a as AdvancedOptions, c as SimpleOptions, d as createSearchAPI, f as initAdvancedSearch, i as AdvancedIndex, l as createFromSource, n as SearchAPI, o as ExportedData, p as initSimpleSearch, r as SearchServer, s as Index, t as QueryOptions, u as createI18nSearchAPI } from "../server-BUYLz3H4.js";
2
2
  export { AdvancedIndex, AdvancedOptions, ExportedData, Index, QueryOptions, SearchAPI, SearchServer, SimpleOptions, createFromSource, createI18nSearchAPI, createSearchAPI, initAdvancedSearch, initSimpleSearch };
@@ -1,7 +1,7 @@
1
1
  import { t as Awaitable } from "./types-Dvkw0Kd0.js";
2
2
  import { n as StructuredData } from "./remark-structure-50nmY6sX.js";
3
- import { n as I18nConfig } from "./index-BIhpw5_j.js";
4
- import { S as LoaderOutput, b as LoaderConfig } from "./index-DAbFAfHX.js";
3
+ import { n as I18nConfig } from "./index-DFrWGSeW.js";
4
+ import { S as LoaderOutput, b as LoaderConfig } from "./index-DWVer6sb.js";
5
5
  import { r as SortedResult } from "./index-CE1OSGGq.js";
6
6
  import { Language, RawData, SearchParams, TypedDocument, ZBSearch, create } from "zbsearch";
7
7
  type SimpleDocument = TypedDocument<ZBSearch<typeof simpleSchema>>;
@@ -1,2 +1,2 @@
1
- import { _ as dynamicLoader, g as DynamicLoaderConfig, h as DynamicLoader } from "../index-DAbFAfHX.js";
1
+ import { _ as dynamicLoader, g as DynamicLoaderConfig, h as DynamicLoader } from "../index-DWVer6sb.js";
2
2
  export { DynamicLoader, DynamicLoaderConfig, dynamicLoader };
@@ -1,2 +1,2 @@
1
- import { A as types_d_exports, B as ContentStorage, C as LoaderPlugin, D as ResolvedLoaderConfig, E as Page, H as ContentStoragePageFile, I as PageTreeBuilder, L as PageTreeBuilderContext, N as getSlugs, O as createGetUrl, R as PageTreeOptions, S as LoaderOutput, T as Meta, U as FileSystem, V as ContentStorageMetaFile, _ as dynamicLoader, a as path_d_exports, b as LoaderConfig, c as PageData, d as StaticSource, f as VirtualFile, g as DynamicLoaderConfig, h as DynamicLoader, i as llms, k as loader, l as Source, m as update, n as LLMsConfig, o as DynamicSource, p as multiple, r as LLMsWithPages, s as MetaData, t as LLMs, u as SourceUnion, v as InferMetaType, w as LoaderPluginOption, x as LoaderOptions, y as InferPageType, z as PageTreeTransformer } from "../index-DAbFAfHX.js";
1
+ import { A as types_d_exports, B as ContentStorage, C as LoaderPlugin, D as ResolvedLoaderConfig, E as Page, H as ContentStoragePageFile, I as PageTreeBuilder, L as PageTreeBuilderContext, N as getSlugs, O as createGetUrl, R as PageTreeOptions, S as LoaderOutput, T as Meta, U as FileSystem, V as ContentStorageMetaFile, _ as dynamicLoader, a as path_d_exports, b as LoaderConfig, c as PageData, d as StaticSource, f as VirtualFile, g as DynamicLoaderConfig, h as DynamicLoader, i as llms, k as loader, l as Source, m as update, n as LLMsConfig, o as DynamicSource, p as multiple, r as LLMsWithPages, s as MetaData, t as LLMs, u as SourceUnion, v as InferMetaType, w as LoaderPluginOption, x as LoaderOptions, y as InferPageType, z as PageTreeTransformer } from "../index-DWVer6sb.js";
2
2
  export { type ContentStorage, type ContentStorageMetaFile, type ContentStoragePageFile, type DynamicLoader, type DynamicLoaderConfig, type DynamicSource, FileSystem, InferMetaType, InferPageType, LLMs, LLMsConfig, LLMsWithPages, LoaderConfig, LoaderOptions, LoaderOutput, LoaderPlugin, LoaderPluginOption, Meta, type MetaData, Page, type PageData, type PageTreeBuilder, type PageTreeBuilderContext, type PageTreeOptions, type PageTreeTransformer, path_d_exports as PathUtils, ResolvedLoaderConfig, type Source, type SourceUnion, type StaticSource, type VirtualFile, type types_d_exports as _Internal, createGetUrl, dynamicLoader, getSlugs, llms, loader, multiple, update };
@@ -1,2 +1,2 @@
1
- import { i as llms, n as LLMsConfig, r as LLMsWithPages, t as LLMs } from "../index-DAbFAfHX.js";
1
+ import { i as llms, n as LLMsConfig, r as LLMsWithPages, t as LLMs } from "../index-DWVer6sb.js";
2
2
  export { LLMs, LLMsConfig, LLMsWithPages, llms };
@@ -31,7 +31,7 @@ function llms(input, config = {}) {
31
31
  }
32
32
  function formatNode(node, indent, ctx) {
33
33
  switch (node.type) {
34
- case "page": return formatListItem(formatMarkdownLink(renderName(node, ctx), node.url), renderDescription(node, ctx), indent);
34
+ case "page": return formatListItem(formatMarkdownLink(renderName(node, ctx), config.renderUrl?.(node, ctx) ?? node.url), renderDescription(node, ctx), indent);
35
35
  case "folder": {
36
36
  const out = [];
37
37
  out.push(formatListItem(renderName(node, ctx), renderDescription(node, ctx), indent));
@@ -1,4 +1,4 @@
1
- import { C as LoaderPlugin } from "../../index-DAbFAfHX.js";
1
+ import { C as LoaderPlugin } from "../../index-DWVer6sb.js";
2
2
  import { icons } from "lucide-react";
3
3
  /**
4
4
  * Convert icon names into Lucide Icons, requires `lucide-react` to be installed.
@@ -1,2 +1,2 @@
1
- import { F as slugsPlugin, M as SlugsPluginOptions, N as getSlugs, P as slugsFromData, j as SlugFn } from "../../index-DAbFAfHX.js";
1
+ import { F as slugsPlugin, M as SlugsPluginOptions, N as getSlugs, P as slugsFromData, j as SlugFn } from "../../index-DWVer6sb.js";
2
2
  export { SlugFn, SlugsPluginOptions, getSlugs, slugsFromData, slugsPlugin };
@@ -1,5 +1,5 @@
1
1
  import { a as Separator$1, n as Item$1, t as Folder$1 } from "../../definitions-BQVehOBz.js";
2
- import { C as LoaderPlugin } from "../../index-DAbFAfHX.js";
2
+ import { C as LoaderPlugin } from "../../index-DWVer6sb.js";
3
3
  import { ReactNode } from "react";
4
4
  export interface Item extends Item$1 {
5
5
  /**
@@ -40,7 +40,7 @@ interface TOCItemProps extends ComponentProps<'a'> {
40
40
  autoScroll?: boolean;
41
41
  onActiveChange?: (v: boolean) => void;
42
42
  }
43
- declare function TOCItem({ ref, onActiveChange, autoScroll, ...props }: TOCItemProps): import("react").JSX.Element;
43
+ declare function TOCItem({ ref, onActiveChange, onClick, autoScroll, ...props }: TOCItemProps): import("react").JSX.Element;
44
44
  /** @returns static info object, useful for custom rendering logic */
45
45
  declare function useTOC(): {
46
46
  get(): TOCItemInfo[];
@@ -50,7 +50,7 @@ declare function useTOC(): {
50
50
  declare function useTOCListener(listener: ChangeListener): void;
51
51
  declare function useTOCSelector<T>(select: (items: TOCItemInfo[]) => T, isEqual?: (a: T, b: T) => boolean): T;
52
52
  /**
53
- * The estimated active heading ID
53
+ * The current heading ID
54
54
  */
55
55
  declare function useActiveAnchor(): string | undefined;
56
56
  /**
package/dist/toc.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { a as TOCItem, c as TOCItemType, d as useActiveAnchors, f as useItems, h as useTOCSelector, i as ScrollProviderProps, l as TableOfContents, m as useTOCListener, n as AnchorProviderProps, o as TOCItemInfo, p as useTOC, r as ScrollProvider, s as TOCItemProps, t as AnchorProvider, u as useActiveAnchor } from "./toc-BPaCQkFr.js";
1
+ import { a as TOCItem, c as TOCItemType, d as useActiveAnchors, f as useItems, h as useTOCSelector, i as ScrollProviderProps, l as TableOfContents, m as useTOCListener, n as AnchorProviderProps, o as TOCItemInfo, p as useTOC, r as ScrollProvider, s as TOCItemProps, t as AnchorProvider, u as useActiveAnchor } from "./toc-BuHOTlzj.js";
2
2
  export { AnchorProvider, AnchorProviderProps, ScrollProvider, ScrollProviderProps, TOCItem, TOCItemInfo, TOCItemProps, TOCItemType, TableOfContents, useActiveAnchor, useActiveAnchors, useItems, useTOC, useTOCListener, useTOCSelector };
package/dist/toc.js CHANGED
@@ -25,7 +25,7 @@ function ScrollProvider({ containerRef, children }) {
25
25
  function AnchorProvider({ toc, single = false, children }) {
26
26
  const observer = useMemo(() => new Observer(toc, single), [toc, single]);
27
27
  useEffect(() => {
28
- observer.watch({ threshold: .9 });
28
+ observer.watch();
29
29
  return () => observer.unwatch();
30
30
  }, [observer]);
31
31
  return /* @__PURE__ */ jsx(ObserverContext, {
@@ -33,7 +33,7 @@ function AnchorProvider({ toc, single = false, children }) {
33
33
  children
34
34
  });
35
35
  }
36
- function TOCItem({ ref, onActiveChange, autoScroll = true, ...props }) {
36
+ function TOCItem({ ref, onActiveChange, onClick, autoScroll = true, ...props }) {
37
37
  const id = props.href ? getItemId(props.href) : null;
38
38
  const containerRef = use(ScrollContext);
39
39
  const anchorRef = useRef(null);
@@ -70,6 +70,10 @@ function TOCItem({ ref, onActiveChange, autoScroll = true, ...props }) {
70
70
  return /* @__PURE__ */ jsx("a", {
71
71
  ref: mergeRefs(anchorRef, ref),
72
72
  "data-active": String(active),
73
+ onClick: (e) => {
74
+ onClick?.(e);
75
+ if (id !== null && !e.defaultPrevented) observer.select(id);
76
+ },
73
77
  ...props
74
78
  });
75
79
  }
@@ -116,7 +120,7 @@ function useTOCSelector(select, isEqual = isEqualShallow) {
116
120
  });
117
121
  }
118
122
  /**
119
- * The estimated active heading ID
123
+ * The current heading ID
120
124
  */
121
125
  function useActiveAnchor() {
122
126
  return useObserverValue((observer) => observer.activeAnchor);
@@ -134,11 +138,14 @@ function getItemId(url) {
134
138
  if (url.startsWith("#")) return url.slice(1);
135
139
  return null;
136
140
  }
141
+ /** a heading is in view when this ratio of it is visible */
142
+ const VISIBLE_RATIO = .9;
137
143
  var Observer = class {
138
144
  constructor(toc, single) {
139
145
  this.single = single;
140
146
  this.activeAnchors = [];
141
147
  this.observer = null;
148
+ this.visible = /* @__PURE__ */ new Set();
142
149
  this.listeners = /* @__PURE__ */ new Set();
143
150
  this.subscribe = (listener) => {
144
151
  this.listeners.add(listener);
@@ -164,9 +171,13 @@ var Observer = class {
164
171
  unlisten(listener) {
165
172
  this.listeners.delete(listener);
166
173
  }
167
- watch(options) {
174
+ select(id) {
175
+ this.activeAnchor = id;
176
+ this.update();
177
+ }
178
+ watch() {
168
179
  if (this.observer) return;
169
- this.observer = new IntersectionObserver(this.callback.bind(this), options);
180
+ this.observer = new IntersectionObserver(this.callback.bind(this), { threshold: VISIBLE_RATIO });
170
181
  for (const item of this.items) {
171
182
  const element = document.getElementById(item.id);
172
183
  if (!element) continue;
@@ -176,57 +187,47 @@ var Observer = class {
176
187
  unwatch() {
177
188
  this.observer?.disconnect();
178
189
  this.observer = null;
190
+ this.visible.clear();
179
191
  }
180
192
  callback(entries) {
181
- if (entries.length === 0) return;
182
- let hasActive = false;
183
- const updated = this.items.map((item) => {
184
- const entry = entries.find((entry) => entry.target.id === item.id);
185
- let active = entry ? entry.isIntersecting : item.active && !item.fallback;
186
- if (this.single && hasActive) active = false;
187
- if (item.active !== active) item = {
193
+ for (const entry of entries) if (entry.intersectionRatio >= VISIBLE_RATIO) this.visible.add(entry.target.id);
194
+ else this.visible.delete(entry.target.id);
195
+ if (this.activeAnchor === void 0 || !this.visible.has(this.activeAnchor)) this.activeAnchor = this.items.find((item) => this.visible.has(item.id))?.id ?? this.findAbove(entries[0].rootBounds);
196
+ this.update();
197
+ }
198
+ /**
199
+ * Measure the last heading above the view, when no heading is in view.
200
+ *
201
+ * Headings can pass the view without intersecting it, so this cannot be tracked from entries.
202
+ */
203
+ findAbove(root) {
204
+ if (!root) return;
205
+ const center = (root.top + root.bottom) / 2;
206
+ let id;
207
+ for (const item of this.items) {
208
+ const rect = document.getElementById(item.id)?.getBoundingClientRect();
209
+ if (!rect || rect.height === 0) continue;
210
+ if (rect.top >= center) break;
211
+ id = item.id;
212
+ }
213
+ return id;
214
+ }
215
+ update() {
216
+ const activeAnchors = [];
217
+ const t = Date.now();
218
+ this.items = this.items.map((item) => {
219
+ const active = this.single || this.visible.size === 0 ? item.id === this.activeAnchor : this.visible.has(item.id);
220
+ const fallback = active && !this.visible.has(item.id);
221
+ if (active) activeAnchors.push(item.id);
222
+ return item.active === active && item.fallback === fallback ? item : {
188
223
  ...item,
189
- t: Date.now(),
190
224
  active,
191
- fallback: false
225
+ fallback,
226
+ t
192
227
  };
193
- if (active) hasActive = true;
194
- return item;
195
228
  });
196
- if (!hasActive && entries[0].rootBounds) {
197
- const viewTop = entries[0].rootBounds.top;
198
- let min = Number.MAX_VALUE;
199
- let fallbackIdx = -1;
200
- for (let i = 0; i < updated.length; i++) {
201
- const element = document.getElementById(updated[i].id);
202
- if (!element) continue;
203
- const d = Math.abs(viewTop - element.getBoundingClientRect().top);
204
- if (d < min) {
205
- fallbackIdx = i;
206
- min = d;
207
- }
208
- }
209
- if (fallbackIdx !== -1) updated[fallbackIdx] = {
210
- ...updated[fallbackIdx],
211
- active: true,
212
- fallback: true,
213
- t: Date.now()
214
- };
215
- }
216
- this.update(updated);
217
- }
218
- update(next) {
219
- let latest;
220
- const activeAnchors = [];
221
- for (const item of next) {
222
- if (!item.active) continue;
223
- activeAnchors.push(item.id);
224
- if (!latest || item.t > latest.t) latest = item;
225
- }
226
- this.items = next;
227
229
  this.activeAnchors = activeAnchors;
228
- this.activeAnchor = latest?.id;
229
- for (const listener of this.listeners) listener(next);
230
+ for (const listener of this.listeners) listener(this.items);
230
231
  }
231
232
  };
232
233
  export { AnchorProvider, ScrollProvider, TOCItem, useActiveAnchor, useActiveAnchors, useItems, useTOC, useTOCListener, useTOCSelector };
@@ -1,7 +1,15 @@
1
1
  import Search from "flexsearch";
2
2
  // src/search/flexsearch/utils.ts
3
- async function search(index, query, tag, limit = 60) {
4
- const arr = await index.searchAsync(query, {
3
+ function toSearchIndex(document) {
4
+ const pages = /* @__PURE__ */ new Map();
5
+ for (let key = 0, doc = document.get(key); doc; doc = document.get(++key)) if (doc.type === "page") pages.set(doc.id, doc);
6
+ return {
7
+ document,
8
+ pages
9
+ };
10
+ }
11
+ async function search({ document, pages }, query, tag, limit = 60) {
12
+ const arr = await document.searchAsync(query, {
5
13
  index: "content",
6
14
  limit,
7
15
  tag: tag ? { tags: tag } : void 0
@@ -10,8 +18,8 @@ async function search(index, query, tag, limit = 60) {
10
18
  if (arr.length === 0) return out;
11
19
  const results = arr[0].result;
12
20
  const grouped = /* @__PURE__ */ new Map();
13
- for (const id of results) {
14
- const doc = index.get(id);
21
+ for (const key of results) {
22
+ const doc = document.get(key);
15
23
  if (!doc) continue;
16
24
  let list = grouped.get(doc.page_id);
17
25
  if (!list) {
@@ -21,7 +29,7 @@ async function search(index, query, tag, limit = 60) {
21
29
  if (doc.type !== "page") list.push(doc);
22
30
  }
23
31
  for (const [page_id, items] of grouped) {
24
- const page = index.get(page_id);
32
+ const page = pages.get(page_id);
25
33
  if (!page) continue;
26
34
  out.push({
27
35
  id: page_id,
@@ -54,4 +62,4 @@ function createDocument(options) {
54
62
  }
55
63
  });
56
64
  }
57
- export { search as n, createDocument as t };
65
+ export { search as n, toSearchIndex as r, createDocument as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "16.17.10",
3
+ "version": "16.18.0",
4
4
  "description": "The React.js library for building a documentation website",
5
5
  "keywords": [
6
6
  "Docs",
@@ -33,6 +33,7 @@
33
33
  "./framework": "./dist/framework/index.js",
34
34
  "./framework/astro": "./dist/framework/astro.js",
35
35
  "./framework/next": "./dist/framework/next.js",
36
+ "./framework/plugin": "./dist/framework/plugin.js",
36
37
  "./framework/react-router": "./dist/framework/react-router.js",
37
38
  "./framework/tanstack": "./dist/framework/tanstack.js",
38
39
  "./framework/waku": "./dist/framework/waku.js",