tabby-rdp 0.5.1 → 0.5.3

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.
@@ -0,0 +1,3237 @@
1
+ // Generated by scripts/make-ironrdp-factory.mjs from iron-remote-desktop-rdp.js.
2
+ export async function createBackend (__trdModule, __trdLevel = 'INFO') {
3
+ if (!(__trdModule instanceof WebAssembly.Module)) throw new TypeError('createBackend needs a compiled WebAssembly.Module');
4
+ let __trdTrap;
5
+ const __trdListeners = new Set();
6
+ let __trdReleased = false;
7
+ const __trdTimers = new Set();
8
+ const __trdEvents = new Set();
9
+ function setInterval (callback, delay, ...args) {
10
+ if (__trdReleased) return 0;
11
+ const handle = globalThis.setInterval(() => { if (!__trdReleased) callback(...args); }, delay);
12
+ __trdTimers.add(handle);
13
+ return handle;
14
+ }
15
+ function setTimeout (callback, delay, ...args) {
16
+ if (__trdReleased) return 0;
17
+ const handle = globalThis.setTimeout(() => {
18
+ __trdTimers.delete(handle);
19
+ if (!__trdReleased) callback(...args);
20
+ }, delay);
21
+ __trdTimers.add(handle);
22
+ return handle;
23
+ }
24
+ function clearInterval (handle) { __trdTimers.delete(handle); globalThis.clearInterval(handle); }
25
+ function clearTimeout (handle) { __trdTimers.delete(handle); globalThis.clearTimeout(handle); }
26
+ function __trdListen (target, type, callback, options) {
27
+ if (__trdReleased) return;
28
+ target.addEventListener(type, callback, options);
29
+ __trdEvents.add({ target, type, callback, capture: typeof options === 'boolean' ? options : !!options?.capture });
30
+ }
31
+ function __trdUnlisten (target, type, callback, options) {
32
+ const capture = typeof options === 'boolean' ? options : !!options?.capture;
33
+ target.removeEventListener(type, callback, options);
34
+ for (const event of __trdEvents) {
35
+ if (event.target === target && event.type === type && event.callback === callback && event.capture === capture) {
36
+ __trdEvents.delete(event);
37
+ }
38
+ }
39
+ }
40
+ function __trdReleaseBrowserRoots () {
41
+ __trdReleased = true;
42
+ for (const handle of __trdTimers) { globalThis.clearTimeout(handle); globalThis.clearInterval(handle); }
43
+ __trdTimers.clear();
44
+ for (const { target, type, callback, capture } of __trdEvents) target.removeEventListener(type, callback, capture);
45
+ __trdEvents.clear();
46
+ }
47
+ function __trdWatchExports (raw) {
48
+ return Object.fromEntries(Object.entries(raw).map(([name, value]) => [name, typeof value !== 'function' ? value : (...args) => {
49
+ // Rust destructors cannot safely run after an abort. Late JS finalizers become harmless.
50
+ if (__trdTrap) {
51
+ if (/^__wbg_.*_free$|^__wbindgen_destroy_closure$/.test(name)) return;
52
+ throw __trdTrap;
53
+ }
54
+ try { return value(...args); } catch (error) {
55
+ if (error instanceof WebAssembly.RuntimeError) {
56
+ __trdTrap = error;
57
+ // Rust cannot cancel its timers/listeners after an abort. Their browser roots retain the heap.
58
+ __trdReleaseBrowserRoots();
59
+ for (const listener of __trdListeners) listener(error);
60
+ __trdListeners.clear();
61
+ }
62
+ throw error;
63
+ }
64
+ }]));
65
+ }
66
+ var __defProp = Object.defineProperty;
67
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
68
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
69
+ class Z {
70
+ static __wrap(A) {
71
+ const I = Object.create(Z.prototype);
72
+ return I.__wbg_ptr = A, u.register(I, I.__wbg_ptr, I), I;
73
+ }
74
+ __destroy_into_raw() {
75
+ const A = this.__wbg_ptr;
76
+ return this.__wbg_ptr = 0, u.unregister(this), A;
77
+ }
78
+ free() {
79
+ const A = this.__destroy_into_raw();
80
+ C.__wbg_clipboarddata_free(A, 0);
81
+ }
82
+ /**
83
+ * @param {string} mime_type
84
+ * @param {Uint8Array} binary
85
+ */
86
+ addBinary(A, I) {
87
+ const g = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = k, E = lA(I, C.__wbindgen_malloc), D = k;
88
+ C.clipboarddata_addBinary(this.__wbg_ptr, g, B, E, D);
89
+ }
90
+ /**
91
+ * @param {string} mime_type
92
+ * @param {string} text
93
+ */
94
+ addText(A, I) {
95
+ const g = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = k, E = R(I, C.__wbindgen_malloc, C.__wbindgen_realloc), D = k;
96
+ C.clipboarddata_addText(this.__wbg_ptr, g, B, E, D);
97
+ }
98
+ constructor() {
99
+ const A = C.clipboarddata_create();
100
+ return this.__wbg_ptr = A, u.register(this, this.__wbg_ptr, this), this;
101
+ }
102
+ /**
103
+ * @returns {boolean}
104
+ */
105
+ isEmpty() {
106
+ return C.clipboarddata_isEmpty(this.__wbg_ptr) !== 0;
107
+ }
108
+ /**
109
+ * @returns {ClipboardItem[]}
110
+ */
111
+ items() {
112
+ const A = C.clipboarddata_items(this.__wbg_ptr);
113
+ var I = pA(A[0], A[1]).slice();
114
+ return C.__wbindgen_free(A[0], A[1] * 4, 4), I;
115
+ }
116
+ }
117
+ Symbol.dispose && (Z.prototype[Symbol.dispose] = Z.prototype.free);
118
+ class f {
119
+ static __wrap(A) {
120
+ const I = Object.create(f.prototype);
121
+ return I.__wbg_ptr = A, CA.register(I, I.__wbg_ptr, I), I;
122
+ }
123
+ __destroy_into_raw() {
124
+ const A = this.__wbg_ptr;
125
+ return this.__wbg_ptr = 0, CA.unregister(this), A;
126
+ }
127
+ free() {
128
+ const A = this.__destroy_into_raw();
129
+ C.__wbg_clipboarditem_free(A, 0);
130
+ }
131
+ /**
132
+ * @returns {string}
133
+ */
134
+ mimeType() {
135
+ let A, I;
136
+ try {
137
+ const g = C.clipboarditem_mimeType(this.__wbg_ptr);
138
+ return A = g[0], I = g[1], y(g[0], g[1]);
139
+ } finally {
140
+ C.__wbindgen_free(A, I, 1);
141
+ }
142
+ }
143
+ /**
144
+ * @returns {any}
145
+ */
146
+ value() {
147
+ return C.clipboarditem_value(this.__wbg_ptr);
148
+ }
149
+ }
150
+ Symbol.dispose && (f.prototype[Symbol.dispose] = f.prototype.free);
151
+ class p {
152
+ static __wrap(A) {
153
+ const I = Object.create(p.prototype);
154
+ return I.__wbg_ptr = A, _.register(I, I.__wbg_ptr, I), I;
155
+ }
156
+ __destroy_into_raw() {
157
+ const A = this.__wbg_ptr;
158
+ return this.__wbg_ptr = 0, _.unregister(this), A;
159
+ }
160
+ free() {
161
+ const A = this.__destroy_into_raw();
162
+ C.__wbg_desktopsize_free(A, 0);
163
+ }
164
+ /**
165
+ * @param {number} width
166
+ * @param {number} height
167
+ */
168
+ constructor(A, I) {
169
+ const g = C.desktopsize_create(A, I);
170
+ return this.__wbg_ptr = g, _.register(this, this.__wbg_ptr, this), this;
171
+ }
172
+ /**
173
+ * @returns {number}
174
+ */
175
+ get height() {
176
+ return C.__wbg_get_desktopsize_height(this.__wbg_ptr);
177
+ }
178
+ /**
179
+ * @returns {number}
180
+ */
181
+ get width() {
182
+ return C.__wbg_get_desktopsize_width(this.__wbg_ptr);
183
+ }
184
+ /**
185
+ * @param {number} arg0
186
+ */
187
+ set height(A) {
188
+ C.__wbg_set_desktopsize_height(this.__wbg_ptr, A);
189
+ }
190
+ /**
191
+ * @param {number} arg0
192
+ */
193
+ set width(A) {
194
+ C.__wbg_set_desktopsize_width(this.__wbg_ptr, A);
195
+ }
196
+ }
197
+ Symbol.dispose && (p.prototype[Symbol.dispose] = p.prototype.free);
198
+ class K {
199
+ static __wrap(A) {
200
+ const I = Object.create(K.prototype);
201
+ return I.__wbg_ptr = A, EA.register(I, I.__wbg_ptr, I), I;
202
+ }
203
+ __destroy_into_raw() {
204
+ const A = this.__wbg_ptr;
205
+ return this.__wbg_ptr = 0, EA.unregister(this), A;
206
+ }
207
+ free() {
208
+ const A = this.__destroy_into_raw();
209
+ C.__wbg_deviceevent_free(A, 0);
210
+ }
211
+ /**
212
+ * @param {number} scancode
213
+ * @returns {DeviceEvent}
214
+ */
215
+ static keyPressed(A) {
216
+ const I = C.deviceevent_keyPressed(A);
217
+ return K.__wrap(I);
218
+ }
219
+ /**
220
+ * @param {number} scancode
221
+ * @returns {DeviceEvent}
222
+ */
223
+ static keyReleased(A) {
224
+ const I = C.deviceevent_keyReleased(A);
225
+ return K.__wrap(I);
226
+ }
227
+ /**
228
+ * @param {number} button
229
+ * @returns {DeviceEvent}
230
+ */
231
+ static mouseButtonPressed(A) {
232
+ const I = C.deviceevent_mouseButtonPressed(A);
233
+ return K.__wrap(I);
234
+ }
235
+ /**
236
+ * @param {number} button
237
+ * @returns {DeviceEvent}
238
+ */
239
+ static mouseButtonReleased(A) {
240
+ const I = C.deviceevent_mouseButtonReleased(A);
241
+ return K.__wrap(I);
242
+ }
243
+ /**
244
+ * @param {number} x
245
+ * @param {number} y
246
+ * @returns {DeviceEvent}
247
+ */
248
+ static mouseMove(A, I) {
249
+ const g = C.deviceevent_mouseMove(A, I);
250
+ return K.__wrap(g);
251
+ }
252
+ /**
253
+ * @param {string} unicode
254
+ * @returns {DeviceEvent}
255
+ */
256
+ static unicodePressed(A) {
257
+ const I = A.codePointAt(0);
258
+ FA(I);
259
+ const g = C.deviceevent_unicodePressed(I);
260
+ return K.__wrap(g);
261
+ }
262
+ /**
263
+ * @param {string} unicode
264
+ * @returns {DeviceEvent}
265
+ */
266
+ static unicodeReleased(A) {
267
+ const I = A.codePointAt(0);
268
+ FA(I);
269
+ const g = C.deviceevent_unicodeReleased(I);
270
+ return K.__wrap(g);
271
+ }
272
+ /**
273
+ * @param {boolean} vertical
274
+ * @param {number} rotation_amount
275
+ * @param {RotationUnit} rotation_unit
276
+ * @returns {DeviceEvent}
277
+ */
278
+ static wheelRotations(A, I, g) {
279
+ const B = C.deviceevent_wheelRotations(A, I, g);
280
+ return K.__wrap(B);
281
+ }
282
+ }
283
+ Symbol.dispose && (K.prototype[Symbol.dispose] = K.prototype.free);
284
+ class N {
285
+ __destroy_into_raw() {
286
+ const A = this.__wbg_ptr;
287
+ return this.__wbg_ptr = 0, DA.unregister(this), A;
288
+ }
289
+ free() {
290
+ const A = this.__destroy_into_raw();
291
+ C.__wbg_extension_free(A, 0);
292
+ }
293
+ /**
294
+ * @param {string} ident
295
+ * @param {any} value
296
+ */
297
+ constructor(A, I) {
298
+ const g = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = k, E = C.extension_create(g, B, I);
299
+ return this.__wbg_ptr = E, DA.register(this, this.__wbg_ptr, this), this;
300
+ }
301
+ }
302
+ Symbol.dispose && (N.prototype[Symbol.dispose] = N.prototype.free);
303
+ class e {
304
+ __destroy_into_raw() {
305
+ const A = this.__wbg_ptr;
306
+ return this.__wbg_ptr = 0, iA.unregister(this), A;
307
+ }
308
+ free() {
309
+ const A = this.__destroy_into_raw();
310
+ C.__wbg_inputtransaction_free(A, 0);
311
+ }
312
+ /**
313
+ * @param {DeviceEvent} event
314
+ */
315
+ addEvent(A) {
316
+ V(A, K);
317
+ var I = A.__destroy_into_raw();
318
+ C.inputtransaction_addEvent(this.__wbg_ptr, I);
319
+ }
320
+ constructor() {
321
+ const A = C.inputtransaction_create();
322
+ return this.__wbg_ptr = A, iA.register(this, this.__wbg_ptr, this), this;
323
+ }
324
+ }
325
+ Symbol.dispose && (e.prototype[Symbol.dispose] = e.prototype.free);
326
+ class T {
327
+ static __wrap(A) {
328
+ const I = Object.create(T.prototype);
329
+ return I.__wbg_ptr = A, wA.register(I, I.__wbg_ptr, I), I;
330
+ }
331
+ __destroy_into_raw() {
332
+ const A = this.__wbg_ptr;
333
+ return this.__wbg_ptr = 0, wA.unregister(this), A;
334
+ }
335
+ free() {
336
+ const A = this.__destroy_into_raw();
337
+ C.__wbg_ironerror_free(A, 0);
338
+ }
339
+ /**
340
+ * @returns {string}
341
+ */
342
+ backtrace() {
343
+ let A, I;
344
+ try {
345
+ const g = C.ironerror_backtrace(this.__wbg_ptr);
346
+ return A = g[0], I = g[1], y(g[0], g[1]);
347
+ } finally {
348
+ C.__wbindgen_free(A, I, 1);
349
+ }
350
+ }
351
+ /**
352
+ * @returns {IronErrorKind}
353
+ */
354
+ kind() {
355
+ return C.ironerror_kind(this.__wbg_ptr);
356
+ }
357
+ /**
358
+ * @returns {RDCleanPathDetails | undefined}
359
+ */
360
+ rdcleanpathDetails() {
361
+ const A = C.ironerror_rdcleanpathDetails(this.__wbg_ptr);
362
+ return A === 0 ? void 0 : n.__wrap(A);
363
+ }
364
+ }
365
+ Symbol.dispose && (T.prototype[Symbol.dispose] = T.prototype.free);
366
+ class n {
367
+ static __wrap(A) {
368
+ const I = Object.create(n.prototype);
369
+ return I.__wbg_ptr = A, GA.register(I, I.__wbg_ptr, I), I;
370
+ }
371
+ __destroy_into_raw() {
372
+ const A = this.__wbg_ptr;
373
+ return this.__wbg_ptr = 0, GA.unregister(this), A;
374
+ }
375
+ free() {
376
+ const A = this.__destroy_into_raw();
377
+ C.__wbg_rdcleanpathdetails_free(A, 0);
378
+ }
379
+ /**
380
+ * HTTP status code if the error originated from an HTTP response.
381
+ *
382
+ * Common values:
383
+ * - 403: Forbidden (e.g., deleted VNET, insufficient permissions)
384
+ * - 404: Not Found
385
+ * - 500: Internal Server Error
386
+ * - 502: Bad Gateway
387
+ * - 503: Service Unavailable
388
+ * @returns {number | undefined}
389
+ */
390
+ get httpStatusCode() {
391
+ const A = C.rdcleanpathdetails_httpStatusCode(this.__wbg_ptr);
392
+ return A === 16777215 ? void 0 : A;
393
+ }
394
+ /**
395
+ * TLS alert code if the error occurred during TLS handshake.
396
+ *
397
+ * Common values:
398
+ * - 40: Handshake failure
399
+ * - 42: Bad certificate
400
+ * - 45: Certificate expired
401
+ * - 48: Unknown CA
402
+ * - 112: Unrecognized name
403
+ * @returns {number | undefined}
404
+ */
405
+ get tlsAlertCode() {
406
+ const A = C.rdcleanpathdetails_tlsAlertCode(this.__wbg_ptr);
407
+ return A === 16777215 ? void 0 : A;
408
+ }
409
+ /**
410
+ * Windows Socket API (WSA) error code.
411
+ *
412
+ * Common values:
413
+ * - 10013: Permission denied (WSAEACCES) - often indicates deleted/invalid VNET
414
+ * - 10060: Connection timed out (WSAETIMEDOUT)
415
+ * - 10061: Connection refused (WSAECONNREFUSED)
416
+ * - 10051: Network is unreachable (WSAENETUNREACH)
417
+ * - 10065: No route to host (WSAEHOSTUNREACH)
418
+ * @returns {number | undefined}
419
+ */
420
+ get wsaErrorCode() {
421
+ const A = C.rdcleanpathdetails_wsaErrorCode(this.__wbg_ptr);
422
+ return A === 16777215 ? void 0 : A;
423
+ }
424
+ }
425
+ Symbol.dispose && (n.prototype[Symbol.dispose] = n.prototype.free);
426
+ class QA {
427
+ __destroy_into_raw() {
428
+ const A = this.__wbg_ptr;
429
+ return this.__wbg_ptr = 0, oA.unregister(this), A;
430
+ }
431
+ free() {
432
+ const A = this.__destroy_into_raw();
433
+ C.__wbg_rdpfile_free(A, 0);
434
+ }
435
+ constructor() {
436
+ const A = C.rdpfile_create();
437
+ return this.__wbg_ptr = A, oA.register(this, this.__wbg_ptr, this), this;
438
+ }
439
+ /**
440
+ * @param {string} key
441
+ * @returns {number | undefined}
442
+ */
443
+ getInt(A) {
444
+ const I = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = k, B = C.rdpfile_getInt(this.__wbg_ptr, I, g);
445
+ return B === Number.MAX_SAFE_INTEGER ? void 0 : B;
446
+ }
447
+ /**
448
+ * @param {string} key
449
+ * @returns {string | undefined}
450
+ */
451
+ getStr(A) {
452
+ const I = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = k, B = C.rdpfile_getStr(this.__wbg_ptr, I, g);
453
+ let E;
454
+ return B[0] !== 0 && (E = y(B[0], B[1]).slice(), C.__wbindgen_free(B[0], B[1] * 1, 1)), E;
455
+ }
456
+ /**
457
+ * @param {string} key
458
+ * @param {number} value
459
+ */
460
+ insertInt(A, I) {
461
+ const g = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = k;
462
+ C.rdpfile_insertInt(this.__wbg_ptr, g, B, I);
463
+ }
464
+ /**
465
+ * @param {string} key
466
+ * @param {string} value
467
+ */
468
+ insertStr(A, I) {
469
+ const g = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = k, E = R(I, C.__wbindgen_malloc, C.__wbindgen_realloc), D = k;
470
+ C.rdpfile_insertStr(this.__wbg_ptr, g, B, E, D);
471
+ }
472
+ /**
473
+ * @param {string} config
474
+ */
475
+ parse(A) {
476
+ const I = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = k;
477
+ C.rdpfile_parse(this.__wbg_ptr, I, g);
478
+ }
479
+ /**
480
+ * @returns {string}
481
+ */
482
+ write() {
483
+ let A, I;
484
+ try {
485
+ const g = C.rdpfile_write(this.__wbg_ptr);
486
+ return A = g[0], I = g[1], y(g[0], g[1]);
487
+ } finally {
488
+ C.__wbindgen_free(A, I, 1);
489
+ }
490
+ }
491
+ }
492
+ Symbol.dispose && (QA.prototype[Symbol.dispose] = QA.prototype.free);
493
+ class r {
494
+ static __wrap(A) {
495
+ const I = Object.create(r.prototype);
496
+ return I.__wbg_ptr = A, NA.register(I, I.__wbg_ptr, I), I;
497
+ }
498
+ __destroy_into_raw() {
499
+ const A = this.__wbg_ptr;
500
+ return this.__wbg_ptr = 0, NA.unregister(this), A;
501
+ }
502
+ free() {
503
+ const A = this.__destroy_into_raw();
504
+ C.__wbg_session_free(A, 0);
505
+ }
506
+ /**
507
+ * @param {InputTransaction} transaction
508
+ */
509
+ applyInputs(A) {
510
+ V(A, e);
511
+ var I = A.__destroy_into_raw();
512
+ const g = C.session_applyInputs(this.__wbg_ptr, I);
513
+ if (g[1])
514
+ throw q(g[0]);
515
+ }
516
+ /**
517
+ * @returns {DesktopSize}
518
+ */
519
+ desktopSize() {
520
+ const A = C.session_desktopSize(this.__wbg_ptr);
521
+ return p.__wrap(A);
522
+ }
523
+ /**
524
+ * @param {Extension} ext
525
+ * @returns {any}
526
+ */
527
+ invokeExtension(A) {
528
+ V(A, N);
529
+ var I = A.__destroy_into_raw();
530
+ const g = C.session_invokeExtension(this.__wbg_ptr, I);
531
+ if (g[2])
532
+ throw q(g[1]);
533
+ return q(g[0]);
534
+ }
535
+ /**
536
+ * @param {ClipboardData} content
537
+ * @returns {Promise<void>}
538
+ */
539
+ onClipboardPaste(A) {
540
+ return V(A, Z), C.session_onClipboardPaste(this.__wbg_ptr, A.__wbg_ptr);
541
+ }
542
+ releaseAllInputs() {
543
+ const A = C.session_releaseAllInputs(this.__wbg_ptr);
544
+ if (A[1])
545
+ throw q(A[0]);
546
+ }
547
+ /**
548
+ * @param {number} width
549
+ * @param {number} height
550
+ * @param {number | null} [scale_factor]
551
+ * @param {number | null} [physical_width]
552
+ * @param {number | null} [physical_height]
553
+ */
554
+ resize(A, I, g, B, E) {
555
+ C.session_resize(this.__wbg_ptr, A, I, h(g) ? Number.MAX_SAFE_INTEGER : g >>> 0, h(B) ? Number.MAX_SAFE_INTEGER : B >>> 0, h(E) ? Number.MAX_SAFE_INTEGER : E >>> 0);
556
+ }
557
+ /**
558
+ * @returns {Promise<SessionTerminationInfo>}
559
+ */
560
+ run() {
561
+ return C.session_run(this.__wbg_ptr);
562
+ }
563
+ shutdown() {
564
+ const A = C.session_shutdown(this.__wbg_ptr);
565
+ if (A[1])
566
+ throw q(A[0]);
567
+ }
568
+ /**
569
+ * @returns {boolean}
570
+ */
571
+ supportsUnicodeKeyboardShortcuts() {
572
+ return C.session_supportsUnicodeKeyboardShortcuts(this.__wbg_ptr) !== 0;
573
+ }
574
+ /**
575
+ * @param {boolean} scroll_lock
576
+ * @param {boolean} num_lock
577
+ * @param {boolean} caps_lock
578
+ * @param {boolean} kana_lock
579
+ */
580
+ synchronizeLockKeys(A, I, g, B) {
581
+ const E = C.session_synchronizeLockKeys(this.__wbg_ptr, A, I, g, B);
582
+ if (E[1])
583
+ throw q(E[0]);
584
+ }
585
+ }
586
+ Symbol.dispose && (r.prototype[Symbol.dispose] = r.prototype.free);
587
+ class c {
588
+ static __wrap(A) {
589
+ const I = Object.create(c.prototype);
590
+ return I.__wbg_ptr = A, $.register(I, I.__wbg_ptr, I), I;
591
+ }
592
+ __destroy_into_raw() {
593
+ const A = this.__wbg_ptr;
594
+ return this.__wbg_ptr = 0, $.unregister(this), A;
595
+ }
596
+ free() {
597
+ const A = this.__destroy_into_raw();
598
+ C.__wbg_sessionbuilder_free(A, 0);
599
+ }
600
+ /**
601
+ * @param {string} token
602
+ * @returns {SessionBuilder}
603
+ */
604
+ authToken(A) {
605
+ const I = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = k, B = C.sessionbuilder_authToken(this.__wbg_ptr, I, g);
606
+ return c.__wrap(B);
607
+ }
608
+ /**
609
+ * @param {Function} callback
610
+ * @returns {SessionBuilder}
611
+ */
612
+ canvasResizedCallback(A) {
613
+ const I = C.sessionbuilder_canvasResizedCallback(this.__wbg_ptr, A);
614
+ return c.__wrap(I);
615
+ }
616
+ /**
617
+ * @returns {Promise<Session>}
618
+ */
619
+ connect() {
620
+ return C.sessionbuilder_connect(this.__wbg_ptr);
621
+ }
622
+ constructor() {
623
+ const A = C.sessionbuilder_create();
624
+ return this.__wbg_ptr = A, $.register(this, this.__wbg_ptr, this), this;
625
+ }
626
+ /**
627
+ * @param {DesktopSize} desktop_size
628
+ * @returns {SessionBuilder}
629
+ */
630
+ desktopSize(A) {
631
+ V(A, p);
632
+ var I = A.__destroy_into_raw();
633
+ const g = C.sessionbuilder_desktopSize(this.__wbg_ptr, I);
634
+ return c.__wrap(g);
635
+ }
636
+ /**
637
+ * @param {string} destination
638
+ * @returns {SessionBuilder}
639
+ */
640
+ destination(A) {
641
+ const I = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = k, B = C.sessionbuilder_destination(this.__wbg_ptr, I, g);
642
+ return c.__wrap(B);
643
+ }
644
+ /**
645
+ * @param {Extension} ext
646
+ * @returns {SessionBuilder}
647
+ */
648
+ extension(A) {
649
+ V(A, N);
650
+ var I = A.__destroy_into_raw();
651
+ const g = C.sessionbuilder_extension(this.__wbg_ptr, I);
652
+ return c.__wrap(g);
653
+ }
654
+ /**
655
+ * @param {Function} callback
656
+ * @returns {SessionBuilder}
657
+ */
658
+ forceClipboardUpdateCallback(A) {
659
+ const I = C.sessionbuilder_forceClipboardUpdateCallback(this.__wbg_ptr, A);
660
+ return c.__wrap(I);
661
+ }
662
+ /**
663
+ * @param {string} password
664
+ * @returns {SessionBuilder}
665
+ */
666
+ password(A) {
667
+ const I = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = k, B = C.sessionbuilder_password(this.__wbg_ptr, I, g);
668
+ return c.__wrap(B);
669
+ }
670
+ /**
671
+ * @param {string} address
672
+ * @returns {SessionBuilder}
673
+ */
674
+ proxyAddress(A) {
675
+ const I = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = k, B = C.sessionbuilder_proxyAddress(this.__wbg_ptr, I, g);
676
+ return c.__wrap(B);
677
+ }
678
+ /**
679
+ * @param {Function} callback
680
+ * @returns {SessionBuilder}
681
+ */
682
+ remoteClipboardChangedCallback(A) {
683
+ const I = C.sessionbuilder_remoteClipboardChangedCallback(this.__wbg_ptr, A);
684
+ return c.__wrap(I);
685
+ }
686
+ /**
687
+ * @param {HTMLCanvasElement} canvas
688
+ * @returns {SessionBuilder}
689
+ */
690
+ renderCanvas(A) {
691
+ const I = C.sessionbuilder_renderCanvas(this.__wbg_ptr, A);
692
+ return c.__wrap(I);
693
+ }
694
+ /**
695
+ * @param {string} server_domain
696
+ * @returns {SessionBuilder}
697
+ */
698
+ serverDomain(A) {
699
+ const I = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = k, B = C.sessionbuilder_serverDomain(this.__wbg_ptr, I, g);
700
+ return c.__wrap(B);
701
+ }
702
+ /**
703
+ * @param {Function} callback
704
+ * @returns {SessionBuilder}
705
+ */
706
+ setCursorStyleCallback(A) {
707
+ const I = C.sessionbuilder_setCursorStyleCallback(this.__wbg_ptr, A);
708
+ return c.__wrap(I);
709
+ }
710
+ /**
711
+ * @param {any} context
712
+ * @returns {SessionBuilder}
713
+ */
714
+ setCursorStyleCallbackContext(A) {
715
+ const I = C.sessionbuilder_setCursorStyleCallbackContext(this.__wbg_ptr, A);
716
+ return c.__wrap(I);
717
+ }
718
+ /**
719
+ * @param {string} username
720
+ * @returns {SessionBuilder}
721
+ */
722
+ username(A) {
723
+ const I = R(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = k, B = C.sessionbuilder_username(this.__wbg_ptr, I, g);
724
+ return c.__wrap(B);
725
+ }
726
+ }
727
+ Symbol.dispose && (c.prototype[Symbol.dispose] = c.prototype.free);
728
+ class P {
729
+ static __wrap(A) {
730
+ const I = Object.create(P.prototype);
731
+ return I.__wbg_ptr = A, kA.register(I, I.__wbg_ptr, I), I;
732
+ }
733
+ __destroy_into_raw() {
734
+ const A = this.__wbg_ptr;
735
+ return this.__wbg_ptr = 0, kA.unregister(this), A;
736
+ }
737
+ free() {
738
+ const A = this.__destroy_into_raw();
739
+ C.__wbg_sessionterminationinfo_free(A, 0);
740
+ }
741
+ /**
742
+ * @returns {string}
743
+ */
744
+ reason() {
745
+ let A, I;
746
+ try {
747
+ const g = C.sessionterminationinfo_reason(this.__wbg_ptr);
748
+ return A = g[0], I = g[1], y(g[0], g[1]);
749
+ } finally {
750
+ C.__wbindgen_free(A, I, 1);
751
+ }
752
+ }
753
+ }
754
+ Symbol.dispose && (P.prototype[Symbol.dispose] = P.prototype.free);
755
+ function JA(Q) {
756
+ const A = R(Q, C.__wbindgen_malloc, C.__wbindgen_realloc), I = k;
757
+ C.setup(A, I);
758
+ }
759
+ function UA() {
760
+ return {
761
+ __proto__: null,
762
+ "./ironrdp_web_bg.js": {
763
+ __proto__: null,
764
+ __wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(A) {
765
+ const I = A, g = typeof I == "boolean" ? I : void 0;
766
+ return h(g) ? 16777215 : g ? 1 : 0;
767
+ },
768
+ __wbg___wbindgen_debug_string_c25d447a39f5578f: function(A, I) {
769
+ const g = gA(I), B = R(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = k;
770
+ M().setInt32(A + 4, E, true), M().setInt32(A + 0, B, true);
771
+ },
772
+ __wbg___wbindgen_is_function_1ff95bcc5517c252: function(A) {
773
+ return typeof A == "function";
774
+ },
775
+ __wbg___wbindgen_is_null_ea9085d691f535d3: function(A) {
776
+ return A === null;
777
+ },
778
+ __wbg___wbindgen_is_object_a27215656b807791: function(A) {
779
+ const I = A;
780
+ return typeof I == "object" && I !== null;
781
+ },
782
+ __wbg___wbindgen_is_string_ea5e6cc2e4141dfe: function(A) {
783
+ return typeof A == "string";
784
+ },
785
+ __wbg___wbindgen_is_undefined_c05833b95a3cf397: function(A) {
786
+ return A === void 0;
787
+ },
788
+ __wbg___wbindgen_number_get_394265ed1e1b84ee: function(A, I) {
789
+ const g = I, B = typeof g == "number" ? g : void 0;
790
+ M().setFloat64(A + 8, h(B) ? 0 : B, true), M().setInt32(A + 0, !h(B), true);
791
+ },
792
+ __wbg___wbindgen_string_get_b0ca35b86a603356: function(A, I) {
793
+ const g = I, B = typeof g == "string" ? g : void 0;
794
+ var E = h(B) ? 0 : R(B, C.__wbindgen_malloc, C.__wbindgen_realloc), D = k;
795
+ M().setInt32(A + 4, D, true), M().setInt32(A + 0, E, true);
796
+ },
797
+ __wbg___wbindgen_throw_344f42d3211c4765: function(A, I) {
798
+ throw new Error(y(A, I));
799
+ },
800
+ __wbg__wbg_cb_unref_fffb441def202758: function(A) {
801
+ A._wbg_cb_unref();
802
+ },
803
+ __wbg_addEventListener_520e749bbae24529: function() {
804
+ return o(function(A, I, g, B, E) {
805
+ __trdListen(A, y(I, g), B, E);
806
+ }, arguments);
807
+ },
808
+ __wbg_addEventListener_d85450ee1320c989: function() {
809
+ return o(function(A, I, g, B) {
810
+ __trdListen(A, y(I, g), B);
811
+ }, arguments);
812
+ },
813
+ __wbg_apply_23dd4d2439189415: function() {
814
+ return o(function(A, I, g) {
815
+ return Reflect.apply(A, I, g);
816
+ }, arguments);
817
+ },
818
+ __wbg_apply_3ac86a26fdb56c05: function() {
819
+ return o(function(A, I, g) {
820
+ return A.apply(I, g);
821
+ }, arguments);
822
+ },
823
+ __wbg_arrayBuffer_3b637f0fa65c5351: function() {
824
+ return o(function(A) {
825
+ return A.arrayBuffer();
826
+ }, arguments);
827
+ },
828
+ __wbg_call_8a2dd23819f8a60a: function() {
829
+ return o(function(A, I) {
830
+ return A.call(I);
831
+ }, arguments);
832
+ },
833
+ __wbg_call_a6e5c5dce5018821: function() {
834
+ return o(function(A, I, g) {
835
+ return A.call(I, g);
836
+ }, arguments);
837
+ },
838
+ __wbg_call_e3b662382210db98: function() {
839
+ return o(function(A, I, g, B) {
840
+ return A.call(I, g, B);
841
+ }, arguments);
842
+ },
843
+ __wbg_clearInterval_26ba580547547579: function(A) {
844
+ return clearInterval(A);
845
+ },
846
+ __wbg_clearTimeout_3629d6209dfcc46e: function(A) {
847
+ return clearTimeout(A);
848
+ },
849
+ __wbg_clipboarddata_new: function(A) {
850
+ return Z.__wrap(A);
851
+ },
852
+ __wbg_clipboarditem_new: function(A) {
853
+ return f.__wrap(A);
854
+ },
855
+ __wbg_close_c65ca0257e895318: function() {
856
+ return o(function(A) {
857
+ A.close();
858
+ }, arguments);
859
+ },
860
+ __wbg_code_1fc52b4142a112ac: function(A) {
861
+ return A.code;
862
+ },
863
+ __wbg_data_328de4280640da92: function(A) {
864
+ return A.data;
865
+ },
866
+ __wbg_debug_87fd9b1a625b7efb: function(A) {
867
+ console.debug(A);
868
+ },
869
+ __wbg_dispatchEvent_ca78eaf3d469bc25: function() {
870
+ return o(function(A, I) {
871
+ return A.dispatchEvent(I);
872
+ }, arguments);
873
+ },
874
+ __wbg_error_744744ff0c9861e6: function(A) {
875
+ console.error(A);
876
+ },
877
+ __wbg_error_a6fa202b58aa1cd3: function(A, I) {
878
+ let g, B;
879
+ try {
880
+ g = A, B = I, console.error(y(A, I));
881
+ } finally {
882
+ C.__wbindgen_free(g, B, 1);
883
+ }
884
+ },
885
+ __wbg_fetch_9b478faef8cda538: function(A) {
886
+ return fetch(A);
887
+ },
888
+ __wbg_from_13e323c65fc8f464: function(A) {
889
+ return Array.from(A);
890
+ },
891
+ __wbg_getContext_e79ddf6a9cb3cc76: function() {
892
+ return o(function(A, I, g) {
893
+ const B = A.getContext(y(I, g));
894
+ return h(B) ? 0 : L(B);
895
+ }, arguments);
896
+ },
897
+ __wbg_getRandomValues_3f44b700395062e5: function() {
898
+ return o(function(A, I) {
899
+ globalThis.crypto.getRandomValues(t(A, I));
900
+ }, arguments);
901
+ },
902
+ __wbg_getRandomValues_bf16787eede473f5: function() {
903
+ return o(function(A, I) {
904
+ globalThis.crypto.getRandomValues(t(A, I));
905
+ }, arguments);
906
+ },
907
+ __wbg_getRandomValues_cc7f052a444bb2ce: function() {
908
+ return o(function(A, I) {
909
+ globalThis.crypto.getRandomValues(t(A, I));
910
+ }, arguments);
911
+ },
912
+ __wbg_getTime_d6f070c088c9b5ed: function(A) {
913
+ return A.getTime();
914
+ },
915
+ __wbg_get_507a50627bffa49b: function(A, I) {
916
+ return A[I >>> 0];
917
+ },
918
+ __wbg_get_78f252d074a84d0b: function() {
919
+ return o(function(A, I) {
920
+ return Reflect.get(A, I);
921
+ }, arguments);
922
+ },
923
+ __wbg_get_unchecked_6e0ad6d2a41b06f6: function(A, I) {
924
+ return A[I >>> 0];
925
+ },
926
+ __wbg_height_6eec812c213259a1: function(A) {
927
+ return A.height;
928
+ },
929
+ __wbg_info_eadbe775a8e2e9eb: function(A) {
930
+ console.info(A);
931
+ },
932
+ __wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(A) {
933
+ let I;
934
+ try {
935
+ I = A instanceof ArrayBuffer;
936
+ } catch {
937
+ I = false;
938
+ }
939
+ return I;
940
+ },
941
+ __wbg_instanceof_CanvasRenderingContext2d_2284b703b7023dcc: function(A) {
942
+ let I;
943
+ try {
944
+ I = A instanceof CanvasRenderingContext2D;
945
+ } catch {
946
+ I = false;
947
+ }
948
+ return I;
949
+ },
950
+ __wbg_instanceof_Error_1fdac9f13a8181ba: function(A) {
951
+ let I;
952
+ try {
953
+ I = A instanceof Error;
954
+ } catch {
955
+ I = false;
956
+ }
957
+ return I;
958
+ },
959
+ __wbg_instanceof_Object_33f20e6f12439f3e: function(A) {
960
+ let I;
961
+ try {
962
+ I = A instanceof Object;
963
+ } catch {
964
+ I = false;
965
+ }
966
+ return I;
967
+ },
968
+ __wbg_instanceof_Response_c8b64b2256f01bec: function(A) {
969
+ let I;
970
+ try {
971
+ I = A instanceof Response;
972
+ } catch {
973
+ I = false;
974
+ }
975
+ return I;
976
+ },
977
+ __wbg_instanceof_Uint8Array_309b927aaf7a3fc7: function(A) {
978
+ let I;
979
+ try {
980
+ I = A instanceof Uint8Array;
981
+ } catch {
982
+ I = false;
983
+ }
984
+ return I;
985
+ },
986
+ __wbg_instanceof_Window_05ba1ee4f6781663: function(A) {
987
+ let I;
988
+ try {
989
+ I = A instanceof Window;
990
+ } catch {
991
+ I = false;
992
+ }
993
+ return I;
994
+ },
995
+ __wbg_ironerror_new: function(A) {
996
+ return T.__wrap(A);
997
+ },
998
+ __wbg_isArray_0677c962b281d01a: function(A) {
999
+ return Array.isArray(A);
1000
+ },
1001
+ __wbg_length_1f0964f4a5e2c6d8: function(A) {
1002
+ return A.length;
1003
+ },
1004
+ __wbg_length_370319915dc99107: function(A) {
1005
+ return A.length;
1006
+ },
1007
+ __wbg_message_8326fb1d549bebc5: function(A) {
1008
+ return A.message;
1009
+ },
1010
+ __wbg_name_b0b4809690944614: function(A) {
1011
+ return A.name;
1012
+ },
1013
+ __wbg_navigator_99621db14b3f1099: function(A) {
1014
+ return A.navigator;
1015
+ },
1016
+ __wbg_new_08cb2fa678b17a48: function() {
1017
+ return o(function(A, I) {
1018
+ return new URL(y(A, I));
1019
+ }, arguments);
1020
+ },
1021
+ __wbg_new_0_3da9e97f24fc69be: function() {
1022
+ return /* @__PURE__ */ new Date();
1023
+ },
1024
+ __wbg_new_0d809930cd1354c6: function() {
1025
+ return o(function() {
1026
+ return new Headers();
1027
+ }, arguments);
1028
+ },
1029
+ __wbg_new_227d7c05414eb861: function() {
1030
+ return new Error();
1031
+ },
1032
+ __wbg_new_32b398fb48b6d94a: function() {
1033
+ return new Array();
1034
+ },
1035
+ __wbg_new_bf8729ffe10e9ee7: function() {
1036
+ return o(function(A, I) {
1037
+ return new WebSocket(y(A, I));
1038
+ }, arguments);
1039
+ },
1040
+ __wbg_new_cd45aabdf6073e84: function(A) {
1041
+ return new Uint8Array(A);
1042
+ },
1043
+ __wbg_new_da52cf8fe3429cb2: function() {
1044
+ return new Object();
1045
+ },
1046
+ __wbg_new_f0787df90791d9ba: function() {
1047
+ return o(function() {
1048
+ return new URLSearchParams();
1049
+ }, arguments);
1050
+ },
1051
+ __wbg_new_from_slice_7568ba55b4a7e81f: function(A, I) {
1052
+ return new Uint32Array(dA(A, I));
1053
+ },
1054
+ __wbg_new_from_slice_77cdfb7977362f3c: function(A, I) {
1055
+ return new Uint8Array(t(A, I));
1056
+ },
1057
+ __wbg_new_typed_1824d93f294193e5: function(A, I) {
1058
+ try {
1059
+ var g = { a: A, b: I }, B = (D, i) => {
1060
+ const w = g.a;
1061
+ g.a = 0;
1062
+ try {
1063
+ return sA(w, g.b, D, i);
1064
+ } finally {
1065
+ g.a = w;
1066
+ }
1067
+ };
1068
+ return new Promise(B);
1069
+ } finally {
1070
+ g.a = 0;
1071
+ }
1072
+ },
1073
+ __wbg_new_with_event_init_dict_7b62c0f9fb241877: function() {
1074
+ return o(function(A, I, g) {
1075
+ return new CloseEvent(y(A, I), g);
1076
+ }, arguments);
1077
+ },
1078
+ __wbg_new_with_str_54bc0f9c32770e1e: function() {
1079
+ return o(function(A, I) {
1080
+ return new Request(y(A, I));
1081
+ }, arguments);
1082
+ },
1083
+ __wbg_new_with_str_and_init_d95cbe11ce28e65e: function() {
1084
+ return o(function(A, I, g) {
1085
+ return new Request(y(A, I), g);
1086
+ }, arguments);
1087
+ },
1088
+ __wbg_new_with_u8_array_sequence_bdda73b0f202f149: function() {
1089
+ return o(function(A) {
1090
+ return new Blob(A);
1091
+ }, arguments);
1092
+ },
1093
+ __wbg_new_with_u8_clamped_array_and_sh_2767e4741c267d25: function() {
1094
+ return o(function(A, I, g, B) {
1095
+ return new ImageData(VA(A, I), g >>> 0, B >>> 0);
1096
+ }, arguments);
1097
+ },
1098
+ __wbg_now_390768da5ee9e776: function(A) {
1099
+ return A.now();
1100
+ },
1101
+ __wbg_now_86c0d4ba3fa605b8: function() {
1102
+ return Date.now();
1103
+ },
1104
+ __wbg_now_e7c6795a7f81e10f: function(A) {
1105
+ return A.now();
1106
+ },
1107
+ __wbg_of_85f52f8b6491a7ca: function(A) {
1108
+ return Array.of(A);
1109
+ },
1110
+ __wbg_ok_acc5e3fb89668864: function(A) {
1111
+ return A.ok;
1112
+ },
1113
+ __wbg_performance_3ef602e13d6c3b56: function(A) {
1114
+ const I = A.performance;
1115
+ return h(I) ? 0 : L(I);
1116
+ },
1117
+ __wbg_performance_3fcf6e32a7e1ed0a: function(A) {
1118
+ return A.performance;
1119
+ },
1120
+ __wbg_prototypesetcall_4770620bbe4688a0: function(A, I, g) {
1121
+ Uint8Array.prototype.set.call(t(A, I), g);
1122
+ },
1123
+ __wbg_push_d2ae3af0c1217ae6: function(A, I) {
1124
+ return A.push(I);
1125
+ },
1126
+ __wbg_putImageData_a4dee11e08ab9ac8: function() {
1127
+ return o(function(A, I, g, B) {
1128
+ A.putImageData(I, g, B);
1129
+ }, arguments);
1130
+ },
1131
+ __wbg_queueMicrotask_0ab5b2d2393e99b9: function(A) {
1132
+ return A.queueMicrotask;
1133
+ },
1134
+ __wbg_queueMicrotask_6a09b7bc46549209: function(A) {
1135
+ queueMicrotask(A);
1136
+ },
1137
+ __wbg_readyState_50bc38c2a9e83db6: function(A) {
1138
+ return A.readyState;
1139
+ },
1140
+ __wbg_reason_5dc8e429d537d6a9: function(A, I) {
1141
+ const g = I.reason, B = R(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = k;
1142
+ M().setInt32(A + 4, E, true), M().setInt32(A + 0, B, true);
1143
+ },
1144
+ __wbg_removeEventListener_a3f23c70077bdcc1: function() {
1145
+ return o(function(A, I, g, B) {
1146
+ __trdUnlisten(A, y(I, g), B);
1147
+ }, arguments);
1148
+ },
1149
+ __wbg_resolve_2191a4dfe481c25b: function(A) {
1150
+ return Promise.resolve(A);
1151
+ },
1152
+ __wbg_search_c905fb82fd20bc6b: function(A, I) {
1153
+ const g = I.search, B = R(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = k;
1154
+ M().setInt32(A + 4, E, true), M().setInt32(A + 0, B, true);
1155
+ },
1156
+ __wbg_send_1733c45567a373ff: function() {
1157
+ return o(function(A, I) {
1158
+ A.send(I);
1159
+ }, arguments);
1160
+ },
1161
+ __wbg_send_df98dd5ede9b3f4d: function() {
1162
+ return o(function(A, I, g) {
1163
+ A.send(y(I, g));
1164
+ }, arguments);
1165
+ },
1166
+ __wbg_session_new: function(A) {
1167
+ return r.__wrap(A);
1168
+ },
1169
+ __wbg_sessionterminationinfo_new: function(A) {
1170
+ return P.__wrap(A);
1171
+ },
1172
+ __wbg_setInterval_cbf1c35c6a692d37: function() {
1173
+ return o(function(A, I) {
1174
+ return setInterval(A, I);
1175
+ }, arguments);
1176
+ },
1177
+ __wbg_setTimeout_56bcdccbad22fd44: function() {
1178
+ return o(function(A, I) {
1179
+ return setTimeout(A, I);
1180
+ }, arguments);
1181
+ },
1182
+ __wbg_set_0de9c62c23d04ad5: function() {
1183
+ return o(function(A, I, g, B, E) {
1184
+ A.set(y(I, g), y(B, E));
1185
+ }, arguments);
1186
+ },
1187
+ __wbg_set_8535240470bf2500: function() {
1188
+ return o(function(A, I, g) {
1189
+ return Reflect.set(A, I, g);
1190
+ }, arguments);
1191
+ },
1192
+ __wbg_set_binaryType_a37b086c78ca7c29: function(A, I) {
1193
+ A.binaryType = ZA[I];
1194
+ },
1195
+ __wbg_set_body_029f2d171e0a005f: function(A, I) {
1196
+ A.body = I;
1197
+ },
1198
+ __wbg_set_code_9d09aecd77d789f4: function(A, I) {
1199
+ A.code = I;
1200
+ },
1201
+ __wbg_set_headers_9c61d123c3ee1f10: function(A, I) {
1202
+ A.headers = I;
1203
+ },
1204
+ __wbg_set_height_7d9d8f892e6964c6: function(A, I) {
1205
+ A.height = I >>> 0;
1206
+ },
1207
+ __wbg_set_method_5532d59b92d76467: function(A, I, g) {
1208
+ A.method = y(I, g);
1209
+ },
1210
+ __wbg_set_once_51a9fb6b8af8a72b: function(A, I) {
1211
+ A.once = I !== 0;
1212
+ },
1213
+ __wbg_set_reason_18dc06ea0d60243b: function(A, I, g) {
1214
+ A.reason = y(I, g);
1215
+ },
1216
+ __wbg_set_search_f9700de567764208: function(A, I, g) {
1217
+ A.search = y(I, g);
1218
+ },
1219
+ __wbg_set_width_8e30d010cd66830d: function(A, I) {
1220
+ A.width = I >>> 0;
1221
+ },
1222
+ __wbg_stack_3b0d974bbf31e44f: function(A, I) {
1223
+ const g = I.stack, B = R(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = k;
1224
+ M().setInt32(A + 4, E, true), M().setInt32(A + 0, B, true);
1225
+ },
1226
+ __wbg_static_accessor_GLOBAL_4ef717fb391d88b7: function() {
1227
+ const A = typeof global > "u" ? null : global;
1228
+ return h(A) ? 0 : L(A);
1229
+ },
1230
+ __wbg_static_accessor_GLOBAL_THIS_8d1badc68b5a74f4: function() {
1231
+ const A = typeof globalThis > "u" ? null : globalThis;
1232
+ return h(A) ? 0 : L(A);
1233
+ },
1234
+ __wbg_static_accessor_SELF_146583524fe1469b: function() {
1235
+ const A = typeof self > "u" ? null : self;
1236
+ return h(A) ? 0 : L(A);
1237
+ },
1238
+ __wbg_static_accessor_WINDOW_f2829a2234d7819e: function() {
1239
+ const A = typeof window > "u" ? null : window;
1240
+ return h(A) ? 0 : L(A);
1241
+ },
1242
+ __wbg_statusText_9f08c32741a99815: function(A, I) {
1243
+ const g = I.statusText, B = R(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = k;
1244
+ M().setInt32(A + 4, E, true), M().setInt32(A + 0, B, true);
1245
+ },
1246
+ __wbg_status_c45b3b9b3033184a: function(A) {
1247
+ return A.status;
1248
+ },
1249
+ __wbg_then_16d107c451e9905d: function(A, I, g) {
1250
+ return A.then(I, g);
1251
+ },
1252
+ __wbg_then_6ec10ae38b3e92f7: function(A, I) {
1253
+ return A.then(I);
1254
+ },
1255
+ __wbg_toString_b201c2690bbe445a: function(A) {
1256
+ return A.toString();
1257
+ },
1258
+ __wbg_toString_bac9199ff382784d: function(A) {
1259
+ return A.toString();
1260
+ },
1261
+ __wbg_url_f6cd241d61f89b82: function(A, I) {
1262
+ const g = I.url, B = R(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = k;
1263
+ M().setInt32(A + 4, E, true), M().setInt32(A + 0, B, true);
1264
+ },
1265
+ __wbg_userAgent_0558f0ac642f7771: function() {
1266
+ return o(function(A, I) {
1267
+ const g = I.userAgent, B = R(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = k;
1268
+ M().setInt32(A + 4, E, true), M().setInt32(A + 0, B, true);
1269
+ }, arguments);
1270
+ },
1271
+ __wbg_warn_b1370d804fa3e259: function(A) {
1272
+ console.warn(A);
1273
+ },
1274
+ __wbg_wasClean_3c7aa2335da09e74: function(A) {
1275
+ return A.wasClean;
1276
+ },
1277
+ __wbg_width_6d9315ecc7140ff6: function(A) {
1278
+ return A.width;
1279
+ },
1280
+ __wbindgen_cast_0000000000000001: function(A, I) {
1281
+ return S(A, I, LA);
1282
+ },
1283
+ __wbindgen_cast_0000000000000002: function(A, I) {
1284
+ return S(A, I, aA);
1285
+ },
1286
+ __wbindgen_cast_0000000000000003: function(A, I) {
1287
+ return S(A, I, HA);
1288
+ },
1289
+ __wbindgen_cast_0000000000000004: function(A, I) {
1290
+ return S(A, I, SA);
1291
+ },
1292
+ __wbindgen_cast_0000000000000005: function(A, I) {
1293
+ return S(A, I, qA);
1294
+ },
1295
+ __wbindgen_cast_0000000000000006: function(A, I) {
1296
+ return S(A, I, KA);
1297
+ },
1298
+ __wbindgen_cast_0000000000000007: function(A, I) {
1299
+ return S(A, I, hA);
1300
+ },
1301
+ __wbindgen_cast_0000000000000008: function(A) {
1302
+ return A;
1303
+ },
1304
+ __wbindgen_cast_0000000000000009: function(A, I) {
1305
+ return y(A, I);
1306
+ },
1307
+ __wbindgen_init_externref_table: function() {
1308
+ const A = C.__wbindgen_externrefs, I = A.grow(4);
1309
+ A.set(0, void 0), A.set(I + 0, void 0), A.set(I + 1, null), A.set(I + 2, true), A.set(I + 3, false);
1310
+ }
1311
+ }
1312
+ };
1313
+ }
1314
+ function KA(Q, A) {
1315
+ C.wasm_bindgen__convert__closures_____invoke__h38edb88495230029(Q, A);
1316
+ }
1317
+ function hA(Q, A) {
1318
+ C.wasm_bindgen__convert__closures_____invoke__h59fff34e32ed8cec(Q, A);
1319
+ }
1320
+ function aA(Q, A, I) {
1321
+ C.wasm_bindgen__convert__closures_____invoke__h64a57be2ca3e0d69(Q, A, I);
1322
+ }
1323
+ function HA(Q, A, I) {
1324
+ C.wasm_bindgen__convert__closures_____invoke__h64a57be2ca3e0d69_2(Q, A, I);
1325
+ }
1326
+ function SA(Q, A, I) {
1327
+ C.wasm_bindgen__convert__closures_____invoke__h64a57be2ca3e0d69_3(Q, A, I);
1328
+ }
1329
+ function LA(Q, A, I) {
1330
+ const g = C.wasm_bindgen__convert__closures_____invoke__hfbb046a5343bcac9(Q, A, I);
1331
+ if (g[1])
1332
+ throw q(g[0]);
1333
+ }
1334
+ function sA(Q, A, I, g) {
1335
+ C.wasm_bindgen__convert__closures_____invoke__h4cc111f3c9bb2945(Q, A, I, g);
1336
+ }
1337
+ function qA(Q, A, I, g, B) {
1338
+ C.wasm_bindgen__convert__closures_____invoke__h777de2c1fe9da8ab(Q, A, I, g, B);
1339
+ }
1340
+ const ZA = ["blob", "arraybuffer"], u = typeof FinalizationRegistry > "u" ? { register: () => {
1341
+ }, unregister: () => {
1342
+ } } : new FinalizationRegistry((Q) => C.__wbg_clipboarddata_free(Q, 1)), CA = typeof FinalizationRegistry > "u" ? { register: () => {
1343
+ }, unregister: () => {
1344
+ } } : new FinalizationRegistry((Q) => C.__wbg_clipboarditem_free(Q, 1)), _ = typeof FinalizationRegistry > "u" ? { register: () => {
1345
+ }, unregister: () => {
1346
+ } } : new FinalizationRegistry((Q) => C.__wbg_desktopsize_free(Q, 1)), EA = typeof FinalizationRegistry > "u" ? { register: () => {
1347
+ }, unregister: () => {
1348
+ } } : new FinalizationRegistry((Q) => C.__wbg_deviceevent_free(Q, 1)), DA = typeof FinalizationRegistry > "u" ? { register: () => {
1349
+ }, unregister: () => {
1350
+ } } : new FinalizationRegistry((Q) => C.__wbg_extension_free(Q, 1)), iA = typeof FinalizationRegistry > "u" ? { register: () => {
1351
+ }, unregister: () => {
1352
+ } } : new FinalizationRegistry((Q) => C.__wbg_inputtransaction_free(Q, 1)), wA = typeof FinalizationRegistry > "u" ? { register: () => {
1353
+ }, unregister: () => {
1354
+ } } : new FinalizationRegistry((Q) => C.__wbg_ironerror_free(Q, 1)), GA = typeof FinalizationRegistry > "u" ? { register: () => {
1355
+ }, unregister: () => {
1356
+ } } : new FinalizationRegistry((Q) => C.__wbg_rdcleanpathdetails_free(Q, 1)), oA = typeof FinalizationRegistry > "u" ? { register: () => {
1357
+ }, unregister: () => {
1358
+ } } : new FinalizationRegistry((Q) => C.__wbg_rdpfile_free(Q, 1)), NA = typeof FinalizationRegistry > "u" ? { register: () => {
1359
+ }, unregister: () => {
1360
+ } } : new FinalizationRegistry((Q) => C.__wbg_session_free(Q, 1)), $ = typeof FinalizationRegistry > "u" ? { register: () => {
1361
+ }, unregister: () => {
1362
+ } } : new FinalizationRegistry((Q) => C.__wbg_sessionbuilder_free(Q, 1)), kA = typeof FinalizationRegistry > "u" ? { register: () => {
1363
+ }, unregister: () => {
1364
+ } } : new FinalizationRegistry((Q) => C.__wbg_sessionterminationinfo_free(Q, 1));
1365
+ function L(Q) {
1366
+ const A = C.__externref_table_alloc();
1367
+ return C.__wbindgen_externrefs.set(A, Q), A;
1368
+ }
1369
+ function FA(Q) {
1370
+ if (typeof Q == "number" && (Q >= 1114112 || Q >= 55296 && Q < 57344)) throw new Error(`expected a valid Unicode scalar value, found ${Q}`);
1371
+ }
1372
+ function V(Q, A) {
1373
+ if (!(Q instanceof A))
1374
+ throw new Error(`expected instance of ${A.name}`);
1375
+ }
1376
+ const RA = typeof FinalizationRegistry > "u" ? { register: () => {
1377
+ }, unregister: () => {
1378
+ } } : new FinalizationRegistry((Q) => C.__wbindgen_destroy_closure(Q.a, Q.b));
1379
+ function gA(Q) {
1380
+ const A = typeof Q;
1381
+ if (A == "number" || A == "boolean" || Q == null)
1382
+ return `${Q}`;
1383
+ if (A == "string")
1384
+ return `"${Q}"`;
1385
+ if (A == "symbol") {
1386
+ const B = Q.description;
1387
+ return B == null ? "Symbol" : `Symbol(${B})`;
1388
+ }
1389
+ if (A == "function") {
1390
+ const B = Q.name;
1391
+ return typeof B == "string" && B.length > 0 ? `Function(${B})` : "Function";
1392
+ }
1393
+ if (Array.isArray(Q)) {
1394
+ const B = Q.length;
1395
+ let E = "[";
1396
+ B > 0 && (E += gA(Q[0]));
1397
+ for (let D = 1; D < B; D++)
1398
+ E += ", " + gA(Q[D]);
1399
+ return E += "]", E;
1400
+ }
1401
+ const I = /\[object ([^\]]+)\]/.exec(toString.call(Q));
1402
+ let g;
1403
+ if (I && I.length > 1)
1404
+ g = I[1];
1405
+ else
1406
+ return toString.call(Q);
1407
+ if (g == "Object")
1408
+ try {
1409
+ return "Object(" + JSON.stringify(Q) + ")";
1410
+ } catch {
1411
+ return "Object";
1412
+ }
1413
+ return Q instanceof Error ? `${Q.name}: ${Q.message}
1414
+ ${Q.stack}` : g;
1415
+ }
1416
+ function pA(Q, A) {
1417
+ Q = Q >>> 0;
1418
+ const I = M(), g = [];
1419
+ for (let B = Q; B < Q + 4 * A; B += 4)
1420
+ g.push(C.__wbindgen_externrefs.get(I.getUint32(B, true)));
1421
+ return C.__externref_drop_slice(Q, A), g;
1422
+ }
1423
+ function dA(Q, A) {
1424
+ return Q = Q >>> 0, WA().subarray(Q / 4, Q / 4 + A);
1425
+ }
1426
+ function t(Q, A) {
1427
+ return Q = Q >>> 0, W().subarray(Q / 1, Q / 1 + A);
1428
+ }
1429
+ function VA(Q, A) {
1430
+ return Q = Q >>> 0, xA().subarray(Q / 1, Q / 1 + A);
1431
+ }
1432
+ let s = null;
1433
+ function M() {
1434
+ return (s === null || s.buffer.detached === true || s.buffer.detached === void 0 && s.buffer !== C.memory.buffer) && (s = new DataView(C.memory.buffer)), s;
1435
+ }
1436
+ function y(Q, A) {
1437
+ return jA(Q >>> 0, A);
1438
+ }
1439
+ let b = null;
1440
+ function WA() {
1441
+ return (b === null || b.byteLength === 0) && (b = new Uint32Array(C.memory.buffer)), b;
1442
+ }
1443
+ let m = null;
1444
+ function W() {
1445
+ return (m === null || m.byteLength === 0) && (m = new Uint8Array(C.memory.buffer)), m;
1446
+ }
1447
+ let O = null;
1448
+ function xA() {
1449
+ return (O === null || O.byteLength === 0) && (O = new Uint8ClampedArray(C.memory.buffer)), O;
1450
+ }
1451
+ function o(Q, A) {
1452
+ try {
1453
+ return Q.apply(this, A);
1454
+ } catch (I) {
1455
+ const g = L(I);
1456
+ C.__wbindgen_exn_store(g);
1457
+ }
1458
+ }
1459
+ function h(Q) {
1460
+ return Q == null;
1461
+ }
1462
+ function S(Q, A, I) {
1463
+ const g = { a: Q, b: A, cnt: 1 }, B = (...E) => {
1464
+ g.cnt++;
1465
+ const D = g.a;
1466
+ g.a = 0;
1467
+ try {
1468
+ return I(D, g.b, ...E);
1469
+ } finally {
1470
+ g.a = D, B._wbg_cb_unref();
1471
+ }
1472
+ };
1473
+ return B._wbg_cb_unref = () => {
1474
+ --g.cnt === 0 && (C.__wbindgen_destroy_closure(g.a, g.b), g.a = 0, RA.unregister(g));
1475
+ }, RA.register(B, g, g), B;
1476
+ }
1477
+ function lA(Q, A) {
1478
+ const I = A(Q.length * 1, 1) >>> 0;
1479
+ return W().set(Q, I / 1), k = Q.length, I;
1480
+ }
1481
+ function R(Q, A, I) {
1482
+ if (I === void 0) {
1483
+ const i = X.encode(Q), w = A(i.length, 1) >>> 0;
1484
+ return W().subarray(w, w + i.length).set(i), k = i.length, w;
1485
+ }
1486
+ let g = Q.length, B = A(g, 1) >>> 0;
1487
+ const E = W();
1488
+ let D = 0;
1489
+ for (; D < g; D++) {
1490
+ const i = Q.charCodeAt(D);
1491
+ if (i > 127) break;
1492
+ E[B + D] = i;
1493
+ }
1494
+ if (D !== g) {
1495
+ D !== 0 && (Q = Q.slice(D)), B = I(B, g, g = D + Q.length * 3, 1) >>> 0;
1496
+ const i = W().subarray(B + D, B + g), w = X.encodeInto(Q, i);
1497
+ D += w.written, B = I(B, g, D, 1) >>> 0;
1498
+ }
1499
+ return k = D, B;
1500
+ }
1501
+ function q(Q) {
1502
+ const A = C.__wbindgen_externrefs.get(Q);
1503
+ return C.__externref_table_dealloc(Q), A;
1504
+ }
1505
+ let z = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
1506
+ z.decode();
1507
+ const tA = 2146435072;
1508
+ let AA = 0;
1509
+ function jA(Q, A) {
1510
+ return AA += A, AA >= tA && (z = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }), z.decode(), AA = A), z.decode(W().subarray(Q, Q + A));
1511
+ }
1512
+ const X = new TextEncoder();
1513
+ "encodeInto" in X || (X.encodeInto = function(Q, A) {
1514
+ const I = X.encode(Q);
1515
+ return A.set(I), {
1516
+ read: Q.length,
1517
+ written: I.length
1518
+ };
1519
+ });
1520
+ let k = 0, C;
1521
+ function bA(Q, A) {
1522
+ return C = __trdWatchExports(Q.exports), s = null, b = null, m = null, O = null, C.__wbindgen_start(), C;
1523
+ }
1524
+ async function mA(Q, A) {
1525
+ if (typeof Response == "function" && Q instanceof Response) {
1526
+ if (typeof WebAssembly.instantiateStreaming == "function")
1527
+ try {
1528
+ return await WebAssembly.instantiateStreaming(Q, A);
1529
+ } catch (B) {
1530
+ if (Q.ok && I(Q.type) && Q.headers.get("Content-Type") !== "application/wasm")
1531
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", B);
1532
+ else
1533
+ throw B;
1534
+ }
1535
+ const g = await Q.arrayBuffer();
1536
+ return await WebAssembly.instantiate(g, A);
1537
+ } else {
1538
+ const g = await WebAssembly.instantiate(Q, A);
1539
+ return g instanceof WebAssembly.Instance ? { instance: g, module: Q } : g;
1540
+ }
1541
+ function I(g) {
1542
+ switch (g) {
1543
+ case "basic":
1544
+ case "cors":
1545
+ case "default":
1546
+ return true;
1547
+ }
1548
+ return false;
1549
+ }
1550
+ }
1551
+ async function OA(Q) {
1552
+ if (C !== void 0) return C;
1553
+ Q !== void 0 && (Object.getPrototypeOf(Q) === Object.prototype ? { module_or_path: Q } = Q : console.warn("using deprecated parameters for the initialization function; pass a single object instead")), Q === void 0 && (Q = new URL("ironrdp_web_bg.wasm", import.meta.url));
1554
+ const A = UA();
1555
+ (typeof Q == "string" || typeof Request == "function" && Q instanceof Request || typeof URL == "function" && Q instanceof URL) && (Q = fetch(Q));
1556
+ const { instance: I, module: g } = await mA(await Q, A);
1557
+ return bA(I);
1558
+ }
1559
+ const XA = "avc1.640033";
1560
+ function MA() {
1561
+ return {
1562
+ codec: XA,
1563
+ optimizeForLatency: true,
1564
+ hardwareAcceleration: "no-preference",
1565
+ colorSpace: { primaries: "bt709", transfer: "bt709", matrix: "bt709", fullRange: true }
1566
+ };
1567
+ }
1568
+ async function BI() {
1569
+ if (typeof VideoDecoder > "u" || typeof EncodedVideoChunk > "u")
1570
+ return false;
1571
+ try {
1572
+ return (await VideoDecoder.isConfigSupported(MA())).supported === true;
1573
+ } catch {
1574
+ return false;
1575
+ }
1576
+ }
1577
+ const _cA = class _cA {
1578
+ constructor(A = {}) {
1579
+ __publicField(this, "stats", {
1580
+ frames: 0,
1581
+ keyFrames: 0,
1582
+ auxiliary: 0,
1583
+ skipped: 0,
1584
+ dropped: 0,
1585
+ pending: 0,
1586
+ lastLatencyMs: 0,
1587
+ maxLatencyMs: 0,
1588
+ readback: "copyTo"
1589
+ });
1590
+ /** Why the decoder failed, once it has. */
1591
+ __publicField(this, "failed", null);
1592
+ /**
1593
+ * The failure was the browser taking an idle decoder back (WebCodecs codec reclamation, in a hidden page with
1594
+ * many decoders around), not a decoding problem: a new session can use H.264 again.
1595
+ */
1596
+ __publicField(this, "reclaimed", false);
1597
+ __publicField(this, "surfaces", /* @__PURE__ */ new Map());
1598
+ __publicField(this, "stallMs");
1599
+ __publicField(this, "now");
1600
+ __publicField(this, "watchdog", null);
1601
+ __publicField(this, "canvas", null);
1602
+ __publicField(this, "closed", false);
1603
+ this.options = A, this.stallMs = A.stallMs ?? 3e3, this.now = A.now ?? (() => performance.now());
1604
+ }
1605
+ decode(A, I) {
1606
+ if (this.failed !== null || this.closed) {
1607
+ I(A.id, null, this.failed ?? "the H.264 decoder is closed");
1608
+ return;
1609
+ }
1610
+ this.watchdog ?? (this.watchdog = setInterval(() => this.checkStalls(), Math.min(250, this.stallMs)));
1611
+ const g = this.surfaces.get(A.surfaceId) ?? this.open(A.surfaceId);
1612
+ if (g.needKey && !A.keyFrame) {
1613
+ this.stats.skipped++, g.waitingSince === null && (g.waitingSince = this.now()), I(A.id, null);
1614
+ return;
1615
+ }
1616
+ g.needKey = false, g.waitingSince = null, A.keyFrame && this.stats.keyFrames++, g.pending.set(A.id, { frame: A, done: I, since: this.now() }), this.stats.pending++;
1617
+ try {
1618
+ g.decoder.decode(
1619
+ new EncodedVideoChunk({
1620
+ type: A.keyFrame ? "key" : "delta",
1621
+ timestamp: A.id,
1622
+ data: A.data
1623
+ })
1624
+ );
1625
+ } catch (B) {
1626
+ this.fail(`decode: ${IA(B)}`);
1627
+ }
1628
+ }
1629
+ close() {
1630
+ this.closed = true, this.stopWatchdog();
1631
+ for (const A of this.surfaces.values())
1632
+ yA(A.decoder);
1633
+ this.surfaces.clear(), this.stats.pending = 0;
1634
+ }
1635
+ open(A) {
1636
+ const I = {
1637
+ decoder: new VideoDecoder({
1638
+ output: (g) => this.output(I, g),
1639
+ error: (g) => {
1640
+ this.reclaimed = g.name === "QuotaExceededError", this.fail(IA(g));
1641
+ }
1642
+ }),
1643
+ needKey: true,
1644
+ waitingSince: null,
1645
+ pending: /* @__PURE__ */ new Map()
1646
+ };
1647
+ return I.decoder.configure(MA()), this.surfaces.set(A, I), I;
1648
+ }
1649
+ output(A, I) {
1650
+ const g = I.timestamp, B = A.pending.get(g);
1651
+ if (B === void 0 || this.failed !== null || this.closed) {
1652
+ I.close();
1653
+ return;
1654
+ }
1655
+ for (const [E, D] of A.pending) {
1656
+ if (E >= g)
1657
+ break;
1658
+ A.pending.delete(E), this.stats.pending--, this.stats.dropped++, D.done(E, null);
1659
+ }
1660
+ A.pending.delete(g), this.stats.pending--, this.readRegions(I, B.frame).then(
1661
+ (E) => {
1662
+ if (I.close(), this.failed !== null || this.closed)
1663
+ return;
1664
+ const D = this.now() - B.since;
1665
+ this.stats.frames++, B.frame.regions.length === 0 && this.stats.auxiliary++, this.stats.lastLatencyMs = D, this.stats.maxLatencyMs = Math.max(this.stats.maxLatencyMs, D), B.done(g, E);
1666
+ },
1667
+ (E) => {
1668
+ I.close(), this.fail(`reading the picture: ${IA(E)}`), B.done(g, null, this.failed ?? void 0);
1669
+ }
1670
+ );
1671
+ }
1672
+ /** The RGBA of the frame's regions, in turn. */
1673
+ async readRegions(A, I) {
1674
+ const g = A.visibleRect ?? { x: 0, y: 0, width: A.codedWidth, height: A.codedHeight }, B = I.destination, [E, D] = g.width >= B.right && g.height >= B.bottom ? [0, 0] : [B.left, B.top], i = I.regions.map((G) => ({
1675
+ x: G.left - E,
1676
+ y: G.top - D,
1677
+ width: G.right - G.left,
1678
+ height: G.bottom - G.top
1679
+ }));
1680
+ for (const G of i)
1681
+ if (G.x < 0 || G.y < 0 || G.x + G.width > g.width || G.y + G.height > g.height)
1682
+ throw new Error(
1683
+ `region ${JSON.stringify(G)} is outside the ${g.width}x${g.height} picture`
1684
+ );
1685
+ const w = i.reduce((G, H) => G + H.width * H.height * 4, 0), F = new Uint8Array(w);
1686
+ if (i.length === 0)
1687
+ return F;
1688
+ const a = Math.min(...i.map((G) => G.x)), J = Math.min(...i.map((G) => G.y)), Y = {
1689
+ x: a,
1690
+ y: J,
1691
+ width: Math.max(...i.map((G) => G.x + G.width)) - a,
1692
+ height: Math.max(...i.map((G) => G.y + G.height)) - J
1693
+ };
1694
+ if (i.length === 1)
1695
+ return await this.readBox(A, g, Y, F), F;
1696
+ if (Y.width * Y.height * 4 > w * _cA.BOX_WASTE) {
1697
+ let G = 0;
1698
+ for (const H of i) {
1699
+ const d = H.width * H.height * 4;
1700
+ await this.readBox(A, g, H, F.subarray(G, G + d)), G += d;
1701
+ }
1702
+ return F;
1703
+ }
1704
+ const l = new Uint8Array(Y.width * Y.height * 4);
1705
+ await this.readBox(A, g, Y, l);
1706
+ let v = 0;
1707
+ for (const G of i) {
1708
+ const H = G.width * 4;
1709
+ for (let d = 0; d < G.height; d++) {
1710
+ const BA = ((G.y - Y.y + d) * Y.width + (G.x - Y.x)) * 4;
1711
+ F.set(l.subarray(BA, BA + H), v), v += H;
1712
+ }
1713
+ }
1714
+ return F;
1715
+ }
1716
+ async readBox(A, I, g, B) {
1717
+ var _a, _b;
1718
+ if (this.stats.readback === "copyTo") {
1719
+ const D = { x: I.x + g.x, y: I.y + g.y, width: g.width, height: g.height };
1720
+ try {
1721
+ if (A.allocationSize({ rect: D, format: "RGBA" }) === g.width * g.height * 4) {
1722
+ await A.copyTo(B, { rect: D, format: "RGBA", colorSpace: "srgb" });
1723
+ return;
1724
+ }
1725
+ this.stats.readback = "canvas";
1726
+ } catch (i) {
1727
+ if (!(i instanceof DOMException && i.name === "NotSupportedError") && !(i instanceof TypeError))
1728
+ throw i;
1729
+ this.stats.readback = "canvas";
1730
+ }
1731
+ }
1732
+ (this.canvas === null || this.canvas.width < g.width || this.canvas.height < g.height) && (this.canvas = new OffscreenCanvas(
1733
+ Math.max(g.width, ((_a = this.canvas) == null ? void 0 : _a.width) ?? 0),
1734
+ Math.max(g.height, ((_b = this.canvas) == null ? void 0 : _b.height) ?? 0)
1735
+ ));
1736
+ const E = this.canvas.getContext("2d", { willReadFrequently: true, colorSpace: "srgb" });
1737
+ if (E === null)
1738
+ throw new Error("no 2D canvas context");
1739
+ E.drawImage(A, -g.x, -g.y, I.width, I.height), B.set(E.getImageData(0, 0, g.width, g.height).data);
1740
+ }
1741
+ stopWatchdog() {
1742
+ this.watchdog !== null && (clearInterval(this.watchdog), this.watchdog = null);
1743
+ }
1744
+ checkStalls() {
1745
+ if (this.failed !== null || this.closed)
1746
+ return;
1747
+ const A = this.now();
1748
+ for (const I of this.surfaces.values()) {
1749
+ if (I.waitingSince !== null && A - I.waitingSince > this.stallMs) {
1750
+ this.fail(`no key frame for ${Math.round(A - I.waitingSince)} ms`);
1751
+ return;
1752
+ }
1753
+ for (const g of I.pending.values())
1754
+ if (A - g.since > this.stallMs) {
1755
+ this.fail(`no picture from the decoder for ${Math.round(A - g.since)} ms`);
1756
+ return;
1757
+ }
1758
+ }
1759
+ }
1760
+ /** Fails for good: every frame in flight completes with the error, which ends the session. */
1761
+ fail(A) {
1762
+ var _a, _b;
1763
+ if (this.failed !== null || this.closed)
1764
+ return;
1765
+ this.failed = A, this.stopWatchdog();
1766
+ const I = [...this.surfaces.values()].flatMap((g) => [...g.pending.values()]);
1767
+ for (const g of this.surfaces.values())
1768
+ yA(g.decoder);
1769
+ this.surfaces.clear(), this.stats.pending = 0, (_b = (_a = this.options).onFailure) == null ? void 0 : _b.call(_a, A);
1770
+ for (const { frame: g, done: B } of I)
1771
+ B(g.id, null, A);
1772
+ }
1773
+ };
1774
+ /** A bounding box may be this many times what its regions hold before they are read one by one instead. */
1775
+ __publicField(_cA, "BOX_WASTE", 2);
1776
+ let cA = _cA;
1777
+ function yA(Q) {
1778
+ if (Q.state !== "closed")
1779
+ try {
1780
+ Q.close();
1781
+ } catch {
1782
+ }
1783
+ }
1784
+ function IA(Q) {
1785
+ return Q instanceof Error || Q instanceof DOMException ? `${Q.name}: ${Q.message}` : String(Q);
1786
+ }
1787
+ const j = {
1788
+ /**
1789
+ * Request file size (8-byte unsigned integer).
1790
+ * When set: position must be 0, size must be 8.
1791
+ */
1792
+ SIZE: 1,
1793
+ /**
1794
+ * Request byte range from file.
1795
+ * When set: position and size define the requested range.
1796
+ */
1797
+ RANGE: 2
1798
+ };
1799
+ function fA(Q) {
1800
+ return new N("files_available_callback", Q);
1801
+ }
1802
+ function TA(Q) {
1803
+ return new N("file_contents_request_callback", Q);
1804
+ }
1805
+ function nA(Q) {
1806
+ return new N("file_contents_response_callback", Q);
1807
+ }
1808
+ function rA(Q) {
1809
+ return new N("lock_callback", Q);
1810
+ }
1811
+ function PA(Q) {
1812
+ return new N("unlock_callback", Q);
1813
+ }
1814
+ function vA(Q) {
1815
+ return new N("locks_expired_callback", Q);
1816
+ }
1817
+ function zA(Q) {
1818
+ return new N("format_list_response_callback", Q);
1819
+ }
1820
+ const QI = {
1821
+ PostScript: "MS Publisher Imagesetter",
1822
+ MicrosoftPrintToPdf: "Microsoft Print to PDF"
1823
+ };
1824
+ function CI(Q) {
1825
+ return new N("print_job_stream_callbacks", Q);
1826
+ }
1827
+ function EI(Q) {
1828
+ return new N("printer_name", Q);
1829
+ }
1830
+ function DI(Q) {
1831
+ return new N("printer_device_id", Q);
1832
+ }
1833
+ function iI(Q) {
1834
+ return new N("printer_driver_name", Q);
1835
+ }
1836
+ function eA(Q) {
1837
+ return new N("request_file_contents", Q);
1838
+ }
1839
+ function uA(Q) {
1840
+ return new N("submit_file_contents", Q);
1841
+ }
1842
+ function _A(Q) {
1843
+ return new N("initiate_file_copy", Q);
1844
+ }
1845
+ class $A {
1846
+ constructor() {
1847
+ __publicField(this, "chunks", []);
1848
+ __publicField(this, "_bytesWritten", 0);
1849
+ __publicField(this, "finalized", false);
1850
+ }
1851
+ get bytesWritten() {
1852
+ return this._bytesWritten;
1853
+ }
1854
+ async write(A) {
1855
+ if (this.finalized)
1856
+ throw new Error("BlobWriteHandle: write after finalize/abort");
1857
+ this.chunks.push(A), this._bytesWritten += A.length;
1858
+ }
1859
+ async finalize() {
1860
+ if (this.finalized)
1861
+ throw new Error("BlobWriteHandle: already finalized or aborted");
1862
+ this.finalized = true;
1863
+ const A = new Blob(this.chunks);
1864
+ return this.chunks = [], A;
1865
+ }
1866
+ async abort() {
1867
+ this.finalized || (this.finalized = true, this.chunks = []);
1868
+ }
1869
+ }
1870
+ class YA {
1871
+ constructor() {
1872
+ __publicField(this, "name", "blob");
1873
+ }
1874
+ async createWriteHandle(A, I) {
1875
+ return new $A();
1876
+ }
1877
+ async dispose() {
1878
+ }
1879
+ }
1880
+ class AI {
1881
+ constructor(A, I, g, B) {
1882
+ __publicField(this, "writable");
1883
+ __publicField(this, "_bytesWritten", 0);
1884
+ __publicField(this, "finalized", false);
1885
+ this.fileHandle = A, this.sessionDir = I, this.entryName = g, this.writable = B;
1886
+ }
1887
+ get bytesWritten() {
1888
+ return this._bytesWritten;
1889
+ }
1890
+ async write(A) {
1891
+ if (this.finalized || !this.writable)
1892
+ throw new Error("OpfsWriteHandle: write after finalize/abort");
1893
+ await this.writable.write(A), this._bytesWritten += A.length;
1894
+ }
1895
+ async finalize() {
1896
+ if (this.finalized)
1897
+ throw new Error("OpfsWriteHandle: already finalized or aborted");
1898
+ return this.finalized = true, this.writable && (await this.writable.close(), this.writable = void 0), this.fileHandle.getFile();
1899
+ }
1900
+ async abort() {
1901
+ if (!this.finalized) {
1902
+ if (this.finalized = true, this.writable) {
1903
+ try {
1904
+ await this.writable.abort();
1905
+ } catch {
1906
+ }
1907
+ this.writable = void 0;
1908
+ }
1909
+ try {
1910
+ await this.sessionDir.removeEntry(this.entryName);
1911
+ } catch {
1912
+ }
1913
+ }
1914
+ }
1915
+ }
1916
+ const _x = class _x {
1917
+ constructor(A, I, g) {
1918
+ __publicField(this, "name", "opfs");
1919
+ /** Sequence counter for generating unique temp file names. */
1920
+ __publicField(this, "sequence", 0);
1921
+ this.opfsRoot = A, this.sessionDir = I, this.sessionId = g;
1922
+ }
1923
+ /**
1924
+ * Create an OPFS backend, including the per-session directory.
1925
+ *
1926
+ * Call {@link probe} first to verify OPFS is available before
1927
+ * constructing -- this factory assumes OPFS works.
1928
+ */
1929
+ static async create(A, I) {
1930
+ const g = I ?? `s-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`, B = await A.getDirectoryHandle("ironrdp-transfers", { create: true }), E = await B.getDirectoryHandle(g, { create: true });
1931
+ return _x.cleanupStale(B, g), new _x(A, E, g);
1932
+ }
1933
+ // 24 hours
1934
+ /**
1935
+ * Remove session directories older than {@link STALE_SESSION_THRESHOLD_MS}.
1936
+ *
1937
+ * Session IDs generated by {@link create} embed a timestamp in the
1938
+ * format `s-{Date.now()}-{random}`. This method parses that timestamp
1939
+ * to determine age. Directories with unparsable names or those
1940
+ * belonging to the current session are skipped.
1941
+ */
1942
+ static async cleanupStale(A, I) {
1943
+ const g = Date.now();
1944
+ try {
1945
+ for await (const B of A.keys()) {
1946
+ if (B === I)
1947
+ continue;
1948
+ const E = /^s-(\d+)-/.exec(B);
1949
+ if (!E)
1950
+ continue;
1951
+ const D = Number(E[1]);
1952
+ if (g - D > _x.STALE_SESSION_THRESHOLD_MS)
1953
+ try {
1954
+ await A.removeEntry(B, { recursive: true });
1955
+ } catch {
1956
+ }
1957
+ }
1958
+ } catch {
1959
+ }
1960
+ }
1961
+ /**
1962
+ * Probe whether OPFS is usable in the current context.
1963
+ *
1964
+ * Performs a full round-trip: creates a temp file, opens a writable,
1965
+ * closes it, and deletes it. This catches environments where the API
1966
+ * exists but throws at runtime (e.g., some private browsing modes).
1967
+ */
1968
+ static async probe(A) {
1969
+ try {
1970
+ return await (await (await A.getFileHandle(".ironrdp-opfs-probe", { create: true })).createWritable()).close(), await A.removeEntry(".ironrdp-opfs-probe"), true;
1971
+ } catch {
1972
+ return false;
1973
+ }
1974
+ }
1975
+ async createWriteHandle(A, I) {
1976
+ if (!this.sessionDir)
1977
+ throw new Error("OpfsStorageBackend: backend has been disposed");
1978
+ const B = `${this.sequence++}-${II(A)}`, E = await this.sessionDir.getFileHandle(B, { create: true }), D = await E.createWritable();
1979
+ return new AI(E, this.sessionDir, B, D);
1980
+ }
1981
+ async dispose() {
1982
+ if (!this.sessionDir)
1983
+ return;
1984
+ const A = this.sessionDir;
1985
+ this.sessionDir = void 0;
1986
+ try {
1987
+ const I = await this.opfsRoot.getDirectoryHandle("ironrdp-transfers");
1988
+ await I.removeEntry(this.sessionId, { recursive: true });
1989
+ let g = false;
1990
+ for await (const B of I.values()) {
1991
+ g = true;
1992
+ break;
1993
+ }
1994
+ g || await this.opfsRoot.removeEntry("ironrdp-transfers");
1995
+ } catch (I) {
1996
+ console.debug("OPFS session directory removal failed, falling back to per-file cleanup:", I);
1997
+ try {
1998
+ for await (const g of A.keys())
1999
+ try {
2000
+ await A.removeEntry(g);
2001
+ } catch {
2002
+ }
2003
+ } catch {
2004
+ }
2005
+ }
2006
+ }
2007
+ };
2008
+ /** Maximum age (in milliseconds) before a session directory is considered stale. */
2009
+ __publicField(_x, "STALE_SESSION_THRESHOLD_MS", 1440 * 60 * 1e3);
2010
+ let x = _x;
2011
+ function II(Q) {
2012
+ let A = Q.replace(/[\u0000-\u001f]/g, "");
2013
+ A = A.replace(/[/\\]/g, "_"), A = A.replace(/^\.+/, ""), A.length === 0 && (A = "unnamed");
2014
+ const I = new TextEncoder();
2015
+ if (I.encode(A).byteLength > 200) {
2016
+ for (; I.encode(A).byteLength > 200; )
2017
+ A = A.slice(0, -1);
2018
+ A.length === 0 && (A = "unnamed");
2019
+ }
2020
+ return A;
2021
+ }
2022
+ async function gI(Q = "auto", A) {
2023
+ var _a, _b;
2024
+ if (Q === "blob")
2025
+ return new YA();
2026
+ if (typeof ((_b = (_a = globalThis.navigator) == null ? void 0 : _a.storage) == null ? void 0 : _b.getDirectory) == "function")
2027
+ try {
2028
+ const I = await navigator.storage.getDirectory();
2029
+ if (await x.probe(I))
2030
+ return x.create(I, A);
2031
+ console.debug("OPFS probe failed (createWritable not functional), falling back to blob storage");
2032
+ } catch (I) {
2033
+ console.debug("OPFS unavailable, falling back to blob storage:", I);
2034
+ }
2035
+ return new YA();
2036
+ }
2037
+ const _U = class _U {
2038
+ constructor(A) {
2039
+ __publicField(this, "session");
2040
+ __publicField(this, "chunkSize");
2041
+ __publicField(this, "onUploadStarted");
2042
+ __publicField(this, "onUploadFinished");
2043
+ __publicField(this, "storagePreference");
2044
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2045
+ __publicField(this, "eventHandlers", /* @__PURE__ */ new Map());
2046
+ __publicField(this, "storageBackend");
2047
+ __publicField(this, "storageBackendReady");
2048
+ __publicField(this, "activeDownloads", /* @__PURE__ */ new Map());
2049
+ __publicField(this, "uploadState");
2050
+ // Upload paste-window watchdog. Armed when we advertise an upload, disarmed on the
2051
+ // first FileContentsRequest (the remote pulled the files). Being armed is the single
2052
+ // "advertised but not yet pulled" signal: on timeout it resumes monitoring and fails
2053
+ // the never-pulled upload, and handleFormatListResponse consults it to fail a refused
2054
+ // paste early (handleUnlock is a deliberate no-op: Unlock is not a reliable failure
2055
+ // signal). Upload completion/failure run only after that first request, so they need
2056
+ // not touch it.
2057
+ __publicField(this, "pasteAckTimeout");
2058
+ // Upload inactivity watchdog. Armed/reset on each FileContentsRequest once the remote
2059
+ // starts pulling; fires if pulls stop for UPLOAD_INACTIVITY_TIMEOUT_MS (a stalled or
2060
+ // clipboard-superseded paste) to release uploadState. Complements the paste-ack
2061
+ // watchdog above, which only covers the "advertised but never pulled" case.
2062
+ __publicField(this, "uploadInactivityTimeout");
2063
+ // True between onUploadStarted (suppress monitoring) and onUploadFinished
2064
+ // (resume), so resume fires exactly once even though it is now deferred until
2065
+ // the paste is pulled, times out, fails, or the provider is disposed.
2066
+ __publicField(this, "uploadMonitoringSuppressed", false);
2067
+ // DroppedFile metadata retained after upload completes so re-paste works
2068
+ // without re-dropping. Cleared when a new upload starts or the manager is disposed.
2069
+ __publicField(this, "retainedFiles");
2070
+ __publicField(this, "availableFiles", []);
2071
+ // Clipboard lock ID received with the most recent file list. The Rust layer
2072
+ // acquires this lock automatically when FileGroupDescriptorW is detected in
2073
+ // the FormatList. Downloads use it instead of explicit lock/unlock calls -
2074
+ // the lock lifecycle is managed entirely by the Rust cliprdr processor.
2075
+ __publicField(this, "clipDataId");
2076
+ __publicField(this, "nextStreamId", 1);
2077
+ __publicField(this, "disposed", false);
2078
+ this.chunkSize = (A == null ? void 0 : A.chunkSize) ?? 65536, this.onUploadStarted = A == null ? void 0 : A.onUploadStarted, this.onUploadFinished = A == null ? void 0 : A.onUploadFinished;
2079
+ const I = A == null ? void 0 : A.storageBackend;
2080
+ if (typeof I == "object" && I !== null) {
2081
+ if (typeof I.createWriteHandle != "function" || typeof I.dispose != "function")
2082
+ throw new Error(
2083
+ "storageBackend: expected 'auto', 'blob', or a FileStorageBackend with createWriteHandle() and dispose() methods"
2084
+ );
2085
+ this.storageBackend = I, this.storagePreference = "auto";
2086
+ } else {
2087
+ const g = I ?? "auto";
2088
+ if (g !== "auto" && g !== "blob")
2089
+ throw new Error(
2090
+ `storageBackend: invalid preference '${g}', expected 'auto', 'blob', or a FileStorageBackend instance`
2091
+ );
2092
+ this.storagePreference = g;
2093
+ }
2094
+ }
2095
+ /**
2096
+ * Set the session instance after connection is established.
2097
+ * Called by the web component's connect() flow via the FileTransferProvider interface.
2098
+ */
2099
+ setSession(A) {
2100
+ this.session = A;
2101
+ }
2102
+ ensureSession() {
2103
+ if (this.session === void 0)
2104
+ throw new Error("RdpFileTransferProvider: Session not available. Ensure connect() has been called.");
2105
+ return this.session;
2106
+ }
2107
+ /**
2108
+ * Lazily initialize and return the storage backend.
2109
+ *
2110
+ * Detection is performed once and cached. Concurrent callers share
2111
+ * the same initialization promise so the probe only runs once.
2112
+ * If detection fails the cached promise is cleared so subsequent
2113
+ * downloads can retry.
2114
+ */
2115
+ async ensureStorageBackend() {
2116
+ return this.storageBackend ? this.storageBackend : (this.storageBackendReady || (this.storageBackendReady = gI(this.storagePreference).then((A) => (this.storageBackend = A, console.debug(`File transfer storage: ${A.name}`), A)).catch((A) => {
2117
+ throw this.storageBackendReady = void 0, A;
2118
+ })), this.storageBackendReady);
2119
+ }
2120
+ // --- Extension-based session method wrappers ---
2121
+ // These replace direct session.requestFileContents() etc. calls
2122
+ // with invokeExtension() to keep the Session interface protocol-agnostic.
2123
+ sendRequestFileContents(A, I, g, B, E, D) {
2124
+ this.ensureSession().invokeExtension(
2125
+ eA({
2126
+ stream_id: A,
2127
+ file_index: I,
2128
+ flags: g,
2129
+ position: B,
2130
+ size: E,
2131
+ clip_data_id: D
2132
+ })
2133
+ );
2134
+ }
2135
+ sendSubmitFileContents(A, I, g) {
2136
+ var _a;
2137
+ (_a = this.session) == null ? void 0 : _a.invokeExtension(uA({ stream_id: A, is_error: I, data: g }));
2138
+ }
2139
+ sendInitiateFileCopy(A) {
2140
+ this.ensureSession().invokeExtension(_A(A));
2141
+ }
2142
+ /**
2143
+ * Returns the extension objects to register on the SessionBuilder before connect().
2144
+ * Implements the FileTransferProvider interface.
2145
+ */
2146
+ getBuilderExtensions() {
2147
+ return [
2148
+ fA(
2149
+ (A, I) => this.handleFilesAvailable(A, I)
2150
+ ),
2151
+ TA((A) => this.handleFileContentsRequest(A)),
2152
+ nA((A) => this.handleFileContentsResponse(A)),
2153
+ rA((A) => this.handleLock(A)),
2154
+ PA((A) => this.handleUnlock(A)),
2155
+ vA((A) => this.handleLocksExpired(A)),
2156
+ zA((A) => this.handleFormatListResponse(A))
2157
+ ];
2158
+ }
2159
+ /**
2160
+ * Register an event handler.
2161
+ *
2162
+ * @param event - Event name
2163
+ * @param handler - Event handler function
2164
+ *
2165
+ * @example
2166
+ * ```typescript
2167
+ * manager.on('download-progress', (progress) => {
2168
+ * console.log(`${progress.fileName}: ${progress.percentage}%`);
2169
+ * });
2170
+ * ```
2171
+ */
2172
+ on(A, I) {
2173
+ this.eventHandlers.has(A) || this.eventHandlers.set(A, /* @__PURE__ */ new Set()), this.eventHandlers.get(A).add(I);
2174
+ }
2175
+ /**
2176
+ * Unregister an event handler.
2177
+ *
2178
+ * @param event - Event name
2179
+ * @param handler - Event handler function to remove
2180
+ */
2181
+ off(A, I) {
2182
+ const g = this.eventHandlers.get(A);
2183
+ g && g.delete(I);
2184
+ }
2185
+ /**
2186
+ * Emit an event to all registered handlers.
2187
+ */
2188
+ emit(A, ...I) {
2189
+ const g = this.eventHandlers.get(A);
2190
+ if (g)
2191
+ for (const B of g)
2192
+ try {
2193
+ B(...I);
2194
+ } catch (E) {
2195
+ console.error(`Error in ${A} handler:`, E);
2196
+ }
2197
+ }
2198
+ /**
2199
+ * Download a single file from the remote.
2200
+ *
2201
+ * Returns a {@link DownloadHandle} with a `transferId` available synchronously
2202
+ * (for immediate UI association) and a `completion` promise that resolves with
2203
+ * the downloaded blob.
2204
+ *
2205
+ * @param fileInfo - File metadata from 'files-available' event
2206
+ * @param fileIndex - Index of the file in the original file list
2207
+ * @returns Handle with synchronous transferId and async completion
2208
+ *
2209
+ * @example
2210
+ * ```typescript
2211
+ * const { transferId, completion } = manager.downloadFile(fileInfo, 0);
2212
+ * // transferId is available immediately for UI binding
2213
+ * const blob = await completion;
2214
+ * saveAs(blob, fileInfo.name);
2215
+ * ```
2216
+ */
2217
+ downloadFile(A, I) {
2218
+ const g = this.generateStreamId(), B = this.executeDownload(A, I, g);
2219
+ return { transferId: g, completion: B };
2220
+ }
2221
+ /**
2222
+ * Internal: execute the async download workflow for a single file.
2223
+ */
2224
+ async executeDownload(A, I, g) {
2225
+ const B = this.clipDataId, E = new Promise((D, i) => {
2226
+ const w = {
2227
+ fileInfo: A,
2228
+ fileIndex: I,
2229
+ streamId: g,
2230
+ clipDataId: B,
2231
+ bytesReceived: 0,
2232
+ resolve: D,
2233
+ reject: i
2234
+ };
2235
+ this.activeDownloads.set(g, w);
2236
+ });
2237
+ try {
2238
+ this.sendRequestFileContents(g, I, j.SIZE, 0, 8, B);
2239
+ } catch (D) {
2240
+ this.activeDownloads.delete(g);
2241
+ const i = {
2242
+ message: "Failed to request file size",
2243
+ transferId: g,
2244
+ fileIndex: I,
2245
+ fileName: A.name,
2246
+ direction: "download",
2247
+ cause: D
2248
+ };
2249
+ throw this.emit("error", i), new Error(i.message, { cause: D });
2250
+ }
2251
+ return E;
2252
+ }
2253
+ /**
2254
+ * Download multiple files sequentially.
2255
+ *
2256
+ * @param files - Array of FileInfo from 'files-available' event
2257
+ * @returns AsyncGenerator yielding file/blob pairs as they complete
2258
+ *
2259
+ * @example
2260
+ * ```typescript
2261
+ * for await (const { file, blob } of manager.downloadFiles(files)) {
2262
+ * saveAs(blob, file.name);
2263
+ * }
2264
+ * ```
2265
+ */
2266
+ async *downloadFiles(A) {
2267
+ for (let I = 0; I < A.length; I++) {
2268
+ const g = A[I], { transferId: B, completion: E } = this.downloadFile(g, I), D = await E;
2269
+ yield { file: g, blob: D, transferId: B };
2270
+ }
2271
+ }
2272
+ /**
2273
+ * Download multiple files concurrently with configurable parallelism.
2274
+ *
2275
+ * This method initiates multiple file downloads in parallel, improving
2276
+ * performance for multi-file transfers. Each file uses an independent
2277
+ * clipboard lock and stream ID.
2278
+ *
2279
+ * @param files - Array of FileInfo from 'files-available' event
2280
+ * @param options - Download options
2281
+ * @param options.maxConcurrent - Maximum concurrent downloads (default: 3)
2282
+ * @returns Promise resolving to map of fileIndex to Blob
2283
+ *
2284
+ * @example
2285
+ * ```typescript
2286
+ * const blobs = await manager.downloadFilesConcurrent(files, { maxConcurrent: 5 });
2287
+ * files.forEach((file, i) => saveAs(blobs.get(i)!, file.name));
2288
+ * ```
2289
+ */
2290
+ async downloadFilesConcurrent(A, I = {}) {
2291
+ const g = I.maxConcurrent ?? 3, B = /* @__PURE__ */ new Map(), E = [], D = A.map((w, F) => async () => {
2292
+ try {
2293
+ const { completion: a } = this.downloadFile(w, F), J = await a;
2294
+ B.set(F, J);
2295
+ } catch (a) {
2296
+ E.push({ index: F, error: a });
2297
+ }
2298
+ }), i = [];
2299
+ for (const w of D) {
2300
+ const F = w().finally(() => {
2301
+ i.splice(i.indexOf(F), 1);
2302
+ });
2303
+ i.push(F), i.length >= g && await Promise.race(i);
2304
+ }
2305
+ if (await Promise.all(i), E.length > 0)
2306
+ throw new Error(
2307
+ `Failed to download ${E.length} file(s): ` + E.map((w) => `file ${w.index}: ${w.error}`).join(", ")
2308
+ );
2309
+ return B;
2310
+ }
2311
+ /**
2312
+ * Upload files to the remote.
2313
+ *
2314
+ * Returns an {@link UploadHandle} with per-file `transferIds` available
2315
+ * synchronously (for immediate UI association) and a `completion` promise
2316
+ * that resolves when all files have been uploaded.
2317
+ *
2318
+ * @param files - Array of File objects to upload
2319
+ * @returns Handle with synchronous transferIds and async completion
2320
+ *
2321
+ * @example
2322
+ * ```typescript
2323
+ * const files = await manager.showFilePicker({ multiple: true });
2324
+ * const { transferIds, completion } = manager.uploadFiles(files);
2325
+ * // transferIds available immediately for UI binding
2326
+ * await completion;
2327
+ * ```
2328
+ */
2329
+ uploadFiles(A) {
2330
+ this.uploadState !== void 0 && this.supersedeUpload(), this.retainedFiles = void 0;
2331
+ const I = _U.normalizeToDroppedFiles(A), g = /* @__PURE__ */ new Map();
2332
+ for (let w = 0; w < I.length; w++)
2333
+ g.set(w, this.generateStreamId());
2334
+ const B = I.map((w) => ({
2335
+ name: w.name,
2336
+ size: w.size,
2337
+ lastModified: w.lastModified,
2338
+ path: w.path,
2339
+ isDirectory: w.isDirectory
2340
+ })), E = I.filter((w) => w.isDirectory !== true).length, D = I.map((w) => w.file), i = new Promise((w, F) => {
2341
+ this.uploadState = {
2342
+ files: D,
2343
+ droppedFiles: I,
2344
+ failedFiles: /* @__PURE__ */ new Set(),
2345
+ expectedFileCount: E,
2346
+ completedFiles: /* @__PURE__ */ new Set(),
2347
+ bytesServed: /* @__PURE__ */ new Map(),
2348
+ activeReaders: /* @__PURE__ */ new Map(),
2349
+ readerTimeouts: /* @__PURE__ */ new Map(),
2350
+ transferIds: g,
2351
+ resolve: w,
2352
+ reject: F
2353
+ }, this.suppressUploadMonitoring();
2354
+ try {
2355
+ this.sendInitiateFileCopy(B), this.emit("upload-batch-started", g, I);
2356
+ } catch (a) {
2357
+ this.uploadState = void 0, this.resumeUploadMonitoring();
2358
+ const J = {
2359
+ message: "Failed to initiate file upload",
2360
+ direction: "upload",
2361
+ cause: a
2362
+ };
2363
+ this.emit("error", J), F(new Error(J.message, { cause: a }));
2364
+ return;
2365
+ }
2366
+ this.armPasteAckWatchdog();
2367
+ });
2368
+ return { transferIds: g, completion: i };
2369
+ }
2370
+ /** Whether an upload batch is currently advertised or in flight (a fresh upload, or a re-paste
2371
+ * rebuilt from retained files). */
2372
+ isUploadInProgress() {
2373
+ return this.uploadState !== void 0;
2374
+ }
2375
+ /** Suppress clipboard monitoring for an upload's paste window. Idempotent: a supersede keeps
2376
+ * monitoring suppressed across the old->new upload, so this must not re-fire `onUploadStarted`. */
2377
+ suppressUploadMonitoring() {
2378
+ var _a;
2379
+ if (!this.uploadMonitoringSuppressed) {
2380
+ this.uploadMonitoringSuppressed = true;
2381
+ try {
2382
+ (_a = this.onUploadStarted) == null ? void 0 : _a.call(this);
2383
+ } catch (A) {
2384
+ console.error("Error in onUploadStarted callback:", A);
2385
+ }
2386
+ }
2387
+ }
2388
+ /** Resume clipboard monitoring (idempotent: fires onUploadFinished at most once
2389
+ * per upload, since the resume point is now deferred past the wire send). */
2390
+ resumeUploadMonitoring() {
2391
+ var _a;
2392
+ if (this.uploadMonitoringSuppressed) {
2393
+ this.uploadMonitoringSuppressed = false;
2394
+ try {
2395
+ (_a = this.onUploadFinished) == null ? void 0 : _a.call(this);
2396
+ } catch (A) {
2397
+ console.error("Error in onUploadFinished callback:", A);
2398
+ }
2399
+ }
2400
+ }
2401
+ /** Arm the paste-acknowledgment watchdog for the current upload. */
2402
+ armPasteAckWatchdog() {
2403
+ this.clearPasteAckWatchdog(), this.clearUploadInactivityWatchdog(), this.pasteAckTimeout = setTimeout(() => {
2404
+ this.pasteAckTimeout = void 0;
2405
+ const A = this.uploadState;
2406
+ A !== void 0 && A.isRePaste !== true ? this.failPendingUpload("The remote did not request the files in time, so the paste was not completed") : this.resumeUploadMonitoring();
2407
+ }, _U.PASTE_ACK_TIMEOUT_MS);
2408
+ }
2409
+ /** Disarm the paste-acknowledgment watchdog, if armed. */
2410
+ clearPasteAckWatchdog() {
2411
+ this.pasteAckTimeout !== void 0 && (clearTimeout(this.pasteAckTimeout), this.pasteAckTimeout = void 0);
2412
+ }
2413
+ /**
2414
+ * (Re)arm the upload inactivity watchdog (see {@link UPLOAD_INACTIVITY_TIMEOUT_MS}).
2415
+ * Called on every FileContentsRequest, so continued pulls keep resetting it and a
2416
+ * slow-but-progressing transfer is never killed; if pulls stop for the window the
2417
+ * upload is failed (releasing uploadState). Skipped for re-pastes, matching the
2418
+ * paste-ack watchdog.
2419
+ */
2420
+ resetUploadInactivityWatchdog() {
2421
+ this.clearUploadInactivityWatchdog(), this.uploadInactivityTimeout = setTimeout(() => {
2422
+ this.uploadInactivityTimeout = void 0;
2423
+ const A = this.uploadState;
2424
+ A !== void 0 && A.isRePaste !== true && this.failPendingUpload("The remote stopped requesting the files, so the paste did not complete");
2425
+ }, _U.UPLOAD_INACTIVITY_TIMEOUT_MS);
2426
+ }
2427
+ /** Disarm the upload inactivity watchdog, if armed. */
2428
+ clearUploadInactivityWatchdog() {
2429
+ this.uploadInactivityTimeout !== void 0 && (clearTimeout(this.uploadInactivityTimeout), this.uploadInactivityTimeout = void 0);
2430
+ }
2431
+ /**
2432
+ * The remote acknowledged the paste by requesting file contents: the clobber
2433
+ * window is over, so disarm the paste-ack watchdog and resume clipboard monitoring.
2434
+ * Called on every FileContentsRequest; only the first disarms/resumes. Every request
2435
+ * also (re)arms the inactivity watchdog so a stall after pulling began is recovered.
2436
+ */
2437
+ acknowledgePaste() {
2438
+ this.pasteAckTimeout !== void 0 && (this.clearPasteAckWatchdog(), this.resumeUploadMonitoring());
2439
+ const A = this.uploadState;
2440
+ if (A !== void 0 && A.isRePaste !== true && A.expectedFileCount === 0) {
2441
+ this.finishUploadBatch(A);
2442
+ return;
2443
+ }
2444
+ this.resetUploadInactivityWatchdog();
2445
+ }
2446
+ /**
2447
+ * Abort any in-flight chunk reads for a batch and clear their timeouts. Without this, a read
2448
+ * still running when the batch is torn down keeps its FileReader and a 60s reader-timeout
2449
+ * alive. Shared by every upload teardown path (fail, supersede, dispose).
2450
+ */
2451
+ abortInFlightReads(A) {
2452
+ for (const I of A.readerTimeouts.values())
2453
+ clearTimeout(I);
2454
+ A.readerTimeouts.clear();
2455
+ for (const I of A.activeReaders.values())
2456
+ I.abort();
2457
+ A.activeReaders.clear();
2458
+ }
2459
+ /**
2460
+ * Fail the in-flight upload (reject its completion, emit an upload error, clear
2461
+ * uploadState) and resume monitoring. Used when the advertise is rejected or the
2462
+ * paste is never pulled, so `uploadState` is released instead of lingering and
2463
+ * throwing "Upload already in progress" on every later upload.
2464
+ */
2465
+ failPendingUpload(A) {
2466
+ this.clearPasteAckWatchdog(), this.clearUploadInactivityWatchdog(), this.resumeUploadMonitoring();
2467
+ const I = this.uploadState;
2468
+ if (I === void 0)
2469
+ return;
2470
+ this.abortInFlightReads(I);
2471
+ const g = { message: A, direction: "upload" };
2472
+ this.emit("error", g);
2473
+ const { reject: B } = I;
2474
+ this.uploadState = void 0, B(new Error(A));
2475
+ }
2476
+ /**
2477
+ * Tear down the current upload because a new paste is replacing it. Unlike
2478
+ * {@link failPendingUpload}, this emits no error and leaves monitoring suppressed (a new upload
2479
+ * is starting); it aborts in-flight reads, clears the state, and *resolves* the old completion
2480
+ * (a replacement, not a failure).
2481
+ */
2482
+ supersedeUpload() {
2483
+ this.clearPasteAckWatchdog(), this.clearUploadInactivityWatchdog();
2484
+ const A = this.uploadState;
2485
+ if (A === void 0)
2486
+ return;
2487
+ this.abortInFlightReads(A);
2488
+ const { resolve: I } = A;
2489
+ this.uploadState = void 0, I();
2490
+ }
2491
+ /**
2492
+ * Finalize a fully-accounted upload batch (every counted file either served in full
2493
+ * or permanently failed). Stops the inactivity watchdog so it cannot linger past
2494
+ * completion, retains the DroppedFile metadata so a re-paste from the remote can serve
2495
+ * the data again, clears `uploadState`, and resolves the completion promise.
2496
+ */
2497
+ finishUploadBatch(A) {
2498
+ this.clearUploadInactivityWatchdog(), this.retainedFiles = A.droppedFiles, this.uploadState = void 0, A.resolve();
2499
+ }
2500
+ /**
2501
+ * Show a file picker dialog and return selected files.
2502
+ *
2503
+ * Note: This must be called in response to a user gesture (e.g., button click)
2504
+ * due to browser security restrictions.
2505
+ *
2506
+ * @param options - File picker options
2507
+ * @returns Promise resolving to selected File objects
2508
+ *
2509
+ * @example
2510
+ * ```typescript
2511
+ * button.onclick = async () => {
2512
+ * const files = await manager.showFilePicker({ multiple: true, accept: 'image/*' });
2513
+ * await manager.uploadFiles(files);
2514
+ * };
2515
+ * ```
2516
+ */
2517
+ showFilePicker(A) {
2518
+ return new Promise((I) => {
2519
+ const g = document.createElement("input");
2520
+ g.type = "file", g.style.display = "none", (A == null ? void 0 : A.multiple) === true && (g.multiple = true), (A == null ? void 0 : A.accept) !== void 0 && A.accept.length > 0 && (g.accept = A.accept), __trdListen(g, "change", () => {
2521
+ const i = Array.from(g.files || []);
2522
+ E(), __trdUnlisten(window, "focus", D), I(i);
2523
+ });
2524
+ let B = false;
2525
+ const E = () => {
2526
+ B || (B = true, g.parentNode && document.body.removeChild(g));
2527
+ };
2528
+ __trdListen(g, "cancel", () => {
2529
+ E(), __trdUnlisten(window, "focus", D), I([]);
2530
+ });
2531
+ const D = () => {
2532
+ setTimeout(() => {
2533
+ B || (E(), I([])), __trdUnlisten(window, "focus", D);
2534
+ }, 300);
2535
+ };
2536
+ __trdListen(window, "focus", D), document.body.appendChild(g), g.click();
2537
+ });
2538
+ }
2539
+ /**
2540
+ * Extract files (and recursively traverse directories) from a drag-and-drop event.
2541
+ *
2542
+ * Uses the File and Directory Entries API (`webkitGetAsEntry`) which is
2543
+ * supported across all major browsers (Chrome, Firefox, Safari, Edge).
2544
+ * Falls back to `getAsFile()` when the Entries API is unavailable.
2545
+ *
2546
+ * Directory entries are included in the result with `isDirectory: true`
2547
+ * and a `null` file handle. Files inside directories have their
2548
+ * {@link DroppedFile.path} set to the relative backslash-separated path.
2549
+ *
2550
+ * @param event - DragEvent from drop handler
2551
+ * @returns Promise resolving to an array of DroppedFile descriptors
2552
+ *
2553
+ * @example
2554
+ * ```typescript
2555
+ * dropZone.addEventListener('drop', async (e) => {
2556
+ * const files = await manager.handleDrop(e);
2557
+ * manager.uploadFiles(files);
2558
+ * });
2559
+ * ```
2560
+ */
2561
+ async handleDrop(A) {
2562
+ var _a, _b, _c;
2563
+ A.preventDefault();
2564
+ const I = [];
2565
+ if ((_a = A.dataTransfer) == null ? void 0 : _a.items) {
2566
+ const g = [], B = [];
2567
+ for (const E of A.dataTransfer.items) {
2568
+ if (E.kind !== "file") continue;
2569
+ const D = (_b = E.webkitGetAsEntry) == null ? void 0 : _b.call(E);
2570
+ if (D)
2571
+ g.push(D);
2572
+ else {
2573
+ const i = E.getAsFile();
2574
+ i && B.push(i);
2575
+ }
2576
+ }
2577
+ for (const E of g)
2578
+ await this.traverseEntry(E, void 0, I, 0);
2579
+ for (const E of B)
2580
+ I.push({
2581
+ file: E,
2582
+ name: E.name,
2583
+ size: E.size,
2584
+ lastModified: E.lastModified
2585
+ });
2586
+ } else if ((_c = A.dataTransfer) == null ? void 0 : _c.files)
2587
+ for (const g of Array.from(A.dataTransfer.files))
2588
+ I.push({
2589
+ file: g,
2590
+ name: g.name,
2591
+ size: g.size,
2592
+ lastModified: g.lastModified
2593
+ });
2594
+ return I;
2595
+ }
2596
+ /**
2597
+ * Normalize a plain `File[]` or `DroppedFile[]` into `DroppedFile[]`.
2598
+ * Allows `uploadFiles` to accept either type for backward compatibility.
2599
+ */
2600
+ static normalizeToDroppedFiles(A) {
2601
+ return A.length === 0 ? [] : "file" in A[0] ? A : A.map((g) => ({
2602
+ file: g,
2603
+ name: g.name,
2604
+ size: g.size,
2605
+ lastModified: g.lastModified
2606
+ }));
2607
+ }
2608
+ /**
2609
+ * Recursively traverse a FileSystemEntry, collecting files and directory
2610
+ * entries into `results`.
2611
+ */
2612
+ async traverseEntry(A, I, g, B) {
2613
+ if (!(g.length >= _U.MAX_DIRECTORY_ENTRIES)) {
2614
+ if (B > _U.MAX_DIRECTORY_DEPTH) {
2615
+ console.warn(
2616
+ `Skipping "${A.name}": directory depth exceeds ${_U.MAX_DIRECTORY_DEPTH}`
2617
+ );
2618
+ return;
2619
+ }
2620
+ if (A.isFile) {
2621
+ const E = await new Promise((D, i) => {
2622
+ A.file(D, i);
2623
+ });
2624
+ g.push({
2625
+ file: E,
2626
+ name: E.name,
2627
+ size: E.size,
2628
+ lastModified: E.lastModified,
2629
+ path: I
2630
+ });
2631
+ } else if (A.isDirectory) {
2632
+ const E = I !== void 0 ? `${I}\\${A.name}` : A.name;
2633
+ g.push({
2634
+ file: null,
2635
+ name: A.name,
2636
+ size: 0,
2637
+ lastModified: 0,
2638
+ path: I,
2639
+ isDirectory: true
2640
+ });
2641
+ const D = A.createReader(), i = await _U.readAllDirectoryEntries(D);
2642
+ for (const w of i)
2643
+ await this.traverseEntry(w, E, g, B + 1);
2644
+ }
2645
+ }
2646
+ }
2647
+ /**
2648
+ * Read all entries from a FileSystemDirectoryReader. Chromium-based
2649
+ * browsers return at most 100 entries per `readEntries()` call, so we
2650
+ * must loop until an empty batch is returned.
2651
+ */
2652
+ static readAllDirectoryEntries(A) {
2653
+ return new Promise((I, g) => {
2654
+ const B = [], E = () => {
2655
+ A.readEntries((D) => {
2656
+ D.length === 0 ? I(B) : (B.push(...D), E());
2657
+ }, g);
2658
+ };
2659
+ E();
2660
+ });
2661
+ }
2662
+ /**
2663
+ * Prevent default drag-over behavior to enable drop target.
2664
+ *
2665
+ * This must be called in the dragover event handler for drag-and-drop to work.
2666
+ *
2667
+ * @param event - DragEvent from dragover handler
2668
+ *
2669
+ * @example
2670
+ * ```typescript
2671
+ * dropZone.addEventListener('dragover', (e) => manager.handleDragOver(e));
2672
+ * ```
2673
+ */
2674
+ handleDragOver(A) {
2675
+ A.preventDefault();
2676
+ }
2677
+ /**
2678
+ * Cleanup resources and unregister callbacks.
2679
+ *
2680
+ * Call this when the session is terminating or RdpFileTransferProvider is no longer needed.
2681
+ */
2682
+ dispose() {
2683
+ this.disposed = true, this.clearPasteAckWatchdog(), this.clearUploadInactivityWatchdog(), this.resumeUploadMonitoring();
2684
+ for (const A of this.activeDownloads.values())
2685
+ this.abortWriteHandle(A), A.reject(new Error("RdpFileTransferProvider disposed"));
2686
+ this.activeDownloads.clear(), this.uploadState !== void 0 && (this.abortInFlightReads(this.uploadState), this.uploadState.reject(new Error("RdpFileTransferProvider disposed"))), this.uploadState = void 0, this.retainedFiles = void 0, this.availableFiles = [], this.clipDataId = void 0, this.storageBackend && (this.storageBackend.dispose(), this.storageBackend = void 0, this.storageBackendReady = void 0), this.eventHandlers.clear();
2687
+ }
2688
+ // ==================== Callback Handlers ====================
2689
+ handleFilesAvailable(A, I) {
2690
+ this.failPendingUpload("Upload interrupted: the remote clipboard changed");
2691
+ const g = A.map((B) => ({
2692
+ ...B,
2693
+ name: _U.sanitizeFileName(B.name),
2694
+ path: B.path !== void 0 ? _U.sanitizePath(B.path) : void 0
2695
+ }));
2696
+ this.availableFiles = g, this.clipDataId = I, this.emit("files-available", g);
2697
+ }
2698
+ /**
2699
+ * Extract the basename from a file name, stripping any path traversal or
2700
+ * directory components. Returns "unnamed_file" if the name is empty or
2701
+ * consists entirely of path separators / traversal sequences.
2702
+ */
2703
+ /** @internal Visible for testing. */
2704
+ static sanitizeFileName(A) {
2705
+ const I = A.split(/[/\\]/);
2706
+ for (let g = I.length - 1; g >= 0; g--) {
2707
+ const B = I[g];
2708
+ if (B.length > 0 && B !== "." && B !== "..")
2709
+ return B;
2710
+ }
2711
+ return "unnamed_file";
2712
+ }
2713
+ /**
2714
+ * Sanitize a relative directory path by stripping traversal components
2715
+ * (`.` and `..`) and absolute path prefixes. Returns undefined if the
2716
+ * path is empty after sanitization.
2717
+ */
2718
+ /** @internal Visible for testing. */
2719
+ static sanitizePath(A) {
2720
+ const g = A.split(/[/\\]/).filter((B) => B.length > 0 && B !== "." && B !== "..");
2721
+ if (g.length > 0 && (g[0] === "?" || g[0] === ".") && (g.shift(), g.length > 0 && /^[A-Za-z]:$/.test(g[0]) && g.shift()), g.length > 0 && /^[A-Za-z]:$/.test(g[0]) && g.shift(), g.length !== 0)
2722
+ return g.join("\\");
2723
+ }
2724
+ handleFileContentsRequest(A) {
2725
+ if (this.acknowledgePaste(), !this.uploadState) {
2726
+ if (!this.retainedFiles) {
2727
+ console.warn("Received file contents request but no upload in progress"), this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2728
+ return;
2729
+ }
2730
+ this.rebuildUploadStateFromRetained();
2731
+ }
2732
+ const I = this.uploadState, { files: g, droppedFiles: B } = I;
2733
+ if (I.failedFiles.has(A.index)) {
2734
+ this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2735
+ return;
2736
+ }
2737
+ const E = g[A.index], D = B[A.index];
2738
+ if (D === void 0) {
2739
+ console.error(
2740
+ `File index ${A.index} out of range (stream ${A.streamId}, valid: 0..${B.length - 1})`
2741
+ ), this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2742
+ return;
2743
+ }
2744
+ if (E == null) {
2745
+ if ((A.flags & j.SIZE) !== 0) {
2746
+ const w = new Uint8Array(8);
2747
+ this.sendSubmitFileContents(A.streamId, false, w);
2748
+ } else
2749
+ this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2750
+ return;
2751
+ }
2752
+ const i = E;
2753
+ if ((A.flags & j.SIZE) !== 0) {
2754
+ const w = new Uint8Array(8);
2755
+ new DataView(w.buffer).setBigUint64(0, BigInt(i.size), true), this.sendSubmitFileContents(A.streamId, false, w), i.size === 0 && this.markUploadFileComplete(A.index, i, I.transferIds.get(A.index) ?? -1);
2756
+ } else if ((A.flags & j.RANGE) !== 0) {
2757
+ const w = i.slice(A.position, A.position + A.size), F = new FileReader();
2758
+ I.activeReaders.set(A.streamId, F);
2759
+ const a = setTimeout(() => {
2760
+ var _a;
2761
+ F.abort(), this.uploadState !== void 0 && (this.uploadState.activeReaders.delete(A.streamId), this.uploadState.readerTimeouts.delete(A.streamId)), this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2762
+ const J = {
2763
+ message: `File read timeout after ${_U.FILE_READER_TIMEOUT_MS / 1e3}s`,
2764
+ transferId: (_a = this.uploadState) == null ? void 0 : _a.transferIds.get(A.index),
2765
+ fileIndex: A.index,
2766
+ fileName: D.name,
2767
+ direction: "upload"
2768
+ };
2769
+ this.emit("error", J), this.uploadState !== void 0 && (this.uploadState.failedFiles.add(A.index), this.uploadState.completedFiles.add(A.index), this.uploadState.completedFiles.size >= this.uploadState.expectedFileCount && this.finishUploadBatch(this.uploadState));
2770
+ }, _U.FILE_READER_TIMEOUT_MS);
2771
+ I.readerTimeouts.set(A.streamId, a), F.onload = () => {
2772
+ if (this.uploadState !== void 0) {
2773
+ this.uploadState.activeReaders.delete(A.streamId);
2774
+ const Y = this.uploadState.readerTimeouts.get(A.streamId);
2775
+ Y !== void 0 && (clearTimeout(Y), this.uploadState.readerTimeouts.delete(A.streamId));
2776
+ }
2777
+ const J = new Uint8Array(F.result);
2778
+ if (this.sendSubmitFileContents(A.streamId, false, J), this.uploadState !== void 0) {
2779
+ const Y = (this.uploadState.bytesServed.get(A.index) ?? 0) + J.length;
2780
+ this.uploadState.bytesServed.set(A.index, Y);
2781
+ const l = this.uploadState.transferIds.get(A.index) ?? -1, v = {
2782
+ transferId: l,
2783
+ fileIndex: A.index,
2784
+ fileName: D.name,
2785
+ bytesTransferred: Y,
2786
+ totalBytes: i.size,
2787
+ percentage: i.size === 0 ? 100 : Math.min(Y / i.size * 100, 100)
2788
+ };
2789
+ this.emit("upload-progress", v), Y >= i.size && this.markUploadFileComplete(A.index, i, l);
2790
+ }
2791
+ }, F.onerror = () => {
2792
+ var _a, _b;
2793
+ if (this.uploadState !== void 0) {
2794
+ this.uploadState.activeReaders.delete(A.streamId);
2795
+ const Y = this.uploadState.readerTimeouts.get(A.streamId);
2796
+ Y !== void 0 && (clearTimeout(Y), this.uploadState.readerTimeouts.delete(A.streamId));
2797
+ }
2798
+ if (((_a = this.uploadState) == null ? void 0 : _a.failedFiles.has(A.index)) === true)
2799
+ return;
2800
+ this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2801
+ const J = {
2802
+ message: "Failed to read file chunk",
2803
+ transferId: (_b = this.uploadState) == null ? void 0 : _b.transferIds.get(A.index),
2804
+ fileIndex: A.index,
2805
+ fileName: D.name,
2806
+ direction: "upload",
2807
+ cause: F.error
2808
+ };
2809
+ this.emit("error", J), this.uploadState !== void 0 && (this.uploadState.failedFiles.add(A.index), this.uploadState.completedFiles.add(A.index), this.uploadState.completedFiles.size >= this.uploadState.expectedFileCount && this.finishUploadBatch(this.uploadState));
2810
+ }, F.readAsArrayBuffer(w);
2811
+ }
2812
+ }
2813
+ /**
2814
+ * Mark a single upload file as fully served: record it, emit upload-complete once, and
2815
+ * finalize the batch once every counted file is accounted for. Shared by the RANGE onload
2816
+ * path (final chunk served) and the SIZE path for 0-byte files (which get no RANGE request).
2817
+ */
2818
+ markUploadFileComplete(A, I, g) {
2819
+ const B = this.uploadState;
2820
+ B === void 0 || B.completedFiles.has(A) || (B.completedFiles.add(A), this.emit("upload-complete", I, A, g), B.completedFiles.size === B.expectedFileCount && this.finishUploadBatch(B));
2821
+ }
2822
+ /**
2823
+ * Lazily rebuild uploadState from retainedFiles when the remote re-pastes
2824
+ * after the original upload completed. This lets the main code path in
2825
+ * handleFileContentsRequest handle progress and completion identically.
2826
+ * No external promise - resolve/reject are no-ops.
2827
+ */
2828
+ rebuildUploadStateFromRetained() {
2829
+ const A = this.retainedFiles, I = /* @__PURE__ */ new Map();
2830
+ for (let B = 0; B < A.length; B++)
2831
+ I.set(B, this.generateStreamId());
2832
+ const g = A.filter((B) => B.isDirectory !== true).length;
2833
+ this.uploadState = {
2834
+ files: A.map((B) => B.file),
2835
+ droppedFiles: A,
2836
+ failedFiles: /* @__PURE__ */ new Set(),
2837
+ expectedFileCount: g,
2838
+ completedFiles: /* @__PURE__ */ new Set(),
2839
+ bytesServed: /* @__PURE__ */ new Map(),
2840
+ activeReaders: /* @__PURE__ */ new Map(),
2841
+ readerTimeouts: /* @__PURE__ */ new Map(),
2842
+ transferIds: I,
2843
+ resolve: () => {
2844
+ },
2845
+ reject: () => {
2846
+ },
2847
+ isRePaste: true
2848
+ }, this.emit("upload-batch-started", I, A);
2849
+ }
2850
+ handleFileContentsResponse(A) {
2851
+ const I = this.activeDownloads.get(A.streamId);
2852
+ if (!I) {
2853
+ console.warn(`Received response for unknown stream ${A.streamId}`);
2854
+ return;
2855
+ }
2856
+ if (A.isError) {
2857
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(I);
2858
+ const g = {
2859
+ message: "Remote failed to provide file contents",
2860
+ transferId: I.streamId,
2861
+ fileIndex: I.fileIndex,
2862
+ fileName: I.fileInfo.name,
2863
+ direction: "download"
2864
+ };
2865
+ this.emit("error", g), I.reject(new Error(g.message));
2866
+ return;
2867
+ }
2868
+ if (I.expectedSize === void 0) {
2869
+ if (A.data.length < 8) {
2870
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(I);
2871
+ const E = {
2872
+ message: "Invalid SIZE response: expected 8 bytes for file size",
2873
+ transferId: I.streamId,
2874
+ fileIndex: I.fileIndex,
2875
+ fileName: I.fileInfo.name,
2876
+ direction: "download"
2877
+ };
2878
+ this.emit("error", E), I.reject(new Error(E.message));
2879
+ return;
2880
+ }
2881
+ const g = new DataView(A.data.buffer, A.data.byteOffset, A.data.byteLength), B = Number(g.getBigUint64(0, true));
2882
+ if (B > _U.MAX_FILE_SIZE) {
2883
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(I);
2884
+ const E = {
2885
+ message: `File size ${(B / (1024 * 1024 * 1024)).toFixed(2)}GB exceeds maximum download limit of 2GB`,
2886
+ transferId: I.streamId,
2887
+ fileIndex: I.fileIndex,
2888
+ fileName: I.fileInfo.name,
2889
+ direction: "download"
2890
+ };
2891
+ this.emit("error", E), I.reject(new Error(E.message));
2892
+ return;
2893
+ }
2894
+ if (I.expectedSize = B, B === 0) {
2895
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(I);
2896
+ const E = new Blob([]);
2897
+ this.emit("download-complete", I.fileInfo, E, I.fileIndex, I.streamId), I.resolve(E);
2898
+ return;
2899
+ }
2900
+ this.initWriteHandleAndRequestFirstChunk(I);
2901
+ } else
2902
+ this.handleDataChunk(I, A.data);
2903
+ }
2904
+ /**
2905
+ * Create a write handle for the given transfer and request the first
2906
+ * data chunk. Runs asynchronously because backend initialization
2907
+ * (especially OPFS) is async.
2908
+ *
2909
+ * The init promise is stored on `state.writeHandleReady` so that
2910
+ * DATA responses arriving before the handle is ready can await it.
2911
+ */
2912
+ initWriteHandleAndRequestFirstChunk(A) {
2913
+ A.writeHandleReady = (async () => {
2914
+ try {
2915
+ const I = (async () => (await this.ensureStorageBackend()).createWriteHandle(A.fileInfo.name, A.expectedSize ?? 0))(), g = _U.WRITE_HANDLE_INIT_TIMEOUT_MS, B = await Promise.race([
2916
+ I,
2917
+ new Promise(
2918
+ (E, D) => setTimeout(() => D(new Error(`Storage init timed out after ${g / 1e3}s`)), g)
2919
+ )
2920
+ ]);
2921
+ if (this.disposed || !this.activeDownloads.has(A.streamId)) {
2922
+ try {
2923
+ await B.abort();
2924
+ } catch {
2925
+ }
2926
+ return;
2927
+ }
2928
+ A.writeHandle = B;
2929
+ } catch (I) {
2930
+ this.activeDownloads.delete(A.streamId);
2931
+ const g = {
2932
+ message: "Failed to initialize storage for download",
2933
+ transferId: A.streamId,
2934
+ fileIndex: A.fileIndex,
2935
+ fileName: A.fileInfo.name,
2936
+ direction: "download",
2937
+ cause: I
2938
+ };
2939
+ this.emit("error", g), A.reject(new Error(g.message, { cause: I }));
2940
+ return;
2941
+ }
2942
+ this.requestNextChunk(A);
2943
+ })();
2944
+ }
2945
+ /**
2946
+ * Write a data chunk to the storage backend and advance the download.
2947
+ *
2948
+ * If the write handle is not yet ready (DATA response arrived before
2949
+ * backend init completed), this method awaits `state.writeHandleReady`
2950
+ * to preserve chunk ordering -- each concurrent caller awaits the same
2951
+ * promise in sequence.
2952
+ */
2953
+ async handleDataChunk(A, I) {
2954
+ if (!A.writeHandle && (!A.writeHandleReady || this.disposed || !this.activeDownloads.has(A.streamId) || (await A.writeHandleReady, this.disposed || !this.activeDownloads.has(A.streamId))))
2955
+ return;
2956
+ const g = A.writeHandle;
2957
+ if (g) {
2958
+ try {
2959
+ await g.write(I);
2960
+ } catch (B) {
2961
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(A);
2962
+ const i = {
2963
+ message: B instanceof DOMException && B.name === "QuotaExceededError" ? `Storage quota exceeded while downloading "${A.fileInfo.name}"` : "Failed to write download chunk to storage",
2964
+ transferId: A.streamId,
2965
+ fileIndex: A.fileIndex,
2966
+ fileName: A.fileInfo.name,
2967
+ direction: "download",
2968
+ cause: B
2969
+ };
2970
+ this.emit("error", i), A.reject(new Error(i.message, { cause: B }));
2971
+ return;
2972
+ }
2973
+ if (A.bytesReceived += I.length, A.expectedSize !== void 0 && A.bytesReceived > A.expectedSize * 2) {
2974
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(A);
2975
+ const B = {
2976
+ message: `Received ${A.bytesReceived} bytes but expected ${A.expectedSize} - aborting`,
2977
+ transferId: A.streamId,
2978
+ fileIndex: A.fileIndex,
2979
+ fileName: A.fileInfo.name,
2980
+ direction: "download"
2981
+ };
2982
+ this.emit("error", B), A.reject(new Error(B.message));
2983
+ return;
2984
+ }
2985
+ if (A.expectedSize !== void 0) {
2986
+ const B = {
2987
+ transferId: A.streamId,
2988
+ fileIndex: A.fileIndex,
2989
+ fileName: A.fileInfo.name,
2990
+ bytesTransferred: A.bytesReceived,
2991
+ totalBytes: A.expectedSize,
2992
+ percentage: Math.min(A.bytesReceived / A.expectedSize * 100, 100)
2993
+ };
2994
+ this.emit("download-progress", B);
2995
+ }
2996
+ if (A.expectedSize !== void 0 && A.bytesReceived >= A.expectedSize) {
2997
+ this.activeDownloads.delete(A.streamId);
2998
+ try {
2999
+ const B = await g.finalize();
3000
+ this.emit("download-complete", A.fileInfo, B, A.fileIndex, A.streamId), A.resolve(B);
3001
+ } catch (B) {
3002
+ this.abortWriteHandle(A);
3003
+ const E = {
3004
+ message: "Failed to finalize downloaded file",
3005
+ transferId: A.streamId,
3006
+ fileIndex: A.fileIndex,
3007
+ fileName: A.fileInfo.name,
3008
+ direction: "download",
3009
+ cause: B
3010
+ };
3011
+ this.emit("error", E), A.reject(new Error(E.message, { cause: B }));
3012
+ }
3013
+ } else
3014
+ this.requestNextChunk(A);
3015
+ }
3016
+ }
3017
+ /** Abort and clean up a write handle, ignoring errors. */
3018
+ async abortWriteHandle(A) {
3019
+ if (A.writeHandle) {
3020
+ try {
3021
+ await A.writeHandle.abort();
3022
+ } catch {
3023
+ }
3024
+ A.writeHandle = void 0;
3025
+ }
3026
+ }
3027
+ /**
3028
+ * Handle the remote's response to one of our outbound Format Lists, surfaced via
3029
+ * `on_format_list_response`. Always re-emitted as a `format-list-response` event so
3030
+ * a frontend can drive paste from it (inject on accept, retry on reject).
3031
+ *
3032
+ * On reject (`ok === false`) the remote silently discards the advertised clipboard
3033
+ * (MS-RDPECLIP), so an upload still waiting to be pulled can never complete --
3034
+ * previously this left `uploadState` set and every later upload threw "Upload
3035
+ * already in progress". The watchdog-armed check scopes the release to an upload
3036
+ * that was advertised but not yet pulled, so re-paste and an already-progressing
3037
+ * transfer are left alone.
3038
+ */
3039
+ handleFormatListResponse(A) {
3040
+ this.emit("format-list-response", A), !A && this.pasteAckTimeout !== void 0 && this.failPendingUpload("The remote rejected the file list, so the paste was not accepted");
3041
+ }
3042
+ handleLock(A) {
3043
+ }
3044
+ handleUnlock(A) {
3045
+ }
3046
+ handleLocksExpired(A) {
3047
+ const I = /* @__PURE__ */ new Set();
3048
+ for (let g = 0; g < A.length; g++)
3049
+ I.add(A[g]);
3050
+ for (const [g, B] of this.activeDownloads)
3051
+ if (B.clipDataId !== void 0 && I.has(B.clipDataId)) {
3052
+ this.activeDownloads.delete(g), this.abortWriteHandle(B);
3053
+ const E = `File download timed out for "${B.fileInfo.name}". Clipboard lock expired due to inactivity. This can happen with slow network connections or large files. Try downloading smaller files, increasing chunk size, or checking your network connection.`;
3054
+ B.reject(new Error(E)), this.emit("error", {
3055
+ message: E,
3056
+ transferId: B.streamId,
3057
+ fileIndex: B.fileIndex,
3058
+ fileName: B.fileInfo.name,
3059
+ direction: "download"
3060
+ });
3061
+ }
3062
+ }
3063
+ // ==================== Helper Methods ====================
3064
+ requestNextChunk(A) {
3065
+ if (A.expectedSize === void 0 || A.expectedSize === 0)
3066
+ return;
3067
+ const I = A.bytesReceived, g = A.expectedSize - I, B = Math.min(this.chunkSize, g);
3068
+ try {
3069
+ this.sendRequestFileContents(
3070
+ A.streamId,
3071
+ A.fileIndex,
3072
+ j.RANGE,
3073
+ I,
3074
+ B,
3075
+ A.clipDataId
3076
+ );
3077
+ } catch (E) {
3078
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(A);
3079
+ const D = {
3080
+ message: "Failed to request file chunk",
3081
+ transferId: A.streamId,
3082
+ fileIndex: A.fileIndex,
3083
+ fileName: A.fileInfo.name,
3084
+ direction: "download",
3085
+ cause: E
3086
+ };
3087
+ this.emit("error", D), A.reject(new Error(D.message, { cause: E }));
3088
+ }
3089
+ }
3090
+ generateStreamId() {
3091
+ const A = this.activeDownloads.size + 2;
3092
+ for (let I = 0; I < A; I++) {
3093
+ const g = this.nextStreamId;
3094
+ if (this.nextStreamId = (this.nextStreamId + 1) % 4294967296, this.nextStreamId === 0 && (this.nextStreamId = 1), !this.activeDownloads.has(g) && g !== 0)
3095
+ return g;
3096
+ }
3097
+ throw new Error("Unable to generate unique stream ID");
3098
+ }
3099
+ };
3100
+ /** Maximum file size for downloads (2GB) to prevent browser out-of-memory errors */
3101
+ __publicField(_U, "MAX_FILE_SIZE", 2 * 1024 * 1024 * 1024);
3102
+ /** Timeout for FileReader operations (60 seconds) to prevent stalled uploads */
3103
+ __publicField(_U, "FILE_READER_TIMEOUT_MS", 60 * 1e3);
3104
+ /**
3105
+ * How long to keep clipboard monitoring suppressed after advertising an upload
3106
+ * while waiting for the remote to pull the files (first FileContentsRequest),
3107
+ * before giving up. Matches the Rust cliprdr lock inactivity timeout (60s), so
3108
+ * the JS side gives up exactly when the protocol lock does. If the remote never
3109
+ * requests contents (the paste landed in a non-file target, or the advertise was
3110
+ * clobbered), the watchdog resumes monitoring and fails the upload so its state
3111
+ * cannot wedge later uploads.
3112
+ */
3113
+ __publicField(_U, "PASTE_ACK_TIMEOUT_MS", 60 * 1e3);
3114
+ /**
3115
+ * Upload inactivity window. After the remote starts pulling, each FileContentsRequest
3116
+ * resets this; if pulls then stop for this long -- e.g. the remote grabbed the
3117
+ * clipboard with a text/image copy that never reaches handleFilesAvailable -- the
3118
+ * upload is failed so `uploadState` is released and later uploads aren't wedged. A
3119
+ * slow-but-progressing transfer keeps resetting it, so it is never killed.
3120
+ */
3121
+ __publicField(_U, "UPLOAD_INACTIVITY_TIMEOUT_MS", 60 * 1e3);
3122
+ /** Timeout for storage backend write handle initialization (30 seconds). */
3123
+ __publicField(_U, "WRITE_HANDLE_INIT_TIMEOUT_MS", 30 * 1e3);
3124
+ /** Maximum recursion depth when traversing dropped directories. */
3125
+ __publicField(_U, "MAX_DIRECTORY_DEPTH", 32);
3126
+ /** Maximum total entries (files + directories) collected from a single drop. */
3127
+ __publicField(_U, "MAX_DIRECTORY_ENTRIES", 1e3);
3128
+ let U = _U;
3129
+ async function wI(Q, A) {
3130
+ await OA(A === void 0 ? void 0 : { module_or_path: A }), JA(Q);
3131
+ }
3132
+ const GI = {
3133
+ DesktopSize: p,
3134
+ InputTransaction: e,
3135
+ SessionBuilder: c,
3136
+ ClipboardData: Z,
3137
+ DeviceEvent: K
3138
+ };
3139
+ function oI(Q) {
3140
+ return new N("pcb", Q);
3141
+ }
3142
+ function NI(Q, A = "enhanced") {
3143
+ if (Q.trim() === "")
3144
+ throw new Error("vmconnect requires a VM ID");
3145
+ const I = A === "enhanced" ? `${Q};EnhancedMode=1` : Q;
3146
+ return new N("vmconnect", I);
3147
+ }
3148
+ function kI(Q) {
3149
+ return new N("display_control", Q);
3150
+ }
3151
+ function FI(Q) {
3152
+ return new N("graphics_pipeline", Q);
3153
+ }
3154
+ function RI(Q) {
3155
+ return new N("h264_decoder", Q);
3156
+ }
3157
+ function yI(Q) {
3158
+ return new N("audio_playback", Q);
3159
+ }
3160
+ function YI(Q) {
3161
+ return new N("drive_redirection", Q);
3162
+ }
3163
+ function MI(Q) {
3164
+ return new N("audio_input", Q);
3165
+ }
3166
+ function cI(Q) {
3167
+ const A = Q instanceof Uint8Array ? Q : new Uint8Array(Q.buffer, Q.byteOffset, Q.byteLength);
3168
+ return new N("audio_input_data", A);
3169
+ }
3170
+ function JI(Q) {
3171
+ return new N("kdc_proxy_url", Q);
3172
+ }
3173
+ function UI(Q) {
3174
+ return new N("outbound_message_size_limit", Q);
3175
+ }
3176
+ function KI(Q) {
3177
+ return new N("enable_credssp", Q);
3178
+ }
3179
+ function hI(Q) {
3180
+ return new N("enable_server_pointer", Q);
3181
+ }
3182
+ function aI(Q) {
3183
+ return new N("legacy_graphics", Q);
3184
+ }
3185
+ try { await wI(__trdLevel, __trdModule); }
3186
+ catch (error) { __trdReleaseBrowserRoots(); throw error; }
3187
+ return {
3188
+ Backend: GI,
3189
+ BlobStorageBackend: YA,
3190
+ FileContentsFlags: j,
3191
+ OpfsStorageBackend: x,
3192
+ PrinterDriverName: QI,
3193
+ RdpFile: QA,
3194
+ RdpFileTransferProvider: U,
3195
+ WebCodecsH264Decoder: cA,
3196
+ audioInput: MI,
3197
+ audioInputData: cI,
3198
+ audioPlayback: yI,
3199
+ detectStorageBackend: gI,
3200
+ displayControl: kI,
3201
+ driveRedirection: YI,
3202
+ enableCredssp: KI,
3203
+ enableServerPointer: hI,
3204
+ fileContentsRequestCallback: TA,
3205
+ fileContentsResponseCallback: nA,
3206
+ filesAvailableCallback: fA,
3207
+ graphicsPipeline: FI,
3208
+ h264Decoder: RI,
3209
+ h264Supported: BI,
3210
+ init: wI,
3211
+ initiateFileCopy: _A,
3212
+ kdcProxyUrl: JI,
3213
+ legacyGraphics: aI,
3214
+ lockCallback: rA,
3215
+ locksExpiredCallback: vA,
3216
+ outboundMessageSizeLimit: UI,
3217
+ preConnectionBlob: oI,
3218
+ printJobStreamCallbacks: CI,
3219
+ printerDeviceId: DI,
3220
+ printerDriverName: iI,
3221
+ printerName: EI,
3222
+ requestFileContents: eA,
3223
+ submitFileContents: uA,
3224
+ unlockCallback: PA,
3225
+ vmConnect: NI,
3226
+ runtime: {
3227
+ dispose () { __trdReleaseBrowserRoots(); __trdListeners.clear(); },
3228
+ get memory () { return C.memory; },
3229
+ get trapped () { return __trdTrap; },
3230
+ onTrap (listener) {
3231
+ if (__trdTrap) listener(__trdTrap);
3232
+ else __trdListeners.add(listener);
3233
+ return () => __trdListeners.delete(listener);
3234
+ },
3235
+ },
3236
+ };
3237
+ }