likec4 1.48.0 → 1.49.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.
Files changed (113) hide show
  1. package/README.md +11 -1
  2. package/__app__/src/likec4.js +5595 -4127
  3. package/__app__/src/routes/index.js +3 -153
  4. package/__app__/src/routes/projects.js +21 -1087
  5. package/__app__/src/routes/single.js +1221 -16
  6. package/__app__/src/style.css +1 -1
  7. package/__app__/src/vendors.js +3507 -894
  8. package/__app__/src/webcomponent.js +1 -1
  9. package/config/schema.json +155 -143
  10. package/dist/THIRD-PARTY-LICENSES.md +1739 -0
  11. package/dist/_chunks/GraphvizBinaryAdapter.mjs +72 -0
  12. package/dist/_chunks/filenames.mjs +14 -0
  13. package/dist/_chunks/index.d.mts +224 -129
  14. package/dist/_chunks/index2.d.mts +2033 -1908
  15. package/dist/_chunks/libs/@chevrotain/gast.mjs +1 -3969
  16. package/dist/_chunks/libs/@chevrotain/regexp-to-ast.mjs +9 -785
  17. package/dist/_chunks/libs/@chevrotain/utils.mjs +1 -37
  18. package/dist/_chunks/libs/@hono/mcp.mjs +34 -0
  19. package/dist/_chunks/libs/@hono/node-server.mjs +1 -436
  20. package/dist/_chunks/libs/@logtape/logtape.d.mts +741 -0
  21. package/dist/_chunks/libs/@logtape/logtape.mjs +6 -1354
  22. package/dist/_chunks/libs/@lume/kiwi.mjs +1 -1355
  23. package/dist/_chunks/libs/@modelcontextprotocol/sdk.d.mts +14 -14
  24. package/dist/_chunks/libs/@modelcontextprotocol/sdk.mjs +12 -25105
  25. package/dist/_chunks/libs/@msgpack/msgpack.mjs +1 -1503
  26. package/dist/_chunks/libs/@nanostores/react.mjs +1 -30
  27. package/dist/_chunks/libs/@smithy/util-base64.mjs +1 -100
  28. package/dist/_chunks/libs/ajv.mjs +1 -777
  29. package/dist/_chunks/libs/atomically.mjs +1 -362
  30. package/dist/_chunks/libs/birpc.mjs +1 -201
  31. package/dist/_chunks/libs/chevrotain-allstar.mjs +2 -850
  32. package/dist/_chunks/libs/chevrotain.mjs +55 -6229
  33. package/dist/_chunks/libs/conf.mjs +1 -2258
  34. package/dist/_chunks/libs/defu.mjs +1 -42
  35. package/dist/_chunks/libs/esm-env.mjs +1 -5
  36. package/dist/_chunks/libs/eventemitter3.mjs +1 -243
  37. package/dist/_chunks/libs/fast-equals.mjs +1 -446
  38. package/dist/_chunks/libs/find-up-simple.mjs +1 -24
  39. package/dist/_chunks/libs/get-port.mjs +1 -107
  40. package/dist/_chunks/libs/is-docker.mjs +1 -26
  41. package/dist/_chunks/libs/is-error-instance.mjs +1 -26
  42. package/dist/_chunks/libs/is-inside-container.mjs +1 -20
  43. package/dist/_chunks/libs/is-plain-obj.mjs +1 -9
  44. package/dist/_chunks/libs/isexe.mjs +1 -127
  45. package/dist/_chunks/libs/json5.mjs +14 -959
  46. package/dist/_chunks/libs/khroma.mjs +1 -605
  47. package/dist/_chunks/libs/ky.mjs +2 -807
  48. package/dist/_chunks/libs/langium.d.mts +2880 -2844
  49. package/dist/_chunks/libs/langium.mjs +32 -20351
  50. package/dist/_chunks/libs/merge-error-cause.mjs +2 -746
  51. package/dist/_chunks/libs/nanostores.mjs +1 -198
  52. package/dist/_chunks/libs/p-limit.mjs +1 -120
  53. package/dist/_chunks/libs/p-queue.mjs +1 -449
  54. package/dist/_chunks/libs/package-manager-detector.mjs +1 -559
  55. package/dist/_chunks/libs/package-up.mjs +1 -10
  56. package/dist/_chunks/libs/parse-ms.mjs +1 -36
  57. package/dist/_chunks/libs/pathe.mjs +1 -0
  58. package/dist/_chunks/libs/picomatch.mjs +1 -1673
  59. package/dist/_chunks/libs/pretty-ms.mjs +1 -80
  60. package/dist/_chunks/libs/remeda.mjs +1 -690
  61. package/dist/_chunks/libs/safe-stringify.mjs +1 -21
  62. package/dist/_chunks/libs/strip-indent.mjs +1 -15
  63. package/dist/_chunks/libs/tinyrainbow.mjs +1 -88
  64. package/dist/_chunks/libs/ts-graphviz.mjs +4 -725
  65. package/dist/_chunks/libs/ufo.mjs +1 -240
  66. package/dist/_chunks/libs/which.mjs +1 -84
  67. package/dist/_chunks/libs/word-wrap.mjs +12 -43
  68. package/dist/_chunks/node.mjs +481 -0
  69. package/dist/_chunks/plugin.mjs +98 -772
  70. package/dist/_chunks/rolldown-runtime.mjs +1 -48
  71. package/dist/_chunks/sequence-view.mjs +1 -575
  72. package/dist/cli/index.mjs +127 -1846
  73. package/dist/config/index.d.mts +2 -2
  74. package/dist/config/index.mjs +1 -6
  75. package/dist/index.d.mts +148 -7
  76. package/dist/index.mjs +1 -21
  77. package/dist/model/builder.mjs +1 -3
  78. package/dist/model/index.d.mts +57 -3
  79. package/dist/model/index.mjs +1 -5
  80. package/dist/vite-plugin/index.d.mts +4 -3
  81. package/dist/vite-plugin/index.mjs +1 -22
  82. package/dist/vite-plugin/internal.d.mts +5 -5
  83. package/dist/vite-plugin/internal.mjs +1 -68
  84. package/package.json +60 -41
  85. package/react/{index.d.ts → index.d.mts} +112 -70
  86. package/react/{index.js → index.mjs} +21361 -22064
  87. package/react/package.json +2 -5
  88. package/vite-plugin-modules.d.ts +5 -5
  89. package/dist/_chunks/LikeC4.d.mts +0 -121
  90. package/dist/_chunks/LikeC4.mjs +0 -202
  91. package/dist/_chunks/config-app.prod.d.mts +0 -18
  92. package/dist/_chunks/config-app.prod.mjs +0 -188
  93. package/dist/_chunks/config-webcomponent.prod.mjs +0 -71
  94. package/dist/_chunks/define-config.mjs +0 -409
  95. package/dist/_chunks/index3.d.mts +0 -60
  96. package/dist/_chunks/index4.d.mts +0 -1
  97. package/dist/_chunks/libs/@smithy/is-array-buffer.mjs +0 -10
  98. package/dist/_chunks/libs/hono.mjs +0 -1829
  99. package/dist/_chunks/libs/nanoid.mjs +0 -29
  100. package/dist/_chunks/model.mjs +0 -12
  101. package/dist/_chunks/module.d.mts +0 -71
  102. package/dist/_chunks/module.mjs +0 -18657
  103. package/dist/_chunks/vite-build.mjs +0 -69
  104. package/dist/_chunks/vite-dev.mjs +0 -79
  105. package/dist/_chunks/vite-preview.mjs +0 -27
  106. package/dist/language/module.d.mts +0 -5
  107. package/dist/language/module.mjs +0 -20
  108. package/dist/vite/vite-build.d.mts +0 -26
  109. package/dist/vite/vite-build.mjs +0 -27
  110. package/dist/vite/vite-dev.d.mts +0 -34
  111. package/dist/vite/vite-dev.mjs +0 -29
  112. package/dist/vite/vite-preview.d.mts +0 -20
  113. package/dist/vite/vite-preview.mjs +0 -26
@@ -1,449 +1 @@
1
- import { t as import_eventemitter3 } from "./eventemitter3.mjs";
2
-
3
- //#region ../../node_modules/.pnpm/p-timeout@6.1.4/node_modules/p-timeout/index.js
4
- var TimeoutError = class extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = "TimeoutError";
8
- }
9
- };
10
- /**
11
- An error to be thrown when the request is aborted by AbortController.
12
- DOMException is thrown instead of this Error when DOMException is available.
13
- */
14
- var AbortError = class extends Error {
15
- constructor(message) {
16
- super();
17
- this.name = "AbortError";
18
- this.message = message;
19
- }
20
- };
21
- /**
22
- TODO: Remove AbortError and just throw DOMException when targeting Node 18.
23
- */
24
- const getDOMException = (errorMessage) => globalThis.DOMException === void 0 ? new AbortError(errorMessage) : new DOMException(errorMessage);
25
- /**
26
- TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
27
- */
28
- const getAbortedReason = (signal) => {
29
- const reason = signal.reason === void 0 ? getDOMException("This operation was aborted.") : signal.reason;
30
- return reason instanceof Error ? reason : getDOMException(reason);
31
- };
32
- function pTimeout(promise, options) {
33
- const { milliseconds, fallback, message, customTimers = {
34
- setTimeout,
35
- clearTimeout
36
- } } = options;
37
- let timer;
38
- let abortHandler;
39
- const cancelablePromise = new Promise((resolve, reject) => {
40
- if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
41
- if (options.signal) {
42
- const { signal } = options;
43
- if (signal.aborted) reject(getAbortedReason(signal));
44
- abortHandler = () => {
45
- reject(getAbortedReason(signal));
46
- };
47
- signal.addEventListener("abort", abortHandler, { once: true });
48
- }
49
- if (milliseconds === Number.POSITIVE_INFINITY) {
50
- promise.then(resolve, reject);
51
- return;
52
- }
53
- const timeoutError = new TimeoutError();
54
- timer = customTimers.setTimeout.call(void 0, () => {
55
- if (fallback) {
56
- try {
57
- resolve(fallback());
58
- } catch (error) {
59
- reject(error);
60
- }
61
- return;
62
- }
63
- if (typeof promise.cancel === "function") promise.cancel();
64
- if (message === false) resolve();
65
- else if (message instanceof Error) reject(message);
66
- else {
67
- timeoutError.message = message ?? `Promise timed out after ${milliseconds} milliseconds`;
68
- reject(timeoutError);
69
- }
70
- }, milliseconds);
71
- (async () => {
72
- try {
73
- resolve(await promise);
74
- } catch (error) {
75
- reject(error);
76
- }
77
- })();
78
- }).finally(() => {
79
- cancelablePromise.clear();
80
- if (abortHandler && options.signal) options.signal.removeEventListener("abort", abortHandler);
81
- });
82
- cancelablePromise.clear = () => {
83
- customTimers.clearTimeout.call(void 0, timer);
84
- timer = void 0;
85
- };
86
- return cancelablePromise;
87
- }
88
-
89
- //#endregion
90
- //#region ../../node_modules/.pnpm/p-queue@8.1.1/node_modules/p-queue/dist/lower-bound.js
91
- function lowerBound(array, value, comparator) {
92
- let first = 0;
93
- let count = array.length;
94
- while (count > 0) {
95
- const step = Math.trunc(count / 2);
96
- let it = first + step;
97
- if (comparator(array[it], value) <= 0) {
98
- first = ++it;
99
- count -= step + 1;
100
- } else count = step;
101
- }
102
- return first;
103
- }
104
-
105
- //#endregion
106
- //#region ../../node_modules/.pnpm/p-queue@8.1.1/node_modules/p-queue/dist/priority-queue.js
107
- var PriorityQueue = class {
108
- #queue = [];
109
- enqueue(run, options) {
110
- options = {
111
- priority: 0,
112
- ...options
113
- };
114
- const element = {
115
- priority: options.priority,
116
- id: options.id,
117
- run
118
- };
119
- if (this.size === 0 || this.#queue[this.size - 1].priority >= options.priority) {
120
- this.#queue.push(element);
121
- return;
122
- }
123
- const index = lowerBound(this.#queue, element, (a, b) => b.priority - a.priority);
124
- this.#queue.splice(index, 0, element);
125
- }
126
- setPriority(id, priority) {
127
- const index = this.#queue.findIndex((element) => element.id === id);
128
- if (index === -1) throw new ReferenceError(`No promise function with the id "${id}" exists in the queue.`);
129
- const [item] = this.#queue.splice(index, 1);
130
- this.enqueue(item.run, {
131
- priority,
132
- id
133
- });
134
- }
135
- dequeue() {
136
- return this.#queue.shift()?.run;
137
- }
138
- filter(options) {
139
- return this.#queue.filter((element) => element.priority === options.priority).map((element) => element.run);
140
- }
141
- get size() {
142
- return this.#queue.length;
143
- }
144
- };
145
-
146
- //#endregion
147
- //#region ../../node_modules/.pnpm/p-queue@8.1.1/node_modules/p-queue/dist/index.js
148
- /**
149
- Promise queue with concurrency control.
150
- */
151
- var PQueue = class extends import_eventemitter3.default {
152
- #carryoverConcurrencyCount;
153
- #isIntervalIgnored;
154
- #intervalCount = 0;
155
- #intervalCap;
156
- #interval;
157
- #intervalEnd = 0;
158
- #intervalId;
159
- #timeoutId;
160
- #queue;
161
- #queueClass;
162
- #pending = 0;
163
- #concurrency;
164
- #isPaused;
165
- #throwOnTimeout;
166
- #idAssigner = 1n;
167
- /**
168
- Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
169
-
170
- Applies to each future operation.
171
- */
172
- timeout;
173
- constructor(options) {
174
- super();
175
- options = {
176
- carryoverConcurrencyCount: false,
177
- intervalCap: Number.POSITIVE_INFINITY,
178
- interval: 0,
179
- concurrency: Number.POSITIVE_INFINITY,
180
- autoStart: true,
181
- queueClass: PriorityQueue,
182
- ...options
183
- };
184
- if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${options.intervalCap?.toString() ?? ""}\` (${typeof options.intervalCap})`);
185
- if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval?.toString() ?? ""}\` (${typeof options.interval})`);
186
- this.#carryoverConcurrencyCount = options.carryoverConcurrencyCount;
187
- this.#isIntervalIgnored = options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0;
188
- this.#intervalCap = options.intervalCap;
189
- this.#interval = options.interval;
190
- this.#queue = new options.queueClass();
191
- this.#queueClass = options.queueClass;
192
- this.concurrency = options.concurrency;
193
- this.timeout = options.timeout;
194
- this.#throwOnTimeout = options.throwOnTimeout === true;
195
- this.#isPaused = options.autoStart === false;
196
- }
197
- get #doesIntervalAllowAnother() {
198
- return this.#isIntervalIgnored || this.#intervalCount < this.#intervalCap;
199
- }
200
- get #doesConcurrentAllowAnother() {
201
- return this.#pending < this.#concurrency;
202
- }
203
- #next() {
204
- this.#pending--;
205
- this.#tryToStartAnother();
206
- this.emit("next");
207
- }
208
- #onResumeInterval() {
209
- this.#onInterval();
210
- this.#initializeIntervalIfNeeded();
211
- this.#timeoutId = void 0;
212
- }
213
- get #isIntervalPaused() {
214
- const now = Date.now();
215
- if (this.#intervalId === void 0) {
216
- const delay = this.#intervalEnd - now;
217
- if (delay < 0) this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
218
- else {
219
- if (this.#timeoutId === void 0) this.#timeoutId = setTimeout(() => {
220
- this.#onResumeInterval();
221
- }, delay);
222
- return true;
223
- }
224
- }
225
- return false;
226
- }
227
- #tryToStartAnother() {
228
- if (this.#queue.size === 0) {
229
- if (this.#intervalId) clearInterval(this.#intervalId);
230
- this.#intervalId = void 0;
231
- this.emit("empty");
232
- if (this.#pending === 0) this.emit("idle");
233
- return false;
234
- }
235
- if (!this.#isPaused) {
236
- const canInitializeInterval = !this.#isIntervalPaused;
237
- if (this.#doesIntervalAllowAnother && this.#doesConcurrentAllowAnother) {
238
- const job = this.#queue.dequeue();
239
- if (!job) return false;
240
- this.emit("active");
241
- job();
242
- if (canInitializeInterval) this.#initializeIntervalIfNeeded();
243
- return true;
244
- }
245
- }
246
- return false;
247
- }
248
- #initializeIntervalIfNeeded() {
249
- if (this.#isIntervalIgnored || this.#intervalId !== void 0) return;
250
- this.#intervalId = setInterval(() => {
251
- this.#onInterval();
252
- }, this.#interval);
253
- this.#intervalEnd = Date.now() + this.#interval;
254
- }
255
- #onInterval() {
256
- if (this.#intervalCount === 0 && this.#pending === 0 && this.#intervalId) {
257
- clearInterval(this.#intervalId);
258
- this.#intervalId = void 0;
259
- }
260
- this.#intervalCount = this.#carryoverConcurrencyCount ? this.#pending : 0;
261
- this.#processQueue();
262
- }
263
- /**
264
- Executes all queued functions until it reaches the limit.
265
- */
266
- #processQueue() {
267
- while (this.#tryToStartAnother());
268
- }
269
- get concurrency() {
270
- return this.#concurrency;
271
- }
272
- set concurrency(newConcurrency) {
273
- if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
274
- this.#concurrency = newConcurrency;
275
- this.#processQueue();
276
- }
277
- async #throwOnAbort(signal) {
278
- return new Promise((_resolve, reject) => {
279
- signal.addEventListener("abort", () => {
280
- reject(signal.reason);
281
- }, { once: true });
282
- });
283
- }
284
- /**
285
- Updates the priority of a promise function by its id, affecting its execution order. Requires a defined concurrency limit to take effect.
286
-
287
- For example, this can be used to prioritize a promise function to run earlier.
288
-
289
- ```js
290
- import PQueue from 'p-queue';
291
-
292
- const queue = new PQueue({concurrency: 1});
293
-
294
- queue.add(async () => '🦄', {priority: 1});
295
- queue.add(async () => '🦀', {priority: 0, id: '🦀'});
296
- queue.add(async () => '🦄', {priority: 1});
297
- queue.add(async () => '🦄', {priority: 1});
298
-
299
- queue.setPriority('🦀', 2);
300
- ```
301
-
302
- In this case, the promise function with `id: '🦀'` runs second.
303
-
304
- You can also deprioritize a promise function to delay its execution:
305
-
306
- ```js
307
- import PQueue from 'p-queue';
308
-
309
- const queue = new PQueue({concurrency: 1});
310
-
311
- queue.add(async () => '🦄', {priority: 1});
312
- queue.add(async () => '🦀', {priority: 1, id: '🦀'});
313
- queue.add(async () => '🦄');
314
- queue.add(async () => '🦄', {priority: 0});
315
-
316
- queue.setPriority('🦀', -1);
317
- ```
318
- Here, the promise function with `id: '🦀'` executes last.
319
- */
320
- setPriority(id, priority) {
321
- this.#queue.setPriority(id, priority);
322
- }
323
- async add(function_, options = {}) {
324
- options.id ??= (this.#idAssigner++).toString();
325
- options = {
326
- timeout: this.timeout,
327
- throwOnTimeout: this.#throwOnTimeout,
328
- ...options
329
- };
330
- return new Promise((resolve, reject) => {
331
- this.#queue.enqueue(async () => {
332
- this.#pending++;
333
- try {
334
- options.signal?.throwIfAborted();
335
- this.#intervalCount++;
336
- let operation = function_({ signal: options.signal });
337
- if (options.timeout) operation = pTimeout(Promise.resolve(operation), { milliseconds: options.timeout });
338
- if (options.signal) operation = Promise.race([operation, this.#throwOnAbort(options.signal)]);
339
- const result = await operation;
340
- resolve(result);
341
- this.emit("completed", result);
342
- } catch (error) {
343
- if (error instanceof TimeoutError && !options.throwOnTimeout) {
344
- resolve();
345
- return;
346
- }
347
- reject(error);
348
- this.emit("error", error);
349
- } finally {
350
- this.#next();
351
- }
352
- }, options);
353
- this.emit("add");
354
- this.#tryToStartAnother();
355
- });
356
- }
357
- async addAll(functions, options) {
358
- return Promise.all(functions.map(async (function_) => this.add(function_, options)));
359
- }
360
- /**
361
- Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
362
- */
363
- start() {
364
- if (!this.#isPaused) return this;
365
- this.#isPaused = false;
366
- this.#processQueue();
367
- return this;
368
- }
369
- /**
370
- Put queue execution on hold.
371
- */
372
- pause() {
373
- this.#isPaused = true;
374
- }
375
- /**
376
- Clear the queue.
377
- */
378
- clear() {
379
- this.#queue = new this.#queueClass();
380
- }
381
- /**
382
- Can be called multiple times. Useful if you for example add additional items at a later time.
383
-
384
- @returns A promise that settles when the queue becomes empty.
385
- */
386
- async onEmpty() {
387
- if (this.#queue.size === 0) return;
388
- await this.#onEvent("empty");
389
- }
390
- /**
391
- @returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
392
-
393
- If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item.
394
-
395
- Note that this only limits the number of items waiting to start. There could still be up to `concurrency` jobs already running that this call does not include in its calculation.
396
- */
397
- async onSizeLessThan(limit) {
398
- if (this.#queue.size < limit) return;
399
- await this.#onEvent("next", () => this.#queue.size < limit);
400
- }
401
- /**
402
- The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
403
-
404
- @returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
405
- */
406
- async onIdle() {
407
- if (this.#pending === 0 && this.#queue.size === 0) return;
408
- await this.#onEvent("idle");
409
- }
410
- async #onEvent(event, filter) {
411
- return new Promise((resolve) => {
412
- const listener = () => {
413
- if (filter && !filter()) return;
414
- this.off(event, listener);
415
- resolve();
416
- };
417
- this.on(event, listener);
418
- });
419
- }
420
- /**
421
- Size of the queue, the number of queued items waiting to run.
422
- */
423
- get size() {
424
- return this.#queue.size;
425
- }
426
- /**
427
- Size of the queue, filtered by the given options.
428
-
429
- For example, this can be used to find the number of items remaining in the queue with a specific priority level.
430
- */
431
- sizeBy(options) {
432
- return this.#queue.filter(options).length;
433
- }
434
- /**
435
- Number of running items (no longer in the queue).
436
- */
437
- get pending() {
438
- return this.#pending;
439
- }
440
- /**
441
- Whether the queue is currently paused.
442
- */
443
- get isPaused() {
444
- return this.#isPaused;
445
- }
446
- };
447
-
448
- //#endregion
449
- export { PQueue as t };
1
+ import{t as import_eventemitter3}from"./eventemitter3.mjs";var TimeoutError=class extends Error{constructor(e){super(e),this.name=`TimeoutError`}},AbortError=class extends Error{constructor(e){super(),this.name=`AbortError`,this.message=e}};const getDOMException=e=>globalThis.DOMException===void 0?new AbortError(e):new DOMException(e),getAbortedReason=e=>{let t=e.reason===void 0?getDOMException(`This operation was aborted.`):e.reason;return t instanceof Error?t:getDOMException(t)};function pTimeout(e,n){let{milliseconds:r,fallback:a,message:o,customTimers:s={setTimeout,clearTimeout}}=n,c,l,u=new Promise((u,d)=>{if(typeof r!=`number`||Math.sign(r)!==1)throw TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(n.signal){let{signal:e}=n;e.aborted&&d(getAbortedReason(e)),l=()=>{d(getAbortedReason(e))},e.addEventListener(`abort`,l,{once:!0})}if(r===1/0){e.then(u,d);return}let f=new TimeoutError;c=s.setTimeout.call(void 0,()=>{if(a){try{u(a())}catch(e){d(e)}return}typeof e.cancel==`function`&&e.cancel(),o===!1?u():o instanceof Error?d(o):(f.message=o??`Promise timed out after ${r} milliseconds`,d(f))},r),(async()=>{try{u(await e)}catch(e){d(e)}})()}).finally(()=>{u.clear(),l&&n.signal&&n.signal.removeEventListener(`abort`,l)});return u.clear=()=>{s.clearTimeout.call(void 0,c),c=void 0},u}function lowerBound(e,t,n){let r=0,i=e.length;for(;i>0;){let a=Math.trunc(i/2),o=r+a;n(e[o],t)<=0?(r=++o,i-=a+1):i=a}return r}var PriorityQueue=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,id:t.id,run:e};if(this.size===0||this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let r=lowerBound(this.#e,n,(e,t)=>t.priority-e.priority);this.#e.splice(r,0,n)}setPriority(e,t){let n=this.#e.findIndex(t=>t.id===e);if(n===-1)throw ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[r]=this.#e.splice(n,1);this.enqueue(r.run,{priority:t,id:e})}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(e=>e.run)}get size(){return this.#e.length}},PQueue=class extends import_eventemitter3.default{#e;#t;#n=0;#r;#i;#a=0;#o;#s;#c;#l;#u=0;#d;#f;#p;#m=1n;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:1/0,interval:0,concurrency:1/0,autoStart:!0,queueClass:PriorityQueue,...e},!(typeof e.intervalCap==`number`&&e.intervalCap>=1))throw TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??``}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??``}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#t=e.intervalCap===1/0||e.interval===0,this.#r=e.intervalCap,this.#i=e.interval,this.#c=new e.queueClass,this.#l=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#p=e.throwOnTimeout===!0,this.#f=e.autoStart===!1}get#h(){return this.#t||this.#n<this.#r}get#g(){return this.#u<this.#d}#_(){this.#u--,this.#b(),this.emit(`next`)}#v(){this.#S(),this.#x(),this.#s=void 0}get#y(){let e=Date.now();if(this.#o===void 0){let t=this.#a-e;if(t<0)this.#n=this.#e?this.#u:0;else return this.#s===void 0&&(this.#s=setTimeout(()=>{this.#v()},t)),!0}return!1}#b(){if(this.#c.size===0)return this.#o&&clearInterval(this.#o),this.#o=void 0,this.emit(`empty`),this.#u===0&&this.emit(`idle`),!1;if(!this.#f){let e=!this.#y;if(this.#h&&this.#g){let t=this.#c.dequeue();return t?(this.emit(`active`),t(),e&&this.#x(),!0):!1}}return!1}#x(){this.#t||this.#o!==void 0||(this.#o=setInterval(()=>{this.#S()},this.#i),this.#a=Date.now()+this.#i)}#S(){this.#n===0&&this.#u===0&&this.#o&&(clearInterval(this.#o),this.#o=void 0),this.#n=this.#e?this.#u:0,this.#C()}#C(){for(;this.#b(););}get concurrency(){return this.#d}set concurrency(e){if(!(typeof e==`number`&&e>=1))throw TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#d=e,this.#C()}async#w(e){return new Promise((t,n)=>{e.addEventListener(`abort`,()=>{n(e.reason)},{once:!0})})}setPriority(e,t){this.#c.setPriority(e,t)}async add(e,n={}){return n.id??=(this.#m++).toString(),n={timeout:this.timeout,throwOnTimeout:this.#p,...n},new Promise((r,i)=>{this.#c.enqueue(async()=>{this.#u++;try{n.signal?.throwIfAborted(),this.#n++;let t=e({signal:n.signal});n.timeout&&(t=pTimeout(Promise.resolve(t),{milliseconds:n.timeout})),n.signal&&(t=Promise.race([t,this.#w(n.signal)]));let i=await t;r(i),this.emit(`completed`,i)}catch(e){if(e instanceof TimeoutError&&!n.throwOnTimeout){r();return}i(e),this.emit(`error`,e)}finally{this.#_()}},n),this.emit(`add`),this.#b()})}async addAll(e,t){return Promise.all(e.map(async e=>this.add(e,t)))}start(){return this.#f?(this.#f=!1,this.#C(),this):this}pause(){this.#f=!0}clear(){this.#c=new this.#l}async onEmpty(){this.#c.size!==0&&await this.#T(`empty`)}async onSizeLessThan(e){this.#c.size<e||await this.#T(`next`,()=>this.#c.size<e)}async onIdle(){this.#u===0&&this.#c.size===0||await this.#T(`idle`)}async#T(e,t){return new Promise(n=>{let r=()=>{t&&!t()||(this.off(e,r),n())};this.on(e,r)})}get size(){return this.#c.size}sizeBy(e){return this.#c.filter(e).length}get pending(){return this.#u}get isPaused(){return this.#f}};export{PQueue as t};