kernel-script 1.0.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/LICENSE +21 -0
- package/README.md +396 -0
- package/bun.lock +385 -0
- package/dist/core/bootstrap.d.ts +2 -0
- package/dist/core/commands.d.ts +15 -0
- package/dist/core/engine-hub.d.ts +8 -0
- package/dist/core/helper.d.ts +1 -0
- package/dist/core/hooks/use-queue.d.ts +36 -0
- package/dist/core/persistence-manager.d.ts +10 -0
- package/dist/core/queue-manager.d.ts +66 -0
- package/dist/core/registry.d.ts +3 -0
- package/dist/core/store/base-task.store.d.ts +39 -0
- package/dist/core/task-context.d.ts +23 -0
- package/dist/index.cjs +4051 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +3575 -0
- package/package.json +59 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3575 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
14
|
+
var __copyProps = (to, from, except, desc) => {
|
|
15
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
16
|
+
for (let key of __getOwnPropNames(from))
|
|
17
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
18
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
31
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
32
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
33
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
34
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
35
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
36
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
37
|
+
set _(value) {
|
|
38
|
+
__privateSet(obj, member, value, setter);
|
|
39
|
+
},
|
|
40
|
+
get _() {
|
|
41
|
+
return __privateGet(obj, member, getter);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// node_modules/eventemitter3/index.js
|
|
46
|
+
var require_eventemitter3 = __commonJS({
|
|
47
|
+
"node_modules/eventemitter3/index.js"(exports, module) {
|
|
48
|
+
"use strict";
|
|
49
|
+
var has = Object.prototype.hasOwnProperty;
|
|
50
|
+
var prefix = "~";
|
|
51
|
+
function Events() {
|
|
52
|
+
}
|
|
53
|
+
if (Object.create) {
|
|
54
|
+
Events.prototype = /* @__PURE__ */ Object.create(null);
|
|
55
|
+
if (!new Events().__proto__) prefix = false;
|
|
56
|
+
}
|
|
57
|
+
function EE(fn, context, once) {
|
|
58
|
+
this.fn = fn;
|
|
59
|
+
this.context = context;
|
|
60
|
+
this.once = once || false;
|
|
61
|
+
}
|
|
62
|
+
function addListener(emitter, event, fn, context, once) {
|
|
63
|
+
if (typeof fn !== "function") {
|
|
64
|
+
throw new TypeError("The listener must be a function");
|
|
65
|
+
}
|
|
66
|
+
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
67
|
+
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
68
|
+
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
69
|
+
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
70
|
+
return emitter;
|
|
71
|
+
}
|
|
72
|
+
function clearEvent(emitter, evt) {
|
|
73
|
+
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
74
|
+
else delete emitter._events[evt];
|
|
75
|
+
}
|
|
76
|
+
function EventEmitter2() {
|
|
77
|
+
this._events = new Events();
|
|
78
|
+
this._eventsCount = 0;
|
|
79
|
+
}
|
|
80
|
+
EventEmitter2.prototype.eventNames = function eventNames() {
|
|
81
|
+
var names = [], events, name;
|
|
82
|
+
if (this._eventsCount === 0) return names;
|
|
83
|
+
for (name in events = this._events) {
|
|
84
|
+
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
85
|
+
}
|
|
86
|
+
if (Object.getOwnPropertySymbols) {
|
|
87
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
88
|
+
}
|
|
89
|
+
return names;
|
|
90
|
+
};
|
|
91
|
+
EventEmitter2.prototype.listeners = function listeners(event) {
|
|
92
|
+
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
93
|
+
if (!handlers) return [];
|
|
94
|
+
if (handlers.fn) return [handlers.fn];
|
|
95
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
96
|
+
ee[i] = handlers[i].fn;
|
|
97
|
+
}
|
|
98
|
+
return ee;
|
|
99
|
+
};
|
|
100
|
+
EventEmitter2.prototype.listenerCount = function listenerCount(event) {
|
|
101
|
+
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
102
|
+
if (!listeners) return 0;
|
|
103
|
+
if (listeners.fn) return 1;
|
|
104
|
+
return listeners.length;
|
|
105
|
+
};
|
|
106
|
+
EventEmitter2.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
107
|
+
var evt = prefix ? prefix + event : event;
|
|
108
|
+
if (!this._events[evt]) return false;
|
|
109
|
+
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
110
|
+
if (listeners.fn) {
|
|
111
|
+
if (listeners.once) this.removeListener(event, listeners.fn, void 0, true);
|
|
112
|
+
switch (len) {
|
|
113
|
+
case 1:
|
|
114
|
+
return listeners.fn.call(listeners.context), true;
|
|
115
|
+
case 2:
|
|
116
|
+
return listeners.fn.call(listeners.context, a1), true;
|
|
117
|
+
case 3:
|
|
118
|
+
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
119
|
+
case 4:
|
|
120
|
+
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
121
|
+
case 5:
|
|
122
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
123
|
+
case 6:
|
|
124
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
125
|
+
}
|
|
126
|
+
for (i = 1, args = new Array(len - 1); i < len; i++) {
|
|
127
|
+
args[i - 1] = arguments[i];
|
|
128
|
+
}
|
|
129
|
+
listeners.fn.apply(listeners.context, args);
|
|
130
|
+
} else {
|
|
131
|
+
var length = listeners.length, j;
|
|
132
|
+
for (i = 0; i < length; i++) {
|
|
133
|
+
if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true);
|
|
134
|
+
switch (len) {
|
|
135
|
+
case 1:
|
|
136
|
+
listeners[i].fn.call(listeners[i].context);
|
|
137
|
+
break;
|
|
138
|
+
case 2:
|
|
139
|
+
listeners[i].fn.call(listeners[i].context, a1);
|
|
140
|
+
break;
|
|
141
|
+
case 3:
|
|
142
|
+
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
143
|
+
break;
|
|
144
|
+
case 4:
|
|
145
|
+
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
146
|
+
break;
|
|
147
|
+
default:
|
|
148
|
+
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
|
|
149
|
+
args[j - 1] = arguments[j];
|
|
150
|
+
}
|
|
151
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return true;
|
|
156
|
+
};
|
|
157
|
+
EventEmitter2.prototype.on = function on(event, fn, context) {
|
|
158
|
+
return addListener(this, event, fn, context, false);
|
|
159
|
+
};
|
|
160
|
+
EventEmitter2.prototype.once = function once(event, fn, context) {
|
|
161
|
+
return addListener(this, event, fn, context, true);
|
|
162
|
+
};
|
|
163
|
+
EventEmitter2.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
164
|
+
var evt = prefix ? prefix + event : event;
|
|
165
|
+
if (!this._events[evt]) return this;
|
|
166
|
+
if (!fn) {
|
|
167
|
+
clearEvent(this, evt);
|
|
168
|
+
return this;
|
|
169
|
+
}
|
|
170
|
+
var listeners = this._events[evt];
|
|
171
|
+
if (listeners.fn) {
|
|
172
|
+
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
173
|
+
clearEvent(this, evt);
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
177
|
+
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
178
|
+
events.push(listeners[i]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
182
|
+
else clearEvent(this, evt);
|
|
183
|
+
}
|
|
184
|
+
return this;
|
|
185
|
+
};
|
|
186
|
+
EventEmitter2.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
187
|
+
var evt;
|
|
188
|
+
if (event) {
|
|
189
|
+
evt = prefix ? prefix + event : event;
|
|
190
|
+
if (this._events[evt]) clearEvent(this, evt);
|
|
191
|
+
} else {
|
|
192
|
+
this._events = new Events();
|
|
193
|
+
this._eventsCount = 0;
|
|
194
|
+
}
|
|
195
|
+
return this;
|
|
196
|
+
};
|
|
197
|
+
EventEmitter2.prototype.off = EventEmitter2.prototype.removeListener;
|
|
198
|
+
EventEmitter2.prototype.addListener = EventEmitter2.prototype.on;
|
|
199
|
+
EventEmitter2.prefixed = prefix;
|
|
200
|
+
EventEmitter2.EventEmitter = EventEmitter2;
|
|
201
|
+
if ("undefined" !== typeof module) {
|
|
202
|
+
module.exports = EventEmitter2;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
// node_modules/react/cjs/react.development.js
|
|
208
|
+
var require_react_development = __commonJS({
|
|
209
|
+
"node_modules/react/cjs/react.development.js"(exports, module) {
|
|
210
|
+
"use strict";
|
|
211
|
+
(function() {
|
|
212
|
+
function defineDeprecationWarning(methodName, info) {
|
|
213
|
+
Object.defineProperty(Component.prototype, methodName, {
|
|
214
|
+
get: function() {
|
|
215
|
+
console.warn(
|
|
216
|
+
"%s(...) is deprecated in plain JavaScript React classes. %s",
|
|
217
|
+
info[0],
|
|
218
|
+
info[1]
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
function getIteratorFn(maybeIterable) {
|
|
224
|
+
if (null === maybeIterable || "object" !== typeof maybeIterable)
|
|
225
|
+
return null;
|
|
226
|
+
maybeIterable = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable["@@iterator"];
|
|
227
|
+
return "function" === typeof maybeIterable ? maybeIterable : null;
|
|
228
|
+
}
|
|
229
|
+
function warnNoop(publicInstance, callerName) {
|
|
230
|
+
publicInstance = (publicInstance = publicInstance.constructor) && (publicInstance.displayName || publicInstance.name) || "ReactClass";
|
|
231
|
+
var warningKey = publicInstance + "." + callerName;
|
|
232
|
+
didWarnStateUpdateForUnmountedComponent[warningKey] || (console.error(
|
|
233
|
+
"Can't call %s on a component that is not yet mounted. This is a no-op, but it might indicate a bug in your application. Instead, assign to `this.state` directly or define a `state = {};` class property with the desired state in the %s component.",
|
|
234
|
+
callerName,
|
|
235
|
+
publicInstance
|
|
236
|
+
), didWarnStateUpdateForUnmountedComponent[warningKey] = true);
|
|
237
|
+
}
|
|
238
|
+
function Component(props, context, updater) {
|
|
239
|
+
this.props = props;
|
|
240
|
+
this.context = context;
|
|
241
|
+
this.refs = emptyObject;
|
|
242
|
+
this.updater = updater || ReactNoopUpdateQueue;
|
|
243
|
+
}
|
|
244
|
+
function ComponentDummy() {
|
|
245
|
+
}
|
|
246
|
+
function PureComponent(props, context, updater) {
|
|
247
|
+
this.props = props;
|
|
248
|
+
this.context = context;
|
|
249
|
+
this.refs = emptyObject;
|
|
250
|
+
this.updater = updater || ReactNoopUpdateQueue;
|
|
251
|
+
}
|
|
252
|
+
function noop() {
|
|
253
|
+
}
|
|
254
|
+
function testStringCoercion(value) {
|
|
255
|
+
return "" + value;
|
|
256
|
+
}
|
|
257
|
+
function checkKeyStringCoercion(value) {
|
|
258
|
+
try {
|
|
259
|
+
testStringCoercion(value);
|
|
260
|
+
var JSCompiler_inline_result = false;
|
|
261
|
+
} catch (e) {
|
|
262
|
+
JSCompiler_inline_result = true;
|
|
263
|
+
}
|
|
264
|
+
if (JSCompiler_inline_result) {
|
|
265
|
+
JSCompiler_inline_result = console;
|
|
266
|
+
var JSCompiler_temp_const = JSCompiler_inline_result.error;
|
|
267
|
+
var JSCompiler_inline_result$jscomp$0 = "function" === typeof Symbol && Symbol.toStringTag && value[Symbol.toStringTag] || value.constructor.name || "Object";
|
|
268
|
+
JSCompiler_temp_const.call(
|
|
269
|
+
JSCompiler_inline_result,
|
|
270
|
+
"The provided key is an unsupported type %s. This value must be coerced to a string before using it here.",
|
|
271
|
+
JSCompiler_inline_result$jscomp$0
|
|
272
|
+
);
|
|
273
|
+
return testStringCoercion(value);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
function getComponentNameFromType(type) {
|
|
277
|
+
if (null == type) return null;
|
|
278
|
+
if ("function" === typeof type)
|
|
279
|
+
return type.$$typeof === REACT_CLIENT_REFERENCE ? null : type.displayName || type.name || null;
|
|
280
|
+
if ("string" === typeof type) return type;
|
|
281
|
+
switch (type) {
|
|
282
|
+
case REACT_FRAGMENT_TYPE:
|
|
283
|
+
return "Fragment";
|
|
284
|
+
case REACT_PROFILER_TYPE:
|
|
285
|
+
return "Profiler";
|
|
286
|
+
case REACT_STRICT_MODE_TYPE:
|
|
287
|
+
return "StrictMode";
|
|
288
|
+
case REACT_SUSPENSE_TYPE:
|
|
289
|
+
return "Suspense";
|
|
290
|
+
case REACT_SUSPENSE_LIST_TYPE:
|
|
291
|
+
return "SuspenseList";
|
|
292
|
+
case REACT_ACTIVITY_TYPE:
|
|
293
|
+
return "Activity";
|
|
294
|
+
}
|
|
295
|
+
if ("object" === typeof type)
|
|
296
|
+
switch ("number" === typeof type.tag && console.error(
|
|
297
|
+
"Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."
|
|
298
|
+
), type.$$typeof) {
|
|
299
|
+
case REACT_PORTAL_TYPE:
|
|
300
|
+
return "Portal";
|
|
301
|
+
case REACT_CONTEXT_TYPE:
|
|
302
|
+
return type.displayName || "Context";
|
|
303
|
+
case REACT_CONSUMER_TYPE:
|
|
304
|
+
return (type._context.displayName || "Context") + ".Consumer";
|
|
305
|
+
case REACT_FORWARD_REF_TYPE:
|
|
306
|
+
var innerType = type.render;
|
|
307
|
+
type = type.displayName;
|
|
308
|
+
type || (type = innerType.displayName || innerType.name || "", type = "" !== type ? "ForwardRef(" + type + ")" : "ForwardRef");
|
|
309
|
+
return type;
|
|
310
|
+
case REACT_MEMO_TYPE:
|
|
311
|
+
return innerType = type.displayName || null, null !== innerType ? innerType : getComponentNameFromType(type.type) || "Memo";
|
|
312
|
+
case REACT_LAZY_TYPE:
|
|
313
|
+
innerType = type._payload;
|
|
314
|
+
type = type._init;
|
|
315
|
+
try {
|
|
316
|
+
return getComponentNameFromType(type(innerType));
|
|
317
|
+
} catch (x) {
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return null;
|
|
321
|
+
}
|
|
322
|
+
function getTaskName(type) {
|
|
323
|
+
if (type === REACT_FRAGMENT_TYPE) return "<>";
|
|
324
|
+
if ("object" === typeof type && null !== type && type.$$typeof === REACT_LAZY_TYPE)
|
|
325
|
+
return "<...>";
|
|
326
|
+
try {
|
|
327
|
+
var name = getComponentNameFromType(type);
|
|
328
|
+
return name ? "<" + name + ">" : "<...>";
|
|
329
|
+
} catch (x) {
|
|
330
|
+
return "<...>";
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function getOwner() {
|
|
334
|
+
var dispatcher = ReactSharedInternals.A;
|
|
335
|
+
return null === dispatcher ? null : dispatcher.getOwner();
|
|
336
|
+
}
|
|
337
|
+
function UnknownOwner() {
|
|
338
|
+
return Error("react-stack-top-frame");
|
|
339
|
+
}
|
|
340
|
+
function hasValidKey(config) {
|
|
341
|
+
if (hasOwnProperty.call(config, "key")) {
|
|
342
|
+
var getter = Object.getOwnPropertyDescriptor(config, "key").get;
|
|
343
|
+
if (getter && getter.isReactWarning) return false;
|
|
344
|
+
}
|
|
345
|
+
return void 0 !== config.key;
|
|
346
|
+
}
|
|
347
|
+
function defineKeyPropWarningGetter(props, displayName) {
|
|
348
|
+
function warnAboutAccessingKey() {
|
|
349
|
+
specialPropKeyWarningShown || (specialPropKeyWarningShown = true, console.error(
|
|
350
|
+
"%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://react.dev/link/special-props)",
|
|
351
|
+
displayName
|
|
352
|
+
));
|
|
353
|
+
}
|
|
354
|
+
warnAboutAccessingKey.isReactWarning = true;
|
|
355
|
+
Object.defineProperty(props, "key", {
|
|
356
|
+
get: warnAboutAccessingKey,
|
|
357
|
+
configurable: true
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
function elementRefGetterWithDeprecationWarning() {
|
|
361
|
+
var componentName = getComponentNameFromType(this.type);
|
|
362
|
+
didWarnAboutElementRef[componentName] || (didWarnAboutElementRef[componentName] = true, console.error(
|
|
363
|
+
"Accessing element.ref was removed in React 19. ref is now a regular prop. It will be removed from the JSX Element type in a future release."
|
|
364
|
+
));
|
|
365
|
+
componentName = this.props.ref;
|
|
366
|
+
return void 0 !== componentName ? componentName : null;
|
|
367
|
+
}
|
|
368
|
+
function ReactElement(type, key, props, owner, debugStack, debugTask) {
|
|
369
|
+
var refProp = props.ref;
|
|
370
|
+
type = {
|
|
371
|
+
$$typeof: REACT_ELEMENT_TYPE,
|
|
372
|
+
type,
|
|
373
|
+
key,
|
|
374
|
+
props,
|
|
375
|
+
_owner: owner
|
|
376
|
+
};
|
|
377
|
+
null !== (void 0 !== refProp ? refProp : null) ? Object.defineProperty(type, "ref", {
|
|
378
|
+
enumerable: false,
|
|
379
|
+
get: elementRefGetterWithDeprecationWarning
|
|
380
|
+
}) : Object.defineProperty(type, "ref", { enumerable: false, value: null });
|
|
381
|
+
type._store = {};
|
|
382
|
+
Object.defineProperty(type._store, "validated", {
|
|
383
|
+
configurable: false,
|
|
384
|
+
enumerable: false,
|
|
385
|
+
writable: true,
|
|
386
|
+
value: 0
|
|
387
|
+
});
|
|
388
|
+
Object.defineProperty(type, "_debugInfo", {
|
|
389
|
+
configurable: false,
|
|
390
|
+
enumerable: false,
|
|
391
|
+
writable: true,
|
|
392
|
+
value: null
|
|
393
|
+
});
|
|
394
|
+
Object.defineProperty(type, "_debugStack", {
|
|
395
|
+
configurable: false,
|
|
396
|
+
enumerable: false,
|
|
397
|
+
writable: true,
|
|
398
|
+
value: debugStack
|
|
399
|
+
});
|
|
400
|
+
Object.defineProperty(type, "_debugTask", {
|
|
401
|
+
configurable: false,
|
|
402
|
+
enumerable: false,
|
|
403
|
+
writable: true,
|
|
404
|
+
value: debugTask
|
|
405
|
+
});
|
|
406
|
+
Object.freeze && (Object.freeze(type.props), Object.freeze(type));
|
|
407
|
+
return type;
|
|
408
|
+
}
|
|
409
|
+
function cloneAndReplaceKey(oldElement, newKey) {
|
|
410
|
+
newKey = ReactElement(
|
|
411
|
+
oldElement.type,
|
|
412
|
+
newKey,
|
|
413
|
+
oldElement.props,
|
|
414
|
+
oldElement._owner,
|
|
415
|
+
oldElement._debugStack,
|
|
416
|
+
oldElement._debugTask
|
|
417
|
+
);
|
|
418
|
+
oldElement._store && (newKey._store.validated = oldElement._store.validated);
|
|
419
|
+
return newKey;
|
|
420
|
+
}
|
|
421
|
+
function validateChildKeys(node) {
|
|
422
|
+
isValidElement(node) ? node._store && (node._store.validated = 1) : "object" === typeof node && null !== node && node.$$typeof === REACT_LAZY_TYPE && ("fulfilled" === node._payload.status ? isValidElement(node._payload.value) && node._payload.value._store && (node._payload.value._store.validated = 1) : node._store && (node._store.validated = 1));
|
|
423
|
+
}
|
|
424
|
+
function isValidElement(object) {
|
|
425
|
+
return "object" === typeof object && null !== object && object.$$typeof === REACT_ELEMENT_TYPE;
|
|
426
|
+
}
|
|
427
|
+
function escape(key) {
|
|
428
|
+
var escaperLookup = { "=": "=0", ":": "=2" };
|
|
429
|
+
return "$" + key.replace(/[=:]/g, function(match) {
|
|
430
|
+
return escaperLookup[match];
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
function getElementKey(element, index) {
|
|
434
|
+
return "object" === typeof element && null !== element && null != element.key ? (checkKeyStringCoercion(element.key), escape("" + element.key)) : index.toString(36);
|
|
435
|
+
}
|
|
436
|
+
function resolveThenable(thenable) {
|
|
437
|
+
switch (thenable.status) {
|
|
438
|
+
case "fulfilled":
|
|
439
|
+
return thenable.value;
|
|
440
|
+
case "rejected":
|
|
441
|
+
throw thenable.reason;
|
|
442
|
+
default:
|
|
443
|
+
switch ("string" === typeof thenable.status ? thenable.then(noop, noop) : (thenable.status = "pending", thenable.then(
|
|
444
|
+
function(fulfilledValue) {
|
|
445
|
+
"pending" === thenable.status && (thenable.status = "fulfilled", thenable.value = fulfilledValue);
|
|
446
|
+
},
|
|
447
|
+
function(error) {
|
|
448
|
+
"pending" === thenable.status && (thenable.status = "rejected", thenable.reason = error);
|
|
449
|
+
}
|
|
450
|
+
)), thenable.status) {
|
|
451
|
+
case "fulfilled":
|
|
452
|
+
return thenable.value;
|
|
453
|
+
case "rejected":
|
|
454
|
+
throw thenable.reason;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
throw thenable;
|
|
458
|
+
}
|
|
459
|
+
function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) {
|
|
460
|
+
var type = typeof children;
|
|
461
|
+
if ("undefined" === type || "boolean" === type) children = null;
|
|
462
|
+
var invokeCallback = false;
|
|
463
|
+
if (null === children) invokeCallback = true;
|
|
464
|
+
else
|
|
465
|
+
switch (type) {
|
|
466
|
+
case "bigint":
|
|
467
|
+
case "string":
|
|
468
|
+
case "number":
|
|
469
|
+
invokeCallback = true;
|
|
470
|
+
break;
|
|
471
|
+
case "object":
|
|
472
|
+
switch (children.$$typeof) {
|
|
473
|
+
case REACT_ELEMENT_TYPE:
|
|
474
|
+
case REACT_PORTAL_TYPE:
|
|
475
|
+
invokeCallback = true;
|
|
476
|
+
break;
|
|
477
|
+
case REACT_LAZY_TYPE:
|
|
478
|
+
return invokeCallback = children._init, mapIntoArray(
|
|
479
|
+
invokeCallback(children._payload),
|
|
480
|
+
array,
|
|
481
|
+
escapedPrefix,
|
|
482
|
+
nameSoFar,
|
|
483
|
+
callback
|
|
484
|
+
);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (invokeCallback) {
|
|
488
|
+
invokeCallback = children;
|
|
489
|
+
callback = callback(invokeCallback);
|
|
490
|
+
var childKey = "" === nameSoFar ? "." + getElementKey(invokeCallback, 0) : nameSoFar;
|
|
491
|
+
isArrayImpl(callback) ? (escapedPrefix = "", null != childKey && (escapedPrefix = childKey.replace(userProvidedKeyEscapeRegex, "$&/") + "/"), mapIntoArray(callback, array, escapedPrefix, "", function(c) {
|
|
492
|
+
return c;
|
|
493
|
+
})) : null != callback && (isValidElement(callback) && (null != callback.key && (invokeCallback && invokeCallback.key === callback.key || checkKeyStringCoercion(callback.key)), escapedPrefix = cloneAndReplaceKey(
|
|
494
|
+
callback,
|
|
495
|
+
escapedPrefix + (null == callback.key || invokeCallback && invokeCallback.key === callback.key ? "" : ("" + callback.key).replace(
|
|
496
|
+
userProvidedKeyEscapeRegex,
|
|
497
|
+
"$&/"
|
|
498
|
+
) + "/") + childKey
|
|
499
|
+
), "" !== nameSoFar && null != invokeCallback && isValidElement(invokeCallback) && null == invokeCallback.key && invokeCallback._store && !invokeCallback._store.validated && (escapedPrefix._store.validated = 2), callback = escapedPrefix), array.push(callback));
|
|
500
|
+
return 1;
|
|
501
|
+
}
|
|
502
|
+
invokeCallback = 0;
|
|
503
|
+
childKey = "" === nameSoFar ? "." : nameSoFar + ":";
|
|
504
|
+
if (isArrayImpl(children))
|
|
505
|
+
for (var i = 0; i < children.length; i++)
|
|
506
|
+
nameSoFar = children[i], type = childKey + getElementKey(nameSoFar, i), invokeCallback += mapIntoArray(
|
|
507
|
+
nameSoFar,
|
|
508
|
+
array,
|
|
509
|
+
escapedPrefix,
|
|
510
|
+
type,
|
|
511
|
+
callback
|
|
512
|
+
);
|
|
513
|
+
else if (i = getIteratorFn(children), "function" === typeof i)
|
|
514
|
+
for (i === children.entries && (didWarnAboutMaps || console.warn(
|
|
515
|
+
"Using Maps as children is not supported. Use an array of keyed ReactElements instead."
|
|
516
|
+
), didWarnAboutMaps = true), children = i.call(children), i = 0; !(nameSoFar = children.next()).done; )
|
|
517
|
+
nameSoFar = nameSoFar.value, type = childKey + getElementKey(nameSoFar, i++), invokeCallback += mapIntoArray(
|
|
518
|
+
nameSoFar,
|
|
519
|
+
array,
|
|
520
|
+
escapedPrefix,
|
|
521
|
+
type,
|
|
522
|
+
callback
|
|
523
|
+
);
|
|
524
|
+
else if ("object" === type) {
|
|
525
|
+
if ("function" === typeof children.then)
|
|
526
|
+
return mapIntoArray(
|
|
527
|
+
resolveThenable(children),
|
|
528
|
+
array,
|
|
529
|
+
escapedPrefix,
|
|
530
|
+
nameSoFar,
|
|
531
|
+
callback
|
|
532
|
+
);
|
|
533
|
+
array = String(children);
|
|
534
|
+
throw Error(
|
|
535
|
+
"Objects are not valid as a React child (found: " + ("[object Object]" === array ? "object with keys {" + Object.keys(children).join(", ") + "}" : array) + "). If you meant to render a collection of children, use an array instead."
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
return invokeCallback;
|
|
539
|
+
}
|
|
540
|
+
function mapChildren(children, func, context) {
|
|
541
|
+
if (null == children) return children;
|
|
542
|
+
var result = [], count = 0;
|
|
543
|
+
mapIntoArray(children, result, "", "", function(child) {
|
|
544
|
+
return func.call(context, child, count++);
|
|
545
|
+
});
|
|
546
|
+
return result;
|
|
547
|
+
}
|
|
548
|
+
function lazyInitializer(payload) {
|
|
549
|
+
if (-1 === payload._status) {
|
|
550
|
+
var ioInfo = payload._ioInfo;
|
|
551
|
+
null != ioInfo && (ioInfo.start = ioInfo.end = performance.now());
|
|
552
|
+
ioInfo = payload._result;
|
|
553
|
+
var thenable = ioInfo();
|
|
554
|
+
thenable.then(
|
|
555
|
+
function(moduleObject) {
|
|
556
|
+
if (0 === payload._status || -1 === payload._status) {
|
|
557
|
+
payload._status = 1;
|
|
558
|
+
payload._result = moduleObject;
|
|
559
|
+
var _ioInfo = payload._ioInfo;
|
|
560
|
+
null != _ioInfo && (_ioInfo.end = performance.now());
|
|
561
|
+
void 0 === thenable.status && (thenable.status = "fulfilled", thenable.value = moduleObject);
|
|
562
|
+
}
|
|
563
|
+
},
|
|
564
|
+
function(error) {
|
|
565
|
+
if (0 === payload._status || -1 === payload._status) {
|
|
566
|
+
payload._status = 2;
|
|
567
|
+
payload._result = error;
|
|
568
|
+
var _ioInfo2 = payload._ioInfo;
|
|
569
|
+
null != _ioInfo2 && (_ioInfo2.end = performance.now());
|
|
570
|
+
void 0 === thenable.status && (thenable.status = "rejected", thenable.reason = error);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
);
|
|
574
|
+
ioInfo = payload._ioInfo;
|
|
575
|
+
if (null != ioInfo) {
|
|
576
|
+
ioInfo.value = thenable;
|
|
577
|
+
var displayName = thenable.displayName;
|
|
578
|
+
"string" === typeof displayName && (ioInfo.name = displayName);
|
|
579
|
+
}
|
|
580
|
+
-1 === payload._status && (payload._status = 0, payload._result = thenable);
|
|
581
|
+
}
|
|
582
|
+
if (1 === payload._status)
|
|
583
|
+
return ioInfo = payload._result, void 0 === ioInfo && console.error(
|
|
584
|
+
"lazy: Expected the result of a dynamic import() call. Instead received: %s\n\nYour code should look like: \n const MyComponent = lazy(() => import('./MyComponent'))\n\nDid you accidentally put curly braces around the import?",
|
|
585
|
+
ioInfo
|
|
586
|
+
), "default" in ioInfo || console.error(
|
|
587
|
+
"lazy: Expected the result of a dynamic import() call. Instead received: %s\n\nYour code should look like: \n const MyComponent = lazy(() => import('./MyComponent'))",
|
|
588
|
+
ioInfo
|
|
589
|
+
), ioInfo.default;
|
|
590
|
+
throw payload._result;
|
|
591
|
+
}
|
|
592
|
+
function resolveDispatcher() {
|
|
593
|
+
var dispatcher = ReactSharedInternals.H;
|
|
594
|
+
null === dispatcher && console.error(
|
|
595
|
+
"Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:\n1. You might have mismatching versions of React and the renderer (such as React DOM)\n2. You might be breaking the Rules of Hooks\n3. You might have more than one copy of React in the same app\nSee https://react.dev/link/invalid-hook-call for tips about how to debug and fix this problem."
|
|
596
|
+
);
|
|
597
|
+
return dispatcher;
|
|
598
|
+
}
|
|
599
|
+
function releaseAsyncTransition() {
|
|
600
|
+
ReactSharedInternals.asyncTransitions--;
|
|
601
|
+
}
|
|
602
|
+
function enqueueTask(task) {
|
|
603
|
+
if (null === enqueueTaskImpl)
|
|
604
|
+
try {
|
|
605
|
+
var requireString = ("require" + Math.random()).slice(0, 7);
|
|
606
|
+
enqueueTaskImpl = (module && module[requireString]).call(
|
|
607
|
+
module,
|
|
608
|
+
"timers"
|
|
609
|
+
).setImmediate;
|
|
610
|
+
} catch (_err) {
|
|
611
|
+
enqueueTaskImpl = function(callback) {
|
|
612
|
+
false === didWarnAboutMessageChannel && (didWarnAboutMessageChannel = true, "undefined" === typeof MessageChannel && console.error(
|
|
613
|
+
"This browser does not have a MessageChannel implementation, so enqueuing tasks via await act(async () => ...) will fail. Please file an issue at https://github.com/facebook/react/issues if you encounter this warning."
|
|
614
|
+
));
|
|
615
|
+
var channel = new MessageChannel();
|
|
616
|
+
channel.port1.onmessage = callback;
|
|
617
|
+
channel.port2.postMessage(void 0);
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
return enqueueTaskImpl(task);
|
|
621
|
+
}
|
|
622
|
+
function aggregateErrors(errors) {
|
|
623
|
+
return 1 < errors.length && "function" === typeof AggregateError ? new AggregateError(errors) : errors[0];
|
|
624
|
+
}
|
|
625
|
+
function popActScope(prevActQueue, prevActScopeDepth) {
|
|
626
|
+
prevActScopeDepth !== actScopeDepth - 1 && console.error(
|
|
627
|
+
"You seem to have overlapping act() calls, this is not supported. Be sure to await previous act() calls before making a new one. "
|
|
628
|
+
);
|
|
629
|
+
actScopeDepth = prevActScopeDepth;
|
|
630
|
+
}
|
|
631
|
+
function recursivelyFlushAsyncActWork(returnValue, resolve, reject) {
|
|
632
|
+
var queue = ReactSharedInternals.actQueue;
|
|
633
|
+
if (null !== queue)
|
|
634
|
+
if (0 !== queue.length)
|
|
635
|
+
try {
|
|
636
|
+
flushActQueue(queue);
|
|
637
|
+
enqueueTask(function() {
|
|
638
|
+
return recursivelyFlushAsyncActWork(returnValue, resolve, reject);
|
|
639
|
+
});
|
|
640
|
+
return;
|
|
641
|
+
} catch (error) {
|
|
642
|
+
ReactSharedInternals.thrownErrors.push(error);
|
|
643
|
+
}
|
|
644
|
+
else ReactSharedInternals.actQueue = null;
|
|
645
|
+
0 < ReactSharedInternals.thrownErrors.length ? (queue = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, reject(queue)) : resolve(returnValue);
|
|
646
|
+
}
|
|
647
|
+
function flushActQueue(queue) {
|
|
648
|
+
if (!isFlushing) {
|
|
649
|
+
isFlushing = true;
|
|
650
|
+
var i = 0;
|
|
651
|
+
try {
|
|
652
|
+
for (; i < queue.length; i++) {
|
|
653
|
+
var callback = queue[i];
|
|
654
|
+
do {
|
|
655
|
+
ReactSharedInternals.didUsePromise = false;
|
|
656
|
+
var continuation = callback(false);
|
|
657
|
+
if (null !== continuation) {
|
|
658
|
+
if (ReactSharedInternals.didUsePromise) {
|
|
659
|
+
queue[i] = callback;
|
|
660
|
+
queue.splice(0, i);
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
callback = continuation;
|
|
664
|
+
} else break;
|
|
665
|
+
} while (1);
|
|
666
|
+
}
|
|
667
|
+
queue.length = 0;
|
|
668
|
+
} catch (error) {
|
|
669
|
+
queue.splice(0, i + 1), ReactSharedInternals.thrownErrors.push(error);
|
|
670
|
+
} finally {
|
|
671
|
+
isFlushing = false;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
676
|
+
var REACT_ELEMENT_TYPE = /* @__PURE__ */ Symbol.for("react.transitional.element"), REACT_PORTAL_TYPE = /* @__PURE__ */ Symbol.for("react.portal"), REACT_FRAGMENT_TYPE = /* @__PURE__ */ Symbol.for("react.fragment"), REACT_STRICT_MODE_TYPE = /* @__PURE__ */ Symbol.for("react.strict_mode"), REACT_PROFILER_TYPE = /* @__PURE__ */ Symbol.for("react.profiler"), REACT_CONSUMER_TYPE = /* @__PURE__ */ Symbol.for("react.consumer"), REACT_CONTEXT_TYPE = /* @__PURE__ */ Symbol.for("react.context"), REACT_FORWARD_REF_TYPE = /* @__PURE__ */ Symbol.for("react.forward_ref"), REACT_SUSPENSE_TYPE = /* @__PURE__ */ Symbol.for("react.suspense"), REACT_SUSPENSE_LIST_TYPE = /* @__PURE__ */ Symbol.for("react.suspense_list"), REACT_MEMO_TYPE = /* @__PURE__ */ Symbol.for("react.memo"), REACT_LAZY_TYPE = /* @__PURE__ */ Symbol.for("react.lazy"), REACT_ACTIVITY_TYPE = /* @__PURE__ */ Symbol.for("react.activity"), MAYBE_ITERATOR_SYMBOL = Symbol.iterator, didWarnStateUpdateForUnmountedComponent = {}, ReactNoopUpdateQueue = {
|
|
677
|
+
isMounted: function() {
|
|
678
|
+
return false;
|
|
679
|
+
},
|
|
680
|
+
enqueueForceUpdate: function(publicInstance) {
|
|
681
|
+
warnNoop(publicInstance, "forceUpdate");
|
|
682
|
+
},
|
|
683
|
+
enqueueReplaceState: function(publicInstance) {
|
|
684
|
+
warnNoop(publicInstance, "replaceState");
|
|
685
|
+
},
|
|
686
|
+
enqueueSetState: function(publicInstance) {
|
|
687
|
+
warnNoop(publicInstance, "setState");
|
|
688
|
+
}
|
|
689
|
+
}, assign = Object.assign, emptyObject = {};
|
|
690
|
+
Object.freeze(emptyObject);
|
|
691
|
+
Component.prototype.isReactComponent = {};
|
|
692
|
+
Component.prototype.setState = function(partialState, callback) {
|
|
693
|
+
if ("object" !== typeof partialState && "function" !== typeof partialState && null != partialState)
|
|
694
|
+
throw Error(
|
|
695
|
+
"takes an object of state variables to update or a function which returns an object of state variables."
|
|
696
|
+
);
|
|
697
|
+
this.updater.enqueueSetState(this, partialState, callback, "setState");
|
|
698
|
+
};
|
|
699
|
+
Component.prototype.forceUpdate = function(callback) {
|
|
700
|
+
this.updater.enqueueForceUpdate(this, callback, "forceUpdate");
|
|
701
|
+
};
|
|
702
|
+
var deprecatedAPIs = {
|
|
703
|
+
isMounted: [
|
|
704
|
+
"isMounted",
|
|
705
|
+
"Instead, make sure to clean up subscriptions and pending requests in componentWillUnmount to prevent memory leaks."
|
|
706
|
+
],
|
|
707
|
+
replaceState: [
|
|
708
|
+
"replaceState",
|
|
709
|
+
"Refactor your code to use setState instead (see https://github.com/facebook/react/issues/3236)."
|
|
710
|
+
]
|
|
711
|
+
};
|
|
712
|
+
for (fnName in deprecatedAPIs)
|
|
713
|
+
deprecatedAPIs.hasOwnProperty(fnName) && defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
|
|
714
|
+
ComponentDummy.prototype = Component.prototype;
|
|
715
|
+
deprecatedAPIs = PureComponent.prototype = new ComponentDummy();
|
|
716
|
+
deprecatedAPIs.constructor = PureComponent;
|
|
717
|
+
assign(deprecatedAPIs, Component.prototype);
|
|
718
|
+
deprecatedAPIs.isPureReactComponent = true;
|
|
719
|
+
var isArrayImpl = Array.isArray, REACT_CLIENT_REFERENCE = /* @__PURE__ */ Symbol.for("react.client.reference"), ReactSharedInternals = {
|
|
720
|
+
H: null,
|
|
721
|
+
A: null,
|
|
722
|
+
T: null,
|
|
723
|
+
S: null,
|
|
724
|
+
actQueue: null,
|
|
725
|
+
asyncTransitions: 0,
|
|
726
|
+
isBatchingLegacy: false,
|
|
727
|
+
didScheduleLegacyUpdate: false,
|
|
728
|
+
didUsePromise: false,
|
|
729
|
+
thrownErrors: [],
|
|
730
|
+
getCurrentStack: null,
|
|
731
|
+
recentlyCreatedOwnerStacks: 0
|
|
732
|
+
}, hasOwnProperty = Object.prototype.hasOwnProperty, createTask = console.createTask ? console.createTask : function() {
|
|
733
|
+
return null;
|
|
734
|
+
};
|
|
735
|
+
deprecatedAPIs = {
|
|
736
|
+
react_stack_bottom_frame: function(callStackForError) {
|
|
737
|
+
return callStackForError();
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
var specialPropKeyWarningShown, didWarnAboutOldJSXRuntime;
|
|
741
|
+
var didWarnAboutElementRef = {};
|
|
742
|
+
var unknownOwnerDebugStack = deprecatedAPIs.react_stack_bottom_frame.bind(
|
|
743
|
+
deprecatedAPIs,
|
|
744
|
+
UnknownOwner
|
|
745
|
+
)();
|
|
746
|
+
var unknownOwnerDebugTask = createTask(getTaskName(UnknownOwner));
|
|
747
|
+
var didWarnAboutMaps = false, userProvidedKeyEscapeRegex = /\/+/g, reportGlobalError = "function" === typeof reportError ? reportError : function(error) {
|
|
748
|
+
if ("object" === typeof window && "function" === typeof window.ErrorEvent) {
|
|
749
|
+
var event = new window.ErrorEvent("error", {
|
|
750
|
+
bubbles: true,
|
|
751
|
+
cancelable: true,
|
|
752
|
+
message: "object" === typeof error && null !== error && "string" === typeof error.message ? String(error.message) : String(error),
|
|
753
|
+
error
|
|
754
|
+
});
|
|
755
|
+
if (!window.dispatchEvent(event)) return;
|
|
756
|
+
} else if ("object" === typeof process && "function" === typeof process.emit) {
|
|
757
|
+
process.emit("uncaughtException", error);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
console.error(error);
|
|
761
|
+
}, didWarnAboutMessageChannel = false, enqueueTaskImpl = null, actScopeDepth = 0, didWarnNoAwaitAct = false, isFlushing = false, queueSeveralMicrotasks = "function" === typeof queueMicrotask ? function(callback) {
|
|
762
|
+
queueMicrotask(function() {
|
|
763
|
+
return queueMicrotask(callback);
|
|
764
|
+
});
|
|
765
|
+
} : enqueueTask;
|
|
766
|
+
deprecatedAPIs = Object.freeze({
|
|
767
|
+
__proto__: null,
|
|
768
|
+
c: function(size) {
|
|
769
|
+
return resolveDispatcher().useMemoCache(size);
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
var fnName = {
|
|
773
|
+
map: mapChildren,
|
|
774
|
+
forEach: function(children, forEachFunc, forEachContext) {
|
|
775
|
+
mapChildren(
|
|
776
|
+
children,
|
|
777
|
+
function() {
|
|
778
|
+
forEachFunc.apply(this, arguments);
|
|
779
|
+
},
|
|
780
|
+
forEachContext
|
|
781
|
+
);
|
|
782
|
+
},
|
|
783
|
+
count: function(children) {
|
|
784
|
+
var n = 0;
|
|
785
|
+
mapChildren(children, function() {
|
|
786
|
+
n++;
|
|
787
|
+
});
|
|
788
|
+
return n;
|
|
789
|
+
},
|
|
790
|
+
toArray: function(children) {
|
|
791
|
+
return mapChildren(children, function(child) {
|
|
792
|
+
return child;
|
|
793
|
+
}) || [];
|
|
794
|
+
},
|
|
795
|
+
only: function(children) {
|
|
796
|
+
if (!isValidElement(children))
|
|
797
|
+
throw Error(
|
|
798
|
+
"React.Children.only expected to receive a single React element child."
|
|
799
|
+
);
|
|
800
|
+
return children;
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
exports.Activity = REACT_ACTIVITY_TYPE;
|
|
804
|
+
exports.Children = fnName;
|
|
805
|
+
exports.Component = Component;
|
|
806
|
+
exports.Fragment = REACT_FRAGMENT_TYPE;
|
|
807
|
+
exports.Profiler = REACT_PROFILER_TYPE;
|
|
808
|
+
exports.PureComponent = PureComponent;
|
|
809
|
+
exports.StrictMode = REACT_STRICT_MODE_TYPE;
|
|
810
|
+
exports.Suspense = REACT_SUSPENSE_TYPE;
|
|
811
|
+
exports.__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE = ReactSharedInternals;
|
|
812
|
+
exports.__COMPILER_RUNTIME = deprecatedAPIs;
|
|
813
|
+
exports.act = function(callback) {
|
|
814
|
+
var prevActQueue = ReactSharedInternals.actQueue, prevActScopeDepth = actScopeDepth;
|
|
815
|
+
actScopeDepth++;
|
|
816
|
+
var queue = ReactSharedInternals.actQueue = null !== prevActQueue ? prevActQueue : [], didAwaitActCall = false;
|
|
817
|
+
try {
|
|
818
|
+
var result = callback();
|
|
819
|
+
} catch (error) {
|
|
820
|
+
ReactSharedInternals.thrownErrors.push(error);
|
|
821
|
+
}
|
|
822
|
+
if (0 < ReactSharedInternals.thrownErrors.length)
|
|
823
|
+
throw popActScope(prevActQueue, prevActScopeDepth), callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback;
|
|
824
|
+
if (null !== result && "object" === typeof result && "function" === typeof result.then) {
|
|
825
|
+
var thenable = result;
|
|
826
|
+
queueSeveralMicrotasks(function() {
|
|
827
|
+
didAwaitActCall || didWarnNoAwaitAct || (didWarnNoAwaitAct = true, console.error(
|
|
828
|
+
"You called act(async () => ...) without await. This could lead to unexpected testing behaviour, interleaving multiple act calls and mixing their scopes. You should - await act(async () => ...);"
|
|
829
|
+
));
|
|
830
|
+
});
|
|
831
|
+
return {
|
|
832
|
+
then: function(resolve, reject) {
|
|
833
|
+
didAwaitActCall = true;
|
|
834
|
+
thenable.then(
|
|
835
|
+
function(returnValue) {
|
|
836
|
+
popActScope(prevActQueue, prevActScopeDepth);
|
|
837
|
+
if (0 === prevActScopeDepth) {
|
|
838
|
+
try {
|
|
839
|
+
flushActQueue(queue), enqueueTask(function() {
|
|
840
|
+
return recursivelyFlushAsyncActWork(
|
|
841
|
+
returnValue,
|
|
842
|
+
resolve,
|
|
843
|
+
reject
|
|
844
|
+
);
|
|
845
|
+
});
|
|
846
|
+
} catch (error$0) {
|
|
847
|
+
ReactSharedInternals.thrownErrors.push(error$0);
|
|
848
|
+
}
|
|
849
|
+
if (0 < ReactSharedInternals.thrownErrors.length) {
|
|
850
|
+
var _thrownError = aggregateErrors(
|
|
851
|
+
ReactSharedInternals.thrownErrors
|
|
852
|
+
);
|
|
853
|
+
ReactSharedInternals.thrownErrors.length = 0;
|
|
854
|
+
reject(_thrownError);
|
|
855
|
+
}
|
|
856
|
+
} else resolve(returnValue);
|
|
857
|
+
},
|
|
858
|
+
function(error) {
|
|
859
|
+
popActScope(prevActQueue, prevActScopeDepth);
|
|
860
|
+
0 < ReactSharedInternals.thrownErrors.length ? (error = aggregateErrors(
|
|
861
|
+
ReactSharedInternals.thrownErrors
|
|
862
|
+
), ReactSharedInternals.thrownErrors.length = 0, reject(error)) : reject(error);
|
|
863
|
+
}
|
|
864
|
+
);
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
}
|
|
868
|
+
var returnValue$jscomp$0 = result;
|
|
869
|
+
popActScope(prevActQueue, prevActScopeDepth);
|
|
870
|
+
0 === prevActScopeDepth && (flushActQueue(queue), 0 !== queue.length && queueSeveralMicrotasks(function() {
|
|
871
|
+
didAwaitActCall || didWarnNoAwaitAct || (didWarnNoAwaitAct = true, console.error(
|
|
872
|
+
"A component suspended inside an `act` scope, but the `act` call was not awaited. When testing React components that depend on asynchronous data, you must await the result:\n\nawait act(() => ...)"
|
|
873
|
+
));
|
|
874
|
+
}), ReactSharedInternals.actQueue = null);
|
|
875
|
+
if (0 < ReactSharedInternals.thrownErrors.length)
|
|
876
|
+
throw callback = aggregateErrors(ReactSharedInternals.thrownErrors), ReactSharedInternals.thrownErrors.length = 0, callback;
|
|
877
|
+
return {
|
|
878
|
+
then: function(resolve, reject) {
|
|
879
|
+
didAwaitActCall = true;
|
|
880
|
+
0 === prevActScopeDepth ? (ReactSharedInternals.actQueue = queue, enqueueTask(function() {
|
|
881
|
+
return recursivelyFlushAsyncActWork(
|
|
882
|
+
returnValue$jscomp$0,
|
|
883
|
+
resolve,
|
|
884
|
+
reject
|
|
885
|
+
);
|
|
886
|
+
})) : resolve(returnValue$jscomp$0);
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
};
|
|
890
|
+
exports.cache = function(fn) {
|
|
891
|
+
return function() {
|
|
892
|
+
return fn.apply(null, arguments);
|
|
893
|
+
};
|
|
894
|
+
};
|
|
895
|
+
exports.cacheSignal = function() {
|
|
896
|
+
return null;
|
|
897
|
+
};
|
|
898
|
+
exports.captureOwnerStack = function() {
|
|
899
|
+
var getCurrentStack = ReactSharedInternals.getCurrentStack;
|
|
900
|
+
return null === getCurrentStack ? null : getCurrentStack();
|
|
901
|
+
};
|
|
902
|
+
exports.cloneElement = function(element, config, children) {
|
|
903
|
+
if (null === element || void 0 === element)
|
|
904
|
+
throw Error(
|
|
905
|
+
"The argument must be a React element, but you passed " + element + "."
|
|
906
|
+
);
|
|
907
|
+
var props = assign({}, element.props), key = element.key, owner = element._owner;
|
|
908
|
+
if (null != config) {
|
|
909
|
+
var JSCompiler_inline_result;
|
|
910
|
+
a: {
|
|
911
|
+
if (hasOwnProperty.call(config, "ref") && (JSCompiler_inline_result = Object.getOwnPropertyDescriptor(
|
|
912
|
+
config,
|
|
913
|
+
"ref"
|
|
914
|
+
).get) && JSCompiler_inline_result.isReactWarning) {
|
|
915
|
+
JSCompiler_inline_result = false;
|
|
916
|
+
break a;
|
|
917
|
+
}
|
|
918
|
+
JSCompiler_inline_result = void 0 !== config.ref;
|
|
919
|
+
}
|
|
920
|
+
JSCompiler_inline_result && (owner = getOwner());
|
|
921
|
+
hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key);
|
|
922
|
+
for (propName in config)
|
|
923
|
+
!hasOwnProperty.call(config, propName) || "key" === propName || "__self" === propName || "__source" === propName || "ref" === propName && void 0 === config.ref || (props[propName] = config[propName]);
|
|
924
|
+
}
|
|
925
|
+
var propName = arguments.length - 2;
|
|
926
|
+
if (1 === propName) props.children = children;
|
|
927
|
+
else if (1 < propName) {
|
|
928
|
+
JSCompiler_inline_result = Array(propName);
|
|
929
|
+
for (var i = 0; i < propName; i++)
|
|
930
|
+
JSCompiler_inline_result[i] = arguments[i + 2];
|
|
931
|
+
props.children = JSCompiler_inline_result;
|
|
932
|
+
}
|
|
933
|
+
props = ReactElement(
|
|
934
|
+
element.type,
|
|
935
|
+
key,
|
|
936
|
+
props,
|
|
937
|
+
owner,
|
|
938
|
+
element._debugStack,
|
|
939
|
+
element._debugTask
|
|
940
|
+
);
|
|
941
|
+
for (key = 2; key < arguments.length; key++)
|
|
942
|
+
validateChildKeys(arguments[key]);
|
|
943
|
+
return props;
|
|
944
|
+
};
|
|
945
|
+
exports.createContext = function(defaultValue) {
|
|
946
|
+
defaultValue = {
|
|
947
|
+
$$typeof: REACT_CONTEXT_TYPE,
|
|
948
|
+
_currentValue: defaultValue,
|
|
949
|
+
_currentValue2: defaultValue,
|
|
950
|
+
_threadCount: 0,
|
|
951
|
+
Provider: null,
|
|
952
|
+
Consumer: null
|
|
953
|
+
};
|
|
954
|
+
defaultValue.Provider = defaultValue;
|
|
955
|
+
defaultValue.Consumer = {
|
|
956
|
+
$$typeof: REACT_CONSUMER_TYPE,
|
|
957
|
+
_context: defaultValue
|
|
958
|
+
};
|
|
959
|
+
defaultValue._currentRenderer = null;
|
|
960
|
+
defaultValue._currentRenderer2 = null;
|
|
961
|
+
return defaultValue;
|
|
962
|
+
};
|
|
963
|
+
exports.createElement = function(type, config, children) {
|
|
964
|
+
for (var i = 2; i < arguments.length; i++)
|
|
965
|
+
validateChildKeys(arguments[i]);
|
|
966
|
+
i = {};
|
|
967
|
+
var key = null;
|
|
968
|
+
if (null != config)
|
|
969
|
+
for (propName in didWarnAboutOldJSXRuntime || !("__self" in config) || "key" in config || (didWarnAboutOldJSXRuntime = true, console.warn(
|
|
970
|
+
"Your app (or one of its dependencies) is using an outdated JSX transform. Update to the modern JSX transform for faster performance: https://react.dev/link/new-jsx-transform"
|
|
971
|
+
)), hasValidKey(config) && (checkKeyStringCoercion(config.key), key = "" + config.key), config)
|
|
972
|
+
hasOwnProperty.call(config, propName) && "key" !== propName && "__self" !== propName && "__source" !== propName && (i[propName] = config[propName]);
|
|
973
|
+
var childrenLength = arguments.length - 2;
|
|
974
|
+
if (1 === childrenLength) i.children = children;
|
|
975
|
+
else if (1 < childrenLength) {
|
|
976
|
+
for (var childArray = Array(childrenLength), _i = 0; _i < childrenLength; _i++)
|
|
977
|
+
childArray[_i] = arguments[_i + 2];
|
|
978
|
+
Object.freeze && Object.freeze(childArray);
|
|
979
|
+
i.children = childArray;
|
|
980
|
+
}
|
|
981
|
+
if (type && type.defaultProps)
|
|
982
|
+
for (propName in childrenLength = type.defaultProps, childrenLength)
|
|
983
|
+
void 0 === i[propName] && (i[propName] = childrenLength[propName]);
|
|
984
|
+
key && defineKeyPropWarningGetter(
|
|
985
|
+
i,
|
|
986
|
+
"function" === typeof type ? type.displayName || type.name || "Unknown" : type
|
|
987
|
+
);
|
|
988
|
+
var propName = 1e4 > ReactSharedInternals.recentlyCreatedOwnerStacks++;
|
|
989
|
+
return ReactElement(
|
|
990
|
+
type,
|
|
991
|
+
key,
|
|
992
|
+
i,
|
|
993
|
+
getOwner(),
|
|
994
|
+
propName ? Error("react-stack-top-frame") : unknownOwnerDebugStack,
|
|
995
|
+
propName ? createTask(getTaskName(type)) : unknownOwnerDebugTask
|
|
996
|
+
);
|
|
997
|
+
};
|
|
998
|
+
exports.createRef = function() {
|
|
999
|
+
var refObject = { current: null };
|
|
1000
|
+
Object.seal(refObject);
|
|
1001
|
+
return refObject;
|
|
1002
|
+
};
|
|
1003
|
+
exports.forwardRef = function(render) {
|
|
1004
|
+
null != render && render.$$typeof === REACT_MEMO_TYPE ? console.error(
|
|
1005
|
+
"forwardRef requires a render function but received a `memo` component. Instead of forwardRef(memo(...)), use memo(forwardRef(...))."
|
|
1006
|
+
) : "function" !== typeof render ? console.error(
|
|
1007
|
+
"forwardRef requires a render function but was given %s.",
|
|
1008
|
+
null === render ? "null" : typeof render
|
|
1009
|
+
) : 0 !== render.length && 2 !== render.length && console.error(
|
|
1010
|
+
"forwardRef render functions accept exactly two parameters: props and ref. %s",
|
|
1011
|
+
1 === render.length ? "Did you forget to use the ref parameter?" : "Any additional parameter will be undefined."
|
|
1012
|
+
);
|
|
1013
|
+
null != render && null != render.defaultProps && console.error(
|
|
1014
|
+
"forwardRef render functions do not support defaultProps. Did you accidentally pass a React component?"
|
|
1015
|
+
);
|
|
1016
|
+
var elementType = { $$typeof: REACT_FORWARD_REF_TYPE, render }, ownName;
|
|
1017
|
+
Object.defineProperty(elementType, "displayName", {
|
|
1018
|
+
enumerable: false,
|
|
1019
|
+
configurable: true,
|
|
1020
|
+
get: function() {
|
|
1021
|
+
return ownName;
|
|
1022
|
+
},
|
|
1023
|
+
set: function(name) {
|
|
1024
|
+
ownName = name;
|
|
1025
|
+
render.name || render.displayName || (Object.defineProperty(render, "name", { value: name }), render.displayName = name);
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
return elementType;
|
|
1029
|
+
};
|
|
1030
|
+
exports.isValidElement = isValidElement;
|
|
1031
|
+
exports.lazy = function(ctor) {
|
|
1032
|
+
ctor = { _status: -1, _result: ctor };
|
|
1033
|
+
var lazyType = {
|
|
1034
|
+
$$typeof: REACT_LAZY_TYPE,
|
|
1035
|
+
_payload: ctor,
|
|
1036
|
+
_init: lazyInitializer
|
|
1037
|
+
}, ioInfo = {
|
|
1038
|
+
name: "lazy",
|
|
1039
|
+
start: -1,
|
|
1040
|
+
end: -1,
|
|
1041
|
+
value: null,
|
|
1042
|
+
owner: null,
|
|
1043
|
+
debugStack: Error("react-stack-top-frame"),
|
|
1044
|
+
debugTask: console.createTask ? console.createTask("lazy()") : null
|
|
1045
|
+
};
|
|
1046
|
+
ctor._ioInfo = ioInfo;
|
|
1047
|
+
lazyType._debugInfo = [{ awaited: ioInfo }];
|
|
1048
|
+
return lazyType;
|
|
1049
|
+
};
|
|
1050
|
+
exports.memo = function(type, compare) {
|
|
1051
|
+
null == type && console.error(
|
|
1052
|
+
"memo: The first argument must be a component. Instead received: %s",
|
|
1053
|
+
null === type ? "null" : typeof type
|
|
1054
|
+
);
|
|
1055
|
+
compare = {
|
|
1056
|
+
$$typeof: REACT_MEMO_TYPE,
|
|
1057
|
+
type,
|
|
1058
|
+
compare: void 0 === compare ? null : compare
|
|
1059
|
+
};
|
|
1060
|
+
var ownName;
|
|
1061
|
+
Object.defineProperty(compare, "displayName", {
|
|
1062
|
+
enumerable: false,
|
|
1063
|
+
configurable: true,
|
|
1064
|
+
get: function() {
|
|
1065
|
+
return ownName;
|
|
1066
|
+
},
|
|
1067
|
+
set: function(name) {
|
|
1068
|
+
ownName = name;
|
|
1069
|
+
type.name || type.displayName || (Object.defineProperty(type, "name", { value: name }), type.displayName = name);
|
|
1070
|
+
}
|
|
1071
|
+
});
|
|
1072
|
+
return compare;
|
|
1073
|
+
};
|
|
1074
|
+
exports.startTransition = function(scope) {
|
|
1075
|
+
var prevTransition = ReactSharedInternals.T, currentTransition = {};
|
|
1076
|
+
currentTransition._updatedFibers = /* @__PURE__ */ new Set();
|
|
1077
|
+
ReactSharedInternals.T = currentTransition;
|
|
1078
|
+
try {
|
|
1079
|
+
var returnValue = scope(), onStartTransitionFinish = ReactSharedInternals.S;
|
|
1080
|
+
null !== onStartTransitionFinish && onStartTransitionFinish(currentTransition, returnValue);
|
|
1081
|
+
"object" === typeof returnValue && null !== returnValue && "function" === typeof returnValue.then && (ReactSharedInternals.asyncTransitions++, returnValue.then(releaseAsyncTransition, releaseAsyncTransition), returnValue.then(noop, reportGlobalError));
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
reportGlobalError(error);
|
|
1084
|
+
} finally {
|
|
1085
|
+
null === prevTransition && currentTransition._updatedFibers && (scope = currentTransition._updatedFibers.size, currentTransition._updatedFibers.clear(), 10 < scope && console.warn(
|
|
1086
|
+
"Detected a large number of updates inside startTransition. If this is due to a subscription please re-write it to use React provided hooks. Otherwise concurrent mode guarantees are off the table."
|
|
1087
|
+
)), null !== prevTransition && null !== currentTransition.types && (null !== prevTransition.types && prevTransition.types !== currentTransition.types && console.error(
|
|
1088
|
+
"We expected inner Transitions to have transferred the outer types set and that you cannot add to the outer Transition while inside the inner.This is a bug in React."
|
|
1089
|
+
), prevTransition.types = currentTransition.types), ReactSharedInternals.T = prevTransition;
|
|
1090
|
+
}
|
|
1091
|
+
};
|
|
1092
|
+
exports.unstable_useCacheRefresh = function() {
|
|
1093
|
+
return resolveDispatcher().useCacheRefresh();
|
|
1094
|
+
};
|
|
1095
|
+
exports.use = function(usable) {
|
|
1096
|
+
return resolveDispatcher().use(usable);
|
|
1097
|
+
};
|
|
1098
|
+
exports.useActionState = function(action, initialState, permalink) {
|
|
1099
|
+
return resolveDispatcher().useActionState(
|
|
1100
|
+
action,
|
|
1101
|
+
initialState,
|
|
1102
|
+
permalink
|
|
1103
|
+
);
|
|
1104
|
+
};
|
|
1105
|
+
exports.useCallback = function(callback, deps) {
|
|
1106
|
+
return resolveDispatcher().useCallback(callback, deps);
|
|
1107
|
+
};
|
|
1108
|
+
exports.useContext = function(Context) {
|
|
1109
|
+
var dispatcher = resolveDispatcher();
|
|
1110
|
+
Context.$$typeof === REACT_CONSUMER_TYPE && console.error(
|
|
1111
|
+
"Calling useContext(Context.Consumer) is not supported and will cause bugs. Did you mean to call useContext(Context) instead?"
|
|
1112
|
+
);
|
|
1113
|
+
return dispatcher.useContext(Context);
|
|
1114
|
+
};
|
|
1115
|
+
exports.useDebugValue = function(value, formatterFn) {
|
|
1116
|
+
return resolveDispatcher().useDebugValue(value, formatterFn);
|
|
1117
|
+
};
|
|
1118
|
+
exports.useDeferredValue = function(value, initialValue) {
|
|
1119
|
+
return resolveDispatcher().useDeferredValue(value, initialValue);
|
|
1120
|
+
};
|
|
1121
|
+
exports.useEffect = function(create2, deps) {
|
|
1122
|
+
null == create2 && console.warn(
|
|
1123
|
+
"React Hook useEffect requires an effect callback. Did you forget to pass a callback to the hook?"
|
|
1124
|
+
);
|
|
1125
|
+
return resolveDispatcher().useEffect(create2, deps);
|
|
1126
|
+
};
|
|
1127
|
+
exports.useEffectEvent = function(callback) {
|
|
1128
|
+
return resolveDispatcher().useEffectEvent(callback);
|
|
1129
|
+
};
|
|
1130
|
+
exports.useId = function() {
|
|
1131
|
+
return resolveDispatcher().useId();
|
|
1132
|
+
};
|
|
1133
|
+
exports.useImperativeHandle = function(ref, create2, deps) {
|
|
1134
|
+
return resolveDispatcher().useImperativeHandle(ref, create2, deps);
|
|
1135
|
+
};
|
|
1136
|
+
exports.useInsertionEffect = function(create2, deps) {
|
|
1137
|
+
null == create2 && console.warn(
|
|
1138
|
+
"React Hook useInsertionEffect requires an effect callback. Did you forget to pass a callback to the hook?"
|
|
1139
|
+
);
|
|
1140
|
+
return resolveDispatcher().useInsertionEffect(create2, deps);
|
|
1141
|
+
};
|
|
1142
|
+
exports.useLayoutEffect = function(create2, deps) {
|
|
1143
|
+
null == create2 && console.warn(
|
|
1144
|
+
"React Hook useLayoutEffect requires an effect callback. Did you forget to pass a callback to the hook?"
|
|
1145
|
+
);
|
|
1146
|
+
return resolveDispatcher().useLayoutEffect(create2, deps);
|
|
1147
|
+
};
|
|
1148
|
+
exports.useMemo = function(create2, deps) {
|
|
1149
|
+
return resolveDispatcher().useMemo(create2, deps);
|
|
1150
|
+
};
|
|
1151
|
+
exports.useOptimistic = function(passthrough, reducer) {
|
|
1152
|
+
return resolveDispatcher().useOptimistic(passthrough, reducer);
|
|
1153
|
+
};
|
|
1154
|
+
exports.useReducer = function(reducer, initialArg, init) {
|
|
1155
|
+
return resolveDispatcher().useReducer(reducer, initialArg, init);
|
|
1156
|
+
};
|
|
1157
|
+
exports.useRef = function(initialValue) {
|
|
1158
|
+
return resolveDispatcher().useRef(initialValue);
|
|
1159
|
+
};
|
|
1160
|
+
exports.useState = function(initialState) {
|
|
1161
|
+
return resolveDispatcher().useState(initialState);
|
|
1162
|
+
};
|
|
1163
|
+
exports.useSyncExternalStore = function(subscribe, getSnapshot, getServerSnapshot) {
|
|
1164
|
+
return resolveDispatcher().useSyncExternalStore(
|
|
1165
|
+
subscribe,
|
|
1166
|
+
getSnapshot,
|
|
1167
|
+
getServerSnapshot
|
|
1168
|
+
);
|
|
1169
|
+
};
|
|
1170
|
+
exports.useTransition = function() {
|
|
1171
|
+
return resolveDispatcher().useTransition();
|
|
1172
|
+
};
|
|
1173
|
+
exports.version = "19.2.5";
|
|
1174
|
+
"undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ && "function" === typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
1175
|
+
})();
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
|
|
1179
|
+
// node_modules/react/index.js
|
|
1180
|
+
var require_react = __commonJS({
|
|
1181
|
+
"node_modules/react/index.js"(exports, module) {
|
|
1182
|
+
"use strict";
|
|
1183
|
+
if (false) {
|
|
1184
|
+
module.exports = null;
|
|
1185
|
+
} else {
|
|
1186
|
+
module.exports = require_react_development();
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
});
|
|
1190
|
+
|
|
1191
|
+
// node_modules/eventemitter3/index.mjs
|
|
1192
|
+
var import_index = __toESM(require_eventemitter3(), 1);
|
|
1193
|
+
|
|
1194
|
+
// node_modules/p-timeout/index.js
|
|
1195
|
+
var TimeoutError = class _TimeoutError extends Error {
|
|
1196
|
+
constructor(message, options) {
|
|
1197
|
+
super(message, options);
|
|
1198
|
+
__publicField(this, "name", "TimeoutError");
|
|
1199
|
+
Error.captureStackTrace?.(this, _TimeoutError);
|
|
1200
|
+
}
|
|
1201
|
+
};
|
|
1202
|
+
var getAbortedReason = (signal) => signal.reason ?? new DOMException("This operation was aborted.", "AbortError");
|
|
1203
|
+
function pTimeout(promise, options) {
|
|
1204
|
+
const {
|
|
1205
|
+
milliseconds,
|
|
1206
|
+
fallback,
|
|
1207
|
+
message,
|
|
1208
|
+
customTimers = { setTimeout, clearTimeout },
|
|
1209
|
+
signal
|
|
1210
|
+
} = options;
|
|
1211
|
+
let timer;
|
|
1212
|
+
let abortHandler;
|
|
1213
|
+
const wrappedPromise = new Promise((resolve, reject) => {
|
|
1214
|
+
if (typeof milliseconds !== "number" || Math.sign(milliseconds) !== 1) {
|
|
1215
|
+
throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${milliseconds}\``);
|
|
1216
|
+
}
|
|
1217
|
+
if (signal?.aborted) {
|
|
1218
|
+
reject(getAbortedReason(signal));
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
if (signal) {
|
|
1222
|
+
abortHandler = () => {
|
|
1223
|
+
reject(getAbortedReason(signal));
|
|
1224
|
+
};
|
|
1225
|
+
signal.addEventListener("abort", abortHandler, { once: true });
|
|
1226
|
+
}
|
|
1227
|
+
promise.then(resolve, reject);
|
|
1228
|
+
if (milliseconds === Number.POSITIVE_INFINITY) {
|
|
1229
|
+
return;
|
|
1230
|
+
}
|
|
1231
|
+
const timeoutError = new TimeoutError();
|
|
1232
|
+
timer = customTimers.setTimeout.call(void 0, () => {
|
|
1233
|
+
if (fallback) {
|
|
1234
|
+
try {
|
|
1235
|
+
resolve(fallback());
|
|
1236
|
+
} catch (error) {
|
|
1237
|
+
reject(error);
|
|
1238
|
+
}
|
|
1239
|
+
return;
|
|
1240
|
+
}
|
|
1241
|
+
if (typeof promise.cancel === "function") {
|
|
1242
|
+
promise.cancel();
|
|
1243
|
+
}
|
|
1244
|
+
if (message === false) {
|
|
1245
|
+
resolve();
|
|
1246
|
+
} else if (message instanceof Error) {
|
|
1247
|
+
reject(message);
|
|
1248
|
+
} else {
|
|
1249
|
+
timeoutError.message = message ?? `Promise timed out after ${milliseconds} milliseconds`;
|
|
1250
|
+
reject(timeoutError);
|
|
1251
|
+
}
|
|
1252
|
+
}, milliseconds);
|
|
1253
|
+
});
|
|
1254
|
+
const cancelablePromise = wrappedPromise.finally(() => {
|
|
1255
|
+
cancelablePromise.clear();
|
|
1256
|
+
if (abortHandler && signal) {
|
|
1257
|
+
signal.removeEventListener("abort", abortHandler);
|
|
1258
|
+
}
|
|
1259
|
+
});
|
|
1260
|
+
cancelablePromise.clear = () => {
|
|
1261
|
+
customTimers.clearTimeout.call(void 0, timer);
|
|
1262
|
+
timer = void 0;
|
|
1263
|
+
};
|
|
1264
|
+
return cancelablePromise;
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
// node_modules/p-queue/dist/lower-bound.js
|
|
1268
|
+
function lowerBound(array, value, comparator) {
|
|
1269
|
+
let first = 0;
|
|
1270
|
+
let count = array.length;
|
|
1271
|
+
while (count > 0) {
|
|
1272
|
+
const step = Math.trunc(count / 2);
|
|
1273
|
+
let it = first + step;
|
|
1274
|
+
if (comparator(array[it], value) <= 0) {
|
|
1275
|
+
first = ++it;
|
|
1276
|
+
count -= step + 1;
|
|
1277
|
+
} else {
|
|
1278
|
+
count = step;
|
|
1279
|
+
}
|
|
1280
|
+
}
|
|
1281
|
+
return first;
|
|
1282
|
+
}
|
|
1283
|
+
|
|
1284
|
+
// node_modules/p-queue/dist/priority-queue.js
|
|
1285
|
+
var _queue;
|
|
1286
|
+
var PriorityQueue = class {
|
|
1287
|
+
constructor() {
|
|
1288
|
+
__privateAdd(this, _queue, []);
|
|
1289
|
+
}
|
|
1290
|
+
enqueue(run, options) {
|
|
1291
|
+
const { priority = 0, id } = options ?? {};
|
|
1292
|
+
const element = {
|
|
1293
|
+
priority,
|
|
1294
|
+
id,
|
|
1295
|
+
run
|
|
1296
|
+
};
|
|
1297
|
+
if (this.size === 0 || __privateGet(this, _queue)[this.size - 1].priority >= priority) {
|
|
1298
|
+
__privateGet(this, _queue).push(element);
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
const index = lowerBound(__privateGet(this, _queue), element, (a, b) => b.priority - a.priority);
|
|
1302
|
+
__privateGet(this, _queue).splice(index, 0, element);
|
|
1303
|
+
}
|
|
1304
|
+
setPriority(id, priority) {
|
|
1305
|
+
const index = __privateGet(this, _queue).findIndex((element) => element.id === id);
|
|
1306
|
+
if (index === -1) {
|
|
1307
|
+
throw new ReferenceError(`No promise function with the id "${id}" exists in the queue.`);
|
|
1308
|
+
}
|
|
1309
|
+
const [item] = __privateGet(this, _queue).splice(index, 1);
|
|
1310
|
+
this.enqueue(item.run, { priority, id });
|
|
1311
|
+
}
|
|
1312
|
+
remove(idOrRun) {
|
|
1313
|
+
const index = __privateGet(this, _queue).findIndex((element) => {
|
|
1314
|
+
if (typeof idOrRun === "string") {
|
|
1315
|
+
return element.id === idOrRun;
|
|
1316
|
+
}
|
|
1317
|
+
return element.run === idOrRun;
|
|
1318
|
+
});
|
|
1319
|
+
if (index !== -1) {
|
|
1320
|
+
__privateGet(this, _queue).splice(index, 1);
|
|
1321
|
+
}
|
|
1322
|
+
}
|
|
1323
|
+
dequeue() {
|
|
1324
|
+
const item = __privateGet(this, _queue).shift();
|
|
1325
|
+
return item?.run;
|
|
1326
|
+
}
|
|
1327
|
+
filter(options) {
|
|
1328
|
+
return __privateGet(this, _queue).filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
1329
|
+
}
|
|
1330
|
+
get size() {
|
|
1331
|
+
return __privateGet(this, _queue).length;
|
|
1332
|
+
}
|
|
1333
|
+
};
|
|
1334
|
+
_queue = new WeakMap();
|
|
1335
|
+
|
|
1336
|
+
// node_modules/p-queue/dist/index.js
|
|
1337
|
+
var _carryoverIntervalCount, _isIntervalIgnored, _intervalCount, _intervalCap, _rateLimitedInInterval, _rateLimitFlushScheduled, _interval, _intervalEnd, _lastExecutionTime, _intervalId, _timeoutId, _strict, _strictTicks, _strictTicksStartIndex, _queue2, _queueClass, _pending, _concurrency, _isPaused, _idAssigner, _runningTasks, _queueAbortListenerCleanupFunctions, _PQueue_instances, cleanupStrictTicks_fn, consumeIntervalSlot_fn, rollbackIntervalSlot_fn, getActiveTicksCount_fn, doesIntervalAllowAnother_get, doesConcurrentAllowAnother_get, next_fn, onResumeInterval_fn, isIntervalPausedAt_fn, createIntervalTimeout_fn, clearIntervalTimer_fn, clearTimeoutTimer_fn, tryToStartAnother_fn, initializeIntervalIfNeeded_fn, onInterval_fn, processQueue_fn, onEvent_fn, setupRateLimitTracking_fn, scheduleRateLimitUpdate_fn, rollbackIntervalConsumption_fn, updateRateLimitState_fn;
|
|
1338
|
+
var PQueue = class extends import_index.default {
|
|
1339
|
+
constructor(options) {
|
|
1340
|
+
super();
|
|
1341
|
+
__privateAdd(this, _PQueue_instances);
|
|
1342
|
+
__privateAdd(this, _carryoverIntervalCount);
|
|
1343
|
+
__privateAdd(this, _isIntervalIgnored);
|
|
1344
|
+
__privateAdd(this, _intervalCount, 0);
|
|
1345
|
+
__privateAdd(this, _intervalCap);
|
|
1346
|
+
__privateAdd(this, _rateLimitedInInterval, false);
|
|
1347
|
+
__privateAdd(this, _rateLimitFlushScheduled, false);
|
|
1348
|
+
__privateAdd(this, _interval);
|
|
1349
|
+
__privateAdd(this, _intervalEnd, 0);
|
|
1350
|
+
__privateAdd(this, _lastExecutionTime, 0);
|
|
1351
|
+
__privateAdd(this, _intervalId);
|
|
1352
|
+
__privateAdd(this, _timeoutId);
|
|
1353
|
+
__privateAdd(this, _strict);
|
|
1354
|
+
// Circular buffer implementation for better performance
|
|
1355
|
+
__privateAdd(this, _strictTicks, []);
|
|
1356
|
+
__privateAdd(this, _strictTicksStartIndex, 0);
|
|
1357
|
+
__privateAdd(this, _queue2);
|
|
1358
|
+
__privateAdd(this, _queueClass);
|
|
1359
|
+
__privateAdd(this, _pending, 0);
|
|
1360
|
+
// The `!` is needed because of https://github.com/microsoft/TypeScript/issues/32194
|
|
1361
|
+
__privateAdd(this, _concurrency);
|
|
1362
|
+
__privateAdd(this, _isPaused);
|
|
1363
|
+
// Use to assign a unique identifier to a promise function, if not explicitly specified
|
|
1364
|
+
__privateAdd(this, _idAssigner, 1n);
|
|
1365
|
+
// Track currently running tasks for debugging
|
|
1366
|
+
__privateAdd(this, _runningTasks, /* @__PURE__ */ new Map());
|
|
1367
|
+
__privateAdd(this, _queueAbortListenerCleanupFunctions, /* @__PURE__ */ new Set());
|
|
1368
|
+
/**
|
|
1369
|
+
Get or set the default timeout for all tasks. Can be changed at runtime.
|
|
1370
|
+
|
|
1371
|
+
Operations will throw a `TimeoutError` if they don't complete within the specified time.
|
|
1372
|
+
|
|
1373
|
+
The timeout begins when the operation is dequeued and starts execution, not while it's waiting in the queue.
|
|
1374
|
+
|
|
1375
|
+
@example
|
|
1376
|
+
```
|
|
1377
|
+
const queue = new PQueue({timeout: 5000});
|
|
1378
|
+
|
|
1379
|
+
// Change timeout for all future tasks
|
|
1380
|
+
queue.timeout = 10000;
|
|
1381
|
+
```
|
|
1382
|
+
*/
|
|
1383
|
+
__publicField(this, "timeout");
|
|
1384
|
+
options = {
|
|
1385
|
+
carryoverIntervalCount: false,
|
|
1386
|
+
intervalCap: Number.POSITIVE_INFINITY,
|
|
1387
|
+
interval: 0,
|
|
1388
|
+
concurrency: Number.POSITIVE_INFINITY,
|
|
1389
|
+
autoStart: true,
|
|
1390
|
+
queueClass: PriorityQueue,
|
|
1391
|
+
strict: false,
|
|
1392
|
+
...options
|
|
1393
|
+
};
|
|
1394
|
+
if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
|
|
1395
|
+
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${options.intervalCap?.toString() ?? ""}\` (${typeof options.intervalCap})`);
|
|
1396
|
+
}
|
|
1397
|
+
if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) {
|
|
1398
|
+
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${options.interval?.toString() ?? ""}\` (${typeof options.interval})`);
|
|
1399
|
+
}
|
|
1400
|
+
if (options.strict && options.interval === 0) {
|
|
1401
|
+
throw new TypeError("The `strict` option requires a non-zero `interval`");
|
|
1402
|
+
}
|
|
1403
|
+
if (options.strict && options.intervalCap === Number.POSITIVE_INFINITY) {
|
|
1404
|
+
throw new TypeError("The `strict` option requires a finite `intervalCap`");
|
|
1405
|
+
}
|
|
1406
|
+
__privateSet(this, _carryoverIntervalCount, options.carryoverIntervalCount ?? options.carryoverConcurrencyCount ?? false);
|
|
1407
|
+
__privateSet(this, _isIntervalIgnored, options.intervalCap === Number.POSITIVE_INFINITY || options.interval === 0);
|
|
1408
|
+
__privateSet(this, _intervalCap, options.intervalCap);
|
|
1409
|
+
__privateSet(this, _interval, options.interval);
|
|
1410
|
+
__privateSet(this, _strict, options.strict);
|
|
1411
|
+
__privateSet(this, _queue2, new options.queueClass());
|
|
1412
|
+
__privateSet(this, _queueClass, options.queueClass);
|
|
1413
|
+
this.concurrency = options.concurrency;
|
|
1414
|
+
if (options.timeout !== void 0 && !(Number.isFinite(options.timeout) && options.timeout > 0)) {
|
|
1415
|
+
throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${options.timeout}\` (${typeof options.timeout})`);
|
|
1416
|
+
}
|
|
1417
|
+
this.timeout = options.timeout;
|
|
1418
|
+
__privateSet(this, _isPaused, options.autoStart === false);
|
|
1419
|
+
__privateMethod(this, _PQueue_instances, setupRateLimitTracking_fn).call(this);
|
|
1420
|
+
}
|
|
1421
|
+
get concurrency() {
|
|
1422
|
+
return __privateGet(this, _concurrency);
|
|
1423
|
+
}
|
|
1424
|
+
set concurrency(newConcurrency) {
|
|
1425
|
+
if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) {
|
|
1426
|
+
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
|
|
1427
|
+
}
|
|
1428
|
+
__privateSet(this, _concurrency, newConcurrency);
|
|
1429
|
+
__privateMethod(this, _PQueue_instances, processQueue_fn).call(this);
|
|
1430
|
+
}
|
|
1431
|
+
/**
|
|
1432
|
+
Updates the priority of a promise function by its id, affecting its execution order. Requires a defined concurrency limit to take effect.
|
|
1433
|
+
|
|
1434
|
+
For example, this can be used to prioritize a promise function to run earlier.
|
|
1435
|
+
|
|
1436
|
+
```js
|
|
1437
|
+
import PQueue from 'p-queue';
|
|
1438
|
+
|
|
1439
|
+
const queue = new PQueue({concurrency: 1});
|
|
1440
|
+
|
|
1441
|
+
queue.add(async () => '🦄', {priority: 1});
|
|
1442
|
+
queue.add(async () => '🦀', {priority: 0, id: '🦀'});
|
|
1443
|
+
queue.add(async () => '🦄', {priority: 1});
|
|
1444
|
+
queue.add(async () => '🦄', {priority: 1});
|
|
1445
|
+
|
|
1446
|
+
queue.setPriority('🦀', 2);
|
|
1447
|
+
```
|
|
1448
|
+
|
|
1449
|
+
In this case, the promise function with `id: '🦀'` runs second.
|
|
1450
|
+
|
|
1451
|
+
You can also deprioritize a promise function to delay its execution:
|
|
1452
|
+
|
|
1453
|
+
```js
|
|
1454
|
+
import PQueue from 'p-queue';
|
|
1455
|
+
|
|
1456
|
+
const queue = new PQueue({concurrency: 1});
|
|
1457
|
+
|
|
1458
|
+
queue.add(async () => '🦄', {priority: 1});
|
|
1459
|
+
queue.add(async () => '🦀', {priority: 1, id: '🦀'});
|
|
1460
|
+
queue.add(async () => '🦄');
|
|
1461
|
+
queue.add(async () => '🦄', {priority: 0});
|
|
1462
|
+
|
|
1463
|
+
queue.setPriority('🦀', -1);
|
|
1464
|
+
```
|
|
1465
|
+
Here, the promise function with `id: '🦀'` executes last.
|
|
1466
|
+
*/
|
|
1467
|
+
setPriority(id, priority) {
|
|
1468
|
+
if (typeof priority !== "number" || !Number.isFinite(priority)) {
|
|
1469
|
+
throw new TypeError(`Expected \`priority\` to be a finite number, got \`${priority}\` (${typeof priority})`);
|
|
1470
|
+
}
|
|
1471
|
+
__privateGet(this, _queue2).setPriority(id, priority);
|
|
1472
|
+
}
|
|
1473
|
+
async add(function_, options = {}) {
|
|
1474
|
+
options = {
|
|
1475
|
+
timeout: this.timeout,
|
|
1476
|
+
...options,
|
|
1477
|
+
// Assign unique ID if not provided
|
|
1478
|
+
id: options.id ?? (__privateWrapper(this, _idAssigner)._++).toString()
|
|
1479
|
+
};
|
|
1480
|
+
return new Promise((resolve, reject) => {
|
|
1481
|
+
const taskSymbol = /* @__PURE__ */ Symbol(`task-${options.id}`);
|
|
1482
|
+
let cleanupQueueAbortHandler = () => void 0;
|
|
1483
|
+
const run = async () => {
|
|
1484
|
+
cleanupQueueAbortHandler();
|
|
1485
|
+
__privateWrapper(this, _pending)._++;
|
|
1486
|
+
__privateGet(this, _runningTasks).set(taskSymbol, {
|
|
1487
|
+
id: options.id,
|
|
1488
|
+
priority: options.priority ?? 0,
|
|
1489
|
+
// Match priority-queue default
|
|
1490
|
+
startTime: Date.now(),
|
|
1491
|
+
timeout: options.timeout
|
|
1492
|
+
});
|
|
1493
|
+
let eventListener;
|
|
1494
|
+
try {
|
|
1495
|
+
try {
|
|
1496
|
+
options.signal?.throwIfAborted();
|
|
1497
|
+
} catch (error) {
|
|
1498
|
+
__privateMethod(this, _PQueue_instances, rollbackIntervalConsumption_fn).call(this);
|
|
1499
|
+
__privateGet(this, _runningTasks).delete(taskSymbol);
|
|
1500
|
+
throw error;
|
|
1501
|
+
}
|
|
1502
|
+
__privateSet(this, _lastExecutionTime, Date.now());
|
|
1503
|
+
let operation = function_({ signal: options.signal });
|
|
1504
|
+
if (options.timeout) {
|
|
1505
|
+
operation = pTimeout(Promise.resolve(operation), {
|
|
1506
|
+
milliseconds: options.timeout,
|
|
1507
|
+
message: `Task timed out after ${options.timeout}ms (queue has ${__privateGet(this, _pending)} running, ${__privateGet(this, _queue2).size} waiting)`
|
|
1508
|
+
});
|
|
1509
|
+
}
|
|
1510
|
+
if (options.signal) {
|
|
1511
|
+
const { signal } = options;
|
|
1512
|
+
operation = Promise.race([operation, new Promise((_resolve, reject2) => {
|
|
1513
|
+
eventListener = () => {
|
|
1514
|
+
reject2(signal.reason);
|
|
1515
|
+
};
|
|
1516
|
+
signal.addEventListener("abort", eventListener, { once: true });
|
|
1517
|
+
})]);
|
|
1518
|
+
}
|
|
1519
|
+
const result = await operation;
|
|
1520
|
+
resolve(result);
|
|
1521
|
+
this.emit("completed", result);
|
|
1522
|
+
} catch (error) {
|
|
1523
|
+
reject(error);
|
|
1524
|
+
this.emit("error", error);
|
|
1525
|
+
} finally {
|
|
1526
|
+
if (eventListener) {
|
|
1527
|
+
options.signal?.removeEventListener("abort", eventListener);
|
|
1528
|
+
}
|
|
1529
|
+
__privateGet(this, _runningTasks).delete(taskSymbol);
|
|
1530
|
+
queueMicrotask(() => {
|
|
1531
|
+
__privateMethod(this, _PQueue_instances, next_fn).call(this);
|
|
1532
|
+
});
|
|
1533
|
+
}
|
|
1534
|
+
};
|
|
1535
|
+
__privateGet(this, _queue2).enqueue(run, options);
|
|
1536
|
+
const removeQueuedTask = () => {
|
|
1537
|
+
if (__privateGet(this, _queue2) instanceof PriorityQueue) {
|
|
1538
|
+
__privateGet(this, _queue2).remove(run);
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
__privateGet(this, _queue2).remove?.(options.id);
|
|
1542
|
+
};
|
|
1543
|
+
if (options.signal) {
|
|
1544
|
+
const { signal } = options;
|
|
1545
|
+
const queueAbortHandler = () => {
|
|
1546
|
+
cleanupQueueAbortHandler();
|
|
1547
|
+
removeQueuedTask();
|
|
1548
|
+
reject(signal.reason);
|
|
1549
|
+
__privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this);
|
|
1550
|
+
this.emit("next");
|
|
1551
|
+
};
|
|
1552
|
+
cleanupQueueAbortHandler = () => {
|
|
1553
|
+
signal.removeEventListener("abort", queueAbortHandler);
|
|
1554
|
+
__privateGet(this, _queueAbortListenerCleanupFunctions).delete(cleanupQueueAbortHandler);
|
|
1555
|
+
};
|
|
1556
|
+
if (signal.aborted) {
|
|
1557
|
+
queueAbortHandler();
|
|
1558
|
+
return;
|
|
1559
|
+
}
|
|
1560
|
+
signal.addEventListener("abort", queueAbortHandler, { once: true });
|
|
1561
|
+
__privateGet(this, _queueAbortListenerCleanupFunctions).add(cleanupQueueAbortHandler);
|
|
1562
|
+
}
|
|
1563
|
+
this.emit("add");
|
|
1564
|
+
__privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this);
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
async addAll(functions, options) {
|
|
1568
|
+
return Promise.all(functions.map(async (function_) => this.add(function_, options)));
|
|
1569
|
+
}
|
|
1570
|
+
/**
|
|
1571
|
+
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.)
|
|
1572
|
+
*/
|
|
1573
|
+
start() {
|
|
1574
|
+
if (!__privateGet(this, _isPaused)) {
|
|
1575
|
+
return this;
|
|
1576
|
+
}
|
|
1577
|
+
__privateSet(this, _isPaused, false);
|
|
1578
|
+
__privateMethod(this, _PQueue_instances, processQueue_fn).call(this);
|
|
1579
|
+
return this;
|
|
1580
|
+
}
|
|
1581
|
+
/**
|
|
1582
|
+
Put queue execution on hold.
|
|
1583
|
+
*/
|
|
1584
|
+
pause() {
|
|
1585
|
+
__privateSet(this, _isPaused, true);
|
|
1586
|
+
}
|
|
1587
|
+
/**
|
|
1588
|
+
Clear the queue.
|
|
1589
|
+
*/
|
|
1590
|
+
clear() {
|
|
1591
|
+
for (const cleanupQueueAbortHandler of __privateGet(this, _queueAbortListenerCleanupFunctions)) {
|
|
1592
|
+
cleanupQueueAbortHandler();
|
|
1593
|
+
}
|
|
1594
|
+
__privateSet(this, _queue2, new (__privateGet(this, _queueClass))());
|
|
1595
|
+
__privateMethod(this, _PQueue_instances, clearIntervalTimer_fn).call(this);
|
|
1596
|
+
__privateMethod(this, _PQueue_instances, updateRateLimitState_fn).call(this);
|
|
1597
|
+
this.emit("empty");
|
|
1598
|
+
if (__privateGet(this, _pending) === 0) {
|
|
1599
|
+
__privateMethod(this, _PQueue_instances, clearTimeoutTimer_fn).call(this);
|
|
1600
|
+
this.emit("idle");
|
|
1601
|
+
}
|
|
1602
|
+
this.emit("next");
|
|
1603
|
+
}
|
|
1604
|
+
/**
|
|
1605
|
+
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
1606
|
+
|
|
1607
|
+
@returns A promise that settles when the queue becomes empty.
|
|
1608
|
+
*/
|
|
1609
|
+
async onEmpty() {
|
|
1610
|
+
if (__privateGet(this, _queue2).size === 0) {
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1613
|
+
await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "empty");
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
@returns A promise that settles when the queue size is less than the given limit: `queue.size < limit`.
|
|
1617
|
+
|
|
1618
|
+
If you want to avoid having the queue grow beyond a certain size you can `await queue.onSizeLessThan()` before adding a new item.
|
|
1619
|
+
|
|
1620
|
+
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.
|
|
1621
|
+
*/
|
|
1622
|
+
async onSizeLessThan(limit) {
|
|
1623
|
+
if (__privateGet(this, _queue2).size < limit) {
|
|
1624
|
+
return;
|
|
1625
|
+
}
|
|
1626
|
+
await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "next", () => __privateGet(this, _queue2).size < limit);
|
|
1627
|
+
}
|
|
1628
|
+
/**
|
|
1629
|
+
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.
|
|
1630
|
+
|
|
1631
|
+
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
|
|
1632
|
+
*/
|
|
1633
|
+
async onIdle() {
|
|
1634
|
+
if (__privateGet(this, _pending) === 0 && __privateGet(this, _queue2).size === 0) {
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "idle");
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
The difference with `.onIdle` is that `.onPendingZero` only waits for currently running tasks to finish, ignoring queued tasks.
|
|
1641
|
+
|
|
1642
|
+
@returns A promise that settles when all currently running tasks have completed; `queue.pending === 0`.
|
|
1643
|
+
*/
|
|
1644
|
+
async onPendingZero() {
|
|
1645
|
+
if (__privateGet(this, _pending) === 0) {
|
|
1646
|
+
return;
|
|
1647
|
+
}
|
|
1648
|
+
await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "pendingZero");
|
|
1649
|
+
}
|
|
1650
|
+
/**
|
|
1651
|
+
@returns A promise that settles when the queue becomes rate-limited due to intervalCap.
|
|
1652
|
+
*/
|
|
1653
|
+
async onRateLimit() {
|
|
1654
|
+
if (this.isRateLimited) {
|
|
1655
|
+
return;
|
|
1656
|
+
}
|
|
1657
|
+
await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "rateLimit");
|
|
1658
|
+
}
|
|
1659
|
+
/**
|
|
1660
|
+
@returns A promise that settles when the queue is no longer rate-limited.
|
|
1661
|
+
*/
|
|
1662
|
+
async onRateLimitCleared() {
|
|
1663
|
+
if (!this.isRateLimited) {
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
await __privateMethod(this, _PQueue_instances, onEvent_fn).call(this, "rateLimitCleared");
|
|
1667
|
+
}
|
|
1668
|
+
/**
|
|
1669
|
+
@returns A promise that rejects when any task in the queue errors.
|
|
1670
|
+
|
|
1671
|
+
Use with `Promise.race([queue.onError(), queue.onIdle()])` to fail fast on the first error while still resolving normally when the queue goes idle.
|
|
1672
|
+
|
|
1673
|
+
Important: The promise returned by `add()` still rejects. You must handle each `add()` promise (for example, `.catch(() => {})`) to avoid unhandled rejections.
|
|
1674
|
+
|
|
1675
|
+
@example
|
|
1676
|
+
```
|
|
1677
|
+
import PQueue from 'p-queue';
|
|
1678
|
+
|
|
1679
|
+
const queue = new PQueue({concurrency: 2});
|
|
1680
|
+
|
|
1681
|
+
queue.add(() => fetchData(1)).catch(() => {});
|
|
1682
|
+
queue.add(() => fetchData(2)).catch(() => {});
|
|
1683
|
+
queue.add(() => fetchData(3)).catch(() => {});
|
|
1684
|
+
|
|
1685
|
+
// Stop processing on first error
|
|
1686
|
+
try {
|
|
1687
|
+
await Promise.race([
|
|
1688
|
+
queue.onError(),
|
|
1689
|
+
queue.onIdle()
|
|
1690
|
+
]);
|
|
1691
|
+
} catch (error) {
|
|
1692
|
+
queue.pause(); // Stop processing remaining tasks
|
|
1693
|
+
console.error('Queue failed:', error);
|
|
1694
|
+
}
|
|
1695
|
+
```
|
|
1696
|
+
*/
|
|
1697
|
+
// eslint-disable-next-line @typescript-eslint/promise-function-async
|
|
1698
|
+
onError() {
|
|
1699
|
+
return new Promise((_resolve, reject) => {
|
|
1700
|
+
const handleError = (error) => {
|
|
1701
|
+
this.off("error", handleError);
|
|
1702
|
+
reject(error);
|
|
1703
|
+
};
|
|
1704
|
+
this.on("error", handleError);
|
|
1705
|
+
});
|
|
1706
|
+
}
|
|
1707
|
+
/**
|
|
1708
|
+
Size of the queue, the number of queued items waiting to run.
|
|
1709
|
+
*/
|
|
1710
|
+
get size() {
|
|
1711
|
+
return __privateGet(this, _queue2).size;
|
|
1712
|
+
}
|
|
1713
|
+
/**
|
|
1714
|
+
Size of the queue, filtered by the given options.
|
|
1715
|
+
|
|
1716
|
+
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
|
|
1717
|
+
*/
|
|
1718
|
+
sizeBy(options) {
|
|
1719
|
+
return __privateGet(this, _queue2).filter(options).length;
|
|
1720
|
+
}
|
|
1721
|
+
/**
|
|
1722
|
+
Number of running items (no longer in the queue).
|
|
1723
|
+
*/
|
|
1724
|
+
get pending() {
|
|
1725
|
+
return __privateGet(this, _pending);
|
|
1726
|
+
}
|
|
1727
|
+
/**
|
|
1728
|
+
Whether the queue is currently paused.
|
|
1729
|
+
*/
|
|
1730
|
+
get isPaused() {
|
|
1731
|
+
return __privateGet(this, _isPaused);
|
|
1732
|
+
}
|
|
1733
|
+
/**
|
|
1734
|
+
Whether the queue is currently rate-limited due to intervalCap.
|
|
1735
|
+
*/
|
|
1736
|
+
get isRateLimited() {
|
|
1737
|
+
return __privateGet(this, _rateLimitedInInterval);
|
|
1738
|
+
}
|
|
1739
|
+
/**
|
|
1740
|
+
Whether the queue is saturated. Returns `true` when:
|
|
1741
|
+
- All concurrency slots are occupied and tasks are waiting, OR
|
|
1742
|
+
- The queue is rate-limited and tasks are waiting
|
|
1743
|
+
|
|
1744
|
+
Useful for detecting backpressure and potential hanging tasks.
|
|
1745
|
+
|
|
1746
|
+
```js
|
|
1747
|
+
import PQueue from 'p-queue';
|
|
1748
|
+
|
|
1749
|
+
const queue = new PQueue({concurrency: 2});
|
|
1750
|
+
|
|
1751
|
+
// Backpressure handling
|
|
1752
|
+
if (queue.isSaturated) {
|
|
1753
|
+
console.log('Queue is saturated, waiting for capacity...');
|
|
1754
|
+
await queue.onSizeLessThan(queue.concurrency);
|
|
1755
|
+
}
|
|
1756
|
+
|
|
1757
|
+
// Monitoring for stuck tasks
|
|
1758
|
+
setInterval(() => {
|
|
1759
|
+
if (queue.isSaturated) {
|
|
1760
|
+
console.warn(`Queue saturated: ${queue.pending} running, ${queue.size} waiting`);
|
|
1761
|
+
}
|
|
1762
|
+
}, 60000);
|
|
1763
|
+
```
|
|
1764
|
+
*/
|
|
1765
|
+
get isSaturated() {
|
|
1766
|
+
return __privateGet(this, _pending) === __privateGet(this, _concurrency) && __privateGet(this, _queue2).size > 0 || this.isRateLimited && __privateGet(this, _queue2).size > 0;
|
|
1767
|
+
}
|
|
1768
|
+
/**
|
|
1769
|
+
The tasks currently being executed. Each task includes its `id`, `priority`, `startTime`, and `timeout` (if set).
|
|
1770
|
+
|
|
1771
|
+
Returns an array of task info objects.
|
|
1772
|
+
|
|
1773
|
+
```js
|
|
1774
|
+
import PQueue from 'p-queue';
|
|
1775
|
+
|
|
1776
|
+
const queue = new PQueue({concurrency: 2});
|
|
1777
|
+
|
|
1778
|
+
// Add tasks with IDs for better debugging
|
|
1779
|
+
queue.add(() => fetchUser(123), {id: 'user-123'});
|
|
1780
|
+
queue.add(() => fetchPosts(456), {id: 'posts-456', priority: 1});
|
|
1781
|
+
|
|
1782
|
+
// Check what's running
|
|
1783
|
+
console.log(queue.runningTasks);
|
|
1784
|
+
// => [{
|
|
1785
|
+
// id: 'user-123',
|
|
1786
|
+
// priority: 0,
|
|
1787
|
+
// startTime: 1759253001716,
|
|
1788
|
+
// timeout: undefined
|
|
1789
|
+
// }, {
|
|
1790
|
+
// id: 'posts-456',
|
|
1791
|
+
// priority: 1,
|
|
1792
|
+
// startTime: 1759253001916,
|
|
1793
|
+
// timeout: undefined
|
|
1794
|
+
// }]
|
|
1795
|
+
```
|
|
1796
|
+
*/
|
|
1797
|
+
get runningTasks() {
|
|
1798
|
+
return [...__privateGet(this, _runningTasks).values()].map((task) => ({ ...task }));
|
|
1799
|
+
}
|
|
1800
|
+
};
|
|
1801
|
+
_carryoverIntervalCount = new WeakMap();
|
|
1802
|
+
_isIntervalIgnored = new WeakMap();
|
|
1803
|
+
_intervalCount = new WeakMap();
|
|
1804
|
+
_intervalCap = new WeakMap();
|
|
1805
|
+
_rateLimitedInInterval = new WeakMap();
|
|
1806
|
+
_rateLimitFlushScheduled = new WeakMap();
|
|
1807
|
+
_interval = new WeakMap();
|
|
1808
|
+
_intervalEnd = new WeakMap();
|
|
1809
|
+
_lastExecutionTime = new WeakMap();
|
|
1810
|
+
_intervalId = new WeakMap();
|
|
1811
|
+
_timeoutId = new WeakMap();
|
|
1812
|
+
_strict = new WeakMap();
|
|
1813
|
+
_strictTicks = new WeakMap();
|
|
1814
|
+
_strictTicksStartIndex = new WeakMap();
|
|
1815
|
+
_queue2 = new WeakMap();
|
|
1816
|
+
_queueClass = new WeakMap();
|
|
1817
|
+
_pending = new WeakMap();
|
|
1818
|
+
_concurrency = new WeakMap();
|
|
1819
|
+
_isPaused = new WeakMap();
|
|
1820
|
+
_idAssigner = new WeakMap();
|
|
1821
|
+
_runningTasks = new WeakMap();
|
|
1822
|
+
_queueAbortListenerCleanupFunctions = new WeakMap();
|
|
1823
|
+
_PQueue_instances = new WeakSet();
|
|
1824
|
+
cleanupStrictTicks_fn = function(now) {
|
|
1825
|
+
while (__privateGet(this, _strictTicksStartIndex) < __privateGet(this, _strictTicks).length) {
|
|
1826
|
+
const oldestTick = __privateGet(this, _strictTicks)[__privateGet(this, _strictTicksStartIndex)];
|
|
1827
|
+
if (oldestTick !== void 0 && now - oldestTick >= __privateGet(this, _interval)) {
|
|
1828
|
+
__privateWrapper(this, _strictTicksStartIndex)._++;
|
|
1829
|
+
} else {
|
|
1830
|
+
break;
|
|
1831
|
+
}
|
|
1832
|
+
}
|
|
1833
|
+
const shouldCompact = __privateGet(this, _strictTicksStartIndex) > 100 && __privateGet(this, _strictTicksStartIndex) > __privateGet(this, _strictTicks).length / 2 || __privateGet(this, _strictTicksStartIndex) === __privateGet(this, _strictTicks).length;
|
|
1834
|
+
if (shouldCompact) {
|
|
1835
|
+
__privateSet(this, _strictTicks, __privateGet(this, _strictTicks).slice(__privateGet(this, _strictTicksStartIndex)));
|
|
1836
|
+
__privateSet(this, _strictTicksStartIndex, 0);
|
|
1837
|
+
}
|
|
1838
|
+
};
|
|
1839
|
+
// Helper methods for interval consumption
|
|
1840
|
+
consumeIntervalSlot_fn = function(now) {
|
|
1841
|
+
if (__privateGet(this, _strict)) {
|
|
1842
|
+
__privateGet(this, _strictTicks).push(now);
|
|
1843
|
+
} else {
|
|
1844
|
+
__privateWrapper(this, _intervalCount)._++;
|
|
1845
|
+
}
|
|
1846
|
+
};
|
|
1847
|
+
rollbackIntervalSlot_fn = function() {
|
|
1848
|
+
if (__privateGet(this, _strict)) {
|
|
1849
|
+
if (__privateGet(this, _strictTicks).length > __privateGet(this, _strictTicksStartIndex)) {
|
|
1850
|
+
__privateGet(this, _strictTicks).pop();
|
|
1851
|
+
}
|
|
1852
|
+
} else if (__privateGet(this, _intervalCount) > 0) {
|
|
1853
|
+
__privateWrapper(this, _intervalCount)._--;
|
|
1854
|
+
}
|
|
1855
|
+
};
|
|
1856
|
+
getActiveTicksCount_fn = function() {
|
|
1857
|
+
return __privateGet(this, _strictTicks).length - __privateGet(this, _strictTicksStartIndex);
|
|
1858
|
+
};
|
|
1859
|
+
doesIntervalAllowAnother_get = function() {
|
|
1860
|
+
if (__privateGet(this, _isIntervalIgnored)) {
|
|
1861
|
+
return true;
|
|
1862
|
+
}
|
|
1863
|
+
if (__privateGet(this, _strict)) {
|
|
1864
|
+
return __privateMethod(this, _PQueue_instances, getActiveTicksCount_fn).call(this) < __privateGet(this, _intervalCap);
|
|
1865
|
+
}
|
|
1866
|
+
return __privateGet(this, _intervalCount) < __privateGet(this, _intervalCap);
|
|
1867
|
+
};
|
|
1868
|
+
doesConcurrentAllowAnother_get = function() {
|
|
1869
|
+
return __privateGet(this, _pending) < __privateGet(this, _concurrency);
|
|
1870
|
+
};
|
|
1871
|
+
next_fn = function() {
|
|
1872
|
+
__privateWrapper(this, _pending)._--;
|
|
1873
|
+
if (__privateGet(this, _pending) === 0) {
|
|
1874
|
+
this.emit("pendingZero");
|
|
1875
|
+
}
|
|
1876
|
+
__privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this);
|
|
1877
|
+
this.emit("next");
|
|
1878
|
+
};
|
|
1879
|
+
onResumeInterval_fn = function() {
|
|
1880
|
+
__privateSet(this, _timeoutId, void 0);
|
|
1881
|
+
__privateMethod(this, _PQueue_instances, onInterval_fn).call(this);
|
|
1882
|
+
__privateMethod(this, _PQueue_instances, initializeIntervalIfNeeded_fn).call(this);
|
|
1883
|
+
};
|
|
1884
|
+
isIntervalPausedAt_fn = function(now) {
|
|
1885
|
+
if (__privateGet(this, _strict)) {
|
|
1886
|
+
__privateMethod(this, _PQueue_instances, cleanupStrictTicks_fn).call(this, now);
|
|
1887
|
+
const activeTicksCount = __privateMethod(this, _PQueue_instances, getActiveTicksCount_fn).call(this);
|
|
1888
|
+
if (activeTicksCount >= __privateGet(this, _intervalCap)) {
|
|
1889
|
+
const oldestTick = __privateGet(this, _strictTicks)[__privateGet(this, _strictTicksStartIndex)];
|
|
1890
|
+
const delay = __privateGet(this, _interval) - (now - oldestTick);
|
|
1891
|
+
__privateMethod(this, _PQueue_instances, createIntervalTimeout_fn).call(this, delay);
|
|
1892
|
+
return true;
|
|
1893
|
+
}
|
|
1894
|
+
return false;
|
|
1895
|
+
}
|
|
1896
|
+
if (__privateGet(this, _intervalId) === void 0) {
|
|
1897
|
+
const delay = __privateGet(this, _intervalEnd) - now;
|
|
1898
|
+
if (delay < 0) {
|
|
1899
|
+
if (__privateGet(this, _lastExecutionTime) > 0) {
|
|
1900
|
+
const timeSinceLastExecution = now - __privateGet(this, _lastExecutionTime);
|
|
1901
|
+
if (timeSinceLastExecution < __privateGet(this, _interval)) {
|
|
1902
|
+
__privateMethod(this, _PQueue_instances, createIntervalTimeout_fn).call(this, __privateGet(this, _interval) - timeSinceLastExecution);
|
|
1903
|
+
return true;
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
__privateSet(this, _intervalCount, __privateGet(this, _carryoverIntervalCount) ? __privateGet(this, _pending) : 0);
|
|
1907
|
+
} else {
|
|
1908
|
+
__privateMethod(this, _PQueue_instances, createIntervalTimeout_fn).call(this, delay);
|
|
1909
|
+
return true;
|
|
1910
|
+
}
|
|
1911
|
+
}
|
|
1912
|
+
return false;
|
|
1913
|
+
};
|
|
1914
|
+
createIntervalTimeout_fn = function(delay) {
|
|
1915
|
+
if (__privateGet(this, _timeoutId) !== void 0) {
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
__privateSet(this, _timeoutId, setTimeout(() => {
|
|
1919
|
+
__privateMethod(this, _PQueue_instances, onResumeInterval_fn).call(this);
|
|
1920
|
+
}, delay));
|
|
1921
|
+
};
|
|
1922
|
+
clearIntervalTimer_fn = function() {
|
|
1923
|
+
if (__privateGet(this, _intervalId)) {
|
|
1924
|
+
clearInterval(__privateGet(this, _intervalId));
|
|
1925
|
+
__privateSet(this, _intervalId, void 0);
|
|
1926
|
+
}
|
|
1927
|
+
};
|
|
1928
|
+
clearTimeoutTimer_fn = function() {
|
|
1929
|
+
if (__privateGet(this, _timeoutId)) {
|
|
1930
|
+
clearTimeout(__privateGet(this, _timeoutId));
|
|
1931
|
+
__privateSet(this, _timeoutId, void 0);
|
|
1932
|
+
}
|
|
1933
|
+
};
|
|
1934
|
+
tryToStartAnother_fn = function() {
|
|
1935
|
+
if (__privateGet(this, _queue2).size === 0) {
|
|
1936
|
+
__privateMethod(this, _PQueue_instances, clearIntervalTimer_fn).call(this);
|
|
1937
|
+
this.emit("empty");
|
|
1938
|
+
if (__privateGet(this, _pending) === 0) {
|
|
1939
|
+
__privateMethod(this, _PQueue_instances, clearTimeoutTimer_fn).call(this);
|
|
1940
|
+
if (__privateGet(this, _strict) && __privateGet(this, _strictTicksStartIndex) > 0) {
|
|
1941
|
+
const now = Date.now();
|
|
1942
|
+
__privateMethod(this, _PQueue_instances, cleanupStrictTicks_fn).call(this, now);
|
|
1943
|
+
}
|
|
1944
|
+
this.emit("idle");
|
|
1945
|
+
}
|
|
1946
|
+
return false;
|
|
1947
|
+
}
|
|
1948
|
+
let taskStarted = false;
|
|
1949
|
+
if (!__privateGet(this, _isPaused)) {
|
|
1950
|
+
const now = Date.now();
|
|
1951
|
+
const canInitializeInterval = !__privateMethod(this, _PQueue_instances, isIntervalPausedAt_fn).call(this, now);
|
|
1952
|
+
if (__privateGet(this, _PQueue_instances, doesIntervalAllowAnother_get) && __privateGet(this, _PQueue_instances, doesConcurrentAllowAnother_get)) {
|
|
1953
|
+
const job = __privateGet(this, _queue2).dequeue();
|
|
1954
|
+
if (!__privateGet(this, _isIntervalIgnored)) {
|
|
1955
|
+
__privateMethod(this, _PQueue_instances, consumeIntervalSlot_fn).call(this, now);
|
|
1956
|
+
__privateMethod(this, _PQueue_instances, scheduleRateLimitUpdate_fn).call(this);
|
|
1957
|
+
}
|
|
1958
|
+
this.emit("active");
|
|
1959
|
+
job();
|
|
1960
|
+
if (canInitializeInterval) {
|
|
1961
|
+
__privateMethod(this, _PQueue_instances, initializeIntervalIfNeeded_fn).call(this);
|
|
1962
|
+
}
|
|
1963
|
+
taskStarted = true;
|
|
1964
|
+
}
|
|
1965
|
+
}
|
|
1966
|
+
return taskStarted;
|
|
1967
|
+
};
|
|
1968
|
+
initializeIntervalIfNeeded_fn = function() {
|
|
1969
|
+
if (__privateGet(this, _isIntervalIgnored) || __privateGet(this, _intervalId) !== void 0) {
|
|
1970
|
+
return;
|
|
1971
|
+
}
|
|
1972
|
+
if (__privateGet(this, _strict)) {
|
|
1973
|
+
return;
|
|
1974
|
+
}
|
|
1975
|
+
__privateSet(this, _intervalId, setInterval(() => {
|
|
1976
|
+
__privateMethod(this, _PQueue_instances, onInterval_fn).call(this);
|
|
1977
|
+
}, __privateGet(this, _interval)));
|
|
1978
|
+
__privateSet(this, _intervalEnd, Date.now() + __privateGet(this, _interval));
|
|
1979
|
+
};
|
|
1980
|
+
onInterval_fn = function() {
|
|
1981
|
+
if (!__privateGet(this, _strict)) {
|
|
1982
|
+
if (__privateGet(this, _intervalCount) === 0 && __privateGet(this, _pending) === 0 && __privateGet(this, _intervalId)) {
|
|
1983
|
+
__privateMethod(this, _PQueue_instances, clearIntervalTimer_fn).call(this);
|
|
1984
|
+
}
|
|
1985
|
+
__privateSet(this, _intervalCount, __privateGet(this, _carryoverIntervalCount) ? __privateGet(this, _pending) : 0);
|
|
1986
|
+
}
|
|
1987
|
+
__privateMethod(this, _PQueue_instances, processQueue_fn).call(this);
|
|
1988
|
+
__privateMethod(this, _PQueue_instances, scheduleRateLimitUpdate_fn).call(this);
|
|
1989
|
+
};
|
|
1990
|
+
/**
|
|
1991
|
+
Executes all queued functions until it reaches the limit.
|
|
1992
|
+
*/
|
|
1993
|
+
processQueue_fn = function() {
|
|
1994
|
+
while (__privateMethod(this, _PQueue_instances, tryToStartAnother_fn).call(this)) {
|
|
1995
|
+
}
|
|
1996
|
+
};
|
|
1997
|
+
onEvent_fn = async function(event, filter) {
|
|
1998
|
+
return new Promise((resolve) => {
|
|
1999
|
+
const listener = () => {
|
|
2000
|
+
if (filter && !filter()) {
|
|
2001
|
+
return;
|
|
2002
|
+
}
|
|
2003
|
+
this.off(event, listener);
|
|
2004
|
+
resolve();
|
|
2005
|
+
};
|
|
2006
|
+
this.on(event, listener);
|
|
2007
|
+
});
|
|
2008
|
+
};
|
|
2009
|
+
setupRateLimitTracking_fn = function() {
|
|
2010
|
+
if (__privateGet(this, _isIntervalIgnored)) {
|
|
2011
|
+
return;
|
|
2012
|
+
}
|
|
2013
|
+
this.on("add", () => {
|
|
2014
|
+
if (__privateGet(this, _queue2).size > 0) {
|
|
2015
|
+
__privateMethod(this, _PQueue_instances, scheduleRateLimitUpdate_fn).call(this);
|
|
2016
|
+
}
|
|
2017
|
+
});
|
|
2018
|
+
this.on("next", () => {
|
|
2019
|
+
__privateMethod(this, _PQueue_instances, scheduleRateLimitUpdate_fn).call(this);
|
|
2020
|
+
});
|
|
2021
|
+
};
|
|
2022
|
+
scheduleRateLimitUpdate_fn = function() {
|
|
2023
|
+
if (__privateGet(this, _isIntervalIgnored) || __privateGet(this, _rateLimitFlushScheduled)) {
|
|
2024
|
+
return;
|
|
2025
|
+
}
|
|
2026
|
+
__privateSet(this, _rateLimitFlushScheduled, true);
|
|
2027
|
+
queueMicrotask(() => {
|
|
2028
|
+
__privateSet(this, _rateLimitFlushScheduled, false);
|
|
2029
|
+
__privateMethod(this, _PQueue_instances, updateRateLimitState_fn).call(this);
|
|
2030
|
+
});
|
|
2031
|
+
};
|
|
2032
|
+
rollbackIntervalConsumption_fn = function() {
|
|
2033
|
+
if (__privateGet(this, _isIntervalIgnored)) {
|
|
2034
|
+
return;
|
|
2035
|
+
}
|
|
2036
|
+
__privateMethod(this, _PQueue_instances, rollbackIntervalSlot_fn).call(this);
|
|
2037
|
+
__privateMethod(this, _PQueue_instances, scheduleRateLimitUpdate_fn).call(this);
|
|
2038
|
+
};
|
|
2039
|
+
updateRateLimitState_fn = function() {
|
|
2040
|
+
const previous = __privateGet(this, _rateLimitedInInterval);
|
|
2041
|
+
if (__privateGet(this, _isIntervalIgnored) || __privateGet(this, _queue2).size === 0) {
|
|
2042
|
+
if (previous) {
|
|
2043
|
+
__privateSet(this, _rateLimitedInInterval, false);
|
|
2044
|
+
this.emit("rateLimitCleared");
|
|
2045
|
+
}
|
|
2046
|
+
return;
|
|
2047
|
+
}
|
|
2048
|
+
let count;
|
|
2049
|
+
if (__privateGet(this, _strict)) {
|
|
2050
|
+
const now = Date.now();
|
|
2051
|
+
__privateMethod(this, _PQueue_instances, cleanupStrictTicks_fn).call(this, now);
|
|
2052
|
+
count = __privateMethod(this, _PQueue_instances, getActiveTicksCount_fn).call(this);
|
|
2053
|
+
} else {
|
|
2054
|
+
count = __privateGet(this, _intervalCount);
|
|
2055
|
+
}
|
|
2056
|
+
const shouldBeRateLimited = count >= __privateGet(this, _intervalCap);
|
|
2057
|
+
if (shouldBeRateLimited !== previous) {
|
|
2058
|
+
__privateSet(this, _rateLimitedInInterval, shouldBeRateLimited);
|
|
2059
|
+
this.emit(shouldBeRateLimited ? "rateLimit" : "rateLimitCleared");
|
|
2060
|
+
}
|
|
2061
|
+
};
|
|
2062
|
+
|
|
2063
|
+
// src/core/persistence-manager.ts
|
|
2064
|
+
var _PersistenceManager = class _PersistenceManager {
|
|
2065
|
+
async saveQueueStates(states) {
|
|
2066
|
+
try {
|
|
2067
|
+
if (chrome.storage) {
|
|
2068
|
+
await chrome.storage.local.set({ [_PersistenceManager.STORAGE_KEY]: states });
|
|
2069
|
+
}
|
|
2070
|
+
} catch (e) {
|
|
2071
|
+
console.error("Failed to persist queue states:", e);
|
|
2072
|
+
}
|
|
2073
|
+
}
|
|
2074
|
+
async loadQueueStates() {
|
|
2075
|
+
try {
|
|
2076
|
+
if (chrome.storage) {
|
|
2077
|
+
const data = await chrome.storage.local.get(_PersistenceManager.STORAGE_KEY);
|
|
2078
|
+
const stored = data[_PersistenceManager.STORAGE_KEY];
|
|
2079
|
+
if (stored && typeof stored === "object") {
|
|
2080
|
+
return stored;
|
|
2081
|
+
}
|
|
2082
|
+
}
|
|
2083
|
+
} catch (e) {
|
|
2084
|
+
console.error("Failed to load queue states:", e);
|
|
2085
|
+
}
|
|
2086
|
+
return {};
|
|
2087
|
+
}
|
|
2088
|
+
};
|
|
2089
|
+
__publicField(_PersistenceManager, "STORAGE_KEY", "queue_manager_state");
|
|
2090
|
+
var PersistenceManager = _PersistenceManager;
|
|
2091
|
+
var persistenceManager = new PersistenceManager();
|
|
2092
|
+
|
|
2093
|
+
// src/core/engine-hub.ts
|
|
2094
|
+
var EngineHub = class {
|
|
2095
|
+
constructor() {
|
|
2096
|
+
__publicField(this, "engines", /* @__PURE__ */ new Map());
|
|
2097
|
+
}
|
|
2098
|
+
register(platformId, engine) {
|
|
2099
|
+
this.engines.set(platformId, engine);
|
|
2100
|
+
}
|
|
2101
|
+
get(platformId) {
|
|
2102
|
+
return this.engines.get(platformId);
|
|
2103
|
+
}
|
|
2104
|
+
getAll() {
|
|
2105
|
+
return this.engines;
|
|
2106
|
+
}
|
|
2107
|
+
};
|
|
2108
|
+
var engineHub = new EngineHub();
|
|
2109
|
+
|
|
2110
|
+
// src/core/helper.ts
|
|
2111
|
+
async function sleep(ms, signal) {
|
|
2112
|
+
if (signal?.aborted) {
|
|
2113
|
+
signal.throwIfAborted();
|
|
2114
|
+
}
|
|
2115
|
+
await new Promise((resolve, reject) => {
|
|
2116
|
+
const abortHandler = () => {
|
|
2117
|
+
reject(new DOMException("Sleep aborted", "AbortError"));
|
|
2118
|
+
};
|
|
2119
|
+
if (signal) {
|
|
2120
|
+
signal.addEventListener("abort", abortHandler, { once: true });
|
|
2121
|
+
}
|
|
2122
|
+
const timeoutId = setTimeout(() => {
|
|
2123
|
+
if (signal) {
|
|
2124
|
+
signal.removeEventListener("abort", abortHandler);
|
|
2125
|
+
}
|
|
2126
|
+
resolve(void 0);
|
|
2127
|
+
}, ms);
|
|
2128
|
+
if (signal) {
|
|
2129
|
+
signal.addEventListener(
|
|
2130
|
+
"abort",
|
|
2131
|
+
() => {
|
|
2132
|
+
clearTimeout(timeoutId);
|
|
2133
|
+
reject(new DOMException("Sleep aborted", "AbortError"));
|
|
2134
|
+
},
|
|
2135
|
+
{ once: true }
|
|
2136
|
+
);
|
|
2137
|
+
}
|
|
2138
|
+
});
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
// src/core/task-context.ts
|
|
2142
|
+
var TaskContext = class {
|
|
2143
|
+
constructor(task, signal) {
|
|
2144
|
+
__publicField(this, "task");
|
|
2145
|
+
__publicField(this, "signal");
|
|
2146
|
+
this.task = task;
|
|
2147
|
+
this.signal = signal;
|
|
2148
|
+
}
|
|
2149
|
+
/**
|
|
2150
|
+
* Helper to execute an async operation while respecting the cancellation signal.
|
|
2151
|
+
* Checks for abortion BEFORE and AFTER the operation.
|
|
2152
|
+
*/
|
|
2153
|
+
async run(fn) {
|
|
2154
|
+
this.signal?.throwIfAborted();
|
|
2155
|
+
const result = await fn();
|
|
2156
|
+
this.signal?.throwIfAborted();
|
|
2157
|
+
return result;
|
|
2158
|
+
}
|
|
2159
|
+
/**
|
|
2160
|
+
* Signal-aware sleep utility.
|
|
2161
|
+
*/
|
|
2162
|
+
async sleep(ms) {
|
|
2163
|
+
return sleep(ms, this.signal);
|
|
2164
|
+
}
|
|
2165
|
+
/**
|
|
2166
|
+
* Check if the task has been cancelled.
|
|
2167
|
+
*/
|
|
2168
|
+
get aborted() {
|
|
2169
|
+
return this.signal?.aborted || false;
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Throw if the task has been cancelled.
|
|
2173
|
+
*/
|
|
2174
|
+
throwIfAborted() {
|
|
2175
|
+
this.signal?.throwIfAborted();
|
|
2176
|
+
}
|
|
2177
|
+
};
|
|
2178
|
+
|
|
2179
|
+
// src/core/queue-manager.ts
|
|
2180
|
+
var QueueManager = class {
|
|
2181
|
+
constructor(options) {
|
|
2182
|
+
__publicField(this, "queues", /* @__PURE__ */ new Map());
|
|
2183
|
+
__publicField(this, "defaultOptions");
|
|
2184
|
+
__publicField(this, "platformOptions", /* @__PURE__ */ new Map());
|
|
2185
|
+
__publicField(this, "runningQueues", /* @__PURE__ */ new Set());
|
|
2186
|
+
__publicField(this, "concurrencyMap", /* @__PURE__ */ new Map());
|
|
2187
|
+
__publicField(this, "abortControllers", /* @__PURE__ */ new Map());
|
|
2188
|
+
this.defaultOptions = options;
|
|
2189
|
+
}
|
|
2190
|
+
logQueueState(keycard, identifier, action) {
|
|
2191
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2192
|
+
const entry = this.queues.get(key);
|
|
2193
|
+
if (!entry) {
|
|
2194
|
+
console.log(`[Queue] ${action} - Queue not found for key: ${key}`);
|
|
2195
|
+
return;
|
|
2196
|
+
}
|
|
2197
|
+
const taskSummary = entry.tasks.map((t) => `[${t.id}] ${t.status}${t.name ? ` (${t.name})` : ""}`).join(", ");
|
|
2198
|
+
console.log(
|
|
2199
|
+
`[Queue] ${action} | Key: ${key} | Tasks: ${entry.tasks.length} | Queue size: ${entry.queue.size} | Pending: ${entry.queue.pending} | isPaused: ${entry.queue.isPaused} | Tasks: ${taskSummary}`
|
|
2200
|
+
);
|
|
2201
|
+
}
|
|
2202
|
+
getQueueKey(keycard, identifier) {
|
|
2203
|
+
if (identifier) return `${keycard}__${identifier}`;
|
|
2204
|
+
return keycard;
|
|
2205
|
+
}
|
|
2206
|
+
registerOptions(keycard, options) {
|
|
2207
|
+
if (!this.platformOptions.has(keycard)) {
|
|
2208
|
+
this.platformOptions.set(keycard, []);
|
|
2209
|
+
}
|
|
2210
|
+
this.platformOptions.get(keycard).push(options);
|
|
2211
|
+
return () => this.unregisterOptions(keycard, options);
|
|
2212
|
+
}
|
|
2213
|
+
unregisterOptions(keycard, options) {
|
|
2214
|
+
const list = this.platformOptions.get(keycard);
|
|
2215
|
+
if (list) {
|
|
2216
|
+
const index = list.indexOf(options);
|
|
2217
|
+
if (index !== -1) {
|
|
2218
|
+
list.splice(index, 1);
|
|
2219
|
+
}
|
|
2220
|
+
if (list.length === 0) {
|
|
2221
|
+
this.platformOptions.delete(keycard);
|
|
2222
|
+
}
|
|
2223
|
+
}
|
|
2224
|
+
}
|
|
2225
|
+
getOptions(keycard) {
|
|
2226
|
+
const platformSpecific = this.platformOptions.get(keycard) || [];
|
|
2227
|
+
const global = this.platformOptions.get("*") || [];
|
|
2228
|
+
return [...platformSpecific, ...global];
|
|
2229
|
+
}
|
|
2230
|
+
getOrCreateQueue(keycard, identifier) {
|
|
2231
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2232
|
+
if (!this.queues.has(key)) {
|
|
2233
|
+
const concurrency = this.options.defaultConcurrency;
|
|
2234
|
+
const queue = new PQueue({
|
|
2235
|
+
concurrency,
|
|
2236
|
+
autoStart: false
|
|
2237
|
+
});
|
|
2238
|
+
const entry2 = {
|
|
2239
|
+
queue,
|
|
2240
|
+
tasks: [],
|
|
2241
|
+
queuedIds: /* @__PURE__ */ new Set(),
|
|
2242
|
+
consecutiveErrors: 0
|
|
2243
|
+
};
|
|
2244
|
+
queue.on("idle", () => {
|
|
2245
|
+
if (this.runningQueues.has(key)) {
|
|
2246
|
+
this.autoStopQueue(keycard, identifier);
|
|
2247
|
+
}
|
|
2248
|
+
});
|
|
2249
|
+
this.queues.set(key, entry2);
|
|
2250
|
+
}
|
|
2251
|
+
const entry = this.queues.get(key);
|
|
2252
|
+
const currentConcurrency = this.concurrencyMap.get(keycard) ?? this.options.defaultConcurrency ?? 1;
|
|
2253
|
+
if (entry.queue.concurrency !== currentConcurrency) {
|
|
2254
|
+
entry.queue.concurrency = currentConcurrency;
|
|
2255
|
+
}
|
|
2256
|
+
return entry;
|
|
2257
|
+
}
|
|
2258
|
+
// Getter for legacy/global options to avoid breaking things during refactor
|
|
2259
|
+
get options() {
|
|
2260
|
+
return this.defaultOptions;
|
|
2261
|
+
}
|
|
2262
|
+
setConcurrency(keycard, concurrency) {
|
|
2263
|
+
this.concurrencyMap.set(keycard, concurrency);
|
|
2264
|
+
for (const [key, entry] of this.queues.entries()) {
|
|
2265
|
+
if (key.startsWith(keycard)) {
|
|
2266
|
+
entry.queue.concurrency = concurrency;
|
|
2267
|
+
}
|
|
2268
|
+
}
|
|
2269
|
+
}
|
|
2270
|
+
registerEngine(keycard, engine) {
|
|
2271
|
+
engineHub.register(keycard, engine);
|
|
2272
|
+
}
|
|
2273
|
+
async add(keycard, identifier, task) {
|
|
2274
|
+
const entry = this.getOrCreateQueue(keycard, identifier);
|
|
2275
|
+
const { queue, tasks, queuedIds } = entry;
|
|
2276
|
+
const exists = tasks.find((t) => t.id === task.id);
|
|
2277
|
+
const updatedTask = { ...task };
|
|
2278
|
+
if (!exists) {
|
|
2279
|
+
tasks.push(updatedTask);
|
|
2280
|
+
} else {
|
|
2281
|
+
const idx = tasks.indexOf(exists);
|
|
2282
|
+
tasks[idx] = updatedTask;
|
|
2283
|
+
}
|
|
2284
|
+
if (updatedTask.status === "Waiting" && !queuedIds.has(updatedTask.id)) {
|
|
2285
|
+
updatedTask.isQueued = true;
|
|
2286
|
+
queuedIds.add(updatedTask.id);
|
|
2287
|
+
queue.add(() => this.processTask(keycard, identifier, updatedTask));
|
|
2288
|
+
}
|
|
2289
|
+
this.updateTasks(keycard, identifier, tasks);
|
|
2290
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2291
|
+
this.logQueueState(keycard, identifier, "ADD");
|
|
2292
|
+
}
|
|
2293
|
+
async addMany(keycard, identifier, newTasks) {
|
|
2294
|
+
const entry = this.getOrCreateQueue(keycard, identifier);
|
|
2295
|
+
const { queue, tasks, queuedIds } = entry;
|
|
2296
|
+
for (const task of newTasks) {
|
|
2297
|
+
const exists = tasks.find((t) => t.id === task.id);
|
|
2298
|
+
const updatedTask = { ...task };
|
|
2299
|
+
if (!exists) {
|
|
2300
|
+
tasks.push(updatedTask);
|
|
2301
|
+
} else {
|
|
2302
|
+
const idx = tasks.indexOf(exists);
|
|
2303
|
+
tasks[idx] = updatedTask;
|
|
2304
|
+
}
|
|
2305
|
+
if (updatedTask.status === "Waiting" && !queuedIds.has(updatedTask.id)) {
|
|
2306
|
+
updatedTask.isQueued = true;
|
|
2307
|
+
queuedIds.add(updatedTask.id);
|
|
2308
|
+
queue.add(() => this.processTask(keycard, identifier, updatedTask));
|
|
2309
|
+
}
|
|
2310
|
+
}
|
|
2311
|
+
this.updateTasks(keycard, identifier, tasks);
|
|
2312
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2313
|
+
this.logQueueState(keycard, identifier, "ADD_MANY");
|
|
2314
|
+
}
|
|
2315
|
+
async start(keycard, identifier) {
|
|
2316
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2317
|
+
const entry = this.queues.get(key);
|
|
2318
|
+
if (entry) {
|
|
2319
|
+
const { queue, tasks, queuedIds } = entry;
|
|
2320
|
+
let addedAny = false;
|
|
2321
|
+
for (const task of tasks) {
|
|
2322
|
+
if (task.status === "Waiting" && !queuedIds.has(task.id)) {
|
|
2323
|
+
task.isQueued = true;
|
|
2324
|
+
queuedIds.add(task.id);
|
|
2325
|
+
queue.add(() => this.processTask(keycard, identifier, task));
|
|
2326
|
+
addedAny = true;
|
|
2327
|
+
}
|
|
2328
|
+
}
|
|
2329
|
+
this.runningQueues.add(key);
|
|
2330
|
+
queue.start();
|
|
2331
|
+
if (addedAny) {
|
|
2332
|
+
this.updateTasks(keycard, identifier, tasks);
|
|
2333
|
+
}
|
|
2334
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2335
|
+
this.logQueueState(keycard, identifier, "START");
|
|
2336
|
+
await this.persistState();
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
async stop(keycard, identifier) {
|
|
2340
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2341
|
+
const entry = this.queues.get(key);
|
|
2342
|
+
if (entry) {
|
|
2343
|
+
entry.queue.pause();
|
|
2344
|
+
entry.queue.clear();
|
|
2345
|
+
entry.queuedIds.clear();
|
|
2346
|
+
entry.tasks.forEach((t) => {
|
|
2347
|
+
if (t.status === "Waiting") t.isQueued = false;
|
|
2348
|
+
});
|
|
2349
|
+
this.runningQueues.delete(key);
|
|
2350
|
+
const runningTasks = entry.tasks.filter((t) => t.status === "Running");
|
|
2351
|
+
for (const t of runningTasks) {
|
|
2352
|
+
await this.haltTask(keycard, identifier, t.id);
|
|
2353
|
+
}
|
|
2354
|
+
await this.persistState();
|
|
2355
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2356
|
+
this.logQueueState(keycard, identifier, "STOP");
|
|
2357
|
+
}
|
|
2358
|
+
}
|
|
2359
|
+
async pause(keycard, identifier) {
|
|
2360
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2361
|
+
const entry = this.queues.get(key);
|
|
2362
|
+
if (entry) {
|
|
2363
|
+
entry.queue.pause();
|
|
2364
|
+
await this.persistState();
|
|
2365
|
+
this.logQueueState(keycard, identifier, "PAUSE");
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
async resume(keycard, identifier) {
|
|
2369
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2370
|
+
const entry = this.queues.get(key);
|
|
2371
|
+
if (entry) {
|
|
2372
|
+
entry.queue.start();
|
|
2373
|
+
await this.persistState();
|
|
2374
|
+
this.logQueueState(keycard, identifier, "RESUME");
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2377
|
+
async clear(keycard, identifier) {
|
|
2378
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2379
|
+
const entry = this.queues.get(key);
|
|
2380
|
+
if (entry) {
|
|
2381
|
+
entry.queue.clear();
|
|
2382
|
+
entry.tasks = [];
|
|
2383
|
+
entry.queuedIds.clear();
|
|
2384
|
+
this.updateTasks(keycard, identifier, []);
|
|
2385
|
+
}
|
|
2386
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2387
|
+
}
|
|
2388
|
+
/**
|
|
2389
|
+
* Immediately halts the engine execution for a task and resets its status to Waiting.
|
|
2390
|
+
* Does NOT remove the task from the list.
|
|
2391
|
+
*/
|
|
2392
|
+
async haltTask(keycard, identifier, taskId) {
|
|
2393
|
+
const controller = this.abortControllers.get(taskId);
|
|
2394
|
+
if (controller) {
|
|
2395
|
+
controller.abort();
|
|
2396
|
+
this.abortControllers.delete(taskId);
|
|
2397
|
+
}
|
|
2398
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2399
|
+
const entry = this.queues.get(key);
|
|
2400
|
+
if (entry) {
|
|
2401
|
+
const idx = entry.tasks.findIndex((t) => t.id === taskId);
|
|
2402
|
+
const currentTask = entry.tasks[idx];
|
|
2403
|
+
if (idx !== -1 && currentTask && currentTask.status === "Running") {
|
|
2404
|
+
entry.tasks[idx] = {
|
|
2405
|
+
...currentTask,
|
|
2406
|
+
status: "Waiting",
|
|
2407
|
+
isQueued: false
|
|
2408
|
+
};
|
|
2409
|
+
entry.queuedIds.delete(taskId);
|
|
2410
|
+
this.updateTasks(keycard, identifier, entry.tasks);
|
|
2411
|
+
}
|
|
2412
|
+
}
|
|
2413
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2414
|
+
}
|
|
2415
|
+
/**
|
|
2416
|
+
* Stops execution AND removes the task from the project entirely.
|
|
2417
|
+
*/
|
|
2418
|
+
async cancelTask(keycard, identifier, taskId) {
|
|
2419
|
+
const controller = this.abortControllers.get(taskId);
|
|
2420
|
+
if (controller) {
|
|
2421
|
+
controller.abort();
|
|
2422
|
+
this.abortControllers.delete(taskId);
|
|
2423
|
+
}
|
|
2424
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2425
|
+
const entry = this.queues.get(key);
|
|
2426
|
+
if (entry) {
|
|
2427
|
+
entry.tasks = entry.tasks.filter((t) => t.id !== taskId);
|
|
2428
|
+
entry.queuedIds.delete(taskId);
|
|
2429
|
+
this.updateTasks(keycard, identifier, entry.tasks);
|
|
2430
|
+
}
|
|
2431
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2432
|
+
}
|
|
2433
|
+
getStatus(keycard, identifier) {
|
|
2434
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2435
|
+
const entry = this.queues.get(key);
|
|
2436
|
+
const activeTasks = entry?.tasks || [];
|
|
2437
|
+
const size = activeTasks.filter((t) => t.status === "Waiting" && t.isQueued).length;
|
|
2438
|
+
const pending = activeTasks.filter((t) => t.status === "Running").length;
|
|
2439
|
+
return {
|
|
2440
|
+
size,
|
|
2441
|
+
pending,
|
|
2442
|
+
isPaused: entry?.queue.isPaused || false,
|
|
2443
|
+
isRunning: this.runningQueues.has(key)
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2446
|
+
getTasks(keycard, identifier) {
|
|
2447
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2448
|
+
const entry = this.queues.get(key);
|
|
2449
|
+
return entry?.tasks || [];
|
|
2450
|
+
}
|
|
2451
|
+
updateTasks(keycard, identifier, tasks) {
|
|
2452
|
+
this.notifyTasksUpdate(keycard, identifier, tasks);
|
|
2453
|
+
}
|
|
2454
|
+
async processTask(keycard, identifier, task) {
|
|
2455
|
+
const engine = engineHub.get(keycard);
|
|
2456
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2457
|
+
const entry = this.queues.get(key);
|
|
2458
|
+
if (!engine) {
|
|
2459
|
+
console.warn(`No engine registered for platform: ${keycard}, skipping task: ${task.id}`);
|
|
2460
|
+
if (entry) {
|
|
2461
|
+
const taskIndex2 = entry.tasks.findIndex((t) => t.id === task.id);
|
|
2462
|
+
const taskEntry = entry.tasks[taskIndex2];
|
|
2463
|
+
if (taskIndex2 !== -1 && taskEntry) {
|
|
2464
|
+
entry.tasks[taskIndex2] = {
|
|
2465
|
+
...taskEntry,
|
|
2466
|
+
status: "Error",
|
|
2467
|
+
errorMessage: "Platform not supported"
|
|
2468
|
+
};
|
|
2469
|
+
this.updateTasks(keycard, identifier, entry.tasks);
|
|
2470
|
+
}
|
|
2471
|
+
}
|
|
2472
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2473
|
+
this.notifyTasksUpdate(keycard, identifier, entry?.tasks || []);
|
|
2474
|
+
return;
|
|
2475
|
+
}
|
|
2476
|
+
if (!entry) {
|
|
2477
|
+
console.error(`Queue entry not found for key: ${key}`);
|
|
2478
|
+
return;
|
|
2479
|
+
}
|
|
2480
|
+
if (task.isFlagged) {
|
|
2481
|
+
console.log(`[QueueManager] Task ${task.id} is flagged. Skipping.`);
|
|
2482
|
+
const taskIndex2 = entry.tasks.findIndex((t) => t.id === task.id);
|
|
2483
|
+
const taskEntry = entry.tasks[taskIndex2];
|
|
2484
|
+
if (taskIndex2 !== -1 && taskEntry) {
|
|
2485
|
+
entry.tasks[taskIndex2] = {
|
|
2486
|
+
...taskEntry,
|
|
2487
|
+
status: "Skipped",
|
|
2488
|
+
isQueued: false
|
|
2489
|
+
};
|
|
2490
|
+
this.updateTasks(keycard, identifier, entry.tasks);
|
|
2491
|
+
}
|
|
2492
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2493
|
+
return;
|
|
2494
|
+
}
|
|
2495
|
+
const taskIndex = entry.tasks.findIndex((t) => t.id === task.id);
|
|
2496
|
+
if (taskIndex === -1) {
|
|
2497
|
+
console.log(`[QueueManager] Task ${task.id} was removed. Skipping execution.`);
|
|
2498
|
+
return;
|
|
2499
|
+
}
|
|
2500
|
+
const currentTask = entry.tasks[taskIndex];
|
|
2501
|
+
entry.tasks[taskIndex] = {
|
|
2502
|
+
...currentTask,
|
|
2503
|
+
status: "Running",
|
|
2504
|
+
isQueued: true
|
|
2505
|
+
};
|
|
2506
|
+
this.updateTasks(keycard, identifier, entry.tasks);
|
|
2507
|
+
await this.persistState();
|
|
2508
|
+
const { delayMin, delayMax } = entry.taskConfig || {
|
|
2509
|
+
delayMin: 0,
|
|
2510
|
+
delayMax: 0
|
|
2511
|
+
};
|
|
2512
|
+
if (delayMax > 0) {
|
|
2513
|
+
const delayMs = Math.floor(Math.random() * (delayMax - delayMin + 1) + delayMin) * 1e3;
|
|
2514
|
+
console.log(`[QueueManager] Delaying task ${task.id} for ${delayMs}ms...`);
|
|
2515
|
+
await sleep(delayMs, this.abortControllers.get(key)?.signal);
|
|
2516
|
+
}
|
|
2517
|
+
this.logQueueState(keycard, identifier, `PROCESS_START ${task.id}`);
|
|
2518
|
+
const opts = this.getOptions(keycard);
|
|
2519
|
+
opts.forEach((opt) => opt.onTaskStart?.(keycard, identifier, task.id));
|
|
2520
|
+
this.notifyTasksUpdate(keycard, identifier, entry.tasks);
|
|
2521
|
+
const controller = new AbortController();
|
|
2522
|
+
this.abortControllers.set(task.id, controller);
|
|
2523
|
+
const ctx = new TaskContext(task, controller.signal);
|
|
2524
|
+
try {
|
|
2525
|
+
const result = await Promise.race([
|
|
2526
|
+
engine.execute(ctx),
|
|
2527
|
+
new Promise((_, reject) => {
|
|
2528
|
+
if (ctx.signal?.aborted) {
|
|
2529
|
+
reject(new Error("CANCELLED"));
|
|
2530
|
+
}
|
|
2531
|
+
ctx.signal?.addEventListener(
|
|
2532
|
+
"abort",
|
|
2533
|
+
() => {
|
|
2534
|
+
reject(new Error("CANCELLED"));
|
|
2535
|
+
},
|
|
2536
|
+
{ once: true }
|
|
2537
|
+
);
|
|
2538
|
+
})
|
|
2539
|
+
]);
|
|
2540
|
+
const idx = entry.tasks.findIndex((t) => t.id === task.id);
|
|
2541
|
+
if (idx !== -1) {
|
|
2542
|
+
const finTask = entry.tasks[idx];
|
|
2543
|
+
if (!finTask) return;
|
|
2544
|
+
if (finTask.status !== "Running") {
|
|
2545
|
+
console.log(
|
|
2546
|
+
`Task ${task.id} finished but its status was already changed to ${finTask.status}. Bailing out.`
|
|
2547
|
+
);
|
|
2548
|
+
return;
|
|
2549
|
+
}
|
|
2550
|
+
if (result.error === "CANCELLED") {
|
|
2551
|
+
entry.tasks[idx] = {
|
|
2552
|
+
...finTask,
|
|
2553
|
+
status: "Waiting",
|
|
2554
|
+
isQueued: false
|
|
2555
|
+
};
|
|
2556
|
+
} else {
|
|
2557
|
+
entry.tasks[idx] = {
|
|
2558
|
+
...finTask,
|
|
2559
|
+
status: result.success ? "Completed" : "Error",
|
|
2560
|
+
output: result.output,
|
|
2561
|
+
errorMessage: result.error,
|
|
2562
|
+
progress: result.success ? 100 : 0,
|
|
2563
|
+
isQueued: false
|
|
2564
|
+
};
|
|
2565
|
+
if (result.success) {
|
|
2566
|
+
entry.consecutiveErrors = 0;
|
|
2567
|
+
} else {
|
|
2568
|
+
entry.consecutiveErrors = (entry.consecutiveErrors || 0) + 1;
|
|
2569
|
+
}
|
|
2570
|
+
}
|
|
2571
|
+
this.updateTasks(keycard, identifier, entry.tasks);
|
|
2572
|
+
}
|
|
2573
|
+
opts.forEach((opt) => opt.onTaskComplete?.(keycard, identifier, task.id, result));
|
|
2574
|
+
} catch (error) {
|
|
2575
|
+
const idx = entry.tasks.findIndex((t) => t.id === task.id);
|
|
2576
|
+
const errorTask = entry.tasks[idx];
|
|
2577
|
+
if (idx !== -1 && errorTask) {
|
|
2578
|
+
const isCancelled = error instanceof Error && (error.name === "AbortError" || error.message === "CANCELLED");
|
|
2579
|
+
if (isCancelled) {
|
|
2580
|
+
entry.tasks[idx] = {
|
|
2581
|
+
...errorTask,
|
|
2582
|
+
status: "Waiting",
|
|
2583
|
+
isQueued: false
|
|
2584
|
+
};
|
|
2585
|
+
} else {
|
|
2586
|
+
entry.tasks[idx] = {
|
|
2587
|
+
...errorTask,
|
|
2588
|
+
status: "Error",
|
|
2589
|
+
errorMessage: error instanceof Error ? error.message : String(error),
|
|
2590
|
+
isQueued: false
|
|
2591
|
+
};
|
|
2592
|
+
entry.consecutiveErrors = (entry.consecutiveErrors || 0) + 1;
|
|
2593
|
+
}
|
|
2594
|
+
this.updateTasks(keycard, identifier, entry.tasks);
|
|
2595
|
+
}
|
|
2596
|
+
opts.forEach(
|
|
2597
|
+
(opt) => opt.onTaskComplete?.(keycard, identifier, task.id, {
|
|
2598
|
+
success: false,
|
|
2599
|
+
error: String(error)
|
|
2600
|
+
})
|
|
2601
|
+
);
|
|
2602
|
+
} finally {
|
|
2603
|
+
this.abortControllers.delete(task.id);
|
|
2604
|
+
entry.queuedIds.delete(task.id);
|
|
2605
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2606
|
+
this.notifyTasksUpdate(keycard, identifier, entry.tasks);
|
|
2607
|
+
const maxErrors = entry.taskConfig?.stopOnErrorCount || 0;
|
|
2608
|
+
if (maxErrors > 0 && (entry.consecutiveErrors || 0) >= maxErrors) {
|
|
2609
|
+
console.warn(
|
|
2610
|
+
`[QueueManager] Stopping queue due to ${entry.consecutiveErrors} consecutive errors.`
|
|
2611
|
+
);
|
|
2612
|
+
this.stop(keycard, identifier);
|
|
2613
|
+
entry.consecutiveErrors = 0;
|
|
2614
|
+
}
|
|
2615
|
+
}
|
|
2616
|
+
this.logQueueState(keycard, identifier, `PROCESS_END ${task.id}`);
|
|
2617
|
+
}
|
|
2618
|
+
async autoStopQueue(keycard, identifier) {
|
|
2619
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2620
|
+
const entry = this.queues.get(key);
|
|
2621
|
+
if (entry) {
|
|
2622
|
+
this.runningQueues.delete(key);
|
|
2623
|
+
entry.queue.pause();
|
|
2624
|
+
await this.persistState();
|
|
2625
|
+
this.notifyStatusChange(keycard, identifier);
|
|
2626
|
+
this.notifyTasksUpdate(keycard, identifier, entry.tasks);
|
|
2627
|
+
const opts = this.getOptions(keycard);
|
|
2628
|
+
opts.forEach((opt) => opt.onQueueEmpty?.(keycard, identifier));
|
|
2629
|
+
}
|
|
2630
|
+
}
|
|
2631
|
+
notifyStatusChange(keycard, identifier) {
|
|
2632
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2633
|
+
const entry = this.queues.get(key);
|
|
2634
|
+
const count = (entry?.queue.size || 0) + (entry?.queue.pending || 0);
|
|
2635
|
+
const opts = this.getOptions(keycard);
|
|
2636
|
+
opts.forEach((opt) => opt.onPendingCountChange?.(keycard, identifier, count));
|
|
2637
|
+
}
|
|
2638
|
+
notifyTasksUpdate(keycard, identifier, tasks) {
|
|
2639
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2640
|
+
const entry = this.queues.get(key);
|
|
2641
|
+
const status = {
|
|
2642
|
+
size: entry?.queue.size || 0,
|
|
2643
|
+
pending: entry?.queue.pending || 0,
|
|
2644
|
+
isPaused: entry?.queue.isPaused || false,
|
|
2645
|
+
isRunning: this.runningQueues.has(key)
|
|
2646
|
+
};
|
|
2647
|
+
const opts = this.getOptions(keycard);
|
|
2648
|
+
opts.forEach((opt) => opt.onTasksUpdate?.(keycard, identifier, tasks, status));
|
|
2649
|
+
}
|
|
2650
|
+
// --- PERSISTENCE & HYDRATION ---
|
|
2651
|
+
async persistState() {
|
|
2652
|
+
const states = {};
|
|
2653
|
+
for (const [key, entry] of this.queues.entries()) {
|
|
2654
|
+
states[key] = {
|
|
2655
|
+
isPaused: entry.queue.isPaused,
|
|
2656
|
+
isRunning: this.runningQueues.has(key)
|
|
2657
|
+
};
|
|
2658
|
+
}
|
|
2659
|
+
await persistenceManager.saveQueueStates(states);
|
|
2660
|
+
}
|
|
2661
|
+
updateTaskConfig(keycard, identifier, taskConfig) {
|
|
2662
|
+
const key = this.getQueueKey(keycard, identifier);
|
|
2663
|
+
const entry = this.queues.get(key);
|
|
2664
|
+
if (entry) {
|
|
2665
|
+
entry.taskConfig = taskConfig;
|
|
2666
|
+
entry.queue.concurrency = taskConfig.threads;
|
|
2667
|
+
console.log(`[QueueManager] Updated concurrency for ${key} to ${taskConfig.threads}`);
|
|
2668
|
+
}
|
|
2669
|
+
this.concurrencyMap.set(keycard, taskConfig.threads);
|
|
2670
|
+
}
|
|
2671
|
+
async hydrate() {
|
|
2672
|
+
const states = await persistenceManager.loadQueueStates();
|
|
2673
|
+
if (!states) return;
|
|
2674
|
+
for (const key in states) {
|
|
2675
|
+
const state = states[key];
|
|
2676
|
+
if (!state) continue;
|
|
2677
|
+
const [keycard, identifier] = key.split("__");
|
|
2678
|
+
if (!keycard || !identifier) continue;
|
|
2679
|
+
const entry = this.getOrCreateQueue(keycard, identifier);
|
|
2680
|
+
if (state.isPaused) {
|
|
2681
|
+
entry.queue.pause();
|
|
2682
|
+
} else {
|
|
2683
|
+
entry.queue.start();
|
|
2684
|
+
}
|
|
2685
|
+
if (state.isRunning) {
|
|
2686
|
+
this.runningQueues.add(key);
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
/**
|
|
2691
|
+
* Scans all hydrated queues and re-enqueues tasks that were in "Waiting" or "Running" status.
|
|
2692
|
+
* This ensures tasks resume after Service Worker restarts.
|
|
2693
|
+
*/
|
|
2694
|
+
async rehydrateTasks() {
|
|
2695
|
+
for (const [key, entry] of this.queues.entries()) {
|
|
2696
|
+
const [keycard, identifier] = key.split("__");
|
|
2697
|
+
if (!keycard || !identifier) continue;
|
|
2698
|
+
const tasks = entry.tasks;
|
|
2699
|
+
if (!tasks || tasks.length === 0) continue;
|
|
2700
|
+
for (const task of tasks) {
|
|
2701
|
+
if (task.status === "Running") {
|
|
2702
|
+
task.status = "Waiting";
|
|
2703
|
+
}
|
|
2704
|
+
if (task.status === "Waiting" && task.id && !entry.queuedIds.has(task.id)) {
|
|
2705
|
+
task.isQueued = true;
|
|
2706
|
+
entry.queuedIds.add(task.id);
|
|
2707
|
+
entry.queue.add(() => this.processTask(keycard, identifier, task));
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
this.updateTasks(keycard, identifier, tasks);
|
|
2711
|
+
}
|
|
2712
|
+
await this.persistState();
|
|
2713
|
+
}
|
|
2714
|
+
};
|
|
2715
|
+
var queueManagerInstance = null;
|
|
2716
|
+
function getQueueManager() {
|
|
2717
|
+
if (!queueManagerInstance) {
|
|
2718
|
+
queueManagerInstance = new QueueManager({
|
|
2719
|
+
defaultConcurrency: 1
|
|
2720
|
+
});
|
|
2721
|
+
}
|
|
2722
|
+
return queueManagerInstance;
|
|
2723
|
+
}
|
|
2724
|
+
|
|
2725
|
+
// src/core/commands.ts
|
|
2726
|
+
var QUEUE_COMMAND = {
|
|
2727
|
+
SYNC: "SYNC",
|
|
2728
|
+
CANCEL_TASK: "CANCEL_TASK",
|
|
2729
|
+
CANCEL_TASKS: "CANCEL_TASKS",
|
|
2730
|
+
ADD: "ADD",
|
|
2731
|
+
ADD_MANY: "ADD_MANY",
|
|
2732
|
+
START: "START",
|
|
2733
|
+
STOP: "STOP",
|
|
2734
|
+
PAUSE: "PAUSE",
|
|
2735
|
+
RESUME: "RESUME",
|
|
2736
|
+
CLEAR: "CLEAR",
|
|
2737
|
+
GET_STATUS: "GET_STATUS",
|
|
2738
|
+
GET_TASKS: "GET_TASKS",
|
|
2739
|
+
SET_TASK_CONFIG: "SET_TASK_CONFIG"
|
|
2740
|
+
};
|
|
2741
|
+
|
|
2742
|
+
// node_modules/zustand/esm/vanilla.mjs
|
|
2743
|
+
var createStoreImpl = (createState) => {
|
|
2744
|
+
let state;
|
|
2745
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
2746
|
+
const setState = (partial, replace) => {
|
|
2747
|
+
const nextState = typeof partial === "function" ? partial(state) : partial;
|
|
2748
|
+
if (!Object.is(nextState, state)) {
|
|
2749
|
+
const previousState = state;
|
|
2750
|
+
state = (replace != null ? replace : typeof nextState !== "object" || nextState === null) ? nextState : Object.assign({}, state, nextState);
|
|
2751
|
+
listeners.forEach((listener) => listener(state, previousState));
|
|
2752
|
+
}
|
|
2753
|
+
};
|
|
2754
|
+
const getState = () => state;
|
|
2755
|
+
const getInitialState = () => initialState;
|
|
2756
|
+
const subscribe = (listener) => {
|
|
2757
|
+
listeners.add(listener);
|
|
2758
|
+
return () => listeners.delete(listener);
|
|
2759
|
+
};
|
|
2760
|
+
const api = { setState, getState, getInitialState, subscribe };
|
|
2761
|
+
const initialState = state = createState(setState, getState, api);
|
|
2762
|
+
return api;
|
|
2763
|
+
};
|
|
2764
|
+
var createStore = ((createState) => createState ? createStoreImpl(createState) : createStoreImpl);
|
|
2765
|
+
|
|
2766
|
+
// node_modules/zustand/esm/react.mjs
|
|
2767
|
+
var import_react = __toESM(require_react(), 1);
|
|
2768
|
+
var identity = (arg) => arg;
|
|
2769
|
+
function useStore(api, selector = identity) {
|
|
2770
|
+
const slice = import_react.default.useSyncExternalStore(
|
|
2771
|
+
api.subscribe,
|
|
2772
|
+
import_react.default.useCallback(() => selector(api.getState()), [api, selector]),
|
|
2773
|
+
import_react.default.useCallback(() => selector(api.getInitialState()), [api, selector])
|
|
2774
|
+
);
|
|
2775
|
+
import_react.default.useDebugValue(slice);
|
|
2776
|
+
return slice;
|
|
2777
|
+
}
|
|
2778
|
+
var createImpl = (createState) => {
|
|
2779
|
+
const api = createStore(createState);
|
|
2780
|
+
const useBoundStore = (selector) => useStore(api, selector);
|
|
2781
|
+
Object.assign(useBoundStore, api);
|
|
2782
|
+
return useBoundStore;
|
|
2783
|
+
};
|
|
2784
|
+
var create = ((createState) => createState ? createImpl(createState) : createImpl);
|
|
2785
|
+
|
|
2786
|
+
// node_modules/zustand/esm/middleware.mjs
|
|
2787
|
+
function createJSONStorage(getStorage, options) {
|
|
2788
|
+
let storage;
|
|
2789
|
+
try {
|
|
2790
|
+
storage = getStorage();
|
|
2791
|
+
} catch (e) {
|
|
2792
|
+
return;
|
|
2793
|
+
}
|
|
2794
|
+
const persistStorage = {
|
|
2795
|
+
getItem: (name) => {
|
|
2796
|
+
var _a;
|
|
2797
|
+
const parse = (str2) => {
|
|
2798
|
+
if (str2 === null) {
|
|
2799
|
+
return null;
|
|
2800
|
+
}
|
|
2801
|
+
return JSON.parse(str2, options == null ? void 0 : options.reviver);
|
|
2802
|
+
};
|
|
2803
|
+
const str = (_a = storage.getItem(name)) != null ? _a : null;
|
|
2804
|
+
if (str instanceof Promise) {
|
|
2805
|
+
return str.then(parse);
|
|
2806
|
+
}
|
|
2807
|
+
return parse(str);
|
|
2808
|
+
},
|
|
2809
|
+
setItem: (name, newValue) => storage.setItem(name, JSON.stringify(newValue, options == null ? void 0 : options.replacer)),
|
|
2810
|
+
removeItem: (name) => storage.removeItem(name)
|
|
2811
|
+
};
|
|
2812
|
+
return persistStorage;
|
|
2813
|
+
}
|
|
2814
|
+
var toThenable = (fn) => (input) => {
|
|
2815
|
+
try {
|
|
2816
|
+
const result = fn(input);
|
|
2817
|
+
if (result instanceof Promise) {
|
|
2818
|
+
return result;
|
|
2819
|
+
}
|
|
2820
|
+
return {
|
|
2821
|
+
then(onFulfilled) {
|
|
2822
|
+
return toThenable(onFulfilled)(result);
|
|
2823
|
+
},
|
|
2824
|
+
catch(_onRejected) {
|
|
2825
|
+
return this;
|
|
2826
|
+
}
|
|
2827
|
+
};
|
|
2828
|
+
} catch (e) {
|
|
2829
|
+
return {
|
|
2830
|
+
then(_onFulfilled) {
|
|
2831
|
+
return this;
|
|
2832
|
+
},
|
|
2833
|
+
catch(onRejected) {
|
|
2834
|
+
return toThenable(onRejected)(e);
|
|
2835
|
+
}
|
|
2836
|
+
};
|
|
2837
|
+
}
|
|
2838
|
+
};
|
|
2839
|
+
var persistImpl = (config, baseOptions) => (set, get, api) => {
|
|
2840
|
+
let options = {
|
|
2841
|
+
storage: createJSONStorage(() => window.localStorage),
|
|
2842
|
+
partialize: (state) => state,
|
|
2843
|
+
version: 0,
|
|
2844
|
+
merge: (persistedState, currentState) => ({
|
|
2845
|
+
...currentState,
|
|
2846
|
+
...persistedState
|
|
2847
|
+
}),
|
|
2848
|
+
...baseOptions
|
|
2849
|
+
};
|
|
2850
|
+
let hasHydrated = false;
|
|
2851
|
+
let hydrationVersion = 0;
|
|
2852
|
+
const hydrationListeners = /* @__PURE__ */ new Set();
|
|
2853
|
+
const finishHydrationListeners = /* @__PURE__ */ new Set();
|
|
2854
|
+
let storage = options.storage;
|
|
2855
|
+
if (!storage) {
|
|
2856
|
+
return config(
|
|
2857
|
+
(...args) => {
|
|
2858
|
+
console.warn(
|
|
2859
|
+
`[zustand persist middleware] Unable to update item '${options.name}', the given storage is currently unavailable.`
|
|
2860
|
+
);
|
|
2861
|
+
set(...args);
|
|
2862
|
+
},
|
|
2863
|
+
get,
|
|
2864
|
+
api
|
|
2865
|
+
);
|
|
2866
|
+
}
|
|
2867
|
+
const setItem = () => {
|
|
2868
|
+
const state = options.partialize({ ...get() });
|
|
2869
|
+
return storage.setItem(options.name, {
|
|
2870
|
+
state,
|
|
2871
|
+
version: options.version
|
|
2872
|
+
});
|
|
2873
|
+
};
|
|
2874
|
+
const savedSetState = api.setState;
|
|
2875
|
+
api.setState = (state, replace) => {
|
|
2876
|
+
savedSetState(state, replace);
|
|
2877
|
+
return setItem();
|
|
2878
|
+
};
|
|
2879
|
+
const configResult = config(
|
|
2880
|
+
(...args) => {
|
|
2881
|
+
set(...args);
|
|
2882
|
+
return setItem();
|
|
2883
|
+
},
|
|
2884
|
+
get,
|
|
2885
|
+
api
|
|
2886
|
+
);
|
|
2887
|
+
api.getInitialState = () => configResult;
|
|
2888
|
+
let stateFromStorage;
|
|
2889
|
+
const hydrate = () => {
|
|
2890
|
+
var _a, _b;
|
|
2891
|
+
if (!storage) return;
|
|
2892
|
+
const currentVersion = ++hydrationVersion;
|
|
2893
|
+
hasHydrated = false;
|
|
2894
|
+
hydrationListeners.forEach((cb) => {
|
|
2895
|
+
var _a2;
|
|
2896
|
+
return cb((_a2 = get()) != null ? _a2 : configResult);
|
|
2897
|
+
});
|
|
2898
|
+
const postRehydrationCallback = ((_b = options.onRehydrateStorage) == null ? void 0 : _b.call(options, (_a = get()) != null ? _a : configResult)) || void 0;
|
|
2899
|
+
return toThenable(storage.getItem.bind(storage))(options.name).then((deserializedStorageValue) => {
|
|
2900
|
+
if (deserializedStorageValue) {
|
|
2901
|
+
if (typeof deserializedStorageValue.version === "number" && deserializedStorageValue.version !== options.version) {
|
|
2902
|
+
if (options.migrate) {
|
|
2903
|
+
const migration = options.migrate(
|
|
2904
|
+
deserializedStorageValue.state,
|
|
2905
|
+
deserializedStorageValue.version
|
|
2906
|
+
);
|
|
2907
|
+
if (migration instanceof Promise) {
|
|
2908
|
+
return migration.then((result) => [true, result]);
|
|
2909
|
+
}
|
|
2910
|
+
return [true, migration];
|
|
2911
|
+
}
|
|
2912
|
+
console.error(
|
|
2913
|
+
`State loaded from storage couldn't be migrated since no migrate function was provided`
|
|
2914
|
+
);
|
|
2915
|
+
} else {
|
|
2916
|
+
return [false, deserializedStorageValue.state];
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
return [false, void 0];
|
|
2920
|
+
}).then((migrationResult) => {
|
|
2921
|
+
var _a2;
|
|
2922
|
+
if (currentVersion !== hydrationVersion) {
|
|
2923
|
+
return;
|
|
2924
|
+
}
|
|
2925
|
+
const [migrated, migratedState] = migrationResult;
|
|
2926
|
+
stateFromStorage = options.merge(
|
|
2927
|
+
migratedState,
|
|
2928
|
+
(_a2 = get()) != null ? _a2 : configResult
|
|
2929
|
+
);
|
|
2930
|
+
set(stateFromStorage, true);
|
|
2931
|
+
if (migrated) {
|
|
2932
|
+
return setItem();
|
|
2933
|
+
}
|
|
2934
|
+
}).then(() => {
|
|
2935
|
+
if (currentVersion !== hydrationVersion) {
|
|
2936
|
+
return;
|
|
2937
|
+
}
|
|
2938
|
+
postRehydrationCallback == null ? void 0 : postRehydrationCallback(get(), void 0);
|
|
2939
|
+
stateFromStorage = get();
|
|
2940
|
+
hasHydrated = true;
|
|
2941
|
+
finishHydrationListeners.forEach((cb) => cb(stateFromStorage));
|
|
2942
|
+
}).catch((e) => {
|
|
2943
|
+
if (currentVersion !== hydrationVersion) {
|
|
2944
|
+
return;
|
|
2945
|
+
}
|
|
2946
|
+
postRehydrationCallback == null ? void 0 : postRehydrationCallback(void 0, e);
|
|
2947
|
+
});
|
|
2948
|
+
};
|
|
2949
|
+
api.persist = {
|
|
2950
|
+
setOptions: (newOptions) => {
|
|
2951
|
+
options = {
|
|
2952
|
+
...options,
|
|
2953
|
+
...newOptions
|
|
2954
|
+
};
|
|
2955
|
+
if (newOptions.storage) {
|
|
2956
|
+
storage = newOptions.storage;
|
|
2957
|
+
}
|
|
2958
|
+
},
|
|
2959
|
+
clearStorage: () => {
|
|
2960
|
+
storage == null ? void 0 : storage.removeItem(options.name);
|
|
2961
|
+
},
|
|
2962
|
+
getOptions: () => options,
|
|
2963
|
+
rehydrate: () => hydrate(),
|
|
2964
|
+
hasHydrated: () => hasHydrated,
|
|
2965
|
+
onHydrate: (cb) => {
|
|
2966
|
+
hydrationListeners.add(cb);
|
|
2967
|
+
return () => {
|
|
2968
|
+
hydrationListeners.delete(cb);
|
|
2969
|
+
};
|
|
2970
|
+
},
|
|
2971
|
+
onFinishHydration: (cb) => {
|
|
2972
|
+
finishHydrationListeners.add(cb);
|
|
2973
|
+
return () => {
|
|
2974
|
+
finishHydrationListeners.delete(cb);
|
|
2975
|
+
};
|
|
2976
|
+
}
|
|
2977
|
+
};
|
|
2978
|
+
if (!options.skipHydration) {
|
|
2979
|
+
hydrate();
|
|
2980
|
+
}
|
|
2981
|
+
return stateFromStorage || configResult;
|
|
2982
|
+
};
|
|
2983
|
+
var persist = persistImpl;
|
|
2984
|
+
|
|
2985
|
+
// src/core/store/base-task.store.ts
|
|
2986
|
+
var createTaskStore = (options) => {
|
|
2987
|
+
const { name, storage, partialize, extend } = options;
|
|
2988
|
+
const baseState = {
|
|
2989
|
+
tasks: [],
|
|
2990
|
+
taskHistory: [],
|
|
2991
|
+
pendingCount: 0,
|
|
2992
|
+
isPaused: true,
|
|
2993
|
+
taskConfig: {
|
|
2994
|
+
threads: 1,
|
|
2995
|
+
delayMin: 1,
|
|
2996
|
+
delayMax: 15,
|
|
2997
|
+
stopOnErrorCount: 0
|
|
2998
|
+
}
|
|
2999
|
+
};
|
|
3000
|
+
if (storage) {
|
|
3001
|
+
return create()(
|
|
3002
|
+
persist(
|
|
3003
|
+
(set, get) => ({
|
|
3004
|
+
...baseState,
|
|
3005
|
+
selectedIds: [],
|
|
3006
|
+
generating: false,
|
|
3007
|
+
getTasks: () => get().tasks,
|
|
3008
|
+
setTasks: (tasks) => {
|
|
3009
|
+
const uniqueTasks = Array.from(new Map(tasks.map((t) => [t.id, t])).values());
|
|
3010
|
+
set({ tasks: uniqueTasks });
|
|
3011
|
+
},
|
|
3012
|
+
setPendingCount: (count) => set({ pendingCount: count }),
|
|
3013
|
+
setIsPaused: (paused) => set({ isPaused: paused }),
|
|
3014
|
+
addTask: (task) => set((state) => {
|
|
3015
|
+
if (state.tasks.some((t) => t.id === task.id)) return state;
|
|
3016
|
+
const now = Date.now();
|
|
3017
|
+
const newTask = {
|
|
3018
|
+
...task,
|
|
3019
|
+
createAt: task.createAt || now,
|
|
3020
|
+
updateAt: task.updateAt || now
|
|
3021
|
+
};
|
|
3022
|
+
return { tasks: [...state.tasks, newTask] };
|
|
3023
|
+
}),
|
|
3024
|
+
addTasks: (newTasks) => set((state) => {
|
|
3025
|
+
const existingIds = new Set(state.tasks.map((t) => t.id));
|
|
3026
|
+
const now = Date.now();
|
|
3027
|
+
const filteredNewTasks = newTasks.filter((t) => !existingIds.has(t.id)).map((t) => ({
|
|
3028
|
+
...t,
|
|
3029
|
+
createAt: t.createAt || now,
|
|
3030
|
+
updateAt: t.updateAt || now
|
|
3031
|
+
}));
|
|
3032
|
+
if (filteredNewTasks.length === 0) return state;
|
|
3033
|
+
return { tasks: [...state.tasks, ...filteredNewTasks] };
|
|
3034
|
+
}),
|
|
3035
|
+
updateTask: (taskId, updates) => {
|
|
3036
|
+
set((state) => ({
|
|
3037
|
+
tasks: state.tasks.map(
|
|
3038
|
+
(t) => t.id === taskId ? { ...t, ...updates, updateAt: Date.now() } : t
|
|
3039
|
+
)
|
|
3040
|
+
}));
|
|
3041
|
+
},
|
|
3042
|
+
updateTasks: (updates) => set((state) => ({
|
|
3043
|
+
tasks: state.tasks.map(
|
|
3044
|
+
(t) => updates[t.id] ? { ...t, ...updates[t.id], updateAt: Date.now() } : t
|
|
3045
|
+
)
|
|
3046
|
+
})),
|
|
3047
|
+
deleteTasks: (taskIds) => set((state) => ({
|
|
3048
|
+
tasks: state.tasks.filter((t) => !taskIds.includes(t.id)).map((t, i) => ({ ...t, no: i + 1 })),
|
|
3049
|
+
selectedIds: state.selectedIds.filter((id) => !taskIds.includes(id))
|
|
3050
|
+
})),
|
|
3051
|
+
clearTasks: () => set({ tasks: [], selectedIds: [] }),
|
|
3052
|
+
addHistoryTask: (task) => set((state) => {
|
|
3053
|
+
const newHistory = [task, ...state.taskHistory || []];
|
|
3054
|
+
if (newHistory.length > 1e3) {
|
|
3055
|
+
newHistory.length = 1e3;
|
|
3056
|
+
}
|
|
3057
|
+
return { taskHistory: newHistory };
|
|
3058
|
+
}),
|
|
3059
|
+
clearHistory: () => set({ taskHistory: [] }),
|
|
3060
|
+
toggleSelect: (id) => set((state) => ({
|
|
3061
|
+
selectedIds: state.selectedIds.includes(id) ? state.selectedIds.filter((i) => i !== id) : [...state.selectedIds, id]
|
|
3062
|
+
})),
|
|
3063
|
+
toggleSelectAll: (ids) => set((state) => {
|
|
3064
|
+
const targetIds = ids || state.tasks.map((t) => t.id);
|
|
3065
|
+
const allTargetSelected = targetIds.length > 0 && targetIds.every((id) => state.selectedIds.includes(id));
|
|
3066
|
+
if (allTargetSelected) {
|
|
3067
|
+
return {
|
|
3068
|
+
selectedIds: state.selectedIds.filter((id) => !targetIds.includes(id))
|
|
3069
|
+
};
|
|
3070
|
+
} else {
|
|
3071
|
+
const newSelectedIds = Array.from(/* @__PURE__ */ new Set([...state.selectedIds, ...targetIds]));
|
|
3072
|
+
return { selectedIds: newSelectedIds };
|
|
3073
|
+
}
|
|
3074
|
+
}),
|
|
3075
|
+
setSelectedIds: (ids) => set({ selectedIds: ids }),
|
|
3076
|
+
clearSelected: () => set({ selectedIds: [] }),
|
|
3077
|
+
setGenerating: (generating) => set({ generating }),
|
|
3078
|
+
getIsPaused: () => get().isPaused,
|
|
3079
|
+
getGenerating: () => get().generating,
|
|
3080
|
+
getTaskConfig: () => get().taskConfig,
|
|
3081
|
+
updateTaskConfig: (updates) => set((state) => ({
|
|
3082
|
+
taskConfig: { ...state.taskConfig, ...updates }
|
|
3083
|
+
})),
|
|
3084
|
+
...extend ? extend(set, get) : {}
|
|
3085
|
+
}),
|
|
3086
|
+
{
|
|
3087
|
+
name,
|
|
3088
|
+
storage: createJSONStorage(() => storage),
|
|
3089
|
+
partialize: (state) => {
|
|
3090
|
+
const basePersist = {
|
|
3091
|
+
tasks: state.tasks,
|
|
3092
|
+
taskHistory: state.taskHistory,
|
|
3093
|
+
selectedIds: state.selectedIds,
|
|
3094
|
+
taskConfig: state.taskConfig
|
|
3095
|
+
};
|
|
3096
|
+
const customPersist = partialize ? partialize(state) : {};
|
|
3097
|
+
return {
|
|
3098
|
+
...basePersist,
|
|
3099
|
+
...customPersist
|
|
3100
|
+
};
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
)
|
|
3104
|
+
);
|
|
3105
|
+
}
|
|
3106
|
+
return create()((set, get) => ({
|
|
3107
|
+
...baseState,
|
|
3108
|
+
selectedIds: [],
|
|
3109
|
+
generating: false,
|
|
3110
|
+
getTasks: () => get().tasks,
|
|
3111
|
+
setTasks: (tasks) => {
|
|
3112
|
+
const uniqueTasks = Array.from(new Map(tasks.map((t) => [t.id, t])).values());
|
|
3113
|
+
set({ tasks: uniqueTasks });
|
|
3114
|
+
},
|
|
3115
|
+
setPendingCount: (count) => set({ pendingCount: count }),
|
|
3116
|
+
setIsPaused: (paused) => set({ isPaused: paused }),
|
|
3117
|
+
addTask: (task) => set((state) => {
|
|
3118
|
+
if (state.tasks.some((t) => t.id === task.id)) return state;
|
|
3119
|
+
return { tasks: [...state.tasks, task] };
|
|
3120
|
+
}),
|
|
3121
|
+
addTasks: (newTasks) => set((state) => {
|
|
3122
|
+
const existingIds = new Set(state.tasks.map((t) => t.id));
|
|
3123
|
+
const filteredNewTasks = newTasks.filter((t) => !existingIds.has(t.id));
|
|
3124
|
+
if (filteredNewTasks.length === 0) return state;
|
|
3125
|
+
return { tasks: [...state.tasks, ...filteredNewTasks] };
|
|
3126
|
+
}),
|
|
3127
|
+
updateTask: (taskId, updates) => {
|
|
3128
|
+
set((state) => ({
|
|
3129
|
+
tasks: state.tasks.map((t) => t.id === taskId ? { ...t, ...updates } : t)
|
|
3130
|
+
}));
|
|
3131
|
+
},
|
|
3132
|
+
updateTasks: (updates) => set((state) => ({
|
|
3133
|
+
tasks: state.tasks.map((t) => updates[t.id] ? { ...t, ...updates[t.id] } : t)
|
|
3134
|
+
})),
|
|
3135
|
+
deleteTasks: (taskIds) => set((state) => ({
|
|
3136
|
+
tasks: state.tasks.filter((t) => !taskIds.includes(t.id)).map((t, i) => ({ ...t, no: i + 1 })),
|
|
3137
|
+
selectedIds: state.selectedIds.filter((id) => !taskIds.includes(id))
|
|
3138
|
+
})),
|
|
3139
|
+
clearTasks: () => set({ tasks: [], selectedIds: [] }),
|
|
3140
|
+
addHistoryTask: (task) => set((state) => {
|
|
3141
|
+
const newHistory = [task, ...state.taskHistory || []];
|
|
3142
|
+
if (newHistory.length > 1e3) {
|
|
3143
|
+
newHistory.length = 1e3;
|
|
3144
|
+
}
|
|
3145
|
+
return { taskHistory: newHistory };
|
|
3146
|
+
}),
|
|
3147
|
+
clearHistory: () => set({ taskHistory: [] }),
|
|
3148
|
+
toggleSelect: (id) => set((state) => ({
|
|
3149
|
+
selectedIds: state.selectedIds.includes(id) ? state.selectedIds.filter((i) => i !== id) : [...state.selectedIds, id]
|
|
3150
|
+
})),
|
|
3151
|
+
toggleSelectAll: (ids) => set((state) => {
|
|
3152
|
+
const targetIds = ids || state.tasks.map((t) => t.id);
|
|
3153
|
+
const allTargetSelected = targetIds.length > 0 && targetIds.every((id) => state.selectedIds.includes(id));
|
|
3154
|
+
if (allTargetSelected) {
|
|
3155
|
+
return {
|
|
3156
|
+
selectedIds: state.selectedIds.filter((id) => !targetIds.includes(id))
|
|
3157
|
+
};
|
|
3158
|
+
} else {
|
|
3159
|
+
const newSelectedIds = Array.from(/* @__PURE__ */ new Set([...state.selectedIds, ...targetIds]));
|
|
3160
|
+
return { selectedIds: newSelectedIds };
|
|
3161
|
+
}
|
|
3162
|
+
}),
|
|
3163
|
+
setSelectedIds: (ids) => set({ selectedIds: ids }),
|
|
3164
|
+
clearSelected: () => set({ selectedIds: [] }),
|
|
3165
|
+
setGenerating: (generating) => set({ generating }),
|
|
3166
|
+
getIsPaused: () => get().isPaused,
|
|
3167
|
+
getGenerating: () => get().generating,
|
|
3168
|
+
updateTaskConfig: (updates) => set((state) => ({
|
|
3169
|
+
taskConfig: { ...state.taskConfig, ...updates }
|
|
3170
|
+
})),
|
|
3171
|
+
...extend ? extend(set, get) : {}
|
|
3172
|
+
}));
|
|
3173
|
+
};
|
|
3174
|
+
|
|
3175
|
+
// src/core/hooks/use-queue.ts
|
|
3176
|
+
var import_react2 = __toESM(require_react());
|
|
3177
|
+
function useQueue(config) {
|
|
3178
|
+
return function initQueue() {
|
|
3179
|
+
const { keycard, getIdentifier, funcs } = config;
|
|
3180
|
+
const safeSendMessage = (0, import_react2.useCallback)((msg, callback) => {
|
|
3181
|
+
try {
|
|
3182
|
+
if (!chrome.runtime?.id) {
|
|
3183
|
+
console.warn("Extension context invalidated.");
|
|
3184
|
+
return;
|
|
3185
|
+
}
|
|
3186
|
+
chrome.runtime.sendMessage(msg, (response) => {
|
|
3187
|
+
if (chrome.runtime.lastError) {
|
|
3188
|
+
console.warn("Message failed:", chrome.runtime.lastError.message);
|
|
3189
|
+
return;
|
|
3190
|
+
}
|
|
3191
|
+
callback?.(response);
|
|
3192
|
+
});
|
|
3193
|
+
} catch (e) {
|
|
3194
|
+
console.error("Critical messaging error:", e);
|
|
3195
|
+
}
|
|
3196
|
+
}, []);
|
|
3197
|
+
const lastInitializedRef = (0, import_react2.useRef)(void 0);
|
|
3198
|
+
const identifier = getIdentifier();
|
|
3199
|
+
(0, import_react2.useEffect)(() => {
|
|
3200
|
+
const currentId = identifier || "";
|
|
3201
|
+
const needsSync = lastInitializedRef.current !== currentId;
|
|
3202
|
+
if (needsSync) {
|
|
3203
|
+
lastInitializedRef.current = currentId;
|
|
3204
|
+
safeSendMessage(
|
|
3205
|
+
{
|
|
3206
|
+
type: "QUEUE_COMMAND",
|
|
3207
|
+
command: QUEUE_COMMAND.SYNC,
|
|
3208
|
+
keycard,
|
|
3209
|
+
identifier
|
|
3210
|
+
},
|
|
3211
|
+
(response) => {
|
|
3212
|
+
if (response) {
|
|
3213
|
+
if (response.tasks && response.tasks.length > 0) {
|
|
3214
|
+
funcs.setTasks(response.tasks);
|
|
3215
|
+
} else {
|
|
3216
|
+
const localTasks = funcs.getTasks();
|
|
3217
|
+
if (localTasks.length > 0) {
|
|
3218
|
+
safeSendMessage({
|
|
3219
|
+
type: "QUEUE_COMMAND",
|
|
3220
|
+
command: QUEUE_COMMAND.ADD_MANY,
|
|
3221
|
+
keycard,
|
|
3222
|
+
identifier,
|
|
3223
|
+
payload: { tasks: localTasks }
|
|
3224
|
+
});
|
|
3225
|
+
}
|
|
3226
|
+
}
|
|
3227
|
+
if (response.status) {
|
|
3228
|
+
funcs.setPendingCount(response.status.size + response.status.pending);
|
|
3229
|
+
funcs.setIsPaused(response.status.isPaused);
|
|
3230
|
+
}
|
|
3231
|
+
}
|
|
3232
|
+
}
|
|
3233
|
+
);
|
|
3234
|
+
}
|
|
3235
|
+
const handleMessage = (message) => {
|
|
3236
|
+
if (message.type === "QUEUE_EVENT") {
|
|
3237
|
+
const { event, keycard: pid, identifier: pjid, data } = message;
|
|
3238
|
+
const isPlatformMatch = pid === keycard || pid === "*";
|
|
3239
|
+
const isIdentifierMatch = (pjid || "") === (identifier || "") || pid === "*";
|
|
3240
|
+
if (!isPlatformMatch || !isIdentifierMatch) return;
|
|
3241
|
+
switch (event) {
|
|
3242
|
+
case "TASKS_UPDATED": {
|
|
3243
|
+
console.log("TASKS_UPDATED", data);
|
|
3244
|
+
const updates = {};
|
|
3245
|
+
data.tasks.forEach((t) => {
|
|
3246
|
+
updates[t.id] = t;
|
|
3247
|
+
});
|
|
3248
|
+
funcs.updateTasks(updates);
|
|
3249
|
+
funcs.setPendingCount(data.status.size + data.status.pending);
|
|
3250
|
+
funcs.setIsPaused(data.status.isPaused);
|
|
3251
|
+
break;
|
|
3252
|
+
}
|
|
3253
|
+
case "PENDING_COUNT_CHANGED":
|
|
3254
|
+
funcs.setPendingCount(data.count);
|
|
3255
|
+
break;
|
|
3256
|
+
case "HISTORY_ADDED":
|
|
3257
|
+
if (funcs.addHistoryTask) {
|
|
3258
|
+
funcs.addHistoryTask(data.task);
|
|
3259
|
+
}
|
|
3260
|
+
break;
|
|
3261
|
+
}
|
|
3262
|
+
}
|
|
3263
|
+
};
|
|
3264
|
+
chrome.runtime.onMessage.addListener(handleMessage);
|
|
3265
|
+
return () => {
|
|
3266
|
+
chrome.runtime.onMessage.removeListener(handleMessage);
|
|
3267
|
+
};
|
|
3268
|
+
}, [keycard, identifier, funcs, safeSendMessage]);
|
|
3269
|
+
const sendQueueCommand = (0, import_react2.useCallback)(
|
|
3270
|
+
async (command, payload) => {
|
|
3271
|
+
const identifier2 = getIdentifier();
|
|
3272
|
+
return new Promise((resolve) => {
|
|
3273
|
+
safeSendMessage(
|
|
3274
|
+
{
|
|
3275
|
+
type: "QUEUE_COMMAND",
|
|
3276
|
+
command,
|
|
3277
|
+
keycard,
|
|
3278
|
+
identifier: identifier2,
|
|
3279
|
+
payload
|
|
3280
|
+
},
|
|
3281
|
+
resolve
|
|
3282
|
+
);
|
|
3283
|
+
});
|
|
3284
|
+
},
|
|
3285
|
+
[keycard, getIdentifier, safeSendMessage]
|
|
3286
|
+
);
|
|
3287
|
+
const addTask = (0, import_react2.useCallback)(
|
|
3288
|
+
async (task) => {
|
|
3289
|
+
return sendQueueCommand(QUEUE_COMMAND.ADD, { task });
|
|
3290
|
+
},
|
|
3291
|
+
[sendQueueCommand, funcs]
|
|
3292
|
+
);
|
|
3293
|
+
const start = (0, import_react2.useCallback)(async () => {
|
|
3294
|
+
console.log(QUEUE_COMMAND.START);
|
|
3295
|
+
return sendQueueCommand(QUEUE_COMMAND.START);
|
|
3296
|
+
}, [sendQueueCommand, funcs]);
|
|
3297
|
+
const stop = (0, import_react2.useCallback)(async () => {
|
|
3298
|
+
console.log(QUEUE_COMMAND.STOP);
|
|
3299
|
+
return sendQueueCommand(QUEUE_COMMAND.STOP);
|
|
3300
|
+
}, [sendQueueCommand, funcs]);
|
|
3301
|
+
const pause = (0, import_react2.useCallback)(async () => {
|
|
3302
|
+
return sendQueueCommand(QUEUE_COMMAND.PAUSE);
|
|
3303
|
+
}, [sendQueueCommand]);
|
|
3304
|
+
const resume = (0, import_react2.useCallback)(async () => {
|
|
3305
|
+
return sendQueueCommand(QUEUE_COMMAND.RESUME);
|
|
3306
|
+
}, [sendQueueCommand]);
|
|
3307
|
+
const clear = (0, import_react2.useCallback)(async () => {
|
|
3308
|
+
return sendQueueCommand(QUEUE_COMMAND.CLEAR);
|
|
3309
|
+
}, [sendQueueCommand]);
|
|
3310
|
+
const getStatus = (0, import_react2.useCallback)(async () => {
|
|
3311
|
+
return sendQueueCommand(QUEUE_COMMAND.GET_STATUS);
|
|
3312
|
+
}, [sendQueueCommand]);
|
|
3313
|
+
const getTasks = (0, import_react2.useCallback)(async () => {
|
|
3314
|
+
return sendQueueCommand(QUEUE_COMMAND.GET_TASKS);
|
|
3315
|
+
}, [sendQueueCommand]);
|
|
3316
|
+
const cancelTask = (0, import_react2.useCallback)(
|
|
3317
|
+
async (taskId) => {
|
|
3318
|
+
return sendQueueCommand(QUEUE_COMMAND.CANCEL_TASK, { taskId });
|
|
3319
|
+
},
|
|
3320
|
+
[sendQueueCommand]
|
|
3321
|
+
);
|
|
3322
|
+
const cancelTasks = (0, import_react2.useCallback)(
|
|
3323
|
+
async (taskIds) => {
|
|
3324
|
+
return sendQueueCommand(QUEUE_COMMAND.CANCEL_TASKS, { taskIds });
|
|
3325
|
+
},
|
|
3326
|
+
[sendQueueCommand]
|
|
3327
|
+
);
|
|
3328
|
+
const setTaskConfig = (0, import_react2.useCallback)((taskConfig) => {
|
|
3329
|
+
return sendQueueCommand(QUEUE_COMMAND.SET_TASK_CONFIG, { taskConfig });
|
|
3330
|
+
}, []);
|
|
3331
|
+
const publishTasks = (0, import_react2.useCallback)(
|
|
3332
|
+
async (tasks) => {
|
|
3333
|
+
await sendQueueCommand(QUEUE_COMMAND.ADD_MANY, {
|
|
3334
|
+
tasks: tasks.map((t) => ({
|
|
3335
|
+
...t,
|
|
3336
|
+
status: "Waiting",
|
|
3337
|
+
isQueued: true
|
|
3338
|
+
}))
|
|
3339
|
+
});
|
|
3340
|
+
},
|
|
3341
|
+
[funcs, sendQueueCommand]
|
|
3342
|
+
);
|
|
3343
|
+
const deleteTasks = (0, import_react2.useCallback)(
|
|
3344
|
+
async (taskIds) => {
|
|
3345
|
+
if (taskIds.length === 0) return;
|
|
3346
|
+
await sendQueueCommand(QUEUE_COMMAND.CANCEL_TASKS, { taskIds });
|
|
3347
|
+
funcs.deleteTasks(taskIds);
|
|
3348
|
+
},
|
|
3349
|
+
[funcs, sendQueueCommand]
|
|
3350
|
+
);
|
|
3351
|
+
const skipTaskIds = (0, import_react2.useCallback)(
|
|
3352
|
+
async (taskIds) => {
|
|
3353
|
+
if (taskIds.length === 0) return;
|
|
3354
|
+
await sendQueueCommand("CANCEL_TASKS", { taskIds });
|
|
3355
|
+
const updates = {};
|
|
3356
|
+
taskIds.forEach((id) => {
|
|
3357
|
+
updates[id] = { status: "Skipped", isQueued: false, isFlagged: true };
|
|
3358
|
+
});
|
|
3359
|
+
funcs.updateTasks(updates);
|
|
3360
|
+
},
|
|
3361
|
+
[funcs, sendQueueCommand]
|
|
3362
|
+
);
|
|
3363
|
+
const retryTasks = (0, import_react2.useCallback)(
|
|
3364
|
+
async (taskIds) => {
|
|
3365
|
+
const tasks = funcs.getTasks().filter((t) => taskIds.includes(t.id));
|
|
3366
|
+
if (tasks.length === 0) return;
|
|
3367
|
+
tasks.forEach((task) => {
|
|
3368
|
+
funcs.updateTask(task.id, {
|
|
3369
|
+
status: "Waiting",
|
|
3370
|
+
errorMessage: void 0,
|
|
3371
|
+
isQueued: true
|
|
3372
|
+
});
|
|
3373
|
+
});
|
|
3374
|
+
await sendQueueCommand(QUEUE_COMMAND.ADD_MANY, {
|
|
3375
|
+
tasks: tasks.map((t) => ({
|
|
3376
|
+
...t,
|
|
3377
|
+
status: "Waiting",
|
|
3378
|
+
errorMessage: void 0,
|
|
3379
|
+
isQueued: true
|
|
3380
|
+
}))
|
|
3381
|
+
});
|
|
3382
|
+
},
|
|
3383
|
+
[funcs, sendQueueCommand]
|
|
3384
|
+
);
|
|
3385
|
+
return {
|
|
3386
|
+
addTask,
|
|
3387
|
+
start,
|
|
3388
|
+
stop,
|
|
3389
|
+
pause,
|
|
3390
|
+
resume,
|
|
3391
|
+
clear,
|
|
3392
|
+
getStatus,
|
|
3393
|
+
getTasks,
|
|
3394
|
+
cancelTask,
|
|
3395
|
+
cancelTasks,
|
|
3396
|
+
publishTasks,
|
|
3397
|
+
deleteTasks,
|
|
3398
|
+
retryTasks,
|
|
3399
|
+
skipTaskIds,
|
|
3400
|
+
setTaskConfig
|
|
3401
|
+
};
|
|
3402
|
+
};
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
// src/core/registry.ts
|
|
3406
|
+
function registerAllEngines(platformEngines, queueManager) {
|
|
3407
|
+
Object.entries(platformEngines).forEach(([keycard, engine]) => {
|
|
3408
|
+
queueManager.registerEngine(keycard, engine);
|
|
3409
|
+
});
|
|
3410
|
+
}
|
|
3411
|
+
|
|
3412
|
+
// src/core/bootstrap.ts
|
|
3413
|
+
var setupBackgroundEngine = (engines) => {
|
|
3414
|
+
const queueManager = getQueueManager();
|
|
3415
|
+
registerAllEngines(engines, queueManager);
|
|
3416
|
+
const broadcast = (message) => {
|
|
3417
|
+
chrome.runtime.sendMessage(message).catch(() => {
|
|
3418
|
+
});
|
|
3419
|
+
};
|
|
3420
|
+
const handleHeartbeat = (count) => {
|
|
3421
|
+
if (count > 0) {
|
|
3422
|
+
chrome.alarms.create("heartbeat", { periodInMinutes: 0.5 });
|
|
3423
|
+
} else {
|
|
3424
|
+
chrome.alarms.clear("heartbeat");
|
|
3425
|
+
}
|
|
3426
|
+
};
|
|
3427
|
+
queueManager.registerOptions("*", {
|
|
3428
|
+
onTasksUpdate: (keycard, identifier, tasks, status) => {
|
|
3429
|
+
broadcast({
|
|
3430
|
+
type: "QUEUE_EVENT",
|
|
3431
|
+
event: "TASKS_UPDATED",
|
|
3432
|
+
keycard,
|
|
3433
|
+
identifier,
|
|
3434
|
+
data: { tasks, status }
|
|
3435
|
+
});
|
|
3436
|
+
},
|
|
3437
|
+
onTaskComplete: (keycard, identifier, _, result) => {
|
|
3438
|
+
const isCancelled = result.error === "CANCELLED" || result.error === "AbortError";
|
|
3439
|
+
if (!isCancelled) {
|
|
3440
|
+
broadcast({
|
|
3441
|
+
type: "QUEUE_EVENT",
|
|
3442
|
+
event: "HISTORY_ADDED",
|
|
3443
|
+
keycard,
|
|
3444
|
+
identifier,
|
|
3445
|
+
data: { task: [] }
|
|
3446
|
+
});
|
|
3447
|
+
}
|
|
3448
|
+
},
|
|
3449
|
+
onPendingCountChange: (keycard, identifier, count) => {
|
|
3450
|
+
broadcast({
|
|
3451
|
+
type: "QUEUE_EVENT",
|
|
3452
|
+
event: "PENDING_COUNT_CHANGED",
|
|
3453
|
+
keycard,
|
|
3454
|
+
identifier,
|
|
3455
|
+
data: { count }
|
|
3456
|
+
});
|
|
3457
|
+
handleHeartbeat(count);
|
|
3458
|
+
}
|
|
3459
|
+
});
|
|
3460
|
+
const bootstrap = async () => {
|
|
3461
|
+
try {
|
|
3462
|
+
console.log("\u{1F680} Bootstrapping Background Queue Manager...");
|
|
3463
|
+
await queueManager.hydrate();
|
|
3464
|
+
await queueManager.rehydrateTasks();
|
|
3465
|
+
console.log("\u2705 Background Queue Manager Ready.");
|
|
3466
|
+
} catch (error) {
|
|
3467
|
+
console.error("\u274C Bootstrap failed:", error);
|
|
3468
|
+
}
|
|
3469
|
+
};
|
|
3470
|
+
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
|
|
3471
|
+
if (message.type === "QUEUE_COMMAND") {
|
|
3472
|
+
const { command, keycard, identifier, payload } = message;
|
|
3473
|
+
const handleAsyncCommand = async (promise) => {
|
|
3474
|
+
await promise;
|
|
3475
|
+
sendResponse({ success: true });
|
|
3476
|
+
};
|
|
3477
|
+
switch (command) {
|
|
3478
|
+
case QUEUE_COMMAND.SYNC:
|
|
3479
|
+
sendResponse({
|
|
3480
|
+
tasks: queueManager.getTasks(keycard, identifier),
|
|
3481
|
+
status: queueManager.getStatus(keycard, identifier)
|
|
3482
|
+
});
|
|
3483
|
+
break;
|
|
3484
|
+
case QUEUE_COMMAND.CANCEL_TASK:
|
|
3485
|
+
handleAsyncCommand(queueManager.cancelTask(keycard, identifier, payload.taskId));
|
|
3486
|
+
return true;
|
|
3487
|
+
// Keep connection to send response later
|
|
3488
|
+
case QUEUE_COMMAND.CANCEL_TASKS:
|
|
3489
|
+
handleAsyncCommand(
|
|
3490
|
+
Promise.all(
|
|
3491
|
+
payload.taskIds.map((id) => queueManager.cancelTask(keycard, identifier, id))
|
|
3492
|
+
)
|
|
3493
|
+
);
|
|
3494
|
+
return true;
|
|
3495
|
+
case QUEUE_COMMAND.ADD:
|
|
3496
|
+
handleAsyncCommand(queueManager.add(keycard, identifier, payload.task));
|
|
3497
|
+
return true;
|
|
3498
|
+
case QUEUE_COMMAND.ADD_MANY:
|
|
3499
|
+
handleAsyncCommand(queueManager.addMany(keycard, identifier, payload.tasks));
|
|
3500
|
+
return true;
|
|
3501
|
+
case QUEUE_COMMAND.START:
|
|
3502
|
+
handleAsyncCommand(queueManager.start(keycard, identifier));
|
|
3503
|
+
return true;
|
|
3504
|
+
case QUEUE_COMMAND.STOP:
|
|
3505
|
+
handleAsyncCommand(queueManager.stop(keycard, identifier));
|
|
3506
|
+
return true;
|
|
3507
|
+
case QUEUE_COMMAND.PAUSE:
|
|
3508
|
+
handleAsyncCommand(queueManager.pause(keycard, identifier));
|
|
3509
|
+
return true;
|
|
3510
|
+
case QUEUE_COMMAND.RESUME:
|
|
3511
|
+
handleAsyncCommand(queueManager.resume(keycard, identifier));
|
|
3512
|
+
return true;
|
|
3513
|
+
case QUEUE_COMMAND.CLEAR:
|
|
3514
|
+
handleAsyncCommand(queueManager.clear(keycard, identifier));
|
|
3515
|
+
return true;
|
|
3516
|
+
case QUEUE_COMMAND.GET_STATUS:
|
|
3517
|
+
sendResponse(queueManager.getStatus(keycard, identifier));
|
|
3518
|
+
break;
|
|
3519
|
+
case QUEUE_COMMAND.GET_TASKS:
|
|
3520
|
+
sendResponse({ tasks: queueManager.getTasks(keycard, identifier) });
|
|
3521
|
+
break;
|
|
3522
|
+
case QUEUE_COMMAND.SET_TASK_CONFIG:
|
|
3523
|
+
queueManager.updateTaskConfig(keycard, identifier, payload.taskConfig);
|
|
3524
|
+
sendResponse({ success: true });
|
|
3525
|
+
break;
|
|
3526
|
+
default:
|
|
3527
|
+
console.warn(`[Queue] Unknown command: ${command}`);
|
|
3528
|
+
break;
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
if (message.type === "PING") {
|
|
3532
|
+
sendResponse({ payload: "PONG from background" });
|
|
3533
|
+
}
|
|
3534
|
+
});
|
|
3535
|
+
chrome.alarms.onAlarm.addListener((alarm) => {
|
|
3536
|
+
if (alarm.name === "heartbeat") {
|
|
3537
|
+
console.debug("Service Worker Heartbeat...");
|
|
3538
|
+
}
|
|
3539
|
+
});
|
|
3540
|
+
chrome.runtime.onInstalled.addListener(() => {
|
|
3541
|
+
console.log("Auto Script Extension Installed");
|
|
3542
|
+
});
|
|
3543
|
+
chrome.commands.onCommand.addListener((command) => {
|
|
3544
|
+
if (command === "open-popup") {
|
|
3545
|
+
chrome.action.openPopup().catch((err) => console.error("Failed to open popup", err));
|
|
3546
|
+
}
|
|
3547
|
+
});
|
|
3548
|
+
bootstrap();
|
|
3549
|
+
};
|
|
3550
|
+
export {
|
|
3551
|
+
QUEUE_COMMAND,
|
|
3552
|
+
QueueManager,
|
|
3553
|
+
TaskContext,
|
|
3554
|
+
createTaskStore,
|
|
3555
|
+
engineHub,
|
|
3556
|
+
getQueueManager,
|
|
3557
|
+
persistenceManager,
|
|
3558
|
+
registerAllEngines,
|
|
3559
|
+
setupBackgroundEngine,
|
|
3560
|
+
sleep,
|
|
3561
|
+
useQueue
|
|
3562
|
+
};
|
|
3563
|
+
/*! Bundled license information:
|
|
3564
|
+
|
|
3565
|
+
react/cjs/react.development.js:
|
|
3566
|
+
(**
|
|
3567
|
+
* @license React
|
|
3568
|
+
* react.development.js
|
|
3569
|
+
*
|
|
3570
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3571
|
+
*
|
|
3572
|
+
* This source code is licensed under the MIT license found in the
|
|
3573
|
+
* LICENSE file in the root directory of this source tree.
|
|
3574
|
+
*)
|
|
3575
|
+
*/
|