跳到主要内容

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

浏览文件

cage-browser-display.js

57 行 · 1.9 KB历史下载
1/*
2 * Cage workbench browser display, based on noVNC Display.
3 * Licensed under MPL 2.0 (see LICENSE.txt)
4 */
5
6import Display from './display.js';
7
8export default class CageBrowserDisplay extends Display {
9 autoscale() {
10 // CSS follows the pane in the same layout pass, even before the guest
11 // receives its first resize request.
12 this._target.style.width = '100%';
13 this._target.style.height = '100%';
14 }
15
16 absX(x) {
17 const width = this._target.getBoundingClientRect().width;
18 return width ? Math.floor(x * this.width / width) : 0;
19 }
20
21 absY(y) {
22 const height = this._target.getBoundingClientRect().height;
23 return height ? Math.floor(y * this.height / height) : 0;
24 }
25
26 resize(width, height) {
27 if (!this.width || !this.height) {
28 super.resize(width, height);
29 return;
30 }
31 if (this.width === width && this.height === height) return;
32
33 const previous = this._backbuffer;
34 const next = document.createElement('canvas');
35 next.width = width;
36 next.height = height;
37 const ctx = next.getContext('2d');
38
39 // The decoder needs the unscaled overlap for incremental updates and CopyRect.
40 ctx.drawImage(previous, 0, 0);
41
42 // Reuse the retiring buffer to hold the last presented frame while
43 // resizing the canvas. Its edges stay painted until the refresh arrives.
44 this._drawCtx.globalCompositeOperation = 'copy';
45 this._drawCtx.drawImage(this._target, 0, 0);
46 this._target.width = width;
47 this._target.height = height;
48 this._targetCtx.drawImage(previous, 0, 0, width, height);
49 previous.width = 0;
50
51 this._backbuffer = next;
52 this._drawCtx = ctx;
53 this._prevDrawStyle = '';
54 this._fbWidth = this._viewportLoc.w = width;
55 this._fbHeight = this._viewportLoc.h = height;
56 }
57}