libav-wasm 0.1.9 → 0.2.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/build/index.d.ts +9 -9
- package/build/index.js +67 -897
- package/build/libav.wasm +0 -0
- package/build/utils.d.ts +6 -4
- package/build/worker.d.ts +12 -7
- package/build/worker.js +2003 -1142
- package/package.json +5 -4
- package/build/mp4box.d.ts +0 -121
package/build/index.js
CHANGED
|
@@ -1,857 +1,12 @@
|
|
|
1
1
|
import { call } from 'osra';
|
|
2
2
|
|
|
3
|
-
var eventemitter3Exports = {};
|
|
4
|
-
var eventemitter3 = {
|
|
5
|
-
get exports(){ return eventemitter3Exports; },
|
|
6
|
-
set exports(v){ eventemitter3Exports = v; },
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
(function (module) {
|
|
10
|
-
|
|
11
|
-
var has = Object.prototype.hasOwnProperty
|
|
12
|
-
, prefix = '~';
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Constructor to create a storage for our `EE` objects.
|
|
16
|
-
* An `Events` instance is a plain object whose properties are event names.
|
|
17
|
-
*
|
|
18
|
-
* @constructor
|
|
19
|
-
* @private
|
|
20
|
-
*/
|
|
21
|
-
function Events() {}
|
|
22
|
-
|
|
23
|
-
//
|
|
24
|
-
// We try to not inherit from `Object.prototype`. In some engines creating an
|
|
25
|
-
// instance in this way is faster than calling `Object.create(null)` directly.
|
|
26
|
-
// If `Object.create(null)` is not supported we prefix the event names with a
|
|
27
|
-
// character to make sure that the built-in object properties are not
|
|
28
|
-
// overridden or used as an attack vector.
|
|
29
|
-
//
|
|
30
|
-
if (Object.create) {
|
|
31
|
-
Events.prototype = Object.create(null);
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
// This hack is needed because the `__proto__` property is still inherited in
|
|
35
|
-
// some old browsers like Android 4, iPhone 5.1, Opera 11 and Safari 5.
|
|
36
|
-
//
|
|
37
|
-
if (!new Events().__proto__) prefix = false;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Representation of a single event listener.
|
|
42
|
-
*
|
|
43
|
-
* @param {Function} fn The listener function.
|
|
44
|
-
* @param {*} context The context to invoke the listener with.
|
|
45
|
-
* @param {Boolean} [once=false] Specify if the listener is a one-time listener.
|
|
46
|
-
* @constructor
|
|
47
|
-
* @private
|
|
48
|
-
*/
|
|
49
|
-
function EE(fn, context, once) {
|
|
50
|
-
this.fn = fn;
|
|
51
|
-
this.context = context;
|
|
52
|
-
this.once = once || false;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Add a listener for a given event.
|
|
57
|
-
*
|
|
58
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
59
|
-
* @param {(String|Symbol)} event The event name.
|
|
60
|
-
* @param {Function} fn The listener function.
|
|
61
|
-
* @param {*} context The context to invoke the listener with.
|
|
62
|
-
* @param {Boolean} once Specify if the listener is a one-time listener.
|
|
63
|
-
* @returns {EventEmitter}
|
|
64
|
-
* @private
|
|
65
|
-
*/
|
|
66
|
-
function addListener(emitter, event, fn, context, once) {
|
|
67
|
-
if (typeof fn !== 'function') {
|
|
68
|
-
throw new TypeError('The listener must be a function');
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
var listener = new EE(fn, context || emitter, once)
|
|
72
|
-
, evt = prefix ? prefix + event : event;
|
|
73
|
-
|
|
74
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
75
|
-
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
76
|
-
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
77
|
-
|
|
78
|
-
return emitter;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Clear event by name.
|
|
83
|
-
*
|
|
84
|
-
* @param {EventEmitter} emitter Reference to the `EventEmitter` instance.
|
|
85
|
-
* @param {(String|Symbol)} evt The Event name.
|
|
86
|
-
* @private
|
|
87
|
-
*/
|
|
88
|
-
function clearEvent(emitter, evt) {
|
|
89
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
90
|
-
else delete emitter._events[evt];
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Minimal `EventEmitter` interface that is molded against the Node.js
|
|
95
|
-
* `EventEmitter` interface.
|
|
96
|
-
*
|
|
97
|
-
* @constructor
|
|
98
|
-
* @public
|
|
99
|
-
*/
|
|
100
|
-
function EventEmitter() {
|
|
101
|
-
this._events = new Events();
|
|
102
|
-
this._eventsCount = 0;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Return an array listing the events for which the emitter has registered
|
|
107
|
-
* listeners.
|
|
108
|
-
*
|
|
109
|
-
* @returns {Array}
|
|
110
|
-
* @public
|
|
111
|
-
*/
|
|
112
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
113
|
-
var names = []
|
|
114
|
-
, events
|
|
115
|
-
, name;
|
|
116
|
-
|
|
117
|
-
if (this._eventsCount === 0) return names;
|
|
118
|
-
|
|
119
|
-
for (name in (events = this._events)) {
|
|
120
|
-
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (Object.getOwnPropertySymbols) {
|
|
124
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return names;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Return the listeners registered for a given event.
|
|
132
|
-
*
|
|
133
|
-
* @param {(String|Symbol)} event The event name.
|
|
134
|
-
* @returns {Array} The registered listeners.
|
|
135
|
-
* @public
|
|
136
|
-
*/
|
|
137
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
138
|
-
var evt = prefix ? prefix + event : event
|
|
139
|
-
, handlers = this._events[evt];
|
|
140
|
-
|
|
141
|
-
if (!handlers) return [];
|
|
142
|
-
if (handlers.fn) return [handlers.fn];
|
|
143
|
-
|
|
144
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
145
|
-
ee[i] = handlers[i].fn;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return ee;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Return the number of listeners listening to a given event.
|
|
153
|
-
*
|
|
154
|
-
* @param {(String|Symbol)} event The event name.
|
|
155
|
-
* @returns {Number} The number of listeners.
|
|
156
|
-
* @public
|
|
157
|
-
*/
|
|
158
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
159
|
-
var evt = prefix ? prefix + event : event
|
|
160
|
-
, listeners = this._events[evt];
|
|
161
|
-
|
|
162
|
-
if (!listeners) return 0;
|
|
163
|
-
if (listeners.fn) return 1;
|
|
164
|
-
return listeners.length;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Calls each of the listeners registered for a given event.
|
|
169
|
-
*
|
|
170
|
-
* @param {(String|Symbol)} event The event name.
|
|
171
|
-
* @returns {Boolean} `true` if the event had listeners, else `false`.
|
|
172
|
-
* @public
|
|
173
|
-
*/
|
|
174
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
175
|
-
var evt = prefix ? prefix + event : event;
|
|
176
|
-
|
|
177
|
-
if (!this._events[evt]) return false;
|
|
178
|
-
|
|
179
|
-
var listeners = this._events[evt]
|
|
180
|
-
, len = arguments.length
|
|
181
|
-
, args
|
|
182
|
-
, i;
|
|
183
|
-
|
|
184
|
-
if (listeners.fn) {
|
|
185
|
-
if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
|
186
|
-
|
|
187
|
-
switch (len) {
|
|
188
|
-
case 1: return listeners.fn.call(listeners.context), true;
|
|
189
|
-
case 2: return listeners.fn.call(listeners.context, a1), true;
|
|
190
|
-
case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
|
191
|
-
case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
192
|
-
case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
193
|
-
case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
for (i = 1, args = new Array(len -1); i < len; i++) {
|
|
197
|
-
args[i - 1] = arguments[i];
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
listeners.fn.apply(listeners.context, args);
|
|
201
|
-
} else {
|
|
202
|
-
var length = listeners.length
|
|
203
|
-
, j;
|
|
204
|
-
|
|
205
|
-
for (i = 0; i < length; i++) {
|
|
206
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
|
207
|
-
|
|
208
|
-
switch (len) {
|
|
209
|
-
case 1: listeners[i].fn.call(listeners[i].context); break;
|
|
210
|
-
case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
|
211
|
-
case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
|
212
|
-
case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
|
213
|
-
default:
|
|
214
|
-
if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
|
215
|
-
args[j - 1] = arguments[j];
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
return true;
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Add a listener for a given event.
|
|
228
|
-
*
|
|
229
|
-
* @param {(String|Symbol)} event The event name.
|
|
230
|
-
* @param {Function} fn The listener function.
|
|
231
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
232
|
-
* @returns {EventEmitter} `this`.
|
|
233
|
-
* @public
|
|
234
|
-
*/
|
|
235
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
236
|
-
return addListener(this, event, fn, context, false);
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
/**
|
|
240
|
-
* Add a one-time listener for a given event.
|
|
241
|
-
*
|
|
242
|
-
* @param {(String|Symbol)} event The event name.
|
|
243
|
-
* @param {Function} fn The listener function.
|
|
244
|
-
* @param {*} [context=this] The context to invoke the listener with.
|
|
245
|
-
* @returns {EventEmitter} `this`.
|
|
246
|
-
* @public
|
|
247
|
-
*/
|
|
248
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
249
|
-
return addListener(this, event, fn, context, true);
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
/**
|
|
253
|
-
* Remove the listeners of a given event.
|
|
254
|
-
*
|
|
255
|
-
* @param {(String|Symbol)} event The event name.
|
|
256
|
-
* @param {Function} fn Only remove the listeners that match this function.
|
|
257
|
-
* @param {*} context Only remove the listeners that have this context.
|
|
258
|
-
* @param {Boolean} once Only remove one-time listeners.
|
|
259
|
-
* @returns {EventEmitter} `this`.
|
|
260
|
-
* @public
|
|
261
|
-
*/
|
|
262
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
263
|
-
var evt = prefix ? prefix + event : event;
|
|
264
|
-
|
|
265
|
-
if (!this._events[evt]) return this;
|
|
266
|
-
if (!fn) {
|
|
267
|
-
clearEvent(this, evt);
|
|
268
|
-
return this;
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
var listeners = this._events[evt];
|
|
272
|
-
|
|
273
|
-
if (listeners.fn) {
|
|
274
|
-
if (
|
|
275
|
-
listeners.fn === fn &&
|
|
276
|
-
(!once || listeners.once) &&
|
|
277
|
-
(!context || listeners.context === context)
|
|
278
|
-
) {
|
|
279
|
-
clearEvent(this, evt);
|
|
280
|
-
}
|
|
281
|
-
} else {
|
|
282
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
283
|
-
if (
|
|
284
|
-
listeners[i].fn !== fn ||
|
|
285
|
-
(once && !listeners[i].once) ||
|
|
286
|
-
(context && listeners[i].context !== context)
|
|
287
|
-
) {
|
|
288
|
-
events.push(listeners[i]);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
//
|
|
293
|
-
// Reset the array, or remove it completely if we have no more listeners.
|
|
294
|
-
//
|
|
295
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
296
|
-
else clearEvent(this, evt);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
return this;
|
|
300
|
-
};
|
|
301
|
-
|
|
302
|
-
/**
|
|
303
|
-
* Remove all listeners, or those of the specified event.
|
|
304
|
-
*
|
|
305
|
-
* @param {(String|Symbol)} [event] The event name.
|
|
306
|
-
* @returns {EventEmitter} `this`.
|
|
307
|
-
* @public
|
|
308
|
-
*/
|
|
309
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
310
|
-
var evt;
|
|
311
|
-
|
|
312
|
-
if (event) {
|
|
313
|
-
evt = prefix ? prefix + event : event;
|
|
314
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
315
|
-
} else {
|
|
316
|
-
this._events = new Events();
|
|
317
|
-
this._eventsCount = 0;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
return this;
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
//
|
|
324
|
-
// Alias methods names because people roll like that.
|
|
325
|
-
//
|
|
326
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
327
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
328
|
-
|
|
329
|
-
//
|
|
330
|
-
// Expose the prefix.
|
|
331
|
-
//
|
|
332
|
-
EventEmitter.prefixed = prefix;
|
|
333
|
-
|
|
334
|
-
//
|
|
335
|
-
// Allow `EventEmitter` to be imported as module namespace.
|
|
336
|
-
//
|
|
337
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
338
|
-
|
|
339
|
-
//
|
|
340
|
-
// Expose the module.
|
|
341
|
-
//
|
|
342
|
-
{
|
|
343
|
-
module.exports = EventEmitter;
|
|
344
|
-
}
|
|
345
|
-
} (eventemitter3));
|
|
346
|
-
|
|
347
|
-
const EventEmitter = eventemitter3Exports;
|
|
348
|
-
|
|
349
|
-
class TimeoutError extends Error {
|
|
350
|
-
constructor(message) {
|
|
351
|
-
super(message);
|
|
352
|
-
this.name = 'TimeoutError';
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
/**
|
|
357
|
-
An error to be thrown when the request is aborted by AbortController.
|
|
358
|
-
DOMException is thrown instead of this Error when DOMException is available.
|
|
359
|
-
*/
|
|
360
|
-
let AbortError$1 = class AbortError extends Error {
|
|
361
|
-
constructor(message) {
|
|
362
|
-
super();
|
|
363
|
-
this.name = 'AbortError';
|
|
364
|
-
this.message = message;
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
TODO: Remove AbortError and just throw DOMException when targeting Node 18.
|
|
370
|
-
*/
|
|
371
|
-
const getDOMException = errorMessage => globalThis.DOMException === undefined ?
|
|
372
|
-
new AbortError$1(errorMessage) :
|
|
373
|
-
new DOMException(errorMessage);
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
TODO: Remove below function and just 'reject(signal.reason)' when targeting Node 18.
|
|
377
|
-
*/
|
|
378
|
-
const getAbortedReason = signal => {
|
|
379
|
-
const reason = signal.reason === undefined ?
|
|
380
|
-
getDOMException('This operation was aborted.') :
|
|
381
|
-
signal.reason;
|
|
382
|
-
|
|
383
|
-
return reason instanceof Error ? reason : getDOMException(reason);
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
function pTimeout(promise, milliseconds, fallback, options) {
|
|
387
|
-
let timer;
|
|
388
|
-
|
|
389
|
-
const cancelablePromise = new Promise((resolve, reject) => {
|
|
390
|
-
if (typeof milliseconds !== 'number' || Math.sign(milliseconds) !== 1) {
|
|
391
|
-
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
|
392
|
-
}
|
|
393
|
-
|
|
394
|
-
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
395
|
-
resolve(promise);
|
|
396
|
-
return;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
options = {
|
|
400
|
-
customTimers: {setTimeout, clearTimeout},
|
|
401
|
-
...options
|
|
402
|
-
};
|
|
403
|
-
|
|
404
|
-
if (options.signal) {
|
|
405
|
-
const {signal} = options;
|
|
406
|
-
if (signal.aborted) {
|
|
407
|
-
reject(getAbortedReason(signal));
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
signal.addEventListener('abort', () => {
|
|
411
|
-
reject(getAbortedReason(signal));
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
timer = options.customTimers.setTimeout.call(undefined, () => {
|
|
416
|
-
if (typeof fallback === 'function') {
|
|
417
|
-
try {
|
|
418
|
-
resolve(fallback());
|
|
419
|
-
} catch (error) {
|
|
420
|
-
reject(error);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
const message = typeof fallback === 'string' ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
|
|
427
|
-
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
|
|
428
|
-
|
|
429
|
-
if (typeof promise.cancel === 'function') {
|
|
430
|
-
promise.cancel();
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
reject(timeoutError);
|
|
434
|
-
}, milliseconds);
|
|
435
|
-
|
|
436
|
-
(async () => {
|
|
437
|
-
try {
|
|
438
|
-
resolve(await promise);
|
|
439
|
-
} catch (error) {
|
|
440
|
-
reject(error);
|
|
441
|
-
} finally {
|
|
442
|
-
options.customTimers.clearTimeout.call(undefined, timer);
|
|
443
|
-
}
|
|
444
|
-
})();
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
cancelablePromise.clear = () => {
|
|
448
|
-
clearTimeout(timer);
|
|
449
|
-
timer = undefined;
|
|
450
|
-
};
|
|
451
|
-
|
|
452
|
-
return cancelablePromise;
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// Port of lower_bound from https://en.cppreference.com/w/cpp/algorithm/lower_bound
|
|
456
|
-
// Used to compute insertion index to keep queue sorted after insertion
|
|
457
|
-
function lowerBound(array, value, comparator) {
|
|
458
|
-
let first = 0;
|
|
459
|
-
let count = array.length;
|
|
460
|
-
while (count > 0) {
|
|
461
|
-
const step = Math.trunc(count / 2);
|
|
462
|
-
let it = first + step;
|
|
463
|
-
if (comparator(array[it], value) <= 0) {
|
|
464
|
-
first = ++it;
|
|
465
|
-
count -= step + 1;
|
|
466
|
-
}
|
|
467
|
-
else {
|
|
468
|
-
count = step;
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
return first;
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
var __classPrivateFieldGet$1 = (globalThis && globalThis.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
475
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
476
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
477
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
478
|
-
};
|
|
479
|
-
var _PriorityQueue_queue;
|
|
480
|
-
class PriorityQueue {
|
|
481
|
-
constructor() {
|
|
482
|
-
_PriorityQueue_queue.set(this, []);
|
|
483
|
-
}
|
|
484
|
-
enqueue(run, options) {
|
|
485
|
-
options = {
|
|
486
|
-
priority: 0,
|
|
487
|
-
...options,
|
|
488
|
-
};
|
|
489
|
-
const element = {
|
|
490
|
-
priority: options.priority,
|
|
491
|
-
run,
|
|
492
|
-
};
|
|
493
|
-
if (this.size && __classPrivateFieldGet$1(this, _PriorityQueue_queue, "f")[this.size - 1].priority >= options.priority) {
|
|
494
|
-
__classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").push(element);
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
const index = lowerBound(__classPrivateFieldGet$1(this, _PriorityQueue_queue, "f"), element, (a, b) => b.priority - a.priority);
|
|
498
|
-
__classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").splice(index, 0, element);
|
|
499
|
-
}
|
|
500
|
-
dequeue() {
|
|
501
|
-
const item = __classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").shift();
|
|
502
|
-
return item === null || item === void 0 ? void 0 : item.run;
|
|
503
|
-
}
|
|
504
|
-
filter(options) {
|
|
505
|
-
return __classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
506
|
-
}
|
|
507
|
-
get size() {
|
|
508
|
-
return __classPrivateFieldGet$1(this, _PriorityQueue_queue, "f").length;
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
_PriorityQueue_queue = new WeakMap();
|
|
512
|
-
|
|
513
|
-
var __classPrivateFieldSet = (globalThis && globalThis.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
514
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
515
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
516
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
517
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
518
|
-
};
|
|
519
|
-
var __classPrivateFieldGet = (globalThis && globalThis.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
520
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
521
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
522
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
523
|
-
};
|
|
524
|
-
var _PQueue_instances, _PQueue_carryoverConcurrencyCount, _PQueue_isIntervalIgnored, _PQueue_intervalCount, _PQueue_intervalCap, _PQueue_interval, _PQueue_intervalEnd, _PQueue_intervalId, _PQueue_timeoutId, _PQueue_queue, _PQueue_queueClass, _PQueue_pendingCount, _PQueue_concurrency, _PQueue_isPaused, _PQueue_throwOnTimeout, _PQueue_doesIntervalAllowAnother_get, _PQueue_doesConcurrentAllowAnother_get, _PQueue_next, _PQueue_emitEvents, _PQueue_onResumeInterval, _PQueue_isIntervalPaused_get, _PQueue_tryToStartAnother, _PQueue_initializeIntervalIfNeeded, _PQueue_onInterval, _PQueue_processQueue, _PQueue_onEvent;
|
|
525
|
-
const timeoutError = new TimeoutError();
|
|
526
|
-
/**
|
|
527
|
-
The error thrown by `queue.add()` when a job is aborted before it is run. See `signal`.
|
|
528
|
-
*/
|
|
529
|
-
class AbortError extends Error {
|
|
530
|
-
}
|
|
531
|
-
/**
|
|
532
|
-
Promise queue with concurrency control.
|
|
533
|
-
*/
|
|
534
|
-
class PQueue extends EventEmitter {
|
|
535
|
-
constructor(options) {
|
|
536
|
-
var _a, _b, _c, _d;
|
|
537
|
-
super();
|
|
538
|
-
_PQueue_instances.add(this);
|
|
539
|
-
_PQueue_carryoverConcurrencyCount.set(this, void 0);
|
|
540
|
-
_PQueue_isIntervalIgnored.set(this, void 0);
|
|
541
|
-
_PQueue_intervalCount.set(this, 0);
|
|
542
|
-
_PQueue_intervalCap.set(this, void 0);
|
|
543
|
-
_PQueue_interval.set(this, void 0);
|
|
544
|
-
_PQueue_intervalEnd.set(this, 0);
|
|
545
|
-
_PQueue_intervalId.set(this, void 0);
|
|
546
|
-
_PQueue_timeoutId.set(this, void 0);
|
|
547
|
-
_PQueue_queue.set(this, void 0);
|
|
548
|
-
_PQueue_queueClass.set(this, void 0);
|
|
549
|
-
_PQueue_pendingCount.set(this, 0);
|
|
550
|
-
// The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
551
|
-
_PQueue_concurrency.set(this, void 0);
|
|
552
|
-
_PQueue_isPaused.set(this, void 0);
|
|
553
|
-
_PQueue_throwOnTimeout.set(this, void 0);
|
|
554
|
-
/**
|
|
555
|
-
Per-operation timeout in milliseconds. Operations fulfill once `timeout` elapses if they haven't already.
|
|
556
|
-
|
|
557
|
-
Applies to each future operation.
|
|
558
|
-
*/
|
|
559
|
-
Object.defineProperty(this, "timeout", {
|
|
560
|
-
enumerable: true,
|
|
561
|
-
configurable: true,
|
|
562
|
-
writable: true,
|
|
563
|
-
value: void 0
|
|
564
|
-
});
|
|
565
|
-
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
566
|
-
options = {
|
|
567
|
-
carryoverConcurrencyCount: false,
|
|
568
|
-
intervalCap: Number.POSITIVE_INFINITY,
|
|
569
|
-
interval: 0,
|
|
570
|
-
concurrency: Number.POSITIVE_INFINITY,
|
|
571
|
-
autoStart: true,
|
|
572
|
-
queueClass: PriorityQueue,
|
|
573
|
-
...options,
|
|
574
|
-
};
|
|
575
|
-
if (!(typeof options.intervalCap === 'number' && options.intervalCap >= 1)) {
|
|
576
|
-
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(_b = (_a = options.intervalCap) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''}\` (${typeof options.intervalCap})`);
|
|
577
|
-
}
|
|
578
|
-
if (options.interval === undefined || !(Number.isFinite(options.interval) && options.interval >= 0)) {
|
|
579
|
-
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(_d = (_c = options.interval) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : ''}\` (${typeof options.interval})`);
|
|
580
|
-
}
|
|
581
|
-
__classPrivateFieldSet(this, _PQueue_carryoverConcurrencyCount, options.carryoverConcurrencyCount, "f");
|
|
582
|
-
__classPrivateFieldSet(this, _PQueue_isIntervalIgnored, options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0, "f");
|
|
583
|
-
__classPrivateFieldSet(this, _PQueue_intervalCap, options.intervalCap, "f");
|
|
584
|
-
__classPrivateFieldSet(this, _PQueue_interval, options.interval, "f");
|
|
585
|
-
__classPrivateFieldSet(this, _PQueue_queue, new options.queueClass(), "f");
|
|
586
|
-
__classPrivateFieldSet(this, _PQueue_queueClass, options.queueClass, "f");
|
|
587
|
-
this.concurrency = options.concurrency;
|
|
588
|
-
this.timeout = options.timeout;
|
|
589
|
-
__classPrivateFieldSet(this, _PQueue_throwOnTimeout, options.throwOnTimeout === true, "f");
|
|
590
|
-
__classPrivateFieldSet(this, _PQueue_isPaused, options.autoStart === false, "f");
|
|
591
|
-
}
|
|
592
|
-
get concurrency() {
|
|
593
|
-
return __classPrivateFieldGet(this, _PQueue_concurrency, "f");
|
|
594
|
-
}
|
|
595
|
-
set concurrency(newConcurrency) {
|
|
596
|
-
if (!(typeof newConcurrency === 'number' && newConcurrency >= 1)) {
|
|
597
|
-
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
|
|
598
|
-
}
|
|
599
|
-
__classPrivateFieldSet(this, _PQueue_concurrency, newConcurrency, "f");
|
|
600
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_processQueue).call(this);
|
|
601
|
-
}
|
|
602
|
-
/**
|
|
603
|
-
Adds a sync or async task to the queue. Always returns a promise.
|
|
604
|
-
*/
|
|
605
|
-
async add(fn, options = {}) {
|
|
606
|
-
return new Promise((resolve, reject) => {
|
|
607
|
-
const run = async () => {
|
|
608
|
-
var _a;
|
|
609
|
-
var _b, _c;
|
|
610
|
-
__classPrivateFieldSet(this, _PQueue_pendingCount, (_b = __classPrivateFieldGet(this, _PQueue_pendingCount, "f"), _b++, _b), "f");
|
|
611
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, (_c = __classPrivateFieldGet(this, _PQueue_intervalCount, "f"), _c++, _c), "f");
|
|
612
|
-
try {
|
|
613
|
-
if ((_a = options.signal) === null || _a === void 0 ? void 0 : _a.aborted) {
|
|
614
|
-
// TODO: Use ABORT_ERR code when targeting Node.js 16 (https://nodejs.org/docs/latest-v16.x/api/errors.html#abort_err)
|
|
615
|
-
reject(new AbortError('The task was aborted.'));
|
|
616
|
-
return;
|
|
617
|
-
}
|
|
618
|
-
const operation = (this.timeout === undefined && options.timeout === undefined) ? fn({ signal: options.signal }) : pTimeout(Promise.resolve(fn({ signal: options.signal })), (options.timeout === undefined ? this.timeout : options.timeout), () => {
|
|
619
|
-
if (options.throwOnTimeout === undefined ? __classPrivateFieldGet(this, _PQueue_throwOnTimeout, "f") : options.throwOnTimeout) {
|
|
620
|
-
reject(timeoutError);
|
|
621
|
-
}
|
|
622
|
-
return undefined;
|
|
623
|
-
});
|
|
624
|
-
const result = await operation;
|
|
625
|
-
resolve(result);
|
|
626
|
-
this.emit('completed', result);
|
|
627
|
-
}
|
|
628
|
-
catch (error) {
|
|
629
|
-
reject(error);
|
|
630
|
-
this.emit('error', error);
|
|
631
|
-
}
|
|
632
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_next).call(this);
|
|
633
|
-
};
|
|
634
|
-
__classPrivateFieldGet(this, _PQueue_queue, "f").enqueue(run, options);
|
|
635
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this);
|
|
636
|
-
this.emit('add');
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
/**
|
|
640
|
-
Same as `.add()`, but accepts an array of sync or async functions.
|
|
641
|
-
|
|
642
|
-
@returns A promise that resolves when all functions are resolved.
|
|
643
|
-
*/
|
|
644
|
-
async addAll(functions, options) {
|
|
645
|
-
return Promise.all(functions.map(async (function_) => this.add(function_, options)));
|
|
646
|
-
}
|
|
647
|
-
/**
|
|
648
|
-
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.)
|
|
649
|
-
*/
|
|
650
|
-
start() {
|
|
651
|
-
if (!__classPrivateFieldGet(this, _PQueue_isPaused, "f")) {
|
|
652
|
-
return this;
|
|
653
|
-
}
|
|
654
|
-
__classPrivateFieldSet(this, _PQueue_isPaused, false, "f");
|
|
655
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_processQueue).call(this);
|
|
656
|
-
return this;
|
|
657
|
-
}
|
|
658
|
-
/**
|
|
659
|
-
Put queue execution on hold.
|
|
660
|
-
*/
|
|
661
|
-
pause() {
|
|
662
|
-
__classPrivateFieldSet(this, _PQueue_isPaused, true, "f");
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
Clear the queue.
|
|
666
|
-
*/
|
|
667
|
-
clear() {
|
|
668
|
-
__classPrivateFieldSet(this, _PQueue_queue, new (__classPrivateFieldGet(this, _PQueue_queueClass, "f"))(), "f");
|
|
669
|
-
}
|
|
670
|
-
/**
|
|
671
|
-
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
672
|
-
|
|
673
|
-
@returns A promise that settles when the queue becomes empty.
|
|
674
|
-
*/
|
|
675
|
-
async onEmpty() {
|
|
676
|
-
// Instantly resolve if the queue is empty
|
|
677
|
-
if (__classPrivateFieldGet(this, _PQueue_queue, "f").size === 0) {
|
|
678
|
-
return;
|
|
679
|
-
}
|
|
680
|
-
await __classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onEvent).call(this, 'empty');
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
@returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
|
|
684
|
-
|
|
685
|
-
If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item.
|
|
686
|
-
|
|
687
|
-
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.
|
|
688
|
-
*/
|
|
689
|
-
async onSizeLessThan(limit) {
|
|
690
|
-
// Instantly resolve if the queue is empty.
|
|
691
|
-
if (__classPrivateFieldGet(this, _PQueue_queue, "f").size < limit) {
|
|
692
|
-
return;
|
|
693
|
-
}
|
|
694
|
-
await __classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onEvent).call(this, 'next', () => __classPrivateFieldGet(this, _PQueue_queue, "f").size < limit);
|
|
695
|
-
}
|
|
696
|
-
/**
|
|
697
|
-
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.
|
|
698
|
-
|
|
699
|
-
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
|
|
700
|
-
*/
|
|
701
|
-
async onIdle() {
|
|
702
|
-
// Instantly resolve if none pending and if nothing else is queued
|
|
703
|
-
if (__classPrivateFieldGet(this, _PQueue_pendingCount, "f") === 0 && __classPrivateFieldGet(this, _PQueue_queue, "f").size === 0) {
|
|
704
|
-
return;
|
|
705
|
-
}
|
|
706
|
-
await __classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onEvent).call(this, 'idle');
|
|
707
|
-
}
|
|
708
|
-
/**
|
|
709
|
-
Size of the queue, the number of queued items waiting to run.
|
|
710
|
-
*/
|
|
711
|
-
get size() {
|
|
712
|
-
return __classPrivateFieldGet(this, _PQueue_queue, "f").size;
|
|
713
|
-
}
|
|
714
|
-
/**
|
|
715
|
-
Size of the queue, filtered by the given options.
|
|
716
|
-
|
|
717
|
-
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
|
|
718
|
-
*/
|
|
719
|
-
sizeBy(options) {
|
|
720
|
-
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
721
|
-
return __classPrivateFieldGet(this, _PQueue_queue, "f").filter(options).length;
|
|
722
|
-
}
|
|
723
|
-
/**
|
|
724
|
-
Number of running items (no longer in the queue).
|
|
725
|
-
*/
|
|
726
|
-
get pending() {
|
|
727
|
-
return __classPrivateFieldGet(this, _PQueue_pendingCount, "f");
|
|
728
|
-
}
|
|
729
|
-
/**
|
|
730
|
-
Whether the queue is currently paused.
|
|
731
|
-
*/
|
|
732
|
-
get isPaused() {
|
|
733
|
-
return __classPrivateFieldGet(this, _PQueue_isPaused, "f");
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
_PQueue_carryoverConcurrencyCount = new WeakMap(), _PQueue_isIntervalIgnored = new WeakMap(), _PQueue_intervalCount = new WeakMap(), _PQueue_intervalCap = new WeakMap(), _PQueue_interval = new WeakMap(), _PQueue_intervalEnd = new WeakMap(), _PQueue_intervalId = new WeakMap(), _PQueue_timeoutId = new WeakMap(), _PQueue_queue = new WeakMap(), _PQueue_queueClass = new WeakMap(), _PQueue_pendingCount = new WeakMap(), _PQueue_concurrency = new WeakMap(), _PQueue_isPaused = new WeakMap(), _PQueue_throwOnTimeout = new WeakMap(), _PQueue_instances = new WeakSet(), _PQueue_doesIntervalAllowAnother_get = function _PQueue_doesIntervalAllowAnother_get() {
|
|
737
|
-
return __classPrivateFieldGet(this, _PQueue_isIntervalIgnored, "f") || __classPrivateFieldGet(this, _PQueue_intervalCount, "f") < __classPrivateFieldGet(this, _PQueue_intervalCap, "f");
|
|
738
|
-
}, _PQueue_doesConcurrentAllowAnother_get = function _PQueue_doesConcurrentAllowAnother_get() {
|
|
739
|
-
return __classPrivateFieldGet(this, _PQueue_pendingCount, "f") < __classPrivateFieldGet(this, _PQueue_concurrency, "f");
|
|
740
|
-
}, _PQueue_next = function _PQueue_next() {
|
|
741
|
-
var _a;
|
|
742
|
-
__classPrivateFieldSet(this, _PQueue_pendingCount, (_a = __classPrivateFieldGet(this, _PQueue_pendingCount, "f"), _a--, _a), "f");
|
|
743
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this);
|
|
744
|
-
this.emit('next');
|
|
745
|
-
}, _PQueue_emitEvents = function _PQueue_emitEvents() {
|
|
746
|
-
this.emit('empty');
|
|
747
|
-
if (__classPrivateFieldGet(this, _PQueue_pendingCount, "f") === 0) {
|
|
748
|
-
this.emit('idle');
|
|
749
|
-
}
|
|
750
|
-
}, _PQueue_onResumeInterval = function _PQueue_onResumeInterval() {
|
|
751
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onInterval).call(this);
|
|
752
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_initializeIntervalIfNeeded).call(this);
|
|
753
|
-
__classPrivateFieldSet(this, _PQueue_timeoutId, undefined, "f");
|
|
754
|
-
}, _PQueue_isIntervalPaused_get = function _PQueue_isIntervalPaused_get() {
|
|
755
|
-
const now = Date.now();
|
|
756
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalId, "f") === undefined) {
|
|
757
|
-
const delay = __classPrivateFieldGet(this, _PQueue_intervalEnd, "f") - now;
|
|
758
|
-
if (delay < 0) {
|
|
759
|
-
// Act as the interval was done
|
|
760
|
-
// We don't need to resume it here because it will be resumed on line 160
|
|
761
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, (__classPrivateFieldGet(this, _PQueue_carryoverConcurrencyCount, "f")) ? __classPrivateFieldGet(this, _PQueue_pendingCount, "f") : 0, "f");
|
|
762
|
-
}
|
|
763
|
-
else {
|
|
764
|
-
// Act as the interval is pending
|
|
765
|
-
if (__classPrivateFieldGet(this, _PQueue_timeoutId, "f") === undefined) {
|
|
766
|
-
__classPrivateFieldSet(this, _PQueue_timeoutId, setTimeout(() => {
|
|
767
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onResumeInterval).call(this);
|
|
768
|
-
}, delay), "f");
|
|
769
|
-
}
|
|
770
|
-
return true;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
return false;
|
|
774
|
-
}, _PQueue_tryToStartAnother = function _PQueue_tryToStartAnother() {
|
|
775
|
-
if (__classPrivateFieldGet(this, _PQueue_queue, "f").size === 0) {
|
|
776
|
-
// We can clear the interval ("pause")
|
|
777
|
-
// Because we can redo it later ("resume")
|
|
778
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalId, "f")) {
|
|
779
|
-
clearInterval(__classPrivateFieldGet(this, _PQueue_intervalId, "f"));
|
|
780
|
-
}
|
|
781
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, undefined, "f");
|
|
782
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_emitEvents).call(this);
|
|
783
|
-
return false;
|
|
784
|
-
}
|
|
785
|
-
if (!__classPrivateFieldGet(this, _PQueue_isPaused, "f")) {
|
|
786
|
-
const canInitializeInterval = !__classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_isIntervalPaused_get);
|
|
787
|
-
if (__classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_doesIntervalAllowAnother_get) && __classPrivateFieldGet(this, _PQueue_instances, "a", _PQueue_doesConcurrentAllowAnother_get)) {
|
|
788
|
-
const job = __classPrivateFieldGet(this, _PQueue_queue, "f").dequeue();
|
|
789
|
-
if (!job) {
|
|
790
|
-
return false;
|
|
791
|
-
}
|
|
792
|
-
this.emit('active');
|
|
793
|
-
job();
|
|
794
|
-
if (canInitializeInterval) {
|
|
795
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_initializeIntervalIfNeeded).call(this);
|
|
796
|
-
}
|
|
797
|
-
return true;
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
return false;
|
|
801
|
-
}, _PQueue_initializeIntervalIfNeeded = function _PQueue_initializeIntervalIfNeeded() {
|
|
802
|
-
if (__classPrivateFieldGet(this, _PQueue_isIntervalIgnored, "f") || __classPrivateFieldGet(this, _PQueue_intervalId, "f") !== undefined) {
|
|
803
|
-
return;
|
|
804
|
-
}
|
|
805
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, setInterval(() => {
|
|
806
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_onInterval).call(this);
|
|
807
|
-
}, __classPrivateFieldGet(this, _PQueue_interval, "f")), "f");
|
|
808
|
-
__classPrivateFieldSet(this, _PQueue_intervalEnd, Date.now() + __classPrivateFieldGet(this, _PQueue_interval, "f"), "f");
|
|
809
|
-
}, _PQueue_onInterval = function _PQueue_onInterval() {
|
|
810
|
-
if (__classPrivateFieldGet(this, _PQueue_intervalCount, "f") === 0 && __classPrivateFieldGet(this, _PQueue_pendingCount, "f") === 0 && __classPrivateFieldGet(this, _PQueue_intervalId, "f")) {
|
|
811
|
-
clearInterval(__classPrivateFieldGet(this, _PQueue_intervalId, "f"));
|
|
812
|
-
__classPrivateFieldSet(this, _PQueue_intervalId, undefined, "f");
|
|
813
|
-
}
|
|
814
|
-
__classPrivateFieldSet(this, _PQueue_intervalCount, __classPrivateFieldGet(this, _PQueue_carryoverConcurrencyCount, "f") ? __classPrivateFieldGet(this, _PQueue_pendingCount, "f") : 0, "f");
|
|
815
|
-
__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_processQueue).call(this);
|
|
816
|
-
}, _PQueue_processQueue = function _PQueue_processQueue() {
|
|
817
|
-
// eslint-disable-next-line no-empty
|
|
818
|
-
while (__classPrivateFieldGet(this, _PQueue_instances, "m", _PQueue_tryToStartAnother).call(this)) { }
|
|
819
|
-
}, _PQueue_onEvent = async function _PQueue_onEvent(event, filter) {
|
|
820
|
-
return new Promise(resolve => {
|
|
821
|
-
const listener = () => {
|
|
822
|
-
if (filter && !filter()) {
|
|
823
|
-
return;
|
|
824
|
-
}
|
|
825
|
-
this.off(event, listener);
|
|
826
|
-
resolve();
|
|
827
|
-
};
|
|
828
|
-
this.on(event, listener);
|
|
829
|
-
});
|
|
830
|
-
};
|
|
831
|
-
|
|
832
|
-
var SEEK_FLAG = /* @__PURE__ */ ((SEEK_FLAG2) => {
|
|
833
|
-
SEEK_FLAG2[SEEK_FLAG2["NONE"] = 0] = "NONE";
|
|
834
|
-
SEEK_FLAG2[SEEK_FLAG2["AVSEEK_FLAG_BACKWARD"] = 1] = "AVSEEK_FLAG_BACKWARD";
|
|
835
|
-
SEEK_FLAG2[SEEK_FLAG2["AVSEEK_FLAG_BYTE"] = 2] = "AVSEEK_FLAG_BYTE";
|
|
836
|
-
SEEK_FLAG2[SEEK_FLAG2["AVSEEK_FLAG_ANY"] = 4] = "AVSEEK_FLAG_ANY";
|
|
837
|
-
SEEK_FLAG2[SEEK_FLAG2["AVSEEK_FLAG_FRAME"] = 8] = "AVSEEK_FLAG_FRAME";
|
|
838
|
-
return SEEK_FLAG2;
|
|
839
|
-
})(SEEK_FLAG || {});
|
|
840
|
-
var SEEK_WHENCE_FLAG = /* @__PURE__ */ ((SEEK_WHENCE_FLAG2) => {
|
|
841
|
-
SEEK_WHENCE_FLAG2[SEEK_WHENCE_FLAG2["SEEK_SET"] = 0] = "SEEK_SET";
|
|
842
|
-
SEEK_WHENCE_FLAG2[SEEK_WHENCE_FLAG2["SEEK_CUR"] = 1] = "SEEK_CUR";
|
|
843
|
-
SEEK_WHENCE_FLAG2[SEEK_WHENCE_FLAG2["SEEK_END"] = 2] = "SEEK_END";
|
|
844
|
-
SEEK_WHENCE_FLAG2[SEEK_WHENCE_FLAG2["AVSEEK_SIZE"] = 65536] = "AVSEEK_SIZE";
|
|
845
|
-
return SEEK_WHENCE_FLAG2;
|
|
846
|
-
})(SEEK_WHENCE_FLAG || {});
|
|
847
|
-
|
|
848
3
|
const convertTimestamp = (ms) => new Date(ms).toISOString().slice(11, 22).replace(/^00/, "0");
|
|
849
4
|
const makeTransmuxer = async ({
|
|
850
5
|
publicPath,
|
|
851
6
|
workerUrl,
|
|
852
7
|
workerOptions,
|
|
853
|
-
|
|
854
|
-
|
|
8
|
+
randomRead: _randomRead,
|
|
9
|
+
getStream: _getStream,
|
|
855
10
|
write: _write,
|
|
856
11
|
attachment,
|
|
857
12
|
subtitle: _subtitle,
|
|
@@ -870,10 +25,13 @@ const makeTransmuxer = async ({
|
|
|
870
25
|
setTimeout(reject, 3e4);
|
|
871
26
|
});
|
|
872
27
|
const target = call(worker);
|
|
873
|
-
const apiQueue = new PQueue();
|
|
874
|
-
const addTask = (func) => apiQueue.add(func);
|
|
875
28
|
const subtitles = /* @__PURE__ */ new Map();
|
|
876
|
-
|
|
29
|
+
let currentStream;
|
|
30
|
+
let reader;
|
|
31
|
+
let streamResultPromiseResolve;
|
|
32
|
+
let streamResultPromiseReject;
|
|
33
|
+
let streamResultPromise;
|
|
34
|
+
const { init: workerInit, destroy: workerDestroy, read: workerRead, seek: workerSeek, getInfo } = await target(
|
|
877
35
|
"init",
|
|
878
36
|
{
|
|
879
37
|
publicPath,
|
|
@@ -924,70 +82,82 @@ ${newSubtitle.dialogues.map(({ dialogue }) => dialogue).join("\n").trim()}`;
|
|
|
924
82
|
_subtitle(subtitle.title, subtitle.language, subtitleString);
|
|
925
83
|
},
|
|
926
84
|
attachment: async (filename, mimetype, buffer) => attachment(filename, mimetype, buffer),
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
85
|
+
randomRead: (offset, bufferSize2) => _randomRead(offset, bufferSize2),
|
|
86
|
+
streamRead: async (offset) => {
|
|
87
|
+
if (!currentStream) {
|
|
88
|
+
currentStream = await _getStream(offset);
|
|
89
|
+
reader = currentStream.getReader();
|
|
90
|
+
}
|
|
91
|
+
streamResultPromise = new Promise((resolve, reject) => {
|
|
92
|
+
streamResultPromiseResolve = resolve;
|
|
93
|
+
streamResultPromiseReject = reject;
|
|
94
|
+
});
|
|
95
|
+
const tryReading = () => reader?.read().then((result2) => ({
|
|
96
|
+
value: result2.value?.buffer,
|
|
97
|
+
done: result2.value === void 0,
|
|
98
|
+
cancelled: false
|
|
99
|
+
})).then(async (result2) => {
|
|
100
|
+
if (result2.done) {
|
|
101
|
+
reader?.cancel();
|
|
102
|
+
if (offset >= length) {
|
|
103
|
+
return streamResultPromiseResolve(result2);
|
|
104
|
+
}
|
|
105
|
+
currentStream = await _getStream(offset);
|
|
106
|
+
reader = currentStream.getReader();
|
|
107
|
+
return tryReading();
|
|
108
|
+
}
|
|
109
|
+
return streamResultPromiseResolve(result2);
|
|
110
|
+
}).catch((err) => streamResultPromiseReject(err));
|
|
111
|
+
tryReading();
|
|
112
|
+
return streamResultPromise.then((value) => ({
|
|
113
|
+
value: value.value,
|
|
114
|
+
done: value.done,
|
|
115
|
+
cancelled: false
|
|
116
|
+
})).catch((err) => {
|
|
117
|
+
console.error(err);
|
|
118
|
+
return {
|
|
119
|
+
value: void 0,
|
|
120
|
+
done: false,
|
|
121
|
+
cancelled: true
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
clearStream: async () => {
|
|
126
|
+
reader?.cancel();
|
|
127
|
+
currentStream = void 0;
|
|
128
|
+
reader = void 0;
|
|
129
|
+
},
|
|
130
|
+
write: ({
|
|
930
131
|
isHeader,
|
|
931
132
|
offset,
|
|
932
133
|
arrayBuffer,
|
|
933
134
|
position,
|
|
934
135
|
pts,
|
|
935
136
|
duration
|
|
936
|
-
}) => {
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
};
|
|
945
|
-
if (!isHeader) {
|
|
946
|
-
processBufferChunks.push(chunk);
|
|
947
|
-
}
|
|
948
|
-
await _write(chunk);
|
|
949
|
-
}
|
|
137
|
+
}) => _write({
|
|
138
|
+
isHeader,
|
|
139
|
+
offset,
|
|
140
|
+
buffer: new Uint8Array(arrayBuffer),
|
|
141
|
+
pts,
|
|
142
|
+
duration,
|
|
143
|
+
pos: position
|
|
144
|
+
})
|
|
950
145
|
}
|
|
951
146
|
);
|
|
952
|
-
const workerQueue = new PQueue({ concurrency: 1 });
|
|
953
|
-
const addWorkerTask = (func) => (...args) => workerQueue.add(() => func(...args));
|
|
954
|
-
const workerInit = addWorkerTask(_workerInit);
|
|
955
|
-
const workerDestroy = addWorkerTask(_workerDestroy);
|
|
956
|
-
const workerProcess = addWorkerTask(_workerProcess);
|
|
957
|
-
const workerSeek = addWorkerTask(_workerSeek);
|
|
958
|
-
const getInfo = addWorkerTask(_getInfo);
|
|
959
|
-
let processBufferChunks = [];
|
|
960
147
|
const result = {
|
|
961
|
-
init: () =>
|
|
962
|
-
processBufferChunks = [];
|
|
963
|
-
await workerInit();
|
|
964
|
-
}),
|
|
148
|
+
init: () => workerInit(),
|
|
965
149
|
destroy: (destroyWorker = false) => {
|
|
966
150
|
if (destroyWorker) {
|
|
967
151
|
worker.terminate();
|
|
968
152
|
return;
|
|
969
153
|
}
|
|
970
|
-
return
|
|
971
|
-
},
|
|
972
|
-
process: (timeToProcess) => addTask(async () => {
|
|
973
|
-
processBufferChunks = [];
|
|
974
|
-
await workerProcess(timeToProcess);
|
|
975
|
-
const writtenChunks = processBufferChunks;
|
|
976
|
-
processBufferChunks = [];
|
|
977
|
-
return writtenChunks;
|
|
978
|
-
}),
|
|
979
|
-
seek: (time) => {
|
|
980
|
-
return addTask(async () => {
|
|
981
|
-
processBufferChunks = [];
|
|
982
|
-
await workerSeek(
|
|
983
|
-
Math.max(0, time) * 1e3,
|
|
984
|
-
SEEK_FLAG.NONE
|
|
985
|
-
);
|
|
986
|
-
});
|
|
154
|
+
return workerDestroy();
|
|
987
155
|
},
|
|
156
|
+
read: () => workerRead(),
|
|
157
|
+
seek: (time) => workerSeek(Math.max(0, time) * 1e3),
|
|
988
158
|
getInfo: () => getInfo()
|
|
989
159
|
};
|
|
990
160
|
return result;
|
|
991
161
|
};
|
|
992
162
|
|
|
993
|
-
export {
|
|
163
|
+
export { makeTransmuxer };
|