vendor-index.0557b03a.mjs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { c as commonjsGlobal } from './vendor-_commonjsHelpers.4da45ef5.mjs';
  2. function _mergeNamespaces(n, m) {
  3. m.forEach(function (e) {
  4. e && typeof e !== 'string' && !Array.isArray(e) && Object.keys(e).forEach(function (k) {
  5. if (k !== 'default' && !(k in n)) {
  6. var d = Object.getOwnPropertyDescriptor(e, k);
  7. Object.defineProperty(n, k, d.get ? d : {
  8. enumerable: true,
  9. get: function () { return e[k]; }
  10. });
  11. }
  12. });
  13. });
  14. return Object.freeze(n);
  15. }
  16. var eventTargetPolyfill = {};
  17. const root =
  18. (typeof globalThis !== "undefined" && globalThis) ||
  19. (typeof self !== "undefined" && self) ||
  20. (typeof commonjsGlobal !== "undefined" && commonjsGlobal);
  21. function isConstructor(fn) {
  22. try {
  23. new fn();
  24. } catch (error) {
  25. return false;
  26. }
  27. return true;
  28. }
  29. if (typeof root.Event !== "function" || !isConstructor(root.Event)) {
  30. root.Event = (function () {
  31. function Event(type, options) {
  32. this.bubbles = !!options && !!options.bubbles;
  33. this.cancelable = !!options && !!options.cancelable;
  34. this.composed = !!options && !!options.composed;
  35. this.type = type;
  36. }
  37. return Event;
  38. })();
  39. }
  40. if (typeof root.EventTarget === "undefined" || !isConstructor(root.Event)) {
  41. root.EventTarget = (function () {
  42. function EventTarget() {
  43. this.__listeners = new Map();
  44. }
  45. EventTarget.prototype = Object.create(Object.prototype);
  46. EventTarget.prototype.addEventListener = function (
  47. type,
  48. listener,
  49. options
  50. ) {
  51. if (arguments.length < 2) {
  52. throw new TypeError(
  53. `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`
  54. );
  55. }
  56. const __listeners = this.__listeners;
  57. const actualType = type.toString();
  58. if (!__listeners.has(actualType)) {
  59. __listeners.set(actualType, new Map());
  60. }
  61. const listenersForType = __listeners.get(actualType);
  62. if (!listenersForType.has(listener)) {
  63. // Any given listener is only registered once
  64. listenersForType.set(listener, options);
  65. }
  66. };
  67. EventTarget.prototype.removeEventListener = function (
  68. type,
  69. listener,
  70. _options
  71. ) {
  72. if (arguments.length < 2) {
  73. throw new TypeError(
  74. `TypeError: Failed to execute 'addEventListener' on 'EventTarget': 2 arguments required, but only ${arguments.length} present.`
  75. );
  76. }
  77. const __listeners = this.__listeners;
  78. const actualType = type.toString();
  79. if (__listeners.has(actualType)) {
  80. const listenersForType = __listeners.get(actualType);
  81. if (listenersForType.has(listener)) {
  82. listenersForType.delete(listener);
  83. }
  84. }
  85. };
  86. EventTarget.prototype.dispatchEvent = function (event) {
  87. if (!(event instanceof Event)) {
  88. throw new TypeError(
  89. `Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'.`
  90. );
  91. }
  92. const type = event.type;
  93. const __listeners = this.__listeners;
  94. const listenersForType = __listeners.get(type);
  95. if (listenersForType) {
  96. for (const [listener, options] of listenersForType.entries()) {
  97. try {
  98. if (typeof listener === "function") {
  99. // Listener functions must be executed with the EventTarget as the `this` context.
  100. listener.call(this, event);
  101. } else if (listener && typeof listener.handleEvent === "function") {
  102. // Listener objects have their handleEvent method called, if they have one
  103. listener.handleEvent(event);
  104. }
  105. } catch (err) {
  106. // We need to report the error to the global error handling event,
  107. // but we do not want to break the loop that is executing the events.
  108. // Unfortunately, this is the best we can do, which isn't great, because the
  109. // native EventTarget will actually do this synchronously before moving to the next
  110. // event in the loop.
  111. setTimeout(() => {
  112. throw err;
  113. });
  114. }
  115. if (options && options.once) {
  116. // If this was registered with { once: true }, we need
  117. // to remove it now.
  118. listenersForType.delete(listener);
  119. }
  120. }
  121. }
  122. // Since there are no cancellable events on a base EventTarget,
  123. // this should always return true.
  124. return true;
  125. };
  126. return EventTarget;
  127. })();
  128. }
  129. var index = /*#__PURE__*/_mergeNamespaces({
  130. __proto__: null,
  131. 'default': eventTargetPolyfill
  132. }, [eventTargetPolyfill]);
  133. export { index as i };