@evandu/super-pi 0.1.288 → 0.1.289
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/desktop/main.cjs +14 -2
- package/desktop/notification-routing.cjs +45 -0
- package/desktop/notifications.cjs +1 -1
- package/desktop/pet-preload.cjs +11 -0
- package/desktop/pet-renderer.js +34 -0
- package/desktop/pet.cjs +77 -0
- package/desktop/pet.css +26 -0
- package/desktop/pet.html +32 -0
- package/desktop/preload.cjs +4 -1
- package/dist/.super-pi-check-inputs.json +2 -2
- package/dist/client/.super-pi-client-sources.json +15 -14
- package/dist/client/assets/{CodeMirrorEditor-CWtrW4l8.js → CodeMirrorEditor-BQEK9QVa.js} +1 -1
- package/dist/client/assets/{GitDiffEditor-as0g7l10.js → GitDiffEditor-jen_6W68.js} +1 -1
- package/dist/client/assets/index-C7o39I4j.js +350 -0
- package/dist/client/assets/index-dkbN-Swt.css +1 -0
- package/dist/client/index.html +2 -2
- package/dist/server/application/catalog-service.js +1 -0
- package/dist/server/application/run-service.d.ts +1 -0
- package/dist/server/application/run-service.js +26 -1
- package/dist/server/command-handler.js +35 -0
- package/dist/server/pi-session-pool.d.ts +1 -0
- package/dist/server/pi-session-pool.js +1 -0
- package/dist/server/pi-session.d.ts +8 -0
- package/dist/server/pi-session.js +19 -1
- package/dist/server/runtime.d.ts +2 -0
- package/dist/server/runtime.js +13 -0
- package/dist/server/types.d.ts +3 -0
- package/dist/shared/slash-commands.d.ts +7 -0
- package/dist/shared/slash-commands.js +18 -0
- package/package.json +1 -1
- package/dist/client/assets/index-CA58HvxO.css +0 -1
- package/dist/client/assets/index-CtgkiwLi.js +0 -350
package/desktop/main.cjs
CHANGED
|
@@ -8,6 +8,8 @@ const { join, resolve } = require("node:path");
|
|
|
8
8
|
const { macLaunchAgent } = require("./login-item.cjs");
|
|
9
9
|
const { expectedServiceExit, shouldRestartDesktop } = require("./update-lifecycle.cjs");
|
|
10
10
|
const { createDesktopNotifications } = require("./notifications.cjs");
|
|
11
|
+
const { createDesktopPet } = require("./pet.cjs");
|
|
12
|
+
const { createNotificationRouting } = require("./notification-routing.cjs");
|
|
11
13
|
const { handoffDesktop } = require("./restart-handoff.cjs");
|
|
12
14
|
const { ensureShellEntries } = require("./shell-entries.cjs");
|
|
13
15
|
const { loadWindowState, trackWindowState } = require("./window-state.cjs");
|
|
@@ -22,7 +24,7 @@ if (!process.env.SUPER_PI_DESKTOP_PROFILE) app.setPath("userData", join(app.getP
|
|
|
22
24
|
if (process.platform === "win32") app.setAppUserModelId("com.evandu.super-pi");
|
|
23
25
|
if (process.platform === "linux") app.setDesktopName("super-pi.desktop");
|
|
24
26
|
let mainWindow, tray, server, origin, managerHost, quitting = false, ownsServer = false;
|
|
25
|
-
let frameTheme, windowMemory;
|
|
27
|
+
let frameTheme, windowMemory, desktopPet;
|
|
26
28
|
let relaunching = false, updateMonitor, restartError, attemptedRestartOperation;
|
|
27
29
|
const resumedOperation = process.env.SUPER_PI_DESKTOP_RESUMED_OPERATION;
|
|
28
30
|
async function diskVersion() { try { return JSON.parse(await readFile(join(root, "package.json"), "utf8")).version; } catch { return undefined; } }
|
|
@@ -129,8 +131,15 @@ async function createWindow() {
|
|
|
129
131
|
const windowState = loadWindowState(stateFile, screen.getAllDisplays());
|
|
130
132
|
mainWindow = new BrowserWindow({ title: "Super Pi", width: 1500, height: 980, ...windowState.bounds, 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 } });
|
|
131
133
|
windowMemory = trackWindowState(mainWindow, stateFile, windowState);
|
|
132
|
-
|
|
134
|
+
let notifications;
|
|
135
|
+
const clicked = id => { notifications?.close(id); mainWindow?.webContents.send("super-pi-desktop:notification-click", id); };
|
|
136
|
+
const system = createDesktopNotifications({ Notification, icon: join(__dirname, "icon.png"), platform: process.platform, showWindow: show, clicked });
|
|
137
|
+
desktopPet = createDesktopPet({ BrowserWindow, screen, ipcMain, Menu, stateFile: join(app.getPath("userData"), "pet-position.json"), showWindow: show, clicked, useSystem: () => notifications.configure({ mode: "system" }).catch(error => dialog.showErrorBox("无法修改通知方式", error.message)) });
|
|
138
|
+
notifications = createNotificationRouting({ system, pet: desktopPet, file: join(app.getPath("userData"), "notification-preferences.json") });
|
|
139
|
+
await notifications.restore();
|
|
133
140
|
app.once("will-quit", () => notifications.dispose());
|
|
141
|
+
ipcMain.handle("super-pi-desktop:notification-configure", (event, value) => { trusted(event); return notifications.configure(value); });
|
|
142
|
+
ipcMain.handle("super-pi-desktop:notification-clear-system", event => { trusted(event); notifications.clearSystem(); });
|
|
134
143
|
ipcMain.handle("super-pi-desktop:notification-status", event => { trusted(event); return notifications.status(); });
|
|
135
144
|
ipcMain.handle("super-pi-desktop:notification-show", (event, value) => { trusted(event); return notifications.show(value); });
|
|
136
145
|
ipcMain.handle("super-pi-desktop:notification-close", (event, id) => { trusted(event); if (typeof id === "string") notifications.close(id); });
|
|
@@ -152,6 +161,9 @@ async function createWindow() {
|
|
|
152
161
|
mainWindow.setBackgroundColor(value.background);
|
|
153
162
|
if (process.platform !== "darwin") mainWindow.setTitleBarOverlay({ color: value.background, symbolColor: value.foreground, height: 38 });
|
|
154
163
|
frameTheme = { background: value.background, foreground: value.foreground, dark: value.dark };
|
|
164
|
+
const names = ["--bg-elevated", "--bg-raised", "--text-primary", "--text-secondary", "--border-default", "--accent", "--accent-contrast", "--focus-ring", "--info"];
|
|
165
|
+
const colors = Object.fromEntries(names.filter(name => /^#[a-f0-9]{6}$/i.test(value.colors?.[name] ?? "")).map(name => [name, value.colors[name]]));
|
|
166
|
+
desktopPet?.setTheme({ ...frameTheme, colors });
|
|
155
167
|
return { platform: process.platform, icon: image.resize({ width: 48, height: 48 }).toDataURL() };
|
|
156
168
|
});
|
|
157
169
|
ipcMain.handle("super-pi-desktop:autostart", async (event, enabled) => { trusted(event); await setAutoStart(enabled === true); return { autoStart: await autoStartStatus() }; });
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const { readFileSync, mkdirSync, writeFileSync, renameSync } = require('node:fs');
|
|
2
|
+
const { dirname } = require('node:path');
|
|
3
|
+
const MODES = ['system', 'pet', 'both'];
|
|
4
|
+
|
|
5
|
+
function createNotificationRouting({ system, pet, file }) {
|
|
6
|
+
let preference = { mode: 'system', enabled: false }, lane = Promise.resolve();
|
|
7
|
+
try { const value = JSON.parse(readFileSync(file, 'utf8')); if (MODES.includes(value.mode)) preference = { mode: value.mode, enabled: value.enabled === true }; } catch { /* Keep system notifications as the upgrade default. */ }
|
|
8
|
+
const usesPet = value => value.enabled && value.mode !== 'system';
|
|
9
|
+
const status = () => {
|
|
10
|
+
const native = system.status(), desktopPet = pet.status();
|
|
11
|
+
return { ...native, ...preference, systemSupported: native.supported, petAvailable: desktopPet.available, petVisible: desktopPet.visible, pendingPetNotifications: desktopPet.pending,
|
|
12
|
+
supported: preference.mode === 'pet' ? desktopPet.available : preference.mode === 'both' ? native.supported || desktopPet.available : native.supported };
|
|
13
|
+
};
|
|
14
|
+
const configure = value => {
|
|
15
|
+
const work = lane.then(async () => {
|
|
16
|
+
if (!value || typeof value !== 'object' || value.mode !== undefined && !MODES.includes(value.mode) || value.enabled !== undefined && typeof value.enabled !== 'boolean') throw new Error('通知方式配置无效');
|
|
17
|
+
const next = { mode: value.mode ?? preference.mode, enabled: value.enabled ?? preference.enabled };
|
|
18
|
+
await pet.setEnabled(usesPet(next));
|
|
19
|
+
try { mkdirSync(dirname(file), { recursive: true }); const temp = `${file}.${process.pid}.tmp`; writeFileSync(temp, JSON.stringify(next), { mode: 0o600 }); renameSync(temp, file); }
|
|
20
|
+
catch (error) { await pet.setEnabled(usesPet(preference)); throw new Error(`无法保存通知方式:${error.message}`); }
|
|
21
|
+
if (next.mode !== preference.mode || !next.enabled) system.dispose();
|
|
22
|
+
preference = next;
|
|
23
|
+
return status();
|
|
24
|
+
});
|
|
25
|
+
lane = work.catch(() => {});
|
|
26
|
+
return work;
|
|
27
|
+
};
|
|
28
|
+
return {
|
|
29
|
+
status, configure,
|
|
30
|
+
restore: () => configure(preference),
|
|
31
|
+
close(id) { system.close(id); pet.close(id); },
|
|
32
|
+
clearSystem() { system.dispose(); },
|
|
33
|
+
async show(value) {
|
|
34
|
+
await lane;
|
|
35
|
+
if (!preference.enabled) throw new Error('请先启用 Agent 状态提醒');
|
|
36
|
+
if (!value || typeof value.id !== 'string' || !value.id || value.id.length > 512 || typeof value.title !== 'string' || value.title.length > 160 || typeof value.body !== 'string' || value.body.length > 1000) throw new Error('通知参数无效');
|
|
37
|
+
if (preference.mode === 'system') return system.show(value);
|
|
38
|
+
const result = await pet.show(value);
|
|
39
|
+
if (preference.mode === 'both') { try { await system.show(value); } catch { /* The pet already delivered the notification; system.status retains its own failure. */ } }
|
|
40
|
+
return result;
|
|
41
|
+
},
|
|
42
|
+
dispose() { system.dispose(); pet.dispose(); },
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
module.exports = { createNotificationRouting };
|
|
@@ -10,7 +10,7 @@ function createDesktopNotifications({ Notification, icon, platform, showWindow,
|
|
|
10
10
|
// macOS and Windows already supply the installed application's identity icon.
|
|
11
11
|
const notification = new Notification({ title: value.title, body: value.body, ...(platform === 'linux' ? { icon } : {}), timeoutType: 'default' });
|
|
12
12
|
live.set(value.id, notification);
|
|
13
|
-
notification.on('click', () => {
|
|
13
|
+
notification.on('click', () => { clicked(value.id); showWindow(); close(value.id); });
|
|
14
14
|
notification.once('close', () => { if (live.get(value.id) === notification) live.delete(value.id); });
|
|
15
15
|
return new Promise((resolve, reject) => {
|
|
16
16
|
let settled = false;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const { contextBridge, ipcRenderer } = require('electron');
|
|
2
|
+
if (process.isMainFrame) contextBridge.exposeInMainWorld('superPiPet', Object.freeze({
|
|
3
|
+
state: () => ipcRenderer.invoke('super-pi-pet:state'),
|
|
4
|
+
regions: value => ipcRenderer.invoke('super-pi-pet:regions', value),
|
|
5
|
+
toggle: () => ipcRenderer.invoke('super-pi-pet:toggle'),
|
|
6
|
+
open: id => ipcRenderer.invoke('super-pi-pet:open', id),
|
|
7
|
+
dismiss: id => ipcRenderer.invoke('super-pi-pet:dismiss', id),
|
|
8
|
+
drag: action => ipcRenderer.invoke('super-pi-pet:drag', action),
|
|
9
|
+
menu: () => ipcRenderer.invoke('super-pi-pet:menu'),
|
|
10
|
+
onState: callback => { const listener = (_event, value) => callback(value); ipcRenderer.on('super-pi-pet:state', listener); return () => ipcRenderer.removeListener('super-pi-pet:state', listener); },
|
|
11
|
+
}));
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
const api = window.superPiPet;
|
|
2
|
+
const element = id => document.getElementById(id);
|
|
3
|
+
let state = { count: 0, expanded: false }, press;
|
|
4
|
+
const call = promise => void promise?.catch(() => {});
|
|
5
|
+
function regions() {
|
|
6
|
+
const boxes = [element('pet-wrap'), ...(!element('bubble').hidden ? [element('bubble')] : [])].map(node => { const rect = node.getBoundingClientRect(); return { x: rect.x, y: rect.y, width: rect.width, height: rect.height }; });
|
|
7
|
+
call(api?.regions(boxes));
|
|
8
|
+
}
|
|
9
|
+
function render(value) {
|
|
10
|
+
state = value;
|
|
11
|
+
const item = value.notification;
|
|
12
|
+
element('bubble').hidden = !item || !value.expanded;
|
|
13
|
+
element('title').textContent = item?.title ?? '';
|
|
14
|
+
element('body').textContent = item?.body ?? '';
|
|
15
|
+
element('kind').textContent = item?.title.includes('回答') || item?.title.includes('决定') ? '需要你的回复' : 'SUPER PI 提醒';
|
|
16
|
+
element('count').textContent = value.count > 1 ? `还有 ${value.count - 1} 条` : '';
|
|
17
|
+
element('badge').hidden = !value.count;
|
|
18
|
+
element('badge').textContent = String(value.count);
|
|
19
|
+
document.body.dataset.notified = value.count ? 'true' : 'false';
|
|
20
|
+
for (const [key, color] of Object.entries(value.theme?.colors ?? {})) if (/^#[\da-f]{6}$/i.test(color)) document.documentElement.style.setProperty(key, color);
|
|
21
|
+
document.documentElement.style.colorScheme = value.theme?.dark === false ? 'light' : 'dark';
|
|
22
|
+
requestAnimationFrame(regions);
|
|
23
|
+
}
|
|
24
|
+
element('collapse').onclick = () => call(api?.toggle());
|
|
25
|
+
element('open').onclick = () => call(api?.open(state.notification?.id));
|
|
26
|
+
element('dismiss').onclick = () => call(api?.dismiss(state.notification?.id));
|
|
27
|
+
element('pet').oncontextmenu = event => { event.preventDefault(); call(api?.menu()); };
|
|
28
|
+
element('pet').onpointerdown = event => { if (event.button !== 0) return; press = { x: event.screenX, y: event.screenY, dragged: false }; element('pet').setPointerCapture(event.pointerId); call(api?.drag('start')); };
|
|
29
|
+
element('pet').onpointermove = event => { if (press && Math.hypot(event.screenX - press.x, event.screenY - press.y) > 5) press.dragged = true; };
|
|
30
|
+
element('pet').onpointerup = event => { if (!press) return; const dragged = press.dragged; press = undefined; call(api?.drag('end')); if (!dragged) call(api?.toggle()); if (element('pet').hasPointerCapture(event.pointerId)) element('pet').releasePointerCapture(event.pointerId); };
|
|
31
|
+
element('pet').onpointercancel = () => { press = undefined; call(api?.drag('end')); };
|
|
32
|
+
element('pet').onkeydown = event => { if (event.key === 'Enter' || event.key === ' ') { event.preventDefault(); call(api?.toggle()); } };
|
|
33
|
+
if (api) { api.onState(render); call(api.state().then(render)); }
|
|
34
|
+
new ResizeObserver(regions).observe(element('bubble'));
|
package/desktop/pet.cjs
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
const { readFileSync, writeFileSync, mkdirSync, renameSync } = require('node:fs');
|
|
2
|
+
const { join, dirname } = require('node:path');
|
|
3
|
+
const { pathToFileURL } = require('node:url');
|
|
4
|
+
|
|
5
|
+
const SIZE = { width: 360, height: 360 };
|
|
6
|
+
function fitPetPosition(position, displays) {
|
|
7
|
+
const areas = displays.map(display => display.workArea).filter(area => area.width > 0 && area.height > 0);
|
|
8
|
+
const point = position && Number.isFinite(position.x) && Number.isFinite(position.y) ? position : undefined;
|
|
9
|
+
const area = (point && areas.find(area => point.x + SIZE.width > area.x && point.x < area.x + area.width && point.y + SIZE.height > area.y && point.y < area.y + area.height)) || areas[0] || { x: 0, y: 0, width: 1280, height: 800 };
|
|
10
|
+
return { x: Math.round(Math.max(area.x, Math.min(point?.x ?? area.x + area.width - SIZE.width - 24, area.x + Math.max(0, area.width - SIZE.width)))), y: Math.round(Math.max(area.y, Math.min(point?.y ?? area.y + area.height - SIZE.height - 24, area.y + Math.max(0, area.height - SIZE.height)))) };
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function createDesktopPet({ BrowserWindow, screen, ipcMain, Menu, stateFile, showWindow, clicked, useSystem }) {
|
|
14
|
+
let window, ready, enabled = false, disposed = false, theme, regions = [], ignore, poll, drag, expanded = false;
|
|
15
|
+
const queue = new Map();
|
|
16
|
+
let saved;
|
|
17
|
+
try { saved = JSON.parse(readFileSync(stateFile, 'utf8')); } catch { /* First launch. */ }
|
|
18
|
+
const localUrl = pathToFileURL(join(__dirname, 'pet.html')).href;
|
|
19
|
+
const alive = () => window && !window.isDestroyed();
|
|
20
|
+
const save = () => {
|
|
21
|
+
if (!alive()) return;
|
|
22
|
+
const [x, y] = window.getPosition(); saved = { x, y };
|
|
23
|
+
try { mkdirSync(dirname(stateFile), { recursive: true }); const temp = `${stateFile}.${process.pid}.tmp`; writeFileSync(temp, JSON.stringify(saved), { mode: 0o600 }); renameSync(temp, stateFile); } catch { /* Position memory must not block notifications. */ }
|
|
24
|
+
};
|
|
25
|
+
const publish = () => { if (alive()) window.webContents.send('super-pi-pet:state', { notification: queue.values().next().value ?? null, count: queue.size, expanded, theme }); };
|
|
26
|
+
const assertPet = event => { if (!alive() || event.sender !== window.webContents || event.senderFrame !== window.webContents.mainFrame || event.senderFrame.url !== localUrl) throw new Error('拒绝来自非宠物窗口的调用'); };
|
|
27
|
+
const move = () => {
|
|
28
|
+
if (!alive()) return;
|
|
29
|
+
const cursor = screen.getCursorScreenPoint();
|
|
30
|
+
if (drag && Date.now() - drag.started < 15000) {
|
|
31
|
+
const point = fitPetPosition({ x: drag.x + cursor.x - drag.cursor.x, y: drag.y + cursor.y - drag.cursor.y }, screen.getAllDisplays());
|
|
32
|
+
window.setPosition(point.x, point.y); return;
|
|
33
|
+
}
|
|
34
|
+
if (drag) { drag = undefined; save(); }
|
|
35
|
+
const [x, y] = window.getPosition();
|
|
36
|
+
const hit = regions.some(rect => cursor.x >= x + rect.x && cursor.x <= x + rect.x + rect.width && cursor.y >= y + rect.y && cursor.y <= y + rect.y + rect.height);
|
|
37
|
+
if (ignore !== !hit) { ignore = !hit; window.setIgnoreMouseEvents(ignore, { forward: true }); }
|
|
38
|
+
};
|
|
39
|
+
const ensure = async () => {
|
|
40
|
+
if (disposed) throw new Error('桌面宠物已退出');
|
|
41
|
+
if (alive()) { await ready; return; }
|
|
42
|
+
const position = fitPetPosition(saved, screen.getAllDisplays());
|
|
43
|
+
window = new BrowserWindow({ title: 'Super Pi · 桌面宠物', ...SIZE, ...position, transparent: true, backgroundColor: '#00000000', frame: false, resizable: false, maximizable: false, minimizable: false, fullscreenable: false, focusable: false, skipTaskbar: true, alwaysOnTop: true, hasShadow: false, show: false, webPreferences: { preload: join(__dirname, 'pet-preload.cjs'), contextIsolation: true, nodeIntegration: false, sandbox: true, webSecurity: true, backgroundThrottling: false } });
|
|
44
|
+
window.setVisibleOnAllWorkspaces(true, { visibleOnFullScreen: true });
|
|
45
|
+
window.setIgnoreMouseEvents(true, { forward: true }); ignore = true;
|
|
46
|
+
window.webContents.on('will-navigate', event => event.preventDefault());
|
|
47
|
+
window.webContents.on('will-attach-webview', event => event.preventDefault());
|
|
48
|
+
window.webContents.setWindowOpenHandler(() => ({ action: 'deny' }));
|
|
49
|
+
window.on('closed', () => { clearInterval(poll); poll = undefined; ready = undefined; regions = []; window = undefined; });
|
|
50
|
+
ready = window.loadFile(join(__dirname, 'pet.html'));
|
|
51
|
+
await ready;
|
|
52
|
+
if (!alive() || !enabled) return;
|
|
53
|
+
publish(); window.showInactive();
|
|
54
|
+
poll = setInterval(move, 80); poll.unref?.();
|
|
55
|
+
};
|
|
56
|
+
const refit = () => { if (!alive()) return; const [x, y] = window.getPosition(); const point = fitPetPosition({ x, y }, screen.getAllDisplays()); window.setPosition(point.x, point.y); save(); };
|
|
57
|
+
screen.on('display-removed', refit); screen.on('display-metrics-changed', refit);
|
|
58
|
+
const handlers = {
|
|
59
|
+
state: () => ({ notification: queue.values().next().value ?? null, count: queue.size, expanded, theme }),
|
|
60
|
+
regions: (_event, value) => { if (!Array.isArray(value) || value.length > 8) throw new Error('宠物交互范围无效'); regions = value.filter(rect => ['x', 'y', 'width', 'height'].every(key => Number.isFinite(rect[key])) && rect.x >= 0 && rect.y >= 0 && rect.width >= 0 && rect.height >= 0 && rect.x + rect.width <= SIZE.width + 1 && rect.y + rect.height <= SIZE.height + 1); move(); },
|
|
61
|
+
toggle: () => { if (!queue.size) { showWindow(); return; } expanded = !expanded; publish(); },
|
|
62
|
+
open: (_event, id) => { if (typeof id !== 'string' || !queue.has(id)) return; queue.delete(id); publish(); clicked(id); showWindow(); },
|
|
63
|
+
dismiss: (_event, id) => { if (typeof id === 'string') { queue.delete(id); publish(); } },
|
|
64
|
+
drag: (_event, action) => { if (action === 'start') { const [x, y] = window.getPosition(); drag = { x, y, cursor: screen.getCursorScreenPoint(), started: Date.now() }; window.setIgnoreMouseEvents(false); ignore = false; } else if (action === 'end') { drag = undefined; save(); move(); } },
|
|
65
|
+
menu: () => Menu.buildFromTemplate([{ label: '打开 Super Pi', click: showWindow }, { label: '隐藏宠物,改用系统通知', click: () => { void useSystem(); } }]).popup({ window }),
|
|
66
|
+
};
|
|
67
|
+
for (const [name, handler] of Object.entries(handlers)) ipcMain.handle(`super-pi-pet:${name}`, (event, value) => { assertPet(event); return handler(event, value); });
|
|
68
|
+
return {
|
|
69
|
+
async setEnabled(value) { enabled = value === true; if (enabled) { try { await ensure(); } catch (error) { if (alive()) window.destroy(); throw error; } } else { queue.clear(); expanded = false; if (alive()) { save(); window.destroy(); } } },
|
|
70
|
+
async show(value) { if (!enabled) throw new Error('请先启用桌面宠物通知'); await ensure(); if (queue.has(value.id)) queue.set(value.id, value); else { if (queue.size >= 64) queue.delete(queue.keys().next().value); queue.set(value.id, value); } expanded = true; publish(); if (alive()) window.showInactive(); return { state: 'shown' }; },
|
|
71
|
+
close(id) { queue.delete(id); publish(); },
|
|
72
|
+
setTheme(value) { theme = value; publish(); },
|
|
73
|
+
status: () => ({ available: !disposed, visible: Boolean(alive() && window.isVisible()), pending: queue.size }),
|
|
74
|
+
dispose() { disposed = true; enabled = false; clearInterval(poll); screen.removeListener('display-removed', refit); screen.removeListener('display-metrics-changed', refit); for (const name of Object.keys(handlers)) ipcMain.removeHandler(`super-pi-pet:${name}`); if (alive()) { save(); window.destroy(); } queue.clear(); },
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
module.exports = { createDesktopPet, fitPetPosition };
|
package/desktop/pet.css
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
:root {color-scheme:dark;--bg-elevated:#282a36;--bg-raised:#343746;--text-primary:#f8f8f2;--text-secondary:#c9cadd;--border-default:#73798a;--accent:#bd93f9;--accent-contrast:#191a22;--focus-ring:#bd93f9;--info:#8be9fd;--pet-shell:#b6a0e8;--pet-face:#242637;--pet-eye:#faf7ff;--pet-shadow:rgba(0,0,0,.18);font-family:system-ui,-apple-system,"Segoe UI",sans-serif;}
|
|
2
|
+
* {box-sizing:border-box;}html,body {width:100%;height:100%;margin:0;overflow:hidden;background:transparent;}button {font:inherit;color:inherit;cursor:pointer;}button:focus-visible {outline:2px solid var(--focus-ring);outline-offset:2px;}[hidden] {display:none!important;}
|
|
3
|
+
#bubble {position:absolute;left:10px;right:12px;bottom:117px;padding:14px;background:var(--bg-elevated);color:var(--text-primary);border:1px solid var(--border-default);border-radius:16px;box-shadow:0 5px 12px var(--pet-shadow);font-size:13px;line-height:1.5;}
|
|
4
|
+
#bubble::after {content:"";position:absolute;bottom:-7px;right:44px;width:12px;height:12px;border-right:1px solid var(--border-default);border-bottom:1px solid var(--border-default);background:var(--bg-elevated);transform:rotate(45deg);}
|
|
5
|
+
.bubble-heading {display:flex;gap:7px;align-items:center;color:var(--text-secondary);font-size:11px;letter-spacing:.04em;}
|
|
6
|
+
.notification-mark {width:18px;height:18px;display:grid;place-items:center;color:var(--text-primary);font-size:16px;}
|
|
7
|
+
#count {margin-left:auto;font-variant-numeric:tabular-nums;letter-spacing:0;}
|
|
8
|
+
#collapse {display:grid;place-items:center;width:24px;height:24px;background:transparent;color:var(--text-secondary);border:0;border-radius:4px;font-size:18px;padding:0;}
|
|
9
|
+
#title {margin:7px 0 4px;font-size:14px;line-height:1.4;font-weight:600;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere;}
|
|
10
|
+
#body {margin:0;color:var(--text-secondary);display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden;overflow-wrap:anywhere;}
|
|
11
|
+
.bubble-actions {display:flex;align-items:center;gap:8px;margin-top:12px;}
|
|
12
|
+
.bubble-actions button {min-height:30px;border:1px solid var(--border-default);border-radius:6px;background:var(--bg-raised);padding:4px 10px;font-size:12px;}
|
|
13
|
+
.bubble-actions button:last-child {background:transparent;border-color:transparent;color:var(--text-secondary);}
|
|
14
|
+
.bubble-actions button:hover,#collapse:hover {background:var(--bg-raised);}
|
|
15
|
+
.pet-wrap {position:absolute;bottom:0;right:8px;width:112px;height:112px;text-align:center;user-select:none;}
|
|
16
|
+
#pet {position:relative;display:block;width:112px;height:105px;padding:0;border:0;background:transparent;touch-action:none;cursor:grab;}
|
|
17
|
+
#pet:active {cursor:grabbing;}#pet svg {display:block;width:104px;height:104px;margin:auto;overflow:visible;}
|
|
18
|
+
.pet-name {display:block;position:absolute;bottom:0;left:0;right:0;font-size:10px;font-weight:600;color:var(--text-secondary);background:var(--bg-elevated);border:1px solid var(--border-default);border-radius:8px;width:max-content;padding:1px 7px;margin:auto;}
|
|
19
|
+
.shell,.ear,.arm,.foot {fill:var(--pet-shell);stroke:var(--pet-face);stroke-width:2.5;stroke-linejoin:round;}
|
|
20
|
+
.face {fill:var(--pet-face);}.shadow {fill:var(--pet-shadow);}.shine {stroke:var(--pet-eye);stroke-width:3;stroke-linecap:round;opacity:.45;fill:none;}
|
|
21
|
+
.eyes,.smile {fill:none;stroke:var(--pet-eye);stroke-width:3;stroke-linecap:round;}.smile {stroke-width:2;}.pi {fill:none;stroke:var(--pet-face);stroke-width:2;stroke-linecap:round;}
|
|
22
|
+
.creature {transform-origin:56px 96px;animation:breathe 4s ease-in-out infinite;}.eyes {transform-origin:56px 60px;animation:blink 6s ease-in-out infinite;}
|
|
23
|
+
body[data-notified="true"] .arm-right {transform-origin:88px 72px;animation:wave 1.2s ease-in-out 3;}
|
|
24
|
+
#badge {position:absolute;right:6px;top:12px;min-width:22px;height:22px;border-radius:12px;background:var(--bg-elevated);color:var(--text-primary);border:1px solid var(--border-default);font-size:11px;font-weight:700;line-height:20px;}
|
|
25
|
+
@keyframes breathe {50%{transform:translateY(-2px) rotate(1deg);}}@keyframes blink {0%,44%,48%,100%{transform:scaleY(1);}46%{transform:scaleY(.1);}}@keyframes wave {50%{transform:rotate(-22deg);}}
|
|
26
|
+
@media(prefers-reduced-motion:reduce) {*,*::before,*::after {animation:none!important;}}
|
package/desktop/pet.html
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
3
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self'; base-uri 'none'; form-action 'none'; frame-src 'none'; connect-src 'none'">
|
|
4
|
+
<title>Super Pi · 桌面宠物</title><link rel="stylesheet" href="pet.css"></head>
|
|
5
|
+
<body>
|
|
6
|
+
<section id="bubble" aria-label="Super Pi 桌面提醒" hidden>
|
|
7
|
+
<div class="bubble-heading"><span class="notification-mark" aria-hidden="true">π</span><span id="kind">SUPER PI</span><span id="count"></span><button id="collapse" title="收起气泡,稍后查看" aria-label="收起气泡">−</button></div>
|
|
8
|
+
<h1 id="title"></h1><p id="body"></p>
|
|
9
|
+
<div class="bubble-actions"><button id="open">打开会话 ↗</button><button id="dismiss">关闭此条</button></div>
|
|
10
|
+
</section>
|
|
11
|
+
<div class="pet-wrap" id="pet-wrap">
|
|
12
|
+
<button id="pet" aria-label="Super Pi 桌面宠物,拖动可移动,点击查看提醒" title="拖动移动 · 点击查看提醒 · 右键更多操作">
|
|
13
|
+
<svg viewBox="0 0 112 112" aria-hidden="true">
|
|
14
|
+
<ellipse class="shadow" cx="56" cy="102" rx="31" ry="5"/>
|
|
15
|
+
<g class="creature">
|
|
16
|
+
<path class="ear" d="M31 35Q21 12 34 13Q46 15 43 32M71 32Q69 14 81 13Q93 12 83 35"/>
|
|
17
|
+
<path class="arm arm-left" d="M24 65Q9 63 12 79Q16 84 25 78"/><path class="arm arm-right" d="M88 64Q101 57 101 70Q102 80 88 79"/>
|
|
18
|
+
<path class="foot" d="M33 88Q23 104 38 102L48 94M66 94L76 102Q91 104 80 88"/>
|
|
19
|
+
<path class="shell" d="M22 48Q22 29 42 29H70Q90 29 90 48V72Q90 95 69 95H43Q22 95 22 72Z"/>
|
|
20
|
+
<path class="shine" d="M31 46Q32 37 42 37H48"/>
|
|
21
|
+
<rect class="face" x="31" y="47" width="50" height="31" rx="13"/>
|
|
22
|
+
<g class="eyes"><path d="M43 58V62M69 58V62"/></g>
|
|
23
|
+
<path class="smile" d="M51 67Q56 72 61 67"/>
|
|
24
|
+
<path class="pi" d="M46 85H66M51 85V91M61 85V91"/>
|
|
25
|
+
</g>
|
|
26
|
+
</svg>
|
|
27
|
+
<span id="badge" hidden></span>
|
|
28
|
+
</button>
|
|
29
|
+
<span class="pet-name">Super Pi</span>
|
|
30
|
+
</div>
|
|
31
|
+
<script src="pet-renderer.js"></script>
|
|
32
|
+
</body></html>
|
package/desktop/preload.cjs
CHANGED
|
@@ -8,6 +8,8 @@ if (process.isMainFrame) {
|
|
|
8
8
|
restart: () => ipcRenderer.invoke("super-pi-desktop:restart"),
|
|
9
9
|
notifications: Object.freeze({
|
|
10
10
|
status: () => ipcRenderer.invoke("super-pi-desktop:notification-status"),
|
|
11
|
+
configure: value => ipcRenderer.invoke("super-pi-desktop:notification-configure", value),
|
|
12
|
+
clearSystem: () => ipcRenderer.invoke("super-pi-desktop:notification-clear-system"),
|
|
11
13
|
show: value => ipcRenderer.invoke("super-pi-desktop:notification-show", value),
|
|
12
14
|
close: id => ipcRenderer.invoke("super-pi-desktop:notification-close", id),
|
|
13
15
|
openSettings: () => ipcRenderer.invoke("super-pi-desktop:notification-settings"),
|
|
@@ -28,7 +30,8 @@ if (process.isMainFrame) {
|
|
|
28
30
|
const theme = getComputedStyle(root), background = color(theme.getPropertyValue("--bg-panel")), foreground = color(theme.getPropertyValue("--text-primary"));
|
|
29
31
|
const rgb = background.slice(1).match(/../g).map(value => parseInt(value, 16));
|
|
30
32
|
const dark = (rgb[0] * .2126 + rgb[1] * .7152 + rgb[2] * .0722) < 128;
|
|
31
|
-
|
|
33
|
+
const colors = Object.fromEntries(["--bg-elevated", "--bg-raised", "--text-primary", "--text-secondary", "--border-default", "--accent", "--accent-contrast", "--focus-ring", "--info"].map(name => [name, color(theme.getPropertyValue(name))]));
|
|
34
|
+
void ipcRenderer.invoke("super-pi-desktop:theme", { background, foreground, dark, colors }).then(value => { bar.dataset.platform = value.platform; icon.src = value.icon; }).catch(() => {});
|
|
32
35
|
};
|
|
33
36
|
new MutationObserver(sync).observe(root, { attributes: true, attributeFilter: ["data-theme"] });
|
|
34
37
|
sync();
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
|
-
"hash": "
|
|
2
|
+
"hash": "ffcf4185abbbb0719b0a22afb093b59fca97b53c09840614adb3466f0dacbd47",
|
|
3
3
|
"files": {
|
|
4
4
|
"src/client/AnchoredPopover.tsx": "3d683cc9e4305678141c83987a37a36b3da30e20d7bd17ea8e48a72504475605",
|
|
5
|
-
"src/client/App.tsx": "
|
|
5
|
+
"src/client/App.tsx": "d990e5fb7a61ce926266b82cde3d9cfd6d9d36f45b35c217344c9b2b52dde8eb",
|
|
6
6
|
"src/client/CacheWarmingSettings.tsx": "cce26c4547634b76c08c681a4b9605f884d8502f554f12ff8c30cbd2fd0bd9c0",
|
|
7
7
|
"src/client/CodeMirrorEditor.tsx": "39cabf374e344430f26cb7fcac654318bbbae99755aee1d7f119915bcb9fece5",
|
|
8
|
-
"src/client/ContextMeter.tsx": "
|
|
9
|
-
"src/client/DesktopPanel.tsx": "
|
|
8
|
+
"src/client/ContextMeter.tsx": "305f7e7ab333299b8254a921c487e238b440340b10dcff39c67eca0bf9da7713",
|
|
9
|
+
"src/client/DesktopPanel.tsx": "1011e9409418afa64cd7c84d8131223b3099bd0842c24ebbda86e38b45f37e1c",
|
|
10
10
|
"src/client/EntryIntegrationNotice.tsx": "b758ed02def94086d8180b0baffbf214df1a82cfdbdeb7d8201d26d4a1a0bbfb",
|
|
11
11
|
"src/client/ErrorBoundary.tsx": "d16376f9f6c7cc1fab8590c65a66438127642f7d6bb8023cec53d8a6cc9f3964",
|
|
12
12
|
"src/client/FeishuPanel.tsx": "3b3257da36bf863e004a33a4c1d721db364b4449fb23f0805cb74b973a2ed2da",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
"src/client/ServerConnectionStatus.tsx": "d49b92bb8de4853fe15ddc171ef78e3e134bc704eeb19a033f49ba983c047e7f",
|
|
42
42
|
"src/client/ServerConnectionsPanel.tsx": "0e19b52a945d9fa5d57de806ba52c3ced85628b438e51edbeeede3220625a7a0",
|
|
43
43
|
"src/client/SidebarSection.tsx": "579c014caeddd94d21911d7b9eca4ceef930ca13c2baeb7bf5ffba59c2bb0b75",
|
|
44
|
-
"src/client/SlashCommandMenu.tsx": "
|
|
44
|
+
"src/client/SlashCommandMenu.tsx": "97920f27715329372dd841bec5d345f9a6bd308dd50b2adbe49acf52ebced91e",
|
|
45
45
|
"src/client/SoftwareUpdate.tsx": "1c6402758db5dc780d357a76c61d9d06fdf1d46af0142d19d3d76c53431ea176",
|
|
46
46
|
"src/client/SshVerificationForm.tsx": "8d7968822203e2404742f9fb6dde24656c97541628999e1d8cd34c8652c1c23e",
|
|
47
|
-
"src/client/StatusBarMenu.tsx": "
|
|
47
|
+
"src/client/StatusBarMenu.tsx": "4ea2359362fb8c8096c8ec6920b4e64d11ad6133c370bb4ca87989144357ac10",
|
|
48
48
|
"src/client/StatusWorktreePicker.tsx": "a38edce2db10a12fe01b53f7f86c610da29841d32c516be967e8d6d574153cf6",
|
|
49
49
|
"src/client/Tabs.tsx": "507aed9c2f25284e5fba70d5a4b9ec2835c01c33eabcb7b91eba33bfb53acb5d",
|
|
50
50
|
"src/client/TavilyPanel.css": "22d4fb4a1bc95b2e0a96c49b9650a56f1a6cf7cfc3c6bc68564417d2c268e193",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"src/client/TeamHandoffCard.tsx": "925284ab81c7845c5cfdcfa1f631e124bb02d7d86b03ede8f3fbabc194c32dca",
|
|
53
53
|
"src/client/TerminalPanel.tsx": "13f288575499103254597e38813ef5cf5fe2b1230e343ede767b6b55a1b035a2",
|
|
54
54
|
"src/client/ToolGlyph.tsx": "a1100b61f1eee9520e7323385f667898763bfd69068f22de7dd36db2d4096c76",
|
|
55
|
-
"src/client/TranscriptFind.tsx": "
|
|
55
|
+
"src/client/TranscriptFind.tsx": "b6e6ea7a75cef5feb28efb9ba5d80d36cd016f6a9b7673c410fd3ab1ca15bbe7",
|
|
56
56
|
"src/client/WorkbenchChrome.tsx": "9a7f761a547a627227302746a20d849f82e04062b40c9b60d0ecaf90c679543a",
|
|
57
57
|
"src/client/WorkbenchSearch.tsx": "e29767e6596d8c29d386cd16fe43db31d565cdffe5d5a3ef972376b17b62271d",
|
|
58
58
|
"src/client/WorkbenchSearchPanel.tsx": "44194765bdb4d15240fbb899a18a52bd85baec5d9ebea26762de319eab0f2341",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"src/client/anchored-popover.css": "1d617952563b642f94d367e62e64aa97514c5aca09aaa128a82ad0b8c320f556",
|
|
65
65
|
"src/client/archive-confirm.ts": "a559c1d251e2e3495519d009c50e3adcaaae5859566290c6b8ffef554ddf268c",
|
|
66
66
|
"src/client/clipboard.ts": "54c7b134515f175acb8befa8e19c55f1c048c3245a7edc2cfc4d233b7593f782",
|
|
67
|
-
"src/client/context-meter.css": "
|
|
67
|
+
"src/client/context-meter.css": "8795907ff6901326c05449af12b82449be8aea24b12f4016ab51954ab535f518",
|
|
68
68
|
"src/client/diff-context-scroll.ts": "11f27a1f56c6ec77bf138119c4d00f798e553852d8de07fe258e4af090adfda1",
|
|
69
69
|
"src/client/diff-layout.ts": "0ca8a64f3cfd3355ebb28542c0bb3ecb52379e3145b45c91a6ef180be2f6f805",
|
|
70
70
|
"src/client/editor-blame.ts": "d680671b98c64f8ba7f639f660f6b4aab0bf112fc4695c436c9d2a505326b0b0",
|
|
@@ -86,6 +86,7 @@
|
|
|
86
86
|
"src/client/markdown.ts": "76c5cad372823701fa62951a517b21b1807cd1e6f4a73e80922e668299f28d31",
|
|
87
87
|
"src/client/model-discovery.css": "495090f6b4d80d03cfa69c9786d650b3c2d8e57550a4b947768ed1c943c70a4d",
|
|
88
88
|
"src/client/native-tools.css": "71bbb365a91105be0925acce27f1e1ea5e0c3369aa5137060d2bc426682e113d",
|
|
89
|
+
"src/client/notification-channels.css": "f016ad41d3698c12b90546521cd4de2323702f52bbb69bf17018d09c1cb789a6",
|
|
89
90
|
"src/client/pending-operations.ts": "8a5f9e9711c0f875c8ed194196c218162de5270298dad4091351d41294c859d7",
|
|
90
91
|
"src/client/project-evidence.ts": "3bc5ea85f6b20a19a36cfdd4a958d83dd53b21f3d8f20fae1914a575dfbad3c4",
|
|
91
92
|
"src/client/reader-recovery.ts": "a72b6255bc66c5585bc5ec6f9eb6ab5e3cdea0edd7582408a0c2881e6417255f",
|
|
@@ -97,24 +98,24 @@
|
|
|
97
98
|
"src/client/server-scope.ts": "34d891ce8efe3b032047814324b06f588f2424d8124c23212a5cff907fa17628",
|
|
98
99
|
"src/client/session-tree.ts": "08a14c6611fdd9a72001eb1672060479e7660de5a5d221c7e80036209fd26546",
|
|
99
100
|
"src/client/shared-read-receipts.ts": "3554e6f85c20d2c2228cca02579b1e5bc2c1c9a3fff7caa4421055d564a04e9b",
|
|
100
|
-
"src/client/slash-commands.ts": "
|
|
101
|
+
"src/client/slash-commands.ts": "daa5a8e6f90605a9a3921c977b24f69e9d9718e31a62a4b8e74a71a1faf0ce66",
|
|
101
102
|
"src/client/software-update.css": "a3bb42e3bc832639d23a54a4e91216192cbb05efa1d41151e64571d883866258",
|
|
102
|
-
"src/client/status-bar-menu.css": "
|
|
103
|
+
"src/client/status-bar-menu.css": "05acaa1cc032a026ad3328d9d2c32a96e2e9e5ef335536646eacad0a33af76af",
|
|
103
104
|
"src/client/styles.css": "ecd20554b663c6c546e3752e0485517b1c40762707284caee67825255f6548f7",
|
|
104
|
-
"src/client/system-notifications.ts": "
|
|
105
|
+
"src/client/system-notifications.ts": "5c3d1b5575fd6f42a1d6176f599f918a35054c23281309f78cbb6899d8d2da21",
|
|
105
106
|
"src/client/terminal-emulator.ts": "ffcc4f5fbddaf25cebcc9e03dbe5d7d0ad2c21586f5d169e57c04c82e2308b3b",
|
|
106
|
-
"src/client/theme.tsx": "
|
|
107
|
+
"src/client/theme.tsx": "4f806b512d894b1f34b86f9d215af541618bc68443f96adde230fb7efb9f5a77",
|
|
107
108
|
"src/client/tool-frame-bridge.ts": "74b8afda4fe321101124cadee6e79ada2d733f05af05d4953d0530d3ed3c2a36",
|
|
108
109
|
"src/client/tool-launcher.ts": "9699c9498c905e395bbe89e0e367721ab253b5ec1e318a8093ce6a88c2ff5c29",
|
|
109
110
|
"src/client/tool-sharing.ts": "011212825dbbffe18c8f15aca721c02938ab6273fb5607b072a1e7b8b1853640",
|
|
110
111
|
"src/client/tool-shortcuts.ts": "4422d29ba770af6acef18e66c6be05a9bc021f7323c7ca28bbe7668f26d4adb8",
|
|
111
112
|
"src/client/tools.ts": "58fe41f0edbd490e3fab7f12f258b1dbc2163b653553b03ac61caf1543618e50",
|
|
112
113
|
"src/client/transcript-find.css": "3cd920b9580c06065d656b41fde677703b6b29b96fed76e5056d55381bc2c594",
|
|
113
|
-
"src/client/types.ts": "
|
|
114
|
+
"src/client/types.ts": "61a0639bff9cce59518ec11c36ee73359588bbea2b6dec18ee2818c4081264b9",
|
|
114
115
|
"src/client/vite-env.d.ts": "65996936fbb042915f7b74a200fcdde7e410f32a669b1ab9597cfaa4b0faddb5",
|
|
115
116
|
"src/client/workbench-memory.ts": "72c9b52cc28f8c8e90636c2425f0d14c4b5af1e36bff9bf8ad272d0811e60099",
|
|
116
117
|
"src/client/workbench-navigation.ts": "3b229752a8ce4a45eba7aeff040eb33001413190141f1e9b8e5f38246a1761e2",
|
|
117
118
|
"src/client/workbench-search-panel.css": "6978c03db4f17411e9064242b0ff786a520ee8cf58fe8a9d0ea42872ba3737f0"
|
|
118
119
|
},
|
|
119
|
-
"recordedAt": "2026-11-
|
|
120
|
+
"recordedAt": "2026-11-24T04:36:08.430Z"
|
|
120
121
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/dist-D978o95T.js","assets/rolldown-runtime-XKyaHtl9.js","assets/dist-B3-a6uF0.js","assets/dist-CX_Hm4GS.js","assets/dist-Cus6_oaF.js","assets/dist-J6XWqRpB.js","assets/dist-scBkrwv-.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{c as t,d as n,f as r,l as i,n as a,r as o,u as s}from"./index-
|
|
2
|
+
import{r as e}from"./rolldown-runtime-XKyaHtl9.js";import{c as t,d as n,f as r,l as i,n as a,r as o,u as s}from"./index-C7o39I4j.js";var c=e(r(),1);function l(e,t){return[t.search({top:!0}),e.EditorState.phrases.of({Find:`查找`,Replace:`替换为`,next:`下一处`,previous:`上一处`,all:`全部选中`,"match case":`区分大小写`,regexp:`正则表达式`,"by word":`全词匹配`,replace:`替换`,"replace all":`全部替换`,close:`关闭查找`,"current match":`当前匹配`,"on line":`所在行`})]}var u=n(),d=262144,f=131072;function p(e){return e.split(`.`).pop()?.toLowerCase()??``}function m(e,t,n=!1){let r=e=>n?`var(--git-diff-${e.slice(5)}, var(${e}))`:`var(${e})`;return e.HighlightStyle.define([{tag:t.tags.keyword,color:r(`--cm-keyword`)},{tag:t.tags.string,color:r(`--cm-string`)},{tag:t.tags.number,color:r(`--cm-number`)},{tag:t.tags.comment,color:r(`--cm-comment`),fontStyle:`italic`},{tag:t.tags.function(t.tags.variableName),color:r(`--cm-function`)},{tag:t.tags.typeName,color:r(`--cm-type`)},{tag:t.tags.className,color:r(`--cm-type`)},{tag:t.tags.propertyName,color:r(`--cm-property`)},{tag:t.tags.operator,color:r(`--cm-operator`)},{tag:t.tags.variableName,color:r(`--cm-variable`)}])}function h({path:e,value:n,onChange:r,jumpToLine:h,onSave:g,workspaceId:_,blame:v,onPosition:y,readOnly:b=!1,languageOverride:x}){let S=(0,c.useRef)(null),C=(0,c.useRef)(null),w=(0,c.useRef)(null),T=(0,c.useRef)(void 0),E=(0,c.useRef)(null),D=(0,c.useRef)(null),O=(0,c.useRef)(null),k=(0,c.useRef)(null),A=(0,c.useRef)(null),j=(0,c.useRef)(null),M=(0,c.useRef)(r),N=(0,c.useRef)(g);M.current=r,N.current=g;let[P,F]=(0,c.useState)(!1),[I,L]=(0,c.useState)(!1),[R,z]=(0,c.useState)(`0,0`),[B,V]=(0,c.useState)(0);(0,c.useEffect)(()=>{let t=!1,r,a,c,u,f;return(async()=>{try{let h=x??p(e),g=i(h),[v,y,P,I,R,B,H,U]=await Promise.all([s(()=>import(`./dist-D978o95T.js`).then(e=>e.S),__vite__mapDeps([0,1])),s(()=>import(`./dist-B3-a6uF0.js`).then(e=>e.s),__vite__mapDeps([2,1,0])),s(()=>import(`./dist-CX_Hm4GS.js`),__vite__mapDeps([3,0,1,2,4,5])),s(()=>import(`./dist-scBkrwv-.js`),__vite__mapDeps([6,0,1,2])),s(()=>import(`./dist-J6XWqRpB.js`).then(e=>e.d),__vite__mapDeps([5,1,0,2,4])),s(()=>import(`./dist-Cus6_oaF.js`).then(e=>e.n),__vite__mapDeps([4,1])),g?g().catch(e=>(console.warn(`[CodeMirror] Failed to load language for .${h}:`,e),null)):Promise.resolve(null),o().catch(e=>(console.warn(`[CodeMirror] Failed to build the blame extension:`,e),null))]);if(t||!S.current)return;w.current=y.EditorView,u=R,f=B,D.current=v.Annotation.define(),O.current=v.Transaction.addToHistory;let W=n.length<=d&&H!==null;a=new v.Compartment;let G=[y.lineNumbers(),y.highlightActiveLine(),y.drawSelection(),P.history(),y.keymap.of([P.indentWithTab,...P.defaultKeymap,...P.historyKeymap,...I.searchKeymap,{key:`Mod-s`,run:()=>(N.current(),!0)}]),y.EditorView.updateListener.of(e=>{e.docChanged&&!(D.current&&e.transactions.some(e=>e.annotation(D.current)===!0))&&M.current(e.state.doc.toString()),e.selectionSet&&z(`${e.state.selection.main.from},${e.state.selection.main.to}`)}),y.EditorView.domEventHandlers({mousedown:(e,t)=>(t.focus(),!1)})];if(G.push(l(v,I)),b&&G.push(v.EditorState.readOnly.of(!0),y.EditorView.editable.of(!1),y.EditorView.contentAttributes.of({tabindex:`0`})),U&&!b&&(c=new v.Compartment,G.splice(1,0,c.of([])),G.push(U.base)),H)try{G.push(H)}catch(e){console.warn(`[CodeMirror] Failed to apply language extension for .${h}:`,e),W=!1}if(W&&a&&u&&f)try{G.push(a.of(u.syntaxHighlighting(m(u,f))))}catch(e){console.warn(`[CodeMirror] Failed to attach syntaxHighlighting for .${h}:`,e),W=!1}let K=T.current,q=K?.scope===JSON.stringify([_,e])&&K.state.doc.toString()===n,J=q?K.state.update({effects:v.StateEffect.reconfigure.of(G)}).state:v.EditorState.create({doc:n,extensions:G});if(r=new y.EditorView({state:J,parent:S.current}),q&&(r.scrollDOM.scrollTop=K.top,r.scrollDOM.scrollLeft=K.left),t){r.destroy();return}C.current=r,F(W),L(!0),k.current=U,A.current=c??null,j.current=null,V(e=>e+1);let Y=new MutationObserver(()=>{let e=C.current;if(e&&W&&a&&u&&f)try{e.dispatch({effects:a.reconfigure(u.syntaxHighlighting(m(u,f)))})}catch{}});E.current=Y,Y.observe(document.documentElement,{attributes:!0,attributeFilter:[`data-theme`]})}catch(e){console.error(`[CodeMirror] Fatal editor initialization error:`,e),t||L(!0)}})(),()=>{t=!0,E.current?.disconnect(),E.current=null,r&&(T.current={scope:JSON.stringify([_,e]),state:r.state,top:r.scrollDOM.scrollTop,left:r.scrollDOM.scrollLeft}),r?.destroy(),C.current=null,L(!1),S.current&&(S.current.textContent=``)}},[e,b,x]),(0,c.useEffect)(()=>{let e=C.current;if(!e)return;let t=e.state.doc.toString();t!==n&&e.dispatch({changes:{from:0,to:t.length,insert:n},annotations:D.current?D.current.of(!0):void 0})},[n]),(0,c.useEffect)(()=>{let e=C.current;if(!e||!h)return;let t=e.state.doc.line(Math.min(Math.max(1,h.line),e.state.doc.lines)),n=Math.min(t.to,t.from+(h.column??1)-1);e.dispatch({selection:{anchor:t.to,head:n},effects:w.current?.scrollIntoView(n,{y:`start`,yMargin:Math.round(e.scrollDOM.clientHeight/3)})}),e.focus()},[h,I]);let H=!!(v&&v.state===`ready`&&v.response&&v.path===e&&v.workspaceId===_);(0,c.useEffect)(()=>{let t=C.current,n=k.current,r=A.current;if(!t||!n||!r)return;let i=v&&v.state===`ready`&&v.response&&v.path===e&&v.workspaceId===_?v.response:null,o=i?a(i):null;j.current!==o&&(j.current=o,t.dispatch({effects:[n.setBlame.of(o),r.reconfigure(o?n.gutter:[])]}))},[v?.state,v?.response,v?.path,v?.workspaceId,e,_,B]);let U=C.current?.state.doc.toString()??n,W=U.length<=f?U:U.slice(0,f),G=x??p(e),K=t(G),q=C.current?.state,J=q?.selection.main.head,Y=J===void 0?void 0:q?.doc.lineAt(J),X=Y?.number,Z=J!==void 0&&Y?J-Y.from+1:void 0;return(0,c.useEffect)(()=>{I&&X!==void 0&&Z!==void 0&&y?.({line:X,column:Z,language:P&&K||`纯文本`,highlight:P?G:`plain`})},[I,X,Z,P,K,G,y]),(0,c.useEffect)(()=>()=>y?.(),[y]),(0,u.jsxs)(`div`,{className:`file-cm-wrap`,"data-file-text":e,"data-file-content":W,"data-file-content-truncated":U.length>f?`1`:`0`,"data-file-selection":R,"data-file-editor-ready":I?`1`:`0`,"data-file-blame-gutter":H?`1`:void 0,onMouseDown:()=>C.current?.focus(),children:[(0,u.jsx)(`div`,{className:`file-cm`,ref:S,"aria-label":`${b?`查看`:`编辑`} ${e}`}),(!I||!y)&&(0,u.jsxs)(`div`,{className:`file-editor-status`,children:[!I&&(0,u.jsx)(`span`,{"data-file-editor-loading":`1`,children:`正在加载编辑器…`}),I&&J!==void 0&&Y&&(0,u.jsxs)(`span`,{children:[`第 `,Y.number,` 行,第 `,J-Y.from+1,` 列`]}),I&&!P&&(0,u.jsx)(`span`,{"data-file-highlight-status":`plain`,children:`纯文本`}),I&&P&&K&&(0,u.jsx)(`span`,{"data-file-highlight-status":G,children:K})]})]})}export{h as CodeMirrorEditor,l as t,m as themeHighlightStyle};
|