dsh-chrome-bridge 1.20.0 → 2.0.0
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.en.md +6 -2
- package/README.md +6 -2
- package/client.js +110 -29
- package/core/ext.js +119 -0
- package/core/hosts.js +277 -0
- package/core/locale.js +8 -0
- package/core/receipt.js +56 -0
- package/core/session.js +157 -0
- package/core/shots.js +56 -0
- package/core/tooldef.js +142 -0
- package/core/transport.js +212 -0
- package/core/upload.js +59 -0
- package/devtools.js +18 -8
- package/download.js +879 -60
- package/drag.js +38 -20
- package/features/frames.js +58 -0
- package/features/gif.js +203 -0
- package/features/index.js +1 -0
- package/features/mock-har.js +85 -0
- package/features/record.js +225 -0
- package/i18n/en.js +168 -16
- package/i18n/ru.js +168 -16
- package/i18n/zh.js +168 -16
- package/image-guard.js +13 -6
- package/index.js +17 -1155
- package/locale/ru.json +7 -0
- package/nav.js +43 -5
- package/package.json +8 -1
- package/panel.js +10 -1
- package/refs.js +275 -230
- package/setup.js +214 -46
- package/tools/click.js +58 -0
- package/tools/devtools.js +61 -0
- package/tools/dialog.js +22 -0
- package/tools/download.js +50 -0
- package/tools/drag.js +61 -0
- package/tools/eval.js +22 -0
- package/tools/fill.js +77 -0
- package/tools/handoff.js +40 -0
- package/tools/index.js +38 -0
- package/tools/input.js +147 -0
- package/tools/nav.js +57 -0
- package/tools/read.js +87 -0
- package/tools/record.js +120 -0
- package/tools/screenshot.js +223 -0
- package/tools/tabs.js +131 -0
- package/tools/wait.js +56 -0
- package/vendor/cb +616 -35
- package/vendor/extension/_locales/en/messages.json +3 -0
- package/vendor/extension/_locales/ru/messages.json +3 -0
- package/vendor/extension/_locales/zh_CN/messages.json +3 -0
- package/vendor/extension/_locales/zh_TW/messages.json +3 -0
- package/vendor/extension/background.js +2 -1969
- package/vendor/extension/confirm.css +148 -0
- package/vendor/extension/confirm.html +49 -0
- package/vendor/extension/confirm.js +188 -0
- package/vendor/extension/in-page-cursor.js +599 -0
- package/vendor/extension/manifest.json +11 -2
- package/vendor/extension/popup.css +99 -5
- package/vendor/extension/popup.html +28 -2
- package/vendor/extension/popup.js +430 -45
- package/vendor/extension/sw/boot.js +111 -0
- package/vendor/extension/sw/cdp.js +411 -0
- package/vendor/extension/sw/chooser.js +192 -0
- package/vendor/extension/sw/confirm.js +608 -0
- package/vendor/extension/sw/cursor.js +241 -0
- package/vendor/extension/sw/dispatch.js +129 -0
- package/vendor/extension/sw/download.js +279 -0
- package/vendor/extension/sw/fetch-hub.js +224 -0
- package/vendor/extension/sw/frames.js +651 -0
- package/vendor/extension/sw/imaging.js +361 -0
- package/vendor/extension/sw/native.js +111 -0
- package/vendor/extension/sw/net-tools.js +525 -0
- package/vendor/extension/sw/ops.js +829 -0
- package/vendor/extension/sw/popup-api.js +303 -0
- package/vendor/extension/sw/profile.js +166 -0
- package/vendor/extension/sw/record.js +494 -0
- package/vendor/extension/sw/state.js +161 -0
- package/vendor/extension/sw/tabui.js +219 -0
- package/vendor/extension/sw/util.js +166 -0
- package/vendor/extension/sw/welcome.js +26 -0
- package/vendor/extension/sw/windows.js +94 -0
- package/vendor/extension/welcome.css +189 -0
- package/vendor/extension/welcome.html +70 -0
- package/vendor/extension/welcome.js +157 -0
- package/vendor/host/host.js +476 -71
- package/vendor/in-page-cursor.js +309 -37
- package/vendor/skill/SKILL.md +34 -16
|
@@ -0,0 +1,599 @@
|
|
|
1
|
+
// 页内光标浮层(v5)—— 让用户一眼看出 DSH 在页面里干什么,人一伸手它就让路
|
|
2
|
+
//
|
|
3
|
+
// 不是系统光标,是注进页面的一层 DOM。扩展用 Runtime.evaluate 或
|
|
4
|
+
// chrome.scripting.executeScript({ files: ['in-page-cursor.js'], world: 'MAIN' }) 注入一次,之后调:
|
|
5
|
+
// window.__dshCursor.move(x, y, { duration?, straight? }) 沿弧线滑到视口坐标,返回动画时长(ms)
|
|
6
|
+
// window.__dshCursor.place(x, y) 直接摆过去(新页面接着上一页的位置出现)
|
|
7
|
+
// window.__dshCursor.click(x, y, n) 按下 + 涟漪(n=2 双击两圈)
|
|
8
|
+
// window.__dshCursor.press() 只做按下反馈
|
|
9
|
+
// window.__dshCursor.down() / up() 拖拽:按住 / 松开
|
|
10
|
+
// window.__dshCursor.label(text, ms) 名牌从「DSH」展开成「DSH · 点击 登录」,过会儿收回
|
|
11
|
+
// window.__dshCursor.scroll(dy) 滚动提示
|
|
12
|
+
// window.__dshCursor.pos() 当前位置 { x, y }
|
|
13
|
+
// window.__dshCursor.hide() 淡出并移除光标(协作浮条不受影响)
|
|
14
|
+
// v5 新增 —— 分清人和 DSH、把页面交给人:
|
|
15
|
+
// beginAgent(ms = 1500) 接下来 ms 毫秒里的输入算 DSH 自己发的(CDP 发的事件也是 isTrusted,只能靠这个窗口分)
|
|
16
|
+
// endAgent(graceMs = 120) 动作做完,窗口收到 graceMs 后结束
|
|
17
|
+
// takeover() 12 秒内人按过鼠标 / 键盘(不在 DSH 的窗口里)→ { at, type },否则 null
|
|
18
|
+
// clearTakeover() 清掉「人接手了」的记号
|
|
19
|
+
// showHandoff({ id, reason, title, doneLabel }) 页面顶部居中弹出协作浮条,人点「完成」就交回
|
|
20
|
+
// handoffStatus(id) 'done'(人点了完成)/ 'waiting'(浮条还在)/ 'gone'(浮条没了,比如页面跳走)
|
|
21
|
+
// hideHandoff() 收掉浮条并清状态
|
|
22
|
+
//
|
|
23
|
+
// 设计要点:
|
|
24
|
+
// * 外观学多人协作工具(Figma 那种):箭头 + 跟着走的名牌,谁在动一眼就知道
|
|
25
|
+
// * 跟桌面光标(dsh-mac-computer-use)同一个箭头、同一个蓝、同一套动效;区分靠两样:
|
|
26
|
+
// 浏览器这边半透明、淡一些,名牌带地球图标;桌面那边实心,名牌带显示器图标
|
|
27
|
+
// * 动效走克制路线,跟桌面光标同一个弹簧、同一套算法:沿轻微的弧线滑过去,先快后慢,
|
|
28
|
+
// 顺着速度方向轻轻拉长、略侧倾,名牌晚半拍跟上,到了冲过头最多 3px 再落回;
|
|
29
|
+
// 点击时以尖端为支点缩一下,一圈淡波纹
|
|
30
|
+
// * 距离越远走得越久(上限 0.62 秒),跟扩展里点击前的等待(≤0.7 秒)配套
|
|
31
|
+
// * 动画全用 Web Animations(按时间算,不靠 requestAnimationFrame):后台标签页 rAF 停了也不会卡在半路,
|
|
32
|
+
// 截图拍到的永远是该在的位置
|
|
33
|
+
// * 进浏览器 top layer(popover):页面开了模态框 / 全屏也盖不住它
|
|
34
|
+
// * 自定义元素 + Shadow DOM + all:initial:页面 CSS 影响不到它;光标 pointer-events:none:绝不挡真实点击
|
|
35
|
+
// * 全用 DOM API 搭(不拼 HTML 字符串):Gmail 这类开了 Trusted Types 的站点也能注入
|
|
36
|
+
// * 贴边自动翻:名牌靠右 / 靠下放不下就翻到左边 / 上面,不会被视口切掉
|
|
37
|
+
// * 三段淡出:6 秒没动作变淡、15 秒没动作隐身,下一个动作立刻回来;人的鼠标凑到 72px 以内就几乎透明,不挡字
|
|
38
|
+
// * 人一按鼠标 / 键盘就让路(淡出),并记下「人接手了」,扩展据此停手
|
|
39
|
+
// * 协作浮条:只有浮条本身接收点击,页面其余地方照常能点;跟着系统深浅色走
|
|
40
|
+
// * 系统开了「减少动态效果」就不做动画
|
|
41
|
+
|
|
42
|
+
(() => {
|
|
43
|
+
const VERSION = 5;
|
|
44
|
+
const TAG = 'dsh-cursor';
|
|
45
|
+
const BAR_TAG = 'dsh-handoff';
|
|
46
|
+
const prev = window.__dshCursor;
|
|
47
|
+
const old = document.querySelector(TAG) || document.getElementById('__dsh_cursor__');
|
|
48
|
+
if (old && prev && prev.version === VERSION && old.isConnected) return 'ready';
|
|
49
|
+
|
|
50
|
+
// 换代 / 重注:位置、人机窗口、接手记号、没点完的协作浮条都接着用
|
|
51
|
+
let keep = null;
|
|
52
|
+
let carry = null;
|
|
53
|
+
try { keep = old && prev && prev.pos ? prev.pos() : null; } catch {}
|
|
54
|
+
try { carry = prev && typeof prev.__state === 'function' ? prev.__state() : null; } catch {}
|
|
55
|
+
try { if (prev && typeof prev.__teardown === 'function') prev.__teardown(); } catch {}
|
|
56
|
+
if (old) old.remove();
|
|
57
|
+
for (const n of document.querySelectorAll(BAR_TAG)) n.remove();
|
|
58
|
+
|
|
59
|
+
const reduce = () => { try { return matchMedia('(prefers-reduced-motion: reduce)').matches; } catch { return false; } };
|
|
60
|
+
const SVG = 'http://www.w3.org/2000/svg';
|
|
61
|
+
const el = (tag, cls) => { const e = document.createElement(tag); if (cls) e.className = cls; return e; };
|
|
62
|
+
const svgEl = (tag, attrs) => {
|
|
63
|
+
const e = document.createElementNS(SVG, tag);
|
|
64
|
+
for (const k in attrs) e.setAttribute(k, attrs[k]);
|
|
65
|
+
return e;
|
|
66
|
+
};
|
|
67
|
+
const hostCss = (extra) => [
|
|
68
|
+
'all:initial', 'display:block', 'position:fixed', 'margin:0', 'padding:0', 'border:0',
|
|
69
|
+
'background:transparent', 'overflow:visible', 'z-index:2147483647', ...extra,
|
|
70
|
+
].map((s) => s + ' !important').join(';');
|
|
71
|
+
/** 样式优先走 adoptedStyleSheets(页面 CSP 不许内联 <style> 时也生效),不行再退回 <style> */
|
|
72
|
+
const adopt = (root, css) => {
|
|
73
|
+
try {
|
|
74
|
+
const sheet = new CSSStyleSheet();
|
|
75
|
+
sheet.replaceSync(css);
|
|
76
|
+
root.adoptedStyleSheets = [sheet];
|
|
77
|
+
return;
|
|
78
|
+
} catch {}
|
|
79
|
+
const s = document.createElement('style');
|
|
80
|
+
s.textContent = css;
|
|
81
|
+
root.append(s);
|
|
82
|
+
};
|
|
83
|
+
/** top layer:模态框、全屏元素也在 top layer 里,后进的在上面 —— 有它们的时候重新进一次,保证我们在最上面 */
|
|
84
|
+
const raiseHost = (h) => {
|
|
85
|
+
try {
|
|
86
|
+
if (!h.isConnected) return;
|
|
87
|
+
if (!h.hasAttribute('popover')) h.setAttribute('popover', 'manual');
|
|
88
|
+
const covered = document.fullscreenElement || document.querySelector('dialog:modal');
|
|
89
|
+
if (h.matches(':popover-open')) {
|
|
90
|
+
if (!covered) return;
|
|
91
|
+
h.hidePopover();
|
|
92
|
+
}
|
|
93
|
+
h.showPopover();
|
|
94
|
+
} catch {}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const host = document.createElement(TAG);
|
|
98
|
+
host.setAttribute('aria-hidden', 'true');
|
|
99
|
+
host.style.cssText = hostCss(['inset:0 auto auto 0', 'width:0', 'height:0', 'pointer-events:none', 'contain:layout style']);
|
|
100
|
+
const sr = host.attachShadow({ mode: 'open' });
|
|
101
|
+
|
|
102
|
+
adopt(sr, `
|
|
103
|
+
:host { all: initial; }
|
|
104
|
+
.cur { position: fixed; left: 0; top: 0; width: 0; height: 0; pointer-events: none; opacity: .9;
|
|
105
|
+
transition: opacity .35s ease; will-change: transform; }
|
|
106
|
+
.cur.idle { opacity: .35; }
|
|
107
|
+
.cur.idle .what, .cur.dormant .what { max-width: 0; opacity: 0; padding-left: 0; }
|
|
108
|
+
.cur.near { opacity: .1; transition-duration: .18s; }
|
|
109
|
+
.cur.dormant { opacity: 0; transition-duration: .6s; }
|
|
110
|
+
.cur.yield { opacity: 0; transition-duration: .22s; }
|
|
111
|
+
.arrow { position: absolute; left: -4px; top: -3px; width: 26px; height: 26px; overflow: visible;
|
|
112
|
+
filter: drop-shadow(0 1.5px 2.5px rgba(16, 24, 64, .3)); transform-origin: 4px 3px; }
|
|
113
|
+
.halo { position: absolute; left: -11px; top: -11px; width: 22px; height: 22px; border-radius: 50%;
|
|
114
|
+
background: rgba(111, 139, 255, .2); border: 1.5px solid rgba(111, 139, 255, .65);
|
|
115
|
+
opacity: 0; transform: scale(.4); transition: opacity .15s ease, transform .18s ease; }
|
|
116
|
+
.cur.down .halo { opacity: 1; transform: scale(1); }
|
|
117
|
+
.tag { position: absolute; left: 17px; top: 21px; display: flex; align-items: center; max-width: 280px;
|
|
118
|
+
height: 22px; overflow: hidden; padding: 0 8px 0 7px; border-radius: 4px 11px 11px 11px; box-sizing: border-box;
|
|
119
|
+
background: linear-gradient(135deg, rgba(111, 139, 255, .92), rgba(77, 107, 254, .9)); color: #fff; white-space: nowrap;
|
|
120
|
+
font: 600 11.5px/22px -apple-system, BlinkMacSystemFont, "PingFang SC", "Segoe UI", system-ui, sans-serif;
|
|
121
|
+
letter-spacing: .2px; box-shadow: 0 2px 8px rgba(30, 50, 160, .28), 0 0 0 1px rgba(255, 255, 255, .55);
|
|
122
|
+
transition: opacity .2s ease; }
|
|
123
|
+
/* 贴右边:名牌翻到箭头左边;贴底边:翻到箭头上面。缺角始终朝着箭头尖 */
|
|
124
|
+
.tag.fx { left: auto; right: 7px; border-radius: 11px 4px 11px 11px; }
|
|
125
|
+
.tag.fy { top: auto; bottom: 7px; border-radius: 11px 11px 11px 4px; }
|
|
126
|
+
.tag.fx.fy { border-radius: 11px 11px 4px 11px; }
|
|
127
|
+
.ico { flex: none; width: 12px; height: 12px; margin-right: 5px; }
|
|
128
|
+
.who { flex: none; }
|
|
129
|
+
.what { display: inline-block; max-width: 0; opacity: 0; overflow: hidden; text-overflow: ellipsis;
|
|
130
|
+
font-weight: 500; padding-left: 0;
|
|
131
|
+
transition: max-width .32s cubic-bezier(.2, .8, .2, 1), opacity .2s ease, padding .32s ease; }
|
|
132
|
+
.tag.open .what { max-width: 230px; opacity: 1; padding-left: 6px; }
|
|
133
|
+
.what::before { content: "·"; margin-right: 6px; opacity: .7; }
|
|
134
|
+
.ring { position: fixed; left: 0; top: 0; width: 40px; height: 40px; margin: -20px 0 0 -20px; border-radius: 50%;
|
|
135
|
+
border: 1.5px solid rgba(111, 139, 255, .75); background: rgba(111, 139, 255, .12);
|
|
136
|
+
box-sizing: border-box; pointer-events: none; opacity: 0;
|
|
137
|
+
box-shadow: 0 0 0 1px rgba(255, 255, 255, .55); }
|
|
138
|
+
.dot { position: fixed; left: 0; top: 0; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 50%;
|
|
139
|
+
background: rgba(111, 139, 255, .85); box-shadow: 0 0 0 2px rgba(255, 255, 255, .85); pointer-events: none; opacity: 0; }
|
|
140
|
+
.wheel { position: absolute; left: 20px; top: -26px; width: 20px; height: 20px; border-radius: 50%;
|
|
141
|
+
background: rgba(111, 139, 255, .85); color: #fff; display: grid; place-items: center; opacity: 0;
|
|
142
|
+
box-shadow: 0 2px 6px rgba(30, 50, 160, .28); }
|
|
143
|
+
.wheel.low { top: 30px; }
|
|
144
|
+
.wheel svg { width: 12px; height: 12px; }
|
|
145
|
+
`);
|
|
146
|
+
|
|
147
|
+
const cur = el('div', 'cur');
|
|
148
|
+
const halo = el('div', 'halo');
|
|
149
|
+
|
|
150
|
+
// 箭头:圆角经典指针,淡蓝渐变 + 白描边;尖端在 (4, 3)。形状跟桌面光标一模一样
|
|
151
|
+
const arrow = svgEl('svg', { class: 'arrow', viewBox: '0 0 24 24', width: '26', height: '26' });
|
|
152
|
+
const defs = svgEl('defs', {});
|
|
153
|
+
const grad = svgEl('linearGradient', { id: 'dshg', x1: '0', y1: '0', x2: '1', y2: '1' });
|
|
154
|
+
grad.append(svgEl('stop', { offset: '0', 'stop-color': '#9fb2ff' }), svgEl('stop', { offset: '1', 'stop-color': '#6f8bff' }));
|
|
155
|
+
defs.append(grad);
|
|
156
|
+
arrow.append(defs, svgEl('path', {
|
|
157
|
+
d: 'M4 3.2v16.1c0 .8.95 1.2 1.5.62l3.86-4.02 3.07 6.3c.25.5.86.71 1.36.47l2.04-.98c.5-.24.71-.84.47-1.34l-3.05-6.25 5.5-.2c.82-.03 1.2-1.03.6-1.6L5.65 2.5C5.06 1.95 4 2.37 4 3.2z',
|
|
158
|
+
fill: 'url(#dshg)', stroke: '#fff', 'stroke-width': '1.6', 'stroke-linejoin': 'round', 'paint-order': 'stroke',
|
|
159
|
+
}));
|
|
160
|
+
|
|
161
|
+
// 名牌:地球图标 = 浏览器里的 DSH(桌面那边是显示器图标)
|
|
162
|
+
const tag = el('div', 'tag');
|
|
163
|
+
const ico = svgEl('svg', { class: 'ico', viewBox: '0 0 12 12', fill: 'none', stroke: '#fff', 'stroke-width': '1.3' });
|
|
164
|
+
ico.append(
|
|
165
|
+
svgEl('circle', { cx: '6', cy: '6', r: '4.8' }),
|
|
166
|
+
svgEl('path', { d: 'M1.2 6h9.6M6 1.2c1.6 1.4 2.4 3 2.4 4.8S7.6 9.4 6 10.8M6 1.2C4.4 2.6 3.6 4.2 3.6 6S4.4 9.4 6 10.8' }),
|
|
167
|
+
);
|
|
168
|
+
const who = el('span', 'who');
|
|
169
|
+
who.textContent = 'DSH';
|
|
170
|
+
const what = el('span', 'what');
|
|
171
|
+
tag.append(ico, who, what);
|
|
172
|
+
|
|
173
|
+
const wheel = el('div', 'wheel');
|
|
174
|
+
const wheelSvg = svgEl('svg', { viewBox: '0 0 12 12', fill: 'none', stroke: '#fff', 'stroke-width': '1.8', 'stroke-linecap': 'round', 'stroke-linejoin': 'round' });
|
|
175
|
+
const wheelPath = svgEl('path', { d: 'M3 4.5 6 7.5 9 4.5' });
|
|
176
|
+
wheelSvg.append(wheelPath);
|
|
177
|
+
wheel.append(wheelSvg);
|
|
178
|
+
|
|
179
|
+
cur.append(halo, arrow, tag, wheel);
|
|
180
|
+
sr.append(cur);
|
|
181
|
+
(document.body || document.documentElement).appendChild(host);
|
|
182
|
+
|
|
183
|
+
const raise = () => {
|
|
184
|
+
if (!host.isConnected) (document.body || document.documentElement).appendChild(host);
|
|
185
|
+
raiseHost(host);
|
|
186
|
+
};
|
|
187
|
+
raise();
|
|
188
|
+
|
|
189
|
+
// ── 状态 ──
|
|
190
|
+
let x = keep ? keep.x : null;
|
|
191
|
+
let y = keep ? keep.y : null;
|
|
192
|
+
let shown = false;
|
|
193
|
+
let idleTimer = 0;
|
|
194
|
+
let dormantTimer = 0;
|
|
195
|
+
let labelTimer = 0;
|
|
196
|
+
let glide = null;
|
|
197
|
+
let agentUntil = carry && carry.agentUntil > Date.now() ? carry.agentUntil : 0;
|
|
198
|
+
let taken = carry && carry.taken ? carry.taken : null; // { at, type }:人最近一次接手
|
|
199
|
+
let handoffResolved = carry && carry.handoffResolved != null ? carry.handoffResolved : null;
|
|
200
|
+
let lastUser = null; // 人的鼠标最后在哪 { x, y, at }
|
|
201
|
+
|
|
202
|
+
const at = (px, py) => `translate3d(${px}px, ${py}px, 0)`;
|
|
203
|
+
const vw = () => Math.min(window.innerWidth || 0, document.documentElement.clientWidth || window.innerWidth || 0) || window.innerWidth || 0;
|
|
204
|
+
const vh = () => Math.min(window.innerHeight || 0, document.documentElement.clientHeight || window.innerHeight || 0) || window.innerHeight || 0;
|
|
205
|
+
|
|
206
|
+
/** 名牌要占多宽:展开时 .what 还在过渡里、offsetWidth 不准,按全文宽(scrollWidth)和 max-width 封顶来算 */
|
|
207
|
+
const TAG_MAX = 280, WHAT_MAX = 230, WHAT_PAD = 6;
|
|
208
|
+
const tagNeed = () => {
|
|
209
|
+
const base = tag.offsetWidth - what.offsetWidth; // 图标 + DSH + 内边距
|
|
210
|
+
if (!tag.classList.contains('open')) return Math.min(TAG_MAX, base);
|
|
211
|
+
const text = what.scrollWidth - (parseFloat(getComputedStyle(what).paddingLeft) || 0);
|
|
212
|
+
return Math.min(TAG_MAX, base + Math.min(WHAT_MAX, text) + WHAT_PAD);
|
|
213
|
+
};
|
|
214
|
+
/** 收起时也按展开后的常见宽度预留,标签一展开名牌不至于左右跳 */
|
|
215
|
+
const TAG_RESERVE = 223;
|
|
216
|
+
const EDGE_GAP = 4;
|
|
217
|
+
/** 贴边就翻:按名牌实际宽度比左右剩余空间,放得下的一边优先右边;两边都放不下就去宽的一边、收窄到刚好不出视口。
|
|
218
|
+
* 贴底就翻到上面;滚轮提示顶到上沿就挪到下面 */
|
|
219
|
+
const edge = (px, py) => {
|
|
220
|
+
if (px == null || py == null) return;
|
|
221
|
+
tag.style.maxWidth = '';
|
|
222
|
+
const need = tagNeed();
|
|
223
|
+
const right = vw() - px - 17 - EDGE_GAP; // 名牌不翻:左缘在箭头尖右边 17px
|
|
224
|
+
const left = px - 7 - EDGE_GAP; // 翻到左边:右缘在箭头尖左边 7px
|
|
225
|
+
const plan = Math.max(need, TAG_RESERVE);
|
|
226
|
+
let fx;
|
|
227
|
+
let fit = null;
|
|
228
|
+
if (plan <= right) fx = false;
|
|
229
|
+
else if (plan <= left) fx = true;
|
|
230
|
+
else if (need <= right) fx = false;
|
|
231
|
+
else if (need <= left) fx = true;
|
|
232
|
+
else { fx = left > right; fit = Math.max(0, Math.floor(fx ? left : right)); }
|
|
233
|
+
tag.classList.toggle('fx', fx);
|
|
234
|
+
if (fit != null) tag.style.maxWidth = fit + 'px';
|
|
235
|
+
tag.classList.toggle('fy', py > vh() - 56);
|
|
236
|
+
wheel.classList.toggle('low', py < 34);
|
|
237
|
+
};
|
|
238
|
+
/** 人的鼠标凑到 72px 以内:几乎透明,别挡人看字 */
|
|
239
|
+
const near = () => {
|
|
240
|
+
const on = !!lastUser && x !== null && Date.now() - lastUser.at < 4000 && Math.hypot(lastUser.x - x, lastUser.y - y) < 72;
|
|
241
|
+
cur.classList.toggle('near', on);
|
|
242
|
+
};
|
|
243
|
+
const wake = () => {
|
|
244
|
+
cur.classList.remove('idle', 'dormant', 'yield');
|
|
245
|
+
clearTimeout(idleTimer);
|
|
246
|
+
clearTimeout(dormantTimer);
|
|
247
|
+
idleTimer = setTimeout(() => cur.classList.add('idle'), 6000);
|
|
248
|
+
dormantTimer = setTimeout(() => cur.classList.add('dormant'), 15000);
|
|
249
|
+
};
|
|
250
|
+
const appear = () => {
|
|
251
|
+
if (shown) return;
|
|
252
|
+
shown = true;
|
|
253
|
+
if (!reduce()) {
|
|
254
|
+
arrow.animate([{ transform: 'scale(.6)', opacity: 0 }, { transform: 'scale(1.04)', opacity: 1, offset: .7 }, { transform: 'scale(1)', opacity: 1 }],
|
|
255
|
+
{ duration: 280, easing: 'ease-out' });
|
|
256
|
+
tag.animate([{ opacity: 0, transform: 'translateY(-4px)' }, { opacity: 1, transform: 'none' }], { duration: 260, delay: 60, easing: 'ease-out', fill: 'backwards' });
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
/** 正在飞的话,取它此刻的位置(动画值),好从半路接着飞 */
|
|
260
|
+
const current = () => {
|
|
261
|
+
if (glide && glide.playState === 'running') {
|
|
262
|
+
try {
|
|
263
|
+
const m = new DOMMatrixReadOnly(getComputedStyle(cur).transform);
|
|
264
|
+
return { x: m.m41, y: m.m42 };
|
|
265
|
+
} catch {}
|
|
266
|
+
}
|
|
267
|
+
return { x, y };
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const place = (px, py) => {
|
|
271
|
+
raise();
|
|
272
|
+
if (glide) { glide.cancel(); glide = null; }
|
|
273
|
+
x = Math.round(px); y = Math.round(py);
|
|
274
|
+
cur.style.transform = at(x, y);
|
|
275
|
+
edge(x, y);
|
|
276
|
+
appear();
|
|
277
|
+
wake();
|
|
278
|
+
near();
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
// 弹簧:跟桌面光标同一个模型(阻尼比 0.86 上下,几乎不回弹)。这里按时长反推刚度,
|
|
282
|
+
// 保证 duration 时已经落到 0.5px 以内;回弹量按距离把阻尼调一调,最多冲过头 3px。
|
|
283
|
+
const spring = (dist, T) => {
|
|
284
|
+
const f = Math.min(0.005, 3 / dist); // 允许冲过头的比例
|
|
285
|
+
const lf = Math.log(f);
|
|
286
|
+
const zeta = Math.min(0.95, -lf / Math.sqrt(Math.PI * Math.PI + lf * lf));
|
|
287
|
+
const zw = Math.log(Math.max(8, 4 * dist)) / T; // 到 T 时离终点不到 0.5px
|
|
288
|
+
const wd = (zw / zeta) * Math.sqrt(1 - zeta * zeta);
|
|
289
|
+
const r = zeta / Math.sqrt(1 - zeta * zeta);
|
|
290
|
+
return (t) => 1 - Math.exp(-zw * t) * (Math.cos(wd * t) + r * Math.sin(wd * t));
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const move = (px, py, opts = {}) => {
|
|
294
|
+
px = Math.round(px); py = Math.round(py);
|
|
295
|
+
raise();
|
|
296
|
+
wake();
|
|
297
|
+
if (x === null) { place(px, py); return 0; }
|
|
298
|
+
const from = current();
|
|
299
|
+
if (glide) { glide.cancel(); glide = null; }
|
|
300
|
+
x = px; y = py;
|
|
301
|
+
cur.style.transform = at(px, py); // 先把终点写死:动画结束(哪怕没帧可画)就停在这
|
|
302
|
+
edge(px, py);
|
|
303
|
+
near();
|
|
304
|
+
appear();
|
|
305
|
+
const dx = px - from.x, dy = py - from.y;
|
|
306
|
+
const dist = Math.hypot(dx, dy);
|
|
307
|
+
if (dist < 2 || reduce()) return 0;
|
|
308
|
+
const duration = Math.round(opts.duration != null ? opts.duration : Math.min(620, 240 + dist * 0.42));
|
|
309
|
+
if (opts.straight) { // 拖拽:匀速直线,跟真实的拖动步子对齐
|
|
310
|
+
glide = cur.animate([{ transform: at(from.x, from.y) }, { transform: at(px, py) }], { duration, easing: 'linear' });
|
|
311
|
+
return duration;
|
|
312
|
+
}
|
|
313
|
+
// 二次贝塞尔弧线:控制点在中点往一侧偏,偏移量随距离走、有上限(桌面光标同一个弯法)
|
|
314
|
+
const ux = dx / dist, uy = dy / dist;
|
|
315
|
+
const bend = Math.min(44, dist * 0.12) * (dx >= 0 ? -1 : 1);
|
|
316
|
+
const cx = (from.x + px) / 2 - uy * bend;
|
|
317
|
+
const cy = (from.y + py) / 2 + ux * bend;
|
|
318
|
+
const curve = (p) => { // p 略大于 1 时沿着到达方向冲出去一点 —— 回弹就是这么来的
|
|
319
|
+
const q = 1 - p;
|
|
320
|
+
return [q * q * from.x + 2 * q * p * cx + p * p * px, q * q * from.y + 2 * q * p * cy + p * p * py];
|
|
321
|
+
};
|
|
322
|
+
const P = spring(dist, duration / 1000);
|
|
323
|
+
// 按帧采样:位置、速度 → 拉伸 / 侧倾 / 名牌落后,全跟桌面光标一个算法
|
|
324
|
+
const N = 30;
|
|
325
|
+
const pts = [];
|
|
326
|
+
for (let i = 0; i <= N; i++) pts.push(i === N ? [px, py] : curve(P((i / N) * duration / 1000)));
|
|
327
|
+
const dt = duration / 1000 / N;
|
|
328
|
+
const posF = [], armF = [], tagF = [];
|
|
329
|
+
for (let i = 0; i <= N; i++) {
|
|
330
|
+
const a = pts[Math.max(0, i - 1)], b = pts[Math.min(N, i + 1)];
|
|
331
|
+
const span = (Math.min(N, i + 1) - Math.max(0, i - 1)) * dt;
|
|
332
|
+
const vx = i === 0 || i === N ? 0 : (b[0] - a[0]) / span;
|
|
333
|
+
const vy = i === 0 || i === N ? 0 : (b[1] - a[1]) / span;
|
|
334
|
+
const v = Math.hypot(vx, vy);
|
|
335
|
+
const amt = Math.min(1, v / 2600);
|
|
336
|
+
const k = 1 + 0.07 * amt; // 顺着方向最多拉长 7%
|
|
337
|
+
const th = v > 1 ? Math.atan2(vy, vx) * 180 / Math.PI : 0;
|
|
338
|
+
const tilt = v > 1 ? (vx / v) * 5.7 * amt : 0; // 侧倾最多 5.7°(0.1 弧度)
|
|
339
|
+
const lx = Math.max(-5, Math.min(5, -vx * 0.004)); // 名牌晚半拍,最多落后 5px
|
|
340
|
+
const ly = Math.max(-5, Math.min(5, -vy * 0.004));
|
|
341
|
+
const offset = i / N;
|
|
342
|
+
posF.push({ offset, transform: at(pts[i][0], pts[i][1]) });
|
|
343
|
+
armF.push({ offset, transform: `rotate(${th.toFixed(2)}deg) scale(${k.toFixed(4)}, ${(1 / Math.sqrt(k)).toFixed(4)}) rotate(${(-th + tilt).toFixed(2)}deg)` });
|
|
344
|
+
tagF.push({ offset, translate: `${lx.toFixed(1)}px ${ly.toFixed(1)}px` });
|
|
345
|
+
}
|
|
346
|
+
glide = cur.animate(posF, { duration, easing: 'linear' });
|
|
347
|
+
arrow.animate(armF, { duration, easing: 'linear' });
|
|
348
|
+
tag.animate(tagF, { duration, easing: 'linear' });
|
|
349
|
+
return duration;
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
const press = () => {
|
|
353
|
+
wake();
|
|
354
|
+
if (reduce()) return;
|
|
355
|
+
arrow.animate([
|
|
356
|
+
{ transform: 'scale(1)' },
|
|
357
|
+
{ transform: 'scale(.86)', offset: .35 },
|
|
358
|
+
{ transform: 'scale(1.03)', offset: .75 },
|
|
359
|
+
{ transform: 'scale(1)' },
|
|
360
|
+
], { duration: 260, easing: 'ease-out' });
|
|
361
|
+
};
|
|
362
|
+
|
|
363
|
+
const ripple = (px, py, delay) => {
|
|
364
|
+
const ring = el('div', 'ring');
|
|
365
|
+
const dot = el('div', 'dot');
|
|
366
|
+
for (const n of [ring, dot]) { n.style.left = px + 'px'; n.style.top = py + 'px'; }
|
|
367
|
+
sr.append(ring, dot);
|
|
368
|
+
if (!reduce()) {
|
|
369
|
+
ring.animate([{ transform: 'scale(.3)', opacity: .9 }, { transform: 'scale(1)', opacity: 0 }],
|
|
370
|
+
{ duration: 560, delay, easing: 'cubic-bezier(.2, .7, .3, 1)', fill: 'both' });
|
|
371
|
+
dot.animate([{ transform: 'scale(.5)', opacity: 1 }, { transform: 'scale(1)', opacity: 1, offset: .3 }, { transform: 'scale(1)', opacity: 0 }],
|
|
372
|
+
{ duration: 600, delay, easing: 'ease-out', fill: 'both' });
|
|
373
|
+
}
|
|
374
|
+
setTimeout(() => { ring.remove(); dot.remove(); }, 800 + delay);
|
|
375
|
+
};
|
|
376
|
+
|
|
377
|
+
const click = (px, py, count = 1) => {
|
|
378
|
+
if (px == null) { px = x; py = y; }
|
|
379
|
+
press();
|
|
380
|
+
const n = Math.max(1, Math.min(3, Number(count) || 1));
|
|
381
|
+
for (let i = 0; i < n; i++) ripple(Math.round(px), Math.round(py), i * 130);
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
const down = () => { wake(); cur.classList.add('down'); if (!reduce()) arrow.animate([{ transform: 'scale(1)' }, { transform: 'scale(.88)' }], { duration: 120, fill: 'forwards' }); };
|
|
385
|
+
const up = () => { wake(); cur.classList.remove('down'); arrow.getAnimations().forEach((a) => a.cancel()); };
|
|
386
|
+
|
|
387
|
+
const label = (text, ms = 2600) => {
|
|
388
|
+
wake();
|
|
389
|
+
what.textContent = text == null ? '' : String(text);
|
|
390
|
+
tag.classList.toggle('open', !!what.textContent);
|
|
391
|
+
edge(x, y);
|
|
392
|
+
clearTimeout(labelTimer);
|
|
393
|
+
if (what.textContent) labelTimer = setTimeout(() => tag.classList.remove('open'), ms);
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
const scroll = (dy = 1) => {
|
|
397
|
+
wake();
|
|
398
|
+
wheelPath.setAttribute('d', dy < 0 ? 'M3 7.5 6 4.5 9 7.5' : 'M3 4.5 6 7.5 9 4.5');
|
|
399
|
+
if (reduce()) return;
|
|
400
|
+
const s = dy < 0 ? -1 : 1;
|
|
401
|
+
wheel.animate([
|
|
402
|
+
{ opacity: 0, transform: `translateY(${-4 * s}px)` },
|
|
403
|
+
{ opacity: 1, transform: 'translateY(0)', offset: .25 },
|
|
404
|
+
{ opacity: 1, transform: `translateY(${3 * s}px)`, offset: .75 },
|
|
405
|
+
{ opacity: 0, transform: `translateY(${5 * s}px)` },
|
|
406
|
+
], { duration: 900, easing: 'ease-in-out' });
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
const hide = () => {
|
|
410
|
+
clearTimeout(idleTimer);
|
|
411
|
+
clearTimeout(dormantTimer);
|
|
412
|
+
clearTimeout(labelTimer);
|
|
413
|
+
if (reduce() || !shown) { host.remove(); return; }
|
|
414
|
+
cur.animate([{ opacity: getComputedStyle(cur).opacity }, { opacity: 0 }], { duration: 180, fill: 'forwards' });
|
|
415
|
+
setTimeout(() => host.remove(), 200);
|
|
416
|
+
};
|
|
417
|
+
|
|
418
|
+
const pos = () => (x === null ? null : { x, y });
|
|
419
|
+
|
|
420
|
+
// ── 人和 DSH 分开:CDP 发的输入也是 isTrusted,只能靠 DSH 自己报的时间窗 ──
|
|
421
|
+
const TAKEOVER_MS = 12000;
|
|
422
|
+
const beginAgent = (ms = 1500) => {
|
|
423
|
+
const n = Math.max(0, Math.min(60000, Number(ms) || 0));
|
|
424
|
+
agentUntil = Math.max(agentUntil, Date.now() + n);
|
|
425
|
+
return true;
|
|
426
|
+
};
|
|
427
|
+
const endAgent = (graceMs = 120) => {
|
|
428
|
+
agentUntil = Date.now() + Math.max(0, Math.min(5000, Number(graceMs) || 0));
|
|
429
|
+
return true;
|
|
430
|
+
};
|
|
431
|
+
const takeover = () => (taken && Date.now() - taken.at < TAKEOVER_MS ? { at: taken.at, type: taken.type } : null);
|
|
432
|
+
const clearTakeover = () => { taken = null; return true; };
|
|
433
|
+
|
|
434
|
+
// ── 协作浮条:页面顶部居中,只有它自己接收点击 ──
|
|
435
|
+
let bar = null; // { id, host }
|
|
436
|
+
const barCss = `
|
|
437
|
+
:host { all: initial; }
|
|
438
|
+
.bar { pointer-events: auto; box-sizing: border-box; display: flex; align-items: center; gap: 12px;
|
|
439
|
+
width: max-content; max-width: min(560px, calc(100vw - 24px)); padding: 10px 10px 10px 12px; border-radius: 18px;
|
|
440
|
+
font: 13px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", system-ui, sans-serif;
|
|
441
|
+
color: #0b0b0f; background: linear-gradient(180deg, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 60%), rgba(246, 247, 252, .86);
|
|
442
|
+
-webkit-backdrop-filter: blur(24px) saturate(1.8); backdrop-filter: blur(24px) saturate(1.8);
|
|
443
|
+
box-shadow: 0 14px 38px rgba(30, 42, 110, .22), 0 2px 6px rgba(30, 42, 110, .12),
|
|
444
|
+
inset 0 0 0 .5px rgba(60, 60, 67, .18), inset 0 1px 0 rgba(255, 255, 255, .9); }
|
|
445
|
+
.badge { flex: none; width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; color: #fff;
|
|
446
|
+
background: linear-gradient(180deg, #8fa3ff, #4d6bfe);
|
|
447
|
+
box-shadow: inset 0 .5px 0 rgba(255, 255, 255, .5), 0 3px 10px rgba(77, 107, 254, .38); }
|
|
448
|
+
.badge svg { width: 18px; height: 18px; }
|
|
449
|
+
.txt { flex: 1; min-width: 0; display: grid; gap: 1px; }
|
|
450
|
+
.t { font-weight: 650; font-size: 13.5px; letter-spacing: -.1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
|
451
|
+
.r { color: rgba(60, 60, 67, .78); font-size: 12.5px; overflow: hidden; display: -webkit-box;
|
|
452
|
+
-webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow-wrap: anywhere; }
|
|
453
|
+
.r:empty { display: none; }
|
|
454
|
+
.done { flex: none; appearance: none; border: 0; margin: 0; cursor: pointer; height: 34px; padding: 0 16px; border-radius: 17px;
|
|
455
|
+
font-family: inherit; font-size: 13px; font-weight: 600; line-height: 34px; color: #fff; white-space: nowrap;
|
|
456
|
+
background: linear-gradient(180deg, #34c759, #28a745);
|
|
457
|
+
box-shadow: 0 4px 12px rgba(52, 199, 89, .35), inset 0 1px 0 rgba(255, 255, 255, .35);
|
|
458
|
+
transition: transform .2s cubic-bezier(.3, 1.35, .5, 1), filter .15s; }
|
|
459
|
+
.done:hover { filter: brightness(1.06); }
|
|
460
|
+
.done:active { transform: scale(.95); }
|
|
461
|
+
.done:focus-visible { outline: 2px solid #0a84ff; outline-offset: 2px; }
|
|
462
|
+
@media (prefers-color-scheme: dark) {
|
|
463
|
+
.bar { color: #fff; background: linear-gradient(180deg, rgba(255, 255, 255, .08), rgba(255, 255, 255, 0) 60%), rgba(36, 38, 48, .86);
|
|
464
|
+
box-shadow: 0 16px 40px rgba(0, 0, 0, .5), 0 2px 6px rgba(0, 0, 0, .3),
|
|
465
|
+
inset 0 0 0 .5px rgba(255, 255, 255, .14), inset 0 1px 0 rgba(255, 255, 255, .12); }
|
|
466
|
+
.r { color: rgba(235, 235, 245, .7); }
|
|
467
|
+
.done { background: linear-gradient(180deg, #30d158, #24a148); }
|
|
468
|
+
}
|
|
469
|
+
@media (max-width: 420px) { .bar { flex-wrap: wrap; } .done { flex: 1 1 100%; } }
|
|
470
|
+
`;
|
|
471
|
+
|
|
472
|
+
const removeBar = (animate) => {
|
|
473
|
+
const b = bar;
|
|
474
|
+
bar = null;
|
|
475
|
+
if (!b) return;
|
|
476
|
+
if (!animate || reduce()) { b.host.remove(); return; }
|
|
477
|
+
try {
|
|
478
|
+
const box = b.host.shadowRoot && b.host.shadowRoot.querySelector('.bar');
|
|
479
|
+
if (box) box.animate([{ opacity: 1, transform: 'none' }, { opacity: 0, transform: 'translateY(-8px) scale(.98)' }], { duration: 160, easing: 'ease-in', fill: 'forwards' });
|
|
480
|
+
} catch {}
|
|
481
|
+
setTimeout(() => b.host.remove(), 170);
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
const showHandoff = ({ id, reason, title, doneLabel } = {}) => {
|
|
485
|
+
removeBar(false);
|
|
486
|
+
handoffResolved = null;
|
|
487
|
+
const h = document.createElement(BAR_TAG);
|
|
488
|
+
h.style.cssText = hostCss(['inset:12px 0 auto 0', 'width:fit-content', 'height:auto', 'margin:0 auto', 'pointer-events:none']);
|
|
489
|
+
const root = h.attachShadow({ mode: 'open' });
|
|
490
|
+
adopt(root, barCss);
|
|
491
|
+
const box = el('div', 'bar');
|
|
492
|
+
box.setAttribute('role', 'region');
|
|
493
|
+
const badge = el('span', 'badge');
|
|
494
|
+
const hand = svgEl('svg', { viewBox: '0 0 16 16', fill: 'none', stroke: 'currentColor', 'stroke-width': '1.6', 'stroke-linecap': 'round', 'stroke-linejoin': 'round' });
|
|
495
|
+
hand.append(
|
|
496
|
+
svgEl('circle', { cx: '8', cy: '5.2', r: '2.4' }),
|
|
497
|
+
svgEl('path', { d: 'M3.4 13.4c.6-2.5 2.4-3.9 4.6-3.9s4 1.4 4.6 3.9' }),
|
|
498
|
+
);
|
|
499
|
+
badge.append(hand);
|
|
500
|
+
const txt = el('div', 'txt');
|
|
501
|
+
const t = el('div', 't');
|
|
502
|
+
t.textContent = title == null || title === '' ? 'DSH' : String(title);
|
|
503
|
+
const r = el('div', 'r');
|
|
504
|
+
r.textContent = reason == null ? '' : String(reason);
|
|
505
|
+
txt.append(t, r);
|
|
506
|
+
const btn = el('button', 'done');
|
|
507
|
+
btn.type = 'button';
|
|
508
|
+
btn.textContent = doneLabel == null || doneLabel === '' ? 'OK' : String(doneLabel);
|
|
509
|
+
box.setAttribute('aria-label', t.textContent);
|
|
510
|
+
box.append(badge, txt, btn);
|
|
511
|
+
// 浮条上的按键、点击别漏给页面(页面上的「点外面就关菜单」之类不该被我们触发)
|
|
512
|
+
for (const type of ['pointerdown', 'mousedown', 'pointerup', 'mouseup', 'click', 'keydown', 'keyup']) {
|
|
513
|
+
box.addEventListener(type, (e) => e.stopPropagation());
|
|
514
|
+
}
|
|
515
|
+
const entry = { id, host: h, args: { id, reason, title, doneLabel } };
|
|
516
|
+
btn.addEventListener('click', (ev) => {
|
|
517
|
+
if (!ev.isTrusted) return; // 页面脚本 btn.click() / dispatchEvent 造的点击不算人点的
|
|
518
|
+
if (bar !== entry) return;
|
|
519
|
+
handoffResolved = id;
|
|
520
|
+
taken = null;
|
|
521
|
+
removeBar(true);
|
|
522
|
+
});
|
|
523
|
+
root.append(box);
|
|
524
|
+
(document.body || document.documentElement).appendChild(h);
|
|
525
|
+
bar = entry;
|
|
526
|
+
raiseHost(h);
|
|
527
|
+
if (!reduce()) {
|
|
528
|
+
box.animate([{ opacity: 0, transform: 'translateY(-12px) scale(.97)' }, { opacity: 1, transform: 'none' }],
|
|
529
|
+
{ duration: 340, easing: 'cubic-bezier(.3, 1.35, .5, 1)' });
|
|
530
|
+
}
|
|
531
|
+
cur.classList.add('yield'); // 轮到人了:光标先让开
|
|
532
|
+
return true;
|
|
533
|
+
};
|
|
534
|
+
|
|
535
|
+
const handoffStatus = (id) => {
|
|
536
|
+
if (handoffResolved != null && handoffResolved === id) return 'done';
|
|
537
|
+
if (bar && bar.id === id && bar.host.isConnected) return 'waiting';
|
|
538
|
+
return 'gone';
|
|
539
|
+
};
|
|
540
|
+
|
|
541
|
+
const hideHandoff = () => {
|
|
542
|
+
removeBar(true);
|
|
543
|
+
handoffResolved = null;
|
|
544
|
+
return true;
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
// ── 监听人:按下 / 按键算接手,鼠标挪近了让路 ──
|
|
548
|
+
const ours = (e) => {
|
|
549
|
+
try {
|
|
550
|
+
const path = e.composedPath ? e.composedPath() : [];
|
|
551
|
+
return path.includes(host) || (bar && path.includes(bar.host));
|
|
552
|
+
} catch { return false; }
|
|
553
|
+
};
|
|
554
|
+
const onInput = (e) => {
|
|
555
|
+
if (!e.isTrusted || Date.now() < agentUntil || ours(e)) return;
|
|
556
|
+
taken = { at: Date.now(), type: e.type };
|
|
557
|
+
clearTimeout(labelTimer);
|
|
558
|
+
tag.classList.remove('open');
|
|
559
|
+
cur.classList.add('yield');
|
|
560
|
+
};
|
|
561
|
+
const onPointerMove = (e) => {
|
|
562
|
+
if (!e.isTrusted || Date.now() < agentUntil) return;
|
|
563
|
+
lastUser = { x: e.clientX, y: e.clientY, at: Date.now() };
|
|
564
|
+
if (shown) near();
|
|
565
|
+
};
|
|
566
|
+
const LISTEN = { capture: true, passive: true };
|
|
567
|
+
window.addEventListener('pointerdown', onInput, LISTEN);
|
|
568
|
+
window.addEventListener('keydown', onInput, LISTEN);
|
|
569
|
+
window.addEventListener('pointermove', onPointerMove, LISTEN);
|
|
570
|
+
// 模态框 / 全屏出来后,浮条要回到最上面
|
|
571
|
+
const onFullscreen = () => { if (bar) raiseHost(bar.host); if (shown && host.isConnected) raiseHost(host); };
|
|
572
|
+
document.addEventListener('fullscreenchange', onFullscreen, true);
|
|
573
|
+
|
|
574
|
+
const __state = () => ({
|
|
575
|
+
agentUntil, taken, handoffResolved,
|
|
576
|
+
handoff: bar && bar.host.isConnected ? bar.args : null,
|
|
577
|
+
});
|
|
578
|
+
const __teardown = () => {
|
|
579
|
+
window.removeEventListener('pointerdown', onInput, LISTEN);
|
|
580
|
+
window.removeEventListener('keydown', onInput, LISTEN);
|
|
581
|
+
window.removeEventListener('pointermove', onPointerMove, LISTEN);
|
|
582
|
+
document.removeEventListener('fullscreenchange', onFullscreen, true);
|
|
583
|
+
clearTimeout(idleTimer);
|
|
584
|
+
clearTimeout(dormantTimer);
|
|
585
|
+
clearTimeout(labelTimer);
|
|
586
|
+
removeBar(false);
|
|
587
|
+
host.remove();
|
|
588
|
+
};
|
|
589
|
+
|
|
590
|
+
window.__dshCursor = {
|
|
591
|
+
move, place, click, press, down, up, label, scroll, hide, pos,
|
|
592
|
+
beginAgent, endAgent, takeover, clearTakeover, showHandoff, handoffStatus, hideHandoff,
|
|
593
|
+
__state, __teardown, version: VERSION,
|
|
594
|
+
};
|
|
595
|
+
if (keep) place(keep.x, keep.y);
|
|
596
|
+
// 重注前浮条还挂着、人还没点完成:接着挂出来
|
|
597
|
+
if (carry && carry.handoff && carry.handoffResolved == null) showHandoff(carry.handoff);
|
|
598
|
+
return 'ready';
|
|
599
|
+
})();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"manifest_version": 3,
|
|
3
3
|
"name": "DSH Bridge",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"description": "__MSG_extDescription__",
|
|
6
6
|
"default_locale": "en",
|
|
7
7
|
"minimum_chrome_version": "116",
|
|
@@ -36,5 +36,14 @@
|
|
|
36
36
|
},
|
|
37
37
|
"host_permissions": [
|
|
38
38
|
"<all_urls>"
|
|
39
|
-
]
|
|
39
|
+
],
|
|
40
|
+
"commands": {
|
|
41
|
+
"emergency-stop": {
|
|
42
|
+
"suggested_key": {
|
|
43
|
+
"default": "Alt+Shift+X",
|
|
44
|
+
"mac": "Alt+Shift+X"
|
|
45
|
+
},
|
|
46
|
+
"description": "__MSG_cmdEmergencyStop__"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
40
49
|
}
|