跳到主要内容

Claude Cage · 面向 Claude 的隔离开发环境,支持桌面工作台、多账号、远程部署与移动端连接。上游 Lee-xeo/Claude-Cage 完整源码镜像,非灵栈原创;主许可 MIT,第三方组件遵循各自许可。来源:https://github.com/Lee-xeo/Claude-Cage 。手动同步,不附带 Release 安装包。

浏览文件

cage-wheel.js

62 行 · 2.1 KB历史下载
1/*
2 * Cage workbench pixel wheel.
3 * Licensed under MPL 2.0 (see LICENSE.txt)
4 */
5
6// Cage's own display server takes the scrolled distance in one message,
7// where RFB sends a press and a release for each fixed step.
8export const cageWheelEncoding = -57345;
9export const cageWheelCapability = 'cage-wheel-v1';
10export const cageWheelMessage = 180;
11export const cageWheelLimit = 2048;
12
13// type, padding, x, y, then the signed horizontal and vertical distance.
14export function cageWheelPacket(x, y, dx, dy) {
15 const packet = new Uint8Array(14), view = new DataView(packet.buffer);
16 packet[0] = cageWheelMessage;
17 view.setUint16(2, x);
18 view.setUint16(4, y);
19 view.setInt32(6, dx);
20 view.setInt32(10, dy);
21 return packet;
22}
23
24// A trackpad reports many small distances, and each message is a round trip
25// to the guest. The first goes out at once; later ones are added up and sent
26// once per frame. Distance beyond the limit of one message stays for the next.
27export default class CageWheel {
28 constructor(send, schedule = callback => requestAnimationFrame(callback),
29 cancel = handle => cancelAnimationFrame(handle)) {
30 this._send = send;
31 this._schedule = schedule;
32 this._cancel = cancel;
33 this._x = this._y = this._dx = this._dy = 0;
34 this._frame = null;
35 }
36
37 add(x, y, dx, dy) {
38 this._x = x;
39 this._y = y;
40 this._dx += dx;
41 this._dy += dy;
42 if (this._frame === null) this._flush();
43 }
44
45 _flush() {
46 this._frame = null;
47 const dx = Math.max(-cageWheelLimit, Math.min(cageWheelLimit, Math.round(this._dx)));
48 const dy = Math.max(-cageWheelLimit, Math.min(cageWheelLimit, Math.round(this._dy)));
49 // Less than a pixel waits for the next event.
50 if (!dx && !dy) return;
51 this._dx -= dx;
52 this._dy -= dy;
53 this._send(this._x, this._y, dx, dy);
54 this._frame = this._schedule(() => this._flush());
55 }
56
57 stop() {
58 if (this._frame !== null) this._cancel(this._frame);
59 this._frame = null;
60 this._dx = this._dy = 0;
61 }
62}