react-native-webrtc 124.0.7 → 124.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/.claude/settings.local.json +9 -0
  2. package/.eslintignore +1 -0
  3. package/CLAUDE.md +714 -0
  4. package/android/src/main/java/com/oney/WebRTCModule/AbstractVideoCaptureController.java +5 -3
  5. package/android/src/main/java/com/oney/WebRTCModule/GetUserMediaImpl.java +67 -7
  6. package/android/src/main/java/com/oney/WebRTCModule/MediaProjectionService.java +24 -3
  7. package/android/src/main/java/com/oney/WebRTCModule/ScreenCaptureController.java +4 -4
  8. package/android/src/main/java/com/oney/WebRTCModule/SerializeUtils.java +8 -0
  9. package/android/src/main/java/com/oney/WebRTCModule/ThreadUtils.java +8 -0
  10. package/android/src/main/java/com/oney/WebRTCModule/WebRTCModule.java +112 -26
  11. package/android/src/main/java/com/oney/WebRTCModule/WebRTCView.java +56 -28
  12. package/ios/RCTWebRTC/RCTConvert+WebRTC.m +19 -0
  13. package/ios/RCTWebRTC/ScreenCapturePickerViewManager.m +22 -23
  14. package/ios/RCTWebRTC/SerializeUtils.m +6 -0
  15. package/ios/RCTWebRTC/VideoCaptureController.m +40 -1
  16. package/ios/RCTWebRTC/WebRTCModule+RTCMediaStream.m +16 -9
  17. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.h +2 -0
  18. package/ios/RCTWebRTC/WebRTCModule+RTCPeerConnection.m +95 -0
  19. package/ios/RCTWebRTC/WebRTCModule+Transceivers.m +1 -0
  20. package/lib/commonjs/MediaDevices.js +12 -10
  21. package/lib/commonjs/MediaDevices.js.map +1 -1
  22. package/lib/commonjs/MediaStream.js +14 -9
  23. package/lib/commonjs/MediaStream.js.map +1 -1
  24. package/lib/commonjs/MediaStreamTrack.js +28 -12
  25. package/lib/commonjs/MediaStreamTrack.js.map +1 -1
  26. package/lib/commonjs/MediaStreamTrackEvent.js +2 -2
  27. package/lib/commonjs/MediaStreamTrackEvent.js.map +1 -1
  28. package/lib/commonjs/MessageEvent.js +2 -2
  29. package/lib/commonjs/MessageEvent.js.map +1 -1
  30. package/lib/commonjs/RTCCertificate.js +25 -0
  31. package/lib/commonjs/RTCCertificate.js.map +1 -0
  32. package/lib/commonjs/RTCDataChannel.js +38 -13
  33. package/lib/commonjs/RTCDataChannel.js.map +1 -1
  34. package/lib/commonjs/RTCDataChannelEvent.js +2 -2
  35. package/lib/commonjs/RTCDataChannelEvent.js.map +1 -1
  36. package/lib/commonjs/RTCErrorEvent.js +2 -2
  37. package/lib/commonjs/RTCErrorEvent.js.map +1 -1
  38. package/lib/commonjs/RTCIceCandidateEvent.js +2 -2
  39. package/lib/commonjs/RTCIceCandidateEvent.js.map +1 -1
  40. package/lib/commonjs/RTCPeerConnection.js +109 -27
  41. package/lib/commonjs/RTCPeerConnection.js.map +1 -1
  42. package/lib/commonjs/RTCRtpEncodingParameters.js +17 -1
  43. package/lib/commonjs/RTCRtpEncodingParameters.js.map +1 -1
  44. package/lib/commonjs/RTCTrackEvent.js +2 -2
  45. package/lib/commonjs/RTCTrackEvent.js.map +1 -1
  46. package/lib/commonjs/getDisplayMedia.js +2 -1
  47. package/lib/commonjs/getDisplayMedia.js.map +1 -1
  48. package/lib/commonjs/index.js +22 -2
  49. package/lib/commonjs/index.js.map +1 -1
  50. package/lib/commonjs/vendor/event-target-shim/LICENSE +22 -0
  51. package/lib/commonjs/vendor/event-target-shim/index.d.js +6 -0
  52. package/lib/commonjs/vendor/event-target-shim/index.d.js.map +1 -0
  53. package/lib/commonjs/vendor/event-target-shim/index.js +1221 -0
  54. package/lib/commonjs/vendor/event-target-shim/index.js.map +1 -0
  55. package/lib/module/MediaDevices.js +11 -9
  56. package/lib/module/MediaDevices.js.map +1 -1
  57. package/lib/module/MediaStream.js +13 -8
  58. package/lib/module/MediaStream.js.map +1 -1
  59. package/lib/module/MediaStreamTrack.js +25 -9
  60. package/lib/module/MediaStreamTrack.js.map +1 -1
  61. package/lib/module/MediaStreamTrackEvent.js +1 -1
  62. package/lib/module/MediaStreamTrackEvent.js.map +1 -1
  63. package/lib/module/MessageEvent.js +1 -1
  64. package/lib/module/MessageEvent.js.map +1 -1
  65. package/lib/module/RTCCertificate.js +18 -0
  66. package/lib/module/RTCCertificate.js.map +1 -0
  67. package/lib/module/RTCDataChannel.js +37 -12
  68. package/lib/module/RTCDataChannel.js.map +1 -1
  69. package/lib/module/RTCDataChannelEvent.js +1 -1
  70. package/lib/module/RTCDataChannelEvent.js.map +1 -1
  71. package/lib/module/RTCErrorEvent.js +1 -1
  72. package/lib/module/RTCErrorEvent.js.map +1 -1
  73. package/lib/module/RTCIceCandidateEvent.js +1 -1
  74. package/lib/module/RTCIceCandidateEvent.js.map +1 -1
  75. package/lib/module/RTCPeerConnection.js +103 -21
  76. package/lib/module/RTCPeerConnection.js.map +1 -1
  77. package/lib/module/RTCRtpEncodingParameters.js +17 -1
  78. package/lib/module/RTCRtpEncodingParameters.js.map +1 -1
  79. package/lib/module/RTCTrackEvent.js +1 -1
  80. package/lib/module/RTCTrackEvent.js.map +1 -1
  81. package/lib/module/getDisplayMedia.js +2 -1
  82. package/lib/module/getDisplayMedia.js.map +1 -1
  83. package/lib/module/index.js +5 -3
  84. package/lib/module/index.js.map +1 -1
  85. package/lib/module/vendor/event-target-shim/LICENSE +22 -0
  86. package/lib/module/vendor/event-target-shim/index.d.js +52 -0
  87. package/lib/module/vendor/event-target-shim/index.d.js.map +1 -0
  88. package/lib/module/vendor/event-target-shim/index.js +1221 -0
  89. package/lib/module/vendor/event-target-shim/index.js.map +1 -0
  90. package/lib/typescript/MediaDevices.d.ts +8 -4
  91. package/lib/typescript/MediaStream.d.ts +5 -1
  92. package/lib/typescript/MediaStreamTrack.d.ts +7 -1
  93. package/lib/typescript/MediaStreamTrackEvent.d.ts +1 -1
  94. package/lib/typescript/MessageEvent.d.ts +1 -1
  95. package/lib/typescript/RTCCertificate.d.ts +16 -0
  96. package/lib/typescript/RTCDataChannel.d.ts +13 -1
  97. package/lib/typescript/RTCDataChannelEvent.d.ts +1 -1
  98. package/lib/typescript/RTCErrorEvent.d.ts +1 -1
  99. package/lib/typescript/RTCIceCandidateEvent.d.ts +1 -1
  100. package/lib/typescript/RTCPeerConnection.d.ts +30 -1
  101. package/lib/typescript/RTCRtpEncodingParameters.d.ts +4 -0
  102. package/lib/typescript/RTCTrackEvent.d.ts +1 -1
  103. package/lib/typescript/getDisplayMedia.d.ts +7 -1
  104. package/lib/typescript/index.d.ts +4 -1
  105. package/package.json +2 -3
  106. package/src/MediaDevices.ts +15 -14
  107. package/src/MediaStream.ts +17 -9
  108. package/src/MediaStreamTrack.ts +30 -10
  109. package/src/MediaStreamTrackEvent.ts +2 -2
  110. package/src/MessageEvent.ts +1 -1
  111. package/src/RTCCertificate.ts +24 -0
  112. package/src/RTCDataChannel.ts +49 -14
  113. package/src/RTCDataChannelEvent.ts +2 -2
  114. package/src/RTCErrorEvent.ts +1 -1
  115. package/src/RTCIceCandidateEvent.ts +2 -2
  116. package/src/RTCPeerConnection.ts +138 -24
  117. package/src/RTCRtpEncodingParameters.ts +20 -0
  118. package/src/RTCTrackEvent.ts +1 -1
  119. package/src/getDisplayMedia.ts +9 -2
  120. package/src/index.ts +9 -2
  121. package/src/vendor/event-target-shim/LICENSE +22 -0
  122. package/src/vendor/event-target-shim/index.d.ts +411 -0
  123. package/src/vendor/event-target-shim/index.js +1186 -0
@@ -0,0 +1,1186 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * Assert a condition.
7
+ * @param condition The condition that it should satisfy.
8
+ * @param message The error message.
9
+ * @param args The arguments for replacing placeholders in the message.
10
+ */
11
+ function assertType(condition, message, ...args) {
12
+ if (!condition) {
13
+ throw new TypeError(format(message, args));
14
+ }
15
+ }
16
+ /**
17
+ * Convert a text and arguments to one string.
18
+ * @param message The formating text
19
+ * @param args The arguments.
20
+ */
21
+ function format(message, args) {
22
+ let i = 0;
23
+ return message.replace(/%[os]/gu, () => anyToString(args[i++]));
24
+ }
25
+ /**
26
+ * Convert a value to a string representation.
27
+ * @param x The value to get the string representation.
28
+ */
29
+ function anyToString(x) {
30
+ if (typeof x !== "object" || x === null) {
31
+ return String(x);
32
+ }
33
+ return Object.prototype.toString.call(x);
34
+ }
35
+
36
+ let currentErrorHandler;
37
+ /**
38
+ * Set the error handler.
39
+ * @param value The error handler to set.
40
+ */
41
+ function setErrorHandler(value) {
42
+ assertType(typeof value === "function" || value === undefined, "The error handler must be a function or undefined, but got %o.", value);
43
+ currentErrorHandler = value;
44
+ }
45
+ /**
46
+ * Print a error message.
47
+ * @param maybeError The error object.
48
+ */
49
+ function reportError(maybeError) {
50
+ try {
51
+ const error = maybeError instanceof Error
52
+ ? maybeError
53
+ : new Error(anyToString(maybeError));
54
+ // Call the user-defined error handler if exists.
55
+ if (currentErrorHandler) {
56
+ currentErrorHandler(error);
57
+ return;
58
+ }
59
+ // Dispatch an `error` event if this is on a browser.
60
+ if (typeof dispatchEvent === "function" &&
61
+ typeof ErrorEvent === "function") {
62
+ dispatchEvent(new ErrorEvent("error", { error, message: error.message }));
63
+ }
64
+ // Emit an `uncaughtException` event if this is on Node.js.
65
+ //istanbul ignore else
66
+ else if (typeof process !== "undefined" &&
67
+ typeof process.emit === "function") {
68
+ process.emit("uncaughtException", error);
69
+ return;
70
+ }
71
+ // Otherwise, print the error.
72
+ console.error(error);
73
+ }
74
+ catch (_a) {
75
+ // ignore.
76
+ }
77
+ }
78
+
79
+ /**
80
+ * The global object.
81
+ */
82
+ //istanbul ignore next
83
+ const Global = typeof window !== "undefined"
84
+ ? window
85
+ : typeof self !== "undefined"
86
+ ? self
87
+ : typeof global !== "undefined"
88
+ ? global
89
+ : typeof globalThis !== "undefined"
90
+ ? globalThis
91
+ : undefined;
92
+
93
+ let currentWarnHandler;
94
+ /**
95
+ * Set the warning handler.
96
+ * @param value The warning handler to set.
97
+ */
98
+ function setWarningHandler(value) {
99
+ assertType(typeof value === "function" || value === undefined, "The warning handler must be a function or undefined, but got %o.", value);
100
+ currentWarnHandler = value;
101
+ }
102
+ /**
103
+ * The warning information.
104
+ */
105
+ class Warning {
106
+ constructor(code, message) {
107
+ this.code = code;
108
+ this.message = message;
109
+ }
110
+ /**
111
+ * Report this warning.
112
+ * @param args The arguments of the warning.
113
+ */
114
+ warn(...args) {
115
+ var _a;
116
+ try {
117
+ // Call the user-defined warning handler if exists.
118
+ if (currentWarnHandler) {
119
+ currentWarnHandler({ ...this, args });
120
+ return;
121
+ }
122
+ // Otherwise, print the warning.
123
+ const stack = ((_a = new Error().stack) !== null && _a !== void 0 ? _a : "").replace(/^(?:.+?\n){2}/gu, "\n");
124
+ console.warn(this.message, ...args, stack);
125
+ }
126
+ catch (_b) {
127
+ // Ignore.
128
+ }
129
+ }
130
+ }
131
+
132
+ const InitEventWasCalledWhileDispatching = new Warning("W01", "Unable to initialize event under dispatching.");
133
+ const FalsyWasAssignedToCancelBubble = new Warning("W02", "Assigning any falsy value to 'cancelBubble' property has no effect.");
134
+ const TruthyWasAssignedToReturnValue = new Warning("W03", "Assigning any truthy value to 'returnValue' property has no effect.");
135
+ const NonCancelableEventWasCanceled = new Warning("W04", "Unable to preventDefault on non-cancelable events.");
136
+ const CanceledInPassiveListener = new Warning("W05", "Unable to preventDefault inside passive event listener invocation.");
137
+ const EventListenerWasDuplicated = new Warning("W06", "An event listener wasn't added because it has been added already: %o, %o");
138
+ const OptionWasIgnored = new Warning("W07", "The %o option value was abandoned because the event listener wasn't added as duplicated.");
139
+ const InvalidEventListener = new Warning("W08", "The 'callback' argument must be a function or an object that has 'handleEvent' method: %o");
140
+ const InvalidAttributeHandler = new Warning("W09", "Event attribute handler must be a function: %o");
141
+
142
+ /*eslint-disable class-methods-use-this */
143
+ /**
144
+ * An implementation of `Event` interface, that wraps a given event object.
145
+ * `EventTarget` shim can control the internal state of this `Event` objects.
146
+ * @see https://dom.spec.whatwg.org/#event
147
+ */
148
+ class Event {
149
+ /**
150
+ * @see https://dom.spec.whatwg.org/#dom-event-none
151
+ */
152
+ static get NONE() {
153
+ return NONE;
154
+ }
155
+ /**
156
+ * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase
157
+ */
158
+ static get CAPTURING_PHASE() {
159
+ return CAPTURING_PHASE;
160
+ }
161
+ /**
162
+ * @see https://dom.spec.whatwg.org/#dom-event-at_target
163
+ */
164
+ static get AT_TARGET() {
165
+ return AT_TARGET;
166
+ }
167
+ /**
168
+ * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase
169
+ */
170
+ static get BUBBLING_PHASE() {
171
+ return BUBBLING_PHASE;
172
+ }
173
+ /**
174
+ * Initialize this event instance.
175
+ * @param type The type of this event.
176
+ * @param eventInitDict Options to initialize.
177
+ * @see https://dom.spec.whatwg.org/#dom-event-event
178
+ */
179
+ constructor(type, eventInitDict) {
180
+ Object.defineProperty(this, "isTrusted", {
181
+ value: false,
182
+ enumerable: true,
183
+ });
184
+ const opts = eventInitDict !== null && eventInitDict !== void 0 ? eventInitDict : {};
185
+ internalDataMap.set(this, {
186
+ type: String(type),
187
+ bubbles: Boolean(opts.bubbles),
188
+ cancelable: Boolean(opts.cancelable),
189
+ composed: Boolean(opts.composed),
190
+ target: null,
191
+ currentTarget: null,
192
+ stopPropagationFlag: false,
193
+ stopImmediatePropagationFlag: false,
194
+ canceledFlag: false,
195
+ inPassiveListenerFlag: false,
196
+ dispatchFlag: false,
197
+ timeStamp: Date.now(),
198
+ });
199
+ }
200
+ /**
201
+ * The type of this event.
202
+ * @see https://dom.spec.whatwg.org/#dom-event-type
203
+ */
204
+ get type() {
205
+ return $(this).type;
206
+ }
207
+ /**
208
+ * The event target of the current dispatching.
209
+ * @see https://dom.spec.whatwg.org/#dom-event-target
210
+ */
211
+ get target() {
212
+ return $(this).target;
213
+ }
214
+ /**
215
+ * The event target of the current dispatching.
216
+ * @deprecated Use the `target` property instead.
217
+ * @see https://dom.spec.whatwg.org/#dom-event-srcelement
218
+ */
219
+ get srcElement() {
220
+ return $(this).target;
221
+ }
222
+ /**
223
+ * The event target of the current dispatching.
224
+ * @see https://dom.spec.whatwg.org/#dom-event-currenttarget
225
+ */
226
+ get currentTarget() {
227
+ return $(this).currentTarget;
228
+ }
229
+ /**
230
+ * The event target of the current dispatching.
231
+ * This doesn't support node tree.
232
+ * @see https://dom.spec.whatwg.org/#dom-event-composedpath
233
+ */
234
+ composedPath() {
235
+ const currentTarget = $(this).currentTarget;
236
+ if (currentTarget) {
237
+ return [currentTarget];
238
+ }
239
+ return [];
240
+ }
241
+ /**
242
+ * @see https://dom.spec.whatwg.org/#dom-event-none
243
+ */
244
+ get NONE() {
245
+ return NONE;
246
+ }
247
+ /**
248
+ * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase
249
+ */
250
+ get CAPTURING_PHASE() {
251
+ return CAPTURING_PHASE;
252
+ }
253
+ /**
254
+ * @see https://dom.spec.whatwg.org/#dom-event-at_target
255
+ */
256
+ get AT_TARGET() {
257
+ return AT_TARGET;
258
+ }
259
+ /**
260
+ * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase
261
+ */
262
+ get BUBBLING_PHASE() {
263
+ return BUBBLING_PHASE;
264
+ }
265
+ /**
266
+ * The current event phase.
267
+ * @see https://dom.spec.whatwg.org/#dom-event-eventphase
268
+ */
269
+ get eventPhase() {
270
+ return $(this).dispatchFlag ? 2 : 0;
271
+ }
272
+ /**
273
+ * Stop event bubbling.
274
+ * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value.
275
+ * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation
276
+ */
277
+ stopPropagation() {
278
+ $(this).stopPropagationFlag = true;
279
+ }
280
+ /**
281
+ * `true` if event bubbling was stopped.
282
+ * @deprecated
283
+ * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble
284
+ */
285
+ get cancelBubble() {
286
+ return $(this).stopPropagationFlag;
287
+ }
288
+ /**
289
+ * Stop event bubbling if `true` is set.
290
+ * @deprecated Use the `stopPropagation()` method instead.
291
+ * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble
292
+ */
293
+ set cancelBubble(value) {
294
+ if (value) {
295
+ $(this).stopPropagationFlag = true;
296
+ }
297
+ else {
298
+ FalsyWasAssignedToCancelBubble.warn();
299
+ }
300
+ }
301
+ /**
302
+ * Stop event bubbling and subsequent event listener callings.
303
+ * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation
304
+ */
305
+ stopImmediatePropagation() {
306
+ const data = $(this);
307
+ data.stopPropagationFlag = data.stopImmediatePropagationFlag = true;
308
+ }
309
+ /**
310
+ * `true` if this event will bubble.
311
+ * @see https://dom.spec.whatwg.org/#dom-event-bubbles
312
+ */
313
+ get bubbles() {
314
+ return $(this).bubbles;
315
+ }
316
+ /**
317
+ * `true` if this event can be canceled by the `preventDefault()` method.
318
+ * @see https://dom.spec.whatwg.org/#dom-event-cancelable
319
+ */
320
+ get cancelable() {
321
+ return $(this).cancelable;
322
+ }
323
+ /**
324
+ * `true` if the default behavior will act.
325
+ * @deprecated Use the `defaultPrevented` proeprty instead.
326
+ * @see https://dom.spec.whatwg.org/#dom-event-returnvalue
327
+ */
328
+ get returnValue() {
329
+ return !$(this).canceledFlag;
330
+ }
331
+ /**
332
+ * Cancel the default behavior if `false` is set.
333
+ * @deprecated Use the `preventDefault()` method instead.
334
+ * @see https://dom.spec.whatwg.org/#dom-event-returnvalue
335
+ */
336
+ set returnValue(value) {
337
+ if (!value) {
338
+ setCancelFlag($(this));
339
+ }
340
+ else {
341
+ TruthyWasAssignedToReturnValue.warn();
342
+ }
343
+ }
344
+ /**
345
+ * Cancel the default behavior.
346
+ * @see https://dom.spec.whatwg.org/#dom-event-preventdefault
347
+ */
348
+ preventDefault() {
349
+ setCancelFlag($(this));
350
+ }
351
+ /**
352
+ * `true` if the default behavior was canceled.
353
+ * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented
354
+ */
355
+ get defaultPrevented() {
356
+ return $(this).canceledFlag;
357
+ }
358
+ /**
359
+ * @see https://dom.spec.whatwg.org/#dom-event-composed
360
+ */
361
+ get composed() {
362
+ return $(this).composed;
363
+ }
364
+ /**
365
+ * @see https://dom.spec.whatwg.org/#dom-event-istrusted
366
+ */
367
+ //istanbul ignore next
368
+ get isTrusted() {
369
+ return false;
370
+ }
371
+ /**
372
+ * @see https://dom.spec.whatwg.org/#dom-event-timestamp
373
+ */
374
+ get timeStamp() {
375
+ return $(this).timeStamp;
376
+ }
377
+ /**
378
+ * @deprecated Don't use this method. The constructor did initialization.
379
+ */
380
+ initEvent(type, bubbles = false, cancelable = false) {
381
+ const data = $(this);
382
+ if (data.dispatchFlag) {
383
+ InitEventWasCalledWhileDispatching.warn();
384
+ return;
385
+ }
386
+ internalDataMap.set(this, {
387
+ ...data,
388
+ type: String(type),
389
+ bubbles: Boolean(bubbles),
390
+ cancelable: Boolean(cancelable),
391
+ target: null,
392
+ currentTarget: null,
393
+ stopPropagationFlag: false,
394
+ stopImmediatePropagationFlag: false,
395
+ canceledFlag: false,
396
+ });
397
+ }
398
+ }
399
+ //------------------------------------------------------------------------------
400
+ // Helpers
401
+ //------------------------------------------------------------------------------
402
+ const NONE = 0;
403
+ const CAPTURING_PHASE = 1;
404
+ const AT_TARGET = 2;
405
+ const BUBBLING_PHASE = 3;
406
+ /**
407
+ * Private data for event wrappers.
408
+ */
409
+ const internalDataMap = new WeakMap();
410
+ /**
411
+ * Get private data.
412
+ * @param event The event object to get private data.
413
+ * @param name The variable name to report.
414
+ * @returns The private data of the event.
415
+ */
416
+ function $(event, name = "this") {
417
+ const retv = internalDataMap.get(event);
418
+ assertType(retv != null, "'%s' must be an object that Event constructor created, but got another one: %o", name, event);
419
+ return retv;
420
+ }
421
+ /**
422
+ * https://dom.spec.whatwg.org/#set-the-canceled-flag
423
+ * @param data private data.
424
+ */
425
+ function setCancelFlag(data) {
426
+ if (data.inPassiveListenerFlag) {
427
+ CanceledInPassiveListener.warn();
428
+ return;
429
+ }
430
+ if (!data.cancelable) {
431
+ NonCancelableEventWasCanceled.warn();
432
+ return;
433
+ }
434
+ data.canceledFlag = true;
435
+ }
436
+ // Set enumerable
437
+ Object.defineProperty(Event, "NONE", { enumerable: true });
438
+ Object.defineProperty(Event, "CAPTURING_PHASE", { enumerable: true });
439
+ Object.defineProperty(Event, "AT_TARGET", { enumerable: true });
440
+ Object.defineProperty(Event, "BUBBLING_PHASE", { enumerable: true });
441
+ const keys = Object.getOwnPropertyNames(Event.prototype);
442
+ for (let i = 0; i < keys.length; ++i) {
443
+ if (keys[i] === "constructor") {
444
+ continue;
445
+ }
446
+ Object.defineProperty(Event.prototype, keys[i], { enumerable: true });
447
+ }
448
+ // Ensure `event instanceof window.Event` is `true`.
449
+ if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") {
450
+ Object.setPrototypeOf(Event.prototype, Global.Event.prototype);
451
+ }
452
+
453
+ /**
454
+ * Create a new InvalidStateError instance.
455
+ * @param message The error message.
456
+ */
457
+ function createInvalidStateError(message) {
458
+ if (Global.DOMException) {
459
+ return new Global.DOMException(message, "InvalidStateError");
460
+ }
461
+ if (DOMException == null) {
462
+ DOMException = class DOMException extends Error {
463
+ constructor(msg) {
464
+ super(msg);
465
+ if (Error.captureStackTrace) {
466
+ Error.captureStackTrace(this, DOMException);
467
+ }
468
+ }
469
+ // eslint-disable-next-line class-methods-use-this
470
+ get code() {
471
+ return 11;
472
+ }
473
+ // eslint-disable-next-line class-methods-use-this
474
+ get name() {
475
+ return "InvalidStateError";
476
+ }
477
+ };
478
+ Object.defineProperties(DOMException.prototype, {
479
+ code: { enumerable: true },
480
+ name: { enumerable: true },
481
+ });
482
+ defineErrorCodeProperties(DOMException);
483
+ defineErrorCodeProperties(DOMException.prototype);
484
+ }
485
+ return new DOMException(message);
486
+ }
487
+ //------------------------------------------------------------------------------
488
+ // Helpers
489
+ //------------------------------------------------------------------------------
490
+ let DOMException;
491
+ const ErrorCodeMap = {
492
+ INDEX_SIZE_ERR: 1,
493
+ DOMSTRING_SIZE_ERR: 2,
494
+ HIERARCHY_REQUEST_ERR: 3,
495
+ WRONG_DOCUMENT_ERR: 4,
496
+ INVALID_CHARACTER_ERR: 5,
497
+ NO_DATA_ALLOWED_ERR: 6,
498
+ NO_MODIFICATION_ALLOWED_ERR: 7,
499
+ NOT_FOUND_ERR: 8,
500
+ NOT_SUPPORTED_ERR: 9,
501
+ INUSE_ATTRIBUTE_ERR: 10,
502
+ INVALID_STATE_ERR: 11,
503
+ SYNTAX_ERR: 12,
504
+ INVALID_MODIFICATION_ERR: 13,
505
+ NAMESPACE_ERR: 14,
506
+ INVALID_ACCESS_ERR: 15,
507
+ VALIDATION_ERR: 16,
508
+ TYPE_MISMATCH_ERR: 17,
509
+ SECURITY_ERR: 18,
510
+ NETWORK_ERR: 19,
511
+ ABORT_ERR: 20,
512
+ URL_MISMATCH_ERR: 21,
513
+ QUOTA_EXCEEDED_ERR: 22,
514
+ TIMEOUT_ERR: 23,
515
+ INVALID_NODE_TYPE_ERR: 24,
516
+ DATA_CLONE_ERR: 25,
517
+ };
518
+ function defineErrorCodeProperties(obj) {
519
+ const keys = Object.keys(ErrorCodeMap);
520
+ for (let i = 0; i < keys.length; ++i) {
521
+ const key = keys[i];
522
+ const value = ErrorCodeMap[key];
523
+ Object.defineProperty(obj, key, {
524
+ get() {
525
+ return value;
526
+ },
527
+ configurable: true,
528
+ enumerable: true,
529
+ });
530
+ }
531
+ }
532
+
533
+ /**
534
+ * An implementation of `Event` interface, that wraps a given event object.
535
+ * This class controls the internal state of `Event`.
536
+ * @see https://dom.spec.whatwg.org/#interface-event
537
+ */
538
+ class EventWrapper extends Event {
539
+ /**
540
+ * Wrap a given event object to control states.
541
+ * @param event The event-like object to wrap.
542
+ */
543
+ static wrap(event) {
544
+ return new (getWrapperClassOf(event))(event);
545
+ }
546
+ constructor(event) {
547
+ super(event.type, {
548
+ bubbles: event.bubbles,
549
+ cancelable: event.cancelable,
550
+ composed: event.composed,
551
+ });
552
+ if (event.cancelBubble) {
553
+ super.stopPropagation();
554
+ }
555
+ if (event.defaultPrevented) {
556
+ super.preventDefault();
557
+ }
558
+ internalDataMap$1.set(this, { original: event });
559
+ // Define accessors
560
+ const keys = Object.keys(event);
561
+ for (let i = 0; i < keys.length; ++i) {
562
+ const key = keys[i];
563
+ if (!(key in this)) {
564
+ Object.defineProperty(this, key, defineRedirectDescriptor(event, key));
565
+ }
566
+ }
567
+ }
568
+ stopPropagation() {
569
+ super.stopPropagation();
570
+ const { original } = $$1(this);
571
+ if ("stopPropagation" in original) {
572
+ original.stopPropagation();
573
+ }
574
+ }
575
+ get cancelBubble() {
576
+ return super.cancelBubble;
577
+ }
578
+ set cancelBubble(value) {
579
+ super.cancelBubble = value;
580
+ const { original } = $$1(this);
581
+ if ("cancelBubble" in original) {
582
+ original.cancelBubble = value;
583
+ }
584
+ }
585
+ stopImmediatePropagation() {
586
+ super.stopImmediatePropagation();
587
+ const { original } = $$1(this);
588
+ if ("stopImmediatePropagation" in original) {
589
+ original.stopImmediatePropagation();
590
+ }
591
+ }
592
+ get returnValue() {
593
+ return super.returnValue;
594
+ }
595
+ set returnValue(value) {
596
+ super.returnValue = value;
597
+ const { original } = $$1(this);
598
+ if ("returnValue" in original) {
599
+ original.returnValue = value;
600
+ }
601
+ }
602
+ preventDefault() {
603
+ super.preventDefault();
604
+ const { original } = $$1(this);
605
+ if ("preventDefault" in original) {
606
+ original.preventDefault();
607
+ }
608
+ }
609
+ get timeStamp() {
610
+ const { original } = $$1(this);
611
+ if ("timeStamp" in original) {
612
+ return original.timeStamp;
613
+ }
614
+ return super.timeStamp;
615
+ }
616
+ }
617
+ /**
618
+ * Private data for event wrappers.
619
+ */
620
+ const internalDataMap$1 = new WeakMap();
621
+ /**
622
+ * Get private data.
623
+ * @param event The event object to get private data.
624
+ * @returns The private data of the event.
625
+ */
626
+ function $$1(event) {
627
+ const retv = internalDataMap$1.get(event);
628
+ assertType(retv != null, "'this' is expected an Event object, but got", event);
629
+ return retv;
630
+ }
631
+ /**
632
+ * Cache for wrapper classes.
633
+ * @type {WeakMap<Object, Function>}
634
+ * @private
635
+ */
636
+ const wrapperClassCache = new WeakMap();
637
+ // Make association for wrappers.
638
+ wrapperClassCache.set(Object.prototype, EventWrapper);
639
+ if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") {
640
+ wrapperClassCache.set(Global.Event.prototype, EventWrapper);
641
+ }
642
+ /**
643
+ * Get the wrapper class of a given prototype.
644
+ * @param originalEvent The event object to wrap.
645
+ */
646
+ function getWrapperClassOf(originalEvent) {
647
+ const prototype = Object.getPrototypeOf(originalEvent);
648
+ if (prototype == null) {
649
+ return EventWrapper;
650
+ }
651
+ let wrapper = wrapperClassCache.get(prototype);
652
+ if (wrapper == null) {
653
+ wrapper = defineWrapper(getWrapperClassOf(prototype), prototype);
654
+ wrapperClassCache.set(prototype, wrapper);
655
+ }
656
+ return wrapper;
657
+ }
658
+ /**
659
+ * Define new wrapper class.
660
+ * @param BaseEventWrapper The base wrapper class.
661
+ * @param originalPrototype The prototype of the original event.
662
+ */
663
+ function defineWrapper(BaseEventWrapper, originalPrototype) {
664
+ class CustomEventWrapper extends BaseEventWrapper {
665
+ }
666
+ const keys = Object.keys(originalPrototype);
667
+ for (let i = 0; i < keys.length; ++i) {
668
+ Object.defineProperty(CustomEventWrapper.prototype, keys[i], defineRedirectDescriptor(originalPrototype, keys[i]));
669
+ }
670
+ return CustomEventWrapper;
671
+ }
672
+ /**
673
+ * Get the property descriptor to redirect a given property.
674
+ */
675
+ function defineRedirectDescriptor(obj, key) {
676
+ const d = Object.getOwnPropertyDescriptor(obj, key);
677
+ return {
678
+ get() {
679
+ const original = $$1(this).original;
680
+ const value = original[key];
681
+ if (typeof value === "function") {
682
+ return value.bind(original);
683
+ }
684
+ return value;
685
+ },
686
+ set(value) {
687
+ const original = $$1(this).original;
688
+ original[key] = value;
689
+ },
690
+ configurable: d.configurable,
691
+ enumerable: d.enumerable,
692
+ };
693
+ }
694
+
695
+ /**
696
+ * Create a new listener.
697
+ * @param callback The callback function.
698
+ * @param capture The capture flag.
699
+ * @param passive The passive flag.
700
+ * @param once The once flag.
701
+ * @param signal The abort signal.
702
+ * @param signalListener The abort event listener for the abort signal.
703
+ */
704
+ function createListener(callback, capture, passive, once, signal, signalListener) {
705
+ return {
706
+ callback,
707
+ flags: (capture ? 1 /* Capture */ : 0) |
708
+ (passive ? 2 /* Passive */ : 0) |
709
+ (once ? 4 /* Once */ : 0),
710
+ signal,
711
+ signalListener,
712
+ };
713
+ }
714
+ /**
715
+ * Set the `removed` flag to the given listener.
716
+ * @param listener The listener to check.
717
+ */
718
+ function setRemoved(listener) {
719
+ listener.flags |= 8 /* Removed */;
720
+ }
721
+ /**
722
+ * Check if the given listener has the `capture` flag or not.
723
+ * @param listener The listener to check.
724
+ */
725
+ function isCapture(listener) {
726
+ return (listener.flags & 1 /* Capture */) === 1 /* Capture */;
727
+ }
728
+ /**
729
+ * Check if the given listener has the `passive` flag or not.
730
+ * @param listener The listener to check.
731
+ */
732
+ function isPassive(listener) {
733
+ return (listener.flags & 2 /* Passive */) === 2 /* Passive */;
734
+ }
735
+ /**
736
+ * Check if the given listener has the `once` flag or not.
737
+ * @param listener The listener to check.
738
+ */
739
+ function isOnce(listener) {
740
+ return (listener.flags & 4 /* Once */) === 4 /* Once */;
741
+ }
742
+ /**
743
+ * Check if the given listener has the `removed` flag or not.
744
+ * @param listener The listener to check.
745
+ */
746
+ function isRemoved(listener) {
747
+ return (listener.flags & 8 /* Removed */) === 8 /* Removed */;
748
+ }
749
+ /**
750
+ * Call an event listener.
751
+ * @param listener The listener to call.
752
+ * @param target The event target object for `thisArg`.
753
+ * @param event The event object for the first argument.
754
+ * @param attribute `true` if this callback is an event attribute handler.
755
+ */
756
+ function invokeCallback({ callback }, target, event) {
757
+ try {
758
+ if (typeof callback === "function") {
759
+ callback.call(target, event);
760
+ }
761
+ else if (typeof callback.handleEvent === "function") {
762
+ callback.handleEvent(event);
763
+ }
764
+ }
765
+ catch (thrownError) {
766
+ reportError(thrownError);
767
+ }
768
+ }
769
+
770
+ /**
771
+ * Find the index of given listener.
772
+ * This returns `-1` if not found.
773
+ * @param list The listener list.
774
+ * @param callback The callback function to find.
775
+ * @param capture The capture flag to find.
776
+ */
777
+ function findIndexOfListener({ listeners }, callback, capture) {
778
+ for (let i = 0; i < listeners.length; ++i) {
779
+ if (listeners[i].callback === callback &&
780
+ isCapture(listeners[i]) === capture) {
781
+ return i;
782
+ }
783
+ }
784
+ return -1;
785
+ }
786
+ /**
787
+ * Add the given listener.
788
+ * Does copy-on-write if needed.
789
+ * @param list The listener list.
790
+ * @param callback The callback function.
791
+ * @param capture The capture flag.
792
+ * @param passive The passive flag.
793
+ * @param once The once flag.
794
+ * @param signal The abort signal.
795
+ */
796
+ function addListener(list, callback, capture, passive, once, signal) {
797
+ let signalListener;
798
+ if (signal) {
799
+ signalListener = removeListener.bind(null, list, callback, capture);
800
+ signal.addEventListener("abort", signalListener);
801
+ }
802
+ const listener = createListener(callback, capture, passive, once, signal, signalListener);
803
+ if (list.cow) {
804
+ list.cow = false;
805
+ list.listeners = [...list.listeners, listener];
806
+ }
807
+ else {
808
+ list.listeners.push(listener);
809
+ }
810
+ return listener;
811
+ }
812
+ /**
813
+ * Remove a listener.
814
+ * @param list The listener list.
815
+ * @param callback The callback function to find.
816
+ * @param capture The capture flag to find.
817
+ * @returns `true` if it mutated the list directly.
818
+ */
819
+ function removeListener(list, callback, capture) {
820
+ const index = findIndexOfListener(list, callback, capture);
821
+ if (index !== -1) {
822
+ return removeListenerAt(list, index);
823
+ }
824
+ return false;
825
+ }
826
+ /**
827
+ * Remove a listener.
828
+ * @param list The listener list.
829
+ * @param index The index of the target listener.
830
+ * @param disableCow Disable copy-on-write if true.
831
+ * @returns `true` if it mutated the `listeners` array directly.
832
+ */
833
+ function removeListenerAt(list, index, disableCow = false) {
834
+ const listener = list.listeners[index];
835
+ // Set the removed flag.
836
+ setRemoved(listener);
837
+ // Dispose the abort signal listener if exists.
838
+ if (listener.signal) {
839
+ listener.signal.removeEventListener("abort", listener.signalListener);
840
+ }
841
+ // Remove it from the array.
842
+ if (list.cow && !disableCow) {
843
+ list.cow = false;
844
+ list.listeners = list.listeners.filter((_, i) => i !== index);
845
+ return false;
846
+ }
847
+ list.listeners.splice(index, 1);
848
+ return true;
849
+ }
850
+
851
+ /**
852
+ * Create a new `ListenerListMap` object.
853
+ */
854
+ function createListenerListMap() {
855
+ return Object.create(null);
856
+ }
857
+ /**
858
+ * Get the listener list of the given type.
859
+ * If the listener list has not been initialized, initialize and return it.
860
+ * @param listenerMap The listener list map.
861
+ * @param type The event type to get.
862
+ */
863
+ function ensureListenerList(listenerMap, type) {
864
+ var _a;
865
+ return ((_a = listenerMap[type]) !== null && _a !== void 0 ? _a : (listenerMap[type] = {
866
+ attrCallback: undefined,
867
+ attrListener: undefined,
868
+ cow: false,
869
+ listeners: [],
870
+ }));
871
+ }
872
+
873
+ /**
874
+ * An implementation of the `EventTarget` interface.
875
+ * @see https://dom.spec.whatwg.org/#eventtarget
876
+ */
877
+ class EventTarget {
878
+ /**
879
+ * Initialize this instance.
880
+ */
881
+ constructor() {
882
+ internalDataMap$2.set(this, createListenerListMap());
883
+ }
884
+ // Implementation
885
+ addEventListener(type0, callback0, options0) {
886
+ const listenerMap = $$2(this);
887
+ const { callback, capture, once, passive, signal, type, } = normalizeAddOptions(type0, callback0, options0);
888
+ if (callback == null || (signal === null || signal === void 0 ? void 0 : signal.aborted)) {
889
+ return;
890
+ }
891
+ const list = ensureListenerList(listenerMap, type);
892
+ // Find existing listener.
893
+ const i = findIndexOfListener(list, callback, capture);
894
+ if (i !== -1) {
895
+ warnDuplicate(list.listeners[i], passive, once, signal);
896
+ return;
897
+ }
898
+ // Add the new listener.
899
+ addListener(list, callback, capture, passive, once, signal);
900
+ }
901
+ // Implementation
902
+ removeEventListener(type0, callback0, options0) {
903
+ const listenerMap = $$2(this);
904
+ const { callback, capture, type } = normalizeOptions(type0, callback0, options0);
905
+ const list = listenerMap[type];
906
+ if (callback != null && list) {
907
+ removeListener(list, callback, capture);
908
+ }
909
+ }
910
+ // Implementation
911
+ dispatchEvent(e) {
912
+ const list = $$2(this)[String(e.type)];
913
+ if (list == null) {
914
+ return true;
915
+ }
916
+ const event = e instanceof Event ? e : EventWrapper.wrap(e);
917
+ const eventData = $(event, "event");
918
+ if (eventData.dispatchFlag) {
919
+ throw createInvalidStateError("This event has been in dispatching.");
920
+ }
921
+ eventData.dispatchFlag = true;
922
+ eventData.target = eventData.currentTarget = this;
923
+ if (!eventData.stopPropagationFlag) {
924
+ const { cow, listeners } = list;
925
+ // Set copy-on-write flag.
926
+ list.cow = true;
927
+ // Call listeners.
928
+ for (let i = 0; i < listeners.length; ++i) {
929
+ const listener = listeners[i];
930
+ // Skip if removed.
931
+ if (isRemoved(listener)) {
932
+ continue;
933
+ }
934
+ // Remove this listener if has the `once` flag.
935
+ if (isOnce(listener) && removeListenerAt(list, i, !cow)) {
936
+ // Because this listener was removed, the next index is the
937
+ // same as the current value.
938
+ i -= 1;
939
+ }
940
+ // Call this listener with the `passive` flag.
941
+ eventData.inPassiveListenerFlag = isPassive(listener);
942
+ invokeCallback(listener, this, event);
943
+ eventData.inPassiveListenerFlag = false;
944
+ // Stop if the `event.stopImmediatePropagation()` method was called.
945
+ if (eventData.stopImmediatePropagationFlag) {
946
+ break;
947
+ }
948
+ }
949
+ // Restore copy-on-write flag.
950
+ if (!cow) {
951
+ list.cow = false;
952
+ }
953
+ }
954
+ eventData.target = null;
955
+ eventData.currentTarget = null;
956
+ eventData.stopImmediatePropagationFlag = false;
957
+ eventData.stopPropagationFlag = false;
958
+ eventData.dispatchFlag = false;
959
+ return !eventData.canceledFlag;
960
+ }
961
+ }
962
+ /**
963
+ * Internal data.
964
+ */
965
+ const internalDataMap$2 = new WeakMap();
966
+ /**
967
+ * Get private data.
968
+ * @param target The event target object to get private data.
969
+ * @param name The variable name to report.
970
+ * @returns The private data of the event.
971
+ */
972
+ function $$2(target, name = "this") {
973
+ const retv = internalDataMap$2.get(target);
974
+ assertType(retv != null, "'%s' must be an object that EventTarget constructor created, but got another one: %o", name, target);
975
+ return retv;
976
+ }
977
+ /**
978
+ * Normalize options.
979
+ * @param options The options to normalize.
980
+ */
981
+ function normalizeAddOptions(type, callback, options) {
982
+ var _a;
983
+ assertCallback(callback);
984
+ if (typeof options === "object" && options !== null) {
985
+ return {
986
+ type: String(type),
987
+ callback: callback !== null && callback !== void 0 ? callback : undefined,
988
+ capture: Boolean(options.capture),
989
+ passive: Boolean(options.passive),
990
+ once: Boolean(options.once),
991
+ signal: (_a = options.signal) !== null && _a !== void 0 ? _a : undefined,
992
+ };
993
+ }
994
+ return {
995
+ type: String(type),
996
+ callback: callback !== null && callback !== void 0 ? callback : undefined,
997
+ capture: Boolean(options),
998
+ passive: false,
999
+ once: false,
1000
+ signal: undefined,
1001
+ };
1002
+ }
1003
+ /**
1004
+ * Normalize options.
1005
+ * @param options The options to normalize.
1006
+ */
1007
+ function normalizeOptions(type, callback, options) {
1008
+ assertCallback(callback);
1009
+ if (typeof options === "object" && options !== null) {
1010
+ return {
1011
+ type: String(type),
1012
+ callback: callback !== null && callback !== void 0 ? callback : undefined,
1013
+ capture: Boolean(options.capture),
1014
+ };
1015
+ }
1016
+ return {
1017
+ type: String(type),
1018
+ callback: callback !== null && callback !== void 0 ? callback : undefined,
1019
+ capture: Boolean(options),
1020
+ };
1021
+ }
1022
+ /**
1023
+ * Assert the type of 'callback' argument.
1024
+ * @param callback The callback to check.
1025
+ */
1026
+ function assertCallback(callback) {
1027
+ if (typeof callback === "function" ||
1028
+ (typeof callback === "object" &&
1029
+ callback !== null &&
1030
+ typeof callback.handleEvent === "function")) {
1031
+ return;
1032
+ }
1033
+ if (callback == null || typeof callback === "object") {
1034
+ InvalidEventListener.warn(callback);
1035
+ return;
1036
+ }
1037
+ throw new TypeError(format(InvalidEventListener.message, [callback]));
1038
+ }
1039
+ /**
1040
+ * Print warning for duplicated.
1041
+ * @param listener The current listener that is duplicated.
1042
+ * @param passive The passive flag of the new duplicated listener.
1043
+ * @param once The once flag of the new duplicated listener.
1044
+ * @param signal The signal object of the new duplicated listener.
1045
+ */
1046
+ function warnDuplicate(listener, passive, once, signal) {
1047
+ EventListenerWasDuplicated.warn(isCapture(listener) ? "capture" : "bubble", listener.callback);
1048
+ if (isPassive(listener) !== passive) {
1049
+ OptionWasIgnored.warn("passive");
1050
+ }
1051
+ if (isOnce(listener) !== once) {
1052
+ OptionWasIgnored.warn("once");
1053
+ }
1054
+ if (listener.signal !== signal) {
1055
+ OptionWasIgnored.warn("signal");
1056
+ }
1057
+ }
1058
+ // Set enumerable
1059
+ const keys$1 = Object.getOwnPropertyNames(EventTarget.prototype);
1060
+ for (let i = 0; i < keys$1.length; ++i) {
1061
+ if (keys$1[i] === "constructor") {
1062
+ continue;
1063
+ }
1064
+ Object.defineProperty(EventTarget.prototype, keys$1[i], { enumerable: true });
1065
+ }
1066
+ // Ensure `eventTarget instanceof window.EventTarget` is `true`.
1067
+ if (typeof Global !== "undefined" &&
1068
+ typeof Global.EventTarget !== "undefined") {
1069
+ Object.setPrototypeOf(EventTarget.prototype, Global.EventTarget.prototype);
1070
+ }
1071
+
1072
+ /**
1073
+ * Get the current value of a given event attribute.
1074
+ * @param target The `EventTarget` object to get.
1075
+ * @param type The event type.
1076
+ */
1077
+ function getEventAttributeValue(target, type) {
1078
+ var _a, _b;
1079
+ const listMap = $$2(target, "target");
1080
+ return (_b = (_a = listMap[type]) === null || _a === void 0 ? void 0 : _a.attrCallback) !== null && _b !== void 0 ? _b : null;
1081
+ }
1082
+ /**
1083
+ * Set an event listener to a given event attribute.
1084
+ * @param target The `EventTarget` object to set.
1085
+ * @param type The event type.
1086
+ * @param callback The event listener.
1087
+ */
1088
+ function setEventAttributeValue(target, type, callback) {
1089
+ if (callback != null && typeof callback !== "function") {
1090
+ InvalidAttributeHandler.warn(callback);
1091
+ }
1092
+ if (typeof callback === "function" ||
1093
+ (typeof callback === "object" && callback !== null)) {
1094
+ upsertEventAttributeListener(target, type, callback);
1095
+ }
1096
+ else {
1097
+ removeEventAttributeListener(target, type);
1098
+ }
1099
+ }
1100
+ //------------------------------------------------------------------------------
1101
+ // Helpers
1102
+ //------------------------------------------------------------------------------
1103
+ /**
1104
+ * Update or insert the given event attribute handler.
1105
+ * @param target The `EventTarget` object to set.
1106
+ * @param type The event type.
1107
+ * @param callback The event listener.
1108
+ */
1109
+ function upsertEventAttributeListener(target, type, callback) {
1110
+ const list = ensureListenerList($$2(target, "target"), String(type));
1111
+ list.attrCallback = callback;
1112
+ if (list.attrListener == null) {
1113
+ list.attrListener = addListener(list, defineEventAttributeCallback(list), false, false, false, undefined);
1114
+ }
1115
+ }
1116
+ /**
1117
+ * Remove the given event attribute handler.
1118
+ * @param target The `EventTarget` object to remove.
1119
+ * @param type The event type.
1120
+ * @param callback The event listener.
1121
+ */
1122
+ function removeEventAttributeListener(target, type) {
1123
+ const listMap = $$2(target, "target");
1124
+ const list = listMap[String(type)];
1125
+ if (list && list.attrListener) {
1126
+ removeListener(list, list.attrListener.callback, false);
1127
+ list.attrCallback = list.attrListener = undefined;
1128
+ }
1129
+ }
1130
+ /**
1131
+ * Define the callback function for the given listener list object.
1132
+ * It calls `attrCallback` property if the property value is a function.
1133
+ * @param list The `ListenerList` object.
1134
+ */
1135
+ function defineEventAttributeCallback(list) {
1136
+ return function (event) {
1137
+ const callback = list.attrCallback;
1138
+ if (typeof callback === "function") {
1139
+ callback.call(this, event);
1140
+ }
1141
+ };
1142
+ }
1143
+
1144
+ /**
1145
+ * Define an `EventTarget` class that has event attibutes.
1146
+ * @param types The types to define event attributes.
1147
+ * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly.
1148
+ */
1149
+ function defineCustomEventTarget(...types) {
1150
+ class CustomEventTarget extends EventTarget {
1151
+ }
1152
+ for (let i = 0; i < types.length; ++i) {
1153
+ defineEventAttribute(CustomEventTarget.prototype, types[i]);
1154
+ }
1155
+ return CustomEventTarget;
1156
+ }
1157
+ /**
1158
+ * Define an event attribute.
1159
+ * @param target The `EventTarget` object to define an event attribute.
1160
+ * @param type The event type to define.
1161
+ * @param _eventClass Unused, but to infer `Event` class type.
1162
+ * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly.
1163
+ */
1164
+ function defineEventAttribute(target, type, _eventClass) {
1165
+ Object.defineProperty(target, `on${type}`, {
1166
+ get() {
1167
+ return getEventAttributeValue(this, type);
1168
+ },
1169
+ set(value) {
1170
+ setEventAttributeValue(this, type, value);
1171
+ },
1172
+ configurable: true,
1173
+ enumerable: true,
1174
+ });
1175
+ }
1176
+
1177
+ exports.Event = Event;
1178
+ exports.EventTarget = EventTarget;
1179
+ exports.default = EventTarget;
1180
+ exports.defineCustomEventTarget = defineCustomEventTarget;
1181
+ exports.defineEventAttribute = defineEventAttribute;
1182
+ exports.getEventAttributeValue = getEventAttributeValue;
1183
+ exports.setErrorHandler = setErrorHandler;
1184
+ exports.setEventAttributeValue = setEventAttributeValue;
1185
+ exports.setWarningHandler = setWarningHandler;
1186
+ //# sourceMappingURL=index.js.map