tabby-rdp 0.5.2 → 0.5.5

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,3427 @@
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 d {
70
+ static __wrap(A) {
71
+ const I = Object.create(d.prototype);
72
+ return I.__wbg_ptr = A, $.register(I, I.__wbg_ptr, I), I;
73
+ }
74
+ __destroy_into_raw() {
75
+ const A = this.__wbg_ptr;
76
+ return this.__wbg_ptr = 0, $.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 = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = R, E = mA(I, C.__wbindgen_malloc), D = R;
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 = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = R, E = F(I, C.__wbindgen_malloc, C.__wbindgen_realloc), D = R;
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, $.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 = OA(A[0], A[1]).slice();
114
+ return C.__wbindgen_free(A[0], A[1] * 4, 4), I;
115
+ }
116
+ }
117
+ Symbol.dispose && (d.prototype[Symbol.dispose] = d.prototype.free);
118
+ class r {
119
+ static __wrap(A) {
120
+ const I = Object.create(r.prototype);
121
+ return I.__wbg_ptr = A, wA.register(I, I.__wbg_ptr, I), I;
122
+ }
123
+ __destroy_into_raw() {
124
+ const A = this.__wbg_ptr;
125
+ return this.__wbg_ptr = 0, wA.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 && (r.prototype[Symbol.dispose] = r.prototype.free);
151
+ class V {
152
+ static __wrap(A) {
153
+ const I = Object.create(V.prototype);
154
+ return I.__wbg_ptr = A, AA.register(I, I.__wbg_ptr, I), I;
155
+ }
156
+ __destroy_into_raw() {
157
+ const A = this.__wbg_ptr;
158
+ return this.__wbg_ptr = 0, AA.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, AA.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 && (V.prototype[Symbol.dispose] = V.prototype.free);
198
+ class h {
199
+ static __wrap(A) {
200
+ const I = Object.create(h.prototype);
201
+ return I.__wbg_ptr = A, GA.register(I, I.__wbg_ptr, I), I;
202
+ }
203
+ __destroy_into_raw() {
204
+ const A = this.__wbg_ptr;
205
+ return this.__wbg_ptr = 0, GA.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 h.__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 h.__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 h.__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 h.__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 h.__wrap(g);
251
+ }
252
+ /**
253
+ * @param {string} unicode
254
+ * @returns {DeviceEvent}
255
+ */
256
+ static unicodePressed(A) {
257
+ const I = A.codePointAt(0);
258
+ MA(I);
259
+ const g = C.deviceevent_unicodePressed(I);
260
+ return h.__wrap(g);
261
+ }
262
+ /**
263
+ * @param {string} unicode
264
+ * @returns {DeviceEvent}
265
+ */
266
+ static unicodeReleased(A) {
267
+ const I = A.codePointAt(0);
268
+ MA(I);
269
+ const g = C.deviceevent_unicodeReleased(I);
270
+ return h.__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 h.__wrap(B);
281
+ }
282
+ }
283
+ Symbol.dispose && (h.prototype[Symbol.dispose] = h.prototype.free);
284
+ class k {
285
+ __destroy_into_raw() {
286
+ const A = this.__wbg_ptr;
287
+ return this.__wbg_ptr = 0, oA.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 = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = R, E = C.extension_create(g, B, I);
299
+ return this.__wbg_ptr = E, oA.register(this, this.__wbg_ptr, this), this;
300
+ }
301
+ }
302
+ Symbol.dispose && (k.prototype[Symbol.dispose] = k.prototype.free);
303
+ class _ {
304
+ __destroy_into_raw() {
305
+ const A = this.__wbg_ptr;
306
+ return this.__wbg_ptr = 0, NA.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
+ x(A, h);
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, NA.register(this, this.__wbg_ptr, this), this;
323
+ }
324
+ }
325
+ Symbol.dispose && (_.prototype[Symbol.dispose] = _.prototype.free);
326
+ class n {
327
+ static __wrap(A) {
328
+ const I = Object.create(n.prototype);
329
+ return I.__wbg_ptr = A, kA.register(I, I.__wbg_ptr, I), I;
330
+ }
331
+ __destroy_into_raw() {
332
+ const A = this.__wbg_ptr;
333
+ return this.__wbg_ptr = 0, kA.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 : z.__wrap(A);
363
+ }
364
+ }
365
+ Symbol.dispose && (n.prototype[Symbol.dispose] = n.prototype.free);
366
+ class z {
367
+ static __wrap(A) {
368
+ const I = Object.create(z.prototype);
369
+ return I.__wbg_ptr = A, RA.register(I, I.__wbg_ptr, I), I;
370
+ }
371
+ __destroy_into_raw() {
372
+ const A = this.__wbg_ptr;
373
+ return this.__wbg_ptr = 0, RA.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 && (z.prototype[Symbol.dispose] = z.prototype.free);
426
+ class iA {
427
+ __destroy_into_raw() {
428
+ const A = this.__wbg_ptr;
429
+ return this.__wbg_ptr = 0, FA.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, FA.register(this, this.__wbg_ptr, this), this;
438
+ }
439
+ /**
440
+ * @param {string} key
441
+ * @returns {number | undefined}
442
+ */
443
+ getInt(A) {
444
+ const I = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = R, 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 = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = R, 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 = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = R;
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 = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), B = R, E = F(I, C.__wbindgen_malloc, C.__wbindgen_realloc), D = R;
470
+ C.rdpfile_insertStr(this.__wbg_ptr, g, B, E, D);
471
+ }
472
+ /**
473
+ * @param {string} config
474
+ */
475
+ parse(A) {
476
+ const I = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = R;
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 && (iA.prototype[Symbol.dispose] = iA.prototype.free);
493
+ class P {
494
+ static __wrap(A) {
495
+ const I = Object.create(P.prototype);
496
+ return I.__wbg_ptr = A, yA.register(I, I.__wbg_ptr, I), I;
497
+ }
498
+ __destroy_into_raw() {
499
+ const A = this.__wbg_ptr;
500
+ return this.__wbg_ptr = 0, yA.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
+ x(A, _);
511
+ var I = A.__destroy_into_raw();
512
+ const g = C.session_applyInputs(this.__wbg_ptr, I);
513
+ if (g[1])
514
+ throw p(g[0]);
515
+ }
516
+ /**
517
+ * @returns {DesktopSize}
518
+ */
519
+ desktopSize() {
520
+ const A = C.session_desktopSize(this.__wbg_ptr);
521
+ return V.__wrap(A);
522
+ }
523
+ /**
524
+ * @param {Extension} ext
525
+ * @returns {any}
526
+ */
527
+ invokeExtension(A) {
528
+ x(A, k);
529
+ var I = A.__destroy_into_raw();
530
+ const g = C.session_invokeExtension(this.__wbg_ptr, I);
531
+ if (g[2])
532
+ throw p(g[1]);
533
+ return p(g[0]);
534
+ }
535
+ /**
536
+ * @param {ClipboardData} content
537
+ * @returns {Promise<void>}
538
+ */
539
+ onClipboardPaste(A) {
540
+ return x(A, d), 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 p(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 p(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 p(E[0]);
584
+ }
585
+ }
586
+ Symbol.dispose && (P.prototype[Symbol.dispose] = P.prototype.free);
587
+ class J {
588
+ static __wrap(A) {
589
+ const I = Object.create(J.prototype);
590
+ return I.__wbg_ptr = A, IA.register(I, I.__wbg_ptr, I), I;
591
+ }
592
+ __destroy_into_raw() {
593
+ const A = this.__wbg_ptr;
594
+ return this.__wbg_ptr = 0, IA.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 = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = R, B = C.sessionbuilder_authToken(this.__wbg_ptr, I, g);
606
+ return J.__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 J.__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, IA.register(this, this.__wbg_ptr, this), this;
625
+ }
626
+ /**
627
+ * @param {DesktopSize} desktop_size
628
+ * @returns {SessionBuilder}
629
+ */
630
+ desktopSize(A) {
631
+ x(A, V);
632
+ var I = A.__destroy_into_raw();
633
+ const g = C.sessionbuilder_desktopSize(this.__wbg_ptr, I);
634
+ return J.__wrap(g);
635
+ }
636
+ /**
637
+ * @param {string} destination
638
+ * @returns {SessionBuilder}
639
+ */
640
+ destination(A) {
641
+ const I = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = R, B = C.sessionbuilder_destination(this.__wbg_ptr, I, g);
642
+ return J.__wrap(B);
643
+ }
644
+ /**
645
+ * @param {Extension} ext
646
+ * @returns {SessionBuilder}
647
+ */
648
+ extension(A) {
649
+ x(A, k);
650
+ var I = A.__destroy_into_raw();
651
+ const g = C.sessionbuilder_extension(this.__wbg_ptr, I);
652
+ return J.__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 J.__wrap(I);
661
+ }
662
+ /**
663
+ * @param {string} password
664
+ * @returns {SessionBuilder}
665
+ */
666
+ password(A) {
667
+ const I = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = R, B = C.sessionbuilder_password(this.__wbg_ptr, I, g);
668
+ return J.__wrap(B);
669
+ }
670
+ /**
671
+ * @param {string} address
672
+ * @returns {SessionBuilder}
673
+ */
674
+ proxyAddress(A) {
675
+ const I = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = R, B = C.sessionbuilder_proxyAddress(this.__wbg_ptr, I, g);
676
+ return J.__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 J.__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 J.__wrap(I);
693
+ }
694
+ /**
695
+ * @param {string} server_domain
696
+ * @returns {SessionBuilder}
697
+ */
698
+ serverDomain(A) {
699
+ const I = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = R, B = C.sessionbuilder_serverDomain(this.__wbg_ptr, I, g);
700
+ return J.__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 J.__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 J.__wrap(I);
717
+ }
718
+ /**
719
+ * @param {string} username
720
+ * @returns {SessionBuilder}
721
+ */
722
+ username(A) {
723
+ const I = F(A, C.__wbindgen_malloc, C.__wbindgen_realloc), g = R, B = C.sessionbuilder_username(this.__wbg_ptr, I, g);
724
+ return J.__wrap(B);
725
+ }
726
+ }
727
+ Symbol.dispose && (J.prototype[Symbol.dispose] = J.prototype.free);
728
+ class v {
729
+ static __wrap(A) {
730
+ const I = Object.create(v.prototype);
731
+ return I.__wbg_ptr = A, YA.register(I, I.__wbg_ptr, I), I;
732
+ }
733
+ __destroy_into_raw() {
734
+ const A = this.__wbg_ptr;
735
+ return this.__wbg_ptr = 0, YA.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 && (v.prototype[Symbol.dispose] = v.prototype.free);
755
+ function hA(Q) {
756
+ const A = F(Q, C.__wbindgen_malloc, C.__wbindgen_realloc), I = R;
757
+ C.setup(A, I);
758
+ }
759
+ function aA() {
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 = QA(I), B = F(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = R;
770
+ Y().setInt32(A + 4, E, true), Y().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
+ Y().setFloat64(A + 8, H(B) ? 0 : B, true), Y().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 : F(B, C.__wbindgen_malloc, C.__wbindgen_realloc), D = R;
795
+ Y().setInt32(A + 4, D, true), Y().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 d.__wrap(A);
851
+ },
852
+ __wbg_clipboarditem_new: function(A) {
853
+ return r.__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 : q(B);
895
+ }, arguments);
896
+ },
897
+ __wbg_getRandomValues_3f44b700395062e5: function() {
898
+ return o(function(A, I) {
899
+ globalThis.crypto.getRandomValues(m(A, I));
900
+ }, arguments);
901
+ },
902
+ __wbg_getRandomValues_bf16787eede473f5: function() {
903
+ return o(function(A, I) {
904
+ globalThis.crypto.getRandomValues(m(A, I));
905
+ }, arguments);
906
+ },
907
+ __wbg_getRandomValues_cc7f052a444bb2ce: function() {
908
+ return o(function(A, I) {
909
+ globalThis.crypto.getRandomValues(m(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 n.__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(WA(A, I));
1053
+ },
1054
+ __wbg_new_from_slice_77cdfb7977362f3c: function(A, I) {
1055
+ return new Uint8Array(m(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 pA(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(xA(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 : q(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(m(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 = F(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = R;
1142
+ Y().setInt32(A + 4, E, true), Y().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 = F(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = R;
1154
+ Y().setInt32(A + 4, E, true), Y().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 P.__wrap(A);
1168
+ },
1169
+ __wbg_sessionterminationinfo_new: function(A) {
1170
+ return v.__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 = VA[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 = F(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = R;
1224
+ Y().setInt32(A + 4, E, true), Y().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 : q(A);
1229
+ },
1230
+ __wbg_static_accessor_GLOBAL_THIS_8d1badc68b5a74f4: function() {
1231
+ const A = typeof globalThis > "u" ? null : globalThis;
1232
+ return H(A) ? 0 : q(A);
1233
+ },
1234
+ __wbg_static_accessor_SELF_146583524fe1469b: function() {
1235
+ const A = typeof self > "u" ? null : self;
1236
+ return H(A) ? 0 : q(A);
1237
+ },
1238
+ __wbg_static_accessor_WINDOW_f2829a2234d7819e: function() {
1239
+ const A = typeof window > "u" ? null : window;
1240
+ return H(A) ? 0 : q(A);
1241
+ },
1242
+ __wbg_statusText_9f08c32741a99815: function(A, I) {
1243
+ const g = I.statusText, B = F(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = R;
1244
+ Y().setInt32(A + 4, E, true), Y().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 = F(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = R;
1263
+ Y().setInt32(A + 4, E, true), Y().setInt32(A + 0, B, true);
1264
+ },
1265
+ __wbg_userAgent_0558f0ac642f7771: function() {
1266
+ return o(function(A, I) {
1267
+ const g = I.userAgent, B = F(g, C.__wbindgen_malloc, C.__wbindgen_realloc), E = R;
1268
+ Y().setInt32(A + 4, E, true), Y().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, ZA);
1282
+ },
1283
+ __wbindgen_cast_0000000000000002: function(A, I) {
1284
+ return s(A, I, LA);
1285
+ },
1286
+ __wbindgen_cast_0000000000000003: function(A, I) {
1287
+ return s(A, I, sA);
1288
+ },
1289
+ __wbindgen_cast_0000000000000004: function(A, I) {
1290
+ return s(A, I, qA);
1291
+ },
1292
+ __wbindgen_cast_0000000000000005: function(A, I) {
1293
+ return s(A, I, dA);
1294
+ },
1295
+ __wbindgen_cast_0000000000000006: function(A, I) {
1296
+ return s(A, I, HA);
1297
+ },
1298
+ __wbindgen_cast_0000000000000007: function(A, I) {
1299
+ return s(A, I, SA);
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 HA(Q, A) {
1315
+ C.wasm_bindgen__convert__closures_____invoke__h38edb88495230029(Q, A);
1316
+ }
1317
+ function SA(Q, A) {
1318
+ C.wasm_bindgen__convert__closures_____invoke__h59fff34e32ed8cec(Q, A);
1319
+ }
1320
+ function LA(Q, A, I) {
1321
+ C.wasm_bindgen__convert__closures_____invoke__h64a57be2ca3e0d69(Q, A, I);
1322
+ }
1323
+ function sA(Q, A, I) {
1324
+ C.wasm_bindgen__convert__closures_____invoke__h64a57be2ca3e0d69_2(Q, A, I);
1325
+ }
1326
+ function qA(Q, A, I) {
1327
+ C.wasm_bindgen__convert__closures_____invoke__h64a57be2ca3e0d69_3(Q, A, I);
1328
+ }
1329
+ function ZA(Q, A, I) {
1330
+ const g = C.wasm_bindgen__convert__closures_____invoke__hfbb046a5343bcac9(Q, A, I);
1331
+ if (g[1])
1332
+ throw p(g[0]);
1333
+ }
1334
+ function pA(Q, A, I, g) {
1335
+ C.wasm_bindgen__convert__closures_____invoke__h4cc111f3c9bb2945(Q, A, I, g);
1336
+ }
1337
+ function dA(Q, A, I, g, B) {
1338
+ C.wasm_bindgen__convert__closures_____invoke__h777de2c1fe9da8ab(Q, A, I, g, B);
1339
+ }
1340
+ const VA = ["blob", "arraybuffer"], $ = typeof FinalizationRegistry > "u" ? { register: () => {
1341
+ }, unregister: () => {
1342
+ } } : new FinalizationRegistry((Q) => C.__wbg_clipboarddata_free(Q, 1)), wA = typeof FinalizationRegistry > "u" ? { register: () => {
1343
+ }, unregister: () => {
1344
+ } } : new FinalizationRegistry((Q) => C.__wbg_clipboarditem_free(Q, 1)), AA = typeof FinalizationRegistry > "u" ? { register: () => {
1345
+ }, unregister: () => {
1346
+ } } : new FinalizationRegistry((Q) => C.__wbg_desktopsize_free(Q, 1)), GA = typeof FinalizationRegistry > "u" ? { register: () => {
1347
+ }, unregister: () => {
1348
+ } } : new FinalizationRegistry((Q) => C.__wbg_deviceevent_free(Q, 1)), oA = typeof FinalizationRegistry > "u" ? { register: () => {
1349
+ }, unregister: () => {
1350
+ } } : new FinalizationRegistry((Q) => C.__wbg_extension_free(Q, 1)), NA = typeof FinalizationRegistry > "u" ? { register: () => {
1351
+ }, unregister: () => {
1352
+ } } : new FinalizationRegistry((Q) => C.__wbg_inputtransaction_free(Q, 1)), kA = typeof FinalizationRegistry > "u" ? { register: () => {
1353
+ }, unregister: () => {
1354
+ } } : new FinalizationRegistry((Q) => C.__wbg_ironerror_free(Q, 1)), RA = typeof FinalizationRegistry > "u" ? { register: () => {
1355
+ }, unregister: () => {
1356
+ } } : new FinalizationRegistry((Q) => C.__wbg_rdcleanpathdetails_free(Q, 1)), FA = typeof FinalizationRegistry > "u" ? { register: () => {
1357
+ }, unregister: () => {
1358
+ } } : new FinalizationRegistry((Q) => C.__wbg_rdpfile_free(Q, 1)), yA = typeof FinalizationRegistry > "u" ? { register: () => {
1359
+ }, unregister: () => {
1360
+ } } : new FinalizationRegistry((Q) => C.__wbg_session_free(Q, 1)), IA = typeof FinalizationRegistry > "u" ? { register: () => {
1361
+ }, unregister: () => {
1362
+ } } : new FinalizationRegistry((Q) => C.__wbg_sessionbuilder_free(Q, 1)), YA = typeof FinalizationRegistry > "u" ? { register: () => {
1363
+ }, unregister: () => {
1364
+ } } : new FinalizationRegistry((Q) => C.__wbg_sessionterminationinfo_free(Q, 1));
1365
+ function q(Q) {
1366
+ const A = C.__externref_table_alloc();
1367
+ return C.__wbindgen_externrefs.set(A, Q), A;
1368
+ }
1369
+ function MA(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 x(Q, A) {
1373
+ if (!(Q instanceof A))
1374
+ throw new Error(`expected instance of ${A.name}`);
1375
+ }
1376
+ const JA = typeof FinalizationRegistry > "u" ? { register: () => {
1377
+ }, unregister: () => {
1378
+ } } : new FinalizationRegistry((Q) => C.__wbindgen_destroy_closure(Q.a, Q.b));
1379
+ function QA(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 += QA(Q[0]));
1397
+ for (let D = 1; D < B; D++)
1398
+ E += ", " + QA(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 OA(Q, A) {
1417
+ Q = Q >>> 0;
1418
+ const I = Y(), 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 WA(Q, A) {
1424
+ return Q = Q >>> 0, tA().subarray(Q / 4, Q / 4 + A);
1425
+ }
1426
+ function m(Q, A) {
1427
+ return Q = Q >>> 0, t().subarray(Q / 1, Q / 1 + A);
1428
+ }
1429
+ function xA(Q, A) {
1430
+ return Q = Q >>> 0, lA().subarray(Q / 1, Q / 1 + A);
1431
+ }
1432
+ let Z = null;
1433
+ function Y() {
1434
+ return (Z === null || Z.buffer.detached === true || Z.buffer.detached === void 0 && Z.buffer !== C.memory.buffer) && (Z = new DataView(C.memory.buffer)), Z;
1435
+ }
1436
+ function y(Q, A) {
1437
+ return bA(Q >>> 0, A);
1438
+ }
1439
+ let b = null;
1440
+ function tA() {
1441
+ return (b === null || b.byteLength === 0) && (b = new Uint32Array(C.memory.buffer)), b;
1442
+ }
1443
+ let T = null;
1444
+ function t() {
1445
+ return (T === null || T.byteLength === 0) && (T = new Uint8Array(C.memory.buffer)), T;
1446
+ }
1447
+ let X = null;
1448
+ function lA() {
1449
+ return (X === null || X.byteLength === 0) && (X = new Uint8ClampedArray(C.memory.buffer)), X;
1450
+ }
1451
+ function o(Q, A) {
1452
+ try {
1453
+ return Q.apply(this, A);
1454
+ } catch (I) {
1455
+ const g = q(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, JA.unregister(g));
1475
+ }, JA.register(B, g, g), B;
1476
+ }
1477
+ function mA(Q, A) {
1478
+ const I = A(Q.length * 1, 1) >>> 0;
1479
+ return t().set(Q, I / 1), R = Q.length, I;
1480
+ }
1481
+ function F(Q, A, I) {
1482
+ if (I === void 0) {
1483
+ const i = f.encode(Q), w = A(i.length, 1) >>> 0;
1484
+ return t().subarray(w, w + i.length).set(i), R = i.length, w;
1485
+ }
1486
+ let g = Q.length, B = A(g, 1) >>> 0;
1487
+ const E = t();
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 = t().subarray(B + D, B + g), w = f.encodeInto(Q, i);
1497
+ D += w.written, B = I(B, g, D, 1) >>> 0;
1498
+ }
1499
+ return R = D, B;
1500
+ }
1501
+ function p(Q) {
1502
+ const A = C.__wbindgen_externrefs.get(Q);
1503
+ return C.__externref_table_dealloc(Q), A;
1504
+ }
1505
+ let u = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true });
1506
+ u.decode();
1507
+ const jA = 2146435072;
1508
+ let gA = 0;
1509
+ function bA(Q, A) {
1510
+ return gA += A, gA >= jA && (u = new TextDecoder("utf-8", { ignoreBOM: true, fatal: true }), u.decode(), gA = A), u.decode(t().subarray(Q, Q + A));
1511
+ }
1512
+ const f = new TextEncoder();
1513
+ "encodeInto" in f || (f.encodeInto = function(Q, A) {
1514
+ const I = f.encode(Q);
1515
+ return A.set(I), {
1516
+ read: Q.length,
1517
+ written: I.length
1518
+ };
1519
+ });
1520
+ let R = 0, C;
1521
+ function TA(Q, A) {
1522
+ return C = __trdWatchExports(Q.exports), Z = null, b = null, T = null, X = null, C.__wbindgen_start(), C;
1523
+ }
1524
+ async function XA(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 fA(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 = aA();
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 XA(await Q, A);
1557
+ return TA(I);
1558
+ }
1559
+ const rA = "avc1.640033";
1560
+ function KA() {
1561
+ return {
1562
+ codec: rA,
1563
+ optimizeForLatency: true,
1564
+ hardwareAcceleration: "no-preference",
1565
+ colorSpace: { primaries: "bt709", transfer: "bt709", matrix: "bt709", fullRange: true }
1566
+ };
1567
+ }
1568
+ async function EI() {
1569
+ if (typeof VideoDecoder > "u" || typeof EncodedVideoChunk > "u")
1570
+ return false;
1571
+ try {
1572
+ return (await VideoDecoder.isConfigSupported(KA())).supported === true;
1573
+ } catch {
1574
+ return false;
1575
+ }
1576
+ }
1577
+ const _M = class _M {
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
+ /** Decoders of surfaces whose streams ended, bringing out the frames given to them before they close. */
1599
+ __publicField(this, "retiring", /* @__PURE__ */ new Set());
1600
+ /** Surfaces waiting for their first key frame; bounded independently of browser decoders. */
1601
+ __publicField(this, "waitingForKey", /* @__PURE__ */ new Map());
1602
+ __publicField(this, "maxDecoders");
1603
+ /** The bytes of H.264 in the decoders: the access units of the pending frames. */
1604
+ __publicField(this, "pendingBytes", 0);
1605
+ /** The bytes the pictures being read back are read into: the RGBA of their frames' regions. */
1606
+ __publicField(this, "readbackBytes", 0);
1607
+ /** Full decoded pictures retained by async copies, independently of their dirty regions' size. */
1608
+ __publicField(this, "readbackPictures", /* @__PURE__ */ new Set());
1609
+ __publicField(this, "readbackPixels", 0);
1610
+ /** How fast decoders open, for all surfaces together (see `SESSION_OPENS`). */
1611
+ __publicField(this, "opens");
1612
+ /** How fast decoders open for each surface (see `SURFACE_OPENS`), kept while a surface's count matters. */
1613
+ __publicField(this, "surfaceOpens", /* @__PURE__ */ new Map());
1614
+ __publicField(this, "stallMs");
1615
+ __publicField(this, "now");
1616
+ __publicField(this, "watchdog", null);
1617
+ __publicField(this, "canvas", null);
1618
+ __publicField(this, "closed", false);
1619
+ if (this.options = A, this.maxDecoders = A.maxDecoders ?? _M.MAX_DECODERS, !Number.isInteger(this.maxDecoders) || this.maxDecoders < 1 || this.maxDecoders > _M.MAX_DECODERS)
1620
+ throw new RangeError("maxDecoders must be an integer from 1 to 32");
1621
+ this.stallMs = A.stallMs ?? 3e3, this.now = A.now ?? (() => performance.now()), this.opens = new UA(_M.SESSION_OPENS, this.now());
1622
+ }
1623
+ decode(A, I) {
1624
+ if (this.failed !== null || this.closed) {
1625
+ I(A.id, null, this.failed ?? "the H.264 decoder is closed");
1626
+ return;
1627
+ }
1628
+ this.watchdog ?? (this.watchdog = setInterval(() => this.checkStalls(), Math.min(250, this.stallMs))), this.endSurfaces(A.endedSurfaces ?? []);
1629
+ let g = this.surfaces.get(A.surfaceId);
1630
+ if (g === void 0) {
1631
+ if (!A.keyFrame) {
1632
+ !this.waitingForKey.has(A.surfaceId) && this.waitingForKey.size < this.maxDecoders && this.waitingForKey.set(A.surfaceId, this.now()), this.stats.skipped++, I(A.id, null);
1633
+ return;
1634
+ }
1635
+ if (this.waitingForKey.delete(A.surfaceId), this.surfaces.size + this.retiring.size >= this.maxDecoders) {
1636
+ this.fail(`H.264 for more than ${this.maxDecoders} surfaces at once`), I(A.id, null, this.failed ?? void 0);
1637
+ return;
1638
+ }
1639
+ const w = this.countOpen(A.surfaceId);
1640
+ if (w !== null) {
1641
+ this.fail(w), I(A.id, null, this.failed ?? void 0);
1642
+ return;
1643
+ }
1644
+ g = this.open(A.surfaceId);
1645
+ }
1646
+ const B = A.data.byteLength;
1647
+ if (g.pending.size >= _M.MAX_PENDING_FRAMES) {
1648
+ this.fail(`more than ${_M.MAX_PENDING_FRAMES} frames in a decoder`), I(A.id, null, this.failed ?? void 0);
1649
+ return;
1650
+ }
1651
+ if (this.pendingBytes + B > _M.MAX_PENDING_BYTES) {
1652
+ this.fail(
1653
+ `more than ${_M.MAX_PENDING_BYTES / (1024 * 1024)} MiB of H.264 in the decoders`
1654
+ ), I(A.id, null, this.failed ?? void 0);
1655
+ return;
1656
+ }
1657
+ A.keyFrame && this.stats.keyFrames++;
1658
+ const { id: E, destination: D, regions: i } = A;
1659
+ g.pending.set(E, { frame: { id: E, destination: D, regions: i }, done: I, since: this.now(), bytes: B }), this.stats.pending++, this.pendingBytes += B;
1660
+ try {
1661
+ g.decoder.decode(
1662
+ new EncodedVideoChunk({
1663
+ type: A.keyFrame ? "key" : "delta",
1664
+ timestamp: A.id,
1665
+ data: A.data
1666
+ })
1667
+ );
1668
+ } catch (w) {
1669
+ this.fail(`decode: ${BA(w)}`);
1670
+ }
1671
+ }
1672
+ close() {
1673
+ this.closed = true, this.stopWatchdog();
1674
+ for (const A of [...this.surfaces.values(), ...this.retiring])
1675
+ e(A.decoder);
1676
+ this.surfaces.clear(), this.retiring.clear(), this.waitingForKey.clear(), this.stats.pending = 0, this.pendingBytes = 0, this.clearReadbacks(), this.canvas = null;
1677
+ }
1678
+ /** Releases streams as soon as their surfaces end, including when no later H.264 frame arrives. */
1679
+ endSurfaces(A) {
1680
+ for (const I of A)
1681
+ this.waitingForKey.delete(I), this.retire(I);
1682
+ }
1683
+ /**
1684
+ * Counts a decoder opening for the surface; says why it may not instead, when that is faster than `SURFACE_OPENS`
1685
+ * or `SESSION_OPENS` allow.
1686
+ */
1687
+ countOpen(A) {
1688
+ const I = this.now();
1689
+ let g = this.surfaceOpens.get(A);
1690
+ if (g === void 0) {
1691
+ if (this.surfaceOpens.size >= _M.MAX_DECODERS)
1692
+ for (const [B, E] of this.surfaceOpens)
1693
+ E.rested(I) && this.surfaceOpens.delete(B);
1694
+ g = new UA(_M.SURFACE_OPENS, I), this.surfaceOpens.set(A, g);
1695
+ }
1696
+ if (!g.take(I)) {
1697
+ const { inARow: B, perSecond: E } = _M.SURFACE_OPENS;
1698
+ return `H.264 decoders opened for surface ${A} faster than ${B} in a row and ${E} a second`;
1699
+ }
1700
+ if (!this.opens.take(I)) {
1701
+ const { inARow: B, perSecond: E } = _M.SESSION_OPENS;
1702
+ return `H.264 decoders opened faster than ${B} in a row and ${E} a second`;
1703
+ }
1704
+ return null;
1705
+ }
1706
+ open(A) {
1707
+ const I = {
1708
+ decoder: new VideoDecoder({
1709
+ output: (g) => this.output(I, g),
1710
+ error: (g) => {
1711
+ this.reclaimed = g.name === "QuotaExceededError", this.fail(BA(g));
1712
+ }
1713
+ }),
1714
+ pending: /* @__PURE__ */ new Map()
1715
+ };
1716
+ return I.decoder.configure(KA()), this.surfaces.set(A, I), I;
1717
+ }
1718
+ /** The server is done with a surface: its decoder closes once the frames given to it are out. */
1719
+ retire(A) {
1720
+ const I = this.surfaces.get(A);
1721
+ if (I === void 0)
1722
+ return;
1723
+ if (this.surfaces.delete(A), I.pending.size === 0) {
1724
+ e(I.decoder);
1725
+ return;
1726
+ }
1727
+ this.retiring.add(I);
1728
+ const g = () => {
1729
+ if (this.retiring.delete(I)) {
1730
+ for (const B of [...I.pending.values()])
1731
+ this.settle(I, B), this.stats.dropped++, B.done(B.frame.id, null);
1732
+ e(I.decoder);
1733
+ }
1734
+ };
1735
+ try {
1736
+ I.decoder.flush().then(g, g);
1737
+ } catch {
1738
+ g();
1739
+ }
1740
+ }
1741
+ output(A, I) {
1742
+ const g = I.timestamp, B = A.pending.get(g);
1743
+ if (B === void 0 || this.failed !== null || this.closed) {
1744
+ I.close();
1745
+ return;
1746
+ }
1747
+ const E = I.codedWidth * I.codedHeight;
1748
+ if (!Number.isSafeInteger(E) || E <= 0 || E > _M.MAX_PICTURE_PIXELS) {
1749
+ I.close(), this.fail("decoded H.264 picture exceeds the pixel budget");
1750
+ return;
1751
+ }
1752
+ for (const [w, G] of A.pending) {
1753
+ if (w >= g)
1754
+ break;
1755
+ this.settle(A, G), this.stats.dropped++, G.done(w, null);
1756
+ }
1757
+ this.settle(A, B);
1758
+ const D = B.frame.regions.reduce((w, G) => w + (G.right - G.left) * (G.bottom - G.top) * 4, 0);
1759
+ if (this.readbackPictures.size >= _M.MAX_READBACKS) {
1760
+ I.close(), this.fail(`more than ${_M.MAX_READBACKS} pictures being read back`), B.done(g, null, this.failed ?? void 0);
1761
+ return;
1762
+ }
1763
+ if (this.readbackBytes + D > _M.MAX_READBACK_BYTES) {
1764
+ I.close(), this.fail(
1765
+ `more than ${_M.MAX_READBACK_BYTES / (1024 * 1024)} MiB of pictures being read back`
1766
+ ), B.done(g, null, this.failed ?? void 0);
1767
+ return;
1768
+ }
1769
+ if (this.readbackPixels + E > _M.MAX_READBACK_PIXELS) {
1770
+ I.close(), this.fail("more than 128 Mi pixels of decoded pictures being read back"), B.done(g, null, this.failed ?? void 0);
1771
+ return;
1772
+ }
1773
+ this.readbackBytes += D, this.readbackPixels += E, this.readbackPictures.add(I);
1774
+ const i = () => {
1775
+ this.readbackPictures.delete(I) && (this.readbackBytes -= D, this.readbackPixels -= E);
1776
+ };
1777
+ this.readRegions(I, B.frame).then(
1778
+ (w) => {
1779
+ if (I.close(), i(), this.failed !== null || this.closed)
1780
+ return;
1781
+ const G = this.now() - B.since;
1782
+ this.stats.frames++, B.frame.regions.length === 0 && this.stats.auxiliary++, this.stats.lastLatencyMs = G, this.stats.maxLatencyMs = Math.max(this.stats.maxLatencyMs, G), B.done(g, w);
1783
+ },
1784
+ (w) => {
1785
+ I.close(), i(), !(this.failed !== null || this.closed) && (this.fail(`reading the picture: ${BA(w)}`), B.done(g, null, this.failed ?? void 0));
1786
+ }
1787
+ );
1788
+ }
1789
+ /** Takes a frame out of the pending ones. */
1790
+ settle(A, I) {
1791
+ A.pending.delete(I.frame.id), this.stats.pending--, this.pendingBytes -= I.bytes;
1792
+ }
1793
+ /** The RGBA of the frame's regions, in turn. */
1794
+ async readRegions(A, I) {
1795
+ 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((N) => ({
1796
+ x: N.left - E,
1797
+ y: N.top - D,
1798
+ width: N.right - N.left,
1799
+ height: N.bottom - N.top
1800
+ }));
1801
+ for (const N of i)
1802
+ if (N.x < 0 || N.y < 0 || N.x + N.width > g.width || N.y + N.height > g.height)
1803
+ throw new Error(
1804
+ `region ${JSON.stringify(N)} is outside the ${g.width}x${g.height} picture`
1805
+ );
1806
+ const w = i.reduce((N, L) => N + L.width * L.height * 4, 0), G = new Uint8Array(w);
1807
+ if (i.length === 0)
1808
+ return G;
1809
+ let [a, U, c, O] = [1 / 0, 1 / 0, -1 / 0, -1 / 0];
1810
+ for (const N of i)
1811
+ a = Math.min(a, N.x), U = Math.min(U, N.y), c = Math.max(c, N.x + N.width), O = Math.max(O, N.y + N.height);
1812
+ const S = { x: a, y: U, width: c - a, height: O - U };
1813
+ if (i.length === 1)
1814
+ return await this.readBox(A, g, S, G), G;
1815
+ if (S.width * S.height * 4 > w * _M.BOX_WASTE) {
1816
+ let N = 0;
1817
+ for (const L of i) {
1818
+ const W = L.width * L.height * 4;
1819
+ await this.readBox(A, g, L, G.subarray(N, N + W)), N += W;
1820
+ }
1821
+ return G;
1822
+ }
1823
+ const CA = new Uint8Array(S.width * S.height * 4);
1824
+ await this.readBox(A, g, S, CA);
1825
+ let EA = 0;
1826
+ for (const N of i) {
1827
+ const L = N.width * 4;
1828
+ for (let W = 0; W < N.height; W++) {
1829
+ const DA = ((N.y - S.y + W) * S.width + (N.x - S.x)) * 4;
1830
+ G.set(CA.subarray(DA, DA + L), EA), EA += L;
1831
+ }
1832
+ }
1833
+ return G;
1834
+ }
1835
+ async readBox(A, I, g, B) {
1836
+ if (this.failed !== null || this.closed)
1837
+ throw new Error("the H.264 decoder is closed");
1838
+ if (this.stats.readback === "copyTo") {
1839
+ const D = { x: I.x + g.x, y: I.y + g.y, width: g.width, height: g.height };
1840
+ try {
1841
+ if (A.allocationSize({ rect: D, format: "RGBA" }) === g.width * g.height * 4) {
1842
+ await A.copyTo(B, { rect: D, format: "RGBA", colorSpace: "srgb" });
1843
+ return;
1844
+ }
1845
+ this.stats.readback = "canvas";
1846
+ } catch (i) {
1847
+ if (!(i instanceof DOMException && i.name === "NotSupportedError") && !(i instanceof TypeError))
1848
+ throw i;
1849
+ this.stats.readback = "canvas";
1850
+ }
1851
+ }
1852
+ if (this.failed !== null || this.closed)
1853
+ throw new Error("the H.264 decoder is closed");
1854
+ (this.canvas === null || this.canvas.width < g.width || this.canvas.height < g.height) && (this.canvas = new OffscreenCanvas(g.width, g.height));
1855
+ const E = this.canvas.getContext("2d", { willReadFrequently: true, colorSpace: "srgb" });
1856
+ if (E === null)
1857
+ throw new Error("no 2D canvas context");
1858
+ E.drawImage(A, -g.x, -g.y, I.width, I.height), B.set(E.getImageData(0, 0, g.width, g.height).data);
1859
+ }
1860
+ clearReadbacks() {
1861
+ for (const A of this.readbackPictures)
1862
+ A.close();
1863
+ this.readbackPictures.clear(), this.readbackBytes = 0, this.readbackPixels = 0;
1864
+ }
1865
+ stopWatchdog() {
1866
+ this.watchdog !== null && (clearInterval(this.watchdog), this.watchdog = null);
1867
+ }
1868
+ checkStalls() {
1869
+ if (this.failed !== null || this.closed)
1870
+ return;
1871
+ const A = this.now();
1872
+ for (const I of this.waitingForKey.values())
1873
+ if (A - I > this.stallMs) {
1874
+ this.fail(`no key frame for ${Math.round(A - I)} ms`);
1875
+ return;
1876
+ }
1877
+ for (const I of [...this.surfaces.values(), ...this.retiring])
1878
+ for (const g of I.pending.values())
1879
+ if (A - g.since > this.stallMs) {
1880
+ this.fail(`no picture from the decoder for ${Math.round(A - g.since)} ms`);
1881
+ return;
1882
+ }
1883
+ }
1884
+ /** Fails for good: every frame in flight completes with the error, which ends the session. */
1885
+ fail(A) {
1886
+ var _a, _b;
1887
+ if (this.failed !== null || this.closed)
1888
+ return;
1889
+ this.failed = A, this.stopWatchdog();
1890
+ const I = [...this.surfaces.values(), ...this.retiring], g = I.flatMap((B) => [...B.pending.values()]);
1891
+ for (const B of I)
1892
+ e(B.decoder);
1893
+ this.surfaces.clear(), this.retiring.clear(), this.waitingForKey.clear(), this.stats.pending = 0, this.pendingBytes = 0, this.clearReadbacks(), this.canvas = null, (_b = (_a = this.options).onFailure) == null ? void 0 : _b.call(_a, A);
1894
+ for (const { frame: B, done: E } of g)
1895
+ E(B.id, null, A);
1896
+ }
1897
+ };
1898
+ /**
1899
+ * The most decoders at once. Servers stream H.264 to a surface per monitor, and a session has 16 monitors at most
1900
+ * (MS-RDPBCGR 2.2.1.3.6); after a reset, the decoders of the surfaces it destroyed may still be finishing their
1901
+ * frames while those of the new ones start.
1902
+ */
1903
+ __publicField(_M, "MAX_DECODERS", 32);
1904
+ /**
1905
+ * How fast one surface's decoders may open: 16 in a row, then 4 a second. A decoder opens for a surface's first
1906
+ * frame, and again for its first frame after its stream ended (the surface deleted, created again or destroyed by
1907
+ * a reset), which servers do when they resize its monitor: a few times in a row at most, and not several times a
1908
+ * second for long. Opening a `VideoDecoder` and closing the one before takes the page's thread about 44
1909
+ * microseconds (Chrome, software decoding), so a server that created a surface again before each of its frames
1910
+ * had that done for every frame: 32,768 times for one message of 90 KB on the wire, which froze the page, and
1911
+ * every session in it, for 1.4 s, message after message.
1912
+ */
1913
+ __publicField(_M, "SURFACE_OPENS", { inARow: 16, perSecond: 4 });
1914
+ /**
1915
+ * How fast decoders may open for all surfaces together: 128 in a row, then 32 a second. That is each of 16
1916
+ * monitors (MS-RDPBCGR 2.2.1.3.6) resized eight times in a row, then twice a second, and opening that many takes
1917
+ * the page's thread under 6 ms, then under 1.5 ms a second.
1918
+ */
1919
+ __publicField(_M, "SESSION_OPENS", { inARow: 128, perSecond: 32 });
1920
+ /**
1921
+ * The most frames one decoder may hold. A decoder keeps up with its stream, so frames wait in it about as long as
1922
+ * one takes to decode, and the server stops at its unacknowledged frames: 256 is over two seconds of 60 Hz AVC444
1923
+ * (two access units a frame), and a frame that waits longer than `stallMs` (3 s) fails the decoder anyway.
1924
+ */
1925
+ __publicField(_M, "MAX_PENDING_FRAMES", 256);
1926
+ /**
1927
+ * The most bytes of H.264 the decoders may hold at once: over a second at the highest bitrate any H.264 level
1928
+ * allows (level 6.2, High profile: 1,000 Mbit/s), where servers send a few to tens of Mbit/s.
1929
+ */
1930
+ __publicField(_M, "MAX_PENDING_BYTES", 128 * 1024 * 1024);
1931
+ /**
1932
+ * The most bytes the pictures being read back may be read into at once: the RGBA of their frames' regions. A
1933
+ * picture is read back as it comes out, while its decoder goes on, so readbacks overlap when pictures come out
1934
+ * faster than they are read. This is two of the largest frames ironrdp-egfx reads back (256 MiB, what its
1935
+ * compositor holds), or four whole 8K pictures (7680x4320, 127 MiB each). Regions read back as their bounding box
1936
+ * take the box as well while it is read, at most twice what they hold.
1937
+ */
1938
+ __publicField(_M, "MAX_READBACK_BYTES", 512 * 1024 * 1024);
1939
+ __publicField(_M, "MAX_READBACKS", 64);
1940
+ __publicField(_M, "MAX_PICTURE_PIXELS", 64 * 1024 * 1024);
1941
+ /** Four whole 8K pictures, or 512 MiB at four bytes per coded pixel, regardless of dirty-region size. */
1942
+ __publicField(_M, "MAX_READBACK_PIXELS", 128 * 1024 * 1024);
1943
+ /** A bounding box may be this many times what its regions hold before they are read one by one instead. */
1944
+ __publicField(_M, "BOX_WASTE", 2);
1945
+ let M = _M;
1946
+ class UA {
1947
+ constructor(A, I) {
1948
+ __publicField(this, "allowance");
1949
+ __publicField(this, "at");
1950
+ this.limit = A, this.allowance = A.inARow, this.at = I;
1951
+ }
1952
+ /** Counts one more time, unless the limit allows none now. */
1953
+ take(A) {
1954
+ return this.catchUp(A), this.allowance < 1 ? false : (this.allowance -= 1, true);
1955
+ }
1956
+ /** Whether all of the allowance is back, as if nothing had been counted. */
1957
+ rested(A) {
1958
+ return this.catchUp(A), this.allowance >= this.limit.inARow;
1959
+ }
1960
+ catchUp(A) {
1961
+ if (A > this.at) {
1962
+ const I = (A - this.at) * this.limit.perSecond / 1e3;
1963
+ this.allowance = Math.min(this.limit.inARow, this.allowance + I), this.at = A;
1964
+ }
1965
+ }
1966
+ }
1967
+ function e(Q) {
1968
+ if (Q.state !== "closed")
1969
+ try {
1970
+ Q.close();
1971
+ } catch {
1972
+ }
1973
+ }
1974
+ function BA(Q) {
1975
+ return Q instanceof Error || Q instanceof DOMException ? `${Q.name}: ${Q.message}` : String(Q);
1976
+ }
1977
+ const j = {
1978
+ /**
1979
+ * Request file size (8-byte unsigned integer).
1980
+ * When set: position must be 0, size must be 8.
1981
+ */
1982
+ SIZE: 1,
1983
+ /**
1984
+ * Request byte range from file.
1985
+ * When set: position and size define the requested range.
1986
+ */
1987
+ RANGE: 2
1988
+ };
1989
+ function nA(Q) {
1990
+ return new k("files_available_callback", Q);
1991
+ }
1992
+ function zA(Q) {
1993
+ return new k("file_contents_request_callback", Q);
1994
+ }
1995
+ function PA(Q) {
1996
+ return new k("file_contents_response_callback", Q);
1997
+ }
1998
+ function vA(Q) {
1999
+ return new k("lock_callback", Q);
2000
+ }
2001
+ function eA(Q) {
2002
+ return new k("unlock_callback", Q);
2003
+ }
2004
+ function uA(Q) {
2005
+ return new k("locks_expired_callback", Q);
2006
+ }
2007
+ function _A(Q) {
2008
+ return new k("format_list_response_callback", Q);
2009
+ }
2010
+ const DI = {
2011
+ PostScript: "MS Publisher Imagesetter",
2012
+ MicrosoftPrintToPdf: "Microsoft Print to PDF"
2013
+ };
2014
+ function iI(Q) {
2015
+ return new k("print_job_stream_callbacks", Q);
2016
+ }
2017
+ function wI(Q) {
2018
+ return new k("printer_name", Q);
2019
+ }
2020
+ function GI(Q) {
2021
+ return new k("printer_device_id", Q);
2022
+ }
2023
+ function oI(Q) {
2024
+ return new k("printer_driver_name", Q);
2025
+ }
2026
+ function $A(Q) {
2027
+ return new k("request_file_contents", Q);
2028
+ }
2029
+ function AI(Q) {
2030
+ return new k("submit_file_contents", Q);
2031
+ }
2032
+ function II(Q) {
2033
+ return new k("initiate_file_copy", Q);
2034
+ }
2035
+ class gI {
2036
+ constructor() {
2037
+ __publicField(this, "chunks", []);
2038
+ __publicField(this, "_bytesWritten", 0);
2039
+ __publicField(this, "finalized", false);
2040
+ }
2041
+ get bytesWritten() {
2042
+ return this._bytesWritten;
2043
+ }
2044
+ async write(A) {
2045
+ if (this.finalized)
2046
+ throw new Error("BlobWriteHandle: write after finalize/abort");
2047
+ this.chunks.push(A), this._bytesWritten += A.length;
2048
+ }
2049
+ async finalize() {
2050
+ if (this.finalized)
2051
+ throw new Error("BlobWriteHandle: already finalized or aborted");
2052
+ this.finalized = true;
2053
+ const A = new Blob(this.chunks);
2054
+ return this.chunks = [], A;
2055
+ }
2056
+ async abort() {
2057
+ this.finalized || (this.finalized = true, this.chunks = []);
2058
+ }
2059
+ }
2060
+ class cA {
2061
+ constructor() {
2062
+ __publicField(this, "name", "blob");
2063
+ }
2064
+ async createWriteHandle(A, I) {
2065
+ return new gI();
2066
+ }
2067
+ async dispose() {
2068
+ }
2069
+ }
2070
+ class BI {
2071
+ constructor(A, I, g, B) {
2072
+ __publicField(this, "writable");
2073
+ __publicField(this, "_bytesWritten", 0);
2074
+ __publicField(this, "finalized", false);
2075
+ this.fileHandle = A, this.sessionDir = I, this.entryName = g, this.writable = B;
2076
+ }
2077
+ get bytesWritten() {
2078
+ return this._bytesWritten;
2079
+ }
2080
+ async write(A) {
2081
+ if (this.finalized || !this.writable)
2082
+ throw new Error("OpfsWriteHandle: write after finalize/abort");
2083
+ await this.writable.write(A), this._bytesWritten += A.length;
2084
+ }
2085
+ async finalize() {
2086
+ if (this.finalized)
2087
+ throw new Error("OpfsWriteHandle: already finalized or aborted");
2088
+ return this.finalized = true, this.writable && (await this.writable.close(), this.writable = void 0), this.fileHandle.getFile();
2089
+ }
2090
+ async abort() {
2091
+ if (!this.finalized) {
2092
+ if (this.finalized = true, this.writable) {
2093
+ try {
2094
+ await this.writable.abort();
2095
+ } catch {
2096
+ }
2097
+ this.writable = void 0;
2098
+ }
2099
+ try {
2100
+ await this.sessionDir.removeEntry(this.entryName);
2101
+ } catch {
2102
+ }
2103
+ }
2104
+ }
2105
+ }
2106
+ const _l = class _l {
2107
+ constructor(A, I, g) {
2108
+ __publicField(this, "name", "opfs");
2109
+ /** Sequence counter for generating unique temp file names. */
2110
+ __publicField(this, "sequence", 0);
2111
+ this.opfsRoot = A, this.sessionDir = I, this.sessionId = g;
2112
+ }
2113
+ /**
2114
+ * Create an OPFS backend, including the per-session directory.
2115
+ *
2116
+ * Call {@link probe} first to verify OPFS is available before
2117
+ * constructing -- this factory assumes OPFS works.
2118
+ */
2119
+ static async create(A, I) {
2120
+ 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 });
2121
+ return _l.cleanupStale(B, g), new _l(A, E, g);
2122
+ }
2123
+ // 24 hours
2124
+ /**
2125
+ * Remove session directories older than {@link STALE_SESSION_THRESHOLD_MS}.
2126
+ *
2127
+ * Session IDs generated by {@link create} embed a timestamp in the
2128
+ * format `s-{Date.now()}-{random}`. This method parses that timestamp
2129
+ * to determine age. Directories with unparsable names or those
2130
+ * belonging to the current session are skipped.
2131
+ */
2132
+ static async cleanupStale(A, I) {
2133
+ const g = Date.now();
2134
+ try {
2135
+ for await (const B of A.keys()) {
2136
+ if (B === I)
2137
+ continue;
2138
+ const E = /^s-(\d+)-/.exec(B);
2139
+ if (!E)
2140
+ continue;
2141
+ const D = Number(E[1]);
2142
+ if (g - D > _l.STALE_SESSION_THRESHOLD_MS)
2143
+ try {
2144
+ await A.removeEntry(B, { recursive: true });
2145
+ } catch {
2146
+ }
2147
+ }
2148
+ } catch {
2149
+ }
2150
+ }
2151
+ /**
2152
+ * Probe whether OPFS is usable in the current context.
2153
+ *
2154
+ * Performs a full round-trip: creates a temp file, opens a writable,
2155
+ * closes it, and deletes it. This catches environments where the API
2156
+ * exists but throws at runtime (e.g., some private browsing modes).
2157
+ */
2158
+ static async probe(A) {
2159
+ try {
2160
+ return await (await (await A.getFileHandle(".ironrdp-opfs-probe", { create: true })).createWritable()).close(), await A.removeEntry(".ironrdp-opfs-probe"), true;
2161
+ } catch {
2162
+ return false;
2163
+ }
2164
+ }
2165
+ async createWriteHandle(A, I) {
2166
+ if (!this.sessionDir)
2167
+ throw new Error("OpfsStorageBackend: backend has been disposed");
2168
+ const B = `${this.sequence++}-${QI(A)}`, E = await this.sessionDir.getFileHandle(B, { create: true }), D = await E.createWritable();
2169
+ return new BI(E, this.sessionDir, B, D);
2170
+ }
2171
+ async dispose() {
2172
+ if (!this.sessionDir)
2173
+ return;
2174
+ const A = this.sessionDir;
2175
+ this.sessionDir = void 0;
2176
+ try {
2177
+ const I = await this.opfsRoot.getDirectoryHandle("ironrdp-transfers");
2178
+ await I.removeEntry(this.sessionId, { recursive: true });
2179
+ let g = false;
2180
+ for await (const B of I.values()) {
2181
+ g = true;
2182
+ break;
2183
+ }
2184
+ g || await this.opfsRoot.removeEntry("ironrdp-transfers");
2185
+ } catch (I) {
2186
+ console.debug("OPFS session directory removal failed, falling back to per-file cleanup:", I);
2187
+ try {
2188
+ for await (const g of A.keys())
2189
+ try {
2190
+ await A.removeEntry(g);
2191
+ } catch {
2192
+ }
2193
+ } catch {
2194
+ }
2195
+ }
2196
+ }
2197
+ };
2198
+ /** Maximum age (in milliseconds) before a session directory is considered stale. */
2199
+ __publicField(_l, "STALE_SESSION_THRESHOLD_MS", 1440 * 60 * 1e3);
2200
+ let l = _l;
2201
+ function QI(Q) {
2202
+ let A = Q.replace(/[\u0000-\u001f]/g, "");
2203
+ A = A.replace(/[/\\]/g, "_"), A = A.replace(/^\.+/, ""), A.length === 0 && (A = "unnamed");
2204
+ const I = new TextEncoder();
2205
+ if (I.encode(A).byteLength > 200) {
2206
+ for (; I.encode(A).byteLength > 200; )
2207
+ A = A.slice(0, -1);
2208
+ A.length === 0 && (A = "unnamed");
2209
+ }
2210
+ return A;
2211
+ }
2212
+ async function CI(Q = "auto", A) {
2213
+ var _a, _b;
2214
+ if (Q === "blob")
2215
+ return new cA();
2216
+ if (typeof ((_b = (_a = globalThis.navigator) == null ? void 0 : _a.storage) == null ? void 0 : _b.getDirectory) == "function")
2217
+ try {
2218
+ const I = await navigator.storage.getDirectory();
2219
+ if (await l.probe(I))
2220
+ return l.create(I, A);
2221
+ console.debug("OPFS probe failed (createWritable not functional), falling back to blob storage");
2222
+ } catch (I) {
2223
+ console.debug("OPFS unavailable, falling back to blob storage:", I);
2224
+ }
2225
+ return new cA();
2226
+ }
2227
+ const _K = class _K {
2228
+ constructor(A) {
2229
+ __publicField(this, "session");
2230
+ __publicField(this, "chunkSize");
2231
+ __publicField(this, "onUploadStarted");
2232
+ __publicField(this, "onUploadFinished");
2233
+ __publicField(this, "storagePreference");
2234
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2235
+ __publicField(this, "eventHandlers", /* @__PURE__ */ new Map());
2236
+ __publicField(this, "storageBackend");
2237
+ __publicField(this, "storageBackendReady");
2238
+ __publicField(this, "activeDownloads", /* @__PURE__ */ new Map());
2239
+ __publicField(this, "uploadState");
2240
+ // Upload paste-window watchdog. Armed when we advertise an upload, disarmed on the
2241
+ // first FileContentsRequest (the remote pulled the files). Being armed is the single
2242
+ // "advertised but not yet pulled" signal: on timeout it resumes monitoring and fails
2243
+ // the never-pulled upload, and handleFormatListResponse consults it to fail a refused
2244
+ // paste early (handleUnlock is a deliberate no-op: Unlock is not a reliable failure
2245
+ // signal). Upload completion/failure run only after that first request, so they need
2246
+ // not touch it.
2247
+ __publicField(this, "pasteAckTimeout");
2248
+ // Upload inactivity watchdog. Armed/reset on each FileContentsRequest once the remote
2249
+ // starts pulling; fires if pulls stop for UPLOAD_INACTIVITY_TIMEOUT_MS (a stalled or
2250
+ // clipboard-superseded paste) to release uploadState. Complements the paste-ack
2251
+ // watchdog above, which only covers the "advertised but never pulled" case.
2252
+ __publicField(this, "uploadInactivityTimeout");
2253
+ // True between onUploadStarted (suppress monitoring) and onUploadFinished
2254
+ // (resume), so resume fires exactly once even though it is now deferred until
2255
+ // the paste is pulled, times out, fails, or the provider is disposed.
2256
+ __publicField(this, "uploadMonitoringSuppressed", false);
2257
+ // DroppedFile metadata retained after upload completes so re-paste works
2258
+ // without re-dropping. Cleared when a new upload starts or the manager is disposed.
2259
+ __publicField(this, "retainedFiles");
2260
+ __publicField(this, "availableFiles", []);
2261
+ // Clipboard lock ID received with the most recent file list. The Rust layer
2262
+ // acquires this lock automatically when FileGroupDescriptorW is detected in
2263
+ // the FormatList. Downloads use it instead of explicit lock/unlock calls -
2264
+ // the lock lifecycle is managed entirely by the Rust cliprdr processor.
2265
+ __publicField(this, "clipDataId");
2266
+ __publicField(this, "nextStreamId", 1);
2267
+ __publicField(this, "disposed", false);
2268
+ 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;
2269
+ const I = A == null ? void 0 : A.storageBackend;
2270
+ if (typeof I == "object" && I !== null) {
2271
+ if (typeof I.createWriteHandle != "function" || typeof I.dispose != "function")
2272
+ throw new Error(
2273
+ "storageBackend: expected 'auto', 'blob', or a FileStorageBackend with createWriteHandle() and dispose() methods"
2274
+ );
2275
+ this.storageBackend = I, this.storagePreference = "auto";
2276
+ } else {
2277
+ const g = I ?? "auto";
2278
+ if (g !== "auto" && g !== "blob")
2279
+ throw new Error(
2280
+ `storageBackend: invalid preference '${g}', expected 'auto', 'blob', or a FileStorageBackend instance`
2281
+ );
2282
+ this.storagePreference = g;
2283
+ }
2284
+ }
2285
+ /**
2286
+ * Set the session instance after connection is established.
2287
+ * Called by the web component's connect() flow via the FileTransferProvider interface.
2288
+ */
2289
+ setSession(A) {
2290
+ this.session = A;
2291
+ }
2292
+ ensureSession() {
2293
+ if (this.session === void 0)
2294
+ throw new Error("RdpFileTransferProvider: Session not available. Ensure connect() has been called.");
2295
+ return this.session;
2296
+ }
2297
+ /**
2298
+ * Lazily initialize and return the storage backend.
2299
+ *
2300
+ * Detection is performed once and cached. Concurrent callers share
2301
+ * the same initialization promise so the probe only runs once.
2302
+ * If detection fails the cached promise is cleared so subsequent
2303
+ * downloads can retry.
2304
+ */
2305
+ async ensureStorageBackend() {
2306
+ return this.storageBackend ? this.storageBackend : (this.storageBackendReady || (this.storageBackendReady = CI(this.storagePreference).then((A) => (this.storageBackend = A, console.debug(`File transfer storage: ${A.name}`), A)).catch((A) => {
2307
+ throw this.storageBackendReady = void 0, A;
2308
+ })), this.storageBackendReady);
2309
+ }
2310
+ // --- Extension-based session method wrappers ---
2311
+ // These replace direct session.requestFileContents() etc. calls
2312
+ // with invokeExtension() to keep the Session interface protocol-agnostic.
2313
+ sendRequestFileContents(A, I, g, B, E, D) {
2314
+ this.ensureSession().invokeExtension(
2315
+ $A({
2316
+ stream_id: A,
2317
+ file_index: I,
2318
+ flags: g,
2319
+ position: B,
2320
+ size: E,
2321
+ clip_data_id: D
2322
+ })
2323
+ );
2324
+ }
2325
+ sendSubmitFileContents(A, I, g) {
2326
+ var _a;
2327
+ (_a = this.session) == null ? void 0 : _a.invokeExtension(AI({ stream_id: A, is_error: I, data: g }));
2328
+ }
2329
+ sendInitiateFileCopy(A) {
2330
+ this.ensureSession().invokeExtension(II(A));
2331
+ }
2332
+ /**
2333
+ * Returns the extension objects to register on the SessionBuilder before connect().
2334
+ * Implements the FileTransferProvider interface.
2335
+ */
2336
+ getBuilderExtensions() {
2337
+ return [
2338
+ nA(
2339
+ (A, I) => this.handleFilesAvailable(A, I)
2340
+ ),
2341
+ zA((A) => this.handleFileContentsRequest(A)),
2342
+ PA((A) => this.handleFileContentsResponse(A)),
2343
+ vA((A) => this.handleLock(A)),
2344
+ eA((A) => this.handleUnlock(A)),
2345
+ uA((A) => this.handleLocksExpired(A)),
2346
+ _A((A) => this.handleFormatListResponse(A))
2347
+ ];
2348
+ }
2349
+ /**
2350
+ * Register an event handler.
2351
+ *
2352
+ * @param event - Event name
2353
+ * @param handler - Event handler function
2354
+ *
2355
+ * @example
2356
+ * ```typescript
2357
+ * manager.on('download-progress', (progress) => {
2358
+ * console.log(`${progress.fileName}: ${progress.percentage}%`);
2359
+ * });
2360
+ * ```
2361
+ */
2362
+ on(A, I) {
2363
+ this.eventHandlers.has(A) || this.eventHandlers.set(A, /* @__PURE__ */ new Set()), this.eventHandlers.get(A).add(I);
2364
+ }
2365
+ /**
2366
+ * Unregister an event handler.
2367
+ *
2368
+ * @param event - Event name
2369
+ * @param handler - Event handler function to remove
2370
+ */
2371
+ off(A, I) {
2372
+ const g = this.eventHandlers.get(A);
2373
+ g && g.delete(I);
2374
+ }
2375
+ /**
2376
+ * Emit an event to all registered handlers.
2377
+ */
2378
+ emit(A, ...I) {
2379
+ const g = this.eventHandlers.get(A);
2380
+ if (g)
2381
+ for (const B of g)
2382
+ try {
2383
+ B(...I);
2384
+ } catch (E) {
2385
+ console.error(`Error in ${A} handler:`, E);
2386
+ }
2387
+ }
2388
+ /**
2389
+ * Download a single file from the remote.
2390
+ *
2391
+ * Returns a {@link DownloadHandle} with a `transferId` available synchronously
2392
+ * (for immediate UI association) and a `completion` promise that resolves with
2393
+ * the downloaded blob.
2394
+ *
2395
+ * @param fileInfo - File metadata from 'files-available' event
2396
+ * @param fileIndex - Index of the file in the original file list
2397
+ * @returns Handle with synchronous transferId and async completion
2398
+ *
2399
+ * @example
2400
+ * ```typescript
2401
+ * const { transferId, completion } = manager.downloadFile(fileInfo, 0);
2402
+ * // transferId is available immediately for UI binding
2403
+ * const blob = await completion;
2404
+ * saveAs(blob, fileInfo.name);
2405
+ * ```
2406
+ */
2407
+ downloadFile(A, I) {
2408
+ const g = this.generateStreamId(), B = this.executeDownload(A, I, g);
2409
+ return { transferId: g, completion: B };
2410
+ }
2411
+ /**
2412
+ * Internal: execute the async download workflow for a single file.
2413
+ */
2414
+ async executeDownload(A, I, g) {
2415
+ const B = this.clipDataId, E = new Promise((D, i) => {
2416
+ const w = {
2417
+ fileInfo: A,
2418
+ fileIndex: I,
2419
+ streamId: g,
2420
+ clipDataId: B,
2421
+ bytesReceived: 0,
2422
+ resolve: D,
2423
+ reject: i
2424
+ };
2425
+ this.activeDownloads.set(g, w);
2426
+ });
2427
+ try {
2428
+ this.sendRequestFileContents(g, I, j.SIZE, 0, 8, B);
2429
+ } catch (D) {
2430
+ this.activeDownloads.delete(g);
2431
+ const i = {
2432
+ message: "Failed to request file size",
2433
+ transferId: g,
2434
+ fileIndex: I,
2435
+ fileName: A.name,
2436
+ direction: "download",
2437
+ cause: D
2438
+ };
2439
+ throw this.emit("error", i), new Error(i.message, { cause: D });
2440
+ }
2441
+ return E;
2442
+ }
2443
+ /**
2444
+ * Download multiple files sequentially.
2445
+ *
2446
+ * @param files - Array of FileInfo from 'files-available' event
2447
+ * @returns AsyncGenerator yielding file/blob pairs as they complete
2448
+ *
2449
+ * @example
2450
+ * ```typescript
2451
+ * for await (const { file, blob } of manager.downloadFiles(files)) {
2452
+ * saveAs(blob, file.name);
2453
+ * }
2454
+ * ```
2455
+ */
2456
+ async *downloadFiles(A) {
2457
+ for (let I = 0; I < A.length; I++) {
2458
+ const g = A[I], { transferId: B, completion: E } = this.downloadFile(g, I), D = await E;
2459
+ yield { file: g, blob: D, transferId: B };
2460
+ }
2461
+ }
2462
+ /**
2463
+ * Download multiple files concurrently with configurable parallelism.
2464
+ *
2465
+ * This method initiates multiple file downloads in parallel, improving
2466
+ * performance for multi-file transfers. Each file uses an independent
2467
+ * clipboard lock and stream ID.
2468
+ *
2469
+ * @param files - Array of FileInfo from 'files-available' event
2470
+ * @param options - Download options
2471
+ * @param options.maxConcurrent - Maximum concurrent downloads (default: 3)
2472
+ * @returns Promise resolving to map of fileIndex to Blob
2473
+ *
2474
+ * @example
2475
+ * ```typescript
2476
+ * const blobs = await manager.downloadFilesConcurrent(files, { maxConcurrent: 5 });
2477
+ * files.forEach((file, i) => saveAs(blobs.get(i)!, file.name));
2478
+ * ```
2479
+ */
2480
+ async downloadFilesConcurrent(A, I = {}) {
2481
+ const g = I.maxConcurrent ?? 3, B = /* @__PURE__ */ new Map(), E = [], D = A.map((w, G) => async () => {
2482
+ try {
2483
+ const { completion: a } = this.downloadFile(w, G), U = await a;
2484
+ B.set(G, U);
2485
+ } catch (a) {
2486
+ E.push({ index: G, error: a });
2487
+ }
2488
+ }), i = [];
2489
+ for (const w of D) {
2490
+ const G = w().finally(() => {
2491
+ i.splice(i.indexOf(G), 1);
2492
+ });
2493
+ i.push(G), i.length >= g && await Promise.race(i);
2494
+ }
2495
+ if (await Promise.all(i), E.length > 0)
2496
+ throw new Error(
2497
+ `Failed to download ${E.length} file(s): ` + E.map((w) => `file ${w.index}: ${w.error}`).join(", ")
2498
+ );
2499
+ return B;
2500
+ }
2501
+ /**
2502
+ * Upload files to the remote.
2503
+ *
2504
+ * Returns an {@link UploadHandle} with per-file `transferIds` available
2505
+ * synchronously (for immediate UI association) and a `completion` promise
2506
+ * that resolves when all files have been uploaded.
2507
+ *
2508
+ * @param files - Array of File objects to upload
2509
+ * @returns Handle with synchronous transferIds and async completion
2510
+ *
2511
+ * @example
2512
+ * ```typescript
2513
+ * const files = await manager.showFilePicker({ multiple: true });
2514
+ * const { transferIds, completion } = manager.uploadFiles(files);
2515
+ * // transferIds available immediately for UI binding
2516
+ * await completion;
2517
+ * ```
2518
+ */
2519
+ uploadFiles(A) {
2520
+ this.uploadState !== void 0 && this.supersedeUpload(), this.retainedFiles = void 0;
2521
+ const I = _K.normalizeToDroppedFiles(A), g = /* @__PURE__ */ new Map();
2522
+ for (let w = 0; w < I.length; w++)
2523
+ g.set(w, this.generateStreamId());
2524
+ const B = I.map((w) => ({
2525
+ name: w.name,
2526
+ size: w.size,
2527
+ lastModified: w.lastModified,
2528
+ path: w.path,
2529
+ isDirectory: w.isDirectory
2530
+ })), E = I.filter((w) => w.isDirectory !== true).length, D = I.map((w) => w.file), i = new Promise((w, G) => {
2531
+ this.uploadState = {
2532
+ files: D,
2533
+ droppedFiles: I,
2534
+ failedFiles: /* @__PURE__ */ new Set(),
2535
+ expectedFileCount: E,
2536
+ completedFiles: /* @__PURE__ */ new Set(),
2537
+ bytesServed: /* @__PURE__ */ new Map(),
2538
+ activeReaders: /* @__PURE__ */ new Map(),
2539
+ readerTimeouts: /* @__PURE__ */ new Map(),
2540
+ transferIds: g,
2541
+ resolve: w,
2542
+ reject: G
2543
+ }, this.suppressUploadMonitoring();
2544
+ try {
2545
+ this.sendInitiateFileCopy(B), this.emit("upload-batch-started", g, I);
2546
+ } catch (a) {
2547
+ this.uploadState = void 0, this.resumeUploadMonitoring();
2548
+ const U = {
2549
+ message: "Failed to initiate file upload",
2550
+ direction: "upload",
2551
+ cause: a
2552
+ };
2553
+ this.emit("error", U), G(new Error(U.message, { cause: a }));
2554
+ return;
2555
+ }
2556
+ this.armPasteAckWatchdog();
2557
+ });
2558
+ return { transferIds: g, completion: i };
2559
+ }
2560
+ /** Whether an upload batch is currently advertised or in flight (a fresh upload, or a re-paste
2561
+ * rebuilt from retained files). */
2562
+ isUploadInProgress() {
2563
+ return this.uploadState !== void 0;
2564
+ }
2565
+ /** Suppress clipboard monitoring for an upload's paste window. Idempotent: a supersede keeps
2566
+ * monitoring suppressed across the old->new upload, so this must not re-fire `onUploadStarted`. */
2567
+ suppressUploadMonitoring() {
2568
+ var _a;
2569
+ if (!this.uploadMonitoringSuppressed) {
2570
+ this.uploadMonitoringSuppressed = true;
2571
+ try {
2572
+ (_a = this.onUploadStarted) == null ? void 0 : _a.call(this);
2573
+ } catch (A) {
2574
+ console.error("Error in onUploadStarted callback:", A);
2575
+ }
2576
+ }
2577
+ }
2578
+ /** Resume clipboard monitoring (idempotent: fires onUploadFinished at most once
2579
+ * per upload, since the resume point is now deferred past the wire send). */
2580
+ resumeUploadMonitoring() {
2581
+ var _a;
2582
+ if (this.uploadMonitoringSuppressed) {
2583
+ this.uploadMonitoringSuppressed = false;
2584
+ try {
2585
+ (_a = this.onUploadFinished) == null ? void 0 : _a.call(this);
2586
+ } catch (A) {
2587
+ console.error("Error in onUploadFinished callback:", A);
2588
+ }
2589
+ }
2590
+ }
2591
+ /** Arm the paste-acknowledgment watchdog for the current upload. */
2592
+ armPasteAckWatchdog() {
2593
+ this.clearPasteAckWatchdog(), this.clearUploadInactivityWatchdog(), this.pasteAckTimeout = setTimeout(() => {
2594
+ this.pasteAckTimeout = void 0;
2595
+ const A = this.uploadState;
2596
+ 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();
2597
+ }, _K.PASTE_ACK_TIMEOUT_MS);
2598
+ }
2599
+ /** Disarm the paste-acknowledgment watchdog, if armed. */
2600
+ clearPasteAckWatchdog() {
2601
+ this.pasteAckTimeout !== void 0 && (clearTimeout(this.pasteAckTimeout), this.pasteAckTimeout = void 0);
2602
+ }
2603
+ /**
2604
+ * (Re)arm the upload inactivity watchdog (see {@link UPLOAD_INACTIVITY_TIMEOUT_MS}).
2605
+ * Called on every FileContentsRequest, so continued pulls keep resetting it and a
2606
+ * slow-but-progressing transfer is never killed; if pulls stop for the window the
2607
+ * upload is failed (releasing uploadState). Skipped for re-pastes, matching the
2608
+ * paste-ack watchdog.
2609
+ */
2610
+ resetUploadInactivityWatchdog() {
2611
+ this.clearUploadInactivityWatchdog(), this.uploadInactivityTimeout = setTimeout(() => {
2612
+ this.uploadInactivityTimeout = void 0;
2613
+ const A = this.uploadState;
2614
+ A !== void 0 && A.isRePaste !== true && this.failPendingUpload("The remote stopped requesting the files, so the paste did not complete");
2615
+ }, _K.UPLOAD_INACTIVITY_TIMEOUT_MS);
2616
+ }
2617
+ /** Disarm the upload inactivity watchdog, if armed. */
2618
+ clearUploadInactivityWatchdog() {
2619
+ this.uploadInactivityTimeout !== void 0 && (clearTimeout(this.uploadInactivityTimeout), this.uploadInactivityTimeout = void 0);
2620
+ }
2621
+ /**
2622
+ * The remote acknowledged the paste by requesting file contents: the clobber
2623
+ * window is over, so disarm the paste-ack watchdog and resume clipboard monitoring.
2624
+ * Called on every FileContentsRequest; only the first disarms/resumes. Every request
2625
+ * also (re)arms the inactivity watchdog so a stall after pulling began is recovered.
2626
+ */
2627
+ acknowledgePaste() {
2628
+ this.pasteAckTimeout !== void 0 && (this.clearPasteAckWatchdog(), this.resumeUploadMonitoring());
2629
+ const A = this.uploadState;
2630
+ if (A !== void 0 && A.isRePaste !== true && A.expectedFileCount === 0) {
2631
+ this.finishUploadBatch(A);
2632
+ return;
2633
+ }
2634
+ this.resetUploadInactivityWatchdog();
2635
+ }
2636
+ /**
2637
+ * Abort any in-flight chunk reads for a batch and clear their timeouts. Without this, a read
2638
+ * still running when the batch is torn down keeps its FileReader and a 60s reader-timeout
2639
+ * alive. Shared by every upload teardown path (fail, supersede, dispose).
2640
+ */
2641
+ abortInFlightReads(A) {
2642
+ for (const I of A.readerTimeouts.values())
2643
+ clearTimeout(I);
2644
+ A.readerTimeouts.clear();
2645
+ for (const I of A.activeReaders.values())
2646
+ I.abort();
2647
+ A.activeReaders.clear();
2648
+ }
2649
+ /**
2650
+ * Fail the in-flight upload (reject its completion, emit an upload error, clear
2651
+ * uploadState) and resume monitoring. Used when the advertise is rejected or the
2652
+ * paste is never pulled, so `uploadState` is released instead of lingering and
2653
+ * throwing "Upload already in progress" on every later upload.
2654
+ */
2655
+ failPendingUpload(A) {
2656
+ this.clearPasteAckWatchdog(), this.clearUploadInactivityWatchdog(), this.resumeUploadMonitoring();
2657
+ const I = this.uploadState;
2658
+ if (I === void 0)
2659
+ return;
2660
+ this.abortInFlightReads(I);
2661
+ const g = { message: A, direction: "upload" };
2662
+ this.emit("error", g);
2663
+ const { reject: B } = I;
2664
+ this.uploadState = void 0, B(new Error(A));
2665
+ }
2666
+ /**
2667
+ * Tear down the current upload because a new paste is replacing it. Unlike
2668
+ * {@link failPendingUpload}, this emits no error and leaves monitoring suppressed (a new upload
2669
+ * is starting); it aborts in-flight reads, clears the state, and *resolves* the old completion
2670
+ * (a replacement, not a failure).
2671
+ */
2672
+ supersedeUpload() {
2673
+ this.clearPasteAckWatchdog(), this.clearUploadInactivityWatchdog();
2674
+ const A = this.uploadState;
2675
+ if (A === void 0)
2676
+ return;
2677
+ this.abortInFlightReads(A);
2678
+ const { resolve: I } = A;
2679
+ this.uploadState = void 0, I();
2680
+ }
2681
+ /**
2682
+ * Finalize a fully-accounted upload batch (every counted file either served in full
2683
+ * or permanently failed). Stops the inactivity watchdog so it cannot linger past
2684
+ * completion, retains the DroppedFile metadata so a re-paste from the remote can serve
2685
+ * the data again, clears `uploadState`, and resolves the completion promise.
2686
+ */
2687
+ finishUploadBatch(A) {
2688
+ this.clearUploadInactivityWatchdog(), this.retainedFiles = A.droppedFiles, this.uploadState = void 0, A.resolve();
2689
+ }
2690
+ /**
2691
+ * Show a file picker dialog and return selected files.
2692
+ *
2693
+ * Note: This must be called in response to a user gesture (e.g., button click)
2694
+ * due to browser security restrictions.
2695
+ *
2696
+ * @param options - File picker options
2697
+ * @returns Promise resolving to selected File objects
2698
+ *
2699
+ * @example
2700
+ * ```typescript
2701
+ * button.onclick = async () => {
2702
+ * const files = await manager.showFilePicker({ multiple: true, accept: 'image/*' });
2703
+ * await manager.uploadFiles(files);
2704
+ * };
2705
+ * ```
2706
+ */
2707
+ showFilePicker(A) {
2708
+ return new Promise((I) => {
2709
+ const g = document.createElement("input");
2710
+ 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", () => {
2711
+ const i = Array.from(g.files || []);
2712
+ E(), __trdUnlisten(window, "focus", D), I(i);
2713
+ });
2714
+ let B = false;
2715
+ const E = () => {
2716
+ B || (B = true, g.parentNode && document.body.removeChild(g));
2717
+ };
2718
+ __trdListen(g, "cancel", () => {
2719
+ E(), __trdUnlisten(window, "focus", D), I([]);
2720
+ });
2721
+ const D = () => {
2722
+ setTimeout(() => {
2723
+ B || (E(), I([])), __trdUnlisten(window, "focus", D);
2724
+ }, 300);
2725
+ };
2726
+ __trdListen(window, "focus", D), document.body.appendChild(g), g.click();
2727
+ });
2728
+ }
2729
+ /**
2730
+ * Extract files (and recursively traverse directories) from a drag-and-drop event.
2731
+ *
2732
+ * Uses the File and Directory Entries API (`webkitGetAsEntry`) which is
2733
+ * supported across all major browsers (Chrome, Firefox, Safari, Edge).
2734
+ * Falls back to `getAsFile()` when the Entries API is unavailable.
2735
+ *
2736
+ * Directory entries are included in the result with `isDirectory: true`
2737
+ * and a `null` file handle. Files inside directories have their
2738
+ * {@link DroppedFile.path} set to the relative backslash-separated path.
2739
+ *
2740
+ * @param event - DragEvent from drop handler
2741
+ * @returns Promise resolving to an array of DroppedFile descriptors
2742
+ *
2743
+ * @example
2744
+ * ```typescript
2745
+ * dropZone.addEventListener('drop', async (e) => {
2746
+ * const files = await manager.handleDrop(e);
2747
+ * manager.uploadFiles(files);
2748
+ * });
2749
+ * ```
2750
+ */
2751
+ async handleDrop(A) {
2752
+ var _a, _b, _c;
2753
+ A.preventDefault();
2754
+ const I = [];
2755
+ if ((_a = A.dataTransfer) == null ? void 0 : _a.items) {
2756
+ const g = [], B = [];
2757
+ for (const E of A.dataTransfer.items) {
2758
+ if (E.kind !== "file") continue;
2759
+ const D = (_b = E.webkitGetAsEntry) == null ? void 0 : _b.call(E);
2760
+ if (D)
2761
+ g.push(D);
2762
+ else {
2763
+ const i = E.getAsFile();
2764
+ i && B.push(i);
2765
+ }
2766
+ }
2767
+ for (const E of g)
2768
+ await this.traverseEntry(E, void 0, I, 0);
2769
+ for (const E of B)
2770
+ I.push({
2771
+ file: E,
2772
+ name: E.name,
2773
+ size: E.size,
2774
+ lastModified: E.lastModified
2775
+ });
2776
+ } else if ((_c = A.dataTransfer) == null ? void 0 : _c.files)
2777
+ for (const g of Array.from(A.dataTransfer.files))
2778
+ I.push({
2779
+ file: g,
2780
+ name: g.name,
2781
+ size: g.size,
2782
+ lastModified: g.lastModified
2783
+ });
2784
+ return I;
2785
+ }
2786
+ /**
2787
+ * Normalize a plain `File[]` or `DroppedFile[]` into `DroppedFile[]`.
2788
+ * Allows `uploadFiles` to accept either type for backward compatibility.
2789
+ */
2790
+ static normalizeToDroppedFiles(A) {
2791
+ return A.length === 0 ? [] : "file" in A[0] ? A : A.map((g) => ({
2792
+ file: g,
2793
+ name: g.name,
2794
+ size: g.size,
2795
+ lastModified: g.lastModified
2796
+ }));
2797
+ }
2798
+ /**
2799
+ * Recursively traverse a FileSystemEntry, collecting files and directory
2800
+ * entries into `results`.
2801
+ */
2802
+ async traverseEntry(A, I, g, B) {
2803
+ if (!(g.length >= _K.MAX_DIRECTORY_ENTRIES)) {
2804
+ if (B > _K.MAX_DIRECTORY_DEPTH) {
2805
+ console.warn(
2806
+ `Skipping "${A.name}": directory depth exceeds ${_K.MAX_DIRECTORY_DEPTH}`
2807
+ );
2808
+ return;
2809
+ }
2810
+ if (A.isFile) {
2811
+ const E = await new Promise((D, i) => {
2812
+ A.file(D, i);
2813
+ });
2814
+ g.push({
2815
+ file: E,
2816
+ name: E.name,
2817
+ size: E.size,
2818
+ lastModified: E.lastModified,
2819
+ path: I
2820
+ });
2821
+ } else if (A.isDirectory) {
2822
+ const E = I !== void 0 ? `${I}\\${A.name}` : A.name;
2823
+ g.push({
2824
+ file: null,
2825
+ name: A.name,
2826
+ size: 0,
2827
+ lastModified: 0,
2828
+ path: I,
2829
+ isDirectory: true
2830
+ });
2831
+ const D = A.createReader(), i = await _K.readAllDirectoryEntries(D);
2832
+ for (const w of i)
2833
+ await this.traverseEntry(w, E, g, B + 1);
2834
+ }
2835
+ }
2836
+ }
2837
+ /**
2838
+ * Read all entries from a FileSystemDirectoryReader. Chromium-based
2839
+ * browsers return at most 100 entries per `readEntries()` call, so we
2840
+ * must loop until an empty batch is returned.
2841
+ */
2842
+ static readAllDirectoryEntries(A) {
2843
+ return new Promise((I, g) => {
2844
+ const B = [], E = () => {
2845
+ A.readEntries((D) => {
2846
+ D.length === 0 ? I(B) : (B.push(...D), E());
2847
+ }, g);
2848
+ };
2849
+ E();
2850
+ });
2851
+ }
2852
+ /**
2853
+ * Prevent default drag-over behavior to enable drop target.
2854
+ *
2855
+ * This must be called in the dragover event handler for drag-and-drop to work.
2856
+ *
2857
+ * @param event - DragEvent from dragover handler
2858
+ *
2859
+ * @example
2860
+ * ```typescript
2861
+ * dropZone.addEventListener('dragover', (e) => manager.handleDragOver(e));
2862
+ * ```
2863
+ */
2864
+ handleDragOver(A) {
2865
+ A.preventDefault();
2866
+ }
2867
+ /**
2868
+ * Cleanup resources and unregister callbacks.
2869
+ *
2870
+ * Call this when the session is terminating or RdpFileTransferProvider is no longer needed.
2871
+ */
2872
+ dispose() {
2873
+ this.disposed = true, this.clearPasteAckWatchdog(), this.clearUploadInactivityWatchdog(), this.resumeUploadMonitoring();
2874
+ for (const A of this.activeDownloads.values())
2875
+ this.abortWriteHandle(A), A.reject(new Error("RdpFileTransferProvider disposed"));
2876
+ 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();
2877
+ }
2878
+ // ==================== Callback Handlers ====================
2879
+ handleFilesAvailable(A, I) {
2880
+ this.failPendingUpload("Upload interrupted: the remote clipboard changed");
2881
+ const g = A.map((B) => ({
2882
+ ...B,
2883
+ name: _K.sanitizeFileName(B.name),
2884
+ path: B.path !== void 0 ? _K.sanitizePath(B.path) : void 0
2885
+ }));
2886
+ this.availableFiles = g, this.clipDataId = I, this.emit("files-available", g);
2887
+ }
2888
+ /**
2889
+ * Extract the basename from a file name, stripping any path traversal or
2890
+ * directory components. Returns "unnamed_file" if the name is empty or
2891
+ * consists entirely of path separators / traversal sequences.
2892
+ */
2893
+ /** @internal Visible for testing. */
2894
+ static sanitizeFileName(A) {
2895
+ const I = A.split(/[/\\]/);
2896
+ for (let g = I.length - 1; g >= 0; g--) {
2897
+ const B = I[g];
2898
+ if (B.length > 0 && B !== "." && B !== "..")
2899
+ return B;
2900
+ }
2901
+ return "unnamed_file";
2902
+ }
2903
+ /**
2904
+ * Sanitize a relative directory path by stripping traversal components
2905
+ * (`.` and `..`) and absolute path prefixes. Returns undefined if the
2906
+ * path is empty after sanitization.
2907
+ */
2908
+ /** @internal Visible for testing. */
2909
+ static sanitizePath(A) {
2910
+ const g = A.split(/[/\\]/).filter((B) => B.length > 0 && B !== "." && B !== "..");
2911
+ 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)
2912
+ return g.join("\\");
2913
+ }
2914
+ handleFileContentsRequest(A) {
2915
+ if (this.acknowledgePaste(), !this.uploadState) {
2916
+ if (!this.retainedFiles) {
2917
+ console.warn("Received file contents request but no upload in progress"), this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2918
+ return;
2919
+ }
2920
+ this.rebuildUploadStateFromRetained();
2921
+ }
2922
+ const I = this.uploadState, { files: g, droppedFiles: B } = I;
2923
+ if (I.failedFiles.has(A.index)) {
2924
+ this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2925
+ return;
2926
+ }
2927
+ const E = g[A.index], D = B[A.index];
2928
+ if (D === void 0) {
2929
+ console.error(
2930
+ `File index ${A.index} out of range (stream ${A.streamId}, valid: 0..${B.length - 1})`
2931
+ ), this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2932
+ return;
2933
+ }
2934
+ if (E == null) {
2935
+ if ((A.flags & j.SIZE) !== 0) {
2936
+ const w = new Uint8Array(8);
2937
+ this.sendSubmitFileContents(A.streamId, false, w);
2938
+ } else
2939
+ this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2940
+ return;
2941
+ }
2942
+ const i = E;
2943
+ if ((A.flags & j.SIZE) !== 0) {
2944
+ const w = new Uint8Array(8);
2945
+ 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);
2946
+ } else if ((A.flags & j.RANGE) !== 0) {
2947
+ const w = i.slice(A.position, A.position + A.size), G = new FileReader();
2948
+ I.activeReaders.set(A.streamId, G);
2949
+ const a = setTimeout(() => {
2950
+ var _a;
2951
+ G.abort(), this.uploadState !== void 0 && (this.uploadState.activeReaders.delete(A.streamId), this.uploadState.readerTimeouts.delete(A.streamId)), this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2952
+ const U = {
2953
+ message: `File read timeout after ${_K.FILE_READER_TIMEOUT_MS / 1e3}s`,
2954
+ transferId: (_a = this.uploadState) == null ? void 0 : _a.transferIds.get(A.index),
2955
+ fileIndex: A.index,
2956
+ fileName: D.name,
2957
+ direction: "upload"
2958
+ };
2959
+ this.emit("error", U), 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));
2960
+ }, _K.FILE_READER_TIMEOUT_MS);
2961
+ I.readerTimeouts.set(A.streamId, a), G.onload = () => {
2962
+ if (this.uploadState !== void 0) {
2963
+ this.uploadState.activeReaders.delete(A.streamId);
2964
+ const c = this.uploadState.readerTimeouts.get(A.streamId);
2965
+ c !== void 0 && (clearTimeout(c), this.uploadState.readerTimeouts.delete(A.streamId));
2966
+ }
2967
+ const U = new Uint8Array(G.result);
2968
+ if (this.sendSubmitFileContents(A.streamId, false, U), this.uploadState !== void 0) {
2969
+ const c = (this.uploadState.bytesServed.get(A.index) ?? 0) + U.length;
2970
+ this.uploadState.bytesServed.set(A.index, c);
2971
+ const O = this.uploadState.transferIds.get(A.index) ?? -1, S = {
2972
+ transferId: O,
2973
+ fileIndex: A.index,
2974
+ fileName: D.name,
2975
+ bytesTransferred: c,
2976
+ totalBytes: i.size,
2977
+ percentage: i.size === 0 ? 100 : Math.min(c / i.size * 100, 100)
2978
+ };
2979
+ this.emit("upload-progress", S), c >= i.size && this.markUploadFileComplete(A.index, i, O);
2980
+ }
2981
+ }, G.onerror = () => {
2982
+ var _a, _b;
2983
+ if (this.uploadState !== void 0) {
2984
+ this.uploadState.activeReaders.delete(A.streamId);
2985
+ const c = this.uploadState.readerTimeouts.get(A.streamId);
2986
+ c !== void 0 && (clearTimeout(c), this.uploadState.readerTimeouts.delete(A.streamId));
2987
+ }
2988
+ if (((_a = this.uploadState) == null ? void 0 : _a.failedFiles.has(A.index)) === true)
2989
+ return;
2990
+ this.sendSubmitFileContents(A.streamId, true, new Uint8Array());
2991
+ const U = {
2992
+ message: "Failed to read file chunk",
2993
+ transferId: (_b = this.uploadState) == null ? void 0 : _b.transferIds.get(A.index),
2994
+ fileIndex: A.index,
2995
+ fileName: D.name,
2996
+ direction: "upload",
2997
+ cause: G.error
2998
+ };
2999
+ this.emit("error", U), 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));
3000
+ }, G.readAsArrayBuffer(w);
3001
+ }
3002
+ }
3003
+ /**
3004
+ * Mark a single upload file as fully served: record it, emit upload-complete once, and
3005
+ * finalize the batch once every counted file is accounted for. Shared by the RANGE onload
3006
+ * path (final chunk served) and the SIZE path for 0-byte files (which get no RANGE request).
3007
+ */
3008
+ markUploadFileComplete(A, I, g) {
3009
+ const B = this.uploadState;
3010
+ 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));
3011
+ }
3012
+ /**
3013
+ * Lazily rebuild uploadState from retainedFiles when the remote re-pastes
3014
+ * after the original upload completed. This lets the main code path in
3015
+ * handleFileContentsRequest handle progress and completion identically.
3016
+ * No external promise - resolve/reject are no-ops.
3017
+ */
3018
+ rebuildUploadStateFromRetained() {
3019
+ const A = this.retainedFiles, I = /* @__PURE__ */ new Map();
3020
+ for (let B = 0; B < A.length; B++)
3021
+ I.set(B, this.generateStreamId());
3022
+ const g = A.filter((B) => B.isDirectory !== true).length;
3023
+ this.uploadState = {
3024
+ files: A.map((B) => B.file),
3025
+ droppedFiles: A,
3026
+ failedFiles: /* @__PURE__ */ new Set(),
3027
+ expectedFileCount: g,
3028
+ completedFiles: /* @__PURE__ */ new Set(),
3029
+ bytesServed: /* @__PURE__ */ new Map(),
3030
+ activeReaders: /* @__PURE__ */ new Map(),
3031
+ readerTimeouts: /* @__PURE__ */ new Map(),
3032
+ transferIds: I,
3033
+ resolve: () => {
3034
+ },
3035
+ reject: () => {
3036
+ },
3037
+ isRePaste: true
3038
+ }, this.emit("upload-batch-started", I, A);
3039
+ }
3040
+ handleFileContentsResponse(A) {
3041
+ const I = this.activeDownloads.get(A.streamId);
3042
+ if (!I) {
3043
+ console.warn(`Received response for unknown stream ${A.streamId}`);
3044
+ return;
3045
+ }
3046
+ if (A.isError) {
3047
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(I);
3048
+ const g = {
3049
+ message: "Remote failed to provide file contents",
3050
+ transferId: I.streamId,
3051
+ fileIndex: I.fileIndex,
3052
+ fileName: I.fileInfo.name,
3053
+ direction: "download"
3054
+ };
3055
+ this.emit("error", g), I.reject(new Error(g.message));
3056
+ return;
3057
+ }
3058
+ if (I.expectedSize === void 0) {
3059
+ if (A.data.length < 8) {
3060
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(I);
3061
+ const E = {
3062
+ message: "Invalid SIZE response: expected 8 bytes for file size",
3063
+ transferId: I.streamId,
3064
+ fileIndex: I.fileIndex,
3065
+ fileName: I.fileInfo.name,
3066
+ direction: "download"
3067
+ };
3068
+ this.emit("error", E), I.reject(new Error(E.message));
3069
+ return;
3070
+ }
3071
+ const g = new DataView(A.data.buffer, A.data.byteOffset, A.data.byteLength), B = Number(g.getBigUint64(0, true));
3072
+ if (B > _K.MAX_FILE_SIZE) {
3073
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(I);
3074
+ const E = {
3075
+ message: `File size ${(B / (1024 * 1024 * 1024)).toFixed(2)}GB exceeds maximum download limit of 2GB`,
3076
+ transferId: I.streamId,
3077
+ fileIndex: I.fileIndex,
3078
+ fileName: I.fileInfo.name,
3079
+ direction: "download"
3080
+ };
3081
+ this.emit("error", E), I.reject(new Error(E.message));
3082
+ return;
3083
+ }
3084
+ if (I.expectedSize = B, B === 0) {
3085
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(I);
3086
+ const E = new Blob([]);
3087
+ this.emit("download-complete", I.fileInfo, E, I.fileIndex, I.streamId), I.resolve(E);
3088
+ return;
3089
+ }
3090
+ this.initWriteHandleAndRequestFirstChunk(I);
3091
+ } else
3092
+ this.handleDataChunk(I, A.data);
3093
+ }
3094
+ /**
3095
+ * Create a write handle for the given transfer and request the first
3096
+ * data chunk. Runs asynchronously because backend initialization
3097
+ * (especially OPFS) is async.
3098
+ *
3099
+ * The init promise is stored on `state.writeHandleReady` so that
3100
+ * DATA responses arriving before the handle is ready can await it.
3101
+ */
3102
+ initWriteHandleAndRequestFirstChunk(A) {
3103
+ A.writeHandleReady = (async () => {
3104
+ try {
3105
+ const I = (async () => (await this.ensureStorageBackend()).createWriteHandle(A.fileInfo.name, A.expectedSize ?? 0))(), g = _K.WRITE_HANDLE_INIT_TIMEOUT_MS, B = await Promise.race([
3106
+ I,
3107
+ new Promise(
3108
+ (E, D) => setTimeout(() => D(new Error(`Storage init timed out after ${g / 1e3}s`)), g)
3109
+ )
3110
+ ]);
3111
+ if (this.disposed || !this.activeDownloads.has(A.streamId)) {
3112
+ try {
3113
+ await B.abort();
3114
+ } catch {
3115
+ }
3116
+ return;
3117
+ }
3118
+ A.writeHandle = B;
3119
+ } catch (I) {
3120
+ this.activeDownloads.delete(A.streamId);
3121
+ const g = {
3122
+ message: "Failed to initialize storage for download",
3123
+ transferId: A.streamId,
3124
+ fileIndex: A.fileIndex,
3125
+ fileName: A.fileInfo.name,
3126
+ direction: "download",
3127
+ cause: I
3128
+ };
3129
+ this.emit("error", g), A.reject(new Error(g.message, { cause: I }));
3130
+ return;
3131
+ }
3132
+ this.requestNextChunk(A);
3133
+ })();
3134
+ }
3135
+ /**
3136
+ * Write a data chunk to the storage backend and advance the download.
3137
+ *
3138
+ * If the write handle is not yet ready (DATA response arrived before
3139
+ * backend init completed), this method awaits `state.writeHandleReady`
3140
+ * to preserve chunk ordering -- each concurrent caller awaits the same
3141
+ * promise in sequence.
3142
+ */
3143
+ async handleDataChunk(A, I) {
3144
+ if (!A.writeHandle && (!A.writeHandleReady || this.disposed || !this.activeDownloads.has(A.streamId) || (await A.writeHandleReady, this.disposed || !this.activeDownloads.has(A.streamId))))
3145
+ return;
3146
+ const g = A.writeHandle;
3147
+ if (g) {
3148
+ try {
3149
+ await g.write(I);
3150
+ } catch (B) {
3151
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(A);
3152
+ const i = {
3153
+ message: B instanceof DOMException && B.name === "QuotaExceededError" ? `Storage quota exceeded while downloading "${A.fileInfo.name}"` : "Failed to write download chunk to storage",
3154
+ transferId: A.streamId,
3155
+ fileIndex: A.fileIndex,
3156
+ fileName: A.fileInfo.name,
3157
+ direction: "download",
3158
+ cause: B
3159
+ };
3160
+ this.emit("error", i), A.reject(new Error(i.message, { cause: B }));
3161
+ return;
3162
+ }
3163
+ if (A.bytesReceived += I.length, A.expectedSize !== void 0 && A.bytesReceived > A.expectedSize * 2) {
3164
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(A);
3165
+ const B = {
3166
+ message: `Received ${A.bytesReceived} bytes but expected ${A.expectedSize} - aborting`,
3167
+ transferId: A.streamId,
3168
+ fileIndex: A.fileIndex,
3169
+ fileName: A.fileInfo.name,
3170
+ direction: "download"
3171
+ };
3172
+ this.emit("error", B), A.reject(new Error(B.message));
3173
+ return;
3174
+ }
3175
+ if (A.expectedSize !== void 0) {
3176
+ const B = {
3177
+ transferId: A.streamId,
3178
+ fileIndex: A.fileIndex,
3179
+ fileName: A.fileInfo.name,
3180
+ bytesTransferred: A.bytesReceived,
3181
+ totalBytes: A.expectedSize,
3182
+ percentage: Math.min(A.bytesReceived / A.expectedSize * 100, 100)
3183
+ };
3184
+ this.emit("download-progress", B);
3185
+ }
3186
+ if (A.expectedSize !== void 0 && A.bytesReceived >= A.expectedSize) {
3187
+ this.activeDownloads.delete(A.streamId);
3188
+ try {
3189
+ const B = await g.finalize();
3190
+ this.emit("download-complete", A.fileInfo, B, A.fileIndex, A.streamId), A.resolve(B);
3191
+ } catch (B) {
3192
+ this.abortWriteHandle(A);
3193
+ const E = {
3194
+ message: "Failed to finalize downloaded file",
3195
+ transferId: A.streamId,
3196
+ fileIndex: A.fileIndex,
3197
+ fileName: A.fileInfo.name,
3198
+ direction: "download",
3199
+ cause: B
3200
+ };
3201
+ this.emit("error", E), A.reject(new Error(E.message, { cause: B }));
3202
+ }
3203
+ } else
3204
+ this.requestNextChunk(A);
3205
+ }
3206
+ }
3207
+ /** Abort and clean up a write handle, ignoring errors. */
3208
+ async abortWriteHandle(A) {
3209
+ if (A.writeHandle) {
3210
+ try {
3211
+ await A.writeHandle.abort();
3212
+ } catch {
3213
+ }
3214
+ A.writeHandle = void 0;
3215
+ }
3216
+ }
3217
+ /**
3218
+ * Handle the remote's response to one of our outbound Format Lists, surfaced via
3219
+ * `on_format_list_response`. Always re-emitted as a `format-list-response` event so
3220
+ * a frontend can drive paste from it (inject on accept, retry on reject).
3221
+ *
3222
+ * On reject (`ok === false`) the remote silently discards the advertised clipboard
3223
+ * (MS-RDPECLIP), so an upload still waiting to be pulled can never complete --
3224
+ * previously this left `uploadState` set and every later upload threw "Upload
3225
+ * already in progress". The watchdog-armed check scopes the release to an upload
3226
+ * that was advertised but not yet pulled, so re-paste and an already-progressing
3227
+ * transfer are left alone.
3228
+ */
3229
+ handleFormatListResponse(A) {
3230
+ 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");
3231
+ }
3232
+ handleLock(A) {
3233
+ }
3234
+ handleUnlock(A) {
3235
+ }
3236
+ handleLocksExpired(A) {
3237
+ const I = /* @__PURE__ */ new Set();
3238
+ for (let g = 0; g < A.length; g++)
3239
+ I.add(A[g]);
3240
+ for (const [g, B] of this.activeDownloads)
3241
+ if (B.clipDataId !== void 0 && I.has(B.clipDataId)) {
3242
+ this.activeDownloads.delete(g), this.abortWriteHandle(B);
3243
+ 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.`;
3244
+ B.reject(new Error(E)), this.emit("error", {
3245
+ message: E,
3246
+ transferId: B.streamId,
3247
+ fileIndex: B.fileIndex,
3248
+ fileName: B.fileInfo.name,
3249
+ direction: "download"
3250
+ });
3251
+ }
3252
+ }
3253
+ // ==================== Helper Methods ====================
3254
+ requestNextChunk(A) {
3255
+ if (A.expectedSize === void 0 || A.expectedSize === 0)
3256
+ return;
3257
+ const I = A.bytesReceived, g = A.expectedSize - I, B = Math.min(this.chunkSize, g);
3258
+ try {
3259
+ this.sendRequestFileContents(
3260
+ A.streamId,
3261
+ A.fileIndex,
3262
+ j.RANGE,
3263
+ I,
3264
+ B,
3265
+ A.clipDataId
3266
+ );
3267
+ } catch (E) {
3268
+ this.activeDownloads.delete(A.streamId), this.abortWriteHandle(A);
3269
+ const D = {
3270
+ message: "Failed to request file chunk",
3271
+ transferId: A.streamId,
3272
+ fileIndex: A.fileIndex,
3273
+ fileName: A.fileInfo.name,
3274
+ direction: "download",
3275
+ cause: E
3276
+ };
3277
+ this.emit("error", D), A.reject(new Error(D.message, { cause: E }));
3278
+ }
3279
+ }
3280
+ generateStreamId() {
3281
+ const A = this.activeDownloads.size + 2;
3282
+ for (let I = 0; I < A; I++) {
3283
+ const g = this.nextStreamId;
3284
+ if (this.nextStreamId = (this.nextStreamId + 1) % 4294967296, this.nextStreamId === 0 && (this.nextStreamId = 1), !this.activeDownloads.has(g) && g !== 0)
3285
+ return g;
3286
+ }
3287
+ throw new Error("Unable to generate unique stream ID");
3288
+ }
3289
+ };
3290
+ /** Maximum file size for downloads (2GB) to prevent browser out-of-memory errors */
3291
+ __publicField(_K, "MAX_FILE_SIZE", 2 * 1024 * 1024 * 1024);
3292
+ /** Timeout for FileReader operations (60 seconds) to prevent stalled uploads */
3293
+ __publicField(_K, "FILE_READER_TIMEOUT_MS", 60 * 1e3);
3294
+ /**
3295
+ * How long to keep clipboard monitoring suppressed after advertising an upload
3296
+ * while waiting for the remote to pull the files (first FileContentsRequest),
3297
+ * before giving up. Matches the Rust cliprdr lock inactivity timeout (60s), so
3298
+ * the JS side gives up exactly when the protocol lock does. If the remote never
3299
+ * requests contents (the paste landed in a non-file target, or the advertise was
3300
+ * clobbered), the watchdog resumes monitoring and fails the upload so its state
3301
+ * cannot wedge later uploads.
3302
+ */
3303
+ __publicField(_K, "PASTE_ACK_TIMEOUT_MS", 60 * 1e3);
3304
+ /**
3305
+ * Upload inactivity window. After the remote starts pulling, each FileContentsRequest
3306
+ * resets this; if pulls then stop for this long -- e.g. the remote grabbed the
3307
+ * clipboard with a text/image copy that never reaches handleFilesAvailable -- the
3308
+ * upload is failed so `uploadState` is released and later uploads aren't wedged. A
3309
+ * slow-but-progressing transfer keeps resetting it, so it is never killed.
3310
+ */
3311
+ __publicField(_K, "UPLOAD_INACTIVITY_TIMEOUT_MS", 60 * 1e3);
3312
+ /** Timeout for storage backend write handle initialization (30 seconds). */
3313
+ __publicField(_K, "WRITE_HANDLE_INIT_TIMEOUT_MS", 30 * 1e3);
3314
+ /** Maximum recursion depth when traversing dropped directories. */
3315
+ __publicField(_K, "MAX_DIRECTORY_DEPTH", 32);
3316
+ /** Maximum total entries (files + directories) collected from a single drop. */
3317
+ __publicField(_K, "MAX_DIRECTORY_ENTRIES", 1e3);
3318
+ let K = _K;
3319
+ async function NI(Q, A) {
3320
+ await fA(A === void 0 ? void 0 : { module_or_path: A }), hA(Q);
3321
+ }
3322
+ const kI = {
3323
+ DesktopSize: V,
3324
+ InputTransaction: _,
3325
+ SessionBuilder: J,
3326
+ ClipboardData: d,
3327
+ DeviceEvent: h
3328
+ };
3329
+ function RI(Q) {
3330
+ return new k("pcb", Q);
3331
+ }
3332
+ function FI(Q, A = "enhanced") {
3333
+ if (Q.trim() === "")
3334
+ throw new Error("vmconnect requires a VM ID");
3335
+ const I = A === "enhanced" ? `${Q};EnhancedMode=1` : Q;
3336
+ return new k("vmconnect", I);
3337
+ }
3338
+ function yI(Q) {
3339
+ return new k("display_control", Q);
3340
+ }
3341
+ function YI(Q) {
3342
+ return new k("graphics_pipeline", Q);
3343
+ }
3344
+ function MI(Q) {
3345
+ return new k("h264_decoder", Q);
3346
+ }
3347
+ function JI(Q) {
3348
+ return new k("audio_playback", Q);
3349
+ }
3350
+ function UI(Q) {
3351
+ return new k("drive_redirection", Q);
3352
+ }
3353
+ function cI(Q) {
3354
+ return new k("audio_input", Q);
3355
+ }
3356
+ function KI(Q) {
3357
+ const A = Q instanceof Uint8Array ? Q : new Uint8Array(Q.buffer, Q.byteOffset, Q.byteLength);
3358
+ return new k("audio_input_data", A);
3359
+ }
3360
+ function hI(Q) {
3361
+ return new k("kdc_proxy_url", Q);
3362
+ }
3363
+ function aI(Q) {
3364
+ return new k("outbound_message_size_limit", Q);
3365
+ }
3366
+ function HI(Q) {
3367
+ return new k("enable_credssp", Q);
3368
+ }
3369
+ function SI(Q) {
3370
+ return new k("enable_server_pointer", Q);
3371
+ }
3372
+ function LI(Q) {
3373
+ return new k("legacy_graphics", Q);
3374
+ }
3375
+ try { await NI(__trdLevel, __trdModule); }
3376
+ catch (error) { __trdReleaseBrowserRoots(); throw error; }
3377
+ return {
3378
+ Backend: kI,
3379
+ BlobStorageBackend: cA,
3380
+ FileContentsFlags: j,
3381
+ OpfsStorageBackend: l,
3382
+ PrinterDriverName: DI,
3383
+ RdpFile: iA,
3384
+ RdpFileTransferProvider: K,
3385
+ WebCodecsH264Decoder: M,
3386
+ audioInput: cI,
3387
+ audioInputData: KI,
3388
+ audioPlayback: JI,
3389
+ detectStorageBackend: CI,
3390
+ displayControl: yI,
3391
+ driveRedirection: UI,
3392
+ enableCredssp: HI,
3393
+ enableServerPointer: SI,
3394
+ fileContentsRequestCallback: zA,
3395
+ fileContentsResponseCallback: PA,
3396
+ filesAvailableCallback: nA,
3397
+ graphicsPipeline: YI,
3398
+ h264Decoder: MI,
3399
+ h264Supported: EI,
3400
+ init: NI,
3401
+ initiateFileCopy: II,
3402
+ kdcProxyUrl: hI,
3403
+ legacyGraphics: LI,
3404
+ lockCallback: vA,
3405
+ locksExpiredCallback: uA,
3406
+ outboundMessageSizeLimit: aI,
3407
+ preConnectionBlob: RI,
3408
+ printJobStreamCallbacks: iI,
3409
+ printerDeviceId: GI,
3410
+ printerDriverName: oI,
3411
+ printerName: wI,
3412
+ requestFileContents: $A,
3413
+ submitFileContents: AI,
3414
+ unlockCallback: eA,
3415
+ vmConnect: FI,
3416
+ runtime: {
3417
+ dispose () { __trdReleaseBrowserRoots(); __trdListeners.clear(); },
3418
+ get memory () { return C.memory; },
3419
+ get trapped () { return __trdTrap; },
3420
+ onTrap (listener) {
3421
+ if (__trdTrap) listener(__trdTrap);
3422
+ else __trdListeners.add(listener);
3423
+ return () => __trdListeners.delete(listener);
3424
+ },
3425
+ },
3426
+ };
3427
+ }