phirepass-widgets 0.0.80 → 0.0.82

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.
Files changed (40) hide show
  1. package/dist/cjs/{index-D-l8xaCI.js → index-Dtiw2goq.js} +28 -0
  2. package/dist/cjs/loader.cjs.js +2 -2
  3. package/dist/cjs/phirepass-rdp.cjs.entry.js +297 -9
  4. package/dist/cjs/phirepass-sftp-client.cjs.entry.js +18 -18
  5. package/dist/cjs/phirepass-terminal.cjs.entry.js +3 -3
  6. package/dist/cjs/phirepass-widgets.cjs.js +2 -2
  7. package/dist/cjs/{protocol-DfRfif9I.js → protocol-DS0qXomZ.js} +3 -3
  8. package/dist/collection/components/phirepass-rdp/phirepass-rdp.css +16 -5
  9. package/dist/collection/components/phirepass-rdp/phirepass-rdp.js +216 -6
  10. package/dist/collection/components/phirepass-rdp/phirepass-rdp.keyboard.js +88 -0
  11. package/dist/collection/components/phirepass-rdp/phirepass-rdp.viewport.js +85 -0
  12. package/dist/collection/components/phirepass-sftp-client/phirepass-sftp-client.js +16 -16
  13. package/dist/collection/components/phirepass-terminal/phirepass-terminal.js +1 -1
  14. package/dist/collection/phirepass-channel_bg.wasm +0 -0
  15. package/dist/components/index.js +1 -1
  16. package/dist/{phirepass-widgets/p-y9WE2vrP.js → components/p-CWIhN33k.js} +1 -1
  17. package/dist/components/phirepass-rdp.js +1 -1
  18. package/dist/components/phirepass-sftp-client.js +1 -1
  19. package/dist/components/phirepass-terminal.js +2 -2
  20. package/dist/esm/{index-DovZQ7sb.js → index-Buu-IaNK.js} +28 -0
  21. package/dist/esm/loader.js +3 -3
  22. package/dist/esm/phirepass-rdp.entry.js +297 -9
  23. package/dist/esm/phirepass-sftp-client.entry.js +18 -18
  24. package/dist/esm/phirepass-terminal.entry.js +3 -3
  25. package/dist/esm/phirepass-widgets.js +3 -3
  26. package/dist/esm/{protocol-y9WE2vrP.js → protocol-CWIhN33k.js} +2 -2
  27. package/dist/phirepass-widgets/p-306c47c5.entry.js +1 -0
  28. package/dist/phirepass-widgets/{p-53672ba5.entry.js → p-8dca9e3a.entry.js} +1 -1
  29. package/dist/phirepass-widgets/p-Buu-IaNK.js +2 -0
  30. package/dist/{components/p-y9WE2vrP.js → phirepass-widgets/p-CWIhN33k.js} +1 -1
  31. package/dist/phirepass-widgets/{p-a9c02bf1.entry.js → p-b74a5300.entry.js} +2 -2
  32. package/dist/phirepass-widgets/phirepass-channel_bg.wasm +0 -0
  33. package/dist/phirepass-widgets/phirepass-widgets.esm.js +1 -1
  34. package/dist/types/components/phirepass-rdp/phirepass-rdp.d.ts +65 -0
  35. package/dist/types/components/phirepass-rdp/phirepass-rdp.keyboard.d.ts +42 -0
  36. package/dist/types/components/phirepass-rdp/phirepass-rdp.viewport.d.ts +33 -0
  37. package/dist/types/components.d.ts +34 -0
  38. package/package.json +2 -2
  39. package/dist/phirepass-widgets/p-3cc5c346.entry.js +0 -1
  40. package/dist/phirepass-widgets/p-DovZQ7sb.js +0 -2
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-D-l8xaCI.js');
3
+ var index = require('./index-Dtiw2goq.js');
4
4
  var appGlobals = require('./app-globals-V2Kpy_OQ.js');
5
5
 
6
6
  var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
@@ -19,7 +19,7 @@ var patchBrowser = () => {
19
19
 
20
20
  patchBrowser().then(async (options) => {
21
21
  await appGlobals.globalScripts();
22
- return index.bootstrapLazy([["phirepass-rdp.cjs",[[513,"phirepass-rdp",{"serverHost":[1,"server-host"],"serverPort":[2,"server-port"],"allowInsecure":[4,"allow-insecure"],"heartbeatInterval":[2,"heartbeat-interval"],"nodeId":[1,"node-id"],"serviceId":[1,"service-id"],"token":[1],"username":[1],"password":[1],"destination":[1],"scale":[1],"serverId":[1,"server-id"],"credentialsPrompt":[32],"statusMessage":[32]},null,{"nodeId":[{"onNodeIdChange":0}],"serverId":[{"onServerIdChange":0}]}]]],["phirepass-sftp-client.cjs",[[513,"phirepass-sftp-client",{"name":[1],"description":[1],"hideHeader":[4,"hide-header"],"serverHost":[1,"server-host"],"serverPort":[2,"server-port"],"allowInsecure":[4,"allow-insecure"],"heartbeatInterval":[2,"heartbeat-interval"],"nodeId":[1,"node-id"],"serviceId":[1,"service-id"],"token":[1],"serverId":[1,"server-id"],"max":[32],"show_login_screen":[32],"show_login_screen_username":[32],"show_error":[32],"error_message":[32],"show_login_screen_password":[32],"show_navigation":[32],"breadcrumbs":[32],"current_dir":[32],"listing":[32],"show_content":[32],"show_loader":[32],"version":[32],"status":[32],"selected_item":[32],"show_upload_modal":[32],"upload_progress":[32],"upload_file_name":[32],"upload_speed":[32],"upload_finished":[32],"show_download_modal":[32],"download_progress":[32],"download_file_name":[32],"download_speed":[32],"download_finished":[32],"show_delete_modal":[32],"delete_file_name":[32],"delete_loading":[32],"maximize":[64],"minimize":[64]},null,{"nodeId":[{"onNodeIdChange":0}],"serverId":[{"onServerIdChange":0}]}]]],["phirepass-terminal.cjs",[[513,"phirepass-terminal",{"terminalOptions":[16],"serverHost":[1,"server-host"],"serverPort":[2,"server-port"],"allowInsecure":[4,"allow-insecure"],"heartbeatInterval":[2,"heartbeat-interval"],"nodeId":[1,"node-id"],"serviceId":[1,"service-id"],"token":[1],"serverId":[1,"server-id"]},null,{"nodeId":[{"onNodeIdChange":0}],"serverId":[{"onServerIdChange":0}]}]]]], options);
22
+ return index.bootstrapLazy([["phirepass-rdp.cjs",[[769,"phirepass-rdp",{"serverHost":[1,"server-host"],"serverPort":[2,"server-port"],"allowInsecure":[4,"allow-insecure"],"heartbeatInterval":[2,"heartbeat-interval"],"nodeId":[1,"node-id"],"serviceId":[1,"service-id"],"token":[1],"username":[1],"password":[1],"destination":[1],"scale":[1],"dynamicResize":[4,"dynamic-resize"],"captureKeyboard":[4,"capture-keyboard"],"serverId":[1,"server-id"],"credentialsPrompt":[32],"statusMessage":[32],"toggleFullscreen":[64],"keyboardLockSupported":[64],"focusDesktop":[64]},null,{"nodeId":[{"onNodeIdChange":0}],"serverId":[{"onServerIdChange":0}]}]]],["phirepass-sftp-client.cjs",[[513,"phirepass-sftp-client",{"name":[1],"description":[1],"hideHeader":[4,"hide-header"],"serverHost":[1,"server-host"],"serverPort":[2,"server-port"],"allowInsecure":[4,"allow-insecure"],"heartbeatInterval":[2,"heartbeat-interval"],"nodeId":[1,"node-id"],"serviceId":[1,"service-id"],"token":[1],"serverId":[1,"server-id"],"max":[32],"show_login_screen":[32],"show_login_screen_username":[32],"show_error":[32],"error_message":[32],"show_login_screen_password":[32],"show_navigation":[32],"breadcrumbs":[32],"current_dir":[32],"listing":[32],"show_content":[32],"show_loader":[32],"version":[32],"status":[32],"selected_item":[32],"show_upload_modal":[32],"upload_progress":[32],"upload_file_name":[32],"upload_speed":[32],"upload_finished":[32],"show_download_modal":[32],"download_progress":[32],"download_file_name":[32],"download_speed":[32],"download_finished":[32],"show_delete_modal":[32],"delete_file_name":[32],"delete_loading":[32],"maximize":[64],"minimize":[64]},null,{"nodeId":[{"onNodeIdChange":0}],"serverId":[{"onServerIdChange":0}]}]]],["phirepass-terminal.cjs",[[513,"phirepass-terminal",{"terminalOptions":[16],"serverHost":[1,"server-host"],"serverPort":[2,"server-port"],"allowInsecure":[4,"allow-insecure"],"heartbeatInterval":[2,"heartbeat-interval"],"nodeId":[1,"node-id"],"serviceId":[1,"service-id"],"token":[1],"serverId":[1,"server-id"]},null,{"nodeId":[{"onNodeIdChange":0}],"serverId":[{"onServerIdChange":0}]}]]]], options);
23
23
  });
24
24
 
25
25
  exports.setNonce = index.setNonce;
@@ -463,7 +463,7 @@ function __wbg_get_imports() {
463
463
  const ret = Reflect.get(getObject(arg0), getObject(arg1));
464
464
  return addHeapObject(ret);
465
465
  }, arguments); },
466
- __wbg_info_9b9ea1f18c57361f: function(arg0, arg1) {
466
+ __wbg_info_e70a4ed57b90fedf: function(arg0, arg1) {
467
467
  console.info(getStringFromWasm0(arg0, arg1));
468
468
  },
469
469
  __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(arg0) {
@@ -535,7 +535,7 @@ function __wbg_get_imports() {
535
535
  __wbg_set_onopen_4f65470ae522a61a: function(arg0, arg1) {
536
536
  getObject(arg0).onopen = getObject(arg1);
537
537
  },
538
- __wbg_warn_79b294b9866d9034: function(arg0, arg1) {
538
+ __wbg_warn_5c89b14defca8e2c: function(arg0, arg1) {
539
539
  console.warn(getStringFromWasm0(arg0, arg1));
540
540
  },
541
541
  __wbindgen_cast_0000000000000001: function(arg0, arg1) {
@@ -905,7 +905,7 @@ async function __wbg_init(module_or_path) {
905
905
  }
906
906
 
907
907
  if (module_or_path === undefined) {
908
- module_or_path = new URL('phirepass-channel_bg.wasm', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('protocol-DfRfif9I.js', document.baseURI).href)));
908
+ module_or_path = new URL('phirepass-channel_bg.wasm', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('protocol-DS0qXomZ.js', document.baseURI).href)));
909
909
  }
910
910
  const imports = __wbg_get_imports();
911
911
 
@@ -12,18 +12,29 @@
12
12
  .screen {
13
13
  width: 100%;
14
14
  height: 100%;
15
+ display: flex;
15
16
  }
16
17
 
17
- /* IronRDP renders into its own canvas; never let it force the page to scroll. */
18
- .screen iron-remote-desktop {
18
+ /*
19
+ * The client lives in the light DOM so that keyboard focus can reach it (see
20
+ * `mount_client`), which is why it is reached through `::slotted` rather than a
21
+ * descendant selector. IronRDP renders into its own canvas; never let it force
22
+ * the page to scroll.
23
+ */
24
+ ::slotted(iron-remote-desktop) {
19
25
  display: block;
26
+ flex: 1 1 auto;
27
+ min-width: 0;
28
+ min-height: 0;
20
29
  width: 100%;
21
30
  height: 100%;
22
31
  }
23
32
 
24
- .screen canvas {
25
- max-width: 100%;
26
- display: block;
33
+ /* Fullscreen is what the keyboard lock needs, so it has to look deliberate. */
34
+ :host(:fullscreen) {
35
+ width: 100vw;
36
+ height: 100vh;
37
+ background: #000;
27
38
  }
28
39
 
29
40
  .prompt {
@@ -1,6 +1,8 @@
1
1
  import { Host, h } from "@stencil/core";
2
2
  import init, { Channel as PhirepassChannel } from "phirepass-channel";
3
3
  import { ConnectionState, ProtocolMessageType, } from "../../common/protocol";
4
+ import { measure_desktop_size, ViewportSync } from "./phirepass-rdp.viewport";
5
+ import { focus_client, keyboard_lock_supported, lock_keyboard, shown_fullscreen, toggle_fullscreen, unlock_keyboard, } from "./phirepass-rdp.keyboard";
4
6
  /**
5
7
  * Remote desktop over RDP.
6
8
  *
@@ -16,10 +18,12 @@ export class PhirepassRdp {
16
18
  containerEl;
17
19
  ironEl;
18
20
  userInteraction;
21
+ viewport;
19
22
  domReady = false;
20
23
  runtimeReady = false;
21
24
  connected = false;
22
25
  session_id;
26
+ onFullscreenChange = () => this.sync_keyboard_lock();
23
27
  /** Credentials in force for this session, from props or from the prompt. */
24
28
  credentials;
25
29
  credentialsPrompt = false;
@@ -54,6 +58,26 @@ export class PhirepassRdp {
54
58
  destination;
55
59
  /** `fit` scales the desktop to the widget, `real` keeps 1:1 pixels. */
56
60
  scale = 'fit';
61
+ /**
62
+ * Ask the remote host to change its resolution to match the widget whenever
63
+ * the widget is resized, so the desktop is rendered at native size rather
64
+ * than scaled.
65
+ *
66
+ * The host has the last word: this needs the display-control channel, and a
67
+ * host that does not offer it simply keeps the resolution it started with —
68
+ * which `scale` then fits into the widget, as before.
69
+ */
70
+ dynamicResize = true;
71
+ /**
72
+ * While the widget is fullscreen, take the keys the browser normally keeps
73
+ * for itself (Ctrl+W, Ctrl+T, Alt+Tab, F11) and send them to the remote
74
+ * host instead. Escape is taken too, so leaving fullscreen becomes a
75
+ * press-and-hold.
76
+ *
77
+ * Ordinary keys do not depend on this — they are forwarded whenever the
78
+ * desktop has focus.
79
+ */
80
+ captureKeyboard = true;
57
81
  onNodeIdChange(newValue, _oldValue) {
58
82
  this.reset_session_state();
59
83
  if (this.channel && this.channel.is_connected()) {
@@ -80,6 +104,7 @@ export class PhirepassRdp {
80
104
  return `${protocol}://${this.serverHost}:${this.serverPort}`;
81
105
  }
82
106
  async connectedCallback() {
107
+ document.addEventListener('fullscreenchange', this.onFullscreenChange);
83
108
  await init();
84
109
  this.open_comms();
85
110
  this.runtimeReady = true;
@@ -94,11 +119,31 @@ export class PhirepassRdp {
94
119
  this.try_connect();
95
120
  }
96
121
  async disconnectedCallback() {
122
+ document.removeEventListener('fullscreenchange', this.onFullscreenChange);
97
123
  this.connected = false;
98
124
  this.domReady = false;
99
125
  this.runtimeReady = false;
100
126
  this.close_comms();
101
127
  }
128
+ /**
129
+ * Puts the widget in and out of fullscreen, returning the state it settled
130
+ * in. Fullscreen is also what makes `captureKeyboard` possible, so a host
131
+ * app wanting the browser's own shortcuts to reach the remote desktop has
132
+ * to come through here.
133
+ */
134
+ async toggleFullscreen() {
135
+ const fullscreen = await toggle_fullscreen(this.el);
136
+ this.focus_desktop();
137
+ return fullscreen;
138
+ }
139
+ /** Whether the browser can hand over its reserved keys at all. */
140
+ async keyboardLockSupported() {
141
+ return keyboard_lock_supported();
142
+ }
143
+ /** Directs keystrokes at the remote desktop without waiting for a click. */
144
+ async focusDesktop() {
145
+ this.focus_desktop();
146
+ }
102
147
  try_connect() {
103
148
  if (this.connected || !this.domReady || !this.runtimeReady) {
104
149
  return;
@@ -225,23 +270,46 @@ export class PhirepassRdp {
225
270
  void this.start_session(detail.irgUserInteraction, web.ticket, backend.enableCredssp(true));
226
271
  });
227
272
  this.ironEl = element;
228
- this.containerEl.appendChild(element);
273
+ this.mount_client(element);
274
+ }
275
+ /**
276
+ * Mounts the client in the widget's **light** DOM, slotted into `.screen`,
277
+ * rather than as a child of the shadow root.
278
+ *
279
+ * This is what makes the keyboard work. IronRDP forwards a key event only
280
+ * while `document.activeElement` is its own element, and `activeElement`
281
+ * retargets focus to the outermost shadow host: with the client inside this
282
+ * widget's shadow root the answer is always `<phirepass-rdp>`, the check
283
+ * never passes, and not one keystroke reaches the remote host — while the
284
+ * mouse, which is bound to the canvas directly, works fine. Slotting the
285
+ * client leaves it in the document tree, so `activeElement` resolves to the
286
+ * client itself.
287
+ */
288
+ mount_client(element) {
289
+ this.el.appendChild(element);
229
290
  }
230
291
  async start_session(userInteraction, ticket, credssp) {
231
292
  this.userInteraction = userInteraction;
232
- const config = userInteraction
293
+ const builder = userInteraction
233
294
  .configBuilder()
234
295
  .withUsername(this.credentials?.username ?? '')
235
296
  .withPassword(this.credentials?.password ?? '')
236
297
  .withDestination(this.destination ?? this.nodeId)
237
298
  .withProxyAddress(`${this.create_web_socket_endpoint()}/api/web/rdp/${this.nodeId}`)
238
299
  .withAuthToken(ticket)
239
- .withExtension(credssp)
240
- .build();
300
+ .withExtension(credssp);
301
+ // Asking for the widget's size up front costs nothing and saves the
302
+ // remote host a resolution change immediately after logon.
303
+ if (this.dynamicResize) {
304
+ builder.withDesktopSize(measure_desktop_size(this.el));
305
+ }
241
306
  try {
242
- const session = await userInteraction.connect(config);
307
+ const session = await userInteraction.connect(builder.build());
243
308
  userInteraction.setVisibility(true);
244
309
  this.statusMessage = undefined;
310
+ this.focus_desktop();
311
+ this.start_viewport_sync();
312
+ void this.sync_keyboard_lock();
245
313
  const termination = await session.run();
246
314
  this.statusMessage = termination.reason();
247
315
  }
@@ -251,6 +319,51 @@ export class PhirepassRdp {
251
319
  this.connectionStateChanged.emit([ConnectionState.Error, err]);
252
320
  }
253
321
  }
322
+ /**
323
+ * Keeps the remote resolution equal to the widget's size.
324
+ *
325
+ * `setVisibility(true)` is what gives the widget its layout, so the first
326
+ * measurement has to happen after it — measuring earlier reads a hidden,
327
+ * zero-sized box.
328
+ */
329
+ start_viewport_sync() {
330
+ if (!this.dynamicResize) {
331
+ return;
332
+ }
333
+ this.viewport = new ViewportSync((size) => this.resize_desktop(size));
334
+ this.viewport.observe(this.el);
335
+ }
336
+ stop_viewport_sync() {
337
+ this.viewport?.disconnect();
338
+ this.viewport = undefined;
339
+ }
340
+ resize_desktop(size) {
341
+ try {
342
+ this.userInteraction?.resize(size.width, size.height);
343
+ }
344
+ catch (err) {
345
+ // A host without the display-control channel refuses the request;
346
+ // the session carries on at the resolution it already has.
347
+ console.warn('The remote host would not resize its desktop:', err);
348
+ }
349
+ }
350
+ focus_desktop() {
351
+ focus_client(this.ironEl);
352
+ }
353
+ /**
354
+ * Holds the keyboard lock exactly while the widget is fullscreen. Both
355
+ * edges matter: the browser drops the lock on its own when fullscreen ends,
356
+ * but not when the session does, and a lock left behind would keep
357
+ * swallowing shortcuts for the rest of the page.
358
+ */
359
+ async sync_keyboard_lock() {
360
+ if (!this.captureKeyboard || !shown_fullscreen(this.el)) {
361
+ unlock_keyboard();
362
+ return;
363
+ }
364
+ await lock_keyboard(this.el);
365
+ this.focus_desktop();
366
+ }
254
367
  /** IronRDP rejects with its own error shape rather than an `Error`. */
255
368
  describe_error(err) {
256
369
  const iron = err;
@@ -270,6 +383,8 @@ export class PhirepassRdp {
270
383
  this.connectionStateChanged.emit([ConnectionState.Error, error]);
271
384
  }
272
385
  teardown_client() {
386
+ this.stop_viewport_sync();
387
+ unlock_keyboard();
273
388
  if (this.userInteraction) {
274
389
  try {
275
390
  this.userInteraction.shutdown();
@@ -294,7 +409,7 @@ export class PhirepassRdp {
294
409
  this.request_tunnel();
295
410
  }
296
411
  render() {
297
- return (h(Host, { key: '97b198af30e4e4b7ae8cbd0d497dc4f4812615f8' }, h("div", { key: 'f7d01492909a0f3cb6c639345eb70a8e1fbf1b90', class: "screen", ref: (el) => (this.containerEl = el) }), this.credentialsPrompt && (h("form", { key: '1dcfeaa956999dc882943e0d0b49ead8d12840bc', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, h("label", { key: 'a62e96bfb6b947167f731020c7ab00a1d9a82652', htmlFor: "rdp-username" }, "Windows username"), h("input", { key: '3135d24b62b2b612a11d3cbfd2c19f3cf381e74b', id: "rdp-username", type: "text", autocomplete: "username", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), h("label", { key: 'd8b901e0fe81de30e6426f80179d5e8da542effc', htmlFor: "rdp-password" }, "Password"), h("input", { key: '0bfad07c7f5355a8693856b1e6b51df59944a339', id: "rdp-password", type: "password", autocomplete: "current-password", onInput: (event) => (this.passwordBuffer = event.target.value) }), h("button", { key: 'e1cbab525870c34fe85299a8ce883d7069cb4bb8', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (h("div", { key: '4144cff9e5d6fb637655203bf67a13adaa7feede', class: "status" }, this.statusMessage))));
412
+ return (h(Host, { key: '140e8f813403dad27cbbe3b0d3e3099e90c9e08d' }, h("div", { key: '0f695b83c808a678b9bff3434ac1ff65a6765e1e', class: "screen", ref: (el) => (this.containerEl = el) }, h("slot", { key: 'b382a47294606909074c8b64983419645cda438b' })), this.credentialsPrompt && (h("form", { key: '18606a269f254c5bffc81c6c45a4e85473fff557', class: "prompt", onSubmit: (event) => this.submit_credentials(event) }, h("label", { key: 'f4c2bf9aaa483e323b38d12774728e3a687962a4', htmlFor: "rdp-username" }, "Windows username"), h("input", { key: 'ba766990c9fc089b1aa9d894ac5d7032f0c87edf', id: "rdp-username", type: "text", autocomplete: "username", autofocus: true, onInput: (event) => (this.usernameBuffer = event.target.value) }), h("label", { key: '885ee563e3537712d3ad85e47485f44f2de576c5', htmlFor: "rdp-password" }, "Password"), h("input", { key: '19cfa162b515e6b230b19a3f2f8fd267ff5388ec', id: "rdp-password", type: "password", autocomplete: "current-password", onInput: (event) => (this.passwordBuffer = event.target.value) }), h("button", { key: '04b428b4947f1d0f957399961c5196d5bbc6b5a7', type: "submit" }, "Connect"))), this.statusMessage && !this.credentialsPrompt && (h("div", { key: 'eb66cd3974a3aa8a563bd54599912bc735007214', class: "status" }, this.statusMessage))));
298
413
  }
299
414
  static get is() { return "phirepass-rdp"; }
300
415
  static get encapsulation() { return "shadow"; }
@@ -524,6 +639,46 @@ export class PhirepassRdp {
524
639
  "attribute": "scale",
525
640
  "defaultValue": "'fit'"
526
641
  },
642
+ "dynamicResize": {
643
+ "type": "boolean",
644
+ "mutable": false,
645
+ "complexType": {
646
+ "original": "boolean",
647
+ "resolved": "boolean",
648
+ "references": {}
649
+ },
650
+ "required": false,
651
+ "optional": false,
652
+ "docs": {
653
+ "tags": [],
654
+ "text": "Ask the remote host to change its resolution to match the widget whenever\nthe widget is resized, so the desktop is rendered at native size rather\nthan scaled.\n\nThe host has the last word: this needs the display-control channel, and a\nhost that does not offer it simply keeps the resolution it started with \u2014\nwhich `scale` then fits into the widget, as before."
655
+ },
656
+ "getter": false,
657
+ "setter": false,
658
+ "reflect": false,
659
+ "attribute": "dynamic-resize",
660
+ "defaultValue": "true"
661
+ },
662
+ "captureKeyboard": {
663
+ "type": "boolean",
664
+ "mutable": false,
665
+ "complexType": {
666
+ "original": "boolean",
667
+ "resolved": "boolean",
668
+ "references": {}
669
+ },
670
+ "required": false,
671
+ "optional": false,
672
+ "docs": {
673
+ "tags": [],
674
+ "text": "While the widget is fullscreen, take the keys the browser normally keeps\nfor itself (Ctrl+W, Ctrl+T, Alt+Tab, F11) and send them to the remote\nhost instead. Escape is taken too, so leaving fullscreen becomes a\npress-and-hold.\n\nOrdinary keys do not depend on this \u2014 they are forwarded whenever the\ndesktop has focus."
675
+ },
676
+ "getter": false,
677
+ "setter": false,
678
+ "reflect": false,
679
+ "attribute": "capture-keyboard",
680
+ "defaultValue": "true"
681
+ },
527
682
  "serverId": {
528
683
  "type": "string",
529
684
  "mutable": false,
@@ -576,6 +731,61 @@ export class PhirepassRdp {
576
731
  }
577
732
  }];
578
733
  }
734
+ static get methods() {
735
+ return {
736
+ "toggleFullscreen": {
737
+ "complexType": {
738
+ "signature": "() => Promise<boolean>",
739
+ "parameters": [],
740
+ "references": {
741
+ "Promise": {
742
+ "location": "global",
743
+ "id": "global::Promise"
744
+ }
745
+ },
746
+ "return": "Promise<boolean>"
747
+ },
748
+ "docs": {
749
+ "text": "Puts the widget in and out of fullscreen, returning the state it settled\nin. Fullscreen is also what makes `captureKeyboard` possible, so a host\napp wanting the browser's own shortcuts to reach the remote desktop has\nto come through here.",
750
+ "tags": []
751
+ }
752
+ },
753
+ "keyboardLockSupported": {
754
+ "complexType": {
755
+ "signature": "() => Promise<boolean>",
756
+ "parameters": [],
757
+ "references": {
758
+ "Promise": {
759
+ "location": "global",
760
+ "id": "global::Promise"
761
+ }
762
+ },
763
+ "return": "Promise<boolean>"
764
+ },
765
+ "docs": {
766
+ "text": "Whether the browser can hand over its reserved keys at all.",
767
+ "tags": []
768
+ }
769
+ },
770
+ "focusDesktop": {
771
+ "complexType": {
772
+ "signature": "() => Promise<void>",
773
+ "parameters": [],
774
+ "references": {
775
+ "Promise": {
776
+ "location": "global",
777
+ "id": "global::Promise"
778
+ }
779
+ },
780
+ "return": "Promise<void>"
781
+ },
782
+ "docs": {
783
+ "text": "Directs keystrokes at the remote desktop without waiting for a click.",
784
+ "tags": []
785
+ }
786
+ }
787
+ };
788
+ }
579
789
  static get elementRef() { return "el"; }
580
790
  static get watchers() {
581
791
  return [{
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Keyboard capture for the RDP widget, in two layers.
3
+ *
4
+ * **Ordinary keys** are IronRDP's own doing: it listens on `window` and
5
+ * forwards a key event only while its element is `document.activeElement`. That
6
+ * check is why the client element is mounted in the widget's *light* DOM — see
7
+ * the note on `mount_client` in the component — and why it has to be focused,
8
+ * which `focus_client` below is for.
9
+ *
10
+ * **Keys the browser reserves** (Ctrl+W, Ctrl+T, Ctrl+N, Alt+Tab, F11, Escape)
11
+ * never reach the page at all, so no amount of focus will forward them. The
12
+ * only way to have them is the Keyboard Lock API, and browsers grant that only
13
+ * to a document that is already fullscreen. So "capture my keyboard" is really
14
+ * "go fullscreen, then lock" — hence `toggle_fullscreen`.
15
+ */
16
+ function keyboard_api() {
17
+ return navigator.keyboard;
18
+ }
19
+ /** Chromium-only at the time of writing; Firefox and Safari have no equivalent. */
20
+ export function keyboard_lock_supported() {
21
+ return typeof keyboard_api()?.lock === 'function';
22
+ }
23
+ /** Strictly this element — what deciding whether to enter or exit turns on. */
24
+ export function is_fullscreen(element) {
25
+ return document.fullscreenElement === element;
26
+ }
27
+ /**
28
+ * This element *or* something around it. The lock is granted per document, so
29
+ * a host app that made a whole panel fullscreen should get it too.
30
+ */
31
+ export function shown_fullscreen(element) {
32
+ return document.fullscreenElement?.contains(element) ?? false;
33
+ }
34
+ /**
35
+ * Takes every key the browser is willing to give up. Called with no arguments
36
+ * `lock()` claims the lot, including Escape — which is also the key that leaves
37
+ * fullscreen, so the browser substitutes a press-and-hold gesture for it.
38
+ */
39
+ export async function lock_keyboard(element) {
40
+ // There is no capability query, and the request rejects outside fullscreen,
41
+ // so the caller's state is the only guard available.
42
+ if (!keyboard_lock_supported() || !shown_fullscreen(element)) {
43
+ return;
44
+ }
45
+ try {
46
+ await keyboard_api().lock();
47
+ }
48
+ catch (err) {
49
+ console.warn('Failed to lock the keyboard for the RDP session:', err);
50
+ }
51
+ }
52
+ export function unlock_keyboard() {
53
+ if (!keyboard_lock_supported()) {
54
+ return;
55
+ }
56
+ try {
57
+ keyboard_api().unlock();
58
+ }
59
+ catch (err) {
60
+ console.warn('Failed to release the keyboard lock:', err);
61
+ }
62
+ }
63
+ /** Returns whether `element` is fullscreen once the request has settled. */
64
+ export async function toggle_fullscreen(element) {
65
+ try {
66
+ if (is_fullscreen(element)) {
67
+ await document.exitFullscreen();
68
+ return false;
69
+ }
70
+ await element.requestFullscreen({ navigationUI: 'hide' });
71
+ return true;
72
+ }
73
+ catch (err) {
74
+ console.warn('Failed to change the fullscreen state of the RDP session:', err);
75
+ return is_fullscreen(element);
76
+ }
77
+ }
78
+ /**
79
+ * Gives the client element focus so IronRDP starts forwarding keys.
80
+ *
81
+ * The element's shadow root is opened with `delegatesFocus`, so focusing the
82
+ * host lands on the canvas inside it; the canvas is what IronRDP watches. Doing
83
+ * this on connect saves the user the mouse-over that would otherwise be needed
84
+ * before the first keystroke lands.
85
+ */
86
+ export function focus_client(element) {
87
+ element?.focus({ preventScroll: true });
88
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * RDP's display-control PDU describes a monitor in whole, even pixels within
3
+ * these bounds. A layout outside them is refused by the host rather than
4
+ * negotiated down, and the client reports nothing when that happens — so the
5
+ * clamping has to be done here, before the request leaves.
6
+ */
7
+ const MIN_DIMENSION = 200;
8
+ const MAX_DIMENSION = 8192;
9
+ /** How long a drag has to settle before the host is asked for a new size. */
10
+ export const RESIZE_DEBOUNCE_MS = 250;
11
+ function clamp(value) {
12
+ if (!Number.isFinite(value) || value <= 0) {
13
+ return MIN_DIMENSION;
14
+ }
15
+ return Math.min(MAX_DIMENSION, Math.max(MIN_DIMENSION, Math.floor(value)));
16
+ }
17
+ function even(value) {
18
+ return value - (value % 2);
19
+ }
20
+ export function clamp_desktop_size(width, height) {
21
+ return { width: even(clamp(width)), height: even(clamp(height)) };
22
+ }
23
+ /** The size the remote desktop would need to be to fill `element` exactly. */
24
+ export function measure_desktop_size(element) {
25
+ const rect = element.getBoundingClientRect();
26
+ return clamp_desktop_size(rect.width, rect.height);
27
+ }
28
+ export function same_desktop_size(a, b) {
29
+ return !!a && !!b && a.width === b.width && a.height === b.height;
30
+ }
31
+ /**
32
+ * Reports the widget's size to whoever can act on it, as the widget is resized.
33
+ *
34
+ * Two behaviours are deliberate. It **debounces**, because dragging a panel
35
+ * edge emits a resize per frame while every report costs a display-control
36
+ * round trip to the host — and a host that is still applying one layout ignores
37
+ * the next. And it **drops repeats**, because a resize observer also fires for
38
+ * changes that do not move the desktop at all (a scrollbar appearing, the
39
+ * canvas being re-laid-out in response to the resize this class just asked for,
40
+ * which would otherwise loop).
41
+ */
42
+ export class ViewportSync {
43
+ onResize;
44
+ debounceMs;
45
+ observer;
46
+ handle;
47
+ reported;
48
+ constructor(onResize, debounceMs = RESIZE_DEBOUNCE_MS) {
49
+ this.onResize = onResize;
50
+ this.debounceMs = debounceMs;
51
+ }
52
+ /**
53
+ * Starts watching `element`. The current size is reported immediately, so a
54
+ * widget that was resized while disconnected catches up on reconnect.
55
+ */
56
+ observe(element) {
57
+ this.disconnect();
58
+ this.report(measure_desktop_size(element));
59
+ // Absent under the spec test environment, and on nothing else worth
60
+ // supporting — a missing observer costs the dynamic resize, not the
61
+ // session.
62
+ if (typeof ResizeObserver === 'undefined') {
63
+ return;
64
+ }
65
+ this.observer = new ResizeObserver(() => {
66
+ clearTimeout(this.handle);
67
+ this.handle = setTimeout(() => this.report(measure_desktop_size(element)), this.debounceMs);
68
+ });
69
+ this.observer.observe(element);
70
+ }
71
+ disconnect() {
72
+ clearTimeout(this.handle);
73
+ this.handle = undefined;
74
+ this.observer?.disconnect();
75
+ this.observer = undefined;
76
+ this.reported = undefined;
77
+ }
78
+ report(size) {
79
+ if (same_desktop_size(size, this.reported)) {
80
+ return;
81
+ }
82
+ this.reported = size;
83
+ this.onResize(size);
84
+ }
85
+ }