@vezham/docs-core 1.0.1

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 (201) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +5 -0
  3. package/dist/advanced-Ct13khZr.js +79 -0
  4. package/dist/algolia-C0E5qQhM.d.ts +66 -0
  5. package/dist/breadcrumb.d.ts +46 -0
  6. package/dist/breadcrumb.js +59 -0
  7. package/dist/build-doc-4OvfjVN2.js +85 -0
  8. package/dist/client-kQ39Ub0-.d.ts +247 -0
  9. package/dist/codeblock-utils-CyP8qsYv.d.ts +29 -0
  10. package/dist/content/github.d.ts +41 -0
  11. package/dist/content/github.js +28 -0
  12. package/dist/content/md/frontmatter.d.ts +15 -0
  13. package/dist/content/md/frontmatter.js +24 -0
  14. package/dist/content/md.d.ts +24 -0
  15. package/dist/content/md.js +43 -0
  16. package/dist/content/mdx/preset-bundler.d.ts +29 -0
  17. package/dist/content/mdx/preset-bundler.js +39 -0
  18. package/dist/content/mdx/preset-runtime.d.ts +26 -0
  19. package/dist/content/mdx/preset-runtime.js +36 -0
  20. package/dist/content/toc.d.ts +19 -0
  21. package/dist/content/toc.js +14 -0
  22. package/dist/definitions-CFOhwE1k.d.ts +72 -0
  23. package/dist/dynamic-CTsodhTH.js +905 -0
  24. package/dist/dynamic-link.d.ts +12 -0
  25. package/dist/dynamic-link.js +31 -0
  26. package/dist/endpoint-MyoBU5IC.js +28 -0
  27. package/dist/framework/astro.d.ts +21 -0
  28. package/dist/framework/astro.js +52 -0
  29. package/dist/framework/index.d.ts +40 -0
  30. package/dist/framework/index.js +66 -0
  31. package/dist/framework/next.d.ts +10 -0
  32. package/dist/framework/next.js +19 -0
  33. package/dist/framework/react-router.d.ts +10 -0
  34. package/dist/framework/react-router.js +43 -0
  35. package/dist/framework/tanstack.d.ts +13 -0
  36. package/dist/framework/tanstack.js +54 -0
  37. package/dist/framework/waku.d.ts +10 -0
  38. package/dist/framework/waku.js +46 -0
  39. package/dist/highlight/client.d.ts +11 -0
  40. package/dist/highlight/client.js +15 -0
  41. package/dist/highlight/index.d.ts +31 -0
  42. package/dist/highlight/index.js +30 -0
  43. package/dist/highlight/shiki/full.d.ts +7 -0
  44. package/dist/highlight/shiki/full.js +23 -0
  45. package/dist/highlight/shiki/index.d.ts +2 -0
  46. package/dist/highlight/shiki/index.js +27 -0
  47. package/dist/highlight/shiki/react.d.ts +23 -0
  48. package/dist/highlight/shiki/react.js +50 -0
  49. package/dist/i18n/index.d.ts +2 -0
  50. package/dist/i18n/index.js +63 -0
  51. package/dist/i18n/middleware.d.ts +34 -0
  52. package/dist/i18n/middleware.js +3855 -0
  53. package/dist/icon-BILaoXeg.js +17 -0
  54. package/dist/index-B-0R0VbS.d.ts +18 -0
  55. package/dist/index-BM36H-xw.d.ts +36 -0
  56. package/dist/index-BMEUQz-F.d.ts +21 -0
  57. package/dist/index-DAYtLGbx.d.ts +16 -0
  58. package/dist/index-DIwKCYOz.d.ts +513 -0
  59. package/dist/index-DydiXvgS.d.ts +90 -0
  60. package/dist/index-E8Qh_yQs.d.ts +49 -0
  61. package/dist/is-equal-LdLqRs0o.js +8 -0
  62. package/dist/link.d.ts +17 -0
  63. package/dist/link.js +23 -0
  64. package/dist/mdx-plugins/codeblock-utils.d.ts +2 -0
  65. package/dist/mdx-plugins/codeblock-utils.js +68 -0
  66. package/dist/mdx-plugins/index.d.ts +20 -0
  67. package/dist/mdx-plugins/index.js +18 -0
  68. package/dist/mdx-plugins/rehype-code.core.d.ts +3 -0
  69. package/dist/mdx-plugins/rehype-code.core.js +3 -0
  70. package/dist/mdx-plugins/rehype-code.d.ts +4 -0
  71. package/dist/mdx-plugins/rehype-code.js +24 -0
  72. package/dist/mdx-plugins/rehype-toc.d.ts +2 -0
  73. package/dist/mdx-plugins/rehype-toc.js +139 -0
  74. package/dist/mdx-plugins/remark-admonition.d.ts +2 -0
  75. package/dist/mdx-plugins/remark-admonition.js +71 -0
  76. package/dist/mdx-plugins/remark-block-id.d.ts +37 -0
  77. package/dist/mdx-plugins/remark-block-id.js +41 -0
  78. package/dist/mdx-plugins/remark-code-tab.d.ts +2 -0
  79. package/dist/mdx-plugins/remark-code-tab.js +190 -0
  80. package/dist/mdx-plugins/remark-directive-admonition.d.ts +2 -0
  81. package/dist/mdx-plugins/remark-directive-admonition.js +57 -0
  82. package/dist/mdx-plugins/remark-feedback-block.d.ts +2 -0
  83. package/dist/mdx-plugins/remark-feedback-block.js +54 -0
  84. package/dist/mdx-plugins/remark-gfm.d.ts +2 -0
  85. package/dist/mdx-plugins/remark-gfm.js +2 -0
  86. package/dist/mdx-plugins/remark-heading.d.ts +2 -0
  87. package/dist/mdx-plugins/remark-heading.js +46 -0
  88. package/dist/mdx-plugins/remark-image.d.ts +2 -0
  89. package/dist/mdx-plugins/remark-image.js +167 -0
  90. package/dist/mdx-plugins/remark-llms.d.ts +2 -0
  91. package/dist/mdx-plugins/remark-llms.js +338 -0
  92. package/dist/mdx-plugins/remark-llms.runtime.d.ts +10 -0
  93. package/dist/mdx-plugins/remark-llms.runtime.js +24 -0
  94. package/dist/mdx-plugins/remark-mdx-files.d.ts +2 -0
  95. package/dist/mdx-plugins/remark-mdx-files.js +182 -0
  96. package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +2 -0
  97. package/dist/mdx-plugins/remark-mdx-mermaid.js +28 -0
  98. package/dist/mdx-plugins/remark-npm.d.ts +2 -0
  99. package/dist/mdx-plugins/remark-npm.js +76 -0
  100. package/dist/mdx-plugins/remark-steps.d.ts +2 -0
  101. package/dist/mdx-plugins/remark-steps.js +93 -0
  102. package/dist/mdx-plugins/remark-structure.d.ts +2 -0
  103. package/dist/mdx-plugins/remark-structure.js +118 -0
  104. package/dist/mdx-plugins/stringifier.d.ts +2 -0
  105. package/dist/mdx-plugins/stringifier.js +91 -0
  106. package/dist/mdx-plugins/transformer-icon.d.ts +2 -0
  107. package/dist/mdx-plugins/transformer-icon.js +145 -0
  108. package/dist/negotiation/index.d.ts +17 -0
  109. package/dist/negotiation/index.js +378 -0
  110. package/dist/page-tree/index.d.ts +3 -0
  111. package/dist/page-tree/index.js +2 -0
  112. package/dist/path-1H5VzYiT.js +75 -0
  113. package/dist/rehype-code-D-RFJb9W.d.ts +14 -0
  114. package/dist/rehype-code.core-BUwNuchP.js +548 -0
  115. package/dist/rehype-code.core-BjH1uHWj.d.ts +115 -0
  116. package/dist/rehype-toc-K51AGb5U.d.ts +43 -0
  117. package/dist/remark-admonition-BwTcmI_S.d.ts +20 -0
  118. package/dist/remark-code-tab-DE_4bdnu.d.ts +34 -0
  119. package/dist/remark-directive-admonition-BLiJ5l43.d.ts +27 -0
  120. package/dist/remark-feedback-block-BxtINXN-.d.ts +45 -0
  121. package/dist/remark-gfm-DpVfAX1x.d.ts +2 -0
  122. package/dist/remark-heading-DEIzTkU5.d.ts +33 -0
  123. package/dist/remark-image-BI2S9LOb.d.ts +57 -0
  124. package/dist/remark-llms-bD3WvU2V.d.ts +73 -0
  125. package/dist/remark-mdx-files-Buvxc-sa.d.ts +54 -0
  126. package/dist/remark-mdx-mermaid-C1bCHHc6.d.ts +15 -0
  127. package/dist/remark-npm-BbpvkJaT.d.ts +31 -0
  128. package/dist/remark-steps-DqVEo0iq.d.ts +23 -0
  129. package/dist/remark-structure-CnHwvNZr.d.ts +87 -0
  130. package/dist/remove-markdown-DfKNMl9w.js +40 -0
  131. package/dist/remove-undefined-CzMSKybq.js +24 -0
  132. package/dist/rolldown-runtime-DC62tzP2.js +33 -0
  133. package/dist/search/algolia.d.ts +2 -0
  134. package/dist/search/algolia.js +75 -0
  135. package/dist/search/client/algolia.d.ts +2 -0
  136. package/dist/search/client/algolia.js +53 -0
  137. package/dist/search/client/fetch.d.ts +2 -0
  138. package/dist/search/client/fetch.js +28 -0
  139. package/dist/search/client/flexsearch-static.d.ts +2 -0
  140. package/dist/search/client/flexsearch-static.js +42 -0
  141. package/dist/search/client/mixedbread.d.ts +2 -0
  142. package/dist/search/client/mixedbread.js +65 -0
  143. package/dist/search/client/orama-cloud-legacy.d.ts +2 -0
  144. package/dist/search/client/orama-cloud-legacy.js +84 -0
  145. package/dist/search/client/orama-cloud.d.ts +2 -0
  146. package/dist/search/client/orama-cloud.js +86 -0
  147. package/dist/search/client/orama-static.d.ts +2 -0
  148. package/dist/search/client/orama-static.js +75 -0
  149. package/dist/search/client.d.ts +2 -0
  150. package/dist/search/client.js +97 -0
  151. package/dist/search/flexsearch.d.ts +56 -0
  152. package/dist/search/flexsearch.js +128 -0
  153. package/dist/search/index.d.ts +2 -0
  154. package/dist/search/index.js +74 -0
  155. package/dist/search/mixedbread.d.ts +49 -0
  156. package/dist/search/mixedbread.js +77 -0
  157. package/dist/search/orama-cloud-legacy.d.ts +75 -0
  158. package/dist/search/orama-cloud-legacy.js +48 -0
  159. package/dist/search/orama-cloud.d.ts +75 -0
  160. package/dist/search/orama-cloud.js +50 -0
  161. package/dist/search/server.d.ts +2 -0
  162. package/dist/search/server.js +237 -0
  163. package/dist/server-CCqACwlF.d.ts +165 -0
  164. package/dist/server.browser.d.ts +13 -0
  165. package/dist/server.browser.js +22 -0
  166. package/dist/server.d.ts +42 -0
  167. package/dist/server.js +398 -0
  168. package/dist/source/client/index.d.ts +2 -0
  169. package/dist/source/client/index.js +37 -0
  170. package/dist/source/dynamic.d.ts +2 -0
  171. package/dist/source/dynamic.js +2 -0
  172. package/dist/source/index.d.ts +2 -0
  173. package/dist/source/index.js +5 -0
  174. package/dist/source/llms.d.ts +2 -0
  175. package/dist/source/llms.js +74 -0
  176. package/dist/source/plugins/lucide-icons.d.ts +11 -0
  177. package/dist/source/plugins/lucide-icons.js +21 -0
  178. package/dist/source/plugins/slugs.d.ts +2 -0
  179. package/dist/source/plugins/slugs.js +75 -0
  180. package/dist/source/plugins/status-badges.d.ts +50 -0
  181. package/dist/source/plugins/status-badges.js +52 -0
  182. package/dist/source/schema.d.ts +30 -0
  183. package/dist/source/schema.js +28 -0
  184. package/dist/stringifier-B_QUcUyo.d.ts +63 -0
  185. package/dist/toc-CtW5lwA1.d.ts +64 -0
  186. package/dist/toc.d.ts +2 -0
  187. package/dist/toc.js +245 -0
  188. package/dist/transformer-icon-DlrneIS3.d.ts +17 -0
  189. package/dist/types-D89QoQR-.d.ts +4 -0
  190. package/dist/url-BVHvi3_K.js +29 -0
  191. package/dist/util-BDsqOxh3.d.ts +6 -0
  192. package/dist/util-DjBr9b3w.js +8 -0
  193. package/dist/utils/use-media-query.d.ts +4 -0
  194. package/dist/utils/use-media-query.js +20 -0
  195. package/dist/utils/use-on-change.d.ts +9 -0
  196. package/dist/utils/use-on-change.js +17 -0
  197. package/dist/utils-Bvy3V-fv.js +59 -0
  198. package/dist/utils-Cgs-6U-z.js +39 -0
  199. package/dist/utils-DEVq3cEC.js +151 -0
  200. package/dist/utils-Yx0IL9eW.js +48 -0
  201. package/package.json +251 -0
@@ -0,0 +1,75 @@
1
+ //#region src/search/algolia.ts
2
+ /**
3
+ * Update index settings and replace all objects
4
+ *
5
+ * @param client - Algolia Admin Client
6
+ * @param options - Index Options
7
+ */
8
+ async function sync(client, options) {
9
+ const { indexName = "document", documents } = options;
10
+ await setIndexSettings(client, indexName);
11
+ await updateDocuments(client, indexName, documents);
12
+ }
13
+ async function setIndexSettings(client, indexName) {
14
+ await client.setSettings({
15
+ indexName,
16
+ indexSettings: {
17
+ attributeForDistinct: "page_id",
18
+ attributesToRetrieve: [
19
+ "title",
20
+ "section",
21
+ "content",
22
+ "url",
23
+ "section_id",
24
+ "breadcrumbs"
25
+ ],
26
+ searchableAttributes: [
27
+ "title",
28
+ "section",
29
+ "content"
30
+ ],
31
+ attributesToSnippet: [],
32
+ attributesForFaceting: ["tag"]
33
+ }
34
+ });
35
+ }
36
+ function toIndex(page) {
37
+ let id = 0;
38
+ const indexes = [];
39
+ const scannedHeadings = /* @__PURE__ */ new Set();
40
+ function createIndex(section, sectionId, content) {
41
+ return {
42
+ objectID: `${page._id}-${(id++).toString()}`,
43
+ breadcrumbs: page.breadcrumbs,
44
+ title: page.title,
45
+ url: page.url,
46
+ page_id: page._id,
47
+ tag: page.tag,
48
+ section,
49
+ section_id: sectionId,
50
+ content,
51
+ ...page.extra_data
52
+ };
53
+ }
54
+ if (page.description) indexes.push(createIndex(void 0, void 0, page.description));
55
+ const { headings, contents } = page.structured;
56
+ for (const p of contents) {
57
+ const heading = p.heading ? headings.find((h) => p.heading === h.id) : null;
58
+ const index = createIndex(heading?.content, heading?.id, p.content);
59
+ if (heading && !scannedHeadings.has(heading.id)) {
60
+ scannedHeadings.add(heading.id);
61
+ indexes.push(createIndex(heading.content, heading.id, heading.content));
62
+ }
63
+ indexes.push(index);
64
+ }
65
+ return indexes;
66
+ }
67
+ async function updateDocuments(client, indexName, documents) {
68
+ const objects = documents.flatMap(toIndex);
69
+ await client.replaceAllObjects({
70
+ indexName,
71
+ objects
72
+ });
73
+ }
74
+ //#endregion
75
+ export { setIndexSettings, sync, updateDocuments };
@@ -0,0 +1,2 @@
1
+ import { m as algoliaClient, p as AlgoliaOptions } from "../../client-kQ39Ub0-.js";
2
+ export { AlgoliaOptions, algoliaClient };
@@ -0,0 +1,53 @@
1
+ import { createContentHighlighter } from "../index.js";
2
+ //#region src/search/client/algolia.ts
3
+ function groupResults(hits) {
4
+ const grouped = [];
5
+ const scannedUrls = /* @__PURE__ */ new Set();
6
+ for (const hit of hits) {
7
+ if (!scannedUrls.has(hit.url)) {
8
+ scannedUrls.add(hit.url);
9
+ grouped.push({
10
+ id: hit.url,
11
+ type: "page",
12
+ breadcrumbs: hit.breadcrumbs,
13
+ url: hit.url,
14
+ content: hit.title
15
+ });
16
+ }
17
+ grouped.push({
18
+ id: hit.objectID,
19
+ type: hit.content === hit.section ? "heading" : "text",
20
+ url: hit.section_id ? `${hit.url}#${hit.section_id}` : hit.url,
21
+ content: hit.content
22
+ });
23
+ }
24
+ return grouped;
25
+ }
26
+ function algoliaClient(options) {
27
+ const { indexName, onSearch, client, locale, tag } = options;
28
+ return {
29
+ deps: [
30
+ indexName,
31
+ client,
32
+ locale,
33
+ tag
34
+ ],
35
+ async search(query) {
36
+ if (query.trim().length === 0) return [];
37
+ const result = onSearch ? await onSearch(query, tag, locale) : await client.searchForHits({ requests: [{
38
+ type: "default",
39
+ indexName,
40
+ query,
41
+ distinct: 5,
42
+ hitsPerPage: 10,
43
+ filters: tag ? `tag:${tag}` : void 0
44
+ }] });
45
+ const highlighter = createContentHighlighter(query);
46
+ const results = groupResults(result.results[0].hits);
47
+ for (const item of results) item.content = highlighter.highlightMarkdown(item.content);
48
+ return results;
49
+ }
50
+ };
51
+ }
52
+ //#endregion
53
+ export { algoliaClient };
@@ -0,0 +1,2 @@
1
+ import { v as FetchOptions, y as fetchClient } from "../../client-kQ39Ub0-.js";
2
+ export { FetchOptions, fetchClient };
@@ -0,0 +1,28 @@
1
+ import { n as join, t as BASE_PATH } from "../../url-BVHvi3_K.js";
2
+ //#region src/search/client/fetch.ts
3
+ const globalCache = /* @__PURE__ */ new Map();
4
+ function fetchClient({ api = join(BASE_PATH, "/api/search"), locale, tag, cache = globalCache } = {}) {
5
+ return {
6
+ deps: [
7
+ api,
8
+ locale,
9
+ tag
10
+ ],
11
+ async search(query) {
12
+ const url = new URL(api, window.location.origin);
13
+ url.searchParams.set("query", query);
14
+ if (locale) url.searchParams.set("locale", locale);
15
+ if (tag) url.searchParams.set("tag", Array.isArray(tag) ? tag.join(",") : tag);
16
+ const key = url.toString();
17
+ const cached = cache.get(key);
18
+ if (cached) return cached;
19
+ const res = await fetch(url);
20
+ if (!res.ok) throw new Error(await res.text());
21
+ const result = await res.json();
22
+ cache.set(key, result);
23
+ return result;
24
+ }
25
+ };
26
+ }
27
+ //#endregion
28
+ export { fetchClient };
@@ -0,0 +1,2 @@
1
+ import { a as flexsearchStaticClient, i as FlexsearchStaticOptions } from "../../client-kQ39Ub0-.js";
2
+ export { FlexsearchStaticOptions, flexsearchStaticClient };
@@ -0,0 +1,42 @@
1
+ import { n as join, t as BASE_PATH } from "../../url-BVHvi3_K.js";
2
+ import { n as search, t as createDocument } from "../../utils-Bvy3V-fv.js";
3
+ //#region src/search/client/flexsearch-static.ts
4
+ function initDocument(data) {
5
+ const document = createDocument();
6
+ for (const [k, v] of Object.entries(data)) document.import(k, v);
7
+ return document;
8
+ }
9
+ const cacheMap = /* @__PURE__ */ new Map();
10
+ function flexsearchStaticClient(options = {}) {
11
+ const { from = join(BASE_PATH, "/api/search"), locale = "", tag } = options;
12
+ let dbs = cacheMap.get(from);
13
+ if (!dbs && typeof window !== "undefined") {
14
+ dbs = init(from);
15
+ cacheMap.set(from, dbs);
16
+ }
17
+ return {
18
+ deps: [
19
+ from,
20
+ locale,
21
+ tag
22
+ ],
23
+ async search(query) {
24
+ const db = (await dbs).get(locale);
25
+ if (!db) return [];
26
+ return search(db, query, tag);
27
+ }
28
+ };
29
+ }
30
+ async function init(from) {
31
+ const res = await fetch(from);
32
+ if (!res.ok) throw new Error(`failed to fetch exported search indexes from ${from}, make sure the search database is exported and available for client.`);
33
+ const data = await res.json();
34
+ const dbs = /* @__PURE__ */ new Map();
35
+ if (data.type === "i18n") {
36
+ for (const [locale, map] of Object.entries(data.raw)) dbs.set(locale, initDocument(map));
37
+ return dbs;
38
+ } else dbs.set("", initDocument(data.raw));
39
+ return dbs;
40
+ }
41
+ //#endregion
42
+ export { flexsearchStaticClient };
@@ -0,0 +1,2 @@
1
+ import { c as mixedbreadClient, o as MixedbreadOptions, s as SearchMetadata } from "../../client-kQ39Ub0-.js";
2
+ export { MixedbreadOptions, SearchMetadata, mixedbreadClient };
@@ -0,0 +1,65 @@
1
+ import { r as __toESM } from "../../rolldown-runtime-DC62tzP2.js";
2
+ import { t as require_remove_markdown } from "../../remove-markdown-DfKNMl9w.js";
3
+ import Slugger from "github-slugger";
4
+ //#region src/search/client/mixedbread.ts
5
+ var import_remove_markdown = /* @__PURE__ */ __toESM(require_remove_markdown(), 1);
6
+ const slugger = new Slugger();
7
+ function extractHeadingTitle(text) {
8
+ const trimmedText = text.trim();
9
+ if (!trimmedText.startsWith("#")) return "";
10
+ const firstLine = trimmedText.split("\n")[0]?.trim();
11
+ if (firstLine) return (0, import_remove_markdown.default)(firstLine, { useImgAltText: false });
12
+ return "";
13
+ }
14
+ /**
15
+ * @deprecated Use `createMixedbreadSearchAPI` from `@vezham/docs-core/search/mixedbread` instead.
16
+ * This client-side approach exposes your API key in the browser.
17
+ * The server-side approach keeps the key secure and uses `client: fetchClient(...)` on the client.
18
+ */
19
+ function mixedbreadClient(options) {
20
+ const { client, storeIdentifier, tag } = options;
21
+ return {
22
+ deps: [
23
+ client,
24
+ storeIdentifier,
25
+ tag
26
+ ],
27
+ async search(query) {
28
+ if (!query.trim()) return [];
29
+ return (await client.stores.search({
30
+ query,
31
+ store_identifiers: [storeIdentifier],
32
+ top_k: 10,
33
+ filters: {
34
+ key: "generated_metadata.tag",
35
+ operator: "eq",
36
+ value: tag
37
+ },
38
+ search_options: { return_metadata: true }
39
+ })).data.flatMap((item) => {
40
+ const metadata = item.generated_metadata;
41
+ const url = metadata.url || "#";
42
+ const title = metadata.title || "Untitled";
43
+ const chunkResults = [{
44
+ id: `${item.file_id}-${item.chunk_index}-page`,
45
+ type: "page",
46
+ content: title,
47
+ url
48
+ }];
49
+ const headingTitle = item.type === "text" && item.text ? extractHeadingTitle(item.text) : "";
50
+ if (headingTitle) {
51
+ slugger.reset();
52
+ chunkResults.push({
53
+ id: `${item.file_id}-${item.chunk_index}-heading`,
54
+ type: "heading",
55
+ content: headingTitle,
56
+ url: `${url}#${slugger.slug(headingTitle)}`
57
+ });
58
+ }
59
+ return chunkResults;
60
+ });
61
+ }
62
+ };
63
+ }
64
+ //#endregion
65
+ export { mixedbreadClient };
@@ -0,0 +1,2 @@
1
+ import { l as OramaCloudLegacyOptions, u as oramaCloudLegacyClient } from "../../client-kQ39Ub0-.js";
2
+ export { OramaCloudLegacyOptions, oramaCloudLegacyClient };
@@ -0,0 +1,84 @@
1
+ import { createContentHighlighter } from "../index.js";
2
+ import { t as removeUndefined } from "../../remove-undefined-CzMSKybq.js";
3
+ //#region src/search/client/orama-cloud-legacy.ts
4
+ function oramaCloudLegacyClient(options) {
5
+ const { index = "default", client, params: extraParams = {}, tag } = options;
6
+ return {
7
+ deps: [
8
+ index,
9
+ client,
10
+ tag
11
+ ],
12
+ async search(query) {
13
+ const highlighter = createContentHighlighter(query);
14
+ const list = [];
15
+ if (index === "crawler") {
16
+ const result = await client.search({
17
+ ...extraParams,
18
+ term: query,
19
+ where: {
20
+ category: tag ? { eq: tag.slice(0, 1).toUpperCase() + tag.slice(1) } : void 0,
21
+ ...extraParams.where
22
+ },
23
+ limit: 10
24
+ });
25
+ if (!result) return list;
26
+ for (const hit of result.hits) {
27
+ const doc = hit.document;
28
+ list.push({
29
+ id: hit.id,
30
+ type: "page",
31
+ content: highlighter.highlightMarkdown(doc.title),
32
+ url: doc.path
33
+ }, {
34
+ id: "page" + hit.id,
35
+ type: "text",
36
+ content: highlighter.highlightMarkdown(doc.content),
37
+ url: doc.path
38
+ });
39
+ }
40
+ return list;
41
+ }
42
+ const params = {
43
+ ...extraParams,
44
+ term: query,
45
+ where: removeUndefined({
46
+ tag,
47
+ ...extraParams.where
48
+ }),
49
+ groupBy: {
50
+ properties: ["page_id"],
51
+ maxResult: 7,
52
+ ...extraParams.groupBy
53
+ }
54
+ };
55
+ const result = await client.search(params);
56
+ if (!result || !result.groups) return list;
57
+ for (const item of result.groups) {
58
+ let addedHead = false;
59
+ for (const hit of item.result) {
60
+ const doc = hit.document;
61
+ if (!addedHead) {
62
+ list.push({
63
+ id: doc.page_id,
64
+ type: "page",
65
+ content: highlighter.highlightMarkdown(doc.title),
66
+ breadcrumbs: doc.breadcrumbs,
67
+ url: doc.url
68
+ });
69
+ addedHead = true;
70
+ }
71
+ list.push({
72
+ id: doc.id,
73
+ content: highlighter.highlightMarkdown(doc.content),
74
+ type: doc.content === doc.section ? "heading" : "text",
75
+ url: doc.section_id ? `${doc.url}#${doc.section_id}` : doc.url
76
+ });
77
+ }
78
+ }
79
+ return list;
80
+ }
81
+ };
82
+ }
83
+ //#endregion
84
+ export { oramaCloudLegacyClient };
@@ -0,0 +1,2 @@
1
+ import { d as OramaCloudOptions, f as oramaCloudClient } from "../../client-kQ39Ub0-.js";
2
+ export { OramaCloudOptions, oramaCloudClient };
@@ -0,0 +1,86 @@
1
+ import { createContentHighlighter } from "../index.js";
2
+ import { t as removeUndefined } from "../../remove-undefined-CzMSKybq.js";
3
+ //#region src/search/client/orama-cloud.ts
4
+ function oramaCloudClient(options) {
5
+ const { index = "default", client, params: extraParams, tag } = options;
6
+ return {
7
+ deps: [
8
+ index,
9
+ client,
10
+ tag
11
+ ],
12
+ async search(query) {
13
+ const highlighter = createContentHighlighter(query);
14
+ const list = [];
15
+ if (index === "crawler") {
16
+ const result = await client.search({
17
+ datasources: [],
18
+ ...extraParams,
19
+ term: query,
20
+ where: {
21
+ category: tag ? { eq: tag.slice(0, 1).toUpperCase() + tag.slice(1) } : void 0,
22
+ ...extraParams?.where
23
+ },
24
+ limit: 10
25
+ });
26
+ if (!result) return list;
27
+ for (const hit of result.hits) {
28
+ const doc = hit.document;
29
+ list.push({
30
+ id: hit.id,
31
+ type: "page",
32
+ content: highlighter.highlightMarkdown(doc.title),
33
+ url: doc.path
34
+ }, {
35
+ id: "page" + hit.id,
36
+ type: "text",
37
+ content: highlighter.highlightMarkdown(doc.content),
38
+ url: doc.path
39
+ });
40
+ }
41
+ return list;
42
+ }
43
+ const result = await client.search({
44
+ datasources: [],
45
+ ...extraParams,
46
+ term: query,
47
+ limit: 20,
48
+ where: removeUndefined({
49
+ tag,
50
+ ...extraParams?.where
51
+ }),
52
+ groupBy: {
53
+ properties: ["page_id"],
54
+ max_results: 7,
55
+ ...extraParams?.groupBy
56
+ }
57
+ });
58
+ if (!result || !result.groups) return list;
59
+ for (const item of result.groups) {
60
+ let addedHead = false;
61
+ for (const hit of item.result) {
62
+ const doc = hit.document;
63
+ if (!addedHead) {
64
+ list.push({
65
+ id: doc.page_id,
66
+ type: "page",
67
+ content: highlighter.highlightMarkdown(doc.title),
68
+ breadcrumbs: doc.breadcrumbs,
69
+ url: doc.url
70
+ });
71
+ addedHead = true;
72
+ }
73
+ list.push({
74
+ id: doc.id,
75
+ content: highlighter.highlightMarkdown(doc.content),
76
+ type: doc.content === doc.section ? "heading" : "text",
77
+ url: doc.section_id ? `${doc.url}#${doc.section_id}` : doc.url
78
+ });
79
+ }
80
+ }
81
+ return list.length > 80 ? list.slice(0, 80) : list;
82
+ }
83
+ };
84
+ }
85
+ //#endregion
86
+ export { oramaCloudClient };
@@ -0,0 +1,2 @@
1
+ import { _ as staticClient, g as oramaStaticClient, h as StaticOptions } from "../../client-kQ39Ub0-.js";
2
+ export { StaticOptions, oramaStaticClient, staticClient };
@@ -0,0 +1,75 @@
1
+ import { n as join, t as BASE_PATH } from "../../url-BVHvi3_K.js";
2
+ import { n as searchSimple, t as searchAdvanced } from "../../advanced-Ct13khZr.js";
3
+ import { create, load } from "zbsearch";
4
+ //#region src/search/client/orama-static.ts
5
+ const cache = /* @__PURE__ */ new Map();
6
+ async function loadDB(from, initDB = () => create({ schema: { _: "string" } })) {
7
+ const res = await fetch(from);
8
+ if (!res.ok) throw new Error(`failed to fetch exported search indexes from ${from}, make sure the search database is exported and available for client.`);
9
+ const data = await res.json();
10
+ const map = /* @__PURE__ */ new Map();
11
+ if (data.type === "i18n") {
12
+ await Promise.all(Object.entries(data.data).map(async ([k, v]) => {
13
+ const db = await initDB(k);
14
+ load(db, v);
15
+ map.set(k, {
16
+ type: v.type,
17
+ db
18
+ });
19
+ }));
20
+ return {
21
+ map,
22
+ unified: false,
23
+ i18n: true
24
+ };
25
+ }
26
+ const db = await initDB();
27
+ load(db, data);
28
+ map.set("", {
29
+ type: data.type,
30
+ db
31
+ });
32
+ return {
33
+ map,
34
+ unified: true,
35
+ i18n: data.i18n === true
36
+ };
37
+ }
38
+ function getDBCached({ from = join(BASE_PATH, "/api/search"), initDB, initOrama }) {
39
+ const cacheKey = from;
40
+ const cached = cache.get(cacheKey);
41
+ if (cached) return cached;
42
+ const result = loadDB(from, initDB ?? initOrama);
43
+ cache.set(cacheKey, result);
44
+ return result;
45
+ }
46
+ function staticClient(options = {}) {
47
+ const { tag, locale, search } = options;
48
+ return {
49
+ deps: [tag, locale],
50
+ async search(query) {
51
+ const { map, unified, i18n } = await getDBCached(options);
52
+ let db;
53
+ let filterLocale;
54
+ if (unified) {
55
+ db = map.get("");
56
+ if (i18n) filterLocale = locale;
57
+ } else {
58
+ db = map.get(locale ?? "");
59
+ if (!db) {
60
+ console.warn(`failed to find search data for "${locale}", available: ${Array.from(map.keys())}.`);
61
+ db = map.values().next().value;
62
+ }
63
+ }
64
+ if (!db) return [];
65
+ if (db.type === "simple") return searchSimple(db.db, query, search, filterLocale);
66
+ return searchAdvanced(db.db, query, tag, search, filterLocale);
67
+ }
68
+ };
69
+ }
70
+ /**
71
+ * @deprecated Renamed to `staticClient`, note that the search engine is now ZBSearch.
72
+ */
73
+ const oramaStaticClient = staticClient;
74
+ //#endregion
75
+ export { oramaStaticClient, staticClient };
@@ -0,0 +1,2 @@
1
+ import { d as OramaCloudOptions, h as StaticOptions, n as SearchClient, p as AlgoliaOptions, r as useDocsSearch, t as ClientPreset, v as FetchOptions } from "../client-kQ39Ub0-.js";
2
+ export { type AlgoliaOptions, ClientPreset, type FetchOptions, type OramaCloudOptions, SearchClient, type StaticOptions, useDocsSearch };
@@ -0,0 +1,97 @@
1
+ import { t as isEqualShallow } from "../is-equal-LdLqRs0o.js";
2
+ import { useEffect, useMemo, useRef, useState } from "react";
3
+ //#region src/utils/use-debounce.ts
4
+ function useDebounce(value, delayMs = 1e3) {
5
+ const [debouncedValue, setDebouncedValue] = useState(value);
6
+ useEffect(() => {
7
+ if (delayMs === 0) return;
8
+ const handler = window.setTimeout(() => {
9
+ setDebouncedValue(value);
10
+ }, delayMs);
11
+ return () => clearTimeout(handler);
12
+ }, [delayMs, value]);
13
+ if (delayMs === 0) return value;
14
+ return debouncedValue;
15
+ }
16
+ //#endregion
17
+ //#region src/search/client.ts
18
+ /**
19
+ * Provide a hook to query different official search clients.
20
+ *
21
+ * Note: it will re-query when its parameters changed, make sure to define `deps` array if you encounter rendering issues.
22
+ */
23
+ function useDocsSearch(clientOptions, customDeps) {
24
+ const { delayMs = 100, allowEmpty = false, ...clientRest } = clientOptions;
25
+ const [search, setSearch] = useState("");
26
+ const [results, setResults] = useState("empty");
27
+ const [error, setError] = useState();
28
+ const [isLoading, setIsLoading] = useState(false);
29
+ const debouncedValue = useDebounce(search, delayMs);
30
+ let client;
31
+ if ("type" in clientRest) switch (clientRest.type) {
32
+ case "fetch":
33
+ client = import("./client/fetch.js").then((mod) => mod.fetchClient(clientRest));
34
+ break;
35
+ case "algolia":
36
+ client = import("./client/algolia.js").then((mod) => mod.algoliaClient(clientRest));
37
+ break;
38
+ case "orama-cloud":
39
+ client = import("./client/orama-cloud.js").then((mod) => mod.oramaCloudClient(clientRest));
40
+ break;
41
+ case "orama-cloud-legacy":
42
+ client = import("./client/orama-cloud-legacy.js").then((mod) => mod.oramaCloudLegacyClient(clientRest));
43
+ break;
44
+ case "mixedbread":
45
+ client = import("./client/mixedbread.js").then((mod) => mod.mixedbreadClient(clientRest));
46
+ break;
47
+ case "static":
48
+ client = import("./client/orama-static.js").then((mod) => mod.staticClient(clientRest));
49
+ break;
50
+ default: throw new Error("unknown search client");
51
+ }
52
+ else client = clientRest.client;
53
+ const deps = [customDeps ?? (client instanceof Promise ? JSON.stringify(clientRest) : client.deps), debouncedValue];
54
+ const [activeDeps, setActiveDeps] = useState(null);
55
+ const activeTaskRef = useRef(null);
56
+ if (!isEqualShallow(activeDeps, deps) && (!activeTaskRef.current || !isEqualShallow(activeTaskRef.current.deps, deps))) {
57
+ if (activeTaskRef.current) activeTaskRef.current.interrupt = true;
58
+ activeTaskRef.current = {
59
+ deps,
60
+ interrupt: false,
61
+ async start() {
62
+ try {
63
+ setIsLoading(true);
64
+ let res;
65
+ if (debouncedValue.length === 0 && !allowEmpty) res = "empty";
66
+ else res = await (await client).search(debouncedValue);
67
+ if (!this.interrupt) {
68
+ setActiveDeps(deps);
69
+ setError(void 0);
70
+ setResults(res);
71
+ }
72
+ } catch (err) {
73
+ if (!this.interrupt) setError(err);
74
+ } finally {
75
+ if (!this.interrupt) setIsLoading(false);
76
+ }
77
+ }
78
+ };
79
+ activeTaskRef.current.start();
80
+ }
81
+ return useMemo(() => ({
82
+ search,
83
+ setSearch,
84
+ query: {
85
+ isLoading,
86
+ data: results,
87
+ error
88
+ }
89
+ }), [
90
+ search,
91
+ isLoading,
92
+ results,
93
+ error
94
+ ]);
95
+ }
96
+ //#endregion
97
+ export { useDocsSearch };