@tomehq/theme 0.4.0 → 0.5.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 (77) hide show
  1. package/CHANGELOG.md +1 -96
  2. package/dist/{chunk-DKSQZLWR.js → chunk-FIUZY65C.js} +74 -5
  3. package/dist/entry.js +1 -1
  4. package/dist/index.d.ts +78 -0
  5. package/dist/index.js +1 -1
  6. package/package.json +3 -3
  7. package/src/Shell.test.tsx +30 -0
  8. package/src/Shell.tsx +2 -2
  9. package/src/entry.tsx +2 -3
  10. package/src/presets.test.ts +4 -2
  11. package/src/presets.ts +30 -0
  12. package/dist/chunk-2APCPR2Y.js +0 -2110
  13. package/dist/chunk-2AXAEADQ.js +0 -2525
  14. package/dist/chunk-2WNOJXK3.js +0 -2581
  15. package/dist/chunk-37JI6XGT.js +0 -1720
  16. package/dist/chunk-3A2LPGUL.js +0 -1991
  17. package/dist/chunk-3I2QTWTW.js +0 -1948
  18. package/dist/chunk-3I4SJMER.js +0 -2538
  19. package/dist/chunk-45M5UIAB.js +0 -2110
  20. package/dist/chunk-462AGU3S.js +0 -1959
  21. package/dist/chunk-5GVQFIPI.js +0 -2581
  22. package/dist/chunk-7MUTU5D4.js +0 -1720
  23. package/dist/chunk-7NQ4IMDY.js +0 -2294
  24. package/dist/chunk-ABNPB6BB.js +0 -2133
  25. package/dist/chunk-BZGWSKT2.js +0 -573
  26. package/dist/chunk-BZIB2LMI.js +0 -2519
  27. package/dist/chunk-CMQCNCSY.js +0 -2127
  28. package/dist/chunk-CTPOZMMK.js +0 -1703
  29. package/dist/chunk-DO544M3G.js +0 -1702
  30. package/dist/chunk-DPKZBFQP.js +0 -1777
  31. package/dist/chunk-EK7PZUEB.js +0 -2147
  32. package/dist/chunk-FMOLIHQF.js +0 -2182
  33. package/dist/chunk-FWBTK5TL.js +0 -1444
  34. package/dist/chunk-GDQIBNX5.js +0 -1962
  35. package/dist/chunk-GHQ2MODM.js +0 -2127
  36. package/dist/chunk-GR2WCRGK.js +0 -2182
  37. package/dist/chunk-H5XZVNBW.js +0 -2291
  38. package/dist/chunk-HNLKDQ64.js +0 -2139
  39. package/dist/chunk-INUMUXN5.js +0 -2095
  40. package/dist/chunk-IW3NHNOQ.js +0 -2187
  41. package/dist/chunk-JA4PMX6M.js +0 -1500
  42. package/dist/chunk-JSPFS7G5.js +0 -2102
  43. package/dist/chunk-JZRT4WNC.js +0 -1441
  44. package/dist/chunk-KQBY2JDB.js +0 -2112
  45. package/dist/chunk-LIMYFTPC.js +0 -1468
  46. package/dist/chunk-LIY62BGC.js +0 -2519
  47. package/dist/chunk-MEP7P6A7.js +0 -1500
  48. package/dist/chunk-MHYKO7KM.js +0 -2570
  49. package/dist/chunk-MSXVVBDW.js +0 -2542
  50. package/dist/chunk-NOZBIES7.js +0 -1948
  51. package/dist/chunk-O4GH3KYX.js +0 -1712
  52. package/dist/chunk-OEDJTH5F.js +0 -2569
  53. package/dist/chunk-OEXM3BEC.js +0 -1702
  54. package/dist/chunk-PGKSFQ7A.js +0 -2459
  55. package/dist/chunk-PIV6CPY2.js +0 -2395
  56. package/dist/chunk-Q7PYTVW3.js +0 -1771
  57. package/dist/chunk-QCWZYABW.js +0 -1468
  58. package/dist/chunk-QYINBNMJ.js +0 -2545
  59. package/dist/chunk-RDF25WB2.js +0 -2085
  60. package/dist/chunk-RKTT3ZEX.js +0 -1500
  61. package/dist/chunk-S47BRMNQ.js +0 -1715
  62. package/dist/chunk-S4ZH5F56.js +0 -1949
  63. package/dist/chunk-SRD7NJHS.js +0 -1949
  64. package/dist/chunk-SWFYJO5H.js +0 -2187
  65. package/dist/chunk-TQDWPSTO.js +0 -2087
  66. package/dist/chunk-TTRXRPP6.js +0 -1941
  67. package/dist/chunk-UKYFJSUA.js +0 -509
  68. package/dist/chunk-VKEQHP2E.js +0 -2133
  69. package/dist/chunk-VUT2FMSI.js +0 -1937
  70. package/dist/chunk-VVCC5JHK.js +0 -1949
  71. package/dist/chunk-W732TVBK.js +0 -1944
  72. package/dist/chunk-X4VQYPKO.js +0 -1768
  73. package/dist/chunk-YX7HV4EP.js +0 -2568
  74. package/dist/chunk-YXKONM3A.js +0 -2192
  75. package/dist/chunk-YZ3P3TNS.js +0 -1760
  76. package/dist/chunk-ZVZ7JN3V.js +0 -2568
  77. package/dist/chunk-ZXW4STTN.js +0 -2568
@@ -1,2519 +0,0 @@
1
- // src/entry.tsx
2
- import { useState as useState3, useEffect as useEffect3, useCallback as useCallback3, useRef as useRef3 } from "react";
3
- import { createRoot } from "react-dom/client";
4
-
5
- // src/Shell.tsx
6
- import React2, { useState as useState2, useEffect as useEffect2, useRef as useRef2, useCallback as useCallback2 } from "react";
7
-
8
- // src/presets.ts
9
- var THEME_PRESETS = {
10
- amber: {
11
- dark: {
12
- bg: "#09090b",
13
- sf: "#111114",
14
- sfH: "#18181c",
15
- bd: "#1e1e24",
16
- tx: "#e4e4e7",
17
- tx2: "#a1a1aa",
18
- txM: "#919199",
19
- ac: "#e8a845",
20
- acD: "rgba(232,168,69,0.12)",
21
- acT: "#fbbf24",
22
- cdBg: "#0c0c0f",
23
- cdTx: "#c4c4cc",
24
- sbBg: "#0c0c0e",
25
- hdBg: "rgba(9,9,11,0.85)"
26
- },
27
- light: {
28
- bg: "#fafaf9",
29
- sf: "#ffffff",
30
- sfH: "#f5f5f4",
31
- bd: "#e7e5e4",
32
- tx: "#1c1917",
33
- tx2: "#57534e",
34
- txM: "#706b66",
35
- ac: "#96640a",
36
- acD: "rgba(150,100,10,0.08)",
37
- acT: "#7a5208",
38
- cdBg: "#f5f3f0",
39
- cdTx: "#2c2520",
40
- sbBg: "#f5f5f3",
41
- hdBg: "rgba(250,250,249,0.85)"
42
- },
43
- fonts: { heading: "Instrument Serif", body: "DM Sans", code: "JetBrains Mono" }
44
- },
45
- editorial: {
46
- dark: {
47
- bg: "#080c1f",
48
- sf: "#0e1333",
49
- sfH: "#141940",
50
- bd: "#1a2050",
51
- tx: "#e8e6f0",
52
- tx2: "#b5b1c8",
53
- txM: "#9490ae",
54
- ac: "#ff6b4a",
55
- acD: "rgba(255,107,74,0.1)",
56
- acT: "#ff8a70",
57
- cdBg: "#0a0e27",
58
- cdTx: "#b8b4cc",
59
- sbBg: "#0a0e27",
60
- hdBg: "rgba(8,12,31,0.9)"
61
- },
62
- light: {
63
- bg: "#f6f4f0",
64
- sf: "#ffffff",
65
- sfH: "#eeece6",
66
- bd: "#ddd9d0",
67
- tx: "#1a1716",
68
- tx2: "#4a443e",
69
- txM: "#706960",
70
- ac: "#b83d22",
71
- acD: "rgba(184,61,34,0.07)",
72
- acT: "#9c3019",
73
- cdBg: "#edeae4",
74
- cdTx: "#3a3530",
75
- sbBg: "#f0ede8",
76
- hdBg: "rgba(246,244,240,0.92)"
77
- },
78
- fonts: { heading: "Cormorant Garamond", body: "Bricolage Grotesque", code: "Fira Code" }
79
- }
80
- };
81
-
82
- // src/AiChat.tsx
83
- import { useState, useRef, useEffect, useCallback } from "react";
84
- import { jsx, jsxs } from "react/jsx-runtime";
85
- var ChatIcon = () => /* @__PURE__ */ jsx(
86
- "svg",
87
- {
88
- width: 22,
89
- height: 22,
90
- viewBox: "0 0 24 24",
91
- fill: "none",
92
- stroke: "currentColor",
93
- strokeWidth: "1.5",
94
- strokeLinecap: "round",
95
- strokeLinejoin: "round",
96
- children: /* @__PURE__ */ jsx("path", { d: "M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" })
97
- }
98
- );
99
- var CloseIcon = () => /* @__PURE__ */ jsx(
100
- "svg",
101
- {
102
- width: 18,
103
- height: 18,
104
- viewBox: "0 0 24 24",
105
- fill: "none",
106
- stroke: "currentColor",
107
- strokeWidth: "1.5",
108
- strokeLinecap: "round",
109
- strokeLinejoin: "round",
110
- children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" })
111
- }
112
- );
113
- var SendIcon = () => /* @__PURE__ */ jsx(
114
- "svg",
115
- {
116
- width: 16,
117
- height: 16,
118
- viewBox: "0 0 24 24",
119
- fill: "none",
120
- stroke: "currentColor",
121
- strokeWidth: "2",
122
- strokeLinecap: "round",
123
- strokeLinejoin: "round",
124
- children: /* @__PURE__ */ jsx("path", { d: "M22 2L11 13M22 2l-7 20-4-9-9-4z" })
125
- }
126
- );
127
- function buildSystemPrompt(context) {
128
- let prompt = "You are a helpful documentation assistant. Answer questions accurately based on the documentation provided below. If the answer isn't in the documentation, say so clearly. Keep answers concise and reference specific sections when possible.";
129
- if (context) {
130
- const trimmed = context.length > 1e5 ? context.slice(0, 1e5) + "\n\n[Documentation truncated...]" : context;
131
- prompt += `
132
-
133
- Documentation:
134
- ${trimmed}`;
135
- }
136
- return prompt;
137
- }
138
- async function callOpenAI(messages, apiKey, model, context) {
139
- const res = await fetch("https://api.openai.com/v1/chat/completions", {
140
- method: "POST",
141
- headers: {
142
- "Content-Type": "application/json",
143
- "Authorization": `Bearer ${apiKey}`
144
- },
145
- body: JSON.stringify({
146
- model,
147
- messages: [
148
- { role: "system", content: buildSystemPrompt(context) },
149
- ...messages.map((m) => ({ role: m.role, content: m.content }))
150
- ]
151
- })
152
- });
153
- if (!res.ok) {
154
- const err = await res.text();
155
- throw new Error(`OpenAI API error (${res.status}): ${err}`);
156
- }
157
- const data = await res.json();
158
- return data.choices?.[0]?.message?.content || "No response.";
159
- }
160
- async function callAnthropic(messages, apiKey, model, context) {
161
- const res = await fetch("https://api.anthropic.com/v1/messages", {
162
- method: "POST",
163
- headers: {
164
- "Content-Type": "application/json",
165
- "x-api-key": apiKey,
166
- "anthropic-version": "2023-06-01",
167
- "anthropic-dangerous-direct-browser-access": "true"
168
- },
169
- body: JSON.stringify({
170
- model,
171
- max_tokens: 1024,
172
- system: buildSystemPrompt(context),
173
- messages: messages.map((m) => ({ role: m.role, content: m.content }))
174
- })
175
- });
176
- if (!res.ok) {
177
- const err = await res.text();
178
- throw new Error(`Anthropic API error (${res.status}): ${err}`);
179
- }
180
- const data = await res.json();
181
- return data.content?.[0]?.text || "No response.";
182
- }
183
- function getDefaultModel(provider) {
184
- if (provider === "openai") return "gpt-4o-mini";
185
- return "claude-sonnet-4-20250514";
186
- }
187
- function AiChat({ provider, model, apiKey, context }) {
188
- const [open, setOpen] = useState(false);
189
- const [messages, setMessages] = useState([]);
190
- const [input, setInput] = useState("");
191
- const [loading, setLoading] = useState(false);
192
- const [error, setError] = useState(null);
193
- const messagesEndRef = useRef(null);
194
- const inputRef = useRef(null);
195
- const resolvedKey = apiKey || (typeof window !== "undefined" ? window.__TOME_AI_API_KEY__ : void 0);
196
- const resolvedModel = model || getDefaultModel(provider);
197
- useEffect(() => {
198
- messagesEndRef.current?.scrollIntoView({ behavior: "smooth" });
199
- }, [messages]);
200
- useEffect(() => {
201
- if (open) {
202
- setTimeout(() => inputRef.current?.focus(), 100);
203
- }
204
- }, [open]);
205
- const sendMessage = useCallback(async () => {
206
- const text = input.trim();
207
- if (!text || loading) return;
208
- if (!resolvedKey) return;
209
- const userMsg = { role: "user", content: text };
210
- const updatedMessages = [...messages, userMsg];
211
- setMessages(updatedMessages);
212
- setInput("");
213
- setLoading(true);
214
- setError(null);
215
- try {
216
- let response;
217
- if (provider === "openai") {
218
- response = await callOpenAI(updatedMessages, resolvedKey, resolvedModel, context);
219
- } else {
220
- response = await callAnthropic(updatedMessages, resolvedKey, resolvedModel, context);
221
- }
222
- setMessages((prev) => [...prev, { role: "assistant", content: response }]);
223
- } catch (err) {
224
- setError(err instanceof Error ? err.message : "Failed to get response");
225
- } finally {
226
- setLoading(false);
227
- }
228
- }, [input, loading, messages, provider, resolvedKey, resolvedModel, context]);
229
- const handleKeyDown = useCallback(
230
- (e) => {
231
- if (e.key === "Enter" && !e.shiftKey) {
232
- e.preventDefault();
233
- sendMessage();
234
- }
235
- },
236
- [sendMessage]
237
- );
238
- if (!open) {
239
- return /* @__PURE__ */ jsx(
240
- "button",
241
- {
242
- "data-testid": "ai-chat-button",
243
- onClick: () => setOpen(true),
244
- "aria-label": "Open AI chat",
245
- style: {
246
- position: "fixed",
247
- bottom: 24,
248
- right: 24,
249
- zIndex: 900,
250
- width: 48,
251
- height: 48,
252
- borderRadius: "50%",
253
- background: "var(--ac)",
254
- color: "#fff",
255
- border: "none",
256
- cursor: "pointer",
257
- display: "flex",
258
- alignItems: "center",
259
- justifyContent: "center",
260
- boxShadow: "0 4px 16px rgba(0,0,0,0.25)",
261
- transition: "transform 0.15s"
262
- },
263
- children: /* @__PURE__ */ jsx(ChatIcon, {})
264
- }
265
- );
266
- }
267
- return /* @__PURE__ */ jsxs(
268
- "div",
269
- {
270
- "data-testid": "ai-chat-panel",
271
- style: {
272
- position: "fixed",
273
- bottom: 24,
274
- right: 24,
275
- zIndex: 900,
276
- width: 380,
277
- maxWidth: "calc(100vw - 48px)",
278
- height: 520,
279
- maxHeight: "calc(100vh - 48px)",
280
- background: "var(--sf)",
281
- border: "1px solid var(--bd)",
282
- borderRadius: 12,
283
- boxShadow: "0 16px 64px rgba(0,0,0,0.3)",
284
- display: "flex",
285
- flexDirection: "column",
286
- overflow: "hidden",
287
- fontFamily: "var(--font-body)"
288
- },
289
- children: [
290
- /* @__PURE__ */ jsxs(
291
- "div",
292
- {
293
- style: {
294
- display: "flex",
295
- alignItems: "center",
296
- justifyContent: "space-between",
297
- padding: "12px 16px",
298
- borderBottom: "1px solid var(--bd)",
299
- flexShrink: 0
300
- },
301
- children: [
302
- /* @__PURE__ */ jsx(
303
- "span",
304
- {
305
- style: {
306
- fontSize: 14,
307
- fontWeight: 600,
308
- color: "var(--tx)"
309
- },
310
- children: "Ask AI"
311
- }
312
- ),
313
- /* @__PURE__ */ jsx(
314
- "button",
315
- {
316
- "data-testid": "ai-chat-close",
317
- onClick: () => setOpen(false),
318
- "aria-label": "Close AI chat",
319
- style: {
320
- background: "none",
321
- border: "none",
322
- color: "var(--txM)",
323
- cursor: "pointer",
324
- display: "flex",
325
- padding: 4
326
- },
327
- children: /* @__PURE__ */ jsx(CloseIcon, {})
328
- }
329
- )
330
- ]
331
- }
332
- ),
333
- /* @__PURE__ */ jsxs(
334
- "div",
335
- {
336
- style: {
337
- flex: 1,
338
- overflow: "auto",
339
- padding: "12px 16px"
340
- },
341
- children: [
342
- !resolvedKey && /* @__PURE__ */ jsxs(
343
- "div",
344
- {
345
- "data-testid": "ai-chat-no-key",
346
- style: {
347
- textAlign: "center",
348
- color: "var(--txM)",
349
- fontSize: 13,
350
- padding: "24px 8px",
351
- lineHeight: 1.6
352
- },
353
- children: [
354
- /* @__PURE__ */ jsx("p", { style: { marginBottom: 8, fontWeight: 500, color: "var(--tx)" }, children: "AI not configured" }),
355
- /* @__PURE__ */ jsxs("p", { style: { marginBottom: 8 }, children: [
356
- "To enable AI chat, set the ",
357
- /* @__PURE__ */ jsx("code", { style: {
358
- fontFamily: "var(--font-code)",
359
- fontSize: "0.88em",
360
- background: "var(--cdBg)",
361
- padding: "0.15em 0.4em",
362
- borderRadius: 4
363
- }, children: "apiKeyEnv" }),
364
- " in ",
365
- /* @__PURE__ */ jsx("code", { style: {
366
- fontFamily: "var(--font-code)",
367
- fontSize: "0.88em",
368
- background: "var(--cdBg)",
369
- padding: "0.15em 0.4em",
370
- borderRadius: 4
371
- }, children: "tome.config.js" }),
372
- " and provide the environment variable at build time."
373
- ] }),
374
- /* @__PURE__ */ jsxs("p", { style: { fontSize: 11.5, color: "var(--txM)" }, children: [
375
- "Example: ",
376
- /* @__PURE__ */ jsx("code", { style: {
377
- fontFamily: "var(--font-code)",
378
- fontSize: "0.88em",
379
- background: "var(--cdBg)",
380
- padding: "0.15em 0.4em",
381
- borderRadius: 4
382
- }, children: "TOME_AI_KEY=sk-... tome build" })
383
- ] })
384
- ]
385
- }
386
- ),
387
- messages.map((msg, i) => /* @__PURE__ */ jsx(
388
- "div",
389
- {
390
- "data-testid": `ai-chat-message-${msg.role}`,
391
- style: {
392
- marginBottom: 12,
393
- display: "flex",
394
- justifyContent: msg.role === "user" ? "flex-end" : "flex-start"
395
- },
396
- children: /* @__PURE__ */ jsx(
397
- "div",
398
- {
399
- style: {
400
- maxWidth: "85%",
401
- padding: "8px 12px",
402
- borderRadius: 10,
403
- fontSize: 13,
404
- lineHeight: 1.55,
405
- whiteSpace: "pre-wrap",
406
- wordBreak: "break-word",
407
- background: msg.role === "user" ? "var(--ac)" : "var(--cdBg)",
408
- color: msg.role === "user" ? "#fff" : "var(--tx)"
409
- },
410
- children: msg.content
411
- }
412
- )
413
- },
414
- i
415
- )),
416
- loading && /* @__PURE__ */ jsx(
417
- "div",
418
- {
419
- "data-testid": "ai-chat-loading",
420
- style: {
421
- display: "flex",
422
- justifyContent: "flex-start",
423
- marginBottom: 12
424
- },
425
- children: /* @__PURE__ */ jsx(
426
- "div",
427
- {
428
- style: {
429
- padding: "8px 12px",
430
- borderRadius: 10,
431
- fontSize: 13,
432
- background: "var(--cdBg)",
433
- color: "var(--txM)"
434
- },
435
- children: "Thinking..."
436
- }
437
- )
438
- }
439
- ),
440
- error && /* @__PURE__ */ jsx(
441
- "div",
442
- {
443
- "data-testid": "ai-chat-error",
444
- style: {
445
- padding: "8px 12px",
446
- borderRadius: 8,
447
- fontSize: 12,
448
- background: "rgba(220,50,50,0.1)",
449
- color: "#d44",
450
- marginBottom: 12
451
- },
452
- children: error
453
- }
454
- ),
455
- /* @__PURE__ */ jsx("div", { ref: messagesEndRef })
456
- ]
457
- }
458
- ),
459
- /* @__PURE__ */ jsxs(
460
- "div",
461
- {
462
- style: {
463
- display: "flex",
464
- alignItems: "center",
465
- gap: 8,
466
- padding: "10px 12px",
467
- borderTop: "1px solid var(--bd)",
468
- flexShrink: 0
469
- },
470
- children: [
471
- /* @__PURE__ */ jsx(
472
- "input",
473
- {
474
- ref: inputRef,
475
- "data-testid": "ai-chat-input",
476
- value: input,
477
- onChange: (e) => setInput(e.target.value),
478
- onKeyDown: handleKeyDown,
479
- placeholder: resolvedKey ? "Ask a question..." : "API key required",
480
- disabled: !resolvedKey,
481
- style: {
482
- flex: 1,
483
- background: "var(--cdBg)",
484
- border: "1px solid var(--bd)",
485
- borderRadius: 8,
486
- padding: "8px 12px",
487
- color: "var(--tx)",
488
- fontSize: 13,
489
- fontFamily: "var(--font-body)",
490
- outline: "none"
491
- }
492
- }
493
- ),
494
- /* @__PURE__ */ jsx(
495
- "button",
496
- {
497
- "data-testid": "ai-chat-send",
498
- onClick: sendMessage,
499
- disabled: !resolvedKey || !input.trim() || loading,
500
- "aria-label": "Send message",
501
- style: {
502
- width: 34,
503
- height: 34,
504
- borderRadius: 8,
505
- background: resolvedKey && input.trim() ? "var(--ac)" : "var(--cdBg)",
506
- color: resolvedKey && input.trim() ? "#fff" : "var(--txM)",
507
- border: "none",
508
- cursor: resolvedKey && input.trim() ? "pointer" : "default",
509
- display: "flex",
510
- alignItems: "center",
511
- justifyContent: "center",
512
- flexShrink: 0
513
- },
514
- children: /* @__PURE__ */ jsx(SendIcon, {})
515
- }
516
- )
517
- ]
518
- }
519
- )
520
- ]
521
- }
522
- );
523
- }
524
-
525
- // src/Shell.tsx
526
- import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
527
- function hexToRgb(hex) {
528
- const m = /^#([0-9a-f]{6})$/i.exec(hex.trim());
529
- if (!m) return null;
530
- const n = parseInt(m[1], 16);
531
- return [n >> 16 & 255, n >> 8 & 255, n & 255];
532
- }
533
- function buildAccentOverride(hex, isDark) {
534
- const rgb = hexToRgb(hex);
535
- if (!rgb) return null;
536
- const [r, g, b] = rgb;
537
- const acD = `rgba(${r},${g},${b},${isDark ? 0.12 : 0.08})`;
538
- const factor = isDark ? 1.15 : 0.85;
539
- const tr = Math.min(255, Math.round(r * factor));
540
- const tg = Math.min(255, Math.round(g * factor));
541
- const tb = Math.min(255, Math.round(b * factor));
542
- const acT = `rgb(${tr},${tg},${tb})`;
543
- return { ac: hex, acD, acT };
544
- }
545
- var Icon = ({ d, size = 16 }) => /* @__PURE__ */ jsx2(
546
- "svg",
547
- {
548
- width: size,
549
- height: size,
550
- viewBox: "0 0 24 24",
551
- fill: "none",
552
- stroke: "currentColor",
553
- strokeWidth: "1.5",
554
- strokeLinecap: "round",
555
- strokeLinejoin: "round",
556
- children: /* @__PURE__ */ jsx2("path", { d })
557
- }
558
- );
559
- var SearchIcon = () => /* @__PURE__ */ jsx2(Icon, { d: "M11 19a8 8 0 1 0 0-16 8 8 0 0 0 0 16ZM21 21l-4.3-4.3" });
560
- var ChevRight = () => /* @__PURE__ */ jsx2(Icon, { d: "M9 18l6-6-6-6", size: 14 });
561
- var ChevDown = () => /* @__PURE__ */ jsx2(Icon, { d: "M6 9l6 6 6-6", size: 14 });
562
- var MenuIcon = () => /* @__PURE__ */ jsx2(Icon, { d: "M3 12h18M3 6h18M3 18h18", size: 20 });
563
- var XIcon = () => /* @__PURE__ */ jsx2(Icon, { d: "M18 6L6 18M6 6l12 12", size: 18 });
564
- var MoonIcon = () => /* @__PURE__ */ jsx2(Icon, { d: "M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z" });
565
- var SunIcon = () => /* @__PURE__ */ jsx2(Icon, { d: "M12 8a4 4 0 1 0 0 8 4 4 0 0 0 0-8Zm0-4a1 1 0 0 1 1-1v-1a1 1 0 0 1-2 0v1a1 1 0 0 1 1 1Zm0 16a1 1 0 0 1 1 1v1a1 1 0 0 1-2 0v-1a1 1 0 0 1 1-1ZM4 12a1 1 0 0 1-1 1H2a1 1 0 0 1 0-2h1a1 1 0 0 1 1 1Zm18-1h-1a1 1 0 0 1 0 2h1a1 1 0 0 1 0-2ZM6.34 6.34a1 1 0 0 1-1.41 0l-.71-.71a1 1 0 0 1 1.41-1.41l.71.71a1 1 0 0 1 0 1.41Zm12.73-2.12-.71.71a1 1 0 0 1-1.41-1.41l.71-.71a1 1 0 1 1 1.41 1.41ZM6.34 17.66l-.71.71a1 1 0 0 1-1.41-1.41l.71-.71a1 1 0 0 1 1.41 1.41Zm12.73 2.12-.71-.71a1 1 0 0 1 1.41-1.41l.71.71a1 1 0 0 1-1.41 1.41Z" });
566
- var ArrowLeft = () => /* @__PURE__ */ jsx2(Icon, { d: "M19 12H5M12 19l-7-7 7-7", size: 14 });
567
- var ArrowRight = () => /* @__PURE__ */ jsx2(Icon, { d: "M5 12h14M12 5l7 7-7 7", size: 14 });
568
- var PencilIcon = () => /* @__PURE__ */ jsx2(Icon, { d: "M17 3a2.83 2.83 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5Z", size: 13 });
569
- function formatRelativeDate(isoDate) {
570
- const date = new Date(isoDate);
571
- const now = /* @__PURE__ */ new Date();
572
- const diffMs = now.getTime() - date.getTime();
573
- if (isNaN(diffMs)) return "";
574
- const seconds = Math.floor(diffMs / 1e3);
575
- const minutes = Math.floor(seconds / 60);
576
- const hours = Math.floor(minutes / 60);
577
- const days = Math.floor(hours / 24);
578
- const months = Math.floor(days / 30);
579
- const years = Math.floor(days / 365);
580
- if (seconds < 60) return "just now";
581
- if (minutes < 60) return `${minutes} minute${minutes === 1 ? "" : "s"} ago`;
582
- if (hours < 24) return `${hours} hour${hours === 1 ? "" : "s"} ago`;
583
- if (days < 30) return `${days} day${days === 1 ? "" : "s"} ago`;
584
- if (months < 12) return `${months} month${months === 1 ? "" : "s"} ago`;
585
- if (years >= 1) return `${years} year${years === 1 ? "" : "s"} ago`;
586
- return date.toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric" });
587
- }
588
- var pagefindInstance = null;
589
- var PAGEFIND_PATH = "/_pagefind/pagefind.js";
590
- async function initPagefind() {
591
- if (pagefindInstance) return pagefindInstance;
592
- try {
593
- pagefindInstance = await import(
594
- /* @vite-ignore */
595
- PAGEFIND_PATH
596
- );
597
- await pagefindInstance.init();
598
- return pagefindInstance;
599
- } catch {
600
- return null;
601
- }
602
- }
603
- var docSearchLoaded = null;
604
- function loadDocSearch() {
605
- if (docSearchLoaded) return docSearchLoaded;
606
- docSearchLoaded = import("@docsearch/react").catch(() => null);
607
- return docSearchLoaded;
608
- }
609
- function AlgoliaSearchModal({
610
- appId,
611
- apiKey,
612
- indexName,
613
- onNavigate,
614
- onClose,
615
- basePath: basePath2 = ""
616
- }) {
617
- const [DocSearchComponent, setDocSearchComponent] = useState2(null);
618
- const [loadFailed, setLoadFailed] = useState2(false);
619
- useEffect2(() => {
620
- loadDocSearch().then((mod) => {
621
- if (mod && mod.DocSearch) {
622
- setDocSearchComponent(() => mod.DocSearch);
623
- } else if (mod && mod.default) {
624
- setDocSearchComponent(() => mod.default);
625
- } else {
626
- setLoadFailed(true);
627
- }
628
- });
629
- }, []);
630
- const extractPageId = useCallback2((url) => {
631
- try {
632
- const parsed = new URL(url, "http://localhost");
633
- let pathname = parsed.pathname;
634
- if (basePath2) {
635
- const bp = basePath2.replace(/\/$/, "");
636
- if (pathname.startsWith(bp)) pathname = pathname.slice(bp.length);
637
- }
638
- return pathname.replace(/^\//, "").replace(/\/index\.html$/, "").replace(/\.html$/, "") || "index";
639
- } catch {
640
- return "index";
641
- }
642
- }, [basePath2]);
643
- if (loadFailed) {
644
- return /* @__PURE__ */ jsx2("div", { onClick: onClose, style: {
645
- position: "fixed",
646
- inset: 0,
647
- zIndex: 1e3,
648
- background: "rgba(0,0,0,0.55)",
649
- backdropFilter: "blur(6px)",
650
- display: "flex",
651
- alignItems: "flex-start",
652
- justifyContent: "center",
653
- paddingTop: "12vh"
654
- }, children: /* @__PURE__ */ jsx2("div", { onClick: (e) => e.stopPropagation(), style: {
655
- background: "var(--sf)",
656
- border: "1px solid var(--bd)",
657
- borderRadius: 12,
658
- width: "100%",
659
- maxWidth: 520,
660
- boxShadow: "0 24px 80px rgba(0,0,0,0.4)",
661
- padding: "32px 18px",
662
- textAlign: "center",
663
- color: "var(--txM)",
664
- fontSize: 14
665
- }, children: "Algolia DocSearch is not available. Install @docsearch/react to enable it." }) });
666
- }
667
- if (!DocSearchComponent) {
668
- return /* @__PURE__ */ jsx2("div", { onClick: onClose, style: {
669
- position: "fixed",
670
- inset: 0,
671
- zIndex: 1e3,
672
- background: "rgba(0,0,0,0.55)",
673
- backdropFilter: "blur(6px)",
674
- display: "flex",
675
- alignItems: "flex-start",
676
- justifyContent: "center",
677
- paddingTop: "12vh"
678
- }, children: /* @__PURE__ */ jsx2("div", { style: {
679
- background: "var(--sf)",
680
- border: "1px solid var(--bd)",
681
- borderRadius: 12,
682
- width: "100%",
683
- maxWidth: 520,
684
- boxShadow: "0 24px 80px rgba(0,0,0,0.4)",
685
- padding: "32px 18px",
686
- textAlign: "center",
687
- color: "var(--txM)",
688
- fontSize: 14
689
- }, children: "Loading search..." }) });
690
- }
691
- return /* @__PURE__ */ jsx2("div", { "data-testid": "algolia-search-modal", children: /* @__PURE__ */ jsx2(
692
- DocSearchComponent,
693
- {
694
- appId,
695
- apiKey,
696
- indexName,
697
- navigator: {
698
- navigate({ itemUrl }) {
699
- const pageId = extractPageId(itemUrl);
700
- onNavigate(pageId);
701
- }
702
- },
703
- hitComponent: ({ hit, children }) => /* @__PURE__ */ jsx2("a", { href: hit.url, onClick: (e) => {
704
- e.preventDefault();
705
- const pageId = extractPageId(hit.url);
706
- onNavigate(pageId);
707
- }, children })
708
- }
709
- ) });
710
- }
711
- var VersionIcon = () => /* @__PURE__ */ jsx2(Icon, { d: "M12 8v4l3 3m6-3a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z", size: 14 });
712
- var GlobeIcon = () => /* @__PURE__ */ jsx2(Icon, { d: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18ZM3.6 9h16.8M3.6 15h16.8M12 3a15 15 0 0 1 4 9 15 15 0 0 1-4 9 15 15 0 0 1-4-9 15 15 0 0 1 4-9Z", size: 14 });
713
- var ExtLinkIcon = () => /* @__PURE__ */ jsx2(Icon, { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3", size: 11 });
714
- var SOCIAL_ICON_PATHS = {
715
- github: "M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z",
716
- twitter: "M12.6.75h2.454l-5.36 6.142L16 15.25h-4.937l-3.867-5.07-4.425 5.07H.316l5.733-6.57L0 .75h5.063l3.495 4.633L12.601.75Zm-.86 13.028h1.36L4.323 2.145H2.865l8.875 11.633Z",
717
- discord: "M13.545 2.907a13.227 13.227 0 00-3.257-1.011.05.05 0 00-.052.025c-.141.25-.297.577-.406.833a12.19 12.19 0 00-3.658 0 8.258 8.258 0 00-.412-.833.051.051 0 00-.052-.025c-1.125.194-2.22.534-3.257 1.011a.041.041 0 00-.021.018C.356 6.024-.213 9.047.066 12.032c.001.014.01.028.021.037a13.276 13.276 0 003.995 2.02.05.05 0 00.056-.019c.308-.42.582-.863.818-1.329a.05.05 0 00-.028-.07 8.735 8.735 0 01-1.248-.595.05.05 0 01-.005-.083c.084-.063.168-.129.248-.195a.05.05 0 01.051-.007c2.619 1.196 5.454 1.196 8.041 0a.052.052 0 01.053.007c.08.066.164.132.248.195a.051.051 0 01-.004.085c-.399.232-.813.431-1.249.594a.05.05 0 00-.03.07c.24.465.515.909.817 1.329a.05.05 0 00.056.019 13.235 13.235 0 004.001-2.02.049.049 0 00.021-.037c.334-3.451-.559-6.449-2.366-9.106a.034.034 0 00-.02-.019z",
718
- linkedin: "M0 1.146C0 .513.526 0 1.175 0h13.65C15.474 0 16 .513 16 1.146v13.708c0 .633-.526 1.146-1.175 1.146H1.175C.526 16 0 15.487 0 14.854V1.146zm4.943 12.248V6.169H2.542v7.225h2.401zm-1.2-8.212c.837 0 1.358-.554 1.358-1.248-.015-.709-.52-1.248-1.342-1.248-.822 0-1.359.54-1.359 1.248 0 .694.521 1.248 1.327 1.248h.016zm4.908 8.212V9.359c0-.216.016-.432.08-.586.173-.431.568-.878 1.232-.878.869 0 1.216.662 1.216 1.634v3.865h2.401V9.25c0-2.22-1.184-3.252-2.764-3.252-1.274 0-1.845.7-2.165 1.193v.025h-.016a5.54 5.54 0 01.016-.025V6.169h-2.4c.03.678 0 7.225 0 7.225h2.4z",
719
- youtube: "M8.051 1.999h.089c.822.003 4.987.033 6.11.335a2.01 2.01 0 011.415 1.42c.101.38.172.883.22 1.402l.01.104.022.26.008.104c.065.914.073 1.77.074 1.957v.075c-.001.194-.01 1.108-.082 2.06l-.008.105-.009.104c-.05.572-.124 1.14-.235 1.558a2.007 2.007 0 01-1.415 1.42c-1.16.312-5.569.334-6.18.335h-.142c-.309 0-1.587-.006-2.927-.052l-.17-.006-.087-.004-.171-.007-.171-.007c-1.11-.049-2.167-.128-2.654-.26a2.007 2.007 0 01-1.415-1.419c-.111-.417-.185-.986-.235-1.558L.09 9.82l-.008-.104A31.4 31.4 0 010 7.68v-.123c.002-.215.01-.958.064-1.778l.007-.103.003-.052.008-.104.022-.26.01-.104c.048-.519.119-1.023.22-1.402a2.007 2.007 0 011.415-1.42c.487-.13 1.544-.21 2.654-.26l.17-.007.172-.006.086-.003.171-.007A99.788 99.788 0 017.858 2h.193zM6.4 5.209v4.818l4.157-2.408L6.4 5.209z",
720
- mastodon: "M11.19 12.195c2.016-.24 3.77-1.475 3.99-2.603.348-1.778.32-4.339.32-4.339 0-3.47-2.286-4.488-2.286-4.488C12.062.238 10.083.017 8.027 0h-.05C5.92.017 3.942.238 2.79.765 2.79.765.504 1.783.504 5.253c-.005.995-.01 2.19.013 3.44.075 4.21.56 8.354 3.383 9.386 1.302.476 2.418.576 3.317.507 1.628-.125 2.541-.8 2.541-.8l-.054-1.182s-1.163.366-2.47.322c-1.293-.044-2.658-.138-2.867-1.716a3.23 3.23 0 01-.028-.465s1.27.31 2.879.384c.984.045 1.905-.058 2.842-.17zM13 8.59V5.319c0-.67-.17-1.2-.507-1.592-.348-.4-.806-.605-1.373-.605-.656 0-1.154.252-1.486.756L9.2 4.595l-.434-.717c-.332-.504-.83-.756-1.486-.756-.567 0-1.025.204-1.373.605-.338.392-.507.923-.507 1.592V8.59h1.69V5.468c0-.67.285-1.012.855-1.012.63 0 .946.404.946 1.204V7.11h1.682V5.66c0-.8.316-1.204.946-1.204.57 0 .855.342.855 1.012V8.59H13z",
721
- bluesky: "M3.468 1.948C5.303 3.325 7.276 6.118 8 7.616c.724-1.498 2.697-4.29 4.532-5.668C13.855 1.013 16 .638 16 3.14c0 .5-.286 4.2-.454 4.8-.585 2.093-2.716 2.628-4.544 2.305 3.195.564 4.007 2.433 2.25 4.302-3.337 3.548-4.8-1.244-5.252-2.547 0 0-.116-.334-.166-.334h.332C8.166 11.666 8.05 12 8.05 12c-.452 1.303-1.916 6.095-5.252 2.547-1.756-1.869-.946-3.738 2.25-4.302-1.829.323-3.96-.212-4.544-2.305C.336 7.34.05 3.64.05 3.14.05.638 2.195 1.013 3.468 1.948z"
722
- };
723
- var SocialIcon = ({ platform, customIcon }) => {
724
- const d = platform === "custom" && customIcon ? customIcon : SOCIAL_ICON_PATHS[platform];
725
- if (!d) return null;
726
- return /* @__PURE__ */ jsx2("svg", { width: 20, height: 20, viewBox: "0 0 16 16", fill: "currentColor", children: /* @__PURE__ */ jsx2("path", { d }) });
727
- };
728
- var CHANGELOG_SECTION_COLORS = {
729
- Added: "#22c55e",
730
- Changed: "#3b82f6",
731
- Deprecated: "#f59e0b",
732
- Removed: "#ef4444",
733
- Fixed: "#8b5cf6",
734
- Security: "#f97316"
735
- };
736
- function ChangelogView({ entries }) {
737
- const [showAll, setShowAll] = useState2(entries.length <= 5);
738
- const visible = showAll ? entries : entries.slice(0, 5);
739
- return /* @__PURE__ */ jsxs2("div", { "data-testid": "changelog-timeline", style: { position: "relative" }, children: [
740
- /* @__PURE__ */ jsx2("div", { style: { position: "absolute", left: 15, top: 8, bottom: 8, width: 2, background: "var(--bd)" } }),
741
- visible.map((entry, i) => /* @__PURE__ */ jsxs2(
742
- "div",
743
- {
744
- "data-testid": `changelog-entry-${entry.version}`,
745
- style: { position: "relative", paddingLeft: 44, paddingBottom: i < visible.length - 1 ? 32 : 0 },
746
- children: [
747
- /* @__PURE__ */ jsx2("div", { style: {
748
- position: "absolute",
749
- left: 8,
750
- top: 6,
751
- width: 16,
752
- height: 16,
753
- borderRadius: "50%",
754
- background: entry.version === "Unreleased" ? "var(--txM)" : "var(--ac)",
755
- border: "3px solid var(--bg, #1a1a1a)"
756
- } }),
757
- /* @__PURE__ */ jsxs2("div", { style: { display: "flex", alignItems: "baseline", gap: 12, marginBottom: 12 }, children: [
758
- /* @__PURE__ */ jsx2("span", { style: { fontSize: 18, fontWeight: 700, color: "var(--tx)", fontFamily: "var(--font-heading, inherit)" }, children: entry.url ? /* @__PURE__ */ jsx2("a", { href: entry.url, target: "_blank", rel: "noopener noreferrer", style: { color: "inherit", textDecoration: "none" }, children: entry.version }) : entry.version }),
759
- entry.date && /* @__PURE__ */ jsx2("span", { style: { fontSize: 13, color: "var(--txM)", fontFamily: "var(--font-code, monospace)" }, children: entry.date })
760
- ] }),
761
- entry.sections.map((section) => {
762
- const sColor = CHANGELOG_SECTION_COLORS[section.type] || "#6b7280";
763
- return /* @__PURE__ */ jsxs2("div", { style: { marginBottom: 16 }, children: [
764
- /* @__PURE__ */ jsxs2("div", { style: { display: "inline-flex", alignItems: "center", gap: 6, marginBottom: 8 }, children: [
765
- /* @__PURE__ */ jsx2("span", { style: { display: "inline-block", width: 8, height: 8, borderRadius: "50%", background: sColor } }),
766
- /* @__PURE__ */ jsx2("span", { style: { fontSize: 12, fontWeight: 600, textTransform: "uppercase", letterSpacing: ".06em", color: sColor, fontFamily: "var(--font-code, monospace)" }, children: section.type })
767
- ] }),
768
- /* @__PURE__ */ jsx2("ul", { style: { margin: 0, paddingLeft: 18, listStyleType: "disc", color: "var(--tx2)" }, children: section.items.map((item, j) => /* @__PURE__ */ jsx2("li", { style: { fontSize: 14, lineHeight: 1.7, color: "var(--tx2)", marginBottom: 2 }, children: item }, j)) })
769
- ] }, section.type);
770
- })
771
- ]
772
- },
773
- entry.version
774
- )),
775
- !showAll && entries.length > 5 && /* @__PURE__ */ jsx2("div", { style: { textAlign: "center", marginTop: 24 }, children: /* @__PURE__ */ jsxs2(
776
- "button",
777
- {
778
- "data-testid": "changelog-show-more",
779
- onClick: () => setShowAll(true),
780
- style: { background: "none", border: "1px solid var(--bd)", borderRadius: 2, padding: "8px 20px", color: "var(--tx2)", fontSize: 13, fontFamily: "var(--font-body, inherit)", cursor: "pointer" },
781
- children: [
782
- "Show all ",
783
- entries.length,
784
- " releases"
785
- ]
786
- }
787
- ) })
788
- ] });
789
- }
790
- function getBreadcrumbs(navigation2, currentPageId, pageTitle) {
791
- if (currentPageId === "index") return [];
792
- for (const section of navigation2) {
793
- const found = section.pages.find((p) => p.id === currentPageId);
794
- if (found) {
795
- const crumbs = [];
796
- const firstPage = section.pages[0];
797
- crumbs.push({
798
- label: section.section,
799
- href: firstPage ? firstPage.urlPath : null
800
- });
801
- crumbs.push({ label: pageTitle, href: null });
802
- return crumbs;
803
- }
804
- }
805
- return [];
806
- }
807
- function Shell({
808
- config: config2,
809
- navigation: navigation2,
810
- currentPageId,
811
- pageHtml,
812
- pageComponent,
813
- mdxComponents,
814
- pageTitle,
815
- pageDescription,
816
- headings,
817
- tocEnabled = true,
818
- editUrl,
819
- lastUpdated,
820
- changelogEntries,
821
- onNavigate,
822
- allPages,
823
- versioning,
824
- currentVersion,
825
- i18n: i18n2,
826
- currentLocale,
827
- docContext: docContext2,
828
- basePath: basePath2 = "",
829
- isDraft,
830
- dir: dirProp,
831
- overrides: overrides2
832
- }) {
833
- const resolvedLocale = currentLocale || i18n2?.defaultLocale || "en";
834
- const dir = dirProp || i18n2?.localeDirs?.[resolvedLocale] || "ltr";
835
- const isRtl = dir === "rtl";
836
- const themeMode = config2.theme?.mode || "auto";
837
- const [isDark, setDark] = useState2(() => {
838
- if (themeMode === "dark") return true;
839
- if (themeMode === "light") return false;
840
- return window.matchMedia?.("(prefers-color-scheme: dark)").matches ?? true;
841
- });
842
- const [mobile, setMobile] = useState2(() => typeof window !== "undefined" && window.innerWidth < 768);
843
- const [sbOpen, setSb] = useState2(() => typeof window !== "undefined" && window.innerWidth >= 768);
844
- const [searchOpen, setSearch] = useState2(false);
845
- const [versionDropdownOpen, setVersionDropdown] = useState2(false);
846
- const [localeDropdownOpen, setLocaleDropdown] = useState2(false);
847
- const [zoomSrc, setZoomSrc] = useState2(null);
848
- const [feedbackGiven, setFeedbackGiven] = useState2({});
849
- const [bannerDismissed, setBannerDismissed] = useState2(() => {
850
- if (!config2.banner?.text) return true;
851
- try {
852
- const hash = Array.from(config2.banner.text).reduce((h, c) => (h << 5) - h + c.charCodeAt(0) | 0, 0).toString(36);
853
- return localStorage.getItem("tome-banner-dismissed") === hash;
854
- } catch {
855
- return false;
856
- }
857
- });
858
- const isOldVersion = versioning && currentVersion && currentVersion !== versioning.current;
859
- const [expanded, setExpanded] = useState2(navigation2.map((n) => n.section));
860
- const contentRef = useRef2(null);
861
- const htmlContentRef = useRef2(null);
862
- const lastHtmlRef = useRef2("");
863
- const [wide, setWide] = useState2(() => typeof window !== "undefined" && window.innerWidth > 1100);
864
- const preset = config2.theme?.preset || "amber";
865
- const baseTokens = THEME_PRESETS[preset]?.[isDark ? "dark" : "light"] || THEME_PRESETS.amber.dark;
866
- const accentOverride = config2.theme?.accent ? buildAccentOverride(config2.theme.accent, isDark) : null;
867
- const t = accentOverride ? { ...baseTokens, ...accentOverride } : baseTokens;
868
- const presetFonts = THEME_PRESETS[preset]?.fonts || THEME_PRESETS.amber.fonts;
869
- const fonts = {
870
- heading: config2.theme?.fonts?.heading || presetFonts.heading,
871
- body: config2.theme?.fonts?.body || presetFonts.body,
872
- code: config2.theme?.fonts?.code || presetFonts.code
873
- };
874
- useEffect2(() => {
875
- if (themeMode !== "auto") return;
876
- const mq = window.matchMedia("(prefers-color-scheme: dark)");
877
- const handler = (e) => setDark(e.matches);
878
- mq.addEventListener("change", handler);
879
- return () => mq.removeEventListener("change", handler);
880
- }, [themeMode]);
881
- useEffect2(() => {
882
- document.documentElement.classList.toggle("dark", isDark);
883
- }, [isDark]);
884
- useEffect2(() => {
885
- const handleResize = () => {
886
- const w = window.innerWidth;
887
- setWide(w > 1100);
888
- setMobile(w < 768);
889
- };
890
- handleResize();
891
- window.addEventListener("resize", handleResize);
892
- return () => window.removeEventListener("resize", handleResize);
893
- }, []);
894
- useEffect2(() => {
895
- if (mobile && sbOpen) {
896
- document.body.style.overflow = "hidden";
897
- return () => {
898
- document.body.style.overflow = "";
899
- };
900
- }
901
- }, [mobile, sbOpen]);
902
- useEffect2(() => {
903
- contentRef.current?.scrollTo(0, 0);
904
- }, [currentPageId]);
905
- useEffect2(() => {
906
- const el = contentRef.current;
907
- if (!el) return;
908
- const handler = (e) => {
909
- const target = e.target;
910
- if (target.tagName === "IMG" && target.closest(".tome-content")) {
911
- setZoomSrc(target.src);
912
- }
913
- };
914
- el.addEventListener("click", handler);
915
- return () => el.removeEventListener("click", handler);
916
- }, []);
917
- useEffect2(() => {
918
- const el = contentRef.current;
919
- if (!el) return;
920
- const handler = (e) => {
921
- const anchor = e.target.closest("a");
922
- if (!anchor) return;
923
- const href = anchor.getAttribute("href");
924
- if (!href) return;
925
- if (href.startsWith("http://") || href.startsWith("https://") || href.startsWith("mailto:") || href.startsWith("tel:") || href.startsWith("//")) return;
926
- if (href.startsWith("#")) return;
927
- e.preventDefault();
928
- let pageId = href.replace(/^\.\//, "").replace(/^\//, "").replace(/\.mdx?$/, "").replace(/\/$/, "");
929
- if (basePath2) {
930
- const normalized = basePath2.replace(/^\//, "").replace(/\/$/, "");
931
- if (normalized && pageId.startsWith(normalized + "/")) {
932
- pageId = pageId.slice(normalized.length + 1);
933
- } else if (normalized && pageId === normalized) {
934
- pageId = "index";
935
- }
936
- }
937
- if (!pageId) pageId = "index";
938
- onNavigate(pageId);
939
- };
940
- el.addEventListener("click", handler);
941
- return () => el.removeEventListener("click", handler);
942
- }, [onNavigate, basePath2]);
943
- useEffect2(() => {
944
- if (!zoomSrc) return;
945
- const handler = (e) => {
946
- if (e.key === "Escape") setZoomSrc(null);
947
- };
948
- window.addEventListener("keydown", handler);
949
- return () => window.removeEventListener("keydown", handler);
950
- }, [zoomSrc]);
951
- const tocConfig = config2.toc;
952
- const tocDepth = tocConfig?.depth ?? 3;
953
- const tocGlobalEnabled = tocConfig?.enabled !== false;
954
- const showToc = tocGlobalEnabled && tocEnabled;
955
- const filteredHeadings = headings.filter((h) => h.depth <= tocDepth);
956
- const [activeHeadingId, setActiveHeadingId] = useState2("");
957
- useEffect2(() => {
958
- if (!showToc || filteredHeadings.length < 2) return;
959
- const scrollRoot = contentRef.current;
960
- if (!scrollRoot) return;
961
- const timerId = setTimeout(() => {
962
- const headingElements = [];
963
- for (const h of filteredHeadings) {
964
- const el = scrollRoot.querySelector(`#${CSS.escape(h.id)}`);
965
- if (el) headingElements.push(el);
966
- }
967
- if (headingElements.length === 0) return;
968
- const observer = new IntersectionObserver(
969
- (entries) => {
970
- const visible = entries.filter((e) => e.isIntersecting).sort((a, b) => a.boundingClientRect.top - b.boundingClientRect.top);
971
- if (visible.length > 0) {
972
- setActiveHeadingId(visible[0].target.id);
973
- }
974
- },
975
- {
976
- root: scrollRoot,
977
- // Trigger when heading enters the top 20% of the scroll container
978
- rootMargin: "0px 0px -80% 0px",
979
- threshold: 0
980
- }
981
- );
982
- for (const el of headingElements) observer.observe(el);
983
- observerRef.current = observer;
984
- }, 100);
985
- return () => {
986
- clearTimeout(timerId);
987
- observerRef.current?.disconnect();
988
- observerRef.current = null;
989
- };
990
- }, [currentPageId, showToc, filteredHeadings.map((h) => h.id).join(",")]);
991
- const observerRef = useRef2(null);
992
- useEffect2(() => {
993
- setActiveHeadingId("");
994
- }, [currentPageId]);
995
- useEffect2(() => {
996
- if (!htmlContentRef.current || !pageHtml) return;
997
- const stripped = pageHtml.replace(/<h1[^>]*>[\s\S]*?<\/h1>\s*/, "");
998
- if (stripped !== lastHtmlRef.current) {
999
- htmlContentRef.current.innerHTML = stripped;
1000
- lastHtmlRef.current = stripped;
1001
- }
1002
- }, [pageHtml]);
1003
- const scrollToHeading = useCallback2((e, id) => {
1004
- e.preventDefault();
1005
- const scrollRoot = contentRef.current;
1006
- if (!scrollRoot) return;
1007
- const target = scrollRoot.querySelector(`#${CSS.escape(id)}`);
1008
- if (target) {
1009
- target.scrollIntoView({ behavior: "smooth", block: "start" });
1010
- setActiveHeadingId(id);
1011
- }
1012
- }, []);
1013
- useEffect2(() => {
1014
- const h = (e) => {
1015
- if ((e.metaKey || e.ctrlKey) && e.key === "k") {
1016
- e.preventDefault();
1017
- setSearch(true);
1018
- }
1019
- if (e.key === "Escape") setSearch(false);
1020
- };
1021
- window.addEventListener("keydown", h);
1022
- return () => window.removeEventListener("keydown", h);
1023
- }, []);
1024
- const allNavPages = navigation2.flatMap((g) => g.pages);
1025
- const idx = allNavPages.findIndex((p) => p.id === currentPageId);
1026
- const prev = idx > 0 ? allNavPages[idx - 1] : null;
1027
- const next = idx < allNavPages.length - 1 ? allNavPages[idx + 1] : null;
1028
- const breadcrumbs = getBreadcrumbs(navigation2, currentPageId, pageTitle);
1029
- const togSec = (s) => setExpanded((p) => p.includes(s) ? p.filter((x) => x !== s) : [...p, s]);
1030
- const cssVars = {
1031
- "--bg": t.bg,
1032
- "--sf": t.sf,
1033
- "--sfH": t.sfH,
1034
- "--bd": t.bd,
1035
- "--tx": t.tx,
1036
- "--tx2": t.tx2,
1037
- "--txM": t.txM,
1038
- "--ac": t.ac,
1039
- "--acD": t.acD,
1040
- "--acT": t.acT,
1041
- "--cdBg": t.cdBg,
1042
- "--cdTx": t.cdTx,
1043
- "--sbBg": t.sbBg,
1044
- "--hdBg": t.hdBg,
1045
- "--font-heading": `"${fonts.heading}", serif`,
1046
- "--font-body": `"${fonts.body}", sans-serif`,
1047
- "--font-code": `"${fonts.code}", monospace`
1048
- };
1049
- const PageComponent = pageComponent;
1050
- const bannerLink = config2.banner?.link;
1051
- const bannerIsInternal = bannerLink ? bannerLink.startsWith("#") || basePath2 && bannerLink.startsWith(basePath2 + "/") : false;
1052
- return /* @__PURE__ */ jsxs2("div", { dir, className: "tome-grain", style: { ...cssVars, color: "var(--tx)", background: "var(--bg)", fontFamily: "var(--font-body)", minHeight: "100vh", overflow: "hidden" }, children: [
1053
- config2.banner?.text && !bannerDismissed && /* @__PURE__ */ jsxs2("div", { style: {
1054
- display: "flex",
1055
- alignItems: "center",
1056
- justifyContent: "center",
1057
- gap: 12,
1058
- background: "var(--ac)",
1059
- color: "#fff",
1060
- padding: "8px 16px",
1061
- fontSize: 13,
1062
- fontFamily: "var(--font-body)",
1063
- fontWeight: 500,
1064
- textAlign: "center",
1065
- width: "100vw",
1066
- boxSizing: "border-box"
1067
- }, children: [
1068
- config2.banner.link ? /* @__PURE__ */ jsx2(
1069
- "a",
1070
- {
1071
- href: bannerIsInternal && bannerLink.startsWith("#") ? basePath2 + "/" + bannerLink.slice(1) : bannerLink,
1072
- ...bannerIsInternal ? {} : { target: "_blank", rel: "noopener noreferrer" },
1073
- style: { color: "#fff", textDecoration: "underline" },
1074
- onClick: bannerIsInternal ? (e) => {
1075
- e.preventDefault();
1076
- const bp = basePath2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1077
- const pageId = bannerLink.startsWith("#") ? bannerLink.slice(1) : bannerLink.replace(new RegExp("^" + bp + "/?"), "");
1078
- onNavigate(pageId || "index");
1079
- } : void 0,
1080
- children: config2.banner.text
1081
- }
1082
- ) : /* @__PURE__ */ jsx2("span", { children: config2.banner.text }),
1083
- config2.banner.dismissible !== false && /* @__PURE__ */ jsx2(
1084
- "button",
1085
- {
1086
- onClick: () => {
1087
- setBannerDismissed(true);
1088
- try {
1089
- const hash = Array.from(config2.banner.text).reduce((h, c) => (h << 5) - h + c.charCodeAt(0) | 0, 0).toString(36);
1090
- localStorage.setItem("tome-banner-dismissed", hash);
1091
- } catch {
1092
- }
1093
- },
1094
- "aria-label": "Dismiss banner",
1095
- style: { background: "none", border: "none", color: "#fff", cursor: "pointer", fontSize: 16, lineHeight: 1, padding: 0, opacity: 0.8 },
1096
- children: "\xD7"
1097
- }
1098
- )
1099
- ] }),
1100
- searchOpen && config2.search?.provider === "algolia" && config2.search.appId && config2.search.apiKey && config2.search.indexName ? /* @__PURE__ */ jsx2(
1101
- AlgoliaSearchModal,
1102
- {
1103
- appId: config2.search.appId,
1104
- apiKey: config2.search.apiKey,
1105
- indexName: config2.search.indexName,
1106
- onNavigate: (id) => {
1107
- onNavigate(id);
1108
- setSearch(false);
1109
- },
1110
- onClose: () => setSearch(false),
1111
- basePath: basePath2
1112
- }
1113
- ) : searchOpen ? /* @__PURE__ */ jsx2(
1114
- SearchModal,
1115
- {
1116
- allPages,
1117
- onNavigate: (id) => {
1118
- onNavigate(id);
1119
- setSearch(false);
1120
- },
1121
- onClose: () => setSearch(false),
1122
- mobile
1123
- }
1124
- ) : null,
1125
- /* @__PURE__ */ jsxs2("div", { style: { display: "flex", flexDirection: isRtl ? "row-reverse" : "row", flex: 1, height: config2.banner?.text && !bannerDismissed ? "calc(100vh - 32px)" : "100vh" }, children: [
1126
- mobile && sbOpen && /* @__PURE__ */ jsx2("div", { onClick: () => setSb(false), style: {
1127
- position: "fixed",
1128
- inset: 0,
1129
- zIndex: 200,
1130
- background: "rgba(0,0,0,0.4)",
1131
- backdropFilter: "blur(2px)"
1132
- } }),
1133
- overrides2?.Sidebar ? /* @__PURE__ */ jsx2(
1134
- overrides2.Sidebar,
1135
- {
1136
- config: config2,
1137
- navigation: navigation2,
1138
- currentPageId,
1139
- onNavigate,
1140
- mobile,
1141
- sbOpen,
1142
- setSbOpen: setSb,
1143
- versioning,
1144
- currentVersion
1145
- }
1146
- ) : /* @__PURE__ */ jsxs2("aside", { style: {
1147
- width: sbOpen ? 270 : 0,
1148
- minWidth: sbOpen ? 270 : 0,
1149
- background: "var(--sbBg)",
1150
- [isRtl ? "borderLeft" : "borderRight"]: "1px solid var(--bd)",
1151
- display: "flex",
1152
- flexDirection: "column",
1153
- transition: "width .2s, min-width .2s",
1154
- overflow: "hidden",
1155
- ...mobile ? { position: "fixed", top: 0, [isRtl ? "right" : "left"]: 0, bottom: 0, zIndex: 201 } : {}
1156
- }, children: [
1157
- /* @__PURE__ */ jsxs2("a", { href: "/", style: { padding: "18px 20px", display: "flex", alignItems: "baseline", gap: 6, borderBottom: "1px solid var(--bd)", textDecoration: "none", color: "inherit" }, children: [
1158
- /* @__PURE__ */ jsx2("span", { style: { fontFamily: "var(--font-heading)", fontSize: 22, fontWeight: 700, fontStyle: "italic" }, children: config2.name }),
1159
- /* @__PURE__ */ jsx2("span", { style: { width: 5, height: 5, borderRadius: "50%", background: "var(--ac)", display: "inline-block" } })
1160
- ] }),
1161
- /* @__PURE__ */ jsx2("div", { style: { padding: "12px 14px" }, children: /* @__PURE__ */ jsxs2("button", { onClick: () => {
1162
- setSearch(true);
1163
- if (mobile) setSb(false);
1164
- }, style: {
1165
- display: "flex",
1166
- alignItems: "center",
1167
- gap: 8,
1168
- width: "100%",
1169
- background: "var(--cdBg)",
1170
- border: "1px solid var(--bd)",
1171
- borderRadius: 2,
1172
- padding: "8px 12px",
1173
- cursor: "pointer",
1174
- color: "var(--txM)",
1175
- fontSize: 12.5,
1176
- fontFamily: "var(--font-body)"
1177
- }, children: [
1178
- /* @__PURE__ */ jsx2(SearchIcon, {}),
1179
- /* @__PURE__ */ jsx2("span", { style: { flex: 1, textAlign: isRtl ? "right" : "left" }, children: "Search..." }),
1180
- /* @__PURE__ */ jsx2("kbd", { style: { fontFamily: "var(--font-code)", fontSize: 9, background: "var(--sf)", border: "1px solid var(--bd)", borderRadius: 2, padding: "2px 6px" }, children: "\u2318K" })
1181
- ] }) }),
1182
- /* @__PURE__ */ jsx2("nav", { style: { flex: 1, overflow: "auto", padding: "4px 10px 20px" }, children: navigation2.map((sec) => /* @__PURE__ */ jsxs2("div", { style: { marginBottom: 8 }, children: [
1183
- /* @__PURE__ */ jsxs2("button", { onClick: () => togSec(sec.section), style: {
1184
- display: "flex",
1185
- alignItems: "center",
1186
- gap: 6,
1187
- width: "100%",
1188
- background: "none",
1189
- border: "none",
1190
- padding: "8px 10px",
1191
- cursor: "pointer",
1192
- borderRadius: 2,
1193
- color: "var(--txM)",
1194
- fontSize: 10,
1195
- fontWeight: 600,
1196
- textTransform: "uppercase",
1197
- letterSpacing: ".1em",
1198
- fontFamily: "var(--font-code)"
1199
- }, children: [
1200
- expanded.includes(sec.section) ? /* @__PURE__ */ jsx2(ChevDown, {}) : /* @__PURE__ */ jsx2(ChevRight, {}),
1201
- sec.section
1202
- ] }),
1203
- expanded.includes(sec.section) && /* @__PURE__ */ jsx2("div", { style: { [isRtl ? "marginRight" : "marginLeft"]: 8, [isRtl ? "borderRight" : "borderLeft"]: "1px solid var(--bd)", [isRtl ? "paddingRight" : "paddingLeft"]: 0 }, children: sec.pages.map((p) => {
1204
- const active = currentPageId === p.id;
1205
- return /* @__PURE__ */ jsxs2("button", { onClick: () => {
1206
- onNavigate(p.id);
1207
- if (mobile) setSb(false);
1208
- }, style: {
1209
- display: "flex",
1210
- alignItems: "center",
1211
- gap: 10,
1212
- width: "100%",
1213
- textAlign: isRtl ? "right" : "left",
1214
- background: "none",
1215
- border: "none",
1216
- borderRadius: 0,
1217
- [isRtl ? "borderRight" : "borderLeft"]: active ? "2px solid var(--ac)" : "2px solid transparent",
1218
- padding: "7px 14px",
1219
- cursor: "pointer",
1220
- color: active ? "var(--ac)" : "var(--tx2)",
1221
- fontSize: 13,
1222
- fontWeight: active ? 500 : 400,
1223
- fontFamily: "var(--font-body)",
1224
- transition: "all .12s"
1225
- }, children: [
1226
- p.title,
1227
- p.badge && (() => {
1228
- const badgeColors = {
1229
- default: { bg: "var(--sf)", text: "var(--tx2)" },
1230
- info: { bg: "rgba(59,130,246,0.15)", text: "rgb(59,130,246)" },
1231
- success: { bg: "rgba(34,197,94,0.15)", text: "rgb(34,197,94)" },
1232
- warning: { bg: "rgba(234,179,8,0.15)", text: "rgb(202,138,4)" },
1233
- danger: { bg: "rgba(239,68,68,0.15)", text: "rgb(239,68,68)" }
1234
- };
1235
- const bc = badgeColors[p.badge.variant || "default"] || badgeColors.default;
1236
- return /* @__PURE__ */ jsx2("span", { style: {
1237
- fontSize: 10,
1238
- fontWeight: 600,
1239
- padding: "2px 6px",
1240
- borderRadius: 4,
1241
- marginLeft: 6,
1242
- whiteSpace: "nowrap",
1243
- background: bc.bg,
1244
- color: bc.text
1245
- }, children: p.badge.text });
1246
- })()
1247
- ] }, p.id);
1248
- }) })
1249
- ] }, sec.section)) }),
1250
- versioning && mobile && /* @__PURE__ */ jsx2("div", { style: { padding: "8px 16px", borderTop: "1px solid var(--bd)", display: "flex", gap: 6 }, children: versioning.versions.map((v) => /* @__PURE__ */ jsxs2(
1251
- "button",
1252
- {
1253
- onClick: () => {
1254
- const targetId = v === versioning.current ? "index" : `${v}/index`;
1255
- onNavigate(targetId);
1256
- },
1257
- style: {
1258
- flex: 1,
1259
- padding: "6px 0",
1260
- textAlign: "center",
1261
- background: v === (currentVersion || versioning.current) ? "var(--acD)" : "var(--sf)",
1262
- border: "1px solid var(--bd)",
1263
- borderRadius: 2,
1264
- cursor: "pointer",
1265
- color: v === (currentVersion || versioning.current) ? "var(--ac)" : "var(--tx2)",
1266
- fontSize: 12,
1267
- fontFamily: "var(--font-code)",
1268
- fontWeight: v === versioning.current ? 600 : 400
1269
- },
1270
- children: [
1271
- v,
1272
- v === versioning.current ? " (latest)" : ""
1273
- ]
1274
- },
1275
- v
1276
- )) }),
1277
- /* @__PURE__ */ jsxs2("div", { style: { padding: "12px 16px", borderTop: "1px solid var(--bd)", display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
1278
- themeMode === "auto" ? /* @__PURE__ */ jsx2("button", { "aria-label": isDark ? "Switch to light mode" : "Switch to dark mode", onClick: () => setDark((d) => !d), style: { background: "none", border: "none", color: "var(--txM)", cursor: "pointer", display: "flex" }, children: isDark ? /* @__PURE__ */ jsx2(SunIcon, {}) : /* @__PURE__ */ jsx2(MoonIcon, {}) }) : /* @__PURE__ */ jsx2("div", {}),
1279
- /* @__PURE__ */ jsxs2("span", { style: { fontSize: 11, color: "var(--txM)", letterSpacing: 0.2 }, children: [
1280
- "Built with ",
1281
- "\u2661",
1282
- " by Tome"
1283
- ] }),
1284
- /* @__PURE__ */ jsx2("span", { style: { fontFamily: "var(--font-code)", fontSize: 10, color: "var(--txM)" }, children: typeof __TOME_VERSION__ !== "undefined" && __TOME_VERSION__ ? `v${__TOME_VERSION__}` : "v0.1.0" })
1285
- ] })
1286
- ] }),
1287
- /* @__PURE__ */ jsxs2("div", { style: { flex: 1, display: "flex", flexDirection: "column", overflow: "hidden" }, children: [
1288
- overrides2?.Header ? /* @__PURE__ */ jsx2(
1289
- overrides2.Header,
1290
- {
1291
- config: config2,
1292
- navigation: navigation2,
1293
- currentPageId,
1294
- onNavigate,
1295
- mobile,
1296
- sbOpen,
1297
- setSbOpen: setSb,
1298
- isDark,
1299
- setDark,
1300
- versioning,
1301
- currentVersion,
1302
- i18n: i18n2,
1303
- currentLocale,
1304
- onSearchOpen: () => setSearch(true),
1305
- basePath: basePath2
1306
- }
1307
- ) : /* @__PURE__ */ jsxs2("header", { style: {
1308
- display: "flex",
1309
- alignItems: "center",
1310
- gap: mobile ? 8 : 12,
1311
- padding: mobile ? "8px 12px" : "10px 24px",
1312
- borderBottom: "1px solid var(--bd)",
1313
- background: "var(--hdBg)",
1314
- backdropFilter: "blur(12px)",
1315
- maxWidth: "100vw",
1316
- overflow: "visible",
1317
- position: "relative",
1318
- zIndex: 200
1319
- }, children: [
1320
- /* @__PURE__ */ jsx2("button", { "aria-label": sbOpen ? "Close sidebar" : "Open sidebar", onClick: () => setSb(!sbOpen), style: { background: "none", border: "none", color: "var(--txM)", cursor: "pointer", display: "flex" }, children: sbOpen ? /* @__PURE__ */ jsx2(XIcon, {}) : /* @__PURE__ */ jsx2(MenuIcon, {}) }),
1321
- mobile ? /* @__PURE__ */ jsx2("span", { style: { fontSize: 13, color: "var(--ac)", fontFamily: "var(--font-code)", flex: 1, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: navigation2.flatMap((s) => s.pages).find((p) => p.id === currentPageId)?.title || "" }) : /* @__PURE__ */ jsx2("div", { style: { display: "flex", alignItems: "center", gap: 8, fontFamily: "var(--font-code)", fontSize: 11, color: "var(--txM)", letterSpacing: ".03em", flex: 1 }, children: navigation2.map((s) => {
1322
- const f = s.pages.find((p) => p.id === currentPageId);
1323
- if (!f) return null;
1324
- return /* @__PURE__ */ jsxs2("span", { style: { display: "flex", alignItems: "center", gap: 8 }, children: [
1325
- /* @__PURE__ */ jsx2("span", { children: s.section }),
1326
- /* @__PURE__ */ jsx2(ChevRight, {}),
1327
- /* @__PURE__ */ jsx2("span", { style: { color: "var(--ac)" }, children: f.title })
1328
- ] }, s.section);
1329
- }) }),
1330
- config2.topNav && config2.topNav.length > 0 && !mobile && /* @__PURE__ */ jsxs2("div", { style: { display: "flex", alignItems: "center", gap: 12 }, children: [
1331
- config2.topNav.map((link) => {
1332
- const isInternal = link.href.startsWith("#") || basePath2 && link.href.startsWith(basePath2 + "/");
1333
- const isExternal = !isInternal;
1334
- return /* @__PURE__ */ jsxs2(
1335
- "a",
1336
- {
1337
- href: isInternal && link.href.startsWith("#") ? basePath2 + "/" + link.href.slice(1) : link.href,
1338
- ...isExternal ? { target: "_blank", rel: "noopener noreferrer" } : {},
1339
- onClick: isInternal ? (e) => {
1340
- e.preventDefault();
1341
- const pageId = link.href.startsWith("#") ? link.href.slice(1) : link.href.replace(new RegExp("^" + basePath2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&") + "/?"), "");
1342
- onNavigate(pageId);
1343
- } : void 0,
1344
- style: {
1345
- display: "flex",
1346
- alignItems: "center",
1347
- gap: 4,
1348
- color: "var(--txM)",
1349
- textDecoration: "none",
1350
- fontSize: 12,
1351
- fontFamily: "var(--font-body)",
1352
- fontWeight: 500,
1353
- transition: "color .15s"
1354
- },
1355
- onMouseOver: (e) => e.currentTarget.style.color = "var(--ac)",
1356
- onMouseOut: (e) => e.currentTarget.style.color = "var(--txM)",
1357
- children: [
1358
- link.label,
1359
- isExternal && /* @__PURE__ */ jsx2(ExtLinkIcon, {})
1360
- ]
1361
- },
1362
- link.label
1363
- );
1364
- }),
1365
- /* @__PURE__ */ jsx2("span", { style: { width: 1, height: 16, background: "var(--bd)" } })
1366
- ] }),
1367
- config2.socialLinks && config2.socialLinks.length > 0 && !mobile && /* @__PURE__ */ jsx2("div", { style: { display: "flex", alignItems: "center", gap: 8 }, children: config2.socialLinks.map((link) => /* @__PURE__ */ jsx2(
1368
- "a",
1369
- {
1370
- href: link.url,
1371
- target: "_blank",
1372
- rel: "noopener noreferrer",
1373
- "aria-label": link.label || link.platform,
1374
- "data-testid": `social-link-${link.platform}`,
1375
- style: {
1376
- display: "flex",
1377
- alignItems: "center",
1378
- justifyContent: "center",
1379
- color: "var(--tx2)",
1380
- cursor: "pointer",
1381
- transition: "color .15s"
1382
- },
1383
- onMouseOver: (e) => e.currentTarget.style.color = "var(--tx)",
1384
- onMouseOut: (e) => e.currentTarget.style.color = "var(--tx2)",
1385
- children: /* @__PURE__ */ jsx2(SocialIcon, { platform: link.platform, customIcon: link.icon })
1386
- },
1387
- link.url
1388
- )) }),
1389
- mobile && themeMode === "auto" && /* @__PURE__ */ jsx2("button", { "aria-label": isDark ? "Switch to light mode" : "Switch to dark mode", onClick: () => setDark((d) => !d), style: { background: "none", border: "none", color: "var(--txM)", cursor: "pointer", display: "flex", flexShrink: 0 }, children: isDark ? /* @__PURE__ */ jsx2(SunIcon, {}) : /* @__PURE__ */ jsx2(MoonIcon, {}) }),
1390
- versioning && !mobile && /* @__PURE__ */ jsxs2("div", { style: { position: "relative" }, children: [
1391
- /* @__PURE__ */ jsxs2(
1392
- "button",
1393
- {
1394
- "data-testid": "version-switcher",
1395
- onClick: () => setVersionDropdown((o) => !o),
1396
- style: {
1397
- display: "flex",
1398
- alignItems: "center",
1399
- gap: 6,
1400
- background: "var(--sf)",
1401
- border: "1px solid var(--bd)",
1402
- borderRadius: 2,
1403
- padding: "5px 10px",
1404
- cursor: "pointer",
1405
- color: "var(--tx2)",
1406
- fontSize: 12,
1407
- fontFamily: "var(--font-code)"
1408
- },
1409
- children: [
1410
- /* @__PURE__ */ jsx2(VersionIcon, {}),
1411
- currentVersion || versioning.current,
1412
- /* @__PURE__ */ jsx2(ChevDown, {})
1413
- ]
1414
- }
1415
- ),
1416
- versionDropdownOpen && /* @__PURE__ */ jsx2(
1417
- "div",
1418
- {
1419
- "data-testid": "version-dropdown",
1420
- style: {
1421
- position: "absolute",
1422
- top: "100%",
1423
- right: 0,
1424
- marginTop: 4,
1425
- background: "var(--sf)",
1426
- border: "1px solid var(--bd)",
1427
- borderRadius: 2,
1428
- boxShadow: "0 8px 32px rgba(0,0,0,0.2)",
1429
- overflow: "hidden",
1430
- zIndex: 100,
1431
- minWidth: 120
1432
- },
1433
- children: versioning.versions.map((v) => /* @__PURE__ */ jsxs2(
1434
- "button",
1435
- {
1436
- onClick: () => {
1437
- setVersionDropdown(false);
1438
- const targetId = v === versioning.current ? "index" : `${v}/index`;
1439
- onNavigate(targetId);
1440
- },
1441
- style: {
1442
- display: "block",
1443
- width: "100%",
1444
- textAlign: "left",
1445
- background: v === (currentVersion || versioning.current) ? "var(--acD)" : "none",
1446
- border: "none",
1447
- padding: "8px 14px",
1448
- cursor: "pointer",
1449
- color: v === (currentVersion || versioning.current) ? "var(--ac)" : "var(--tx2)",
1450
- fontSize: 12,
1451
- fontFamily: "var(--font-code)",
1452
- fontWeight: v === versioning.current ? 600 : 400
1453
- },
1454
- children: [
1455
- v,
1456
- v === versioning.current ? " (latest)" : ""
1457
- ]
1458
- },
1459
- v
1460
- ))
1461
- }
1462
- )
1463
- ] }),
1464
- i18n2 && i18n2.locales.length > 1 && !mobile && /* @__PURE__ */ jsxs2("div", { style: { position: "relative" }, children: [
1465
- /* @__PURE__ */ jsxs2(
1466
- "button",
1467
- {
1468
- "data-testid": "language-switcher",
1469
- onClick: () => setLocaleDropdown((o) => !o),
1470
- style: {
1471
- display: "flex",
1472
- alignItems: "center",
1473
- gap: 6,
1474
- background: "var(--sf)",
1475
- border: "1px solid var(--bd)",
1476
- borderRadius: 2,
1477
- padding: "5px 10px",
1478
- cursor: "pointer",
1479
- color: "var(--tx2)",
1480
- fontSize: 12,
1481
- fontFamily: "var(--font-body)"
1482
- },
1483
- children: [
1484
- /* @__PURE__ */ jsx2(GlobeIcon, {}),
1485
- i18n2.localeNames?.[currentLocale || i18n2.defaultLocale] || currentLocale || i18n2.defaultLocale,
1486
- /* @__PURE__ */ jsx2(ChevDown, {})
1487
- ]
1488
- }
1489
- ),
1490
- localeDropdownOpen && /* @__PURE__ */ jsx2(
1491
- "div",
1492
- {
1493
- "data-testid": "language-dropdown",
1494
- style: {
1495
- position: "absolute",
1496
- top: "100%",
1497
- right: 0,
1498
- marginTop: 4,
1499
- background: "var(--sf)",
1500
- border: "1px solid var(--bd)",
1501
- borderRadius: 2,
1502
- boxShadow: "0 8px 32px rgba(0,0,0,0.2)",
1503
- overflow: "hidden",
1504
- zIndex: 100,
1505
- minWidth: 120
1506
- },
1507
- children: i18n2.locales.map((locale) => {
1508
- const isActive = locale === (currentLocale || i18n2.defaultLocale);
1509
- const displayName = i18n2.localeNames?.[locale] || locale;
1510
- const activeLocale = currentLocale || i18n2.defaultLocale;
1511
- let basePageId = currentPageId;
1512
- if (activeLocale !== i18n2.defaultLocale && currentPageId.startsWith(`${activeLocale}/`)) {
1513
- basePageId = currentPageId.slice(activeLocale.length + 1);
1514
- }
1515
- const targetId = locale === i18n2.defaultLocale ? basePageId : `${locale}/${basePageId}`;
1516
- return /* @__PURE__ */ jsx2(
1517
- "button",
1518
- {
1519
- onClick: () => {
1520
- setLocaleDropdown(false);
1521
- onNavigate(targetId);
1522
- },
1523
- style: {
1524
- display: "block",
1525
- width: "100%",
1526
- textAlign: "left",
1527
- background: isActive ? "var(--acD)" : "none",
1528
- border: "none",
1529
- padding: "8px 14px",
1530
- cursor: "pointer",
1531
- color: isActive ? "var(--ac)" : "var(--tx2)",
1532
- fontSize: 12,
1533
- fontFamily: "var(--font-body)",
1534
- fontWeight: isActive ? 600 : 400
1535
- },
1536
- children: displayName
1537
- },
1538
- locale
1539
- );
1540
- })
1541
- }
1542
- )
1543
- ] })
1544
- ] }),
1545
- isOldVersion && /* @__PURE__ */ jsxs2(
1546
- "div",
1547
- {
1548
- "data-testid": "old-version-banner",
1549
- style: {
1550
- display: "flex",
1551
- alignItems: "center",
1552
- justifyContent: "center",
1553
- gap: 8,
1554
- background: "var(--acD)",
1555
- borderBottom: "1px solid var(--bd)",
1556
- padding: "8px 24px",
1557
- fontSize: 13,
1558
- color: "var(--tx2)"
1559
- },
1560
- children: [
1561
- /* @__PURE__ */ jsxs2("span", { children: [
1562
- "You're viewing docs for ",
1563
- currentVersion,
1564
- "."
1565
- ] }),
1566
- /* @__PURE__ */ jsx2(
1567
- "button",
1568
- {
1569
- onClick: () => {
1570
- onNavigate("index");
1571
- },
1572
- style: {
1573
- background: "none",
1574
- border: "none",
1575
- color: "var(--ac)",
1576
- cursor: "pointer",
1577
- fontWeight: 600,
1578
- fontSize: 13,
1579
- fontFamily: "var(--font-body)",
1580
- textDecoration: "underline"
1581
- },
1582
- children: "Switch to latest."
1583
- }
1584
- )
1585
- ]
1586
- }
1587
- ),
1588
- /* @__PURE__ */ jsxs2("div", { ref: contentRef, style: { flex: 1, overflow: "auto", display: "flex" }, children: [
1589
- /* @__PURE__ */ jsxs2("main", { style: { flex: 1, maxWidth: mobile ? "100%" : 760, padding: mobile ? "24px 16px 60px" : "40px 48px 80px", margin: "0 auto", minWidth: 0 }, children: [
1590
- breadcrumbs.length > 0 && /* @__PURE__ */ jsx2("nav", { "aria-label": "Breadcrumbs", "data-testid": "breadcrumbs", style: {
1591
- display: "flex",
1592
- alignItems: "center",
1593
- gap: 6,
1594
- fontSize: 13,
1595
- color: "var(--tx2)",
1596
- marginBottom: 8
1597
- }, children: breadcrumbs.map((crumb, i) => /* @__PURE__ */ jsxs2(React2.Fragment, { children: [
1598
- i > 0 && /* @__PURE__ */ jsx2("span", { style: { color: "var(--tx2)", opacity: 0.5 }, children: "\u203A" }),
1599
- i < breadcrumbs.length - 1 && crumb.href !== null ? /* @__PURE__ */ jsx2(
1600
- "a",
1601
- {
1602
- href: crumb.href,
1603
- onClick: (e) => {
1604
- e.preventDefault();
1605
- const page = navigation2.flatMap((s) => s.pages).find((p) => p.urlPath === crumb.href);
1606
- if (page) onNavigate(page.id);
1607
- },
1608
- style: { color: "var(--tx2)", textDecoration: "none", cursor: "pointer" },
1609
- children: crumb.label
1610
- }
1611
- ) : /* @__PURE__ */ jsx2("span", { style: i === breadcrumbs.length - 1 ? { color: "var(--tx)" } : void 0, children: crumb.label })
1612
- ] }, i)) }),
1613
- /* @__PURE__ */ jsx2("h1", { style: { fontFamily: "var(--font-heading)", fontSize: mobile ? 26 : 38, fontWeight: 400, fontStyle: "italic", lineHeight: 1.15, marginBottom: 8 }, children: pageTitle }),
1614
- isDraft && /* @__PURE__ */ jsx2("div", { "data-testid": "draft-banner", style: { background: "#fef3c7", color: "#92400e", padding: "8px 16px", borderRadius: 6, fontSize: 13, marginBottom: 16 }, children: "Draft \u2014 This page is only visible in development" }),
1615
- pageDescription && /* @__PURE__ */ jsx2("p", { style: { fontSize: 16, color: "var(--tx2)", lineHeight: 1.6, marginBottom: 32 }, children: pageDescription }),
1616
- /* @__PURE__ */ jsx2("div", { style: { borderTop: "1px solid var(--bd)", paddingTop: 28 }, children: changelogEntries && changelogEntries.length > 0 ? /* @__PURE__ */ jsx2(ChangelogView, { entries: changelogEntries }) : PageComponent ? /* @__PURE__ */ jsx2("div", { className: "tome-content", children: /* @__PURE__ */ jsx2(PageComponent, { components: mdxComponents || {} }) }) : /* @__PURE__ */ jsx2(
1617
- "div",
1618
- {
1619
- className: "tome-content",
1620
- ref: htmlContentRef
1621
- }
1622
- ) }),
1623
- overrides2?.PageFooter ? /* @__PURE__ */ jsx2(
1624
- overrides2.PageFooter,
1625
- {
1626
- editUrl,
1627
- lastUpdated,
1628
- currentPageId,
1629
- prev,
1630
- next,
1631
- onNavigate,
1632
- mobile
1633
- }
1634
- ) : /* @__PURE__ */ jsxs2(Fragment, { children: [
1635
- (editUrl || lastUpdated) && /* @__PURE__ */ jsxs2("div", { style: { marginTop: 40, display: "flex", flexDirection: mobile ? "column" : "row", alignItems: mobile ? "flex-start" : "center", justifyContent: "space-between", gap: mobile ? 8 : 16 }, children: [
1636
- editUrl && /* @__PURE__ */ jsx2("div", { "data-testid": "edit-page-link", children: /* @__PURE__ */ jsxs2(
1637
- "a",
1638
- {
1639
- href: editUrl,
1640
- target: "_blank",
1641
- rel: "noopener noreferrer",
1642
- style: {
1643
- display: "inline-flex",
1644
- alignItems: "center",
1645
- gap: 6,
1646
- color: "var(--txM)",
1647
- textDecoration: "none",
1648
- fontSize: 13,
1649
- fontFamily: "var(--font-body)",
1650
- transition: "color .15s"
1651
- },
1652
- onMouseOver: (e) => e.currentTarget.style.color = "var(--ac)",
1653
- onMouseOut: (e) => e.currentTarget.style.color = "var(--txM)",
1654
- children: [
1655
- /* @__PURE__ */ jsx2(PencilIcon, {}),
1656
- " Edit this page on GitHub"
1657
- ]
1658
- }
1659
- ) }),
1660
- lastUpdated && /* @__PURE__ */ jsxs2("div", { "data-testid": "last-updated", style: { fontSize: 12, color: "var(--txM)", fontFamily: "var(--font-body)" }, children: [
1661
- "Last updated ",
1662
- formatRelativeDate(lastUpdated)
1663
- ] })
1664
- ] }),
1665
- /* @__PURE__ */ jsx2("div", { style: { display: "flex", alignItems: "center", gap: 12, marginTop: 24, padding: "12px 0" }, children: feedbackGiven[currentPageId] ? /* @__PURE__ */ jsx2("span", { style: { fontSize: 13, color: "var(--txM)", fontFamily: "var(--font-body)" }, children: "Thanks for your feedback!" }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
1666
- /* @__PURE__ */ jsx2("span", { style: { fontSize: 13, color: "var(--txM)", fontFamily: "var(--font-body)" }, children: "Was this helpful?" }),
1667
- /* @__PURE__ */ jsx2("button", { onClick: () => {
1668
- setFeedbackGiven((prev2) => ({ ...prev2, [currentPageId]: true }));
1669
- try {
1670
- localStorage.setItem(`tome-feedback-${currentPageId}`, "up");
1671
- } catch {
1672
- }
1673
- }, style: {
1674
- background: "none",
1675
- border: "1px solid var(--bd)",
1676
- borderRadius: 2,
1677
- padding: "4px 10px",
1678
- cursor: "pointer",
1679
- fontSize: 13,
1680
- color: "var(--txM)",
1681
- transition: "border-color .15s"
1682
- }, children: "\u{1F44D}" }),
1683
- /* @__PURE__ */ jsx2("button", { onClick: () => {
1684
- setFeedbackGiven((prev2) => ({ ...prev2, [currentPageId]: true }));
1685
- try {
1686
- localStorage.setItem(`tome-feedback-${currentPageId}`, "down");
1687
- } catch {
1688
- }
1689
- }, style: {
1690
- background: "none",
1691
- border: "1px solid var(--bd)",
1692
- borderRadius: 2,
1693
- padding: "4px 10px",
1694
- cursor: "pointer",
1695
- fontSize: 13,
1696
- color: "var(--txM)",
1697
- transition: "border-color .15s"
1698
- }, children: "\u{1F44E}" })
1699
- ] }) }),
1700
- /* @__PURE__ */ jsxs2("div", { style: { display: "flex", flexDirection: mobile ? "column" : "row", justifyContent: "space-between", marginTop: 16, paddingTop: 24, borderTop: "1px solid var(--bd)", gap: mobile ? 12 : 16 }, children: [
1701
- prev ? /* @__PURE__ */ jsxs2("button", { onClick: () => onNavigate(prev.id), style: {
1702
- display: "flex",
1703
- alignItems: "center",
1704
- gap: 8,
1705
- background: "none",
1706
- border: "1px solid var(--bd)",
1707
- borderRadius: 2,
1708
- padding: "10px 16px",
1709
- cursor: "pointer",
1710
- color: "var(--tx2)",
1711
- fontSize: 13,
1712
- fontFamily: "var(--font-body)",
1713
- transition: "border-color .15s, color .15s"
1714
- }, children: [
1715
- isRtl ? /* @__PURE__ */ jsx2(ArrowRight, {}) : /* @__PURE__ */ jsx2(ArrowLeft, {}),
1716
- " ",
1717
- prev.title
1718
- ] }) : /* @__PURE__ */ jsx2("div", {}),
1719
- next ? /* @__PURE__ */ jsxs2("button", { onClick: () => onNavigate(next.id), style: {
1720
- display: "flex",
1721
- alignItems: "center",
1722
- gap: 8,
1723
- background: "none",
1724
- border: "1px solid var(--bd)",
1725
- borderRadius: 2,
1726
- padding: "10px 16px",
1727
- cursor: "pointer",
1728
- color: "var(--tx2)",
1729
- fontSize: 13,
1730
- fontFamily: "var(--font-body)",
1731
- transition: "border-color .15s, color .15s"
1732
- }, children: [
1733
- next.title,
1734
- " ",
1735
- isRtl ? /* @__PURE__ */ jsx2(ArrowLeft, {}) : /* @__PURE__ */ jsx2(ArrowRight, {})
1736
- ] }) : /* @__PURE__ */ jsx2("div", {})
1737
- ] })
1738
- ] })
1739
- ] }),
1740
- overrides2?.Toc ? showToc && filteredHeadings.length >= 2 && wide && /* @__PURE__ */ jsx2(
1741
- overrides2.Toc,
1742
- {
1743
- headings: filteredHeadings,
1744
- activeHeadingId,
1745
- onScrollToHeading: scrollToHeading
1746
- }
1747
- ) : showToc && filteredHeadings.length >= 2 && wide && /* @__PURE__ */ jsxs2("aside", { "data-testid": "toc-sidebar", style: { width: 200, padding: isRtl ? "40px 0 40px 16px" : "40px 16px 40px 0", position: "sticky", top: 0, alignSelf: "flex-start", flexShrink: 0 }, children: [
1748
- /* @__PURE__ */ jsx2("div", { style: { fontSize: 10, fontWeight: 600, textTransform: "uppercase", letterSpacing: ".1em", color: "var(--txM)", marginBottom: 12, fontFamily: "var(--font-code)" }, children: "On this page" }),
1749
- /* @__PURE__ */ jsx2("nav", { "aria-label": "Table of contents", style: { [isRtl ? "borderRight" : "borderLeft"]: "1px solid var(--bd)", [isRtl ? "paddingRight" : "paddingLeft"]: 0 }, children: filteredHeadings.map((h, i) => {
1750
- const isActive = activeHeadingId === h.id;
1751
- return /* @__PURE__ */ jsx2(
1752
- "a",
1753
- {
1754
- href: `#${h.id}`,
1755
- onClick: (e) => scrollToHeading(e, h.id),
1756
- "data-testid": `toc-link-${h.id}`,
1757
- style: {
1758
- display: "block",
1759
- fontSize: 12,
1760
- color: isActive ? "var(--ac)" : "var(--txM)",
1761
- fontWeight: isActive ? 500 : 400,
1762
- textDecoration: "none",
1763
- padding: "4px 12px",
1764
- [isRtl ? "paddingRight" : "paddingLeft"]: 12 + (h.depth - 2) * 12,
1765
- lineHeight: 1.4,
1766
- transition: "color .15s, font-weight .15s",
1767
- [isRtl ? "borderRight" : "borderLeft"]: isActive ? "2px solid var(--ac)" : "2px solid transparent",
1768
- [isRtl ? "marginRight" : "marginLeft"]: -1
1769
- },
1770
- children: h.text
1771
- },
1772
- i
1773
- );
1774
- }) })
1775
- ] })
1776
- ] })
1777
- ] })
1778
- ] }),
1779
- overrides2?.Footer && /* @__PURE__ */ jsx2(
1780
- overrides2.Footer,
1781
- {
1782
- config: config2,
1783
- navigation: navigation2,
1784
- currentPageId,
1785
- onNavigate
1786
- }
1787
- ),
1788
- config2.ai?.enabled && /* @__PURE__ */ jsx2(
1789
- AiChat,
1790
- {
1791
- provider: config2.ai.provider || "anthropic",
1792
- model: config2.ai.model,
1793
- apiKey: typeof __TOME_AI_API_KEY__ !== "undefined" && __TOME_AI_API_KEY__ ? __TOME_AI_API_KEY__ : void 0,
1794
- context: docContext2?.map((d) => `## ${d.title}
1795
- ${d.content}`).join("\n\n") ?? allPages.map((p) => `- ${p.title}${p.description ? ": " + p.description : ""}`).join("\n")
1796
- }
1797
- ),
1798
- zoomSrc && /* @__PURE__ */ jsx2("div", { onClick: () => setZoomSrc(null), style: {
1799
- position: "fixed",
1800
- inset: 0,
1801
- zIndex: 9999,
1802
- display: "flex",
1803
- alignItems: "center",
1804
- justifyContent: "center",
1805
- background: "rgba(0,0,0,0.7)",
1806
- backdropFilter: "blur(8px)",
1807
- cursor: "zoom-out"
1808
- }, children: /* @__PURE__ */ jsx2("img", { src: zoomSrc, alt: "", style: { maxWidth: "90vw", maxHeight: "90vh", objectFit: "contain", borderRadius: 4, boxShadow: "0 16px 64px rgba(0,0,0,0.4)" } }) })
1809
- ] });
1810
- }
1811
- function SearchModal({ allPages, onNavigate, onClose, mobile }) {
1812
- const [q, setQ] = useState2("");
1813
- const [results, setResults] = useState2([]);
1814
- const [selected, setSelected] = useState2(0);
1815
- const [pagefindReady, setPagefindReady] = useState2(null);
1816
- const inputRef = useRef2(null);
1817
- const debounceRef = useRef2(void 0);
1818
- useEffect2(() => {
1819
- initPagefind().then((pf) => setPagefindReady(!!pf));
1820
- setTimeout(() => inputRef.current?.focus(), 50);
1821
- }, []);
1822
- const fallbackSearch = useCallback2((query) => {
1823
- if (!query.trim()) return [];
1824
- const ql = query.toLowerCase();
1825
- return allPages.filter((p) => p.title.toLowerCase().includes(ql) || (p.description || "").toLowerCase().includes(ql)).slice(0, 8).map((p) => ({ id: p.id, title: p.title, excerpt: p.description }));
1826
- }, [allPages]);
1827
- const doSearch = useCallback2(async (query) => {
1828
- if (!query.trim()) {
1829
- setResults([]);
1830
- setSelected(0);
1831
- return;
1832
- }
1833
- const pf = pagefindInstance;
1834
- if (pf) {
1835
- try {
1836
- const search = await pf.search(query);
1837
- const items = [];
1838
- for (const result of search.results.slice(0, 8)) {
1839
- const data = await result.data();
1840
- const url = data.url || "";
1841
- const id = url.replace(/^\//, "").replace(/\/index\.html$/, "").replace(/\.html$/, "") || "index";
1842
- items.push({
1843
- id,
1844
- title: data.meta?.title || id,
1845
- excerpt: data.excerpt || void 0
1846
- });
1847
- }
1848
- setResults(items);
1849
- setSelected(0);
1850
- return;
1851
- } catch {
1852
- }
1853
- }
1854
- setResults(fallbackSearch(query));
1855
- setSelected(0);
1856
- }, [fallbackSearch]);
1857
- useEffect2(() => {
1858
- if (debounceRef.current) clearTimeout(debounceRef.current);
1859
- debounceRef.current = setTimeout(() => doSearch(q), 120);
1860
- return () => {
1861
- if (debounceRef.current) clearTimeout(debounceRef.current);
1862
- };
1863
- }, [q, doSearch]);
1864
- const handleKeyDown = useCallback2((e) => {
1865
- if (e.key === "ArrowDown") {
1866
- e.preventDefault();
1867
- setSelected((i) => Math.min(i + 1, results.length - 1));
1868
- } else if (e.key === "ArrowUp") {
1869
- e.preventDefault();
1870
- setSelected((i) => Math.max(i - 1, 0));
1871
- } else if (e.key === "Enter" && results.length > 0) {
1872
- e.preventDefault();
1873
- onNavigate(results[selected].id);
1874
- }
1875
- }, [results, selected, onNavigate]);
1876
- return /* @__PURE__ */ jsx2("div", { onClick: onClose, style: {
1877
- position: "fixed",
1878
- inset: 0,
1879
- zIndex: 1e3,
1880
- background: "rgba(0,0,0,0.55)",
1881
- backdropFilter: "blur(6px)",
1882
- display: "flex",
1883
- alignItems: mobile ? "stretch" : "flex-start",
1884
- justifyContent: "center",
1885
- paddingTop: mobile ? 0 : "12vh"
1886
- }, children: /* @__PURE__ */ jsxs2("div", { onClick: (e) => e.stopPropagation(), style: {
1887
- background: "var(--sf)",
1888
- border: mobile ? "none" : "1px solid var(--bd)",
1889
- borderRadius: mobile ? 0 : 2,
1890
- width: "100%",
1891
- maxWidth: mobile ? "100%" : 520,
1892
- boxShadow: mobile ? "none" : "0 24px 80px rgba(0,0,0,0.4)",
1893
- overflow: "hidden",
1894
- display: "flex",
1895
- flexDirection: "column",
1896
- ...mobile ? { height: "100%" } : {}
1897
- }, children: [
1898
- /* @__PURE__ */ jsxs2("div", { style: { display: "flex", alignItems: "center", gap: 10, padding: "14px 18px", borderBottom: "1px solid var(--bd)" }, children: [
1899
- /* @__PURE__ */ jsx2(SearchIcon, {}),
1900
- /* @__PURE__ */ jsx2(
1901
- "input",
1902
- {
1903
- ref: inputRef,
1904
- value: q,
1905
- onChange: (e) => setQ(e.target.value),
1906
- onKeyDown: handleKeyDown,
1907
- placeholder: "Search documentation...",
1908
- style: { flex: 1, background: "none", border: "none", outline: "none", color: "var(--tx)", fontSize: 15, fontFamily: "var(--font-body)" }
1909
- }
1910
- ),
1911
- /* @__PURE__ */ jsx2("kbd", { style: { fontFamily: "var(--font-code)", fontSize: 10, color: "var(--txM)", background: "var(--cdBg)", padding: "2px 6px", borderRadius: 2, border: "1px solid var(--bd)" }, children: "ESC" })
1912
- ] }),
1913
- results.length > 0 && /* @__PURE__ */ jsx2("div", { style: { padding: 6, maxHeight: mobile ? "none" : 360, overflow: "auto", flex: mobile ? 1 : void 0 }, children: results.map((r, i) => /* @__PURE__ */ jsxs2(
1914
- "button",
1915
- {
1916
- onClick: () => onNavigate(r.id),
1917
- style: {
1918
- display: "block",
1919
- width: "100%",
1920
- textAlign: "left",
1921
- background: i === selected ? "var(--acD)" : "none",
1922
- border: "none",
1923
- borderRadius: 2,
1924
- padding: "10px 14px",
1925
- cursor: "pointer",
1926
- color: "var(--tx)",
1927
- fontFamily: "var(--font-body)"
1928
- },
1929
- onMouseEnter: () => setSelected(i),
1930
- children: [
1931
- /* @__PURE__ */ jsx2("div", { style: { fontWeight: 500, fontSize: 14, marginBottom: 2 }, children: r.title }),
1932
- r.excerpt && /* @__PURE__ */ jsx2("div", { style: {
1933
- fontSize: 12,
1934
- color: "var(--txM)",
1935
- lineHeight: 1.3
1936
- }, dangerouslySetInnerHTML: { __html: r.excerpt } })
1937
- ]
1938
- },
1939
- r.id + i
1940
- )) }),
1941
- q && !results.length && /* @__PURE__ */ jsx2("div", { style: { padding: "32px 18px", textAlign: "center", color: "var(--txM)", fontSize: 14 }, children: "No results found" }),
1942
- pagefindReady === false && q && results.length > 0 && /* @__PURE__ */ jsx2("div", { style: { padding: "6px 18px 10px", fontSize: 11, color: "var(--txM)", textAlign: "center" }, children: "Showing title matches. Build your site for full-text search." })
1943
- ] }) });
1944
- }
1945
-
1946
- // src/routing.ts
1947
- function pathnameToPageId(pathname, basePath2, routes2) {
1948
- let relative = pathname;
1949
- if (basePath2 && relative.startsWith(basePath2)) {
1950
- relative = relative.slice(basePath2.length);
1951
- }
1952
- const id = relative.replace(/^\//, "").replace(/\/index\.html$/, "").replace(/\.html$/, "").replace(/\/$/, "") || "index";
1953
- const route = routes2.find((r) => r.id === id);
1954
- return route ? id : null;
1955
- }
1956
- function pageIdToPath(id, basePath2, routes2) {
1957
- const route = routes2.find((r) => r.id === id);
1958
- if (route) return basePath2 + route.urlPath;
1959
- return basePath2 + "/" + id;
1960
- }
1961
-
1962
- // src/entry-helpers.ts
1963
- function computeEditUrl(editLink, filePath) {
1964
- if (!editLink || !filePath) return void 0;
1965
- const { repo, branch = "main", dir = "" } = editLink;
1966
- const dirPrefix = dir ? `${dir.replace(/\/$/, "")}/` : "";
1967
- return `https://github.com/${repo}/edit/${branch}/${dirPrefix}${filePath}`;
1968
- }
1969
- function resolveInitialPageId(pathname, hash, routes2, basePath2, pathnameToPageIdFn) {
1970
- const resolved = pathnameToPageIdFn(pathname, basePath2, routes2);
1971
- if (resolved) return resolved;
1972
- const hashId = hash.startsWith("#") ? hash.slice(1) : hash;
1973
- if (hashId && routes2.some((r) => r.id === hashId)) return hashId;
1974
- return routes2[0]?.id || "index";
1975
- }
1976
- async function loadPage(id, routes2, loadPageModule2) {
1977
- try {
1978
- const route = routes2.find((r) => r.id === id);
1979
- const mod = await loadPageModule2(id);
1980
- if (route?.isMdx && mod.meta) {
1981
- return {
1982
- isMdx: true,
1983
- component: mod.default,
1984
- frontmatter: mod.meta.frontmatter,
1985
- headings: mod.meta.headings
1986
- };
1987
- }
1988
- if (!mod.default) return null;
1989
- if (mod.isChangelog && mod.changelogEntries) {
1990
- return { isMdx: false, ...mod.default, changelogEntries: mod.changelogEntries };
1991
- }
1992
- return { isMdx: false, ...mod.default };
1993
- } catch (err) {
1994
- console.error(`Failed to load page: ${id}`, err);
1995
- return null;
1996
- }
1997
- }
1998
- function detectCurrentVersion(currentRoute, versions2) {
1999
- return currentRoute?.version || (versions2?.current ?? void 0);
2000
- }
2001
-
2002
- // src/entry.tsx
2003
- import config from "virtual:tome/config";
2004
- import { routes, navigation, versions, i18n } from "virtual:tome/routes";
2005
- import loadPageModule from "virtual:tome/page-loader";
2006
- import docContext from "virtual:tome/doc-context";
2007
- import overrides from "virtual:tome/overrides";
2008
- import {
2009
- Callout,
2010
- Tabs,
2011
- Card,
2012
- CardGroup,
2013
- Steps,
2014
- Accordion,
2015
- ChangelogTimeline,
2016
- PackageManager,
2017
- TypeTable,
2018
- FileTree
2019
- } from "@tomehq/components";
2020
- import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
2021
- var MDX_COMPONENTS = {
2022
- Callout,
2023
- Tabs,
2024
- Card,
2025
- CardGroup,
2026
- Steps,
2027
- Accordion,
2028
- ChangelogTimeline,
2029
- PackageManager,
2030
- TypeTable,
2031
- FileTree
2032
- // Sub-components accessible as <FileTree.File /> and <FileTree.Folder /> in MDX
2033
- };
2034
- var contentStyles = `
2035
- @import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:wght@300;400;500;600;700&family=Cormorant+Garamond:ital,wght@0,300;0,400;0,600;0,700;1,300;1,400;1,700&family=Fira+Code:wght@400;500;600&display=swap');
2036
-
2037
- .tome-content h1 { display: none; }
2038
- .tome-content h2 { font-family: var(--font-body); font-size: 1.35em; font-weight: 600; margin-top: 2em; margin-bottom: 0.5em; display: flex; align-items: center; gap: 10px; letter-spacing: 0.01em; }
2039
- .tome-content h2::before { content: "#"; font-family: var(--font-heading); font-size: 1.2em; font-weight: 300; font-style: italic; color: var(--ac); opacity: 0.5; }
2040
- .tome-content h3 { font-family: var(--font-body); font-size: 1.15em; font-weight: 600; margin-top: 1.5em; margin-bottom: 0.5em; }
2041
- .tome-content h4 { font-family: var(--font-body); font-size: 1.05em; font-weight: 600; margin-top: 1.2em; margin-bottom: 0.5em; }
2042
- .tome-content p { color: var(--tx2); line-height: 1.8; margin-bottom: 1em; font-size: 14.5px; }
2043
- .tome-content a { color: var(--ac); text-decoration: none; }
2044
- .tome-content a:hover { text-decoration: underline; }
2045
- .tome-content .heading-anchor { display: none; }
2046
- .tome-content ul, .tome-content ol { color: var(--tx2); padding-inline-start: 1.5em; margin-bottom: 1em; }
2047
- .tome-content li { margin-bottom: 0.3em; line-height: 1.7; }
2048
- .tome-content code { font-family: var(--font-code); font-size: 0.88em; background: var(--cdBg); padding: 0.15em 0.4em; border-radius: 2px; color: var(--ac); }
2049
- .tome-content pre { margin-bottom: 1.2em; border-radius: 2px; overflow-x: auto; border: 1px solid var(--bd); }
2050
- .tome-content pre code { background: none; padding: 1em 1.2em; display: block; font-size: 12.5px; line-height: 1.7; color: var(--cdTx); }
2051
- .tome-content blockquote { border-inline-start: 3px solid var(--ac); padding: 0.5em 1em; margin: 1em 0; background: var(--acD); border-radius: 0 2px 2px 0; }
2052
- .tome-content blockquote p { color: var(--tx2); margin: 0; }
2053
- .tome-content table { width: 100%; border-collapse: collapse; margin-bottom: 1em; }
2054
- .tome-content th, .tome-content td { padding: 0.5em 0.8em; border: 1px solid var(--bd); text-align: start; font-size: 0.9em; }
2055
- .tome-content th { background: var(--sf); font-weight: 600; }
2056
- .tome-content img { max-width: 100%; border-radius: 2px; cursor: zoom-in; }
2057
- .tome-content hr { border: none; border-top: 1px solid var(--bd); margin: 2em 0; }
2058
- .tome-mermaid { margin: 1.2em 0; text-align: center; overflow-x: auto; }
2059
- .tome-mermaid svg { max-width: 100%; height: auto; overflow: visible; }
2060
- .tome-mermaid svg .nodeLabel { overflow: visible; white-space: nowrap; }
2061
- /* Ensure mermaid text meets WCAG AA contrast in light mode */
2062
- /* Mermaid v11 uses foreignObject with inline-styled spans \u2014 !important needed */
2063
- html:not(.dark) .tome-mermaid svg .nodeLabel,
2064
- html:not(.dark) .tome-mermaid svg .nodeLabel span,
2065
- html:not(.dark) .tome-mermaid svg .nodeLabel div,
2066
- html:not(.dark) .tome-mermaid svg foreignObject div,
2067
- html:not(.dark) .tome-mermaid svg foreignObject span { color: #1a1a1a !important; }
2068
- html:not(.dark) .tome-mermaid svg .edgeLabel,
2069
- html:not(.dark) .tome-mermaid svg .edgeLabel span { color: #333 !important; }
2070
- html:not(.dark) .tome-mermaid svg text { fill: #1a1a1a !important; }
2071
- html:not(.dark) .tome-mermaid svg .node rect,
2072
- html:not(.dark) .tome-mermaid svg .node polygon { stroke: #555 !important; }
2073
- /* Dark mode: force bright text in mermaid nodes for readability */
2074
- html.dark .tome-mermaid svg .nodeLabel,
2075
- html.dark .tome-mermaid svg .nodeLabel span,
2076
- html.dark .tome-mermaid svg .nodeLabel div,
2077
- html.dark .tome-mermaid svg foreignObject div,
2078
- html.dark .tome-mermaid svg foreignObject span { color: #f0f0f0 !important; }
2079
- html.dark .tome-mermaid svg .edgeLabel,
2080
- html.dark .tome-mermaid svg .edgeLabel span { color: #ddd !important; }
2081
- html.dark .tome-mermaid svg text { fill: #f0f0f0 !important; }
2082
-
2083
- /* Mobile responsive content */
2084
- @media (max-width: 767px) {
2085
- .tome-content h2 { font-size: 1.2em; margin-top: 1.5em; }
2086
- .tome-content h3 { font-size: 1.05em; }
2087
- .tome-content pre code { font-size: 12px; padding: 0.8em 1em; }
2088
- .tome-content table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
2089
- .tome-content blockquote { margin: 0.8em 0; }
2090
- }
2091
-
2092
- /* Selection style */
2093
- ::selection { background: var(--acD); color: var(--ac); }
2094
-
2095
- /* Scrollbar style */
2096
- ::-webkit-scrollbar { width: 5px; height: 5px; }
2097
- ::-webkit-scrollbar-track { background: transparent; }
2098
- ::-webkit-scrollbar-thumb { background: var(--bd); border-radius: 10px; }
2099
-
2100
- /* Grain overlay */
2101
- .tome-grain::before {
2102
- content: ""; position: fixed; inset: 0; z-index: 9999; pointer-events: none;
2103
- opacity: .35;
2104
- background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.04'/%3E%3C/svg%3E");
2105
- background-repeat: repeat; background-size: 256px;
2106
- }
2107
-
2108
- /* \u2500\u2500 Expressive code blocks \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
2109
-
2110
- /* Code block wrapper (for titled blocks) */
2111
- .tome-code-block-wrapper { position: relative; margin-bottom: 1.2em; border: 1px solid var(--bd); border-radius: 2px; overflow: hidden; }
2112
- .tome-code-block-wrapper pre { margin-bottom: 0; border: none; border-radius: 0; }
2113
- .tome-code-title {
2114
- font-family: var(--font-code); font-size: 12px; color: var(--tx2);
2115
- background: var(--sf); padding: 6px 12px; border-bottom: 1px solid var(--bd);
2116
- letter-spacing: 0.01em; font-weight: 500;
2117
- }
2118
-
2119
- /* Line highlighting */
2120
- .tome-content pre .line.tome-line-highlight {
2121
- background: rgba(139, 148, 158, 0.1);
2122
- display: inline-block; width: 100%; margin: 0 -1.2em; padding: 0 1.2em;
2123
- }
2124
- html.dark .tome-content pre .line.tome-line-highlight {
2125
- background: rgba(200, 210, 220, 0.08);
2126
- }
2127
-
2128
- /* Diff lines */
2129
- .tome-content pre .line.tome-line-added {
2130
- background: rgba(34, 197, 94, 0.12);
2131
- display: inline-block; width: 100%; margin: 0 -1.2em; padding: 0 1.2em;
2132
- }
2133
- .tome-content pre .line.tome-line-removed {
2134
- background: rgba(239, 68, 68, 0.12);
2135
- display: inline-block; width: 100%; margin: 0 -1.2em; padding: 0 1.2em;
2136
- }
2137
- html.dark .tome-content pre .line.tome-line-added { background: rgba(34, 197, 94, 0.15); }
2138
- html.dark .tome-content pre .line.tome-line-removed { background: rgba(239, 68, 68, 0.15); }
2139
-
2140
- /* Line numbers (CSS counter) */
2141
- .tome-content pre[data-line-numbers] code {
2142
- counter-reset: line;
2143
- }
2144
- .tome-content pre[data-line-numbers] .line::before {
2145
- counter-increment: line;
2146
- content: counter(line);
2147
- display: inline-block; width: 2.5em; margin-inline-end: 1em;
2148
- text-align: end; color: var(--txM); opacity: 0.4;
2149
- font-size: 0.85em; user-select: none;
2150
- border-inline-end: 1px solid var(--bd); padding-inline-end: 0.8em; margin-inline-end: 0.8em;
2151
- }
2152
-
2153
- /* Word highlighting */
2154
- .tome-word-highlight {
2155
- background: rgba(139, 148, 158, 0.2); border-radius: 2px;
2156
- padding: 1px 3px; margin: 0 -1px;
2157
- }
2158
- html.dark .tome-word-highlight {
2159
- background: rgba(200, 210, 220, 0.15);
2160
- }
2161
-
2162
- /* Copy button */
2163
- .tome-content pre { position: relative; }
2164
- .tome-copy-btn {
2165
- position: absolute; top: 8px; inset-inline-end: 8px;
2166
- font-family: var(--font-code); font-size: 11px;
2167
- color: var(--tx2); background: var(--sf); border: 1px solid var(--bd);
2168
- padding: 3px 8px; border-radius: 2px; cursor: pointer;
2169
- opacity: 0; transition: opacity 0.15s;
2170
- z-index: 2; line-height: 1.4;
2171
- }
2172
- .tome-content pre:hover .tome-copy-btn,
2173
- .tome-copy-btn:focus { opacity: 1; }
2174
- .tome-copy-btn:hover { background: var(--sfH); }
2175
-
2176
- /* Shiki dual-theme support */
2177
- .shiki { background: var(--cdBg) !important; }
2178
-
2179
- /* Dark mode: switch Shiki tokens from light-theme inline colors to --shiki-dark CSS vars */
2180
- html.dark .shiki,
2181
- html.dark .shiki span {
2182
- color: var(--shiki-dark) !important;
2183
- }
2184
-
2185
- /* Brighten dim comment tokens (github-dark #6A737D is too low-contrast on dark backgrounds) */
2186
- html.dark .shiki span[style*="--shiki-dark:#6A737D"] {
2187
- --shiki-dark: #a0aab5 !important;
2188
- }
2189
-
2190
- /* Light mode: darken low-contrast github-light tokens for WCAG AA on --cdBg backgrounds */
2191
- html:not(.dark) .shiki span[style*="color:#6A737D"] { color: #57606a !important; }
2192
- html:not(.dark) .shiki span[style*="color:#E36209"] { color: #b35405 !important; }
2193
- html:not(.dark) .shiki span[style*="color:#6F42C1"] { color: #5a32a3 !important; }
2194
- html:not(.dark) .shiki span[style*="color:#22863A"] { color: #1a6e2e !important; }
2195
- html:not(.dark) .shiki span[style*="color:#D73A49"] { color: #b62324 !important; }
2196
- html:not(.dark) .shiki span[style*="color:#005CC5"] { color: #0349b4 !important; }
2197
-
2198
- /* \u2500\u2500 Twoslash type hover tooltips \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
2199
- .twoslash-hover {
2200
- position: relative;
2201
- border-bottom: 1px dotted var(--tx2);
2202
- cursor: help;
2203
- }
2204
- .twoslash-popup-container {
2205
- position: absolute;
2206
- opacity: 0;
2207
- display: none;
2208
- z-index: 10;
2209
- left: 0;
2210
- top: 100%;
2211
- margin-top: 4px;
2212
- padding: 6px 10px;
2213
- background: var(--sf);
2214
- border: 1px solid var(--bd);
2215
- border-radius: 6px;
2216
- font-size: 12px;
2217
- font-family: var(--font-code);
2218
- color: var(--tx);
2219
- white-space: pre-wrap;
2220
- max-width: 500px;
2221
- box-shadow: 0 4px 12px rgba(0,0,0,0.15);
2222
- pointer-events: none;
2223
- }
2224
- .twoslash-hover:hover .twoslash-popup-container {
2225
- opacity: 1;
2226
- display: block;
2227
- }
2228
- /* Twoslash error/warning underlines */
2229
- .twoslash-error {
2230
- position: relative;
2231
- background: rgba(239, 68, 68, 0.1);
2232
- border-bottom: 2px wavy rgba(239, 68, 68, 0.6);
2233
- }
2234
- /* Twoslash highlighted identifiers */
2235
- .twoslash-highlighted {
2236
- background: rgba(139, 148, 158, 0.15);
2237
- border-radius: 2px;
2238
- padding: 1px 2px;
2239
- }
2240
- /* Twoslash type annotation line (^?) */
2241
- .twoslash-popup-code .shiki { background: transparent !important; padding: 0; margin: 0; }
2242
- .twoslash-popup-code .shiki code { padding: 0; font-size: 12px; }
2243
- html.dark .twoslash-popup-container {
2244
- background: var(--sf);
2245
- border-color: var(--bd);
2246
- box-shadow: 0 4px 12px rgba(0,0,0,0.3);
2247
- }
2248
- `;
2249
- var basePath = (config.basePath || "/").replace(/\/$/, "");
2250
- function pathnameToPageId2(pathname) {
2251
- return pathnameToPageId(pathname, basePath, routes);
2252
- }
2253
- function pageIdToPath2(id) {
2254
- return pageIdToPath(id, basePath, routes);
2255
- }
2256
- var _initialPageId = resolveInitialPageId(
2257
- window.location.pathname,
2258
- window.location.hash,
2259
- routes,
2260
- basePath,
2261
- pathnameToPageId
2262
- );
2263
- var _initialPagePromise = loadPage(_initialPageId, routes, loadPageModule);
2264
- function App() {
2265
- const [currentPageId, setCurrentPageId] = useState3(_initialPageId);
2266
- const [pageData, setPageData] = useState3(null);
2267
- const [loading, setLoading] = useState3(true);
2268
- const navigateTo = useCallback3(async (id, opts) => {
2269
- setLoading(true);
2270
- setCurrentPageId(id);
2271
- const fullPath = pageIdToPath2(id);
2272
- if (opts?.replace) {
2273
- window.history.replaceState(null, "", fullPath);
2274
- } else {
2275
- window.history.pushState(null, "", fullPath);
2276
- }
2277
- const data = await loadPage(id, routes, loadPageModule);
2278
- setPageData(data);
2279
- setLoading(false);
2280
- if (!opts?.skipScroll) {
2281
- const anchor = window.location.hash.slice(1);
2282
- if (anchor) {
2283
- requestAnimationFrame(() => {
2284
- const el = document.getElementById(anchor);
2285
- if (el) el.scrollIntoView({ behavior: "smooth", block: "start" });
2286
- });
2287
- } else {
2288
- window.scrollTo(0, 0);
2289
- }
2290
- }
2291
- }, []);
2292
- useEffect3(() => {
2293
- const hash = window.location.hash.slice(1);
2294
- if (hash && routes.some((r) => r.id === hash)) {
2295
- const fullPath = pageIdToPath2(hash);
2296
- window.history.replaceState(null, "", fullPath);
2297
- navigateTo(hash, { replace: true });
2298
- } else {
2299
- const fullPath = pageIdToPath2(currentPageId);
2300
- window.history.replaceState(null, "", fullPath);
2301
- _initialPagePromise.then((data) => {
2302
- setPageData(data);
2303
- setLoading(false);
2304
- });
2305
- }
2306
- }, []);
2307
- useEffect3(() => {
2308
- const onPopState = () => {
2309
- const id = pathnameToPageId2(window.location.pathname);
2310
- if (id && id !== currentPageId) {
2311
- navigateTo(id, { replace: true, skipScroll: true });
2312
- }
2313
- };
2314
- window.addEventListener("popstate", onPopState);
2315
- return () => window.removeEventListener("popstate", onPopState);
2316
- }, [currentPageId, navigateTo]);
2317
- const mermaidModuleRef = useRef3(null);
2318
- const [mermaidTheme, setMermaidTheme] = useState3(() => {
2319
- if (typeof document === "undefined") return "light";
2320
- if (document.documentElement.classList.contains("dark")) return "dark";
2321
- const mode = config.theme?.mode || "auto";
2322
- if (mode === "dark") return "dark";
2323
- if (mode === "light") return "light";
2324
- return window.matchMedia?.("(prefers-color-scheme: dark)").matches ? "dark" : "light";
2325
- });
2326
- useEffect3(() => {
2327
- const observer = new MutationObserver(() => {
2328
- const isDark = document.documentElement.classList.contains("dark");
2329
- setMermaidTheme(isDark ? "dark" : "light");
2330
- });
2331
- observer.observe(document.documentElement, { attributes: true, attributeFilter: ["class"] });
2332
- return () => observer.disconnect();
2333
- }, []);
2334
- useEffect3(() => {
2335
- const els = document.querySelectorAll(".tome-mermaid[data-mermaid]");
2336
- if (els.length === 0) return;
2337
- let cancelled = false;
2338
- const MERMAID_CDN = "https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs";
2339
- (async () => {
2340
- try {
2341
- if (!mermaidModuleRef.current) {
2342
- mermaidModuleRef.current = (await import(
2343
- /* @vite-ignore */
2344
- MERMAID_CDN
2345
- )).default;
2346
- }
2347
- const mermaid = mermaidModuleRef.current;
2348
- if (cancelled) return;
2349
- const isDark = mermaidTheme === "dark";
2350
- const resolvedFont = getComputedStyle(document.documentElement).getPropertyValue("--font-body").trim() || "sans-serif";
2351
- mermaid.initialize({
2352
- startOnLoad: false,
2353
- theme: isDark ? "dark" : "default",
2354
- fontFamily: resolvedFont,
2355
- flowchart: { padding: 15, nodeSpacing: 30, rankSpacing: 40 }
2356
- });
2357
- for (let i = 0; i < els.length; i++) {
2358
- const el = els[i];
2359
- const encoded = el.getAttribute("data-mermaid");
2360
- if (!encoded) continue;
2361
- try {
2362
- const code = atob(encoded);
2363
- const { svg } = await mermaid.render(`tome-mermaid-${i}-${Date.now()}`, code);
2364
- if (!cancelled) {
2365
- el.innerHTML = svg;
2366
- }
2367
- } catch (err) {
2368
- console.warn("[tome] Mermaid render failed:", err);
2369
- el.textContent = "Diagram rendering failed";
2370
- el.style.cssText = "padding:16px;color:var(--txM);font-size:13px;border:1px dashed var(--bd);border-radius:2px;text-align:center;";
2371
- }
2372
- }
2373
- } catch (err) {
2374
- console.warn("[tome] Failed to load mermaid from CDN:", err);
2375
- els.forEach((el) => {
2376
- el.textContent = "Failed to load diagram renderer";
2377
- el.style.cssText = "padding:16px;color:var(--txM);font-size:13px;border:1px dashed var(--bd);border-radius:2px;text-align:center;";
2378
- });
2379
- }
2380
- })();
2381
- return () => {
2382
- cancelled = true;
2383
- };
2384
- }, [pageData, loading, mermaidTheme]);
2385
- useEffect3(() => {
2386
- if (loading) return;
2387
- const preBlocks = document.querySelectorAll(".tome-content pre");
2388
- const buttons = [];
2389
- preBlocks.forEach((pre) => {
2390
- if (pre.querySelector(".tome-copy-btn")) return;
2391
- const btn = document.createElement("button");
2392
- btn.className = "tome-copy-btn";
2393
- btn.textContent = "Copy";
2394
- btn.addEventListener("click", async () => {
2395
- const code = pre.querySelector("code");
2396
- if (code) {
2397
- try {
2398
- await navigator.clipboard.writeText(code.textContent || "");
2399
- btn.textContent = "Copied!";
2400
- setTimeout(() => {
2401
- btn.textContent = "Copy";
2402
- }, 2e3);
2403
- } catch {
2404
- btn.textContent = "Failed";
2405
- setTimeout(() => {
2406
- btn.textContent = "Copy";
2407
- }, 2e3);
2408
- }
2409
- }
2410
- });
2411
- pre.appendChild(btn);
2412
- buttons.push(btn);
2413
- });
2414
- return () => {
2415
- buttons.forEach((btn) => btn.remove());
2416
- };
2417
- }, [pageData, loading]);
2418
- const allPages = routes.map((r) => ({
2419
- id: r.id,
2420
- title: r.frontmatter.title,
2421
- description: r.frontmatter.description
2422
- }));
2423
- const currentRoute = routes.find((r) => r.id === currentPageId);
2424
- const currentVersion = detectCurrentVersion(currentRoute, versions);
2425
- const editUrl = computeEditUrl(config.editLink, currentRoute?.filePath);
2426
- const currentLocale = currentRoute?.locale || i18n?.defaultLocale || "en";
2427
- const dir = i18n?.localeDirs?.[currentLocale] || "ltr";
2428
- useEffect3(() => {
2429
- const hasMathPlaceholders = document.querySelectorAll(".tome-math[data-math]").length > 0;
2430
- if (!config.math && !hasMathPlaceholders) return;
2431
- const id = "tome-katex-css";
2432
- if (document.getElementById(id)) return;
2433
- const link = document.createElement("link");
2434
- link.id = id;
2435
- link.rel = "stylesheet";
2436
- link.href = "https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css";
2437
- link.crossOrigin = "anonymous";
2438
- document.head.appendChild(link);
2439
- }, [pageData, loading]);
2440
- useEffect3(() => {
2441
- const els = document.querySelectorAll(".tome-math[data-math]");
2442
- if (els.length === 0) return;
2443
- let cancelled = false;
2444
- const KATEX_CDN = "https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.mjs";
2445
- (async () => {
2446
- try {
2447
- const katex = (await import(
2448
- /* @vite-ignore */
2449
- KATEX_CDN
2450
- )).default;
2451
- if (cancelled) return;
2452
- for (const el of els) {
2453
- const encoded = el.getAttribute("data-math");
2454
- if (!encoded) continue;
2455
- try {
2456
- const tex = atob(encoded);
2457
- const isBlock = el.classList.contains("tome-math-block");
2458
- katex.render(tex, el, {
2459
- displayMode: isBlock,
2460
- throwOnError: false
2461
- });
2462
- } catch (err) {
2463
- console.warn("[tome] KaTeX render failed:", err);
2464
- }
2465
- }
2466
- } catch (err) {
2467
- console.warn("[tome] Failed to load KaTeX from CDN:", err);
2468
- }
2469
- })();
2470
- return () => {
2471
- cancelled = true;
2472
- };
2473
- }, [pageData, loading]);
2474
- return /* @__PURE__ */ jsxs3(Fragment2, { children: [
2475
- /* @__PURE__ */ jsx3("style", { children: contentStyles }),
2476
- /* @__PURE__ */ jsx3(
2477
- Shell,
2478
- {
2479
- config,
2480
- navigation,
2481
- currentPageId,
2482
- pageHtml: !pageData?.isMdx ? loading ? "" : pageData?.html || "<p>Page not found</p>" : void 0,
2483
- pageComponent: pageData?.isMdx ? pageData.component : void 0,
2484
- mdxComponents: MDX_COMPONENTS,
2485
- pageTitle: pageData?.frontmatter.title || (loading ? "" : "Not Found"),
2486
- pageDescription: pageData?.frontmatter.description,
2487
- headings: pageData?.headings || [],
2488
- tocEnabled: pageData?.frontmatter.toc !== false,
2489
- editUrl,
2490
- lastUpdated: currentRoute?.lastUpdated,
2491
- changelogEntries: !pageData?.isMdx ? pageData?.changelogEntries : void 0,
2492
- onNavigate: navigateTo,
2493
- allPages,
2494
- docContext,
2495
- versioning: versions || void 0,
2496
- currentVersion,
2497
- basePath,
2498
- isDraft: currentRoute?.frontmatter?.draft === true,
2499
- dir,
2500
- i18n: i18n || void 0,
2501
- currentLocale,
2502
- overrides
2503
- }
2504
- )
2505
- ] });
2506
- }
2507
- var container = document.getElementById("tome-root");
2508
- if (container) {
2509
- const root = createRoot(container);
2510
- root.render(/* @__PURE__ */ jsx3(App, {}));
2511
- }
2512
- var entry_default = App;
2513
-
2514
- export {
2515
- THEME_PRESETS,
2516
- AiChat,
2517
- Shell,
2518
- entry_default
2519
- };