@evandu/super-pi 0.1.259 → 0.1.261
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/README.md +3 -1
- package/bin/super-pi.js +1 -1
- package/desktop/brand.svg +6 -0
- package/desktop/icon.png +0 -0
- package/desktop/launch.cjs +7 -7
- package/desktop/login-item.cjs +7 -0
- package/desktop/main.cjs +27 -7
- package/desktop/preload.cjs +19 -0
- package/desktop/runtime.cjs +107 -0
- package/desktop/tray-icon.png +0 -0
- package/desktop/tray-icon@2x.png +0 -0
- package/desktop/tray.svg +1 -0
- package/dist/client/.super-pi-client-sources.json +7 -6
- package/dist/client/assets/{CodeMirrorEditor-mi9rGUce.js → CodeMirrorEditor-DGK07ECt.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-FQBfGxOY.js → GitDiffEditor-DCQ2HgfJ.js} +1 -1
- package/dist/client/assets/index-BVn_-dwp.js +350 -0
- package/dist/client/assets/{index-UfzqdECL.css → index-DhW875H-.css} +1 -1
- package/dist/client/favicon.ico +0 -0
- package/dist/client/favicon.png +0 -0
- package/dist/client/favicon.svg +5 -9
- package/dist/client/index.html +2 -2
- package/dist/server/existing-service.d.ts +12 -0
- package/dist/server/existing-service.js +18 -0
- package/dist/server/managed-http-tunnel.d.ts +2 -2
- package/dist/server/managed-http-tunnel.js +7 -5
- package/dist/server/managed-http.js +6 -2
- package/dist/server/managed-servers.d.ts +46 -3
- package/dist/server/managed-servers.js +199 -20
- package/dist/server/managed-ssh.d.ts +14 -1
- package/dist/server/managed-ssh.js +55 -5
- package/dist/server/runtime.js +2 -2
- package/dist/shared/managed-servers.d.ts +23 -2
- package/package.json +8 -1
- package/scripts/pack-server.mjs +1 -1
- package/dist/client/assets/index-Cn7hdrDw.js +0 -350
package/README.md
CHANGED
|
@@ -17,7 +17,9 @@ npm install -g @evandu/super-pi
|
|
|
17
17
|
super_pi desktop
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
The first desktop launch
|
|
20
|
+
The first desktop launch prepares the Electron runtime automatically, with progress, retries,
|
|
21
|
+
an alternate mirror, and official checksum verification. It caches the runtime in the user's
|
|
22
|
+
data directory across npm upgrades; users do not need to configure a mirror. Closing the window
|
|
21
23
|
keeps the app in the system tray. Settings → Desktop and background provides optional startup
|
|
22
24
|
at sign-in. Browser access remains available; both interfaces use the same local service.
|
|
23
25
|
|
package/bin/super-pi.js
CHANGED
|
@@ -297,7 +297,7 @@ const command = implicitStart ? "start" : raw?.toLowerCase();
|
|
|
297
297
|
const args = implicitStart ? [raw, ...rest] : rest;
|
|
298
298
|
try {
|
|
299
299
|
if (command === "help" || command === "--help" || command === "-h") { usage(); process.exit(0); }
|
|
300
|
-
if (command === "desktop" || command === "app") { if (!existsSync(join(root, "desktop", "launch.cjs"))) throw new Error("纯服务包不包含桌面端,请在自己的电脑安装完整包 @evandu/super-pi"); await import(pathToFileURL(join(root, "desktop", "launch.cjs")).href); process.exit(
|
|
300
|
+
if (command === "desktop" || command === "app") { if (!existsSync(join(root, "desktop", "launch.cjs"))) throw new Error("纯服务包不包含桌面端,请在自己的电脑安装完整包 @evandu/super-pi"); const launcher = await import(pathToFileURL(join(root, "desktop", "launch.cjs")).href); await launcher.default.launchDesktop(args); process.exit(0); }
|
|
301
301
|
else if (!command) { const value = options(args); await start(value); const url = `http://127.0.0.1:${value.port}`; if (value.browser) openBrowser(url); console.log(value.browser ? `Opened ${url}\n${runningBanner(url)}` : runningBanner(url)); process.exit(0); }
|
|
302
302
|
if (command === "autostart" || command === "startup") { const action = args.shift()?.toLowerCase() ?? "status"; const value = options(args); if (action === "enable") await enable(value); else if (action === "disable") await disable(); else if (action === "status") await status(); else throw new Error("Autostart action must be enable, disable, or status."); process.exit(0); }
|
|
303
303
|
if (command === "diagnose" || command === "diagnose-latency") {
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" style="--brand-start:#526ff5;--brand-end:#6844ce;--brand-mark:#ffffff;--brand-edge:#ffffff">
|
|
2
|
+
<defs><linearGradient id="brand" x1="0" y1="0" x2="1" y2="1"><stop stop-color="var(--brand-start)"/><stop offset="1" stop-color="var(--brand-end)"/></linearGradient></defs>
|
|
3
|
+
<rect x="16" y="16" width="224" height="224" rx="52" fill="url(#brand)"/>
|
|
4
|
+
<rect x="17" y="17" width="222" height="222" rx="51" fill="none" stroke="var(--brand-edge)" stroke-opacity=".16" stroke-width="2"/>
|
|
5
|
+
<g fill="none" stroke="var(--brand-mark)" stroke-width="16" stroke-linecap="round" stroke-linejoin="round"><path d="M66 86h124"/><path d="M103 88v49c0 19-5 34-15 47"/><path d="M158 88v69c0 16 8 23 23 23h5"/></g>
|
|
6
|
+
</svg>
|
package/desktop/icon.png
CHANGED
|
Binary file
|
package/desktop/launch.cjs
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
const { spawn } = require("node:child_process");
|
|
3
3
|
const { join } = require("node:path");
|
|
4
|
+
const { ensureDesktopRuntime } = require("./runtime.cjs");
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
const electron =
|
|
6
|
+
async function launchDesktop(args = process.argv.slice(2)) {
|
|
7
|
+
const electron = await ensureDesktopRuntime();
|
|
7
8
|
const env = { ...process.env }; delete env.ELECTRON_RUN_AS_NODE;
|
|
8
|
-
const child = spawn(electron, [join(__dirname, "main.cjs"), ...
|
|
9
|
-
child.once("
|
|
9
|
+
const child = spawn(electron, [join(__dirname, "main.cjs"), ...args], { detached: true, stdio: "ignore", windowsHide: true, env });
|
|
10
|
+
await new Promise((resolve, reject) => { child.once("spawn", resolve); child.once("error", () => reject(new Error("桌面运行时已准备好,但系统未能启动桌面进程,请检查系统执行权限"))); });
|
|
10
11
|
child.unref();
|
|
11
|
-
} catch {
|
|
12
|
-
console.error("当前安装不包含桌面运行时。请安装完整包:npm install -g @evandu/super-pi");
|
|
13
|
-
process.exitCode = 1;
|
|
14
12
|
}
|
|
13
|
+
module.exports = { launchDesktop };
|
|
14
|
+
if (require.main === module) launchDesktop().catch(error => { console.error(`Super Pi 桌面启动失败:${error.message}`); process.exitCode = 1; });
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const escape = value => String(value).replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
2
|
+
function macLaunchAgent({ executable, script, node, dataDir, path }) {
|
|
3
|
+
const args = [executable, script, "--hidden"].map(value => `<string>${escape(value)}</string>`).join("");
|
|
4
|
+
const env = { PATH: path || "/usr/bin:/bin:/usr/sbin:/sbin", SUPER_PI_NODE_BINARY: node, SUPER_PI_DATA_DIR: dataDir };
|
|
5
|
+
return `<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n<plist version="1.0"><dict><key>Label</key><string>com.evandu.super-pi.desktop</string><key>ProgramArguments</key><array>${args}</array><key>EnvironmentVariables</key><dict>${Object.entries(env).map(([key, value]) => `<key>${key}</key><string>${escape(value)}</string>`).join("")}</dict><key>RunAtLoad</key><true/><key>LimitLoadToSessionType</key><string>Aqua</string></dict></plist>\n`;
|
|
6
|
+
}
|
|
7
|
+
module.exports = { macLaunchAgent };
|
package/desktop/main.cjs
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
const { app, BrowserWindow, Tray, Menu, shell, ipcMain, dialog, nativeImage } = require("electron");
|
|
1
|
+
const { app, BrowserWindow, Tray, Menu, shell, ipcMain, dialog, nativeImage, nativeTheme } = require("electron");
|
|
2
2
|
const { spawn, execFile } = require("node:child_process");
|
|
3
3
|
const { promisify } = require("node:util");
|
|
4
4
|
const { readFile, writeFile, mkdir, rm, access } = require("node:fs/promises");
|
|
5
5
|
const { existsSync } = require("node:fs");
|
|
6
6
|
const { homedir } = require("node:os");
|
|
7
7
|
const { join, resolve } = require("node:path");
|
|
8
|
+
const { macLaunchAgent } = require("./login-item.cjs");
|
|
8
9
|
|
|
9
10
|
const exec = promisify(execFile), root = resolve(__dirname, "..");
|
|
10
11
|
const dataDir = process.env.SUPER_PI_DATA_DIR || join(homedir(), ".super-pi");
|
|
@@ -12,6 +13,7 @@ if (process.env.SUPER_PI_DESKTOP_PROFILE) app.setPath("userData", resolve(proces
|
|
|
12
13
|
app.setName("Super Pi");
|
|
13
14
|
if (process.platform === "win32") app.setAppUserModelId("com.evandu.super-pi");
|
|
14
15
|
let mainWindow, tray, server, origin, quitting = false, ownsServer = false;
|
|
16
|
+
let frameTheme;
|
|
15
17
|
|
|
16
18
|
async function config() { try { return JSON.parse(await readFile(join(dataDir, "config.json"), "utf8")); } catch { return {}; } }
|
|
17
19
|
async function health(port) { try { const result = await fetch(`http://127.0.0.1:${port}/api/health`, { signal: AbortSignal.timeout(1500) }); return result.ok ? await result.json() : undefined; } catch { return undefined; } }
|
|
@@ -48,10 +50,16 @@ async function startManager() {
|
|
|
48
50
|
function trusted(event) {
|
|
49
51
|
if (!mainWindow || event.sender !== mainWindow.webContents || event.senderFrame !== mainWindow.webContents.mainFrame || !event.senderFrame.url.startsWith(`${origin}/`)) throw new Error("拒绝来自非主界面的桌面调用");
|
|
50
52
|
}
|
|
51
|
-
const startupFile = () => join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "autostart", "super-pi.desktop");
|
|
52
|
-
async function autoStartStatus() { return process.platform
|
|
53
|
+
const startupFile = () => process.platform === "darwin" ? join(homedir(), "Library", "LaunchAgents", "com.evandu.super-pi.desktop.plist") : join(process.env.XDG_CONFIG_HOME || join(homedir(), ".config"), "autostart", "super-pi.desktop");
|
|
54
|
+
async function autoStartStatus() { return process.platform !== "win32" ? existsSync(startupFile()) : app.getLoginItemSettings({ path: process.execPath, args: [__filename, "--hidden"] }).openAtLogin; }
|
|
53
55
|
async function setAutoStart(enabled) {
|
|
54
|
-
if (process.platform === "
|
|
56
|
+
if (process.platform === "darwin") {
|
|
57
|
+
if (!enabled) { await rm(startupFile(), { force: true }); return; }
|
|
58
|
+
const content = macLaunchAgent({ executable: process.execPath, script: __filename, node: await nodeBinary(), dataDir, path: process.env.PATH });
|
|
59
|
+
await exec("/bin/launchctl", ["enable", `gui/${process.getuid()}/com.evandu.super-pi.desktop`]);
|
|
60
|
+
await mkdir(resolve(startupFile(), ".."), { recursive: true });
|
|
61
|
+
await writeFile(startupFile(), content, { mode: 0o600 });
|
|
62
|
+
} else if (process.platform === "linux") {
|
|
55
63
|
if (!enabled) { await rm(startupFile(), { force: true }); return; }
|
|
56
64
|
const quote = value => `"${String(value).replace(/[\\"$`]/g, "\\$&")}"`;
|
|
57
65
|
await mkdir(resolve(startupFile(), ".."), { recursive: true });
|
|
@@ -62,7 +70,8 @@ function show() { if (mainWindow?.isMinimized()) mainWindow.restore(); mainWindo
|
|
|
62
70
|
function external(url) { try { const parsed = new URL(url); if (["http:", "https:", "mailto:"].includes(parsed.protocol) && !parsed.username && !parsed.password) void shell.openExternal(parsed.href); } catch {} }
|
|
63
71
|
async function createWindow() {
|
|
64
72
|
const image = nativeImage.createFromPath(join(__dirname, "icon.png"));
|
|
65
|
-
|
|
73
|
+
if (process.platform === "darwin") app.dock?.setIcon(image);
|
|
74
|
+
mainWindow = new BrowserWindow({ title: "Super Pi", width: 1500, height: 980, minWidth: 800, minHeight: 560, show: false, icon: image, titleBarStyle: process.platform === "darwin" ? "hiddenInset" : "hidden", titleBarOverlay: process.platform === "darwin" ? undefined : { height: 38 }, trafficLightPosition: process.platform === "darwin" ? { x: 14, y: 12 } : undefined, autoHideMenuBar: true, webPreferences: { preload: join(__dirname, "preload.cjs"), contextIsolation: true, nodeIntegration: false, sandbox: true, webSecurity: true, backgroundThrottling: false } });
|
|
66
75
|
mainWindow.on("close", event => { if (!quitting) { event.preventDefault(); mainWindow.hide(); } });
|
|
67
76
|
mainWindow.webContents.on("will-navigate", (event, url) => { if (!url.startsWith(`${origin}/`)) { event.preventDefault(); external(url); } });
|
|
68
77
|
mainWindow.webContents.on("will-attach-webview", event => event.preventDefault());
|
|
@@ -71,12 +80,23 @@ async function createWindow() {
|
|
|
71
80
|
external(url); return { action: "deny" };
|
|
72
81
|
});
|
|
73
82
|
mainWindow.on("app-command", (_event, command) => { if (["browser-backward", "browser-forward"].includes(command)) { const keyCode = command === "browser-backward" ? "Left" : "Right"; mainWindow.webContents.sendInputEvent({ type: "keyDown", keyCode, modifiers: ["alt"] }); mainWindow.webContents.sendInputEvent({ type: "keyUp", keyCode, modifiers: ["alt"] }); } });
|
|
74
|
-
ipcMain.handle("super-pi-desktop:status", async event => { trusted(event); return { desktop: true, platform: process.platform, autoStart: await autoStartStatus(), origin, ownsServer }; });
|
|
83
|
+
ipcMain.handle("super-pi-desktop:status", async event => { trusted(event); return { desktop: true, platform: process.platform, autoStart: await autoStartStatus(), origin, ownsServer, frameTheme, backgroundColor: mainWindow.getBackgroundColor() }; });
|
|
84
|
+
ipcMain.handle("super-pi-desktop:theme", (event, value) => {
|
|
85
|
+
trusted(event);
|
|
86
|
+
if (!value || !/^#[a-f0-9]{6}$/i.test(value.background) || !/^#[a-f0-9]{6}$/i.test(value.foreground) || typeof value.dark !== "boolean") throw new Error("窗口主题参数无效");
|
|
87
|
+
nativeTheme.themeSource = value.dark ? "dark" : "light";
|
|
88
|
+
mainWindow.setBackgroundColor(value.background);
|
|
89
|
+
if (process.platform !== "darwin") mainWindow.setTitleBarOverlay({ color: value.background, symbolColor: value.foreground, height: 38 });
|
|
90
|
+
frameTheme = { background: value.background, foreground: value.foreground, dark: value.dark };
|
|
91
|
+
return { platform: process.platform, icon: image.resize({ width: 48, height: 48 }).toDataURL() };
|
|
92
|
+
});
|
|
75
93
|
ipcMain.handle("super-pi-desktop:autostart", async (event, enabled) => { trusted(event); await setAutoStart(enabled === true); return { autoStart: await autoStartStatus() }; });
|
|
76
94
|
ipcMain.handle("super-pi-desktop:browser", event => { trusted(event); external(origin); });
|
|
77
95
|
ipcMain.handle("super-pi-desktop:minimize", event => { trusted(event); mainWindow.hide(); });
|
|
78
96
|
const trayMenu = Menu.buildFromTemplate([{ label: "打开 Super Pi", click: show }, { label: "在浏览器打开", click: () => external(origin) }, { type: "separator" }, { label: "退出 Super Pi", click: () => app.quit() }]);
|
|
79
|
-
|
|
97
|
+
const trayImage = process.platform === "darwin" ? nativeImage.createFromPath(join(__dirname, "tray-icon.png")).resize({ width: 20, height: 20 }) : image.resize({ width: 24, height: 24 });
|
|
98
|
+
if (process.platform === "darwin") trayImage.setTemplateImage(true);
|
|
99
|
+
tray = new Tray(trayImage); tray.setToolTip("Super Pi · 本地管理服务运行中"); tray.setContextMenu(trayMenu); tray.on("double-click", show); tray.on("click", show);
|
|
80
100
|
Menu.setApplicationMenu(Menu.buildFromTemplate([{ label: "Super Pi", submenu: [{ label: "在浏览器打开", click: () => external(origin) }, { label: "隐藏到托盘", click: () => mainWindow.hide() }, { type: "separator" }, { role: "quit", label: "退出 Super Pi" }] }, { role: "editMenu", label: "编辑" }, { role: "viewMenu", label: "视图" }, { role: "windowMenu", label: "窗口" }]));
|
|
81
101
|
await mainWindow.loadURL(origin);
|
|
82
102
|
if (!process.argv.includes("--hidden")) show();
|
package/desktop/preload.cjs
CHANGED
|
@@ -6,4 +6,23 @@ if (process.isMainFrame) {
|
|
|
6
6
|
openBrowser: () => ipcRenderer.invoke("super-pi-desktop:browser"),
|
|
7
7
|
minimize: () => ipcRenderer.invoke("super-pi-desktop:minimize"),
|
|
8
8
|
}));
|
|
9
|
+
window.addEventListener("DOMContentLoaded", () => {
|
|
10
|
+
const root = document.documentElement;
|
|
11
|
+
root.dataset.superPiDesktop = "true";
|
|
12
|
+
const style = document.createElement("style");
|
|
13
|
+
style.textContent = `html[data-super-pi-desktop] body {box-sizing:border-box;padding-top:38px;}html[data-super-pi-desktop] #root {height:calc(100dvh - 38px);}html[data-super-pi-desktop] #root > .shell {height:100%;min-height:0;}#super-pi-desktop-titlebar {position:fixed;inset:0 0 auto;height:38px;box-sizing:border-box;display:flex;align-items:center;gap:8px;padding:0 150px 0 14px;background:var(--bg-panel);color:var(--text-secondary);border-bottom:1px solid var(--border-subtle);font:500 12px system-ui;user-select:none;-webkit-app-region:drag;z-index:1000;}#super-pi-desktop-titlebar[data-platform=darwin]{padding-left:84px;padding-right:14px;}#super-pi-desktop-titlebar img {width:20px;height:20px;pointer-events:none;}#super-pi-desktop-titlebar img:not([src]) {visibility:hidden;}`;
|
|
14
|
+
document.head.append(style);
|
|
15
|
+
const bar = document.createElement("div"); bar.id = "super-pi-desktop-titlebar"; bar.setAttribute("aria-label", "Super Pi 窗口标题栏");
|
|
16
|
+
const icon = document.createElement("img"); icon.alt = ""; const title = document.createElement("span"); title.textContent = "Super Pi"; bar.append(icon, title); document.body.prepend(bar);
|
|
17
|
+
const pixel = document.createElement("canvas"); pixel.width = pixel.height = 1; const context = pixel.getContext("2d");
|
|
18
|
+
const color = value => { context.clearRect(0, 0, 1, 1); context.fillStyle = value; context.fillRect(0, 0, 1, 1); return "#" + [...context.getImageData(0, 0, 1, 1).data].slice(0, 3).map(value => value.toString(16).padStart(2, "0")).join(""); };
|
|
19
|
+
const sync = () => {
|
|
20
|
+
const theme = getComputedStyle(root), background = color(theme.getPropertyValue("--bg-panel")), foreground = color(theme.getPropertyValue("--text-primary"));
|
|
21
|
+
const rgb = background.slice(1).match(/../g).map(value => parseInt(value, 16));
|
|
22
|
+
const dark = (rgb[0] * .2126 + rgb[1] * .7152 + rgb[2] * .0722) < 128;
|
|
23
|
+
void ipcRenderer.invoke("super-pi-desktop:theme", { background, foreground, dark }).then(value => { bar.dataset.platform = value.platform; icon.src = value.icon; }).catch(() => {});
|
|
24
|
+
};
|
|
25
|
+
new MutationObserver(sync).observe(root, { attributes: true, attributeFilter: ["data-theme"] });
|
|
26
|
+
sync();
|
|
27
|
+
}, { once: true });
|
|
9
28
|
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
const fs = require("node:fs/promises");
|
|
2
|
+
const { existsSync } = require("node:fs");
|
|
3
|
+
const { join, dirname, resolve, sep } = require("node:path");
|
|
4
|
+
const { homedir } = require("node:os");
|
|
5
|
+
|
|
6
|
+
const delay = ms => new Promise(done => setTimeout(done, ms));
|
|
7
|
+
const executableFor = platform => platform === "darwin" ? "Electron.app/Contents/MacOS/Electron" : platform === "win32" ? "electron.exe" : "electron";
|
|
8
|
+
function runtimeSources(version, platform, arch, env = process.env) {
|
|
9
|
+
const file = `electron-v${version}-${platform}-${arch}.zip`;
|
|
10
|
+
const configured = env.ELECTRON_MIRROR || env.npm_config_electron_mirror;
|
|
11
|
+
const sources = [];
|
|
12
|
+
if (configured) {
|
|
13
|
+
const directory = (env.ELECTRON_CUSTOM_DIR || env.npm_config_electron_custom_dir || `v${version}`).replaceAll("{{ version }}", version);
|
|
14
|
+
sources.push({ name: "已配置下载源", url: `${configured.replace(/\/$/, "")}/${directory}/${file}` });
|
|
15
|
+
}
|
|
16
|
+
sources.push({ name: "Electron 官方源", url: `https://github.com/electron/electron/releases/download/v${version}/${file}` });
|
|
17
|
+
sources.push({ name: "Electron 国内镜像", url: `https://npmmirror.com/mirrors/electron/${version}/${file}` });
|
|
18
|
+
return sources.filter((source, index) => sources.findIndex(item => item.url === source.url) === index);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Alternate sources still use the official checksums pinned by the Electron dependency. */
|
|
22
|
+
async function ensureDesktopRuntime(options = {}) {
|
|
23
|
+
const metadataPath = require.resolve("electron/package.json");
|
|
24
|
+
const metadata = options.metadata || JSON.parse(await fs.readFile(metadataPath, "utf8"));
|
|
25
|
+
const { downloadArtifact, getHostArch, initializeProxy } = require("@electron/get");
|
|
26
|
+
const { extract } = require("@electron-internal/extract-zip");
|
|
27
|
+
if (process.env.HTTP_PROXY || process.env.HTTPS_PROXY || process.env.http_proxy || process.env.https_proxy) initializeProxy();
|
|
28
|
+
const version = metadata.version, platform = options.platform || process.platform, arch = options.arch || getHostArch();
|
|
29
|
+
if (!/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(version) || !["darwin", "win32", "linux"].includes(platform) || !["x64", "arm64"].includes(arch)) throw new Error("此系统或 CPU 架构暂不支持桌面运行时");
|
|
30
|
+
const binary = executableFor(platform), dependencyRoot = dirname(metadataPath);
|
|
31
|
+
if (!options.metadata && !options.root && !process.env.SUPER_PI_DESKTOP_RUNTIME_DIR) {
|
|
32
|
+
try {
|
|
33
|
+
if ((await fs.readFile(join(dependencyRoot, "dist", "version"), "utf8")).trim().replace(/^v/, "") === version && (await fs.readFile(join(dependencyRoot, "path.txt"), "utf8")).trim() === binary && existsSync(join(dependencyRoot, "dist", binary))) return join(dependencyRoot, "dist", binary);
|
|
34
|
+
} catch { /* Missing dependency-side binaries are normal on the first launch. */ }
|
|
35
|
+
}
|
|
36
|
+
const root = resolve(options.root || process.env.SUPER_PI_DESKTOP_RUNTIME_DIR || join(process.env.SUPER_PI_DATA_DIR || join(homedir(), ".super-pi"), "desktop", "runtimes"));
|
|
37
|
+
const key = `${version}-${platform}-${arch}`, target = join(root, key), lock = join(root, `${key}.lock`);
|
|
38
|
+
const log = options.log || console.log;
|
|
39
|
+
const ready = async () => {
|
|
40
|
+
try { const marker = JSON.parse(await fs.readFile(join(target, ".super-pi-runtime.json"), "utf8")); return marker.version === version && marker.platform === platform && marker.arch === arch && existsSync(join(target, binary)); } catch { return false; }
|
|
41
|
+
};
|
|
42
|
+
if (await ready()) return join(target, binary);
|
|
43
|
+
await fs.mkdir(root, { recursive: true });
|
|
44
|
+
const removeOwned = async path => {
|
|
45
|
+
if (!resolve(path).startsWith(root + sep)) throw new Error("拒绝清理运行时缓存以外的路径");
|
|
46
|
+
await fs.rm(path, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 });
|
|
47
|
+
};
|
|
48
|
+
const deadline = Date.now() + 20 * 60_000;
|
|
49
|
+
let waiting = false;
|
|
50
|
+
for (;;) {
|
|
51
|
+
try { await fs.mkdir(lock); await fs.writeFile(join(lock, "owner.json"), JSON.stringify({ pid: process.pid })); break; }
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error.code !== "EEXIST") throw error;
|
|
54
|
+
if (await ready()) return join(target, binary);
|
|
55
|
+
try { const owner = JSON.parse(await fs.readFile(join(lock, "owner.json"), "utf8")); try { process.kill(owner.pid, 0); } catch (error) { if (error.code === "ESRCH") { await removeOwned(lock); continue; } } }
|
|
56
|
+
catch { if (Date.now() - (await fs.stat(lock).catch(() => ({ mtimeMs: Date.now() }))).mtimeMs > 30_000) { await removeOwned(lock); continue; } }
|
|
57
|
+
if (Date.now() > deadline) throw new Error("另一个桌面启动仍在准备运行时,请稍后重新运行 super_pi desktop");
|
|
58
|
+
if (!waiting) { waiting = true; log("另一个启动正在准备桌面运行时,正在等待…"); }
|
|
59
|
+
await delay(500);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
let stage;
|
|
63
|
+
try {
|
|
64
|
+
if (await ready()) return join(target, binary);
|
|
65
|
+
log(`正在准备 Super Pi 桌面运行时 · ${platform}/${arch} · Electron ${version}`);
|
|
66
|
+
const checksums = options.checksums || JSON.parse(await fs.readFile(join(dependencyRoot, "checksums.json"), "utf8"));
|
|
67
|
+
let sources = options.sources || runtimeSources(version, platform, arch);
|
|
68
|
+
if (!options.sources && !process.env.ELECTRON_MIRROR && !process.env.npm_config_electron_mirror) {
|
|
69
|
+
const reachable = await Promise.all(sources.map(async source => { try { return (await fetch(source.url, { method: "HEAD", signal: AbortSignal.timeout(6000) })).ok; } catch { return false; } }));
|
|
70
|
+
sources = [...sources.filter((_, index) => reachable[index]), ...sources.filter((_, index) => !reachable[index])];
|
|
71
|
+
}
|
|
72
|
+
let archive;
|
|
73
|
+
for (const source of sources) {
|
|
74
|
+
for (let attempt = 1; attempt <= 2; attempt++) {
|
|
75
|
+
const abort = new AbortController(), total = setTimeout(() => abort.abort(), options.timeoutMs || 10 * 60_000);
|
|
76
|
+
let idle = setTimeout(() => abort.abort(), options.idleTimeoutMs || 45_000), lastProgress = 0;
|
|
77
|
+
log(`正在下载 · ${source.name}(${attempt}/2)`);
|
|
78
|
+
try {
|
|
79
|
+
archive = await downloadArtifact({ version, platform, arch, artifactName: "electron", checksums, cacheRoot: join(root, "downloads"), mirrorOptions: { resolveAssetURL: async () => source.url }, downloadOptions: { quiet: true, signal: abort.signal, getProgressCallback: ({ transferred, total: bytes }) => {
|
|
80
|
+
clearTimeout(idle); idle = setTimeout(() => abort.abort(), options.idleTimeoutMs || 45_000);
|
|
81
|
+
if (Date.now() - lastProgress > 5000 || transferred === bytes) { lastProgress = Date.now(); log(`桌面运行时 · 已下载 ${Math.round(transferred / 1024 / 1024)} MB${bytes ? ` / ${Math.round(bytes / 1024 / 1024)} MB` : ""}`); }
|
|
82
|
+
} } });
|
|
83
|
+
break;
|
|
84
|
+
} catch (error) {
|
|
85
|
+
const code = error.code || error.cause?.code || error.name || "NETWORK_ERROR";
|
|
86
|
+
log(`${source.name}未完成(${code}),${attempt < 2 ? "正在自动重试" : "正在自动切换下载源"}…`);
|
|
87
|
+
if (attempt < 2) await delay(options.retryDelayMs ?? 1000);
|
|
88
|
+
} finally { clearTimeout(total); clearTimeout(idle); }
|
|
89
|
+
}
|
|
90
|
+
if (archive) break;
|
|
91
|
+
}
|
|
92
|
+
if (!archive) throw new Error("桌面运行时下载失败,已自动尝试备用源。Super Pi 已正确安装,浏览器服务仍可使用;稍后重新运行 super_pi desktop 将继续准备,无需重装或手动配置镜像。");
|
|
93
|
+
log("校验已通过,正在安装桌面运行时…");
|
|
94
|
+
stage = await fs.mkdtemp(join(root, `${key}-install-`));
|
|
95
|
+
await extract(archive, { dir: stage });
|
|
96
|
+
await fs.access(join(stage, binary));
|
|
97
|
+
await fs.writeFile(join(stage, ".super-pi-runtime.json"), JSON.stringify({ version, platform, arch }));
|
|
98
|
+
await removeOwned(target);
|
|
99
|
+
await fs.rename(stage, target); stage = undefined;
|
|
100
|
+
log("桌面运行时已就绪,正在打开 Super Pi…");
|
|
101
|
+
return join(target, binary);
|
|
102
|
+
} finally {
|
|
103
|
+
if (stage) await removeOwned(stage);
|
|
104
|
+
await removeOwned(lock);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
module.exports = { ensureDesktopRuntime, runtimeSources, executableFor };
|
|
Binary file
|
|
Binary file
|
package/desktop/tray.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256" style="--brand-mark:#000000"><g fill="none" stroke="var(--brand-mark)" stroke-width="20" stroke-linecap="round" stroke-linejoin="round"><path d="M52 72h152"/><path d="M98 75v58c0 23-6 40-19 57"/><path d="M164 75v82c0 20 10 28 29 28h5"/></g></svg>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"hash": "
|
|
2
|
+
"hash": "a7eb6cc6b70c71e886ab1c624edb90d78ad7c7a280dcab3cd37d7379c0927f17",
|
|
3
3
|
"files": {
|
|
4
4
|
"src/client/App.tsx": "f3dc490797eddd9dff9d20e6b4599127e136b25830f13e6e21b912b49281b3d3",
|
|
5
5
|
"src/client/CacheWarmingSettings.tsx": "cce26c4547634b76c08c681a4b9605f884d8502f554f12ff8c30cbd2fd0bd9c0",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"src/client/HelpWindow.tsx": "dd4767f4cdced2fcdb50769eb5417ef8de722f43bbd594c9854f49fe61d15d97",
|
|
18
18
|
"src/client/KnowledgeFilePicker.tsx": "82bdd65e8a624276abd5a7530ef47f86a5f9b7649b464080638055991f6278cf",
|
|
19
19
|
"src/client/KnowledgePanel.tsx": "1e64ee6f9d29456ab9470424def8269cc9b3935e3b8ba674739ce5a6cb7db56d",
|
|
20
|
-
"src/client/ManagedServersPanel.tsx": "
|
|
20
|
+
"src/client/ManagedServersPanel.tsx": "14725f22f2bf95c5c8bdf7f68cd10057351e792da5b8eb5bf0e2bc318f9e64e9",
|
|
21
21
|
"src/client/MarkdownSyntaxSettings.tsx": "9124d02956a4d70e2607fc584b226f8a82764b613015958fe117159d0cbf78e1",
|
|
22
22
|
"src/client/MarkdownView.tsx": "c52e63bddd2275573731166375275caf80f3327a3b4a2aff07d14aecfda00b8e",
|
|
23
23
|
"src/client/MathView.tsx": "f322a430b93594dd625b4c699994574f81d9bac72fa49b904505ca6e9e3dcb93",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"src/client/SidebarSection.tsx": "579c014caeddd94d21911d7b9eca4ceef930ca13c2baeb7bf5ffba59c2bb0b75",
|
|
32
32
|
"src/client/SlashCommandMenu.tsx": "8b2319da03b55827865fb9b6646f7a820aa26cc460cceeed9fb7edb20ad9ebb7",
|
|
33
33
|
"src/client/SoftwareUpdate.tsx": "5ded9a91f0387be96a56228bd02aaf3673821feba28cb74b3493cd1f432f49e1",
|
|
34
|
+
"src/client/SshVerificationForm.tsx": "8d7968822203e2404742f9fb6dde24656c97541628999e1d8cd34c8652c1c23e",
|
|
34
35
|
"src/client/Tabs.tsx": "a6a853b0752f5a96f451de502669fbb7ad4b5c141cb3f6a9cd3b9746797b5649",
|
|
35
36
|
"src/client/TavilyPanel.css": "22d4fb4a1bc95b2e0a96c49b9650a56f1a6cf7cfc3c6bc68564417d2c268e193",
|
|
36
37
|
"src/client/TavilyPanel.tsx": "c60ffea2bf89811503408f4d32eb9419c65f401275d31c047b2bd36e0df42251",
|
|
@@ -61,15 +62,15 @@
|
|
|
61
62
|
"src/client/pending-operations.ts": "8a5f9e9711c0f875c8ed194196c218162de5270298dad4091351d41294c859d7",
|
|
62
63
|
"src/client/project-evidence.ts": "3bc5ea85f6b20a19a36cfdd4a958d83dd53b21f3d8f20fae1914a575dfbad3c4",
|
|
63
64
|
"src/client/reader-recovery.ts": "20030e65dce38d06bcc65d13cbe451e87dcee9c10cae7cdb7c056e5407f77849",
|
|
64
|
-
"src/client/server-connections.ts": "
|
|
65
|
+
"src/client/server-connections.ts": "660d29088664cb9756f45553335607a0de1f774eaf46871ebcdc4b37847c258c",
|
|
65
66
|
"src/client/server-scope.ts": "8edad8ebe6f35179584c3d2627304f394dd40e6dd83881d7edaf386ff46243cc",
|
|
66
67
|
"src/client/session-tree.ts": "08a14c6611fdd9a72001eb1672060479e7660de5a5d221c7e80036209fd26546",
|
|
67
68
|
"src/client/slash-commands.ts": "4a2cef1eb9517628eadfdc38bca7e3663e4d48090d8b87a8a79de4bfd586e112",
|
|
68
69
|
"src/client/software-update.css": "a4ec1565b70008b55618197a8d88db51a79fb932b9a69bfe4318a62774e8020a",
|
|
69
|
-
"src/client/styles.css": "
|
|
70
|
+
"src/client/styles.css": "47099ff0f5c233836ae279e33f2c6973411428c9709ea1171f8492cd55269cc4",
|
|
70
71
|
"src/client/system-notifications.ts": "36dccbda2d831812d34af7217778a7a3596b184dfc2b39e0d5a0207a1a7eebd0",
|
|
71
72
|
"src/client/terminal-emulator.ts": "ffcc4f5fbddaf25cebcc9e03dbe5d7d0ad2c21586f5d169e57c04c82e2308b3b",
|
|
72
|
-
"src/client/theme.tsx": "
|
|
73
|
+
"src/client/theme.tsx": "6cd1fce371635b73e76dc4c163c362d538c643c94037188365d42401fe08ba55",
|
|
73
74
|
"src/client/tool-launcher.ts": "9699c9498c905e395bbe89e0e367721ab253b5ec1e318a8093ce6a88c2ff5c29",
|
|
74
75
|
"src/client/tool-sharing.ts": "011212825dbbffe18c8f15aca721c02938ab6273fb5607b072a1e7b8b1853640",
|
|
75
76
|
"src/client/tool-shortcuts.ts": "4422d29ba770af6acef18e66c6be05a9bc021f7323c7ca28bbe7668f26d4adb8",
|
|
@@ -78,5 +79,5 @@
|
|
|
78
79
|
"src/client/vite-env.d.ts": "65996936fbb042915f7b74a200fcdde7e410f32a669b1ab9597cfaa4b0faddb5",
|
|
79
80
|
"src/client/workbench-navigation.ts": "3b229752a8ce4a45eba7aeff040eb33001413190141f1e9b8e5f38246a1761e2"
|
|
80
81
|
},
|
|
81
|
-
"recordedAt": "2026-11-
|
|
82
|
+
"recordedAt": "2026-11-20T05:17:54.696Z"
|
|
82
83
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-J6XWqRpB.js","assets/rolldown-runtime-XKyaHtl9.js","assets/dist-D978o95T.js","assets/dist-B3-a6uF0.js","assets/dist-Cus6_oaF.js","assets/dist-Dc1MBGAG.js","assets/dist-BXAOrsjq.js","assets/dist-Cx00EZKR.js","assets/dist-moiMRpw_.js","assets/dist-Dds-qLxY.js","assets/dist-AW5lyI3I.js","assets/dist-BGxkyh6e.js","assets/dist-CKF2Jksy.js","assets/dist-BV64A9Ji.js","assets/dist-Dvb0SqcK.js","assets/dist-D71y2EI1.js","assets/dist-DeD9copn.js","assets/dist-QzbOCAU6.js","assets/dist-DuvGReu-.js","assets/dist-BRVQKlcp.js","assets/dist-BJxfd7yb.js","assets/dist-CX_Hm4GS.js","assets/dist-scBkrwv-.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{c as t,l as n,n as r,r as i,t as a}from"./index-Cn7hdrDw.js";var o=e(n(),1);async function s(e,t){let[{StreamLanguage:n},r]=await Promise.all([i(()=>import(`./dist-J6XWqRpB.js`).then(e=>e.d),__vite__mapDeps([0,1,2,3,4])),e()]),a=r[t]??r.default??r;return n.define(a)}var c={cpp:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),cc:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),cxx:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),hpp:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),hh:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),hxx:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),c:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),h:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),cu:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),cuh:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),js:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,1,2,3,4,0,6,8])),jsx:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({jsx:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),mjs:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,1,2,3,4,0,6,8])),cjs:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,1,2,3,4,0,6,8])),ts:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),tsx:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0,jsx:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),mts:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),cts:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),py:()=>i(()=>import(`./dist-Dds-qLxY.js`).then(e=>e.python()),__vite__mapDeps([9,4,1,0,2,3,6,8])),pyi:()=>i(()=>import(`./dist-Dds-qLxY.js`).then(e=>e.python()),__vite__mapDeps([9,4,1,0,2,3,6,8])),java:()=>i(()=>import(`./dist-AW5lyI3I.js`).then(e=>e.java()),__vite__mapDeps([10,4,1,0,2,3,6])),php:()=>i(()=>import(`./dist-BGxkyh6e.js`).then(e=>e.php()),__vite__mapDeps([11,4,1,0,2,3,6,12,13,7,8])),sql:()=>i(()=>import(`./dist-Dvb0SqcK.js`).then(e=>e.sql()),__vite__mapDeps([14,4,1,0,2,3,6,8])),yaml:()=>i(()=>import(`./dist-D71y2EI1.js`).then(e=>e.yaml()),__vite__mapDeps([15,4,1,0,2,3,6])),yml:()=>i(()=>import(`./dist-D71y2EI1.js`).then(e=>e.yaml()),__vite__mapDeps([15,4,1,0,2,3,6])),xml:()=>i(()=>import(`./dist-DeD9copn.js`).then(e=>e.xml()),__vite__mapDeps([16,2,1,3,4,0,6])),json:()=>i(()=>import(`./dist-QzbOCAU6.js`).then(e=>e.json()),__vite__mapDeps([17,4,1,0,2,3,6])),jsonc:()=>i(()=>import(`./dist-QzbOCAU6.js`).then(e=>e.json()),__vite__mapDeps([17,4,1,0,2,3,6])),json5:()=>i(()=>import(`./dist-QzbOCAU6.js`).then(e=>e.json()),__vite__mapDeps([17,4,1,0,2,3,6])),html:()=>i(()=>import(`./dist-CKF2Jksy.js`).then(e=>e.html()),__vite__mapDeps([12,2,1,3,4,0,6,13,7,8])),htm:()=>i(()=>import(`./dist-CKF2Jksy.js`).then(e=>e.html()),__vite__mapDeps([12,2,1,3,4,0,6,13,7,8])),vue:()=>i(()=>import(`./dist-CKF2Jksy.js`).then(e=>e.html()),__vite__mapDeps([12,2,1,3,4,0,6,13,7,8])),svelte:()=>i(()=>import(`./dist-CKF2Jksy.js`).then(e=>e.html()),__vite__mapDeps([12,2,1,3,4,0,6,13,7,8])),css:()=>i(()=>import(`./dist-BV64A9Ji.js`).then(e=>e.r).then(e=>e.css()),__vite__mapDeps([13,1,4,0,2,3,6])),md:()=>i(()=>import(`./dist-DuvGReu-.js`).then(e=>e.markdown()),__vite__mapDeps([18,2,1,3,4,0,8,12,6,13,7])),markdown:()=>i(()=>import(`./dist-DuvGReu-.js`).then(e=>e.markdown()),__vite__mapDeps([18,2,1,3,4,0,8,12,6,13,7])),mdx:()=>i(()=>import(`./dist-DuvGReu-.js`).then(e=>e.markdown()),__vite__mapDeps([18,2,1,3,4,0,8,12,6,13,7])),rs:()=>i(()=>import(`./dist-BRVQKlcp.js`).then(e=>e.rust()),__vite__mapDeps([19,4,1,0,2,3,6])),go:()=>i(()=>import(`./dist-BJxfd7yb.js`).then(e=>e.go()),__vite__mapDeps([20,4,1,0,2,3,6,8])),sh:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),bash:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),zsh:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),fish:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),ps1:()=>s(()=>i(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),psm1:()=>s(()=>i(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),rb:()=>s(()=>i(()=>import(`./ruby-ChfNwlCY.js`),[]),`ruby`),swift:()=>s(()=>i(()=>import(`./swift-DKB6_1j6.js`),[]),`swift`),toml:()=>s(()=>i(()=>import(`./toml-BPTmHmyx.js`),[]),`toml`),ini:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),cfg:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),conf:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),properties:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),dockerfile:()=>s(()=>i(()=>import(`./dockerfile-BDePf5PZ.js`),[]),`dockerfile`),diff:()=>s(()=>i(()=>import(`./diff-ChtP43wD.js`),[]),`diff`),patch:()=>s(()=>i(()=>import(`./diff-ChtP43wD.js`),[]),`diff`)},l={cpp:`C++`,cc:`C++`,cxx:`C++`,hpp:`C++`,hh:`C++`,hxx:`C++`,cu:`CUDA C++`,cuh:`CUDA C++`,c:`C`,h:`C/C++ Header`,js:`JavaScript`,jsx:`JSX`,mjs:`JavaScript`,cjs:`JavaScript`,ts:`TypeScript`,tsx:`TSX`,mts:`TypeScript`,cts:`TypeScript`,py:`Python`,pyi:`Python Stub`,java:`Java`,php:`PHP`,sql:`SQL`,yaml:`YAML`,yml:`YAML`,xml:`XML`,json:`JSON`,jsonc:`JSON with Comments`,json5:`JSON5`,css:`CSS`,md:`Markdown`,markdown:`Markdown`,mdx:`MDX`,rs:`Rust`,go:`Go`,html:`HTML`,htm:`HTML`,vue:`Vue`,svelte:`Svelte`,sh:`Shell`,bash:`Bash`,zsh:`Zsh`,fish:`Fish`,ps1:`PowerShell`,psm1:`PowerShell`,rb:`Ruby`,swift:`Swift`,toml:`TOML`,ini:`INI`,cfg:`Config`,conf:`Config`,properties:`Properties`,dockerfile:`Dockerfile`,diff:`Diff`,patch:`Patch`};function u(e){return c[e.toLowerCase()]}function d(e){return l[e.toLowerCase()]}var f=t(),p=262144,m=131072;function h(e){return e.split(`.`).pop()?.toLowerCase()??``}function g(e){return getComputedStyle(document.documentElement).getPropertyValue(e).trim()}function _(e,t){return e.HighlightStyle.define([{tag:t.tags.keyword,color:g(`--cm-keyword`)},{tag:t.tags.string,color:g(`--cm-string`)},{tag:t.tags.number,color:g(`--cm-number`)},{tag:t.tags.comment,color:g(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:g(`--cm-function`)},{tag:t.tags.typeName,color:g(`--cm-type`)},{tag:t.tags.className,color:g(`--cm-type`)},{tag:t.tags.propertyName,color:g(`--cm-property`)},{tag:t.tags.operator,color:g(`--cm-operator`)},{tag:t.tags.variableName,color:g(`--cm-variable`)}])}function v({path:e,value:t,onChange:n,jumpToLine:s,onSave:c,workspaceId:l,blame:g,onPosition:v,readOnly:y=!1}){let b=(0,o.useRef)(null),x=(0,o.useRef)(null),S=(0,o.useRef)(null),C=(0,o.useRef)(null),w=(0,o.useRef)(null),T=(0,o.useRef)(null),E=(0,o.useRef)(null),D=(0,o.useRef)(null),O=(0,o.useRef)(n),k=(0,o.useRef)(c);O.current=n,k.current=c;let[A,j]=(0,o.useState)(!1),[M,N]=(0,o.useState)(!1),[P,F]=(0,o.useState)(`0,0`),[I,L]=(0,o.useState)(0);(0,o.useEffect)(()=>{let n=!1,a,o,s,c,l;return(async()=>{try{let d=h(e),f=u(d),[m,g,v,A,M,P,I,R]=await Promise.all([i(()=>import(`./dist-D978o95T.js`).then(e=>e.S),__vite__mapDeps([2,1])),i(()=>import(`./dist-B3-a6uF0.js`).then(e=>e.s),__vite__mapDeps([3,1,2])),i(()=>import(`./dist-CX_Hm4GS.js`),__vite__mapDeps([21,2,1,3,4,0])),i(()=>import(`./dist-scBkrwv-.js`),__vite__mapDeps([22,2,1,3])),i(()=>import(`./dist-J6XWqRpB.js`).then(e=>e.d),__vite__mapDeps([0,1,2,3,4])),i(()=>import(`./dist-Cus6_oaF.js`).then(e=>e.n),__vite__mapDeps([4,1])),f?f().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${d}:`,e),null)):Promise.resolve(null),r().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null))]);if(n||!b.current)return;c=M,l=P,C.current=m.Annotation.define(),w.current=m.Transaction.addToHistory;let z=t.length<=p&&I!==null;o=new m.Compartment;let B=[g.lineNumbers(),g.highlightActiveLine(),g.drawSelection(),v.history(),g.keymap.of([v.indentWithTab,...v.defaultKeymap,...v.historyKeymap,...A.searchKeymap,{key:`Mod-s`,run:()=>(k.current(),!0)}]),g.EditorView.updateListener.of(e=>{e.docChanged&&!(C.current&&e.transactions.some(e=>e.annotation(C.current)===!0))&&O.current(e.state.doc.toString()),e.selectionSet&&F(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),g.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(y&&B.push(m.EditorState.readOnly.of(!0),g.EditorView.editable.of(!1)),R&&!y&&(s=new m.Compartment,B.splice(1,0,s.of([])),B.push(R.base)),I)try{B.push(I)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${d}:`,e),z=!1}if(z&&o&&c&&l)try{B.push(o.of(c.syntaxHighlighting(_(c,l))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${d}:`,e),z=!1}if(a=new g.EditorView({state:m.EditorState.create({doc:t,extensions:B}),parent:b.current}),n){a.destroy();return}x.current=a,j(z),N(!0),T.current=R,E.current=s??null,D.current=null,L(e=>e+1);let V=new MutationObserver(()=>{let e=x.current;if(e&&z&&o&&c&&l)try{e.dispatch({effects:o.reconfigure(c.syntaxHighlighting(_(c,l)))})}catch{}});S.current=V,V.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),n||N(!0)}})(),()=>{n=!0,S.current?.disconnect(),S.current=null,a?.destroy(),x.current=null,N(!1),b.current&&(b.current.textContent=``)}},[e,y]),(0,o.useEffect)(()=>{let e=x.current;if(!e)return;let n=e.state.doc.toString();n!==t&&e.dispatch({changes:{from:0,to:n.length,insert:t},annotations:C.current?C.current.of(!0):void 0})},[t]),(0,o.useEffect)(()=>{let e=x.current;if(!e||!s)return;let t=e.state.doc.line(Math.min(Math.max(1,s.line),e.state.doc.lines)),n=Math.min(t.to,t.from+(s.column??1)-1);e.dispatch({selection:{anchor:t.to,head:n},scrollIntoView:!0}),e.focus()},[s,M]);let R=!!(g&&g.state===`ready`&&g.response&&g.path===e&&g.workspaceId===l);(0,o.useEffect)(()=>{let t=x.current,n=T.current,r=E.current;if(!t||!n||!r)return;let i=g&&g.state===`ready`&&g.response&&g.path===e&&g.workspaceId===l?g.response:null,o=i?a(i):null;D.current!==o&&(D.current=o,t.dispatch({effects:[n.setBlame.of(o),r.reconfigure(o?n.gutter:[])]}))},[g?.state,g?.response,g?.path,g?.workspaceId,e,l,I]);let z=x.current?.state.doc.toString()??t,B=z.length<=m?z:z.slice(0,m),V=h(e),H=d(V),U=x.current?.state,W=U?.selection.main.head,G=W===void 0?void 0:U?.doc.lineAt(W),K=G?.number,q=W!==void 0&&G?W-G.from+1:void 0;return(0,o.useEffect)(()=>{M&&K!==void 0&&q!==void 0&&v?.({line:K,column:q,language:A&&H||`纯文本`,highlight:A?V:`plain`})},[M,K,q,A,H,V,v]),(0,o.useEffect)(()=>()=>v?.(),[v]),(0,f.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":B,"data-file-content-truncated":z.length>m?`1`:`0`,"data-file-selection":P,"data-file-editor-ready":M?`1`:`0`,"data-file-blame-gutter":R?`1`:void 0,onMouseDown:()=>x.current?.focus(),children:[(0,f.jsx)(`div`,{className:`file-cm`,ref:b,"aria-label":`${y?`查看`:`编辑`} ${e}`}),(!M||!v)&&(0,f.jsxs)(`div`,{className:`file-editor-status`,children:[!M&&(0,f.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),M&&W!==void 0&&G&&(0,f.jsxs)(`span`,{children:[`第 `,G.number,` 行,第 `,W-G.from+1,` 列`]}),M&&!A&&(0,f.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),M&&A&&H&&(0,f.jsx)(`span`,{"data-file-highlight-status":V,children:H})]})]})}export{v as CodeMirrorEditor,u as t,_ as themeHighlightStyle};
|
|
2
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{c as t,l as n,n as r,r as i,t as a}from"./index-BVn_-dwp.js";var o=e(n(),1);async function s(e,t){let[{StreamLanguage:n},r]=await Promise.all([i(()=>import(`./dist-J6XWqRpB.js`).then(e=>e.d),__vite__mapDeps([0,1,2,3,4])),e()]),a=r[t]??r.default??r;return n.define(a)}var c={cpp:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),cc:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),cxx:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),hpp:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),hh:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),hxx:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),c:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),h:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),cu:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),cuh:()=>i(()=>import(`./dist-Dc1MBGAG.js`).then(e=>e.cpp()),__vite__mapDeps([5,4,1,0,2,3,6])),js:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,1,2,3,4,0,6,8])),jsx:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({jsx:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),mjs:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,1,2,3,4,0,6,8])),cjs:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript()),__vite__mapDeps([7,1,2,3,4,0,6,8])),ts:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),tsx:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0,jsx:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),mts:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),cts:()=>i(()=>import(`./dist-Cx00EZKR.js`).then(e=>e.t).then(e=>e.javascript({typescript:!0})),__vite__mapDeps([7,1,2,3,4,0,6,8])),py:()=>i(()=>import(`./dist-Dds-qLxY.js`).then(e=>e.python()),__vite__mapDeps([9,4,1,0,2,3,6,8])),pyi:()=>i(()=>import(`./dist-Dds-qLxY.js`).then(e=>e.python()),__vite__mapDeps([9,4,1,0,2,3,6,8])),java:()=>i(()=>import(`./dist-AW5lyI3I.js`).then(e=>e.java()),__vite__mapDeps([10,4,1,0,2,3,6])),php:()=>i(()=>import(`./dist-BGxkyh6e.js`).then(e=>e.php()),__vite__mapDeps([11,4,1,0,2,3,6,12,13,7,8])),sql:()=>i(()=>import(`./dist-Dvb0SqcK.js`).then(e=>e.sql()),__vite__mapDeps([14,4,1,0,2,3,6,8])),yaml:()=>i(()=>import(`./dist-D71y2EI1.js`).then(e=>e.yaml()),__vite__mapDeps([15,4,1,0,2,3,6])),yml:()=>i(()=>import(`./dist-D71y2EI1.js`).then(e=>e.yaml()),__vite__mapDeps([15,4,1,0,2,3,6])),xml:()=>i(()=>import(`./dist-DeD9copn.js`).then(e=>e.xml()),__vite__mapDeps([16,2,1,3,4,0,6])),json:()=>i(()=>import(`./dist-QzbOCAU6.js`).then(e=>e.json()),__vite__mapDeps([17,4,1,0,2,3,6])),jsonc:()=>i(()=>import(`./dist-QzbOCAU6.js`).then(e=>e.json()),__vite__mapDeps([17,4,1,0,2,3,6])),json5:()=>i(()=>import(`./dist-QzbOCAU6.js`).then(e=>e.json()),__vite__mapDeps([17,4,1,0,2,3,6])),html:()=>i(()=>import(`./dist-CKF2Jksy.js`).then(e=>e.html()),__vite__mapDeps([12,2,1,3,4,0,6,13,7,8])),htm:()=>i(()=>import(`./dist-CKF2Jksy.js`).then(e=>e.html()),__vite__mapDeps([12,2,1,3,4,0,6,13,7,8])),vue:()=>i(()=>import(`./dist-CKF2Jksy.js`).then(e=>e.html()),__vite__mapDeps([12,2,1,3,4,0,6,13,7,8])),svelte:()=>i(()=>import(`./dist-CKF2Jksy.js`).then(e=>e.html()),__vite__mapDeps([12,2,1,3,4,0,6,13,7,8])),css:()=>i(()=>import(`./dist-BV64A9Ji.js`).then(e=>e.r).then(e=>e.css()),__vite__mapDeps([13,1,4,0,2,3,6])),md:()=>i(()=>import(`./dist-DuvGReu-.js`).then(e=>e.markdown()),__vite__mapDeps([18,2,1,3,4,0,8,12,6,13,7])),markdown:()=>i(()=>import(`./dist-DuvGReu-.js`).then(e=>e.markdown()),__vite__mapDeps([18,2,1,3,4,0,8,12,6,13,7])),mdx:()=>i(()=>import(`./dist-DuvGReu-.js`).then(e=>e.markdown()),__vite__mapDeps([18,2,1,3,4,0,8,12,6,13,7])),rs:()=>i(()=>import(`./dist-BRVQKlcp.js`).then(e=>e.rust()),__vite__mapDeps([19,4,1,0,2,3,6])),go:()=>i(()=>import(`./dist-BJxfd7yb.js`).then(e=>e.go()),__vite__mapDeps([20,4,1,0,2,3,6,8])),sh:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),bash:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),zsh:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),fish:()=>s(()=>i(()=>import(`./shell-DwuoZtxw.js`),[]),`shell`),ps1:()=>s(()=>i(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),psm1:()=>s(()=>i(()=>import(`./powershell-D8WpQPaX.js`),[]),`powershell`),rb:()=>s(()=>i(()=>import(`./ruby-ChfNwlCY.js`),[]),`ruby`),swift:()=>s(()=>i(()=>import(`./swift-DKB6_1j6.js`),[]),`swift`),toml:()=>s(()=>i(()=>import(`./toml-BPTmHmyx.js`),[]),`toml`),ini:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),cfg:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),conf:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),properties:()=>s(()=>i(()=>import(`./properties-C357ku5U.js`),[]),`properties`),dockerfile:()=>s(()=>i(()=>import(`./dockerfile-BDePf5PZ.js`),[]),`dockerfile`),diff:()=>s(()=>i(()=>import(`./diff-ChtP43wD.js`),[]),`diff`),patch:()=>s(()=>i(()=>import(`./diff-ChtP43wD.js`),[]),`diff`)},l={cpp:`C++`,cc:`C++`,cxx:`C++`,hpp:`C++`,hh:`C++`,hxx:`C++`,cu:`CUDA C++`,cuh:`CUDA C++`,c:`C`,h:`C/C++ Header`,js:`JavaScript`,jsx:`JSX`,mjs:`JavaScript`,cjs:`JavaScript`,ts:`TypeScript`,tsx:`TSX`,mts:`TypeScript`,cts:`TypeScript`,py:`Python`,pyi:`Python Stub`,java:`Java`,php:`PHP`,sql:`SQL`,yaml:`YAML`,yml:`YAML`,xml:`XML`,json:`JSON`,jsonc:`JSON with Comments`,json5:`JSON5`,css:`CSS`,md:`Markdown`,markdown:`Markdown`,mdx:`MDX`,rs:`Rust`,go:`Go`,html:`HTML`,htm:`HTML`,vue:`Vue`,svelte:`Svelte`,sh:`Shell`,bash:`Bash`,zsh:`Zsh`,fish:`Fish`,ps1:`PowerShell`,psm1:`PowerShell`,rb:`Ruby`,swift:`Swift`,toml:`TOML`,ini:`INI`,cfg:`Config`,conf:`Config`,properties:`Properties`,dockerfile:`Dockerfile`,diff:`Diff`,patch:`Patch`};function u(e){return c[e.toLowerCase()]}function d(e){return l[e.toLowerCase()]}var f=t(),p=262144,m=131072;function h(e){return e.split(`.`).pop()?.toLowerCase()??``}function g(e){return getComputedStyle(document.documentElement).getPropertyValue(e).trim()}function _(e,t){return e.HighlightStyle.define([{tag:t.tags.keyword,color:g(`--cm-keyword`)},{tag:t.tags.string,color:g(`--cm-string`)},{tag:t.tags.number,color:g(`--cm-number`)},{tag:t.tags.comment,color:g(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:g(`--cm-function`)},{tag:t.tags.typeName,color:g(`--cm-type`)},{tag:t.tags.className,color:g(`--cm-type`)},{tag:t.tags.propertyName,color:g(`--cm-property`)},{tag:t.tags.operator,color:g(`--cm-operator`)},{tag:t.tags.variableName,color:g(`--cm-variable`)}])}function v({path:e,value:t,onChange:n,jumpToLine:s,onSave:c,workspaceId:l,blame:g,onPosition:v,readOnly:y=!1}){let b=(0,o.useRef)(null),x=(0,o.useRef)(null),S=(0,o.useRef)(null),C=(0,o.useRef)(null),w=(0,o.useRef)(null),T=(0,o.useRef)(null),E=(0,o.useRef)(null),D=(0,o.useRef)(null),O=(0,o.useRef)(n),k=(0,o.useRef)(c);O.current=n,k.current=c;let[A,j]=(0,o.useState)(!1),[M,N]=(0,o.useState)(!1),[P,F]=(0,o.useState)(`0,0`),[I,L]=(0,o.useState)(0);(0,o.useEffect)(()=>{let n=!1,a,o,s,c,l;return(async()=>{try{let d=h(e),f=u(d),[m,g,v,A,M,P,I,R]=await Promise.all([i(()=>import(`./dist-D978o95T.js`).then(e=>e.S),__vite__mapDeps([2,1])),i(()=>import(`./dist-B3-a6uF0.js`).then(e=>e.s),__vite__mapDeps([3,1,2])),i(()=>import(`./dist-CX_Hm4GS.js`),__vite__mapDeps([21,2,1,3,4,0])),i(()=>import(`./dist-scBkrwv-.js`),__vite__mapDeps([22,2,1,3])),i(()=>import(`./dist-J6XWqRpB.js`).then(e=>e.d),__vite__mapDeps([0,1,2,3,4])),i(()=>import(`./dist-Cus6_oaF.js`).then(e=>e.n),__vite__mapDeps([4,1])),f?f().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${d}:`,e),null)):Promise.resolve(null),r().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null))]);if(n||!b.current)return;c=M,l=P,C.current=m.Annotation.define(),w.current=m.Transaction.addToHistory;let z=t.length<=p&&I!==null;o=new m.Compartment;let B=[g.lineNumbers(),g.highlightActiveLine(),g.drawSelection(),v.history(),g.keymap.of([v.indentWithTab,...v.defaultKeymap,...v.historyKeymap,...A.searchKeymap,{key:`Mod-s`,run:()=>(k.current(),!0)}]),g.EditorView.updateListener.of(e=>{e.docChanged&&!(C.current&&e.transactions.some(e=>e.annotation(C.current)===!0))&&O.current(e.state.doc.toString()),e.selectionSet&&F(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),g.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(y&&B.push(m.EditorState.readOnly.of(!0),g.EditorView.editable.of(!1)),R&&!y&&(s=new m.Compartment,B.splice(1,0,s.of([])),B.push(R.base)),I)try{B.push(I)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${d}:`,e),z=!1}if(z&&o&&c&&l)try{B.push(o.of(c.syntaxHighlighting(_(c,l))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${d}:`,e),z=!1}if(a=new g.EditorView({state:m.EditorState.create({doc:t,extensions:B}),parent:b.current}),n){a.destroy();return}x.current=a,j(z),N(!0),T.current=R,E.current=s??null,D.current=null,L(e=>e+1);let V=new MutationObserver(()=>{let e=x.current;if(e&&z&&o&&c&&l)try{e.dispatch({effects:o.reconfigure(c.syntaxHighlighting(_(c,l)))})}catch{}});S.current=V,V.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),n||N(!0)}})(),()=>{n=!0,S.current?.disconnect(),S.current=null,a?.destroy(),x.current=null,N(!1),b.current&&(b.current.textContent=``)}},[e,y]),(0,o.useEffect)(()=>{let e=x.current;if(!e)return;let n=e.state.doc.toString();n!==t&&e.dispatch({changes:{from:0,to:n.length,insert:t},annotations:C.current?C.current.of(!0):void 0})},[t]),(0,o.useEffect)(()=>{let e=x.current;if(!e||!s)return;let t=e.state.doc.line(Math.min(Math.max(1,s.line),e.state.doc.lines)),n=Math.min(t.to,t.from+(s.column??1)-1);e.dispatch({selection:{anchor:t.to,head:n},scrollIntoView:!0}),e.focus()},[s,M]);let R=!!(g&&g.state===`ready`&&g.response&&g.path===e&&g.workspaceId===l);(0,o.useEffect)(()=>{let t=x.current,n=T.current,r=E.current;if(!t||!n||!r)return;let i=g&&g.state===`ready`&&g.response&&g.path===e&&g.workspaceId===l?g.response:null,o=i?a(i):null;D.current!==o&&(D.current=o,t.dispatch({effects:[n.setBlame.of(o),r.reconfigure(o?n.gutter:[])]}))},[g?.state,g?.response,g?.path,g?.workspaceId,e,l,I]);let z=x.current?.state.doc.toString()??t,B=z.length<=m?z:z.slice(0,m),V=h(e),H=d(V),U=x.current?.state,W=U?.selection.main.head,G=W===void 0?void 0:U?.doc.lineAt(W),K=G?.number,q=W!==void 0&&G?W-G.from+1:void 0;return(0,o.useEffect)(()=>{M&&K!==void 0&&q!==void 0&&v?.({line:K,column:q,language:A&&H||`纯文本`,highlight:A?V:`plain`})},[M,K,q,A,H,V,v]),(0,o.useEffect)(()=>()=>v?.(),[v]),(0,f.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":B,"data-file-content-truncated":z.length>m?`1`:`0`,"data-file-selection":P,"data-file-editor-ready":M?`1`:`0`,"data-file-blame-gutter":R?`1`:void 0,onMouseDown:()=>x.current?.focus(),children:[(0,f.jsx)(`div`,{className:`file-cm`,ref:b,"aria-label":`${y?`查看`:`编辑`} ${e}`}),(!M||!v)&&(0,f.jsxs)(`div`,{className:`file-editor-status`,children:[!M&&(0,f.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),M&&W!==void 0&&G&&(0,f.jsxs)(`span`,{children:[`第 `,G.number,` 行,第 `,W-G.from+1,` 列`]}),M&&!A&&(0,f.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),M&&A&&H&&(0,f.jsx)(`span`,{"data-file-highlight-status":V,children:H})]})]})}export{v as CodeMirrorEditor,u as t,_ as themeHighlightStyle};
|