@oscarpalmer/atoms 0.189.0 → 0.190.0
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/beacon.d.mts +51 -31
- package/dist/beacon.mjs +163 -141
- package/dist/color/index.d.mts +1 -2
- package/dist/color/index.mjs +2 -2
- package/dist/color/instance.d.mts +3 -167
- package/dist/color/instance.mjs +58 -217
- package/dist/color/misc/get.d.mts +1 -2
- package/dist/color/misc/get.mjs +3 -3
- package/dist/color/misc/index.d.mts +4 -4
- package/dist/color/misc/index.mjs +9 -9
- package/dist/color/misc/is.d.mts +1 -2
- package/dist/color/misc/is.mjs +5 -2
- package/dist/color/models.d.mts +158 -2
- package/dist/function/memoize.d.mts +3 -9
- package/dist/function/memoize.mjs +43 -90
- package/dist/function/once.mjs +16 -4
- package/dist/herald.d.mts +19 -15
- package/dist/herald.mjs +79 -89
- package/dist/index.d.mts +173 -162
- package/dist/index.mjs +754 -996
- package/dist/internal/result.d.mts +6 -6
- package/dist/internal/result.mjs +1 -1
- package/dist/internal/value/has.d.mts +2 -2
- package/dist/logger.d.mts +7 -7
- package/dist/logger.mjs +72 -51
- package/dist/promise/helpers.d.mts +2 -2
- package/dist/promise/helpers.mjs +2 -2
- package/dist/queue.d.mts +24 -12
- package/dist/queue.mjs +288 -346
- package/dist/string/fuzzy.d.mts +4 -13
- package/dist/string/fuzzy.mjs +15 -41
- package/package.json +2 -2
- package/src/beacon.ts +262 -160
- package/src/color/index.ts +8 -8
- package/src/color/instance.ts +82 -258
- package/src/color/misc/get.ts +4 -4
- package/src/color/misc/index.ts +10 -11
- package/src/color/misc/is.ts +4 -1
- package/src/color/models.ts +180 -2
- package/src/function/memoize.ts +74 -65
- package/src/function/once.ts +4 -0
- package/src/herald.ts +136 -94
- package/src/internal/result.ts +6 -6
- package/src/internal/value/has.ts +2 -2
- package/src/logger.ts +93 -42
- package/src/promise/helpers.ts +2 -2
- package/src/queue.ts +480 -375
- package/src/string/fuzzy.ts +36 -31
package/dist/index.mjs
CHANGED
|
@@ -1390,7 +1390,7 @@ function isOk(value) {
|
|
|
1390
1390
|
* Is the value a _Result_?
|
|
1391
1391
|
*
|
|
1392
1392
|
* @param value Value to check
|
|
1393
|
-
* @returns `true` if the value is a _Result_, `false`
|
|
1393
|
+
* @returns `true` if the value is a _Result_, otherwise `false`
|
|
1394
1394
|
*/
|
|
1395
1395
|
function isResult(value) {
|
|
1396
1396
|
return isResultValue(value, true) || isResultValue(value, false);
|
|
@@ -1735,95 +1735,6 @@ var SizedMap = class extends Map {
|
|
|
1735
1735
|
};
|
|
1736
1736
|
//#endregion
|
|
1737
1737
|
//#region src/function/memoize.ts
|
|
1738
|
-
/**
|
|
1739
|
-
* A _Memoized_ function instance, caching and retrieving results based on the its parameters _(or a custom cache key)_
|
|
1740
|
-
*/
|
|
1741
|
-
var Memoized = class {
|
|
1742
|
-
#state;
|
|
1743
|
-
/**
|
|
1744
|
-
* Maximum cache size
|
|
1745
|
-
*
|
|
1746
|
-
* @returns Maximum cache size _(or `Number.NaN` if the instance has been destroyed)_
|
|
1747
|
-
*/
|
|
1748
|
-
get maximum() {
|
|
1749
|
-
return this.#state.cache?.maximum ?? NaN;
|
|
1750
|
-
}
|
|
1751
|
-
/**
|
|
1752
|
-
* Current cache size
|
|
1753
|
-
*
|
|
1754
|
-
* @returns Current cache size _(or `Number.NaN` if the instance has been destroyed)_
|
|
1755
|
-
*/
|
|
1756
|
-
get size() {
|
|
1757
|
-
return this.#state.cache?.size ?? NaN;
|
|
1758
|
-
}
|
|
1759
|
-
constructor(callback, options) {
|
|
1760
|
-
const cache = new SizedMap(options.cacheSize);
|
|
1761
|
-
const getter = (...parameters) => {
|
|
1762
|
-
const key = options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), SEPARATOR));
|
|
1763
|
-
if (cache.has(key)) return cache.get(key);
|
|
1764
|
-
const value = callback(...parameters);
|
|
1765
|
-
cache.set(key, value);
|
|
1766
|
-
return value;
|
|
1767
|
-
};
|
|
1768
|
-
this.#state = {
|
|
1769
|
-
cache,
|
|
1770
|
-
getter
|
|
1771
|
-
};
|
|
1772
|
-
}
|
|
1773
|
-
/**
|
|
1774
|
-
* Clear the cache
|
|
1775
|
-
*/
|
|
1776
|
-
clear() {
|
|
1777
|
-
this.#state.cache?.clear();
|
|
1778
|
-
}
|
|
1779
|
-
/**
|
|
1780
|
-
* Delete a result from the cache
|
|
1781
|
-
*
|
|
1782
|
-
* @param key Key to delete
|
|
1783
|
-
* @returns `true` if the key existed and was removed, otherwise `false`
|
|
1784
|
-
*/
|
|
1785
|
-
delete(key) {
|
|
1786
|
-
return this.#state.cache?.delete(key) ?? false;
|
|
1787
|
-
}
|
|
1788
|
-
/**
|
|
1789
|
-
* Destroy the instance
|
|
1790
|
-
*
|
|
1791
|
-
* _(When a Memoized instance is destroyed, its cache and callback are removed, and calls to `run` will throw an error)_
|
|
1792
|
-
*/
|
|
1793
|
-
destroy() {
|
|
1794
|
-
this.#state.cache?.clear();
|
|
1795
|
-
this.#state.cache = void 0;
|
|
1796
|
-
this.#state.getter = void 0;
|
|
1797
|
-
}
|
|
1798
|
-
/**
|
|
1799
|
-
* Get a result from the cache
|
|
1800
|
-
*
|
|
1801
|
-
* @param key Key to get
|
|
1802
|
-
* @returns Cached result or `undefined` if it does not exist
|
|
1803
|
-
*/
|
|
1804
|
-
get(key) {
|
|
1805
|
-
return this.#state.cache?.get(key);
|
|
1806
|
-
}
|
|
1807
|
-
/**
|
|
1808
|
-
* Does the result exist?
|
|
1809
|
-
*
|
|
1810
|
-
* @param key Key to check
|
|
1811
|
-
* @returns `true` if the result exists, otherwise `false`
|
|
1812
|
-
*/
|
|
1813
|
-
has(key) {
|
|
1814
|
-
return this.#state.cache?.has(key) ?? false;
|
|
1815
|
-
}
|
|
1816
|
-
/**
|
|
1817
|
-
* Run the callback with the provided parameters
|
|
1818
|
-
*
|
|
1819
|
-
* @param parameters Parameters to pass to the callback
|
|
1820
|
-
* @returns Cached or computed _(then cached)_ result
|
|
1821
|
-
*/
|
|
1822
|
-
run(...parameters) {
|
|
1823
|
-
if (this.#state.cache == null || this.#state.getter == null) throw new Error(MEMOIZED_ERROR_DESTROYED);
|
|
1824
|
-
return this.#state.getter(...parameters);
|
|
1825
|
-
}
|
|
1826
|
-
};
|
|
1827
1738
|
function getMemoizationOptions(input) {
|
|
1828
1739
|
const { cacheKey, cacheSize } = isPlainObject(input) ? input : {};
|
|
1829
1740
|
return {
|
|
@@ -1840,7 +1751,49 @@ function getMemoizationOptions(input) {
|
|
|
1840
1751
|
*/
|
|
1841
1752
|
function memoize(callback, options) {
|
|
1842
1753
|
if (typeof callback !== "function") throw new TypeError(MEMOIZED_ERROR_CALLBACK);
|
|
1843
|
-
|
|
1754
|
+
const state = { options: getMemoizationOptions(options) };
|
|
1755
|
+
state.cache = new SizedMap(state.options.cacheSize);
|
|
1756
|
+
state.getter = (...parameters) => {
|
|
1757
|
+
const key = state.options.cacheKey?.(...parameters) ?? (parameters.length === 1 ? parameters[0] : join(parameters.map(getString), SEPARATOR));
|
|
1758
|
+
if (state.cache.has(key)) return state.cache.get(key);
|
|
1759
|
+
const value = callback(...parameters);
|
|
1760
|
+
state.cache?.set(key, value);
|
|
1761
|
+
return value;
|
|
1762
|
+
};
|
|
1763
|
+
const instance = {
|
|
1764
|
+
clear: () => {
|
|
1765
|
+
state.cache?.clear();
|
|
1766
|
+
},
|
|
1767
|
+
delete: (key) => {
|
|
1768
|
+
return state.cache?.delete(key) ?? false;
|
|
1769
|
+
},
|
|
1770
|
+
destroy: () => {
|
|
1771
|
+
state.cache?.clear();
|
|
1772
|
+
state.cache = void 0;
|
|
1773
|
+
state.getter = void 0;
|
|
1774
|
+
},
|
|
1775
|
+
get: (key) => {
|
|
1776
|
+
return state.cache?.get(key);
|
|
1777
|
+
},
|
|
1778
|
+
has: (key) => {
|
|
1779
|
+
return state.cache?.has(key) ?? false;
|
|
1780
|
+
},
|
|
1781
|
+
run: (...parameters) => {
|
|
1782
|
+
if (state.cache == null || state.getter == null) throw new Error(MEMOIZED_ERROR_DESTROYED);
|
|
1783
|
+
return state.getter(...parameters);
|
|
1784
|
+
}
|
|
1785
|
+
};
|
|
1786
|
+
Object.defineProperties(instance, {
|
|
1787
|
+
maximum: {
|
|
1788
|
+
enumerable: true,
|
|
1789
|
+
get: () => state.cache?.maximum ?? NaN
|
|
1790
|
+
},
|
|
1791
|
+
size: {
|
|
1792
|
+
enumerable: true,
|
|
1793
|
+
get: () => state.cache?.size ?? NaN
|
|
1794
|
+
}
|
|
1795
|
+
});
|
|
1796
|
+
return Object.freeze(instance);
|
|
1844
1797
|
}
|
|
1845
1798
|
const DEFAULT_CACHE_SIZE = 1024;
|
|
1846
1799
|
const MEMOIZED_ERROR_CALLBACK = "Memoized requires a callback function";
|
|
@@ -2029,10 +1982,22 @@ function asyncOnce(callback) {
|
|
|
2029
1982
|
});
|
|
2030
1983
|
};
|
|
2031
1984
|
Object.defineProperties(fn, {
|
|
2032
|
-
called: {
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
1985
|
+
called: {
|
|
1986
|
+
enumerable: true,
|
|
1987
|
+
get: () => state.called
|
|
1988
|
+
},
|
|
1989
|
+
cleared: {
|
|
1990
|
+
enumerable: true,
|
|
1991
|
+
get: () => state.cleared
|
|
1992
|
+
},
|
|
1993
|
+
error: {
|
|
1994
|
+
enumerable: true,
|
|
1995
|
+
get: () => state.error
|
|
1996
|
+
},
|
|
1997
|
+
finished: {
|
|
1998
|
+
enumerable: true,
|
|
1999
|
+
get: () => state.finished
|
|
2000
|
+
}
|
|
2036
2001
|
});
|
|
2037
2002
|
fn.clear = () => {
|
|
2038
2003
|
if (!state.called || !state.finished || state.cleared) return;
|
|
@@ -2235,93 +2200,17 @@ const assertFlowFunctions = assert.condition((value) => Array.isArray(value) &&
|
|
|
2235
2200
|
const assertPipeFunctions = assert.condition((value) => Array.isArray(value) && value.every((item) => typeof item === "function"), MESSAGE_PIPE_ARRAY, TypeError);
|
|
2236
2201
|
//#endregion
|
|
2237
2202
|
//#region src/herald.ts
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
}
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
*/
|
|
2250
|
-
subscribe(event, callback) {
|
|
2251
|
-
return this.#herald.subscribe(event, callback);
|
|
2252
|
-
}
|
|
2253
|
-
/**
|
|
2254
|
-
* Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
|
|
2255
|
-
*
|
|
2256
|
-
* @param event Event name
|
|
2257
|
-
* @param callback Callback function
|
|
2258
|
-
* @returns Unsubscriber function
|
|
2259
|
-
*/
|
|
2260
|
-
unsubscribe(event, callback) {
|
|
2261
|
-
return this.#herald.unsubscribe(event, callback);
|
|
2262
|
-
}
|
|
2263
|
-
};
|
|
2264
|
-
/**
|
|
2265
|
-
* A _Herald_ is an announcer for named events, allowing emission, subscription, and unsubscription of events
|
|
2266
|
-
*/
|
|
2267
|
-
var Herald = class {
|
|
2268
|
-
#names;
|
|
2269
|
-
#subscribers = /* @__PURE__ */ new Map();
|
|
2270
|
-
constructor(names) {
|
|
2271
|
-
this.#names = new Set(names);
|
|
2272
|
-
Object.defineProperty(this, "events", { value: new Events(this) });
|
|
2273
|
-
}
|
|
2274
|
-
/**
|
|
2275
|
-
* Remove all event subscribers
|
|
2276
|
-
*/
|
|
2277
|
-
clear() {
|
|
2278
|
-
this.#subscribers.clear();
|
|
2279
|
-
}
|
|
2280
|
-
/**
|
|
2281
|
-
* Emit an event with parameters
|
|
2282
|
-
*
|
|
2283
|
-
* @param event Event name
|
|
2284
|
-
* @param parameters Event parameters
|
|
2285
|
-
*/
|
|
2286
|
-
emit(event, ...parameters) {
|
|
2287
|
-
const subscribers = this.#subscribers.get(event);
|
|
2288
|
-
if (subscribers == null) return;
|
|
2289
|
-
for (const callback of subscribers) callback(...parameters);
|
|
2290
|
-
}
|
|
2291
|
-
/**
|
|
2292
|
-
* Subscribe to an event with a callback
|
|
2293
|
-
*
|
|
2294
|
-
* @param event Event name
|
|
2295
|
-
* @param callback Callback function
|
|
2296
|
-
* @returns Unsubscriber function
|
|
2297
|
-
*/
|
|
2298
|
-
subscribe(event, callback) {
|
|
2299
|
-
if (!this.#names.has(event) || typeof callback !== "function") return noop;
|
|
2300
|
-
let subscribers = this.#subscribers.get(event);
|
|
2301
|
-
if (subscribers == null) {
|
|
2302
|
-
subscribers = /* @__PURE__ */ new Set();
|
|
2303
|
-
this.#subscribers.set(event, subscribers);
|
|
2304
|
-
}
|
|
2305
|
-
subscribers.add(callback);
|
|
2306
|
-
return () => {
|
|
2307
|
-
subscribers?.delete(callback);
|
|
2308
|
-
};
|
|
2309
|
-
}
|
|
2310
|
-
/**
|
|
2311
|
-
* Unsubscribe from an event with a callback _(or all callbacks, if no callback is provided)_
|
|
2312
|
-
*
|
|
2313
|
-
* @param event Event name
|
|
2314
|
-
* @param callback Callback function
|
|
2315
|
-
*/
|
|
2316
|
-
unsubscribe(event, callback) {
|
|
2317
|
-
if (!this.#names.has(event) || (callback != null ? typeof callback !== "function" : false)) return;
|
|
2318
|
-
const subscribers = this.#subscribers.get(event);
|
|
2319
|
-
if (subscribers == null) return;
|
|
2320
|
-
if (callback == null) subscribers.clear();
|
|
2321
|
-
else subscribers.delete(callback);
|
|
2322
|
-
if (callback == null || subscribers.size === 0) this.#subscribers.delete(event);
|
|
2323
|
-
}
|
|
2324
|
-
};
|
|
2203
|
+
function getEvents(herald) {
|
|
2204
|
+
const events = {
|
|
2205
|
+
subscribe: (event, callback) => herald.subscribe(event, callback),
|
|
2206
|
+
unsubscribe: (event, callback) => herald.unsubscribe(event, callback)
|
|
2207
|
+
};
|
|
2208
|
+
Object.defineProperty(events, KEY_HERALD, {
|
|
2209
|
+
enumerable: false,
|
|
2210
|
+
value: NAME_EVENTS
|
|
2211
|
+
});
|
|
2212
|
+
return Object.freeze(events);
|
|
2213
|
+
}
|
|
2325
2214
|
/**
|
|
2326
2215
|
* Create a _Herald_ for announcing named events
|
|
2327
2216
|
*
|
|
@@ -2330,9 +2219,75 @@ var Herald = class {
|
|
|
2330
2219
|
*/
|
|
2331
2220
|
function herald(names) {
|
|
2332
2221
|
if (!Array.isArray(names) || names.length === 0 || !names.every((name) => typeof name === "string")) throw new Error(MESSAGE);
|
|
2333
|
-
|
|
2222
|
+
const set = new Set(names);
|
|
2223
|
+
const subscribers = /* @__PURE__ */ new Map();
|
|
2224
|
+
const instance = {
|
|
2225
|
+
clear() {
|
|
2226
|
+
subscribers.clear();
|
|
2227
|
+
},
|
|
2228
|
+
emit(event, ...parameters) {
|
|
2229
|
+
const callbacks = subscribers.get(event);
|
|
2230
|
+
if (callbacks == null) return;
|
|
2231
|
+
for (const callback of callbacks) callback(...parameters);
|
|
2232
|
+
},
|
|
2233
|
+
subscribe(event, callback) {
|
|
2234
|
+
if (!set.has(event) || typeof callback !== "function") return noop;
|
|
2235
|
+
let eventSubscribers = subscribers.get(event);
|
|
2236
|
+
if (eventSubscribers == null) {
|
|
2237
|
+
eventSubscribers = /* @__PURE__ */ new Set();
|
|
2238
|
+
subscribers.set(event, eventSubscribers);
|
|
2239
|
+
}
|
|
2240
|
+
eventSubscribers.add(callback);
|
|
2241
|
+
return () => {
|
|
2242
|
+
eventSubscribers?.delete(callback);
|
|
2243
|
+
};
|
|
2244
|
+
},
|
|
2245
|
+
unsubscribe(event, callback) {
|
|
2246
|
+
if (!set.has(event) || (callback != null ? typeof callback !== "function" : false)) return;
|
|
2247
|
+
const eventSubscribers = subscribers.get(event);
|
|
2248
|
+
if (eventSubscribers == null) return;
|
|
2249
|
+
if (callback == null) eventSubscribers.clear();
|
|
2250
|
+
else eventSubscribers.delete(callback);
|
|
2251
|
+
if (callback == null || eventSubscribers.size === 0) subscribers.delete(event);
|
|
2252
|
+
}
|
|
2253
|
+
};
|
|
2254
|
+
Object.defineProperties(instance, {
|
|
2255
|
+
[KEY_HERALD]: {
|
|
2256
|
+
enumerable: false,
|
|
2257
|
+
value: NAME_HERALD
|
|
2258
|
+
},
|
|
2259
|
+
events: {
|
|
2260
|
+
enumerable: true,
|
|
2261
|
+
value: getEvents(instance)
|
|
2262
|
+
}
|
|
2263
|
+
});
|
|
2264
|
+
return Object.freeze(instance);
|
|
2265
|
+
}
|
|
2266
|
+
/**
|
|
2267
|
+
* Is the value events for a herald?
|
|
2268
|
+
*
|
|
2269
|
+
* @param value Value to check
|
|
2270
|
+
* @returns `true` if the value is events for a herald, otherwise `false`
|
|
2271
|
+
*/
|
|
2272
|
+
function isEvents(value) {
|
|
2273
|
+
return isHeraldInstance(NAME_EVENTS, value);
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Is the value a herald?
|
|
2277
|
+
*
|
|
2278
|
+
* @param value Value to check
|
|
2279
|
+
* @returns `true` if the value is a herald, otherwise `false`
|
|
2280
|
+
*/
|
|
2281
|
+
function isHerald(value) {
|
|
2282
|
+
return isHeraldInstance(NAME_HERALD, value);
|
|
2283
|
+
}
|
|
2284
|
+
function isHeraldInstance(name, value) {
|
|
2285
|
+
return typeof value === "object" && value != null && KEY_HERALD in value && value[KEY_HERALD] === name;
|
|
2334
2286
|
}
|
|
2287
|
+
const KEY_HERALD = "$herald";
|
|
2335
2288
|
const MESSAGE = "Herald requires an array of event names.";
|
|
2289
|
+
const NAME_EVENTS = "events";
|
|
2290
|
+
const NAME_HERALD = "herald";
|
|
2336
2291
|
//#endregion
|
|
2337
2292
|
//#region src/internal/value/equal.ts
|
|
2338
2293
|
/**
|
|
@@ -2845,45 +2800,6 @@ const MATCH_STARTS_WITH = "startsWith";
|
|
|
2845
2800
|
const matchMemoizers = {};
|
|
2846
2801
|
//#endregion
|
|
2847
2802
|
//#region src/string/fuzzy.ts
|
|
2848
|
-
/**
|
|
2849
|
-
* Fuzzy searcher for an array of items
|
|
2850
|
-
*/
|
|
2851
|
-
var Fuzzy = class {
|
|
2852
|
-
#state;
|
|
2853
|
-
/**
|
|
2854
|
-
* Get items currently being searched through
|
|
2855
|
-
*
|
|
2856
|
-
* @returns Original items
|
|
2857
|
-
*/
|
|
2858
|
-
get items() {
|
|
2859
|
-
return this.#state.items.slice();
|
|
2860
|
-
}
|
|
2861
|
-
/**
|
|
2862
|
-
* Set new items to search through
|
|
2863
|
-
*
|
|
2864
|
-
* @param items New items to search through
|
|
2865
|
-
*/
|
|
2866
|
-
set items(items) {
|
|
2867
|
-
if (Array.isArray(items)) {
|
|
2868
|
-
this.#state.items = items.slice();
|
|
2869
|
-
this.#state.strings = items.map(this.#state.handler);
|
|
2870
|
-
}
|
|
2871
|
-
}
|
|
2872
|
-
/**
|
|
2873
|
-
* Get strings currently being searched through _(the stringified version of `items`)_
|
|
2874
|
-
*
|
|
2875
|
-
* @returns Stringified items
|
|
2876
|
-
*/
|
|
2877
|
-
get strings() {
|
|
2878
|
-
return this.#state.strings.slice();
|
|
2879
|
-
}
|
|
2880
|
-
constructor(state) {
|
|
2881
|
-
this.#state = state;
|
|
2882
|
-
}
|
|
2883
|
-
search(value, options) {
|
|
2884
|
-
return search(this.#state.items, this.#state.strings, value, options == null ? this.#state : getFuzzyOptions(options, this.#state));
|
|
2885
|
-
}
|
|
2886
|
-
};
|
|
2887
2803
|
function getHandler(input) {
|
|
2888
2804
|
if (input == null || input === getString) return getString;
|
|
2889
2805
|
switch (typeof input) {
|
|
@@ -2922,7 +2838,20 @@ function getTolerance(input, state) {
|
|
|
2922
2838
|
}
|
|
2923
2839
|
function fuzzy(items, configuration) {
|
|
2924
2840
|
if (!Array.isArray(items)) throw new TypeError(MESSAGE_ARRAY);
|
|
2925
|
-
|
|
2841
|
+
const state = getFuzzyState(items, configuration);
|
|
2842
|
+
const instance = { search: (value, options) => search(state.items, state.strings, value, options == null ? state : getFuzzyOptions(options, state)) };
|
|
2843
|
+
Object.defineProperties(instance, {
|
|
2844
|
+
items: {
|
|
2845
|
+
get: () => state.items.slice(),
|
|
2846
|
+
set: (items) => {
|
|
2847
|
+
if (!Array.isArray(items)) throw new TypeError(MESSAGE_ARRAY);
|
|
2848
|
+
state.items = items.slice();
|
|
2849
|
+
state.strings = items.map(state.handler);
|
|
2850
|
+
}
|
|
2851
|
+
},
|
|
2852
|
+
strings: { get: () => state.strings.slice() }
|
|
2853
|
+
});
|
|
2854
|
+
return Object.freeze(instance);
|
|
2926
2855
|
}
|
|
2927
2856
|
fuzzy.match = fuzzyMatch;
|
|
2928
2857
|
/**
|
|
@@ -2930,7 +2859,7 @@ fuzzy.match = fuzzyMatch;
|
|
|
2930
2859
|
*
|
|
2931
2860
|
* @param haystack Haystack to search through
|
|
2932
2861
|
* @param needle Needle to search for
|
|
2933
|
-
* @returns `true` if the needle matches the haystack in a fuzzy way, `false`
|
|
2862
|
+
* @returns `true` if the needle matches the haystack in a fuzzy way, otherwise `false`
|
|
2934
2863
|
*/
|
|
2935
2864
|
function fuzzyMatch(haystack, needle) {
|
|
2936
2865
|
if (typeof haystack !== "string" || typeof needle !== "string") return false;
|
|
@@ -3880,141 +3809,6 @@ function transformValue(value, transformer) {
|
|
|
3880
3809
|
//#endregion
|
|
3881
3810
|
//#region src/beacon.ts
|
|
3882
3811
|
/**
|
|
3883
|
-
* A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
|
|
3884
|
-
*/
|
|
3885
|
-
var Beacon = class {
|
|
3886
|
-
#options;
|
|
3887
|
-
#state;
|
|
3888
|
-
/**
|
|
3889
|
-
* Is the beacon active?
|
|
3890
|
-
*/
|
|
3891
|
-
get active() {
|
|
3892
|
-
return this.#state.active;
|
|
3893
|
-
}
|
|
3894
|
-
/**
|
|
3895
|
-
* The observable that can be subscribed to
|
|
3896
|
-
*/
|
|
3897
|
-
get observable() {
|
|
3898
|
-
if (!this.#state.active) throw new Error(MESSAGE_BEACON);
|
|
3899
|
-
return this.#state.observable;
|
|
3900
|
-
}
|
|
3901
|
-
/**
|
|
3902
|
-
* The current value
|
|
3903
|
-
*/
|
|
3904
|
-
get value() {
|
|
3905
|
-
return this.#state.value;
|
|
3906
|
-
}
|
|
3907
|
-
constructor(value, options) {
|
|
3908
|
-
const observers = /* @__PURE__ */ new Map();
|
|
3909
|
-
this.#options = getBeaconOptions(options);
|
|
3910
|
-
this.#state = {
|
|
3911
|
-
observers,
|
|
3912
|
-
value,
|
|
3913
|
-
active: true,
|
|
3914
|
-
observable: new Observable(this, observers)
|
|
3915
|
-
};
|
|
3916
|
-
}
|
|
3917
|
-
/**
|
|
3918
|
-
* Destroy the beacon
|
|
3919
|
-
*/
|
|
3920
|
-
destroy() {
|
|
3921
|
-
finishBeacon(this.#state, false);
|
|
3922
|
-
}
|
|
3923
|
-
/**
|
|
3924
|
-
* Emit a new value
|
|
3925
|
-
*
|
|
3926
|
-
* @param value Value to set and emit
|
|
3927
|
-
* @param finish Finish the beacon after emitting? _(defaults to `false`)_
|
|
3928
|
-
*/
|
|
3929
|
-
emit(value, finish) {
|
|
3930
|
-
this.#on(TYPE_NEXT, value, finish);
|
|
3931
|
-
}
|
|
3932
|
-
/**
|
|
3933
|
-
* Emit an error
|
|
3934
|
-
*
|
|
3935
|
-
* @param value Error to emit
|
|
3936
|
-
* @param finish Finish the beacon after emitting? _(defaults to `false`)_
|
|
3937
|
-
*/
|
|
3938
|
-
error(value, finish) {
|
|
3939
|
-
this.#on(TYPE_ERROR, value, finish);
|
|
3940
|
-
}
|
|
3941
|
-
/**
|
|
3942
|
-
* Finish the beacon
|
|
3943
|
-
*/
|
|
3944
|
-
finish() {
|
|
3945
|
-
finishBeacon(this.#state, true);
|
|
3946
|
-
}
|
|
3947
|
-
#on(type, value, finish) {
|
|
3948
|
-
if (!this.#state.active) return;
|
|
3949
|
-
if (type === TYPE_NEXT) {
|
|
3950
|
-
if (this.#options.equal(this.#state.value, value)) return;
|
|
3951
|
-
this.#state.value = value;
|
|
3952
|
-
}
|
|
3953
|
-
for (const [, observer] of this.#state.observers) observer[type]?.(value);
|
|
3954
|
-
if (finish === true) finishBeacon(this.#state, true);
|
|
3955
|
-
}
|
|
3956
|
-
};
|
|
3957
|
-
/**
|
|
3958
|
-
* An observable holds a value and allows observers to subscribe to changes in that value
|
|
3959
|
-
*/
|
|
3960
|
-
var Observable = class {
|
|
3961
|
-
#state;
|
|
3962
|
-
constructor(instance, observers) {
|
|
3963
|
-
this.#state = {
|
|
3964
|
-
observers,
|
|
3965
|
-
beacon: instance,
|
|
3966
|
-
closed: false
|
|
3967
|
-
};
|
|
3968
|
-
}
|
|
3969
|
-
/**
|
|
3970
|
-
* Destroy the observable
|
|
3971
|
-
*/
|
|
3972
|
-
destroy() {
|
|
3973
|
-
this.#state.closed = true;
|
|
3974
|
-
}
|
|
3975
|
-
subscribe(first, second, third) {
|
|
3976
|
-
if (this.#state.closed) throw new Error(MESSAGE_OBSERVABLE);
|
|
3977
|
-
const observer = getObserver(first, second, third);
|
|
3978
|
-
const instance = new Subscription(this.#state);
|
|
3979
|
-
this.#state.observers.set(instance, observer);
|
|
3980
|
-
observer.next?.(this.#state.beacon.value);
|
|
3981
|
-
return instance;
|
|
3982
|
-
}
|
|
3983
|
-
};
|
|
3984
|
-
/**
|
|
3985
|
-
* A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from
|
|
3986
|
-
*/
|
|
3987
|
-
var Subscription = class {
|
|
3988
|
-
#state;
|
|
3989
|
-
constructor(state) {
|
|
3990
|
-
this.#state = {
|
|
3991
|
-
...state,
|
|
3992
|
-
closed: false
|
|
3993
|
-
};
|
|
3994
|
-
}
|
|
3995
|
-
/**
|
|
3996
|
-
* Is the subscription closed?
|
|
3997
|
-
*/
|
|
3998
|
-
get closed() {
|
|
3999
|
-
return this.#state.closed || !this.#state.beacon.active;
|
|
4000
|
-
}
|
|
4001
|
-
/**
|
|
4002
|
-
* Destroy the subscription
|
|
4003
|
-
*/
|
|
4004
|
-
destroy() {
|
|
4005
|
-
if (!this.#state.closed) this.unsubscribe();
|
|
4006
|
-
}
|
|
4007
|
-
/**
|
|
4008
|
-
* Unsubscribe from its observable
|
|
4009
|
-
*/
|
|
4010
|
-
unsubscribe() {
|
|
4011
|
-
if (!this.#state.closed) {
|
|
4012
|
-
this.#state.closed = true;
|
|
4013
|
-
this.#state.observers.delete(this);
|
|
4014
|
-
}
|
|
4015
|
-
}
|
|
4016
|
-
};
|
|
4017
|
-
/**
|
|
4018
3812
|
* Create a new beacon
|
|
4019
3813
|
*
|
|
4020
3814
|
* @param value Initial value
|
|
@@ -4022,7 +3816,54 @@ var Subscription = class {
|
|
|
4022
3816
|
* @returns Beacon instance
|
|
4023
3817
|
*/
|
|
4024
3818
|
function beacon(value, options) {
|
|
4025
|
-
|
|
3819
|
+
const state = {
|
|
3820
|
+
value,
|
|
3821
|
+
active: true,
|
|
3822
|
+
observable: void 0,
|
|
3823
|
+
observers: /* @__PURE__ */ new Map(),
|
|
3824
|
+
options: getBeaconOptions(options)
|
|
3825
|
+
};
|
|
3826
|
+
const instance = {
|
|
3827
|
+
close: () => {
|
|
3828
|
+
finishBeacon(state, false);
|
|
3829
|
+
},
|
|
3830
|
+
emit: (value, finish) => {
|
|
3831
|
+
update$1(TYPE_NEXT, state, value, finish);
|
|
3832
|
+
},
|
|
3833
|
+
error: (value, finish) => {
|
|
3834
|
+
update$1(TYPE_ERROR, state, value, finish);
|
|
3835
|
+
},
|
|
3836
|
+
finish: () => {
|
|
3837
|
+
finishBeacon(state, true);
|
|
3838
|
+
}
|
|
3839
|
+
};
|
|
3840
|
+
Object.defineProperties(instance, {
|
|
3841
|
+
[KEY_BEACON]: {
|
|
3842
|
+
enumerable: false,
|
|
3843
|
+
value: NAME_BEACON
|
|
3844
|
+
},
|
|
3845
|
+
active: {
|
|
3846
|
+
enumerable: true,
|
|
3847
|
+
get: () => state.active
|
|
3848
|
+
},
|
|
3849
|
+
closed: {
|
|
3850
|
+
enumerable: true,
|
|
3851
|
+
get: () => !state.active
|
|
3852
|
+
},
|
|
3853
|
+
observable: {
|
|
3854
|
+
enumerable: true,
|
|
3855
|
+
get: () => {
|
|
3856
|
+
if (!state.active) throw new Error(MESSAGE_BEACON);
|
|
3857
|
+
state.observable ??= observe(state);
|
|
3858
|
+
return state.observable;
|
|
3859
|
+
}
|
|
3860
|
+
},
|
|
3861
|
+
value: {
|
|
3862
|
+
enumerable: true,
|
|
3863
|
+
get: () => state.value
|
|
3864
|
+
}
|
|
3865
|
+
});
|
|
3866
|
+
return Object.freeze(instance);
|
|
4026
3867
|
}
|
|
4027
3868
|
function finishBeacon(state, emit) {
|
|
4028
3869
|
if (!state.active) return;
|
|
@@ -4032,10 +3873,11 @@ function finishBeacon(state, emit) {
|
|
|
4032
3873
|
for (let index = 0; index < length; index += 1) {
|
|
4033
3874
|
const [subscription, observer] = entries[index];
|
|
4034
3875
|
if (emit) observer.complete?.();
|
|
4035
|
-
subscription.
|
|
3876
|
+
subscription.close();
|
|
4036
3877
|
}
|
|
4037
|
-
state.observable?.
|
|
3878
|
+
state.observable?.close();
|
|
4038
3879
|
state.observers.clear();
|
|
3880
|
+
state.observable = void 0;
|
|
4039
3881
|
}
|
|
4040
3882
|
function getBeaconOptions(input) {
|
|
4041
3883
|
const options = isPlainObject(input) ? input : {};
|
|
@@ -4059,11 +3901,134 @@ function getObserver(first, second, third) {
|
|
|
4059
3901
|
}
|
|
4060
3902
|
return observer;
|
|
4061
3903
|
}
|
|
4062
|
-
|
|
4063
|
-
|
|
3904
|
+
/**
|
|
3905
|
+
* Is the value a beacon?
|
|
3906
|
+
*
|
|
3907
|
+
* @param value Value to check
|
|
3908
|
+
* @returns `true` if the value is a beacon, otherwise `false`
|
|
3909
|
+
*/
|
|
3910
|
+
function isBeacon(value) {
|
|
3911
|
+
return isBeaconInstance(NAME_BEACON, value);
|
|
3912
|
+
}
|
|
3913
|
+
function isBeaconInstance(name, value) {
|
|
3914
|
+
return isPlainObject(value) && value[KEY_BEACON] === name;
|
|
3915
|
+
}
|
|
3916
|
+
/**
|
|
3917
|
+
* Is the value an observable?
|
|
3918
|
+
*
|
|
3919
|
+
* @param value Value to check
|
|
3920
|
+
* @returns `true` if the value is an observable, otherwise `false`
|
|
3921
|
+
*/
|
|
3922
|
+
function isObservable(value) {
|
|
3923
|
+
return isBeaconInstance(NAME_OBSERVABLE, value);
|
|
3924
|
+
}
|
|
3925
|
+
/**
|
|
3926
|
+
* Is the value a subscription?
|
|
3927
|
+
*
|
|
3928
|
+
* @param value Value to check
|
|
3929
|
+
* @returns `true` if the value is a subscription, otherwise `false`
|
|
3930
|
+
*/
|
|
3931
|
+
function isSubscription(value) {
|
|
3932
|
+
return isBeaconInstance(NAME_SUBSCRIPTION, value);
|
|
3933
|
+
}
|
|
3934
|
+
function observe(beacon) {
|
|
3935
|
+
const state = {
|
|
3936
|
+
beacon,
|
|
3937
|
+
active: beacon.active
|
|
3938
|
+
};
|
|
3939
|
+
const instance = {
|
|
3940
|
+
close: () => {
|
|
3941
|
+
state.active = false;
|
|
3942
|
+
},
|
|
3943
|
+
subscribe(first, second, third) {
|
|
3944
|
+
if (!beacon.active || !state.active) throw new Error(MESSAGE_OBSERVABLE);
|
|
3945
|
+
const observer = getObserver(first, second, third);
|
|
3946
|
+
const subscription = subscribe(state);
|
|
3947
|
+
beacon.observers.set(subscription, observer);
|
|
3948
|
+
observer.next?.(beacon.value);
|
|
3949
|
+
return subscription;
|
|
3950
|
+
}
|
|
3951
|
+
};
|
|
3952
|
+
Object.defineProperties(instance, {
|
|
3953
|
+
[KEY_BEACON]: {
|
|
3954
|
+
enumerable: false,
|
|
3955
|
+
value: NAME_OBSERVABLE
|
|
3956
|
+
},
|
|
3957
|
+
active: {
|
|
3958
|
+
enumerable: true,
|
|
3959
|
+
get: () => beacon.active && state.active
|
|
3960
|
+
},
|
|
3961
|
+
closed: {
|
|
3962
|
+
enumerable: true,
|
|
3963
|
+
get: () => !beacon.active || !state.active
|
|
3964
|
+
}
|
|
3965
|
+
});
|
|
3966
|
+
return Object.freeze(instance);
|
|
3967
|
+
}
|
|
3968
|
+
function subscribe(observable) {
|
|
3969
|
+
function unsubscribe() {
|
|
3970
|
+
if (active) {
|
|
3971
|
+
active = false;
|
|
3972
|
+
observable.beacon.observers.delete(instance);
|
|
3973
|
+
}
|
|
3974
|
+
}
|
|
3975
|
+
let active = true;
|
|
3976
|
+
const instance = {
|
|
3977
|
+
close: () => {
|
|
3978
|
+
unsubscribe();
|
|
3979
|
+
},
|
|
3980
|
+
unsubscribe: () => {
|
|
3981
|
+
unsubscribe();
|
|
3982
|
+
}
|
|
3983
|
+
};
|
|
3984
|
+
Object.defineProperties(instance, {
|
|
3985
|
+
[KEY_BEACON]: {
|
|
3986
|
+
enumerable: false,
|
|
3987
|
+
value: NAME_SUBSCRIPTION
|
|
3988
|
+
},
|
|
3989
|
+
active: {
|
|
3990
|
+
enumerable: true,
|
|
3991
|
+
get: () => observable.beacon.active && observable.active && active
|
|
3992
|
+
},
|
|
3993
|
+
closed: {
|
|
3994
|
+
enumerable: true,
|
|
3995
|
+
get: () => !observable.beacon.active || !observable.active || !active
|
|
3996
|
+
}
|
|
3997
|
+
});
|
|
3998
|
+
return Object.freeze(instance);
|
|
3999
|
+
}
|
|
4000
|
+
function update$1(type, state, value, finish) {
|
|
4001
|
+
if (!state.active) return;
|
|
4002
|
+
if (type === TYPE_NEXT) {
|
|
4003
|
+
if (state.options.equal(state.value, value)) return;
|
|
4004
|
+
state.value = value;
|
|
4005
|
+
}
|
|
4006
|
+
for (const [, observer] of state.observers) observer[type]?.(value);
|
|
4007
|
+
if (finish === true) finishBeacon(state, true);
|
|
4008
|
+
}
|
|
4009
|
+
const KEY_BEACON = "$beacon";
|
|
4010
|
+
const MESSAGE_BEACON = "Cannot retrieve observable from a closed beacon";
|
|
4011
|
+
const MESSAGE_OBSERVABLE = "Cannot subscribe to a closed observable";
|
|
4012
|
+
const NAME_BEACON = "beacon";
|
|
4013
|
+
const NAME_OBSERVABLE = "observable";
|
|
4014
|
+
const NAME_SUBSCRIPTION = "subscription";
|
|
4064
4015
|
const TYPE_ERROR = "error";
|
|
4065
4016
|
const TYPE_NEXT = "next";
|
|
4066
4017
|
//#endregion
|
|
4018
|
+
//#region src/color/misc/index.ts
|
|
4019
|
+
function formatHslColor(state, alpha) {
|
|
4020
|
+
const { hue, lightness, saturation } = state.hsl;
|
|
4021
|
+
return `hsl(${hue}deg ${saturation}% ${lightness}%${alpha ? ` / ${state.alpha.value}%` : ""})`;
|
|
4022
|
+
}
|
|
4023
|
+
function formatHwbColor(state, alpha) {
|
|
4024
|
+
const { blackness, hue, whiteness } = state.hwb;
|
|
4025
|
+
return `hwb(${hue}deg ${whiteness}% ${blackness}%${alpha ? ` / ${state.alpha.value}%` : ""})`;
|
|
4026
|
+
}
|
|
4027
|
+
function formatRgbColor(state, alpha) {
|
|
4028
|
+
const { blue, green, red } = state.rgb;
|
|
4029
|
+
return `rgb(${red} ${green} ${blue}${alpha ? ` / ${state.alpha.value}%` : ""})`;
|
|
4030
|
+
}
|
|
4031
|
+
//#endregion
|
|
4067
4032
|
//#region src/internal/math/misc.ts
|
|
4068
4033
|
/**
|
|
4069
4034
|
* Round a number
|
|
@@ -4081,20 +4046,6 @@ function roundNumber(callback, value, decimals) {
|
|
|
4081
4046
|
const mod = 10 ** decimals;
|
|
4082
4047
|
return callback((value + Number.EPSILON) * mod) / mod;
|
|
4083
4048
|
}
|
|
4084
|
-
//#endregion
|
|
4085
|
-
//#region src/color/misc/index.ts
|
|
4086
|
-
function formatHslColor(color, alpha) {
|
|
4087
|
-
const { hue, lightness, saturation } = color.hsl;
|
|
4088
|
-
return `hsl(${hue}deg ${saturation}% ${lightness}%${alpha ? ` / ${color.alpha}%` : ""})`;
|
|
4089
|
-
}
|
|
4090
|
-
function formatHwbColor(color, alpha) {
|
|
4091
|
-
const { blackness, hue, whiteness } = color.hwb;
|
|
4092
|
-
return `hwb(${hue}deg ${whiteness}% ${blackness}%${alpha ? ` / ${color.alpha}%` : ""})`;
|
|
4093
|
-
}
|
|
4094
|
-
function formatRgbColor(color, alpha) {
|
|
4095
|
-
const { blue, green, red } = color.rgb;
|
|
4096
|
-
return `rgb(${red} ${green} ${blue}${alpha ? ` / ${color.alpha}%` : ""})`;
|
|
4097
|
-
}
|
|
4098
4049
|
const ALPHA_FULL_HEX_LONG = `ff`;
|
|
4099
4050
|
const DEFAULT_ALPHA = {
|
|
4100
4051
|
hex: ALPHA_FULL_HEX_LONG,
|
|
@@ -4186,8 +4137,8 @@ function getForegroundColor(value, hex) {
|
|
|
4186
4137
|
if (color <= .03928) values[index] /= SRGB_LUMINANCE_MULTIPLIER;
|
|
4187
4138
|
else values[index] = ((color + SRGB_LUMINANCE_OFFSET) / SRGB_LUMINANCE_MODIFIER) ** SRGB_LUMINANCE_EXPONENT;
|
|
4188
4139
|
}
|
|
4189
|
-
const
|
|
4190
|
-
return hex === true ?
|
|
4140
|
+
const foreground = .2126 * values[2] + .7152 * values[1] + .0722 * values[0] > .625 ? HEX_BLACK : HEX_WHITE;
|
|
4141
|
+
return hex === true ? foreground : color(foreground);
|
|
4191
4142
|
}
|
|
4192
4143
|
/**
|
|
4193
4144
|
* Get the hex color _(with alpha channel, i.e., opacity)_ from any kind of value
|
|
@@ -4360,7 +4311,10 @@ function isDegree(value) {
|
|
|
4360
4311
|
function isHexColor(value, alpha) {
|
|
4361
4312
|
if (typeof value !== "string") return false;
|
|
4362
4313
|
if (!(EXPRESSION_HEX_SHORT.test(value) || EXPRESSION_HEX_LONG.test(value))) return false;
|
|
4363
|
-
if (alpha === false)
|
|
4314
|
+
if (alpha === false) {
|
|
4315
|
+
const unprefixed = value.replace(EXPRESSION_PREFIX, "");
|
|
4316
|
+
return unprefixed.length === 3 || unprefixed.length === 6;
|
|
4317
|
+
}
|
|
4364
4318
|
return true;
|
|
4365
4319
|
}
|
|
4366
4320
|
/**
|
|
@@ -5047,222 +5001,63 @@ function setRGBColor(state, value, alpha) {
|
|
|
5047
5001
|
}
|
|
5048
5002
|
//#endregion
|
|
5049
5003
|
//#region src/color/instance.ts
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
5060
|
-
|
|
5061
|
-
|
|
5062
|
-
|
|
5063
|
-
|
|
5064
|
-
|
|
5065
|
-
|
|
5066
|
-
|
|
5067
|
-
|
|
5068
|
-
|
|
5069
|
-
|
|
5070
|
-
|
|
5071
|
-
|
|
5072
|
-
|
|
5073
|
-
|
|
5074
|
-
|
|
5075
|
-
|
|
5076
|
-
|
|
5077
|
-
|
|
5078
|
-
|
|
5079
|
-
|
|
5080
|
-
|
|
5081
|
-
|
|
5082
|
-
|
|
5083
|
-
|
|
5084
|
-
|
|
5085
|
-
|
|
5086
|
-
|
|
5087
|
-
|
|
5088
|
-
|
|
5089
|
-
|
|
5090
|
-
|
|
5091
|
-
|
|
5092
|
-
|
|
5093
|
-
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
|
|
5097
|
-
|
|
5098
|
-
|
|
5099
|
-
|
|
5100
|
-
|
|
5101
|
-
|
|
5102
|
-
|
|
5103
|
-
|
|
5104
|
-
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
*
|
|
5108
|
-
* @param value New hex color string
|
|
5109
|
-
*/
|
|
5110
|
-
set hexa(value) {
|
|
5111
|
-
setHexColor(this.#state, value, true);
|
|
5112
|
-
}
|
|
5113
|
-
/**
|
|
5114
|
-
* Get the color as an _HSL_ color
|
|
5115
|
-
*
|
|
5116
|
-
* @returns Current color as an _HSL_ color
|
|
5117
|
-
*/
|
|
5118
|
-
get hsl() {
|
|
5119
|
-
return { ...this.#state.hsl };
|
|
5120
|
-
}
|
|
5121
|
-
/**
|
|
5122
|
-
* Set colors from an _HSL_ color
|
|
5123
|
-
*
|
|
5124
|
-
* @param value New _HSL_ color
|
|
5125
|
-
*/
|
|
5126
|
-
set hsl(value) {
|
|
5127
|
-
setHSLColor(this.#state, value, false);
|
|
5128
|
-
}
|
|
5129
|
-
/**
|
|
5130
|
-
* Get the color as an _HSLA_ color
|
|
5131
|
-
*
|
|
5132
|
-
* @returns Current color as an _HSLA_ color
|
|
5133
|
-
*/
|
|
5134
|
-
get hsla() {
|
|
5135
|
-
return {
|
|
5136
|
-
...this.#state.hsl,
|
|
5137
|
-
alpha: this.#state.alpha.value
|
|
5138
|
-
};
|
|
5139
|
-
}
|
|
5140
|
-
/**
|
|
5141
|
-
* Set colors and alpha from an _HSLA_ color
|
|
5142
|
-
*
|
|
5143
|
-
* @param value New _HSLA_ color
|
|
5144
|
-
*/
|
|
5145
|
-
set hsla(value) {
|
|
5146
|
-
setHSLColor(this.#state, value, true);
|
|
5147
|
-
}
|
|
5148
|
-
/**
|
|
5149
|
-
* Get the color as an _HWB_ color
|
|
5150
|
-
*
|
|
5151
|
-
* @returns Current color as an _HWB_ color
|
|
5152
|
-
*/
|
|
5153
|
-
get hwb() {
|
|
5154
|
-
return { ...this.#state.hwb };
|
|
5155
|
-
}
|
|
5156
|
-
/**
|
|
5157
|
-
* Set colors from an _HWB_ color
|
|
5158
|
-
*
|
|
5159
|
-
* @param value New _HWB_ color
|
|
5160
|
-
*/
|
|
5161
|
-
set hwb(value) {
|
|
5162
|
-
setHWBColor(this.#state, value, false);
|
|
5163
|
-
}
|
|
5164
|
-
/**
|
|
5165
|
-
* Get the color as an _HWBA_ color
|
|
5166
|
-
*
|
|
5167
|
-
* @returns Current color as an _HWBA_ color
|
|
5168
|
-
*/
|
|
5169
|
-
get hwba() {
|
|
5170
|
-
return {
|
|
5171
|
-
...this.#state.hwb,
|
|
5172
|
-
alpha: this.#state.alpha.value
|
|
5173
|
-
};
|
|
5174
|
-
}
|
|
5175
|
-
/**
|
|
5176
|
-
* Set colors and alpha from an _HWBA_ color
|
|
5177
|
-
*
|
|
5178
|
-
* @param value New _HWBA_ color
|
|
5179
|
-
*/
|
|
5180
|
-
set hwba(value) {
|
|
5181
|
-
setHWBColor(this.#state, value, true);
|
|
5182
|
-
}
|
|
5183
|
-
/**
|
|
5184
|
-
* Get the color as an _RGB_ color
|
|
5185
|
-
*
|
|
5186
|
-
* @returns Current color as an _RGB_ color
|
|
5187
|
-
*/
|
|
5188
|
-
get rgb() {
|
|
5189
|
-
return { ...this.#state.rgb };
|
|
5190
|
-
}
|
|
5191
|
-
/**
|
|
5192
|
-
* Set colors from an _RGB_ color
|
|
5193
|
-
*
|
|
5194
|
-
* @param value New _RGB_ color
|
|
5195
|
-
*/
|
|
5196
|
-
set rgb(value) {
|
|
5197
|
-
setRGBColor(this.#state, value, false);
|
|
5198
|
-
}
|
|
5199
|
-
/**
|
|
5200
|
-
* Get the color as an _RGBA_ color
|
|
5201
|
-
*
|
|
5202
|
-
* @returns Current color as an _RGBA_ color
|
|
5203
|
-
*/
|
|
5204
|
-
get rgba() {
|
|
5205
|
-
return {
|
|
5206
|
-
...this.#state.rgb,
|
|
5207
|
-
alpha: this.#state.alpha.value
|
|
5208
|
-
};
|
|
5209
|
-
}
|
|
5210
|
-
/**
|
|
5211
|
-
* Set colors and alpha from an _RGBA_ color
|
|
5212
|
-
*
|
|
5213
|
-
* @param value New _RGBA_ color
|
|
5214
|
-
*/
|
|
5215
|
-
set rgba(value) {
|
|
5216
|
-
setRGBColor(this.#state, value, true);
|
|
5217
|
-
}
|
|
5218
|
-
constructor(value) {
|
|
5219
|
-
this.#state = getColorState(value);
|
|
5220
|
-
Object.defineProperty(this, "$color", { value: true });
|
|
5221
|
-
}
|
|
5222
|
-
/**
|
|
5223
|
-
* Get the color as a hex string
|
|
5224
|
-
*
|
|
5225
|
-
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
5226
|
-
* @returns Hex color string
|
|
5227
|
-
*/
|
|
5228
|
-
toHexString(alpha) {
|
|
5229
|
-
return `#${alpha === true ? this.hexa : this.hex}`;
|
|
5230
|
-
}
|
|
5231
|
-
/**
|
|
5232
|
-
* Get the color as an _HSL(A)_ string
|
|
5233
|
-
*
|
|
5234
|
-
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
5235
|
-
* @returns _HSL(A)_ color string
|
|
5236
|
-
*/
|
|
5237
|
-
toHslString(alpha) {
|
|
5238
|
-
return formatHslColor(this, alpha === true);
|
|
5239
|
-
}
|
|
5240
|
-
/**
|
|
5241
|
-
* Get the color as an _HWB(A)_ string
|
|
5242
|
-
*
|
|
5243
|
-
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
5244
|
-
* @returns _HWB(A)_ color string
|
|
5245
|
-
*/
|
|
5246
|
-
toHwbString(alpha) {
|
|
5247
|
-
return formatHwbColor(this, alpha === true);
|
|
5248
|
-
}
|
|
5249
|
-
/**
|
|
5250
|
-
* Get the color as an _RGB(A)_ string
|
|
5251
|
-
*
|
|
5252
|
-
* @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
|
|
5253
|
-
* @returns _RGB(A)_ color string
|
|
5254
|
-
*/
|
|
5255
|
-
toRgbString(alpha) {
|
|
5256
|
-
return formatRgbColor(this, alpha === true);
|
|
5257
|
-
}
|
|
5258
|
-
/**
|
|
5259
|
-
* Get the color as a hex color string
|
|
5260
|
-
*
|
|
5261
|
-
* @returns Hex color string
|
|
5262
|
-
*/
|
|
5263
|
-
toString() {
|
|
5264
|
-
return this.toHexString();
|
|
5265
|
-
}
|
|
5004
|
+
function color(value) {
|
|
5005
|
+
const state = getColorState(value);
|
|
5006
|
+
const instance = {
|
|
5007
|
+
toHexString: (alpha) => `#${alpha === true ? instance.hexa : instance.hex}`,
|
|
5008
|
+
toHslString: (alpha) => formatHslColor(state, alpha === true),
|
|
5009
|
+
toHwbString: (alpha) => formatHwbColor(state, alpha === true),
|
|
5010
|
+
toRgbString: (alpha) => formatRgbColor(state, alpha === true),
|
|
5011
|
+
toString: () => instance.toHexString()
|
|
5012
|
+
};
|
|
5013
|
+
Object.defineProperties(instance, {
|
|
5014
|
+
$color: {
|
|
5015
|
+
enumerable: false,
|
|
5016
|
+
get: () => true
|
|
5017
|
+
},
|
|
5018
|
+
alpha: {
|
|
5019
|
+
enumerable: true,
|
|
5020
|
+
get: () => state.alpha.value,
|
|
5021
|
+
set: (value) => {
|
|
5022
|
+
if (typeof value === "number" && !Number.isNaN(value)) state.alpha = getAlpha(value);
|
|
5023
|
+
}
|
|
5024
|
+
},
|
|
5025
|
+
hex: getProperty("hex", state, false),
|
|
5026
|
+
hexa: getProperty("hex", state, true),
|
|
5027
|
+
hsl: getProperty("hsl", state, false),
|
|
5028
|
+
hsla: getProperty("hsl", state, true),
|
|
5029
|
+
hwb: getProperty("hwb", state, false),
|
|
5030
|
+
hwba: getProperty("hwb", state, true),
|
|
5031
|
+
rgb: getProperty("rgb", state, false),
|
|
5032
|
+
rgba: getProperty("rgb", state, true)
|
|
5033
|
+
});
|
|
5034
|
+
return Object.freeze(instance);
|
|
5035
|
+
}
|
|
5036
|
+
function getHex(state, alpha) {
|
|
5037
|
+
return alpha ? `${state.hex}${state.alpha.hex}` : state.hex;
|
|
5038
|
+
}
|
|
5039
|
+
function getProperty(space, state, alpha) {
|
|
5040
|
+
const setter = setters[space];
|
|
5041
|
+
return {
|
|
5042
|
+
enumerable: true,
|
|
5043
|
+
get: () => {
|
|
5044
|
+
const value = state[space];
|
|
5045
|
+
if (typeof value === "string") return getHex(state, alpha);
|
|
5046
|
+
return alpha ? {
|
|
5047
|
+
...value,
|
|
5048
|
+
alpha: state.alpha.value
|
|
5049
|
+
} : { ...value };
|
|
5050
|
+
},
|
|
5051
|
+
set: (value) => {
|
|
5052
|
+
setter(state, value, alpha);
|
|
5053
|
+
}
|
|
5054
|
+
};
|
|
5055
|
+
}
|
|
5056
|
+
const setters = {
|
|
5057
|
+
hex: setHexColor,
|
|
5058
|
+
hsl: setHSLColor,
|
|
5059
|
+
hwb: setHWBColor,
|
|
5060
|
+
rgb: setRGBColor
|
|
5266
5061
|
};
|
|
5267
5062
|
//#endregion
|
|
5268
5063
|
//#region src/color/index.ts
|
|
@@ -5276,55 +5071,65 @@ var Color = class {
|
|
|
5276
5071
|
* @returns _Color_ instance
|
|
5277
5072
|
*/
|
|
5278
5073
|
function getColor(value) {
|
|
5279
|
-
return isColor(value) ? value :
|
|
5074
|
+
return isColor(value) ? value : color(value);
|
|
5280
5075
|
}
|
|
5281
5076
|
//#endregion
|
|
5282
5077
|
//#region src/logger.ts
|
|
5283
|
-
|
|
5284
|
-
|
|
5285
|
-
|
|
5286
|
-
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
5290
|
-
|
|
5291
|
-
|
|
5292
|
-
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
|
|
5297
|
-
|
|
5298
|
-
|
|
5299
|
-
get log() {
|
|
5300
|
-
return this.active ? this.#logger : noop;
|
|
5301
|
-
}
|
|
5302
|
-
/**
|
|
5303
|
-
* Stop the timer and logs the total duration
|
|
5304
|
-
*
|
|
5305
|
-
* _(Will always log the total duration, even if logging is disabled)_
|
|
5306
|
-
*/
|
|
5307
|
-
get stop() {
|
|
5308
|
-
return this.active ? this.#stopTimer() : noop;
|
|
5309
|
-
}
|
|
5310
|
-
constructor(label) {
|
|
5311
|
-
this.#logger = console.timeLog.bind(console, label);
|
|
5312
|
-
this.#stopper = console.timeEnd.bind(console, label);
|
|
5313
|
-
this.#state = {
|
|
5314
|
-
label,
|
|
5315
|
-
started: enabled,
|
|
5316
|
-
stopped: false
|
|
5317
|
-
};
|
|
5318
|
-
if (this.#state.started) console.time(label);
|
|
5319
|
-
}
|
|
5320
|
-
#stopTimer() {
|
|
5321
|
-
const stopper = this.#stopper;
|
|
5322
|
-
this.#state.stopped = true;
|
|
5323
|
-
this.#logger = void 0;
|
|
5324
|
-
this.#stopper = void 0;
|
|
5325
|
-
return stopper;
|
|
5078
|
+
function isLogger(value) {
|
|
5079
|
+
return isLoggerInstance(NAME_LOGGER, value);
|
|
5080
|
+
}
|
|
5081
|
+
function isLoggerInstance(name, value) {
|
|
5082
|
+
return typeof value === "object" && value !== null && value[KEY_LOGGER] === name;
|
|
5083
|
+
}
|
|
5084
|
+
function isTimedLogger(value) {
|
|
5085
|
+
return isLoggerInstance(NAME_TIMED, value);
|
|
5086
|
+
}
|
|
5087
|
+
function timedLogger(label) {
|
|
5088
|
+
function stop() {
|
|
5089
|
+
const fn = stopper;
|
|
5090
|
+
state.stopped = true;
|
|
5091
|
+
logger = void 0;
|
|
5092
|
+
stopper = void 0;
|
|
5093
|
+
return fn;
|
|
5326
5094
|
}
|
|
5327
|
-
|
|
5095
|
+
let logger = console.timeLog.bind(console, label);
|
|
5096
|
+
let stopper = console.timeEnd.bind(console, label);
|
|
5097
|
+
const state = {
|
|
5098
|
+
label,
|
|
5099
|
+
started: enabled,
|
|
5100
|
+
stopped: false
|
|
5101
|
+
};
|
|
5102
|
+
const instance = {};
|
|
5103
|
+
Object.defineProperties(instance, {
|
|
5104
|
+
[KEY_LOGGER]: {
|
|
5105
|
+
enumerable: false,
|
|
5106
|
+
value: NAME_TIMED
|
|
5107
|
+
},
|
|
5108
|
+
active: {
|
|
5109
|
+
enumerable: true,
|
|
5110
|
+
get() {
|
|
5111
|
+
return state.started && !state.stopped && enabled;
|
|
5112
|
+
}
|
|
5113
|
+
},
|
|
5114
|
+
log: {
|
|
5115
|
+
enumerable: true,
|
|
5116
|
+
get() {
|
|
5117
|
+
return this.active ? logger : noop;
|
|
5118
|
+
}
|
|
5119
|
+
},
|
|
5120
|
+
stop: {
|
|
5121
|
+
enumerable: true,
|
|
5122
|
+
get() {
|
|
5123
|
+
return instance.active ? stop() : noop;
|
|
5124
|
+
}
|
|
5125
|
+
}
|
|
5126
|
+
});
|
|
5127
|
+
if (state.started) console.time(label);
|
|
5128
|
+
return Object.freeze(instance);
|
|
5129
|
+
}
|
|
5130
|
+
const KEY_LOGGER = "$logger";
|
|
5131
|
+
const NAME_LOGGER = "Logger";
|
|
5132
|
+
const NAME_TIMED = "TimedLogger";
|
|
5328
5133
|
const methods = [
|
|
5329
5134
|
"debug",
|
|
5330
5135
|
"dir",
|
|
@@ -5343,7 +5148,12 @@ const methods = [
|
|
|
5343
5148
|
const Logger = (() => {
|
|
5344
5149
|
const instance = {};
|
|
5345
5150
|
Object.defineProperties(instance, {
|
|
5151
|
+
[KEY_LOGGER]: {
|
|
5152
|
+
enumerable: false,
|
|
5153
|
+
value: NAME_LOGGER
|
|
5154
|
+
},
|
|
5346
5155
|
enabled: {
|
|
5156
|
+
enumerable: true,
|
|
5347
5157
|
get() {
|
|
5348
5158
|
return enabled;
|
|
5349
5159
|
},
|
|
@@ -5351,13 +5161,19 @@ const Logger = (() => {
|
|
|
5351
5161
|
enabled = typeof value === "boolean" ? value : enabled;
|
|
5352
5162
|
}
|
|
5353
5163
|
},
|
|
5354
|
-
time: {
|
|
5355
|
-
|
|
5356
|
-
|
|
5164
|
+
time: {
|
|
5165
|
+
enumerable: true,
|
|
5166
|
+
value(label) {
|
|
5167
|
+
return timedLogger(label);
|
|
5168
|
+
}
|
|
5169
|
+
}
|
|
5170
|
+
});
|
|
5171
|
+
for (const method of methods) Object.defineProperty(instance, method, {
|
|
5172
|
+
enumerable: true,
|
|
5173
|
+
get() {
|
|
5174
|
+
return enabled ? console[method].bind(console) : noop;
|
|
5175
|
+
}
|
|
5357
5176
|
});
|
|
5358
|
-
for (const method of methods) Object.defineProperty(instance, method, { get() {
|
|
5359
|
-
return enabled ? console[method].bind(console) : noop;
|
|
5360
|
-
} });
|
|
5361
5177
|
return Object.freeze(instance);
|
|
5362
5178
|
})();
|
|
5363
5179
|
let enabled = true;
|
|
@@ -5501,7 +5317,7 @@ function getStrategyOrDefault(value) {
|
|
|
5501
5317
|
* Is the value a fulfilled _Promise_ result?
|
|
5502
5318
|
*
|
|
5503
5319
|
* @param value Value to check
|
|
5504
|
-
* @returns `true` if the value is a fulfilled _Promise_ result, `false`
|
|
5320
|
+
* @returns `true` if the value is a fulfilled _Promise_ result, otherwise `false`
|
|
5505
5321
|
*/
|
|
5506
5322
|
function isFulfilled(value) {
|
|
5507
5323
|
return isType(value, PROMISE_TYPE_FULFILLED);
|
|
@@ -5510,7 +5326,7 @@ function isFulfilled(value) {
|
|
|
5510
5326
|
* Is the value a rejected _Promise_ result?
|
|
5511
5327
|
*
|
|
5512
5328
|
* @param value Value to check
|
|
5513
|
-
* @returns `true` if the value is a rejected _Promise_ result, `false`
|
|
5329
|
+
* @returns `true` if the value is a rejected _Promise_ result, otherwise `false`
|
|
5514
5330
|
*/
|
|
5515
5331
|
function isRejected(value) {
|
|
5516
5332
|
return isType(value, PROMISE_TYPE_REJECTED);
|
|
@@ -5761,345 +5577,6 @@ const TYPES = /* @__PURE__ */ new Set([
|
|
|
5761
5577
|
//#endregion
|
|
5762
5578
|
//#region src/queue.ts
|
|
5763
5579
|
/**
|
|
5764
|
-
* A queue that can be used to manage (a)synchronous tasks with a specific key
|
|
5765
|
-
*/
|
|
5766
|
-
var KeyedQueue = class {
|
|
5767
|
-
#callback;
|
|
5768
|
-
#options;
|
|
5769
|
-
#queues = /* @__PURE__ */ new Map();
|
|
5770
|
-
/**
|
|
5771
|
-
* Get keys of all active queues
|
|
5772
|
-
*/
|
|
5773
|
-
get active() {
|
|
5774
|
-
return this.#getStatus(STATUS_ACTIVE);
|
|
5775
|
-
}
|
|
5776
|
-
/**
|
|
5777
|
-
* Does the queue automatically start when the first item is added?
|
|
5778
|
-
*/
|
|
5779
|
-
get autostart() {
|
|
5780
|
-
return this.#options.autostart;
|
|
5781
|
-
}
|
|
5782
|
-
/**
|
|
5783
|
-
* Maximum number of runners to process the queue concurrently
|
|
5784
|
-
*/
|
|
5785
|
-
get concurrency() {
|
|
5786
|
-
return this.#options.concurrency;
|
|
5787
|
-
}
|
|
5788
|
-
/**
|
|
5789
|
-
* Get keys of all empty queues
|
|
5790
|
-
*/
|
|
5791
|
-
get empty() {
|
|
5792
|
-
return this.#getStatus(STATUS_EMPTY);
|
|
5793
|
-
}
|
|
5794
|
-
/**
|
|
5795
|
-
* Get keys of all full queues
|
|
5796
|
-
*/
|
|
5797
|
-
get full() {
|
|
5798
|
-
return this.#getStatus(STATUS_FULL);
|
|
5799
|
-
}
|
|
5800
|
-
/**
|
|
5801
|
-
* Number of items in all queues
|
|
5802
|
-
*/
|
|
5803
|
-
get items() {
|
|
5804
|
-
const size = {};
|
|
5805
|
-
const queues = this.#queues.entries();
|
|
5806
|
-
for (const [key, queue] of queues) size[key] = queue.size;
|
|
5807
|
-
return size;
|
|
5808
|
-
}
|
|
5809
|
-
/**
|
|
5810
|
-
* Keys of all queues
|
|
5811
|
-
*/
|
|
5812
|
-
get keys() {
|
|
5813
|
-
return [...this.#queues.keys()];
|
|
5814
|
-
}
|
|
5815
|
-
/**
|
|
5816
|
-
* Maximum number of items allowed in the queue
|
|
5817
|
-
*/
|
|
5818
|
-
get maximum() {
|
|
5819
|
-
return this.#options.maximum;
|
|
5820
|
-
}
|
|
5821
|
-
/**
|
|
5822
|
-
* Are all queues paused?
|
|
5823
|
-
*/
|
|
5824
|
-
get paused() {
|
|
5825
|
-
return this.#getStatus(STATUS_PAUSED);
|
|
5826
|
-
}
|
|
5827
|
-
/**
|
|
5828
|
-
* Number of queues
|
|
5829
|
-
*/
|
|
5830
|
-
get queues() {
|
|
5831
|
-
return this.#queues.size;
|
|
5832
|
-
}
|
|
5833
|
-
constructor(callback, options) {
|
|
5834
|
-
this.#callback = callback;
|
|
5835
|
-
this.#options = options;
|
|
5836
|
-
}
|
|
5837
|
-
/**
|
|
5838
|
-
* Queue an item for a specific key
|
|
5839
|
-
*
|
|
5840
|
-
* @param key Key to queue the item for
|
|
5841
|
-
* @param parameters Parameters to use when item runs
|
|
5842
|
-
* @param signal Optional signal to abort the item
|
|
5843
|
-
* @returns Queued item
|
|
5844
|
-
*/
|
|
5845
|
-
add(key, parameters, signal) {
|
|
5846
|
-
return this.#getQueue(key, true).add(parameters, signal);
|
|
5847
|
-
}
|
|
5848
|
-
/**
|
|
5849
|
-
* Clear all items for a specific key _(or all items for all keys, if no key is provided)_
|
|
5850
|
-
*
|
|
5851
|
-
* @param key Optional key to clear the queue for
|
|
5852
|
-
*/
|
|
5853
|
-
clear(key) {
|
|
5854
|
-
this.#handleQueues(HANDLE_CLEAR, key);
|
|
5855
|
-
}
|
|
5856
|
-
/**
|
|
5857
|
-
* Get the queue for a specific key
|
|
5858
|
-
*
|
|
5859
|
-
* @param key Key to get the queue for
|
|
5860
|
-
* @returns Queue for the key, or `undefined` if it doesn't exist
|
|
5861
|
-
*/
|
|
5862
|
-
get(key) {
|
|
5863
|
-
return this.#getQueue(key);
|
|
5864
|
-
}
|
|
5865
|
-
/**
|
|
5866
|
-
* Pause the queue for a specific key _(or all queues, if no key is provided)_
|
|
5867
|
-
*
|
|
5868
|
-
* @param key Optional key to pause the queue for
|
|
5869
|
-
*/
|
|
5870
|
-
pause(key) {
|
|
5871
|
-
this.#handleQueues(HANDLE_PAUSE, key);
|
|
5872
|
-
}
|
|
5873
|
-
remove(key, id) {
|
|
5874
|
-
if (key == null) {
|
|
5875
|
-
this.#handleQueues(HANDLE_CLEAR);
|
|
5876
|
-
this.#queues.clear();
|
|
5877
|
-
return;
|
|
5878
|
-
}
|
|
5879
|
-
const queue = this.#getQueue(key);
|
|
5880
|
-
if (queue == null) return;
|
|
5881
|
-
if (typeof id === "number") {
|
|
5882
|
-
queue.remove(id);
|
|
5883
|
-
return;
|
|
5884
|
-
}
|
|
5885
|
-
queue.clear();
|
|
5886
|
-
this.#queues.delete(key);
|
|
5887
|
-
}
|
|
5888
|
-
/**
|
|
5889
|
-
* Resume the queue for a specific key _(or all queues, if no key is provided)_
|
|
5890
|
-
*
|
|
5891
|
-
* @param key Optional key to resume the queue for
|
|
5892
|
-
*/
|
|
5893
|
-
resume(key) {
|
|
5894
|
-
this.#handleQueues(HANDLE_RESUME, key);
|
|
5895
|
-
}
|
|
5896
|
-
#getQueue(key, add) {
|
|
5897
|
-
if (typeof key !== "string" || key.trim().length === 0) throw new TypeError(MESSAGE_KEY);
|
|
5898
|
-
let queue = this.#queues.get(key);
|
|
5899
|
-
if (queue == null && add === true) {
|
|
5900
|
-
queue = new Queue(this.#callback, this.#options, key);
|
|
5901
|
-
this.#queues.set(key, queue);
|
|
5902
|
-
}
|
|
5903
|
-
return queue;
|
|
5904
|
-
}
|
|
5905
|
-
#getStatus(status) {
|
|
5906
|
-
const queues = this.#queues.entries();
|
|
5907
|
-
const result = [];
|
|
5908
|
-
for (const [key, queue] of queues) if (queue[status]) result.push(key);
|
|
5909
|
-
return result;
|
|
5910
|
-
}
|
|
5911
|
-
#handleQueues(type, key) {
|
|
5912
|
-
if (typeof key === "string") {
|
|
5913
|
-
this.#getQueue(key)?.[type]();
|
|
5914
|
-
return;
|
|
5915
|
-
}
|
|
5916
|
-
const queues = this.#queues.values();
|
|
5917
|
-
for (const queue of queues) queue[type]();
|
|
5918
|
-
}
|
|
5919
|
-
};
|
|
5920
|
-
/**
|
|
5921
|
-
* A queue that can be used to manage (a)synchronous tasks
|
|
5922
|
-
*/
|
|
5923
|
-
var Queue = class {
|
|
5924
|
-
#callback;
|
|
5925
|
-
#handled = [];
|
|
5926
|
-
#id = 0;
|
|
5927
|
-
#items = [];
|
|
5928
|
-
#key;
|
|
5929
|
-
#options;
|
|
5930
|
-
#paused;
|
|
5931
|
-
#runners = 0;
|
|
5932
|
-
/**
|
|
5933
|
-
* Is the queue active?
|
|
5934
|
-
*/
|
|
5935
|
-
get active() {
|
|
5936
|
-
return this.#runners > 0;
|
|
5937
|
-
}
|
|
5938
|
-
/**
|
|
5939
|
-
* Does the queue automatically start when the first item is added?
|
|
5940
|
-
*/
|
|
5941
|
-
get autostart() {
|
|
5942
|
-
return this.#options.autostart;
|
|
5943
|
-
}
|
|
5944
|
-
/**
|
|
5945
|
-
* Maximum number of runners to process the queue concurrently
|
|
5946
|
-
*/
|
|
5947
|
-
get concurrency() {
|
|
5948
|
-
return this.#options.concurrency;
|
|
5949
|
-
}
|
|
5950
|
-
/**
|
|
5951
|
-
* Is the queue empty?
|
|
5952
|
-
*/
|
|
5953
|
-
get empty() {
|
|
5954
|
-
return this.#items.length === 0;
|
|
5955
|
-
}
|
|
5956
|
-
/**
|
|
5957
|
-
* Is the queue full?
|
|
5958
|
-
*/
|
|
5959
|
-
get full() {
|
|
5960
|
-
return this.#options.maximum > 0 && this.#items.length >= this.#options.maximum;
|
|
5961
|
-
}
|
|
5962
|
-
/**
|
|
5963
|
-
* Maximum number of items allowed in the queue
|
|
5964
|
-
*/
|
|
5965
|
-
get maximum() {
|
|
5966
|
-
return this.#options.maximum;
|
|
5967
|
-
}
|
|
5968
|
-
/**
|
|
5969
|
-
* Is the queue paused?
|
|
5970
|
-
*/
|
|
5971
|
-
get paused() {
|
|
5972
|
-
return this.#paused;
|
|
5973
|
-
}
|
|
5974
|
-
/**
|
|
5975
|
-
* Number of items in the queue
|
|
5976
|
-
*/
|
|
5977
|
-
get size() {
|
|
5978
|
-
return this.#items.length;
|
|
5979
|
-
}
|
|
5980
|
-
constructor(callback, options, key) {
|
|
5981
|
-
this.#callback = callback;
|
|
5982
|
-
this.#key = key;
|
|
5983
|
-
this.#options = options;
|
|
5984
|
-
this.#paused = !options.autostart;
|
|
5985
|
-
}
|
|
5986
|
-
/**
|
|
5987
|
-
* Add an item to the queue
|
|
5988
|
-
*
|
|
5989
|
-
* @param parameters Parameters to use when item runs
|
|
5990
|
-
* @param signal Optional signal to abort the item
|
|
5991
|
-
* @returns Queued item
|
|
5992
|
-
*/
|
|
5993
|
-
add(parameters, signal) {
|
|
5994
|
-
if (this.full) throw new QueueError(MESSAGE_MAXIMUM);
|
|
5995
|
-
const abortSignal = signal instanceof AbortSignal ? signal : void 0;
|
|
5996
|
-
if (abortSignal?.aborted ?? false) throw new Error(abortSignal.reason);
|
|
5997
|
-
const id = this.#identify();
|
|
5998
|
-
let rejector;
|
|
5999
|
-
let resolver;
|
|
6000
|
-
const promise = new Promise((resolve, reject) => {
|
|
6001
|
-
rejector = reject;
|
|
6002
|
-
resolver = resolve;
|
|
6003
|
-
});
|
|
6004
|
-
const aborter = abortSignal == null ? void 0 : () => rejector(abortSignal.reason);
|
|
6005
|
-
signal?.addEventListener(EVENT_NAME, aborter, EVENT_OPTIONS);
|
|
6006
|
-
this.#items.push({
|
|
6007
|
-
id,
|
|
6008
|
-
parameters,
|
|
6009
|
-
promise,
|
|
6010
|
-
abort: aborter,
|
|
6011
|
-
key: this.#key,
|
|
6012
|
-
reject: rejector,
|
|
6013
|
-
resolve: resolver,
|
|
6014
|
-
signal: abortSignal
|
|
6015
|
-
});
|
|
6016
|
-
if (this.#options.autostart) this.#run();
|
|
6017
|
-
return {
|
|
6018
|
-
id,
|
|
6019
|
-
promise
|
|
6020
|
-
};
|
|
6021
|
-
}
|
|
6022
|
-
/**
|
|
6023
|
-
* Remove and reject all items in the queue
|
|
6024
|
-
*/
|
|
6025
|
-
clear() {
|
|
6026
|
-
const items = this.#items.splice(0);
|
|
6027
|
-
const { length } = items;
|
|
6028
|
-
for (let index = 0; index < length; index += 1) {
|
|
6029
|
-
const { abort, reject, signal } = items[index];
|
|
6030
|
-
reject(new QueueError(MESSAGE_CLEAR));
|
|
6031
|
-
signal?.removeEventListener(EVENT_NAME, abort);
|
|
6032
|
-
}
|
|
6033
|
-
}
|
|
6034
|
-
/**
|
|
6035
|
-
* Pause the queue
|
|
6036
|
-
*
|
|
6037
|
-
* - Currently running items will not be stopped
|
|
6038
|
-
* - New added items will not run until the queue is resumed
|
|
6039
|
-
*/
|
|
6040
|
-
pause() {
|
|
6041
|
-
this.#paused = true;
|
|
6042
|
-
}
|
|
6043
|
-
/**
|
|
6044
|
-
* Remove and reject a specific item in the queue
|
|
6045
|
-
*
|
|
6046
|
-
* @param id ID of queued item
|
|
6047
|
-
*/
|
|
6048
|
-
remove(id) {
|
|
6049
|
-
const index = this.#items.findIndex((item) => item.id === id);
|
|
6050
|
-
if (index > -1) {
|
|
6051
|
-
const { abort, reject, signal } = this.#items.splice(index, 1)[0];
|
|
6052
|
-
reject(new QueueError(MESSAGE_REMOVE));
|
|
6053
|
-
signal?.removeEventListener(EVENT_NAME, abort);
|
|
6054
|
-
}
|
|
6055
|
-
}
|
|
6056
|
-
/**
|
|
6057
|
-
* Resume the queue
|
|
6058
|
-
*/
|
|
6059
|
-
resume() {
|
|
6060
|
-
if (this.#paused) {
|
|
6061
|
-
const handled = this.#handled.splice(0);
|
|
6062
|
-
const { length } = handled;
|
|
6063
|
-
for (let index = 0; index < length; index += 1) handled[index]();
|
|
6064
|
-
}
|
|
6065
|
-
this.#paused = false;
|
|
6066
|
-
const length = Math.min(this.#options.concurrency, this.#items.length);
|
|
6067
|
-
for (let index = 0; index < length; index += 1) this.#run();
|
|
6068
|
-
}
|
|
6069
|
-
#identify() {
|
|
6070
|
-
this.#id += 1;
|
|
6071
|
-
return this.#id;
|
|
6072
|
-
}
|
|
6073
|
-
async #run() {
|
|
6074
|
-
if (this.#paused || this.#runners >= this.#options.concurrency) return;
|
|
6075
|
-
this.#runners += 1;
|
|
6076
|
-
let item = this.#items.shift();
|
|
6077
|
-
while (item != null) {
|
|
6078
|
-
let error = false;
|
|
6079
|
-
let result;
|
|
6080
|
-
try {
|
|
6081
|
-
if (!(item.signal?.aborted ?? false)) {
|
|
6082
|
-
const parameters = item.key == null ? item.parameters : [item.key, ...item.parameters];
|
|
6083
|
-
result = await this.#callback(...parameters);
|
|
6084
|
-
}
|
|
6085
|
-
} catch (thrown) {
|
|
6086
|
-
error = true;
|
|
6087
|
-
result = thrown;
|
|
6088
|
-
}
|
|
6089
|
-
if (this.#paused) {
|
|
6090
|
-
const paused = item;
|
|
6091
|
-
this.#handled.push(() => {
|
|
6092
|
-
handleQueuedResult(paused, error, result, this.#items.length === 0);
|
|
6093
|
-
});
|
|
6094
|
-
break;
|
|
6095
|
-
}
|
|
6096
|
-
handleQueuedResult(item, error, result, this.#items.length === 0);
|
|
6097
|
-
item = this.#items.shift();
|
|
6098
|
-
}
|
|
6099
|
-
this.#runners -= 1;
|
|
6100
|
-
}
|
|
6101
|
-
};
|
|
6102
|
-
/**
|
|
6103
5580
|
* An error thrown by the Queue when an operation fails
|
|
6104
5581
|
*/
|
|
6105
5582
|
var QueueError = class extends Error {
|
|
@@ -6108,6 +5585,119 @@ var QueueError = class extends Error {
|
|
|
6108
5585
|
this.name = ERROR_NAME;
|
|
6109
5586
|
}
|
|
6110
5587
|
};
|
|
5588
|
+
function createQueue(callback, options, key) {
|
|
5589
|
+
if (typeof callback !== "function") throw new TypeError(MESSAGE_CALLBACK);
|
|
5590
|
+
const state = {
|
|
5591
|
+
callback,
|
|
5592
|
+
key,
|
|
5593
|
+
handled: [],
|
|
5594
|
+
id: 0,
|
|
5595
|
+
items: [],
|
|
5596
|
+
options: getOptions(options),
|
|
5597
|
+
paused: !getBooleanOrDefault(options?.autostart, true),
|
|
5598
|
+
runners: 0
|
|
5599
|
+
};
|
|
5600
|
+
const instance = {
|
|
5601
|
+
add: (parameters, signal) => {
|
|
5602
|
+
if (instance.full) throw new QueueError(MESSAGE_MAXIMUM);
|
|
5603
|
+
const abortSignal = signal instanceof AbortSignal ? signal : void 0;
|
|
5604
|
+
if (abortSignal?.aborted ?? false) throw new Error(abortSignal.reason);
|
|
5605
|
+
const id = identify(state);
|
|
5606
|
+
let rejector;
|
|
5607
|
+
let resolver;
|
|
5608
|
+
const promise = new Promise((resolve, reject) => {
|
|
5609
|
+
rejector = reject;
|
|
5610
|
+
resolver = resolve;
|
|
5611
|
+
});
|
|
5612
|
+
const aborter = abortSignal == null ? void 0 : () => rejector(abortSignal.reason);
|
|
5613
|
+
signal?.addEventListener(EVENT_NAME, aborter, EVENT_OPTIONS);
|
|
5614
|
+
state.items.push({
|
|
5615
|
+
id,
|
|
5616
|
+
parameters,
|
|
5617
|
+
promise,
|
|
5618
|
+
abort: aborter,
|
|
5619
|
+
key: state.key,
|
|
5620
|
+
reject: rejector,
|
|
5621
|
+
resolve: resolver,
|
|
5622
|
+
signal: abortSignal
|
|
5623
|
+
});
|
|
5624
|
+
if (state.options.autostart) run(state);
|
|
5625
|
+
return {
|
|
5626
|
+
id,
|
|
5627
|
+
promise
|
|
5628
|
+
};
|
|
5629
|
+
},
|
|
5630
|
+
clear: () => {
|
|
5631
|
+
const items = state.items.splice(0);
|
|
5632
|
+
const { length } = items;
|
|
5633
|
+
for (let index = 0; index < length; index += 1) {
|
|
5634
|
+
const { abort, reject, signal } = items[index];
|
|
5635
|
+
reject(new QueueError(MESSAGE_CLEAR));
|
|
5636
|
+
signal?.removeEventListener(EVENT_NAME, abort);
|
|
5637
|
+
}
|
|
5638
|
+
},
|
|
5639
|
+
pause: () => {
|
|
5640
|
+
state.paused = true;
|
|
5641
|
+
},
|
|
5642
|
+
remove: (id) => {
|
|
5643
|
+
const index = state.items.findIndex((item) => item.id === id);
|
|
5644
|
+
if (index > -1) {
|
|
5645
|
+
const { abort, reject, signal } = state.items.splice(index, 1)[0];
|
|
5646
|
+
reject(new QueueError(MESSAGE_REMOVE));
|
|
5647
|
+
signal?.removeEventListener(EVENT_NAME, abort);
|
|
5648
|
+
}
|
|
5649
|
+
},
|
|
5650
|
+
resume: () => {
|
|
5651
|
+
if (state.paused) {
|
|
5652
|
+
const handled = state.handled.splice(0);
|
|
5653
|
+
const { length } = handled;
|
|
5654
|
+
for (let index = 0; index < length; index += 1) handled[index]();
|
|
5655
|
+
}
|
|
5656
|
+
state.paused = false;
|
|
5657
|
+
const length = Math.min(state.options.concurrency, state.items.length);
|
|
5658
|
+
for (let index = 0; index < length; index += 1) run(state);
|
|
5659
|
+
}
|
|
5660
|
+
};
|
|
5661
|
+
Object.defineProperties(instance, {
|
|
5662
|
+
[KEY_QUEUE]: {
|
|
5663
|
+
enumerable: false,
|
|
5664
|
+
value: NAME_QUEUE
|
|
5665
|
+
},
|
|
5666
|
+
active: {
|
|
5667
|
+
enumerable: true,
|
|
5668
|
+
get: () => state.runners > 0
|
|
5669
|
+
},
|
|
5670
|
+
autostart: {
|
|
5671
|
+
enumerable: true,
|
|
5672
|
+
get: () => state.options.autostart
|
|
5673
|
+
},
|
|
5674
|
+
concurrency: {
|
|
5675
|
+
enumerable: true,
|
|
5676
|
+
get: () => state.options.concurrency
|
|
5677
|
+
},
|
|
5678
|
+
empty: {
|
|
5679
|
+
enumerable: true,
|
|
5680
|
+
get: () => state.items.length === 0
|
|
5681
|
+
},
|
|
5682
|
+
full: {
|
|
5683
|
+
enumerable: true,
|
|
5684
|
+
get: () => state.options.maximum > 0 && state.items.length >= state.options.maximum
|
|
5685
|
+
},
|
|
5686
|
+
maximum: {
|
|
5687
|
+
enumerable: true,
|
|
5688
|
+
get: () => state.options.maximum
|
|
5689
|
+
},
|
|
5690
|
+
paused: {
|
|
5691
|
+
enumerable: true,
|
|
5692
|
+
get: () => state.paused
|
|
5693
|
+
},
|
|
5694
|
+
size: {
|
|
5695
|
+
enumerable: true,
|
|
5696
|
+
get: () => state.items.length
|
|
5697
|
+
}
|
|
5698
|
+
});
|
|
5699
|
+
return Object.freeze(instance);
|
|
5700
|
+
}
|
|
6111
5701
|
function getBooleanOrDefault(value, defaultValue) {
|
|
6112
5702
|
return typeof value === "boolean" ? value : defaultValue;
|
|
6113
5703
|
}
|
|
@@ -6119,27 +5709,193 @@ function getOptions(input) {
|
|
|
6119
5709
|
maximum: getNumberOrDefault(options.maximum, 0)
|
|
6120
5710
|
};
|
|
6121
5711
|
}
|
|
5712
|
+
function getQueue(state, key, add) {
|
|
5713
|
+
if (typeof key !== "string" || key.trim().length === 0) throw new TypeError(MESSAGE_KEY);
|
|
5714
|
+
let queue = state.queues.get(key);
|
|
5715
|
+
if (queue == null && add === true) {
|
|
5716
|
+
queue = createQueue(state.callback, state.options, key);
|
|
5717
|
+
state.queues.set(key, queue);
|
|
5718
|
+
}
|
|
5719
|
+
return queue;
|
|
5720
|
+
}
|
|
5721
|
+
function getStatus(state, status) {
|
|
5722
|
+
const queues = state.queues.entries();
|
|
5723
|
+
const result = [];
|
|
5724
|
+
for (const [key, queue] of queues) if (queue[status]) result.push(key);
|
|
5725
|
+
return result;
|
|
5726
|
+
}
|
|
6122
5727
|
function handleQueuedResult(item, error, result, finished) {
|
|
6123
5728
|
item.signal?.removeEventListener(EVENT_NAME, item.abort);
|
|
6124
|
-
if (item.signal?.aborted ?? false)
|
|
6125
|
-
|
|
6126
|
-
|
|
5729
|
+
if (item.signal?.aborted ?? false) {
|
|
5730
|
+
item.reject();
|
|
5731
|
+
return;
|
|
5732
|
+
}
|
|
5733
|
+
if (error) {
|
|
5734
|
+
item.reject(result);
|
|
5735
|
+
return;
|
|
5736
|
+
}
|
|
5737
|
+
item.resolve({
|
|
6127
5738
|
finished,
|
|
6128
5739
|
value: result
|
|
6129
5740
|
});
|
|
6130
5741
|
}
|
|
5742
|
+
function handleQueues(state, type, key) {
|
|
5743
|
+
if (typeof key === "string") {
|
|
5744
|
+
getQueue(state, key)?.[type]();
|
|
5745
|
+
return;
|
|
5746
|
+
}
|
|
5747
|
+
const queues = state.queues.values();
|
|
5748
|
+
for (const queue of queues) queue[type]();
|
|
5749
|
+
}
|
|
5750
|
+
function identify(state) {
|
|
5751
|
+
state.id += 1;
|
|
5752
|
+
return state.id;
|
|
5753
|
+
}
|
|
5754
|
+
/**
|
|
5755
|
+
* Is the value keyed queue?
|
|
5756
|
+
*
|
|
5757
|
+
* @param value Value to check
|
|
5758
|
+
* @returns `true` if the value is a keyed queue, otherwise `false`
|
|
5759
|
+
*/
|
|
5760
|
+
function isKeyedQueue(value) {
|
|
5761
|
+
return isQueueInstance(NAME_KEYED, value);
|
|
5762
|
+
}
|
|
5763
|
+
/**
|
|
5764
|
+
* Is the value a queue?
|
|
5765
|
+
*
|
|
5766
|
+
* @param value Value to check
|
|
5767
|
+
* @returns `true` if the value is a queue, otherwise `false`
|
|
5768
|
+
*/
|
|
5769
|
+
function isQueue(value) {
|
|
5770
|
+
return isQueueInstance(NAME_QUEUE, value);
|
|
5771
|
+
}
|
|
5772
|
+
function isQueueInstance(name, value) {
|
|
5773
|
+
return typeof value === "object" && value != null && value[KEY_QUEUE] === name;
|
|
5774
|
+
}
|
|
6131
5775
|
function keyedQueue(callback, options) {
|
|
6132
5776
|
if (typeof callback !== "function") throw new TypeError(MESSAGE_CALLBACK);
|
|
6133
|
-
|
|
5777
|
+
const state = {
|
|
5778
|
+
callback,
|
|
5779
|
+
options: getOptions(options),
|
|
5780
|
+
queues: /* @__PURE__ */ new Map()
|
|
5781
|
+
};
|
|
5782
|
+
const instance = {
|
|
5783
|
+
add: (key, parameters, signal) => getQueue(state, key, true).add(parameters, signal),
|
|
5784
|
+
clear: (key) => {
|
|
5785
|
+
handleQueues(state, HANDLE_CLEAR, key);
|
|
5786
|
+
},
|
|
5787
|
+
get: (key) => getQueue(state, key),
|
|
5788
|
+
pause: (key) => {
|
|
5789
|
+
handleQueues(state, HANDLE_PAUSE, key);
|
|
5790
|
+
},
|
|
5791
|
+
remove: (key, id) => {
|
|
5792
|
+
if (key == null) {
|
|
5793
|
+
handleQueues(state, HANDLE_CLEAR);
|
|
5794
|
+
state.queues.clear();
|
|
5795
|
+
return;
|
|
5796
|
+
}
|
|
5797
|
+
const queue = getQueue(state, key);
|
|
5798
|
+
if (queue == null) return;
|
|
5799
|
+
if (typeof id === "number") {
|
|
5800
|
+
queue.remove(id);
|
|
5801
|
+
return;
|
|
5802
|
+
}
|
|
5803
|
+
queue.clear();
|
|
5804
|
+
state.queues.delete(key);
|
|
5805
|
+
},
|
|
5806
|
+
resume: (key) => {
|
|
5807
|
+
handleQueues(state, HANDLE_RESUME, key);
|
|
5808
|
+
}
|
|
5809
|
+
};
|
|
5810
|
+
Object.defineProperties(instance, {
|
|
5811
|
+
[KEY_QUEUE]: {
|
|
5812
|
+
enumerable: false,
|
|
5813
|
+
value: NAME_KEYED
|
|
5814
|
+
},
|
|
5815
|
+
active: {
|
|
5816
|
+
enumerable: true,
|
|
5817
|
+
get: () => getStatus(state, STATUS_ACTIVE)
|
|
5818
|
+
},
|
|
5819
|
+
autostart: {
|
|
5820
|
+
enumerable: true,
|
|
5821
|
+
get: () => state.options.autostart
|
|
5822
|
+
},
|
|
5823
|
+
concurrency: {
|
|
5824
|
+
enumerable: true,
|
|
5825
|
+
get: () => state.options.concurrency
|
|
5826
|
+
},
|
|
5827
|
+
empty: {
|
|
5828
|
+
enumerable: true,
|
|
5829
|
+
get: () => getStatus(state, STATUS_EMPTY)
|
|
5830
|
+
},
|
|
5831
|
+
full: {
|
|
5832
|
+
enumerable: true,
|
|
5833
|
+
get: () => getStatus(state, STATUS_FULL)
|
|
5834
|
+
},
|
|
5835
|
+
items: {
|
|
5836
|
+
enumerable: true,
|
|
5837
|
+
get: () => {
|
|
5838
|
+
const size = {};
|
|
5839
|
+
const queues = state.queues.entries();
|
|
5840
|
+
for (const [key, queue] of queues) size[key] = queue.size;
|
|
5841
|
+
return size;
|
|
5842
|
+
}
|
|
5843
|
+
},
|
|
5844
|
+
keys: {
|
|
5845
|
+
enumerable: true,
|
|
5846
|
+
get: () => [...state.queues.keys()]
|
|
5847
|
+
},
|
|
5848
|
+
maximum: {
|
|
5849
|
+
enumerable: true,
|
|
5850
|
+
get: () => state.options.maximum
|
|
5851
|
+
},
|
|
5852
|
+
paused: {
|
|
5853
|
+
enumerable: true,
|
|
5854
|
+
get: () => getStatus(state, STATUS_PAUSED)
|
|
5855
|
+
},
|
|
5856
|
+
queues: {
|
|
5857
|
+
enumerable: true,
|
|
5858
|
+
get: () => state.queues.size
|
|
5859
|
+
}
|
|
5860
|
+
});
|
|
5861
|
+
return Object.freeze(instance);
|
|
6134
5862
|
}
|
|
6135
5863
|
function queue(callback, options) {
|
|
6136
|
-
|
|
6137
|
-
return new Queue(callback, getOptions(options));
|
|
5864
|
+
return createQueue(callback, options);
|
|
6138
5865
|
}
|
|
6139
5866
|
queue.keyed = keyedQueue;
|
|
5867
|
+
async function run(state) {
|
|
5868
|
+
if (state.paused || state.runners >= state.options.concurrency) return;
|
|
5869
|
+
state.runners += 1;
|
|
5870
|
+
let item = state.items.shift();
|
|
5871
|
+
while (item != null) {
|
|
5872
|
+
let error = false;
|
|
5873
|
+
let result;
|
|
5874
|
+
try {
|
|
5875
|
+
if (!(item.signal?.aborted ?? false)) {
|
|
5876
|
+
const parameters = item.key == null ? item.parameters : [item.key, ...item.parameters];
|
|
5877
|
+
result = await state.callback(...parameters);
|
|
5878
|
+
}
|
|
5879
|
+
} catch (thrown) {
|
|
5880
|
+
error = true;
|
|
5881
|
+
result = thrown;
|
|
5882
|
+
}
|
|
5883
|
+
if (state.paused) {
|
|
5884
|
+
const paused = item;
|
|
5885
|
+
state.handled.push(() => {
|
|
5886
|
+
handleQueuedResult(paused, error, result, state.items.length === 0);
|
|
5887
|
+
});
|
|
5888
|
+
break;
|
|
5889
|
+
}
|
|
5890
|
+
handleQueuedResult(item, error, result, state.items.length === 0);
|
|
5891
|
+
item = state.items.shift();
|
|
5892
|
+
}
|
|
5893
|
+
state.runners -= 1;
|
|
5894
|
+
}
|
|
6140
5895
|
const ERROR_NAME = "QueueError";
|
|
6141
5896
|
const EVENT_NAME = "abort";
|
|
6142
5897
|
const EVENT_OPTIONS = { once: true };
|
|
5898
|
+
const KEY_QUEUE = "$queue";
|
|
6143
5899
|
const HANDLE_CLEAR = "clear";
|
|
6144
5900
|
const HANDLE_PAUSE = "pause";
|
|
6145
5901
|
const HANDLE_RESUME = "resume";
|
|
@@ -6148,6 +5904,8 @@ const MESSAGE_CLEAR = "Queue was cleared";
|
|
|
6148
5904
|
const MESSAGE_KEY = "Key must be a non-empty string";
|
|
6149
5905
|
const MESSAGE_MAXIMUM = "Queue has reached its maximum size";
|
|
6150
5906
|
const MESSAGE_REMOVE = "Item removed from queue";
|
|
5907
|
+
const NAME_KEYED = "keyedQueue";
|
|
5908
|
+
const NAME_QUEUE = "queue";
|
|
6151
5909
|
const STATUS_ACTIVE = "active";
|
|
6152
5910
|
const STATUS_EMPTY = "empty";
|
|
6153
5911
|
const STATUS_FULL = "full";
|
|
@@ -6356,4 +6114,4 @@ var SizedSet = class extends Set {
|
|
|
6356
6114
|
}
|
|
6357
6115
|
};
|
|
6358
6116
|
//#endregion
|
|
6359
|
-
export { CancelablePromise, Logger, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isColor, isConstructor, isEmpty, isError, isFrozen, isFulfilled, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isInstanceOf, isKey, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isOk, isPlainObject, isPrimitive, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|
|
6117
|
+
export { CancelablePromise, Logger, PROMISE_ABORT_EVENT, PROMISE_ABORT_OPTIONS, PROMISE_ERROR_NAME, PROMISE_MESSAGE_EXPECTATION_ATTEMPT, PROMISE_MESSAGE_EXPECTATION_RESULT, PROMISE_MESSAGE_EXPECTATION_TIMED, PROMISE_MESSAGE_TIMEOUT, PROMISE_STRATEGY_ALL, PROMISE_STRATEGY_DEFAULT, PROMISE_TYPE_FULFILLED, PROMISE_TYPE_REJECTED, PromiseTimeoutError, QueueError, RetryError, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SizedMap, SizedSet, assert, assertCondition, assertDefined, assertInstanceOf, assertIs, assertProperty, assign, asyncAttempt, asyncDebounce, asyncFlow, asyncMatchResult, asyncOnce, asyncPipe, asyncThrottle, attempt, attemptAsyncFlow, attemptAsyncPipe, attemptFlow, attemptPipe, attemptPromise, average, beacon, between, camelCase, cancelable, capitalize, ceil, chunk, clamp, clone, compact, compare, copy, count, debounce, deburr, dedent, delay, deregisterCloner, deregisterComparator, deregisterEqualizer, diff, difference, drop, endsWith, endsWithArray, equal, error, exclude, exists, filter, find, findLast, first, firstOrDefault, flatFreeze, flatten, floor, flow, freeze, fromQuery, toPromise as fromResult, toPromise, fuzzy, fuzzyMatch, getArray, getArrayComparison, getColor, getError, getForegroundColor, getHexColor, getHexaColor, getHslColor, getHslaColor, getHwbColor, getHwbaColor, getNormalizedHex, getNumber, getRandomBoolean, getRandomCharacters, getRandomColor, getRandomFloatingNumber as getRandomFloat, getRandomHex, getRandomInteger, getRandomItem, getRandomItems, getRgbColor, getRgbaColor, getSortedIndex, getString, getTimedPromise, getUuid, getValue, groupArraysBy, groupBy, handleResult, hasValue, hasValueResult, herald, hexToHsl, hexToHsla, hexToHwb, hexToHwba, hexToRgb, hexToRgba, hslToHex, hslToHwb, hslToHwba, hslToRgb, hslToRgba, hwbToHex, hwbToHsl, hwbToHsla, hwbToRgb, hwbToRgba, ignoreKey, inMap, inSet, includes, includesArray, indexOf, indexOfArray, initializeAssigner, initializeEqualizer, initializeMerger, initializeNormalizer, initializeSorter, initializeTemplater, initializeTransformer, insert, interpolate, intersection, isArrayOrPlainObject, isBeacon, isColor, isConstructor, isEmpty, isError, isEvents, isFrozen, isFulfilled, isHerald, isHexColor, isHslColor, isHslLike, isHslaColor, isHwbColor, isHwbLike, isHwbaColor, isHwbaLike, isInstanceOf, isKey, isKeyedQueue, isLogger, isNonArrayOrPlainObject, isNonConstructor, isNonEmpty, isNonInstanceOf, isNonKey, isNonNullable, isNonNullableOrEmpty, isNonNullableOrWhitespace, isNonNumber, isNonNumerical, isNonObject, isNonPlainObject, isNonPrimitive, isNonTypedArray, isNullable, isNullableOrEmpty, isNullableOrWhitespace, isNumber, isNumerical, isObject, isObservable, isOk, isPlainObject, isPrimitive, isQueue, isQueueInstance, isRejected, isResult, isRgbColor, isRgbLike, isRgbaColor, isSorted, isSubscription, isTimedLogger, isTypedArray, join, kebabCase, keyedQueue, last, lastIndexOf, lastOrDefault, lowerCase, matchResult, max, median, memoize, merge, min, move, moveIndices, moveToIndex, noop, normalize, ok, omit, once, parse, partition, pascalCase, pick, pipe, promises, push, queue, range, registerCloner, registerComparator, registerEqualizer, resultPromises, retry, reverse, rgbToHex, rgbToHsl, rgbToHsla, rgbToHwb, rgbToHwba, round, select, setValue, settlePromise, shake, shuffle, single, slice, smush, snakeCase, sort, splice, startsWith, startsWithArray, sum, swap, take, template, throttle, timed, times, titleCase, toMap, toMapArrays, toQuery, toRecord, toRecordArrays, toResult, toSet, toggle, transform, trim, truncate, tryDecode, tryEncode, union, unique, unsmush, unwrap, update, upperCase, words };
|