@makuja/peek 1.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/dist/index.mjs +1473 -0
- package/package.json +85 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,1473 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { execFile } from "node:child_process";
|
|
4
|
+
import { access, readFile, readdir, realpath, stat } from "node:fs/promises";
|
|
5
|
+
import { homedir, platform } from "node:os";
|
|
6
|
+
import { basename, isAbsolute, join, normalize, relative, resolve, sep } from "node:path";
|
|
7
|
+
import { cancel, intro, log, outro, spinner } from "@clack/prompts";
|
|
8
|
+
import { cli, define } from "gunshi";
|
|
9
|
+
import pc from "picocolors";
|
|
10
|
+
import { tasklist } from "@mdit/plugin-tasklist";
|
|
11
|
+
import { fromAsyncCodeToHtml } from "@shikijs/markdown-it/async";
|
|
12
|
+
import createMarkdownItAsync from "markdown-it-async";
|
|
13
|
+
import { codeToHtml } from "shiki";
|
|
14
|
+
import { serve } from "@hono/node-server";
|
|
15
|
+
import { Hono } from "hono";
|
|
16
|
+
import ignore from "ignore";
|
|
17
|
+
import { constants, watch } from "node:fs";
|
|
18
|
+
import renderToString from "preact-render-to-string";
|
|
19
|
+
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
|
|
20
|
+
import { useState } from "preact/hooks";
|
|
21
|
+
import { streamSSE } from "hono/streaming";
|
|
22
|
+
//#region src/core/content-type.ts
|
|
23
|
+
const EXTENSION_MAP = new Map([
|
|
24
|
+
[".md", "markdown"],
|
|
25
|
+
[".html", "html"],
|
|
26
|
+
[".htm", "html"]
|
|
27
|
+
]);
|
|
28
|
+
function getExtension(filePath) {
|
|
29
|
+
const lastSep = Math.max(filePath.lastIndexOf("/"), filePath.lastIndexOf("\\"));
|
|
30
|
+
const name = lastSep === -1 ? filePath : filePath.slice(lastSep + 1);
|
|
31
|
+
const lastDot = name.lastIndexOf(".");
|
|
32
|
+
if (lastDot === -1 || lastDot === name.length - 1) return "";
|
|
33
|
+
return name.slice(lastDot).toLowerCase();
|
|
34
|
+
}
|
|
35
|
+
function getContentType(filePath) {
|
|
36
|
+
return EXTENSION_MAP.get(getExtension(filePath)) ?? null;
|
|
37
|
+
}
|
|
38
|
+
function isSupportedFile(filePath) {
|
|
39
|
+
return getContentType(filePath) !== null;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/lib/logger.ts
|
|
43
|
+
const PREFIX = "[peek]";
|
|
44
|
+
const logger = {
|
|
45
|
+
info: (...args) => console.log(PREFIX, ...args),
|
|
46
|
+
warn: (...args) => console.warn(PREFIX, ...args),
|
|
47
|
+
error: (...args) => console.error(PREFIX, ...args)
|
|
48
|
+
};
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/lib/markdown.ts
|
|
51
|
+
let md = null;
|
|
52
|
+
let initPromise = null;
|
|
53
|
+
function initMarkdown() {
|
|
54
|
+
if (!initPromise) initPromise = (async () => {
|
|
55
|
+
const instance = createMarkdownItAsync();
|
|
56
|
+
instance.use(tasklist);
|
|
57
|
+
instance.use(fromAsyncCodeToHtml(codeToHtml, {
|
|
58
|
+
themes: {
|
|
59
|
+
light: "vitesse-light",
|
|
60
|
+
dark: "vitesse-dark"
|
|
61
|
+
},
|
|
62
|
+
defaultColor: false
|
|
63
|
+
}));
|
|
64
|
+
md = instance;
|
|
65
|
+
})().catch((e) => {
|
|
66
|
+
initPromise = null;
|
|
67
|
+
throw e;
|
|
68
|
+
});
|
|
69
|
+
return initPromise;
|
|
70
|
+
}
|
|
71
|
+
async function renderMarkdown(content) {
|
|
72
|
+
if (!md) throw new Error("Markdown renderer not initialized. Call initMarkdown() first.");
|
|
73
|
+
if (content === "") return "";
|
|
74
|
+
return md.renderAsync(content);
|
|
75
|
+
}
|
|
76
|
+
//#endregion
|
|
77
|
+
//#region src/lib/node-error.ts
|
|
78
|
+
function isNodeError(e) {
|
|
79
|
+
return e instanceof Error && "code" in e && typeof e.code === "string" && typeof e.message === "string";
|
|
80
|
+
}
|
|
81
|
+
//#endregion
|
|
82
|
+
//#region src/core/result.ts
|
|
83
|
+
function ok(value) {
|
|
84
|
+
return {
|
|
85
|
+
ok: true,
|
|
86
|
+
value
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function err(error) {
|
|
90
|
+
return {
|
|
91
|
+
ok: false,
|
|
92
|
+
error
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function map(result, fn) {
|
|
96
|
+
return result.ok ? ok(fn(result.value)) : result;
|
|
97
|
+
}
|
|
98
|
+
async function safe(fn, onError) {
|
|
99
|
+
try {
|
|
100
|
+
return ok(await fn());
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return err(onError(e));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/styles/content.css?inline
|
|
107
|
+
var content_default = ".markdown-body {\n color: var(--foreground);\n word-wrap: break-word;\n font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif;\n font-size: 16px;\n line-height: 1.75;\n\n & h1, & h2, & h3, & h4, & h5, & h6 {\n margin-top: 24px;\n margin-bottom: 16px;\n font-weight: 600;\n line-height: 1.5;\n }\n\n & h1 {\n font-size: 2em;\n }\n\n & h2 {\n border-bottom: 1px solid var(--border);\n padding-bottom: .3em;\n font-size: 1.5em;\n }\n\n & h3 {\n font-size: 1.25em;\n }\n\n & h4 {\n font-size: 1em;\n }\n\n & h5 {\n font-size: .875em;\n }\n\n & h6 {\n color: var(--muted-foreground);\n font-size: .85em;\n }\n\n & p {\n margin-top: 0;\n margin-bottom: 16px;\n }\n\n & a {\n color: var(--primary);\n text-decoration: none;\n\n &:hover {\n text-decoration: underline;\n }\n }\n\n & strong {\n font-weight: 600;\n }\n\n & ul, & ol {\n list-style: revert;\n margin-top: 0;\n margin-bottom: 16px;\n padding-left: 1.5em;\n }\n\n & li + li {\n margin-top: .25em;\n }\n\n & .task-list-container {\n list-style: none;\n }\n\n & blockquote {\n color: var(--muted-foreground);\n border-left: .25em solid var(--border);\n margin: 0 0 16px;\n padding: 0 1em;\n }\n\n & code {\n white-space: break-spaces;\n background-color: var(--muted);\n border-radius: 6px;\n margin: 0;\n padding: .2em .4em;\n font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;\n font-size: 85%;\n }\n\n & pre {\n color: var(--shiki-light);\n background-color: var(--muted);\n border-radius: 6px;\n margin-top: 0;\n margin-bottom: 16px;\n padding: 16px;\n font-size: 85%;\n line-height: 1.45;\n overflow: auto;\n\n & code {\n white-space: pre;\n background: none;\n border: 0;\n margin: 0;\n padding: 0;\n font-size: 100%;\n }\n }\n\n & pre.shiki {\n font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;\n }\n\n & .shiki, & .shiki span {\n color: var(--shiki-light);\n background-color: var(--muted);\n }\n\n & table {\n border-spacing: 0;\n border-collapse: collapse;\n width: max-content;\n max-width: 100%;\n margin-top: 0;\n margin-bottom: 16px;\n display: block;\n overflow: auto;\n\n & th {\n font-weight: 600;\n }\n\n & th, & td {\n border: 1px solid var(--border);\n padding: 6px 13px;\n }\n\n & tr {\n background-color: var(--card);\n border-top: 1px solid var(--border);\n }\n }\n\n & hr {\n background-color: var(--border);\n border: 0;\n height: .25em;\n margin: 24px 0;\n padding: 0;\n }\n\n & img {\n box-sizing: border-box;\n max-width: 100%;\n }\n\n & input[type=\"checkbox\"] {\n vertical-align: middle;\n margin: 0 .2em .25em -1.4em;\n }\n\n & del {\n text-decoration: line-through;\n }\n\n & > :first-child {\n margin-top: 0;\n }\n\n & > :last-child {\n margin-bottom: 0;\n }\n}\n\n.dark .markdown-body {\n & .shiki, & .shiki span {\n color: var(--shiki-dark);\n background-color: var(--muted);\n }\n}\n";
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/core/error.ts
|
|
110
|
+
function toError(value) {
|
|
111
|
+
if (value instanceof Error) return value;
|
|
112
|
+
if (typeof value === "string") return new Error(value);
|
|
113
|
+
return new Error(String(value));
|
|
114
|
+
}
|
|
115
|
+
function typedError(type, cause, props) {
|
|
116
|
+
return {
|
|
117
|
+
...props,
|
|
118
|
+
type,
|
|
119
|
+
cause: toError(cause)
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/lib/read-text-file.ts
|
|
124
|
+
function readTextFile(path) {
|
|
125
|
+
return safe(() => readFile(path, "utf-8"), (e) => isNodeError(e) && e.code === "ENOENT" ? typedError("file-not-found", e, { path }) : typedError("read-error", e, { path }));
|
|
126
|
+
}
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/lib/styles.ts
|
|
129
|
+
function getXdgConfigPath() {
|
|
130
|
+
const xdgConfigHome = process.env.XDG_CONFIG_HOME;
|
|
131
|
+
if (xdgConfigHome) return resolve(xdgConfigHome, "peek", "style.css");
|
|
132
|
+
return resolve(homedir(), ".config", "peek", "style.css");
|
|
133
|
+
}
|
|
134
|
+
async function resolveStyles(cssOption) {
|
|
135
|
+
if (cssOption) return map(await readTextFile(isAbsolute(cssOption) ? cssOption : resolve(process.cwd(), cssOption)), (contentCss) => ({ contentCss }));
|
|
136
|
+
const xdgResult = await readTextFile(getXdgConfigPath());
|
|
137
|
+
if (xdgResult.ok) return ok({ contentCss: xdgResult.value });
|
|
138
|
+
if (xdgResult.error.type === "read-error") return xdgResult;
|
|
139
|
+
return ok({ contentCss: content_default });
|
|
140
|
+
}
|
|
141
|
+
//#endregion
|
|
142
|
+
//#region src/lib/file-tree.ts
|
|
143
|
+
const DEFAULT_IGNORE_PATTERNS = [".git/"];
|
|
144
|
+
async function readGitignore(path) {
|
|
145
|
+
const result = await readTextFile(path);
|
|
146
|
+
if (result.ok) {
|
|
147
|
+
const ig = ignore();
|
|
148
|
+
ig.add(result.value);
|
|
149
|
+
return ig;
|
|
150
|
+
}
|
|
151
|
+
if (result.error.type !== "file-not-found") logger.warn(`Failed to read .gitignore at ${path}:`, result.error);
|
|
152
|
+
return null;
|
|
153
|
+
}
|
|
154
|
+
function tryLoadGitignoreFromEntries(dir, entries) {
|
|
155
|
+
if (!entries.some((e) => e.isFile() && e.name === ".gitignore")) return Promise.resolve(null);
|
|
156
|
+
return readGitignore(join(dir, ".gitignore"));
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Check whether a path is ignored by any of the loaded .gitignore rules.
|
|
160
|
+
*
|
|
161
|
+
* NOTE: Cross-file negation is not supported. A negation pattern (`!pattern`)
|
|
162
|
+
* in a child .gitignore will NOT override a match from a parent .gitignore
|
|
163
|
+
* because each rule set is evaluated independently.
|
|
164
|
+
*/
|
|
165
|
+
function isPathIgnored(relPath, isDir, rules) {
|
|
166
|
+
for (const rule of rules) {
|
|
167
|
+
const pathFromBase = rule.baseDir === "" ? relPath : relative(rule.baseDir, relPath);
|
|
168
|
+
if (pathFromBase.startsWith("..")) continue;
|
|
169
|
+
const checkPath = isDir ? `${pathFromBase}/` : pathFromBase;
|
|
170
|
+
if (rule.ig.ignores(checkPath)) return true;
|
|
171
|
+
}
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
async function buildFileTree(rootDir) {
|
|
175
|
+
let rootEntries;
|
|
176
|
+
try {
|
|
177
|
+
rootEntries = await readdir(rootDir, { withFileTypes: true });
|
|
178
|
+
} catch (e) {
|
|
179
|
+
return err(typedError("root-not-accessible", e));
|
|
180
|
+
}
|
|
181
|
+
const defaultIg = ignore();
|
|
182
|
+
defaultIg.add(DEFAULT_IGNORE_PATTERNS);
|
|
183
|
+
const rules = [{
|
|
184
|
+
ig: defaultIg,
|
|
185
|
+
baseDir: ""
|
|
186
|
+
}];
|
|
187
|
+
const rootGitignore = await tryLoadGitignoreFromEntries(rootDir, rootEntries);
|
|
188
|
+
if (rootGitignore) rules.push({
|
|
189
|
+
ig: rootGitignore,
|
|
190
|
+
baseDir: ""
|
|
191
|
+
});
|
|
192
|
+
let rootReal;
|
|
193
|
+
try {
|
|
194
|
+
rootReal = await realpath(rootDir);
|
|
195
|
+
} catch (e) {
|
|
196
|
+
return err(typedError("root-not-accessible", e));
|
|
197
|
+
}
|
|
198
|
+
const visited = new Set([rootReal]);
|
|
199
|
+
try {
|
|
200
|
+
return ok(await processEntries(rootEntries, rootDir, rootDir, rules, visited));
|
|
201
|
+
} catch (e) {
|
|
202
|
+
return err(typedError("tree-traversal-error", e));
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
async function scanDirectory(dir, rootDir, parentRules, visited) {
|
|
206
|
+
let real;
|
|
207
|
+
try {
|
|
208
|
+
real = await realpath(dir);
|
|
209
|
+
} catch {
|
|
210
|
+
return [];
|
|
211
|
+
}
|
|
212
|
+
if (visited.has(real)) return [];
|
|
213
|
+
visited.add(real);
|
|
214
|
+
let entries;
|
|
215
|
+
try {
|
|
216
|
+
entries = await readdir(dir, { withFileTypes: true });
|
|
217
|
+
} catch (e) {
|
|
218
|
+
logger.warn(`Failed to read directory ${dir}:`, e);
|
|
219
|
+
return [];
|
|
220
|
+
}
|
|
221
|
+
const localGitignore = await tryLoadGitignoreFromEntries(dir, entries);
|
|
222
|
+
const rules = localGitignore ? [...parentRules, {
|
|
223
|
+
ig: localGitignore,
|
|
224
|
+
baseDir: relative(rootDir, dir)
|
|
225
|
+
}] : parentRules;
|
|
226
|
+
return processEntries(entries, dir, rootDir, rules, visited);
|
|
227
|
+
}
|
|
228
|
+
async function processEntries(entries, dir, rootDir, rules, visited) {
|
|
229
|
+
const fileNodes = [];
|
|
230
|
+
const dirPromises = [];
|
|
231
|
+
for (const entry of entries) {
|
|
232
|
+
const fullPath = join(dir, entry.name);
|
|
233
|
+
const relPath = relative(rootDir, fullPath);
|
|
234
|
+
if (entry.isDirectory()) {
|
|
235
|
+
if (isPathIgnored(relPath, true, rules)) continue;
|
|
236
|
+
dirPromises.push(scanDirectory(fullPath, rootDir, rules, visited).then((children) => children.length > 0 ? {
|
|
237
|
+
name: entry.name,
|
|
238
|
+
path: relPath,
|
|
239
|
+
type: "directory",
|
|
240
|
+
children
|
|
241
|
+
} : null));
|
|
242
|
+
} else if (entry.isFile() && isSupportedFile(entry.name)) {
|
|
243
|
+
if (isPathIgnored(relPath, false, rules)) continue;
|
|
244
|
+
fileNodes.push({
|
|
245
|
+
name: entry.name,
|
|
246
|
+
path: relPath,
|
|
247
|
+
type: "file"
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
const nodes = [...(await Promise.all(dirPromises)).filter((node) => node !== null), ...fileNodes];
|
|
252
|
+
nodes.sort((a, b) => {
|
|
253
|
+
if (a.type !== b.type) return a.type === "directory" ? -1 : 1;
|
|
254
|
+
return a.name.localeCompare(b.name, "en");
|
|
255
|
+
});
|
|
256
|
+
return nodes;
|
|
257
|
+
}
|
|
258
|
+
//#endregion
|
|
259
|
+
//#region src/lib/file-tree-cache.ts
|
|
260
|
+
/**
|
|
261
|
+
* Callers that already hold a reference to the pending promise will still
|
|
262
|
+
* receive its (now-stale) result after `invalidate()` is called. The next
|
|
263
|
+
* call to `get()` after invalidation will trigger a fresh build.
|
|
264
|
+
*/
|
|
265
|
+
function createFileTreeCache(rootDir) {
|
|
266
|
+
let cached = null;
|
|
267
|
+
let pending = null;
|
|
268
|
+
return {
|
|
269
|
+
async get() {
|
|
270
|
+
if (cached) return cached;
|
|
271
|
+
if (pending) return pending;
|
|
272
|
+
const currentPending = buildFileTree(rootDir).then((result) => {
|
|
273
|
+
if (pending === currentPending) {
|
|
274
|
+
if (result.ok) cached = result;
|
|
275
|
+
pending = null;
|
|
276
|
+
}
|
|
277
|
+
return result;
|
|
278
|
+
});
|
|
279
|
+
pending = currentPending;
|
|
280
|
+
return currentPending;
|
|
281
|
+
},
|
|
282
|
+
invalidate() {
|
|
283
|
+
cached = null;
|
|
284
|
+
pending = null;
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/lib/watcher.ts
|
|
290
|
+
function createFileWatcher(debounceMs = 100) {
|
|
291
|
+
const watchers = [];
|
|
292
|
+
const debounceTimers = /* @__PURE__ */ new Map();
|
|
293
|
+
let closed = false;
|
|
294
|
+
function debounced(key, fn) {
|
|
295
|
+
if (closed) return;
|
|
296
|
+
const existing = debounceTimers.get(key);
|
|
297
|
+
if (existing) clearTimeout(existing);
|
|
298
|
+
debounceTimers.set(key, setTimeout(() => {
|
|
299
|
+
debounceTimers.delete(key);
|
|
300
|
+
if (!closed) fn();
|
|
301
|
+
}, debounceMs));
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
watchFile(filePath, callback) {
|
|
305
|
+
if (closed) return;
|
|
306
|
+
const watcher = watch(filePath, (eventType) => {
|
|
307
|
+
debounced(filePath, () => callback(filePath));
|
|
308
|
+
if (eventType === "rename") watcher.close();
|
|
309
|
+
});
|
|
310
|
+
watcher.on("error", () => {
|
|
311
|
+
watcher.close();
|
|
312
|
+
});
|
|
313
|
+
watchers.push(watcher);
|
|
314
|
+
},
|
|
315
|
+
watchDirectory(dirPath, callback) {
|
|
316
|
+
if (closed) return;
|
|
317
|
+
const watcher = watch(dirPath, { recursive: true }, (_eventType, filename) => {
|
|
318
|
+
if (!filename) return;
|
|
319
|
+
const filePath = filename.toString();
|
|
320
|
+
if (isSupportedFile(filePath)) debounced(filePath, () => callback(filePath));
|
|
321
|
+
});
|
|
322
|
+
watchers.push(watcher);
|
|
323
|
+
},
|
|
324
|
+
close() {
|
|
325
|
+
closed = true;
|
|
326
|
+
for (const watcher of watchers) watcher.close();
|
|
327
|
+
watchers.length = 0;
|
|
328
|
+
for (const timer of debounceTimers.values()) clearTimeout(timer);
|
|
329
|
+
debounceTimers.clear();
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
//#endregion
|
|
334
|
+
//#region src/server/renderer/favicon.js
|
|
335
|
+
const faviconBase64 = "AAABAAMAMDAAAAEAIACoJQAANgAAACAgAAABACAAqBAAAN4lAAAQEAAAAQAgAGgEAACGNgAAKAAAADAAAABgAAAAAQAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////Kv///3H///+r////1/////P/////////////////////////////////////////////////////////////////////////////////////////8////9f///+r////cf///yoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///1n////B///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////B////WQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8+////xP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8T///8+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///3r/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////egAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////mf///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////5kAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///+Z//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+ZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///3r/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////egAAAAAAAAAAAAAAAAAAAAAAAAAA////Pv///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////z4AAAAAAAAAAAAAAAAAAAAA////xP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8QAAAAAAAAAAAAAAAD///9Z////////////////////////////////////////////////////////////////////////////////+/v7//X19f/9/f3/////////////////////////////////9PT0//r6+v/+/v7///////////////////////////////////////////////////////////////////////////////////////////////9ZAAAAAAAAAAD////B///////////////////////////////////////////////////////////////////////////29vb/nJ+e/19kY/+6vLz////////////////////////////U1dX/YWZl/3yAf//19fX////////////////////////////////////////////////////////////////////////////////////////////////BAAAAAP///yr////////////////////////////////////////////////////////////////////////////////s7e3/U1hY/zY8O/9dYmH///////////////////////////+lp6f/Oj8+/z9EQ//u7u7/////////////////////////////////////////////////////////////////////////////////////////////////////Kv///3H////////////////////////////////////////////////////////////////////////////////w8PD/Wl9f/zQ6Of9HTUz/+vr6//////////////////////+xs7P/Oj8//zU7Ov/g4eD//v7+////////////////////////////////////////////////////////////////////////////////////////////////cf///6v////////////////////////////////////////////////////////////////////////////////z8/P/dnp5/zQ6Of9FSkn/7+/v///////////////////////DxMT/O0FA/zQ6Of/DxcT//Pz8////////////////////////////////////////////////////////////////////////////////////////////////q////9f////////////////////////////////////////////////////////////////////////////////39/f/kZSU/zQ6Of9CSEf/4+Pj///////////////////////U1dX/PEJB/zQ6Of+lp6f/+fn5////////////////////////////////////////////////////////////////////////////////////////////////1/////P////////////////////////////////////////////////////////////////////////////////6+vr/ra+v/zQ6Of9ARkX/19jY///////////////////////l5ub/PUNC/zQ6Of+Hi4r/9/f3////////////////////////////////////////////////////////////////////////////////////////////////8//////////////////////////////////////////////////////////////////////////////////////9/f3/yMrK/zU7Ov8+REP/yszM///////////////////////29vb/P0VE/zQ6Of9pbm7/9PT0/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////v7+//v7+//4+Pj/+Pj4//j4+P/4+Pj/09XU/zc9PP88QkH/srSz//j4+P/4+Pj/+Pj4//j4+P/4+Pj/S1BP/zU7Ov9XXFz/7Ozs//j4+P/4+Pj/+Pj4//j4+P/4+Pj/+/v7//7+/v//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8vLy/7W3tv+doKD/naCg/52goP+doKD/i46O/zg+Pf84Pj3/a29v/52goP+doKD/naCg/52goP+doKD/S1BP/zU7Ov9FSkr/lZiX/52goP+doKD/naCg/52goP+doKD/tLe2//Ly8v//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////nJ+f/z1DQv80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/PUNC/5ygn///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////vsC//0lOTf8/RUT/P0VE/z9FRP8/RUT/PkNC/zg+Pf80Ojn/Njw7/z9FRP8/RUT/P0VE/z9FRP8/RUT/OkA//zU7Ov80Ojn/PEJB/z9FRP8/RUT/P0VE/z9FRP8/RUT/SU5N/77Av////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////f39/+jo6P/d3t3/3d7e/93e3v/d3t7/0dPS/05TUv80Ojn/QUdG/9vc3P/d3t7/3d7e/93e3v/d3t7/oqSk/zpAP/81Ozr/xsfH/9zd3f/d3t7/3d7e/93e3v/d3t3/6Ojo//39/f//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////9PT0/21ycf80Ojn/QkdG//Ly8v//////////////////////xsfH/z1DQv80Ojn/ycrK//z9/P//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////9vf3/4yPjv80Ojn/QEZF/+Pk4///////////////////////1NXV/z5EQ/80Ojn/qq2s//n5+f//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+fn5/6qtrP80Ojn/PkRD/9TV1f//////////////////////4+Tj/0BGRf80Ojn/jI+O//b39////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////P39/8nKyv80Ojn/PUNC/8bHx///////////////////////8vLy/0JHRv80Ojn/bXJx//T09P///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////f39/+jo6P/d3t3/3d7e/93e3v/d3t7/3N3d/8bHx/81Ozr/OkA//6KkpP/d3t7/3d7e/93e3v/d3t7/29zc/0FHRv80Ojn/TlNS/9HT0v/d3t7/3d7e/93e3v/d3t3/6Ojo//39/f//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////vsC//0lOTf8/RUT/P0VE/z9FRP8/RUT/P0VE/zxCQf80Ojn/NTs6/zpAP/8/RUT/P0VE/z9FRP8/RUT/P0VE/zY8O/80Ojn/OD49/z5DQv8/RUT/P0VE/z9FRP8/RUT/SU5N/77Av///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////nKCf/z1DQv80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/NDo5/zQ6Of80Ojn/PUNC/5yfn///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8vLy/7S3tv+doKD/naCg/52goP+doKD/naCg/5WYl/9FSkr/NTs6/0tQT/+doKD/naCg/52goP+doKD/naCg/2tvb/84Pj3/OD49/4uOjv+doKD/naCg/52goP+doKD/tbe2//Ly8v///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////v7+//v7+//4+Pj/+Pj4//j4+P/4+Pj/+Pj4/+zs7P9XXFz/NTs6/0tQT//4+Pj/+Pj4//j4+P/4+Pj/+Pj4/7K0tP88QkH/Nz08/9PV1P/4+Pj/+Pj4//j4+P/4+Pj/+/v7//7+/v////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////T09P9pbm7/NDo5/z9FRP/29vb//////////////////////8rMzP8+REP/NTs6/8jKyf/9/f3///////////////////////////////////////////////////////////////////////////////////////////P///////////////////////////////////////////////////////////////////////////////////////////f39/+Hi4r/NDo5/z1DQv/l5ub//////////////////////9fY2P9ARkX/NDo5/62vr//6+vr/////////////////////////////////////////////////////////////////////////////////////8////9f///////////////////////////////////////////////////////////////////////////////////////////n5+f+lp6f/NDo5/zxCQf/U1dX//////////////////////+Pj4/9CSEf/NDo5/5GUlP/39/f/////////////////////////////////////////////////////////////////////////////////////1////6v///////////////////////////////////////////////////////////////////////////////////////////z8/P/DxcT/NDo5/ztBQP/DxMT//////////////////////+/v7/9FSkn/NDo5/3Z6ef/z8/P/////////////////////////////////////////////////////////////////////////////////////q////3H///////////////////////////////////////////////////////////////////////////////////////////7+/v/g4eH/NTs6/zo/P/+xs7P///////////////////////r6+v9HTUz/NDo5/1pfX//w8PD/////////////////////////////////////////////////////////////////////////////////////cf///yr////////////////////////////////////////////////////////////////////////////////////////////////u7u7/P0RD/zo/Pv+lp6f///////////////////////////9dYmH/Njw7/1NYWP/s7e3/////////////////////////////////////////////////////////////////////////////////////KgAAAAD////B///////////////////////////////////////////////////////////////////////////////////////////19fX/fIB//2FmZf/U1dX///////////////////////////+6vLz/X2Rj/5yfnv/29vb////////////////////////////////////////////////////////////////////////////////BAAAAAAAAAAD///9Z///////////////////////////////////////////////////////////////////////////////////////////+/v7/+vr6//T09P/////////////////////////////////9/f3/9fX1//v7+/////////////////////////////////////////////////////////////////////////////////////9ZAAAAAAAAAAAAAAAA////xP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8QAAAAAAAAAAAAAAAAAAAAA////Pv///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////z4AAAAAAAAAAAAAAAAAAAAAAAAAAP///3r/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////egAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///+Z//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////+ZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////mf///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////5kAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///3r/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////egAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8+////xP///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8T///8+AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///1n////B///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////B////WQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////Kv///3H///+r////1/////P/////////////////////////////////////////////////////////////////////////////////////////8////9f///+r////cf///yoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP/gAAAH/wAA/4AAAAH/AAD+AAAAAH8AAPwAAAAAPwAA+AAAAAAfAADwAAAAAA8AAOAAAAAABwAAwAAAAAADAADAAAAAAAMAAIAAAAAAAQAAgAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAABAACAAAAAAAEAAMAAAAAAAwAAwAAAAAADAADgAAAAAAcAAPAAAAAADwAA+AAAAAAfAAD8AAAAAD8AAP4AAAAAfwAA/4AAAAH/AAD/4AAAB/8AACgAAAAgAAAAQAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8G////Yf///6r////e/////P/////////////////////////////////////////////////////////8////3v///6r///9h////BgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////cv///+3////////////////////////////////////////////////////////////////////////////////////////////////////t////cgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA////FP///7j/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////uP///xQAAAAAAAAAAAAAAAAAAAAAAAAAAP///xT////Q////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////0P///xQAAAAAAAAAAAAAAAAAAAAA////uP//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////uAAAAAAAAAAAAAAAAP///3L/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////cgAAAAD///8G////7f////////////////////////////////////////////////v8/P/m5ub//v7+/////////////////+Xm5v/19fX////////////////////////////////////////////////////////////////t////Bv///2H////////////////////////////////////////////////+/v7/mZyb/0VLSv/y8vL////////////q6+v/XGFg/2JmZv////////////////////////////////////////////////////////////////////9h////qv////////////////////////////////////////////////7+/v+coKD/NTs6/+Lk4////////////+vs7P9dYmH/Q0lI//j4+P///////////////////////////////////////////////////////////////6r////e/////////////////////////////////////////////////////7q8vP80Ojn/xsfH////////////8vLy/2hsbP9ARkX/6Onp////////////////////////////////////////////////////////////////3v////z/////////////////////////////////////////////////////2NnZ/zQ6Of+pq6v//v7+///////5+fn/c3h3/z5EQ//Y2dn////////////////////////////////////////////////////////////////8//////////////////////////////////////7+/v/7+/v/+/v7//r7+//r7Oz/Nz08/4mMjP/6+vr/+/v7//r6+v9+goH/O0FA/8XGxv/6+vr/+/v7//v7+//7+/v//v7+////////////////////////////////////////////////////////////////////////////4eLi/4qOjf+BhIT/gISD/3t/fv85Pj3/TlNT/4CEg/+AhIP/gISD/1VaWf82PDv/aG1s/4CEg/+AhIP/gYSE/4qOjf/h4uL////////////////////////////////////////////////////////////////////////////Iysn/QEZF/zY8O/82PDv/Njw7/zQ6Of81Ozr/Njw7/zY8O/82PDv/NTs6/zU7Ov81Ozr/Njw7/zY8O/82PDv/QEZF/8jKyf////////////////////////////////////////////////////////////////////////////z8/P/j5OT/3t7e/97e3v/X2Nj/YGVk/zc9PP/Y2dn/3t7e/97e3v+pq6v/NTs6/4aJif/d3d3/3t7e/97e3v/j5OT//Pz8//////////////////////////////////////////////////////////////////////////////////////////////////n5+f94e3v/Njw7/+fn5////////////9LT0/82PDv/h4uK//z8/P///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Pz8/4eLiv82PDv/0tPT////////////5+fn/zY8O/94e3v/+fn5//////////////////////////////////////////////////////////////////////////////////////////////////z8/P/j5OT/3t7e/97e3v/d3d3/homJ/zU7Ov+pq6v/3t7e/97e3v/Y2dn/Nz08/2BlZP/X2Nj/3t7e/97e3v/j5OT//Pz8////////////////////////////////////////////////////////////////////////////yMrJ/0BGRf82PDv/Njw7/zY8O/81Ozr/NTs6/zU7Ov82PDv/Njw7/zY8O/81Ozr/NDo5/zY8O/82PDv/Njw7/0BGRf/Iysn////////////////////////////////////////////////////////////////////////////h4uL/io6N/4GEhP+AhIP/gISD/2htbP82PDv/VVpZ/4CEg/+AhIP/gISD/05TU/85Pj3/e39+/4CEg/+BhIT/io6N/+Hi4v////////////////////////////////////////////////////////////////////////////7+/v/7+/v/+/v7//v7+//6+vr/xcbG/ztBQP9+goH/+vr6//v7+//6+vr/iYyM/zc9PP/r7Oz/+vv7//v7+//7+/v//v7+///////////////////////////////////////////8///////////////////////////////////////////////////////////Y2dn/PkRD/3N4d//5+fn///////7+/v+pq6v/NDo5/9jZ2P///////////////////////////////////////////////////////////P///97//////////////////////////////////////////////////////////+jp6f9ARkX/aGxs//Ly8v///////////8bHx/80Ojn/ury8///////////////////////////////////////////////////////////e////qv//////////////////////////////////////////////////////////+Pj4/0NJSP9dYmH/6+zs////////////4uTk/zU7Ov+coKD//v7+/////////////////////////////////////////////////////6r///9h////////////////////////////////////////////////////////////////YmZm/1xhYP/q6+v////////////y8vL/RUtK/5mcm//+/v7/////////////////////////////////////////////////////Yf///wb////t///////////////////////////////////////////////////////////19fX/5ebm//////////////////7+/v/m5ub/+/z8/////////////////////////////////////////////////////+3///8GAAAAAP///3L/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////cgAAAAAAAAAAAAAAAP///7j//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////7gAAAAAAAAAAAAAAAAAAAAA////FP///9D////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Q////FAAAAAAAAAAAAAAAAAAAAAAAAAAA////FP///7j/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////uP///xQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///3L////t////////////////////////////////////////////////////////////////////////////////////////////////////7f///3IAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP///wb///9h////qv///97////8//////////////////////////////////////////////////////////z////e////qv///2H///8GAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA/AAAP/gAAB/gAAAHwAAAA8AAAAOAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAABwAAAA8AAAAPgAAAH+AAAH/wAAD8oAAAAEAAAACAAAAABACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8h////lf///+X////////////////////////////////////l////lf///yEAAAAAAAAAAAAAAAD///9N////+v/////////////////////////////////////////////////////////6////TQAAAAD///8h////+v////////////////////////////////////////////////////////////////////r///8h////lf/////////////////////o6en/ubu7///////U1tb/2NnZ////////////////////////////////lf///+X/////////////////////29zc/3l9ff/7+/v/tri4/62wr////////////////////////////////+X//////////////////////v7+//j4+P9ucnL/9PT0/87Pz/+ZnJv//v7+//7+/v//////////////////////////////////////9/f3/4yQj/+AhIP/TFFR/3t/fv9ydnX/V1xb/4GFhP+MkI//9/f3//////////////////////////////////39/f/l5ub/4uPj/3N3dv/Nz87/yMrJ/3l9fP/i4+P/5ebm//39/f/////////////////////////////////9/f3/5ebm/+Lj4/95fXz/yMrJ/83Pzv9zd3b/4uPj/+Xm5v/9/f3/////////////////////////////////9/f3/4yQj/+BhYT/V1xb/3J2df97f37/TFFR/4CEg/+MkI//9/f3///////////////////////////////////////+/v7//v7+/5mcm//Oz8//9PT0/25ycv/4+Pj//v7+///////////////////////////l//////////////////////////+tsK//tri4//v7+/95fX3/29zc///////////////////////////l////lf//////////////////////////2NnZ/9TW1v//////ubu7/+jp6f//////////////////////////lf///yH////6////////////////////////////////////////////////////////////////////+v///yEAAAAA////Tf////r/////////////////////////////////////////////////////////+v///00AAAAAAAAAAAAAAAD///8h////lf///+X////////////////////////////////////l////lf///yEAAAAAAAAAAMADAACAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAEAAMADAAA=";
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/core/iframe-style.ts
|
|
338
|
+
const FULLSCREEN_IFRAME_STYLE = {
|
|
339
|
+
border: "none",
|
|
340
|
+
width: "100%",
|
|
341
|
+
height: "100%",
|
|
342
|
+
position: "absolute",
|
|
343
|
+
top: "0",
|
|
344
|
+
left: "0"
|
|
345
|
+
};
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/core/path.ts
|
|
348
|
+
function isWithinBase(base, target) {
|
|
349
|
+
const resolvedBase = resolve(base);
|
|
350
|
+
const resolvedTarget = resolve(target);
|
|
351
|
+
const prefix = resolvedBase.endsWith(sep) ? resolvedBase : resolvedBase + sep;
|
|
352
|
+
return resolvedTarget === resolvedBase || resolvedTarget.startsWith(prefix);
|
|
353
|
+
}
|
|
354
|
+
//#endregion
|
|
355
|
+
//#region src/server/routes/api.tsx
|
|
356
|
+
function renderRawHtmlIframe(rawUrl, title) {
|
|
357
|
+
return renderToString(/* @__PURE__ */ jsx("iframe", {
|
|
358
|
+
src: rawUrl,
|
|
359
|
+
style: FULLSCREEN_IFRAME_STYLE,
|
|
360
|
+
title
|
|
361
|
+
}));
|
|
362
|
+
}
|
|
363
|
+
function resolveAndValidatePath(basePath, query) {
|
|
364
|
+
if (!query) return {
|
|
365
|
+
ok: false,
|
|
366
|
+
status: 400,
|
|
367
|
+
message: "Missing path parameter"
|
|
368
|
+
};
|
|
369
|
+
const fullPath = resolve(basePath, normalize(query));
|
|
370
|
+
if (!isWithinBase(basePath, fullPath)) return {
|
|
371
|
+
ok: false,
|
|
372
|
+
status: 403,
|
|
373
|
+
message: "Forbidden"
|
|
374
|
+
};
|
|
375
|
+
const contentType = getContentType(query);
|
|
376
|
+
if (!contentType) return {
|
|
377
|
+
ok: false,
|
|
378
|
+
status: 415,
|
|
379
|
+
message: "Unsupported file type"
|
|
380
|
+
};
|
|
381
|
+
return {
|
|
382
|
+
ok: true,
|
|
383
|
+
value: {
|
|
384
|
+
relativePath: query,
|
|
385
|
+
fullPath,
|
|
386
|
+
contentType
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
function createApiRoutes(config) {
|
|
391
|
+
const app = new Hono();
|
|
392
|
+
const fileContentType = config.mode === "file" ? getContentType(config.targetPath) : null;
|
|
393
|
+
app.get("/api/content", async (c) => {
|
|
394
|
+
if (config.mode === "file") {
|
|
395
|
+
if (fileContentType === "html") return c.html(renderRawHtmlIframe("/api/raw", basename(config.targetPath)));
|
|
396
|
+
const result = await readTextFile(config.targetPath);
|
|
397
|
+
if (!result.ok) {
|
|
398
|
+
if (result.error.type === "file-not-found") return c.text("File not found", 404);
|
|
399
|
+
logger.error("Failed to read file:", result.error);
|
|
400
|
+
return c.text("Failed to read file", 500);
|
|
401
|
+
}
|
|
402
|
+
return c.html(await renderMarkdown(result.value));
|
|
403
|
+
}
|
|
404
|
+
const resolved = resolveAndValidatePath(config.targetPath, c.req.query("path"));
|
|
405
|
+
if (!resolved.ok) return c.text(resolved.message, resolved.status);
|
|
406
|
+
const { relativePath, fullPath, contentType } = resolved.value;
|
|
407
|
+
if (contentType === "html") return c.html(renderRawHtmlIframe(`/api/raw?path=${encodeURIComponent(relativePath)}`, basename(relativePath)));
|
|
408
|
+
const result = await readTextFile(fullPath);
|
|
409
|
+
if (!result.ok) {
|
|
410
|
+
if (result.error.type === "file-not-found") return c.text("File not found", 404);
|
|
411
|
+
logger.error("Failed to read file:", result.error);
|
|
412
|
+
return c.text("Failed to read file", 500);
|
|
413
|
+
}
|
|
414
|
+
return c.html(await renderMarkdown(result.value));
|
|
415
|
+
});
|
|
416
|
+
app.get("/api/raw", async (c) => {
|
|
417
|
+
if (config.mode === "file") {
|
|
418
|
+
if (fileContentType !== "html") return c.text("Not found", 404);
|
|
419
|
+
const result = await readTextFile(config.targetPath);
|
|
420
|
+
if (!result.ok) {
|
|
421
|
+
if (result.error.type === "file-not-found") return c.text("File not found", 404);
|
|
422
|
+
logger.error("Failed to read file:", result.error);
|
|
423
|
+
return c.text("Failed to read file", 500);
|
|
424
|
+
}
|
|
425
|
+
c.header("X-Content-Type-Options", "nosniff");
|
|
426
|
+
return c.html(result.value);
|
|
427
|
+
}
|
|
428
|
+
const resolved = resolveAndValidatePath(config.targetPath, c.req.query("path"));
|
|
429
|
+
if (!resolved.ok) return c.text(resolved.message, resolved.status);
|
|
430
|
+
if (resolved.value.contentType !== "html") return c.text("Not found", 404);
|
|
431
|
+
const result = await readTextFile(resolved.value.fullPath);
|
|
432
|
+
if (!result.ok) {
|
|
433
|
+
if (result.error.type === "file-not-found") return c.text("File not found", 404);
|
|
434
|
+
logger.error("Failed to read file:", result.error);
|
|
435
|
+
return c.text("Failed to read file", 500);
|
|
436
|
+
}
|
|
437
|
+
c.header("X-Content-Type-Options", "nosniff");
|
|
438
|
+
return c.html(result.value);
|
|
439
|
+
});
|
|
440
|
+
app.get("/api/tree", async (c) => {
|
|
441
|
+
if (config.mode === "file") return c.json([]);
|
|
442
|
+
const result = await config.treeCache.get();
|
|
443
|
+
if (!result.ok) {
|
|
444
|
+
logger.error("Failed to read directory tree:", result.error);
|
|
445
|
+
return c.text("Failed to read directory", 500);
|
|
446
|
+
}
|
|
447
|
+
return c.json(result.value);
|
|
448
|
+
});
|
|
449
|
+
return app;
|
|
450
|
+
}
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/components/layout/main-content.tsx
|
|
453
|
+
function MainContent({ class: className, children }) {
|
|
454
|
+
return /* @__PURE__ */ jsx("main", {
|
|
455
|
+
id: "main-content",
|
|
456
|
+
class: className ?? "",
|
|
457
|
+
children
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
//#endregion
|
|
461
|
+
//#region src/components/layout/markdown-content.tsx
|
|
462
|
+
function MarkdownContent({ htmlContent }) {
|
|
463
|
+
return /* @__PURE__ */ jsx("div", {
|
|
464
|
+
id: "markdown-content",
|
|
465
|
+
class: "markdown-body",
|
|
466
|
+
dangerouslySetInnerHTML: { __html: htmlContent }
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
//#endregion
|
|
470
|
+
//#region src/components/content-view.tsx
|
|
471
|
+
function ContentView({ contentType, fileTitle, rawUrl, htmlContent, htmlReloadKey, markdownClass = "px-5 sm:px-10 py-5 sm:py-10" }) {
|
|
472
|
+
if (contentType === "html") return /* @__PURE__ */ jsx(MainContent, {
|
|
473
|
+
class: "relative flex-1 overflow-hidden",
|
|
474
|
+
children: /* @__PURE__ */ jsx("iframe", {
|
|
475
|
+
title: fileTitle,
|
|
476
|
+
src: rawUrl,
|
|
477
|
+
style: FULLSCREEN_IFRAME_STYLE
|
|
478
|
+
}, htmlReloadKey)
|
|
479
|
+
});
|
|
480
|
+
return /* @__PURE__ */ jsx(MainContent, {
|
|
481
|
+
class: markdownClass,
|
|
482
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
483
|
+
class: "max-w-4xl mx-auto",
|
|
484
|
+
children: /* @__PURE__ */ jsx(MarkdownContent, { htmlContent })
|
|
485
|
+
})
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
//#endregion
|
|
489
|
+
//#region src/components/icons/svg-base.tsx
|
|
490
|
+
function SvgBase({ class: className, children, width = "24", height = "24", viewBox = "0 0 24 24", ...rest }) {
|
|
491
|
+
return /* @__PURE__ */ jsx("svg", {
|
|
492
|
+
...rest,
|
|
493
|
+
class: className,
|
|
494
|
+
"aria-hidden": "true",
|
|
495
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
496
|
+
width,
|
|
497
|
+
height,
|
|
498
|
+
viewBox,
|
|
499
|
+
fill: "none",
|
|
500
|
+
stroke: "currentColor",
|
|
501
|
+
"stroke-width": "2",
|
|
502
|
+
"stroke-linecap": "round",
|
|
503
|
+
"stroke-linejoin": "round",
|
|
504
|
+
children
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/components/icons/chevron-down-icon.tsx
|
|
509
|
+
function ChevronDownIcon(props) {
|
|
510
|
+
return /* @__PURE__ */ jsx(SvgBase, {
|
|
511
|
+
...props,
|
|
512
|
+
children: /* @__PURE__ */ jsx("path", { d: "m6 9 6 6 6-6" })
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
//#endregion
|
|
516
|
+
//#region src/components/icons/external-link-icon.tsx
|
|
517
|
+
function ExternalLinkIcon({ class: className }) {
|
|
518
|
+
return /* @__PURE__ */ jsxs(SvgBase, {
|
|
519
|
+
class: className,
|
|
520
|
+
children: [
|
|
521
|
+
/* @__PURE__ */ jsx("path", { d: "M15 3h6v6" }),
|
|
522
|
+
/* @__PURE__ */ jsx("path", { d: "M10 14 21 3" }),
|
|
523
|
+
/* @__PURE__ */ jsx("path", { d: "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6" })
|
|
524
|
+
]
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
//#endregion
|
|
528
|
+
//#region src/components/icons/file-icon.tsx
|
|
529
|
+
function FileIcon(props) {
|
|
530
|
+
return /* @__PURE__ */ jsxs(SvgBase, {
|
|
531
|
+
...props,
|
|
532
|
+
children: [/* @__PURE__ */ jsx("path", { d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z" }), /* @__PURE__ */ jsx("path", { d: "M14 2v4a2 2 0 0 0 2 2h4" })]
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
//#endregion
|
|
536
|
+
//#region src/components/icons/folder-icon.tsx
|
|
537
|
+
function FolderIcon(props) {
|
|
538
|
+
return /* @__PURE__ */ jsx(SvgBase, {
|
|
539
|
+
...props,
|
|
540
|
+
children: /* @__PURE__ */ jsx("path", { d: "M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 0-1.69.9L9.6 8H4a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2Z" })
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
//#endregion
|
|
544
|
+
//#region src/components/icons/moon-icon.tsx
|
|
545
|
+
function MoonIcon({ class: className, ...rest }) {
|
|
546
|
+
return /* @__PURE__ */ jsx(SvgBase, {
|
|
547
|
+
class: className,
|
|
548
|
+
...rest,
|
|
549
|
+
children: /* @__PURE__ */ jsx("path", { d: "M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z" })
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
//#endregion
|
|
553
|
+
//#region src/components/icons/sidebar-close-icon.tsx
|
|
554
|
+
function SidebarCloseIcon({ class: className, ...rest }) {
|
|
555
|
+
return /* @__PURE__ */ jsxs(SvgBase, {
|
|
556
|
+
class: className,
|
|
557
|
+
...rest,
|
|
558
|
+
children: [
|
|
559
|
+
/* @__PURE__ */ jsx("polyline", { points: "7 8 3 12 7 16" }),
|
|
560
|
+
/* @__PURE__ */ jsx("line", {
|
|
561
|
+
x1: "21",
|
|
562
|
+
x2: "11",
|
|
563
|
+
y1: "12",
|
|
564
|
+
y2: "12"
|
|
565
|
+
}),
|
|
566
|
+
/* @__PURE__ */ jsx("line", {
|
|
567
|
+
x1: "21",
|
|
568
|
+
x2: "11",
|
|
569
|
+
y1: "6",
|
|
570
|
+
y2: "6"
|
|
571
|
+
}),
|
|
572
|
+
/* @__PURE__ */ jsx("line", {
|
|
573
|
+
x1: "21",
|
|
574
|
+
x2: "11",
|
|
575
|
+
y1: "18",
|
|
576
|
+
y2: "18"
|
|
577
|
+
})
|
|
578
|
+
]
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
//#endregion
|
|
582
|
+
//#region src/components/icons/sidebar-open-icon.tsx
|
|
583
|
+
function SidebarOpenIcon({ class: className, ...rest }) {
|
|
584
|
+
return /* @__PURE__ */ jsx(SvgBase, {
|
|
585
|
+
class: className,
|
|
586
|
+
...rest,
|
|
587
|
+
children: /* @__PURE__ */ jsx("path", { d: "M17 8L21 12L17 16M3 12H13M3 6H13M3 18H13" })
|
|
588
|
+
});
|
|
589
|
+
}
|
|
590
|
+
//#endregion
|
|
591
|
+
//#region src/components/icons/slash-icon.tsx
|
|
592
|
+
function SlashIcon(props) {
|
|
593
|
+
return /* @__PURE__ */ jsx(SvgBase, {
|
|
594
|
+
...props,
|
|
595
|
+
width: "16",
|
|
596
|
+
height: "16",
|
|
597
|
+
viewBox: "0 0 16 16",
|
|
598
|
+
children: /* @__PURE__ */ jsx("path", {
|
|
599
|
+
d: "M6 13L10 3",
|
|
600
|
+
"stroke-linecap": "round"
|
|
601
|
+
})
|
|
602
|
+
});
|
|
603
|
+
}
|
|
604
|
+
//#endregion
|
|
605
|
+
//#region src/components/icons/sun-icon.tsx
|
|
606
|
+
function SunIcon({ class: className, ...rest }) {
|
|
607
|
+
return /* @__PURE__ */ jsxs(SvgBase, {
|
|
608
|
+
class: className,
|
|
609
|
+
...rest,
|
|
610
|
+
children: [
|
|
611
|
+
/* @__PURE__ */ jsx("circle", {
|
|
612
|
+
cx: "12",
|
|
613
|
+
cy: "12",
|
|
614
|
+
r: "4"
|
|
615
|
+
}),
|
|
616
|
+
/* @__PURE__ */ jsx("path", { d: "M12 2v2" }),
|
|
617
|
+
/* @__PURE__ */ jsx("path", { d: "M12 20v2" }),
|
|
618
|
+
/* @__PURE__ */ jsx("path", { d: "m4.93 4.93 1.41 1.41" }),
|
|
619
|
+
/* @__PURE__ */ jsx("path", { d: "m17.66 17.66 1.41 1.41" }),
|
|
620
|
+
/* @__PURE__ */ jsx("path", { d: "M2 12h2" }),
|
|
621
|
+
/* @__PURE__ */ jsx("path", { d: "M20 12h2" }),
|
|
622
|
+
/* @__PURE__ */ jsx("path", { d: "m6.34 17.66-1.41 1.41" }),
|
|
623
|
+
/* @__PURE__ */ jsx("path", { d: "m19.07 4.93-1.41 1.41" })
|
|
624
|
+
]
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
//#endregion
|
|
628
|
+
//#region src/components/icons/sun-moon-icon.tsx
|
|
629
|
+
function SunMoonIcon({ class: className, ...rest }) {
|
|
630
|
+
return /* @__PURE__ */ jsxs(SvgBase, {
|
|
631
|
+
class: className,
|
|
632
|
+
...rest,
|
|
633
|
+
children: [
|
|
634
|
+
/* @__PURE__ */ jsx("path", { d: "M12 2v2" }),
|
|
635
|
+
/* @__PURE__ */ jsx("path", { d: "M14.837 16.385a6 6 0 1 1-7.223-7.222c.624-.147.97.66.715 1.248a4 4 0 0 0 5.26 5.259c.589-.255 1.396.09 1.248.715" }),
|
|
636
|
+
/* @__PURE__ */ jsx("path", { d: "M16 12a4 4 0 0 0-4-4" }),
|
|
637
|
+
/* @__PURE__ */ jsx("path", { d: "m19 5-1.256 1.256" }),
|
|
638
|
+
/* @__PURE__ */ jsx("path", { d: "M20 12h2" })
|
|
639
|
+
]
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
//#endregion
|
|
643
|
+
//#region src/components/layout/breadcrumb.tsx
|
|
644
|
+
const BREADCRUMB_CLASSES = {
|
|
645
|
+
dirItem: "inline-flex items-center shrink-0",
|
|
646
|
+
dirLink: "text-sm text-muted-foreground hover:text-foreground",
|
|
647
|
+
fileItem: "inline-flex items-center text-sm font-semibold text-foreground truncate"
|
|
648
|
+
};
|
|
649
|
+
const SLASH_ICON_CLASS = "shrink-0 mx-1 size-4 text-muted-foreground";
|
|
650
|
+
function Breadcrumb({ items }) {
|
|
651
|
+
return /* @__PURE__ */ jsx("nav", {
|
|
652
|
+
"aria-label": "Breadcrumb",
|
|
653
|
+
children: /* @__PURE__ */ jsx("ol", {
|
|
654
|
+
class: "flex items-center min-w-0",
|
|
655
|
+
children: items.map((item, index) => {
|
|
656
|
+
const isLast = index === items.length - 1;
|
|
657
|
+
return /* @__PURE__ */ jsx("li", {
|
|
658
|
+
class: isLast ? BREADCRUMB_CLASSES.fileItem : BREADCRUMB_CLASSES.dirItem,
|
|
659
|
+
"aria-current": isLast ? "page" : void 0,
|
|
660
|
+
children: isLast ? item.label : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("a", {
|
|
661
|
+
class: BREADCRUMB_CLASSES.dirLink,
|
|
662
|
+
href: item.href ?? "#",
|
|
663
|
+
children: item.label
|
|
664
|
+
}), /* @__PURE__ */ jsx(SlashIcon, { class: SLASH_ICON_CLASS })] })
|
|
665
|
+
}, index);
|
|
666
|
+
})
|
|
667
|
+
})
|
|
668
|
+
});
|
|
669
|
+
}
|
|
670
|
+
//#endregion
|
|
671
|
+
//#region src/components/layout/external-link.tsx
|
|
672
|
+
function ExternalLink({ href }) {
|
|
673
|
+
return /* @__PURE__ */ jsx("a", {
|
|
674
|
+
href,
|
|
675
|
+
target: "_blank",
|
|
676
|
+
rel: "noopener noreferrer",
|
|
677
|
+
class: "shrink-0 w-7 h-7 inline-flex justify-center items-center rounded-lg text-muted-foreground hover:text-foreground cursor-pointer",
|
|
678
|
+
"aria-label": "Open in new tab",
|
|
679
|
+
children: /* @__PURE__ */ jsx(ExternalLinkIcon, { class: "size-4" })
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
//#endregion
|
|
683
|
+
//#region src/components/layout/theme-toggle.tsx
|
|
684
|
+
function ThemeToggle() {
|
|
685
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
686
|
+
type: "button",
|
|
687
|
+
id: "theme-toggle",
|
|
688
|
+
class: "shrink-0 w-7 h-7 inline-flex justify-center items-center rounded-lg text-muted-foreground hover:text-foreground cursor-pointer",
|
|
689
|
+
"aria-label": "Toggle theme",
|
|
690
|
+
children: [
|
|
691
|
+
/* @__PURE__ */ jsx(SunIcon, {
|
|
692
|
+
class: "hidden size-4",
|
|
693
|
+
id: "icon-theme-light"
|
|
694
|
+
}),
|
|
695
|
+
/* @__PURE__ */ jsx(MoonIcon, {
|
|
696
|
+
class: "hidden size-4",
|
|
697
|
+
id: "icon-theme-dark"
|
|
698
|
+
}),
|
|
699
|
+
/* @__PURE__ */ jsx(SunMoonIcon, {
|
|
700
|
+
class: "hidden size-4",
|
|
701
|
+
id: "icon-theme-system"
|
|
702
|
+
})
|
|
703
|
+
]
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
//#endregion
|
|
707
|
+
//#region src/components/layout/page-header.tsx
|
|
708
|
+
function PageHeader({ id, breadcrumbs, showSidebarToggle, onToggleSidebar, externalLinkHref }) {
|
|
709
|
+
return /* @__PURE__ */ jsx("header", {
|
|
710
|
+
id,
|
|
711
|
+
class: "sticky top-0 z-50 bg-background border-b border-border",
|
|
712
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
713
|
+
class: "flex items-center justify-between w-full py-2 px-2 sm:px-5",
|
|
714
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
715
|
+
class: "flex items-center gap-1 min-w-0",
|
|
716
|
+
children: [showSidebarToggle && /* @__PURE__ */ jsxs("button", {
|
|
717
|
+
type: "button",
|
|
718
|
+
id: "sidebar-toggle",
|
|
719
|
+
onClick: onToggleSidebar,
|
|
720
|
+
class: "shrink-0 w-7 h-7 inline-flex justify-center items-center rounded-lg text-muted-foreground hover:bg-sidebar-accent cursor-pointer",
|
|
721
|
+
children: [/* @__PURE__ */ jsx(SidebarOpenIcon, {
|
|
722
|
+
class: "shrink-0 size-4",
|
|
723
|
+
id: "icon-sidebar-open"
|
|
724
|
+
}), /* @__PURE__ */ jsx(SidebarCloseIcon, {
|
|
725
|
+
class: "shrink-0 size-4 hidden",
|
|
726
|
+
id: "icon-sidebar-close"
|
|
727
|
+
})]
|
|
728
|
+
}), /* @__PURE__ */ jsx(Breadcrumb, { items: breadcrumbs })]
|
|
729
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
730
|
+
class: "flex items-center gap-1",
|
|
731
|
+
children: [/* @__PURE__ */ jsx(ThemeToggle, {}), externalLinkHref !== void 0 && /* @__PURE__ */ jsx(ExternalLink, { href: externalLinkHref })]
|
|
732
|
+
})]
|
|
733
|
+
})
|
|
734
|
+
});
|
|
735
|
+
}
|
|
736
|
+
//#endregion
|
|
737
|
+
//#region src/components/navigation/file-tree-items.tsx
|
|
738
|
+
const MAX_DEPTH = 20;
|
|
739
|
+
function DirectoryItem({ node, currentPath, depth }) {
|
|
740
|
+
const [open, setOpen] = useState(true);
|
|
741
|
+
return /* @__PURE__ */ jsxs("li", {
|
|
742
|
+
class: depth === 0 ? "px-2 lg:px-5" : "",
|
|
743
|
+
children: [/* @__PURE__ */ jsxs("button", {
|
|
744
|
+
type: "button",
|
|
745
|
+
"aria-expanded": open,
|
|
746
|
+
onClick: () => setOpen((prev) => !prev),
|
|
747
|
+
class: "flex items-center gap-x-3 w-full py-2 px-3 text-left text-sm text-sidebar-foreground hover:bg-sidebar-accent rounded-lg overflow-hidden",
|
|
748
|
+
children: [
|
|
749
|
+
/* @__PURE__ */ jsx(FolderIcon, { class: "shrink-0 size-4" }),
|
|
750
|
+
/* @__PURE__ */ jsx("span", {
|
|
751
|
+
class: "min-w-0 truncate",
|
|
752
|
+
children: node.name
|
|
753
|
+
}),
|
|
754
|
+
/* @__PURE__ */ jsx(ChevronDownIcon, { class: `${open ? "" : "-rotate-180 "}shrink-0 size-3.5 ms-auto transition-transform` })
|
|
755
|
+
]
|
|
756
|
+
}), open && /* @__PURE__ */ jsx("ul", {
|
|
757
|
+
class: "ps-7 mt-1 flex flex-col gap-y-1 relative before:absolute before:top-0 before:start-[1.125rem] before:w-px before:h-full before:bg-sidebar-border",
|
|
758
|
+
children: node.children && depth < MAX_DEPTH ? /* @__PURE__ */ jsx(FileTreeItems, {
|
|
759
|
+
nodes: node.children,
|
|
760
|
+
currentPath,
|
|
761
|
+
depth: depth + 1
|
|
762
|
+
}) : null
|
|
763
|
+
})]
|
|
764
|
+
});
|
|
765
|
+
}
|
|
766
|
+
function FileTreeItems({ nodes, currentPath, depth = 0 }) {
|
|
767
|
+
return /* @__PURE__ */ jsx(Fragment, { children: nodes.map((node) => {
|
|
768
|
+
if (node.type === "directory") return /* @__PURE__ */ jsx(DirectoryItem, {
|
|
769
|
+
node,
|
|
770
|
+
currentPath,
|
|
771
|
+
depth
|
|
772
|
+
}, node.path);
|
|
773
|
+
const isActive = currentPath === node.path;
|
|
774
|
+
return /* @__PURE__ */ jsx("li", {
|
|
775
|
+
class: depth === 0 ? "px-2 lg:px-5" : "",
|
|
776
|
+
children: /* @__PURE__ */ jsxs("a", {
|
|
777
|
+
href: `/view?path=${encodeURIComponent(node.path)}`,
|
|
778
|
+
class: `flex items-center gap-x-3 py-2 px-3 text-sm rounded-lg overflow-hidden ${isActive ? "bg-sidebar-accent text-sidebar-primary font-medium" : "hover:bg-sidebar-accent text-sidebar-foreground"}`,
|
|
779
|
+
children: [/* @__PURE__ */ jsx(FileIcon, { class: "shrink-0 size-4" }), /* @__PURE__ */ jsx("span", {
|
|
780
|
+
class: "min-w-0 truncate",
|
|
781
|
+
children: node.name
|
|
782
|
+
})]
|
|
783
|
+
})
|
|
784
|
+
}, node.path);
|
|
785
|
+
}) });
|
|
786
|
+
}
|
|
787
|
+
//#endregion
|
|
788
|
+
//#region src/components/navigation/file-tree.tsx
|
|
789
|
+
function FileTree({ nodes, currentPath }) {
|
|
790
|
+
return /* @__PURE__ */ jsx("ul", {
|
|
791
|
+
id: "file-tree",
|
|
792
|
+
class: "flex flex-col gap-y-1",
|
|
793
|
+
children: /* @__PURE__ */ jsx(FileTreeItems, {
|
|
794
|
+
nodes,
|
|
795
|
+
currentPath
|
|
796
|
+
})
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
//#endregion
|
|
800
|
+
//#region src/components/navigation/sidebar.tsx
|
|
801
|
+
function Sidebar({ title, tree, currentPath, onClose }) {
|
|
802
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
803
|
+
role: "none",
|
|
804
|
+
id: "sidebar-overlay",
|
|
805
|
+
class: "fixed inset-0 z-50 bg-black/50 hidden",
|
|
806
|
+
onClick: onClose
|
|
807
|
+
}), /* @__PURE__ */ jsxs("aside", {
|
|
808
|
+
id: "sidebar",
|
|
809
|
+
"aria-label": "File navigation",
|
|
810
|
+
class: "fixed inset-y-0 start-0 z-60 w-72 lg:w-auto overflow-hidden bg-sidebar border-e border-sidebar-border -translate-x-full",
|
|
811
|
+
children: [/* @__PURE__ */ jsxs("div", {
|
|
812
|
+
class: "relative flex flex-col h-full max-h-full pt-3",
|
|
813
|
+
children: [/* @__PURE__ */ jsx("header", {
|
|
814
|
+
class: "h-11.5 ps-5 pe-2 lg:ps-8 flex items-center",
|
|
815
|
+
children: /* @__PURE__ */ jsx("a", {
|
|
816
|
+
href: "/",
|
|
817
|
+
class: "flex-none text-sm font-semibold text-sidebar-foreground hover:text-sidebar-primary",
|
|
818
|
+
children: title
|
|
819
|
+
})
|
|
820
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
821
|
+
class: "mt-1.5 h-full overflow-x-hidden overflow-y-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-none [&::-webkit-scrollbar-track]:bg-scrollbar-track [&::-webkit-scrollbar-thumb]:bg-scrollbar-thumb",
|
|
822
|
+
children: /* @__PURE__ */ jsx("nav", {
|
|
823
|
+
class: "pb-3 w-full flex flex-col",
|
|
824
|
+
children: /* @__PURE__ */ jsx(FileTree, {
|
|
825
|
+
nodes: tree,
|
|
826
|
+
currentPath
|
|
827
|
+
})
|
|
828
|
+
})
|
|
829
|
+
})]
|
|
830
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
831
|
+
id: "sidebar-resize",
|
|
832
|
+
class: "absolute inset-y-0 end-0 w-1 cursor-col-resize hover:bg-sidebar-border hidden lg:block pointer-events-auto"
|
|
833
|
+
})]
|
|
834
|
+
})] });
|
|
835
|
+
}
|
|
836
|
+
//#endregion
|
|
837
|
+
//#region src/server/renderer/client-bundle.js
|
|
838
|
+
const clientBundle = "\"use strict\";(()=>{var Y,h,je,Pt,A,Ue,We,Ke,Ve,le,oe,ie,Mt,K={},V=[],At=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i,q=Array.isArray;function P(e,t){for(var n in t)e[n]=t[n];return e}function ae(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function Lt(e,t,n){var r,l,o,a={};for(o in t)o==\"key\"?r=t[o]:o==\"ref\"?l=t[o]:a[o]=t[o];if(arguments.length>2&&(a.children=arguments.length>3?Y.call(arguments,2):n),typeof e==\"function\"&&e.defaultProps!=null)for(o in e.defaultProps)a[o]===void 0&&(a[o]=e.defaultProps[o]);return j(e,a,r,l,null)}function j(e,t,n,r,l){var o={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:l??++je,__i:-1,__u:0};return l==null&&h.vnode!=null&&h.vnode(o),o}function T(e){return e.children}function W(e,t){this.props=e,this.context=t}function R(e,t){if(t==null)return e.__?R(e.__,e.__i+1):null;for(var n;t<e.__k.length;t++)if((n=e.__k[t])!=null&&n.__e!=null)return n.__e;return typeof e.type==\"function\"?R(e):null}function Ft(e){if(e.__P&&e.__d){var t=e.__v,n=t.__e,r=[],l=[],o=P({},t);o.__v=t.__v+1,h.vnode&&h.vnode(o),ce(e.__P,o,t,e.__n,e.__P.namespaceURI,32&t.__u?[n]:null,r,n??R(t),!!(32&t.__u),l),o.__v=t.__v,o.__.__k[o.__i]=o,Ze(r,o,l),t.__e=t.__=null,o.__e!=n&&Xe(o)}}function Xe(e){if((e=e.__)!=null&&e.__c!=null)return e.__e=e.__c.base=null,e.__k.some(function(t){if(t!=null&&t.__e!=null)return e.__e=e.__c.base=t.__e}),Xe(e)}function Oe(e){(!e.__d&&(e.__d=!0)&&A.push(e)&&!X.__r++||Ue!=h.debounceRendering)&&((Ue=h.debounceRendering)||We)(X)}function X(){try{for(var e,t=1;A.length;)A.length>t&&A.sort(Ke),e=A.shift(),t=A.length,Ft(e)}finally{A.length=X.__r=0}}function Ye(e,t,n,r,l,o,a,c,u,_,d){var s,f,p,v,S,x,y,m=r&&r.__k||V,k=t.length;for(u=Rt(n,t,m,u,k),s=0;s<k;s++)(p=n.__k[s])!=null&&(f=p.__i!=-1&&m[p.__i]||K,p.__i=s,x=ce(e,p,f,l,o,a,c,u,_,d),v=p.__e,p.ref&&f.ref!=p.ref&&(f.ref&&_e(f.ref,null,p),d.push(p.ref,p.__c||v,p)),S==null&&v!=null&&(S=v),(y=!!(4&p.__u))||f.__k===p.__k?u=qe(p,u,e,y):typeof p.type==\"function\"&&x!==void 0?u=x:v&&(u=v.nextSibling),p.__u&=-7);return n.__e=S,u}function Rt(e,t,n,r,l){var o,a,c,u,_,d=n.length,s=d,f=0;for(e.__k=new Array(l),o=0;o<l;o++)(a=t[o])!=null&&typeof a!=\"boolean\"&&typeof a!=\"function\"?(typeof a==\"string\"||typeof a==\"number\"||typeof a==\"bigint\"||a.constructor==String?a=e.__k[o]=j(null,a,null,null,null):q(a)?a=e.__k[o]=j(T,{children:a},null,null,null):a.constructor===void 0&&a.__b>0?a=e.__k[o]=j(a.type,a.props,a.key,a.ref?a.ref:null,a.__v):e.__k[o]=a,u=o+f,a.__=e,a.__b=e.__b+1,c=null,(_=a.__i=Bt(a,n,u,s))!=-1&&(s--,(c=n[_])&&(c.__u|=2)),c==null||c.__v==null?(_==-1&&(l>d?f--:l<d&&f++),typeof a.type!=\"function\"&&(a.__u|=4)):_!=u&&(_==u-1?f--:_==u+1?f++:(_>u?f--:f++,a.__u|=4))):e.__k[o]=null;if(s)for(o=0;o<d;o++)(c=n[o])!=null&&(2&c.__u)==0&&(c.__e==r&&(r=R(c)),Ge(c,c));return r}function qe(e,t,n,r){var l,o;if(typeof e.type==\"function\"){for(l=e.__k,o=0;l&&o<l.length;o++)l[o]&&(l[o].__=e,t=qe(l[o],t,n,r));return t}e.__e!=t&&(r&&(t&&e.type&&!t.parentNode&&(t=R(e)),n.insertBefore(e.__e,t||null)),t=e.__e);do t=t&&t.nextSibling;while(t!=null&&t.nodeType==8);return t}function Bt(e,t,n,r){var l,o,a,c=e.key,u=e.type,_=t[n],d=_!=null&&(2&_.__u)==0;if(_===null&&c==null||d&&c==_.key&&u==_.type)return n;if(r>(d?1:0)){for(l=n-1,o=n+1;l>=0||o<t.length;)if((_=t[a=l>=0?l--:o++])!=null&&(2&_.__u)==0&&c==_.key&&u==_.type)return a}return-1}function $e(e,t,n){t[0]==\"-\"?e.setProperty(t,n??\"\"):e[t]=n==null?\"\":typeof n!=\"number\"||At.test(t)?n:n+\"px\"}function z(e,t,n,r,l){var o,a;e:if(t==\"style\")if(typeof n==\"string\")e.style.cssText=n;else{if(typeof r==\"string\"&&(e.style.cssText=r=\"\"),r)for(t in r)n&&t in n||$e(e.style,t,\"\");if(n)for(t in n)r&&n[t]==r[t]||$e(e.style,t,n[t])}else if(t[0]==\"o\"&&t[1]==\"n\")o=t!=(t=t.replace(Ve,\"$1\")),a=t.toLowerCase(),t=a in e||t==\"onFocusOut\"||t==\"onFocusIn\"?a.slice(2):t.slice(2),e.l||(e.l={}),e.l[t+o]=n,n?r?n.u=r.u:(n.u=le,e.addEventListener(t,o?ie:oe,o)):e.removeEventListener(t,o?ie:oe,o);else{if(l==\"http://www.w3.org/2000/svg\")t=t.replace(/xlink(H|:h)/,\"h\").replace(/sName$/,\"s\");else if(t!=\"width\"&&t!=\"height\"&&t!=\"href\"&&t!=\"list\"&&t!=\"form\"&&t!=\"tabIndex\"&&t!=\"download\"&&t!=\"rowSpan\"&&t!=\"colSpan\"&&t!=\"role\"&&t!=\"popover\"&&t in e)try{e[t]=n??\"\";break e}catch{}typeof n==\"function\"||(n==null||n===!1&&t[4]!=\"-\"?e.removeAttribute(t):e.setAttribute(t,t==\"popover\"&&n==1?\"\":n))}}function ze(e){return function(t){if(this.l){var n=this.l[t.type+e];if(t.t==null)t.t=le++;else if(t.t<n.u)return;return n(h.event?h.event(t):t)}}}function ce(e,t,n,r,l,o,a,c,u,_){var d,s,f,p,v,S,x,y,m,k,E,M,De,$,re,I=t.type;if(t.constructor!==void 0)return null;128&n.__u&&(u=!!(32&n.__u),o=[c=t.__e=n.__e]),(d=h.__b)&&d(t);e:if(typeof I==\"function\")try{if(y=t.props,m=I.prototype&&I.prototype.render,k=(d=I.contextType)&&r[d.__c],E=d?k?k.props.value:d.__:r,n.__c?x=(s=t.__c=n.__c).__=s.__E:(m?t.__c=s=new I(y,E):(t.__c=s=new W(y,E),s.constructor=I,s.render=Nt),k&&k.sub(s),s.state||(s.state={}),s.__n=r,f=s.__d=!0,s.__h=[],s._sb=[]),m&&s.__s==null&&(s.__s=s.state),m&&I.getDerivedStateFromProps!=null&&(s.__s==s.state&&(s.__s=P({},s.__s)),P(s.__s,I.getDerivedStateFromProps(y,s.__s))),p=s.props,v=s.state,s.__v=t,f)m&&I.getDerivedStateFromProps==null&&s.componentWillMount!=null&&s.componentWillMount(),m&&s.componentDidMount!=null&&s.__h.push(s.componentDidMount);else{if(m&&I.getDerivedStateFromProps==null&&y!==p&&s.componentWillReceiveProps!=null&&s.componentWillReceiveProps(y,E),t.__v==n.__v||!s.__e&&s.shouldComponentUpdate!=null&&s.shouldComponentUpdate(y,s.__s,E)===!1){t.__v!=n.__v&&(s.props=y,s.state=s.__s,s.__d=!1),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(F){F&&(F.__=t)}),V.push.apply(s.__h,s._sb),s._sb=[],s.__h.length&&a.push(s);break e}s.componentWillUpdate!=null&&s.componentWillUpdate(y,s.__s,E),m&&s.componentDidUpdate!=null&&s.__h.push(function(){s.componentDidUpdate(p,v,S)})}if(s.context=E,s.props=y,s.__P=e,s.__e=!1,M=h.__r,De=0,m)s.state=s.__s,s.__d=!1,M&&M(t),d=s.render(s.props,s.state,s.context),V.push.apply(s.__h,s._sb),s._sb=[];else do s.__d=!1,M&&M(t),d=s.render(s.props,s.state,s.context),s.state=s.__s;while(s.__d&&++De<25);s.state=s.__s,s.getChildContext!=null&&(r=P(P({},r),s.getChildContext())),m&&!f&&s.getSnapshotBeforeUpdate!=null&&(S=s.getSnapshotBeforeUpdate(p,v)),$=d!=null&&d.type===T&&d.key==null?Je(d.props.children):d,c=Ye(e,q($)?$:[$],t,n,r,l,o,a,c,u,_),s.base=t.__e,t.__u&=-161,s.__h.length&&a.push(s),x&&(s.__E=s.__=null)}catch(F){if(t.__v=null,u||o!=null)if(F.then){for(t.__u|=u?160:128;c&&c.nodeType==8&&c.nextSibling;)c=c.nextSibling;o[o.indexOf(c)]=null,t.__e=c}else{for(re=o.length;re--;)ae(o[re]);se(t)}else t.__e=n.__e,t.__k=n.__k,F.then||se(t);h.__e(F,t,n)}else o==null&&t.__v==n.__v?(t.__k=n.__k,t.__e=n.__e):c=t.__e=Ht(n.__e,t,n,r,l,o,a,u,_);return(d=h.diffed)&&d(t),128&t.__u?void 0:c}function se(e){e&&(e.__c&&(e.__c.__e=!0),e.__k&&e.__k.some(se))}function Ze(e,t,n){for(var r=0;r<n.length;r++)_e(n[r],n[++r],n[++r]);h.__c&&h.__c(t,e),e.some(function(l){try{e=l.__h,l.__h=[],e.some(function(o){o.call(l)})}catch(o){h.__e(o,l.__v)}})}function Je(e){return typeof e!=\"object\"||e==null||e.__b>0?e:q(e)?e.map(Je):P({},e)}function Ht(e,t,n,r,l,o,a,c,u){var _,d,s,f,p,v,S,x=n.props||K,y=t.props,m=t.type;if(m==\"svg\"?l=\"http://www.w3.org/2000/svg\":m==\"math\"?l=\"http://www.w3.org/1998/Math/MathML\":l||(l=\"http://www.w3.org/1999/xhtml\"),o!=null){for(_=0;_<o.length;_++)if((p=o[_])&&\"setAttribute\"in p==!!m&&(m?p.localName==m:p.nodeType==3)){e=p,o[_]=null;break}}if(e==null){if(m==null)return document.createTextNode(y);e=document.createElementNS(l,m,y.is&&y),c&&(h.__m&&h.__m(t,o),c=!1),o=null}if(m==null)x===y||c&&e.data==y||(e.data=y);else{if(o=o&&Y.call(e.childNodes),!c&&o!=null)for(x={},_=0;_<e.attributes.length;_++)x[(p=e.attributes[_]).name]=p.value;for(_ in x)p=x[_],_==\"dangerouslySetInnerHTML\"?s=p:_==\"children\"||_ in y||_==\"value\"&&\"defaultValue\"in y||_==\"checked\"&&\"defaultChecked\"in y||z(e,_,null,p,l);for(_ in y)p=y[_],_==\"children\"?f=p:_==\"dangerouslySetInnerHTML\"?d=p:_==\"value\"?v=p:_==\"checked\"?S=p:c&&typeof p!=\"function\"||x[_]===p||z(e,_,p,x[_],l);if(d)c||s&&(d.__html==s.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[];else if(s&&(e.innerHTML=\"\"),Ye(t.type==\"template\"?e.content:e,q(f)?f:[f],t,n,r,m==\"foreignObject\"?\"http://www.w3.org/1999/xhtml\":l,o,a,o?o[0]:n.__k&&R(n,0),c,u),o!=null)for(_=o.length;_--;)ae(o[_]);c||(_=\"value\",m==\"progress\"&&v==null?e.removeAttribute(\"value\"):v!=null&&(v!==e[_]||m==\"progress\"&&!v||m==\"option\"&&v!=x[_])&&z(e,_,v,x[_],l),_=\"checked\",S!=null&&S!=e[_]&&z(e,_,S,x[_],l))}return e}function _e(e,t,n){try{if(typeof e==\"function\"){var r=typeof e.__u==\"function\";r&&e.__u(),r&&t==null||(e.__u=e(t))}else e.current=t}catch(l){h.__e(l,n)}}function Ge(e,t,n){var r,l;if(h.unmount&&h.unmount(e),(r=e.ref)&&(r.current&&r.current!=e.__e||_e(r,null,t)),(r=e.__c)!=null){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(o){h.__e(o,t)}r.base=r.__P=null}if(r=e.__k)for(l=0;l<r.length;l++)r[l]&&Ge(r[l],t,n||typeof e.type!=\"function\");n||ae(e.__e),e.__c=e.__=e.__e=void 0}function Nt(e,t,n){return this.constructor(e,n)}function Dt(e,t,n){var r,l,o,a;t==document&&(t=document.documentElement),h.__&&h.__(e,t),l=(r=typeof n==\"function\")?null:n&&n.__k||t.__k,o=[],a=[],ce(t,e=(!r&&n||t).__k=Lt(T,null,[e]),l||K,K,t.namespaceURI,!r&&n?[n]:l?null:t.firstChild?Y.call(t.childNodes):null,o,!r&&n?n:l?l.__e:t.firstChild,r,a),Ze(o,e,a)}function Z(e,t){Dt(e,t,Z)}Y=V.slice,h={__e:function(e,t,n,r){for(var l,o,a;t=t.__;)if((l=t.__c)&&!l.__)try{if((o=l.constructor)&&o.getDerivedStateFromError!=null&&(l.setState(o.getDerivedStateFromError(e)),a=l.__d),l.componentDidCatch!=null&&(l.componentDidCatch(e,r||{}),a=l.__d),a)return l.__E=l}catch(c){e=c}throw e}},je=0,Pt=function(e){return e!=null&&e.constructor===void 0},W.prototype.setState=function(e,t){var n;n=this.__s!=null&&this.__s!=this.state?this.__s:this.__s=P({},this.state),typeof e==\"function\"&&(e=e(P({},n),this.props)),e&&P(n,e),e!=null&&this.__v&&(t&&this._sb.push(t),Oe(this))},W.prototype.forceUpdate=function(e){this.__v&&(this.__e=!0,e&&this.__h.push(e),Oe(this))},W.prototype.render=T,A=[],We=typeof Promise==\"function\"?Promise.prototype.then.bind(Promise.resolve()):setTimeout,Ke=function(e,t){return e.__v.__b-t.__v.__b},X.__r=0,Ve=/(PointerCapture)$|Capture$/i,le=0,oe=ze(!1),ie=ze(!0),Mt=0;var B,g,ue,Qe,N=0,lt=[],b=h,et=b.__b,tt=b.__r,nt=b.diffed,rt=b.__c,ot=b.unmount,it=b.__;function G(e,t){b.__h&&b.__h(g,e,N||t),N=0;var n=g.__H||(g.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function C(e){return N=1,Ut(_t,e)}function Ut(e,t,n){var r=G(B++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):_t(void 0,t),function(c){var u=r.__N?r.__N[0]:r.__[0],_=r.t(u,c);u!==_&&(r.__N=[_,r.__[1]],r.__c.setState({}))}],r.__c=g,!g.__f)){var l=function(c,u,_){if(!r.__c.__H)return!0;var d=r.__c.__H.__.filter(function(f){return f.__c});if(d.every(function(f){return!f.__N}))return!o||o.call(this,c,u,_);var s=r.__c.props!==c;return d.some(function(f){if(f.__N){var p=f.__[0];f.__=f.__N,f.__N=void 0,p!==f.__[0]&&(s=!0)}}),o&&o.call(this,c,u,_)||s};g.__f=!0;var o=g.shouldComponentUpdate,a=g.componentWillUpdate;g.componentWillUpdate=function(c,u,_){if(this.__e){var d=o;o=void 0,l(c,u,_),o=d}a&&a.call(this,c,u,_)},g.shouldComponentUpdate=l}return r.__N||r.__}function H(e,t){var n=G(B++,3);!b.__s&&pe(n.__H,t)&&(n.__=e,n.u=t,g.__H.__h.push(n))}function at(e,t){var n=G(B++,4);!b.__s&&pe(n.__H,t)&&(n.__=e,n.u=t,g.__h.push(n))}function L(e){return N=5,ct(function(){return{current:e}},[])}function ct(e,t){var n=G(B++,7);return pe(n.__H,t)&&(n.__=e(),n.__H=t,n.__h=e),n.__}function D(e,t){return N=8,ct(function(){return e},t)}function Ot(){for(var e;e=lt.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(J),t.__h.some(de),t.__h=[]}catch(n){t.__h=[],b.__e(n,e.__v)}}}b.__b=function(e){g=null,et&&et(e)},b.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),it&&it(e,t)},b.__r=function(e){tt&&tt(e),B=0;var t=(g=e.__c).__H;t&&(ue===g?(t.__h=[],g.__h=[],t.__.some(function(n){n.__N&&(n.__=n.__N),n.u=n.__N=void 0})):(t.__h.some(J),t.__h.some(de),t.__h=[],B=0)),ue=g},b.diffed=function(e){nt&&nt(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&(lt.push(t)!==1&&Qe===b.requestAnimationFrame||((Qe=b.requestAnimationFrame)||$t)(Ot)),t.__H.__.some(function(n){n.u&&(n.__H=n.u),n.u=void 0})),ue=g=null},b.__c=function(e,t){t.some(function(n){try{n.__h.some(J),n.__h=n.__h.filter(function(r){return!r.__||de(r)})}catch(r){t.some(function(l){l.__h&&(l.__h=[])}),t=[],b.__e(r,n.__v)}}),rt&&rt(e,t)},b.unmount=function(e){ot&&ot(e);var t,n=e.__c;n&&n.__H&&(n.__H.__.some(function(r){try{J(r)}catch(l){t=l}}),n.__H=void 0,t&&b.__e(t,n.__v))};var st=typeof requestAnimationFrame==\"function\";function $t(e){var t,n=function(){clearTimeout(r),st&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);st&&(t=requestAnimationFrame(n))}function J(e){var t=g,n=e.__c;typeof n==\"function\"&&(e.__c=void 0,n()),g=t}function de(e){var t=g;e.__c=e.__(),g=t}function pe(e,t){return!e||e.length!==t.length||t.some(function(n,r){return n!==e[r]})}function _t(e,t){return typeof t==\"function\"?t(e):t}var ut={border:\"none\",width:\"100%\",height:\"100%\",position:\"absolute\",top:\"0\",left:\"0\"};var zt=0;function i(e,t,n,r,l,o){t||(t={});var a,c,u=t;if(\"ref\"in u)for(c in u={},t)c==\"ref\"?a=t[c]:u[c]=t[c];var _={type:e,props:u,key:n,ref:a,__k:null,__:null,__b:0,__e:null,__c:null,constructor:void 0,__v:--zt,__i:-1,__u:0,__source:l,__self:o};if(typeof e==\"function\"&&(a=e.defaultProps))for(c in a)u[c]===void 0&&(u[c]=a[c]);return h.vnode&&h.vnode(_),_}function fe({class:e,children:t}){return i(\"main\",{id:\"main-content\",class:e??\"\",children:t})}function Q({htmlContent:e}){return i(\"div\",{id:\"markdown-content\",class:\"markdown-body\",dangerouslySetInnerHTML:{__html:e}})}function dt({contentType:e,fileTitle:t,rawUrl:n,htmlContent:r,htmlReloadKey:l,markdownClass:o=\"px-5 sm:px-10 py-5 sm:py-10\"}){return e===\"html\"?i(fe,{class:\"relative flex-1 overflow-hidden\",children:i(\"iframe\",{title:t,src:n,style:ut},l)}):i(fe,{class:o,children:i(\"div\",{class:\"max-w-4xl mx-auto\",children:i(Q,{htmlContent:r})})})}function w({class:e,children:t,width:n=\"24\",height:r=\"24\",viewBox:l=\"0 0 24 24\",...o}){return i(\"svg\",{...o,class:e,\"aria-hidden\":\"true\",xmlns:\"http://www.w3.org/2000/svg\",width:n,height:r,viewBox:l,fill:\"none\",stroke:\"currentColor\",\"stroke-width\":\"2\",\"stroke-linecap\":\"round\",\"stroke-linejoin\":\"round\",children:t})}function me(e){return i(w,{...e,children:i(\"path\",{d:\"m6 9 6 6 6-6\"})})}function he({class:e}){return i(w,{class:e,children:[i(\"path\",{d:\"M15 3h6v6\"}),i(\"path\",{d:\"M10 14 21 3\"}),i(\"path\",{d:\"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6\"})]})}function ye(e){return i(w,{...e,children:[i(\"path\",{d:\"M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z\"}),i(\"path\",{d:\"M14 2v4a2 2 0 0 0 2 2h4\"})]})}function ge(e){return i(w,{...e,children:i(\"path\",{d:\"M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 0-1.69.9L9.6 8H4a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2Z\"})})}function ve({class:e,...t}){return i(w,{class:e,...t,children:i(\"path\",{d:\"M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z\"})})}function be({class:e,...t}){return i(w,{class:e,...t,children:[i(\"polyline\",{points:\"7 8 3 12 7 16\"}),i(\"line\",{x1:\"21\",x2:\"11\",y1:\"12\",y2:\"12\"}),i(\"line\",{x1:\"21\",x2:\"11\",y1:\"6\",y2:\"6\"}),i(\"line\",{x1:\"21\",x2:\"11\",y1:\"18\",y2:\"18\"})]})}function xe({class:e,...t}){return i(w,{class:e,...t,children:i(\"path\",{d:\"M17 8L21 12L17 16M3 12H13M3 6H13M3 18H13\"})})}function we(e){return i(w,{...e,width:\"16\",height:\"16\",viewBox:\"0 0 16 16\",children:i(\"path\",{d:\"M6 13L10 3\",\"stroke-linecap\":\"round\"})})}function Se({class:e,...t}){return i(w,{class:e,...t,children:[i(\"circle\",{cx:\"12\",cy:\"12\",r:\"4\"}),i(\"path\",{d:\"M12 2v2\"}),i(\"path\",{d:\"M12 20v2\"}),i(\"path\",{d:\"m4.93 4.93 1.41 1.41\"}),i(\"path\",{d:\"m17.66 17.66 1.41 1.41\"}),i(\"path\",{d:\"M2 12h2\"}),i(\"path\",{d:\"M20 12h2\"}),i(\"path\",{d:\"m6.34 17.66-1.41 1.41\"}),i(\"path\",{d:\"m19.07 4.93-1.41 1.41\"})]})}function ke({class:e,...t}){return i(w,{class:e,...t,children:[i(\"path\",{d:\"M12 2v2\"}),i(\"path\",{d:\"M14.837 16.385a6 6 0 1 1-7.223-7.222c.624-.147.97.66.715 1.248a4 4 0 0 0 5.26 5.259c.589-.255 1.396.09 1.248.715\"}),i(\"path\",{d:\"M16 12a4 4 0 0 0-4-4\"}),i(\"path\",{d:\"m19 5-1.256 1.256\"}),i(\"path\",{d:\"M20 12h2\"})]})}var Te={dirItem:\"inline-flex items-center shrink-0\",dirLink:\"text-sm text-muted-foreground hover:text-foreground\",fileItem:\"inline-flex items-center text-sm font-semibold text-foreground truncate\"},jt=\"shrink-0 mx-1 size-4 text-muted-foreground\";function pt({items:e}){return i(\"nav\",{\"aria-label\":\"Breadcrumb\",children:i(\"ol\",{class:\"flex items-center min-w-0\",children:e.map((t,n)=>{let r=n===e.length-1;return i(\"li\",{class:r?Te.fileItem:Te.dirItem,\"aria-current\":r?\"page\":void 0,children:r?t.label:i(T,{children:[i(\"a\",{class:Te.dirLink,href:t.href??\"#\",children:t.label}),i(we,{class:jt})]})},n)})})})}function ft({href:e}){return i(\"a\",{href:e,target:\"_blank\",rel:\"noopener noreferrer\",class:\"shrink-0 w-7 h-7 inline-flex justify-center items-center rounded-lg text-muted-foreground hover:text-foreground cursor-pointer\",\"aria-label\":\"Open in new tab\",children:i(he,{class:\"size-4\"})})}function mt(){return i(\"button\",{type:\"button\",id:\"theme-toggle\",class:\"shrink-0 w-7 h-7 inline-flex justify-center items-center rounded-lg text-muted-foreground hover:text-foreground cursor-pointer\",\"aria-label\":\"Toggle theme\",children:[i(Se,{class:\"hidden size-4\",id:\"icon-theme-light\"}),i(ve,{class:\"hidden size-4\",id:\"icon-theme-dark\"}),i(ke,{class:\"hidden size-4\",id:\"icon-theme-system\"})]})}function ht({id:e,breadcrumbs:t,showSidebarToggle:n,onToggleSidebar:r,externalLinkHref:l}){return i(\"header\",{id:e,class:\"sticky top-0 z-50 bg-background border-b border-border\",children:i(\"div\",{class:\"flex items-center justify-between w-full py-2 px-2 sm:px-5\",children:[i(\"div\",{class:\"flex items-center gap-1 min-w-0\",children:[n&&i(\"button\",{type:\"button\",id:\"sidebar-toggle\",onClick:r,class:\"shrink-0 w-7 h-7 inline-flex justify-center items-center rounded-lg text-muted-foreground hover:bg-sidebar-accent cursor-pointer\",children:[i(xe,{class:\"shrink-0 size-4\",id:\"icon-sidebar-open\"}),i(be,{class:\"shrink-0 size-4 hidden\",id:\"icon-sidebar-close\"})]}),i(pt,{items:t})]}),i(\"div\",{class:\"flex items-center gap-1\",children:[i(mt,{}),l!==void 0&&i(ft,{href:l})]})]})})}var Wt=20;function Kt({node:e,currentPath:t,depth:n}){let[r,l]=C(!0);return i(\"li\",{class:n===0?\"px-2 lg:px-5\":\"\",children:[i(\"button\",{type:\"button\",\"aria-expanded\":r,onClick:()=>l(o=>!o),class:\"flex items-center gap-x-3 w-full py-2 px-3 text-left text-sm text-sidebar-foreground hover:bg-sidebar-accent rounded-lg overflow-hidden\",children:[i(ge,{class:\"shrink-0 size-4\"}),i(\"span\",{class:\"min-w-0 truncate\",children:e.name}),i(me,{class:`${r?\"\":\"-rotate-180 \"}shrink-0 size-3.5 ms-auto transition-transform`})]}),r&&i(\"ul\",{class:\"ps-7 mt-1 flex flex-col gap-y-1 relative before:absolute before:top-0 before:start-[1.125rem] before:w-px before:h-full before:bg-sidebar-border\",children:e.children&&n<Wt?i(Ce,{nodes:e.children,currentPath:t,depth:n+1}):null})]})}function Ce({nodes:e,currentPath:t,depth:n=0}){return i(T,{children:e.map(r=>{if(r.type===\"directory\")return i(Kt,{node:r,currentPath:t,depth:n},r.path);let l=t===r.path;return i(\"li\",{class:n===0?\"px-2 lg:px-5\":\"\",children:i(\"a\",{href:`/view?path=${encodeURIComponent(r.path)}`,class:`flex items-center gap-x-3 py-2 px-3 text-sm rounded-lg overflow-hidden ${l?\"bg-sidebar-accent text-sidebar-primary font-medium\":\"hover:bg-sidebar-accent text-sidebar-foreground\"}`,children:[i(ye,{class:\"shrink-0 size-4\"}),i(\"span\",{class:\"min-w-0 truncate\",children:r.name})]})},r.path)})})}function yt({nodes:e,currentPath:t}){return i(\"ul\",{id:\"file-tree\",class:\"flex flex-col gap-y-1\",children:i(Ce,{nodes:e,currentPath:t})})}function gt({title:e,tree:t,currentPath:n,onClose:r}){return i(T,{children:[i(\"div\",{role:\"none\",id:\"sidebar-overlay\",class:\"fixed inset-0 z-50 bg-black/50 hidden\",onClick:r}),i(\"aside\",{id:\"sidebar\",\"aria-label\":\"File navigation\",class:\"fixed inset-y-0 start-0 z-60 w-72 lg:w-auto overflow-hidden bg-sidebar border-e border-sidebar-border -translate-x-full\",children:[i(\"div\",{class:\"relative flex flex-col h-full max-h-full pt-3\",children:[i(\"header\",{class:\"h-11.5 ps-5 pe-2 lg:ps-8 flex items-center\",children:i(\"a\",{href:\"/\",class:\"flex-none text-sm font-semibold text-sidebar-foreground hover:text-sidebar-primary\",children:e})}),i(\"div\",{class:\"mt-1.5 h-full overflow-x-hidden overflow-y-auto [&::-webkit-scrollbar]:w-2 [&::-webkit-scrollbar-thumb]:rounded-none [&::-webkit-scrollbar-track]:bg-scrollbar-track [&::-webkit-scrollbar-thumb]:bg-scrollbar-thumb\",children:i(\"nav\",{class:\"pb-3 w-full flex flex-col\",children:i(yt,{nodes:t,currentPath:n})})})]}),i(\"div\",{id:\"sidebar-resize\",class:\"absolute inset-y-0 end-0 w-1 cursor-col-resize hover:bg-sidebar-border hidden lg:block pointer-events-auto\"})]})]})}var Vt=new Map([[\".md\",\"markdown\"],[\".html\",\"html\"],[\".htm\",\"html\"]]);function Xt(e){let t=Math.max(e.lastIndexOf(\"/\"),e.lastIndexOf(\"\\\\\")),n=t===-1?e:e.slice(t+1),r=n.lastIndexOf(\".\");return r===-1||r===n.length-1?\"\":n.slice(r).toLowerCase()}function vt(e){return Vt.get(Xt(e))??null}async function U(e,t){try{let n=e?`/api/content?path=${encodeURIComponent(e)}`:\"/api/content\",r=await fetch(n,t?.signal?{signal:t.signal}:void 0);return r.ok?await r.text():(console.error(`[peek] Failed to fetch content: HTTP ${r.status}`),null)}catch(n){if(n instanceof DOMException&&n.name===\"AbortError\")throw n;return console.error(\"[peek] Failed to fetch content:\",n),null}}async function bt(e){try{let t=await fetch(\"/api/tree\",e?.signal?{signal:e.signal}:void 0);if(!t.ok)return console.error(`[peek] Failed to fetch tree: HTTP ${t.status}`),null;let n=await t.json();return Array.isArray(n)?n:(console.error(\"[peek] Unexpected tree response format\"),null)}catch(t){if(t instanceof DOMException&&t.name===\"AbortError\")throw t;return console.error(\"[peek] Failed to fetch tree:\",t),null}}function O(e){return e&&e.replace(/\\\\/g,\"/\")}function ee(e){let n=e.replace(/\\/+$/,\"\").split(\"/\");return n[n.length-1]||e}function xt(e){let t=L(null),n=L(e);n.current=e;let r=D(async(l,o)=>{t.current&&t.current.abort();let a=new AbortController;t.current=a;try{let c=await U(l,{signal:a.signal});if(c===null)return;n.current(l,c),document.title=`${ee(l)} - peek`;let u=`/view?path=${encodeURIComponent(l)}`;o&&history.pushState({path:l},\"\",u)}catch(c){if(c instanceof DOMException&&c.name===\"AbortError\")return;console.error(\"[peek] Failed to navigate:\",c)}},[]);return H(()=>{let l=new URLSearchParams(window.location.search).get(\"path\");l&&history.replaceState({path:l},\"\");function o(c){if(c.ctrlKey||c.metaKey||c.shiftKey||c.altKey)return;let u=c.target.closest(\"a[href]\");if(!u)return;let _;try{_=new URL(u.href,window.location.origin)}catch{return}if(_.origin!==window.location.origin||_.pathname!==\"/view\")return;let d=_.searchParams.get(\"path\");d&&(c.preventDefault(),r(d,!0))}function a(c){let _=c.state?.path??new URLSearchParams(window.location.search).get(\"path\");_?r(_,!1):window.location.reload()}return document.addEventListener(\"click\",o),window.addEventListener(\"popstate\",a),()=>{document.removeEventListener(\"click\",o),window.removeEventListener(\"popstate\",a)}},[r]),r}var Ie=\"sidebar-open\",wt=\"sidebar-width\",Ee=200,Pe=480,Yt=1024;function Me(){return window.innerWidth>=Yt}function St(){let[e,t]=C(!1),n=L(!0);at(()=>{if(n.current){n.current=!1;let o=localStorage.getItem(wt);if(o){let a=Number(o);a>=Ee&&a<=Pe&&document.documentElement.style.setProperty(\"--sidebar-width\",`${a}px`)}if(Me()&&localStorage.getItem(Ie)!==\"false\"){let a=[document.getElementById(\"sidebar\"),document.getElementById(\"header-bar\"),document.getElementById(\"main-content\")];for(let c of a)c&&(c.style.transition=\"none\");document.body.setAttribute(\"data-sidebar-open\",\"\"),document.body.offsetHeight,requestAnimationFrame(()=>{for(let c of a)c&&c.style.removeProperty(\"transition\")}),t(!0)}return}e?document.body.setAttribute(\"data-sidebar-open\",\"\"):document.body.removeAttribute(\"data-sidebar-open\")},[e]),H(()=>{let o=document.getElementById(\"sidebar-resize\");if(!o)return;function a(c){c.preventDefault(),o.setPointerCapture(c.pointerId);let u=document.getElementById(\"sidebar\");document.body.style.setProperty(\"user-select\",\"none\"),u?.style.setProperty(\"transition\",\"none\");function _(s){let f=Math.min(Math.max(s.clientX,Ee),Pe);document.documentElement.style.setProperty(\"--sidebar-width\",`${f}px`)}function d(s){if(o.releasePointerCapture(s.pointerId),o.removeEventListener(\"pointermove\",_),o.removeEventListener(\"pointerup\",d),o.removeEventListener(\"pointercancel\",d),document.body.style.removeProperty(\"user-select\"),u?.style.removeProperty(\"transition\"),s.type===\"pointerup\"){let f=Math.min(Math.max(s.clientX,Ee),Pe);localStorage.setItem(wt,String(f))}}o.addEventListener(\"pointermove\",_),o.addEventListener(\"pointerup\",d),o.addEventListener(\"pointercancel\",d)}return o.addEventListener(\"pointerdown\",a),()=>o.removeEventListener(\"pointerdown\",a)},[]);let r=D(()=>{t(o=>{let a=!o;return Me()&&localStorage.setItem(Ie,String(a)),a})},[]),l=D(()=>{t(!1),Me()&&localStorage.setItem(Ie,\"false\")},[]);return{toggle:r,close:l}}var Ae=\"[peek]\",Le={info:(...e)=>console.log(Ae,...e),warn:(...e)=>console.warn(Ae,...e),error:(...e)=>console.error(Ae,...e)};function Gt(e){let t;try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!=\"object\")return null;let n=t;return typeof n.path!=\"string\"?null:{path:n.path}}function kt(e){let t=0,n=null,r=null,l=null;function o(){r&&(clearTimeout(r),r=null);let a=new EventSource(\"/sse\");if(l=a,a.addEventListener(\"file-changed\",c=>{let u=Gt(c.data);e.onFileChanged(u?O(u.path):null)}),e.onTreeChanged){let c=e.onTreeChanged;a.addEventListener(\"tree-changed\",()=>{c()})}a.onerror=()=>{if(a.close(),l=null,r&&(clearTimeout(r),r=null),t++,t>10){Le.warn(`SSE connection lost after ${10} retries, giving up.`);return}let c=Math.min(1e3*2**(t-1),3e4);Le.info(`SSE reconnecting in ${c}ms (${t}/${10})...`),n=setTimeout(o,c)},r=setTimeout(()=>{t=0,r=null},5e3)}return o(),()=>{n&&clearTimeout(n),r&&clearTimeout(r),l&&l.close()}}function te(e){let{onContentUpdate:t,getCurrentPath:n,getCurrentContentType:r,onHtmlReload:l,onTreeUpdate:o}=e;H(()=>{let a=null,c=null,u=kt({onFileChanged:_=>{if(n){if(_===null)return;let d=n();if(O(_)!==O(d))return;if(r?.()===\"html\"){l?.();return}a?.abort(),a=new AbortController,U(d,{signal:a.signal}).then(s=>{s!==null&&t(s)}).catch(s=>{s instanceof DOMException&&s.name===\"AbortError\"||console.error(\"[peek] Failed to refresh content:\",s)})}else a?.abort(),a=new AbortController,U(void 0,{signal:a.signal}).then(d=>{d!==null&&t(d)}).catch(d=>{d instanceof DOMException&&d.name===\"AbortError\"||console.error(\"[peek] Failed to refresh content:\",d)})},onTreeChanged:o?()=>{c?.abort(),c=new AbortController,bt({signal:c.signal}).then(_=>{_&&o(_)}).catch(_=>{_ instanceof DOMException&&_.name===\"AbortError\"||console.error(\"[peek] Failed to refresh tree:\",_)})}:void 0});return()=>{a?.abort(),c?.abort(),u()}},[])}function Tt({dirTitle:e,currentPath:t,contentType:n,content:r,tree:l}){let[o,a]=C(t),[c,u]=C(n),[_,d]=C(r),[s,f]=C(l),[p,v]=C(0),S=L(o);S.current=o;let x=St();xt((k,E)=>{let M=vt(k);if(!M){console.error(`Unexpected unsupported file type: ${k}`);return}S.current=k,a(k),u(M),d(E),v(0)});let y=L(c);y.current=c,te({getCurrentPath:()=>S.current,getCurrentContentType:()=>y.current,onContentUpdate:d,onHtmlReload:()=>v(k=>k+1),onTreeUpdate:f});let m=ee(o);return i(T,{children:[i(gt,{title:e,tree:s,currentPath:o,onClose:x.close}),i(ht,{id:\"header-bar\",breadcrumbs:[{label:e,href:\"/\"},{label:m}],showSidebarToggle:!0,onToggleSidebar:x.toggle,externalLinkHref:`/${o.split(\"/\").map(encodeURIComponent).join(\"/\")}`}),i(dt,{contentType:c,fileTitle:m,rawUrl:`/api/raw?path=${encodeURIComponent(o)}`,htmlContent:_,htmlReloadKey:p})]})}function Ct({content:e}){let[t,n]=C(e);return te({onContentUpdate:n}),i(\"main\",{class:\"px-2 sm:px-5 py-5 sm:py-15\",children:i(\"div\",{class:\"max-w-4xl mx-auto\",children:i(Q,{htmlContent:t})})})}var He=\"theme\";function Re(){let e=localStorage.getItem(He);return e===\"light\"||e===\"dark\"?e:\"system\"}function Be(e){let t=document.documentElement;e===\"dark\"?t.classList.add(\"dark\"):e===\"light\"?t.classList.remove(\"dark\"):window.matchMedia(\"(prefers-color-scheme: dark)\").matches?t.classList.add(\"dark\"):t.classList.remove(\"dark\")}function It(e){let t=document.getElementById(\"icon-theme-light\"),n=document.getElementById(\"icon-theme-dark\"),r=document.getElementById(\"icon-theme-system\");!t||!n||!r||(t.classList.add(\"hidden\"),n.classList.add(\"hidden\"),r.classList.add(\"hidden\"),e===\"light\"?t.classList.remove(\"hidden\"):e===\"dark\"?n.classList.remove(\"hidden\"):r.classList.remove(\"hidden\"))}function Qt(e){return e===\"light\"?\"dark\":e===\"dark\"?\"system\":\"light\"}function Et(){let e=Re();Be(e),It(e);let t=document.getElementById(\"theme-toggle\");t&&t.addEventListener(\"click\",()=>{let n=Qt(Re());n===\"system\"?localStorage.removeItem(He):localStorage.setItem(He,n),Be(n),It(n)}),window.matchMedia(\"(prefers-color-scheme: dark)\").addEventListener(\"change\",()=>{Re()===\"system\"&&Be(\"system\")})}var ne=window.__INITIAL_STATE__,Ne=document.getElementById(\"app\");Ne&&ne?ne.mode===\"directory\"?Z(i(Tt,{...ne}),Ne):Z(i(Ct,{...ne}),Ne):console.error(\"[peek] hydration failed: missing #app or initial state\");Et();})();\n";
|
|
839
|
+
//#endregion
|
|
840
|
+
//#region src/server/renderer/global.css?inline
|
|
841
|
+
var global_default = "/*! tailwindcss v4.2.1 | MIT License | https://tailwindcss.com */\n@layer properties {\n @supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {\n *, :before, :after, ::backdrop {\n --tw-translate-x: 0;\n --tw-translate-y: 0;\n --tw-translate-z: 0;\n --tw-rotate-x: initial;\n --tw-rotate-y: initial;\n --tw-rotate-z: initial;\n --tw-skew-x: initial;\n --tw-skew-y: initial;\n --tw-border-style: solid;\n --tw-font-weight: initial;\n --tw-shadow: 0 0 #0000;\n --tw-shadow-color: initial;\n --tw-shadow-alpha: 100%;\n --tw-inset-shadow: 0 0 #0000;\n --tw-inset-shadow-color: initial;\n --tw-inset-shadow-alpha: 100%;\n --tw-ring-color: initial;\n --tw-ring-shadow: 0 0 #0000;\n --tw-inset-ring-color: initial;\n --tw-inset-ring-shadow: 0 0 #0000;\n --tw-ring-inset: initial;\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-ease: initial;\n --tw-content: \"\";\n }\n }\n}\n\n@layer theme {\n :root, :host {\n --font-sans: ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\";\n --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace;\n --color-black: #000;\n --spacing: .25rem;\n --container-4xl: 56rem;\n --text-sm: .875rem;\n --text-sm--line-height: calc(1.25 / .875);\n --font-weight-medium: 500;\n --font-weight-semibold: 600;\n --radius-lg: .5rem;\n --radius-xl: .75rem;\n --ease-in-out: cubic-bezier(.4, 0, .2, 1);\n --animate-spin: spin 1s linear infinite;\n --animate-pulse: pulse 2s cubic-bezier(.4, 0, .6, 1) infinite;\n --default-transition-duration: .15s;\n --default-transition-timing-function: cubic-bezier(.4, 0, .2, 1);\n --default-font-family: var(--font-sans);\n --default-mono-font-family: var(--font-mono);\n --color-background: var(--background);\n --color-foreground: var(--foreground);\n --color-card: var(--card);\n --color-muted-foreground: var(--muted-foreground);\n --color-border: var(--border);\n --color-sidebar: var(--sidebar);\n --color-sidebar-foreground: var(--sidebar-foreground);\n --color-sidebar-primary: var(--sidebar-primary);\n --color-sidebar-accent: var(--sidebar-accent);\n --color-sidebar-border: var(--sidebar-border);\n --color-scrollbar-track: var(--scrollbar-track);\n --color-scrollbar-thumb: var(--scrollbar-thumb);\n }\n}\n\n@layer base {\n *, :after, :before, ::backdrop {\n box-sizing: border-box;\n border: 0 solid;\n margin: 0;\n padding: 0;\n }\n\n ::file-selector-button {\n box-sizing: border-box;\n border: 0 solid;\n margin: 0;\n padding: 0;\n }\n\n html, :host {\n -webkit-text-size-adjust: 100%;\n tab-size: 4;\n line-height: 1.5;\n font-family: var(--default-font-family, ui-sans-serif, system-ui, sans-serif, \"Apple Color Emoji\", \"Segoe UI Emoji\", \"Segoe UI Symbol\", \"Noto Color Emoji\");\n font-feature-settings: var(--default-font-feature-settings, normal);\n font-variation-settings: var(--default-font-variation-settings, normal);\n -webkit-tap-highlight-color: transparent;\n }\n\n hr {\n height: 0;\n color: inherit;\n border-top-width: 1px;\n }\n\n abbr:where([title]) {\n text-decoration: underline dotted;\n }\n\n h1, h2, h3, h4, h5, h6 {\n font-size: inherit;\n font-weight: inherit;\n }\n\n a {\n color: inherit;\n -webkit-text-decoration: inherit;\n -webkit-text-decoration: inherit;\n -webkit-text-decoration: inherit;\n text-decoration: inherit;\n }\n\n b, strong {\n font-weight: bolder;\n }\n\n code, kbd, samp, pre {\n font-family: var(--default-mono-font-family, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, \"Liberation Mono\", \"Courier New\", monospace);\n font-feature-settings: var(--default-mono-font-feature-settings, normal);\n font-variation-settings: var(--default-mono-font-variation-settings, normal);\n font-size: 1em;\n }\n\n small {\n font-size: 80%;\n }\n\n sub, sup {\n vertical-align: baseline;\n font-size: 75%;\n line-height: 0;\n position: relative;\n }\n\n sub {\n bottom: -.25em;\n }\n\n sup {\n top: -.5em;\n }\n\n table {\n text-indent: 0;\n border-color: inherit;\n border-collapse: collapse;\n }\n\n :-moz-focusring {\n outline: auto;\n }\n\n progress {\n vertical-align: baseline;\n }\n\n summary {\n display: list-item;\n }\n\n ol, ul, menu {\n list-style: none;\n }\n\n img, svg, video, canvas, audio, iframe, embed, object {\n vertical-align: middle;\n display: block;\n }\n\n img, video {\n max-width: 100%;\n height: auto;\n }\n\n button, input, select, optgroup, textarea {\n font: inherit;\n font-feature-settings: inherit;\n font-variation-settings: inherit;\n letter-spacing: inherit;\n color: inherit;\n opacity: 1;\n background-color: #0000;\n border-radius: 0;\n }\n\n ::file-selector-button {\n font: inherit;\n font-feature-settings: inherit;\n font-variation-settings: inherit;\n letter-spacing: inherit;\n color: inherit;\n opacity: 1;\n background-color: #0000;\n border-radius: 0;\n }\n\n :where(select:is([multiple], [size])) optgroup {\n font-weight: bolder;\n }\n\n :where(select:is([multiple], [size])) optgroup option {\n padding-inline-start: 20px;\n }\n\n ::file-selector-button {\n margin-inline-end: 4px;\n }\n\n ::placeholder {\n opacity: 1;\n }\n\n @supports (not ((-webkit-appearance: -apple-pay-button))) or (contain-intrinsic-size: 1px) {\n ::placeholder {\n color: currentColor;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n ::placeholder {\n color: color-mix(in oklab, currentcolor 50%, transparent);\n }\n }\n }\n\n textarea {\n resize: vertical;\n }\n\n ::-webkit-search-decoration {\n -webkit-appearance: none;\n }\n\n ::-webkit-date-and-time-value {\n min-height: 1lh;\n text-align: inherit;\n }\n\n ::-webkit-datetime-edit {\n display: inline-flex;\n }\n\n ::-webkit-datetime-edit-fields-wrapper {\n padding: 0;\n }\n\n ::-webkit-datetime-edit {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-year-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-month-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-day-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-hour-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-minute-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-second-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-millisecond-field {\n padding-block: 0;\n }\n\n ::-webkit-datetime-edit-meridiem-field {\n padding-block: 0;\n }\n\n ::-webkit-calendar-picker-indicator {\n line-height: 1;\n }\n\n :-moz-ui-invalid {\n box-shadow: none;\n }\n\n button, input:where([type=\"button\"], [type=\"reset\"], [type=\"submit\"]) {\n appearance: button;\n }\n\n ::file-selector-button {\n appearance: button;\n }\n\n ::-webkit-inner-spin-button {\n height: auto;\n }\n\n ::-webkit-outer-spin-button {\n height: auto;\n }\n\n [hidden]:where(:not([hidden=\"until-found\"])) {\n display: none !important;\n }\n}\n\n@layer components;\n\n@layer utilities {\n .pointer-events-auto {\n pointer-events: auto;\n }\n\n .visible {\n visibility: visible;\n }\n\n .absolute {\n position: absolute;\n }\n\n .fixed {\n position: fixed;\n }\n\n .relative {\n position: relative;\n }\n\n .sticky {\n position: sticky;\n }\n\n .inset-0 {\n inset: calc(var(--spacing) * 0);\n }\n\n .inset-y-0 {\n inset-block: calc(var(--spacing) * 0);\n }\n\n .start {\n inset-inline-start: var(--spacing);\n }\n\n .start-0 {\n inset-inline-start: calc(var(--spacing) * 0);\n }\n\n .end-0 {\n inset-inline-end: calc(var(--spacing) * 0);\n }\n\n .top-0 {\n top: calc(var(--spacing) * 0);\n }\n\n .z-50 {\n z-index: 50;\n }\n\n .z-60 {\n z-index: 60;\n }\n\n .container {\n width: 100%;\n }\n\n @media (width >= 40rem) {\n .container {\n max-width: 40rem;\n }\n }\n\n @media (width >= 48rem) {\n .container {\n max-width: 48rem;\n }\n }\n\n @media (width >= 64rem) {\n .container {\n max-width: 64rem;\n }\n }\n\n @media (width >= 80rem) {\n .container {\n max-width: 80rem;\n }\n }\n\n @media (width >= 96rem) {\n .container {\n max-width: 96rem;\n }\n }\n\n .mx-1 {\n margin-inline: calc(var(--spacing) * 1);\n }\n\n .mx-auto {\n margin-inline: auto;\n }\n\n .ms-auto {\n margin-inline-start: auto;\n }\n\n .mt-1 {\n margin-top: calc(var(--spacing) * 1);\n }\n\n .mt-1\\.5 {\n margin-top: calc(var(--spacing) * 1.5);\n }\n\n .block {\n display: block;\n }\n\n .contents {\n display: contents;\n }\n\n .flex {\n display: flex;\n }\n\n .hidden {\n display: none;\n }\n\n .inline {\n display: inline;\n }\n\n .inline-flex {\n display: inline-flex;\n }\n\n .table {\n display: table;\n }\n\n .size-3\\.5 {\n width: calc(var(--spacing) * 3.5);\n height: calc(var(--spacing) * 3.5);\n }\n\n .size-4 {\n width: calc(var(--spacing) * 4);\n height: calc(var(--spacing) * 4);\n }\n\n .h-7 {\n height: calc(var(--spacing) * 7);\n }\n\n .h-11\\.5 {\n height: calc(var(--spacing) * 11.5);\n }\n\n .h-full {\n height: 100%;\n }\n\n .max-h-full {\n max-height: 100%;\n }\n\n .min-h-dvh {\n min-height: 100dvh;\n }\n\n .min-h-screen {\n min-height: 100vh;\n }\n\n .w-1 {\n width: calc(var(--spacing) * 1);\n }\n\n .w-7 {\n width: calc(var(--spacing) * 7);\n }\n\n .w-72 {\n width: calc(var(--spacing) * 72);\n }\n\n .w-full {\n width: 100%;\n }\n\n .max-w-4xl {\n max-width: var(--container-4xl);\n }\n\n .min-w-0 {\n min-width: calc(var(--spacing) * 0);\n }\n\n .flex-1 {\n flex: 1;\n }\n\n .flex-none {\n flex: none;\n }\n\n .shrink-0 {\n flex-shrink: 0;\n }\n\n .border-collapse {\n border-collapse: collapse;\n }\n\n .-translate-x-full {\n --tw-translate-x: -100%;\n translate: var(--tw-translate-x) var(--tw-translate-y);\n }\n\n .-rotate-180 {\n rotate: -180deg;\n }\n\n .transform {\n transform: var(--tw-rotate-x, ) var(--tw-rotate-y, ) var(--tw-rotate-z, ) var(--tw-skew-x, ) var(--tw-skew-y, );\n }\n\n .animate-pulse {\n animation: var(--animate-pulse);\n }\n\n .animate-spin {\n animation: var(--animate-spin);\n }\n\n .cursor-col-resize {\n cursor: col-resize;\n }\n\n .cursor-pointer {\n cursor: pointer;\n }\n\n .resize {\n resize: both;\n }\n\n .flex-col {\n flex-direction: column;\n }\n\n .flex-wrap {\n flex-wrap: wrap;\n }\n\n .items-center {\n align-items: center;\n }\n\n .justify-between {\n justify-content: space-between;\n }\n\n .justify-center {\n justify-content: center;\n }\n\n .gap-1 {\n gap: calc(var(--spacing) * 1);\n }\n\n .gap-x-3 {\n column-gap: calc(var(--spacing) * 3);\n }\n\n .gap-y-1 {\n row-gap: calc(var(--spacing) * 1);\n }\n\n .truncate {\n text-overflow: ellipsis;\n white-space: nowrap;\n overflow: hidden;\n }\n\n .overflow-hidden {\n overflow: hidden;\n }\n\n .overflow-x-hidden {\n overflow-x: hidden;\n }\n\n .overflow-y-auto {\n overflow-y: auto;\n }\n\n .rounded-lg {\n border-radius: var(--radius-lg);\n }\n\n .rounded-xl {\n border-radius: var(--radius-xl);\n }\n\n .border {\n border-style: var(--tw-border-style);\n border-width: 1px;\n }\n\n .border-e {\n border-inline-end-style: var(--tw-border-style);\n border-inline-end-width: 1px;\n }\n\n .border-b {\n border-bottom-style: var(--tw-border-style);\n border-bottom-width: 1px;\n }\n\n .border-border {\n border-color: var(--color-border);\n }\n\n .border-sidebar-border {\n border-color: var(--color-sidebar-border);\n }\n\n .bg-background {\n background-color: var(--color-background);\n }\n\n .bg-black\\/50 {\n background-color: #00000080;\n }\n\n @supports (color: color-mix(in lab, red, red)) {\n .bg-black\\/50 {\n background-color: color-mix(in oklab, var(--color-black) 50%, transparent);\n }\n }\n\n .bg-card {\n background-color: var(--color-card);\n }\n\n .bg-sidebar {\n background-color: var(--color-sidebar);\n }\n\n .bg-sidebar-accent {\n background-color: var(--color-sidebar-accent);\n }\n\n .px-2 {\n padding-inline: calc(var(--spacing) * 2);\n }\n\n .px-3 {\n padding-inline: calc(var(--spacing) * 3);\n }\n\n .px-5 {\n padding-inline: calc(var(--spacing) * 5);\n }\n\n .px-6 {\n padding-inline: calc(var(--spacing) * 6);\n }\n\n .py-2 {\n padding-block: calc(var(--spacing) * 2);\n }\n\n .py-5 {\n padding-block: calc(var(--spacing) * 5);\n }\n\n .py-8 {\n padding-block: calc(var(--spacing) * 8);\n }\n\n .ps-5 {\n padding-inline-start: calc(var(--spacing) * 5);\n }\n\n .ps-7 {\n padding-inline-start: calc(var(--spacing) * 7);\n }\n\n .pe-2 {\n padding-inline-end: calc(var(--spacing) * 2);\n }\n\n .pt-3 {\n padding-top: calc(var(--spacing) * 3);\n }\n\n .pb-3 {\n padding-bottom: calc(var(--spacing) * 3);\n }\n\n .text-left {\n text-align: left;\n }\n\n .text-sm {\n font-size: var(--text-sm);\n line-height: var(--tw-leading, var(--text-sm--line-height));\n }\n\n .font-medium {\n --tw-font-weight: var(--font-weight-medium);\n font-weight: var(--font-weight-medium);\n }\n\n .font-semibold {\n --tw-font-weight: var(--font-weight-semibold);\n font-weight: var(--font-weight-semibold);\n }\n\n .text-foreground {\n color: var(--color-foreground);\n }\n\n .text-muted-foreground {\n color: var(--color-muted-foreground);\n }\n\n .text-sidebar-foreground {\n color: var(--color-sidebar-foreground);\n }\n\n .text-sidebar-primary {\n color: var(--color-sidebar-primary);\n }\n\n .italic {\n font-style: italic;\n }\n\n .shadow-2xs {\n --tw-shadow: 0 1px var(--tw-shadow-color, #0000000d);\n box-shadow: var(--tw-inset-shadow), var(--tw-inset-ring-shadow), var(--tw-ring-offset-shadow), var(--tw-ring-shadow), var(--tw-shadow);\n }\n\n .transition {\n transition-property: color, background-color, border-color, outline-color, text-decoration-color, fill, stroke, --tw-gradient-from, --tw-gradient-via, --tw-gradient-to, opacity, box-shadow, transform, translate, scale, rotate, filter, -webkit-backdrop-filter, backdrop-filter, display, content-visibility, overlay, pointer-events;\n transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));\n transition-duration: var(--tw-duration, var(--default-transition-duration));\n }\n\n .transition-transform {\n transition-property: transform, translate, scale, rotate;\n transition-timing-function: var(--tw-ease, var(--default-transition-timing-function));\n transition-duration: var(--tw-duration, var(--default-transition-duration));\n }\n\n .ease-in-out {\n --tw-ease: var(--ease-in-out);\n transition-timing-function: var(--ease-in-out);\n }\n\n .before\\:absolute:before {\n content: var(--tw-content);\n position: absolute;\n }\n\n .before\\:start-\\[1\\.125rem\\]:before {\n content: var(--tw-content);\n inset-inline-start: 1.125rem;\n }\n\n .before\\:top-0:before {\n content: var(--tw-content);\n top: calc(var(--spacing) * 0);\n }\n\n .before\\:h-full:before {\n content: var(--tw-content);\n height: 100%;\n }\n\n .before\\:w-px:before {\n content: var(--tw-content);\n width: 1px;\n }\n\n .before\\:bg-sidebar-border:before {\n content: var(--tw-content);\n background-color: var(--color-sidebar-border);\n }\n\n @media (hover: hover) {\n .hover\\:bg-sidebar-accent:hover {\n background-color: var(--color-sidebar-accent);\n }\n\n .hover\\:bg-sidebar-border:hover {\n background-color: var(--color-sidebar-border);\n }\n\n .hover\\:text-foreground:hover {\n color: var(--color-foreground);\n }\n\n .hover\\:text-sidebar-primary:hover {\n color: var(--color-sidebar-primary);\n }\n }\n\n @media (width >= 40rem) {\n .sm\\:px-5 {\n padding-inline: calc(var(--spacing) * 5);\n }\n\n .sm\\:px-10 {\n padding-inline: calc(var(--spacing) * 10);\n }\n\n .sm\\:py-10 {\n padding-block: calc(var(--spacing) * 10);\n }\n\n .sm\\:py-15 {\n padding-block: calc(var(--spacing) * 15);\n }\n }\n\n @media (width >= 64rem) {\n .lg\\:block {\n display: block;\n }\n\n .lg\\:w-auto {\n width: auto;\n }\n\n .lg\\:px-5 {\n padding-inline: calc(var(--spacing) * 5);\n }\n\n .lg\\:ps-8 {\n padding-inline-start: calc(var(--spacing) * 8);\n }\n }\n\n .\\[\\&\\:\\:-webkit-scrollbar\\]\\:w-2::-webkit-scrollbar {\n width: calc(var(--spacing) * 2);\n }\n\n .\\[\\&\\:\\:-webkit-scrollbar-thumb\\]\\:rounded-none::-webkit-scrollbar-thumb {\n border-radius: 0;\n }\n\n .\\[\\&\\:\\:-webkit-scrollbar-thumb\\]\\:bg-scrollbar-thumb::-webkit-scrollbar-thumb {\n background-color: var(--color-scrollbar-thumb);\n }\n\n .\\[\\&\\:\\:-webkit-scrollbar-track\\]\\:bg-scrollbar-track::-webkit-scrollbar-track {\n background-color: var(--color-scrollbar-track);\n }\n}\n\n:root {\n --background: #fff;\n --foreground: #393a34;\n --card: #fff;\n --card-foreground: #393a34;\n --primary: #1c6b48;\n --primary-foreground: #fff;\n --muted: #f7f7f7;\n --muted-foreground: #6a737d;\n --border: #f0f0f0;\n --sidebar: #fff;\n --sidebar-foreground: #4e4f47;\n --sidebar-primary: #1c6b48;\n --sidebar-accent: #f7f7f7;\n --sidebar-accent-foreground: #393a34;\n --sidebar-border: #f0f0f0;\n --font-sans: ui-sans-serif, system-ui, sans-serif;\n --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;\n --scrollbar-track: #f7f7f7;\n --scrollbar-thumb: #393a3450;\n --radius: .5rem;\n}\n\n.dark {\n --background: #121212;\n --foreground: #dbd7caee;\n --card: #181818;\n --card-foreground: #dbd7caee;\n --primary: #4d9375;\n --primary-foreground: #121212;\n --muted: #181818;\n --muted-foreground: #959da5;\n --border: #191919;\n --sidebar: #121212;\n --sidebar-foreground: #bfbaaa;\n --sidebar-primary: #4d9375;\n --sidebar-accent: #181818;\n --sidebar-accent-foreground: #dbd7caee;\n --sidebar-border: #191919;\n --scrollbar-track: #181818;\n --scrollbar-thumb: #dedcd550;\n}\n\n#sidebar {\n transition: translate .3s;\n}\n\nbody[data-sidebar-open] #sidebar {\n translate: 0;\n}\n\nbody[data-sidebar-open] #sidebar-overlay {\n display: block;\n}\n\nbody[data-sidebar-open] #icon-sidebar-open {\n display: none;\n}\n\nbody[data-sidebar-open] #icon-sidebar-close {\n display: inline;\n}\n\n@media (width >= 1024px) {\n #sidebar {\n width: var(--sidebar-width, 18rem);\n }\n\n #header-bar, #main-content {\n transition: margin .3s;\n }\n\n body[data-sidebar-open] #sidebar-overlay {\n display: none;\n }\n\n body[data-sidebar-open] #header-bar, body[data-sidebar-open] #main-content {\n margin-inline-start: var(--sidebar-width, 18rem);\n }\n}\n\n@property --tw-translate-x {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-translate-y {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-translate-z {\n syntax: \"*\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-rotate-x {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-rotate-y {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-rotate-z {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-skew-x {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-skew-y {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-border-style {\n syntax: \"*\";\n inherits: false;\n initial-value: solid;\n}\n\n@property --tw-font-weight {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-shadow-color {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-shadow-alpha {\n syntax: \"<percentage>\";\n inherits: false;\n initial-value: 100%;\n}\n\n@property --tw-inset-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-inset-shadow-color {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-inset-shadow-alpha {\n syntax: \"<percentage>\";\n inherits: false;\n initial-value: 100%;\n}\n\n@property --tw-ring-color {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-ring-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-inset-ring-color {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-inset-ring-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-ring-inset {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-ring-offset-width {\n syntax: \"<length>\";\n inherits: false;\n initial-value: 0;\n}\n\n@property --tw-ring-offset-color {\n syntax: \"*\";\n inherits: false;\n initial-value: #fff;\n}\n\n@property --tw-ring-offset-shadow {\n syntax: \"*\";\n inherits: false;\n initial-value: 0 0 #0000;\n}\n\n@property --tw-ease {\n syntax: \"*\";\n inherits: false\n}\n\n@property --tw-content {\n syntax: \"*\";\n inherits: false;\n initial-value: \"\";\n}\n\n@keyframes spin {\n to {\n transform: rotate(360deg);\n }\n}\n\n@keyframes pulse {\n 50% {\n opacity: .5;\n }\n}\n";
|
|
842
|
+
//#endregion
|
|
843
|
+
//#region src/server/renderer/document.tsx
|
|
844
|
+
const themeInitScript = `(function(){var t=localStorage.getItem("theme");if(t==="dark"||(t!=="light"&&window.matchMedia("(prefers-color-scheme: dark)").matches))document.documentElement.classList.add("dark")})()`;
|
|
845
|
+
function Document({ title, styles, initialState, children }) {
|
|
846
|
+
const initialStateScript = initialState ? `window.__INITIAL_STATE__=${JSON.stringify(initialState).replaceAll("<", "\\u003c").replaceAll(">", "\\u003e").replaceAll("\u2028", "\\u2028").replaceAll("\u2029", "\\u2029")}` : "";
|
|
847
|
+
return /* @__PURE__ */ jsxs("html", {
|
|
848
|
+
lang: "en",
|
|
849
|
+
children: [/* @__PURE__ */ jsxs("head", { children: [
|
|
850
|
+
/* @__PURE__ */ jsx("meta", { charSet: "UTF-8" }),
|
|
851
|
+
/* @__PURE__ */ jsx("meta", {
|
|
852
|
+
name: "viewport",
|
|
853
|
+
content: "width=device-width, initial-scale=1.0"
|
|
854
|
+
}),
|
|
855
|
+
/* @__PURE__ */ jsxs("title", { children: [title, " - peek"] }),
|
|
856
|
+
/* @__PURE__ */ jsx("link", {
|
|
857
|
+
rel: "icon",
|
|
858
|
+
href: "/favicon.ico",
|
|
859
|
+
type: "image/x-icon"
|
|
860
|
+
}),
|
|
861
|
+
/* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: themeInitScript } }),
|
|
862
|
+
/* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: global_default } }),
|
|
863
|
+
/* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: styles.contentCss.replaceAll("</style", "<\\/style") } })
|
|
864
|
+
] }), /* @__PURE__ */ jsxs("body", {
|
|
865
|
+
class: "bg-background text-foreground min-h-screen",
|
|
866
|
+
children: [
|
|
867
|
+
/* @__PURE__ */ jsx("div", {
|
|
868
|
+
id: "app",
|
|
869
|
+
class: "flex flex-col min-h-dvh",
|
|
870
|
+
children
|
|
871
|
+
}),
|
|
872
|
+
initialStateScript && /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: initialStateScript } }),
|
|
873
|
+
/* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: clientBundle } })
|
|
874
|
+
]
|
|
875
|
+
})]
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
function renderDocument(vnode) {
|
|
879
|
+
return `<!DOCTYPE html>${renderToString(vnode)}`;
|
|
880
|
+
}
|
|
881
|
+
//#endregion
|
|
882
|
+
//#region src/core/sse-constants.ts
|
|
883
|
+
const SSE_INITIAL_RETRY_MS = 1e3;
|
|
884
|
+
const SSE_MAX_RETRY_MS = 3e4;
|
|
885
|
+
//#endregion
|
|
886
|
+
//#region src/server/renderer/html-document.tsx
|
|
887
|
+
function HtmlDocument({ title, rawContentUrl }) {
|
|
888
|
+
const sseReloadScript = `(function () {
|
|
889
|
+
var maxRetries = 10;
|
|
890
|
+
var retryCount = 0;
|
|
891
|
+
var initialDelay = ${SSE_INITIAL_RETRY_MS};
|
|
892
|
+
var maxDelay = ${SSE_MAX_RETRY_MS};
|
|
893
|
+
|
|
894
|
+
function connect() {
|
|
895
|
+
var es = new EventSource("/sse");
|
|
896
|
+
|
|
897
|
+
es.addEventListener("file-changed", function () {
|
|
898
|
+
var f = document.getElementById("content-frame");
|
|
899
|
+
if (f && f.contentWindow) {
|
|
900
|
+
f.contentWindow.location.reload();
|
|
901
|
+
}
|
|
902
|
+
});
|
|
903
|
+
|
|
904
|
+
es.onopen = function () {
|
|
905
|
+
retryCount = 0;
|
|
906
|
+
};
|
|
907
|
+
|
|
908
|
+
es.onerror = function () {
|
|
909
|
+
es.close();
|
|
910
|
+
retryCount++;
|
|
911
|
+
if (retryCount > maxRetries) return;
|
|
912
|
+
var delay = Math.min(
|
|
913
|
+
initialDelay * Math.pow(2, retryCount - 1),
|
|
914
|
+
maxDelay
|
|
915
|
+
);
|
|
916
|
+
setTimeout(connect, delay);
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
connect();
|
|
921
|
+
})()`;
|
|
922
|
+
return /* @__PURE__ */ jsxs("html", {
|
|
923
|
+
lang: "en",
|
|
924
|
+
children: [/* @__PURE__ */ jsxs("head", { children: [
|
|
925
|
+
/* @__PURE__ */ jsx("meta", { charSet: "UTF-8" }),
|
|
926
|
+
/* @__PURE__ */ jsx("meta", {
|
|
927
|
+
name: "viewport",
|
|
928
|
+
content: "width=device-width, initial-scale=1.0"
|
|
929
|
+
}),
|
|
930
|
+
/* @__PURE__ */ jsxs("title", { children: [title, " - peek"] }),
|
|
931
|
+
/* @__PURE__ */ jsx("style", { dangerouslySetInnerHTML: { __html: "html,body{margin:0;padding:0;height:100%;overflow:hidden}iframe{border:none;width:100%;height:100%}" } })
|
|
932
|
+
] }), /* @__PURE__ */ jsxs("body", { children: [/* @__PURE__ */ jsx("iframe", {
|
|
933
|
+
id: "content-frame",
|
|
934
|
+
title,
|
|
935
|
+
src: rawContentUrl
|
|
936
|
+
}), /* @__PURE__ */ jsx("script", { dangerouslySetInnerHTML: { __html: sseReloadScript } })] })]
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
function renderHtmlDocument(title, rawContentUrl) {
|
|
940
|
+
if (!rawContentUrl.startsWith("/")) throw new Error(`rawContentUrl must be an absolute path, got: ${rawContentUrl}`);
|
|
941
|
+
return `<!DOCTYPE html>${renderToString(/* @__PURE__ */ jsx(HtmlDocument, {
|
|
942
|
+
title,
|
|
943
|
+
rawContentUrl
|
|
944
|
+
}))}`;
|
|
945
|
+
}
|
|
946
|
+
//#endregion
|
|
947
|
+
//#region src/server/routes/directory.tsx
|
|
948
|
+
function findFirstFile(nodes) {
|
|
949
|
+
for (const node of nodes) {
|
|
950
|
+
if (node.type === "file") return node;
|
|
951
|
+
if (node.children) {
|
|
952
|
+
const found = findFirstFile(node.children);
|
|
953
|
+
if (found) return found;
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
function renderDirectoryView(params) {
|
|
958
|
+
const { dirTitle, fileTitle, currentPath, contentType, html, tree, styles } = params;
|
|
959
|
+
return renderDocument(/* @__PURE__ */ jsxs(Document, {
|
|
960
|
+
title: fileTitle,
|
|
961
|
+
styles,
|
|
962
|
+
initialState: {
|
|
963
|
+
mode: "directory",
|
|
964
|
+
dirTitle,
|
|
965
|
+
currentPath,
|
|
966
|
+
contentType,
|
|
967
|
+
content: html,
|
|
968
|
+
tree
|
|
969
|
+
},
|
|
970
|
+
children: [
|
|
971
|
+
/* @__PURE__ */ jsx(Sidebar, {
|
|
972
|
+
title: dirTitle,
|
|
973
|
+
tree,
|
|
974
|
+
currentPath
|
|
975
|
+
}),
|
|
976
|
+
/* @__PURE__ */ jsx(PageHeader, {
|
|
977
|
+
id: "header-bar",
|
|
978
|
+
breadcrumbs: [{
|
|
979
|
+
label: dirTitle,
|
|
980
|
+
href: "/"
|
|
981
|
+
}, { label: fileTitle }],
|
|
982
|
+
showSidebarToggle: true,
|
|
983
|
+
externalLinkHref: `/${currentPath.split("/").map(encodeURIComponent).join("/")}`
|
|
984
|
+
}),
|
|
985
|
+
/* @__PURE__ */ jsx(ContentView, {
|
|
986
|
+
contentType,
|
|
987
|
+
fileTitle,
|
|
988
|
+
rawUrl: `/api/raw?path=${encodeURIComponent(currentPath)}`,
|
|
989
|
+
htmlContent: html
|
|
990
|
+
})
|
|
991
|
+
]
|
|
992
|
+
}));
|
|
993
|
+
}
|
|
994
|
+
async function renderFileContent(fullPath, contentType) {
|
|
995
|
+
if (contentType === "html") {
|
|
996
|
+
try {
|
|
997
|
+
await access(fullPath, constants.R_OK);
|
|
998
|
+
} catch (e) {
|
|
999
|
+
if (isNodeError(e) && e.code === "ENOENT") return {
|
|
1000
|
+
ok: false,
|
|
1001
|
+
status: 404,
|
|
1002
|
+
message: "File not found"
|
|
1003
|
+
};
|
|
1004
|
+
logger.error("Failed to access file:", e);
|
|
1005
|
+
return {
|
|
1006
|
+
ok: false,
|
|
1007
|
+
status: 500,
|
|
1008
|
+
message: "Internal server error"
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
return {
|
|
1012
|
+
ok: true,
|
|
1013
|
+
html: ""
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
const result = await readTextFile(fullPath);
|
|
1017
|
+
if (!result.ok) {
|
|
1018
|
+
if (result.error.type === "file-not-found") return {
|
|
1019
|
+
ok: false,
|
|
1020
|
+
status: 404,
|
|
1021
|
+
message: "File not found"
|
|
1022
|
+
};
|
|
1023
|
+
logger.error("Failed to read file:", result.error);
|
|
1024
|
+
return {
|
|
1025
|
+
ok: false,
|
|
1026
|
+
status: 500,
|
|
1027
|
+
message: "Internal server error"
|
|
1028
|
+
};
|
|
1029
|
+
}
|
|
1030
|
+
return {
|
|
1031
|
+
ok: true,
|
|
1032
|
+
html: await renderMarkdown(result.value)
|
|
1033
|
+
};
|
|
1034
|
+
}
|
|
1035
|
+
function createDirectoryRoutes(dirPath, styles, treeCache) {
|
|
1036
|
+
const app = new Hono();
|
|
1037
|
+
app.get("/", async (c) => {
|
|
1038
|
+
const treeResult = await treeCache.get();
|
|
1039
|
+
if (!treeResult.ok) {
|
|
1040
|
+
logger.error("Failed to build file tree:", treeResult.error);
|
|
1041
|
+
return c.text("Internal server error", 500);
|
|
1042
|
+
}
|
|
1043
|
+
const firstFile = findFirstFile(treeResult.value);
|
|
1044
|
+
if (!firstFile) return c.text("No supported files found", 404);
|
|
1045
|
+
const contentType = getContentType(firstFile.path);
|
|
1046
|
+
if (!contentType) {
|
|
1047
|
+
logger.error("Unexpected unsupported file in tree:", firstFile.path);
|
|
1048
|
+
return c.text("Internal server error", 500);
|
|
1049
|
+
}
|
|
1050
|
+
const rendered = await renderFileContent(resolve(dirPath, normalize(firstFile.path)), contentType);
|
|
1051
|
+
if (!rendered.ok) return c.text(rendered.message, rendered.status);
|
|
1052
|
+
const dirTitle = basename(dirPath) || dirPath;
|
|
1053
|
+
return c.html(renderDirectoryView({
|
|
1054
|
+
dirTitle,
|
|
1055
|
+
fileTitle: basename(firstFile.path),
|
|
1056
|
+
currentPath: firstFile.path,
|
|
1057
|
+
contentType,
|
|
1058
|
+
html: rendered.html,
|
|
1059
|
+
tree: treeResult.value,
|
|
1060
|
+
styles
|
|
1061
|
+
}));
|
|
1062
|
+
});
|
|
1063
|
+
app.get("/view", async (c) => {
|
|
1064
|
+
const relativePath = c.req.query("path");
|
|
1065
|
+
if (!relativePath) return c.redirect("/");
|
|
1066
|
+
const fullPath = resolve(dirPath, normalize(relativePath));
|
|
1067
|
+
if (!isWithinBase(dirPath, fullPath)) return c.text("Forbidden", 403);
|
|
1068
|
+
const contentType = getContentType(relativePath);
|
|
1069
|
+
if (!contentType) return c.text("Not found", 404);
|
|
1070
|
+
const rendered = await renderFileContent(fullPath, contentType);
|
|
1071
|
+
if (!rendered.ok) return c.text(rendered.message, rendered.status);
|
|
1072
|
+
const treeResult = await treeCache.get();
|
|
1073
|
+
if (!treeResult.ok) {
|
|
1074
|
+
logger.error("Failed to build file tree:", treeResult.error);
|
|
1075
|
+
return c.text("Internal server error", 500);
|
|
1076
|
+
}
|
|
1077
|
+
const dirTitle = basename(dirPath) || dirPath;
|
|
1078
|
+
return c.html(renderDirectoryView({
|
|
1079
|
+
dirTitle,
|
|
1080
|
+
fileTitle: basename(relativePath),
|
|
1081
|
+
currentPath: relativePath,
|
|
1082
|
+
contentType,
|
|
1083
|
+
html: rendered.html,
|
|
1084
|
+
tree: treeResult.value,
|
|
1085
|
+
styles
|
|
1086
|
+
}));
|
|
1087
|
+
});
|
|
1088
|
+
app.get("/:path{.+}", async (c) => {
|
|
1089
|
+
const relativePath = c.req.param("path");
|
|
1090
|
+
const fullPath = resolve(dirPath, normalize(relativePath));
|
|
1091
|
+
if (!isWithinBase(dirPath, fullPath)) return c.text("Forbidden", 403);
|
|
1092
|
+
const contentType = getContentType(relativePath);
|
|
1093
|
+
if (!contentType) return c.text("Not found", 404);
|
|
1094
|
+
if (contentType === "html") {
|
|
1095
|
+
const rendered = await renderFileContent(fullPath, contentType);
|
|
1096
|
+
if (!rendered.ok) return c.text(rendered.message, rendered.status);
|
|
1097
|
+
const fileTitle = basename(relativePath);
|
|
1098
|
+
return c.html(renderHtmlDocument(fileTitle, `/api/raw?path=${encodeURIComponent(relativePath)}`));
|
|
1099
|
+
}
|
|
1100
|
+
const rendered = await renderFileContent(fullPath, contentType);
|
|
1101
|
+
if (!rendered.ok) return c.text(rendered.message, rendered.status);
|
|
1102
|
+
const fileTitle = basename(relativePath);
|
|
1103
|
+
return c.html(renderDocument(/* @__PURE__ */ jsx(Document, {
|
|
1104
|
+
title: fileTitle,
|
|
1105
|
+
styles,
|
|
1106
|
+
initialState: {
|
|
1107
|
+
mode: "file",
|
|
1108
|
+
content: rendered.html
|
|
1109
|
+
},
|
|
1110
|
+
children: /* @__PURE__ */ jsx(ContentView, {
|
|
1111
|
+
contentType,
|
|
1112
|
+
fileTitle,
|
|
1113
|
+
rawUrl: `/api/raw?path=${encodeURIComponent(relativePath)}`,
|
|
1114
|
+
htmlContent: rendered.html,
|
|
1115
|
+
markdownClass: "px-2 sm:px-5 py-5 sm:py-15"
|
|
1116
|
+
})
|
|
1117
|
+
})));
|
|
1118
|
+
});
|
|
1119
|
+
return app;
|
|
1120
|
+
}
|
|
1121
|
+
//#endregion
|
|
1122
|
+
//#region src/server/routes/file.tsx
|
|
1123
|
+
function createFileRoutes(filePath, styles) {
|
|
1124
|
+
const app = new Hono();
|
|
1125
|
+
app.get("/", async (c) => {
|
|
1126
|
+
const result = await readTextFile(filePath);
|
|
1127
|
+
if (!result.ok) {
|
|
1128
|
+
logger.error("Failed to read file:", result.error);
|
|
1129
|
+
return c.text("Failed to read file", 500);
|
|
1130
|
+
}
|
|
1131
|
+
const html = await renderMarkdown(result.value);
|
|
1132
|
+
const title = basename(filePath);
|
|
1133
|
+
return c.html(renderDocument(/* @__PURE__ */ jsx(Document, {
|
|
1134
|
+
title,
|
|
1135
|
+
styles,
|
|
1136
|
+
initialState: {
|
|
1137
|
+
mode: "file",
|
|
1138
|
+
content: html
|
|
1139
|
+
},
|
|
1140
|
+
children: /* @__PURE__ */ jsx("main", {
|
|
1141
|
+
class: "px-2 sm:px-5 py-5 sm:py-15",
|
|
1142
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
1143
|
+
class: "max-w-4xl mx-auto",
|
|
1144
|
+
children: /* @__PURE__ */ jsx(MarkdownContent, { htmlContent: html })
|
|
1145
|
+
})
|
|
1146
|
+
})
|
|
1147
|
+
})));
|
|
1148
|
+
});
|
|
1149
|
+
return app;
|
|
1150
|
+
}
|
|
1151
|
+
//#endregion
|
|
1152
|
+
//#region src/server/routes/html-file.tsx
|
|
1153
|
+
function createHtmlFileRoutes(filePath) {
|
|
1154
|
+
const app = new Hono();
|
|
1155
|
+
app.get("/", (c) => {
|
|
1156
|
+
const title = basename(filePath);
|
|
1157
|
+
return c.html(renderHtmlDocument(title, "/api/raw"));
|
|
1158
|
+
});
|
|
1159
|
+
return app;
|
|
1160
|
+
}
|
|
1161
|
+
//#endregion
|
|
1162
|
+
//#region src/server/routes/sse.ts
|
|
1163
|
+
function sleep(ms, signal) {
|
|
1164
|
+
return new Promise((resolve, reject) => {
|
|
1165
|
+
const timer = setTimeout(resolve, ms);
|
|
1166
|
+
signal.addEventListener("abort", () => {
|
|
1167
|
+
clearTimeout(timer);
|
|
1168
|
+
reject(signal.reason);
|
|
1169
|
+
}, { once: true });
|
|
1170
|
+
});
|
|
1171
|
+
}
|
|
1172
|
+
const KEEP_ALIVE_INTERVAL_MS = 3e4;
|
|
1173
|
+
function createSseManager() {
|
|
1174
|
+
const clients = /* @__PURE__ */ new Set();
|
|
1175
|
+
function broadcast(event, data) {
|
|
1176
|
+
for (const client of Array.from(clients)) client.send(event, data);
|
|
1177
|
+
}
|
|
1178
|
+
function closeAll() {
|
|
1179
|
+
for (const client of clients) client.close();
|
|
1180
|
+
clients.clear();
|
|
1181
|
+
}
|
|
1182
|
+
const app = new Hono();
|
|
1183
|
+
app.get("/sse", (c) => {
|
|
1184
|
+
return streamSSE(c, async (stream) => {
|
|
1185
|
+
let closed = false;
|
|
1186
|
+
const abortController = new AbortController();
|
|
1187
|
+
function cleanup() {
|
|
1188
|
+
if (!closed) {
|
|
1189
|
+
closed = true;
|
|
1190
|
+
abortController.abort();
|
|
1191
|
+
clients.delete(client);
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
const client = {
|
|
1195
|
+
send: (event, data) => {
|
|
1196
|
+
if (!closed) stream.writeSSE({
|
|
1197
|
+
event,
|
|
1198
|
+
data
|
|
1199
|
+
}).catch(cleanup);
|
|
1200
|
+
},
|
|
1201
|
+
close: cleanup
|
|
1202
|
+
};
|
|
1203
|
+
clients.add(client);
|
|
1204
|
+
stream.onAbort(cleanup);
|
|
1205
|
+
while (!closed) {
|
|
1206
|
+
try {
|
|
1207
|
+
await sleep(KEEP_ALIVE_INTERVAL_MS, abortController.signal);
|
|
1208
|
+
} catch {
|
|
1209
|
+
break;
|
|
1210
|
+
}
|
|
1211
|
+
if (!closed) await stream.write(": keep-alive\n\n").catch(cleanup);
|
|
1212
|
+
}
|
|
1213
|
+
});
|
|
1214
|
+
});
|
|
1215
|
+
return {
|
|
1216
|
+
app,
|
|
1217
|
+
broadcast,
|
|
1218
|
+
closeAll,
|
|
1219
|
+
get clientCount() {
|
|
1220
|
+
return clients.size;
|
|
1221
|
+
}
|
|
1222
|
+
};
|
|
1223
|
+
}
|
|
1224
|
+
//#endregion
|
|
1225
|
+
//#region src/server/index.ts
|
|
1226
|
+
function createApp(ctx, sse) {
|
|
1227
|
+
const app = new Hono();
|
|
1228
|
+
app.get("/favicon.ico", (c) => {
|
|
1229
|
+
const buf = Buffer.from(faviconBase64, "base64");
|
|
1230
|
+
return c.body(buf, 200, {
|
|
1231
|
+
"Content-Type": "image/x-icon",
|
|
1232
|
+
"Cache-Control": "public, max-age=86400"
|
|
1233
|
+
});
|
|
1234
|
+
});
|
|
1235
|
+
app.route("/", sse.app);
|
|
1236
|
+
if (ctx.mode === "file") {
|
|
1237
|
+
const apiRoutes = createApiRoutes({
|
|
1238
|
+
mode: "file",
|
|
1239
|
+
targetPath: ctx.targetPath
|
|
1240
|
+
});
|
|
1241
|
+
app.route("/", apiRoutes);
|
|
1242
|
+
if (ctx.contentType === "html") app.route("/", createHtmlFileRoutes(ctx.targetPath));
|
|
1243
|
+
else app.route("/", createFileRoutes(ctx.targetPath, ctx.styles));
|
|
1244
|
+
} else {
|
|
1245
|
+
const apiConfig = {
|
|
1246
|
+
mode: "directory",
|
|
1247
|
+
targetPath: ctx.targetPath,
|
|
1248
|
+
treeCache: ctx.treeCache
|
|
1249
|
+
};
|
|
1250
|
+
app.route("/", createApiRoutes(apiConfig));
|
|
1251
|
+
app.route("/", createDirectoryRoutes(ctx.targetPath, ctx.styles, ctx.treeCache));
|
|
1252
|
+
}
|
|
1253
|
+
return app;
|
|
1254
|
+
}
|
|
1255
|
+
function setupWatcher(ctx, sse) {
|
|
1256
|
+
const watcher = createFileWatcher();
|
|
1257
|
+
if (ctx.mode === "file") watcher.watchFile(ctx.targetPath, () => {
|
|
1258
|
+
sse.broadcast("file-changed", JSON.stringify({}));
|
|
1259
|
+
});
|
|
1260
|
+
else watcher.watchDirectory(ctx.targetPath, (filePath) => {
|
|
1261
|
+
const normalizedPath = filePath.replace(/\\/g, "/");
|
|
1262
|
+
ctx.treeCache.invalidate();
|
|
1263
|
+
sse.broadcast("file-changed", JSON.stringify({ path: normalizedPath }));
|
|
1264
|
+
sse.broadcast("tree-changed", JSON.stringify({}));
|
|
1265
|
+
});
|
|
1266
|
+
return watcher;
|
|
1267
|
+
}
|
|
1268
|
+
async function startServer(config) {
|
|
1269
|
+
const sse = createSseManager();
|
|
1270
|
+
const ctx = config.mode === "directory" ? {
|
|
1271
|
+
mode: "directory",
|
|
1272
|
+
targetPath: config.targetPath,
|
|
1273
|
+
styles: config.styles,
|
|
1274
|
+
treeCache: createFileTreeCache(config.targetPath)
|
|
1275
|
+
} : config.contentType === "html" ? {
|
|
1276
|
+
mode: "file",
|
|
1277
|
+
targetPath: config.targetPath,
|
|
1278
|
+
contentType: "html"
|
|
1279
|
+
} : {
|
|
1280
|
+
mode: "file",
|
|
1281
|
+
targetPath: config.targetPath,
|
|
1282
|
+
contentType: config.contentType,
|
|
1283
|
+
styles: config.styles
|
|
1284
|
+
};
|
|
1285
|
+
const app = createApp(ctx, sse);
|
|
1286
|
+
const watcher = setupWatcher(ctx, sse);
|
|
1287
|
+
const server = serve({
|
|
1288
|
+
fetch: app.fetch,
|
|
1289
|
+
hostname: config.hostname,
|
|
1290
|
+
port: config.port
|
|
1291
|
+
});
|
|
1292
|
+
await new Promise((resolve, reject) => {
|
|
1293
|
+
const onListening = () => {
|
|
1294
|
+
server.removeListener("error", onError);
|
|
1295
|
+
resolve();
|
|
1296
|
+
};
|
|
1297
|
+
const onError = (err) => {
|
|
1298
|
+
server.removeListener("listening", onListening);
|
|
1299
|
+
sse.closeAll();
|
|
1300
|
+
watcher.close();
|
|
1301
|
+
reject(err);
|
|
1302
|
+
};
|
|
1303
|
+
server.once("listening", onListening);
|
|
1304
|
+
server.once("error", onError);
|
|
1305
|
+
});
|
|
1306
|
+
const close = () => new Promise((resolve, reject) => {
|
|
1307
|
+
server.close((err) => err ? reject(err) : resolve());
|
|
1308
|
+
});
|
|
1309
|
+
const sseCloseAll = () => sse.closeAll();
|
|
1310
|
+
return {
|
|
1311
|
+
close,
|
|
1312
|
+
watcher,
|
|
1313
|
+
sseCloseAll,
|
|
1314
|
+
async shutdown() {
|
|
1315
|
+
sseCloseAll();
|
|
1316
|
+
watcher.close();
|
|
1317
|
+
await close();
|
|
1318
|
+
}
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
//#endregion
|
|
1322
|
+
//#region src/index.ts
|
|
1323
|
+
const pkg = createRequire(import.meta.url)("../package.json");
|
|
1324
|
+
const command = define({
|
|
1325
|
+
name: "peek",
|
|
1326
|
+
description: "Preview Markdown and HTML files in the browser",
|
|
1327
|
+
args: {
|
|
1328
|
+
path: {
|
|
1329
|
+
type: "positional",
|
|
1330
|
+
description: "File or directory path to preview"
|
|
1331
|
+
},
|
|
1332
|
+
port: {
|
|
1333
|
+
type: "number",
|
|
1334
|
+
short: "p",
|
|
1335
|
+
default: 3e3,
|
|
1336
|
+
description: "Server port"
|
|
1337
|
+
},
|
|
1338
|
+
host: {
|
|
1339
|
+
type: "string",
|
|
1340
|
+
short: "H",
|
|
1341
|
+
default: "localhost",
|
|
1342
|
+
description: "Bind hostname (use 0.0.0.0 for external access)"
|
|
1343
|
+
},
|
|
1344
|
+
css: {
|
|
1345
|
+
type: "string",
|
|
1346
|
+
short: "c",
|
|
1347
|
+
description: "Custom CSS file path"
|
|
1348
|
+
},
|
|
1349
|
+
open: {
|
|
1350
|
+
type: "boolean",
|
|
1351
|
+
default: true,
|
|
1352
|
+
negatable: true,
|
|
1353
|
+
description: "Open browser automatically"
|
|
1354
|
+
}
|
|
1355
|
+
},
|
|
1356
|
+
examples: `$ peek README.md
|
|
1357
|
+
$ peek index.html
|
|
1358
|
+
$ peek docs/
|
|
1359
|
+
$ peek . --port 8080
|
|
1360
|
+
$ peek README.md --css ./custom.css --no-open`,
|
|
1361
|
+
run: async (ctx) => {
|
|
1362
|
+
const { path: targetArg, port, host: hostname, css, open } = ctx.values;
|
|
1363
|
+
intro(pc.bgCyan(pc.black(" peek ")));
|
|
1364
|
+
const fullPath = resolve(targetArg || ".");
|
|
1365
|
+
const mode = (await stat(fullPath).catch((e) => {
|
|
1366
|
+
logger.error("Failed to stat path:", e);
|
|
1367
|
+
cancel(`Path not found: ${fullPath}`);
|
|
1368
|
+
return process.exit(1);
|
|
1369
|
+
})).isDirectory() ? "directory" : "file";
|
|
1370
|
+
const contentType = mode === "file" ? getContentType(fullPath) : null;
|
|
1371
|
+
if (mode === "file" && !contentType) {
|
|
1372
|
+
cancel("Only Markdown (.md) and HTML (.html, .htm) files are supported");
|
|
1373
|
+
process.exit(1);
|
|
1374
|
+
}
|
|
1375
|
+
if (Number.isNaN(port) || !Number.isInteger(port) || port < 1 || port > 65535) {
|
|
1376
|
+
cancel(`Invalid port number: ${port}`);
|
|
1377
|
+
process.exit(1);
|
|
1378
|
+
}
|
|
1379
|
+
const s = spinner();
|
|
1380
|
+
s.start("Initializing...");
|
|
1381
|
+
const isHtmlFileMode = mode === "file" && contentType === "html";
|
|
1382
|
+
if (isHtmlFileMode && css) log.warn("--css option is ignored for HTML file preview");
|
|
1383
|
+
if (!isHtmlFileMode) await initMarkdown().catch((e) => {
|
|
1384
|
+
logger.error("Failed to initialize Markdown renderer:", e);
|
|
1385
|
+
s.stop("Failed to initialize");
|
|
1386
|
+
cancel("Failed to initialize Markdown renderer");
|
|
1387
|
+
return process.exit(1);
|
|
1388
|
+
});
|
|
1389
|
+
let serverConfig;
|
|
1390
|
+
if (isHtmlFileMode) serverConfig = {
|
|
1391
|
+
targetPath: fullPath,
|
|
1392
|
+
mode: "file",
|
|
1393
|
+
port,
|
|
1394
|
+
hostname,
|
|
1395
|
+
contentType: "html"
|
|
1396
|
+
};
|
|
1397
|
+
else {
|
|
1398
|
+
const styles = await resolveStyles(css).then((result) => {
|
|
1399
|
+
if (result.ok) return result.value;
|
|
1400
|
+
s.stop("Failed to resolve styles");
|
|
1401
|
+
cancel(result.error.type === "file-not-found" ? `CSS file not found: ${result.error.path}` : `Failed to read CSS file: ${result.error.path}`);
|
|
1402
|
+
return process.exit(1);
|
|
1403
|
+
});
|
|
1404
|
+
serverConfig = mode === "file" && contentType && contentType !== "html" ? {
|
|
1405
|
+
targetPath: fullPath,
|
|
1406
|
+
mode: "file",
|
|
1407
|
+
port,
|
|
1408
|
+
hostname,
|
|
1409
|
+
styles,
|
|
1410
|
+
contentType
|
|
1411
|
+
} : {
|
|
1412
|
+
targetPath: fullPath,
|
|
1413
|
+
mode: "directory",
|
|
1414
|
+
port,
|
|
1415
|
+
hostname,
|
|
1416
|
+
styles
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
const server = await startServer(serverConfig).catch((e) => {
|
|
1420
|
+
s.stop("Failed to start server");
|
|
1421
|
+
cancel(isNodeError(e) && e.code === "EADDRINUSE" ? `Port ${port} is already in use` : "Failed to start server");
|
|
1422
|
+
return process.exit(1);
|
|
1423
|
+
});
|
|
1424
|
+
s.stop("Server started");
|
|
1425
|
+
const url = `http://${hostname}:${port}`;
|
|
1426
|
+
log.info(`${pc.green("Preview:")} ${pc.cyan(pc.underline(url))}`);
|
|
1427
|
+
log.info(`${pc.dim(`Mode: ${mode} | Path: ${fullPath}`)}`);
|
|
1428
|
+
if (open) openBrowser(url);
|
|
1429
|
+
outro(pc.dim("Press Ctrl+C to stop"));
|
|
1430
|
+
let shuttingDown = false;
|
|
1431
|
+
const shutdown = async () => {
|
|
1432
|
+
if (shuttingDown) return;
|
|
1433
|
+
shuttingDown = true;
|
|
1434
|
+
console.log();
|
|
1435
|
+
intro(pc.bgYellow(pc.black(" Shutting down... ")));
|
|
1436
|
+
await server.shutdown();
|
|
1437
|
+
outro(pc.green("Server stopped. Bye!"));
|
|
1438
|
+
process.exit(0);
|
|
1439
|
+
};
|
|
1440
|
+
process.on("SIGINT", shutdown);
|
|
1441
|
+
process.on("SIGTERM", shutdown);
|
|
1442
|
+
}
|
|
1443
|
+
});
|
|
1444
|
+
function openBrowser(url) {
|
|
1445
|
+
const os = platform();
|
|
1446
|
+
let cmd;
|
|
1447
|
+
let args;
|
|
1448
|
+
if (os === "darwin") {
|
|
1449
|
+
cmd = "open";
|
|
1450
|
+
args = [url];
|
|
1451
|
+
} else if (os === "win32") {
|
|
1452
|
+
cmd = "cmd";
|
|
1453
|
+
args = [
|
|
1454
|
+
"/c",
|
|
1455
|
+
"start",
|
|
1456
|
+
"",
|
|
1457
|
+
url
|
|
1458
|
+
];
|
|
1459
|
+
} else {
|
|
1460
|
+
cmd = "xdg-open";
|
|
1461
|
+
args = [url];
|
|
1462
|
+
}
|
|
1463
|
+
execFile(cmd, args, (err) => {
|
|
1464
|
+
if (err) logger.error(`Failed to open browser: ${err.message}`);
|
|
1465
|
+
});
|
|
1466
|
+
}
|
|
1467
|
+
await cli(process.argv.slice(2), command, {
|
|
1468
|
+
name: "peek",
|
|
1469
|
+
version: pkg.version,
|
|
1470
|
+
description: "Preview Markdown and HTML files in the browser"
|
|
1471
|
+
});
|
|
1472
|
+
//#endregion
|
|
1473
|
+
export {};
|