diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..c39e694 --- /dev/null +++ b/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015 Toru Nagashima + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..e21899b --- /dev/null +++ b/README.md @@ -0,0 +1,77 @@ +# event-target-shim + +[![npm version](https://img.shields.io/npm/v/event-target-shim.svg)](https://www.npmjs.com/package/event-target-shim) +[![Downloads/month](https://img.shields.io/npm/dm/event-target-shim.svg)](http://www.npmtrends.com/event-target-shim) +[![Build Status](https://github.com/mysticatea/event-target-shim/workflows/CI/badge.svg)](https://github.com/mysticatea/event-target-shim/actions) +[![Coverage Status](https://codecov.io/gh/mysticatea/event-target-shim/branch/master/graph/badge.svg)](https://codecov.io/gh/mysticatea/event-target-shim) +[![Dependency Status](https://david-dm.org/mysticatea/event-target-shim.svg)](https://david-dm.org/mysticatea/event-target-shim) + +An implementation of [WHATWG `EventTarget` interface](https://dom.spec.whatwg.org/#interface-eventtarget) and [WHATWG `Event` interface](https://dom.spec.whatwg.org/#interface-event). This implementation supports constructor, `passive`, `once`, and `signal`. + +This implementation is designed ... + +- Working fine on both browsers and Node.js. +- TypeScript friendly. + +## 💿 Installation + +Use [npm](https://www.npmjs.com/) or a compatible tool. + +``` +npm install event-target-shim +``` + +## 📖 Getting started + +```js +import { EventTarget, Event } from "event-target-shim"; + +// constructor (was added to the standard on 8 Jul 2017) +const myNode = new EventTarget(); + +// passive flag (was added to the standard on 6 Jan 2016) +myNode.addEventListener( + "hello", + (e) => { + e.preventDefault(); // ignored and print warning on console. + }, + { passive: true } +); + +// once flag (was added to the standard on 15 Apr 2016) +myNode.addEventListener("hello", listener, { once: true }); +myNode.dispatchEvent(new Event("hello")); // remove the listener after call. + +// signal (was added to the standard on 4 Dec 2020) +const ac = new AbortController(); +myNode.addEventListener("hello", listener, { signal: ac.signal }); +ac.abort(); // remove the listener. +``` + +- For browsers, use a bundler such as [Webpack](https://webpack.js.org/) to bundle. + - If you want to support IE11, use `import {} from "event-target-shim/es5"` instead. It's a transpiled code by babel. It depends on `@baebl/runtime` (`^7.12.0`) package. +- The `AbortController` class was added to the standard on 14 Jul 2017. If you want the shim of that, use [abort-controller](https://www.npmjs.com/package/abort-controller) package. + +## 📚 API Reference + +See [docs/reference.md](docs/reference.md). + +## 💥 Migrating to v6 + +See [docs/migrating-to-v6.md](docs/migrating-to-v6.md). + +## 📰 Changelog + +See [GitHub releases](https://github.com/mysticatea/event-target-shim/releases). + +## 🍻 Contributing + +Contributing is welcome ❤️ + +Please use GitHub issues/PRs. + +### Development tools + +- `npm install` installs dependencies for development. +- `npm test` runs tests and measures code coverage. +- `npm run watch:mocha` runs tests on each file change. diff --git a/es5.d.ts b/es5.d.ts new file mode 100644 index 0000000..7a5bfc7 --- /dev/null +++ b/es5.d.ts @@ -0,0 +1,411 @@ +// Generated by dts-bundle-generator v5.5.0 + +/** + * Set the error handler. + * @param value The error handler to set. + */ +export declare function setErrorHandler(value: setErrorHandler.ErrorHandler | undefined): void; +export declare namespace setErrorHandler { + /** + * The error handler. + * @param error The thrown error object. + */ + type ErrorHandler = (error: Error) => void; +} +/** + * An implementation of the `EventTarget` interface. + * @see https://dom.spec.whatwg.org/#eventtarget + */ +export declare class EventTarget = Record, TMode extends "standard" | "strict" = "standard"> { + /** + * Initialize this instance. + */ + constructor(); + /** + * Add an event listener. + * @param type The event type. + * @param callback The event listener. + * @param options Options. + */ + addEventListener(type: T, callback?: EventTarget.EventListener | null, options?: EventTarget.AddOptions): void; + /** + * Add an event listener. + * @param type The event type. + * @param callback The event listener. + * @param options Options. + */ + addEventListener(type: string, callback?: EventTarget.FallbackEventListener, options?: EventTarget.AddOptions): void; + /** + * Add an event listener. + * @param type The event type. + * @param callback The event listener. + * @param capture The capture flag. + * @deprecated Use `{capture: boolean}` object instead of a boolean value. + */ + addEventListener(type: T, callback: EventTarget.EventListener | null | undefined, capture: boolean): void; + /** + * Add an event listener. + * @param type The event type. + * @param callback The event listener. + * @param capture The capture flag. + * @deprecated Use `{capture: boolean}` object instead of a boolean value. + */ + addEventListener(type: string, callback: EventTarget.FallbackEventListener, capture: boolean): void; + /** + * Remove an added event listener. + * @param type The event type. + * @param callback The event listener. + * @param options Options. + */ + removeEventListener(type: T, callback?: EventTarget.EventListener | null, options?: EventTarget.Options): void; + /** + * Remove an added event listener. + * @param type The event type. + * @param callback The event listener. + * @param options Options. + */ + removeEventListener(type: string, callback?: EventTarget.FallbackEventListener, options?: EventTarget.Options): void; + /** + * Remove an added event listener. + * @param type The event type. + * @param callback The event listener. + * @param capture The capture flag. + * @deprecated Use `{capture: boolean}` object instead of a boolean value. + */ + removeEventListener(type: T, callback: EventTarget.EventListener | null | undefined, capture: boolean): void; + /** + * Remove an added event listener. + * @param type The event type. + * @param callback The event listener. + * @param capture The capture flag. + * @deprecated Use `{capture: boolean}` object instead of a boolean value. + */ + removeEventListener(type: string, callback: EventTarget.FallbackEventListener, capture: boolean): void; + /** + * Dispatch an event. + * @param event The `Event` object to dispatch. + */ + dispatchEvent(event: EventTarget.EventData): boolean; + /** + * Dispatch an event. + * @param event The `Event` object to dispatch. + */ + dispatchEvent(event: EventTarget.FallbackEvent): boolean; +} +export declare namespace EventTarget { + /** + * The event listener. + */ + type EventListener, TEvent extends Event> = CallbackFunction | CallbackObject; + /** + * The event listener function. + */ + interface CallbackFunction, TEvent extends Event> { + (this: TEventTarget, event: TEvent): void; + } + /** + * The event listener object. + * @see https://dom.spec.whatwg.org/#callbackdef-eventlistener + */ + interface CallbackObject { + handleEvent(event: TEvent): void; + } + /** + * The common options for both `addEventListener` and `removeEventListener` methods. + * @see https://dom.spec.whatwg.org/#dictdef-eventlisteneroptions + */ + interface Options { + capture?: boolean; + } + /** + * The options for the `addEventListener` methods. + * @see https://dom.spec.whatwg.org/#dictdef-addeventlisteneroptions + */ + interface AddOptions extends Options { + passive?: boolean; + once?: boolean; + signal?: AbortSignal | null | undefined; + } + /** + * The abort signal. + * @see https://dom.spec.whatwg.org/#abortsignal + */ + interface AbortSignal extends EventTarget<{ + abort: Event; + }> { + readonly aborted: boolean; + onabort: CallbackFunction | null; + } + /** + * The event data to dispatch in strict mode. + */ + type EventData, TMode extends "standard" | "strict", TEventType extends string> = TMode extends "strict" ? IsValidEventMap extends true ? ExplicitType & Omit & Partial> : never : never; + /** + * Define explicit `type` property if `T` is a string literal. + * Otherwise, never. + */ + type ExplicitType = string extends T ? never : { + readonly type: T; + }; + /** + * The event listener type in standard mode. + * Otherwise, never. + */ + type FallbackEventListener, TMode extends "standard" | "strict"> = TMode extends "standard" ? EventListener | null | undefined : never; + /** + * The event type in standard mode. + * Otherwise, never. + */ + type FallbackEvent = TMode extends "standard" ? Event : never; + /** + * Check if given event map is valid. + * It's valid if the keys of the event map are narrower than `string`. + */ + type IsValidEventMap = string extends keyof T ? false : true; +} +/** + * An implementation of `Event` interface, that wraps a given event object. + * `EventTarget` shim can control the internal state of this `Event` objects. + * @see https://dom.spec.whatwg.org/#event + */ +export declare class Event { + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + static get NONE(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + static get CAPTURING_PHASE(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + static get AT_TARGET(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + static get BUBBLING_PHASE(): number; + /** + * Initialize this event instance. + * @param type The type of this event. + * @param eventInitDict Options to initialize. + * @see https://dom.spec.whatwg.org/#dom-event-event + */ + constructor(type: TEventType, eventInitDict?: Event.EventInit); + /** + * The type of this event. + * @see https://dom.spec.whatwg.org/#dom-event-type + */ + get type(): TEventType; + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-target + */ + get target(): EventTarget | null; + /** + * The event target of the current dispatching. + * @deprecated Use the `target` property instead. + * @see https://dom.spec.whatwg.org/#dom-event-srcelement + */ + get srcElement(): EventTarget | null; + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-currenttarget + */ + get currentTarget(): EventTarget | null; + /** + * The event target of the current dispatching. + * This doesn't support node tree. + * @see https://dom.spec.whatwg.org/#dom-event-composedpath + */ + composedPath(): EventTarget[]; + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + get NONE(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + get CAPTURING_PHASE(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + get AT_TARGET(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + get BUBBLING_PHASE(): number; + /** + * The current event phase. + * @see https://dom.spec.whatwg.org/#dom-event-eventphase + */ + get eventPhase(): number; + /** + * Stop event bubbling. + * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value. + * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation + */ + stopPropagation(): void; + /** + * `true` if event bubbling was stopped. + * @deprecated + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + get cancelBubble(): boolean; + /** + * Stop event bubbling if `true` is set. + * @deprecated Use the `stopPropagation()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + set cancelBubble(value: boolean); + /** + * Stop event bubbling and subsequent event listener callings. + * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation + */ + stopImmediatePropagation(): void; + /** + * `true` if this event will bubble. + * @see https://dom.spec.whatwg.org/#dom-event-bubbles + */ + get bubbles(): boolean; + /** + * `true` if this event can be canceled by the `preventDefault()` method. + * @see https://dom.spec.whatwg.org/#dom-event-cancelable + */ + get cancelable(): boolean; + /** + * `true` if the default behavior will act. + * @deprecated Use the `defaultPrevented` proeprty instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + get returnValue(): boolean; + /** + * Cancel the default behavior if `false` is set. + * @deprecated Use the `preventDefault()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + set returnValue(value: boolean); + /** + * Cancel the default behavior. + * @see https://dom.spec.whatwg.org/#dom-event-preventdefault + */ + preventDefault(): void; + /** + * `true` if the default behavior was canceled. + * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented + */ + get defaultPrevented(): boolean; + /** + * @see https://dom.spec.whatwg.org/#dom-event-composed + */ + get composed(): boolean; + /** + * @see https://dom.spec.whatwg.org/#dom-event-istrusted + */ + get isTrusted(): boolean; + /** + * @see https://dom.spec.whatwg.org/#dom-event-timestamp + */ + get timeStamp(): number; + /** + * @deprecated Don't use this method. The constructor did initialization. + */ + initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void; +} +export declare namespace Event { + /** + * The options of the `Event` constructor. + * @see https://dom.spec.whatwg.org/#dictdef-eventinit + */ + interface EventInit { + bubbles?: boolean; + cancelable?: boolean; + composed?: boolean; + } +} +/** + * Get the current value of a given event attribute. + * @param target The `EventTarget` object to get. + * @param type The event type. + */ +export declare function getEventAttributeValue, TEvent extends Event>(target: TEventTarget, type: string): EventTarget.CallbackFunction | null; +/** + * Set an event listener to a given event attribute. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ +export declare function setEventAttributeValue(target: EventTarget, type: string, callback: EventTarget.CallbackFunction | null): void; +/** + * Define an `EventTarget` class that has event attibutes. + * @param types The types to define event attributes. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ +export declare function defineCustomEventTarget, TMode extends "standard" | "strict" = "standard">(...types: (string & keyof TEventMap)[]): defineCustomEventTarget.CustomEventTargetConstructor; +export declare namespace defineCustomEventTarget { + /** + * The interface of CustomEventTarget constructor. + */ + type CustomEventTargetConstructor, TMode extends "standard" | "strict"> = { + /** + * Create a new instance. + */ + new (): CustomEventTarget; + /** + * prototype object. + */ + prototype: CustomEventTarget; + }; + /** + * The interface of CustomEventTarget. + */ + type CustomEventTarget, TMode extends "standard" | "strict"> = EventTarget & defineEventAttribute.EventAttributes; +} +/** + * Define an event attribute. + * @param target The `EventTarget` object to define an event attribute. + * @param type The event type to define. + * @param _eventClass Unused, but to infer `Event` class type. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ +export declare function defineEventAttribute(target: TEventTarget, type: TEventType, _eventClass?: TEventConstrucor): asserts target is TEventTarget & defineEventAttribute.EventAttributes>>; +export declare namespace defineEventAttribute { + /** + * Definition of event attributes. + */ + type EventAttributes, TEventMap extends Record> = { + [P in string & keyof TEventMap as `on${P}`]: EventTarget.CallbackFunction | null; + }; +} +/** + * Set the warning handler. + * @param value The warning handler to set. + */ +export declare function setWarningHandler(value: setWarningHandler.WarningHandler | undefined): void; +export declare namespace setWarningHandler { + /** + * The warning information. + */ + interface Warning { + /** + * The code of this warning. + */ + code: string; + /** + * The message in English. + */ + message: string; + /** + * The arguments for replacing placeholders in the text. + */ + args: any[]; + } + /** + * The warning handler. + * @param warning The warning. + */ + type WarningHandler = (warning: Warning) => void; +} +export default EventTarget; + +export {}; diff --git a/es5.js b/es5.js new file mode 100644 index 0000000..8af71d6 --- /dev/null +++ b/es5.js @@ -0,0 +1,1634 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray'); +var _set = require('@babel/runtime/helpers/set'); +var _get = require('@babel/runtime/helpers/get'); +var _assertThisInitialized = require('@babel/runtime/helpers/assertThisInitialized'); +var _inherits = require('@babel/runtime/helpers/inherits'); +var _possibleConstructorReturn = require('@babel/runtime/helpers/possibleConstructorReturn'); +var _getPrototypeOf = require('@babel/runtime/helpers/getPrototypeOf'); +var _wrapNativeSuper = require('@babel/runtime/helpers/wrapNativeSuper'); +var _defineProperty = require('@babel/runtime/helpers/defineProperty'); +var _classCallCheck = require('@babel/runtime/helpers/classCallCheck'); +var _createClass = require('@babel/runtime/helpers/createClass'); +var _typeof = require('@babel/runtime/helpers/typeof'); + +function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } + +var _toConsumableArray__default = /*#__PURE__*/_interopDefaultLegacy(_toConsumableArray); +var _set__default = /*#__PURE__*/_interopDefaultLegacy(_set); +var _get__default = /*#__PURE__*/_interopDefaultLegacy(_get); +var _assertThisInitialized__default = /*#__PURE__*/_interopDefaultLegacy(_assertThisInitialized); +var _inherits__default = /*#__PURE__*/_interopDefaultLegacy(_inherits); +var _possibleConstructorReturn__default = /*#__PURE__*/_interopDefaultLegacy(_possibleConstructorReturn); +var _getPrototypeOf__default = /*#__PURE__*/_interopDefaultLegacy(_getPrototypeOf); +var _wrapNativeSuper__default = /*#__PURE__*/_interopDefaultLegacy(_wrapNativeSuper); +var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty); +var _classCallCheck__default = /*#__PURE__*/_interopDefaultLegacy(_classCallCheck); +var _createClass__default = /*#__PURE__*/_interopDefaultLegacy(_createClass); +var _typeof__default = /*#__PURE__*/_interopDefaultLegacy(_typeof); + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf__default['default'](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default['default'](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default['default'](this, result); }; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } + +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } + +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty__default['default'](target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } + +/** + * Assert a condition. + * @param condition The condition that it should satisfy. + * @param message The error message. + * @param args The arguments for replacing placeholders in the message. + */ +function assertType(condition, message) { + if (!condition) { + for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { + args[_key - 2] = arguments[_key]; + } + + throw new TypeError(format(message, args)); + } +} +/** + * Convert a text and arguments to one string. + * @param message The formating text + * @param args The arguments. + */ + + +function format(message, args) { + var i = 0; + return message.replace(/%[os]/g, function () { + return anyToString(args[i++]); + }); +} +/** + * Convert a value to a string representation. + * @param x The value to get the string representation. + */ + + +function anyToString(x) { + if (_typeof__default['default'](x) !== "object" || x === null) { + return String(x); + } + + return Object.prototype.toString.call(x); +} + +var currentErrorHandler; +/** + * Set the error handler. + * @param value The error handler to set. + */ + +function setErrorHandler(value) { + assertType(typeof value === "function" || value === undefined, "The error handler must be a function or undefined, but got %o.", value); + currentErrorHandler = value; +} +/** + * Print a error message. + * @param maybeError The error object. + */ + + +function reportError(maybeError) { + try { + var error = maybeError instanceof Error ? maybeError : new Error(anyToString(maybeError)); // Call the user-defined error handler if exists. + + if (currentErrorHandler) { + currentErrorHandler(error); + return; + } // Dispatch an `error` event if this is on a browser. + + + if (typeof dispatchEvent === "function" && typeof ErrorEvent === "function") { + dispatchEvent(new ErrorEvent("error", { + error: error, + message: error.message + })); + } // Emit an `uncaughtException` event if this is on Node.js. + //istanbul ignore else + else if (typeof process !== "undefined" && typeof process.emit === "function") { + process.emit("uncaughtException", error); + return; + } // Otherwise, print the error. + + + console.error(error); + } catch (_a) {// ignore. + } +} +/** + * The global object. + */ +//istanbul ignore next + + +var Global = typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : typeof globalThis !== "undefined" ? globalThis : undefined; +var currentWarnHandler; +/** + * Set the warning handler. + * @param value The warning handler to set. + */ + +function setWarningHandler(value) { + assertType(typeof value === "function" || value === undefined, "The warning handler must be a function or undefined, but got %o.", value); + currentWarnHandler = value; +} +/** + * The warning information. + */ + + +var Warning = /*#__PURE__*/function () { + function Warning(code, message) { + _classCallCheck__default['default'](this, Warning); + + this.code = code; + this.message = message; + } + /** + * Report this warning. + * @param args The arguments of the warning. + */ + + + _createClass__default['default'](Warning, [{ + key: "warn", + value: function warn() { + var _a; + + try { + var _console; + + for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + + // Call the user-defined warning handler if exists. + if (currentWarnHandler) { + currentWarnHandler(_objectSpread(_objectSpread({}, this), {}, { + args: args + })); + return; + } // Otherwise, print the warning. + + + var stack = ((_a = new Error().stack) !== null && _a !== void 0 ? _a : "").replace(/^(?:(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+?\n){2}/g, "\n"); + + (_console = console).warn.apply(_console, [this.message].concat(args, [stack])); + } catch (_b) {// Ignore. + } + } + }]); + + return Warning; +}(); + +var InitEventWasCalledWhileDispatching = new Warning("W01", "Unable to initialize event under dispatching."); +var FalsyWasAssignedToCancelBubble = new Warning("W02", "Assigning any falsy value to 'cancelBubble' property has no effect."); +var TruthyWasAssignedToReturnValue = new Warning("W03", "Assigning any truthy value to 'returnValue' property has no effect."); +var NonCancelableEventWasCanceled = new Warning("W04", "Unable to preventDefault on non-cancelable events."); +var CanceledInPassiveListener = new Warning("W05", "Unable to preventDefault inside passive event listener invocation."); +var EventListenerWasDuplicated = new Warning("W06", "An event listener wasn't added because it has been added already: %o, %o"); +var OptionWasIgnored = new Warning("W07", "The %o option value was abandoned because the event listener wasn't added as duplicated."); +var InvalidEventListener = new Warning("W08", "The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"); +var InvalidAttributeHandler = new Warning("W09", "Event attribute handler must be a function: %o"); +/*eslint-disable class-methods-use-this */ + +/** + * An implementation of `Event` interface, that wraps a given event object. + * `EventTarget` shim can control the internal state of this `Event` objects. + * @see https://dom.spec.whatwg.org/#event + */ + +var Event = /*#__PURE__*/function () { + _createClass__default['default'](Event, null, [{ + key: "NONE", + + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + get: function get() { + return NONE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + + }, { + key: "CAPTURING_PHASE", + get: function get() { + return CAPTURING_PHASE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + + }, { + key: "AT_TARGET", + get: function get() { + return AT_TARGET; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + + }, { + key: "BUBBLING_PHASE", + get: function get() { + return BUBBLING_PHASE; + } + /** + * Initialize this event instance. + * @param type The type of this event. + * @param eventInitDict Options to initialize. + * @see https://dom.spec.whatwg.org/#dom-event-event + */ + + }]); + + function Event(type, eventInitDict) { + _classCallCheck__default['default'](this, Event); + + Object.defineProperty(this, "isTrusted", { + value: false, + enumerable: true + }); + var opts = eventInitDict !== null && eventInitDict !== void 0 ? eventInitDict : {}; + internalDataMap.set(this, { + type: String(type), + bubbles: Boolean(opts.bubbles), + cancelable: Boolean(opts.cancelable), + composed: Boolean(opts.composed), + target: null, + currentTarget: null, + stopPropagationFlag: false, + stopImmediatePropagationFlag: false, + canceledFlag: false, + inPassiveListenerFlag: false, + dispatchFlag: false, + timeStamp: Date.now() + }); + } + /** + * The type of this event. + * @see https://dom.spec.whatwg.org/#dom-event-type + */ + + + _createClass__default['default'](Event, [{ + key: "composedPath", + + /** + * The event target of the current dispatching. + * This doesn't support node tree. + * @see https://dom.spec.whatwg.org/#dom-event-composedpath + */ + value: function composedPath() { + var currentTarget = $(this).currentTarget; + + if (currentTarget) { + return [currentTarget]; + } + + return []; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + + }, { + key: "stopPropagation", + + /** + * Stop event bubbling. + * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value. + * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation + */ + value: function stopPropagation() { + $(this).stopPropagationFlag = true; + } + /** + * `true` if event bubbling was stopped. + * @deprecated + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + + }, { + key: "stopImmediatePropagation", + + /** + * Stop event bubbling and subsequent event listener callings. + * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation + */ + value: function stopImmediatePropagation() { + var data = $(this); + data.stopPropagationFlag = data.stopImmediatePropagationFlag = true; + } + /** + * `true` if this event will bubble. + * @see https://dom.spec.whatwg.org/#dom-event-bubbles + */ + + }, { + key: "preventDefault", + + /** + * Cancel the default behavior. + * @see https://dom.spec.whatwg.org/#dom-event-preventdefault + */ + value: function preventDefault() { + setCancelFlag($(this)); + } + /** + * `true` if the default behavior was canceled. + * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented + */ + + }, { + key: "initEvent", + + /** + * @deprecated Don't use this method. The constructor did initialization. + */ + value: function initEvent(type) { + var bubbles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var cancelable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var data = $(this); + + if (data.dispatchFlag) { + InitEventWasCalledWhileDispatching.warn(); + return; + } + + internalDataMap.set(this, _objectSpread(_objectSpread({}, data), {}, { + type: String(type), + bubbles: Boolean(bubbles), + cancelable: Boolean(cancelable), + target: null, + currentTarget: null, + stopPropagationFlag: false, + stopImmediatePropagationFlag: false, + canceledFlag: false + })); + } + }, { + key: "type", + get: function get() { + return $(this).type; + } + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-target + */ + + }, { + key: "target", + get: function get() { + return $(this).target; + } + /** + * The event target of the current dispatching. + * @deprecated Use the `target` property instead. + * @see https://dom.spec.whatwg.org/#dom-event-srcelement + */ + + }, { + key: "srcElement", + get: function get() { + return $(this).target; + } + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-currenttarget + */ + + }, { + key: "currentTarget", + get: function get() { + return $(this).currentTarget; + } + }, { + key: "NONE", + get: function get() { + return NONE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + + }, { + key: "CAPTURING_PHASE", + get: function get() { + return CAPTURING_PHASE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + + }, { + key: "AT_TARGET", + get: function get() { + return AT_TARGET; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + + }, { + key: "BUBBLING_PHASE", + get: function get() { + return BUBBLING_PHASE; + } + /** + * The current event phase. + * @see https://dom.spec.whatwg.org/#dom-event-eventphase + */ + + }, { + key: "eventPhase", + get: function get() { + return $(this).dispatchFlag ? 2 : 0; + } + }, { + key: "cancelBubble", + get: function get() { + return $(this).stopPropagationFlag; + } + /** + * Stop event bubbling if `true` is set. + * @deprecated Use the `stopPropagation()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + , + set: function set(value) { + if (value) { + $(this).stopPropagationFlag = true; + } else { + FalsyWasAssignedToCancelBubble.warn(); + } + } + }, { + key: "bubbles", + get: function get() { + return $(this).bubbles; + } + /** + * `true` if this event can be canceled by the `preventDefault()` method. + * @see https://dom.spec.whatwg.org/#dom-event-cancelable + */ + + }, { + key: "cancelable", + get: function get() { + return $(this).cancelable; + } + /** + * `true` if the default behavior will act. + * @deprecated Use the `defaultPrevented` proeprty instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + + }, { + key: "returnValue", + get: function get() { + return !$(this).canceledFlag; + } + /** + * Cancel the default behavior if `false` is set. + * @deprecated Use the `preventDefault()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + , + set: function set(value) { + if (!value) { + setCancelFlag($(this)); + } else { + TruthyWasAssignedToReturnValue.warn(); + } + } + }, { + key: "defaultPrevented", + get: function get() { + return $(this).canceledFlag; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-composed + */ + + }, { + key: "composed", + get: function get() { + return $(this).composed; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-istrusted + */ + //istanbul ignore next + + }, { + key: "isTrusted", + get: function get() { + return false; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-timestamp + */ + + }, { + key: "timeStamp", + get: function get() { + return $(this).timeStamp; + } + }]); + + return Event; +}(); //------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + + +var NONE = 0; +var CAPTURING_PHASE = 1; +var AT_TARGET = 2; +var BUBBLING_PHASE = 3; +/** + * Private data for event wrappers. + */ + +var internalDataMap = new WeakMap(); +/** + * Get private data. + * @param event The event object to get private data. + * @param name The variable name to report. + * @returns The private data of the event. + */ + +function $(event) { + var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "this"; + var retv = internalDataMap.get(event); + assertType(retv != null, "'%s' must be an object that Event constructor created, but got another one: %o", name, event); + return retv; +} +/** + * https://dom.spec.whatwg.org/#set-the-canceled-flag + * @param data private data. + */ + + +function setCancelFlag(data) { + if (data.inPassiveListenerFlag) { + CanceledInPassiveListener.warn(); + return; + } + + if (!data.cancelable) { + NonCancelableEventWasCanceled.warn(); + return; + } + + data.canceledFlag = true; +} // Set enumerable + + +Object.defineProperty(Event, "NONE", { + enumerable: true +}); +Object.defineProperty(Event, "CAPTURING_PHASE", { + enumerable: true +}); +Object.defineProperty(Event, "AT_TARGET", { + enumerable: true +}); +Object.defineProperty(Event, "BUBBLING_PHASE", { + enumerable: true +}); +var keys = Object.getOwnPropertyNames(Event.prototype); + +for (var i = 0; i < keys.length; ++i) { + if (keys[i] === "constructor") { + continue; + } + + Object.defineProperty(Event.prototype, keys[i], { + enumerable: true + }); +} // Ensure `event instanceof window.Event` is `true`. + + +if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") { + Object.setPrototypeOf(Event.prototype, Global.Event.prototype); +} +/** + * Create a new InvalidStateError instance. + * @param message The error message. + */ + + +function createInvalidStateError(message) { + if (Global.DOMException) { + return new Global.DOMException(message, "InvalidStateError"); + } + + if (DOMException == null) { + DOMException = /*#__PURE__*/function (_Error) { + _inherits__default['default'](DOMException, _Error); + + var _super = _createSuper(DOMException); + + function DOMException(msg) { + var _this; + + _classCallCheck__default['default'](this, DOMException); + + _this = _super.call(this, msg); + + if (Error.captureStackTrace) { + Error.captureStackTrace(_assertThisInitialized__default['default'](_this), DOMException); + } + + return _this; + } // eslint-disable-next-line class-methods-use-this + + + _createClass__default['default'](DOMException, [{ + key: "code", + get: function get() { + return 11; + } // eslint-disable-next-line class-methods-use-this + + }, { + key: "name", + get: function get() { + return "InvalidStateError"; + } + }]); + + return DOMException; + }( /*#__PURE__*/_wrapNativeSuper__default['default'](Error)); + + Object.defineProperties(DOMException.prototype, { + code: { + enumerable: true + }, + name: { + enumerable: true + } + }); + defineErrorCodeProperties(DOMException); + defineErrorCodeProperties(DOMException.prototype); + } + + return new DOMException(message); +} //------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + + +var DOMException; +var ErrorCodeMap = { + INDEX_SIZE_ERR: 1, + DOMSTRING_SIZE_ERR: 2, + HIERARCHY_REQUEST_ERR: 3, + WRONG_DOCUMENT_ERR: 4, + INVALID_CHARACTER_ERR: 5, + NO_DATA_ALLOWED_ERR: 6, + NO_MODIFICATION_ALLOWED_ERR: 7, + NOT_FOUND_ERR: 8, + NOT_SUPPORTED_ERR: 9, + INUSE_ATTRIBUTE_ERR: 10, + INVALID_STATE_ERR: 11, + SYNTAX_ERR: 12, + INVALID_MODIFICATION_ERR: 13, + NAMESPACE_ERR: 14, + INVALID_ACCESS_ERR: 15, + VALIDATION_ERR: 16, + TYPE_MISMATCH_ERR: 17, + SECURITY_ERR: 18, + NETWORK_ERR: 19, + ABORT_ERR: 20, + URL_MISMATCH_ERR: 21, + QUOTA_EXCEEDED_ERR: 22, + TIMEOUT_ERR: 23, + INVALID_NODE_TYPE_ERR: 24, + DATA_CLONE_ERR: 25 +}; + +function defineErrorCodeProperties(obj) { + var keys = Object.keys(ErrorCodeMap); + + var _loop = function _loop(_i) { + var key = keys[_i]; + var value = ErrorCodeMap[key]; + Object.defineProperty(obj, key, { + get: function get() { + return value; + }, + configurable: true, + enumerable: true + }); + }; + + for (var _i = 0; _i < keys.length; ++_i) { + _loop(_i); + } +} +/** + * An implementation of `Event` interface, that wraps a given event object. + * This class controls the internal state of `Event`. + * @see https://dom.spec.whatwg.org/#interface-event + */ + + +var EventWrapper = /*#__PURE__*/function (_Event) { + _inherits__default['default'](EventWrapper, _Event); + + var _super2 = _createSuper(EventWrapper); + + _createClass__default['default'](EventWrapper, null, [{ + key: "wrap", + + /** + * Wrap a given event object to control states. + * @param event The event-like object to wrap. + */ + value: function wrap(event) { + return new (getWrapperClassOf(event))(event); + } + }]); + + function EventWrapper(event) { + var _thisSuper, _thisSuper2, _this2; + + _classCallCheck__default['default'](this, EventWrapper); + + _this2 = _super2.call(this, event.type, { + bubbles: event.bubbles, + cancelable: event.cancelable, + composed: event.composed + }); + + if (event.cancelBubble) { + _get__default['default']((_thisSuper = _assertThisInitialized__default['default'](_this2), _getPrototypeOf__default['default'](EventWrapper.prototype)), "stopPropagation", _thisSuper).call(_thisSuper); + } + + if (event.defaultPrevented) { + _get__default['default']((_thisSuper2 = _assertThisInitialized__default['default'](_this2), _getPrototypeOf__default['default'](EventWrapper.prototype)), "preventDefault", _thisSuper2).call(_thisSuper2); + } + + internalDataMap$1.set(_assertThisInitialized__default['default'](_this2), { + original: event + }); // Define accessors + + var keys = Object.keys(event); + + for (var _i2 = 0; _i2 < keys.length; ++_i2) { + var key = keys[_i2]; + + if (!(key in _assertThisInitialized__default['default'](_this2))) { + Object.defineProperty(_assertThisInitialized__default['default'](_this2), key, defineRedirectDescriptor(event, key)); + } + } + + return _this2; + } + + _createClass__default['default'](EventWrapper, [{ + key: "stopPropagation", + value: function stopPropagation() { + _get__default['default'](_getPrototypeOf__default['default'](EventWrapper.prototype), "stopPropagation", this).call(this); + + var _$$ = $$1(this), + original = _$$.original; + + if ("stopPropagation" in original) { + original.stopPropagation(); + } + } + }, { + key: "stopImmediatePropagation", + value: function stopImmediatePropagation() { + _get__default['default'](_getPrototypeOf__default['default'](EventWrapper.prototype), "stopImmediatePropagation", this).call(this); + + var _$$2 = $$1(this), + original = _$$2.original; + + if ("stopImmediatePropagation" in original) { + original.stopImmediatePropagation(); + } + } + }, { + key: "preventDefault", + value: function preventDefault() { + _get__default['default'](_getPrototypeOf__default['default'](EventWrapper.prototype), "preventDefault", this).call(this); + + var _$$3 = $$1(this), + original = _$$3.original; + + if ("preventDefault" in original) { + original.preventDefault(); + } + } + }, { + key: "cancelBubble", + get: function get() { + return _get__default['default'](_getPrototypeOf__default['default'](EventWrapper.prototype), "cancelBubble", this); + }, + set: function set(value) { + _set__default['default'](_getPrototypeOf__default['default'](EventWrapper.prototype), "cancelBubble", value, this, true); + + var _$$4 = $$1(this), + original = _$$4.original; + + if ("cancelBubble" in original) { + original.cancelBubble = value; + } + } + }, { + key: "returnValue", + get: function get() { + return _get__default['default'](_getPrototypeOf__default['default'](EventWrapper.prototype), "returnValue", this); + }, + set: function set(value) { + _set__default['default'](_getPrototypeOf__default['default'](EventWrapper.prototype), "returnValue", value, this, true); + + var _$$5 = $$1(this), + original = _$$5.original; + + if ("returnValue" in original) { + original.returnValue = value; + } + } + }, { + key: "timeStamp", + get: function get() { + var _$$6 = $$1(this), + original = _$$6.original; + + if ("timeStamp" in original) { + return original.timeStamp; + } + + return _get__default['default'](_getPrototypeOf__default['default'](EventWrapper.prototype), "timeStamp", this); + } + }]); + + return EventWrapper; +}(Event); +/** + * Private data for event wrappers. + */ + + +var internalDataMap$1 = new WeakMap(); +/** + * Get private data. + * @param event The event object to get private data. + * @returns The private data of the event. + */ + +function $$1(event) { + var retv = internalDataMap$1.get(event); + assertType(retv != null, "'this' is expected an Event object, but got", event); + return retv; +} +/** + * Cache for wrapper classes. + * @type {WeakMap} + * @private + */ + + +var wrapperClassCache = new WeakMap(); // Make association for wrappers. + +wrapperClassCache.set(Object.prototype, EventWrapper); + +if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") { + wrapperClassCache.set(Global.Event.prototype, EventWrapper); +} +/** + * Get the wrapper class of a given prototype. + * @param originalEvent The event object to wrap. + */ + + +function getWrapperClassOf(originalEvent) { + var prototype = Object.getPrototypeOf(originalEvent); + + if (prototype == null) { + return EventWrapper; + } + + var wrapper = wrapperClassCache.get(prototype); + + if (wrapper == null) { + wrapper = defineWrapper(getWrapperClassOf(prototype), prototype); + wrapperClassCache.set(prototype, wrapper); + } + + return wrapper; +} +/** + * Define new wrapper class. + * @param BaseEventWrapper The base wrapper class. + * @param originalPrototype The prototype of the original event. + */ + + +function defineWrapper(BaseEventWrapper, originalPrototype) { + var CustomEventWrapper = /*#__PURE__*/function (_BaseEventWrapper) { + _inherits__default['default'](CustomEventWrapper, _BaseEventWrapper); + + var _super3 = _createSuper(CustomEventWrapper); + + function CustomEventWrapper() { + _classCallCheck__default['default'](this, CustomEventWrapper); + + return _super3.apply(this, arguments); + } + + return CustomEventWrapper; + }(BaseEventWrapper); + + var keys = Object.keys(originalPrototype); + + for (var _i3 = 0; _i3 < keys.length; ++_i3) { + Object.defineProperty(CustomEventWrapper.prototype, keys[_i3], defineRedirectDescriptor(originalPrototype, keys[_i3])); + } + + return CustomEventWrapper; +} +/** + * Get the property descriptor to redirect a given property. + */ + + +function defineRedirectDescriptor(obj, key) { + var d = Object.getOwnPropertyDescriptor(obj, key); + return { + get: function get() { + var original = $$1(this).original; + var value = original[key]; + + if (typeof value === "function") { + return value.bind(original); + } + + return value; + }, + set: function set(value) { + var original = $$1(this).original; + original[key] = value; + }, + configurable: d.configurable, + enumerable: d.enumerable + }; +} +/** + * Create a new listener. + * @param callback The callback function. + * @param capture The capture flag. + * @param passive The passive flag. + * @param once The once flag. + * @param signal The abort signal. + * @param signalListener The abort event listener for the abort signal. + */ + + +function createListener(callback, capture, passive, once, signal, signalListener) { + return { + callback: callback, + flags: (capture ? 1 + /* Capture */ + : 0) | (passive ? 2 + /* Passive */ + : 0) | (once ? 4 + /* Once */ + : 0), + signal: signal, + signalListener: signalListener + }; +} +/** + * Set the `removed` flag to the given listener. + * @param listener The listener to check. + */ + + +function setRemoved(listener) { + listener.flags |= 8 + /* Removed */ + ; +} +/** + * Check if the given listener has the `capture` flag or not. + * @param listener The listener to check. + */ + + +function isCapture(listener) { + return (listener.flags & 1 + /* Capture */ + ) === 1 + /* Capture */ + ; +} +/** + * Check if the given listener has the `passive` flag or not. + * @param listener The listener to check. + */ + + +function isPassive(listener) { + return (listener.flags & 2 + /* Passive */ + ) === 2 + /* Passive */ + ; +} +/** + * Check if the given listener has the `once` flag or not. + * @param listener The listener to check. + */ + + +function isOnce(listener) { + return (listener.flags & 4 + /* Once */ + ) === 4 + /* Once */ + ; +} +/** + * Check if the given listener has the `removed` flag or not. + * @param listener The listener to check. + */ + + +function isRemoved(listener) { + return (listener.flags & 8 + /* Removed */ + ) === 8 + /* Removed */ + ; +} +/** + * Call an event listener. + * @param listener The listener to call. + * @param target The event target object for `thisArg`. + * @param event The event object for the first argument. + * @param attribute `true` if this callback is an event attribute handler. + */ + + +function invokeCallback(_ref, target, event) { + var callback = _ref.callback; + + try { + if (typeof callback === "function") { + callback.call(target, event); + } else if (typeof callback.handleEvent === "function") { + callback.handleEvent(event); + } + } catch (thrownError) { + reportError(thrownError); + } +} +/** + * Find the index of given listener. + * This returns `-1` if not found. + * @param list The listener list. + * @param callback The callback function to find. + * @param capture The capture flag to find. + */ + + +function findIndexOfListener(_ref2, callback, capture) { + var listeners = _ref2.listeners; + + for (var _i4 = 0; _i4 < listeners.length; ++_i4) { + if (listeners[_i4].callback === callback && isCapture(listeners[_i4]) === capture) { + return _i4; + } + } + + return -1; +} +/** + * Add the given listener. + * Does copy-on-write if needed. + * @param list The listener list. + * @param callback The callback function. + * @param capture The capture flag. + * @param passive The passive flag. + * @param once The once flag. + * @param signal The abort signal. + */ + + +function addListener(list, callback, capture, passive, once, signal) { + var signalListener; + + if (signal) { + signalListener = removeListener.bind(null, list, callback, capture); + signal.addEventListener("abort", signalListener); + } + + var listener = createListener(callback, capture, passive, once, signal, signalListener); + + if (list.cow) { + list.cow = false; + list.listeners = [].concat(_toConsumableArray__default['default'](list.listeners), [listener]); + } else { + list.listeners.push(listener); + } + + return listener; +} +/** + * Remove a listener. + * @param list The listener list. + * @param callback The callback function to find. + * @param capture The capture flag to find. + * @returns `true` if it mutated the list directly. + */ + + +function removeListener(list, callback, capture) { + var index = findIndexOfListener(list, callback, capture); + + if (index !== -1) { + return removeListenerAt(list, index); + } + + return false; +} +/** + * Remove a listener. + * @param list The listener list. + * @param index The index of the target listener. + * @param disableCow Disable copy-on-write if true. + * @returns `true` if it mutated the `listeners` array directly. + */ + + +function removeListenerAt(list, index) { + var disableCow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var listener = list.listeners[index]; // Set the removed flag. + + setRemoved(listener); // Dispose the abort signal listener if exists. + + if (listener.signal) { + listener.signal.removeEventListener("abort", listener.signalListener); + } // Remove it from the array. + + + if (list.cow && !disableCow) { + list.cow = false; + list.listeners = list.listeners.filter(function (_, i) { + return i !== index; + }); + return false; + } + + list.listeners.splice(index, 1); + return true; +} +/** + * Create a new `ListenerListMap` object. + */ + + +function createListenerListMap() { + return Object.create(null); +} +/** + * Get the listener list of the given type. + * If the listener list has not been initialized, initialize and return it. + * @param listenerMap The listener list map. + * @param type The event type to get. + */ + + +function ensureListenerList(listenerMap, type) { + var _a; + + return (_a = listenerMap[type]) !== null && _a !== void 0 ? _a : listenerMap[type] = { + attrCallback: undefined, + attrListener: undefined, + cow: false, + listeners: [] + }; +} +/** + * An implementation of the `EventTarget` interface. + * @see https://dom.spec.whatwg.org/#eventtarget + */ + + +var EventTarget = /*#__PURE__*/function () { + /** + * Initialize this instance. + */ + function EventTarget() { + _classCallCheck__default['default'](this, EventTarget); + + internalDataMap$2.set(this, createListenerListMap()); + } // Implementation + + + _createClass__default['default'](EventTarget, [{ + key: "addEventListener", + value: function addEventListener(type0, callback0, options0) { + var listenerMap = $$2(this); + + var _normalizeAddOptions = normalizeAddOptions(type0, callback0, options0), + callback = _normalizeAddOptions.callback, + capture = _normalizeAddOptions.capture, + once = _normalizeAddOptions.once, + passive = _normalizeAddOptions.passive, + signal = _normalizeAddOptions.signal, + type = _normalizeAddOptions.type; + + if (callback == null || (signal === null || signal === void 0 ? void 0 : signal.aborted)) { + return; + } + + var list = ensureListenerList(listenerMap, type); // Find existing listener. + + var i = findIndexOfListener(list, callback, capture); + + if (i !== -1) { + warnDuplicate(list.listeners[i], passive, once, signal); + return; + } // Add the new listener. + + + addListener(list, callback, capture, passive, once, signal); + } // Implementation + + }, { + key: "removeEventListener", + value: function removeEventListener(type0, callback0, options0) { + var listenerMap = $$2(this); + + var _normalizeOptions = normalizeOptions(type0, callback0, options0), + callback = _normalizeOptions.callback, + capture = _normalizeOptions.capture, + type = _normalizeOptions.type; + + var list = listenerMap[type]; + + if (callback != null && list) { + removeListener(list, callback, capture); + } + } // Implementation + + }, { + key: "dispatchEvent", + value: function dispatchEvent(e) { + var list = $$2(this)[String(e.type)]; + + if (list == null) { + return true; + } + + var event = e instanceof Event ? e : EventWrapper.wrap(e); + var eventData = $(event, "event"); + + if (eventData.dispatchFlag) { + throw createInvalidStateError("This event has been in dispatching."); + } + + eventData.dispatchFlag = true; + eventData.target = eventData.currentTarget = this; + + if (!eventData.stopPropagationFlag) { + var cow = list.cow, + listeners = list.listeners; // Set copy-on-write flag. + + list.cow = true; // Call listeners. + + for (var _i5 = 0; _i5 < listeners.length; ++_i5) { + var listener = listeners[_i5]; // Skip if removed. + + if (isRemoved(listener)) { + continue; + } // Remove this listener if has the `once` flag. + + + if (isOnce(listener) && removeListenerAt(list, _i5, !cow)) { + // Because this listener was removed, the next index is the + // same as the current value. + _i5 -= 1; + } // Call this listener with the `passive` flag. + + + eventData.inPassiveListenerFlag = isPassive(listener); + invokeCallback(listener, this, event); + eventData.inPassiveListenerFlag = false; // Stop if the `event.stopImmediatePropagation()` method was called. + + if (eventData.stopImmediatePropagationFlag) { + break; + } + } // Restore copy-on-write flag. + + + if (!cow) { + list.cow = false; + } + } + + eventData.target = null; + eventData.currentTarget = null; + eventData.stopImmediatePropagationFlag = false; + eventData.stopPropagationFlag = false; + eventData.dispatchFlag = false; + return !eventData.canceledFlag; + } + }]); + + return EventTarget; +}(); +/** + * Internal data. + */ + + +var internalDataMap$2 = new WeakMap(); +/** + * Get private data. + * @param target The event target object to get private data. + * @param name The variable name to report. + * @returns The private data of the event. + */ + +function $$2(target) { + var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "this"; + var retv = internalDataMap$2.get(target); + assertType(retv != null, "'%s' must be an object that EventTarget constructor created, but got another one: %o", name, target); + return retv; +} +/** + * Normalize options. + * @param options The options to normalize. + */ + + +function normalizeAddOptions(type, callback, options) { + var _a; + + assertCallback(callback); + + if (_typeof__default['default'](options) === "object" && options !== null) { + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options.capture), + passive: Boolean(options.passive), + once: Boolean(options.once), + signal: (_a = options.signal) !== null && _a !== void 0 ? _a : undefined + }; + } + + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options), + passive: false, + once: false, + signal: undefined + }; +} +/** + * Normalize options. + * @param options The options to normalize. + */ + + +function normalizeOptions(type, callback, options) { + assertCallback(callback); + + if (_typeof__default['default'](options) === "object" && options !== null) { + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options.capture) + }; + } + + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options) + }; +} +/** + * Assert the type of 'callback' argument. + * @param callback The callback to check. + */ + + +function assertCallback(callback) { + if (typeof callback === "function" || _typeof__default['default'](callback) === "object" && callback !== null && typeof callback.handleEvent === "function") { + return; + } + + if (callback == null || _typeof__default['default'](callback) === "object") { + InvalidEventListener.warn(callback); + return; + } + + throw new TypeError(format(InvalidEventListener.message, [callback])); +} +/** + * Print warning for duplicated. + * @param listener The current listener that is duplicated. + * @param passive The passive flag of the new duplicated listener. + * @param once The once flag of the new duplicated listener. + * @param signal The signal object of the new duplicated listener. + */ + + +function warnDuplicate(listener, passive, once, signal) { + EventListenerWasDuplicated.warn(isCapture(listener) ? "capture" : "bubble", listener.callback); + + if (isPassive(listener) !== passive) { + OptionWasIgnored.warn("passive"); + } + + if (isOnce(listener) !== once) { + OptionWasIgnored.warn("once"); + } + + if (listener.signal !== signal) { + OptionWasIgnored.warn("signal"); + } +} // Set enumerable + + +var keys$1 = Object.getOwnPropertyNames(EventTarget.prototype); + +for (var _i6 = 0; _i6 < keys$1.length; ++_i6) { + if (keys$1[_i6] === "constructor") { + continue; + } + + Object.defineProperty(EventTarget.prototype, keys$1[_i6], { + enumerable: true + }); +} // Ensure `eventTarget instanceof window.EventTarget` is `true`. + + +if (typeof Global !== "undefined" && typeof Global.EventTarget !== "undefined") { + Object.setPrototypeOf(EventTarget.prototype, Global.EventTarget.prototype); +} +/** + * Get the current value of a given event attribute. + * @param target The `EventTarget` object to get. + * @param type The event type. + */ + + +function getEventAttributeValue(target, type) { + var _a, _b; + + var listMap = $$2(target, "target"); + return (_b = (_a = listMap[type]) === null || _a === void 0 ? void 0 : _a.attrCallback) !== null && _b !== void 0 ? _b : null; +} +/** + * Set an event listener to a given event attribute. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ + + +function setEventAttributeValue(target, type, callback) { + if (callback != null && typeof callback !== "function") { + InvalidAttributeHandler.warn(callback); + } + + if (typeof callback === "function" || _typeof__default['default'](callback) === "object" && callback !== null) { + upsertEventAttributeListener(target, type, callback); + } else { + removeEventAttributeListener(target, type); + } +} //------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +/** + * Update or insert the given event attribute handler. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ + + +function upsertEventAttributeListener(target, type, callback) { + var list = ensureListenerList($$2(target, "target"), String(type)); + list.attrCallback = callback; + + if (list.attrListener == null) { + list.attrListener = addListener(list, defineEventAttributeCallback(list), false, false, false, undefined); + } +} +/** + * Remove the given event attribute handler. + * @param target The `EventTarget` object to remove. + * @param type The event type. + * @param callback The event listener. + */ + + +function removeEventAttributeListener(target, type) { + var listMap = $$2(target, "target"); + var list = listMap[String(type)]; + + if (list && list.attrListener) { + removeListener(list, list.attrListener.callback, false); + list.attrCallback = list.attrListener = undefined; + } +} +/** + * Define the callback function for the given listener list object. + * It calls `attrCallback` property if the property value is a function. + * @param list The `ListenerList` object. + */ + + +function defineEventAttributeCallback(list) { + return function (event) { + var callback = list.attrCallback; + + if (typeof callback === "function") { + callback.call(this, event); + } + }; +} +/** + * Define an `EventTarget` class that has event attibutes. + * @param types The types to define event attributes. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ + + +function defineCustomEventTarget() { + var CustomEventTarget = /*#__PURE__*/function (_EventTarget) { + _inherits__default['default'](CustomEventTarget, _EventTarget); + + var _super4 = _createSuper(CustomEventTarget); + + function CustomEventTarget() { + _classCallCheck__default['default'](this, CustomEventTarget); + + return _super4.apply(this, arguments); + } + + return CustomEventTarget; + }(EventTarget); + + for (var _i7 = 0; _i7 < arguments.length; ++_i7) { + defineEventAttribute(CustomEventTarget.prototype, _i7 < 0 || arguments.length <= _i7 ? undefined : arguments[_i7]); + } + + return CustomEventTarget; +} +/** + * Define an event attribute. + * @param target The `EventTarget` object to define an event attribute. + * @param type The event type to define. + * @param _eventClass Unused, but to infer `Event` class type. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ + + +function defineEventAttribute(target, type, _eventClass) { + Object.defineProperty(target, "on".concat(type), { + get: function get() { + return getEventAttributeValue(this, type); + }, + set: function set(value) { + setEventAttributeValue(this, type, value); + }, + configurable: true, + enumerable: true + }); +} + +exports.Event = Event; +exports.EventTarget = EventTarget; +exports.default = EventTarget; +exports.defineCustomEventTarget = defineCustomEventTarget; +exports.defineEventAttribute = defineEventAttribute; +exports.getEventAttributeValue = getEventAttributeValue; +exports.setErrorHandler = setErrorHandler; +exports.setEventAttributeValue = setEventAttributeValue; +exports.setWarningHandler = setWarningHandler; diff --git a/es5.mjs b/es5.mjs new file mode 100644 index 0000000..4fe57ed --- /dev/null +++ b/es5.mjs @@ -0,0 +1,1608 @@ +import _toConsumableArray from '@babel/runtime/helpers/esm/toConsumableArray'; +import _set from '@babel/runtime/helpers/esm/set'; +import _get from '@babel/runtime/helpers/esm/get'; +import _assertThisInitialized from '@babel/runtime/helpers/esm/assertThisInitialized'; +import _inherits from '@babel/runtime/helpers/esm/inherits'; +import _possibleConstructorReturn from '@babel/runtime/helpers/esm/possibleConstructorReturn'; +import _getPrototypeOf from '@babel/runtime/helpers/esm/getPrototypeOf'; +import _wrapNativeSuper from '@babel/runtime/helpers/esm/wrapNativeSuper'; +import _defineProperty from '@babel/runtime/helpers/esm/defineProperty'; +import _classCallCheck from '@babel/runtime/helpers/esm/classCallCheck'; +import _createClass from '@babel/runtime/helpers/esm/createClass'; +import _typeof from '@babel/runtime/helpers/esm/typeof'; + +function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } + +function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } + +function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } + +function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } + +/** + * Assert a condition. + * @param condition The condition that it should satisfy. + * @param message The error message. + * @param args The arguments for replacing placeholders in the message. + */ +function assertType(condition, message) { + if (!condition) { + for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { + args[_key - 2] = arguments[_key]; + } + + throw new TypeError(format(message, args)); + } +} +/** + * Convert a text and arguments to one string. + * @param message The formating text + * @param args The arguments. + */ + + +function format(message, args) { + var i = 0; + return message.replace(/%[os]/g, function () { + return anyToString(args[i++]); + }); +} +/** + * Convert a value to a string representation. + * @param x The value to get the string representation. + */ + + +function anyToString(x) { + if (_typeof(x) !== "object" || x === null) { + return String(x); + } + + return Object.prototype.toString.call(x); +} + +var currentErrorHandler; +/** + * Set the error handler. + * @param value The error handler to set. + */ + +function setErrorHandler(value) { + assertType(typeof value === "function" || value === undefined, "The error handler must be a function or undefined, but got %o.", value); + currentErrorHandler = value; +} +/** + * Print a error message. + * @param maybeError The error object. + */ + + +function reportError(maybeError) { + try { + var error = maybeError instanceof Error ? maybeError : new Error(anyToString(maybeError)); // Call the user-defined error handler if exists. + + if (currentErrorHandler) { + currentErrorHandler(error); + return; + } // Dispatch an `error` event if this is on a browser. + + + if (typeof dispatchEvent === "function" && typeof ErrorEvent === "function") { + dispatchEvent(new ErrorEvent("error", { + error: error, + message: error.message + })); + } // Emit an `uncaughtException` event if this is on Node.js. + //istanbul ignore else + else if (typeof process !== "undefined" && typeof process.emit === "function") { + process.emit("uncaughtException", error); + return; + } // Otherwise, print the error. + + + console.error(error); + } catch (_a) {// ignore. + } +} +/** + * The global object. + */ +//istanbul ignore next + + +var Global = typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : typeof global !== "undefined" ? global : typeof globalThis !== "undefined" ? globalThis : undefined; +var currentWarnHandler; +/** + * Set the warning handler. + * @param value The warning handler to set. + */ + +function setWarningHandler(value) { + assertType(typeof value === "function" || value === undefined, "The warning handler must be a function or undefined, but got %o.", value); + currentWarnHandler = value; +} +/** + * The warning information. + */ + + +var Warning = /*#__PURE__*/function () { + function Warning(code, message) { + _classCallCheck(this, Warning); + + this.code = code; + this.message = message; + } + /** + * Report this warning. + * @param args The arguments of the warning. + */ + + + _createClass(Warning, [{ + key: "warn", + value: function warn() { + var _a; + + try { + var _console; + + for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) { + args[_key2] = arguments[_key2]; + } + + // Call the user-defined warning handler if exists. + if (currentWarnHandler) { + currentWarnHandler(_objectSpread(_objectSpread({}, this), {}, { + args: args + })); + return; + } // Otherwise, print the warning. + + + var stack = ((_a = new Error().stack) !== null && _a !== void 0 ? _a : "").replace(/^(?:(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])+?\n){2}/g, "\n"); + + (_console = console).warn.apply(_console, [this.message].concat(args, [stack])); + } catch (_b) {// Ignore. + } + } + }]); + + return Warning; +}(); + +var InitEventWasCalledWhileDispatching = new Warning("W01", "Unable to initialize event under dispatching."); +var FalsyWasAssignedToCancelBubble = new Warning("W02", "Assigning any falsy value to 'cancelBubble' property has no effect."); +var TruthyWasAssignedToReturnValue = new Warning("W03", "Assigning any truthy value to 'returnValue' property has no effect."); +var NonCancelableEventWasCanceled = new Warning("W04", "Unable to preventDefault on non-cancelable events."); +var CanceledInPassiveListener = new Warning("W05", "Unable to preventDefault inside passive event listener invocation."); +var EventListenerWasDuplicated = new Warning("W06", "An event listener wasn't added because it has been added already: %o, %o"); +var OptionWasIgnored = new Warning("W07", "The %o option value was abandoned because the event listener wasn't added as duplicated."); +var InvalidEventListener = new Warning("W08", "The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"); +var InvalidAttributeHandler = new Warning("W09", "Event attribute handler must be a function: %o"); +/*eslint-disable class-methods-use-this */ + +/** + * An implementation of `Event` interface, that wraps a given event object. + * `EventTarget` shim can control the internal state of this `Event` objects. + * @see https://dom.spec.whatwg.org/#event + */ + +var Event = /*#__PURE__*/function () { + _createClass(Event, null, [{ + key: "NONE", + + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + get: function get() { + return NONE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + + }, { + key: "CAPTURING_PHASE", + get: function get() { + return CAPTURING_PHASE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + + }, { + key: "AT_TARGET", + get: function get() { + return AT_TARGET; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + + }, { + key: "BUBBLING_PHASE", + get: function get() { + return BUBBLING_PHASE; + } + /** + * Initialize this event instance. + * @param type The type of this event. + * @param eventInitDict Options to initialize. + * @see https://dom.spec.whatwg.org/#dom-event-event + */ + + }]); + + function Event(type, eventInitDict) { + _classCallCheck(this, Event); + + Object.defineProperty(this, "isTrusted", { + value: false, + enumerable: true + }); + var opts = eventInitDict !== null && eventInitDict !== void 0 ? eventInitDict : {}; + internalDataMap.set(this, { + type: String(type), + bubbles: Boolean(opts.bubbles), + cancelable: Boolean(opts.cancelable), + composed: Boolean(opts.composed), + target: null, + currentTarget: null, + stopPropagationFlag: false, + stopImmediatePropagationFlag: false, + canceledFlag: false, + inPassiveListenerFlag: false, + dispatchFlag: false, + timeStamp: Date.now() + }); + } + /** + * The type of this event. + * @see https://dom.spec.whatwg.org/#dom-event-type + */ + + + _createClass(Event, [{ + key: "composedPath", + + /** + * The event target of the current dispatching. + * This doesn't support node tree. + * @see https://dom.spec.whatwg.org/#dom-event-composedpath + */ + value: function composedPath() { + var currentTarget = $(this).currentTarget; + + if (currentTarget) { + return [currentTarget]; + } + + return []; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + + }, { + key: "stopPropagation", + + /** + * Stop event bubbling. + * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value. + * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation + */ + value: function stopPropagation() { + $(this).stopPropagationFlag = true; + } + /** + * `true` if event bubbling was stopped. + * @deprecated + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + + }, { + key: "stopImmediatePropagation", + + /** + * Stop event bubbling and subsequent event listener callings. + * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation + */ + value: function stopImmediatePropagation() { + var data = $(this); + data.stopPropagationFlag = data.stopImmediatePropagationFlag = true; + } + /** + * `true` if this event will bubble. + * @see https://dom.spec.whatwg.org/#dom-event-bubbles + */ + + }, { + key: "preventDefault", + + /** + * Cancel the default behavior. + * @see https://dom.spec.whatwg.org/#dom-event-preventdefault + */ + value: function preventDefault() { + setCancelFlag($(this)); + } + /** + * `true` if the default behavior was canceled. + * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented + */ + + }, { + key: "initEvent", + + /** + * @deprecated Don't use this method. The constructor did initialization. + */ + value: function initEvent(type) { + var bubbles = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; + var cancelable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var data = $(this); + + if (data.dispatchFlag) { + InitEventWasCalledWhileDispatching.warn(); + return; + } + + internalDataMap.set(this, _objectSpread(_objectSpread({}, data), {}, { + type: String(type), + bubbles: Boolean(bubbles), + cancelable: Boolean(cancelable), + target: null, + currentTarget: null, + stopPropagationFlag: false, + stopImmediatePropagationFlag: false, + canceledFlag: false + })); + } + }, { + key: "type", + get: function get() { + return $(this).type; + } + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-target + */ + + }, { + key: "target", + get: function get() { + return $(this).target; + } + /** + * The event target of the current dispatching. + * @deprecated Use the `target` property instead. + * @see https://dom.spec.whatwg.org/#dom-event-srcelement + */ + + }, { + key: "srcElement", + get: function get() { + return $(this).target; + } + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-currenttarget + */ + + }, { + key: "currentTarget", + get: function get() { + return $(this).currentTarget; + } + }, { + key: "NONE", + get: function get() { + return NONE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + + }, { + key: "CAPTURING_PHASE", + get: function get() { + return CAPTURING_PHASE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + + }, { + key: "AT_TARGET", + get: function get() { + return AT_TARGET; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + + }, { + key: "BUBBLING_PHASE", + get: function get() { + return BUBBLING_PHASE; + } + /** + * The current event phase. + * @see https://dom.spec.whatwg.org/#dom-event-eventphase + */ + + }, { + key: "eventPhase", + get: function get() { + return $(this).dispatchFlag ? 2 : 0; + } + }, { + key: "cancelBubble", + get: function get() { + return $(this).stopPropagationFlag; + } + /** + * Stop event bubbling if `true` is set. + * @deprecated Use the `stopPropagation()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + , + set: function set(value) { + if (value) { + $(this).stopPropagationFlag = true; + } else { + FalsyWasAssignedToCancelBubble.warn(); + } + } + }, { + key: "bubbles", + get: function get() { + return $(this).bubbles; + } + /** + * `true` if this event can be canceled by the `preventDefault()` method. + * @see https://dom.spec.whatwg.org/#dom-event-cancelable + */ + + }, { + key: "cancelable", + get: function get() { + return $(this).cancelable; + } + /** + * `true` if the default behavior will act. + * @deprecated Use the `defaultPrevented` proeprty instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + + }, { + key: "returnValue", + get: function get() { + return !$(this).canceledFlag; + } + /** + * Cancel the default behavior if `false` is set. + * @deprecated Use the `preventDefault()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + , + set: function set(value) { + if (!value) { + setCancelFlag($(this)); + } else { + TruthyWasAssignedToReturnValue.warn(); + } + } + }, { + key: "defaultPrevented", + get: function get() { + return $(this).canceledFlag; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-composed + */ + + }, { + key: "composed", + get: function get() { + return $(this).composed; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-istrusted + */ + //istanbul ignore next + + }, { + key: "isTrusted", + get: function get() { + return false; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-timestamp + */ + + }, { + key: "timeStamp", + get: function get() { + return $(this).timeStamp; + } + }]); + + return Event; +}(); //------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + + +var NONE = 0; +var CAPTURING_PHASE = 1; +var AT_TARGET = 2; +var BUBBLING_PHASE = 3; +/** + * Private data for event wrappers. + */ + +var internalDataMap = new WeakMap(); +/** + * Get private data. + * @param event The event object to get private data. + * @param name The variable name to report. + * @returns The private data of the event. + */ + +function $(event) { + var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "this"; + var retv = internalDataMap.get(event); + assertType(retv != null, "'%s' must be an object that Event constructor created, but got another one: %o", name, event); + return retv; +} +/** + * https://dom.spec.whatwg.org/#set-the-canceled-flag + * @param data private data. + */ + + +function setCancelFlag(data) { + if (data.inPassiveListenerFlag) { + CanceledInPassiveListener.warn(); + return; + } + + if (!data.cancelable) { + NonCancelableEventWasCanceled.warn(); + return; + } + + data.canceledFlag = true; +} // Set enumerable + + +Object.defineProperty(Event, "NONE", { + enumerable: true +}); +Object.defineProperty(Event, "CAPTURING_PHASE", { + enumerable: true +}); +Object.defineProperty(Event, "AT_TARGET", { + enumerable: true +}); +Object.defineProperty(Event, "BUBBLING_PHASE", { + enumerable: true +}); +var keys = Object.getOwnPropertyNames(Event.prototype); + +for (var i = 0; i < keys.length; ++i) { + if (keys[i] === "constructor") { + continue; + } + + Object.defineProperty(Event.prototype, keys[i], { + enumerable: true + }); +} // Ensure `event instanceof window.Event` is `true`. + + +if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") { + Object.setPrototypeOf(Event.prototype, Global.Event.prototype); +} +/** + * Create a new InvalidStateError instance. + * @param message The error message. + */ + + +function createInvalidStateError(message) { + if (Global.DOMException) { + return new Global.DOMException(message, "InvalidStateError"); + } + + if (DOMException == null) { + DOMException = /*#__PURE__*/function (_Error) { + _inherits(DOMException, _Error); + + var _super = _createSuper(DOMException); + + function DOMException(msg) { + var _this; + + _classCallCheck(this, DOMException); + + _this = _super.call(this, msg); + + if (Error.captureStackTrace) { + Error.captureStackTrace(_assertThisInitialized(_this), DOMException); + } + + return _this; + } // eslint-disable-next-line class-methods-use-this + + + _createClass(DOMException, [{ + key: "code", + get: function get() { + return 11; + } // eslint-disable-next-line class-methods-use-this + + }, { + key: "name", + get: function get() { + return "InvalidStateError"; + } + }]); + + return DOMException; + }( /*#__PURE__*/_wrapNativeSuper(Error)); + + Object.defineProperties(DOMException.prototype, { + code: { + enumerable: true + }, + name: { + enumerable: true + } + }); + defineErrorCodeProperties(DOMException); + defineErrorCodeProperties(DOMException.prototype); + } + + return new DOMException(message); +} //------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + + +var DOMException; +var ErrorCodeMap = { + INDEX_SIZE_ERR: 1, + DOMSTRING_SIZE_ERR: 2, + HIERARCHY_REQUEST_ERR: 3, + WRONG_DOCUMENT_ERR: 4, + INVALID_CHARACTER_ERR: 5, + NO_DATA_ALLOWED_ERR: 6, + NO_MODIFICATION_ALLOWED_ERR: 7, + NOT_FOUND_ERR: 8, + NOT_SUPPORTED_ERR: 9, + INUSE_ATTRIBUTE_ERR: 10, + INVALID_STATE_ERR: 11, + SYNTAX_ERR: 12, + INVALID_MODIFICATION_ERR: 13, + NAMESPACE_ERR: 14, + INVALID_ACCESS_ERR: 15, + VALIDATION_ERR: 16, + TYPE_MISMATCH_ERR: 17, + SECURITY_ERR: 18, + NETWORK_ERR: 19, + ABORT_ERR: 20, + URL_MISMATCH_ERR: 21, + QUOTA_EXCEEDED_ERR: 22, + TIMEOUT_ERR: 23, + INVALID_NODE_TYPE_ERR: 24, + DATA_CLONE_ERR: 25 +}; + +function defineErrorCodeProperties(obj) { + var keys = Object.keys(ErrorCodeMap); + + var _loop = function _loop(_i) { + var key = keys[_i]; + var value = ErrorCodeMap[key]; + Object.defineProperty(obj, key, { + get: function get() { + return value; + }, + configurable: true, + enumerable: true + }); + }; + + for (var _i = 0; _i < keys.length; ++_i) { + _loop(_i); + } +} +/** + * An implementation of `Event` interface, that wraps a given event object. + * This class controls the internal state of `Event`. + * @see https://dom.spec.whatwg.org/#interface-event + */ + + +var EventWrapper = /*#__PURE__*/function (_Event) { + _inherits(EventWrapper, _Event); + + var _super2 = _createSuper(EventWrapper); + + _createClass(EventWrapper, null, [{ + key: "wrap", + + /** + * Wrap a given event object to control states. + * @param event The event-like object to wrap. + */ + value: function wrap(event) { + return new (getWrapperClassOf(event))(event); + } + }]); + + function EventWrapper(event) { + var _thisSuper, _thisSuper2, _this2; + + _classCallCheck(this, EventWrapper); + + _this2 = _super2.call(this, event.type, { + bubbles: event.bubbles, + cancelable: event.cancelable, + composed: event.composed + }); + + if (event.cancelBubble) { + _get((_thisSuper = _assertThisInitialized(_this2), _getPrototypeOf(EventWrapper.prototype)), "stopPropagation", _thisSuper).call(_thisSuper); + } + + if (event.defaultPrevented) { + _get((_thisSuper2 = _assertThisInitialized(_this2), _getPrototypeOf(EventWrapper.prototype)), "preventDefault", _thisSuper2).call(_thisSuper2); + } + + internalDataMap$1.set(_assertThisInitialized(_this2), { + original: event + }); // Define accessors + + var keys = Object.keys(event); + + for (var _i2 = 0; _i2 < keys.length; ++_i2) { + var key = keys[_i2]; + + if (!(key in _assertThisInitialized(_this2))) { + Object.defineProperty(_assertThisInitialized(_this2), key, defineRedirectDescriptor(event, key)); + } + } + + return _this2; + } + + _createClass(EventWrapper, [{ + key: "stopPropagation", + value: function stopPropagation() { + _get(_getPrototypeOf(EventWrapper.prototype), "stopPropagation", this).call(this); + + var _$$ = $$1(this), + original = _$$.original; + + if ("stopPropagation" in original) { + original.stopPropagation(); + } + } + }, { + key: "stopImmediatePropagation", + value: function stopImmediatePropagation() { + _get(_getPrototypeOf(EventWrapper.prototype), "stopImmediatePropagation", this).call(this); + + var _$$2 = $$1(this), + original = _$$2.original; + + if ("stopImmediatePropagation" in original) { + original.stopImmediatePropagation(); + } + } + }, { + key: "preventDefault", + value: function preventDefault() { + _get(_getPrototypeOf(EventWrapper.prototype), "preventDefault", this).call(this); + + var _$$3 = $$1(this), + original = _$$3.original; + + if ("preventDefault" in original) { + original.preventDefault(); + } + } + }, { + key: "cancelBubble", + get: function get() { + return _get(_getPrototypeOf(EventWrapper.prototype), "cancelBubble", this); + }, + set: function set(value) { + _set(_getPrototypeOf(EventWrapper.prototype), "cancelBubble", value, this, true); + + var _$$4 = $$1(this), + original = _$$4.original; + + if ("cancelBubble" in original) { + original.cancelBubble = value; + } + } + }, { + key: "returnValue", + get: function get() { + return _get(_getPrototypeOf(EventWrapper.prototype), "returnValue", this); + }, + set: function set(value) { + _set(_getPrototypeOf(EventWrapper.prototype), "returnValue", value, this, true); + + var _$$5 = $$1(this), + original = _$$5.original; + + if ("returnValue" in original) { + original.returnValue = value; + } + } + }, { + key: "timeStamp", + get: function get() { + var _$$6 = $$1(this), + original = _$$6.original; + + if ("timeStamp" in original) { + return original.timeStamp; + } + + return _get(_getPrototypeOf(EventWrapper.prototype), "timeStamp", this); + } + }]); + + return EventWrapper; +}(Event); +/** + * Private data for event wrappers. + */ + + +var internalDataMap$1 = new WeakMap(); +/** + * Get private data. + * @param event The event object to get private data. + * @returns The private data of the event. + */ + +function $$1(event) { + var retv = internalDataMap$1.get(event); + assertType(retv != null, "'this' is expected an Event object, but got", event); + return retv; +} +/** + * Cache for wrapper classes. + * @type {WeakMap} + * @private + */ + + +var wrapperClassCache = new WeakMap(); // Make association for wrappers. + +wrapperClassCache.set(Object.prototype, EventWrapper); + +if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") { + wrapperClassCache.set(Global.Event.prototype, EventWrapper); +} +/** + * Get the wrapper class of a given prototype. + * @param originalEvent The event object to wrap. + */ + + +function getWrapperClassOf(originalEvent) { + var prototype = Object.getPrototypeOf(originalEvent); + + if (prototype == null) { + return EventWrapper; + } + + var wrapper = wrapperClassCache.get(prototype); + + if (wrapper == null) { + wrapper = defineWrapper(getWrapperClassOf(prototype), prototype); + wrapperClassCache.set(prototype, wrapper); + } + + return wrapper; +} +/** + * Define new wrapper class. + * @param BaseEventWrapper The base wrapper class. + * @param originalPrototype The prototype of the original event. + */ + + +function defineWrapper(BaseEventWrapper, originalPrototype) { + var CustomEventWrapper = /*#__PURE__*/function (_BaseEventWrapper) { + _inherits(CustomEventWrapper, _BaseEventWrapper); + + var _super3 = _createSuper(CustomEventWrapper); + + function CustomEventWrapper() { + _classCallCheck(this, CustomEventWrapper); + + return _super3.apply(this, arguments); + } + + return CustomEventWrapper; + }(BaseEventWrapper); + + var keys = Object.keys(originalPrototype); + + for (var _i3 = 0; _i3 < keys.length; ++_i3) { + Object.defineProperty(CustomEventWrapper.prototype, keys[_i3], defineRedirectDescriptor(originalPrototype, keys[_i3])); + } + + return CustomEventWrapper; +} +/** + * Get the property descriptor to redirect a given property. + */ + + +function defineRedirectDescriptor(obj, key) { + var d = Object.getOwnPropertyDescriptor(obj, key); + return { + get: function get() { + var original = $$1(this).original; + var value = original[key]; + + if (typeof value === "function") { + return value.bind(original); + } + + return value; + }, + set: function set(value) { + var original = $$1(this).original; + original[key] = value; + }, + configurable: d.configurable, + enumerable: d.enumerable + }; +} +/** + * Create a new listener. + * @param callback The callback function. + * @param capture The capture flag. + * @param passive The passive flag. + * @param once The once flag. + * @param signal The abort signal. + * @param signalListener The abort event listener for the abort signal. + */ + + +function createListener(callback, capture, passive, once, signal, signalListener) { + return { + callback: callback, + flags: (capture ? 1 + /* Capture */ + : 0) | (passive ? 2 + /* Passive */ + : 0) | (once ? 4 + /* Once */ + : 0), + signal: signal, + signalListener: signalListener + }; +} +/** + * Set the `removed` flag to the given listener. + * @param listener The listener to check. + */ + + +function setRemoved(listener) { + listener.flags |= 8 + /* Removed */ + ; +} +/** + * Check if the given listener has the `capture` flag or not. + * @param listener The listener to check. + */ + + +function isCapture(listener) { + return (listener.flags & 1 + /* Capture */ + ) === 1 + /* Capture */ + ; +} +/** + * Check if the given listener has the `passive` flag or not. + * @param listener The listener to check. + */ + + +function isPassive(listener) { + return (listener.flags & 2 + /* Passive */ + ) === 2 + /* Passive */ + ; +} +/** + * Check if the given listener has the `once` flag or not. + * @param listener The listener to check. + */ + + +function isOnce(listener) { + return (listener.flags & 4 + /* Once */ + ) === 4 + /* Once */ + ; +} +/** + * Check if the given listener has the `removed` flag or not. + * @param listener The listener to check. + */ + + +function isRemoved(listener) { + return (listener.flags & 8 + /* Removed */ + ) === 8 + /* Removed */ + ; +} +/** + * Call an event listener. + * @param listener The listener to call. + * @param target The event target object for `thisArg`. + * @param event The event object for the first argument. + * @param attribute `true` if this callback is an event attribute handler. + */ + + +function invokeCallback(_ref, target, event) { + var callback = _ref.callback; + + try { + if (typeof callback === "function") { + callback.call(target, event); + } else if (typeof callback.handleEvent === "function") { + callback.handleEvent(event); + } + } catch (thrownError) { + reportError(thrownError); + } +} +/** + * Find the index of given listener. + * This returns `-1` if not found. + * @param list The listener list. + * @param callback The callback function to find. + * @param capture The capture flag to find. + */ + + +function findIndexOfListener(_ref2, callback, capture) { + var listeners = _ref2.listeners; + + for (var _i4 = 0; _i4 < listeners.length; ++_i4) { + if (listeners[_i4].callback === callback && isCapture(listeners[_i4]) === capture) { + return _i4; + } + } + + return -1; +} +/** + * Add the given listener. + * Does copy-on-write if needed. + * @param list The listener list. + * @param callback The callback function. + * @param capture The capture flag. + * @param passive The passive flag. + * @param once The once flag. + * @param signal The abort signal. + */ + + +function addListener(list, callback, capture, passive, once, signal) { + var signalListener; + + if (signal) { + signalListener = removeListener.bind(null, list, callback, capture); + signal.addEventListener("abort", signalListener); + } + + var listener = createListener(callback, capture, passive, once, signal, signalListener); + + if (list.cow) { + list.cow = false; + list.listeners = [].concat(_toConsumableArray(list.listeners), [listener]); + } else { + list.listeners.push(listener); + } + + return listener; +} +/** + * Remove a listener. + * @param list The listener list. + * @param callback The callback function to find. + * @param capture The capture flag to find. + * @returns `true` if it mutated the list directly. + */ + + +function removeListener(list, callback, capture) { + var index = findIndexOfListener(list, callback, capture); + + if (index !== -1) { + return removeListenerAt(list, index); + } + + return false; +} +/** + * Remove a listener. + * @param list The listener list. + * @param index The index of the target listener. + * @param disableCow Disable copy-on-write if true. + * @returns `true` if it mutated the `listeners` array directly. + */ + + +function removeListenerAt(list, index) { + var disableCow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; + var listener = list.listeners[index]; // Set the removed flag. + + setRemoved(listener); // Dispose the abort signal listener if exists. + + if (listener.signal) { + listener.signal.removeEventListener("abort", listener.signalListener); + } // Remove it from the array. + + + if (list.cow && !disableCow) { + list.cow = false; + list.listeners = list.listeners.filter(function (_, i) { + return i !== index; + }); + return false; + } + + list.listeners.splice(index, 1); + return true; +} +/** + * Create a new `ListenerListMap` object. + */ + + +function createListenerListMap() { + return Object.create(null); +} +/** + * Get the listener list of the given type. + * If the listener list has not been initialized, initialize and return it. + * @param listenerMap The listener list map. + * @param type The event type to get. + */ + + +function ensureListenerList(listenerMap, type) { + var _a; + + return (_a = listenerMap[type]) !== null && _a !== void 0 ? _a : listenerMap[type] = { + attrCallback: undefined, + attrListener: undefined, + cow: false, + listeners: [] + }; +} +/** + * An implementation of the `EventTarget` interface. + * @see https://dom.spec.whatwg.org/#eventtarget + */ + + +var EventTarget = /*#__PURE__*/function () { + /** + * Initialize this instance. + */ + function EventTarget() { + _classCallCheck(this, EventTarget); + + internalDataMap$2.set(this, createListenerListMap()); + } // Implementation + + + _createClass(EventTarget, [{ + key: "addEventListener", + value: function addEventListener(type0, callback0, options0) { + var listenerMap = $$2(this); + + var _normalizeAddOptions = normalizeAddOptions(type0, callback0, options0), + callback = _normalizeAddOptions.callback, + capture = _normalizeAddOptions.capture, + once = _normalizeAddOptions.once, + passive = _normalizeAddOptions.passive, + signal = _normalizeAddOptions.signal, + type = _normalizeAddOptions.type; + + if (callback == null || (signal === null || signal === void 0 ? void 0 : signal.aborted)) { + return; + } + + var list = ensureListenerList(listenerMap, type); // Find existing listener. + + var i = findIndexOfListener(list, callback, capture); + + if (i !== -1) { + warnDuplicate(list.listeners[i], passive, once, signal); + return; + } // Add the new listener. + + + addListener(list, callback, capture, passive, once, signal); + } // Implementation + + }, { + key: "removeEventListener", + value: function removeEventListener(type0, callback0, options0) { + var listenerMap = $$2(this); + + var _normalizeOptions = normalizeOptions(type0, callback0, options0), + callback = _normalizeOptions.callback, + capture = _normalizeOptions.capture, + type = _normalizeOptions.type; + + var list = listenerMap[type]; + + if (callback != null && list) { + removeListener(list, callback, capture); + } + } // Implementation + + }, { + key: "dispatchEvent", + value: function dispatchEvent(e) { + var list = $$2(this)[String(e.type)]; + + if (list == null) { + return true; + } + + var event = e instanceof Event ? e : EventWrapper.wrap(e); + var eventData = $(event, "event"); + + if (eventData.dispatchFlag) { + throw createInvalidStateError("This event has been in dispatching."); + } + + eventData.dispatchFlag = true; + eventData.target = eventData.currentTarget = this; + + if (!eventData.stopPropagationFlag) { + var cow = list.cow, + listeners = list.listeners; // Set copy-on-write flag. + + list.cow = true; // Call listeners. + + for (var _i5 = 0; _i5 < listeners.length; ++_i5) { + var listener = listeners[_i5]; // Skip if removed. + + if (isRemoved(listener)) { + continue; + } // Remove this listener if has the `once` flag. + + + if (isOnce(listener) && removeListenerAt(list, _i5, !cow)) { + // Because this listener was removed, the next index is the + // same as the current value. + _i5 -= 1; + } // Call this listener with the `passive` flag. + + + eventData.inPassiveListenerFlag = isPassive(listener); + invokeCallback(listener, this, event); + eventData.inPassiveListenerFlag = false; // Stop if the `event.stopImmediatePropagation()` method was called. + + if (eventData.stopImmediatePropagationFlag) { + break; + } + } // Restore copy-on-write flag. + + + if (!cow) { + list.cow = false; + } + } + + eventData.target = null; + eventData.currentTarget = null; + eventData.stopImmediatePropagationFlag = false; + eventData.stopPropagationFlag = false; + eventData.dispatchFlag = false; + return !eventData.canceledFlag; + } + }]); + + return EventTarget; +}(); +/** + * Internal data. + */ + + +var internalDataMap$2 = new WeakMap(); +/** + * Get private data. + * @param target The event target object to get private data. + * @param name The variable name to report. + * @returns The private data of the event. + */ + +function $$2(target) { + var name = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "this"; + var retv = internalDataMap$2.get(target); + assertType(retv != null, "'%s' must be an object that EventTarget constructor created, but got another one: %o", name, target); + return retv; +} +/** + * Normalize options. + * @param options The options to normalize. + */ + + +function normalizeAddOptions(type, callback, options) { + var _a; + + assertCallback(callback); + + if (_typeof(options) === "object" && options !== null) { + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options.capture), + passive: Boolean(options.passive), + once: Boolean(options.once), + signal: (_a = options.signal) !== null && _a !== void 0 ? _a : undefined + }; + } + + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options), + passive: false, + once: false, + signal: undefined + }; +} +/** + * Normalize options. + * @param options The options to normalize. + */ + + +function normalizeOptions(type, callback, options) { + assertCallback(callback); + + if (_typeof(options) === "object" && options !== null) { + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options.capture) + }; + } + + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options) + }; +} +/** + * Assert the type of 'callback' argument. + * @param callback The callback to check. + */ + + +function assertCallback(callback) { + if (typeof callback === "function" || _typeof(callback) === "object" && callback !== null && typeof callback.handleEvent === "function") { + return; + } + + if (callback == null || _typeof(callback) === "object") { + InvalidEventListener.warn(callback); + return; + } + + throw new TypeError(format(InvalidEventListener.message, [callback])); +} +/** + * Print warning for duplicated. + * @param listener The current listener that is duplicated. + * @param passive The passive flag of the new duplicated listener. + * @param once The once flag of the new duplicated listener. + * @param signal The signal object of the new duplicated listener. + */ + + +function warnDuplicate(listener, passive, once, signal) { + EventListenerWasDuplicated.warn(isCapture(listener) ? "capture" : "bubble", listener.callback); + + if (isPassive(listener) !== passive) { + OptionWasIgnored.warn("passive"); + } + + if (isOnce(listener) !== once) { + OptionWasIgnored.warn("once"); + } + + if (listener.signal !== signal) { + OptionWasIgnored.warn("signal"); + } +} // Set enumerable + + +var keys$1 = Object.getOwnPropertyNames(EventTarget.prototype); + +for (var _i6 = 0; _i6 < keys$1.length; ++_i6) { + if (keys$1[_i6] === "constructor") { + continue; + } + + Object.defineProperty(EventTarget.prototype, keys$1[_i6], { + enumerable: true + }); +} // Ensure `eventTarget instanceof window.EventTarget` is `true`. + + +if (typeof Global !== "undefined" && typeof Global.EventTarget !== "undefined") { + Object.setPrototypeOf(EventTarget.prototype, Global.EventTarget.prototype); +} +/** + * Get the current value of a given event attribute. + * @param target The `EventTarget` object to get. + * @param type The event type. + */ + + +function getEventAttributeValue(target, type) { + var _a, _b; + + var listMap = $$2(target, "target"); + return (_b = (_a = listMap[type]) === null || _a === void 0 ? void 0 : _a.attrCallback) !== null && _b !== void 0 ? _b : null; +} +/** + * Set an event listener to a given event attribute. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ + + +function setEventAttributeValue(target, type, callback) { + if (callback != null && typeof callback !== "function") { + InvalidAttributeHandler.warn(callback); + } + + if (typeof callback === "function" || _typeof(callback) === "object" && callback !== null) { + upsertEventAttributeListener(target, type, callback); + } else { + removeEventAttributeListener(target, type); + } +} //------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ + +/** + * Update or insert the given event attribute handler. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ + + +function upsertEventAttributeListener(target, type, callback) { + var list = ensureListenerList($$2(target, "target"), String(type)); + list.attrCallback = callback; + + if (list.attrListener == null) { + list.attrListener = addListener(list, defineEventAttributeCallback(list), false, false, false, undefined); + } +} +/** + * Remove the given event attribute handler. + * @param target The `EventTarget` object to remove. + * @param type The event type. + * @param callback The event listener. + */ + + +function removeEventAttributeListener(target, type) { + var listMap = $$2(target, "target"); + var list = listMap[String(type)]; + + if (list && list.attrListener) { + removeListener(list, list.attrListener.callback, false); + list.attrCallback = list.attrListener = undefined; + } +} +/** + * Define the callback function for the given listener list object. + * It calls `attrCallback` property if the property value is a function. + * @param list The `ListenerList` object. + */ + + +function defineEventAttributeCallback(list) { + return function (event) { + var callback = list.attrCallback; + + if (typeof callback === "function") { + callback.call(this, event); + } + }; +} +/** + * Define an `EventTarget` class that has event attibutes. + * @param types The types to define event attributes. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ + + +function defineCustomEventTarget() { + var CustomEventTarget = /*#__PURE__*/function (_EventTarget) { + _inherits(CustomEventTarget, _EventTarget); + + var _super4 = _createSuper(CustomEventTarget); + + function CustomEventTarget() { + _classCallCheck(this, CustomEventTarget); + + return _super4.apply(this, arguments); + } + + return CustomEventTarget; + }(EventTarget); + + for (var _i7 = 0; _i7 < arguments.length; ++_i7) { + defineEventAttribute(CustomEventTarget.prototype, _i7 < 0 || arguments.length <= _i7 ? undefined : arguments[_i7]); + } + + return CustomEventTarget; +} +/** + * Define an event attribute. + * @param target The `EventTarget` object to define an event attribute. + * @param type The event type to define. + * @param _eventClass Unused, but to infer `Event` class type. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ + + +function defineEventAttribute(target, type, _eventClass) { + Object.defineProperty(target, "on".concat(type), { + get: function get() { + return getEventAttributeValue(this, type); + }, + set: function set(value) { + setEventAttributeValue(this, type, value); + }, + configurable: true, + enumerable: true + }); +} + +export default EventTarget; +export { Event, EventTarget, defineCustomEventTarget, defineEventAttribute, getEventAttributeValue, setErrorHandler, setEventAttributeValue, setWarningHandler }; diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..7a5bfc7 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,411 @@ +// Generated by dts-bundle-generator v5.5.0 + +/** + * Set the error handler. + * @param value The error handler to set. + */ +export declare function setErrorHandler(value: setErrorHandler.ErrorHandler | undefined): void; +export declare namespace setErrorHandler { + /** + * The error handler. + * @param error The thrown error object. + */ + type ErrorHandler = (error: Error) => void; +} +/** + * An implementation of the `EventTarget` interface. + * @see https://dom.spec.whatwg.org/#eventtarget + */ +export declare class EventTarget = Record, TMode extends "standard" | "strict" = "standard"> { + /** + * Initialize this instance. + */ + constructor(); + /** + * Add an event listener. + * @param type The event type. + * @param callback The event listener. + * @param options Options. + */ + addEventListener(type: T, callback?: EventTarget.EventListener | null, options?: EventTarget.AddOptions): void; + /** + * Add an event listener. + * @param type The event type. + * @param callback The event listener. + * @param options Options. + */ + addEventListener(type: string, callback?: EventTarget.FallbackEventListener, options?: EventTarget.AddOptions): void; + /** + * Add an event listener. + * @param type The event type. + * @param callback The event listener. + * @param capture The capture flag. + * @deprecated Use `{capture: boolean}` object instead of a boolean value. + */ + addEventListener(type: T, callback: EventTarget.EventListener | null | undefined, capture: boolean): void; + /** + * Add an event listener. + * @param type The event type. + * @param callback The event listener. + * @param capture The capture flag. + * @deprecated Use `{capture: boolean}` object instead of a boolean value. + */ + addEventListener(type: string, callback: EventTarget.FallbackEventListener, capture: boolean): void; + /** + * Remove an added event listener. + * @param type The event type. + * @param callback The event listener. + * @param options Options. + */ + removeEventListener(type: T, callback?: EventTarget.EventListener | null, options?: EventTarget.Options): void; + /** + * Remove an added event listener. + * @param type The event type. + * @param callback The event listener. + * @param options Options. + */ + removeEventListener(type: string, callback?: EventTarget.FallbackEventListener, options?: EventTarget.Options): void; + /** + * Remove an added event listener. + * @param type The event type. + * @param callback The event listener. + * @param capture The capture flag. + * @deprecated Use `{capture: boolean}` object instead of a boolean value. + */ + removeEventListener(type: T, callback: EventTarget.EventListener | null | undefined, capture: boolean): void; + /** + * Remove an added event listener. + * @param type The event type. + * @param callback The event listener. + * @param capture The capture flag. + * @deprecated Use `{capture: boolean}` object instead of a boolean value. + */ + removeEventListener(type: string, callback: EventTarget.FallbackEventListener, capture: boolean): void; + /** + * Dispatch an event. + * @param event The `Event` object to dispatch. + */ + dispatchEvent(event: EventTarget.EventData): boolean; + /** + * Dispatch an event. + * @param event The `Event` object to dispatch. + */ + dispatchEvent(event: EventTarget.FallbackEvent): boolean; +} +export declare namespace EventTarget { + /** + * The event listener. + */ + type EventListener, TEvent extends Event> = CallbackFunction | CallbackObject; + /** + * The event listener function. + */ + interface CallbackFunction, TEvent extends Event> { + (this: TEventTarget, event: TEvent): void; + } + /** + * The event listener object. + * @see https://dom.spec.whatwg.org/#callbackdef-eventlistener + */ + interface CallbackObject { + handleEvent(event: TEvent): void; + } + /** + * The common options for both `addEventListener` and `removeEventListener` methods. + * @see https://dom.spec.whatwg.org/#dictdef-eventlisteneroptions + */ + interface Options { + capture?: boolean; + } + /** + * The options for the `addEventListener` methods. + * @see https://dom.spec.whatwg.org/#dictdef-addeventlisteneroptions + */ + interface AddOptions extends Options { + passive?: boolean; + once?: boolean; + signal?: AbortSignal | null | undefined; + } + /** + * The abort signal. + * @see https://dom.spec.whatwg.org/#abortsignal + */ + interface AbortSignal extends EventTarget<{ + abort: Event; + }> { + readonly aborted: boolean; + onabort: CallbackFunction | null; + } + /** + * The event data to dispatch in strict mode. + */ + type EventData, TMode extends "standard" | "strict", TEventType extends string> = TMode extends "strict" ? IsValidEventMap extends true ? ExplicitType & Omit & Partial> : never : never; + /** + * Define explicit `type` property if `T` is a string literal. + * Otherwise, never. + */ + type ExplicitType = string extends T ? never : { + readonly type: T; + }; + /** + * The event listener type in standard mode. + * Otherwise, never. + */ + type FallbackEventListener, TMode extends "standard" | "strict"> = TMode extends "standard" ? EventListener | null | undefined : never; + /** + * The event type in standard mode. + * Otherwise, never. + */ + type FallbackEvent = TMode extends "standard" ? Event : never; + /** + * Check if given event map is valid. + * It's valid if the keys of the event map are narrower than `string`. + */ + type IsValidEventMap = string extends keyof T ? false : true; +} +/** + * An implementation of `Event` interface, that wraps a given event object. + * `EventTarget` shim can control the internal state of this `Event` objects. + * @see https://dom.spec.whatwg.org/#event + */ +export declare class Event { + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + static get NONE(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + static get CAPTURING_PHASE(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + static get AT_TARGET(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + static get BUBBLING_PHASE(): number; + /** + * Initialize this event instance. + * @param type The type of this event. + * @param eventInitDict Options to initialize. + * @see https://dom.spec.whatwg.org/#dom-event-event + */ + constructor(type: TEventType, eventInitDict?: Event.EventInit); + /** + * The type of this event. + * @see https://dom.spec.whatwg.org/#dom-event-type + */ + get type(): TEventType; + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-target + */ + get target(): EventTarget | null; + /** + * The event target of the current dispatching. + * @deprecated Use the `target` property instead. + * @see https://dom.spec.whatwg.org/#dom-event-srcelement + */ + get srcElement(): EventTarget | null; + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-currenttarget + */ + get currentTarget(): EventTarget | null; + /** + * The event target of the current dispatching. + * This doesn't support node tree. + * @see https://dom.spec.whatwg.org/#dom-event-composedpath + */ + composedPath(): EventTarget[]; + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + get NONE(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + get CAPTURING_PHASE(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + get AT_TARGET(): number; + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + get BUBBLING_PHASE(): number; + /** + * The current event phase. + * @see https://dom.spec.whatwg.org/#dom-event-eventphase + */ + get eventPhase(): number; + /** + * Stop event bubbling. + * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value. + * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation + */ + stopPropagation(): void; + /** + * `true` if event bubbling was stopped. + * @deprecated + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + get cancelBubble(): boolean; + /** + * Stop event bubbling if `true` is set. + * @deprecated Use the `stopPropagation()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + set cancelBubble(value: boolean); + /** + * Stop event bubbling and subsequent event listener callings. + * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation + */ + stopImmediatePropagation(): void; + /** + * `true` if this event will bubble. + * @see https://dom.spec.whatwg.org/#dom-event-bubbles + */ + get bubbles(): boolean; + /** + * `true` if this event can be canceled by the `preventDefault()` method. + * @see https://dom.spec.whatwg.org/#dom-event-cancelable + */ + get cancelable(): boolean; + /** + * `true` if the default behavior will act. + * @deprecated Use the `defaultPrevented` proeprty instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + get returnValue(): boolean; + /** + * Cancel the default behavior if `false` is set. + * @deprecated Use the `preventDefault()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + set returnValue(value: boolean); + /** + * Cancel the default behavior. + * @see https://dom.spec.whatwg.org/#dom-event-preventdefault + */ + preventDefault(): void; + /** + * `true` if the default behavior was canceled. + * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented + */ + get defaultPrevented(): boolean; + /** + * @see https://dom.spec.whatwg.org/#dom-event-composed + */ + get composed(): boolean; + /** + * @see https://dom.spec.whatwg.org/#dom-event-istrusted + */ + get isTrusted(): boolean; + /** + * @see https://dom.spec.whatwg.org/#dom-event-timestamp + */ + get timeStamp(): number; + /** + * @deprecated Don't use this method. The constructor did initialization. + */ + initEvent(type: string, bubbles?: boolean, cancelable?: boolean): void; +} +export declare namespace Event { + /** + * The options of the `Event` constructor. + * @see https://dom.spec.whatwg.org/#dictdef-eventinit + */ + interface EventInit { + bubbles?: boolean; + cancelable?: boolean; + composed?: boolean; + } +} +/** + * Get the current value of a given event attribute. + * @param target The `EventTarget` object to get. + * @param type The event type. + */ +export declare function getEventAttributeValue, TEvent extends Event>(target: TEventTarget, type: string): EventTarget.CallbackFunction | null; +/** + * Set an event listener to a given event attribute. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ +export declare function setEventAttributeValue(target: EventTarget, type: string, callback: EventTarget.CallbackFunction | null): void; +/** + * Define an `EventTarget` class that has event attibutes. + * @param types The types to define event attributes. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ +export declare function defineCustomEventTarget, TMode extends "standard" | "strict" = "standard">(...types: (string & keyof TEventMap)[]): defineCustomEventTarget.CustomEventTargetConstructor; +export declare namespace defineCustomEventTarget { + /** + * The interface of CustomEventTarget constructor. + */ + type CustomEventTargetConstructor, TMode extends "standard" | "strict"> = { + /** + * Create a new instance. + */ + new (): CustomEventTarget; + /** + * prototype object. + */ + prototype: CustomEventTarget; + }; + /** + * The interface of CustomEventTarget. + */ + type CustomEventTarget, TMode extends "standard" | "strict"> = EventTarget & defineEventAttribute.EventAttributes; +} +/** + * Define an event attribute. + * @param target The `EventTarget` object to define an event attribute. + * @param type The event type to define. + * @param _eventClass Unused, but to infer `Event` class type. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ +export declare function defineEventAttribute(target: TEventTarget, type: TEventType, _eventClass?: TEventConstrucor): asserts target is TEventTarget & defineEventAttribute.EventAttributes>>; +export declare namespace defineEventAttribute { + /** + * Definition of event attributes. + */ + type EventAttributes, TEventMap extends Record> = { + [P in string & keyof TEventMap as `on${P}`]: EventTarget.CallbackFunction | null; + }; +} +/** + * Set the warning handler. + * @param value The warning handler to set. + */ +export declare function setWarningHandler(value: setWarningHandler.WarningHandler | undefined): void; +export declare namespace setWarningHandler { + /** + * The warning information. + */ + interface Warning { + /** + * The code of this warning. + */ + code: string; + /** + * The message in English. + */ + message: string; + /** + * The arguments for replacing placeholders in the text. + */ + args: any[]; + } + /** + * The warning handler. + * @param warning The warning. + */ + type WarningHandler = (warning: Warning) => void; +} +export default EventTarget; + +export {}; diff --git a/index.js b/index.js new file mode 100644 index 0000000..2bf2cb8 --- /dev/null +++ b/index.js @@ -0,0 +1,1186 @@ +'use strict'; + +Object.defineProperty(exports, '__esModule', { value: true }); + +/** + * Assert a condition. + * @param condition The condition that it should satisfy. + * @param message The error message. + * @param args The arguments for replacing placeholders in the message. + */ +function assertType(condition, message, ...args) { + if (!condition) { + throw new TypeError(format(message, args)); + } +} +/** + * Convert a text and arguments to one string. + * @param message The formating text + * @param args The arguments. + */ +function format(message, args) { + let i = 0; + return message.replace(/%[os]/gu, () => anyToString(args[i++])); +} +/** + * Convert a value to a string representation. + * @param x The value to get the string representation. + */ +function anyToString(x) { + if (typeof x !== "object" || x === null) { + return String(x); + } + return Object.prototype.toString.call(x); +} + +let currentErrorHandler; +/** + * Set the error handler. + * @param value The error handler to set. + */ +function setErrorHandler(value) { + assertType(typeof value === "function" || value === undefined, "The error handler must be a function or undefined, but got %o.", value); + currentErrorHandler = value; +} +/** + * Print a error message. + * @param maybeError The error object. + */ +function reportError(maybeError) { + try { + const error = maybeError instanceof Error + ? maybeError + : new Error(anyToString(maybeError)); + // Call the user-defined error handler if exists. + if (currentErrorHandler) { + currentErrorHandler(error); + return; + } + // Dispatch an `error` event if this is on a browser. + if (typeof dispatchEvent === "function" && + typeof ErrorEvent === "function") { + dispatchEvent(new ErrorEvent("error", { error, message: error.message })); + } + // Emit an `uncaughtException` event if this is on Node.js. + //istanbul ignore else + else if (typeof process !== "undefined" && + typeof process.emit === "function") { + process.emit("uncaughtException", error); + return; + } + // Otherwise, print the error. + console.error(error); + } + catch (_a) { + // ignore. + } +} + +/** + * The global object. + */ +//istanbul ignore next +const Global = typeof window !== "undefined" + ? window + : typeof self !== "undefined" + ? self + : typeof global !== "undefined" + ? global + : typeof globalThis !== "undefined" + ? globalThis + : undefined; + +let currentWarnHandler; +/** + * Set the warning handler. + * @param value The warning handler to set. + */ +function setWarningHandler(value) { + assertType(typeof value === "function" || value === undefined, "The warning handler must be a function or undefined, but got %o.", value); + currentWarnHandler = value; +} +/** + * The warning information. + */ +class Warning { + constructor(code, message) { + this.code = code; + this.message = message; + } + /** + * Report this warning. + * @param args The arguments of the warning. + */ + warn(...args) { + var _a; + try { + // Call the user-defined warning handler if exists. + if (currentWarnHandler) { + currentWarnHandler({ ...this, args }); + return; + } + // Otherwise, print the warning. + const stack = ((_a = new Error().stack) !== null && _a !== void 0 ? _a : "").replace(/^(?:.+?\n){2}/gu, "\n"); + console.warn(this.message, ...args, stack); + } + catch (_b) { + // Ignore. + } + } +} + +const InitEventWasCalledWhileDispatching = new Warning("W01", "Unable to initialize event under dispatching."); +const FalsyWasAssignedToCancelBubble = new Warning("W02", "Assigning any falsy value to 'cancelBubble' property has no effect."); +const TruthyWasAssignedToReturnValue = new Warning("W03", "Assigning any truthy value to 'returnValue' property has no effect."); +const NonCancelableEventWasCanceled = new Warning("W04", "Unable to preventDefault on non-cancelable events."); +const CanceledInPassiveListener = new Warning("W05", "Unable to preventDefault inside passive event listener invocation."); +const EventListenerWasDuplicated = new Warning("W06", "An event listener wasn't added because it has been added already: %o, %o"); +const OptionWasIgnored = new Warning("W07", "The %o option value was abandoned because the event listener wasn't added as duplicated."); +const InvalidEventListener = new Warning("W08", "The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"); +const InvalidAttributeHandler = new Warning("W09", "Event attribute handler must be a function: %o"); + +/*eslint-disable class-methods-use-this */ +/** + * An implementation of `Event` interface, that wraps a given event object. + * `EventTarget` shim can control the internal state of this `Event` objects. + * @see https://dom.spec.whatwg.org/#event + */ +class Event { + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + static get NONE() { + return NONE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + static get CAPTURING_PHASE() { + return CAPTURING_PHASE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + static get AT_TARGET() { + return AT_TARGET; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + static get BUBBLING_PHASE() { + return BUBBLING_PHASE; + } + /** + * Initialize this event instance. + * @param type The type of this event. + * @param eventInitDict Options to initialize. + * @see https://dom.spec.whatwg.org/#dom-event-event + */ + constructor(type, eventInitDict) { + Object.defineProperty(this, "isTrusted", { + value: false, + enumerable: true, + }); + const opts = eventInitDict !== null && eventInitDict !== void 0 ? eventInitDict : {}; + internalDataMap.set(this, { + type: String(type), + bubbles: Boolean(opts.bubbles), + cancelable: Boolean(opts.cancelable), + composed: Boolean(opts.composed), + target: null, + currentTarget: null, + stopPropagationFlag: false, + stopImmediatePropagationFlag: false, + canceledFlag: false, + inPassiveListenerFlag: false, + dispatchFlag: false, + timeStamp: Date.now(), + }); + } + /** + * The type of this event. + * @see https://dom.spec.whatwg.org/#dom-event-type + */ + get type() { + return $(this).type; + } + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-target + */ + get target() { + return $(this).target; + } + /** + * The event target of the current dispatching. + * @deprecated Use the `target` property instead. + * @see https://dom.spec.whatwg.org/#dom-event-srcelement + */ + get srcElement() { + return $(this).target; + } + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-currenttarget + */ + get currentTarget() { + return $(this).currentTarget; + } + /** + * The event target of the current dispatching. + * This doesn't support node tree. + * @see https://dom.spec.whatwg.org/#dom-event-composedpath + */ + composedPath() { + const currentTarget = $(this).currentTarget; + if (currentTarget) { + return [currentTarget]; + } + return []; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + get NONE() { + return NONE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + get CAPTURING_PHASE() { + return CAPTURING_PHASE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + get AT_TARGET() { + return AT_TARGET; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + get BUBBLING_PHASE() { + return BUBBLING_PHASE; + } + /** + * The current event phase. + * @see https://dom.spec.whatwg.org/#dom-event-eventphase + */ + get eventPhase() { + return $(this).dispatchFlag ? 2 : 0; + } + /** + * Stop event bubbling. + * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value. + * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation + */ + stopPropagation() { + $(this).stopPropagationFlag = true; + } + /** + * `true` if event bubbling was stopped. + * @deprecated + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + get cancelBubble() { + return $(this).stopPropagationFlag; + } + /** + * Stop event bubbling if `true` is set. + * @deprecated Use the `stopPropagation()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + set cancelBubble(value) { + if (value) { + $(this).stopPropagationFlag = true; + } + else { + FalsyWasAssignedToCancelBubble.warn(); + } + } + /** + * Stop event bubbling and subsequent event listener callings. + * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation + */ + stopImmediatePropagation() { + const data = $(this); + data.stopPropagationFlag = data.stopImmediatePropagationFlag = true; + } + /** + * `true` if this event will bubble. + * @see https://dom.spec.whatwg.org/#dom-event-bubbles + */ + get bubbles() { + return $(this).bubbles; + } + /** + * `true` if this event can be canceled by the `preventDefault()` method. + * @see https://dom.spec.whatwg.org/#dom-event-cancelable + */ + get cancelable() { + return $(this).cancelable; + } + /** + * `true` if the default behavior will act. + * @deprecated Use the `defaultPrevented` proeprty instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + get returnValue() { + return !$(this).canceledFlag; + } + /** + * Cancel the default behavior if `false` is set. + * @deprecated Use the `preventDefault()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + set returnValue(value) { + if (!value) { + setCancelFlag($(this)); + } + else { + TruthyWasAssignedToReturnValue.warn(); + } + } + /** + * Cancel the default behavior. + * @see https://dom.spec.whatwg.org/#dom-event-preventdefault + */ + preventDefault() { + setCancelFlag($(this)); + } + /** + * `true` if the default behavior was canceled. + * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented + */ + get defaultPrevented() { + return $(this).canceledFlag; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-composed + */ + get composed() { + return $(this).composed; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-istrusted + */ + //istanbul ignore next + get isTrusted() { + return false; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-timestamp + */ + get timeStamp() { + return $(this).timeStamp; + } + /** + * @deprecated Don't use this method. The constructor did initialization. + */ + initEvent(type, bubbles = false, cancelable = false) { + const data = $(this); + if (data.dispatchFlag) { + InitEventWasCalledWhileDispatching.warn(); + return; + } + internalDataMap.set(this, { + ...data, + type: String(type), + bubbles: Boolean(bubbles), + cancelable: Boolean(cancelable), + target: null, + currentTarget: null, + stopPropagationFlag: false, + stopImmediatePropagationFlag: false, + canceledFlag: false, + }); + } +} +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ +const NONE = 0; +const CAPTURING_PHASE = 1; +const AT_TARGET = 2; +const BUBBLING_PHASE = 3; +/** + * Private data for event wrappers. + */ +const internalDataMap = new WeakMap(); +/** + * Get private data. + * @param event The event object to get private data. + * @param name The variable name to report. + * @returns The private data of the event. + */ +function $(event, name = "this") { + const retv = internalDataMap.get(event); + assertType(retv != null, "'%s' must be an object that Event constructor created, but got another one: %o", name, event); + return retv; +} +/** + * https://dom.spec.whatwg.org/#set-the-canceled-flag + * @param data private data. + */ +function setCancelFlag(data) { + if (data.inPassiveListenerFlag) { + CanceledInPassiveListener.warn(); + return; + } + if (!data.cancelable) { + NonCancelableEventWasCanceled.warn(); + return; + } + data.canceledFlag = true; +} +// Set enumerable +Object.defineProperty(Event, "NONE", { enumerable: true }); +Object.defineProperty(Event, "CAPTURING_PHASE", { enumerable: true }); +Object.defineProperty(Event, "AT_TARGET", { enumerable: true }); +Object.defineProperty(Event, "BUBBLING_PHASE", { enumerable: true }); +const keys = Object.getOwnPropertyNames(Event.prototype); +for (let i = 0; i < keys.length; ++i) { + if (keys[i] === "constructor") { + continue; + } + Object.defineProperty(Event.prototype, keys[i], { enumerable: true }); +} +// Ensure `event instanceof window.Event` is `true`. +if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") { + Object.setPrototypeOf(Event.prototype, Global.Event.prototype); +} + +/** + * Create a new InvalidStateError instance. + * @param message The error message. + */ +function createInvalidStateError(message) { + if (Global.DOMException) { + return new Global.DOMException(message, "InvalidStateError"); + } + if (DOMException == null) { + DOMException = class DOMException extends Error { + constructor(msg) { + super(msg); + if (Error.captureStackTrace) { + Error.captureStackTrace(this, DOMException); + } + } + // eslint-disable-next-line class-methods-use-this + get code() { + return 11; + } + // eslint-disable-next-line class-methods-use-this + get name() { + return "InvalidStateError"; + } + }; + Object.defineProperties(DOMException.prototype, { + code: { enumerable: true }, + name: { enumerable: true }, + }); + defineErrorCodeProperties(DOMException); + defineErrorCodeProperties(DOMException.prototype); + } + return new DOMException(message); +} +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ +let DOMException; +const ErrorCodeMap = { + INDEX_SIZE_ERR: 1, + DOMSTRING_SIZE_ERR: 2, + HIERARCHY_REQUEST_ERR: 3, + WRONG_DOCUMENT_ERR: 4, + INVALID_CHARACTER_ERR: 5, + NO_DATA_ALLOWED_ERR: 6, + NO_MODIFICATION_ALLOWED_ERR: 7, + NOT_FOUND_ERR: 8, + NOT_SUPPORTED_ERR: 9, + INUSE_ATTRIBUTE_ERR: 10, + INVALID_STATE_ERR: 11, + SYNTAX_ERR: 12, + INVALID_MODIFICATION_ERR: 13, + NAMESPACE_ERR: 14, + INVALID_ACCESS_ERR: 15, + VALIDATION_ERR: 16, + TYPE_MISMATCH_ERR: 17, + SECURITY_ERR: 18, + NETWORK_ERR: 19, + ABORT_ERR: 20, + URL_MISMATCH_ERR: 21, + QUOTA_EXCEEDED_ERR: 22, + TIMEOUT_ERR: 23, + INVALID_NODE_TYPE_ERR: 24, + DATA_CLONE_ERR: 25, +}; +function defineErrorCodeProperties(obj) { + const keys = Object.keys(ErrorCodeMap); + for (let i = 0; i < keys.length; ++i) { + const key = keys[i]; + const value = ErrorCodeMap[key]; + Object.defineProperty(obj, key, { + get() { + return value; + }, + configurable: true, + enumerable: true, + }); + } +} + +/** + * An implementation of `Event` interface, that wraps a given event object. + * This class controls the internal state of `Event`. + * @see https://dom.spec.whatwg.org/#interface-event + */ +class EventWrapper extends Event { + /** + * Wrap a given event object to control states. + * @param event The event-like object to wrap. + */ + static wrap(event) { + return new (getWrapperClassOf(event))(event); + } + constructor(event) { + super(event.type, { + bubbles: event.bubbles, + cancelable: event.cancelable, + composed: event.composed, + }); + if (event.cancelBubble) { + super.stopPropagation(); + } + if (event.defaultPrevented) { + super.preventDefault(); + } + internalDataMap$1.set(this, { original: event }); + // Define accessors + const keys = Object.keys(event); + for (let i = 0; i < keys.length; ++i) { + const key = keys[i]; + if (!(key in this)) { + Object.defineProperty(this, key, defineRedirectDescriptor(event, key)); + } + } + } + stopPropagation() { + super.stopPropagation(); + const { original } = $$1(this); + if ("stopPropagation" in original) { + original.stopPropagation(); + } + } + get cancelBubble() { + return super.cancelBubble; + } + set cancelBubble(value) { + super.cancelBubble = value; + const { original } = $$1(this); + if ("cancelBubble" in original) { + original.cancelBubble = value; + } + } + stopImmediatePropagation() { + super.stopImmediatePropagation(); + const { original } = $$1(this); + if ("stopImmediatePropagation" in original) { + original.stopImmediatePropagation(); + } + } + get returnValue() { + return super.returnValue; + } + set returnValue(value) { + super.returnValue = value; + const { original } = $$1(this); + if ("returnValue" in original) { + original.returnValue = value; + } + } + preventDefault() { + super.preventDefault(); + const { original } = $$1(this); + if ("preventDefault" in original) { + original.preventDefault(); + } + } + get timeStamp() { + const { original } = $$1(this); + if ("timeStamp" in original) { + return original.timeStamp; + } + return super.timeStamp; + } +} +/** + * Private data for event wrappers. + */ +const internalDataMap$1 = new WeakMap(); +/** + * Get private data. + * @param event The event object to get private data. + * @returns The private data of the event. + */ +function $$1(event) { + const retv = internalDataMap$1.get(event); + assertType(retv != null, "'this' is expected an Event object, but got", event); + return retv; +} +/** + * Cache for wrapper classes. + * @type {WeakMap} + * @private + */ +const wrapperClassCache = new WeakMap(); +// Make association for wrappers. +wrapperClassCache.set(Object.prototype, EventWrapper); +if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") { + wrapperClassCache.set(Global.Event.prototype, EventWrapper); +} +/** + * Get the wrapper class of a given prototype. + * @param originalEvent The event object to wrap. + */ +function getWrapperClassOf(originalEvent) { + const prototype = Object.getPrototypeOf(originalEvent); + if (prototype == null) { + return EventWrapper; + } + let wrapper = wrapperClassCache.get(prototype); + if (wrapper == null) { + wrapper = defineWrapper(getWrapperClassOf(prototype), prototype); + wrapperClassCache.set(prototype, wrapper); + } + return wrapper; +} +/** + * Define new wrapper class. + * @param BaseEventWrapper The base wrapper class. + * @param originalPrototype The prototype of the original event. + */ +function defineWrapper(BaseEventWrapper, originalPrototype) { + class CustomEventWrapper extends BaseEventWrapper { + } + const keys = Object.keys(originalPrototype); + for (let i = 0; i < keys.length; ++i) { + Object.defineProperty(CustomEventWrapper.prototype, keys[i], defineRedirectDescriptor(originalPrototype, keys[i])); + } + return CustomEventWrapper; +} +/** + * Get the property descriptor to redirect a given property. + */ +function defineRedirectDescriptor(obj, key) { + const d = Object.getOwnPropertyDescriptor(obj, key); + return { + get() { + const original = $$1(this).original; + const value = original[key]; + if (typeof value === "function") { + return value.bind(original); + } + return value; + }, + set(value) { + const original = $$1(this).original; + original[key] = value; + }, + configurable: d.configurable, + enumerable: d.enumerable, + }; +} + +/** + * Create a new listener. + * @param callback The callback function. + * @param capture The capture flag. + * @param passive The passive flag. + * @param once The once flag. + * @param signal The abort signal. + * @param signalListener The abort event listener for the abort signal. + */ +function createListener(callback, capture, passive, once, signal, signalListener) { + return { + callback, + flags: (capture ? 1 /* Capture */ : 0) | + (passive ? 2 /* Passive */ : 0) | + (once ? 4 /* Once */ : 0), + signal, + signalListener, + }; +} +/** + * Set the `removed` flag to the given listener. + * @param listener The listener to check. + */ +function setRemoved(listener) { + listener.flags |= 8 /* Removed */; +} +/** + * Check if the given listener has the `capture` flag or not. + * @param listener The listener to check. + */ +function isCapture(listener) { + return (listener.flags & 1 /* Capture */) === 1 /* Capture */; +} +/** + * Check if the given listener has the `passive` flag or not. + * @param listener The listener to check. + */ +function isPassive(listener) { + return (listener.flags & 2 /* Passive */) === 2 /* Passive */; +} +/** + * Check if the given listener has the `once` flag or not. + * @param listener The listener to check. + */ +function isOnce(listener) { + return (listener.flags & 4 /* Once */) === 4 /* Once */; +} +/** + * Check if the given listener has the `removed` flag or not. + * @param listener The listener to check. + */ +function isRemoved(listener) { + return (listener.flags & 8 /* Removed */) === 8 /* Removed */; +} +/** + * Call an event listener. + * @param listener The listener to call. + * @param target The event target object for `thisArg`. + * @param event The event object for the first argument. + * @param attribute `true` if this callback is an event attribute handler. + */ +function invokeCallback({ callback }, target, event) { + try { + if (typeof callback === "function") { + callback.call(target, event); + } + else if (typeof callback.handleEvent === "function") { + callback.handleEvent(event); + } + } + catch (thrownError) { + reportError(thrownError); + } +} + +/** + * Find the index of given listener. + * This returns `-1` if not found. + * @param list The listener list. + * @param callback The callback function to find. + * @param capture The capture flag to find. + */ +function findIndexOfListener({ listeners }, callback, capture) { + for (let i = 0; i < listeners.length; ++i) { + if (listeners[i].callback === callback && + isCapture(listeners[i]) === capture) { + return i; + } + } + return -1; +} +/** + * Add the given listener. + * Does copy-on-write if needed. + * @param list The listener list. + * @param callback The callback function. + * @param capture The capture flag. + * @param passive The passive flag. + * @param once The once flag. + * @param signal The abort signal. + */ +function addListener(list, callback, capture, passive, once, signal) { + let signalListener; + if (signal) { + signalListener = removeListener.bind(null, list, callback, capture); + signal.addEventListener("abort", signalListener); + } + const listener = createListener(callback, capture, passive, once, signal, signalListener); + if (list.cow) { + list.cow = false; + list.listeners = [...list.listeners, listener]; + } + else { + list.listeners.push(listener); + } + return listener; +} +/** + * Remove a listener. + * @param list The listener list. + * @param callback The callback function to find. + * @param capture The capture flag to find. + * @returns `true` if it mutated the list directly. + */ +function removeListener(list, callback, capture) { + const index = findIndexOfListener(list, callback, capture); + if (index !== -1) { + return removeListenerAt(list, index); + } + return false; +} +/** + * Remove a listener. + * @param list The listener list. + * @param index The index of the target listener. + * @param disableCow Disable copy-on-write if true. + * @returns `true` if it mutated the `listeners` array directly. + */ +function removeListenerAt(list, index, disableCow = false) { + const listener = list.listeners[index]; + // Set the removed flag. + setRemoved(listener); + // Dispose the abort signal listener if exists. + if (listener.signal) { + listener.signal.removeEventListener("abort", listener.signalListener); + } + // Remove it from the array. + if (list.cow && !disableCow) { + list.cow = false; + list.listeners = list.listeners.filter((_, i) => i !== index); + return false; + } + list.listeners.splice(index, 1); + return true; +} + +/** + * Create a new `ListenerListMap` object. + */ +function createListenerListMap() { + return Object.create(null); +} +/** + * Get the listener list of the given type. + * If the listener list has not been initialized, initialize and return it. + * @param listenerMap The listener list map. + * @param type The event type to get. + */ +function ensureListenerList(listenerMap, type) { + var _a; + return ((_a = listenerMap[type]) !== null && _a !== void 0 ? _a : (listenerMap[type] = { + attrCallback: undefined, + attrListener: undefined, + cow: false, + listeners: [], + })); +} + +/** + * An implementation of the `EventTarget` interface. + * @see https://dom.spec.whatwg.org/#eventtarget + */ +class EventTarget { + /** + * Initialize this instance. + */ + constructor() { + internalDataMap$2.set(this, createListenerListMap()); + } + // Implementation + addEventListener(type0, callback0, options0) { + const listenerMap = $$2(this); + const { callback, capture, once, passive, signal, type, } = normalizeAddOptions(type0, callback0, options0); + if (callback == null || (signal === null || signal === void 0 ? void 0 : signal.aborted)) { + return; + } + const list = ensureListenerList(listenerMap, type); + // Find existing listener. + const i = findIndexOfListener(list, callback, capture); + if (i !== -1) { + warnDuplicate(list.listeners[i], passive, once, signal); + return; + } + // Add the new listener. + addListener(list, callback, capture, passive, once, signal); + } + // Implementation + removeEventListener(type0, callback0, options0) { + const listenerMap = $$2(this); + const { callback, capture, type } = normalizeOptions(type0, callback0, options0); + const list = listenerMap[type]; + if (callback != null && list) { + removeListener(list, callback, capture); + } + } + // Implementation + dispatchEvent(e) { + const list = $$2(this)[String(e.type)]; + if (list == null) { + return true; + } + const event = e instanceof Event ? e : EventWrapper.wrap(e); + const eventData = $(event, "event"); + if (eventData.dispatchFlag) { + throw createInvalidStateError("This event has been in dispatching."); + } + eventData.dispatchFlag = true; + eventData.target = eventData.currentTarget = this; + if (!eventData.stopPropagationFlag) { + const { cow, listeners } = list; + // Set copy-on-write flag. + list.cow = true; + // Call listeners. + for (let i = 0; i < listeners.length; ++i) { + const listener = listeners[i]; + // Skip if removed. + if (isRemoved(listener)) { + continue; + } + // Remove this listener if has the `once` flag. + if (isOnce(listener) && removeListenerAt(list, i, !cow)) { + // Because this listener was removed, the next index is the + // same as the current value. + i -= 1; + } + // Call this listener with the `passive` flag. + eventData.inPassiveListenerFlag = isPassive(listener); + invokeCallback(listener, this, event); + eventData.inPassiveListenerFlag = false; + // Stop if the `event.stopImmediatePropagation()` method was called. + if (eventData.stopImmediatePropagationFlag) { + break; + } + } + // Restore copy-on-write flag. + if (!cow) { + list.cow = false; + } + } + eventData.target = null; + eventData.currentTarget = null; + eventData.stopImmediatePropagationFlag = false; + eventData.stopPropagationFlag = false; + eventData.dispatchFlag = false; + return !eventData.canceledFlag; + } +} +/** + * Internal data. + */ +const internalDataMap$2 = new WeakMap(); +/** + * Get private data. + * @param target The event target object to get private data. + * @param name The variable name to report. + * @returns The private data of the event. + */ +function $$2(target, name = "this") { + const retv = internalDataMap$2.get(target); + assertType(retv != null, "'%s' must be an object that EventTarget constructor created, but got another one: %o", name, target); + return retv; +} +/** + * Normalize options. + * @param options The options to normalize. + */ +function normalizeAddOptions(type, callback, options) { + var _a; + assertCallback(callback); + if (typeof options === "object" && options !== null) { + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options.capture), + passive: Boolean(options.passive), + once: Boolean(options.once), + signal: (_a = options.signal) !== null && _a !== void 0 ? _a : undefined, + }; + } + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options), + passive: false, + once: false, + signal: undefined, + }; +} +/** + * Normalize options. + * @param options The options to normalize. + */ +function normalizeOptions(type, callback, options) { + assertCallback(callback); + if (typeof options === "object" && options !== null) { + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options.capture), + }; + } + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options), + }; +} +/** + * Assert the type of 'callback' argument. + * @param callback The callback to check. + */ +function assertCallback(callback) { + if (typeof callback === "function" || + (typeof callback === "object" && + callback !== null && + typeof callback.handleEvent === "function")) { + return; + } + if (callback == null || typeof callback === "object") { + InvalidEventListener.warn(callback); + return; + } + throw new TypeError(format(InvalidEventListener.message, [callback])); +} +/** + * Print warning for duplicated. + * @param listener The current listener that is duplicated. + * @param passive The passive flag of the new duplicated listener. + * @param once The once flag of the new duplicated listener. + * @param signal The signal object of the new duplicated listener. + */ +function warnDuplicate(listener, passive, once, signal) { + EventListenerWasDuplicated.warn(isCapture(listener) ? "capture" : "bubble", listener.callback); + if (isPassive(listener) !== passive) { + OptionWasIgnored.warn("passive"); + } + if (isOnce(listener) !== once) { + OptionWasIgnored.warn("once"); + } + if (listener.signal !== signal) { + OptionWasIgnored.warn("signal"); + } +} +// Set enumerable +const keys$1 = Object.getOwnPropertyNames(EventTarget.prototype); +for (let i = 0; i < keys$1.length; ++i) { + if (keys$1[i] === "constructor") { + continue; + } + Object.defineProperty(EventTarget.prototype, keys$1[i], { enumerable: true }); +} +// Ensure `eventTarget instanceof window.EventTarget` is `true`. +if (typeof Global !== "undefined" && + typeof Global.EventTarget !== "undefined") { + Object.setPrototypeOf(EventTarget.prototype, Global.EventTarget.prototype); +} + +/** + * Get the current value of a given event attribute. + * @param target The `EventTarget` object to get. + * @param type The event type. + */ +function getEventAttributeValue(target, type) { + var _a, _b; + const listMap = $$2(target, "target"); + return (_b = (_a = listMap[type]) === null || _a === void 0 ? void 0 : _a.attrCallback) !== null && _b !== void 0 ? _b : null; +} +/** + * Set an event listener to a given event attribute. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ +function setEventAttributeValue(target, type, callback) { + if (callback != null && typeof callback !== "function") { + InvalidAttributeHandler.warn(callback); + } + if (typeof callback === "function" || + (typeof callback === "object" && callback !== null)) { + upsertEventAttributeListener(target, type, callback); + } + else { + removeEventAttributeListener(target, type); + } +} +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ +/** + * Update or insert the given event attribute handler. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ +function upsertEventAttributeListener(target, type, callback) { + const list = ensureListenerList($$2(target, "target"), String(type)); + list.attrCallback = callback; + if (list.attrListener == null) { + list.attrListener = addListener(list, defineEventAttributeCallback(list), false, false, false, undefined); + } +} +/** + * Remove the given event attribute handler. + * @param target The `EventTarget` object to remove. + * @param type The event type. + * @param callback The event listener. + */ +function removeEventAttributeListener(target, type) { + const listMap = $$2(target, "target"); + const list = listMap[String(type)]; + if (list && list.attrListener) { + removeListener(list, list.attrListener.callback, false); + list.attrCallback = list.attrListener = undefined; + } +} +/** + * Define the callback function for the given listener list object. + * It calls `attrCallback` property if the property value is a function. + * @param list The `ListenerList` object. + */ +function defineEventAttributeCallback(list) { + return function (event) { + const callback = list.attrCallback; + if (typeof callback === "function") { + callback.call(this, event); + } + }; +} + +/** + * Define an `EventTarget` class that has event attibutes. + * @param types The types to define event attributes. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ +function defineCustomEventTarget(...types) { + class CustomEventTarget extends EventTarget { + } + for (let i = 0; i < types.length; ++i) { + defineEventAttribute(CustomEventTarget.prototype, types[i]); + } + return CustomEventTarget; +} +/** + * Define an event attribute. + * @param target The `EventTarget` object to define an event attribute. + * @param type The event type to define. + * @param _eventClass Unused, but to infer `Event` class type. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ +function defineEventAttribute(target, type, _eventClass) { + Object.defineProperty(target, `on${type}`, { + get() { + return getEventAttributeValue(this, type); + }, + set(value) { + setEventAttributeValue(this, type, value); + }, + configurable: true, + enumerable: true, + }); +} + +exports.Event = Event; +exports.EventTarget = EventTarget; +exports.default = EventTarget; +exports.defineCustomEventTarget = defineCustomEventTarget; +exports.defineEventAttribute = defineEventAttribute; +exports.getEventAttributeValue = getEventAttributeValue; +exports.setErrorHandler = setErrorHandler; +exports.setEventAttributeValue = setEventAttributeValue; +exports.setWarningHandler = setWarningHandler; +//# sourceMappingURL=index.js.map diff --git a/index.js.map b/index.js.map new file mode 100644 index 0000000..5093659 --- /dev/null +++ b/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sources":["../src/lib/misc.ts","../src/lib/error-handler.ts","../src/lib/global.ts","../src/lib/warning-handler.ts","../src/lib/warnings.ts","../src/lib/event.ts","../src/lib/dom-exception.ts","../src/lib/event-wrapper.ts","../src/lib/listener.ts","../src/lib/listener-list.ts","../src/lib/listener-list-map.ts","../src/lib/event-target.ts","../src/lib/event-attribute-handler.ts","../src/lib/legacy.ts"],"sourcesContent":["/**\n * Assert a condition.\n * @param condition The condition that it should satisfy.\n * @param message The error message.\n * @param args The arguments for replacing placeholders in the message.\n */\nexport function assertType(\n condition: boolean,\n message: string,\n ...args: any[]\n): asserts condition {\n if (!condition) {\n throw new TypeError(format(message, args))\n }\n}\n\n/**\n * Convert a text and arguments to one string.\n * @param message The formating text\n * @param args The arguments.\n */\nexport function format(message: string, args: any[]): string {\n let i = 0\n return message.replace(/%[os]/gu, () => anyToString(args[i++]))\n}\n\n/**\n * Convert a value to a string representation.\n * @param x The value to get the string representation.\n */\nexport function anyToString(x: any): string {\n if (typeof x !== \"object\" || x === null) {\n return String(x)\n }\n return Object.prototype.toString.call(x)\n}\n","import { anyToString, assertType } from \"./misc\"\n\ndeclare const console: any\ndeclare const dispatchEvent: any\ndeclare const ErrorEvent: any\ndeclare const process: any\n\nlet currentErrorHandler: setErrorHandler.ErrorHandler | undefined\n\n/**\n * Set the error handler.\n * @param value The error handler to set.\n */\nexport function setErrorHandler(\n value: setErrorHandler.ErrorHandler | undefined,\n): void {\n assertType(\n typeof value === \"function\" || value === undefined,\n \"The error handler must be a function or undefined, but got %o.\",\n value,\n )\n currentErrorHandler = value\n}\nexport namespace setErrorHandler {\n /**\n * The error handler.\n * @param error The thrown error object.\n */\n export type ErrorHandler = (error: Error) => void\n}\n\n/**\n * Print a error message.\n * @param maybeError The error object.\n */\nexport function reportError(maybeError: unknown): void {\n try {\n const error =\n maybeError instanceof Error\n ? maybeError\n : new Error(anyToString(maybeError))\n\n // Call the user-defined error handler if exists.\n if (currentErrorHandler) {\n currentErrorHandler(error)\n return\n }\n\n // Dispatch an `error` event if this is on a browser.\n if (\n typeof dispatchEvent === \"function\" &&\n typeof ErrorEvent === \"function\"\n ) {\n dispatchEvent(\n new ErrorEvent(\"error\", { error, message: error.message }),\n )\n }\n\n // Emit an `uncaughtException` event if this is on Node.js.\n //istanbul ignore else\n else if (\n typeof process !== \"undefined\" &&\n typeof process.emit === \"function\"\n ) {\n process.emit(\"uncaughtException\", error)\n return\n }\n\n // Otherwise, print the error.\n console.error(error)\n } catch {\n // ignore.\n }\n}\n","declare const globalThis: any\ndeclare const window: any\ndeclare const self: any\ndeclare const global: any\n\n/**\n * The global object.\n */\n//istanbul ignore next\nexport const Global: any =\n typeof window !== \"undefined\"\n ? window\n : typeof self !== \"undefined\"\n ? self\n : typeof global !== \"undefined\"\n ? global\n : typeof globalThis !== \"undefined\"\n ? globalThis\n : undefined\n","import { assertType } from \"./misc\"\n\ndeclare const console: any\n\nlet currentWarnHandler: setWarningHandler.WarningHandler | undefined\n\n/**\n * Set the warning handler.\n * @param value The warning handler to set.\n */\nexport function setWarningHandler(\n value: setWarningHandler.WarningHandler | undefined,\n): void {\n assertType(\n typeof value === \"function\" || value === undefined,\n \"The warning handler must be a function or undefined, but got %o.\",\n value,\n )\n currentWarnHandler = value\n}\nexport namespace setWarningHandler {\n /**\n * The warning information.\n */\n export interface Warning {\n /**\n * The code of this warning.\n */\n code: string\n /**\n * The message in English.\n */\n message: string\n /**\n * The arguments for replacing placeholders in the text.\n */\n args: any[]\n }\n\n /**\n * The warning handler.\n * @param warning The warning.\n */\n export type WarningHandler = (warning: Warning) => void\n}\n\n/**\n * The warning information.\n */\nexport class Warning {\n readonly code: string\n readonly message: string\n\n constructor(code: string, message: string) {\n this.code = code\n this.message = message\n }\n\n /**\n * Report this warning.\n * @param args The arguments of the warning.\n */\n warn(...args: TArgs): void {\n try {\n // Call the user-defined warning handler if exists.\n if (currentWarnHandler) {\n currentWarnHandler({ ...this, args })\n return\n }\n\n // Otherwise, print the warning.\n const stack = (new Error().stack ?? \"\").replace(\n /^(?:.+?\\n){2}/gu,\n \"\\n\",\n )\n console.warn(this.message, ...args, stack)\n } catch {\n // Ignore.\n }\n }\n}\n","import { EventTarget } from \"./event-target\" // Used as only type, so no circular.\nimport { Warning } from \"./warning-handler\"\n\nexport const InitEventWasCalledWhileDispatching = new Warning<[]>(\n \"W01\",\n \"Unable to initialize event under dispatching.\",\n)\n\nexport const FalsyWasAssignedToCancelBubble = new Warning<[]>(\n \"W02\",\n \"Assigning any falsy value to 'cancelBubble' property has no effect.\",\n)\n\nexport const TruthyWasAssignedToReturnValue = new Warning<[]>(\n \"W03\",\n \"Assigning any truthy value to 'returnValue' property has no effect.\",\n)\n\nexport const NonCancelableEventWasCanceled = new Warning<[]>(\n \"W04\",\n \"Unable to preventDefault on non-cancelable events.\",\n)\n\nexport const CanceledInPassiveListener = new Warning<[]>(\n \"W05\",\n \"Unable to preventDefault inside passive event listener invocation.\",\n)\n\nexport const EventListenerWasDuplicated = new Warning<\n [type: \"bubble\" | \"capture\", callback: EventTarget.EventListener]\n>(\n \"W06\",\n \"An event listener wasn't added because it has been added already: %o, %o\",\n)\n\nexport const OptionWasIgnored = new Warning<\n [name: \"passive\" | \"once\" | \"signal\"]\n>(\n \"W07\",\n \"The %o option value was abandoned because the event listener wasn't added as duplicated.\",\n)\n\nexport const InvalidEventListener = new Warning<\n [callback: EventTarget.EventListener | {} | null | undefined]\n>(\n \"W08\",\n \"The 'callback' argument must be a function or an object that has 'handleEvent' method: %o\",\n)\n\nexport const InvalidAttributeHandler = new Warning<\n [callback: EventTarget.EventListener | {}]\n>(\"W09\", \"Event attribute handler must be a function: %o\")\n","import { EventTarget } from \"./event-target\" // Used as only type, so no circular.\nimport { Global } from \"./global\"\nimport { assertType } from \"./misc\"\nimport {\n CanceledInPassiveListener,\n FalsyWasAssignedToCancelBubble,\n InitEventWasCalledWhileDispatching,\n NonCancelableEventWasCanceled,\n TruthyWasAssignedToReturnValue,\n} from \"./warnings\"\n\n/*eslint-disable class-methods-use-this */\n\n/**\n * An implementation of `Event` interface, that wraps a given event object.\n * `EventTarget` shim can control the internal state of this `Event` objects.\n * @see https://dom.spec.whatwg.org/#event\n */\nexport class Event {\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-none\n */\n static get NONE(): number {\n return NONE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase\n */\n static get CAPTURING_PHASE(): number {\n return CAPTURING_PHASE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-at_target\n */\n static get AT_TARGET(): number {\n return AT_TARGET\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase\n */\n static get BUBBLING_PHASE(): number {\n return BUBBLING_PHASE\n }\n\n /**\n * Initialize this event instance.\n * @param type The type of this event.\n * @param eventInitDict Options to initialize.\n * @see https://dom.spec.whatwg.org/#dom-event-event\n */\n constructor(type: TEventType, eventInitDict?: Event.EventInit) {\n Object.defineProperty(this, \"isTrusted\", {\n value: false,\n enumerable: true,\n })\n\n const opts = eventInitDict ?? {}\n internalDataMap.set(this, {\n type: String(type),\n bubbles: Boolean(opts.bubbles),\n cancelable: Boolean(opts.cancelable),\n composed: Boolean(opts.composed),\n target: null,\n currentTarget: null,\n stopPropagationFlag: false,\n stopImmediatePropagationFlag: false,\n canceledFlag: false,\n inPassiveListenerFlag: false,\n dispatchFlag: false,\n timeStamp: Date.now(),\n })\n }\n\n /**\n * The type of this event.\n * @see https://dom.spec.whatwg.org/#dom-event-type\n */\n get type(): TEventType {\n return $(this).type as TEventType\n }\n\n /**\n * The event target of the current dispatching.\n * @see https://dom.spec.whatwg.org/#dom-event-target\n */\n get target(): EventTarget | null {\n return $(this).target\n }\n\n /**\n * The event target of the current dispatching.\n * @deprecated Use the `target` property instead.\n * @see https://dom.spec.whatwg.org/#dom-event-srcelement\n */\n get srcElement(): EventTarget | null {\n return $(this).target\n }\n\n /**\n * The event target of the current dispatching.\n * @see https://dom.spec.whatwg.org/#dom-event-currenttarget\n */\n get currentTarget(): EventTarget | null {\n return $(this).currentTarget\n }\n\n /**\n * The event target of the current dispatching.\n * This doesn't support node tree.\n * @see https://dom.spec.whatwg.org/#dom-event-composedpath\n */\n composedPath(): EventTarget[] {\n const currentTarget = $(this).currentTarget\n if (currentTarget) {\n return [currentTarget]\n }\n return []\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-none\n */\n get NONE(): number {\n return NONE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase\n */\n get CAPTURING_PHASE(): number {\n return CAPTURING_PHASE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-at_target\n */\n get AT_TARGET(): number {\n return AT_TARGET\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase\n */\n get BUBBLING_PHASE(): number {\n return BUBBLING_PHASE\n }\n\n /**\n * The current event phase.\n * @see https://dom.spec.whatwg.org/#dom-event-eventphase\n */\n get eventPhase(): number {\n return $(this).dispatchFlag ? 2 : 0\n }\n\n /**\n * Stop event bubbling.\n * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value.\n * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation\n */\n stopPropagation(): void {\n $(this).stopPropagationFlag = true\n }\n\n /**\n * `true` if event bubbling was stopped.\n * @deprecated\n * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble\n */\n get cancelBubble(): boolean {\n return $(this).stopPropagationFlag\n }\n\n /**\n * Stop event bubbling if `true` is set.\n * @deprecated Use the `stopPropagation()` method instead.\n * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble\n */\n set cancelBubble(value: boolean) {\n if (value) {\n $(this).stopPropagationFlag = true\n } else {\n FalsyWasAssignedToCancelBubble.warn()\n }\n }\n\n /**\n * Stop event bubbling and subsequent event listener callings.\n * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation\n */\n stopImmediatePropagation(): void {\n const data = $(this)\n data.stopPropagationFlag = data.stopImmediatePropagationFlag = true\n }\n\n /**\n * `true` if this event will bubble.\n * @see https://dom.spec.whatwg.org/#dom-event-bubbles\n */\n get bubbles(): boolean {\n return $(this).bubbles\n }\n\n /**\n * `true` if this event can be canceled by the `preventDefault()` method.\n * @see https://dom.spec.whatwg.org/#dom-event-cancelable\n */\n get cancelable(): boolean {\n return $(this).cancelable\n }\n\n /**\n * `true` if the default behavior will act.\n * @deprecated Use the `defaultPrevented` proeprty instead.\n * @see https://dom.spec.whatwg.org/#dom-event-returnvalue\n */\n get returnValue(): boolean {\n return !$(this).canceledFlag\n }\n\n /**\n * Cancel the default behavior if `false` is set.\n * @deprecated Use the `preventDefault()` method instead.\n * @see https://dom.spec.whatwg.org/#dom-event-returnvalue\n */\n set returnValue(value: boolean) {\n if (!value) {\n setCancelFlag($(this))\n } else {\n TruthyWasAssignedToReturnValue.warn()\n }\n }\n\n /**\n * Cancel the default behavior.\n * @see https://dom.spec.whatwg.org/#dom-event-preventdefault\n */\n preventDefault(): void {\n setCancelFlag($(this))\n }\n\n /**\n * `true` if the default behavior was canceled.\n * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented\n */\n get defaultPrevented(): boolean {\n return $(this).canceledFlag\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-composed\n */\n get composed(): boolean {\n return $(this).composed\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-istrusted\n */\n //istanbul ignore next\n get isTrusted(): boolean {\n return false\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-timestamp\n */\n get timeStamp(): number {\n return $(this).timeStamp\n }\n\n /**\n * @deprecated Don't use this method. The constructor did initialization.\n */\n initEvent(type: string, bubbles = false, cancelable = false) {\n const data = $(this)\n if (data.dispatchFlag) {\n InitEventWasCalledWhileDispatching.warn()\n return\n }\n\n internalDataMap.set(this, {\n ...data,\n type: String(type),\n bubbles: Boolean(bubbles),\n cancelable: Boolean(cancelable),\n target: null,\n currentTarget: null,\n stopPropagationFlag: false,\n stopImmediatePropagationFlag: false,\n canceledFlag: false,\n })\n }\n}\n\n/*eslint-enable class-methods-use-this */\n\nexport namespace Event {\n /**\n * The options of the `Event` constructor.\n * @see https://dom.spec.whatwg.org/#dictdef-eventinit\n */\n export interface EventInit {\n bubbles?: boolean\n cancelable?: boolean\n composed?: boolean\n }\n}\n\nexport { $ as getEventInternalData }\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\nconst NONE = 0\nconst CAPTURING_PHASE = 1\nconst AT_TARGET = 2\nconst BUBBLING_PHASE = 3\n\n/**\n * Private data.\n */\ninterface EventInternalData {\n /**\n * The value of `type` attribute.\n */\n readonly type: string\n /**\n * The value of `bubbles` attribute.\n */\n readonly bubbles: boolean\n /**\n * The value of `cancelable` attribute.\n */\n readonly cancelable: boolean\n /**\n * The value of `composed` attribute.\n */\n readonly composed: boolean\n /**\n * The value of `timeStamp` attribute.\n */\n readonly timeStamp: number\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-target\n */\n target: EventTarget | null\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-currenttarget\n */\n currentTarget: EventTarget | null\n /**\n * @see https://dom.spec.whatwg.org/#stop-propagation-flag\n */\n stopPropagationFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#stop-immediate-propagation-flag\n */\n stopImmediatePropagationFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#canceled-flag\n */\n canceledFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#in-passive-listener-flag\n */\n inPassiveListenerFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#dispatch-flag\n */\n dispatchFlag: boolean\n}\n\n/**\n * Private data for event wrappers.\n */\nconst internalDataMap = new WeakMap()\n\n/**\n * Get private data.\n * @param event The event object to get private data.\n * @param name The variable name to report.\n * @returns The private data of the event.\n */\nfunction $(event: unknown, name = \"this\"): EventInternalData {\n const retv = internalDataMap.get(event)\n assertType(\n retv != null,\n \"'%s' must be an object that Event constructor created, but got another one: %o\",\n name,\n event,\n )\n return retv\n}\n\n/**\n * https://dom.spec.whatwg.org/#set-the-canceled-flag\n * @param data private data.\n */\nfunction setCancelFlag(data: EventInternalData) {\n if (data.inPassiveListenerFlag) {\n CanceledInPassiveListener.warn()\n return\n }\n if (!data.cancelable) {\n NonCancelableEventWasCanceled.warn()\n return\n }\n\n data.canceledFlag = true\n}\n\n// Set enumerable\nObject.defineProperty(Event, \"NONE\", { enumerable: true })\nObject.defineProperty(Event, \"CAPTURING_PHASE\", { enumerable: true })\nObject.defineProperty(Event, \"AT_TARGET\", { enumerable: true })\nObject.defineProperty(Event, \"BUBBLING_PHASE\", { enumerable: true })\nconst keys = Object.getOwnPropertyNames(Event.prototype)\nfor (let i = 0; i < keys.length; ++i) {\n if (keys[i] === \"constructor\") {\n continue\n }\n Object.defineProperty(Event.prototype, keys[i], { enumerable: true })\n}\n\n// Ensure `event instanceof window.Event` is `true`.\nif (typeof Global !== \"undefined\" && typeof Global.Event !== \"undefined\") {\n Object.setPrototypeOf(Event.prototype, Global.Event.prototype)\n}\n","import { Global } from \"./global\"\n\n/**\n * Create a new InvalidStateError instance.\n * @param message The error message.\n */\nexport function createInvalidStateError(message: string): Error {\n if (Global.DOMException) {\n return new Global.DOMException(message, \"InvalidStateError\")\n }\n\n if (DOMException == null) {\n DOMException = class DOMException extends Error {\n constructor(msg: string) {\n super(msg)\n if ((Error as any).captureStackTrace) {\n ;(Error as any).captureStackTrace(this, DOMException)\n }\n }\n // eslint-disable-next-line class-methods-use-this\n get code() {\n return 11\n }\n // eslint-disable-next-line class-methods-use-this\n get name() {\n return \"InvalidStateError\"\n }\n }\n Object.defineProperties(DOMException.prototype, {\n code: { enumerable: true },\n name: { enumerable: true },\n })\n defineErrorCodeProperties(DOMException)\n defineErrorCodeProperties(DOMException.prototype)\n }\n return new DOMException(message)\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\nlet DOMException: { new (message: string): Error } | undefined\n\nconst ErrorCodeMap = {\n INDEX_SIZE_ERR: 1,\n DOMSTRING_SIZE_ERR: 2,\n HIERARCHY_REQUEST_ERR: 3,\n WRONG_DOCUMENT_ERR: 4,\n INVALID_CHARACTER_ERR: 5,\n NO_DATA_ALLOWED_ERR: 6,\n NO_MODIFICATION_ALLOWED_ERR: 7,\n NOT_FOUND_ERR: 8,\n NOT_SUPPORTED_ERR: 9,\n INUSE_ATTRIBUTE_ERR: 10,\n INVALID_STATE_ERR: 11,\n SYNTAX_ERR: 12,\n INVALID_MODIFICATION_ERR: 13,\n NAMESPACE_ERR: 14,\n INVALID_ACCESS_ERR: 15,\n VALIDATION_ERR: 16,\n TYPE_MISMATCH_ERR: 17,\n SECURITY_ERR: 18,\n NETWORK_ERR: 19,\n ABORT_ERR: 20,\n URL_MISMATCH_ERR: 21,\n QUOTA_EXCEEDED_ERR: 22,\n TIMEOUT_ERR: 23,\n INVALID_NODE_TYPE_ERR: 24,\n DATA_CLONE_ERR: 25,\n}\ntype ErrorCodeMap = typeof ErrorCodeMap\n\nfunction defineErrorCodeProperties(obj: any): void {\n const keys = Object.keys(ErrorCodeMap) as (keyof ErrorCodeMap)[]\n for (let i = 0; i < keys.length; ++i) {\n const key = keys[i]\n const value = ErrorCodeMap[key]\n Object.defineProperty(obj, key, {\n get() {\n return value\n },\n configurable: true,\n enumerable: true,\n })\n }\n}\n","import { Event } from \"./event\"\nimport { Global } from \"./global\"\nimport { assertType } from \"./misc\"\n\n/**\n * An implementation of `Event` interface, that wraps a given event object.\n * This class controls the internal state of `Event`.\n * @see https://dom.spec.whatwg.org/#interface-event\n */\nexport class EventWrapper extends Event {\n /**\n * Wrap a given event object to control states.\n * @param event The event-like object to wrap.\n */\n static wrap(event: T): EventWrapperOf {\n return new (getWrapperClassOf(event))(event)\n }\n\n protected constructor(event: Event) {\n super(event.type, {\n bubbles: event.bubbles,\n cancelable: event.cancelable,\n composed: event.composed,\n })\n\n if (event.cancelBubble) {\n super.stopPropagation()\n }\n if (event.defaultPrevented) {\n super.preventDefault()\n }\n\n internalDataMap.set(this, { original: event })\n\n // Define accessors\n const keys = Object.keys(event)\n for (let i = 0; i < keys.length; ++i) {\n const key = keys[i]\n if (!(key in this)) {\n Object.defineProperty(\n this,\n key,\n defineRedirectDescriptor(event, key),\n )\n }\n }\n }\n\n stopPropagation(): void {\n super.stopPropagation()\n\n const { original } = $(this)\n if (\"stopPropagation\" in original) {\n original.stopPropagation!()\n }\n }\n\n get cancelBubble(): boolean {\n return super.cancelBubble\n }\n set cancelBubble(value: boolean) {\n super.cancelBubble = value\n\n const { original } = $(this)\n if (\"cancelBubble\" in original) {\n original.cancelBubble = value\n }\n }\n\n stopImmediatePropagation(): void {\n super.stopImmediatePropagation()\n\n const { original } = $(this)\n if (\"stopImmediatePropagation\" in original) {\n original.stopImmediatePropagation!()\n }\n }\n\n get returnValue(): boolean {\n return super.returnValue\n }\n set returnValue(value: boolean) {\n super.returnValue = value\n\n const { original } = $(this)\n if (\"returnValue\" in original) {\n original.returnValue = value\n }\n }\n\n preventDefault(): void {\n super.preventDefault()\n\n const { original } = $(this)\n if (\"preventDefault\" in original) {\n original.preventDefault!()\n }\n }\n\n get timeStamp(): number {\n const { original } = $(this)\n if (\"timeStamp\" in original) {\n return original.timeStamp!\n }\n return super.timeStamp\n }\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\ntype EventLike = { readonly type: string } & Partial\ntype EventWrapperOf = Event &\n Omit\n\ninterface EventWrapperInternalData {\n readonly original: EventLike\n}\n\n/**\n * Private data for event wrappers.\n */\nconst internalDataMap = new WeakMap()\n\n/**\n * Get private data.\n * @param event The event object to get private data.\n * @returns The private data of the event.\n */\nfunction $(event: unknown): EventWrapperInternalData {\n const retv = internalDataMap.get(event)\n assertType(\n retv != null,\n \"'this' is expected an Event object, but got\",\n event,\n )\n return retv\n}\n\n/**\n * Cache for wrapper classes.\n * @type {WeakMap}\n * @private\n */\nconst wrapperClassCache = new WeakMap()\n\n// Make association for wrappers.\nwrapperClassCache.set(Object.prototype, EventWrapper)\nif (typeof Global !== \"undefined\" && typeof Global.Event !== \"undefined\") {\n wrapperClassCache.set(Global.Event.prototype, EventWrapper)\n}\n\n/**\n * Get the wrapper class of a given prototype.\n * @param originalEvent The event object to wrap.\n */\nfunction getWrapperClassOf(\n originalEvent: T,\n): { new (e: T): EventWrapperOf } {\n const prototype = Object.getPrototypeOf(originalEvent)\n if (prototype == null) {\n return EventWrapper as any\n }\n\n let wrapper: any = wrapperClassCache.get(prototype)\n if (wrapper == null) {\n wrapper = defineWrapper(getWrapperClassOf(prototype), prototype)\n wrapperClassCache.set(prototype, wrapper)\n }\n\n return wrapper\n}\n\n/**\n * Define new wrapper class.\n * @param BaseEventWrapper The base wrapper class.\n * @param originalPrototype The prototype of the original event.\n */\nfunction defineWrapper(BaseEventWrapper: any, originalPrototype: any): any {\n class CustomEventWrapper extends BaseEventWrapper {}\n\n const keys = Object.keys(originalPrototype)\n for (let i = 0; i < keys.length; ++i) {\n Object.defineProperty(\n CustomEventWrapper.prototype,\n keys[i],\n defineRedirectDescriptor(originalPrototype, keys[i]),\n )\n }\n\n return CustomEventWrapper\n}\n\n/**\n * Get the property descriptor to redirect a given property.\n */\nfunction defineRedirectDescriptor(obj: any, key: string): PropertyDescriptor {\n const d = Object.getOwnPropertyDescriptor(obj, key)!\n return {\n get() {\n const original: any = $(this).original\n const value = original[key]\n if (typeof value === \"function\") {\n return value.bind(original)\n }\n return value\n },\n set(value: any) {\n const original: any = $(this).original\n original[key] = value\n },\n configurable: d.configurable,\n enumerable: d.enumerable,\n }\n}\n","import { reportError } from \"./error-handler\"\nimport { Event } from \"./event\" // Used as only type, so no circular.\nimport { EventTarget } from \"./event-target\" // Used as only type, so no circular.\n\n/**\n * The event listener concept.\n * @see https://dom.spec.whatwg.org/#concept-event-listener\n */\nexport interface Listener {\n /**\n * The callback function.\n */\n readonly callback: Listener.Callback\n /**\n * The flags of this listener.\n * This is writable to add the removed flag.\n */\n flags: ListenerFlags\n /**\n * The `AbortSignal` to remove this listener.\n */\n readonly signal: Listener.AbortSignal | undefined\n /**\n * The `abort` event listener for the `signal`.\n * To remove it from the `signal`.\n */\n readonly signalListener: (() => void) | undefined\n}\n\nexport namespace Listener {\n export type Callback<\n TEventTarget extends EventTarget,\n TEvent extends Event\n > = CallbackFunction | CallbackObject\n\n export interface CallbackFunction<\n TEventTarget extends EventTarget,\n TEvent extends Event\n > {\n (this: TEventTarget, event: TEvent): void\n }\n\n export interface CallbackObject {\n handleEvent(event: TEvent): void\n }\n\n export interface AbortSignal {\n addEventListener(type: string, callback: Callback): void\n removeEventListener(type: string, callback: Callback): void\n }\n}\n\n/**\n * Create a new listener.\n * @param callback The callback function.\n * @param capture The capture flag.\n * @param passive The passive flag.\n * @param once The once flag.\n * @param signal The abort signal.\n * @param signalListener The abort event listener for the abort signal.\n */\nexport function createListener(\n callback: Listener.Callback,\n capture: boolean,\n passive: boolean,\n once: boolean,\n signal: Listener.AbortSignal | undefined,\n signalListener: (() => void) | undefined,\n): Listener {\n return {\n callback,\n flags:\n (capture ? ListenerFlags.Capture : 0) |\n (passive ? ListenerFlags.Passive : 0) |\n (once ? ListenerFlags.Once : 0),\n signal,\n signalListener,\n }\n}\n\n/**\n * Set the `removed` flag to the given listener.\n * @param listener The listener to check.\n */\nexport function setRemoved(listener: Listener): void {\n listener.flags |= ListenerFlags.Removed\n}\n\n/**\n * Check if the given listener has the `capture` flag or not.\n * @param listener The listener to check.\n */\nexport function isCapture(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Capture) === ListenerFlags.Capture\n}\n\n/**\n * Check if the given listener has the `passive` flag or not.\n * @param listener The listener to check.\n */\nexport function isPassive(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Passive) === ListenerFlags.Passive\n}\n\n/**\n * Check if the given listener has the `once` flag or not.\n * @param listener The listener to check.\n */\nexport function isOnce(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Once) === ListenerFlags.Once\n}\n\n/**\n * Check if the given listener has the `removed` flag or not.\n * @param listener The listener to check.\n */\nexport function isRemoved(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Removed) === ListenerFlags.Removed\n}\n\n/**\n * Call an event listener.\n * @param listener The listener to call.\n * @param target The event target object for `thisArg`.\n * @param event The event object for the first argument.\n * @param attribute `true` if this callback is an event attribute handler.\n */\nexport function invokeCallback(\n { callback }: Listener,\n target: EventTarget,\n event: Event,\n): void {\n try {\n if (typeof callback === \"function\") {\n callback.call(target, event)\n } else if (typeof callback.handleEvent === \"function\") {\n callback.handleEvent(event)\n }\n } catch (thrownError) {\n reportError(thrownError)\n }\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\n/**\n * The flags of listeners.\n */\nconst enum ListenerFlags {\n Capture = 0x01,\n Passive = 0x02,\n Once = 0x04,\n Removed = 0x08,\n}\n","import { createListener, isCapture, Listener, setRemoved } from \"./listener\"\n\n/**\n * Information of an listener list.\n */\nexport interface ListenerList {\n /**\n * The callback function of the event attribute handler.\n */\n attrCallback: Listener.CallbackFunction | undefined\n /**\n * The listener of the event attribute handler.\n */\n attrListener: Listener | undefined\n /**\n * `true` if the `dispatchEvent` method is traversing the current `listeners` array.\n */\n cow: boolean\n /**\n * The listeners.\n * This is writable for copy-on-write.\n */\n listeners: Listener[]\n}\n\n/**\n * Find the index of given listener.\n * This returns `-1` if not found.\n * @param list The listener list.\n * @param callback The callback function to find.\n * @param capture The capture flag to find.\n */\nexport function findIndexOfListener(\n { listeners }: ListenerList,\n callback: Listener.Callback,\n capture: boolean,\n): number {\n for (let i = 0; i < listeners.length; ++i) {\n if (\n listeners[i].callback === callback &&\n isCapture(listeners[i]) === capture\n ) {\n return i\n }\n }\n return -1\n}\n\n/**\n * Add the given listener.\n * Does copy-on-write if needed.\n * @param list The listener list.\n * @param callback The callback function.\n * @param capture The capture flag.\n * @param passive The passive flag.\n * @param once The once flag.\n * @param signal The abort signal.\n */\nexport function addListener(\n list: ListenerList,\n callback: Listener.Callback,\n capture: boolean,\n passive: boolean,\n once: boolean,\n signal: Listener.AbortSignal | undefined,\n): Listener {\n let signalListener: (() => void) | undefined\n if (signal) {\n signalListener = removeListener.bind(null, list, callback, capture)\n signal.addEventListener(\"abort\", signalListener)\n }\n\n const listener = createListener(\n callback,\n capture,\n passive,\n once,\n signal,\n signalListener,\n )\n\n if (list.cow) {\n list.cow = false\n list.listeners = [...list.listeners, listener]\n } else {\n list.listeners.push(listener)\n }\n\n return listener\n}\n\n/**\n * Remove a listener.\n * @param list The listener list.\n * @param callback The callback function to find.\n * @param capture The capture flag to find.\n * @returns `true` if it mutated the list directly.\n */\nexport function removeListener(\n list: ListenerList,\n callback: Listener.Callback,\n capture: boolean,\n): boolean {\n const index = findIndexOfListener(list, callback, capture)\n if (index !== -1) {\n return removeListenerAt(list, index)\n }\n return false\n}\n\n/**\n * Remove a listener.\n * @param list The listener list.\n * @param index The index of the target listener.\n * @param disableCow Disable copy-on-write if true.\n * @returns `true` if it mutated the `listeners` array directly.\n */\nexport function removeListenerAt(\n list: ListenerList,\n index: number,\n disableCow = false,\n): boolean {\n const listener = list.listeners[index]\n\n // Set the removed flag.\n setRemoved(listener)\n\n // Dispose the abort signal listener if exists.\n if (listener.signal) {\n listener.signal.removeEventListener(\"abort\", listener.signalListener!)\n }\n\n // Remove it from the array.\n if (list.cow && !disableCow) {\n list.cow = false\n list.listeners = list.listeners.filter((_, i) => i !== index)\n return false\n }\n list.listeners.splice(index, 1)\n return true\n}\n","import { ListenerList } from \"./listener-list\"\n\n/**\n * The map from event types to each listener list.\n */\nexport interface ListenerListMap {\n [type: string]: ListenerList | undefined\n}\n\n/**\n * Create a new `ListenerListMap` object.\n */\nexport function createListenerListMap(): ListenerListMap {\n return Object.create(null)\n}\n\n/**\n * Get the listener list of the given type.\n * If the listener list has not been initialized, initialize and return it.\n * @param listenerMap The listener list map.\n * @param type The event type to get.\n */\nexport function ensureListenerList(\n listenerMap: Record,\n type: string,\n): ListenerList {\n return (listenerMap[type] ??= {\n attrCallback: undefined,\n attrListener: undefined,\n cow: false,\n listeners: [],\n })\n}\n","import { createInvalidStateError } from \"./dom-exception\"\nimport { Event, getEventInternalData } from \"./event\"\nimport { EventWrapper } from \"./event-wrapper\"\nimport { Global } from \"./global\"\nimport {\n invokeCallback,\n isCapture,\n isOnce,\n isPassive,\n isRemoved,\n Listener,\n} from \"./listener\"\nimport {\n addListener,\n findIndexOfListener,\n removeListener,\n removeListenerAt,\n} from \"./listener-list\"\nimport {\n createListenerListMap,\n ensureListenerList,\n ListenerListMap,\n} from \"./listener-list-map\"\nimport { assertType, format } from \"./misc\"\nimport {\n EventListenerWasDuplicated,\n InvalidEventListener,\n OptionWasIgnored,\n} from \"./warnings\"\n\n/**\n * An implementation of the `EventTarget` interface.\n * @see https://dom.spec.whatwg.org/#eventtarget\n */\nexport class EventTarget<\n TEventMap extends Record = Record,\n TMode extends \"standard\" | \"strict\" = \"standard\"\n> {\n /**\n * Initialize this instance.\n */\n constructor() {\n internalDataMap.set(this, createListenerListMap())\n }\n\n /**\n * Add an event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param options Options.\n */\n addEventListener(\n type: T,\n callback?: EventTarget.EventListener | null,\n options?: EventTarget.AddOptions,\n ): void\n\n /**\n * Add an event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param options Options.\n */\n addEventListener(\n type: string,\n callback?: EventTarget.FallbackEventListener,\n options?: EventTarget.AddOptions,\n ): void\n\n /**\n * Add an event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param capture The capture flag.\n * @deprecated Use `{capture: boolean}` object instead of a boolean value.\n */\n addEventListener(\n type: T,\n callback:\n | EventTarget.EventListener\n | null\n | undefined,\n capture: boolean,\n ): void\n\n /**\n * Add an event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param capture The capture flag.\n * @deprecated Use `{capture: boolean}` object instead of a boolean value.\n */\n addEventListener(\n type: string,\n callback: EventTarget.FallbackEventListener,\n capture: boolean,\n ): void\n\n // Implementation\n addEventListener(\n type0: T,\n callback0?: EventTarget.EventListener | null,\n options0?: boolean | EventTarget.AddOptions,\n ): void {\n const listenerMap = $(this)\n const {\n callback,\n capture,\n once,\n passive,\n signal,\n type,\n } = normalizeAddOptions(type0, callback0, options0)\n if (callback == null || signal?.aborted) {\n return\n }\n const list = ensureListenerList(listenerMap, type)\n\n // Find existing listener.\n const i = findIndexOfListener(list, callback, capture)\n if (i !== -1) {\n warnDuplicate(list.listeners[i], passive, once, signal)\n return\n }\n\n // Add the new listener.\n addListener(list, callback, capture, passive, once, signal)\n }\n\n /**\n * Remove an added event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param options Options.\n */\n removeEventListener(\n type: T,\n callback?: EventTarget.EventListener | null,\n options?: EventTarget.Options,\n ): void\n\n /**\n * Remove an added event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param options Options.\n */\n removeEventListener(\n type: string,\n callback?: EventTarget.FallbackEventListener,\n options?: EventTarget.Options,\n ): void\n\n /**\n * Remove an added event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param capture The capture flag.\n * @deprecated Use `{capture: boolean}` object instead of a boolean value.\n */\n removeEventListener(\n type: T,\n callback:\n | EventTarget.EventListener\n | null\n | undefined,\n capture: boolean,\n ): void\n\n /**\n * Remove an added event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param capture The capture flag.\n * @deprecated Use `{capture: boolean}` object instead of a boolean value.\n */\n removeEventListener(\n type: string,\n callback: EventTarget.FallbackEventListener,\n capture: boolean,\n ): void\n\n // Implementation\n removeEventListener(\n type0: T,\n callback0?: EventTarget.EventListener | null,\n options0?: boolean | EventTarget.Options,\n ): void {\n const listenerMap = $(this)\n const { callback, capture, type } = normalizeOptions(\n type0,\n callback0,\n options0,\n )\n const list = listenerMap[type]\n\n if (callback != null && list) {\n removeListener(list, callback, capture)\n }\n }\n\n /**\n * Dispatch an event.\n * @param event The `Event` object to dispatch.\n */\n dispatchEvent(\n event: EventTarget.EventData,\n ): boolean\n\n /**\n * Dispatch an event.\n * @param event The `Event` object to dispatch.\n */\n dispatchEvent(event: EventTarget.FallbackEvent): boolean\n\n // Implementation\n dispatchEvent(\n e:\n | EventTarget.EventData\n | EventTarget.FallbackEvent,\n ): boolean {\n const list = $(this)[String(e.type)]\n if (list == null) {\n return true\n }\n\n const event = e instanceof Event ? e : EventWrapper.wrap(e)\n const eventData = getEventInternalData(event, \"event\")\n if (eventData.dispatchFlag) {\n throw createInvalidStateError(\"This event has been in dispatching.\")\n }\n\n eventData.dispatchFlag = true\n eventData.target = eventData.currentTarget = this\n\n if (!eventData.stopPropagationFlag) {\n const { cow, listeners } = list\n\n // Set copy-on-write flag.\n list.cow = true\n\n // Call listeners.\n for (let i = 0; i < listeners.length; ++i) {\n const listener = listeners[i]\n\n // Skip if removed.\n if (isRemoved(listener)) {\n continue\n }\n\n // Remove this listener if has the `once` flag.\n if (isOnce(listener) && removeListenerAt(list, i, !cow)) {\n // Because this listener was removed, the next index is the\n // same as the current value.\n i -= 1\n }\n\n // Call this listener with the `passive` flag.\n eventData.inPassiveListenerFlag = isPassive(listener)\n invokeCallback(listener, this, event)\n eventData.inPassiveListenerFlag = false\n\n // Stop if the `event.stopImmediatePropagation()` method was called.\n if (eventData.stopImmediatePropagationFlag) {\n break\n }\n }\n\n // Restore copy-on-write flag.\n if (!cow) {\n list.cow = false\n }\n }\n\n eventData.target = null\n eventData.currentTarget = null\n eventData.stopImmediatePropagationFlag = false\n eventData.stopPropagationFlag = false\n eventData.dispatchFlag = false\n\n return !eventData.canceledFlag\n }\n}\n\nexport namespace EventTarget {\n /**\n * The event listener.\n */\n export type EventListener<\n TEventTarget extends EventTarget,\n TEvent extends Event\n > = CallbackFunction | CallbackObject\n\n /**\n * The event listener function.\n */\n export interface CallbackFunction<\n TEventTarget extends EventTarget,\n TEvent extends Event\n > {\n (this: TEventTarget, event: TEvent): void\n }\n\n /**\n * The event listener object.\n * @see https://dom.spec.whatwg.org/#callbackdef-eventlistener\n */\n export interface CallbackObject {\n handleEvent(event: TEvent): void\n }\n\n /**\n * The common options for both `addEventListener` and `removeEventListener` methods.\n * @see https://dom.spec.whatwg.org/#dictdef-eventlisteneroptions\n */\n export interface Options {\n capture?: boolean\n }\n\n /**\n * The options for the `addEventListener` methods.\n * @see https://dom.spec.whatwg.org/#dictdef-addeventlisteneroptions\n */\n export interface AddOptions extends Options {\n passive?: boolean\n once?: boolean\n signal?: AbortSignal | null | undefined\n }\n\n /**\n * The abort signal.\n * @see https://dom.spec.whatwg.org/#abortsignal\n */\n export interface AbortSignal extends EventTarget<{ abort: Event }> {\n readonly aborted: boolean\n onabort: CallbackFunction | null\n }\n\n /**\n * The event data to dispatch in strict mode.\n */\n export type EventData<\n TEventMap extends Record,\n TMode extends \"standard\" | \"strict\",\n TEventType extends string\n > = TMode extends \"strict\"\n ? IsValidEventMap extends true\n ? ExplicitType &\n Omit &\n Partial>\n : never\n : never\n\n /**\n * Define explicit `type` property if `T` is a string literal.\n * Otherwise, never.\n */\n export type ExplicitType = string extends T\n ? never\n : { readonly type: T }\n\n /**\n * The event listener type in standard mode.\n * Otherwise, never.\n */\n export type FallbackEventListener<\n TEventTarget extends EventTarget,\n TMode extends \"standard\" | \"strict\"\n > = TMode extends \"standard\"\n ? EventListener | null | undefined\n : never\n\n /**\n * The event type in standard mode.\n * Otherwise, never.\n */\n export type FallbackEvent<\n TMode extends \"standard\" | \"strict\"\n > = TMode extends \"standard\" ? Event : never\n\n /**\n * Check if given event map is valid.\n * It's valid if the keys of the event map are narrower than `string`.\n */\n export type IsValidEventMap = string extends keyof T ? false : true\n}\n\nexport { $ as getEventTargetInternalData }\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\n/**\n * Internal data for EventTarget\n */\ntype EventTargetInternalData = ListenerListMap\n\n/**\n * Internal data.\n */\nconst internalDataMap = new WeakMap()\n\n/**\n * Get private data.\n * @param target The event target object to get private data.\n * @param name The variable name to report.\n * @returns The private data of the event.\n */\nfunction $(target: any, name = \"this\"): EventTargetInternalData {\n const retv = internalDataMap.get(target)\n assertType(\n retv != null,\n \"'%s' must be an object that EventTarget constructor created, but got another one: %o\",\n name,\n target,\n )\n return retv\n}\n\n/**\n * Normalize options.\n * @param options The options to normalize.\n */\nfunction normalizeAddOptions(\n type: string,\n callback: EventTarget.EventListener | null | undefined,\n options: boolean | EventTarget.AddOptions | undefined,\n): {\n type: string\n callback: EventTarget.EventListener | undefined\n capture: boolean\n passive: boolean\n once: boolean\n signal: EventTarget.AbortSignal | undefined\n} {\n assertCallback(callback)\n\n if (typeof options === \"object\" && options !== null) {\n return {\n type: String(type),\n callback: callback ?? undefined,\n capture: Boolean(options.capture),\n passive: Boolean(options.passive),\n once: Boolean(options.once),\n signal: options.signal ?? undefined,\n }\n }\n\n return {\n type: String(type),\n callback: callback ?? undefined,\n capture: Boolean(options),\n passive: false,\n once: false,\n signal: undefined,\n }\n}\n\n/**\n * Normalize options.\n * @param options The options to normalize.\n */\nfunction normalizeOptions(\n type: string,\n callback: EventTarget.EventListener | null | undefined,\n options: boolean | EventTarget.Options | undefined,\n): {\n type: string\n callback: EventTarget.EventListener | undefined\n capture: boolean\n} {\n assertCallback(callback)\n\n if (typeof options === \"object\" && options !== null) {\n return {\n type: String(type),\n callback: callback ?? undefined,\n capture: Boolean(options.capture),\n }\n }\n\n return {\n type: String(type),\n callback: callback ?? undefined,\n capture: Boolean(options),\n }\n}\n\n/**\n * Assert the type of 'callback' argument.\n * @param callback The callback to check.\n */\nfunction assertCallback(callback: any): void {\n if (\n typeof callback === \"function\" ||\n (typeof callback === \"object\" &&\n callback !== null &&\n typeof callback.handleEvent === \"function\")\n ) {\n return\n }\n if (callback == null || typeof callback === \"object\") {\n InvalidEventListener.warn(callback)\n return\n }\n\n throw new TypeError(format(InvalidEventListener.message, [callback]))\n}\n\n/**\n * Print warning for duplicated.\n * @param listener The current listener that is duplicated.\n * @param passive The passive flag of the new duplicated listener.\n * @param once The once flag of the new duplicated listener.\n * @param signal The signal object of the new duplicated listener.\n */\nfunction warnDuplicate(\n listener: Listener,\n passive: boolean,\n once: boolean,\n signal: EventTarget.AbortSignal | undefined,\n): void {\n EventListenerWasDuplicated.warn(\n isCapture(listener) ? \"capture\" : \"bubble\",\n listener.callback,\n )\n\n if (isPassive(listener) !== passive) {\n OptionWasIgnored.warn(\"passive\")\n }\n if (isOnce(listener) !== once) {\n OptionWasIgnored.warn(\"once\")\n }\n if (listener.signal !== signal) {\n OptionWasIgnored.warn(\"signal\")\n }\n}\n\n// Set enumerable\nconst keys = Object.getOwnPropertyNames(EventTarget.prototype)\nfor (let i = 0; i < keys.length; ++i) {\n if (keys[i] === \"constructor\") {\n continue\n }\n Object.defineProperty(EventTarget.prototype, keys[i], { enumerable: true })\n}\n\n// Ensure `eventTarget instanceof window.EventTarget` is `true`.\nif (\n typeof Global !== \"undefined\" &&\n typeof Global.EventTarget !== \"undefined\"\n) {\n Object.setPrototypeOf(EventTarget.prototype, Global.EventTarget.prototype)\n}\n","import { Event } from \"./event\"\nimport { EventTarget, getEventTargetInternalData } from \"./event-target\"\nimport { addListener, ListenerList, removeListener } from \"./listener-list\"\nimport { ensureListenerList } from \"./listener-list-map\"\nimport { InvalidAttributeHandler } from \"./warnings\"\n\n/**\n * Get the current value of a given event attribute.\n * @param target The `EventTarget` object to get.\n * @param type The event type.\n */\nexport function getEventAttributeValue<\n TEventTarget extends EventTarget,\n TEvent extends Event\n>(\n target: TEventTarget,\n type: string,\n): EventTarget.CallbackFunction | null {\n const listMap = getEventTargetInternalData(target, \"target\")\n return listMap[type]?.attrCallback ?? null\n}\n\n/**\n * Set an event listener to a given event attribute.\n * @param target The `EventTarget` object to set.\n * @param type The event type.\n * @param callback The event listener.\n */\nexport function setEventAttributeValue(\n target: EventTarget,\n type: string,\n callback: EventTarget.CallbackFunction | null,\n): void {\n if (callback != null && typeof callback !== \"function\") {\n InvalidAttributeHandler.warn(callback)\n }\n\n if (\n typeof callback === \"function\" ||\n (typeof callback === \"object\" && callback !== null)\n ) {\n upsertEventAttributeListener(target, type, callback)\n } else {\n removeEventAttributeListener(target, type)\n }\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\n/**\n * Update or insert the given event attribute handler.\n * @param target The `EventTarget` object to set.\n * @param type The event type.\n * @param callback The event listener.\n */\nfunction upsertEventAttributeListener<\n TEventTarget extends EventTarget\n>(\n target: TEventTarget,\n type: string,\n callback: EventTarget.CallbackFunction,\n): void {\n const list = ensureListenerList(\n getEventTargetInternalData(target, \"target\"),\n String(type),\n )\n list.attrCallback = callback\n\n if (list.attrListener == null) {\n list.attrListener = addListener(\n list,\n defineEventAttributeCallback(list),\n false,\n false,\n false,\n undefined,\n )\n }\n}\n\n/**\n * Remove the given event attribute handler.\n * @param target The `EventTarget` object to remove.\n * @param type The event type.\n * @param callback The event listener.\n */\nfunction removeEventAttributeListener(\n target: EventTarget,\n type: string,\n): void {\n const listMap = getEventTargetInternalData(target, \"target\")\n const list = listMap[String(type)]\n if (list && list.attrListener) {\n removeListener(list, list.attrListener.callback, false)\n list.attrCallback = list.attrListener = undefined\n }\n}\n\n/**\n * Define the callback function for the given listener list object.\n * It calls `attrCallback` property if the property value is a function.\n * @param list The `ListenerList` object.\n */\nfunction defineEventAttributeCallback(\n list: ListenerList,\n): EventTarget.CallbackFunction {\n return function (event) {\n const callback = list.attrCallback\n if (typeof callback === \"function\") {\n callback.call(this, event)\n }\n }\n}\n","import { Event } from \"./event\"\nimport {\n getEventAttributeValue,\n setEventAttributeValue,\n} from \"./event-attribute-handler\"\nimport { EventTarget } from \"./event-target\"\n\n/**\n * Define an `EventTarget` class that has event attibutes.\n * @param types The types to define event attributes.\n * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly.\n */\nexport function defineCustomEventTarget<\n TEventMap extends Record,\n TMode extends \"standard\" | \"strict\" = \"standard\"\n>(\n ...types: (string & keyof TEventMap)[]\n): defineCustomEventTarget.CustomEventTargetConstructor {\n class CustomEventTarget extends EventTarget {}\n for (let i = 0; i < types.length; ++i) {\n defineEventAttribute(CustomEventTarget.prototype, types[i])\n }\n\n return CustomEventTarget as any\n}\n\nexport namespace defineCustomEventTarget {\n /**\n * The interface of CustomEventTarget constructor.\n */\n export type CustomEventTargetConstructor<\n TEventMap extends Record,\n TMode extends \"standard\" | \"strict\"\n > = {\n /**\n * Create a new instance.\n */\n new (): CustomEventTarget\n /**\n * prototype object.\n */\n prototype: CustomEventTarget\n }\n\n /**\n * The interface of CustomEventTarget.\n */\n export type CustomEventTarget<\n TEventMap extends Record,\n TMode extends \"standard\" | \"strict\"\n > = EventTarget &\n defineEventAttribute.EventAttributes\n}\n\n/**\n * Define an event attribute.\n * @param target The `EventTarget` object to define an event attribute.\n * @param type The event type to define.\n * @param _eventClass Unused, but to infer `Event` class type.\n * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly.\n */\nexport function defineEventAttribute<\n TEventTarget extends EventTarget,\n TEventType extends string,\n TEventConstrucor extends typeof Event\n>(\n target: TEventTarget,\n type: TEventType,\n _eventClass?: TEventConstrucor,\n): asserts target is TEventTarget &\n defineEventAttribute.EventAttributes<\n TEventTarget,\n Record>\n > {\n Object.defineProperty(target, `on${type}`, {\n get() {\n return getEventAttributeValue(this, type)\n },\n set(value) {\n setEventAttributeValue(this, type, value)\n },\n configurable: true,\n enumerable: true,\n })\n}\n\nexport namespace defineEventAttribute {\n /**\n * Definition of event attributes.\n */\n export type EventAttributes<\n TEventTarget extends EventTarget,\n TEventMap extends Record\n > = {\n [P in string &\n keyof TEventMap as `on${P}`]: EventTarget.CallbackFunction<\n TEventTarget,\n TEventMap[P]\n > | null\n }\n}\n"],"names":["internalDataMap","$","getEventInternalData","keys","getEventTargetInternalData"],"mappings":";;;;AAAA;;;;;;SAMgB,UAAU,CACtB,SAAkB,EAClB,OAAe,EACf,GAAG,IAAW;IAEd,IAAI,CAAC,SAAS,EAAE;QACZ,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;KAC7C;AACL,CAAC;AAED;;;;;SAKgB,MAAM,CAAC,OAAe,EAAE,IAAW;IAC/C,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACnE,CAAC;AAED;;;;SAIgB,WAAW,CAAC,CAAM;IAC9B,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,EAAE;QACrC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAA;KACnB;IACD,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AAC5C;;AC5BA,IAAI,mBAA6D,CAAA;AAEjE;;;;SAIgB,eAAe,CAC3B,KAA+C;IAE/C,UAAU,CACN,OAAO,KAAK,KAAK,UAAU,IAAI,KAAK,KAAK,SAAS,EAClD,gEAAgE,EAChE,KAAK,CACR,CAAA;IACD,mBAAmB,GAAG,KAAK,CAAA;AAC/B,CAAC;AASD;;;;SAIgB,WAAW,CAAC,UAAmB;IAC3C,IAAI;QACA,MAAM,KAAK,GACP,UAAU,YAAY,KAAK;cACrB,UAAU;cACV,IAAI,KAAK,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAA;;QAG5C,IAAI,mBAAmB,EAAE;YACrB,mBAAmB,CAAC,KAAK,CAAC,CAAA;YAC1B,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CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;KAC9D;IAED,OAAO,iBAAwB,CAAA;AACnC,CAAC;AA8BD;;;;;;;SAOgB,oBAAoB,CAKhC,MAAoB,EACpB,IAAgB,EAChB,WAA8B;IAM9B,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,EAAE;QACvC,GAAG;YACC,OAAO,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;SAC5C;QACD,GAAG,CAAC,KAAK;YACL,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;SAC5C;QACD,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,IAAI;KACnB,CAAC,CAAA;AACN;;;;;;;;;;;;"} \ No newline at end of file diff --git a/index.mjs b/index.mjs new file mode 100644 index 0000000..6b6f6cd --- /dev/null +++ b/index.mjs @@ -0,0 +1,1175 @@ +/** + * Assert a condition. + * @param condition The condition that it should satisfy. + * @param message The error message. + * @param args The arguments for replacing placeholders in the message. + */ +function assertType(condition, message, ...args) { + if (!condition) { + throw new TypeError(format(message, args)); + } +} +/** + * Convert a text and arguments to one string. + * @param message The formating text + * @param args The arguments. + */ +function format(message, args) { + let i = 0; + return message.replace(/%[os]/gu, () => anyToString(args[i++])); +} +/** + * Convert a value to a string representation. + * @param x The value to get the string representation. + */ +function anyToString(x) { + if (typeof x !== "object" || x === null) { + return String(x); + } + return Object.prototype.toString.call(x); +} + +let currentErrorHandler; +/** + * Set the error handler. + * @param value The error handler to set. + */ +function setErrorHandler(value) { + assertType(typeof value === "function" || value === undefined, "The error handler must be a function or undefined, but got %o.", value); + currentErrorHandler = value; +} +/** + * Print a error message. + * @param maybeError The error object. + */ +function reportError(maybeError) { + try { + const error = maybeError instanceof Error + ? maybeError + : new Error(anyToString(maybeError)); + // Call the user-defined error handler if exists. + if (currentErrorHandler) { + currentErrorHandler(error); + return; + } + // Dispatch an `error` event if this is on a browser. + if (typeof dispatchEvent === "function" && + typeof ErrorEvent === "function") { + dispatchEvent(new ErrorEvent("error", { error, message: error.message })); + } + // Emit an `uncaughtException` event if this is on Node.js. + //istanbul ignore else + else if (typeof process !== "undefined" && + typeof process.emit === "function") { + process.emit("uncaughtException", error); + return; + } + // Otherwise, print the error. + console.error(error); + } + catch (_a) { + // ignore. + } +} + +/** + * The global object. + */ +//istanbul ignore next +const Global = typeof window !== "undefined" + ? window + : typeof self !== "undefined" + ? self + : typeof global !== "undefined" + ? global + : typeof globalThis !== "undefined" + ? globalThis + : undefined; + +let currentWarnHandler; +/** + * Set the warning handler. + * @param value The warning handler to set. + */ +function setWarningHandler(value) { + assertType(typeof value === "function" || value === undefined, "The warning handler must be a function or undefined, but got %o.", value); + currentWarnHandler = value; +} +/** + * The warning information. + */ +class Warning { + constructor(code, message) { + this.code = code; + this.message = message; + } + /** + * Report this warning. + * @param args The arguments of the warning. + */ + warn(...args) { + var _a; + try { + // Call the user-defined warning handler if exists. + if (currentWarnHandler) { + currentWarnHandler({ ...this, args }); + return; + } + // Otherwise, print the warning. + const stack = ((_a = new Error().stack) !== null && _a !== void 0 ? _a : "").replace(/^(?:.+?\n){2}/gu, "\n"); + console.warn(this.message, ...args, stack); + } + catch (_b) { + // Ignore. + } + } +} + +const InitEventWasCalledWhileDispatching = new Warning("W01", "Unable to initialize event under dispatching."); +const FalsyWasAssignedToCancelBubble = new Warning("W02", "Assigning any falsy value to 'cancelBubble' property has no effect."); +const TruthyWasAssignedToReturnValue = new Warning("W03", "Assigning any truthy value to 'returnValue' property has no effect."); +const NonCancelableEventWasCanceled = new Warning("W04", "Unable to preventDefault on non-cancelable events."); +const CanceledInPassiveListener = new Warning("W05", "Unable to preventDefault inside passive event listener invocation."); +const EventListenerWasDuplicated = new Warning("W06", "An event listener wasn't added because it has been added already: %o, %o"); +const OptionWasIgnored = new Warning("W07", "The %o option value was abandoned because the event listener wasn't added as duplicated."); +const InvalidEventListener = new Warning("W08", "The 'callback' argument must be a function or an object that has 'handleEvent' method: %o"); +const InvalidAttributeHandler = new Warning("W09", "Event attribute handler must be a function: %o"); + +/*eslint-disable class-methods-use-this */ +/** + * An implementation of `Event` interface, that wraps a given event object. + * `EventTarget` shim can control the internal state of this `Event` objects. + * @see https://dom.spec.whatwg.org/#event + */ +class Event { + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + static get NONE() { + return NONE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + static get CAPTURING_PHASE() { + return CAPTURING_PHASE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + static get AT_TARGET() { + return AT_TARGET; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + static get BUBBLING_PHASE() { + return BUBBLING_PHASE; + } + /** + * Initialize this event instance. + * @param type The type of this event. + * @param eventInitDict Options to initialize. + * @see https://dom.spec.whatwg.org/#dom-event-event + */ + constructor(type, eventInitDict) { + Object.defineProperty(this, "isTrusted", { + value: false, + enumerable: true, + }); + const opts = eventInitDict !== null && eventInitDict !== void 0 ? eventInitDict : {}; + internalDataMap.set(this, { + type: String(type), + bubbles: Boolean(opts.bubbles), + cancelable: Boolean(opts.cancelable), + composed: Boolean(opts.composed), + target: null, + currentTarget: null, + stopPropagationFlag: false, + stopImmediatePropagationFlag: false, + canceledFlag: false, + inPassiveListenerFlag: false, + dispatchFlag: false, + timeStamp: Date.now(), + }); + } + /** + * The type of this event. + * @see https://dom.spec.whatwg.org/#dom-event-type + */ + get type() { + return $(this).type; + } + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-target + */ + get target() { + return $(this).target; + } + /** + * The event target of the current dispatching. + * @deprecated Use the `target` property instead. + * @see https://dom.spec.whatwg.org/#dom-event-srcelement + */ + get srcElement() { + return $(this).target; + } + /** + * The event target of the current dispatching. + * @see https://dom.spec.whatwg.org/#dom-event-currenttarget + */ + get currentTarget() { + return $(this).currentTarget; + } + /** + * The event target of the current dispatching. + * This doesn't support node tree. + * @see https://dom.spec.whatwg.org/#dom-event-composedpath + */ + composedPath() { + const currentTarget = $(this).currentTarget; + if (currentTarget) { + return [currentTarget]; + } + return []; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-none + */ + get NONE() { + return NONE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase + */ + get CAPTURING_PHASE() { + return CAPTURING_PHASE; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-at_target + */ + get AT_TARGET() { + return AT_TARGET; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase + */ + get BUBBLING_PHASE() { + return BUBBLING_PHASE; + } + /** + * The current event phase. + * @see https://dom.spec.whatwg.org/#dom-event-eventphase + */ + get eventPhase() { + return $(this).dispatchFlag ? 2 : 0; + } + /** + * Stop event bubbling. + * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value. + * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation + */ + stopPropagation() { + $(this).stopPropagationFlag = true; + } + /** + * `true` if event bubbling was stopped. + * @deprecated + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + get cancelBubble() { + return $(this).stopPropagationFlag; + } + /** + * Stop event bubbling if `true` is set. + * @deprecated Use the `stopPropagation()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble + */ + set cancelBubble(value) { + if (value) { + $(this).stopPropagationFlag = true; + } + else { + FalsyWasAssignedToCancelBubble.warn(); + } + } + /** + * Stop event bubbling and subsequent event listener callings. + * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation + */ + stopImmediatePropagation() { + const data = $(this); + data.stopPropagationFlag = data.stopImmediatePropagationFlag = true; + } + /** + * `true` if this event will bubble. + * @see https://dom.spec.whatwg.org/#dom-event-bubbles + */ + get bubbles() { + return $(this).bubbles; + } + /** + * `true` if this event can be canceled by the `preventDefault()` method. + * @see https://dom.spec.whatwg.org/#dom-event-cancelable + */ + get cancelable() { + return $(this).cancelable; + } + /** + * `true` if the default behavior will act. + * @deprecated Use the `defaultPrevented` proeprty instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + get returnValue() { + return !$(this).canceledFlag; + } + /** + * Cancel the default behavior if `false` is set. + * @deprecated Use the `preventDefault()` method instead. + * @see https://dom.spec.whatwg.org/#dom-event-returnvalue + */ + set returnValue(value) { + if (!value) { + setCancelFlag($(this)); + } + else { + TruthyWasAssignedToReturnValue.warn(); + } + } + /** + * Cancel the default behavior. + * @see https://dom.spec.whatwg.org/#dom-event-preventdefault + */ + preventDefault() { + setCancelFlag($(this)); + } + /** + * `true` if the default behavior was canceled. + * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented + */ + get defaultPrevented() { + return $(this).canceledFlag; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-composed + */ + get composed() { + return $(this).composed; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-istrusted + */ + //istanbul ignore next + get isTrusted() { + return false; + } + /** + * @see https://dom.spec.whatwg.org/#dom-event-timestamp + */ + get timeStamp() { + return $(this).timeStamp; + } + /** + * @deprecated Don't use this method. The constructor did initialization. + */ + initEvent(type, bubbles = false, cancelable = false) { + const data = $(this); + if (data.dispatchFlag) { + InitEventWasCalledWhileDispatching.warn(); + return; + } + internalDataMap.set(this, { + ...data, + type: String(type), + bubbles: Boolean(bubbles), + cancelable: Boolean(cancelable), + target: null, + currentTarget: null, + stopPropagationFlag: false, + stopImmediatePropagationFlag: false, + canceledFlag: false, + }); + } +} +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ +const NONE = 0; +const CAPTURING_PHASE = 1; +const AT_TARGET = 2; +const BUBBLING_PHASE = 3; +/** + * Private data for event wrappers. + */ +const internalDataMap = new WeakMap(); +/** + * Get private data. + * @param event The event object to get private data. + * @param name The variable name to report. + * @returns The private data of the event. + */ +function $(event, name = "this") { + const retv = internalDataMap.get(event); + assertType(retv != null, "'%s' must be an object that Event constructor created, but got another one: %o", name, event); + return retv; +} +/** + * https://dom.spec.whatwg.org/#set-the-canceled-flag + * @param data private data. + */ +function setCancelFlag(data) { + if (data.inPassiveListenerFlag) { + CanceledInPassiveListener.warn(); + return; + } + if (!data.cancelable) { + NonCancelableEventWasCanceled.warn(); + return; + } + data.canceledFlag = true; +} +// Set enumerable +Object.defineProperty(Event, "NONE", { enumerable: true }); +Object.defineProperty(Event, "CAPTURING_PHASE", { enumerable: true }); +Object.defineProperty(Event, "AT_TARGET", { enumerable: true }); +Object.defineProperty(Event, "BUBBLING_PHASE", { enumerable: true }); +const keys = Object.getOwnPropertyNames(Event.prototype); +for (let i = 0; i < keys.length; ++i) { + if (keys[i] === "constructor") { + continue; + } + Object.defineProperty(Event.prototype, keys[i], { enumerable: true }); +} +// Ensure `event instanceof window.Event` is `true`. +if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") { + Object.setPrototypeOf(Event.prototype, Global.Event.prototype); +} + +/** + * Create a new InvalidStateError instance. + * @param message The error message. + */ +function createInvalidStateError(message) { + if (Global.DOMException) { + return new Global.DOMException(message, "InvalidStateError"); + } + if (DOMException == null) { + DOMException = class DOMException extends Error { + constructor(msg) { + super(msg); + if (Error.captureStackTrace) { + Error.captureStackTrace(this, DOMException); + } + } + // eslint-disable-next-line class-methods-use-this + get code() { + return 11; + } + // eslint-disable-next-line class-methods-use-this + get name() { + return "InvalidStateError"; + } + }; + Object.defineProperties(DOMException.prototype, { + code: { enumerable: true }, + name: { enumerable: true }, + }); + defineErrorCodeProperties(DOMException); + defineErrorCodeProperties(DOMException.prototype); + } + return new DOMException(message); +} +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ +let DOMException; +const ErrorCodeMap = { + INDEX_SIZE_ERR: 1, + DOMSTRING_SIZE_ERR: 2, + HIERARCHY_REQUEST_ERR: 3, + WRONG_DOCUMENT_ERR: 4, + INVALID_CHARACTER_ERR: 5, + NO_DATA_ALLOWED_ERR: 6, + NO_MODIFICATION_ALLOWED_ERR: 7, + NOT_FOUND_ERR: 8, + NOT_SUPPORTED_ERR: 9, + INUSE_ATTRIBUTE_ERR: 10, + INVALID_STATE_ERR: 11, + SYNTAX_ERR: 12, + INVALID_MODIFICATION_ERR: 13, + NAMESPACE_ERR: 14, + INVALID_ACCESS_ERR: 15, + VALIDATION_ERR: 16, + TYPE_MISMATCH_ERR: 17, + SECURITY_ERR: 18, + NETWORK_ERR: 19, + ABORT_ERR: 20, + URL_MISMATCH_ERR: 21, + QUOTA_EXCEEDED_ERR: 22, + TIMEOUT_ERR: 23, + INVALID_NODE_TYPE_ERR: 24, + DATA_CLONE_ERR: 25, +}; +function defineErrorCodeProperties(obj) { + const keys = Object.keys(ErrorCodeMap); + for (let i = 0; i < keys.length; ++i) { + const key = keys[i]; + const value = ErrorCodeMap[key]; + Object.defineProperty(obj, key, { + get() { + return value; + }, + configurable: true, + enumerable: true, + }); + } +} + +/** + * An implementation of `Event` interface, that wraps a given event object. + * This class controls the internal state of `Event`. + * @see https://dom.spec.whatwg.org/#interface-event + */ +class EventWrapper extends Event { + /** + * Wrap a given event object to control states. + * @param event The event-like object to wrap. + */ + static wrap(event) { + return new (getWrapperClassOf(event))(event); + } + constructor(event) { + super(event.type, { + bubbles: event.bubbles, + cancelable: event.cancelable, + composed: event.composed, + }); + if (event.cancelBubble) { + super.stopPropagation(); + } + if (event.defaultPrevented) { + super.preventDefault(); + } + internalDataMap$1.set(this, { original: event }); + // Define accessors + const keys = Object.keys(event); + for (let i = 0; i < keys.length; ++i) { + const key = keys[i]; + if (!(key in this)) { + Object.defineProperty(this, key, defineRedirectDescriptor(event, key)); + } + } + } + stopPropagation() { + super.stopPropagation(); + const { original } = $$1(this); + if ("stopPropagation" in original) { + original.stopPropagation(); + } + } + get cancelBubble() { + return super.cancelBubble; + } + set cancelBubble(value) { + super.cancelBubble = value; + const { original } = $$1(this); + if ("cancelBubble" in original) { + original.cancelBubble = value; + } + } + stopImmediatePropagation() { + super.stopImmediatePropagation(); + const { original } = $$1(this); + if ("stopImmediatePropagation" in original) { + original.stopImmediatePropagation(); + } + } + get returnValue() { + return super.returnValue; + } + set returnValue(value) { + super.returnValue = value; + const { original } = $$1(this); + if ("returnValue" in original) { + original.returnValue = value; + } + } + preventDefault() { + super.preventDefault(); + const { original } = $$1(this); + if ("preventDefault" in original) { + original.preventDefault(); + } + } + get timeStamp() { + const { original } = $$1(this); + if ("timeStamp" in original) { + return original.timeStamp; + } + return super.timeStamp; + } +} +/** + * Private data for event wrappers. + */ +const internalDataMap$1 = new WeakMap(); +/** + * Get private data. + * @param event The event object to get private data. + * @returns The private data of the event. + */ +function $$1(event) { + const retv = internalDataMap$1.get(event); + assertType(retv != null, "'this' is expected an Event object, but got", event); + return retv; +} +/** + * Cache for wrapper classes. + * @type {WeakMap} + * @private + */ +const wrapperClassCache = new WeakMap(); +// Make association for wrappers. +wrapperClassCache.set(Object.prototype, EventWrapper); +if (typeof Global !== "undefined" && typeof Global.Event !== "undefined") { + wrapperClassCache.set(Global.Event.prototype, EventWrapper); +} +/** + * Get the wrapper class of a given prototype. + * @param originalEvent The event object to wrap. + */ +function getWrapperClassOf(originalEvent) { + const prototype = Object.getPrototypeOf(originalEvent); + if (prototype == null) { + return EventWrapper; + } + let wrapper = wrapperClassCache.get(prototype); + if (wrapper == null) { + wrapper = defineWrapper(getWrapperClassOf(prototype), prototype); + wrapperClassCache.set(prototype, wrapper); + } + return wrapper; +} +/** + * Define new wrapper class. + * @param BaseEventWrapper The base wrapper class. + * @param originalPrototype The prototype of the original event. + */ +function defineWrapper(BaseEventWrapper, originalPrototype) { + class CustomEventWrapper extends BaseEventWrapper { + } + const keys = Object.keys(originalPrototype); + for (let i = 0; i < keys.length; ++i) { + Object.defineProperty(CustomEventWrapper.prototype, keys[i], defineRedirectDescriptor(originalPrototype, keys[i])); + } + return CustomEventWrapper; +} +/** + * Get the property descriptor to redirect a given property. + */ +function defineRedirectDescriptor(obj, key) { + const d = Object.getOwnPropertyDescriptor(obj, key); + return { + get() { + const original = $$1(this).original; + const value = original[key]; + if (typeof value === "function") { + return value.bind(original); + } + return value; + }, + set(value) { + const original = $$1(this).original; + original[key] = value; + }, + configurable: d.configurable, + enumerable: d.enumerable, + }; +} + +/** + * Create a new listener. + * @param callback The callback function. + * @param capture The capture flag. + * @param passive The passive flag. + * @param once The once flag. + * @param signal The abort signal. + * @param signalListener The abort event listener for the abort signal. + */ +function createListener(callback, capture, passive, once, signal, signalListener) { + return { + callback, + flags: (capture ? 1 /* Capture */ : 0) | + (passive ? 2 /* Passive */ : 0) | + (once ? 4 /* Once */ : 0), + signal, + signalListener, + }; +} +/** + * Set the `removed` flag to the given listener. + * @param listener The listener to check. + */ +function setRemoved(listener) { + listener.flags |= 8 /* Removed */; +} +/** + * Check if the given listener has the `capture` flag or not. + * @param listener The listener to check. + */ +function isCapture(listener) { + return (listener.flags & 1 /* Capture */) === 1 /* Capture */; +} +/** + * Check if the given listener has the `passive` flag or not. + * @param listener The listener to check. + */ +function isPassive(listener) { + return (listener.flags & 2 /* Passive */) === 2 /* Passive */; +} +/** + * Check if the given listener has the `once` flag or not. + * @param listener The listener to check. + */ +function isOnce(listener) { + return (listener.flags & 4 /* Once */) === 4 /* Once */; +} +/** + * Check if the given listener has the `removed` flag or not. + * @param listener The listener to check. + */ +function isRemoved(listener) { + return (listener.flags & 8 /* Removed */) === 8 /* Removed */; +} +/** + * Call an event listener. + * @param listener The listener to call. + * @param target The event target object for `thisArg`. + * @param event The event object for the first argument. + * @param attribute `true` if this callback is an event attribute handler. + */ +function invokeCallback({ callback }, target, event) { + try { + if (typeof callback === "function") { + callback.call(target, event); + } + else if (typeof callback.handleEvent === "function") { + callback.handleEvent(event); + } + } + catch (thrownError) { + reportError(thrownError); + } +} + +/** + * Find the index of given listener. + * This returns `-1` if not found. + * @param list The listener list. + * @param callback The callback function to find. + * @param capture The capture flag to find. + */ +function findIndexOfListener({ listeners }, callback, capture) { + for (let i = 0; i < listeners.length; ++i) { + if (listeners[i].callback === callback && + isCapture(listeners[i]) === capture) { + return i; + } + } + return -1; +} +/** + * Add the given listener. + * Does copy-on-write if needed. + * @param list The listener list. + * @param callback The callback function. + * @param capture The capture flag. + * @param passive The passive flag. + * @param once The once flag. + * @param signal The abort signal. + */ +function addListener(list, callback, capture, passive, once, signal) { + let signalListener; + if (signal) { + signalListener = removeListener.bind(null, list, callback, capture); + signal.addEventListener("abort", signalListener); + } + const listener = createListener(callback, capture, passive, once, signal, signalListener); + if (list.cow) { + list.cow = false; + list.listeners = [...list.listeners, listener]; + } + else { + list.listeners.push(listener); + } + return listener; +} +/** + * Remove a listener. + * @param list The listener list. + * @param callback The callback function to find. + * @param capture The capture flag to find. + * @returns `true` if it mutated the list directly. + */ +function removeListener(list, callback, capture) { + const index = findIndexOfListener(list, callback, capture); + if (index !== -1) { + return removeListenerAt(list, index); + } + return false; +} +/** + * Remove a listener. + * @param list The listener list. + * @param index The index of the target listener. + * @param disableCow Disable copy-on-write if true. + * @returns `true` if it mutated the `listeners` array directly. + */ +function removeListenerAt(list, index, disableCow = false) { + const listener = list.listeners[index]; + // Set the removed flag. + setRemoved(listener); + // Dispose the abort signal listener if exists. + if (listener.signal) { + listener.signal.removeEventListener("abort", listener.signalListener); + } + // Remove it from the array. + if (list.cow && !disableCow) { + list.cow = false; + list.listeners = list.listeners.filter((_, i) => i !== index); + return false; + } + list.listeners.splice(index, 1); + return true; +} + +/** + * Create a new `ListenerListMap` object. + */ +function createListenerListMap() { + return Object.create(null); +} +/** + * Get the listener list of the given type. + * If the listener list has not been initialized, initialize and return it. + * @param listenerMap The listener list map. + * @param type The event type to get. + */ +function ensureListenerList(listenerMap, type) { + var _a; + return ((_a = listenerMap[type]) !== null && _a !== void 0 ? _a : (listenerMap[type] = { + attrCallback: undefined, + attrListener: undefined, + cow: false, + listeners: [], + })); +} + +/** + * An implementation of the `EventTarget` interface. + * @see https://dom.spec.whatwg.org/#eventtarget + */ +class EventTarget { + /** + * Initialize this instance. + */ + constructor() { + internalDataMap$2.set(this, createListenerListMap()); + } + // Implementation + addEventListener(type0, callback0, options0) { + const listenerMap = $$2(this); + const { callback, capture, once, passive, signal, type, } = normalizeAddOptions(type0, callback0, options0); + if (callback == null || (signal === null || signal === void 0 ? void 0 : signal.aborted)) { + return; + } + const list = ensureListenerList(listenerMap, type); + // Find existing listener. + const i = findIndexOfListener(list, callback, capture); + if (i !== -1) { + warnDuplicate(list.listeners[i], passive, once, signal); + return; + } + // Add the new listener. + addListener(list, callback, capture, passive, once, signal); + } + // Implementation + removeEventListener(type0, callback0, options0) { + const listenerMap = $$2(this); + const { callback, capture, type } = normalizeOptions(type0, callback0, options0); + const list = listenerMap[type]; + if (callback != null && list) { + removeListener(list, callback, capture); + } + } + // Implementation + dispatchEvent(e) { + const list = $$2(this)[String(e.type)]; + if (list == null) { + return true; + } + const event = e instanceof Event ? e : EventWrapper.wrap(e); + const eventData = $(event, "event"); + if (eventData.dispatchFlag) { + throw createInvalidStateError("This event has been in dispatching."); + } + eventData.dispatchFlag = true; + eventData.target = eventData.currentTarget = this; + if (!eventData.stopPropagationFlag) { + const { cow, listeners } = list; + // Set copy-on-write flag. + list.cow = true; + // Call listeners. + for (let i = 0; i < listeners.length; ++i) { + const listener = listeners[i]; + // Skip if removed. + if (isRemoved(listener)) { + continue; + } + // Remove this listener if has the `once` flag. + if (isOnce(listener) && removeListenerAt(list, i, !cow)) { + // Because this listener was removed, the next index is the + // same as the current value. + i -= 1; + } + // Call this listener with the `passive` flag. + eventData.inPassiveListenerFlag = isPassive(listener); + invokeCallback(listener, this, event); + eventData.inPassiveListenerFlag = false; + // Stop if the `event.stopImmediatePropagation()` method was called. + if (eventData.stopImmediatePropagationFlag) { + break; + } + } + // Restore copy-on-write flag. + if (!cow) { + list.cow = false; + } + } + eventData.target = null; + eventData.currentTarget = null; + eventData.stopImmediatePropagationFlag = false; + eventData.stopPropagationFlag = false; + eventData.dispatchFlag = false; + return !eventData.canceledFlag; + } +} +/** + * Internal data. + */ +const internalDataMap$2 = new WeakMap(); +/** + * Get private data. + * @param target The event target object to get private data. + * @param name The variable name to report. + * @returns The private data of the event. + */ +function $$2(target, name = "this") { + const retv = internalDataMap$2.get(target); + assertType(retv != null, "'%s' must be an object that EventTarget constructor created, but got another one: %o", name, target); + return retv; +} +/** + * Normalize options. + * @param options The options to normalize. + */ +function normalizeAddOptions(type, callback, options) { + var _a; + assertCallback(callback); + if (typeof options === "object" && options !== null) { + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options.capture), + passive: Boolean(options.passive), + once: Boolean(options.once), + signal: (_a = options.signal) !== null && _a !== void 0 ? _a : undefined, + }; + } + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options), + passive: false, + once: false, + signal: undefined, + }; +} +/** + * Normalize options. + * @param options The options to normalize. + */ +function normalizeOptions(type, callback, options) { + assertCallback(callback); + if (typeof options === "object" && options !== null) { + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options.capture), + }; + } + return { + type: String(type), + callback: callback !== null && callback !== void 0 ? callback : undefined, + capture: Boolean(options), + }; +} +/** + * Assert the type of 'callback' argument. + * @param callback The callback to check. + */ +function assertCallback(callback) { + if (typeof callback === "function" || + (typeof callback === "object" && + callback !== null && + typeof callback.handleEvent === "function")) { + return; + } + if (callback == null || typeof callback === "object") { + InvalidEventListener.warn(callback); + return; + } + throw new TypeError(format(InvalidEventListener.message, [callback])); +} +/** + * Print warning for duplicated. + * @param listener The current listener that is duplicated. + * @param passive The passive flag of the new duplicated listener. + * @param once The once flag of the new duplicated listener. + * @param signal The signal object of the new duplicated listener. + */ +function warnDuplicate(listener, passive, once, signal) { + EventListenerWasDuplicated.warn(isCapture(listener) ? "capture" : "bubble", listener.callback); + if (isPassive(listener) !== passive) { + OptionWasIgnored.warn("passive"); + } + if (isOnce(listener) !== once) { + OptionWasIgnored.warn("once"); + } + if (listener.signal !== signal) { + OptionWasIgnored.warn("signal"); + } +} +// Set enumerable +const keys$1 = Object.getOwnPropertyNames(EventTarget.prototype); +for (let i = 0; i < keys$1.length; ++i) { + if (keys$1[i] === "constructor") { + continue; + } + Object.defineProperty(EventTarget.prototype, keys$1[i], { enumerable: true }); +} +// Ensure `eventTarget instanceof window.EventTarget` is `true`. +if (typeof Global !== "undefined" && + typeof Global.EventTarget !== "undefined") { + Object.setPrototypeOf(EventTarget.prototype, Global.EventTarget.prototype); +} + +/** + * Get the current value of a given event attribute. + * @param target The `EventTarget` object to get. + * @param type The event type. + */ +function getEventAttributeValue(target, type) { + var _a, _b; + const listMap = $$2(target, "target"); + return (_b = (_a = listMap[type]) === null || _a === void 0 ? void 0 : _a.attrCallback) !== null && _b !== void 0 ? _b : null; +} +/** + * Set an event listener to a given event attribute. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ +function setEventAttributeValue(target, type, callback) { + if (callback != null && typeof callback !== "function") { + InvalidAttributeHandler.warn(callback); + } + if (typeof callback === "function" || + (typeof callback === "object" && callback !== null)) { + upsertEventAttributeListener(target, type, callback); + } + else { + removeEventAttributeListener(target, type); + } +} +//------------------------------------------------------------------------------ +// Helpers +//------------------------------------------------------------------------------ +/** + * Update or insert the given event attribute handler. + * @param target The `EventTarget` object to set. + * @param type The event type. + * @param callback The event listener. + */ +function upsertEventAttributeListener(target, type, callback) { + const list = ensureListenerList($$2(target, "target"), String(type)); + list.attrCallback = callback; + if (list.attrListener == null) { + list.attrListener = addListener(list, defineEventAttributeCallback(list), false, false, false, undefined); + } +} +/** + * Remove the given event attribute handler. + * @param target The `EventTarget` object to remove. + * @param type The event type. + * @param callback The event listener. + */ +function removeEventAttributeListener(target, type) { + const listMap = $$2(target, "target"); + const list = listMap[String(type)]; + if (list && list.attrListener) { + removeListener(list, list.attrListener.callback, false); + list.attrCallback = list.attrListener = undefined; + } +} +/** + * Define the callback function for the given listener list object. + * It calls `attrCallback` property if the property value is a function. + * @param list The `ListenerList` object. + */ +function defineEventAttributeCallback(list) { + return function (event) { + const callback = list.attrCallback; + if (typeof callback === "function") { + callback.call(this, event); + } + }; +} + +/** + * Define an `EventTarget` class that has event attibutes. + * @param types The types to define event attributes. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ +function defineCustomEventTarget(...types) { + class CustomEventTarget extends EventTarget { + } + for (let i = 0; i < types.length; ++i) { + defineEventAttribute(CustomEventTarget.prototype, types[i]); + } + return CustomEventTarget; +} +/** + * Define an event attribute. + * @param target The `EventTarget` object to define an event attribute. + * @param type The event type to define. + * @param _eventClass Unused, but to infer `Event` class type. + * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly. + */ +function defineEventAttribute(target, type, _eventClass) { + Object.defineProperty(target, `on${type}`, { + get() { + return getEventAttributeValue(this, type); + }, + set(value) { + setEventAttributeValue(this, type, value); + }, + configurable: true, + enumerable: true, + }); +} + +export default EventTarget; +export { Event, EventTarget, defineCustomEventTarget, defineEventAttribute, getEventAttributeValue, setErrorHandler, setEventAttributeValue, setWarningHandler }; +//# sourceMappingURL=index.mjs.map diff --git a/index.mjs.map b/index.mjs.map new file mode 100644 index 0000000..9b303e1 --- /dev/null +++ b/index.mjs.map @@ -0,0 +1 @@ +{"version":3,"file":"index.mjs","sources":["../src/lib/misc.ts","../src/lib/error-handler.ts","../src/lib/global.ts","../src/lib/warning-handler.ts","../src/lib/warnings.ts","../src/lib/event.ts","../src/lib/dom-exception.ts","../src/lib/event-wrapper.ts","../src/lib/listener.ts","../src/lib/listener-list.ts","../src/lib/listener-list-map.ts","../src/lib/event-target.ts","../src/lib/event-attribute-handler.ts","../src/lib/legacy.ts"],"sourcesContent":["/**\n * Assert a condition.\n * @param condition The condition that it should satisfy.\n * @param message The error message.\n * @param args The arguments for replacing placeholders in the message.\n */\nexport function assertType(\n condition: boolean,\n message: string,\n ...args: any[]\n): asserts condition {\n if (!condition) {\n throw new TypeError(format(message, args))\n }\n}\n\n/**\n * Convert a text and arguments to one string.\n * @param message The formating text\n * @param args The arguments.\n */\nexport function format(message: string, args: any[]): string {\n let i = 0\n return message.replace(/%[os]/gu, () => anyToString(args[i++]))\n}\n\n/**\n * Convert a value to a string representation.\n * @param x The value to get the string representation.\n */\nexport function anyToString(x: any): string {\n if (typeof x !== \"object\" || x === null) {\n return String(x)\n }\n return Object.prototype.toString.call(x)\n}\n","import { anyToString, assertType } from \"./misc\"\n\ndeclare const console: any\ndeclare const dispatchEvent: any\ndeclare const ErrorEvent: any\ndeclare const process: any\n\nlet currentErrorHandler: setErrorHandler.ErrorHandler | undefined\n\n/**\n * Set the error handler.\n * @param value The error handler to set.\n */\nexport function setErrorHandler(\n value: setErrorHandler.ErrorHandler | undefined,\n): void {\n assertType(\n typeof value === \"function\" || value === undefined,\n \"The error handler must be a function or undefined, but got %o.\",\n value,\n )\n currentErrorHandler = value\n}\nexport namespace setErrorHandler {\n /**\n * The error handler.\n * @param error The thrown error object.\n */\n export type ErrorHandler = (error: Error) => void\n}\n\n/**\n * Print a error message.\n * @param maybeError The error object.\n */\nexport function reportError(maybeError: unknown): void {\n try {\n const error =\n maybeError instanceof Error\n ? maybeError\n : new Error(anyToString(maybeError))\n\n // Call the user-defined error handler if exists.\n if (currentErrorHandler) {\n currentErrorHandler(error)\n return\n }\n\n // Dispatch an `error` event if this is on a browser.\n if (\n typeof dispatchEvent === \"function\" &&\n typeof ErrorEvent === \"function\"\n ) {\n dispatchEvent(\n new ErrorEvent(\"error\", { error, message: error.message }),\n )\n }\n\n // Emit an `uncaughtException` event if this is on Node.js.\n //istanbul ignore else\n else if (\n typeof process !== \"undefined\" &&\n typeof process.emit === \"function\"\n ) {\n process.emit(\"uncaughtException\", error)\n return\n }\n\n // Otherwise, print the error.\n console.error(error)\n } catch {\n // ignore.\n }\n}\n","declare const globalThis: any\ndeclare const window: any\ndeclare const self: any\ndeclare const global: any\n\n/**\n * The global object.\n */\n//istanbul ignore next\nexport const Global: any =\n typeof window !== \"undefined\"\n ? window\n : typeof self !== \"undefined\"\n ? self\n : typeof global !== \"undefined\"\n ? global\n : typeof globalThis !== \"undefined\"\n ? globalThis\n : undefined\n","import { assertType } from \"./misc\"\n\ndeclare const console: any\n\nlet currentWarnHandler: setWarningHandler.WarningHandler | undefined\n\n/**\n * Set the warning handler.\n * @param value The warning handler to set.\n */\nexport function setWarningHandler(\n value: setWarningHandler.WarningHandler | undefined,\n): void {\n assertType(\n typeof value === \"function\" || value === undefined,\n \"The warning handler must be a function or undefined, but got %o.\",\n value,\n )\n currentWarnHandler = value\n}\nexport namespace setWarningHandler {\n /**\n * The warning information.\n */\n export interface Warning {\n /**\n * The code of this warning.\n */\n code: string\n /**\n * The message in English.\n */\n message: string\n /**\n * The arguments for replacing placeholders in the text.\n */\n args: any[]\n }\n\n /**\n * The warning handler.\n * @param warning The warning.\n */\n export type WarningHandler = (warning: Warning) => void\n}\n\n/**\n * The warning information.\n */\nexport class Warning {\n readonly code: string\n readonly message: string\n\n constructor(code: string, message: string) {\n this.code = code\n this.message = message\n }\n\n /**\n * Report this warning.\n * @param args The arguments of the warning.\n */\n warn(...args: TArgs): void {\n try {\n // Call the user-defined warning handler if exists.\n if (currentWarnHandler) {\n currentWarnHandler({ ...this, args })\n return\n }\n\n // Otherwise, print the warning.\n const stack = (new Error().stack ?? \"\").replace(\n /^(?:.+?\\n){2}/gu,\n \"\\n\",\n )\n console.warn(this.message, ...args, stack)\n } catch {\n // Ignore.\n }\n }\n}\n","import { EventTarget } from \"./event-target\" // Used as only type, so no circular.\nimport { Warning } from \"./warning-handler\"\n\nexport const InitEventWasCalledWhileDispatching = new Warning<[]>(\n \"W01\",\n \"Unable to initialize event under dispatching.\",\n)\n\nexport const FalsyWasAssignedToCancelBubble = new Warning<[]>(\n \"W02\",\n \"Assigning any falsy value to 'cancelBubble' property has no effect.\",\n)\n\nexport const TruthyWasAssignedToReturnValue = new Warning<[]>(\n \"W03\",\n \"Assigning any truthy value to 'returnValue' property has no effect.\",\n)\n\nexport const NonCancelableEventWasCanceled = new Warning<[]>(\n \"W04\",\n \"Unable to preventDefault on non-cancelable events.\",\n)\n\nexport const CanceledInPassiveListener = new Warning<[]>(\n \"W05\",\n \"Unable to preventDefault inside passive event listener invocation.\",\n)\n\nexport const EventListenerWasDuplicated = new Warning<\n [type: \"bubble\" | \"capture\", callback: EventTarget.EventListener]\n>(\n \"W06\",\n \"An event listener wasn't added because it has been added already: %o, %o\",\n)\n\nexport const OptionWasIgnored = new Warning<\n [name: \"passive\" | \"once\" | \"signal\"]\n>(\n \"W07\",\n \"The %o option value was abandoned because the event listener wasn't added as duplicated.\",\n)\n\nexport const InvalidEventListener = new Warning<\n [callback: EventTarget.EventListener | {} | null | undefined]\n>(\n \"W08\",\n \"The 'callback' argument must be a function or an object that has 'handleEvent' method: %o\",\n)\n\nexport const InvalidAttributeHandler = new Warning<\n [callback: EventTarget.EventListener | {}]\n>(\"W09\", \"Event attribute handler must be a function: %o\")\n","import { EventTarget } from \"./event-target\" // Used as only type, so no circular.\nimport { Global } from \"./global\"\nimport { assertType } from \"./misc\"\nimport {\n CanceledInPassiveListener,\n FalsyWasAssignedToCancelBubble,\n InitEventWasCalledWhileDispatching,\n NonCancelableEventWasCanceled,\n TruthyWasAssignedToReturnValue,\n} from \"./warnings\"\n\n/*eslint-disable class-methods-use-this */\n\n/**\n * An implementation of `Event` interface, that wraps a given event object.\n * `EventTarget` shim can control the internal state of this `Event` objects.\n * @see https://dom.spec.whatwg.org/#event\n */\nexport class Event {\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-none\n */\n static get NONE(): number {\n return NONE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase\n */\n static get CAPTURING_PHASE(): number {\n return CAPTURING_PHASE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-at_target\n */\n static get AT_TARGET(): number {\n return AT_TARGET\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase\n */\n static get BUBBLING_PHASE(): number {\n return BUBBLING_PHASE\n }\n\n /**\n * Initialize this event instance.\n * @param type The type of this event.\n * @param eventInitDict Options to initialize.\n * @see https://dom.spec.whatwg.org/#dom-event-event\n */\n constructor(type: TEventType, eventInitDict?: Event.EventInit) {\n Object.defineProperty(this, \"isTrusted\", {\n value: false,\n enumerable: true,\n })\n\n const opts = eventInitDict ?? {}\n internalDataMap.set(this, {\n type: String(type),\n bubbles: Boolean(opts.bubbles),\n cancelable: Boolean(opts.cancelable),\n composed: Boolean(opts.composed),\n target: null,\n currentTarget: null,\n stopPropagationFlag: false,\n stopImmediatePropagationFlag: false,\n canceledFlag: false,\n inPassiveListenerFlag: false,\n dispatchFlag: false,\n timeStamp: Date.now(),\n })\n }\n\n /**\n * The type of this event.\n * @see https://dom.spec.whatwg.org/#dom-event-type\n */\n get type(): TEventType {\n return $(this).type as TEventType\n }\n\n /**\n * The event target of the current dispatching.\n * @see https://dom.spec.whatwg.org/#dom-event-target\n */\n get target(): EventTarget | null {\n return $(this).target\n }\n\n /**\n * The event target of the current dispatching.\n * @deprecated Use the `target` property instead.\n * @see https://dom.spec.whatwg.org/#dom-event-srcelement\n */\n get srcElement(): EventTarget | null {\n return $(this).target\n }\n\n /**\n * The event target of the current dispatching.\n * @see https://dom.spec.whatwg.org/#dom-event-currenttarget\n */\n get currentTarget(): EventTarget | null {\n return $(this).currentTarget\n }\n\n /**\n * The event target of the current dispatching.\n * This doesn't support node tree.\n * @see https://dom.spec.whatwg.org/#dom-event-composedpath\n */\n composedPath(): EventTarget[] {\n const currentTarget = $(this).currentTarget\n if (currentTarget) {\n return [currentTarget]\n }\n return []\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-none\n */\n get NONE(): number {\n return NONE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-capturing_phase\n */\n get CAPTURING_PHASE(): number {\n return CAPTURING_PHASE\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-at_target\n */\n get AT_TARGET(): number {\n return AT_TARGET\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-bubbling_phase\n */\n get BUBBLING_PHASE(): number {\n return BUBBLING_PHASE\n }\n\n /**\n * The current event phase.\n * @see https://dom.spec.whatwg.org/#dom-event-eventphase\n */\n get eventPhase(): number {\n return $(this).dispatchFlag ? 2 : 0\n }\n\n /**\n * Stop event bubbling.\n * Because this shim doesn't support node tree, this merely changes the `cancelBubble` property value.\n * @see https://dom.spec.whatwg.org/#dom-event-stoppropagation\n */\n stopPropagation(): void {\n $(this).stopPropagationFlag = true\n }\n\n /**\n * `true` if event bubbling was stopped.\n * @deprecated\n * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble\n */\n get cancelBubble(): boolean {\n return $(this).stopPropagationFlag\n }\n\n /**\n * Stop event bubbling if `true` is set.\n * @deprecated Use the `stopPropagation()` method instead.\n * @see https://dom.spec.whatwg.org/#dom-event-cancelbubble\n */\n set cancelBubble(value: boolean) {\n if (value) {\n $(this).stopPropagationFlag = true\n } else {\n FalsyWasAssignedToCancelBubble.warn()\n }\n }\n\n /**\n * Stop event bubbling and subsequent event listener callings.\n * @see https://dom.spec.whatwg.org/#dom-event-stopimmediatepropagation\n */\n stopImmediatePropagation(): void {\n const data = $(this)\n data.stopPropagationFlag = data.stopImmediatePropagationFlag = true\n }\n\n /**\n * `true` if this event will bubble.\n * @see https://dom.spec.whatwg.org/#dom-event-bubbles\n */\n get bubbles(): boolean {\n return $(this).bubbles\n }\n\n /**\n * `true` if this event can be canceled by the `preventDefault()` method.\n * @see https://dom.spec.whatwg.org/#dom-event-cancelable\n */\n get cancelable(): boolean {\n return $(this).cancelable\n }\n\n /**\n * `true` if the default behavior will act.\n * @deprecated Use the `defaultPrevented` proeprty instead.\n * @see https://dom.spec.whatwg.org/#dom-event-returnvalue\n */\n get returnValue(): boolean {\n return !$(this).canceledFlag\n }\n\n /**\n * Cancel the default behavior if `false` is set.\n * @deprecated Use the `preventDefault()` method instead.\n * @see https://dom.spec.whatwg.org/#dom-event-returnvalue\n */\n set returnValue(value: boolean) {\n if (!value) {\n setCancelFlag($(this))\n } else {\n TruthyWasAssignedToReturnValue.warn()\n }\n }\n\n /**\n * Cancel the default behavior.\n * @see https://dom.spec.whatwg.org/#dom-event-preventdefault\n */\n preventDefault(): void {\n setCancelFlag($(this))\n }\n\n /**\n * `true` if the default behavior was canceled.\n * @see https://dom.spec.whatwg.org/#dom-event-defaultprevented\n */\n get defaultPrevented(): boolean {\n return $(this).canceledFlag\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-composed\n */\n get composed(): boolean {\n return $(this).composed\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-istrusted\n */\n //istanbul ignore next\n get isTrusted(): boolean {\n return false\n }\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-timestamp\n */\n get timeStamp(): number {\n return $(this).timeStamp\n }\n\n /**\n * @deprecated Don't use this method. The constructor did initialization.\n */\n initEvent(type: string, bubbles = false, cancelable = false) {\n const data = $(this)\n if (data.dispatchFlag) {\n InitEventWasCalledWhileDispatching.warn()\n return\n }\n\n internalDataMap.set(this, {\n ...data,\n type: String(type),\n bubbles: Boolean(bubbles),\n cancelable: Boolean(cancelable),\n target: null,\n currentTarget: null,\n stopPropagationFlag: false,\n stopImmediatePropagationFlag: false,\n canceledFlag: false,\n })\n }\n}\n\n/*eslint-enable class-methods-use-this */\n\nexport namespace Event {\n /**\n * The options of the `Event` constructor.\n * @see https://dom.spec.whatwg.org/#dictdef-eventinit\n */\n export interface EventInit {\n bubbles?: boolean\n cancelable?: boolean\n composed?: boolean\n }\n}\n\nexport { $ as getEventInternalData }\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\nconst NONE = 0\nconst CAPTURING_PHASE = 1\nconst AT_TARGET = 2\nconst BUBBLING_PHASE = 3\n\n/**\n * Private data.\n */\ninterface EventInternalData {\n /**\n * The value of `type` attribute.\n */\n readonly type: string\n /**\n * The value of `bubbles` attribute.\n */\n readonly bubbles: boolean\n /**\n * The value of `cancelable` attribute.\n */\n readonly cancelable: boolean\n /**\n * The value of `composed` attribute.\n */\n readonly composed: boolean\n /**\n * The value of `timeStamp` attribute.\n */\n readonly timeStamp: number\n\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-target\n */\n target: EventTarget | null\n /**\n * @see https://dom.spec.whatwg.org/#dom-event-currenttarget\n */\n currentTarget: EventTarget | null\n /**\n * @see https://dom.spec.whatwg.org/#stop-propagation-flag\n */\n stopPropagationFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#stop-immediate-propagation-flag\n */\n stopImmediatePropagationFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#canceled-flag\n */\n canceledFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#in-passive-listener-flag\n */\n inPassiveListenerFlag: boolean\n /**\n * @see https://dom.spec.whatwg.org/#dispatch-flag\n */\n dispatchFlag: boolean\n}\n\n/**\n * Private data for event wrappers.\n */\nconst internalDataMap = new WeakMap()\n\n/**\n * Get private data.\n * @param event The event object to get private data.\n * @param name The variable name to report.\n * @returns The private data of the event.\n */\nfunction $(event: unknown, name = \"this\"): EventInternalData {\n const retv = internalDataMap.get(event)\n assertType(\n retv != null,\n \"'%s' must be an object that Event constructor created, but got another one: %o\",\n name,\n event,\n )\n return retv\n}\n\n/**\n * https://dom.spec.whatwg.org/#set-the-canceled-flag\n * @param data private data.\n */\nfunction setCancelFlag(data: EventInternalData) {\n if (data.inPassiveListenerFlag) {\n CanceledInPassiveListener.warn()\n return\n }\n if (!data.cancelable) {\n NonCancelableEventWasCanceled.warn()\n return\n }\n\n data.canceledFlag = true\n}\n\n// Set enumerable\nObject.defineProperty(Event, \"NONE\", { enumerable: true })\nObject.defineProperty(Event, \"CAPTURING_PHASE\", { enumerable: true })\nObject.defineProperty(Event, \"AT_TARGET\", { enumerable: true })\nObject.defineProperty(Event, \"BUBBLING_PHASE\", { enumerable: true })\nconst keys = Object.getOwnPropertyNames(Event.prototype)\nfor (let i = 0; i < keys.length; ++i) {\n if (keys[i] === \"constructor\") {\n continue\n }\n Object.defineProperty(Event.prototype, keys[i], { enumerable: true })\n}\n\n// Ensure `event instanceof window.Event` is `true`.\nif (typeof Global !== \"undefined\" && typeof Global.Event !== \"undefined\") {\n Object.setPrototypeOf(Event.prototype, Global.Event.prototype)\n}\n","import { Global } from \"./global\"\n\n/**\n * Create a new InvalidStateError instance.\n * @param message The error message.\n */\nexport function createInvalidStateError(message: string): Error {\n if (Global.DOMException) {\n return new Global.DOMException(message, \"InvalidStateError\")\n }\n\n if (DOMException == null) {\n DOMException = class DOMException extends Error {\n constructor(msg: string) {\n super(msg)\n if ((Error as any).captureStackTrace) {\n ;(Error as any).captureStackTrace(this, DOMException)\n }\n }\n // eslint-disable-next-line class-methods-use-this\n get code() {\n return 11\n }\n // eslint-disable-next-line class-methods-use-this\n get name() {\n return \"InvalidStateError\"\n }\n }\n Object.defineProperties(DOMException.prototype, {\n code: { enumerable: true },\n name: { enumerable: true },\n })\n defineErrorCodeProperties(DOMException)\n defineErrorCodeProperties(DOMException.prototype)\n }\n return new DOMException(message)\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\nlet DOMException: { new (message: string): Error } | undefined\n\nconst ErrorCodeMap = {\n INDEX_SIZE_ERR: 1,\n DOMSTRING_SIZE_ERR: 2,\n HIERARCHY_REQUEST_ERR: 3,\n WRONG_DOCUMENT_ERR: 4,\n INVALID_CHARACTER_ERR: 5,\n NO_DATA_ALLOWED_ERR: 6,\n NO_MODIFICATION_ALLOWED_ERR: 7,\n NOT_FOUND_ERR: 8,\n NOT_SUPPORTED_ERR: 9,\n INUSE_ATTRIBUTE_ERR: 10,\n INVALID_STATE_ERR: 11,\n SYNTAX_ERR: 12,\n INVALID_MODIFICATION_ERR: 13,\n NAMESPACE_ERR: 14,\n INVALID_ACCESS_ERR: 15,\n VALIDATION_ERR: 16,\n TYPE_MISMATCH_ERR: 17,\n SECURITY_ERR: 18,\n NETWORK_ERR: 19,\n ABORT_ERR: 20,\n URL_MISMATCH_ERR: 21,\n QUOTA_EXCEEDED_ERR: 22,\n TIMEOUT_ERR: 23,\n INVALID_NODE_TYPE_ERR: 24,\n DATA_CLONE_ERR: 25,\n}\ntype ErrorCodeMap = typeof ErrorCodeMap\n\nfunction defineErrorCodeProperties(obj: any): void {\n const keys = Object.keys(ErrorCodeMap) as (keyof ErrorCodeMap)[]\n for (let i = 0; i < keys.length; ++i) {\n const key = keys[i]\n const value = ErrorCodeMap[key]\n Object.defineProperty(obj, key, {\n get() {\n return value\n },\n configurable: true,\n enumerable: true,\n })\n }\n}\n","import { Event } from \"./event\"\nimport { Global } from \"./global\"\nimport { assertType } from \"./misc\"\n\n/**\n * An implementation of `Event` interface, that wraps a given event object.\n * This class controls the internal state of `Event`.\n * @see https://dom.spec.whatwg.org/#interface-event\n */\nexport class EventWrapper extends Event {\n /**\n * Wrap a given event object to control states.\n * @param event The event-like object to wrap.\n */\n static wrap(event: T): EventWrapperOf {\n return new (getWrapperClassOf(event))(event)\n }\n\n protected constructor(event: Event) {\n super(event.type, {\n bubbles: event.bubbles,\n cancelable: event.cancelable,\n composed: event.composed,\n })\n\n if (event.cancelBubble) {\n super.stopPropagation()\n }\n if (event.defaultPrevented) {\n super.preventDefault()\n }\n\n internalDataMap.set(this, { original: event })\n\n // Define accessors\n const keys = Object.keys(event)\n for (let i = 0; i < keys.length; ++i) {\n const key = keys[i]\n if (!(key in this)) {\n Object.defineProperty(\n this,\n key,\n defineRedirectDescriptor(event, key),\n )\n }\n }\n }\n\n stopPropagation(): void {\n super.stopPropagation()\n\n const { original } = $(this)\n if (\"stopPropagation\" in original) {\n original.stopPropagation!()\n }\n }\n\n get cancelBubble(): boolean {\n return super.cancelBubble\n }\n set cancelBubble(value: boolean) {\n super.cancelBubble = value\n\n const { original } = $(this)\n if (\"cancelBubble\" in original) {\n original.cancelBubble = value\n }\n }\n\n stopImmediatePropagation(): void {\n super.stopImmediatePropagation()\n\n const { original } = $(this)\n if (\"stopImmediatePropagation\" in original) {\n original.stopImmediatePropagation!()\n }\n }\n\n get returnValue(): boolean {\n return super.returnValue\n }\n set returnValue(value: boolean) {\n super.returnValue = value\n\n const { original } = $(this)\n if (\"returnValue\" in original) {\n original.returnValue = value\n }\n }\n\n preventDefault(): void {\n super.preventDefault()\n\n const { original } = $(this)\n if (\"preventDefault\" in original) {\n original.preventDefault!()\n }\n }\n\n get timeStamp(): number {\n const { original } = $(this)\n if (\"timeStamp\" in original) {\n return original.timeStamp!\n }\n return super.timeStamp\n }\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\ntype EventLike = { readonly type: string } & Partial\ntype EventWrapperOf = Event &\n Omit\n\ninterface EventWrapperInternalData {\n readonly original: EventLike\n}\n\n/**\n * Private data for event wrappers.\n */\nconst internalDataMap = new WeakMap()\n\n/**\n * Get private data.\n * @param event The event object to get private data.\n * @returns The private data of the event.\n */\nfunction $(event: unknown): EventWrapperInternalData {\n const retv = internalDataMap.get(event)\n assertType(\n retv != null,\n \"'this' is expected an Event object, but got\",\n event,\n )\n return retv\n}\n\n/**\n * Cache for wrapper classes.\n * @type {WeakMap}\n * @private\n */\nconst wrapperClassCache = new WeakMap()\n\n// Make association for wrappers.\nwrapperClassCache.set(Object.prototype, EventWrapper)\nif (typeof Global !== \"undefined\" && typeof Global.Event !== \"undefined\") {\n wrapperClassCache.set(Global.Event.prototype, EventWrapper)\n}\n\n/**\n * Get the wrapper class of a given prototype.\n * @param originalEvent The event object to wrap.\n */\nfunction getWrapperClassOf(\n originalEvent: T,\n): { new (e: T): EventWrapperOf } {\n const prototype = Object.getPrototypeOf(originalEvent)\n if (prototype == null) {\n return EventWrapper as any\n }\n\n let wrapper: any = wrapperClassCache.get(prototype)\n if (wrapper == null) {\n wrapper = defineWrapper(getWrapperClassOf(prototype), prototype)\n wrapperClassCache.set(prototype, wrapper)\n }\n\n return wrapper\n}\n\n/**\n * Define new wrapper class.\n * @param BaseEventWrapper The base wrapper class.\n * @param originalPrototype The prototype of the original event.\n */\nfunction defineWrapper(BaseEventWrapper: any, originalPrototype: any): any {\n class CustomEventWrapper extends BaseEventWrapper {}\n\n const keys = Object.keys(originalPrototype)\n for (let i = 0; i < keys.length; ++i) {\n Object.defineProperty(\n CustomEventWrapper.prototype,\n keys[i],\n defineRedirectDescriptor(originalPrototype, keys[i]),\n )\n }\n\n return CustomEventWrapper\n}\n\n/**\n * Get the property descriptor to redirect a given property.\n */\nfunction defineRedirectDescriptor(obj: any, key: string): PropertyDescriptor {\n const d = Object.getOwnPropertyDescriptor(obj, key)!\n return {\n get() {\n const original: any = $(this).original\n const value = original[key]\n if (typeof value === \"function\") {\n return value.bind(original)\n }\n return value\n },\n set(value: any) {\n const original: any = $(this).original\n original[key] = value\n },\n configurable: d.configurable,\n enumerable: d.enumerable,\n }\n}\n","import { reportError } from \"./error-handler\"\nimport { Event } from \"./event\" // Used as only type, so no circular.\nimport { EventTarget } from \"./event-target\" // Used as only type, so no circular.\n\n/**\n * The event listener concept.\n * @see https://dom.spec.whatwg.org/#concept-event-listener\n */\nexport interface Listener {\n /**\n * The callback function.\n */\n readonly callback: Listener.Callback\n /**\n * The flags of this listener.\n * This is writable to add the removed flag.\n */\n flags: ListenerFlags\n /**\n * The `AbortSignal` to remove this listener.\n */\n readonly signal: Listener.AbortSignal | undefined\n /**\n * The `abort` event listener for the `signal`.\n * To remove it from the `signal`.\n */\n readonly signalListener: (() => void) | undefined\n}\n\nexport namespace Listener {\n export type Callback<\n TEventTarget extends EventTarget,\n TEvent extends Event\n > = CallbackFunction | CallbackObject\n\n export interface CallbackFunction<\n TEventTarget extends EventTarget,\n TEvent extends Event\n > {\n (this: TEventTarget, event: TEvent): void\n }\n\n export interface CallbackObject {\n handleEvent(event: TEvent): void\n }\n\n export interface AbortSignal {\n addEventListener(type: string, callback: Callback): void\n removeEventListener(type: string, callback: Callback): void\n }\n}\n\n/**\n * Create a new listener.\n * @param callback The callback function.\n * @param capture The capture flag.\n * @param passive The passive flag.\n * @param once The once flag.\n * @param signal The abort signal.\n * @param signalListener The abort event listener for the abort signal.\n */\nexport function createListener(\n callback: Listener.Callback,\n capture: boolean,\n passive: boolean,\n once: boolean,\n signal: Listener.AbortSignal | undefined,\n signalListener: (() => void) | undefined,\n): Listener {\n return {\n callback,\n flags:\n (capture ? ListenerFlags.Capture : 0) |\n (passive ? ListenerFlags.Passive : 0) |\n (once ? ListenerFlags.Once : 0),\n signal,\n signalListener,\n }\n}\n\n/**\n * Set the `removed` flag to the given listener.\n * @param listener The listener to check.\n */\nexport function setRemoved(listener: Listener): void {\n listener.flags |= ListenerFlags.Removed\n}\n\n/**\n * Check if the given listener has the `capture` flag or not.\n * @param listener The listener to check.\n */\nexport function isCapture(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Capture) === ListenerFlags.Capture\n}\n\n/**\n * Check if the given listener has the `passive` flag or not.\n * @param listener The listener to check.\n */\nexport function isPassive(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Passive) === ListenerFlags.Passive\n}\n\n/**\n * Check if the given listener has the `once` flag or not.\n * @param listener The listener to check.\n */\nexport function isOnce(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Once) === ListenerFlags.Once\n}\n\n/**\n * Check if the given listener has the `removed` flag or not.\n * @param listener The listener to check.\n */\nexport function isRemoved(listener: Listener): boolean {\n return (listener.flags & ListenerFlags.Removed) === ListenerFlags.Removed\n}\n\n/**\n * Call an event listener.\n * @param listener The listener to call.\n * @param target The event target object for `thisArg`.\n * @param event The event object for the first argument.\n * @param attribute `true` if this callback is an event attribute handler.\n */\nexport function invokeCallback(\n { callback }: Listener,\n target: EventTarget,\n event: Event,\n): void {\n try {\n if (typeof callback === \"function\") {\n callback.call(target, event)\n } else if (typeof callback.handleEvent === \"function\") {\n callback.handleEvent(event)\n }\n } catch (thrownError) {\n reportError(thrownError)\n }\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\n/**\n * The flags of listeners.\n */\nconst enum ListenerFlags {\n Capture = 0x01,\n Passive = 0x02,\n Once = 0x04,\n Removed = 0x08,\n}\n","import { createListener, isCapture, Listener, setRemoved } from \"./listener\"\n\n/**\n * Information of an listener list.\n */\nexport interface ListenerList {\n /**\n * The callback function of the event attribute handler.\n */\n attrCallback: Listener.CallbackFunction | undefined\n /**\n * The listener of the event attribute handler.\n */\n attrListener: Listener | undefined\n /**\n * `true` if the `dispatchEvent` method is traversing the current `listeners` array.\n */\n cow: boolean\n /**\n * The listeners.\n * This is writable for copy-on-write.\n */\n listeners: Listener[]\n}\n\n/**\n * Find the index of given listener.\n * This returns `-1` if not found.\n * @param list The listener list.\n * @param callback The callback function to find.\n * @param capture The capture flag to find.\n */\nexport function findIndexOfListener(\n { listeners }: ListenerList,\n callback: Listener.Callback,\n capture: boolean,\n): number {\n for (let i = 0; i < listeners.length; ++i) {\n if (\n listeners[i].callback === callback &&\n isCapture(listeners[i]) === capture\n ) {\n return i\n }\n }\n return -1\n}\n\n/**\n * Add the given listener.\n * Does copy-on-write if needed.\n * @param list The listener list.\n * @param callback The callback function.\n * @param capture The capture flag.\n * @param passive The passive flag.\n * @param once The once flag.\n * @param signal The abort signal.\n */\nexport function addListener(\n list: ListenerList,\n callback: Listener.Callback,\n capture: boolean,\n passive: boolean,\n once: boolean,\n signal: Listener.AbortSignal | undefined,\n): Listener {\n let signalListener: (() => void) | undefined\n if (signal) {\n signalListener = removeListener.bind(null, list, callback, capture)\n signal.addEventListener(\"abort\", signalListener)\n }\n\n const listener = createListener(\n callback,\n capture,\n passive,\n once,\n signal,\n signalListener,\n )\n\n if (list.cow) {\n list.cow = false\n list.listeners = [...list.listeners, listener]\n } else {\n list.listeners.push(listener)\n }\n\n return listener\n}\n\n/**\n * Remove a listener.\n * @param list The listener list.\n * @param callback The callback function to find.\n * @param capture The capture flag to find.\n * @returns `true` if it mutated the list directly.\n */\nexport function removeListener(\n list: ListenerList,\n callback: Listener.Callback,\n capture: boolean,\n): boolean {\n const index = findIndexOfListener(list, callback, capture)\n if (index !== -1) {\n return removeListenerAt(list, index)\n }\n return false\n}\n\n/**\n * Remove a listener.\n * @param list The listener list.\n * @param index The index of the target listener.\n * @param disableCow Disable copy-on-write if true.\n * @returns `true` if it mutated the `listeners` array directly.\n */\nexport function removeListenerAt(\n list: ListenerList,\n index: number,\n disableCow = false,\n): boolean {\n const listener = list.listeners[index]\n\n // Set the removed flag.\n setRemoved(listener)\n\n // Dispose the abort signal listener if exists.\n if (listener.signal) {\n listener.signal.removeEventListener(\"abort\", listener.signalListener!)\n }\n\n // Remove it from the array.\n if (list.cow && !disableCow) {\n list.cow = false\n list.listeners = list.listeners.filter((_, i) => i !== index)\n return false\n }\n list.listeners.splice(index, 1)\n return true\n}\n","import { ListenerList } from \"./listener-list\"\n\n/**\n * The map from event types to each listener list.\n */\nexport interface ListenerListMap {\n [type: string]: ListenerList | undefined\n}\n\n/**\n * Create a new `ListenerListMap` object.\n */\nexport function createListenerListMap(): ListenerListMap {\n return Object.create(null)\n}\n\n/**\n * Get the listener list of the given type.\n * If the listener list has not been initialized, initialize and return it.\n * @param listenerMap The listener list map.\n * @param type The event type to get.\n */\nexport function ensureListenerList(\n listenerMap: Record,\n type: string,\n): ListenerList {\n return (listenerMap[type] ??= {\n attrCallback: undefined,\n attrListener: undefined,\n cow: false,\n listeners: [],\n })\n}\n","import { createInvalidStateError } from \"./dom-exception\"\nimport { Event, getEventInternalData } from \"./event\"\nimport { EventWrapper } from \"./event-wrapper\"\nimport { Global } from \"./global\"\nimport {\n invokeCallback,\n isCapture,\n isOnce,\n isPassive,\n isRemoved,\n Listener,\n} from \"./listener\"\nimport {\n addListener,\n findIndexOfListener,\n removeListener,\n removeListenerAt,\n} from \"./listener-list\"\nimport {\n createListenerListMap,\n ensureListenerList,\n ListenerListMap,\n} from \"./listener-list-map\"\nimport { assertType, format } from \"./misc\"\nimport {\n EventListenerWasDuplicated,\n InvalidEventListener,\n OptionWasIgnored,\n} from \"./warnings\"\n\n/**\n * An implementation of the `EventTarget` interface.\n * @see https://dom.spec.whatwg.org/#eventtarget\n */\nexport class EventTarget<\n TEventMap extends Record = Record,\n TMode extends \"standard\" | \"strict\" = \"standard\"\n> {\n /**\n * Initialize this instance.\n */\n constructor() {\n internalDataMap.set(this, createListenerListMap())\n }\n\n /**\n * Add an event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param options Options.\n */\n addEventListener(\n type: T,\n callback?: EventTarget.EventListener | null,\n options?: EventTarget.AddOptions,\n ): void\n\n /**\n * Add an event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param options Options.\n */\n addEventListener(\n type: string,\n callback?: EventTarget.FallbackEventListener,\n options?: EventTarget.AddOptions,\n ): void\n\n /**\n * Add an event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param capture The capture flag.\n * @deprecated Use `{capture: boolean}` object instead of a boolean value.\n */\n addEventListener(\n type: T,\n callback:\n | EventTarget.EventListener\n | null\n | undefined,\n capture: boolean,\n ): void\n\n /**\n * Add an event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param capture The capture flag.\n * @deprecated Use `{capture: boolean}` object instead of a boolean value.\n */\n addEventListener(\n type: string,\n callback: EventTarget.FallbackEventListener,\n capture: boolean,\n ): void\n\n // Implementation\n addEventListener(\n type0: T,\n callback0?: EventTarget.EventListener | null,\n options0?: boolean | EventTarget.AddOptions,\n ): void {\n const listenerMap = $(this)\n const {\n callback,\n capture,\n once,\n passive,\n signal,\n type,\n } = normalizeAddOptions(type0, callback0, options0)\n if (callback == null || signal?.aborted) {\n return\n }\n const list = ensureListenerList(listenerMap, type)\n\n // Find existing listener.\n const i = findIndexOfListener(list, callback, capture)\n if (i !== -1) {\n warnDuplicate(list.listeners[i], passive, once, signal)\n return\n }\n\n // Add the new listener.\n addListener(list, callback, capture, passive, once, signal)\n }\n\n /**\n * Remove an added event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param options Options.\n */\n removeEventListener(\n type: T,\n callback?: EventTarget.EventListener | null,\n options?: EventTarget.Options,\n ): void\n\n /**\n * Remove an added event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param options Options.\n */\n removeEventListener(\n type: string,\n callback?: EventTarget.FallbackEventListener,\n options?: EventTarget.Options,\n ): void\n\n /**\n * Remove an added event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param capture The capture flag.\n * @deprecated Use `{capture: boolean}` object instead of a boolean value.\n */\n removeEventListener(\n type: T,\n callback:\n | EventTarget.EventListener\n | null\n | undefined,\n capture: boolean,\n ): void\n\n /**\n * Remove an added event listener.\n * @param type The event type.\n * @param callback The event listener.\n * @param capture The capture flag.\n * @deprecated Use `{capture: boolean}` object instead of a boolean value.\n */\n removeEventListener(\n type: string,\n callback: EventTarget.FallbackEventListener,\n capture: boolean,\n ): void\n\n // Implementation\n removeEventListener(\n type0: T,\n callback0?: EventTarget.EventListener | null,\n options0?: boolean | EventTarget.Options,\n ): void {\n const listenerMap = $(this)\n const { callback, capture, type } = normalizeOptions(\n type0,\n callback0,\n options0,\n )\n const list = listenerMap[type]\n\n if (callback != null && list) {\n removeListener(list, callback, capture)\n }\n }\n\n /**\n * Dispatch an event.\n * @param event The `Event` object to dispatch.\n */\n dispatchEvent(\n event: EventTarget.EventData,\n ): boolean\n\n /**\n * Dispatch an event.\n * @param event The `Event` object to dispatch.\n */\n dispatchEvent(event: EventTarget.FallbackEvent): boolean\n\n // Implementation\n dispatchEvent(\n e:\n | EventTarget.EventData\n | EventTarget.FallbackEvent,\n ): boolean {\n const list = $(this)[String(e.type)]\n if (list == null) {\n return true\n }\n\n const event = e instanceof Event ? e : EventWrapper.wrap(e)\n const eventData = getEventInternalData(event, \"event\")\n if (eventData.dispatchFlag) {\n throw createInvalidStateError(\"This event has been in dispatching.\")\n }\n\n eventData.dispatchFlag = true\n eventData.target = eventData.currentTarget = this\n\n if (!eventData.stopPropagationFlag) {\n const { cow, listeners } = list\n\n // Set copy-on-write flag.\n list.cow = true\n\n // Call listeners.\n for (let i = 0; i < listeners.length; ++i) {\n const listener = listeners[i]\n\n // Skip if removed.\n if (isRemoved(listener)) {\n continue\n }\n\n // Remove this listener if has the `once` flag.\n if (isOnce(listener) && removeListenerAt(list, i, !cow)) {\n // Because this listener was removed, the next index is the\n // same as the current value.\n i -= 1\n }\n\n // Call this listener with the `passive` flag.\n eventData.inPassiveListenerFlag = isPassive(listener)\n invokeCallback(listener, this, event)\n eventData.inPassiveListenerFlag = false\n\n // Stop if the `event.stopImmediatePropagation()` method was called.\n if (eventData.stopImmediatePropagationFlag) {\n break\n }\n }\n\n // Restore copy-on-write flag.\n if (!cow) {\n list.cow = false\n }\n }\n\n eventData.target = null\n eventData.currentTarget = null\n eventData.stopImmediatePropagationFlag = false\n eventData.stopPropagationFlag = false\n eventData.dispatchFlag = false\n\n return !eventData.canceledFlag\n }\n}\n\nexport namespace EventTarget {\n /**\n * The event listener.\n */\n export type EventListener<\n TEventTarget extends EventTarget,\n TEvent extends Event\n > = CallbackFunction | CallbackObject\n\n /**\n * The event listener function.\n */\n export interface CallbackFunction<\n TEventTarget extends EventTarget,\n TEvent extends Event\n > {\n (this: TEventTarget, event: TEvent): void\n }\n\n /**\n * The event listener object.\n * @see https://dom.spec.whatwg.org/#callbackdef-eventlistener\n */\n export interface CallbackObject {\n handleEvent(event: TEvent): void\n }\n\n /**\n * The common options for both `addEventListener` and `removeEventListener` methods.\n * @see https://dom.spec.whatwg.org/#dictdef-eventlisteneroptions\n */\n export interface Options {\n capture?: boolean\n }\n\n /**\n * The options for the `addEventListener` methods.\n * @see https://dom.spec.whatwg.org/#dictdef-addeventlisteneroptions\n */\n export interface AddOptions extends Options {\n passive?: boolean\n once?: boolean\n signal?: AbortSignal | null | undefined\n }\n\n /**\n * The abort signal.\n * @see https://dom.spec.whatwg.org/#abortsignal\n */\n export interface AbortSignal extends EventTarget<{ abort: Event }> {\n readonly aborted: boolean\n onabort: CallbackFunction | null\n }\n\n /**\n * The event data to dispatch in strict mode.\n */\n export type EventData<\n TEventMap extends Record,\n TMode extends \"standard\" | \"strict\",\n TEventType extends string\n > = TMode extends \"strict\"\n ? IsValidEventMap extends true\n ? ExplicitType &\n Omit &\n Partial>\n : never\n : never\n\n /**\n * Define explicit `type` property if `T` is a string literal.\n * Otherwise, never.\n */\n export type ExplicitType = string extends T\n ? never\n : { readonly type: T }\n\n /**\n * The event listener type in standard mode.\n * Otherwise, never.\n */\n export type FallbackEventListener<\n TEventTarget extends EventTarget,\n TMode extends \"standard\" | \"strict\"\n > = TMode extends \"standard\"\n ? EventListener | null | undefined\n : never\n\n /**\n * The event type in standard mode.\n * Otherwise, never.\n */\n export type FallbackEvent<\n TMode extends \"standard\" | \"strict\"\n > = TMode extends \"standard\" ? Event : never\n\n /**\n * Check if given event map is valid.\n * It's valid if the keys of the event map are narrower than `string`.\n */\n export type IsValidEventMap = string extends keyof T ? false : true\n}\n\nexport { $ as getEventTargetInternalData }\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\n/**\n * Internal data for EventTarget\n */\ntype EventTargetInternalData = ListenerListMap\n\n/**\n * Internal data.\n */\nconst internalDataMap = new WeakMap()\n\n/**\n * Get private data.\n * @param target The event target object to get private data.\n * @param name The variable name to report.\n * @returns The private data of the event.\n */\nfunction $(target: any, name = \"this\"): EventTargetInternalData {\n const retv = internalDataMap.get(target)\n assertType(\n retv != null,\n \"'%s' must be an object that EventTarget constructor created, but got another one: %o\",\n name,\n target,\n )\n return retv\n}\n\n/**\n * Normalize options.\n * @param options The options to normalize.\n */\nfunction normalizeAddOptions(\n type: string,\n callback: EventTarget.EventListener | null | undefined,\n options: boolean | EventTarget.AddOptions | undefined,\n): {\n type: string\n callback: EventTarget.EventListener | undefined\n capture: boolean\n passive: boolean\n once: boolean\n signal: EventTarget.AbortSignal | undefined\n} {\n assertCallback(callback)\n\n if (typeof options === \"object\" && options !== null) {\n return {\n type: String(type),\n callback: callback ?? undefined,\n capture: Boolean(options.capture),\n passive: Boolean(options.passive),\n once: Boolean(options.once),\n signal: options.signal ?? undefined,\n }\n }\n\n return {\n type: String(type),\n callback: callback ?? undefined,\n capture: Boolean(options),\n passive: false,\n once: false,\n signal: undefined,\n }\n}\n\n/**\n * Normalize options.\n * @param options The options to normalize.\n */\nfunction normalizeOptions(\n type: string,\n callback: EventTarget.EventListener | null | undefined,\n options: boolean | EventTarget.Options | undefined,\n): {\n type: string\n callback: EventTarget.EventListener | undefined\n capture: boolean\n} {\n assertCallback(callback)\n\n if (typeof options === \"object\" && options !== null) {\n return {\n type: String(type),\n callback: callback ?? undefined,\n capture: Boolean(options.capture),\n }\n }\n\n return {\n type: String(type),\n callback: callback ?? undefined,\n capture: Boolean(options),\n }\n}\n\n/**\n * Assert the type of 'callback' argument.\n * @param callback The callback to check.\n */\nfunction assertCallback(callback: any): void {\n if (\n typeof callback === \"function\" ||\n (typeof callback === \"object\" &&\n callback !== null &&\n typeof callback.handleEvent === \"function\")\n ) {\n return\n }\n if (callback == null || typeof callback === \"object\") {\n InvalidEventListener.warn(callback)\n return\n }\n\n throw new TypeError(format(InvalidEventListener.message, [callback]))\n}\n\n/**\n * Print warning for duplicated.\n * @param listener The current listener that is duplicated.\n * @param passive The passive flag of the new duplicated listener.\n * @param once The once flag of the new duplicated listener.\n * @param signal The signal object of the new duplicated listener.\n */\nfunction warnDuplicate(\n listener: Listener,\n passive: boolean,\n once: boolean,\n signal: EventTarget.AbortSignal | undefined,\n): void {\n EventListenerWasDuplicated.warn(\n isCapture(listener) ? \"capture\" : \"bubble\",\n listener.callback,\n )\n\n if (isPassive(listener) !== passive) {\n OptionWasIgnored.warn(\"passive\")\n }\n if (isOnce(listener) !== once) {\n OptionWasIgnored.warn(\"once\")\n }\n if (listener.signal !== signal) {\n OptionWasIgnored.warn(\"signal\")\n }\n}\n\n// Set enumerable\nconst keys = Object.getOwnPropertyNames(EventTarget.prototype)\nfor (let i = 0; i < keys.length; ++i) {\n if (keys[i] === \"constructor\") {\n continue\n }\n Object.defineProperty(EventTarget.prototype, keys[i], { enumerable: true })\n}\n\n// Ensure `eventTarget instanceof window.EventTarget` is `true`.\nif (\n typeof Global !== \"undefined\" &&\n typeof Global.EventTarget !== \"undefined\"\n) {\n Object.setPrototypeOf(EventTarget.prototype, Global.EventTarget.prototype)\n}\n","import { Event } from \"./event\"\nimport { EventTarget, getEventTargetInternalData } from \"./event-target\"\nimport { addListener, ListenerList, removeListener } from \"./listener-list\"\nimport { ensureListenerList } from \"./listener-list-map\"\nimport { InvalidAttributeHandler } from \"./warnings\"\n\n/**\n * Get the current value of a given event attribute.\n * @param target The `EventTarget` object to get.\n * @param type The event type.\n */\nexport function getEventAttributeValue<\n TEventTarget extends EventTarget,\n TEvent extends Event\n>(\n target: TEventTarget,\n type: string,\n): EventTarget.CallbackFunction | null {\n const listMap = getEventTargetInternalData(target, \"target\")\n return listMap[type]?.attrCallback ?? null\n}\n\n/**\n * Set an event listener to a given event attribute.\n * @param target The `EventTarget` object to set.\n * @param type The event type.\n * @param callback The event listener.\n */\nexport function setEventAttributeValue(\n target: EventTarget,\n type: string,\n callback: EventTarget.CallbackFunction | null,\n): void {\n if (callback != null && typeof callback !== \"function\") {\n InvalidAttributeHandler.warn(callback)\n }\n\n if (\n typeof callback === \"function\" ||\n (typeof callback === \"object\" && callback !== null)\n ) {\n upsertEventAttributeListener(target, type, callback)\n } else {\n removeEventAttributeListener(target, type)\n }\n}\n\n//------------------------------------------------------------------------------\n// Helpers\n//------------------------------------------------------------------------------\n\n/**\n * Update or insert the given event attribute handler.\n * @param target The `EventTarget` object to set.\n * @param type The event type.\n * @param callback The event listener.\n */\nfunction upsertEventAttributeListener<\n TEventTarget extends EventTarget\n>(\n target: TEventTarget,\n type: string,\n callback: EventTarget.CallbackFunction,\n): void {\n const list = ensureListenerList(\n getEventTargetInternalData(target, \"target\"),\n String(type),\n )\n list.attrCallback = callback\n\n if (list.attrListener == null) {\n list.attrListener = addListener(\n list,\n defineEventAttributeCallback(list),\n false,\n false,\n false,\n undefined,\n )\n }\n}\n\n/**\n * Remove the given event attribute handler.\n * @param target The `EventTarget` object to remove.\n * @param type The event type.\n * @param callback The event listener.\n */\nfunction removeEventAttributeListener(\n target: EventTarget,\n type: string,\n): void {\n const listMap = getEventTargetInternalData(target, \"target\")\n const list = listMap[String(type)]\n if (list && list.attrListener) {\n removeListener(list, list.attrListener.callback, false)\n list.attrCallback = list.attrListener = undefined\n }\n}\n\n/**\n * Define the callback function for the given listener list object.\n * It calls `attrCallback` property if the property value is a function.\n * @param list The `ListenerList` object.\n */\nfunction defineEventAttributeCallback(\n list: ListenerList,\n): EventTarget.CallbackFunction {\n return function (event) {\n const callback = list.attrCallback\n if (typeof callback === \"function\") {\n callback.call(this, event)\n }\n }\n}\n","import { Event } from \"./event\"\nimport {\n getEventAttributeValue,\n setEventAttributeValue,\n} from \"./event-attribute-handler\"\nimport { EventTarget } from \"./event-target\"\n\n/**\n * Define an `EventTarget` class that has event attibutes.\n * @param types The types to define event attributes.\n * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly.\n */\nexport function defineCustomEventTarget<\n TEventMap extends Record,\n TMode extends \"standard\" | \"strict\" = \"standard\"\n>(\n ...types: (string & keyof TEventMap)[]\n): defineCustomEventTarget.CustomEventTargetConstructor {\n class CustomEventTarget extends EventTarget {}\n for (let i = 0; i < types.length; ++i) {\n defineEventAttribute(CustomEventTarget.prototype, types[i])\n }\n\n return CustomEventTarget as any\n}\n\nexport namespace defineCustomEventTarget {\n /**\n * The interface of CustomEventTarget constructor.\n */\n export type CustomEventTargetConstructor<\n TEventMap extends Record,\n TMode extends \"standard\" | \"strict\"\n > = {\n /**\n * Create a new instance.\n */\n new (): CustomEventTarget\n /**\n * prototype object.\n */\n prototype: CustomEventTarget\n }\n\n /**\n * The interface of CustomEventTarget.\n */\n export type CustomEventTarget<\n TEventMap extends Record,\n TMode extends \"standard\" | \"strict\"\n > = EventTarget &\n defineEventAttribute.EventAttributes\n}\n\n/**\n * Define an event attribute.\n * @param target The `EventTarget` object to define an event attribute.\n * @param type The event type to define.\n * @param _eventClass Unused, but to infer `Event` class type.\n * @deprecated Use `getEventAttributeValue`/`setEventAttributeValue` pair on your derived class instead because of static analysis friendly.\n */\nexport function defineEventAttribute<\n TEventTarget extends EventTarget,\n TEventType extends string,\n TEventConstrucor extends typeof Event\n>(\n target: TEventTarget,\n type: TEventType,\n _eventClass?: TEventConstrucor,\n): asserts target is TEventTarget &\n defineEventAttribute.EventAttributes<\n TEventTarget,\n Record>\n > {\n Object.defineProperty(target, `on${type}`, {\n get() {\n return getEventAttributeValue(this, type)\n },\n set(value) {\n setEventAttributeValue(this, type, value)\n },\n configurable: true,\n enumerable: true,\n })\n}\n\nexport namespace defineEventAttribute {\n /**\n * Definition of event attributes.\n */\n export type EventAttributes<\n TEventTarget extends EventTarget,\n TEventMap extends Record\n > = {\n [P in string &\n keyof TEventMap as `on${P}`]: EventTarget.CallbackFunction<\n TEventTarget,\n TEventMap[P]\n > | null\n }\n}\n"],"names":["internalDataMap","$","getEventInternalData","keys","getEventTargetInternalData"],"mappings":"AAAA;;;;;;SAMgB,UAAU,CACtB,SAAkB,EAClB,OAAe,EACf,GAAG,IAAW;IAEd,IAAI,CAAC,SAAS,EAAE;QACZ,MAAM,IAAI,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAA;KAC7C;AACL,CAAC;AAED;;;;;SAKgB,MAAM,CAAC,OAAe,EAAE,IAAW;IAC/C,IAAI,CAAC,GAAG,CAAC,CAAA;IACT,OAAO,OAAO,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA;AACnE,CAAC;AAED;;;;SAIgB,WAAW,CAAC,CAAM;IAC9B,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,EAAE;QACrC,OAAO,MAAM,CAAC,CAAC,CAAC,CAAA;KAC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IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,YAAY,GAAG,SAAS,CAAA;KACpD;AACL,CAAC;AAED;;;;;AAKA,SAAS,4BAA4B,CACjC,IAAkB;IAElB,OAAO,UAAU,KAAK;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAA;QAClC,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;YAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAA;SAC7B;KACJ,CAAA;AACL;;AC3GA;;;;;SAKgB,uBAAuB,CAInC,GAAG,KAAmC;IAEtC,MAAM,iBAAkB,SAAQ,WAAW;KAAG;IAC9C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;QACnC,oBAAoB,CAAC,iBAAiB,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAA;KAC9D;IAED,OAAO,iBAAwB,CAAA;AACnC,CAAC;AA8BD;;;;;;;SAOgB,oBAAoB,CAKhC,MAAoB,EACpB,IAAgB,EAChB,WAA8B;IAM9B,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,KAAK,IAAI,EAAE,EAAE;QACvC,GAAG;YACC,OAAO,sBAAsB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;SAC5C;QACD,GAAG,CAAC,KAAK;YACL,sBAAsB,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAA;SAC5C;QACD,YAAY,EAAE,IAAI;QAClB,UAAU,EAAE,IAAI;KACnB,CAAC,CAAA;AACN;;;;;"} \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..045cf8b --- /dev/null +++ b/package.json @@ -0,0 +1,112 @@ +{ + "name": "event-target-shim", + "version": "6.0.2", + "description": "An implementation of WHATWG EventTarget interface.", + "main": "index.js", + "exports": { + ".": { + "import": "./index.mjs", + "require": "./index.js" + }, + "./es5": { + "import": "./es5.mjs", + "require": "./es5.js" + }, + "./umd": "./umd.js", + "./package.json": "./package.json" + }, + "files": [ + "index.*", + "es5.*", + "umd.*" + ], + "engines": { + "node": ">=10.13.0" + }, + "scripts": { + "build": "run-s \"build:{clean,rollup,dts,meta}\"", + "build:clean": "rimraf \"dist/*\"", + "build:rollup": "rollup --config scripts/rollup.config.js", + "build:dts": "dts-bundle-generator --project tsconfig/dts.json --out-file dist/index.d.ts src/index.ts && dts-bundle-generator --project tsconfig/dts.json --out-file dist/es5.d.ts src/index.ts", + "build:meta": "cpx \"{LICENSE,package.json,README.md}\" dist/", + "preversion": "npm test", + "version": "npm run build", + "postversion": "release", + "test": "run-s \"test:{clean,tsc,lint,format,mocha}\"", + "test:clean": "rimraf \"coverage/*\"", + "test:tsc": "tsc -p tsconfig/build.json --noEmit", + "test:lint": "eslint .", + "test:format": "prettier --check .", + "test:mocha": "ts-node scripts/test", + "watch:mocha": "mocha --require ts-node/register/transpile-only --extensions ts --watch-files src,test --watch \"test/*.ts\"" + }, + "dependencies": {}, + "devDependencies": { + "@babel/core": "^7.12.10", + "@babel/plugin-transform-runtime": "^7.12.10", + "@babel/preset-env": "^7.12.11", + "@mysticatea/eslint-plugin": "^13.0.0", + "@mysticatea/spy": "^0.1.2", + "@mysticatea/tools": "^0.1.1", + "@rollup/plugin-babel": "^5.2.2", + "@rollup/plugin-typescript": "^8.1.0", + "@types/istanbul-lib-coverage": "^2.0.3", + "@types/istanbul-lib-report": "^3.0.0", + "@types/istanbul-lib-source-maps": "^4.0.1", + "@types/istanbul-reports": "^3.0.0", + "@types/mocha": "^8.2.0", + "@types/rimraf": "^3.0.0", + "assert": "^2.0.0", + "babel-loader": "^8.2.2", + "babel-plugin-istanbul": "^6.0.0", + "buffer": "^6.0.3", + "chalk": "^4.1.0", + "codecov": "^3.8.1", + "cpx": "^1.5.0", + "dts-bundle-generator": "^5.5.0", + "eslint": "^7.15.0", + "istanbul-lib-coverage": "^3.0.0", + "istanbul-lib-report": "^3.0.0", + "istanbul-lib-source-maps": "^4.0.0", + "istanbul-reports": "^3.0.2", + "mocha": "^7.2.0", + "npm-run-all": "^4.1.5", + "path-browserify": "^1.0.1", + "playwright": "^1.7.0", + "prettier": "~2.2.1", + "process": "^0.11.10", + "rimraf": "^3.0.2", + "rollup": "^2.35.1", + "rollup-plugin-terser": "^7.0.2", + "rollup-watch": "^4.3.1", + "stream-browserify": "^3.0.0", + "ts-loader": "^8.0.12", + "ts-node": "^9.1.1", + "tslib": "^2.0.3", + "typescript": "~4.1.3", + "url": "^0.11.0", + "util": "^0.12.3", + "webpack": "^5.11.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/mysticatea/event-target-shim.git" + }, + "keywords": [ + "w3c", + "whatwg", + "eventtarget", + "event", + "events", + "shim" + ], + "author": "Toru Nagashima", + "license": "MIT", + "bugs": { + "url": "https://github.com/mysticatea/event-target-shim/issues" + }, + "homepage": "https://github.com/mysticatea/event-target-shim", + "funding": "https://github.com/sponsors/mysticatea", + "sideEffects": false, + "unpkg": "umd.js" +} diff --git a/umd.js b/umd.js new file mode 100644 index 0000000..3d7bf2e --- /dev/null +++ b/umd.js @@ -0,0 +1 @@ +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).EventTargetShim={})}(this,(function(e){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var n=0;ne.length)&&(t=e.length);for(var n=0,r=new Array(t);n2?n-2:0),o=2;o1&&void 0!==arguments[1]&&arguments[1],n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=Y(this);r.dispatchFlag?S.warn():G.set(this,u(u({},r),{},{type:String(e),bubbles:Boolean(t),cancelable:Boolean(n),target:null,currentTarget:null,stopPropagationFlag:!1,stopImmediatePropagationFlag:!1,canceledFlag:!1}))}},{key:"type",get:function(){return Y(this).type}},{key:"target",get:function(){return Y(this).target}},{key:"srcElement",get:function(){return Y(this).target}},{key:"currentTarget",get:function(){return Y(this).currentTarget}},{key:"NONE",get:function(){return W}},{key:"CAPTURING_PHASE",get:function(){return V}},{key:"AT_TARGET",get:function(){return x}},{key:"BUBBLING_PHASE",get:function(){return H}},{key:"eventPhase",get:function(){return Y(this).dispatchFlag?2:0}},{key:"cancelBubble",get:function(){return Y(this).stopPropagationFlag},set:function(e){e?Y(this).stopPropagationFlag=!0:F.warn()}},{key:"bubbles",get:function(){return Y(this).bubbles}},{key:"cancelable",get:function(){return Y(this).cancelable}},{key:"returnValue",get:function(){return!Y(this).canceledFlag},set:function(e){e?D.warn():X(Y(this))}},{key:"defaultPrevented",get:function(){return Y(this).canceledFlag}},{key:"composed",get:function(){return Y(this).composed}},{key:"isTrusted",get:function(){return!1}},{key:"timeStamp",get:function(){return Y(this).timeStamp}}]),e}(),W=0,V=1,x=2,H=3,G=new WeakMap;function Y(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"this",n=G.get(e);return P(null!=n,"'%s' must be an object that Event constructor created, but got another one: %o",t,e),n}function X(e){e.inPassiveListenerFlag?N.warn():e.cancelable?e.canceledFlag=!0:I.warn()}Object.defineProperty(U,"NONE",{enumerable:!0}),Object.defineProperty(U,"CAPTURING_PHASE",{enumerable:!0}),Object.defineProperty(U,"AT_TARGET",{enumerable:!0}),Object.defineProperty(U,"BUBBLING_PHASE",{enumerable:!0});for(var Q,Z=Object.getOwnPropertyNames(U.prototype),z=0;z2&&void 0!==arguments[2]&&arguments[2],r=e.listeners[t];return oe(r),r.signal&&r.signal.removeEventListener("abort",r.signalListener),e.cow&&!n?(e.cow=!1,e.listeners=e.listeners.filter((function(e,n){return n!==t})),!1):(e.listeners.splice(t,1),!0)}function be(e,t){var n;return null!==(n=e[t])&&void 0!==n?n:e[t]={attrCallback:void 0,attrListener:void 0,cow:!1,listeners:[]}}te.set(Object.prototype,q),void 0!==_&&void 0!==_.Event&&te.set(_.Event.prototype,q);var ye=function(){function e(){n(this,e),ve.set(this,Object.create(null))}return o(e,[{key:"addEventListener",value:function(e,n,r){var o=de(this),a=function(e,n,r){var o;if(he(n),"object"===t(r)&&null!==r)return{type:String(e),callback:null!=n?n:void 0,capture:Boolean(r.capture),passive:Boolean(r.passive),once:Boolean(r.once),signal:null!==(o=r.signal)&&void 0!==o?o:void 0};return{type:String(e),callback:null!=n?n:void 0,capture:Boolean(r),passive:!1,once:!1,signal:void 0}}(e,n,r),i=a.callback,u=a.capture,c=a.once,l=a.passive,s=a.signal,f=a.type;if(null!=i&&!(null==s?void 0:s.aborted)){var p=be(o,f),g=se(p,i,u);-1===g?fe(p,i,u,l,c,s):function(e,t,n,r){B.warn(ae(e)?"capture":"bubble",e.callback),ie(e)!==t&&L.warn("passive");ue(e)!==n&&L.warn("once");e.signal!==r&&L.warn("signal")}(p.listeners[g],l,c,s)}}},{key:"removeEventListener",value:function(e,n,r){var o=de(this),a=function(e,n,r){if(he(n),"object"===t(r)&&null!==r)return{type:String(e),callback:null!=n?n:void 0,capture:Boolean(r.capture)};return{type:String(e),callback:null!=n?n:void 0,capture:Boolean(r)}}(e,n,r),i=a.callback,u=a.capture,c=o[a.type];null!=i&&c&&pe(c,i,u)}},{key:"dispatchEvent",value:function(e){var t=de(this)[String(e.type)];if(null==t)return!0;var r,a=e instanceof U?e:q.wrap(e),i=Y(a,"event");if(i.dispatchFlag)throw r="This event has been in dispatching.",_.DOMException?new _.DOMException(r,"InvalidStateError"):(null==Q&&(Q=function(e){c(r,e);var t=v(r);function r(e){var o;return n(this,r),o=t.call(this,e),Error.captureStackTrace&&Error.captureStackTrace(b(o),r),o}return o(r,[{key:"code",get:function(){return 11}},{key:"name",get:function(){return"InvalidStateError"}}]),r}(g(Error)),Object.defineProperties(Q.prototype,{code:{enumerable:!0},name:{enumerable:!0}}),$(Q),$(Q.prototype)),new Q(r));if(i.dispatchFlag=!0,i.target=i.currentTarget=this,!i.stopPropagationFlag){var u=t.cow,l=t.listeners;t.cow=!0;for(var s=0;s1&&void 0!==arguments[1]?arguments[1]:"this",n=ve.get(e);return P(null!=n,"'%s' must be an object that EventTarget constructor created, but got another one: %o",t,e),n}function he(e){if("function"!=typeof e&&("object"!==t(e)||null===e||"function"!=typeof e.handleEvent)){if(null!=e&&"object"!==t(e))throw new TypeError(R(C.message,[e]));C.warn(e)}}for(var Ee=Object.getOwnPropertyNames(ye.prototype),me=0;me