boltdocs 3.2.2 → 3.3.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 (156) hide show
  1. package/bin/boltdocs.js +20 -1
  2. package/bin/preloader.mjs +28 -0
  3. package/dist/{adapters-ByYY44Zy.mjs → adapters-BmB4TKCc.mjs} +1 -1
  4. package/dist/{adapters-DvmtpdSF.cjs → adapters-Cp1Maurn.cjs} +1 -1
  5. package/dist/audit-CLXjMzwQ.mjs +11 -0
  6. package/dist/audit-COgjnQ5n.cjs +11 -0
  7. package/dist/build-D6FfNA8m.cjs +6 -0
  8. package/dist/build-D_7SvwTh.mjs +6 -0
  9. package/dist/cache-CJE9nWLE.cjs +6 -0
  10. package/dist/cache-OY4HzIXl.mjs +6 -0
  11. package/dist/callout-oI_LCbxS.d.ts +71 -0
  12. package/dist/callout-plqx9Dw-.d.cts +71 -0
  13. package/dist/client/index.cjs +1265 -569
  14. package/dist/client/index.d.cts +3 -542
  15. package/dist/client/index.d.ts +3 -542
  16. package/dist/client/index.js +1167 -521
  17. package/dist/client/mdx.cjs +1 -1
  18. package/dist/client/mdx.d.cts +24 -2
  19. package/dist/client/mdx.d.ts +24 -2
  20. package/dist/client/mdx.js +1 -1
  21. package/dist/client/primitives.cjs +14 -4
  22. package/dist/client/primitives.d.cts +281 -38
  23. package/dist/client/primitives.d.ts +281 -38
  24. package/dist/client/primitives.js +5 -5
  25. package/dist/client/router.cjs +49 -0
  26. package/dist/client/router.d.cts +3 -0
  27. package/dist/client/router.d.ts +3 -0
  28. package/dist/client/router.js +8 -0
  29. package/dist/client/theme/reset.css +40 -4
  30. package/dist/{config-BpzaPsJj.d.cts → config-BoRlz0Ca.d.mts} +157 -14
  31. package/dist/{config-xtS0ZkMm.d.mts → config-CTsX_tGM.d.cts} +157 -14
  32. package/dist/config-Ceib-AOH.cjs +7 -0
  33. package/dist/config-DGLQsy7y.mjs +7 -0
  34. package/dist/{package-CH2ChQqw.cjs → config-files-BYHDOrKn.mjs} +1 -1
  35. package/dist/config-files-D9cdBMl2.cjs +6 -0
  36. package/dist/config-jJh8WYJI.cjs +6 -0
  37. package/dist/csp-C4LmN1ko.cjs +6 -0
  38. package/dist/csp-D6JEOqKh.mjs +6 -0
  39. package/dist/dev-B9l7fVoQ.cjs +6 -0
  40. package/dist/dev-CwOyh-wP.mjs +6 -0
  41. package/dist/{docs-layout-BdtZ9z6s.js → docs-layout-CbZ7LDRe.js} +504 -249
  42. package/dist/{docs-layout-CFWI15Id.cjs → docs-layout-vzfXed1Q.cjs} +516 -254
  43. package/dist/{doctor-BBtmNJE0.cjs → doctor-B1_YL0Wt.cjs} +1 -1
  44. package/dist/doctor-C7whl4ED.cjs +6 -0
  45. package/dist/doctor-DmQnml2k.mjs +6 -0
  46. package/dist/{generator-COepVWGi.cjs → generator-BlW45ST7.cjs} +5 -3
  47. package/dist/{generator-CcOBN5vI.mjs → generator-BwknNejd.mjs} +5 -3
  48. package/dist/{handler-XX7cLTqe.cjs → handler-CDEoKARD.cjs} +2 -2
  49. package/dist/{handler-DzQae4eA.mjs → handler-D7UyZlPm.mjs} +2 -2
  50. package/dist/{image-Bz87fCla.js → image-B-NDSDuY.js} +129 -11
  51. package/dist/{image-C4TlpMHn.cjs → image-Hnaa2bJd.cjs} +175 -9
  52. package/dist/index-C56bL-A-.d.cts +1344 -0
  53. package/dist/{sidebar-COTaMHR-.d.ts → index-CPUUKzxD.d.cts} +344 -327
  54. package/dist/{sidebar-CrEdJuHX.d.cts → index-Ci4kfOHF.d.ts} +344 -327
  55. package/dist/index-Cu9H6CRa.d.ts +1344 -0
  56. package/dist/link-CgdI6O2o.js +872 -0
  57. package/dist/{link-D1Gjkb-2.cjs → link-vZjmD-es.cjs} +406 -223
  58. package/dist/{mdx-BuO6a1f7.js → mdx-BRT71V5Q.js} +211 -168
  59. package/dist/{mdx-CD-tSjRG.cjs → mdx-D0Absdq5.cjs} +225 -169
  60. package/dist/native-BNCY7PRF.cjs +6 -0
  61. package/dist/native-Di9Fnfrv.mjs +6 -0
  62. package/dist/native-Kre2T5eS.cjs +6 -0
  63. package/dist/node/cache.cjs +1 -1
  64. package/dist/node/cache.d.cts +19 -3
  65. package/dist/node/cache.d.mts +19 -3
  66. package/dist/node/cache.mjs +1 -1
  67. package/dist/node/cli-entry.cjs +1 -9
  68. package/dist/node/cli-entry.mjs +1 -9
  69. package/dist/node/index.cjs +1 -1
  70. package/dist/node/index.d.cts +245 -17
  71. package/dist/node/index.d.mts +246 -18
  72. package/dist/node/index.mjs +1 -1
  73. package/dist/node/mdx/shiki-adapter.cjs +1 -1
  74. package/dist/node/mdx/shiki-adapter.d.cts +24 -3
  75. package/dist/node/mdx/shiki-adapter.d.mts +24 -2
  76. package/dist/node/mdx/shiki-adapter.mjs +1 -1
  77. package/dist/node-BFNCsPs3.mjs +23 -0
  78. package/dist/node-TpmWEqXM.cjs +23 -0
  79. package/dist/{package-DSSB8B5L.mjs → package-5EsGUTVl.mjs} +1 -1
  80. package/dist/package-Ca2WSiy2.cjs +6 -0
  81. package/dist/pages-external-BBw8ObVK.mjs +6 -0
  82. package/dist/pages-external-DPiPFxxP.cjs +6 -0
  83. package/dist/parser-BqTOsEUa.cjs +6 -0
  84. package/dist/parser-CGMY2lJ7.mjs +6 -0
  85. package/dist/plugin-CUmUZOLD.mjs +69 -0
  86. package/dist/plugin-Ds3RLYpy.cjs +69 -0
  87. package/dist/plugin-context-C-l90hFt.cjs +15 -0
  88. package/dist/plugin-context-wqHNSZum.mjs +15 -0
  89. package/dist/plugin-lifecycle-BAKNKOxd.cjs +6 -0
  90. package/dist/resolve-B7vWOd8R.cjs +6 -0
  91. package/dist/resolve-C2kKnk_5.mjs +6 -0
  92. package/dist/resolve-It1Iug83.cjs +6 -0
  93. package/dist/resolve-YdTrt_FG.mjs +6 -0
  94. package/dist/router-C3kygdRK.cjs +1285 -0
  95. package/dist/router-CZBxMRAH.js +987 -0
  96. package/dist/routes-BL4y79tb.mjs +6 -0
  97. package/dist/routes-C2nPecwu.cjs +6 -0
  98. package/dist/routes-U9L8psZ9.cjs +6 -0
  99. package/dist/{search-dialog-DFnlx8LO.js → search-dialog-BqkzDTq2.js} +107 -57
  100. package/dist/search-dialog-D3jtaw6w.cjs +525 -0
  101. package/dist/search-dialog-DRiXejws.js +501 -0
  102. package/dist/{search-dialog-DHqwjJuG.cjs → search-dialog-DmirOMPg.cjs} +1 -1
  103. package/dist/{search-dialog-D6TvjcuV.js → search-dialog-MmwxFMmE.js} +1 -1
  104. package/dist/{search-dialog-B1NERUNx.cjs → search-dialog-x_qHU8ty.cjs} +107 -58
  105. package/dist/server/index.cjs +1 -1
  106. package/dist/server/index.d.mts +1 -1
  107. package/dist/server/index.mjs +1 -1
  108. package/dist/update-check-BKqmYfwT.cjs +11 -0
  109. package/dist/update-check-QnrVR3q1.mjs +11 -0
  110. package/dist/utils-8lzafE49.mjs +7 -0
  111. package/dist/utils-ej6_SjIZ.cjs +7 -0
  112. package/dist/virtual-modules-Ca5tHk1X.cjs +30 -0
  113. package/dist/virtual-modules-Dlgt1fP0.mjs +30 -0
  114. package/package.json +18 -16
  115. package/src/shared/mdx-path.ts +12 -0
  116. package/src/shared/structured-data.ts +145 -0
  117. package/src/shared/types.ts +220 -16
  118. package/dist/banner-BMop1KLF.d.ts +0 -100
  119. package/dist/banner-CVD0GugR.d.cts +0 -100
  120. package/dist/cache-CO4Dy2uQ.cjs +0 -6
  121. package/dist/cache-Dk53iOo6.mjs +0 -6
  122. package/dist/config-CCXp3aXO.mjs +0 -7
  123. package/dist/config-CMd4XoFq.cjs +0 -6
  124. package/dist/config-DlGoEM9D.cjs +0 -7
  125. package/dist/csp-CRp_3U7a.cjs +0 -6
  126. package/dist/csp-oTC2ygvF.mjs +0 -6
  127. package/dist/doctor-Bv16QSrI.cjs +0 -7
  128. package/dist/doctor-DOAbSaiL.mjs +0 -7
  129. package/dist/headers-Ddwek8K7.mjs +0 -6
  130. package/dist/headers-dg4SDrjY.cjs +0 -6
  131. package/dist/link-2PzgTnaP.js +0 -673
  132. package/dist/meta-loader-C4Hu9RN9.mjs +0 -6
  133. package/dist/meta-loader-Dq1zcFnh.cjs +0 -6
  134. package/dist/node-B5hu_6qj.cjs +0 -104
  135. package/dist/node-BXtqM1uH.mjs +0 -6
  136. package/dist/node-C8725aw7.mjs +0 -104
  137. package/dist/node-aD1eisrR.cjs +0 -6
  138. package/dist/pages-external-BYa4JSda.mjs +0 -6
  139. package/dist/pages-external-XkYIs-d5.cjs +0 -6
  140. package/dist/parser-DCiEWkSk.cjs +0 -8
  141. package/dist/parser-qk9FIHJ7.mjs +0 -8
  142. package/dist/plugin-CX1OZ6jB.cjs +0 -73
  143. package/dist/plugin-CgfiWaFZ.mjs +0 -73
  144. package/dist/routes-BW6zsk7Z.mjs +0 -6
  145. package/dist/routes-BgoIB5wb.cjs +0 -6
  146. package/dist/routes-CORVxc02.cjs +0 -6
  147. package/dist/search-dialog-BRFno7HD.cjs +0 -330
  148. package/dist/search-dialog-BmxHiKwt.js +0 -312
  149. package/dist/shiki-adapter-CoQ6jyJ4.cjs +0 -6
  150. package/dist/shiki-adapter-D-aKw7PP.mjs +0 -6
  151. package/dist/utils-Crm9oPcV.mjs +0 -7
  152. package/dist/utils-D6Xtj0FZ.cjs +0 -7
  153. /package/dist/{errors-0zGHRLue.mjs → errors-N-b6Sn2G.mjs} +0 -0
  154. /package/dist/{index-1KsTDq4o.d.mts → index-lFoyzCXy.d.mts} +0 -0
  155. /package/dist/{types-generator-BXhv7Ill.cjs → types-generator-DDSA93P3.cjs} +0 -0
  156. /package/dist/{types-generator-bDPvUztF.mjs → types-generator-DG1GX1EZ.mjs} +0 -0
@@ -0,0 +1,501 @@
1
+ /**
2
+ * Boltdocs - https://boltdocs.vercel.app
3
+ * Copyright (c) 2026 Jesus Alcala
4
+ * Licensed under the MIT License.
5
+ */
6
+ import { R as Search, V as X, W as useConfig, l as useRoutesContext, o as cn, q as useBoltdocsContext, u as normalizePath } from "./link-CgdI6O2o.js";
7
+ import { E as useLocation, O as useNavigate } from "./router-CZBxMRAH.js";
8
+ import { i as ErrorBoundary, n as Navbar, t as SearchDialog$1 } from "./search-dialog-BqkzDTq2.js";
9
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
10
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
11
+ import { Index } from "flexsearch";
12
+ import fetchSearchData from "virtual:boltdocs-search";
13
+
14
+ //#region src/client/hooks/use-routes.ts
15
+ /**
16
+ * Hook to access the framework's routing state.
17
+ * Returns both the complete set of routes and a filtered list based on the current
18
+ * version and locale.
19
+ */
20
+ function useRoutes() {
21
+ const routeContext = useRoutesContext();
22
+ const allRoutes = routeContext.routes;
23
+ const routeIndex = routeContext.index || {
24
+ byPath: new Map(allRoutes.map((route) => [normalizePath(route.path), route])),
25
+ hintsByPath: /* @__PURE__ */ new Map(),
26
+ collectionNames: []
27
+ };
28
+ const config = useConfig();
29
+ const location = useLocation();
30
+ const { pathname } = location;
31
+ const { currentLocale: currentLocaleStore, currentVersion: currentVersionStore } = useBoltdocsContext();
32
+ const currentPath = normalizePath(pathname);
33
+ const currentRoute = routeIndex.byPath.get(currentPath);
34
+ const pathParts = pathname.split("/").filter(Boolean);
35
+ const urlLocale = config.i18n ? pathParts.find((part) => Array.isArray(config.i18n?.locales) ? config.i18n?.locales.includes(part) : part in (config.i18n?.locales || {})) : void 0;
36
+ const currentLocale = config.i18n ? urlLocale || currentLocaleStore || config.i18n.defaultLocale : void 0;
37
+ const configuredVersions = config.versions?.versions || [];
38
+ const currentVersion = config.versions ? configuredVersions.some((version) => version.path === currentVersionStore) ? currentVersionStore : config.versions.defaultVersion : void 0;
39
+ const routes = useMemo(() => {
40
+ if (!allRoutes) return [];
41
+ const alternateCounts = /* @__PURE__ */ new Map();
42
+ const defaultLocale = config.i18n?.defaultLocale || "";
43
+ const defaultVersion = config.versions?.defaultVersion || "";
44
+ for (const r of allRoutes) {
45
+ const locale = r.locale || defaultLocale;
46
+ const version = r.version || defaultVersion;
47
+ const key = `${r.filePath}::${locale}::${version}`;
48
+ alternateCounts.set(key, (alternateCounts.get(key) || 0) + 1);
49
+ }
50
+ return allRoutes.filter((r) => {
51
+ const localeMatch = config.i18n ? (r.locale || config.i18n.defaultLocale) === currentLocale : true;
52
+ const versionMatch = config.versions ? (r.version || config.versions.defaultVersion) === currentVersion : true;
53
+ if (!(localeMatch && versionMatch)) return false;
54
+ const pathParts = pathname.split("/").filter(Boolean);
55
+ const isCurrentLocalePrefixed = !!(config.i18n && pathParts.includes(currentLocaleStore || config.i18n.defaultLocale));
56
+ const isCurrentVersionPrefixed = !!(config.versions && !!currentVersion && pathParts.includes(currentVersion));
57
+ const isRouteLocalePrefixed = !!r.locale;
58
+ const isRouteVersionPrefixed = !!r.version;
59
+ const locale = r.locale || defaultLocale;
60
+ const version = r.version || defaultVersion;
61
+ const key = `${r.filePath}::${locale}::${version}`;
62
+ if ((alternateCounts.get(key) || 0) > 1) {
63
+ const localeMismatch = config.i18n && isCurrentLocalePrefixed !== isRouteLocalePrefixed;
64
+ const versionMismatch = config.versions && isCurrentVersionPrefixed !== isRouteVersionPrefixed;
65
+ if (localeMismatch || versionMismatch) return false;
66
+ }
67
+ return true;
68
+ });
69
+ }, [
70
+ allRoutes,
71
+ config,
72
+ pathname,
73
+ currentLocale,
74
+ currentVersion,
75
+ currentLocaleStore
76
+ ]);
77
+ const collections = useMemo(() => new Set(routeIndex.collectionNames), [routeIndex.collectionNames]);
78
+ return {
79
+ routes,
80
+ allRoutes,
81
+ currentRoute,
82
+ isCollectionPage: !!currentRoute?.collection || location.pathname.split("/").filter(Boolean).some((segment) => collections.has(segment.toLowerCase())),
83
+ currentLocale,
84
+ currentVersion
85
+ };
86
+ }
87
+
88
+ //#endregion
89
+ //#region src/client/components/internal/error-boundary.tsx
90
+ function InternalFallback({ error, resetErrorBoundary, className }) {
91
+ return /* @__PURE__ */ jsxs("div", {
92
+ role: "alert",
93
+ className: cn("p-2 font-mono flex flex-col items-center justify-between min-h-[30vh]", className),
94
+ children: [
95
+ /* @__PURE__ */ jsx("p", {
96
+ className: "text-lg font-semibold text-danger-500",
97
+ children: "Something went wrong"
98
+ }),
99
+ error?.message && /* @__PURE__ */ jsx("pre", {
100
+ className: "text-sm mt-2 max-w-md overflow-auto whitespace-pre-wrap break-word",
101
+ children: error.message
102
+ }),
103
+ error?.stack && /* @__PURE__ */ jsxs("details", {
104
+ className: "mt-2 max-w-md text-left text-xs",
105
+ children: [/* @__PURE__ */ jsx("summary", {
106
+ className: "cursor-pointer text-muted select-none outline-none",
107
+ children: "Error details"
108
+ }), /* @__PURE__ */ jsx("pre", {
109
+ className: "mt-2 p-2 bg-soft rounded border-subtle border overflow-auto max-h-48 whitespace-pre-wrap break-words",
110
+ children: error.stack
111
+ })]
112
+ }),
113
+ /* @__PURE__ */ jsxs("div", {
114
+ className: "flex items-center gap-2 mt-2",
115
+ children: [/* @__PURE__ */ jsx("button", {
116
+ type: "button",
117
+ onClick: resetErrorBoundary,
118
+ className: "px-2 py-3 bg-soft rounded border-subtle border font-mono font-semibold text-body hover:scale-105 transition-transform active:scale-95 cursor-pointer",
119
+ children: "Try again"
120
+ }), typeof window !== "undefined" && /* @__PURE__ */ jsx("button", {
121
+ type: "button",
122
+ onClick: () => window.location.reload(),
123
+ className: "px-2 py-3 rounded font-mono font-semibold text-muted hover:text-body transition-colors cursor-pointer",
124
+ children: "Reload page"
125
+ })]
126
+ })
127
+ ]
128
+ });
129
+ }
130
+ function InternalErrorBoundary({ children, fallback, resetKeys }) {
131
+ return /* @__PURE__ */ jsx(ErrorBoundary, {
132
+ fallback,
133
+ resetKeys,
134
+ FallbackComponent: !fallback ? InternalFallback : void 0,
135
+ children
136
+ });
137
+ }
138
+
139
+ //#endregion
140
+ //#region src/client/hooks/use-search.ts
141
+ function useSearch(routes) {
142
+ const { currentLocale, currentVersion } = useRoutes();
143
+ const config = useConfig();
144
+ const algoliaConfig = config.integrations?.search?.algolia;
145
+ const [isOpen, setIsOpen] = useState(false);
146
+ const [query, setQuery] = useState("");
147
+ const [index, setIndex] = useState(null);
148
+ const [algoliaResults, setAlgoliaResults] = useState([]);
149
+ const [searchData, setSearchData] = useState([]);
150
+ const [searchDataLoading, setSearchDataLoading] = useState(false);
151
+ const [searchDataError, setSearchDataError] = useState(null);
152
+ const searchGeneration = useRef(0);
153
+ const loadingGeneration = useRef(null);
154
+ const navigate = useNavigate();
155
+ useEffect(() => {
156
+ if (algoliaConfig || !isOpen) return;
157
+ if (searchData.length > 0) return;
158
+ setSearchDataLoading(true);
159
+ setSearchDataError(null);
160
+ let active = true;
161
+ const generation = ++searchGeneration.current;
162
+ loadingGeneration.current = generation;
163
+ fetchSearchData().then((data) => {
164
+ if (!active || generation !== searchGeneration.current) return;
165
+ setSearchData(data || []);
166
+ if (loadingGeneration.current === generation) {
167
+ loadingGeneration.current = null;
168
+ setSearchDataLoading(false);
169
+ }
170
+ }).catch((err) => {
171
+ if (!active || generation !== searchGeneration.current) return;
172
+ console.error("[boltdocs] Failed to load search index:", err);
173
+ setSearchDataError(err);
174
+ if (loadingGeneration.current === generation) {
175
+ loadingGeneration.current = null;
176
+ setSearchDataLoading(false);
177
+ }
178
+ });
179
+ return () => {
180
+ active = false;
181
+ };
182
+ }, [
183
+ isOpen,
184
+ algoliaConfig,
185
+ searchData.length
186
+ ]);
187
+ useEffect(() => {
188
+ if (!import.meta.hot) return;
189
+ const applyFrontmatterDelta = (payload) => {
190
+ const updated = payload.search?.updated ?? [];
191
+ const deleted = new Set(payload.search?.deleted ?? []);
192
+ searchGeneration.current += 1;
193
+ if (loadingGeneration.current !== null) {
194
+ loadingGeneration.current = null;
195
+ setSearchDataLoading(false);
196
+ }
197
+ setSearchData((prev) => {
198
+ const map = new Map(prev.map((d) => [d.id, d]));
199
+ for (const doc of updated) map.set(doc.id, doc);
200
+ for (const id of deleted) map.delete(id);
201
+ return Array.from(map.values());
202
+ });
203
+ setIndex(null);
204
+ };
205
+ const refreshFromAsset = async () => {
206
+ const generation = ++searchGeneration.current;
207
+ loadingGeneration.current = generation;
208
+ setSearchDataLoading(true);
209
+ try {
210
+ const data = await fetchSearchData({ bustCache: true });
211
+ if (generation !== searchGeneration.current) return;
212
+ setSearchData(data || []);
213
+ setSearchDataError(null);
214
+ setIndex(null);
215
+ } catch (error) {
216
+ if (generation !== searchGeneration.current) return;
217
+ console.error("[boltdocs] Failed to refresh search index:", error);
218
+ setSearchDataError(error instanceof Error ? error : new Error(String(error)));
219
+ } finally {
220
+ if (generation === searchGeneration.current) {
221
+ loadingGeneration.current = null;
222
+ setSearchDataLoading(false);
223
+ }
224
+ }
225
+ };
226
+ const hot = import.meta.hot;
227
+ hot.on("boltdocs:frontmatter-update", applyFrontmatterDelta);
228
+ hot.on("boltdocs:mdx-update", refreshFromAsset);
229
+ return () => {
230
+ hot.off?.("boltdocs:frontmatter-update", applyFrontmatterDelta);
231
+ hot.off?.("boltdocs:mdx-update", refreshFromAsset);
232
+ };
233
+ }, []);
234
+ useEffect(() => {
235
+ const handleKeyDown = (e) => {
236
+ if ((/Mac/.test(navigator.userAgent) ? e.metaKey : e.ctrlKey) && (e.key === "k" || e.key === "j")) {
237
+ e.preventDefault();
238
+ setIsOpen((prev) => !prev);
239
+ }
240
+ };
241
+ window.addEventListener("keydown", handleKeyDown);
242
+ return () => window.removeEventListener("keydown", handleKeyDown);
243
+ }, []);
244
+ const handleSelect = useCallback((key) => {
245
+ const path = String(key);
246
+ if (!path) return;
247
+ setIsOpen(false);
248
+ const url = new URL(path, window.location.origin);
249
+ if (query) url.searchParams.set("hl", query);
250
+ navigate(`${url.pathname}${url.search}${url.hash}`);
251
+ }, [navigate, query]);
252
+ useEffect(() => {
253
+ if (algoliaConfig) return;
254
+ if (!isOpen || searchData.length === 0 || index) return;
255
+ const newIndex = new Index({
256
+ tokenize: "forward",
257
+ cache: true
258
+ });
259
+ for (let i = 0; i < searchData.length; i++) {
260
+ const doc = searchData[i];
261
+ if (!doc) continue;
262
+ newIndex.add(i, `${doc.title} ${doc.content}`);
263
+ }
264
+ setIndex(newIndex);
265
+ }, [
266
+ isOpen,
267
+ index,
268
+ algoliaConfig,
269
+ searchData
270
+ ]);
271
+ useEffect(() => {
272
+ if (!algoliaConfig) return;
273
+ if (!query) {
274
+ setAlgoliaResults([]);
275
+ return;
276
+ }
277
+ const delayDebounceFn = setTimeout(async () => {
278
+ try {
279
+ const url = `https://${algoliaConfig.appId}-dsn.algolia.net/1/indexes/${algoliaConfig.indexName}/query`;
280
+ const facetFilters = [];
281
+ if (currentLocale) facetFilters.push(`lang:${currentLocale}`);
282
+ if (currentVersion) facetFilters.push(`version:${currentVersion}`);
283
+ let params = `query=${encodeURIComponent(query)}&hitsPerPage=20`;
284
+ if (facetFilters.length > 0) params += `&facetFilters=${encodeURIComponent(JSON.stringify(facetFilters))}`;
285
+ const response = await fetch(url, {
286
+ method: "POST",
287
+ headers: {
288
+ "Content-Type": "application/json",
289
+ "X-Algolia-API-Key": algoliaConfig.apiKey,
290
+ "X-Algolia-Application-Id": algoliaConfig.appId
291
+ },
292
+ body: JSON.stringify({ params })
293
+ });
294
+ if (!response.ok) throw new Error(`Algolia search request failed: ${response.statusText}`);
295
+ setAlgoliaResults(((await response.json()).hits || []).map((hit) => {
296
+ let path = hit.url || "";
297
+ try {
298
+ if (path.startsWith("http://") || path.startsWith("https://")) {
299
+ const urlObj = new URL(path);
300
+ path = urlObj.pathname + urlObj.search + urlObj.hash;
301
+ }
302
+ } catch {}
303
+ const hierarchy = hit.hierarchy || {};
304
+ const levels = [
305
+ hierarchy.lvl0,
306
+ hierarchy.lvl1,
307
+ hierarchy.lvl2,
308
+ hierarchy.lvl3,
309
+ hierarchy.lvl4,
310
+ hierarchy.lvl5,
311
+ hierarchy.lvl6
312
+ ].filter(Boolean);
313
+ const title = levels[levels.length - 1] || "Documentation";
314
+ const bio = levels.join(" > ");
315
+ return {
316
+ id: hit.objectID || path,
317
+ title,
318
+ path,
319
+ bio,
320
+ groupTitle: hierarchy.lvl0 || "Docs",
321
+ isHeading: !!hit.anchor || path.includes("#")
322
+ };
323
+ }));
324
+ } catch (err) {
325
+ console.error("Error fetching search results from Algolia:", err);
326
+ }
327
+ }, 250);
328
+ return () => clearTimeout(delayDebounceFn);
329
+ }, [
330
+ query,
331
+ algoliaConfig,
332
+ currentLocale,
333
+ currentVersion
334
+ ]);
335
+ return {
336
+ isOpen,
337
+ setIsOpen,
338
+ query,
339
+ setQuery,
340
+ list: useMemo(() => {
341
+ if (!query) return routes.filter((r) => {
342
+ const routeLocale = r.locale || config.i18n?.defaultLocale;
343
+ const routeVersion = r.version || config.versions?.defaultVersion;
344
+ return (!currentLocale || routeLocale === currentLocale) && (!currentVersion || routeVersion === currentVersion);
345
+ }).slice(0, 10).map((r) => ({
346
+ id: r.path,
347
+ title: r.title,
348
+ path: r.path,
349
+ bio: r.description || "",
350
+ groupTitle: r.groupTitle
351
+ }));
352
+ if (algoliaConfig) return algoliaResults;
353
+ if (!index) return [];
354
+ const searchResults = index.search(query, {
355
+ limit: 20,
356
+ suggest: true
357
+ });
358
+ const results = [];
359
+ const seen = /* @__PURE__ */ new Set();
360
+ for (const id of searchResults) {
361
+ const doc = searchData[typeof id === "number" ? id : Number(id)];
362
+ if (!doc) continue;
363
+ const docLocale = doc.locale || config.i18n?.defaultLocale;
364
+ const docVersion = doc.version || config.versions?.defaultVersion;
365
+ const localeMatch = !currentLocale || docLocale === currentLocale || !doc.locale && currentLocale === config.i18n?.defaultLocale;
366
+ if (!(!currentVersion || docVersion === currentVersion)) continue;
367
+ if (seen.has(doc.url)) continue;
368
+ seen.add(doc.url);
369
+ results.push({
370
+ id: doc.url,
371
+ title: doc.title,
372
+ path: doc.url,
373
+ bio: doc.display,
374
+ groupTitle: doc.display.split(" > ")[0],
375
+ isHeading: doc.url.includes("#"),
376
+ localeMatch
377
+ });
378
+ }
379
+ return results.filter((result) => result.localeMatch).slice(0, 10);
380
+ }, [
381
+ query,
382
+ index,
383
+ currentLocale,
384
+ currentVersion,
385
+ routes,
386
+ searchData,
387
+ algoliaConfig,
388
+ algoliaResults,
389
+ config
390
+ ]),
391
+ searchDataLoading,
392
+ searchDataError,
393
+ handleSelect,
394
+ input: {
395
+ value: query,
396
+ onChange: (e) => setQuery(e.target.value)
397
+ }
398
+ };
399
+ }
400
+
401
+ //#endregion
402
+ //#region src/client/components/ui-base/search-dialog.tsx
403
+ function Highlight({ text, query, markClassName }) {
404
+ if (!query || !text) return /* @__PURE__ */ jsx(Fragment$1, { children: text });
405
+ const escapedQuery = query.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
406
+ const regex = new RegExp(`(${escapedQuery})`, "gi");
407
+ return /* @__PURE__ */ jsx(Fragment$1, { children: text.split(regex).map((part, i) => regex.test(part) ? /* @__PURE__ */ jsx("mark", {
408
+ className: cn("bg-primary-500/20 text-primary-600 dark:text-primary-400 font-bold px-0.5 rounded-sm", markClassName),
409
+ children: part
410
+ }, i) : part) });
411
+ }
412
+ function SearchDialog({ routes, className, markClassName }) {
413
+ const { isOpen, setIsOpen, query, setQuery, list, searchDataLoading, searchDataError, handleSelect } = useSearch(routes);
414
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
415
+ /* @__PURE__ */ jsxs(Navbar.SearchTrigger.Desktop, {
416
+ onPress: () => setIsOpen(true),
417
+ className: "rounded-xl border border-subtle bg-surface text-muted transition-all duration-200 hover:border-primary-500/50 hover:text-body hover:bg-soft/50 hover:shadow-sm active:scale-[0.98] focus-visible:ring-2 focus-visible:ring-primary-500/30",
418
+ children: [/* @__PURE__ */ jsxs("div", {
419
+ className: "flex items-center gap-2",
420
+ children: [/* @__PURE__ */ jsx(Search, { size: 16 }), /* @__PURE__ */ jsx("span", {
421
+ className: "hidden sm:inline-block",
422
+ children: "Search docs..."
423
+ })]
424
+ }), /* @__PURE__ */ jsx(Navbar.SearchTrigger.Kbd, { className: "[&_kbd]:bg-main [&_kbd]:border [&_kbd]:border-subtle [&_kbd]:rounded [&_kbd]:px-1.5 [&_kbd]:h-5 [&_kbd]:w-5" })]
425
+ }),
426
+ /* @__PURE__ */ jsx(Navbar.SearchTrigger.Mobile, {
427
+ onPress: () => setIsOpen(true),
428
+ className: "rounded-xl text-muted transition-all duration-200 hover:text-body active:scale-95 focus-visible:ring-2 focus-visible:ring-primary-500/30",
429
+ children: /* @__PURE__ */ jsx(Search, { size: 20 })
430
+ }),
431
+ /* @__PURE__ */ jsx(InternalErrorBoundary, { children: /* @__PURE__ */ jsx(SearchDialog$1.Overlay, {
432
+ isOpen,
433
+ isDismissable: true,
434
+ onOpenChange: () => setIsOpen(false),
435
+ className: cn("fixed inset-0 z-100 flex items-center justify-center p-4 bg-black/40 backdrop-blur-xs animate-fade-in", className),
436
+ children: /* @__PURE__ */ jsx(SearchDialog$1.Content, {
437
+ className: "w-full max-w-lg bg-main border border-subtle shadow-md rounded-2xl overflow-hidden p-6",
438
+ children: /* @__PURE__ */ jsx(SearchDialog$1.Dialog, {
439
+ "aria-label": "Search documentation",
440
+ className: "flex flex-col min-h-0 h-[450px]",
441
+ children: /* @__PURE__ */ jsxs(SearchDialog$1.Autocomplete, {
442
+ className: "flex flex-col min-h-0",
443
+ children: [/* @__PURE__ */ jsxs(SearchDialog$1.Input, {
444
+ value: query,
445
+ onChange: setQuery,
446
+ className: "flex items-center gap-2 border border-subtle bg-surface px-4 py-2.5 rounded-xl focus-within:border-primary-500 mb-4",
447
+ children: [/* @__PURE__ */ jsx(SearchDialog$1.Input.SearchInput, {
448
+ placeholder: "Search documentation...",
449
+ className: "w-full bg-transparent outline-none text-body text-sm"
450
+ }), query && /* @__PURE__ */ jsx(SearchDialog$1.Input.Button, {
451
+ onPress: () => setQuery(""),
452
+ className: "text-muted hover:text-body hover:bg-surface rounded-md p-1 cursor-pointer select-none transition-colors",
453
+ children: /* @__PURE__ */ jsx(X, { size: 16 })
454
+ })]
455
+ }), searchDataLoading ? /* @__PURE__ */ jsx("div", {
456
+ className: "flex flex-1 items-center justify-center px-4 py-8 text-sm text-muted",
457
+ children: "Loading search index…"
458
+ }) : searchDataError ? /* @__PURE__ */ jsx("div", {
459
+ className: "flex flex-1 items-center justify-center px-4 py-8 text-center text-sm text-muted",
460
+ children: "Search is temporarily unavailable."
461
+ }) : query && list.length === 0 ? /* @__PURE__ */ jsx("div", {
462
+ className: "flex flex-1 items-center justify-center px-4 py-8 text-sm text-muted",
463
+ children: "No results found."
464
+ }) : /* @__PURE__ */ jsx(SearchDialog$1.List, {
465
+ items: list,
466
+ onAction: handleSelect,
467
+ children: (item) => /* @__PURE__ */ jsxs(SearchDialog$1.Item, {
468
+ textValue: item.title,
469
+ className: "flex items-center gap-3 px-4 py-2 rounded-xl group dark:hover:bg-primary-300/40 hover:bg-primary-200/50 transition-colors duration-100",
470
+ children: [/* @__PURE__ */ jsx(SearchDialog$1.Item.Icon, {
471
+ isHeading: item.isHeading,
472
+ className: "text-muted group-hover:text-primary-500 group-focus:text-primary-500"
473
+ }), /* @__PURE__ */ jsxs("div", {
474
+ className: "flex flex-col justify-center min-w-0",
475
+ children: [/* @__PURE__ */ jsx(SearchDialog$1.Item.Title, {
476
+ className: "text-sm font-medium text-body truncate dark:group-hover:text-primary-100",
477
+ children: /* @__PURE__ */ jsx(Highlight, {
478
+ text: item.title,
479
+ query,
480
+ markClassName
481
+ })
482
+ }), /* @__PURE__ */ jsx(SearchDialog$1.Item.Bio, {
483
+ className: "text-xs text-muted truncate",
484
+ children: /* @__PURE__ */ jsx(Highlight, {
485
+ text: item.bio,
486
+ query,
487
+ markClassName
488
+ })
489
+ })]
490
+ })]
491
+ }, item.id)
492
+ })]
493
+ })
494
+ })
495
+ })
496
+ }) })
497
+ ] });
498
+ }
499
+
500
+ //#endregion
501
+ export { useRoutes as i, useSearch as n, InternalErrorBoundary as r, SearchDialog as t };
@@ -3,6 +3,6 @@
3
3
  * Copyright (c) 2026 Jesus Alcala
4
4
  * Licensed under the MIT License.
5
5
  */
6
- const require_search_dialog = require('./search-dialog-BRFno7HD.cjs');
6
+ const require_search_dialog = require('./search-dialog-D3jtaw6w.cjs');
7
7
 
8
8
  exports.SearchDialog = require_search_dialog.SearchDialog;
@@ -3,6 +3,6 @@
3
3
  * Copyright (c) 2026 Jesus Alcala
4
4
  * Licensed under the MIT License.
5
5
  */
6
- import { t as SearchDialog } from "./search-dialog-BmxHiKwt.js";
6
+ import { t as SearchDialog } from "./search-dialog-DRiXejws.js";
7
7
 
8
8
  export { SearchDialog };