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