utils-lib-js 2.0.4 → 2.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1725,6 +1725,979 @@ var TaskQueue = (function () {
1725
1725
 
1726
1726
  __assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1(__assign$1({}, object), base), array), __function), element), __static), event), storage), log), animate), { eventMessageCenter: MessageCenter, taskQueueLib: TaskQueue });
1727
1727
 
1728
+ /**
1729
+ * @author Toru Nagashima <https://github.com/mysticatea>
1730
+ * @copyright 2015 Toru Nagashima. All rights reserved.
1731
+ * See LICENSE file in root directory for full license.
1732
+ */
1733
+ /**
1734
+ * @typedef {object} PrivateData
1735
+ * @property {EventTarget} eventTarget The event target.
1736
+ * @property {{type:string}} event The original event object.
1737
+ * @property {number} eventPhase The current event phase.
1738
+ * @property {EventTarget|null} currentTarget The current event target.
1739
+ * @property {boolean} canceled The flag to prevent default.
1740
+ * @property {boolean} stopped The flag to stop propagation.
1741
+ * @property {boolean} immediateStopped The flag to stop propagation immediately.
1742
+ * @property {Function|null} passiveListener The listener if the current listener is passive. Otherwise this is null.
1743
+ * @property {number} timeStamp The unix time.
1744
+ * @private
1745
+ */
1746
+
1747
+ /**
1748
+ * Private data for event wrappers.
1749
+ * @type {WeakMap<Event, PrivateData>}
1750
+ * @private
1751
+ */
1752
+ const privateData = new WeakMap();
1753
+
1754
+ /**
1755
+ * Cache for wrapper classes.
1756
+ * @type {WeakMap<Object, Function>}
1757
+ * @private
1758
+ */
1759
+ const wrappers = new WeakMap();
1760
+
1761
+ /**
1762
+ * Get private data.
1763
+ * @param {Event} event The event object to get private data.
1764
+ * @returns {PrivateData} The private data of the event.
1765
+ * @private
1766
+ */
1767
+ function pd(event) {
1768
+ const retv = privateData.get(event);
1769
+ console.assert(
1770
+ retv != null,
1771
+ "'this' is expected an Event object, but got",
1772
+ event
1773
+ );
1774
+ return retv
1775
+ }
1776
+
1777
+ /**
1778
+ * https://dom.spec.whatwg.org/#set-the-canceled-flag
1779
+ * @param data {PrivateData} private data.
1780
+ */
1781
+ function setCancelFlag(data) {
1782
+ if (data.passiveListener != null) {
1783
+ if (
1784
+ typeof console !== "undefined" &&
1785
+ typeof console.error === "function"
1786
+ ) {
1787
+ console.error(
1788
+ "Unable to preventDefault inside passive event listener invocation.",
1789
+ data.passiveListener
1790
+ );
1791
+ }
1792
+ return
1793
+ }
1794
+ if (!data.event.cancelable) {
1795
+ return
1796
+ }
1797
+
1798
+ data.canceled = true;
1799
+ if (typeof data.event.preventDefault === "function") {
1800
+ data.event.preventDefault();
1801
+ }
1802
+ }
1803
+
1804
+ /**
1805
+ * @see https://dom.spec.whatwg.org/#interface-event
1806
+ * @private
1807
+ */
1808
+ /**
1809
+ * The event wrapper.
1810
+ * @constructor
1811
+ * @param {EventTarget} eventTarget The event target of this dispatching.
1812
+ * @param {Event|{type:string}} event The original event to wrap.
1813
+ */
1814
+ function Event$1(eventTarget, event) {
1815
+ privateData.set(this, {
1816
+ eventTarget,
1817
+ event,
1818
+ eventPhase: 2,
1819
+ currentTarget: eventTarget,
1820
+ canceled: false,
1821
+ stopped: false,
1822
+ immediateStopped: false,
1823
+ passiveListener: null,
1824
+ timeStamp: event.timeStamp || Date.now(),
1825
+ });
1826
+
1827
+ // https://heycam.github.io/webidl/#Unforgeable
1828
+ Object.defineProperty(this, "isTrusted", { value: false, enumerable: true });
1829
+
1830
+ // Define accessors
1831
+ const keys = Object.keys(event);
1832
+ for (let i = 0; i < keys.length; ++i) {
1833
+ const key = keys[i];
1834
+ if (!(key in this)) {
1835
+ Object.defineProperty(this, key, defineRedirectDescriptor(key));
1836
+ }
1837
+ }
1838
+ }
1839
+
1840
+ // Should be enumerable, but class methods are not enumerable.
1841
+ Event$1.prototype = {
1842
+ /**
1843
+ * The type of this event.
1844
+ * @type {string}
1845
+ */
1846
+ get type() {
1847
+ return pd(this).event.type
1848
+ },
1849
+
1850
+ /**
1851
+ * The target of this event.
1852
+ * @type {EventTarget}
1853
+ */
1854
+ get target() {
1855
+ return pd(this).eventTarget
1856
+ },
1857
+
1858
+ /**
1859
+ * The target of this event.
1860
+ * @type {EventTarget}
1861
+ */
1862
+ get currentTarget() {
1863
+ return pd(this).currentTarget
1864
+ },
1865
+
1866
+ /**
1867
+ * @returns {EventTarget[]} The composed path of this event.
1868
+ */
1869
+ composedPath() {
1870
+ const currentTarget = pd(this).currentTarget;
1871
+ if (currentTarget == null) {
1872
+ return []
1873
+ }
1874
+ return [currentTarget]
1875
+ },
1876
+
1877
+ /**
1878
+ * Constant of NONE.
1879
+ * @type {number}
1880
+ */
1881
+ get NONE() {
1882
+ return 0
1883
+ },
1884
+
1885
+ /**
1886
+ * Constant of CAPTURING_PHASE.
1887
+ * @type {number}
1888
+ */
1889
+ get CAPTURING_PHASE() {
1890
+ return 1
1891
+ },
1892
+
1893
+ /**
1894
+ * Constant of AT_TARGET.
1895
+ * @type {number}
1896
+ */
1897
+ get AT_TARGET() {
1898
+ return 2
1899
+ },
1900
+
1901
+ /**
1902
+ * Constant of BUBBLING_PHASE.
1903
+ * @type {number}
1904
+ */
1905
+ get BUBBLING_PHASE() {
1906
+ return 3
1907
+ },
1908
+
1909
+ /**
1910
+ * The target of this event.
1911
+ * @type {number}
1912
+ */
1913
+ get eventPhase() {
1914
+ return pd(this).eventPhase
1915
+ },
1916
+
1917
+ /**
1918
+ * Stop event bubbling.
1919
+ * @returns {void}
1920
+ */
1921
+ stopPropagation() {
1922
+ const data = pd(this);
1923
+
1924
+ data.stopped = true;
1925
+ if (typeof data.event.stopPropagation === "function") {
1926
+ data.event.stopPropagation();
1927
+ }
1928
+ },
1929
+
1930
+ /**
1931
+ * Stop event bubbling.
1932
+ * @returns {void}
1933
+ */
1934
+ stopImmediatePropagation() {
1935
+ const data = pd(this);
1936
+
1937
+ data.stopped = true;
1938
+ data.immediateStopped = true;
1939
+ if (typeof data.event.stopImmediatePropagation === "function") {
1940
+ data.event.stopImmediatePropagation();
1941
+ }
1942
+ },
1943
+
1944
+ /**
1945
+ * The flag to be bubbling.
1946
+ * @type {boolean}
1947
+ */
1948
+ get bubbles() {
1949
+ return Boolean(pd(this).event.bubbles)
1950
+ },
1951
+
1952
+ /**
1953
+ * The flag to be cancelable.
1954
+ * @type {boolean}
1955
+ */
1956
+ get cancelable() {
1957
+ return Boolean(pd(this).event.cancelable)
1958
+ },
1959
+
1960
+ /**
1961
+ * Cancel this event.
1962
+ * @returns {void}
1963
+ */
1964
+ preventDefault() {
1965
+ setCancelFlag(pd(this));
1966
+ },
1967
+
1968
+ /**
1969
+ * The flag to indicate cancellation state.
1970
+ * @type {boolean}
1971
+ */
1972
+ get defaultPrevented() {
1973
+ return pd(this).canceled
1974
+ },
1975
+
1976
+ /**
1977
+ * The flag to be composed.
1978
+ * @type {boolean}
1979
+ */
1980
+ get composed() {
1981
+ return Boolean(pd(this).event.composed)
1982
+ },
1983
+
1984
+ /**
1985
+ * The unix time of this event.
1986
+ * @type {number}
1987
+ */
1988
+ get timeStamp() {
1989
+ return pd(this).timeStamp
1990
+ },
1991
+
1992
+ /**
1993
+ * The target of this event.
1994
+ * @type {EventTarget}
1995
+ * @deprecated
1996
+ */
1997
+ get srcElement() {
1998
+ return pd(this).eventTarget
1999
+ },
2000
+
2001
+ /**
2002
+ * The flag to stop event bubbling.
2003
+ * @type {boolean}
2004
+ * @deprecated
2005
+ */
2006
+ get cancelBubble() {
2007
+ return pd(this).stopped
2008
+ },
2009
+ set cancelBubble(value) {
2010
+ if (!value) {
2011
+ return
2012
+ }
2013
+ const data = pd(this);
2014
+
2015
+ data.stopped = true;
2016
+ if (typeof data.event.cancelBubble === "boolean") {
2017
+ data.event.cancelBubble = true;
2018
+ }
2019
+ },
2020
+
2021
+ /**
2022
+ * The flag to indicate cancellation state.
2023
+ * @type {boolean}
2024
+ * @deprecated
2025
+ */
2026
+ get returnValue() {
2027
+ return !pd(this).canceled
2028
+ },
2029
+ set returnValue(value) {
2030
+ if (!value) {
2031
+ setCancelFlag(pd(this));
2032
+ }
2033
+ },
2034
+
2035
+ /**
2036
+ * Initialize this event object. But do nothing under event dispatching.
2037
+ * @param {string} type The event type.
2038
+ * @param {boolean} [bubbles=false] The flag to be possible to bubble up.
2039
+ * @param {boolean} [cancelable=false] The flag to be possible to cancel.
2040
+ * @deprecated
2041
+ */
2042
+ initEvent() {
2043
+ // Do nothing.
2044
+ },
2045
+ };
2046
+
2047
+ // `constructor` is not enumerable.
2048
+ Object.defineProperty(Event$1.prototype, "constructor", {
2049
+ value: Event$1,
2050
+ configurable: true,
2051
+ writable: true,
2052
+ });
2053
+
2054
+ // Ensure `event instanceof window.Event` is `true`.
2055
+ if (typeof window !== "undefined" && typeof window.Event !== "undefined") {
2056
+ Object.setPrototypeOf(Event$1.prototype, window.Event.prototype);
2057
+
2058
+ // Make association for wrappers.
2059
+ wrappers.set(window.Event.prototype, Event$1);
2060
+ }
2061
+
2062
+ /**
2063
+ * Get the property descriptor to redirect a given property.
2064
+ * @param {string} key Property name to define property descriptor.
2065
+ * @returns {PropertyDescriptor} The property descriptor to redirect the property.
2066
+ * @private
2067
+ */
2068
+ function defineRedirectDescriptor(key) {
2069
+ return {
2070
+ get() {
2071
+ return pd(this).event[key]
2072
+ },
2073
+ set(value) {
2074
+ pd(this).event[key] = value;
2075
+ },
2076
+ configurable: true,
2077
+ enumerable: true,
2078
+ }
2079
+ }
2080
+
2081
+ /**
2082
+ * Get the property descriptor to call a given method property.
2083
+ * @param {string} key Property name to define property descriptor.
2084
+ * @returns {PropertyDescriptor} The property descriptor to call the method property.
2085
+ * @private
2086
+ */
2087
+ function defineCallDescriptor(key) {
2088
+ return {
2089
+ value() {
2090
+ const event = pd(this).event;
2091
+ return event[key].apply(event, arguments)
2092
+ },
2093
+ configurable: true,
2094
+ enumerable: true,
2095
+ }
2096
+ }
2097
+
2098
+ /**
2099
+ * Define new wrapper class.
2100
+ * @param {Function} BaseEvent The base wrapper class.
2101
+ * @param {Object} proto The prototype of the original event.
2102
+ * @returns {Function} The defined wrapper class.
2103
+ * @private
2104
+ */
2105
+ function defineWrapper(BaseEvent, proto) {
2106
+ const keys = Object.keys(proto);
2107
+ if (keys.length === 0) {
2108
+ return BaseEvent
2109
+ }
2110
+
2111
+ /** CustomEvent */
2112
+ function CustomEvent(eventTarget, event) {
2113
+ BaseEvent.call(this, eventTarget, event);
2114
+ }
2115
+
2116
+ CustomEvent.prototype = Object.create(BaseEvent.prototype, {
2117
+ constructor: { value: CustomEvent, configurable: true, writable: true },
2118
+ });
2119
+
2120
+ // Define accessors.
2121
+ for (let i = 0; i < keys.length; ++i) {
2122
+ const key = keys[i];
2123
+ if (!(key in BaseEvent.prototype)) {
2124
+ const descriptor = Object.getOwnPropertyDescriptor(proto, key);
2125
+ const isFunc = typeof descriptor.value === "function";
2126
+ Object.defineProperty(
2127
+ CustomEvent.prototype,
2128
+ key,
2129
+ isFunc
2130
+ ? defineCallDescriptor(key)
2131
+ : defineRedirectDescriptor(key)
2132
+ );
2133
+ }
2134
+ }
2135
+
2136
+ return CustomEvent
2137
+ }
2138
+
2139
+ /**
2140
+ * Get the wrapper class of a given prototype.
2141
+ * @param {Object} proto The prototype of the original event to get its wrapper.
2142
+ * @returns {Function} The wrapper class.
2143
+ * @private
2144
+ */
2145
+ function getWrapper(proto) {
2146
+ if (proto == null || proto === Object.prototype) {
2147
+ return Event$1
2148
+ }
2149
+
2150
+ let wrapper = wrappers.get(proto);
2151
+ if (wrapper == null) {
2152
+ wrapper = defineWrapper(getWrapper(Object.getPrototypeOf(proto)), proto);
2153
+ wrappers.set(proto, wrapper);
2154
+ }
2155
+ return wrapper
2156
+ }
2157
+
2158
+ /**
2159
+ * Wrap a given event to management a dispatching.
2160
+ * @param {EventTarget} eventTarget The event target of this dispatching.
2161
+ * @param {Object} event The event to wrap.
2162
+ * @returns {Event} The wrapper instance.
2163
+ * @private
2164
+ */
2165
+ function wrapEvent(eventTarget, event) {
2166
+ const Wrapper = getWrapper(Object.getPrototypeOf(event));
2167
+ return new Wrapper(eventTarget, event)
2168
+ }
2169
+
2170
+ /**
2171
+ * Get the immediateStopped flag of a given event.
2172
+ * @param {Event} event The event to get.
2173
+ * @returns {boolean} The flag to stop propagation immediately.
2174
+ * @private
2175
+ */
2176
+ function isStopped(event) {
2177
+ return pd(event).immediateStopped
2178
+ }
2179
+
2180
+ /**
2181
+ * Set the current event phase of a given event.
2182
+ * @param {Event} event The event to set current target.
2183
+ * @param {number} eventPhase New event phase.
2184
+ * @returns {void}
2185
+ * @private
2186
+ */
2187
+ function setEventPhase(event, eventPhase) {
2188
+ pd(event).eventPhase = eventPhase;
2189
+ }
2190
+
2191
+ /**
2192
+ * Set the current target of a given event.
2193
+ * @param {Event} event The event to set current target.
2194
+ * @param {EventTarget|null} currentTarget New current target.
2195
+ * @returns {void}
2196
+ * @private
2197
+ */
2198
+ function setCurrentTarget(event, currentTarget) {
2199
+ pd(event).currentTarget = currentTarget;
2200
+ }
2201
+
2202
+ /**
2203
+ * Set a passive listener of a given event.
2204
+ * @param {Event} event The event to set current target.
2205
+ * @param {Function|null} passiveListener New passive listener.
2206
+ * @returns {void}
2207
+ * @private
2208
+ */
2209
+ function setPassiveListener(event, passiveListener) {
2210
+ pd(event).passiveListener = passiveListener;
2211
+ }
2212
+
2213
+ /**
2214
+ * @typedef {object} ListenerNode
2215
+ * @property {Function} listener
2216
+ * @property {1|2|3} listenerType
2217
+ * @property {boolean} passive
2218
+ * @property {boolean} once
2219
+ * @property {ListenerNode|null} next
2220
+ * @private
2221
+ */
2222
+
2223
+ /**
2224
+ * @type {WeakMap<object, Map<string, ListenerNode>>}
2225
+ * @private
2226
+ */
2227
+ const listenersMap = new WeakMap();
2228
+
2229
+ // Listener types
2230
+ const CAPTURE = 1;
2231
+ const BUBBLE = 2;
2232
+ const ATTRIBUTE = 3;
2233
+
2234
+ /**
2235
+ * Check whether a given value is an object or not.
2236
+ * @param {any} x The value to check.
2237
+ * @returns {boolean} `true` if the value is an object.
2238
+ */
2239
+ function isObject(x) {
2240
+ return x !== null && typeof x === "object" //eslint-disable-line no-restricted-syntax
2241
+ }
2242
+
2243
+ /**
2244
+ * Get listeners.
2245
+ * @param {EventTarget} eventTarget The event target to get.
2246
+ * @returns {Map<string, ListenerNode>} The listeners.
2247
+ * @private
2248
+ */
2249
+ function getListeners(eventTarget) {
2250
+ const listeners = listenersMap.get(eventTarget);
2251
+ if (listeners == null) {
2252
+ throw new TypeError(
2253
+ "'this' is expected an EventTarget object, but got another value."
2254
+ )
2255
+ }
2256
+ return listeners
2257
+ }
2258
+
2259
+ /**
2260
+ * Get the property descriptor for the event attribute of a given event.
2261
+ * @param {string} eventName The event name to get property descriptor.
2262
+ * @returns {PropertyDescriptor} The property descriptor.
2263
+ * @private
2264
+ */
2265
+ function defineEventAttributeDescriptor(eventName) {
2266
+ return {
2267
+ get() {
2268
+ const listeners = getListeners(this);
2269
+ let node = listeners.get(eventName);
2270
+ while (node != null) {
2271
+ if (node.listenerType === ATTRIBUTE) {
2272
+ return node.listener
2273
+ }
2274
+ node = node.next;
2275
+ }
2276
+ return null
2277
+ },
2278
+
2279
+ set(listener) {
2280
+ if (typeof listener !== "function" && !isObject(listener)) {
2281
+ listener = null; // eslint-disable-line no-param-reassign
2282
+ }
2283
+ const listeners = getListeners(this);
2284
+
2285
+ // Traverse to the tail while removing old value.
2286
+ let prev = null;
2287
+ let node = listeners.get(eventName);
2288
+ while (node != null) {
2289
+ if (node.listenerType === ATTRIBUTE) {
2290
+ // Remove old value.
2291
+ if (prev !== null) {
2292
+ prev.next = node.next;
2293
+ } else if (node.next !== null) {
2294
+ listeners.set(eventName, node.next);
2295
+ } else {
2296
+ listeners.delete(eventName);
2297
+ }
2298
+ } else {
2299
+ prev = node;
2300
+ }
2301
+
2302
+ node = node.next;
2303
+ }
2304
+
2305
+ // Add new value.
2306
+ if (listener !== null) {
2307
+ const newNode = {
2308
+ listener,
2309
+ listenerType: ATTRIBUTE,
2310
+ passive: false,
2311
+ once: false,
2312
+ next: null,
2313
+ };
2314
+ if (prev === null) {
2315
+ listeners.set(eventName, newNode);
2316
+ } else {
2317
+ prev.next = newNode;
2318
+ }
2319
+ }
2320
+ },
2321
+ configurable: true,
2322
+ enumerable: true,
2323
+ }
2324
+ }
2325
+
2326
+ /**
2327
+ * Define an event attribute (e.g. `eventTarget.onclick`).
2328
+ * @param {Object} eventTargetPrototype The event target prototype to define an event attrbite.
2329
+ * @param {string} eventName The event name to define.
2330
+ * @returns {void}
2331
+ */
2332
+ function defineEventAttribute(eventTargetPrototype, eventName) {
2333
+ Object.defineProperty(
2334
+ eventTargetPrototype,
2335
+ `on${eventName}`,
2336
+ defineEventAttributeDescriptor(eventName)
2337
+ );
2338
+ }
2339
+
2340
+ /**
2341
+ * Define a custom EventTarget with event attributes.
2342
+ * @param {string[]} eventNames Event names for event attributes.
2343
+ * @returns {EventTarget} The custom EventTarget.
2344
+ * @private
2345
+ */
2346
+ function defineCustomEventTarget(eventNames) {
2347
+ /** CustomEventTarget */
2348
+ function CustomEventTarget() {
2349
+ EventTarget.call(this);
2350
+ }
2351
+
2352
+ CustomEventTarget.prototype = Object.create(EventTarget.prototype, {
2353
+ constructor: {
2354
+ value: CustomEventTarget,
2355
+ configurable: true,
2356
+ writable: true,
2357
+ },
2358
+ });
2359
+
2360
+ for (let i = 0; i < eventNames.length; ++i) {
2361
+ defineEventAttribute(CustomEventTarget.prototype, eventNames[i]);
2362
+ }
2363
+
2364
+ return CustomEventTarget
2365
+ }
2366
+
2367
+ /**
2368
+ * EventTarget.
2369
+ *
2370
+ * - This is constructor if no arguments.
2371
+ * - This is a function which returns a CustomEventTarget constructor if there are arguments.
2372
+ *
2373
+ * For example:
2374
+ *
2375
+ * class A extends EventTarget {}
2376
+ * class B extends EventTarget("message") {}
2377
+ * class C extends EventTarget("message", "error") {}
2378
+ * class D extends EventTarget(["message", "error"]) {}
2379
+ */
2380
+ function EventTarget() {
2381
+ /*eslint-disable consistent-return */
2382
+ if (this instanceof EventTarget) {
2383
+ listenersMap.set(this, new Map());
2384
+ return
2385
+ }
2386
+ if (arguments.length === 1 && Array.isArray(arguments[0])) {
2387
+ return defineCustomEventTarget(arguments[0])
2388
+ }
2389
+ if (arguments.length > 0) {
2390
+ const types = new Array(arguments.length);
2391
+ for (let i = 0; i < arguments.length; ++i) {
2392
+ types[i] = arguments[i];
2393
+ }
2394
+ return defineCustomEventTarget(types)
2395
+ }
2396
+ throw new TypeError("Cannot call a class as a function")
2397
+ /*eslint-enable consistent-return */
2398
+ }
2399
+
2400
+ // Should be enumerable, but class methods are not enumerable.
2401
+ EventTarget.prototype = {
2402
+ /**
2403
+ * Add a given listener to this event target.
2404
+ * @param {string} eventName The event name to add.
2405
+ * @param {Function} listener The listener to add.
2406
+ * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
2407
+ * @returns {void}
2408
+ */
2409
+ addEventListener(eventName, listener, options) {
2410
+ if (listener == null) {
2411
+ return
2412
+ }
2413
+ if (typeof listener !== "function" && !isObject(listener)) {
2414
+ throw new TypeError("'listener' should be a function or an object.")
2415
+ }
2416
+
2417
+ const listeners = getListeners(this);
2418
+ const optionsIsObj = isObject(options);
2419
+ const capture = optionsIsObj
2420
+ ? Boolean(options.capture)
2421
+ : Boolean(options);
2422
+ const listenerType = capture ? CAPTURE : BUBBLE;
2423
+ const newNode = {
2424
+ listener,
2425
+ listenerType,
2426
+ passive: optionsIsObj && Boolean(options.passive),
2427
+ once: optionsIsObj && Boolean(options.once),
2428
+ next: null,
2429
+ };
2430
+
2431
+ // Set it as the first node if the first node is null.
2432
+ let node = listeners.get(eventName);
2433
+ if (node === undefined) {
2434
+ listeners.set(eventName, newNode);
2435
+ return
2436
+ }
2437
+
2438
+ // Traverse to the tail while checking duplication..
2439
+ let prev = null;
2440
+ while (node != null) {
2441
+ if (
2442
+ node.listener === listener &&
2443
+ node.listenerType === listenerType
2444
+ ) {
2445
+ // Should ignore duplication.
2446
+ return
2447
+ }
2448
+ prev = node;
2449
+ node = node.next;
2450
+ }
2451
+
2452
+ // Add it.
2453
+ prev.next = newNode;
2454
+ },
2455
+
2456
+ /**
2457
+ * Remove a given listener from this event target.
2458
+ * @param {string} eventName The event name to remove.
2459
+ * @param {Function} listener The listener to remove.
2460
+ * @param {boolean|{capture?:boolean,passive?:boolean,once?:boolean}} [options] The options for this listener.
2461
+ * @returns {void}
2462
+ */
2463
+ removeEventListener(eventName, listener, options) {
2464
+ if (listener == null) {
2465
+ return
2466
+ }
2467
+
2468
+ const listeners = getListeners(this);
2469
+ const capture = isObject(options)
2470
+ ? Boolean(options.capture)
2471
+ : Boolean(options);
2472
+ const listenerType = capture ? CAPTURE : BUBBLE;
2473
+
2474
+ let prev = null;
2475
+ let node = listeners.get(eventName);
2476
+ while (node != null) {
2477
+ if (
2478
+ node.listener === listener &&
2479
+ node.listenerType === listenerType
2480
+ ) {
2481
+ if (prev !== null) {
2482
+ prev.next = node.next;
2483
+ } else if (node.next !== null) {
2484
+ listeners.set(eventName, node.next);
2485
+ } else {
2486
+ listeners.delete(eventName);
2487
+ }
2488
+ return
2489
+ }
2490
+
2491
+ prev = node;
2492
+ node = node.next;
2493
+ }
2494
+ },
2495
+
2496
+ /**
2497
+ * Dispatch a given event.
2498
+ * @param {Event|{type:string}} event The event to dispatch.
2499
+ * @returns {boolean} `false` if canceled.
2500
+ */
2501
+ dispatchEvent(event) {
2502
+ if (event == null || typeof event.type !== "string") {
2503
+ throw new TypeError('"event.type" should be a string.')
2504
+ }
2505
+
2506
+ // If listeners aren't registered, terminate.
2507
+ const listeners = getListeners(this);
2508
+ const eventName = event.type;
2509
+ let node = listeners.get(eventName);
2510
+ if (node == null) {
2511
+ return true
2512
+ }
2513
+
2514
+ // Since we cannot rewrite several properties, so wrap object.
2515
+ const wrappedEvent = wrapEvent(this, event);
2516
+
2517
+ // This doesn't process capturing phase and bubbling phase.
2518
+ // This isn't participating in a tree.
2519
+ let prev = null;
2520
+ while (node != null) {
2521
+ // Remove this listener if it's once
2522
+ if (node.once) {
2523
+ if (prev !== null) {
2524
+ prev.next = node.next;
2525
+ } else if (node.next !== null) {
2526
+ listeners.set(eventName, node.next);
2527
+ } else {
2528
+ listeners.delete(eventName);
2529
+ }
2530
+ } else {
2531
+ prev = node;
2532
+ }
2533
+
2534
+ // Call this listener
2535
+ setPassiveListener(
2536
+ wrappedEvent,
2537
+ node.passive ? node.listener : null
2538
+ );
2539
+ if (typeof node.listener === "function") {
2540
+ try {
2541
+ node.listener.call(this, wrappedEvent);
2542
+ } catch (err) {
2543
+ if (
2544
+ typeof console !== "undefined" &&
2545
+ typeof console.error === "function"
2546
+ ) {
2547
+ console.error(err);
2548
+ }
2549
+ }
2550
+ } else if (
2551
+ node.listenerType !== ATTRIBUTE &&
2552
+ typeof node.listener.handleEvent === "function"
2553
+ ) {
2554
+ node.listener.handleEvent(wrappedEvent);
2555
+ }
2556
+
2557
+ // Break if `event.stopImmediatePropagation` was called.
2558
+ if (isStopped(wrappedEvent)) {
2559
+ break
2560
+ }
2561
+
2562
+ node = node.next;
2563
+ }
2564
+ setPassiveListener(wrappedEvent, null);
2565
+ setEventPhase(wrappedEvent, 0);
2566
+ setCurrentTarget(wrappedEvent, null);
2567
+
2568
+ return !wrappedEvent.defaultPrevented
2569
+ },
2570
+ };
2571
+
2572
+ // `constructor` is not enumerable.
2573
+ Object.defineProperty(EventTarget.prototype, "constructor", {
2574
+ value: EventTarget,
2575
+ configurable: true,
2576
+ writable: true,
2577
+ });
2578
+
2579
+ // Ensure `eventTarget instanceof window.EventTarget` is `true`.
2580
+ if (
2581
+ typeof window !== "undefined" &&
2582
+ typeof window.EventTarget !== "undefined"
2583
+ ) {
2584
+ Object.setPrototypeOf(EventTarget.prototype, window.EventTarget.prototype);
2585
+ }
2586
+
2587
+ /**
2588
+ * @author Toru Nagashima <https://github.com/mysticatea>
2589
+ * See LICENSE file in root directory for full license.
2590
+ */
2591
+
2592
+ /**
2593
+ * The signal class.
2594
+ * @see https://dom.spec.whatwg.org/#abortsignal
2595
+ */
2596
+ class AbortSignal extends EventTarget {
2597
+ /**
2598
+ * AbortSignal cannot be constructed directly.
2599
+ */
2600
+ constructor() {
2601
+ super();
2602
+ throw new TypeError("AbortSignal cannot be constructed directly");
2603
+ }
2604
+ /**
2605
+ * Returns `true` if this `AbortSignal`'s `AbortController` has signaled to abort, and `false` otherwise.
2606
+ */
2607
+ get aborted() {
2608
+ const aborted = abortedFlags.get(this);
2609
+ if (typeof aborted !== "boolean") {
2610
+ throw new TypeError(`Expected 'this' to be an 'AbortSignal' object, but got ${this === null ? "null" : typeof this}`);
2611
+ }
2612
+ return aborted;
2613
+ }
2614
+ }
2615
+ defineEventAttribute(AbortSignal.prototype, "abort");
2616
+ /**
2617
+ * Create an AbortSignal object.
2618
+ */
2619
+ function createAbortSignal() {
2620
+ const signal = Object.create(AbortSignal.prototype);
2621
+ EventTarget.call(signal);
2622
+ abortedFlags.set(signal, false);
2623
+ return signal;
2624
+ }
2625
+ /**
2626
+ * Abort a given signal.
2627
+ */
2628
+ function abortSignal(signal) {
2629
+ if (abortedFlags.get(signal) !== false) {
2630
+ return;
2631
+ }
2632
+ abortedFlags.set(signal, true);
2633
+ signal.dispatchEvent({ type: "abort" });
2634
+ }
2635
+ /**
2636
+ * Aborted flag for each instances.
2637
+ */
2638
+ const abortedFlags = new WeakMap();
2639
+ // Properties should be enumerable.
2640
+ Object.defineProperties(AbortSignal.prototype, {
2641
+ aborted: { enumerable: true },
2642
+ });
2643
+ // `toString()` should return `"[object AbortSignal]"`
2644
+ if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
2645
+ Object.defineProperty(AbortSignal.prototype, Symbol.toStringTag, {
2646
+ configurable: true,
2647
+ value: "AbortSignal",
2648
+ });
2649
+ }
2650
+
2651
+ /**
2652
+ * The AbortController.
2653
+ * @see https://dom.spec.whatwg.org/#abortcontroller
2654
+ */
2655
+ let AbortController$1 = class AbortController {
2656
+ /**
2657
+ * Initialize this controller.
2658
+ */
2659
+ constructor() {
2660
+ signals.set(this, createAbortSignal());
2661
+ }
2662
+ /**
2663
+ * Returns the `AbortSignal` object associated with this object.
2664
+ */
2665
+ get signal() {
2666
+ return getSignal(this);
2667
+ }
2668
+ /**
2669
+ * Abort and signal to any observers that the associated activity is to be aborted.
2670
+ */
2671
+ abort() {
2672
+ abortSignal(getSignal(this));
2673
+ }
2674
+ };
2675
+ /**
2676
+ * Associated signals.
2677
+ */
2678
+ const signals = new WeakMap();
2679
+ /**
2680
+ * Get the associated signal of a given controller.
2681
+ */
2682
+ function getSignal(controller) {
2683
+ const signal = signals.get(controller);
2684
+ if (signal == null) {
2685
+ throw new TypeError(`Expected 'this' to be an 'AbortController' object, but got ${controller === null ? "null" : typeof controller}`);
2686
+ }
2687
+ return signal;
2688
+ }
2689
+ // Properties should be enumerable.
2690
+ Object.defineProperties(AbortController$1.prototype, {
2691
+ signal: { enumerable: true },
2692
+ abort: { enumerable: true },
2693
+ });
2694
+ if (typeof Symbol === "function" && typeof Symbol.toStringTag === "symbol") {
2695
+ Object.defineProperty(AbortController$1.prototype, Symbol.toStringTag, {
2696
+ configurable: true,
2697
+ value: "AbortController",
2698
+ });
2699
+ }
2700
+
1728
2701
  /******************************************************************************
1729
2702
  Copyright (c) Microsoft Corporation.
1730
2703
 
@@ -1788,20 +2761,21 @@ var CustomAbortController;
1788
2761
  var httpRequest;
1789
2762
  var httpsRequest;
1790
2763
  var parse;
1791
- if (typeof window !== 'undefined') {
1792
- CustomAbortController = AbortController;
2764
+ var hasAbort = typeof AbortController !== "undefined";
2765
+ if (typeof window !== 'undefined' || hasAbort) {
2766
+ CustomAbortController = globalThis.AbortController;
1793
2767
  }
1794
2768
  else if (typeof require !== "undefined") {
1795
- CustomAbortController = require("abort-controller");
1796
2769
  httpRequest = require("http").request;
1797
2770
  httpsRequest = require("https").request;
1798
2771
  parse = require("url").parse;
2772
+ CustomAbortController = require('abort-controller');
1799
2773
  }
1800
2774
  else if (typeof globalThis === "object") {
1801
2775
  httpRequest = http.request;
1802
2776
  httpsRequest = https.request;
1803
2777
  parse = url.parse;
1804
- CustomAbortController = globalThis.AbortController;
2778
+ CustomAbortController = AbortController$1;
1805
2779
  }
1806
2780
  else {
1807
2781
  CustomAbortController = function () {