@celljs/ta-screen-share 0.0.0-stage → 4.19.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 +13 -0
- package/README.md +12 -2
- package/package.json +52 -4
- package/web/index.js +1703 -0
package/web/index.js
ADDED
|
@@ -0,0 +1,1703 @@
|
|
|
1
|
+
// ../ta-protocol/esm/common/language.js
|
|
2
|
+
var TaLanguageUtil;
|
|
3
|
+
(function(TaLanguageUtil2) {
|
|
4
|
+
TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
|
|
5
|
+
TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
|
|
6
|
+
function of(tag) {
|
|
7
|
+
const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
|
|
8
|
+
if (/^zh(\b|-)/.test(said)) {
|
|
9
|
+
return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
|
|
10
|
+
}
|
|
11
|
+
return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
|
|
12
|
+
}
|
|
13
|
+
TaLanguageUtil2.of = of;
|
|
14
|
+
function server(env = typeof process === "undefined" ? {} : process.env) {
|
|
15
|
+
return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
|
|
16
|
+
}
|
|
17
|
+
TaLanguageUtil2.server = server;
|
|
18
|
+
function pick(language, words) {
|
|
19
|
+
return words[of(language)];
|
|
20
|
+
}
|
|
21
|
+
TaLanguageUtil2.pick = pick;
|
|
22
|
+
function say(words) {
|
|
23
|
+
return words[server()];
|
|
24
|
+
}
|
|
25
|
+
TaLanguageUtil2.say = say;
|
|
26
|
+
function chinese(language) {
|
|
27
|
+
return of(language).startsWith("zh");
|
|
28
|
+
}
|
|
29
|
+
TaLanguageUtil2.chinese = chinese;
|
|
30
|
+
function cjk(language) {
|
|
31
|
+
return of(language) !== "en-US";
|
|
32
|
+
}
|
|
33
|
+
TaLanguageUtil2.cjk = cjk;
|
|
34
|
+
function list(language, items) {
|
|
35
|
+
return items.join(cjk(language) ? "、" : ", ");
|
|
36
|
+
}
|
|
37
|
+
TaLanguageUtil2.list = list;
|
|
38
|
+
})(TaLanguageUtil || (TaLanguageUtil = {}));
|
|
39
|
+
|
|
40
|
+
// web-src/i18n.ts
|
|
41
|
+
var EN = {
|
|
42
|
+
hideBar: "Hide the bar",
|
|
43
|
+
showBar: "Show the bar",
|
|
44
|
+
modifiers: "Keys",
|
|
45
|
+
title: "Remote desktop",
|
|
46
|
+
intro: "See and work the screen of a computer from here",
|
|
47
|
+
thisComputer: "This computer",
|
|
48
|
+
added: "Added",
|
|
49
|
+
hosts: "Remote hosts",
|
|
50
|
+
add: "Add a computer",
|
|
51
|
+
addTitle: "Add a computer",
|
|
52
|
+
addHint: "Its address and port, as its screen sharing (VNC) listens: 192.168.1.20 or 192.168.1.20:5901",
|
|
53
|
+
remove: "Remove",
|
|
54
|
+
removeConfirm: "Remove {name} from the list?",
|
|
55
|
+
open: "Open",
|
|
56
|
+
connecting: "Connecting…",
|
|
57
|
+
lost: "Lost the connection",
|
|
58
|
+
retry: "Connect again",
|
|
59
|
+
back: "Back",
|
|
60
|
+
keyboard: "Keyboard",
|
|
61
|
+
trackpad: "Trackpad",
|
|
62
|
+
direct: "Tap where you point",
|
|
63
|
+
paste: "Paste text",
|
|
64
|
+
pastePlaceholder: "Text to paste on the computer",
|
|
65
|
+
fit: "Fit the screen",
|
|
66
|
+
take: "Work it here",
|
|
67
|
+
watching: "{name} works it now",
|
|
68
|
+
watchingYou: "Worked on another page of yours",
|
|
69
|
+
viewOnly: "You can only look",
|
|
70
|
+
quality: "Picture",
|
|
71
|
+
auto: "Auto",
|
|
72
|
+
crisp: "Sharp",
|
|
73
|
+
smooth: "Smooth",
|
|
74
|
+
username: "Account",
|
|
75
|
+
passwordField: "Password",
|
|
76
|
+
signInTitle: "Sign in to {name}",
|
|
77
|
+
signInMac: "The account and password you sign in to this Mac with",
|
|
78
|
+
signInVnc: "The password of its screen sharing (VNC)",
|
|
79
|
+
refusedAccount: "The account or password is not right. Try again.",
|
|
80
|
+
refusedPassword: "The password is not right. Try again.",
|
|
81
|
+
showPassword: "Show the password",
|
|
82
|
+
signingIn: "Signing in…",
|
|
83
|
+
cancel: "Cancel",
|
|
84
|
+
remember: "Sign in by itself next time",
|
|
85
|
+
ok: "Connect",
|
|
86
|
+
none: "No computer to show",
|
|
87
|
+
noneHint: "Turn on screen sharing on a computer, then add it here",
|
|
88
|
+
setupHint: "On a Mac: System Settings, General, Sharing, Screen Sharing. On Windows or Linux: a VNC server such as TigerVNC.",
|
|
89
|
+
viewers: "open on {n} pages",
|
|
90
|
+
failed: "Could not connect: {reason}"
|
|
91
|
+
};
|
|
92
|
+
var ZH = {
|
|
93
|
+
hideBar: "收起工具栏",
|
|
94
|
+
showBar: "显示工具栏",
|
|
95
|
+
modifiers: "按键",
|
|
96
|
+
title: "远程桌面",
|
|
97
|
+
intro: "在这里看到并操作一台电脑的屏幕",
|
|
98
|
+
thisComputer: "这台电脑",
|
|
99
|
+
added: "已添加",
|
|
100
|
+
hosts: "远程主机",
|
|
101
|
+
add: "添加电脑",
|
|
102
|
+
addTitle: "添加电脑",
|
|
103
|
+
addHint: "它的屏幕共享(VNC)所在的地址和端口,例如 192.168.1.20 或 192.168.1.20:5901",
|
|
104
|
+
remove: "移除",
|
|
105
|
+
removeConfirm: "从列表里移除 {name}?",
|
|
106
|
+
open: "打开",
|
|
107
|
+
connecting: "正在连接…",
|
|
108
|
+
lost: "连接断开了",
|
|
109
|
+
retry: "重新连接",
|
|
110
|
+
back: "返回",
|
|
111
|
+
keyboard: "键盘",
|
|
112
|
+
trackpad: "触控板",
|
|
113
|
+
direct: "指哪点哪",
|
|
114
|
+
paste: "粘贴文字",
|
|
115
|
+
pastePlaceholder: "要粘贴到电脑上的文字",
|
|
116
|
+
fit: "适应屏幕",
|
|
117
|
+
take: "在这里操作",
|
|
118
|
+
watching: "{name} 正在操作",
|
|
119
|
+
watchingYou: "正在你的另一个页面上操作",
|
|
120
|
+
viewOnly: "你只能观看",
|
|
121
|
+
quality: "画面",
|
|
122
|
+
auto: "自动",
|
|
123
|
+
crisp: "清晰",
|
|
124
|
+
smooth: "流畅",
|
|
125
|
+
username: "账号",
|
|
126
|
+
passwordField: "密码",
|
|
127
|
+
signInTitle: "登录 {name}",
|
|
128
|
+
signInMac: "用这台 Mac 的开机账号和密码",
|
|
129
|
+
signInVnc: "输入这台电脑屏幕共享(VNC)的密码",
|
|
130
|
+
refusedAccount: "账号或密码不对,请再试一次",
|
|
131
|
+
refusedPassword: "密码不对,请再试一次",
|
|
132
|
+
showPassword: "显示密码",
|
|
133
|
+
signingIn: "正在登录…",
|
|
134
|
+
cancel: "取消",
|
|
135
|
+
remember: "记住密码,下次自动登录",
|
|
136
|
+
ok: "连接",
|
|
137
|
+
none: "还没有可以打开的电脑",
|
|
138
|
+
noneHint: "在电脑上打开屏幕共享,再到这里添加",
|
|
139
|
+
setupHint: "Mac:系统设置 → 通用 → 共享 → 屏幕共享。Windows 或 Linux:装一个 VNC 服务,例如 TigerVNC。",
|
|
140
|
+
viewers: "{n} 个页面开着",
|
|
141
|
+
failed: "连不上:{reason}"
|
|
142
|
+
};
|
|
143
|
+
var ZH_TW = {
|
|
144
|
+
hideBar: "收起工具列",
|
|
145
|
+
showBar: "顯示工具列",
|
|
146
|
+
modifiers: "按鍵",
|
|
147
|
+
title: "遠端桌面",
|
|
148
|
+
intro: "在這裡看到並操作一台電腦的螢幕",
|
|
149
|
+
thisComputer: "這台電腦",
|
|
150
|
+
added: "已新增",
|
|
151
|
+
hosts: "遠端主機",
|
|
152
|
+
add: "新增電腦",
|
|
153
|
+
addTitle: "新增電腦",
|
|
154
|
+
addHint: "它的螢幕共享(VNC)所在的位址和連接埠,例如 192.168.1.20 或 192.168.1.20:5901",
|
|
155
|
+
remove: "移除",
|
|
156
|
+
removeConfirm: "從列表裡移除 {name}?",
|
|
157
|
+
open: "開啟",
|
|
158
|
+
connecting: "正在連線…",
|
|
159
|
+
lost: "連線中斷了",
|
|
160
|
+
retry: "重新連線",
|
|
161
|
+
back: "返回",
|
|
162
|
+
keyboard: "鍵盤",
|
|
163
|
+
trackpad: "觸控板",
|
|
164
|
+
direct: "指哪點哪",
|
|
165
|
+
paste: "貼上文字",
|
|
166
|
+
pastePlaceholder: "要貼到電腦上的文字",
|
|
167
|
+
fit: "符合螢幕",
|
|
168
|
+
take: "在這裡操作",
|
|
169
|
+
watching: "{name} 正在操作",
|
|
170
|
+
watchingYou: "正在你的另一個頁面上操作",
|
|
171
|
+
viewOnly: "你只能觀看",
|
|
172
|
+
quality: "畫面",
|
|
173
|
+
auto: "自動",
|
|
174
|
+
crisp: "清晰",
|
|
175
|
+
smooth: "流暢",
|
|
176
|
+
username: "帳號",
|
|
177
|
+
passwordField: "密碼",
|
|
178
|
+
signInTitle: "登入 {name}",
|
|
179
|
+
signInMac: "用這台 Mac 的開機帳號和密碼",
|
|
180
|
+
signInVnc: "輸入這台電腦螢幕共享(VNC)的密碼",
|
|
181
|
+
refusedAccount: "帳號或密碼不對,請再試一次",
|
|
182
|
+
refusedPassword: "密碼不對,請再試一次",
|
|
183
|
+
showPassword: "顯示密碼",
|
|
184
|
+
signingIn: "正在登入…",
|
|
185
|
+
cancel: "取消",
|
|
186
|
+
remember: "記住密碼,下次自動登入",
|
|
187
|
+
ok: "連線",
|
|
188
|
+
none: "還沒有可以開啟的電腦",
|
|
189
|
+
noneHint: "在電腦上開啟螢幕共享,再到這裡新增",
|
|
190
|
+
setupHint: "Mac:系統設定 → 一般 → 共享 → 螢幕共享。Windows 或 Linux:安裝一個 VNC 服務,例如 TigerVNC。",
|
|
191
|
+
viewers: "{n} 個頁面開著",
|
|
192
|
+
failed: "連不上:{reason}"
|
|
193
|
+
};
|
|
194
|
+
var JA = {
|
|
195
|
+
hideBar: "ツールバーを隠す",
|
|
196
|
+
showBar: "ツールバーを表示",
|
|
197
|
+
modifiers: "キー",
|
|
198
|
+
title: "リモートデスクトップ",
|
|
199
|
+
intro: "ここからパソコンの画面を見て操作します",
|
|
200
|
+
thisComputer: "このパソコン",
|
|
201
|
+
added: "追加済み",
|
|
202
|
+
hosts: "リモートホスト",
|
|
203
|
+
add: "パソコンを追加",
|
|
204
|
+
addTitle: "パソコンを追加",
|
|
205
|
+
addHint: "画面共有(VNC)のアドレスとポート。例:192.168.1.20 または 192.168.1.20:5901",
|
|
206
|
+
remove: "削除",
|
|
207
|
+
removeConfirm: "{name} を一覧から削除しますか?",
|
|
208
|
+
open: "開く",
|
|
209
|
+
connecting: "接続中…",
|
|
210
|
+
lost: "接続が切れました",
|
|
211
|
+
retry: "再接続",
|
|
212
|
+
back: "戻る",
|
|
213
|
+
keyboard: "キーボード",
|
|
214
|
+
trackpad: "トラックパッド",
|
|
215
|
+
direct: "指した所をタップ",
|
|
216
|
+
paste: "テキストを貼り付け",
|
|
217
|
+
pastePlaceholder: "パソコンに貼り付けるテキスト",
|
|
218
|
+
fit: "画面に合わせる",
|
|
219
|
+
take: "ここで操作",
|
|
220
|
+
watching: "{name} が操作中",
|
|
221
|
+
watchingYou: "あなたの別のページで操作中",
|
|
222
|
+
viewOnly: "見るだけです",
|
|
223
|
+
quality: "画質",
|
|
224
|
+
auto: "自動",
|
|
225
|
+
crisp: "鮮明",
|
|
226
|
+
smooth: "なめらか",
|
|
227
|
+
username: "アカウント",
|
|
228
|
+
passwordField: "パスワード",
|
|
229
|
+
signInTitle: "{name} にサインイン",
|
|
230
|
+
signInMac: "この Mac にログインするアカウントとパスワード",
|
|
231
|
+
signInVnc: "この画面共有(VNC)のパスワード",
|
|
232
|
+
refusedAccount: "アカウントまたはパスワードが違います。もう一度どうぞ",
|
|
233
|
+
refusedPassword: "パスワードが違います。もう一度どうぞ",
|
|
234
|
+
showPassword: "パスワードを表示",
|
|
235
|
+
signingIn: "サインイン中…",
|
|
236
|
+
cancel: "キャンセル",
|
|
237
|
+
remember: "パスワードを保存し、次回は自動でサインイン",
|
|
238
|
+
ok: "接続",
|
|
239
|
+
none: "開けるパソコンがまだありません",
|
|
240
|
+
noneHint: "パソコンで画面共有をオンにしてから、ここで追加します",
|
|
241
|
+
setupHint: "Mac:システム設定 → 一般 → 共有 → 画面共有。Windows や Linux:TigerVNC などの VNC サーバー。",
|
|
242
|
+
viewers: "{n} ページで表示中",
|
|
243
|
+
failed: "接続できません:{reason}"
|
|
244
|
+
};
|
|
245
|
+
var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
|
|
246
|
+
var DesktopWordsUtil;
|
|
247
|
+
((DesktopWordsUtil) => {
|
|
248
|
+
function of(language) {
|
|
249
|
+
return TaLanguageUtil.pick(language, WORDS);
|
|
250
|
+
}
|
|
251
|
+
DesktopWordsUtil.of = of;
|
|
252
|
+
function format(text, values) {
|
|
253
|
+
return text.replace(/\{(\w+)\}/g, (whole, key) => (key in values) ? String(values[key]) : whole);
|
|
254
|
+
}
|
|
255
|
+
DesktopWordsUtil.format = format;
|
|
256
|
+
})(DesktopWordsUtil ||= {});
|
|
257
|
+
|
|
258
|
+
// web-src/react.ts
|
|
259
|
+
var React;
|
|
260
|
+
function bind(react) {
|
|
261
|
+
React = react;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// web-src/desktop-sign-in.tsx
|
|
265
|
+
function DesktopSignIn({ pi, prompt, onCancel }) {
|
|
266
|
+
const words = DesktopWordsUtil.of(pi.ui.language);
|
|
267
|
+
const [user, setUser] = React.useState(prompt.user ?? "");
|
|
268
|
+
const [password, setPassword] = React.useState("");
|
|
269
|
+
const [shown, setShown] = React.useState(false);
|
|
270
|
+
const [remember, setRemember] = React.useState(true);
|
|
271
|
+
const [sent, setSent] = React.useState(false);
|
|
272
|
+
const userRef = React.useRef(null);
|
|
273
|
+
const passwordRef = React.useRef(null);
|
|
274
|
+
React.useEffect(() => (prompt.account && !prompt.user ? userRef : passwordRef).current?.focus(), []);
|
|
275
|
+
const ready = !!password && (!prompt.account || !!user.trim());
|
|
276
|
+
const answer = (given) => void pi.screenShare?.answerDesktop(prompt.promptId, given, given !== null && !!prompt.remember && remember).catch(() => {
|
|
277
|
+
return;
|
|
278
|
+
});
|
|
279
|
+
const Icon = pi.ui.icons.Monitor;
|
|
280
|
+
return /* @__PURE__ */ React.createElement("form", {
|
|
281
|
+
className: "trd-signin",
|
|
282
|
+
onSubmit: (event) => {
|
|
283
|
+
event.preventDefault();
|
|
284
|
+
if (ready && !sent) {
|
|
285
|
+
setSent(true);
|
|
286
|
+
answer({ password, ...prompt.account ? { username: user.trim() } : {} });
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
290
|
+
className: "trd-signin-icon",
|
|
291
|
+
"aria-hidden": "true"
|
|
292
|
+
}, /* @__PURE__ */ React.createElement(Icon, {
|
|
293
|
+
size: 22
|
|
294
|
+
})), /* @__PURE__ */ React.createElement("h2", {
|
|
295
|
+
className: "trd-signin-title"
|
|
296
|
+
}, DesktopWordsUtil.format(words.signInTitle, { name: prompt.name })), /* @__PURE__ */ React.createElement("p", {
|
|
297
|
+
className: `trd-signin-hint${prompt.refused ? " trd-signin-refused" : ""}`,
|
|
298
|
+
role: prompt.refused ? "alert" : undefined
|
|
299
|
+
}, prompt.refused ? prompt.account ? words.refusedAccount : words.refusedPassword : prompt.account ? words.signInMac : words.signInVnc), /* @__PURE__ */ React.createElement("div", {
|
|
300
|
+
className: "trd-signin-fields"
|
|
301
|
+
}, prompt.account && /* @__PURE__ */ React.createElement("input", {
|
|
302
|
+
ref: userRef,
|
|
303
|
+
className: "trd-signin-input",
|
|
304
|
+
"aria-label": words.username,
|
|
305
|
+
placeholder: words.username,
|
|
306
|
+
autoComplete: "username",
|
|
307
|
+
autoCapitalize: "none",
|
|
308
|
+
autoCorrect: "off",
|
|
309
|
+
spellCheck: false,
|
|
310
|
+
enterKeyHint: "next",
|
|
311
|
+
value: user,
|
|
312
|
+
onChange: (event) => setUser(event.target.value),
|
|
313
|
+
onKeyDown: (event) => {
|
|
314
|
+
if (event.key === "Enter" && !event.nativeEvent.isComposing) {
|
|
315
|
+
event.preventDefault();
|
|
316
|
+
passwordRef.current?.focus();
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}), /* @__PURE__ */ React.createElement("span", {
|
|
320
|
+
className: "trd-signin-secret"
|
|
321
|
+
}, /* @__PURE__ */ React.createElement("input", {
|
|
322
|
+
ref: passwordRef,
|
|
323
|
+
className: "trd-signin-input",
|
|
324
|
+
type: shown ? "text" : "password",
|
|
325
|
+
"aria-label": words.passwordField,
|
|
326
|
+
placeholder: words.passwordField,
|
|
327
|
+
autoComplete: "current-password",
|
|
328
|
+
autoCapitalize: "none",
|
|
329
|
+
autoCorrect: "off",
|
|
330
|
+
spellCheck: false,
|
|
331
|
+
enterKeyHint: "go",
|
|
332
|
+
value: password,
|
|
333
|
+
onChange: (event) => setPassword(event.target.value)
|
|
334
|
+
}), /* @__PURE__ */ React.createElement("button", {
|
|
335
|
+
type: "button",
|
|
336
|
+
className: `trd-signin-eye${shown ? " trd-on" : ""}`,
|
|
337
|
+
"aria-label": words.showPassword,
|
|
338
|
+
"aria-pressed": shown,
|
|
339
|
+
tabIndex: -1,
|
|
340
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
341
|
+
onClick: () => setShown(!shown)
|
|
342
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.icons.Eye, {
|
|
343
|
+
size: 18
|
|
344
|
+
})))), prompt.remember && /* @__PURE__ */ React.createElement("label", {
|
|
345
|
+
className: "trd-signin-remember"
|
|
346
|
+
}, /* @__PURE__ */ React.createElement("input", {
|
|
347
|
+
type: "checkbox",
|
|
348
|
+
checked: remember,
|
|
349
|
+
onChange: (event) => setRemember(event.target.checked)
|
|
350
|
+
}), /* @__PURE__ */ React.createElement("span", null, words.remember)), /* @__PURE__ */ React.createElement("button", {
|
|
351
|
+
type: "submit",
|
|
352
|
+
className: "trd-signin-go",
|
|
353
|
+
disabled: !ready || sent
|
|
354
|
+
}, sent ? words.signingIn : words.ok), /* @__PURE__ */ React.createElement("button", {
|
|
355
|
+
type: "button",
|
|
356
|
+
className: "trd-signin-cancel",
|
|
357
|
+
onClick: () => {
|
|
358
|
+
answer(null);
|
|
359
|
+
onCancel();
|
|
360
|
+
}
|
|
361
|
+
}, words.cancel));
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// web-src/desktop-gestures.ts
|
|
365
|
+
var TAP_SLOP = 10;
|
|
366
|
+
var HOLD_MS = 450;
|
|
367
|
+
var DOUBLE_MS = 300;
|
|
368
|
+
var DRAG_AFTER_TAP_MS = 250;
|
|
369
|
+
var PINCH_RATIO = 0.08;
|
|
370
|
+
var PINCH_DECIDE_MS = 80;
|
|
371
|
+
var NOTCH = 24;
|
|
372
|
+
|
|
373
|
+
class DesktopGestures {
|
|
374
|
+
mode;
|
|
375
|
+
emit;
|
|
376
|
+
now;
|
|
377
|
+
later;
|
|
378
|
+
state = { kind: "idle" };
|
|
379
|
+
lastTap;
|
|
380
|
+
holdTimer;
|
|
381
|
+
constructor(mode, emit, now = () => Date.now(), later = setTimeout) {
|
|
382
|
+
this.mode = mode;
|
|
383
|
+
this.emit = emit;
|
|
384
|
+
this.now = now;
|
|
385
|
+
this.later = later;
|
|
386
|
+
}
|
|
387
|
+
down(touches) {
|
|
388
|
+
const at = this.now();
|
|
389
|
+
if (touches.length === 1 && this.state.kind === "idle") {
|
|
390
|
+
const start = touches[0];
|
|
391
|
+
const afterTap = this.lastTap && at - this.lastTap.at < DRAG_AFTER_TAP_MS && Math.hypot(start.x - this.lastTap.x, start.y - this.lastTap.y) < TAP_SLOP * 3;
|
|
392
|
+
this.state = {
|
|
393
|
+
kind: "one",
|
|
394
|
+
start,
|
|
395
|
+
last: start,
|
|
396
|
+
at,
|
|
397
|
+
moved: false,
|
|
398
|
+
dragging: false,
|
|
399
|
+
held: false,
|
|
400
|
+
afterTap: this.mode() === "trackpad" && !!afterTap
|
|
401
|
+
};
|
|
402
|
+
this.holdTimer = this.later(() => this.hold(), HOLD_MS);
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (touches.length >= 2) {
|
|
406
|
+
this.cancelHold();
|
|
407
|
+
if (this.state.kind === "one" && this.state.dragging) {
|
|
408
|
+
this.emit({ kind: "release" });
|
|
409
|
+
}
|
|
410
|
+
const pair = [touches[0], touches[1]];
|
|
411
|
+
this.state = { kind: "two", start: pair, last: pair, at, moved: false, rest: 0 };
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
move(touches) {
|
|
415
|
+
const state = this.state;
|
|
416
|
+
if (state.kind === "one" && touches.length === 1) {
|
|
417
|
+
const point = touches[0];
|
|
418
|
+
if (!state.moved && Math.hypot(point.x - state.start.x, point.y - state.start.y) < TAP_SLOP) {
|
|
419
|
+
return;
|
|
420
|
+
}
|
|
421
|
+
if (!state.moved) {
|
|
422
|
+
state.moved = true;
|
|
423
|
+
this.cancelHold();
|
|
424
|
+
if (state.afterTap && !state.dragging) {
|
|
425
|
+
state.dragging = true;
|
|
426
|
+
this.lastTap = undefined;
|
|
427
|
+
this.emit({ kind: "press" });
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
const dx = point.x - state.last.x;
|
|
431
|
+
const dy = point.y - state.last.y;
|
|
432
|
+
state.last = point;
|
|
433
|
+
if (this.mode() === "trackpad") {
|
|
434
|
+
this.emit({ kind: "move", dx, dy });
|
|
435
|
+
} else if (state.dragging) {
|
|
436
|
+
this.emit({ kind: "point", x: point.x, y: point.y });
|
|
437
|
+
} else {
|
|
438
|
+
this.emit({ kind: "pan", dx, dy });
|
|
439
|
+
}
|
|
440
|
+
return;
|
|
441
|
+
}
|
|
442
|
+
if (state.kind === "two" && touches.length >= 2) {
|
|
443
|
+
const pair = [touches[0], touches[1]];
|
|
444
|
+
const distance = (a, b) => Math.hypot(a.x - b.x, a.y - b.y);
|
|
445
|
+
const middle = (a, b) => ({ x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 });
|
|
446
|
+
const start = distance(...state.start);
|
|
447
|
+
const was = distance(...state.last);
|
|
448
|
+
const is = distance(...pair);
|
|
449
|
+
const before = middle(...state.last);
|
|
450
|
+
const after = middle(...pair);
|
|
451
|
+
if (!state.mode) {
|
|
452
|
+
if (Math.abs(is - start) / Math.max(1, start) > PINCH_RATIO) {
|
|
453
|
+
state.mode = "zoom";
|
|
454
|
+
} else if (this.now() - state.at > PINCH_DECIDE_MS && Math.hypot(after.x - middle(...state.start).x, after.y - middle(...state.start).y) > TAP_SLOP) {
|
|
455
|
+
state.mode = "scroll";
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
if (Math.hypot(after.x - before.x, after.y - before.y) > 0 || is !== was) {
|
|
459
|
+
state.moved = state.moved || Math.abs(is - start) > TAP_SLOP || Math.hypot(after.x - middle(...state.start).x, after.y - middle(...state.start).y) > TAP_SLOP;
|
|
460
|
+
}
|
|
461
|
+
if (state.mode === "zoom") {
|
|
462
|
+
this.emit({ kind: "zoom", factor: is / Math.max(1, was), x: after.x, y: after.y });
|
|
463
|
+
this.emit({ kind: "pan", dx: after.x - before.x, dy: after.y - before.y });
|
|
464
|
+
} else if (state.mode === "scroll") {
|
|
465
|
+
state.rest += before.y - after.y;
|
|
466
|
+
const notches = Math.trunc(state.rest / NOTCH);
|
|
467
|
+
if (notches) {
|
|
468
|
+
state.rest -= notches * NOTCH;
|
|
469
|
+
this.emit({ kind: "scroll", dx: 0, dy: notches });
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
state.last = pair;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
up(remaining) {
|
|
476
|
+
const state = this.state;
|
|
477
|
+
const at = this.now();
|
|
478
|
+
this.cancelHold();
|
|
479
|
+
if (state.kind === "one") {
|
|
480
|
+
if (state.dragging) {
|
|
481
|
+
this.emit({ kind: "release" });
|
|
482
|
+
} else if (!state.moved && !state.held) {
|
|
483
|
+
const double = state.afterTap || !!this.lastTap && at - this.lastTap.at < DOUBLE_MS;
|
|
484
|
+
const where = this.mode() === "direct" ? { x: state.start.x, y: state.start.y } : {};
|
|
485
|
+
this.emit({ kind: "click", button: "left", ...where, ...double ? { double: true } : {} });
|
|
486
|
+
this.lastTap = double ? undefined : { at, x: state.start.x, y: state.start.y };
|
|
487
|
+
}
|
|
488
|
+
this.state = { kind: "idle" };
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
if (state.kind === "two" && remaining.length === 0) {
|
|
492
|
+
if (!state.moved && at - state.at < HOLD_MS) {
|
|
493
|
+
this.emit({ kind: "click", button: "right" });
|
|
494
|
+
}
|
|
495
|
+
this.state = { kind: "idle" };
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
cancel() {
|
|
499
|
+
this.cancelHold();
|
|
500
|
+
if (this.state.kind === "one" && this.state.dragging) {
|
|
501
|
+
this.emit({ kind: "release" });
|
|
502
|
+
}
|
|
503
|
+
this.state = { kind: "idle" };
|
|
504
|
+
}
|
|
505
|
+
hold() {
|
|
506
|
+
const state = this.state;
|
|
507
|
+
if (state.kind !== "one" || state.moved) {
|
|
508
|
+
return;
|
|
509
|
+
}
|
|
510
|
+
state.held = true;
|
|
511
|
+
if (state.afterTap) {
|
|
512
|
+
state.dragging = true;
|
|
513
|
+
this.lastTap = undefined;
|
|
514
|
+
this.emit({ kind: "press" });
|
|
515
|
+
} else if (this.mode() === "direct") {
|
|
516
|
+
state.dragging = true;
|
|
517
|
+
this.emit({ kind: "press", x: state.start.x, y: state.start.y });
|
|
518
|
+
} else {
|
|
519
|
+
this.emit({ kind: "click", button: "right" });
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
cancelHold() {
|
|
523
|
+
if (this.holdTimer !== undefined) {
|
|
524
|
+
clearTimeout(this.holdTimer);
|
|
525
|
+
this.holdTimer = undefined;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// ../ta-protocol/esm/common/screen-share-protocol.js
|
|
531
|
+
var TaScreenShareServer = Symbol("TaScreenShareServer");
|
|
532
|
+
var TaDesktopUtil;
|
|
533
|
+
(function(TaDesktopUtil2) {
|
|
534
|
+
TaDesktopUtil2.DEFAULT_PORT = 5900;
|
|
535
|
+
function id(target) {
|
|
536
|
+
var _a;
|
|
537
|
+
return `${(_a = target.via) !== null && _a !== undefined ? _a : ""}|${host(target)}:${port(target)}`;
|
|
538
|
+
}
|
|
539
|
+
TaDesktopUtil2.id = id;
|
|
540
|
+
function host(target) {
|
|
541
|
+
var _a;
|
|
542
|
+
return ((_a = target.host) !== null && _a !== undefined ? _a : "").trim() || "127.0.0.1";
|
|
543
|
+
}
|
|
544
|
+
TaDesktopUtil2.host = host;
|
|
545
|
+
function port(target) {
|
|
546
|
+
var _a;
|
|
547
|
+
return (_a = target.port) !== null && _a !== undefined ? _a : TaDesktopUtil2.DEFAULT_PORT;
|
|
548
|
+
}
|
|
549
|
+
TaDesktopUtil2.port = port;
|
|
550
|
+
function parse(id2) {
|
|
551
|
+
const match = /^([^|]*)\|(.+):(\d+)$/.exec(String(id2 !== null && id2 !== undefined ? id2 : ""));
|
|
552
|
+
if (!match) {
|
|
553
|
+
return;
|
|
554
|
+
}
|
|
555
|
+
const port2 = Number(match[3]);
|
|
556
|
+
return port2 > 0 && port2 < 65536 ? { via: match[1], host: match[2], port: port2 } : undefined;
|
|
557
|
+
}
|
|
558
|
+
TaDesktopUtil2.parse = parse;
|
|
559
|
+
function validPort(port2) {
|
|
560
|
+
return typeof port2 === "number" && Number.isInteger(port2) && port2 >= 1024 && port2 < 65536;
|
|
561
|
+
}
|
|
562
|
+
TaDesktopUtil2.validPort = validPort;
|
|
563
|
+
function loopback(host2) {
|
|
564
|
+
return /^(127\.\d+\.\d+\.\d+|localhost|::1|\[::1\])$/i.test(host2);
|
|
565
|
+
}
|
|
566
|
+
TaDesktopUtil2.loopback = loopback;
|
|
567
|
+
function validHost(host2) {
|
|
568
|
+
return typeof host2 === "string" && /^[A-Za-z0-9.:\-[\]]{1,253}$/.test(host2);
|
|
569
|
+
}
|
|
570
|
+
TaDesktopUtil2.validHost = validHost;
|
|
571
|
+
})(TaDesktopUtil || (TaDesktopUtil = {}));
|
|
572
|
+
var TA_DESKTOP_KEYSYMS = {
|
|
573
|
+
Backspace: 65288,
|
|
574
|
+
Tab: 65289,
|
|
575
|
+
Enter: 65293,
|
|
576
|
+
Escape: 65307,
|
|
577
|
+
Delete: 65535,
|
|
578
|
+
Home: 65360,
|
|
579
|
+
ArrowLeft: 65361,
|
|
580
|
+
ArrowUp: 65362,
|
|
581
|
+
ArrowRight: 65363,
|
|
582
|
+
ArrowDown: 65364,
|
|
583
|
+
PageUp: 65365,
|
|
584
|
+
PageDown: 65366,
|
|
585
|
+
End: 65367,
|
|
586
|
+
Insert: 65379,
|
|
587
|
+
F1: 65470,
|
|
588
|
+
F2: 65471,
|
|
589
|
+
F3: 65472,
|
|
590
|
+
F4: 65473,
|
|
591
|
+
F5: 65474,
|
|
592
|
+
F6: 65475,
|
|
593
|
+
F7: 65476,
|
|
594
|
+
F8: 65477,
|
|
595
|
+
F9: 65478,
|
|
596
|
+
F10: 65479,
|
|
597
|
+
F11: 65480,
|
|
598
|
+
F12: 65481,
|
|
599
|
+
Shift: 65505,
|
|
600
|
+
Control: 65507,
|
|
601
|
+
Meta: 65511,
|
|
602
|
+
Alt: 65513,
|
|
603
|
+
Super: 65515,
|
|
604
|
+
CapsLock: 65509
|
|
605
|
+
};
|
|
606
|
+
|
|
607
|
+
// web-src/desktop-keys.ts
|
|
608
|
+
var DESKTOP_MODIFIERS = ["Control", "Alt", "Meta", "Shift"];
|
|
609
|
+
var DesktopKeys;
|
|
610
|
+
((DesktopKeys) => {
|
|
611
|
+
function keysym(key) {
|
|
612
|
+
const named = TA_DESKTOP_KEYSYMS[key];
|
|
613
|
+
if (named !== undefined) {
|
|
614
|
+
return named;
|
|
615
|
+
}
|
|
616
|
+
const chars = [...key];
|
|
617
|
+
if (chars.length !== 1) {
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
const code = chars[0].codePointAt(0) ?? 0;
|
|
621
|
+
return code >= 32 && code <= 255 ? code : code > 255 ? 16777216 + code : undefined;
|
|
622
|
+
}
|
|
623
|
+
DesktopKeys.keysym = keysym;
|
|
624
|
+
function typed(text) {
|
|
625
|
+
const out = [];
|
|
626
|
+
for (const char of text) {
|
|
627
|
+
const sym = char === `
|
|
628
|
+
` ? TA_DESKTOP_KEYSYMS.Enter : keysym(char);
|
|
629
|
+
if (sym !== undefined) {
|
|
630
|
+
out.push({ keysym: sym, down: true }, { keysym: sym, down: false });
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
return out;
|
|
634
|
+
}
|
|
635
|
+
DesktopKeys.typed = typed;
|
|
636
|
+
function combo(key, modifiers) {
|
|
637
|
+
const main = keysym(key);
|
|
638
|
+
if (main === undefined) {
|
|
639
|
+
return [];
|
|
640
|
+
}
|
|
641
|
+
const held = modifiers.map((modifier) => TA_DESKTOP_KEYSYMS[modifier]);
|
|
642
|
+
return [
|
|
643
|
+
...held.map((keysym2) => ({ keysym: keysym2, down: true })),
|
|
644
|
+
{ keysym: main, down: true },
|
|
645
|
+
{ keysym: main, down: false },
|
|
646
|
+
...[...held].reverse().map((keysym2) => ({ keysym: keysym2, down: false }))
|
|
647
|
+
];
|
|
648
|
+
}
|
|
649
|
+
DesktopKeys.combo = combo;
|
|
650
|
+
})(DesktopKeys ||= {});
|
|
651
|
+
|
|
652
|
+
// web-src/desktop-key-bar.tsx
|
|
653
|
+
var EXTRA_KEYS = ["Escape", "Tab", "ArrowLeft", "ArrowUp", "ArrowDown", "ArrowRight"];
|
|
654
|
+
var LABELS = {
|
|
655
|
+
Control: "Ctrl",
|
|
656
|
+
Alt: "⌥ Alt",
|
|
657
|
+
Meta: "⌘ Win",
|
|
658
|
+
Shift: "⇧",
|
|
659
|
+
Escape: "Esc",
|
|
660
|
+
Tab: "Tab",
|
|
661
|
+
ArrowLeft: "←",
|
|
662
|
+
ArrowUp: "↑",
|
|
663
|
+
ArrowDown: "↓",
|
|
664
|
+
ArrowRight: "→"
|
|
665
|
+
};
|
|
666
|
+
function DesktopKeyBar({ pi, send, onClose }) {
|
|
667
|
+
const words = DesktopWordsUtil.of(pi.ui.language);
|
|
668
|
+
const field = React.useRef(null);
|
|
669
|
+
const [held, setHeld] = React.useState({});
|
|
670
|
+
const heldRef = React.useRef(held);
|
|
671
|
+
heldRef.current = held;
|
|
672
|
+
pi.ui.useBackLayer(true, onClose);
|
|
673
|
+
React.useEffect(() => {
|
|
674
|
+
field.current?.focus();
|
|
675
|
+
}, []);
|
|
676
|
+
const press = (key) => {
|
|
677
|
+
const modifiers = DESKTOP_MODIFIERS.filter((modifier) => heldRef.current[modifier]);
|
|
678
|
+
const events = modifiers.length ? DesktopKeys.combo(key, modifiers) : DesktopKeys.combo(key, []);
|
|
679
|
+
send(events.map((event) => ({ kind: "key", ...event })));
|
|
680
|
+
if (modifiers.some((modifier) => heldRef.current[modifier] === "once")) {
|
|
681
|
+
setHeld((old) => Object.fromEntries(Object.entries(old).filter(([, how]) => how === "locked")));
|
|
682
|
+
}
|
|
683
|
+
};
|
|
684
|
+
const toggle = (modifier) => setHeld((old) => {
|
|
685
|
+
const now = old[modifier];
|
|
686
|
+
const next = { ...old };
|
|
687
|
+
if (!now) {
|
|
688
|
+
next[modifier] = "once";
|
|
689
|
+
} else if (now === "once") {
|
|
690
|
+
next[modifier] = "locked";
|
|
691
|
+
} else {
|
|
692
|
+
delete next[modifier];
|
|
693
|
+
}
|
|
694
|
+
return next;
|
|
695
|
+
});
|
|
696
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
697
|
+
className: "trd-keys",
|
|
698
|
+
role: "toolbar",
|
|
699
|
+
"aria-label": words.modifiers
|
|
700
|
+
}, /* @__PURE__ */ React.createElement("textarea", {
|
|
701
|
+
ref: field,
|
|
702
|
+
className: "trd-keys-field",
|
|
703
|
+
"data-native-press": "",
|
|
704
|
+
autoCapitalize: "off",
|
|
705
|
+
autoComplete: "off",
|
|
706
|
+
autoCorrect: "off",
|
|
707
|
+
spellCheck: false,
|
|
708
|
+
"aria-label": words.keyboard,
|
|
709
|
+
onKeyDown: (event) => {
|
|
710
|
+
if (event.key.length > 1 && event.key !== "Unidentified" && event.key !== "Process" && !event.nativeEvent.isComposing) {
|
|
711
|
+
event.preventDefault();
|
|
712
|
+
press(event.key);
|
|
713
|
+
} else if (event.key.length === 1 && DESKTOP_MODIFIERS.some((modifier) => heldRef.current[modifier])) {
|
|
714
|
+
event.preventDefault();
|
|
715
|
+
press(event.key);
|
|
716
|
+
}
|
|
717
|
+
},
|
|
718
|
+
onInput: (event) => {
|
|
719
|
+
const target = event.currentTarget;
|
|
720
|
+
if (event.nativeEvent.isComposing) {
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
if (target.value) {
|
|
724
|
+
for (const char of target.value) {
|
|
725
|
+
press(char === `
|
|
726
|
+
` ? "Enter" : char);
|
|
727
|
+
}
|
|
728
|
+
target.value = "";
|
|
729
|
+
}
|
|
730
|
+
},
|
|
731
|
+
onCompositionEnd: (event) => {
|
|
732
|
+
const text = event.data || event.currentTarget.value;
|
|
733
|
+
event.currentTarget.value = "";
|
|
734
|
+
for (const char of text) {
|
|
735
|
+
press(char);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}), DESKTOP_MODIFIERS.map((modifier) => /* @__PURE__ */ React.createElement("button", {
|
|
739
|
+
key: modifier,
|
|
740
|
+
type: "button",
|
|
741
|
+
className: `trd-key${held[modifier] ? " trd-on" : ""}${held[modifier] === "locked" ? " trd-locked" : ""}`,
|
|
742
|
+
"aria-pressed": !!held[modifier],
|
|
743
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
744
|
+
onClick: () => toggle(modifier)
|
|
745
|
+
}, LABELS[modifier])), EXTRA_KEYS.map((key) => /* @__PURE__ */ React.createElement("button", {
|
|
746
|
+
key,
|
|
747
|
+
type: "button",
|
|
748
|
+
className: "trd-key",
|
|
749
|
+
onPointerDown: (event) => event.preventDefault(),
|
|
750
|
+
onClick: () => press(key)
|
|
751
|
+
}, LABELS[key])));
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// web-src/desktop-link.ts
|
|
755
|
+
var RETRY_MS = [300, 1000, 3000];
|
|
756
|
+
var BATCH_MS = 16;
|
|
757
|
+
var MAX_WINDOW = 4;
|
|
758
|
+
var TARGET_FPS = 15;
|
|
759
|
+
var SAMPLES = 8;
|
|
760
|
+
|
|
761
|
+
class DesktopLink {
|
|
762
|
+
server;
|
|
763
|
+
target;
|
|
764
|
+
clientId;
|
|
765
|
+
device;
|
|
766
|
+
paint;
|
|
767
|
+
failed;
|
|
768
|
+
viewer;
|
|
769
|
+
have = 0;
|
|
770
|
+
out = new Set;
|
|
771
|
+
early = new Map;
|
|
772
|
+
cycles = [];
|
|
773
|
+
running = false;
|
|
774
|
+
seq = 0;
|
|
775
|
+
queue = [];
|
|
776
|
+
flushTimer;
|
|
777
|
+
revision = 0;
|
|
778
|
+
failures = 0;
|
|
779
|
+
constructor(server, target, clientId, device, paint, failed) {
|
|
780
|
+
this.server = server;
|
|
781
|
+
this.target = target;
|
|
782
|
+
this.clientId = clientId;
|
|
783
|
+
this.device = device;
|
|
784
|
+
this.paint = paint;
|
|
785
|
+
this.failed = failed;
|
|
786
|
+
}
|
|
787
|
+
get viewerId() {
|
|
788
|
+
return this.viewer?.viewerId;
|
|
789
|
+
}
|
|
790
|
+
async open(view) {
|
|
791
|
+
const viewer = await this.server.openDesktop({
|
|
792
|
+
target: this.target,
|
|
793
|
+
view: { ...view, revision: ++this.revision },
|
|
794
|
+
clientMessageId: `${this.clientId}|${this.target.via}|${this.target.host ?? ""}|${this.target.port ?? ""}`,
|
|
795
|
+
device: this.device
|
|
796
|
+
});
|
|
797
|
+
if (viewer.viewerId !== this.viewer?.viewerId) {
|
|
798
|
+
this.cycles = [];
|
|
799
|
+
}
|
|
800
|
+
this.viewer = viewer;
|
|
801
|
+
this.restart(viewer.next - 1);
|
|
802
|
+
if (!this.running) {
|
|
803
|
+
this.running = true;
|
|
804
|
+
}
|
|
805
|
+
this.fill();
|
|
806
|
+
return viewer;
|
|
807
|
+
}
|
|
808
|
+
close() {
|
|
809
|
+
this.running = false;
|
|
810
|
+
clearTimeout(this.flushTimer);
|
|
811
|
+
if (this.viewerId) {
|
|
812
|
+
this.server.closeDesktop(this.viewerId).catch(() => {
|
|
813
|
+
return;
|
|
814
|
+
});
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
setView(view) {
|
|
818
|
+
if (this.viewerId) {
|
|
819
|
+
this.server.setDesktopView(this.viewerId, { ...view, revision: ++this.revision }).catch(() => {
|
|
820
|
+
return;
|
|
821
|
+
});
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
input(events) {
|
|
825
|
+
this.queue.push(...events);
|
|
826
|
+
this.flushTimer ??= setTimeout(() => this.flush(), BATCH_MS);
|
|
827
|
+
}
|
|
828
|
+
async take() {
|
|
829
|
+
if (this.viewerId) {
|
|
830
|
+
await this.server.takeDesktopControl(this.viewerId);
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
async paste(text) {
|
|
834
|
+
if (this.viewerId) {
|
|
835
|
+
await this.server.pasteToDesktop(this.viewerId, { text, press: true, clientMessageId: `${this.clientId}|paste|${Date.now()}` });
|
|
836
|
+
}
|
|
837
|
+
}
|
|
838
|
+
get window() {
|
|
839
|
+
if (this.cycles.length === 0) {
|
|
840
|
+
return 1;
|
|
841
|
+
}
|
|
842
|
+
const sorted = [...this.cycles].sort((a, b) => a - b);
|
|
843
|
+
const cycle = sorted[Math.floor(sorted.length / 2)];
|
|
844
|
+
return Math.max(1, Math.min(MAX_WINDOW, Math.ceil(cycle / 1000 * TARGET_FPS)));
|
|
845
|
+
}
|
|
846
|
+
restart(have) {
|
|
847
|
+
this.have = have;
|
|
848
|
+
this.out.clear();
|
|
849
|
+
this.early.clear();
|
|
850
|
+
}
|
|
851
|
+
fill() {
|
|
852
|
+
if (!this.running || !this.viewerId) {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
855
|
+
for (let want = this.have + 1;want <= this.have + this.window; want++) {
|
|
856
|
+
if (!this.out.has(want) && !this.early.has(want)) {
|
|
857
|
+
this.claim(want);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
claim(want) {
|
|
862
|
+
const viewerId = this.viewerId;
|
|
863
|
+
this.out.add(want);
|
|
864
|
+
const sent = performance.now();
|
|
865
|
+
this.server.readDesktopFrames(viewerId, want).then((frames) => {
|
|
866
|
+
this.out.delete(want);
|
|
867
|
+
if (!this.running || viewerId !== this.viewerId) {
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
this.failures = 0;
|
|
871
|
+
this.arrived(want, frames, performance.now() - sent);
|
|
872
|
+
}, (error) => {
|
|
873
|
+
this.out.delete(want);
|
|
874
|
+
if (!this.running || viewerId !== this.viewerId) {
|
|
875
|
+
return;
|
|
876
|
+
}
|
|
877
|
+
this.failures++;
|
|
878
|
+
if (this.failures >= 3) {
|
|
879
|
+
this.running = false;
|
|
880
|
+
this.failed(error);
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
setTimeout(() => this.fill(), RETRY_MS[Math.min(this.failures, RETRY_MS.length) - 1]);
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
arrived(want, frames, took) {
|
|
887
|
+
if (frames.unknown) {
|
|
888
|
+
this.running = false;
|
|
889
|
+
this.failed(new Error("The desktop viewer is gone."));
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
if (frames.stale) {
|
|
893
|
+
this.restart(frames.seq);
|
|
894
|
+
this.fill();
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
if (frames.idle) {
|
|
898
|
+
this.claim(want);
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
this.cycles = [...this.cycles, Math.max(0, took - frames.waited)].slice(-SAMPLES);
|
|
902
|
+
this.early.set(frames.seq, frames);
|
|
903
|
+
for (;; ) {
|
|
904
|
+
const next = this.early.get(this.have + 1) ?? [...this.early.values()].find((one) => one.base === 0 && one.seq > this.have);
|
|
905
|
+
if (!next) {
|
|
906
|
+
break;
|
|
907
|
+
}
|
|
908
|
+
for (const seq of [...this.early.keys()]) {
|
|
909
|
+
if (seq <= next.seq) {
|
|
910
|
+
this.early.delete(seq);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
if (next.base !== 0 && next.base !== this.have) {
|
|
914
|
+
this.restart(this.have);
|
|
915
|
+
break;
|
|
916
|
+
}
|
|
917
|
+
this.have = next.seq;
|
|
918
|
+
this.paint(next);
|
|
919
|
+
}
|
|
920
|
+
this.fill();
|
|
921
|
+
}
|
|
922
|
+
flush() {
|
|
923
|
+
this.flushTimer = undefined;
|
|
924
|
+
const events = this.queue.splice(0);
|
|
925
|
+
if (events.length && this.viewerId) {
|
|
926
|
+
this.server.sendDesktopInput(this.viewerId, { seq: ++this.seq, events }).catch(() => {
|
|
927
|
+
return;
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
// web-src/desktop-picture.ts
|
|
934
|
+
class DesktopPicture {
|
|
935
|
+
changed;
|
|
936
|
+
backing;
|
|
937
|
+
cursorImage;
|
|
938
|
+
cursor;
|
|
939
|
+
chain = Promise.resolve();
|
|
940
|
+
constructor(changed) {
|
|
941
|
+
this.changed = changed;
|
|
942
|
+
}
|
|
943
|
+
take(frames) {
|
|
944
|
+
if (frames.cursor !== undefined) {
|
|
945
|
+
this.setCursor(frames.cursor);
|
|
946
|
+
}
|
|
947
|
+
if (!frames.view || frames.tiles.length === 0) {
|
|
948
|
+
return;
|
|
949
|
+
}
|
|
950
|
+
const view = frames.view;
|
|
951
|
+
const tiles = frames.tiles;
|
|
952
|
+
const decoded = Promise.all(tiles.map((tile) => DesktopPicture.decode(tile.jpeg)));
|
|
953
|
+
this.chain = this.chain.then(async () => {
|
|
954
|
+
const images = await decoded.catch(() => {
|
|
955
|
+
return;
|
|
956
|
+
});
|
|
957
|
+
if (!images) {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
const backing = this.backingFor(view);
|
|
961
|
+
const context = backing.canvas.getContext("2d");
|
|
962
|
+
if (!context) {
|
|
963
|
+
return;
|
|
964
|
+
}
|
|
965
|
+
tiles.forEach((tile, index) => {
|
|
966
|
+
context.drawImage(images[index], tile.x, tile.y, tile.w, tile.h);
|
|
967
|
+
images[index].close?.();
|
|
968
|
+
});
|
|
969
|
+
this.changed();
|
|
970
|
+
});
|
|
971
|
+
}
|
|
972
|
+
draw(context, viewport, dpr, pointer) {
|
|
973
|
+
const { canvas } = context;
|
|
974
|
+
context.setTransform(1, 0, 0, 1, 0, 0);
|
|
975
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
976
|
+
const backing = this.backing;
|
|
977
|
+
if (!backing) {
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
{
|
|
981
|
+
const scale = viewport.scale * dpr;
|
|
982
|
+
const dx = (backing.rect.x - viewport.x) * scale;
|
|
983
|
+
const dy = (backing.rect.y - viewport.y) * scale;
|
|
984
|
+
context.imageSmoothingEnabled = true;
|
|
985
|
+
context.imageSmoothingQuality = "high";
|
|
986
|
+
context.drawImage(backing.canvas, 0, 0, backing.width, backing.height, dx, dy, backing.rect.w * scale, backing.rect.h * scale);
|
|
987
|
+
}
|
|
988
|
+
if (pointer && this.cursor && this.cursorImage?.complete) {
|
|
989
|
+
const size = Math.max(1, viewport.scale) * dpr;
|
|
990
|
+
context.drawImage(this.cursorImage, (pointer.x - viewport.x) * viewport.scale * dpr - this.cursor.hotX * size, (pointer.y - viewport.y) * viewport.scale * dpr - this.cursor.hotY * size, this.cursor.width * size, this.cursor.height * size);
|
|
991
|
+
} else if (pointer && this.cursor === undefined) {
|
|
992
|
+
const x = (pointer.x - viewport.x) * viewport.scale * dpr;
|
|
993
|
+
const y = (pointer.y - viewport.y) * viewport.scale * dpr;
|
|
994
|
+
context.beginPath();
|
|
995
|
+
context.arc(x, y, 5 * dpr, 0, Math.PI * 2);
|
|
996
|
+
context.lineWidth = 1.5 * dpr;
|
|
997
|
+
context.strokeStyle = "rgba(255,255,255,0.9)";
|
|
998
|
+
context.fillStyle = "rgba(0,0,0,0.35)";
|
|
999
|
+
context.fill();
|
|
1000
|
+
context.stroke();
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
setCursor(cursor) {
|
|
1004
|
+
if (!cursor) {
|
|
1005
|
+
this.cursor = null;
|
|
1006
|
+
this.cursorImage = undefined;
|
|
1007
|
+
this.changed();
|
|
1008
|
+
return;
|
|
1009
|
+
}
|
|
1010
|
+
const image = new Image;
|
|
1011
|
+
image.onload = () => this.changed();
|
|
1012
|
+
image.src = `data:image/png;base64,${cursor.png}`;
|
|
1013
|
+
this.cursor = { hotX: cursor.hotX, hotY: cursor.hotY, width: cursor.width, height: cursor.height };
|
|
1014
|
+
this.cursorImage = image;
|
|
1015
|
+
}
|
|
1016
|
+
backingFor(view) {
|
|
1017
|
+
const current = this.backing;
|
|
1018
|
+
const same = current && current.width === view.width && current.height === view.height && current.rect.x === view.rect.x && current.rect.y === view.rect.y && current.rect.w === view.rect.w && current.rect.h === view.rect.h;
|
|
1019
|
+
if (same && current) {
|
|
1020
|
+
return current;
|
|
1021
|
+
}
|
|
1022
|
+
const canvas = document.createElement("canvas");
|
|
1023
|
+
canvas.width = view.width;
|
|
1024
|
+
canvas.height = view.height;
|
|
1025
|
+
if (current) {
|
|
1026
|
+
const context = canvas.getContext("2d");
|
|
1027
|
+
const sx = view.width / view.rect.w;
|
|
1028
|
+
const sy = view.height / view.rect.h;
|
|
1029
|
+
context?.drawImage(current.canvas, 0, 0, current.width, current.height, (current.rect.x - view.rect.x) * sx, (current.rect.y - view.rect.y) * sy, current.rect.w * sx, current.rect.h * sy);
|
|
1030
|
+
}
|
|
1031
|
+
this.backing = { canvas, rect: view.rect, width: view.width, height: view.height };
|
|
1032
|
+
return this.backing;
|
|
1033
|
+
}
|
|
1034
|
+
static async decode(base64) {
|
|
1035
|
+
const bytes = Uint8Array.from(atob(base64), (char) => char.charCodeAt(0));
|
|
1036
|
+
return createImageBitmap(new Blob([bytes], { type: "image/jpeg" }));
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
// web-src/desktop-viewport.ts
|
|
1041
|
+
var DesktopViewportUtil;
|
|
1042
|
+
((DesktopViewportUtil) => {
|
|
1043
|
+
DesktopViewportUtil.MAX_ZOOM = 4;
|
|
1044
|
+
function fitScale(desktop, box) {
|
|
1045
|
+
return Math.min(box.width / desktop.width, box.height / desktop.height);
|
|
1046
|
+
}
|
|
1047
|
+
DesktopViewportUtil.fitScale = fitScale;
|
|
1048
|
+
function fit(desktop, box) {
|
|
1049
|
+
const scale = fitScale(desktop, box);
|
|
1050
|
+
return clamp({ x: 0, y: 0, scale }, desktop, box);
|
|
1051
|
+
}
|
|
1052
|
+
DesktopViewportUtil.fit = fit;
|
|
1053
|
+
function clamp(view, desktop, box) {
|
|
1054
|
+
const min = fitScale(desktop, box);
|
|
1055
|
+
const scale = Math.max(min, Math.min(Math.max(min, DesktopViewportUtil.MAX_ZOOM), view.scale));
|
|
1056
|
+
const along = (at, size, room) => {
|
|
1057
|
+
const shown = room / scale;
|
|
1058
|
+
return shown >= size ? (size - shown) / 2 : Math.max(0, Math.min(size - shown, at));
|
|
1059
|
+
};
|
|
1060
|
+
return { scale, x: along(view.x, desktop.width, box.width), y: along(view.y, desktop.height, box.height) };
|
|
1061
|
+
}
|
|
1062
|
+
DesktopViewportUtil.clamp = clamp;
|
|
1063
|
+
function toDesktop(view, at) {
|
|
1064
|
+
return { x: view.x + at.x / view.scale, y: view.y + at.y / view.scale };
|
|
1065
|
+
}
|
|
1066
|
+
DesktopViewportUtil.toDesktop = toDesktop;
|
|
1067
|
+
function toBox(view, at) {
|
|
1068
|
+
return { x: (at.x - view.x) * view.scale, y: (at.y - view.y) * view.scale };
|
|
1069
|
+
}
|
|
1070
|
+
DesktopViewportUtil.toBox = toBox;
|
|
1071
|
+
function zoom(view, factor, about, desktop, box) {
|
|
1072
|
+
const fixed = toDesktop(view, about);
|
|
1073
|
+
const scale = view.scale * factor;
|
|
1074
|
+
return clamp({ scale, x: fixed.x - about.x / scale, y: fixed.y - about.y / scale }, desktop, box);
|
|
1075
|
+
}
|
|
1076
|
+
DesktopViewportUtil.zoom = zoom;
|
|
1077
|
+
function pan(view, by, desktop, box) {
|
|
1078
|
+
return clamp({ ...view, x: view.x - by.x / view.scale, y: view.y - by.y / view.scale }, desktop, box);
|
|
1079
|
+
}
|
|
1080
|
+
DesktopViewportUtil.pan = pan;
|
|
1081
|
+
function follow(view, point, desktop, box, margin = 40) {
|
|
1082
|
+
const at = toBox(view, point);
|
|
1083
|
+
const dx = at.x < margin ? at.x - margin : at.x > box.width - margin ? at.x - (box.width - margin) : 0;
|
|
1084
|
+
const dy = at.y < margin ? at.y - margin : at.y > box.height - margin ? at.y - (box.height - margin) : 0;
|
|
1085
|
+
return dx || dy ? pan(view, { x: -dx, y: -dy }, desktop, box) : view;
|
|
1086
|
+
}
|
|
1087
|
+
DesktopViewportUtil.follow = follow;
|
|
1088
|
+
function visible(view, desktop, box) {
|
|
1089
|
+
const x = Math.max(0, Math.floor(view.x));
|
|
1090
|
+
const y = Math.max(0, Math.floor(view.y));
|
|
1091
|
+
const w = Math.min(desktop.width - x, Math.ceil(box.width / view.scale) + 1);
|
|
1092
|
+
const h = Math.min(desktop.height - y, Math.ceil(box.height / view.scale) + 1);
|
|
1093
|
+
return { x, y, w: Math.max(1, w), h: Math.max(1, h) };
|
|
1094
|
+
}
|
|
1095
|
+
DesktopViewportUtil.visible = visible;
|
|
1096
|
+
})(DesktopViewportUtil ||= {});
|
|
1097
|
+
|
|
1098
|
+
// web-src/desktop-viewer.tsx
|
|
1099
|
+
function pageId() {
|
|
1100
|
+
const key = "ta-screen-share:page";
|
|
1101
|
+
let id = sessionStorage.getItem(key);
|
|
1102
|
+
if (!id) {
|
|
1103
|
+
id = crypto.randomUUID();
|
|
1104
|
+
sessionStorage.setItem(key, id);
|
|
1105
|
+
}
|
|
1106
|
+
return id;
|
|
1107
|
+
}
|
|
1108
|
+
var BUTTON = { left: 1, right: 4 };
|
|
1109
|
+
function DesktopViewer({ pi, desktop, prompt, onBack }) {
|
|
1110
|
+
const words = DesktopWordsUtil.of(pi.ui.language);
|
|
1111
|
+
const { touch, handheld } = pi.ui.useDevice();
|
|
1112
|
+
const device = handheld ? "phone" : touch ? "tablet" : "computer";
|
|
1113
|
+
const boxRef = React.useRef(null);
|
|
1114
|
+
const canvasRef = React.useRef(null);
|
|
1115
|
+
const [shown, setShown] = React.useState({
|
|
1116
|
+
state: "connecting",
|
|
1117
|
+
control: null,
|
|
1118
|
+
width: 0,
|
|
1119
|
+
height: 0
|
|
1120
|
+
});
|
|
1121
|
+
const [mode, setMode] = React.useState(touch ? "trackpad" : "direct");
|
|
1122
|
+
const [quality, setQuality] = React.useState("auto");
|
|
1123
|
+
const [keyboard, setKeyboard] = React.useState(false);
|
|
1124
|
+
const [bar, setBar] = React.useState(true);
|
|
1125
|
+
const [opening, setOpening] = React.useState(0);
|
|
1126
|
+
const live = React.useRef({
|
|
1127
|
+
viewport: { x: 0, y: 0, scale: 1 },
|
|
1128
|
+
pointer: { x: 0, y: 0 },
|
|
1129
|
+
desktop: { width: 0, height: 0 },
|
|
1130
|
+
box: { width: 1, height: 1 },
|
|
1131
|
+
fitted: true,
|
|
1132
|
+
buttons: 0,
|
|
1133
|
+
mode,
|
|
1134
|
+
mine: false,
|
|
1135
|
+
frame: 0
|
|
1136
|
+
});
|
|
1137
|
+
live.current.mode = mode;
|
|
1138
|
+
const server = pi.screenShare;
|
|
1139
|
+
const [link, setLink] = React.useState();
|
|
1140
|
+
const picture = React.useMemo(() => new DesktopPicture(() => redraw()), []);
|
|
1141
|
+
function redraw() {
|
|
1142
|
+
if (live.current.frame) {
|
|
1143
|
+
return;
|
|
1144
|
+
}
|
|
1145
|
+
live.current.frame = requestAnimationFrame(() => {
|
|
1146
|
+
live.current.frame = 0;
|
|
1147
|
+
const canvas = canvasRef.current;
|
|
1148
|
+
const context = canvas?.getContext("2d");
|
|
1149
|
+
if (canvas && context) {
|
|
1150
|
+
picture.draw(context, live.current.viewport, window.devicePixelRatio || 1, live.current.mine || live.current.mode === "trackpad" ? live.current.pointer : undefined);
|
|
1151
|
+
}
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
const wanted = React.useCallback(() => {
|
|
1155
|
+
const { viewport, desktop: size, box } = live.current;
|
|
1156
|
+
const dpr = window.devicePixelRatio || 1;
|
|
1157
|
+
if (size.width < 1) {
|
|
1158
|
+
return { width: Math.round(box.width * dpr), height: Math.round(box.height * dpr), quality };
|
|
1159
|
+
}
|
|
1160
|
+
const rect = DesktopViewportUtil.visible(viewport, size, box);
|
|
1161
|
+
return { rect, width: Math.round(rect.w * viewport.scale * dpr), height: Math.round(rect.h * viewport.scale * dpr), quality };
|
|
1162
|
+
}, [quality]);
|
|
1163
|
+
React.useEffect(() => {
|
|
1164
|
+
if (!server) {
|
|
1165
|
+
return;
|
|
1166
|
+
}
|
|
1167
|
+
let closed = false;
|
|
1168
|
+
const next = new DesktopLink(server, desktop.target, pageId(), device, (frames) => {
|
|
1169
|
+
if (frames.size) {
|
|
1170
|
+
const fresh = live.current.desktop.width === 0;
|
|
1171
|
+
live.current.desktop = { width: frames.size.width, height: frames.size.height };
|
|
1172
|
+
if (fresh || live.current.fitted) {
|
|
1173
|
+
live.current.viewport = DesktopViewportUtil.fit(live.current.desktop, live.current.box);
|
|
1174
|
+
live.current.pointer = { x: frames.size.width / 2, y: frames.size.height / 2 };
|
|
1175
|
+
next.setView(wanted());
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
if (frames.control !== undefined) {
|
|
1179
|
+
live.current.mine = !!frames.control?.self;
|
|
1180
|
+
}
|
|
1181
|
+
setShown((old) => {
|
|
1182
|
+
const state = frames.state ?? old.state;
|
|
1183
|
+
const control = frames.control === undefined ? old.control : frames.control;
|
|
1184
|
+
const error = frames.state ? frames.error : old.error;
|
|
1185
|
+
const { width, height } = live.current.desktop;
|
|
1186
|
+
return old.state === state && old.error === error && old.control?.self === control?.self && old.control?.by === control?.by && old.width === width && old.height === height ? old : { state, error, control, width, height };
|
|
1187
|
+
});
|
|
1188
|
+
picture.take(frames);
|
|
1189
|
+
redraw();
|
|
1190
|
+
}, () => !closed && setTimeout(() => setOpening((n) => n + 1), 1000));
|
|
1191
|
+
setLink(next);
|
|
1192
|
+
next.open(wanted()).then((opened) => setShown((old) => ({ ...old, control: opened.control }))).catch((error) => {
|
|
1193
|
+
if (!closed) {
|
|
1194
|
+
setShown((old) => ({ ...old, state: "lost", error: error.message }));
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
return () => {
|
|
1198
|
+
closed = true;
|
|
1199
|
+
next.close();
|
|
1200
|
+
};
|
|
1201
|
+
}, [server, desktop.id, opening, device]);
|
|
1202
|
+
React.useEffect(() => link?.setView(wanted()), [link, wanted]);
|
|
1203
|
+
React.useLayoutEffect(() => {
|
|
1204
|
+
const box = boxRef.current;
|
|
1205
|
+
if (!box) {
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
let timer;
|
|
1209
|
+
const observer = new ResizeObserver(() => {
|
|
1210
|
+
const rect = box.getBoundingClientRect();
|
|
1211
|
+
const dpr = window.devicePixelRatio || 1;
|
|
1212
|
+
live.current.box = { width: Math.max(1, rect.width), height: Math.max(1, rect.height) };
|
|
1213
|
+
const canvas = canvasRef.current;
|
|
1214
|
+
if (canvas) {
|
|
1215
|
+
canvas.width = Math.round(rect.width * dpr);
|
|
1216
|
+
canvas.height = Math.round(rect.height * dpr);
|
|
1217
|
+
}
|
|
1218
|
+
if (live.current.desktop.width > 0) {
|
|
1219
|
+
live.current.viewport = live.current.fitted ? DesktopViewportUtil.fit(live.current.desktop, live.current.box) : DesktopViewportUtil.clamp(live.current.viewport, live.current.desktop, live.current.box);
|
|
1220
|
+
}
|
|
1221
|
+
redraw();
|
|
1222
|
+
clearTimeout(timer);
|
|
1223
|
+
timer = setTimeout(() => link?.setView(wanted()), 150);
|
|
1224
|
+
});
|
|
1225
|
+
observer.observe(box);
|
|
1226
|
+
return () => {
|
|
1227
|
+
observer.disconnect();
|
|
1228
|
+
clearTimeout(timer);
|
|
1229
|
+
};
|
|
1230
|
+
}, [link, wanted]);
|
|
1231
|
+
const send = React.useCallback((events) => link?.input(events), [link]);
|
|
1232
|
+
const viewTimer = React.useRef(undefined);
|
|
1233
|
+
const moveView = (viewport) => {
|
|
1234
|
+
live.current.viewport = viewport;
|
|
1235
|
+
live.current.fitted = viewport.scale <= DesktopViewportUtil.fitScale(live.current.desktop, live.current.box) + 0.000001;
|
|
1236
|
+
redraw();
|
|
1237
|
+
clearTimeout(viewTimer.current);
|
|
1238
|
+
viewTimer.current = setTimeout(() => link?.setView(wanted()), 120);
|
|
1239
|
+
};
|
|
1240
|
+
const pointerAt = (box) => {
|
|
1241
|
+
const point = DesktopViewportUtil.toDesktop(live.current.viewport, box);
|
|
1242
|
+
return pointerTo(point.x, point.y);
|
|
1243
|
+
};
|
|
1244
|
+
const pointerTo = (x, y) => {
|
|
1245
|
+
const { desktop: size } = live.current;
|
|
1246
|
+
live.current.pointer = { x: Math.max(0, Math.min(size.width - 1, x)), y: Math.max(0, Math.min(size.height - 1, y)) };
|
|
1247
|
+
return live.current.pointer;
|
|
1248
|
+
};
|
|
1249
|
+
const gestures = React.useMemo(() => new DesktopGestures(() => live.current.mode, (gesture) => {
|
|
1250
|
+
const state = live.current;
|
|
1251
|
+
if (state.desktop.width < 1) {
|
|
1252
|
+
return;
|
|
1253
|
+
}
|
|
1254
|
+
const at = (x, y) => x === undefined || y === undefined ? state.pointer : pointerAt({ x, y });
|
|
1255
|
+
switch (gesture.kind) {
|
|
1256
|
+
case "move": {
|
|
1257
|
+
const speed = Math.min(2.5, 1 + Math.hypot(gesture.dx, gesture.dy) / 30);
|
|
1258
|
+
const point = pointerTo(state.pointer.x + gesture.dx * speed / state.viewport.scale, state.pointer.y + gesture.dy * speed / state.viewport.scale);
|
|
1259
|
+
send([{ kind: "pointer", ...point, buttons: state.buttons }]);
|
|
1260
|
+
moveView(DesktopViewportUtil.follow(state.viewport, point, state.desktop, state.box));
|
|
1261
|
+
break;
|
|
1262
|
+
}
|
|
1263
|
+
case "point": {
|
|
1264
|
+
const point = at(gesture.x, gesture.y);
|
|
1265
|
+
send([{ kind: "pointer", ...point, buttons: state.buttons }]);
|
|
1266
|
+
redraw();
|
|
1267
|
+
break;
|
|
1268
|
+
}
|
|
1269
|
+
case "click": {
|
|
1270
|
+
const point = at(gesture.x, gesture.y);
|
|
1271
|
+
const button = BUTTON[gesture.button];
|
|
1272
|
+
const one = [
|
|
1273
|
+
{ kind: "pointer", ...point, buttons: 0 },
|
|
1274
|
+
{ kind: "pointer", ...point, buttons: button },
|
|
1275
|
+
{ kind: "pointer", ...point, buttons: 0 }
|
|
1276
|
+
];
|
|
1277
|
+
send(gesture.double ? [...one, ...one.slice(1)] : one);
|
|
1278
|
+
redraw();
|
|
1279
|
+
break;
|
|
1280
|
+
}
|
|
1281
|
+
case "press": {
|
|
1282
|
+
const point = at(gesture.x, gesture.y);
|
|
1283
|
+
state.buttons = BUTTON.left;
|
|
1284
|
+
send([{ kind: "pointer", ...point, buttons: state.buttons }]);
|
|
1285
|
+
break;
|
|
1286
|
+
}
|
|
1287
|
+
case "release":
|
|
1288
|
+
state.buttons = 0;
|
|
1289
|
+
send([{ kind: "pointer", ...state.pointer, buttons: 0 }]);
|
|
1290
|
+
break;
|
|
1291
|
+
case "scroll":
|
|
1292
|
+
send([{ kind: "wheel", ...state.pointer, dx: gesture.dx, dy: gesture.dy }]);
|
|
1293
|
+
break;
|
|
1294
|
+
case "zoom":
|
|
1295
|
+
moveView(DesktopViewportUtil.zoom(state.viewport, gesture.factor, { x: gesture.x, y: gesture.y }, state.desktop, state.box));
|
|
1296
|
+
break;
|
|
1297
|
+
case "pan":
|
|
1298
|
+
moveView(DesktopViewportUtil.pan(state.viewport, { x: gesture.dx, y: gesture.dy }, state.desktop, state.box));
|
|
1299
|
+
break;
|
|
1300
|
+
}
|
|
1301
|
+
}), [send]);
|
|
1302
|
+
const points = (event) => {
|
|
1303
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
1304
|
+
return Array.from({ length: event.touches.length }, (_, index) => event.touches[index]).map((one) => ({
|
|
1305
|
+
id: one.identifier,
|
|
1306
|
+
x: one.clientX - rect.left,
|
|
1307
|
+
y: one.clientY - rect.top
|
|
1308
|
+
}));
|
|
1309
|
+
};
|
|
1310
|
+
const mouse = (event, buttons) => {
|
|
1311
|
+
if (live.current.desktop.width < 1) {
|
|
1312
|
+
return;
|
|
1313
|
+
}
|
|
1314
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
1315
|
+
const point = pointerAt({ x: event.clientX - rect.left, y: event.clientY - rect.top });
|
|
1316
|
+
const rfb = buttons & 1 | (buttons & 4) >> 1 | (buttons & 2) << 1;
|
|
1317
|
+
send([{ kind: "pointer", ...point, buttons: rfb }]);
|
|
1318
|
+
};
|
|
1319
|
+
const key = (event, down) => {
|
|
1320
|
+
const keysym = DesktopKeys.keysym(event.key);
|
|
1321
|
+
if (keysym === undefined || event.nativeEvent.isComposing) {
|
|
1322
|
+
return;
|
|
1323
|
+
}
|
|
1324
|
+
event.preventDefault();
|
|
1325
|
+
send([{ kind: "key", keysym, down }]);
|
|
1326
|
+
};
|
|
1327
|
+
const mine = !!shown.control?.self;
|
|
1328
|
+
const watching = !!shown.control && !mine;
|
|
1329
|
+
const status = prompt ? undefined : shown.state === "connecting" ? words.connecting : shown.state === "lost" ? DesktopWordsUtil.format(words.failed, { reason: shown.error ?? words.lost }) : undefined;
|
|
1330
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
1331
|
+
className: `trd-viewer${bar ? "" : " trd-bare"}`
|
|
1332
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1333
|
+
ref: boxRef,
|
|
1334
|
+
className: "trd-screen",
|
|
1335
|
+
"data-own-gestures": "",
|
|
1336
|
+
role: "application",
|
|
1337
|
+
"aria-label": desktop.name,
|
|
1338
|
+
tabIndex: 0,
|
|
1339
|
+
onTouchStart: (event) => {
|
|
1340
|
+
if (mine) {
|
|
1341
|
+
gestures.down(points(event));
|
|
1342
|
+
}
|
|
1343
|
+
},
|
|
1344
|
+
onTouchMove: (event) => mine && gestures.move(points(event)),
|
|
1345
|
+
onTouchEnd: (event) => mine && gestures.up(points(event)),
|
|
1346
|
+
onTouchCancel: () => gestures.cancel(),
|
|
1347
|
+
onPointerMove: (event) => event.pointerType === "mouse" && mine && mouse(event, event.buttons),
|
|
1348
|
+
onPointerDown: (event) => {
|
|
1349
|
+
if (event.pointerType === "mouse" && mine) {
|
|
1350
|
+
event.currentTarget.focus();
|
|
1351
|
+
event.currentTarget.setPointerCapture(event.pointerId);
|
|
1352
|
+
mouse(event, event.buttons);
|
|
1353
|
+
}
|
|
1354
|
+
},
|
|
1355
|
+
onPointerUp: (event) => event.pointerType === "mouse" && mine && mouse(event, event.buttons),
|
|
1356
|
+
onContextMenu: (event) => event.preventDefault(),
|
|
1357
|
+
onWheel: (event) => {
|
|
1358
|
+
if (!mine || live.current.desktop.width < 1) {
|
|
1359
|
+
return;
|
|
1360
|
+
}
|
|
1361
|
+
if (event.ctrlKey) {
|
|
1362
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
1363
|
+
moveView(DesktopViewportUtil.zoom(live.current.viewport, Math.exp(-event.deltaY / 100), { x: event.clientX - rect.left, y: event.clientY - rect.top }, live.current.desktop, live.current.box));
|
|
1364
|
+
return;
|
|
1365
|
+
}
|
|
1366
|
+
const notches = (delta) => Math.sign(delta) * Math.min(5, Math.ceil(Math.abs(delta) / 40));
|
|
1367
|
+
send([{ kind: "wheel", ...live.current.pointer, dx: notches(event.deltaX), dy: notches(event.deltaY) }]);
|
|
1368
|
+
},
|
|
1369
|
+
onKeyDown: (event) => mine && key(event, true),
|
|
1370
|
+
onKeyUp: (event) => mine && key(event, false)
|
|
1371
|
+
}, /* @__PURE__ */ React.createElement("canvas", {
|
|
1372
|
+
ref: canvasRef,
|
|
1373
|
+
className: "trd-canvas"
|
|
1374
|
+
}), status && /* @__PURE__ */ React.createElement("div", {
|
|
1375
|
+
className: "trd-status",
|
|
1376
|
+
role: "status"
|
|
1377
|
+
}, /* @__PURE__ */ React.createElement("span", null, status), shown.state === "lost" && /* @__PURE__ */ React.createElement("button", {
|
|
1378
|
+
type: "button",
|
|
1379
|
+
className: "ta-button",
|
|
1380
|
+
onClick: () => setOpening((n) => n + 1)
|
|
1381
|
+
}, words.retry)), !status && watching && /* @__PURE__ */ React.createElement("div", {
|
|
1382
|
+
className: "trd-watching"
|
|
1383
|
+
}, /* @__PURE__ */ React.createElement("span", null, shown.control?.name ? DesktopWordsUtil.format(words.watching, { name: shown.control.name }) : words.watchingYou), /* @__PURE__ */ React.createElement("button", {
|
|
1384
|
+
type: "button",
|
|
1385
|
+
className: "ta-button",
|
|
1386
|
+
onClick: () => void link?.take().catch((error) => pi.ui.notify(error.message, "error"))
|
|
1387
|
+
}, words.take))), /* @__PURE__ */ React.createElement("div", {
|
|
1388
|
+
className: "trd-bar",
|
|
1389
|
+
role: "toolbar"
|
|
1390
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1391
|
+
type: "button",
|
|
1392
|
+
className: "trd-tool",
|
|
1393
|
+
title: words.back,
|
|
1394
|
+
"aria-label": words.back,
|
|
1395
|
+
onClick: onBack
|
|
1396
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.icons.ChevronLeft, {
|
|
1397
|
+
size: 18
|
|
1398
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
1399
|
+
className: "trd-name"
|
|
1400
|
+
}, desktop.name), touch && /* @__PURE__ */ React.createElement("button", {
|
|
1401
|
+
type: "button",
|
|
1402
|
+
className: `trd-tool${mode === "trackpad" ? " trd-on" : ""}`,
|
|
1403
|
+
title: mode === "trackpad" ? words.trackpad : words.direct,
|
|
1404
|
+
"aria-label": mode === "trackpad" ? words.trackpad : words.direct,
|
|
1405
|
+
onClick: () => setMode(mode === "trackpad" ? "direct" : "trackpad")
|
|
1406
|
+
}, mode === "trackpad" ? /* @__PURE__ */ React.createElement(pi.ui.icons.MousePointer2, {
|
|
1407
|
+
size: 18
|
|
1408
|
+
}) : /* @__PURE__ */ React.createElement(pi.ui.icons.Pointer, {
|
|
1409
|
+
size: 18
|
|
1410
|
+
})), /* @__PURE__ */ React.createElement("button", {
|
|
1411
|
+
type: "button",
|
|
1412
|
+
className: `trd-tool${keyboard ? " trd-on" : ""}`,
|
|
1413
|
+
title: words.keyboard,
|
|
1414
|
+
"aria-label": words.keyboard,
|
|
1415
|
+
disabled: !mine,
|
|
1416
|
+
onClick: () => setKeyboard(!keyboard)
|
|
1417
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.icons.Keyboard, {
|
|
1418
|
+
size: 18
|
|
1419
|
+
})), /* @__PURE__ */ React.createElement("button", {
|
|
1420
|
+
type: "button",
|
|
1421
|
+
className: "trd-tool",
|
|
1422
|
+
title: words.paste,
|
|
1423
|
+
"aria-label": words.paste,
|
|
1424
|
+
disabled: !mine,
|
|
1425
|
+
onClick: async () => {
|
|
1426
|
+
const text = await pi.ui.input(words.paste, words.pastePlaceholder);
|
|
1427
|
+
if (text) {
|
|
1428
|
+
await link?.paste(text).catch((error) => pi.ui.notify(error.message, "error"));
|
|
1429
|
+
}
|
|
1430
|
+
}
|
|
1431
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.icons.ClipboardPaste, {
|
|
1432
|
+
size: 18
|
|
1433
|
+
})), /* @__PURE__ */ React.createElement("button", {
|
|
1434
|
+
type: "button",
|
|
1435
|
+
className: "trd-tool",
|
|
1436
|
+
title: words.fit,
|
|
1437
|
+
"aria-label": words.fit,
|
|
1438
|
+
onClick: () => moveView(DesktopViewportUtil.fit(live.current.desktop, live.current.box))
|
|
1439
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.icons.Maximize, {
|
|
1440
|
+
size: 18
|
|
1441
|
+
})), /* @__PURE__ */ React.createElement("button", {
|
|
1442
|
+
type: "button",
|
|
1443
|
+
className: "trd-tool trd-quality",
|
|
1444
|
+
title: words.quality,
|
|
1445
|
+
onClick: () => setQuality(quality === "auto" ? "crisp" : quality === "crisp" ? "smooth" : "auto")
|
|
1446
|
+
}, words[quality]), touch && /* @__PURE__ */ React.createElement("button", {
|
|
1447
|
+
type: "button",
|
|
1448
|
+
className: "trd-tool",
|
|
1449
|
+
"aria-label": words.hideBar,
|
|
1450
|
+
onClick: () => setBar(false)
|
|
1451
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.icons.ChevronDown, {
|
|
1452
|
+
size: 18
|
|
1453
|
+
}))), !bar && /* @__PURE__ */ React.createElement("button", {
|
|
1454
|
+
type: "button",
|
|
1455
|
+
className: "trd-show-bar",
|
|
1456
|
+
"aria-label": words.showBar,
|
|
1457
|
+
onClick: () => setBar(true)
|
|
1458
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.icons.ChevronUp, {
|
|
1459
|
+
size: 16
|
|
1460
|
+
})), keyboard && mine && /* @__PURE__ */ React.createElement(DesktopKeyBar, {
|
|
1461
|
+
pi,
|
|
1462
|
+
send,
|
|
1463
|
+
onClose: () => setKeyboard(false)
|
|
1464
|
+
}), prompt && /* @__PURE__ */ React.createElement("div", {
|
|
1465
|
+
className: "trd-signin-layer"
|
|
1466
|
+
}, /* @__PURE__ */ React.createElement(DesktopSignIn, {
|
|
1467
|
+
key: prompt.promptId,
|
|
1468
|
+
pi,
|
|
1469
|
+
prompt,
|
|
1470
|
+
onCancel: onBack
|
|
1471
|
+
})));
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
// web-src/desktops-view.tsx
|
|
1475
|
+
function readAddress(text) {
|
|
1476
|
+
const trimmed = text.trim();
|
|
1477
|
+
const bracketed = /^\[([0-9A-Fa-f:.]+)\](?::(\d{1,5}))?$/.exec(trimmed);
|
|
1478
|
+
const plain = /^([A-Za-z0-9.-]+)(?::(\d{1,5}))?$/.exec(trimmed);
|
|
1479
|
+
const match = bracketed ?? plain;
|
|
1480
|
+
if (match) {
|
|
1481
|
+
return { host: match[1], ...match[2] ? { port: Number(match[2]) } : {} };
|
|
1482
|
+
}
|
|
1483
|
+
return /^[0-9A-Fa-f:]+$/.test(trimmed) && trimmed.includes(":") ? { host: trimmed } : undefined;
|
|
1484
|
+
}
|
|
1485
|
+
function DesktopsView({ pi }) {
|
|
1486
|
+
const words = DesktopWordsUtil.of(pi.ui.language);
|
|
1487
|
+
const server = pi.screenShare;
|
|
1488
|
+
const [desktops, setDesktops] = React.useState();
|
|
1489
|
+
const [failed, setFailed] = React.useState(false);
|
|
1490
|
+
const [open, setOpen] = React.useState();
|
|
1491
|
+
const [prompts, setPrompts] = React.useState([]);
|
|
1492
|
+
const [, busy] = pi.ui.useBusy();
|
|
1493
|
+
const Loading = pi.ui.Loading ?? pi.ui.Skeleton;
|
|
1494
|
+
const load = React.useCallback(() => {
|
|
1495
|
+
if (!server) {
|
|
1496
|
+
setFailed(true);
|
|
1497
|
+
return;
|
|
1498
|
+
}
|
|
1499
|
+
server.listDesktops().then((list) => {
|
|
1500
|
+
setDesktops(list);
|
|
1501
|
+
setFailed(false);
|
|
1502
|
+
}, () => setFailed(true));
|
|
1503
|
+
}, [server]);
|
|
1504
|
+
React.useEffect(load, [load]);
|
|
1505
|
+
React.useEffect(() => pi.onScreenShareEvent?.((event) => setPrompts((old) => event.type === "prompt" ? [...old.filter((one) => one.promptId !== event.prompt.promptId), event.prompt] : old.filter((one) => one.promptId !== event.promptId))), [pi]);
|
|
1506
|
+
const add = () => busy(async () => {
|
|
1507
|
+
const typed = await pi.ui.input(words.addTitle, words.addHint);
|
|
1508
|
+
const address = typed && readAddress(typed);
|
|
1509
|
+
if (!typed || !server) {
|
|
1510
|
+
return;
|
|
1511
|
+
}
|
|
1512
|
+
if (!address) {
|
|
1513
|
+
pi.ui.notify(words.addHint, "error");
|
|
1514
|
+
return;
|
|
1515
|
+
}
|
|
1516
|
+
try {
|
|
1517
|
+
await server.addDesktop({ via: "", ...address });
|
|
1518
|
+
load();
|
|
1519
|
+
} catch (error) {
|
|
1520
|
+
pi.ui.notify(error.message, "error");
|
|
1521
|
+
}
|
|
1522
|
+
});
|
|
1523
|
+
const remove = (desktop) => busy(async () => {
|
|
1524
|
+
if (server && await pi.ui.confirm(DesktopWordsUtil.format(words.removeConfirm, { name: desktop.name }), undefined, { danger: true })) {
|
|
1525
|
+
await server.removeDesktop(desktop.id).catch((error) => pi.ui.notify(error.message, "error"));
|
|
1526
|
+
load();
|
|
1527
|
+
}
|
|
1528
|
+
});
|
|
1529
|
+
const groups = desktops ? [
|
|
1530
|
+
[words.thisComputer, desktops.filter((one) => one.source === "this")],
|
|
1531
|
+
[words.added, desktops.filter((one) => one.source === "lan")],
|
|
1532
|
+
[words.hosts, desktops.filter((one) => one.source === "ssh")]
|
|
1533
|
+
] : [];
|
|
1534
|
+
const base = /* @__PURE__ */ React.createElement("div", {
|
|
1535
|
+
className: "trd-scroll"
|
|
1536
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
1537
|
+
className: "trd-page"
|
|
1538
|
+
}, /* @__PURE__ */ React.createElement("header", {
|
|
1539
|
+
className: "trd-head"
|
|
1540
|
+
}, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h1", {
|
|
1541
|
+
className: "trd-title"
|
|
1542
|
+
}, words.title), /* @__PURE__ */ React.createElement("p", {
|
|
1543
|
+
className: "trd-intro"
|
|
1544
|
+
}, words.intro)), /* @__PURE__ */ React.createElement("button", {
|
|
1545
|
+
type: "button",
|
|
1546
|
+
className: "ta-button",
|
|
1547
|
+
onClick: () => void add()
|
|
1548
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.icons.Plus, {
|
|
1549
|
+
size: 16
|
|
1550
|
+
}), /* @__PURE__ */ React.createElement("span", null, words.add))), !desktops && !failed && /* @__PURE__ */ React.createElement(Loading, null), failed && /* @__PURE__ */ React.createElement(pi.ui.Empty, {
|
|
1551
|
+
title: words.none,
|
|
1552
|
+
hint: words.noneHint,
|
|
1553
|
+
tone: "error"
|
|
1554
|
+
}), groups.map(([title, list]) => list.length > 0 && /* @__PURE__ */ React.createElement("section", {
|
|
1555
|
+
key: title,
|
|
1556
|
+
className: "trd-group"
|
|
1557
|
+
}, /* @__PURE__ */ React.createElement("h2", null, title), /* @__PURE__ */ React.createElement("ul", {
|
|
1558
|
+
className: "trd-list"
|
|
1559
|
+
}, list.map((desktop) => /* @__PURE__ */ React.createElement("li", {
|
|
1560
|
+
key: desktop.id
|
|
1561
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.SwipeRow, {
|
|
1562
|
+
actions: desktop.source === "lan" ? [{ key: "remove", label: words.remove, danger: true, run: () => void remove(desktop) }] : []
|
|
1563
|
+
}, /* @__PURE__ */ React.createElement("button", {
|
|
1564
|
+
type: "button",
|
|
1565
|
+
className: "trd-row",
|
|
1566
|
+
onClick: () => setOpen(desktop)
|
|
1567
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1568
|
+
className: "trd-icon"
|
|
1569
|
+
}, desktop.source === "ssh" ? /* @__PURE__ */ React.createElement(pi.ui.icons.Server, {
|
|
1570
|
+
size: 18
|
|
1571
|
+
}) : /* @__PURE__ */ React.createElement(pi.ui.icons.Monitor, {
|
|
1572
|
+
size: 18
|
|
1573
|
+
})), /* @__PURE__ */ React.createElement("span", {
|
|
1574
|
+
className: "trd-row-text"
|
|
1575
|
+
}, /* @__PURE__ */ React.createElement("span", {
|
|
1576
|
+
className: "trd-row-name"
|
|
1577
|
+
}, desktop.name), /* @__PURE__ */ React.createElement("span", {
|
|
1578
|
+
className: "trd-row-place"
|
|
1579
|
+
}, desktop.target.via ? desktop.target.via.replace(/^ssh:\/\//, "") : `${desktop.target.host ?? "127.0.0.1"}:${desktop.target.port ?? 5900}`, desktop.viewers.length > 0 ? ` · ${DesktopWordsUtil.format(words.viewers, { n: desktop.viewers.length })}` : "")), /* @__PURE__ */ React.createElement("span", {
|
|
1580
|
+
className: "trd-chevron"
|
|
1581
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.icons.ChevronRight, {
|
|
1582
|
+
size: 16
|
|
1583
|
+
}))))))))), /* @__PURE__ */ React.createElement("p", {
|
|
1584
|
+
className: "trd-note"
|
|
1585
|
+
}, words.setupHint)));
|
|
1586
|
+
const loose = prompts.find((prompt) => prompt.desktop !== open?.id);
|
|
1587
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
1588
|
+
className: "trd-root"
|
|
1589
|
+
}, /* @__PURE__ */ React.createElement(pi.ui.Stack, {
|
|
1590
|
+
base,
|
|
1591
|
+
top: open ? /* @__PURE__ */ React.createElement(DesktopViewer, {
|
|
1592
|
+
key: open.id,
|
|
1593
|
+
pi,
|
|
1594
|
+
desktop: open,
|
|
1595
|
+
prompt: prompts.find((prompt) => prompt.desktop === open.id),
|
|
1596
|
+
onBack: () => setOpen(undefined)
|
|
1597
|
+
}) : null,
|
|
1598
|
+
open: !!open,
|
|
1599
|
+
onClose: () => {
|
|
1600
|
+
setOpen(undefined);
|
|
1601
|
+
load();
|
|
1602
|
+
}
|
|
1603
|
+
}), loose && /* @__PURE__ */ React.createElement("div", {
|
|
1604
|
+
className: "trd-signin-layer trd-signin-over"
|
|
1605
|
+
}, /* @__PURE__ */ React.createElement(DesktopSignIn, {
|
|
1606
|
+
key: loose.promptId,
|
|
1607
|
+
pi,
|
|
1608
|
+
prompt: loose,
|
|
1609
|
+
onCancel: () => {
|
|
1610
|
+
return;
|
|
1611
|
+
}
|
|
1612
|
+
})));
|
|
1613
|
+
}
|
|
1614
|
+
|
|
1615
|
+
// web-src/style.ts
|
|
1616
|
+
var STYLE = `
|
|
1617
|
+
.trd-root { display: flex; flex-direction: column; flex: 1; min-height: 0; height: 100%; }
|
|
1618
|
+
.trd-scroll { flex: 1; min-height: 0; height: 100%; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
|
|
1619
|
+
.trd-page { display: flex; flex-direction: column; gap: 18px; width: 100%; max-width: var(--ta-page-wide); margin: 0 auto; padding: 28px 24px 48px; box-sizing: border-box; }
|
|
1620
|
+
.trd-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 0 2px; }
|
|
1621
|
+
.trd-title { margin: 0; color: var(--ta-text); font-size: calc(20px * var(--ta-font-scale)); line-height: calc(28px * var(--ta-font-scale)); font-weight: 600; }
|
|
1622
|
+
.trd-intro { margin: 4px 0 0; color: var(--ta-muted); font-size: calc(13.5px * var(--ta-font-scale)); line-height: calc(20px * var(--ta-font-scale)); }
|
|
1623
|
+
.trd-group h2 { margin: 0 2px 6px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: calc(18px * var(--ta-font-scale)); font-weight: 500; }
|
|
1624
|
+
.trd-list { margin: 0; padding: 0; list-style: none; border-radius: 12px; background: var(--ta-card); border: 1px solid var(--ta-border-muted); overflow: hidden; }
|
|
1625
|
+
.trd-list li + li { border-top: 1px solid var(--ta-border-muted); }
|
|
1626
|
+
.trd-row { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 14px; border: 0; background: transparent; color: var(--ta-text); font: inherit; text-align: left; cursor: pointer; }
|
|
1627
|
+
.trd-row:hover { background: var(--ta-hover); }
|
|
1628
|
+
.trd-icon { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; flex: none; border-radius: 10px; background: var(--ta-hover); color: var(--ta-text); }
|
|
1629
|
+
.trd-row-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
|
|
1630
|
+
.trd-row-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: calc(14px * var(--ta-font-scale)); line-height: calc(20px * var(--ta-font-scale)); font-weight: 500; }
|
|
1631
|
+
.trd-row-place { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: calc(18px * var(--ta-font-scale)); font-variant-numeric: tabular-nums; }
|
|
1632
|
+
.trd-chevron { display: inline-flex; color: var(--ta-muted); flex: none; }
|
|
1633
|
+
.trd-note { margin: 0 2px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: calc(18px * var(--ta-font-scale)); }
|
|
1634
|
+
.trd-viewer { position: relative; display: flex; flex-direction: column; height: 100%; min-height: 0; background: #0b0d10; color-scheme: dark; }
|
|
1635
|
+
.trd-screen { position: relative; flex: 1; min-height: 0; overflow: hidden; outline: none; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
|
|
1636
|
+
.trd-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
|
|
1637
|
+
.trd-status span, .trd-watching span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
1638
|
+
.trd-status .ta-button, .trd-watching .ta-button { flex: none; }
|
|
1639
|
+
.trd-status, .trd-watching { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; width: max-content; max-width: calc(100% - 32px); box-sizing: border-box; padding: 8px 10px 8px 14px; border-radius: 12px; background: rgba(20, 22, 26, 0.86); color: #f2f3f5; font-size: calc(13px * var(--ta-font-scale)); line-height: calc(18px * var(--ta-font-scale)); backdrop-filter: blur(8px); }
|
|
1640
|
+
.trd-status { top: 50%; bottom: auto; transform: translate(-50%, -50%); }
|
|
1641
|
+
.trd-status .ta-button, .trd-watching .ta-button { color: #f2f3f5; border-color: rgba(255, 255, 255, 0.24); }
|
|
1642
|
+
.trd-bar { display: flex; align-items: center; gap: 2px; height: 48px; padding: 0 6px; box-sizing: content-box; padding-bottom: env(safe-area-inset-bottom, 0px); flex: none; background: #16181c; border-top: 1px solid rgba(255, 255, 255, 0.08); color: #e8eaed; }
|
|
1643
|
+
.trd-bare .trd-bar { display: none; }
|
|
1644
|
+
.trd-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; color: #e8eaed; font-size: calc(13.5px * var(--ta-font-scale)); font-weight: 500; }
|
|
1645
|
+
.trd-tool { display: inline-flex; align-items: center; justify-content: center; flex: none; min-width: 36px; height: 36px; padding: 0 8px; border: 0; border-radius: 8px; background: transparent; color: #e8eaed; font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; }
|
|
1646
|
+
.trd-tool:hover:not(:disabled) { background: rgba(255, 255, 255, 0.08); }
|
|
1647
|
+
.trd-tool:disabled { opacity: 0.35; cursor: default; }
|
|
1648
|
+
.trd-tool.trd-on { background: rgba(255, 255, 255, 0.14); color: #ffffff; }
|
|
1649
|
+
.trd-quality { color: rgba(232, 234, 237, 0.7); }
|
|
1650
|
+
.trd-show-bar { position: absolute; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); width: 36px; height: 28px; border: 0; border-radius: 14px; background: rgba(20, 22, 26, 0.7); color: #f2f3f5; display: inline-flex; align-items: center; justify-content: center; }
|
|
1651
|
+
.trd-keys { position: relative; display: flex; align-items: center; gap: 6px; padding: 6px 8px; overflow-x: auto; flex: none; background: #16181c; border-top: 1px solid rgba(255, 255, 255, 0.08); scrollbar-width: none; }
|
|
1652
|
+
.trd-keys-field { position: absolute; left: 0; top: 0; width: 1px; height: 1px; opacity: 0; border: 0; padding: 0; resize: none; font-size: max(16px, calc(13px * var(--ta-font-scale))); }
|
|
1653
|
+
.trd-key { flex: none; min-width: 40px; height: 34px; padding: 0 10px; border: 0; border-radius: 8px; background: rgba(255, 255, 255, 0.1); color: #e8eaed; font: inherit; font-size: calc(13px * var(--ta-font-scale)); }
|
|
1654
|
+
.trd-key.trd-on { background: rgba(255, 255, 255, 0.22); color: #ffffff; }
|
|
1655
|
+
.trd-key.trd-locked { background: #e8eaed; color: #16181c; }
|
|
1656
|
+
.trd-signin-layer { position: absolute; inset: 0; z-index: 3; display: flex; overflow-y: auto; overscroll-behavior: contain; padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px)); box-sizing: border-box; background: #0b0d10; color-scheme: dark; }
|
|
1657
|
+
.trd-signin-over { position: fixed; z-index: 60; }
|
|
1658
|
+
.trd-signin { display: flex; flex-direction: column; width: 100%; max-width: 340px; margin: auto; color: #f2f3f5; text-align: center; }
|
|
1659
|
+
.trd-signin-icon { display: inline-flex; align-items: center; justify-content: center; align-self: center; width: 52px; height: 52px; margin-bottom: 14px; border-radius: 14px; background: rgba(255, 255, 255, 0.08); color: #e8eaed; }
|
|
1660
|
+
.trd-signin-title { margin: 0; overflow-wrap: anywhere; font-size: calc(18px * var(--ta-font-scale)); line-height: calc(26px * var(--ta-font-scale)); font-weight: 600; }
|
|
1661
|
+
.trd-signin-hint { margin: 6px 0 20px; color: rgba(232, 234, 237, 0.62); font-size: calc(13.5px * var(--ta-font-scale)); line-height: calc(20px * var(--ta-font-scale)); }
|
|
1662
|
+
.trd-signin-hint.trd-signin-refused { color: #ff8a80; }
|
|
1663
|
+
.trd-signin-fields { display: flex; flex-direction: column; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 12px; background: rgba(255, 255, 255, 0.06); transition: border-color 0.15s; }
|
|
1664
|
+
.trd-signin-fields:focus-within { border-color: rgba(255, 255, 255, 0.28); }
|
|
1665
|
+
.trd-signin-fields > * + * { border-top: 1px solid rgba(255, 255, 255, 0.1); }
|
|
1666
|
+
.trd-signin-input { width: 100%; height: 48px; padding: 0 14px; border: 0; outline: none; box-sizing: border-box; background: transparent; color: #f2f3f5; font: inherit; font-size: max(16px, calc(15px * var(--ta-font-scale))); text-align: left; }
|
|
1667
|
+
.trd-signin-input::placeholder { color: rgba(232, 234, 237, 0.4); }
|
|
1668
|
+
.trd-signin-secret { position: relative; display: flex; align-items: center; }
|
|
1669
|
+
.trd-signin-secret .trd-signin-input { padding-right: 48px; }
|
|
1670
|
+
.trd-signin-eye { position: absolute; right: 4px; display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px; border: 0; border-radius: 8px; background: transparent; color: rgba(232, 234, 237, 0.45); cursor: pointer; }
|
|
1671
|
+
.trd-signin-eye.trd-on { color: #f2f3f5; }
|
|
1672
|
+
.trd-signin-remember { display: flex; align-items: center; gap: 8px; margin: 14px 2px 0; color: rgba(232, 234, 237, 0.75); font-size: calc(13.5px * var(--ta-font-scale)); line-height: calc(20px * var(--ta-font-scale)); text-align: left; cursor: pointer; }
|
|
1673
|
+
.trd-signin-remember input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: #34d399; }
|
|
1674
|
+
.trd-signin-go { height: 46px; margin-top: 20px; border: 0; border-radius: 12px; background: #f2f3f5; color: #16181c; font: inherit; font-size: calc(15px * var(--ta-font-scale)); font-weight: 600; cursor: pointer; }
|
|
1675
|
+
.trd-signin-go:disabled { background: rgba(255, 255, 255, 0.1); color: rgba(232, 234, 237, 0.38); cursor: default; }
|
|
1676
|
+
.trd-signin-cancel { height: 40px; margin-top: 6px; border: 0; background: transparent; color: rgba(232, 234, 237, 0.7); font: inherit; font-size: calc(14px * var(--ta-font-scale)); cursor: pointer; }
|
|
1677
|
+
[data-layout='compact'] .trd-page { padding: 18px 14px 40px; }
|
|
1678
|
+
`;
|
|
1679
|
+
function injectStyle() {
|
|
1680
|
+
const style = document.createElement("style");
|
|
1681
|
+
style.dataset.taScreenShare = "";
|
|
1682
|
+
style.textContent = STYLE;
|
|
1683
|
+
document.head.appendChild(style);
|
|
1684
|
+
return () => style.remove();
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
// web-src/index.tsx
|
|
1688
|
+
function activate(pi) {
|
|
1689
|
+
bind(pi.React);
|
|
1690
|
+
const removeStyle = injectStyle();
|
|
1691
|
+
pi.registerView("desktops", {
|
|
1692
|
+
title: () => DesktopWordsUtil.of(pi.ui.language).title,
|
|
1693
|
+
icon: pi.ui.icons.MonitorSmartphone,
|
|
1694
|
+
location: "page",
|
|
1695
|
+
render: () => /* @__PURE__ */ React.createElement(DesktopsView, {
|
|
1696
|
+
pi
|
|
1697
|
+
})
|
|
1698
|
+
});
|
|
1699
|
+
return removeStyle;
|
|
1700
|
+
}
|
|
1701
|
+
export {
|
|
1702
|
+
activate as default
|
|
1703
|
+
};
|