@clazic/kordoc 2.4.19 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-AEWWERJ5.js +35 -0
- package/dist/chunk-AEWWERJ5.js.map +1 -0
- package/dist/chunk-CPTOBJJD.js +125 -0
- package/dist/chunk-CPTOBJJD.js.map +1 -0
- package/dist/{chunk-MZN7PLTZ.js → chunk-IJGNPAK2.js} +2 -2
- package/dist/{chunk-MZN7PLTZ.js.map → chunk-IJGNPAK2.js.map} +1 -1
- package/dist/{chunk-463YQ2WL.js → chunk-NKUNXGWI.js} +4 -6
- package/dist/chunk-NKUNXGWI.js.map +1 -0
- package/dist/chunk-THBLCND6.js +33 -0
- package/dist/chunk-THBLCND6.js.map +1 -0
- package/dist/cli.js +37 -5
- package/dist/cli.js.map +1 -1
- package/dist/doctor-SJ7NYSXC.js +126 -0
- package/dist/doctor-SJ7NYSXC.js.map +1 -0
- package/dist/index.cjs +2591 -82
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2604 -94
- package/dist/index.js.map +1 -1
- package/dist/install-commands-P2KTEXQ4.js +11 -0
- package/dist/mcp.js +5 -2
- package/dist/mcp.js.map +1 -1
- package/dist/pm-7KGLH6MX.js +9 -0
- package/dist/pm-7KGLH6MX.js.map +1 -0
- package/dist/setup/doctor.cjs +308 -0
- package/dist/setup/doctor.js +288 -0
- package/dist/{utils-YUAT7LFD.js → utils-RBXHHCLI.js} +2 -2
- package/dist/utils-RBXHHCLI.js.map +1 -0
- package/dist/{watch-WEOFVVDO.js → watch-FRLS6FKE.js} +6 -3
- package/dist/{watch-WEOFVVDO.js.map → watch-FRLS6FKE.js.map} +1 -1
- package/package.json +7 -3
- package/scripts/postinstall.cjs +27 -0
- package/dist/chunk-463YQ2WL.js.map +0 -1
- /package/dist/{utils-YUAT7LFD.js.map → install-commands-P2KTEXQ4.js.map} +0 -0
package/dist/index.js
CHANGED
|
@@ -36,6 +36,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
36
36
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
37
|
mod
|
|
38
38
|
));
|
|
39
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
39
40
|
|
|
40
41
|
// src/page-range.ts
|
|
41
42
|
var page_range_exports = {};
|
|
@@ -126,9 +127,9 @@ function sanitizeMeta(meta, cfg) {
|
|
|
126
127
|
}
|
|
127
128
|
return out;
|
|
128
129
|
}
|
|
129
|
-
function parsePositiveInt(input,
|
|
130
|
+
function parsePositiveInt(input, fallback2) {
|
|
130
131
|
const n = Number(input);
|
|
131
|
-
if (!Number.isFinite(n) || n < 0) return
|
|
132
|
+
if (!Number.isFinite(n) || n < 0) return fallback2;
|
|
132
133
|
return Math.floor(n);
|
|
133
134
|
}
|
|
134
135
|
function limitText(input, maxLen) {
|
|
@@ -293,9 +294,9 @@ var init_logger = __esm({
|
|
|
293
294
|
}
|
|
294
295
|
});
|
|
295
296
|
|
|
296
|
-
// node_modules/cfb/cfb.js
|
|
297
|
+
// ../../../node_modules/cfb/cfb.js
|
|
297
298
|
var require_cfb = __commonJS({
|
|
298
|
-
"node_modules/cfb/cfb.js"(exports, module) {
|
|
299
|
+
"../../../node_modules/cfb/cfb.js"(exports, module) {
|
|
299
300
|
"use strict";
|
|
300
301
|
var Base64_map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
301
302
|
function Base64_encode(input) {
|
|
@@ -2475,7 +2476,7 @@ function createBatchCliProvider(mode, batchSize) {
|
|
|
2475
2476
|
};
|
|
2476
2477
|
}
|
|
2477
2478
|
function spawnAsync(cmd, args, opts) {
|
|
2478
|
-
return new Promise((resolve4,
|
|
2479
|
+
return new Promise((resolve4, reject2) => {
|
|
2479
2480
|
const child = spawn(cmd, args, {
|
|
2480
2481
|
cwd: opts.cwd,
|
|
2481
2482
|
env: process.env,
|
|
@@ -2509,14 +2510,14 @@ function spawnAsync(cmd, args, opts) {
|
|
|
2509
2510
|
child.on("close", (code) => {
|
|
2510
2511
|
clearTimeout(timer);
|
|
2511
2512
|
if (killed) {
|
|
2512
|
-
|
|
2513
|
+
reject2(new Error(`\uD0C0\uC784\uC544\uC6C3 (${Math.round(opts.timeoutMs / 1e3)}\uCD08)`));
|
|
2513
2514
|
} else {
|
|
2514
2515
|
resolve4({ stdout, stderr, exitCode: code ?? 1 });
|
|
2515
2516
|
}
|
|
2516
2517
|
});
|
|
2517
2518
|
child.on("error", (err) => {
|
|
2518
2519
|
clearTimeout(timer);
|
|
2519
|
-
|
|
2520
|
+
reject2(err);
|
|
2520
2521
|
});
|
|
2521
2522
|
});
|
|
2522
2523
|
}
|
|
@@ -2934,9 +2935,9 @@ async function ocrPagesBatch(doc, provider, pageFilter, effectivePageCount, warn
|
|
|
2934
2935
|
});
|
|
2935
2936
|
}
|
|
2936
2937
|
} catch (err) {
|
|
2937
|
-
const
|
|
2938
|
+
const range2 = `${batchPageNums[0]}-${batchPageNums[batchPageNums.length - 1]}`;
|
|
2938
2939
|
warnings?.push({
|
|
2939
|
-
message: `\uBC30\uCE58 OCR \uC2E4\uD328 (\uD398\uC774\uC9C0 ${
|
|
2940
|
+
message: `\uBC30\uCE58 OCR \uC2E4\uD328 (\uD398\uC774\uC9C0 ${range2}): ${err instanceof Error ? err.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"} \u2014 \uB2E8\uC77C \uD398\uC774\uC9C0\uB85C \uC7AC\uC2DC\uB3C4`,
|
|
2940
2941
|
code: "OCR_PAGE_FAILED"
|
|
2941
2942
|
});
|
|
2942
2943
|
for (const { image, pageNum } of batchImages) {
|
|
@@ -2981,6 +2982,2320 @@ var init_provider = __esm({
|
|
|
2981
2982
|
}
|
|
2982
2983
|
});
|
|
2983
2984
|
|
|
2985
|
+
// ../../../node_modules/async/dist/async.mjs
|
|
2986
|
+
var async_exports = {};
|
|
2987
|
+
__export(async_exports, {
|
|
2988
|
+
all: () => every$1,
|
|
2989
|
+
allLimit: () => everyLimit$1,
|
|
2990
|
+
allSeries: () => everySeries$1,
|
|
2991
|
+
any: () => some$1,
|
|
2992
|
+
anyLimit: () => someLimit$1,
|
|
2993
|
+
anySeries: () => someSeries$1,
|
|
2994
|
+
apply: () => apply,
|
|
2995
|
+
applyEach: () => applyEach,
|
|
2996
|
+
applyEachSeries: () => applyEachSeries,
|
|
2997
|
+
asyncify: () => asyncify,
|
|
2998
|
+
auto: () => auto,
|
|
2999
|
+
autoInject: () => autoInject,
|
|
3000
|
+
cargo: () => cargo$1,
|
|
3001
|
+
cargoQueue: () => cargo,
|
|
3002
|
+
compose: () => compose,
|
|
3003
|
+
concat: () => concat$1,
|
|
3004
|
+
concatLimit: () => concatLimit$1,
|
|
3005
|
+
concatSeries: () => concatSeries$1,
|
|
3006
|
+
constant: () => constant$1,
|
|
3007
|
+
default: () => index,
|
|
3008
|
+
detect: () => detect$1,
|
|
3009
|
+
detectLimit: () => detectLimit$1,
|
|
3010
|
+
detectSeries: () => detectSeries$1,
|
|
3011
|
+
dir: () => dir,
|
|
3012
|
+
doDuring: () => doWhilst$1,
|
|
3013
|
+
doUntil: () => doUntil,
|
|
3014
|
+
doWhilst: () => doWhilst$1,
|
|
3015
|
+
during: () => whilst$1,
|
|
3016
|
+
each: () => each,
|
|
3017
|
+
eachLimit: () => eachLimit$1,
|
|
3018
|
+
eachOf: () => eachOf$1,
|
|
3019
|
+
eachOfLimit: () => eachOfLimit$1,
|
|
3020
|
+
eachOfSeries: () => eachOfSeries$1,
|
|
3021
|
+
eachSeries: () => eachSeries$1,
|
|
3022
|
+
ensureAsync: () => ensureAsync,
|
|
3023
|
+
every: () => every$1,
|
|
3024
|
+
everyLimit: () => everyLimit$1,
|
|
3025
|
+
everySeries: () => everySeries$1,
|
|
3026
|
+
filter: () => filter$1,
|
|
3027
|
+
filterLimit: () => filterLimit$1,
|
|
3028
|
+
filterSeries: () => filterSeries$1,
|
|
3029
|
+
find: () => detect$1,
|
|
3030
|
+
findLimit: () => detectLimit$1,
|
|
3031
|
+
findSeries: () => detectSeries$1,
|
|
3032
|
+
flatMap: () => concat$1,
|
|
3033
|
+
flatMapLimit: () => concatLimit$1,
|
|
3034
|
+
flatMapSeries: () => concatSeries$1,
|
|
3035
|
+
foldl: () => reduce$1,
|
|
3036
|
+
foldr: () => reduceRight,
|
|
3037
|
+
forEach: () => each,
|
|
3038
|
+
forEachLimit: () => eachLimit$1,
|
|
3039
|
+
forEachOf: () => eachOf$1,
|
|
3040
|
+
forEachOfLimit: () => eachOfLimit$1,
|
|
3041
|
+
forEachOfSeries: () => eachOfSeries$1,
|
|
3042
|
+
forEachSeries: () => eachSeries$1,
|
|
3043
|
+
forever: () => forever$1,
|
|
3044
|
+
groupBy: () => groupBy,
|
|
3045
|
+
groupByLimit: () => groupByLimit$1,
|
|
3046
|
+
groupBySeries: () => groupBySeries,
|
|
3047
|
+
inject: () => reduce$1,
|
|
3048
|
+
log: () => log,
|
|
3049
|
+
map: () => map$1,
|
|
3050
|
+
mapLimit: () => mapLimit$1,
|
|
3051
|
+
mapSeries: () => mapSeries$1,
|
|
3052
|
+
mapValues: () => mapValues,
|
|
3053
|
+
mapValuesLimit: () => mapValuesLimit$1,
|
|
3054
|
+
mapValuesSeries: () => mapValuesSeries,
|
|
3055
|
+
memoize: () => memoize,
|
|
3056
|
+
nextTick: () => nextTick,
|
|
3057
|
+
parallel: () => parallel,
|
|
3058
|
+
parallelLimit: () => parallelLimit,
|
|
3059
|
+
priorityQueue: () => priorityQueue,
|
|
3060
|
+
queue: () => queue,
|
|
3061
|
+
race: () => race$1,
|
|
3062
|
+
reduce: () => reduce$1,
|
|
3063
|
+
reduceRight: () => reduceRight,
|
|
3064
|
+
reflect: () => reflect,
|
|
3065
|
+
reflectAll: () => reflectAll,
|
|
3066
|
+
reject: () => reject$1,
|
|
3067
|
+
rejectLimit: () => rejectLimit$1,
|
|
3068
|
+
rejectSeries: () => rejectSeries$1,
|
|
3069
|
+
retry: () => retry,
|
|
3070
|
+
retryable: () => retryable,
|
|
3071
|
+
select: () => filter$1,
|
|
3072
|
+
selectLimit: () => filterLimit$1,
|
|
3073
|
+
selectSeries: () => filterSeries$1,
|
|
3074
|
+
seq: () => seq,
|
|
3075
|
+
series: () => series,
|
|
3076
|
+
setImmediate: () => setImmediate$1,
|
|
3077
|
+
some: () => some$1,
|
|
3078
|
+
someLimit: () => someLimit$1,
|
|
3079
|
+
someSeries: () => someSeries$1,
|
|
3080
|
+
sortBy: () => sortBy$1,
|
|
3081
|
+
timeout: () => timeout,
|
|
3082
|
+
times: () => times,
|
|
3083
|
+
timesLimit: () => timesLimit,
|
|
3084
|
+
timesSeries: () => timesSeries,
|
|
3085
|
+
transform: () => transform,
|
|
3086
|
+
tryEach: () => tryEach$1,
|
|
3087
|
+
unmemoize: () => unmemoize,
|
|
3088
|
+
until: () => until,
|
|
3089
|
+
waterfall: () => waterfall$1,
|
|
3090
|
+
whilst: () => whilst$1,
|
|
3091
|
+
wrapSync: () => asyncify
|
|
3092
|
+
});
|
|
3093
|
+
function apply(fn, ...args) {
|
|
3094
|
+
return (...callArgs) => fn(...args, ...callArgs);
|
|
3095
|
+
}
|
|
3096
|
+
function initialParams(fn) {
|
|
3097
|
+
return function(...args) {
|
|
3098
|
+
var callback = args.pop();
|
|
3099
|
+
return fn.call(this, args, callback);
|
|
3100
|
+
};
|
|
3101
|
+
}
|
|
3102
|
+
function fallback(fn) {
|
|
3103
|
+
setTimeout(fn, 0);
|
|
3104
|
+
}
|
|
3105
|
+
function wrap(defer) {
|
|
3106
|
+
return (fn, ...args) => defer(() => fn(...args));
|
|
3107
|
+
}
|
|
3108
|
+
function asyncify(func) {
|
|
3109
|
+
if (isAsync(func)) {
|
|
3110
|
+
return function(...args) {
|
|
3111
|
+
const callback = args.pop();
|
|
3112
|
+
const promise = func.apply(this, args);
|
|
3113
|
+
return handlePromise(promise, callback);
|
|
3114
|
+
};
|
|
3115
|
+
}
|
|
3116
|
+
return initialParams(function(args, callback) {
|
|
3117
|
+
var result;
|
|
3118
|
+
try {
|
|
3119
|
+
result = func.apply(this, args);
|
|
3120
|
+
} catch (e) {
|
|
3121
|
+
return callback(e);
|
|
3122
|
+
}
|
|
3123
|
+
if (result && typeof result.then === "function") {
|
|
3124
|
+
return handlePromise(result, callback);
|
|
3125
|
+
} else {
|
|
3126
|
+
callback(null, result);
|
|
3127
|
+
}
|
|
3128
|
+
});
|
|
3129
|
+
}
|
|
3130
|
+
function handlePromise(promise, callback) {
|
|
3131
|
+
return promise.then((value) => {
|
|
3132
|
+
invokeCallback(callback, null, value);
|
|
3133
|
+
}, (err) => {
|
|
3134
|
+
invokeCallback(callback, err && (err instanceof Error || err.message) ? err : new Error(err));
|
|
3135
|
+
});
|
|
3136
|
+
}
|
|
3137
|
+
function invokeCallback(callback, error, value) {
|
|
3138
|
+
try {
|
|
3139
|
+
callback(error, value);
|
|
3140
|
+
} catch (err) {
|
|
3141
|
+
setImmediate$1((e) => {
|
|
3142
|
+
throw e;
|
|
3143
|
+
}, err);
|
|
3144
|
+
}
|
|
3145
|
+
}
|
|
3146
|
+
function isAsync(fn) {
|
|
3147
|
+
return fn[Symbol.toStringTag] === "AsyncFunction";
|
|
3148
|
+
}
|
|
3149
|
+
function isAsyncGenerator(fn) {
|
|
3150
|
+
return fn[Symbol.toStringTag] === "AsyncGenerator";
|
|
3151
|
+
}
|
|
3152
|
+
function isAsyncIterable(obj) {
|
|
3153
|
+
return typeof obj[Symbol.asyncIterator] === "function";
|
|
3154
|
+
}
|
|
3155
|
+
function wrapAsync(asyncFn) {
|
|
3156
|
+
if (typeof asyncFn !== "function") throw new Error("expected a function");
|
|
3157
|
+
return isAsync(asyncFn) ? asyncify(asyncFn) : asyncFn;
|
|
3158
|
+
}
|
|
3159
|
+
function awaitify(asyncFn, arity) {
|
|
3160
|
+
if (!arity) arity = asyncFn.length;
|
|
3161
|
+
if (!arity) throw new Error("arity is undefined");
|
|
3162
|
+
function awaitable(...args) {
|
|
3163
|
+
if (typeof args[arity - 1] === "function") {
|
|
3164
|
+
return asyncFn.apply(this, args);
|
|
3165
|
+
}
|
|
3166
|
+
return new Promise((resolve4, reject2) => {
|
|
3167
|
+
args[arity - 1] = (err, ...cbArgs) => {
|
|
3168
|
+
if (err) return reject2(err);
|
|
3169
|
+
resolve4(cbArgs.length > 1 ? cbArgs : cbArgs[0]);
|
|
3170
|
+
};
|
|
3171
|
+
asyncFn.apply(this, args);
|
|
3172
|
+
});
|
|
3173
|
+
}
|
|
3174
|
+
return awaitable;
|
|
3175
|
+
}
|
|
3176
|
+
function applyEach$1(eachfn) {
|
|
3177
|
+
return function applyEach2(fns, ...callArgs) {
|
|
3178
|
+
const go = awaitify(function(callback) {
|
|
3179
|
+
var that = this;
|
|
3180
|
+
return eachfn(fns, (fn, cb) => {
|
|
3181
|
+
wrapAsync(fn).apply(that, callArgs.concat(cb));
|
|
3182
|
+
}, callback);
|
|
3183
|
+
});
|
|
3184
|
+
return go;
|
|
3185
|
+
};
|
|
3186
|
+
}
|
|
3187
|
+
function _asyncMap(eachfn, arr, iteratee, callback) {
|
|
3188
|
+
arr = arr || [];
|
|
3189
|
+
var results = [];
|
|
3190
|
+
var counter = 0;
|
|
3191
|
+
var _iteratee = wrapAsync(iteratee);
|
|
3192
|
+
return eachfn(arr, (value, _, iterCb) => {
|
|
3193
|
+
var index2 = counter++;
|
|
3194
|
+
_iteratee(value, (err, v) => {
|
|
3195
|
+
results[index2] = v;
|
|
3196
|
+
iterCb(err);
|
|
3197
|
+
});
|
|
3198
|
+
}, (err) => {
|
|
3199
|
+
callback(err, results);
|
|
3200
|
+
});
|
|
3201
|
+
}
|
|
3202
|
+
function isArrayLike(value) {
|
|
3203
|
+
return value && typeof value.length === "number" && value.length >= 0 && value.length % 1 === 0;
|
|
3204
|
+
}
|
|
3205
|
+
function once(fn) {
|
|
3206
|
+
function wrapper(...args) {
|
|
3207
|
+
if (fn === null) return;
|
|
3208
|
+
var callFn = fn;
|
|
3209
|
+
fn = null;
|
|
3210
|
+
callFn.apply(this, args);
|
|
3211
|
+
}
|
|
3212
|
+
Object.assign(wrapper, fn);
|
|
3213
|
+
return wrapper;
|
|
3214
|
+
}
|
|
3215
|
+
function getIterator(coll) {
|
|
3216
|
+
return coll[Symbol.iterator] && coll[Symbol.iterator]();
|
|
3217
|
+
}
|
|
3218
|
+
function createArrayIterator(coll) {
|
|
3219
|
+
var i = -1;
|
|
3220
|
+
var len = coll.length;
|
|
3221
|
+
return function next() {
|
|
3222
|
+
return ++i < len ? { value: coll[i], key: i } : null;
|
|
3223
|
+
};
|
|
3224
|
+
}
|
|
3225
|
+
function createES2015Iterator(iterator) {
|
|
3226
|
+
var i = -1;
|
|
3227
|
+
return function next() {
|
|
3228
|
+
var item = iterator.next();
|
|
3229
|
+
if (item.done)
|
|
3230
|
+
return null;
|
|
3231
|
+
i++;
|
|
3232
|
+
return { value: item.value, key: i };
|
|
3233
|
+
};
|
|
3234
|
+
}
|
|
3235
|
+
function createObjectIterator(obj) {
|
|
3236
|
+
var okeys = obj ? Object.keys(obj) : [];
|
|
3237
|
+
var i = -1;
|
|
3238
|
+
var len = okeys.length;
|
|
3239
|
+
return function next() {
|
|
3240
|
+
var key = okeys[++i];
|
|
3241
|
+
if (key === "__proto__") {
|
|
3242
|
+
return next();
|
|
3243
|
+
}
|
|
3244
|
+
return i < len ? { value: obj[key], key } : null;
|
|
3245
|
+
};
|
|
3246
|
+
}
|
|
3247
|
+
function createIterator(coll) {
|
|
3248
|
+
if (isArrayLike(coll)) {
|
|
3249
|
+
return createArrayIterator(coll);
|
|
3250
|
+
}
|
|
3251
|
+
var iterator = getIterator(coll);
|
|
3252
|
+
return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll);
|
|
3253
|
+
}
|
|
3254
|
+
function onlyOnce(fn) {
|
|
3255
|
+
return function(...args) {
|
|
3256
|
+
if (fn === null) throw new Error("Callback was already called.");
|
|
3257
|
+
var callFn = fn;
|
|
3258
|
+
fn = null;
|
|
3259
|
+
callFn.apply(this, args);
|
|
3260
|
+
};
|
|
3261
|
+
}
|
|
3262
|
+
function asyncEachOfLimit(generator, limit, iteratee, callback) {
|
|
3263
|
+
let done = false;
|
|
3264
|
+
let canceled = false;
|
|
3265
|
+
let awaiting = false;
|
|
3266
|
+
let running = 0;
|
|
3267
|
+
let idx = 0;
|
|
3268
|
+
function replenish() {
|
|
3269
|
+
if (running >= limit || awaiting || done) return;
|
|
3270
|
+
awaiting = true;
|
|
3271
|
+
generator.next().then(({ value, done: iterDone }) => {
|
|
3272
|
+
if (canceled || done) return;
|
|
3273
|
+
awaiting = false;
|
|
3274
|
+
if (iterDone) {
|
|
3275
|
+
done = true;
|
|
3276
|
+
if (running <= 0) {
|
|
3277
|
+
callback(null);
|
|
3278
|
+
}
|
|
3279
|
+
return;
|
|
3280
|
+
}
|
|
3281
|
+
running++;
|
|
3282
|
+
iteratee(value, idx, iterateeCallback);
|
|
3283
|
+
idx++;
|
|
3284
|
+
replenish();
|
|
3285
|
+
}).catch(handleError);
|
|
3286
|
+
}
|
|
3287
|
+
function iterateeCallback(err, result) {
|
|
3288
|
+
running -= 1;
|
|
3289
|
+
if (canceled) return;
|
|
3290
|
+
if (err) return handleError(err);
|
|
3291
|
+
if (err === false) {
|
|
3292
|
+
done = true;
|
|
3293
|
+
canceled = true;
|
|
3294
|
+
return;
|
|
3295
|
+
}
|
|
3296
|
+
if (result === breakLoop || done && running <= 0) {
|
|
3297
|
+
done = true;
|
|
3298
|
+
return callback(null);
|
|
3299
|
+
}
|
|
3300
|
+
replenish();
|
|
3301
|
+
}
|
|
3302
|
+
function handleError(err) {
|
|
3303
|
+
if (canceled) return;
|
|
3304
|
+
awaiting = false;
|
|
3305
|
+
done = true;
|
|
3306
|
+
callback(err);
|
|
3307
|
+
}
|
|
3308
|
+
replenish();
|
|
3309
|
+
}
|
|
3310
|
+
function eachOfLimit(coll, limit, iteratee, callback) {
|
|
3311
|
+
return eachOfLimit$2(limit)(coll, wrapAsync(iteratee), callback);
|
|
3312
|
+
}
|
|
3313
|
+
function eachOfArrayLike(coll, iteratee, callback) {
|
|
3314
|
+
callback = once(callback);
|
|
3315
|
+
var index2 = 0, completed = 0, { length } = coll, canceled = false;
|
|
3316
|
+
if (length === 0) {
|
|
3317
|
+
callback(null);
|
|
3318
|
+
}
|
|
3319
|
+
function iteratorCallback(err, value) {
|
|
3320
|
+
if (err === false) {
|
|
3321
|
+
canceled = true;
|
|
3322
|
+
}
|
|
3323
|
+
if (canceled === true) return;
|
|
3324
|
+
if (err) {
|
|
3325
|
+
callback(err);
|
|
3326
|
+
} else if (++completed === length || value === breakLoop) {
|
|
3327
|
+
callback(null);
|
|
3328
|
+
}
|
|
3329
|
+
}
|
|
3330
|
+
for (; index2 < length; index2++) {
|
|
3331
|
+
iteratee(coll[index2], index2, onlyOnce(iteratorCallback));
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
function eachOfGeneric(coll, iteratee, callback) {
|
|
3335
|
+
return eachOfLimit$1(coll, Infinity, iteratee, callback);
|
|
3336
|
+
}
|
|
3337
|
+
function eachOf(coll, iteratee, callback) {
|
|
3338
|
+
var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric;
|
|
3339
|
+
return eachOfImplementation(coll, wrapAsync(iteratee), callback);
|
|
3340
|
+
}
|
|
3341
|
+
function map(coll, iteratee, callback) {
|
|
3342
|
+
return _asyncMap(eachOf$1, coll, iteratee, callback);
|
|
3343
|
+
}
|
|
3344
|
+
function eachOfSeries(coll, iteratee, callback) {
|
|
3345
|
+
return eachOfLimit$1(coll, 1, iteratee, callback);
|
|
3346
|
+
}
|
|
3347
|
+
function mapSeries(coll, iteratee, callback) {
|
|
3348
|
+
return _asyncMap(eachOfSeries$1, coll, iteratee, callback);
|
|
3349
|
+
}
|
|
3350
|
+
function promiseCallback() {
|
|
3351
|
+
let resolve4, reject2;
|
|
3352
|
+
function callback(err, ...args) {
|
|
3353
|
+
if (err) return reject2(err);
|
|
3354
|
+
resolve4(args.length > 1 ? args : args[0]);
|
|
3355
|
+
}
|
|
3356
|
+
callback[PROMISE_SYMBOL] = new Promise((res, rej) => {
|
|
3357
|
+
resolve4 = res, reject2 = rej;
|
|
3358
|
+
});
|
|
3359
|
+
return callback;
|
|
3360
|
+
}
|
|
3361
|
+
function auto(tasks, concurrency, callback) {
|
|
3362
|
+
if (typeof concurrency !== "number") {
|
|
3363
|
+
callback = concurrency;
|
|
3364
|
+
concurrency = null;
|
|
3365
|
+
}
|
|
3366
|
+
callback = once(callback || promiseCallback());
|
|
3367
|
+
var numTasks = Object.keys(tasks).length;
|
|
3368
|
+
if (!numTasks) {
|
|
3369
|
+
return callback(null);
|
|
3370
|
+
}
|
|
3371
|
+
if (!concurrency) {
|
|
3372
|
+
concurrency = numTasks;
|
|
3373
|
+
}
|
|
3374
|
+
var results = {};
|
|
3375
|
+
var runningTasks = 0;
|
|
3376
|
+
var canceled = false;
|
|
3377
|
+
var hasError = false;
|
|
3378
|
+
var listeners = /* @__PURE__ */ Object.create(null);
|
|
3379
|
+
var readyTasks = [];
|
|
3380
|
+
var readyToCheck = [];
|
|
3381
|
+
var uncheckedDependencies = {};
|
|
3382
|
+
Object.keys(tasks).forEach((key) => {
|
|
3383
|
+
var task = tasks[key];
|
|
3384
|
+
if (!Array.isArray(task)) {
|
|
3385
|
+
enqueueTask(key, [task]);
|
|
3386
|
+
readyToCheck.push(key);
|
|
3387
|
+
return;
|
|
3388
|
+
}
|
|
3389
|
+
var dependencies = task.slice(0, task.length - 1);
|
|
3390
|
+
var remainingDependencies = dependencies.length;
|
|
3391
|
+
if (remainingDependencies === 0) {
|
|
3392
|
+
enqueueTask(key, task);
|
|
3393
|
+
readyToCheck.push(key);
|
|
3394
|
+
return;
|
|
3395
|
+
}
|
|
3396
|
+
uncheckedDependencies[key] = remainingDependencies;
|
|
3397
|
+
dependencies.forEach((dependencyName) => {
|
|
3398
|
+
if (!tasks[dependencyName]) {
|
|
3399
|
+
throw new Error("async.auto task `" + key + "` has a non-existent dependency `" + dependencyName + "` in " + dependencies.join(", "));
|
|
3400
|
+
}
|
|
3401
|
+
addListener(dependencyName, () => {
|
|
3402
|
+
remainingDependencies--;
|
|
3403
|
+
if (remainingDependencies === 0) {
|
|
3404
|
+
enqueueTask(key, task);
|
|
3405
|
+
}
|
|
3406
|
+
});
|
|
3407
|
+
});
|
|
3408
|
+
});
|
|
3409
|
+
checkForDeadlocks();
|
|
3410
|
+
processQueue();
|
|
3411
|
+
function enqueueTask(key, task) {
|
|
3412
|
+
readyTasks.push(() => runTask(key, task));
|
|
3413
|
+
}
|
|
3414
|
+
function processQueue() {
|
|
3415
|
+
if (canceled) return;
|
|
3416
|
+
if (readyTasks.length === 0 && runningTasks === 0) {
|
|
3417
|
+
return callback(null, results);
|
|
3418
|
+
}
|
|
3419
|
+
while (readyTasks.length && runningTasks < concurrency) {
|
|
3420
|
+
var run = readyTasks.shift();
|
|
3421
|
+
run();
|
|
3422
|
+
}
|
|
3423
|
+
}
|
|
3424
|
+
function addListener(taskName, fn) {
|
|
3425
|
+
var taskListeners = listeners[taskName];
|
|
3426
|
+
if (!taskListeners) {
|
|
3427
|
+
taskListeners = listeners[taskName] = [];
|
|
3428
|
+
}
|
|
3429
|
+
taskListeners.push(fn);
|
|
3430
|
+
}
|
|
3431
|
+
function taskComplete(taskName) {
|
|
3432
|
+
var taskListeners = listeners[taskName] || [];
|
|
3433
|
+
taskListeners.forEach((fn) => fn());
|
|
3434
|
+
processQueue();
|
|
3435
|
+
}
|
|
3436
|
+
function runTask(key, task) {
|
|
3437
|
+
if (hasError) return;
|
|
3438
|
+
var taskCallback = onlyOnce((err, ...result) => {
|
|
3439
|
+
runningTasks--;
|
|
3440
|
+
if (err === false) {
|
|
3441
|
+
canceled = true;
|
|
3442
|
+
return;
|
|
3443
|
+
}
|
|
3444
|
+
if (result.length < 2) {
|
|
3445
|
+
[result] = result;
|
|
3446
|
+
}
|
|
3447
|
+
if (err) {
|
|
3448
|
+
var safeResults = {};
|
|
3449
|
+
Object.keys(results).forEach((rkey) => {
|
|
3450
|
+
safeResults[rkey] = results[rkey];
|
|
3451
|
+
});
|
|
3452
|
+
safeResults[key] = result;
|
|
3453
|
+
hasError = true;
|
|
3454
|
+
listeners = /* @__PURE__ */ Object.create(null);
|
|
3455
|
+
if (canceled) return;
|
|
3456
|
+
callback(err, safeResults);
|
|
3457
|
+
} else {
|
|
3458
|
+
results[key] = result;
|
|
3459
|
+
taskComplete(key);
|
|
3460
|
+
}
|
|
3461
|
+
});
|
|
3462
|
+
runningTasks++;
|
|
3463
|
+
var taskFn = wrapAsync(task[task.length - 1]);
|
|
3464
|
+
if (task.length > 1) {
|
|
3465
|
+
taskFn(results, taskCallback);
|
|
3466
|
+
} else {
|
|
3467
|
+
taskFn(taskCallback);
|
|
3468
|
+
}
|
|
3469
|
+
}
|
|
3470
|
+
function checkForDeadlocks() {
|
|
3471
|
+
var currentTask;
|
|
3472
|
+
var counter = 0;
|
|
3473
|
+
while (readyToCheck.length) {
|
|
3474
|
+
currentTask = readyToCheck.pop();
|
|
3475
|
+
counter++;
|
|
3476
|
+
getDependents(currentTask).forEach((dependent) => {
|
|
3477
|
+
if (--uncheckedDependencies[dependent] === 0) {
|
|
3478
|
+
readyToCheck.push(dependent);
|
|
3479
|
+
}
|
|
3480
|
+
});
|
|
3481
|
+
}
|
|
3482
|
+
if (counter !== numTasks) {
|
|
3483
|
+
throw new Error(
|
|
3484
|
+
"async.auto cannot execute tasks due to a recursive dependency"
|
|
3485
|
+
);
|
|
3486
|
+
}
|
|
3487
|
+
}
|
|
3488
|
+
function getDependents(taskName) {
|
|
3489
|
+
var result = [];
|
|
3490
|
+
Object.keys(tasks).forEach((key) => {
|
|
3491
|
+
const task = tasks[key];
|
|
3492
|
+
if (Array.isArray(task) && task.indexOf(taskName) >= 0) {
|
|
3493
|
+
result.push(key);
|
|
3494
|
+
}
|
|
3495
|
+
});
|
|
3496
|
+
return result;
|
|
3497
|
+
}
|
|
3498
|
+
return callback[PROMISE_SYMBOL];
|
|
3499
|
+
}
|
|
3500
|
+
function stripComments(string) {
|
|
3501
|
+
let stripped = "";
|
|
3502
|
+
let index2 = 0;
|
|
3503
|
+
let endBlockComment = string.indexOf("*/");
|
|
3504
|
+
while (index2 < string.length) {
|
|
3505
|
+
if (string[index2] === "/" && string[index2 + 1] === "/") {
|
|
3506
|
+
let endIndex = string.indexOf("\n", index2);
|
|
3507
|
+
index2 = endIndex === -1 ? string.length : endIndex;
|
|
3508
|
+
} else if (endBlockComment !== -1 && string[index2] === "/" && string[index2 + 1] === "*") {
|
|
3509
|
+
let endIndex = string.indexOf("*/", index2);
|
|
3510
|
+
if (endIndex !== -1) {
|
|
3511
|
+
index2 = endIndex + 2;
|
|
3512
|
+
endBlockComment = string.indexOf("*/", index2);
|
|
3513
|
+
} else {
|
|
3514
|
+
stripped += string[index2];
|
|
3515
|
+
index2++;
|
|
3516
|
+
}
|
|
3517
|
+
} else {
|
|
3518
|
+
stripped += string[index2];
|
|
3519
|
+
index2++;
|
|
3520
|
+
}
|
|
3521
|
+
}
|
|
3522
|
+
return stripped;
|
|
3523
|
+
}
|
|
3524
|
+
function parseParams(func) {
|
|
3525
|
+
const src = stripComments(func.toString());
|
|
3526
|
+
let match = src.match(FN_ARGS);
|
|
3527
|
+
if (!match) {
|
|
3528
|
+
match = src.match(ARROW_FN_ARGS);
|
|
3529
|
+
}
|
|
3530
|
+
if (!match) throw new Error("could not parse args in autoInject\nSource:\n" + src);
|
|
3531
|
+
let [, args] = match;
|
|
3532
|
+
return args.replace(/\s/g, "").split(FN_ARG_SPLIT).map((arg) => arg.replace(FN_ARG, "").trim());
|
|
3533
|
+
}
|
|
3534
|
+
function autoInject(tasks, callback) {
|
|
3535
|
+
var newTasks = {};
|
|
3536
|
+
Object.keys(tasks).forEach((key) => {
|
|
3537
|
+
var taskFn = tasks[key];
|
|
3538
|
+
var params;
|
|
3539
|
+
var fnIsAsync = isAsync(taskFn);
|
|
3540
|
+
var hasNoDeps = !fnIsAsync && taskFn.length === 1 || fnIsAsync && taskFn.length === 0;
|
|
3541
|
+
if (Array.isArray(taskFn)) {
|
|
3542
|
+
params = [...taskFn];
|
|
3543
|
+
taskFn = params.pop();
|
|
3544
|
+
newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);
|
|
3545
|
+
} else if (hasNoDeps) {
|
|
3546
|
+
newTasks[key] = taskFn;
|
|
3547
|
+
} else {
|
|
3548
|
+
params = parseParams(taskFn);
|
|
3549
|
+
if (taskFn.length === 0 && !fnIsAsync && params.length === 0) {
|
|
3550
|
+
throw new Error("autoInject task functions require explicit parameters.");
|
|
3551
|
+
}
|
|
3552
|
+
if (!fnIsAsync) params.pop();
|
|
3553
|
+
newTasks[key] = params.concat(newTask);
|
|
3554
|
+
}
|
|
3555
|
+
function newTask(results, taskCb) {
|
|
3556
|
+
var newArgs = params.map((name) => results[name]);
|
|
3557
|
+
newArgs.push(taskCb);
|
|
3558
|
+
wrapAsync(taskFn)(...newArgs);
|
|
3559
|
+
}
|
|
3560
|
+
});
|
|
3561
|
+
return auto(newTasks, callback);
|
|
3562
|
+
}
|
|
3563
|
+
function setInitial(dll, node) {
|
|
3564
|
+
dll.length = 1;
|
|
3565
|
+
dll.head = dll.tail = node;
|
|
3566
|
+
}
|
|
3567
|
+
function queue$1(worker, concurrency, payload) {
|
|
3568
|
+
if (concurrency == null) {
|
|
3569
|
+
concurrency = 1;
|
|
3570
|
+
} else if (concurrency === 0) {
|
|
3571
|
+
throw new RangeError("Concurrency must not be zero");
|
|
3572
|
+
}
|
|
3573
|
+
var _worker = wrapAsync(worker);
|
|
3574
|
+
var numRunning = 0;
|
|
3575
|
+
var workersList = [];
|
|
3576
|
+
const events = {
|
|
3577
|
+
error: [],
|
|
3578
|
+
drain: [],
|
|
3579
|
+
saturated: [],
|
|
3580
|
+
unsaturated: [],
|
|
3581
|
+
empty: []
|
|
3582
|
+
};
|
|
3583
|
+
function on(event, handler) {
|
|
3584
|
+
events[event].push(handler);
|
|
3585
|
+
}
|
|
3586
|
+
function once2(event, handler) {
|
|
3587
|
+
const handleAndRemove = (...args) => {
|
|
3588
|
+
off(event, handleAndRemove);
|
|
3589
|
+
handler(...args);
|
|
3590
|
+
};
|
|
3591
|
+
events[event].push(handleAndRemove);
|
|
3592
|
+
}
|
|
3593
|
+
function off(event, handler) {
|
|
3594
|
+
if (!event) return Object.keys(events).forEach((ev) => events[ev] = []);
|
|
3595
|
+
if (!handler) return events[event] = [];
|
|
3596
|
+
events[event] = events[event].filter((ev) => ev !== handler);
|
|
3597
|
+
}
|
|
3598
|
+
function trigger(event, ...args) {
|
|
3599
|
+
events[event].forEach((handler) => handler(...args));
|
|
3600
|
+
}
|
|
3601
|
+
var processingScheduled = false;
|
|
3602
|
+
function _insert(data, insertAtFront, rejectOnError, callback) {
|
|
3603
|
+
if (callback != null && typeof callback !== "function") {
|
|
3604
|
+
throw new Error("task callback must be a function");
|
|
3605
|
+
}
|
|
3606
|
+
q.started = true;
|
|
3607
|
+
var res, rej;
|
|
3608
|
+
function promiseCallback2(err, ...args) {
|
|
3609
|
+
if (err) return rejectOnError ? rej(err) : res();
|
|
3610
|
+
if (args.length <= 1) return res(args[0]);
|
|
3611
|
+
res(args);
|
|
3612
|
+
}
|
|
3613
|
+
var item = q._createTaskItem(
|
|
3614
|
+
data,
|
|
3615
|
+
rejectOnError ? promiseCallback2 : callback || promiseCallback2
|
|
3616
|
+
);
|
|
3617
|
+
if (insertAtFront) {
|
|
3618
|
+
q._tasks.unshift(item);
|
|
3619
|
+
} else {
|
|
3620
|
+
q._tasks.push(item);
|
|
3621
|
+
}
|
|
3622
|
+
if (!processingScheduled) {
|
|
3623
|
+
processingScheduled = true;
|
|
3624
|
+
setImmediate$1(() => {
|
|
3625
|
+
processingScheduled = false;
|
|
3626
|
+
q.process();
|
|
3627
|
+
});
|
|
3628
|
+
}
|
|
3629
|
+
if (rejectOnError || !callback) {
|
|
3630
|
+
return new Promise((resolve4, reject2) => {
|
|
3631
|
+
res = resolve4;
|
|
3632
|
+
rej = reject2;
|
|
3633
|
+
});
|
|
3634
|
+
}
|
|
3635
|
+
}
|
|
3636
|
+
function _createCB(tasks) {
|
|
3637
|
+
return function(err, ...args) {
|
|
3638
|
+
numRunning -= 1;
|
|
3639
|
+
for (var i = 0, l = tasks.length; i < l; i++) {
|
|
3640
|
+
var task = tasks[i];
|
|
3641
|
+
var index2 = workersList.indexOf(task);
|
|
3642
|
+
if (index2 === 0) {
|
|
3643
|
+
workersList.shift();
|
|
3644
|
+
} else if (index2 > 0) {
|
|
3645
|
+
workersList.splice(index2, 1);
|
|
3646
|
+
}
|
|
3647
|
+
task.callback(err, ...args);
|
|
3648
|
+
if (err != null) {
|
|
3649
|
+
trigger("error", err, task.data);
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
if (numRunning <= q.concurrency - q.buffer) {
|
|
3653
|
+
trigger("unsaturated");
|
|
3654
|
+
}
|
|
3655
|
+
if (q.idle()) {
|
|
3656
|
+
trigger("drain");
|
|
3657
|
+
}
|
|
3658
|
+
q.process();
|
|
3659
|
+
};
|
|
3660
|
+
}
|
|
3661
|
+
function _maybeDrain(data) {
|
|
3662
|
+
if (data.length === 0 && q.idle()) {
|
|
3663
|
+
setImmediate$1(() => trigger("drain"));
|
|
3664
|
+
return true;
|
|
3665
|
+
}
|
|
3666
|
+
return false;
|
|
3667
|
+
}
|
|
3668
|
+
const eventMethod = (name) => (handler) => {
|
|
3669
|
+
if (!handler) {
|
|
3670
|
+
return new Promise((resolve4, reject2) => {
|
|
3671
|
+
once2(name, (err, data) => {
|
|
3672
|
+
if (err) return reject2(err);
|
|
3673
|
+
resolve4(data);
|
|
3674
|
+
});
|
|
3675
|
+
});
|
|
3676
|
+
}
|
|
3677
|
+
off(name);
|
|
3678
|
+
on(name, handler);
|
|
3679
|
+
};
|
|
3680
|
+
var isProcessing = false;
|
|
3681
|
+
var q = {
|
|
3682
|
+
_tasks: new DLL(),
|
|
3683
|
+
_createTaskItem(data, callback) {
|
|
3684
|
+
return {
|
|
3685
|
+
data,
|
|
3686
|
+
callback
|
|
3687
|
+
};
|
|
3688
|
+
},
|
|
3689
|
+
*[Symbol.iterator]() {
|
|
3690
|
+
yield* q._tasks[Symbol.iterator]();
|
|
3691
|
+
},
|
|
3692
|
+
concurrency,
|
|
3693
|
+
payload,
|
|
3694
|
+
buffer: concurrency / 4,
|
|
3695
|
+
started: false,
|
|
3696
|
+
paused: false,
|
|
3697
|
+
push(data, callback) {
|
|
3698
|
+
if (Array.isArray(data)) {
|
|
3699
|
+
if (_maybeDrain(data)) return;
|
|
3700
|
+
return data.map((datum) => _insert(datum, false, false, callback));
|
|
3701
|
+
}
|
|
3702
|
+
return _insert(data, false, false, callback);
|
|
3703
|
+
},
|
|
3704
|
+
pushAsync(data, callback) {
|
|
3705
|
+
if (Array.isArray(data)) {
|
|
3706
|
+
if (_maybeDrain(data)) return;
|
|
3707
|
+
return data.map((datum) => _insert(datum, false, true, callback));
|
|
3708
|
+
}
|
|
3709
|
+
return _insert(data, false, true, callback);
|
|
3710
|
+
},
|
|
3711
|
+
kill() {
|
|
3712
|
+
off();
|
|
3713
|
+
q._tasks.empty();
|
|
3714
|
+
},
|
|
3715
|
+
unshift(data, callback) {
|
|
3716
|
+
if (Array.isArray(data)) {
|
|
3717
|
+
if (_maybeDrain(data)) return;
|
|
3718
|
+
return data.map((datum) => _insert(datum, true, false, callback));
|
|
3719
|
+
}
|
|
3720
|
+
return _insert(data, true, false, callback);
|
|
3721
|
+
},
|
|
3722
|
+
unshiftAsync(data, callback) {
|
|
3723
|
+
if (Array.isArray(data)) {
|
|
3724
|
+
if (_maybeDrain(data)) return;
|
|
3725
|
+
return data.map((datum) => _insert(datum, true, true, callback));
|
|
3726
|
+
}
|
|
3727
|
+
return _insert(data, true, true, callback);
|
|
3728
|
+
},
|
|
3729
|
+
remove(testFn) {
|
|
3730
|
+
q._tasks.remove(testFn);
|
|
3731
|
+
},
|
|
3732
|
+
process() {
|
|
3733
|
+
if (isProcessing) {
|
|
3734
|
+
return;
|
|
3735
|
+
}
|
|
3736
|
+
isProcessing = true;
|
|
3737
|
+
while (!q.paused && numRunning < q.concurrency && q._tasks.length) {
|
|
3738
|
+
var tasks = [], data = [];
|
|
3739
|
+
var l = q._tasks.length;
|
|
3740
|
+
if (q.payload) l = Math.min(l, q.payload);
|
|
3741
|
+
for (var i = 0; i < l; i++) {
|
|
3742
|
+
var node = q._tasks.shift();
|
|
3743
|
+
tasks.push(node);
|
|
3744
|
+
workersList.push(node);
|
|
3745
|
+
data.push(node.data);
|
|
3746
|
+
}
|
|
3747
|
+
numRunning += 1;
|
|
3748
|
+
if (q._tasks.length === 0) {
|
|
3749
|
+
trigger("empty");
|
|
3750
|
+
}
|
|
3751
|
+
if (numRunning === q.concurrency) {
|
|
3752
|
+
trigger("saturated");
|
|
3753
|
+
}
|
|
3754
|
+
var cb = onlyOnce(_createCB(tasks));
|
|
3755
|
+
_worker(data, cb);
|
|
3756
|
+
}
|
|
3757
|
+
isProcessing = false;
|
|
3758
|
+
},
|
|
3759
|
+
length() {
|
|
3760
|
+
return q._tasks.length;
|
|
3761
|
+
},
|
|
3762
|
+
running() {
|
|
3763
|
+
return numRunning;
|
|
3764
|
+
},
|
|
3765
|
+
workersList() {
|
|
3766
|
+
return workersList;
|
|
3767
|
+
},
|
|
3768
|
+
idle() {
|
|
3769
|
+
return q._tasks.length + numRunning === 0;
|
|
3770
|
+
},
|
|
3771
|
+
pause() {
|
|
3772
|
+
q.paused = true;
|
|
3773
|
+
},
|
|
3774
|
+
resume() {
|
|
3775
|
+
if (q.paused === false) {
|
|
3776
|
+
return;
|
|
3777
|
+
}
|
|
3778
|
+
q.paused = false;
|
|
3779
|
+
setImmediate$1(q.process);
|
|
3780
|
+
}
|
|
3781
|
+
};
|
|
3782
|
+
Object.defineProperties(q, {
|
|
3783
|
+
saturated: {
|
|
3784
|
+
writable: false,
|
|
3785
|
+
value: eventMethod("saturated")
|
|
3786
|
+
},
|
|
3787
|
+
unsaturated: {
|
|
3788
|
+
writable: false,
|
|
3789
|
+
value: eventMethod("unsaturated")
|
|
3790
|
+
},
|
|
3791
|
+
empty: {
|
|
3792
|
+
writable: false,
|
|
3793
|
+
value: eventMethod("empty")
|
|
3794
|
+
},
|
|
3795
|
+
drain: {
|
|
3796
|
+
writable: false,
|
|
3797
|
+
value: eventMethod("drain")
|
|
3798
|
+
},
|
|
3799
|
+
error: {
|
|
3800
|
+
writable: false,
|
|
3801
|
+
value: eventMethod("error")
|
|
3802
|
+
}
|
|
3803
|
+
});
|
|
3804
|
+
return q;
|
|
3805
|
+
}
|
|
3806
|
+
function cargo$1(worker, payload) {
|
|
3807
|
+
return queue$1(worker, 1, payload);
|
|
3808
|
+
}
|
|
3809
|
+
function cargo(worker, concurrency, payload) {
|
|
3810
|
+
return queue$1(worker, concurrency, payload);
|
|
3811
|
+
}
|
|
3812
|
+
function reduce(coll, memo, iteratee, callback) {
|
|
3813
|
+
callback = once(callback);
|
|
3814
|
+
var _iteratee = wrapAsync(iteratee);
|
|
3815
|
+
return eachOfSeries$1(coll, (x, i, iterCb) => {
|
|
3816
|
+
_iteratee(memo, x, (err, v) => {
|
|
3817
|
+
memo = v;
|
|
3818
|
+
iterCb(err);
|
|
3819
|
+
});
|
|
3820
|
+
}, (err) => callback(err, memo));
|
|
3821
|
+
}
|
|
3822
|
+
function seq(...functions) {
|
|
3823
|
+
var _functions = functions.map(wrapAsync);
|
|
3824
|
+
return function(...args) {
|
|
3825
|
+
var that = this;
|
|
3826
|
+
var cb = args[args.length - 1];
|
|
3827
|
+
if (typeof cb == "function") {
|
|
3828
|
+
args.pop();
|
|
3829
|
+
} else {
|
|
3830
|
+
cb = promiseCallback();
|
|
3831
|
+
}
|
|
3832
|
+
reduce$1(
|
|
3833
|
+
_functions,
|
|
3834
|
+
args,
|
|
3835
|
+
(newargs, fn, iterCb) => {
|
|
3836
|
+
fn.apply(that, newargs.concat((err, ...nextargs) => {
|
|
3837
|
+
iterCb(err, nextargs);
|
|
3838
|
+
}));
|
|
3839
|
+
},
|
|
3840
|
+
(err, results) => cb(err, ...results)
|
|
3841
|
+
);
|
|
3842
|
+
return cb[PROMISE_SYMBOL];
|
|
3843
|
+
};
|
|
3844
|
+
}
|
|
3845
|
+
function compose(...args) {
|
|
3846
|
+
return seq(...args.reverse());
|
|
3847
|
+
}
|
|
3848
|
+
function mapLimit(coll, limit, iteratee, callback) {
|
|
3849
|
+
return _asyncMap(eachOfLimit$2(limit), coll, iteratee, callback);
|
|
3850
|
+
}
|
|
3851
|
+
function concatLimit(coll, limit, iteratee, callback) {
|
|
3852
|
+
var _iteratee = wrapAsync(iteratee);
|
|
3853
|
+
return mapLimit$1(coll, limit, (val, iterCb) => {
|
|
3854
|
+
_iteratee(val, (err, ...args) => {
|
|
3855
|
+
if (err) return iterCb(err);
|
|
3856
|
+
return iterCb(err, args);
|
|
3857
|
+
});
|
|
3858
|
+
}, (err, mapResults) => {
|
|
3859
|
+
var result = [];
|
|
3860
|
+
for (var i = 0; i < mapResults.length; i++) {
|
|
3861
|
+
if (mapResults[i]) {
|
|
3862
|
+
result = result.concat(...mapResults[i]);
|
|
3863
|
+
}
|
|
3864
|
+
}
|
|
3865
|
+
return callback(err, result);
|
|
3866
|
+
});
|
|
3867
|
+
}
|
|
3868
|
+
function concat(coll, iteratee, callback) {
|
|
3869
|
+
return concatLimit$1(coll, Infinity, iteratee, callback);
|
|
3870
|
+
}
|
|
3871
|
+
function concatSeries(coll, iteratee, callback) {
|
|
3872
|
+
return concatLimit$1(coll, 1, iteratee, callback);
|
|
3873
|
+
}
|
|
3874
|
+
function constant$1(...args) {
|
|
3875
|
+
return function(...ignoredArgs) {
|
|
3876
|
+
var callback = ignoredArgs.pop();
|
|
3877
|
+
return callback(null, ...args);
|
|
3878
|
+
};
|
|
3879
|
+
}
|
|
3880
|
+
function _createTester(check, getResult) {
|
|
3881
|
+
return (eachfn, arr, _iteratee, cb) => {
|
|
3882
|
+
var testPassed = false;
|
|
3883
|
+
var testResult;
|
|
3884
|
+
const iteratee = wrapAsync(_iteratee);
|
|
3885
|
+
eachfn(arr, (value, _, callback) => {
|
|
3886
|
+
iteratee(value, (err, result) => {
|
|
3887
|
+
if (err || err === false) return callback(err);
|
|
3888
|
+
if (check(result) && !testResult) {
|
|
3889
|
+
testPassed = true;
|
|
3890
|
+
testResult = getResult(true, value);
|
|
3891
|
+
return callback(null, breakLoop);
|
|
3892
|
+
}
|
|
3893
|
+
callback();
|
|
3894
|
+
});
|
|
3895
|
+
}, (err) => {
|
|
3896
|
+
if (err) return cb(err);
|
|
3897
|
+
cb(null, testPassed ? testResult : getResult(false));
|
|
3898
|
+
});
|
|
3899
|
+
};
|
|
3900
|
+
}
|
|
3901
|
+
function detect(coll, iteratee, callback) {
|
|
3902
|
+
return _createTester((bool) => bool, (res, item) => item)(eachOf$1, coll, iteratee, callback);
|
|
3903
|
+
}
|
|
3904
|
+
function detectLimit(coll, limit, iteratee, callback) {
|
|
3905
|
+
return _createTester((bool) => bool, (res, item) => item)(eachOfLimit$2(limit), coll, iteratee, callback);
|
|
3906
|
+
}
|
|
3907
|
+
function detectSeries(coll, iteratee, callback) {
|
|
3908
|
+
return _createTester((bool) => bool, (res, item) => item)(eachOfLimit$2(1), coll, iteratee, callback);
|
|
3909
|
+
}
|
|
3910
|
+
function consoleFunc(name) {
|
|
3911
|
+
return (fn, ...args) => wrapAsync(fn)(...args, (err, ...resultArgs) => {
|
|
3912
|
+
if (typeof console === "object") {
|
|
3913
|
+
if (err) {
|
|
3914
|
+
if (console.error) {
|
|
3915
|
+
console.error(err);
|
|
3916
|
+
}
|
|
3917
|
+
} else if (console[name]) {
|
|
3918
|
+
resultArgs.forEach((x) => console[name](x));
|
|
3919
|
+
}
|
|
3920
|
+
}
|
|
3921
|
+
});
|
|
3922
|
+
}
|
|
3923
|
+
function doWhilst(iteratee, test, callback) {
|
|
3924
|
+
callback = onlyOnce(callback);
|
|
3925
|
+
var _fn = wrapAsync(iteratee);
|
|
3926
|
+
var _test = wrapAsync(test);
|
|
3927
|
+
var results;
|
|
3928
|
+
function next(err, ...args) {
|
|
3929
|
+
if (err) return callback(err);
|
|
3930
|
+
if (err === false) return;
|
|
3931
|
+
results = args;
|
|
3932
|
+
_test(...args, check);
|
|
3933
|
+
}
|
|
3934
|
+
function check(err, truth) {
|
|
3935
|
+
if (err) return callback(err);
|
|
3936
|
+
if (err === false) return;
|
|
3937
|
+
if (!truth) return callback(null, ...results);
|
|
3938
|
+
_fn(next);
|
|
3939
|
+
}
|
|
3940
|
+
return check(null, true);
|
|
3941
|
+
}
|
|
3942
|
+
function doUntil(iteratee, test, callback) {
|
|
3943
|
+
const _test = wrapAsync(test);
|
|
3944
|
+
return doWhilst$1(iteratee, (...args) => {
|
|
3945
|
+
const cb = args.pop();
|
|
3946
|
+
_test(...args, (err, truth) => cb(err, !truth));
|
|
3947
|
+
}, callback);
|
|
3948
|
+
}
|
|
3949
|
+
function _withoutIndex(iteratee) {
|
|
3950
|
+
return (value, index2, callback) => iteratee(value, callback);
|
|
3951
|
+
}
|
|
3952
|
+
function eachLimit$2(coll, iteratee, callback) {
|
|
3953
|
+
return eachOf$1(coll, _withoutIndex(wrapAsync(iteratee)), callback);
|
|
3954
|
+
}
|
|
3955
|
+
function eachLimit(coll, limit, iteratee, callback) {
|
|
3956
|
+
return eachOfLimit$2(limit)(coll, _withoutIndex(wrapAsync(iteratee)), callback);
|
|
3957
|
+
}
|
|
3958
|
+
function eachSeries(coll, iteratee, callback) {
|
|
3959
|
+
return eachLimit$1(coll, 1, iteratee, callback);
|
|
3960
|
+
}
|
|
3961
|
+
function ensureAsync(fn) {
|
|
3962
|
+
if (isAsync(fn)) return fn;
|
|
3963
|
+
return function(...args) {
|
|
3964
|
+
var callback = args.pop();
|
|
3965
|
+
var sync = true;
|
|
3966
|
+
args.push((...innerArgs) => {
|
|
3967
|
+
if (sync) {
|
|
3968
|
+
setImmediate$1(() => callback(...innerArgs));
|
|
3969
|
+
} else {
|
|
3970
|
+
callback(...innerArgs);
|
|
3971
|
+
}
|
|
3972
|
+
});
|
|
3973
|
+
fn.apply(this, args);
|
|
3974
|
+
sync = false;
|
|
3975
|
+
};
|
|
3976
|
+
}
|
|
3977
|
+
function every(coll, iteratee, callback) {
|
|
3978
|
+
return _createTester((bool) => !bool, (res) => !res)(eachOf$1, coll, iteratee, callback);
|
|
3979
|
+
}
|
|
3980
|
+
function everyLimit(coll, limit, iteratee, callback) {
|
|
3981
|
+
return _createTester((bool) => !bool, (res) => !res)(eachOfLimit$2(limit), coll, iteratee, callback);
|
|
3982
|
+
}
|
|
3983
|
+
function everySeries(coll, iteratee, callback) {
|
|
3984
|
+
return _createTester((bool) => !bool, (res) => !res)(eachOfSeries$1, coll, iteratee, callback);
|
|
3985
|
+
}
|
|
3986
|
+
function filterArray(eachfn, arr, iteratee, callback) {
|
|
3987
|
+
var truthValues = new Array(arr.length);
|
|
3988
|
+
eachfn(arr, (x, index2, iterCb) => {
|
|
3989
|
+
iteratee(x, (err, v) => {
|
|
3990
|
+
truthValues[index2] = !!v;
|
|
3991
|
+
iterCb(err);
|
|
3992
|
+
});
|
|
3993
|
+
}, (err) => {
|
|
3994
|
+
if (err) return callback(err);
|
|
3995
|
+
var results = [];
|
|
3996
|
+
for (var i = 0; i < arr.length; i++) {
|
|
3997
|
+
if (truthValues[i]) results.push(arr[i]);
|
|
3998
|
+
}
|
|
3999
|
+
callback(null, results);
|
|
4000
|
+
});
|
|
4001
|
+
}
|
|
4002
|
+
function filterGeneric(eachfn, coll, iteratee, callback) {
|
|
4003
|
+
var results = [];
|
|
4004
|
+
eachfn(coll, (x, index2, iterCb) => {
|
|
4005
|
+
iteratee(x, (err, v) => {
|
|
4006
|
+
if (err) return iterCb(err);
|
|
4007
|
+
if (v) {
|
|
4008
|
+
results.push({ index: index2, value: x });
|
|
4009
|
+
}
|
|
4010
|
+
iterCb(err);
|
|
4011
|
+
});
|
|
4012
|
+
}, (err) => {
|
|
4013
|
+
if (err) return callback(err);
|
|
4014
|
+
callback(null, results.sort((a, b) => a.index - b.index).map((v) => v.value));
|
|
4015
|
+
});
|
|
4016
|
+
}
|
|
4017
|
+
function _filter(eachfn, coll, iteratee, callback) {
|
|
4018
|
+
var filter2 = isArrayLike(coll) ? filterArray : filterGeneric;
|
|
4019
|
+
return filter2(eachfn, coll, wrapAsync(iteratee), callback);
|
|
4020
|
+
}
|
|
4021
|
+
function filter(coll, iteratee, callback) {
|
|
4022
|
+
return _filter(eachOf$1, coll, iteratee, callback);
|
|
4023
|
+
}
|
|
4024
|
+
function filterLimit(coll, limit, iteratee, callback) {
|
|
4025
|
+
return _filter(eachOfLimit$2(limit), coll, iteratee, callback);
|
|
4026
|
+
}
|
|
4027
|
+
function filterSeries(coll, iteratee, callback) {
|
|
4028
|
+
return _filter(eachOfSeries$1, coll, iteratee, callback);
|
|
4029
|
+
}
|
|
4030
|
+
function forever(fn, errback) {
|
|
4031
|
+
var done = onlyOnce(errback);
|
|
4032
|
+
var task = wrapAsync(ensureAsync(fn));
|
|
4033
|
+
function next(err) {
|
|
4034
|
+
if (err) return done(err);
|
|
4035
|
+
if (err === false) return;
|
|
4036
|
+
task(next);
|
|
4037
|
+
}
|
|
4038
|
+
return next();
|
|
4039
|
+
}
|
|
4040
|
+
function groupByLimit(coll, limit, iteratee, callback) {
|
|
4041
|
+
var _iteratee = wrapAsync(iteratee);
|
|
4042
|
+
return mapLimit$1(coll, limit, (val, iterCb) => {
|
|
4043
|
+
_iteratee(val, (err, key) => {
|
|
4044
|
+
if (err) return iterCb(err);
|
|
4045
|
+
return iterCb(err, { key, val });
|
|
4046
|
+
});
|
|
4047
|
+
}, (err, mapResults) => {
|
|
4048
|
+
var result = {};
|
|
4049
|
+
var { hasOwnProperty } = Object.prototype;
|
|
4050
|
+
for (var i = 0; i < mapResults.length; i++) {
|
|
4051
|
+
if (mapResults[i]) {
|
|
4052
|
+
var { key } = mapResults[i];
|
|
4053
|
+
var { val } = mapResults[i];
|
|
4054
|
+
if (hasOwnProperty.call(result, key)) {
|
|
4055
|
+
result[key].push(val);
|
|
4056
|
+
} else {
|
|
4057
|
+
result[key] = [val];
|
|
4058
|
+
}
|
|
4059
|
+
}
|
|
4060
|
+
}
|
|
4061
|
+
return callback(err, result);
|
|
4062
|
+
});
|
|
4063
|
+
}
|
|
4064
|
+
function groupBy(coll, iteratee, callback) {
|
|
4065
|
+
return groupByLimit$1(coll, Infinity, iteratee, callback);
|
|
4066
|
+
}
|
|
4067
|
+
function groupBySeries(coll, iteratee, callback) {
|
|
4068
|
+
return groupByLimit$1(coll, 1, iteratee, callback);
|
|
4069
|
+
}
|
|
4070
|
+
function mapValuesLimit(obj, limit, iteratee, callback) {
|
|
4071
|
+
callback = once(callback);
|
|
4072
|
+
var newObj = {};
|
|
4073
|
+
var _iteratee = wrapAsync(iteratee);
|
|
4074
|
+
return eachOfLimit$2(limit)(obj, (val, key, next) => {
|
|
4075
|
+
_iteratee(val, key, (err, result) => {
|
|
4076
|
+
if (err) return next(err);
|
|
4077
|
+
newObj[key] = result;
|
|
4078
|
+
next(err);
|
|
4079
|
+
});
|
|
4080
|
+
}, (err) => callback(err, newObj));
|
|
4081
|
+
}
|
|
4082
|
+
function mapValues(obj, iteratee, callback) {
|
|
4083
|
+
return mapValuesLimit$1(obj, Infinity, iteratee, callback);
|
|
4084
|
+
}
|
|
4085
|
+
function mapValuesSeries(obj, iteratee, callback) {
|
|
4086
|
+
return mapValuesLimit$1(obj, 1, iteratee, callback);
|
|
4087
|
+
}
|
|
4088
|
+
function memoize(fn, hasher = (v) => v) {
|
|
4089
|
+
var memo = /* @__PURE__ */ Object.create(null);
|
|
4090
|
+
var queues = /* @__PURE__ */ Object.create(null);
|
|
4091
|
+
var _fn = wrapAsync(fn);
|
|
4092
|
+
var memoized = initialParams((args, callback) => {
|
|
4093
|
+
var key = hasher(...args);
|
|
4094
|
+
if (key in memo) {
|
|
4095
|
+
setImmediate$1(() => callback(null, ...memo[key]));
|
|
4096
|
+
} else if (key in queues) {
|
|
4097
|
+
queues[key].push(callback);
|
|
4098
|
+
} else {
|
|
4099
|
+
queues[key] = [callback];
|
|
4100
|
+
_fn(...args, (err, ...resultArgs) => {
|
|
4101
|
+
if (!err) {
|
|
4102
|
+
memo[key] = resultArgs;
|
|
4103
|
+
}
|
|
4104
|
+
var q = queues[key];
|
|
4105
|
+
delete queues[key];
|
|
4106
|
+
for (var i = 0, l = q.length; i < l; i++) {
|
|
4107
|
+
q[i](err, ...resultArgs);
|
|
4108
|
+
}
|
|
4109
|
+
});
|
|
4110
|
+
}
|
|
4111
|
+
});
|
|
4112
|
+
memoized.memo = memo;
|
|
4113
|
+
memoized.unmemoized = fn;
|
|
4114
|
+
return memoized;
|
|
4115
|
+
}
|
|
4116
|
+
function parallel(tasks, callback) {
|
|
4117
|
+
return _parallel(eachOf$1, tasks, callback);
|
|
4118
|
+
}
|
|
4119
|
+
function parallelLimit(tasks, limit, callback) {
|
|
4120
|
+
return _parallel(eachOfLimit$2(limit), tasks, callback);
|
|
4121
|
+
}
|
|
4122
|
+
function queue(worker, concurrency) {
|
|
4123
|
+
var _worker = wrapAsync(worker);
|
|
4124
|
+
return queue$1((items, cb) => {
|
|
4125
|
+
_worker(items[0], cb);
|
|
4126
|
+
}, concurrency, 1);
|
|
4127
|
+
}
|
|
4128
|
+
function leftChi(i) {
|
|
4129
|
+
return (i << 1) + 1;
|
|
4130
|
+
}
|
|
4131
|
+
function parent(i) {
|
|
4132
|
+
return (i + 1 >> 1) - 1;
|
|
4133
|
+
}
|
|
4134
|
+
function smaller(x, y) {
|
|
4135
|
+
if (x.priority !== y.priority) {
|
|
4136
|
+
return x.priority < y.priority;
|
|
4137
|
+
} else {
|
|
4138
|
+
return x.pushCount < y.pushCount;
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
4141
|
+
function priorityQueue(worker, concurrency) {
|
|
4142
|
+
var q = queue(worker, concurrency);
|
|
4143
|
+
var {
|
|
4144
|
+
push,
|
|
4145
|
+
pushAsync
|
|
4146
|
+
} = q;
|
|
4147
|
+
q._tasks = new Heap();
|
|
4148
|
+
q._createTaskItem = ({ data, priority }, callback) => {
|
|
4149
|
+
return {
|
|
4150
|
+
data,
|
|
4151
|
+
priority,
|
|
4152
|
+
callback
|
|
4153
|
+
};
|
|
4154
|
+
};
|
|
4155
|
+
function createDataItems(tasks, priority) {
|
|
4156
|
+
if (!Array.isArray(tasks)) {
|
|
4157
|
+
return { data: tasks, priority };
|
|
4158
|
+
}
|
|
4159
|
+
return tasks.map((data) => {
|
|
4160
|
+
return { data, priority };
|
|
4161
|
+
});
|
|
4162
|
+
}
|
|
4163
|
+
q.push = function(data, priority = 0, callback) {
|
|
4164
|
+
return push(createDataItems(data, priority), callback);
|
|
4165
|
+
};
|
|
4166
|
+
q.pushAsync = function(data, priority = 0, callback) {
|
|
4167
|
+
return pushAsync(createDataItems(data, priority), callback);
|
|
4168
|
+
};
|
|
4169
|
+
delete q.unshift;
|
|
4170
|
+
delete q.unshiftAsync;
|
|
4171
|
+
return q;
|
|
4172
|
+
}
|
|
4173
|
+
function race(tasks, callback) {
|
|
4174
|
+
callback = once(callback);
|
|
4175
|
+
if (!Array.isArray(tasks)) return callback(new TypeError("First argument to race must be an array of functions"));
|
|
4176
|
+
if (!tasks.length) return callback();
|
|
4177
|
+
for (var i = 0, l = tasks.length; i < l; i++) {
|
|
4178
|
+
wrapAsync(tasks[i])(callback);
|
|
4179
|
+
}
|
|
4180
|
+
}
|
|
4181
|
+
function reduceRight(array, memo, iteratee, callback) {
|
|
4182
|
+
var reversed = [...array].reverse();
|
|
4183
|
+
return reduce$1(reversed, memo, iteratee, callback);
|
|
4184
|
+
}
|
|
4185
|
+
function reflect(fn) {
|
|
4186
|
+
var _fn = wrapAsync(fn);
|
|
4187
|
+
return initialParams(function reflectOn(args, reflectCallback) {
|
|
4188
|
+
args.push((error, ...cbArgs) => {
|
|
4189
|
+
let retVal = {};
|
|
4190
|
+
if (error) {
|
|
4191
|
+
retVal.error = error;
|
|
4192
|
+
}
|
|
4193
|
+
if (cbArgs.length > 0) {
|
|
4194
|
+
var value = cbArgs;
|
|
4195
|
+
if (cbArgs.length <= 1) {
|
|
4196
|
+
[value] = cbArgs;
|
|
4197
|
+
}
|
|
4198
|
+
retVal.value = value;
|
|
4199
|
+
}
|
|
4200
|
+
reflectCallback(null, retVal);
|
|
4201
|
+
});
|
|
4202
|
+
return _fn.apply(this, args);
|
|
4203
|
+
});
|
|
4204
|
+
}
|
|
4205
|
+
function reflectAll(tasks) {
|
|
4206
|
+
var results;
|
|
4207
|
+
if (Array.isArray(tasks)) {
|
|
4208
|
+
results = tasks.map(reflect);
|
|
4209
|
+
} else {
|
|
4210
|
+
results = {};
|
|
4211
|
+
Object.keys(tasks).forEach((key) => {
|
|
4212
|
+
results[key] = reflect.call(this, tasks[key]);
|
|
4213
|
+
});
|
|
4214
|
+
}
|
|
4215
|
+
return results;
|
|
4216
|
+
}
|
|
4217
|
+
function reject$2(eachfn, arr, _iteratee, callback) {
|
|
4218
|
+
const iteratee = wrapAsync(_iteratee);
|
|
4219
|
+
return _filter(eachfn, arr, (value, cb) => {
|
|
4220
|
+
iteratee(value, (err, v) => {
|
|
4221
|
+
cb(err, !v);
|
|
4222
|
+
});
|
|
4223
|
+
}, callback);
|
|
4224
|
+
}
|
|
4225
|
+
function reject(coll, iteratee, callback) {
|
|
4226
|
+
return reject$2(eachOf$1, coll, iteratee, callback);
|
|
4227
|
+
}
|
|
4228
|
+
function rejectLimit(coll, limit, iteratee, callback) {
|
|
4229
|
+
return reject$2(eachOfLimit$2(limit), coll, iteratee, callback);
|
|
4230
|
+
}
|
|
4231
|
+
function rejectSeries(coll, iteratee, callback) {
|
|
4232
|
+
return reject$2(eachOfSeries$1, coll, iteratee, callback);
|
|
4233
|
+
}
|
|
4234
|
+
function constant(value) {
|
|
4235
|
+
return function() {
|
|
4236
|
+
return value;
|
|
4237
|
+
};
|
|
4238
|
+
}
|
|
4239
|
+
function retry(opts, task, callback) {
|
|
4240
|
+
var options = {
|
|
4241
|
+
times: DEFAULT_TIMES,
|
|
4242
|
+
intervalFunc: constant(DEFAULT_INTERVAL)
|
|
4243
|
+
};
|
|
4244
|
+
if (arguments.length < 3 && typeof opts === "function") {
|
|
4245
|
+
callback = task || promiseCallback();
|
|
4246
|
+
task = opts;
|
|
4247
|
+
} else {
|
|
4248
|
+
parseTimes(options, opts);
|
|
4249
|
+
callback = callback || promiseCallback();
|
|
4250
|
+
}
|
|
4251
|
+
if (typeof task !== "function") {
|
|
4252
|
+
throw new Error("Invalid arguments for async.retry");
|
|
4253
|
+
}
|
|
4254
|
+
var _task = wrapAsync(task);
|
|
4255
|
+
var attempt = 1;
|
|
4256
|
+
function retryAttempt() {
|
|
4257
|
+
_task((err, ...args) => {
|
|
4258
|
+
if (err === false) return;
|
|
4259
|
+
if (err && attempt++ < options.times && (typeof options.errorFilter != "function" || options.errorFilter(err))) {
|
|
4260
|
+
setTimeout(retryAttempt, options.intervalFunc(attempt - 1));
|
|
4261
|
+
} else {
|
|
4262
|
+
callback(err, ...args);
|
|
4263
|
+
}
|
|
4264
|
+
});
|
|
4265
|
+
}
|
|
4266
|
+
retryAttempt();
|
|
4267
|
+
return callback[PROMISE_SYMBOL];
|
|
4268
|
+
}
|
|
4269
|
+
function parseTimes(acc, t) {
|
|
4270
|
+
if (typeof t === "object") {
|
|
4271
|
+
acc.times = +t.times || DEFAULT_TIMES;
|
|
4272
|
+
acc.intervalFunc = typeof t.interval === "function" ? t.interval : constant(+t.interval || DEFAULT_INTERVAL);
|
|
4273
|
+
acc.errorFilter = t.errorFilter;
|
|
4274
|
+
} else if (typeof t === "number" || typeof t === "string") {
|
|
4275
|
+
acc.times = +t || DEFAULT_TIMES;
|
|
4276
|
+
} else {
|
|
4277
|
+
throw new Error("Invalid arguments for async.retry");
|
|
4278
|
+
}
|
|
4279
|
+
}
|
|
4280
|
+
function retryable(opts, task) {
|
|
4281
|
+
if (!task) {
|
|
4282
|
+
task = opts;
|
|
4283
|
+
opts = null;
|
|
4284
|
+
}
|
|
4285
|
+
let arity = opts && opts.arity || task.length;
|
|
4286
|
+
if (isAsync(task)) {
|
|
4287
|
+
arity += 1;
|
|
4288
|
+
}
|
|
4289
|
+
var _task = wrapAsync(task);
|
|
4290
|
+
return initialParams((args, callback) => {
|
|
4291
|
+
if (args.length < arity - 1 || callback == null) {
|
|
4292
|
+
args.push(callback);
|
|
4293
|
+
callback = promiseCallback();
|
|
4294
|
+
}
|
|
4295
|
+
function taskFn(cb) {
|
|
4296
|
+
_task(...args, cb);
|
|
4297
|
+
}
|
|
4298
|
+
if (opts) retry(opts, taskFn, callback);
|
|
4299
|
+
else retry(taskFn, callback);
|
|
4300
|
+
return callback[PROMISE_SYMBOL];
|
|
4301
|
+
});
|
|
4302
|
+
}
|
|
4303
|
+
function series(tasks, callback) {
|
|
4304
|
+
return _parallel(eachOfSeries$1, tasks, callback);
|
|
4305
|
+
}
|
|
4306
|
+
function some(coll, iteratee, callback) {
|
|
4307
|
+
return _createTester(Boolean, (res) => res)(eachOf$1, coll, iteratee, callback);
|
|
4308
|
+
}
|
|
4309
|
+
function someLimit(coll, limit, iteratee, callback) {
|
|
4310
|
+
return _createTester(Boolean, (res) => res)(eachOfLimit$2(limit), coll, iteratee, callback);
|
|
4311
|
+
}
|
|
4312
|
+
function someSeries(coll, iteratee, callback) {
|
|
4313
|
+
return _createTester(Boolean, (res) => res)(eachOfSeries$1, coll, iteratee, callback);
|
|
4314
|
+
}
|
|
4315
|
+
function sortBy(coll, iteratee, callback) {
|
|
4316
|
+
var _iteratee = wrapAsync(iteratee);
|
|
4317
|
+
return map$1(coll, (x, iterCb) => {
|
|
4318
|
+
_iteratee(x, (err, criteria) => {
|
|
4319
|
+
if (err) return iterCb(err);
|
|
4320
|
+
iterCb(err, { value: x, criteria });
|
|
4321
|
+
});
|
|
4322
|
+
}, (err, results) => {
|
|
4323
|
+
if (err) return callback(err);
|
|
4324
|
+
callback(null, results.sort(comparator).map((v) => v.value));
|
|
4325
|
+
});
|
|
4326
|
+
function comparator(left, right) {
|
|
4327
|
+
var a = left.criteria, b = right.criteria;
|
|
4328
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
4329
|
+
}
|
|
4330
|
+
}
|
|
4331
|
+
function timeout(asyncFn, milliseconds, info) {
|
|
4332
|
+
var fn = wrapAsync(asyncFn);
|
|
4333
|
+
return initialParams((args, callback) => {
|
|
4334
|
+
var timedOut = false;
|
|
4335
|
+
var timer;
|
|
4336
|
+
function timeoutCallback() {
|
|
4337
|
+
var name = asyncFn.name || "anonymous";
|
|
4338
|
+
var error = new Error('Callback function "' + name + '" timed out.');
|
|
4339
|
+
error.code = "ETIMEDOUT";
|
|
4340
|
+
if (info) {
|
|
4341
|
+
error.info = info;
|
|
4342
|
+
}
|
|
4343
|
+
timedOut = true;
|
|
4344
|
+
callback(error);
|
|
4345
|
+
}
|
|
4346
|
+
args.push((...cbArgs) => {
|
|
4347
|
+
if (!timedOut) {
|
|
4348
|
+
callback(...cbArgs);
|
|
4349
|
+
clearTimeout(timer);
|
|
4350
|
+
}
|
|
4351
|
+
});
|
|
4352
|
+
timer = setTimeout(timeoutCallback, milliseconds);
|
|
4353
|
+
fn(...args);
|
|
4354
|
+
});
|
|
4355
|
+
}
|
|
4356
|
+
function range(size) {
|
|
4357
|
+
var result = Array(size);
|
|
4358
|
+
while (size--) {
|
|
4359
|
+
result[size] = size;
|
|
4360
|
+
}
|
|
4361
|
+
return result;
|
|
4362
|
+
}
|
|
4363
|
+
function timesLimit(count, limit, iteratee, callback) {
|
|
4364
|
+
var _iteratee = wrapAsync(iteratee);
|
|
4365
|
+
return mapLimit$1(range(count), limit, _iteratee, callback);
|
|
4366
|
+
}
|
|
4367
|
+
function times(n, iteratee, callback) {
|
|
4368
|
+
return timesLimit(n, Infinity, iteratee, callback);
|
|
4369
|
+
}
|
|
4370
|
+
function timesSeries(n, iteratee, callback) {
|
|
4371
|
+
return timesLimit(n, 1, iteratee, callback);
|
|
4372
|
+
}
|
|
4373
|
+
function transform(coll, accumulator, iteratee, callback) {
|
|
4374
|
+
if (arguments.length <= 3 && typeof accumulator === "function") {
|
|
4375
|
+
callback = iteratee;
|
|
4376
|
+
iteratee = accumulator;
|
|
4377
|
+
accumulator = Array.isArray(coll) ? [] : {};
|
|
4378
|
+
}
|
|
4379
|
+
callback = once(callback || promiseCallback());
|
|
4380
|
+
var _iteratee = wrapAsync(iteratee);
|
|
4381
|
+
eachOf$1(coll, (v, k, cb) => {
|
|
4382
|
+
_iteratee(accumulator, v, k, cb);
|
|
4383
|
+
}, (err) => callback(err, accumulator));
|
|
4384
|
+
return callback[PROMISE_SYMBOL];
|
|
4385
|
+
}
|
|
4386
|
+
function tryEach(tasks, callback) {
|
|
4387
|
+
var error = null;
|
|
4388
|
+
var result;
|
|
4389
|
+
return eachSeries$1(tasks, (task, taskCb) => {
|
|
4390
|
+
wrapAsync(task)((err, ...args) => {
|
|
4391
|
+
if (err === false) return taskCb(err);
|
|
4392
|
+
if (args.length < 2) {
|
|
4393
|
+
[result] = args;
|
|
4394
|
+
} else {
|
|
4395
|
+
result = args;
|
|
4396
|
+
}
|
|
4397
|
+
error = err;
|
|
4398
|
+
taskCb(err ? null : {});
|
|
4399
|
+
});
|
|
4400
|
+
}, () => callback(error, result));
|
|
4401
|
+
}
|
|
4402
|
+
function unmemoize(fn) {
|
|
4403
|
+
return (...args) => {
|
|
4404
|
+
return (fn.unmemoized || fn)(...args);
|
|
4405
|
+
};
|
|
4406
|
+
}
|
|
4407
|
+
function whilst(test, iteratee, callback) {
|
|
4408
|
+
callback = onlyOnce(callback);
|
|
4409
|
+
var _fn = wrapAsync(iteratee);
|
|
4410
|
+
var _test = wrapAsync(test);
|
|
4411
|
+
var results = [];
|
|
4412
|
+
function next(err, ...rest) {
|
|
4413
|
+
if (err) return callback(err);
|
|
4414
|
+
results = rest;
|
|
4415
|
+
if (err === false) return;
|
|
4416
|
+
_test(check);
|
|
4417
|
+
}
|
|
4418
|
+
function check(err, truth) {
|
|
4419
|
+
if (err) return callback(err);
|
|
4420
|
+
if (err === false) return;
|
|
4421
|
+
if (!truth) return callback(null, ...results);
|
|
4422
|
+
_fn(next);
|
|
4423
|
+
}
|
|
4424
|
+
return _test(check);
|
|
4425
|
+
}
|
|
4426
|
+
function until(test, iteratee, callback) {
|
|
4427
|
+
const _test = wrapAsync(test);
|
|
4428
|
+
return whilst$1((cb) => _test((err, truth) => cb(err, !truth)), iteratee, callback);
|
|
4429
|
+
}
|
|
4430
|
+
function waterfall(tasks, callback) {
|
|
4431
|
+
callback = once(callback);
|
|
4432
|
+
if (!Array.isArray(tasks)) return callback(new Error("First argument to waterfall must be an array of functions"));
|
|
4433
|
+
if (!tasks.length) return callback();
|
|
4434
|
+
var taskIndex = 0;
|
|
4435
|
+
function nextTask(args) {
|
|
4436
|
+
var task = wrapAsync(tasks[taskIndex++]);
|
|
4437
|
+
task(...args, onlyOnce(next));
|
|
4438
|
+
}
|
|
4439
|
+
function next(err, ...args) {
|
|
4440
|
+
if (err === false) return;
|
|
4441
|
+
if (err || taskIndex === tasks.length) {
|
|
4442
|
+
return callback(err, ...args);
|
|
4443
|
+
}
|
|
4444
|
+
nextTask(args);
|
|
4445
|
+
}
|
|
4446
|
+
nextTask([]);
|
|
4447
|
+
}
|
|
4448
|
+
var hasQueueMicrotask, hasSetImmediate, hasNextTick, _defer$1, setImmediate$1, breakLoop, eachOfLimit$2, eachOfLimit$1, eachOf$1, map$1, applyEach, eachOfSeries$1, mapSeries$1, applyEachSeries, PROMISE_SYMBOL, FN_ARGS, ARROW_FN_ARGS, FN_ARG_SPLIT, FN_ARG, DLL, reduce$1, mapLimit$1, concatLimit$1, concat$1, concatSeries$1, detect$1, detectLimit$1, detectSeries$1, dir, doWhilst$1, each, eachLimit$1, eachSeries$1, every$1, everyLimit$1, everySeries$1, filter$1, filterLimit$1, filterSeries$1, forever$1, groupByLimit$1, log, mapValuesLimit$1, _defer, nextTick, _parallel, Heap, race$1, reject$1, rejectLimit$1, rejectSeries$1, DEFAULT_TIMES, DEFAULT_INTERVAL, some$1, someLimit$1, someSeries$1, sortBy$1, tryEach$1, whilst$1, waterfall$1, index;
|
|
4449
|
+
var init_async = __esm({
|
|
4450
|
+
"../../../node_modules/async/dist/async.mjs"() {
|
|
4451
|
+
"use strict";
|
|
4452
|
+
hasQueueMicrotask = typeof queueMicrotask === "function" && queueMicrotask;
|
|
4453
|
+
hasSetImmediate = typeof setImmediate === "function" && setImmediate;
|
|
4454
|
+
hasNextTick = typeof process === "object" && typeof process.nextTick === "function";
|
|
4455
|
+
if (hasQueueMicrotask) {
|
|
4456
|
+
_defer$1 = queueMicrotask;
|
|
4457
|
+
} else if (hasSetImmediate) {
|
|
4458
|
+
_defer$1 = setImmediate;
|
|
4459
|
+
} else if (hasNextTick) {
|
|
4460
|
+
_defer$1 = process.nextTick;
|
|
4461
|
+
} else {
|
|
4462
|
+
_defer$1 = fallback;
|
|
4463
|
+
}
|
|
4464
|
+
setImmediate$1 = wrap(_defer$1);
|
|
4465
|
+
breakLoop = {};
|
|
4466
|
+
eachOfLimit$2 = (limit) => {
|
|
4467
|
+
return (obj, iteratee, callback) => {
|
|
4468
|
+
callback = once(callback);
|
|
4469
|
+
if (limit <= 0) {
|
|
4470
|
+
throw new RangeError("concurrency limit cannot be less than 1");
|
|
4471
|
+
}
|
|
4472
|
+
if (!obj) {
|
|
4473
|
+
return callback(null);
|
|
4474
|
+
}
|
|
4475
|
+
if (isAsyncGenerator(obj)) {
|
|
4476
|
+
return asyncEachOfLimit(obj, limit, iteratee, callback);
|
|
4477
|
+
}
|
|
4478
|
+
if (isAsyncIterable(obj)) {
|
|
4479
|
+
return asyncEachOfLimit(obj[Symbol.asyncIterator](), limit, iteratee, callback);
|
|
4480
|
+
}
|
|
4481
|
+
var nextElem = createIterator(obj);
|
|
4482
|
+
var done = false;
|
|
4483
|
+
var canceled = false;
|
|
4484
|
+
var running = 0;
|
|
4485
|
+
var looping = false;
|
|
4486
|
+
function iterateeCallback(err, value) {
|
|
4487
|
+
if (canceled) return;
|
|
4488
|
+
running -= 1;
|
|
4489
|
+
if (err) {
|
|
4490
|
+
done = true;
|
|
4491
|
+
callback(err);
|
|
4492
|
+
} else if (err === false) {
|
|
4493
|
+
done = true;
|
|
4494
|
+
canceled = true;
|
|
4495
|
+
} else if (value === breakLoop || done && running <= 0) {
|
|
4496
|
+
done = true;
|
|
4497
|
+
return callback(null);
|
|
4498
|
+
} else if (!looping) {
|
|
4499
|
+
replenish();
|
|
4500
|
+
}
|
|
4501
|
+
}
|
|
4502
|
+
function replenish() {
|
|
4503
|
+
looping = true;
|
|
4504
|
+
while (running < limit && !done) {
|
|
4505
|
+
var elem = nextElem();
|
|
4506
|
+
if (elem === null) {
|
|
4507
|
+
done = true;
|
|
4508
|
+
if (running <= 0) {
|
|
4509
|
+
callback(null);
|
|
4510
|
+
}
|
|
4511
|
+
return;
|
|
4512
|
+
}
|
|
4513
|
+
running += 1;
|
|
4514
|
+
iteratee(elem.value, elem.key, onlyOnce(iterateeCallback));
|
|
4515
|
+
}
|
|
4516
|
+
looping = false;
|
|
4517
|
+
}
|
|
4518
|
+
replenish();
|
|
4519
|
+
};
|
|
4520
|
+
};
|
|
4521
|
+
eachOfLimit$1 = awaitify(eachOfLimit, 4);
|
|
4522
|
+
eachOf$1 = awaitify(eachOf, 3);
|
|
4523
|
+
map$1 = awaitify(map, 3);
|
|
4524
|
+
applyEach = applyEach$1(map$1);
|
|
4525
|
+
eachOfSeries$1 = awaitify(eachOfSeries, 3);
|
|
4526
|
+
mapSeries$1 = awaitify(mapSeries, 3);
|
|
4527
|
+
applyEachSeries = applyEach$1(mapSeries$1);
|
|
4528
|
+
PROMISE_SYMBOL = /* @__PURE__ */ Symbol("promiseCallback");
|
|
4529
|
+
FN_ARGS = /^(?:async\s)?(?:function)?\s*(?:\w+\s*)?\(([^)]+)\)(?:\s*{)/;
|
|
4530
|
+
ARROW_FN_ARGS = /^(?:async\s)?\s*(?:\(\s*)?((?:[^)=\s]\s*)*)(?:\)\s*)?=>/;
|
|
4531
|
+
FN_ARG_SPLIT = /,/;
|
|
4532
|
+
FN_ARG = /(=.+)?(\s*)$/;
|
|
4533
|
+
DLL = class {
|
|
4534
|
+
constructor() {
|
|
4535
|
+
this.head = this.tail = null;
|
|
4536
|
+
this.length = 0;
|
|
4537
|
+
}
|
|
4538
|
+
removeLink(node) {
|
|
4539
|
+
if (node.prev) node.prev.next = node.next;
|
|
4540
|
+
else this.head = node.next;
|
|
4541
|
+
if (node.next) node.next.prev = node.prev;
|
|
4542
|
+
else this.tail = node.prev;
|
|
4543
|
+
node.prev = node.next = null;
|
|
4544
|
+
this.length -= 1;
|
|
4545
|
+
return node;
|
|
4546
|
+
}
|
|
4547
|
+
empty() {
|
|
4548
|
+
while (this.head) this.shift();
|
|
4549
|
+
return this;
|
|
4550
|
+
}
|
|
4551
|
+
insertAfter(node, newNode) {
|
|
4552
|
+
newNode.prev = node;
|
|
4553
|
+
newNode.next = node.next;
|
|
4554
|
+
if (node.next) node.next.prev = newNode;
|
|
4555
|
+
else this.tail = newNode;
|
|
4556
|
+
node.next = newNode;
|
|
4557
|
+
this.length += 1;
|
|
4558
|
+
}
|
|
4559
|
+
insertBefore(node, newNode) {
|
|
4560
|
+
newNode.prev = node.prev;
|
|
4561
|
+
newNode.next = node;
|
|
4562
|
+
if (node.prev) node.prev.next = newNode;
|
|
4563
|
+
else this.head = newNode;
|
|
4564
|
+
node.prev = newNode;
|
|
4565
|
+
this.length += 1;
|
|
4566
|
+
}
|
|
4567
|
+
unshift(node) {
|
|
4568
|
+
if (this.head) this.insertBefore(this.head, node);
|
|
4569
|
+
else setInitial(this, node);
|
|
4570
|
+
}
|
|
4571
|
+
push(node) {
|
|
4572
|
+
if (this.tail) this.insertAfter(this.tail, node);
|
|
4573
|
+
else setInitial(this, node);
|
|
4574
|
+
}
|
|
4575
|
+
shift() {
|
|
4576
|
+
return this.head && this.removeLink(this.head);
|
|
4577
|
+
}
|
|
4578
|
+
pop() {
|
|
4579
|
+
return this.tail && this.removeLink(this.tail);
|
|
4580
|
+
}
|
|
4581
|
+
toArray() {
|
|
4582
|
+
return [...this];
|
|
4583
|
+
}
|
|
4584
|
+
*[Symbol.iterator]() {
|
|
4585
|
+
var cur = this.head;
|
|
4586
|
+
while (cur) {
|
|
4587
|
+
yield cur.data;
|
|
4588
|
+
cur = cur.next;
|
|
4589
|
+
}
|
|
4590
|
+
}
|
|
4591
|
+
remove(testFn) {
|
|
4592
|
+
var curr = this.head;
|
|
4593
|
+
while (curr) {
|
|
4594
|
+
var { next } = curr;
|
|
4595
|
+
if (testFn(curr)) {
|
|
4596
|
+
this.removeLink(curr);
|
|
4597
|
+
}
|
|
4598
|
+
curr = next;
|
|
4599
|
+
}
|
|
4600
|
+
return this;
|
|
4601
|
+
}
|
|
4602
|
+
};
|
|
4603
|
+
reduce$1 = awaitify(reduce, 4);
|
|
4604
|
+
mapLimit$1 = awaitify(mapLimit, 4);
|
|
4605
|
+
concatLimit$1 = awaitify(concatLimit, 4);
|
|
4606
|
+
concat$1 = awaitify(concat, 3);
|
|
4607
|
+
concatSeries$1 = awaitify(concatSeries, 3);
|
|
4608
|
+
detect$1 = awaitify(detect, 3);
|
|
4609
|
+
detectLimit$1 = awaitify(detectLimit, 4);
|
|
4610
|
+
detectSeries$1 = awaitify(detectSeries, 3);
|
|
4611
|
+
dir = consoleFunc("dir");
|
|
4612
|
+
doWhilst$1 = awaitify(doWhilst, 3);
|
|
4613
|
+
each = awaitify(eachLimit$2, 3);
|
|
4614
|
+
eachLimit$1 = awaitify(eachLimit, 4);
|
|
4615
|
+
eachSeries$1 = awaitify(eachSeries, 3);
|
|
4616
|
+
every$1 = awaitify(every, 3);
|
|
4617
|
+
everyLimit$1 = awaitify(everyLimit, 4);
|
|
4618
|
+
everySeries$1 = awaitify(everySeries, 3);
|
|
4619
|
+
filter$1 = awaitify(filter, 3);
|
|
4620
|
+
filterLimit$1 = awaitify(filterLimit, 4);
|
|
4621
|
+
filterSeries$1 = awaitify(filterSeries, 3);
|
|
4622
|
+
forever$1 = awaitify(forever, 2);
|
|
4623
|
+
groupByLimit$1 = awaitify(groupByLimit, 4);
|
|
4624
|
+
log = consoleFunc("log");
|
|
4625
|
+
mapValuesLimit$1 = awaitify(mapValuesLimit, 4);
|
|
4626
|
+
if (hasNextTick) {
|
|
4627
|
+
_defer = process.nextTick;
|
|
4628
|
+
} else if (hasSetImmediate) {
|
|
4629
|
+
_defer = setImmediate;
|
|
4630
|
+
} else {
|
|
4631
|
+
_defer = fallback;
|
|
4632
|
+
}
|
|
4633
|
+
nextTick = wrap(_defer);
|
|
4634
|
+
_parallel = awaitify((eachfn, tasks, callback) => {
|
|
4635
|
+
var results = isArrayLike(tasks) ? [] : {};
|
|
4636
|
+
eachfn(tasks, (task, key, taskCb) => {
|
|
4637
|
+
wrapAsync(task)((err, ...result) => {
|
|
4638
|
+
if (result.length < 2) {
|
|
4639
|
+
[result] = result;
|
|
4640
|
+
}
|
|
4641
|
+
results[key] = result;
|
|
4642
|
+
taskCb(err);
|
|
4643
|
+
});
|
|
4644
|
+
}, (err) => callback(err, results));
|
|
4645
|
+
}, 3);
|
|
4646
|
+
Heap = class {
|
|
4647
|
+
constructor() {
|
|
4648
|
+
this.heap = [];
|
|
4649
|
+
this.pushCount = Number.MIN_SAFE_INTEGER;
|
|
4650
|
+
}
|
|
4651
|
+
get length() {
|
|
4652
|
+
return this.heap.length;
|
|
4653
|
+
}
|
|
4654
|
+
empty() {
|
|
4655
|
+
this.heap = [];
|
|
4656
|
+
return this;
|
|
4657
|
+
}
|
|
4658
|
+
percUp(index2) {
|
|
4659
|
+
let p;
|
|
4660
|
+
while (index2 > 0 && smaller(this.heap[index2], this.heap[p = parent(index2)])) {
|
|
4661
|
+
let t = this.heap[index2];
|
|
4662
|
+
this.heap[index2] = this.heap[p];
|
|
4663
|
+
this.heap[p] = t;
|
|
4664
|
+
index2 = p;
|
|
4665
|
+
}
|
|
4666
|
+
}
|
|
4667
|
+
percDown(index2) {
|
|
4668
|
+
let l;
|
|
4669
|
+
while ((l = leftChi(index2)) < this.heap.length) {
|
|
4670
|
+
if (l + 1 < this.heap.length && smaller(this.heap[l + 1], this.heap[l])) {
|
|
4671
|
+
l = l + 1;
|
|
4672
|
+
}
|
|
4673
|
+
if (smaller(this.heap[index2], this.heap[l])) {
|
|
4674
|
+
break;
|
|
4675
|
+
}
|
|
4676
|
+
let t = this.heap[index2];
|
|
4677
|
+
this.heap[index2] = this.heap[l];
|
|
4678
|
+
this.heap[l] = t;
|
|
4679
|
+
index2 = l;
|
|
4680
|
+
}
|
|
4681
|
+
}
|
|
4682
|
+
push(node) {
|
|
4683
|
+
node.pushCount = ++this.pushCount;
|
|
4684
|
+
this.heap.push(node);
|
|
4685
|
+
this.percUp(this.heap.length - 1);
|
|
4686
|
+
}
|
|
4687
|
+
unshift(node) {
|
|
4688
|
+
return this.heap.push(node);
|
|
4689
|
+
}
|
|
4690
|
+
shift() {
|
|
4691
|
+
let [top] = this.heap;
|
|
4692
|
+
this.heap[0] = this.heap[this.heap.length - 1];
|
|
4693
|
+
this.heap.pop();
|
|
4694
|
+
this.percDown(0);
|
|
4695
|
+
return top;
|
|
4696
|
+
}
|
|
4697
|
+
toArray() {
|
|
4698
|
+
return [...this];
|
|
4699
|
+
}
|
|
4700
|
+
*[Symbol.iterator]() {
|
|
4701
|
+
for (let i = 0; i < this.heap.length; i++) {
|
|
4702
|
+
yield this.heap[i].data;
|
|
4703
|
+
}
|
|
4704
|
+
}
|
|
4705
|
+
remove(testFn) {
|
|
4706
|
+
let j = 0;
|
|
4707
|
+
for (let i = 0; i < this.heap.length; i++) {
|
|
4708
|
+
if (!testFn(this.heap[i])) {
|
|
4709
|
+
this.heap[j] = this.heap[i];
|
|
4710
|
+
j++;
|
|
4711
|
+
}
|
|
4712
|
+
}
|
|
4713
|
+
this.heap.splice(j);
|
|
4714
|
+
for (let i = parent(this.heap.length - 1); i >= 0; i--) {
|
|
4715
|
+
this.percDown(i);
|
|
4716
|
+
}
|
|
4717
|
+
return this;
|
|
4718
|
+
}
|
|
4719
|
+
};
|
|
4720
|
+
race$1 = awaitify(race, 2);
|
|
4721
|
+
reject$1 = awaitify(reject, 3);
|
|
4722
|
+
rejectLimit$1 = awaitify(rejectLimit, 4);
|
|
4723
|
+
rejectSeries$1 = awaitify(rejectSeries, 3);
|
|
4724
|
+
DEFAULT_TIMES = 5;
|
|
4725
|
+
DEFAULT_INTERVAL = 0;
|
|
4726
|
+
some$1 = awaitify(some, 3);
|
|
4727
|
+
someLimit$1 = awaitify(someLimit, 4);
|
|
4728
|
+
someSeries$1 = awaitify(someSeries, 3);
|
|
4729
|
+
sortBy$1 = awaitify(sortBy, 3);
|
|
4730
|
+
tryEach$1 = awaitify(tryEach);
|
|
4731
|
+
whilst$1 = awaitify(whilst, 3);
|
|
4732
|
+
waterfall$1 = awaitify(waterfall);
|
|
4733
|
+
index = {
|
|
4734
|
+
apply,
|
|
4735
|
+
applyEach,
|
|
4736
|
+
applyEachSeries,
|
|
4737
|
+
asyncify,
|
|
4738
|
+
auto,
|
|
4739
|
+
autoInject,
|
|
4740
|
+
cargo: cargo$1,
|
|
4741
|
+
cargoQueue: cargo,
|
|
4742
|
+
compose,
|
|
4743
|
+
concat: concat$1,
|
|
4744
|
+
concatLimit: concatLimit$1,
|
|
4745
|
+
concatSeries: concatSeries$1,
|
|
4746
|
+
constant: constant$1,
|
|
4747
|
+
detect: detect$1,
|
|
4748
|
+
detectLimit: detectLimit$1,
|
|
4749
|
+
detectSeries: detectSeries$1,
|
|
4750
|
+
dir,
|
|
4751
|
+
doUntil,
|
|
4752
|
+
doWhilst: doWhilst$1,
|
|
4753
|
+
each,
|
|
4754
|
+
eachLimit: eachLimit$1,
|
|
4755
|
+
eachOf: eachOf$1,
|
|
4756
|
+
eachOfLimit: eachOfLimit$1,
|
|
4757
|
+
eachOfSeries: eachOfSeries$1,
|
|
4758
|
+
eachSeries: eachSeries$1,
|
|
4759
|
+
ensureAsync,
|
|
4760
|
+
every: every$1,
|
|
4761
|
+
everyLimit: everyLimit$1,
|
|
4762
|
+
everySeries: everySeries$1,
|
|
4763
|
+
filter: filter$1,
|
|
4764
|
+
filterLimit: filterLimit$1,
|
|
4765
|
+
filterSeries: filterSeries$1,
|
|
4766
|
+
forever: forever$1,
|
|
4767
|
+
groupBy,
|
|
4768
|
+
groupByLimit: groupByLimit$1,
|
|
4769
|
+
groupBySeries,
|
|
4770
|
+
log,
|
|
4771
|
+
map: map$1,
|
|
4772
|
+
mapLimit: mapLimit$1,
|
|
4773
|
+
mapSeries: mapSeries$1,
|
|
4774
|
+
mapValues,
|
|
4775
|
+
mapValuesLimit: mapValuesLimit$1,
|
|
4776
|
+
mapValuesSeries,
|
|
4777
|
+
memoize,
|
|
4778
|
+
nextTick,
|
|
4779
|
+
parallel,
|
|
4780
|
+
parallelLimit,
|
|
4781
|
+
priorityQueue,
|
|
4782
|
+
queue,
|
|
4783
|
+
race: race$1,
|
|
4784
|
+
reduce: reduce$1,
|
|
4785
|
+
reduceRight,
|
|
4786
|
+
reflect,
|
|
4787
|
+
reflectAll,
|
|
4788
|
+
reject: reject$1,
|
|
4789
|
+
rejectLimit: rejectLimit$1,
|
|
4790
|
+
rejectSeries: rejectSeries$1,
|
|
4791
|
+
retry,
|
|
4792
|
+
retryable,
|
|
4793
|
+
seq,
|
|
4794
|
+
series,
|
|
4795
|
+
setImmediate: setImmediate$1,
|
|
4796
|
+
some: some$1,
|
|
4797
|
+
someLimit: someLimit$1,
|
|
4798
|
+
someSeries: someSeries$1,
|
|
4799
|
+
sortBy: sortBy$1,
|
|
4800
|
+
timeout,
|
|
4801
|
+
times,
|
|
4802
|
+
timesLimit,
|
|
4803
|
+
timesSeries,
|
|
4804
|
+
transform,
|
|
4805
|
+
tryEach: tryEach$1,
|
|
4806
|
+
unmemoize,
|
|
4807
|
+
until,
|
|
4808
|
+
waterfall: waterfall$1,
|
|
4809
|
+
whilst: whilst$1,
|
|
4810
|
+
// aliases
|
|
4811
|
+
all: every$1,
|
|
4812
|
+
allLimit: everyLimit$1,
|
|
4813
|
+
allSeries: everySeries$1,
|
|
4814
|
+
any: some$1,
|
|
4815
|
+
anyLimit: someLimit$1,
|
|
4816
|
+
anySeries: someSeries$1,
|
|
4817
|
+
find: detect$1,
|
|
4818
|
+
findLimit: detectLimit$1,
|
|
4819
|
+
findSeries: detectSeries$1,
|
|
4820
|
+
flatMap: concat$1,
|
|
4821
|
+
flatMapLimit: concatLimit$1,
|
|
4822
|
+
flatMapSeries: concatSeries$1,
|
|
4823
|
+
forEach: each,
|
|
4824
|
+
forEachSeries: eachSeries$1,
|
|
4825
|
+
forEachLimit: eachLimit$1,
|
|
4826
|
+
forEachOf: eachOf$1,
|
|
4827
|
+
forEachOfSeries: eachOfSeries$1,
|
|
4828
|
+
forEachOfLimit: eachOfLimit$1,
|
|
4829
|
+
inject: reduce$1,
|
|
4830
|
+
foldl: reduce$1,
|
|
4831
|
+
foldr: reduceRight,
|
|
4832
|
+
select: filter$1,
|
|
4833
|
+
selectLimit: filterLimit$1,
|
|
4834
|
+
selectSeries: filterSeries$1,
|
|
4835
|
+
wrapSync: asyncify,
|
|
4836
|
+
during: whilst$1,
|
|
4837
|
+
doDuring: doWhilst$1
|
|
4838
|
+
};
|
|
4839
|
+
}
|
|
4840
|
+
});
|
|
4841
|
+
|
|
4842
|
+
// ../../../node_modules/tmp/lib/tmp.js
|
|
4843
|
+
var require_tmp = __commonJS({
|
|
4844
|
+
"../../../node_modules/tmp/lib/tmp.js"(exports, module) {
|
|
4845
|
+
"use strict";
|
|
4846
|
+
var fs = __require("fs");
|
|
4847
|
+
var os = __require("os");
|
|
4848
|
+
var path = __require("path");
|
|
4849
|
+
var crypto = __require("crypto");
|
|
4850
|
+
var _c = { fs: fs.constants, os: os.constants };
|
|
4851
|
+
var RANDOM_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
4852
|
+
var TEMPLATE_PATTERN = /XXXXXX/;
|
|
4853
|
+
var DEFAULT_TRIES = 3;
|
|
4854
|
+
var CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR);
|
|
4855
|
+
var IS_WIN32 = os.platform() === "win32";
|
|
4856
|
+
var EBADF = _c.EBADF || _c.os.errno.EBADF;
|
|
4857
|
+
var ENOENT = _c.ENOENT || _c.os.errno.ENOENT;
|
|
4858
|
+
var DIR_MODE = 448;
|
|
4859
|
+
var FILE_MODE = 384;
|
|
4860
|
+
var EXIT = "exit";
|
|
4861
|
+
var _removeObjects = [];
|
|
4862
|
+
var FN_RMDIR_SYNC = fs.rmdirSync.bind(fs);
|
|
4863
|
+
var _gracefulCleanup = false;
|
|
4864
|
+
function rimraf(dirPath, callback) {
|
|
4865
|
+
return fs.rm(dirPath, { recursive: true }, callback);
|
|
4866
|
+
}
|
|
4867
|
+
function FN_RIMRAF_SYNC(dirPath) {
|
|
4868
|
+
return fs.rmSync(dirPath, { recursive: true });
|
|
4869
|
+
}
|
|
4870
|
+
function tmpName(options, callback) {
|
|
4871
|
+
const args = _parseArguments(options, callback), opts = args[0], cb = args[1];
|
|
4872
|
+
_assertAndSanitizeOptions(opts, function(err, sanitizedOptions) {
|
|
4873
|
+
if (err) return cb(err);
|
|
4874
|
+
let tries = sanitizedOptions.tries;
|
|
4875
|
+
(function _getUniqueName() {
|
|
4876
|
+
try {
|
|
4877
|
+
const name = _generateTmpName(sanitizedOptions);
|
|
4878
|
+
fs.stat(name, function(err2) {
|
|
4879
|
+
if (!err2) {
|
|
4880
|
+
if (tries-- > 0) return _getUniqueName();
|
|
4881
|
+
return cb(new Error("Could not get a unique tmp filename, max tries reached " + name));
|
|
4882
|
+
}
|
|
4883
|
+
cb(null, name);
|
|
4884
|
+
});
|
|
4885
|
+
} catch (err2) {
|
|
4886
|
+
cb(err2);
|
|
4887
|
+
}
|
|
4888
|
+
})();
|
|
4889
|
+
});
|
|
4890
|
+
}
|
|
4891
|
+
function tmpNameSync(options) {
|
|
4892
|
+
const args = _parseArguments(options), opts = args[0];
|
|
4893
|
+
const sanitizedOptions = _assertAndSanitizeOptionsSync(opts);
|
|
4894
|
+
let tries = sanitizedOptions.tries;
|
|
4895
|
+
do {
|
|
4896
|
+
const name = _generateTmpName(sanitizedOptions);
|
|
4897
|
+
try {
|
|
4898
|
+
fs.statSync(name);
|
|
4899
|
+
} catch (e) {
|
|
4900
|
+
return name;
|
|
4901
|
+
}
|
|
4902
|
+
} while (tries-- > 0);
|
|
4903
|
+
throw new Error("Could not get a unique tmp filename, max tries reached");
|
|
4904
|
+
}
|
|
4905
|
+
function file(options, callback) {
|
|
4906
|
+
const args = _parseArguments(options, callback), opts = args[0], cb = args[1];
|
|
4907
|
+
tmpName(opts, function _tmpNameCreated(err, name) {
|
|
4908
|
+
if (err) return cb(err);
|
|
4909
|
+
fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err2, fd) {
|
|
4910
|
+
if (err2) return cb(err2);
|
|
4911
|
+
if (opts.discardDescriptor) {
|
|
4912
|
+
return fs.close(fd, function _discardCallback(possibleErr) {
|
|
4913
|
+
return cb(possibleErr, name, void 0, _prepareTmpFileRemoveCallback(name, -1, opts, false));
|
|
4914
|
+
});
|
|
4915
|
+
} else {
|
|
4916
|
+
const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
|
|
4917
|
+
cb(null, name, fd, _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, false));
|
|
4918
|
+
}
|
|
4919
|
+
});
|
|
4920
|
+
});
|
|
4921
|
+
}
|
|
4922
|
+
function fileSync(options) {
|
|
4923
|
+
const args = _parseArguments(options), opts = args[0];
|
|
4924
|
+
const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
|
|
4925
|
+
const name = tmpNameSync(opts);
|
|
4926
|
+
let fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
|
|
4927
|
+
if (opts.discardDescriptor) {
|
|
4928
|
+
fs.closeSync(fd);
|
|
4929
|
+
fd = void 0;
|
|
4930
|
+
}
|
|
4931
|
+
return {
|
|
4932
|
+
name,
|
|
4933
|
+
fd,
|
|
4934
|
+
removeCallback: _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, true)
|
|
4935
|
+
};
|
|
4936
|
+
}
|
|
4937
|
+
function dir2(options, callback) {
|
|
4938
|
+
const args = _parseArguments(options, callback), opts = args[0], cb = args[1];
|
|
4939
|
+
tmpName(opts, function _tmpNameCreated(err, name) {
|
|
4940
|
+
if (err) return cb(err);
|
|
4941
|
+
fs.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err2) {
|
|
4942
|
+
if (err2) return cb(err2);
|
|
4943
|
+
cb(null, name, _prepareTmpDirRemoveCallback(name, opts, false));
|
|
4944
|
+
});
|
|
4945
|
+
});
|
|
4946
|
+
}
|
|
4947
|
+
function dirSync(options) {
|
|
4948
|
+
const args = _parseArguments(options), opts = args[0];
|
|
4949
|
+
const name = tmpNameSync(opts);
|
|
4950
|
+
fs.mkdirSync(name, opts.mode || DIR_MODE);
|
|
4951
|
+
return {
|
|
4952
|
+
name,
|
|
4953
|
+
removeCallback: _prepareTmpDirRemoveCallback(name, opts, true)
|
|
4954
|
+
};
|
|
4955
|
+
}
|
|
4956
|
+
function _removeFileAsync(fdPath, next) {
|
|
4957
|
+
const _handler = function(err) {
|
|
4958
|
+
if (err && !_isENOENT(err)) {
|
|
4959
|
+
return next(err);
|
|
4960
|
+
}
|
|
4961
|
+
next();
|
|
4962
|
+
};
|
|
4963
|
+
if (0 <= fdPath[0])
|
|
4964
|
+
fs.close(fdPath[0], function() {
|
|
4965
|
+
fs.unlink(fdPath[1], _handler);
|
|
4966
|
+
});
|
|
4967
|
+
else fs.unlink(fdPath[1], _handler);
|
|
4968
|
+
}
|
|
4969
|
+
function _removeFileSync(fdPath) {
|
|
4970
|
+
let rethrownException = null;
|
|
4971
|
+
try {
|
|
4972
|
+
if (0 <= fdPath[0]) fs.closeSync(fdPath[0]);
|
|
4973
|
+
} catch (e) {
|
|
4974
|
+
if (!_isEBADF(e) && !_isENOENT(e)) throw e;
|
|
4975
|
+
} finally {
|
|
4976
|
+
try {
|
|
4977
|
+
fs.unlinkSync(fdPath[1]);
|
|
4978
|
+
} catch (e) {
|
|
4979
|
+
if (!_isENOENT(e)) rethrownException = e;
|
|
4980
|
+
}
|
|
4981
|
+
}
|
|
4982
|
+
if (rethrownException !== null) {
|
|
4983
|
+
throw rethrownException;
|
|
4984
|
+
}
|
|
4985
|
+
}
|
|
4986
|
+
function _prepareTmpFileRemoveCallback(name, fd, opts, sync) {
|
|
4987
|
+
const removeCallbackSync = _prepareRemoveCallback(_removeFileSync, [fd, name], sync);
|
|
4988
|
+
const removeCallback = _prepareRemoveCallback(_removeFileAsync, [fd, name], sync, removeCallbackSync);
|
|
4989
|
+
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
|
|
4990
|
+
return sync ? removeCallbackSync : removeCallback;
|
|
4991
|
+
}
|
|
4992
|
+
function _prepareTmpDirRemoveCallback(name, opts, sync) {
|
|
4993
|
+
const removeFunction = opts.unsafeCleanup ? rimraf : fs.rmdir.bind(fs);
|
|
4994
|
+
const removeFunctionSync = opts.unsafeCleanup ? FN_RIMRAF_SYNC : FN_RMDIR_SYNC;
|
|
4995
|
+
const removeCallbackSync = _prepareRemoveCallback(removeFunctionSync, name, sync);
|
|
4996
|
+
const removeCallback = _prepareRemoveCallback(removeFunction, name, sync, removeCallbackSync);
|
|
4997
|
+
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
|
|
4998
|
+
return sync ? removeCallbackSync : removeCallback;
|
|
4999
|
+
}
|
|
5000
|
+
function _prepareRemoveCallback(removeFunction, fileOrDirName, sync, cleanupCallbackSync) {
|
|
5001
|
+
let called = false;
|
|
5002
|
+
return function _cleanupCallback(next) {
|
|
5003
|
+
if (!called) {
|
|
5004
|
+
const toRemove = cleanupCallbackSync || _cleanupCallback;
|
|
5005
|
+
const index2 = _removeObjects.indexOf(toRemove);
|
|
5006
|
+
if (index2 >= 0) _removeObjects.splice(index2, 1);
|
|
5007
|
+
called = true;
|
|
5008
|
+
if (sync || removeFunction === FN_RMDIR_SYNC || removeFunction === FN_RIMRAF_SYNC) {
|
|
5009
|
+
return removeFunction(fileOrDirName);
|
|
5010
|
+
} else {
|
|
5011
|
+
return removeFunction(fileOrDirName, next || function() {
|
|
5012
|
+
});
|
|
5013
|
+
}
|
|
5014
|
+
}
|
|
5015
|
+
};
|
|
5016
|
+
}
|
|
5017
|
+
function _garbageCollector() {
|
|
5018
|
+
if (!_gracefulCleanup) return;
|
|
5019
|
+
while (_removeObjects.length) {
|
|
5020
|
+
try {
|
|
5021
|
+
_removeObjects[0]();
|
|
5022
|
+
} catch (e) {
|
|
5023
|
+
}
|
|
5024
|
+
}
|
|
5025
|
+
}
|
|
5026
|
+
function _randomChars(howMany) {
|
|
5027
|
+
let value = [], rnd = null;
|
|
5028
|
+
try {
|
|
5029
|
+
rnd = crypto.randomBytes(howMany);
|
|
5030
|
+
} catch (e) {
|
|
5031
|
+
rnd = crypto.pseudoRandomBytes(howMany);
|
|
5032
|
+
}
|
|
5033
|
+
for (let i = 0; i < howMany; i++) {
|
|
5034
|
+
value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
|
|
5035
|
+
}
|
|
5036
|
+
return value.join("");
|
|
5037
|
+
}
|
|
5038
|
+
function _isUndefined(obj) {
|
|
5039
|
+
return typeof obj === "undefined";
|
|
5040
|
+
}
|
|
5041
|
+
function _parseArguments(options, callback) {
|
|
5042
|
+
if (typeof options === "function") {
|
|
5043
|
+
return [{}, options];
|
|
5044
|
+
}
|
|
5045
|
+
if (_isUndefined(options)) {
|
|
5046
|
+
return [{}, callback];
|
|
5047
|
+
}
|
|
5048
|
+
const actualOptions = {};
|
|
5049
|
+
for (const key of Object.getOwnPropertyNames(options)) {
|
|
5050
|
+
actualOptions[key] = options[key];
|
|
5051
|
+
}
|
|
5052
|
+
return [actualOptions, callback];
|
|
5053
|
+
}
|
|
5054
|
+
function _resolvePath(name, tmpDir, cb) {
|
|
5055
|
+
const pathToResolve = path.isAbsolute(name) ? name : path.join(tmpDir, name);
|
|
5056
|
+
fs.stat(pathToResolve, function(err) {
|
|
5057
|
+
if (err) {
|
|
5058
|
+
fs.realpath(path.dirname(pathToResolve), function(err2, parentDir) {
|
|
5059
|
+
if (err2) return cb(err2);
|
|
5060
|
+
cb(null, path.join(parentDir, path.basename(pathToResolve)));
|
|
5061
|
+
});
|
|
5062
|
+
} else {
|
|
5063
|
+
fs.realpath(pathToResolve, cb);
|
|
5064
|
+
}
|
|
5065
|
+
});
|
|
5066
|
+
}
|
|
5067
|
+
function _resolvePathSync(name, tmpDir) {
|
|
5068
|
+
const pathToResolve = path.isAbsolute(name) ? name : path.join(tmpDir, name);
|
|
5069
|
+
try {
|
|
5070
|
+
fs.statSync(pathToResolve);
|
|
5071
|
+
return fs.realpathSync(pathToResolve);
|
|
5072
|
+
} catch (_err) {
|
|
5073
|
+
const parentDir = fs.realpathSync(path.dirname(pathToResolve));
|
|
5074
|
+
return path.join(parentDir, path.basename(pathToResolve));
|
|
5075
|
+
}
|
|
5076
|
+
}
|
|
5077
|
+
function _generateTmpName(opts) {
|
|
5078
|
+
const tmpDir = opts.tmpdir;
|
|
5079
|
+
if (!_isUndefined(opts.name)) {
|
|
5080
|
+
return path.join(tmpDir, opts.dir, opts.name);
|
|
5081
|
+
}
|
|
5082
|
+
if (!_isUndefined(opts.template)) {
|
|
5083
|
+
return path.join(tmpDir, opts.dir, opts.template).replace(TEMPLATE_PATTERN, _randomChars(6));
|
|
5084
|
+
}
|
|
5085
|
+
const name = [
|
|
5086
|
+
opts.prefix ? opts.prefix : "tmp",
|
|
5087
|
+
"-",
|
|
5088
|
+
process.pid,
|
|
5089
|
+
"-",
|
|
5090
|
+
_randomChars(12),
|
|
5091
|
+
opts.postfix ? "-" + opts.postfix : ""
|
|
5092
|
+
].join("");
|
|
5093
|
+
return path.join(tmpDir, opts.dir, name);
|
|
5094
|
+
}
|
|
5095
|
+
function _assertOptionsBase(options) {
|
|
5096
|
+
if (!_isUndefined(options.name)) {
|
|
5097
|
+
const name = options.name;
|
|
5098
|
+
if (path.isAbsolute(name)) throw new Error(`name option must not contain an absolute path, found "${name}".`);
|
|
5099
|
+
const basename3 = path.basename(name);
|
|
5100
|
+
if (basename3 === ".." || basename3 === "." || basename3 !== name)
|
|
5101
|
+
throw new Error(`name option must not contain a path, found "${name}".`);
|
|
5102
|
+
}
|
|
5103
|
+
if (!_isUndefined(options.template) && !options.template.match(TEMPLATE_PATTERN)) {
|
|
5104
|
+
throw new Error(`Invalid template, found "${options.template}".`);
|
|
5105
|
+
}
|
|
5106
|
+
if (!_isUndefined(options.tries) && isNaN(options.tries) || options.tries < 0) {
|
|
5107
|
+
throw new Error(`Invalid tries, found "${options.tries}".`);
|
|
5108
|
+
}
|
|
5109
|
+
options.tries = _isUndefined(options.name) ? options.tries || DEFAULT_TRIES : 1;
|
|
5110
|
+
options.keep = !!options.keep;
|
|
5111
|
+
options.detachDescriptor = !!options.detachDescriptor;
|
|
5112
|
+
options.discardDescriptor = !!options.discardDescriptor;
|
|
5113
|
+
options.unsafeCleanup = !!options.unsafeCleanup;
|
|
5114
|
+
options.prefix = _isUndefined(options.prefix) ? "" : options.prefix;
|
|
5115
|
+
options.postfix = _isUndefined(options.postfix) ? "" : options.postfix;
|
|
5116
|
+
}
|
|
5117
|
+
function _getRelativePath(option, name, tmpDir, cb) {
|
|
5118
|
+
if (_isUndefined(name)) return cb(null);
|
|
5119
|
+
_resolvePath(name, tmpDir, function(err, resolvedPath) {
|
|
5120
|
+
if (err) return cb(err);
|
|
5121
|
+
const relativePath = path.relative(tmpDir, resolvedPath);
|
|
5122
|
+
if (!resolvedPath.startsWith(tmpDir)) {
|
|
5123
|
+
return cb(new Error(`${option} option must be relative to "${tmpDir}", found "${relativePath}".`));
|
|
5124
|
+
}
|
|
5125
|
+
cb(null, relativePath);
|
|
5126
|
+
});
|
|
5127
|
+
}
|
|
5128
|
+
function _getRelativePathSync(option, name, tmpDir) {
|
|
5129
|
+
if (_isUndefined(name)) return;
|
|
5130
|
+
const resolvedPath = _resolvePathSync(name, tmpDir);
|
|
5131
|
+
const relativePath = path.relative(tmpDir, resolvedPath);
|
|
5132
|
+
if (!resolvedPath.startsWith(tmpDir)) {
|
|
5133
|
+
throw new Error(`${option} option must be relative to "${tmpDir}", found "${relativePath}".`);
|
|
5134
|
+
}
|
|
5135
|
+
return relativePath;
|
|
5136
|
+
}
|
|
5137
|
+
function _assertAndSanitizeOptions(options, cb) {
|
|
5138
|
+
_getTmpDir(options, function(err, tmpDir) {
|
|
5139
|
+
if (err) return cb(err);
|
|
5140
|
+
options.tmpdir = tmpDir;
|
|
5141
|
+
try {
|
|
5142
|
+
_assertOptionsBase(options, tmpDir);
|
|
5143
|
+
} catch (err2) {
|
|
5144
|
+
return cb(err2);
|
|
5145
|
+
}
|
|
5146
|
+
_getRelativePath("dir", options.dir, tmpDir, function(err2, dir3) {
|
|
5147
|
+
if (err2) return cb(err2);
|
|
5148
|
+
options.dir = _isUndefined(dir3) ? "" : dir3;
|
|
5149
|
+
_getRelativePath("template", options.template, tmpDir, function(err3, template) {
|
|
5150
|
+
if (err3) return cb(err3);
|
|
5151
|
+
options.template = template;
|
|
5152
|
+
cb(null, options);
|
|
5153
|
+
});
|
|
5154
|
+
});
|
|
5155
|
+
});
|
|
5156
|
+
}
|
|
5157
|
+
function _assertAndSanitizeOptionsSync(options) {
|
|
5158
|
+
const tmpDir = options.tmpdir = _getTmpDirSync(options);
|
|
5159
|
+
_assertOptionsBase(options, tmpDir);
|
|
5160
|
+
const dir3 = _getRelativePathSync("dir", options.dir, tmpDir);
|
|
5161
|
+
options.dir = _isUndefined(dir3) ? "" : dir3;
|
|
5162
|
+
options.template = _getRelativePathSync("template", options.template, tmpDir);
|
|
5163
|
+
return options;
|
|
5164
|
+
}
|
|
5165
|
+
function _isEBADF(error) {
|
|
5166
|
+
return _isExpectedError(error, -EBADF, "EBADF");
|
|
5167
|
+
}
|
|
5168
|
+
function _isENOENT(error) {
|
|
5169
|
+
return _isExpectedError(error, -ENOENT, "ENOENT");
|
|
5170
|
+
}
|
|
5171
|
+
function _isExpectedError(error, errno, code) {
|
|
5172
|
+
return IS_WIN32 ? error.code === code : error.code === code && error.errno === errno;
|
|
5173
|
+
}
|
|
5174
|
+
function setGracefulCleanup() {
|
|
5175
|
+
_gracefulCleanup = true;
|
|
5176
|
+
}
|
|
5177
|
+
function _getTmpDir(options, cb) {
|
|
5178
|
+
return fs.realpath(options && options.tmpdir || os.tmpdir(), cb);
|
|
5179
|
+
}
|
|
5180
|
+
function _getTmpDirSync(options) {
|
|
5181
|
+
return fs.realpathSync(options && options.tmpdir || os.tmpdir());
|
|
5182
|
+
}
|
|
5183
|
+
process.addListener(EXIT, _garbageCollector);
|
|
5184
|
+
Object.defineProperty(module.exports, "tmpdir", {
|
|
5185
|
+
enumerable: true,
|
|
5186
|
+
configurable: false,
|
|
5187
|
+
get: function() {
|
|
5188
|
+
return _getTmpDirSync();
|
|
5189
|
+
}
|
|
5190
|
+
});
|
|
5191
|
+
module.exports.dir = dir2;
|
|
5192
|
+
module.exports.dirSync = dirSync;
|
|
5193
|
+
module.exports.file = file;
|
|
5194
|
+
module.exports.fileSync = fileSync;
|
|
5195
|
+
module.exports.tmpName = tmpName;
|
|
5196
|
+
module.exports.tmpNameSync = tmpNameSync;
|
|
5197
|
+
module.exports.setGracefulCleanup = setGracefulCleanup;
|
|
5198
|
+
}
|
|
5199
|
+
});
|
|
5200
|
+
|
|
5201
|
+
// ../../../node_modules/libreoffice-convert/index.js
|
|
5202
|
+
var require_libreoffice_convert = __commonJS({
|
|
5203
|
+
"../../../node_modules/libreoffice-convert/index.js"(exports, module) {
|
|
5204
|
+
"use strict";
|
|
5205
|
+
var fs = __require("fs");
|
|
5206
|
+
var path = __require("path");
|
|
5207
|
+
var url = __require("url");
|
|
5208
|
+
var async = (init_async(), __toCommonJS(async_exports));
|
|
5209
|
+
var tmp = require_tmp();
|
|
5210
|
+
var { execFile } = __require("child_process");
|
|
5211
|
+
var convertWithOptions = (document, format, filter2, options, callback) => {
|
|
5212
|
+
const tmpOptions = (options || {}).tmpOptions || {};
|
|
5213
|
+
const asyncOptions = (options || {}).asyncOptions || {};
|
|
5214
|
+
const execOptions = (options || {}).execOptions || {};
|
|
5215
|
+
const fileName = (options || {}).fileName || "source";
|
|
5216
|
+
const sofficeAdditionalArgs = (options || {}).sofficeAdditionalArgs || [];
|
|
5217
|
+
const tempDir = tmp.dirSync({ prefix: "libreofficeConvert_", unsafeCleanup: true, ...tmpOptions });
|
|
5218
|
+
const installDir = tmp.dirSync({ prefix: "soffice", unsafeCleanup: true, ...tmpOptions });
|
|
5219
|
+
return async.auto({
|
|
5220
|
+
soffice: (callback2) => {
|
|
5221
|
+
let paths = (options || {}).sofficeBinaryPaths || [];
|
|
5222
|
+
switch (process.platform) {
|
|
5223
|
+
case "darwin":
|
|
5224
|
+
paths = [...paths, "/Applications/LibreOffice.app/Contents/MacOS/soffice"];
|
|
5225
|
+
break;
|
|
5226
|
+
case "linux":
|
|
5227
|
+
paths = [...paths, "/usr/bin/libreoffice", "/usr/bin/soffice", "/snap/bin/libreoffice", "/opt/libreoffice/program/soffice", "/opt/libreoffice7.6/program/soffice"];
|
|
5228
|
+
break;
|
|
5229
|
+
case "win32":
|
|
5230
|
+
paths = [
|
|
5231
|
+
...paths,
|
|
5232
|
+
path.join(process.env["PROGRAMFILES(X86)"] || "", "LIBREO~1/program/soffice.exe"),
|
|
5233
|
+
path.join(process.env["PROGRAMFILES(X86)"] || "", "LibreOffice/program/soffice.exe"),
|
|
5234
|
+
path.join(process.env.PROGRAMFILES_X86 || "", "LibreOffice/program/soffice.exe"),
|
|
5235
|
+
path.join(process.env.PROGRAMFILES || "", "LibreOffice/program/soffice.exe"),
|
|
5236
|
+
process.env.LIBRE_OFFICE_EXE || "",
|
|
5237
|
+
"C:/Program Files/LibreOffice/program/soffice.exe"
|
|
5238
|
+
];
|
|
5239
|
+
break;
|
|
5240
|
+
default:
|
|
5241
|
+
return callback2(new Error(`Operating system not yet supported: ${process.platform}`));
|
|
5242
|
+
}
|
|
5243
|
+
return async.filter(
|
|
5244
|
+
paths,
|
|
5245
|
+
(filePath, callback3) => fs.access(filePath, (err) => callback3(null, !err)),
|
|
5246
|
+
(err, res) => {
|
|
5247
|
+
if (res.length === 0) {
|
|
5248
|
+
return callback2(new Error("Could not find soffice binary"));
|
|
5249
|
+
}
|
|
5250
|
+
return callback2(null, res[0]);
|
|
5251
|
+
}
|
|
5252
|
+
);
|
|
5253
|
+
},
|
|
5254
|
+
saveSource: (callback2) => fs.writeFile(path.join(tempDir.name, fileName), document, callback2),
|
|
5255
|
+
convert: ["soffice", "saveSource", (results, callback2) => {
|
|
5256
|
+
let filterParam = filter2?.length ? `:${filter2}` : "";
|
|
5257
|
+
let fmt = !(filter2 ?? "").includes(" ") ? `${format}${filterParam}` : `"${format}${filterParam}"`;
|
|
5258
|
+
let args = [];
|
|
5259
|
+
args.push(`-env:UserInstallation=${url.pathToFileURL(installDir.name)}`);
|
|
5260
|
+
args.push("--headless");
|
|
5261
|
+
args.push("--convert-to");
|
|
5262
|
+
args.push(fmt);
|
|
5263
|
+
args.push("--outdir");
|
|
5264
|
+
args.push(tempDir.name);
|
|
5265
|
+
args.push(...sofficeAdditionalArgs);
|
|
5266
|
+
args.push(path.join(tempDir.name, fileName));
|
|
5267
|
+
return execFile(results.soffice, args, execOptions, (err, stdout, stderr) => {
|
|
5268
|
+
if (stderr && stderr.toLowerCase().includes("error"))
|
|
5269
|
+
callback2(new Error("Error calling soffice: " + stderr));
|
|
5270
|
+
else callback2(err, stdout, stderr);
|
|
5271
|
+
});
|
|
5272
|
+
}],
|
|
5273
|
+
loadDestination: [
|
|
5274
|
+
"convert",
|
|
5275
|
+
(results, callback2) => async.retry({
|
|
5276
|
+
times: asyncOptions.times || 3,
|
|
5277
|
+
interval: asyncOptions.interval || 200
|
|
5278
|
+
}, (callback3) => fs.readFile(path.join(tempDir.name, `${fileName.slice(0, fileName.length - path.extname(fileName).length)}.${format.split(":")[0]}`), callback3), callback2)
|
|
5279
|
+
]
|
|
5280
|
+
}).then((res) => {
|
|
5281
|
+
return callback(null, res.loadDestination);
|
|
5282
|
+
}).catch((err) => {
|
|
5283
|
+
return callback(err);
|
|
5284
|
+
}).finally(() => {
|
|
5285
|
+
tempDir.removeCallback();
|
|
5286
|
+
installDir.removeCallback();
|
|
5287
|
+
});
|
|
5288
|
+
};
|
|
5289
|
+
var convert = (document, format, filter2, callback) => {
|
|
5290
|
+
return convertWithOptions(document, format, filter2, {}, callback);
|
|
5291
|
+
};
|
|
5292
|
+
module.exports = {
|
|
5293
|
+
convert,
|
|
5294
|
+
convertWithOptions
|
|
5295
|
+
};
|
|
5296
|
+
}
|
|
5297
|
+
});
|
|
5298
|
+
|
|
2984
5299
|
// src/index.ts
|
|
2985
5300
|
import { readFile as readFile2 } from "fs/promises";
|
|
2986
5301
|
|
|
@@ -3035,7 +5350,7 @@ import JSZip2 from "jszip";
|
|
|
3035
5350
|
import { DOMParser } from "@xmldom/xmldom";
|
|
3036
5351
|
|
|
3037
5352
|
// src/utils.ts
|
|
3038
|
-
var VERSION = true ? "2.
|
|
5353
|
+
var VERSION = true ? "2.5.0" : "0.0.0-dev";
|
|
3039
5354
|
function toArrayBuffer(buf) {
|
|
3040
5355
|
if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
|
|
3041
5356
|
return buf.buffer;
|
|
@@ -3428,7 +5743,7 @@ async function extractHwpxStyles(zip, decompressed) {
|
|
|
3428
5743
|
}
|
|
3429
5744
|
return result;
|
|
3430
5745
|
}
|
|
3431
|
-
function parseCharProperties(doc,
|
|
5746
|
+
function parseCharProperties(doc, map2) {
|
|
3432
5747
|
const tagNames = ["hh:charPr", "charPr", "hp:charPr"];
|
|
3433
5748
|
for (const tagName of tagNames) {
|
|
3434
5749
|
const elements = doc.getElementsByTagName(tagName);
|
|
@@ -3455,11 +5770,11 @@ function parseCharProperties(doc, map) {
|
|
|
3455
5770
|
}
|
|
3456
5771
|
}
|
|
3457
5772
|
}
|
|
3458
|
-
|
|
5773
|
+
map2.set(id, prop);
|
|
3459
5774
|
}
|
|
3460
5775
|
}
|
|
3461
5776
|
}
|
|
3462
|
-
function parseStyleElements(doc,
|
|
5777
|
+
function parseStyleElements(doc, map2) {
|
|
3463
5778
|
const tagNames = ["hh:style", "style", "hp:style"];
|
|
3464
5779
|
for (const tagName of tagNames) {
|
|
3465
5780
|
const elements = doc.getElementsByTagName(tagName);
|
|
@@ -3469,7 +5784,7 @@ function parseStyleElements(doc, map) {
|
|
|
3469
5784
|
const name = el.getAttribute("name") || el.getAttribute("engName") || "";
|
|
3470
5785
|
const charPrId = el.getAttribute("charPrIDRef") || void 0;
|
|
3471
5786
|
const paraPrId = el.getAttribute("paraPrIDRef") || void 0;
|
|
3472
|
-
|
|
5787
|
+
map2.set(id, { name, charPrId, paraPrId });
|
|
3473
5788
|
}
|
|
3474
5789
|
}
|
|
3475
5790
|
}
|
|
@@ -3995,9 +6310,9 @@ function walkParagraphChildren(node, blocks, tableCtx, tableStack, styleMap, war
|
|
|
3995
6310
|
if (depth > MAX_XML_DEPTH) return tableCtx;
|
|
3996
6311
|
const children = node.childNodes;
|
|
3997
6312
|
if (!children) return tableCtx;
|
|
3998
|
-
const walkChildren = (
|
|
6313
|
+
const walkChildren = (parent2, d) => {
|
|
3999
6314
|
if (d > MAX_XML_DEPTH) return;
|
|
4000
|
-
const kids =
|
|
6315
|
+
const kids = parent2.childNodes;
|
|
4001
6316
|
if (!kids) return;
|
|
4002
6317
|
for (let i = 0; i < kids.length; i++) {
|
|
4003
6318
|
const el = kids[i];
|
|
@@ -6210,17 +8525,17 @@ function lineOverlapRatio(a1, a2, b1, b2) {
|
|
|
6210
8525
|
return overlap / target;
|
|
6211
8526
|
}
|
|
6212
8527
|
function groupConnectedLines(lines) {
|
|
6213
|
-
const
|
|
8528
|
+
const parent2 = lines.map((_, i) => i);
|
|
6214
8529
|
function find2(x) {
|
|
6215
|
-
while (
|
|
6216
|
-
|
|
6217
|
-
x =
|
|
8530
|
+
while (parent2[x] !== x) {
|
|
8531
|
+
parent2[x] = parent2[parent2[x]];
|
|
8532
|
+
x = parent2[x];
|
|
6218
8533
|
}
|
|
6219
8534
|
return x;
|
|
6220
8535
|
}
|
|
6221
8536
|
function union(a, b) {
|
|
6222
8537
|
const ra = find2(a), rb = find2(b);
|
|
6223
|
-
if (ra !== rb)
|
|
8538
|
+
if (ra !== rb) parent2[ra] = rb;
|
|
6224
8539
|
}
|
|
6225
8540
|
for (let i = 0; i < lines.length; i++) {
|
|
6226
8541
|
for (let j = i + 1; j < lines.length; j++) {
|
|
@@ -6641,10 +8956,10 @@ async function loadPdfWithTimeout(buffer) {
|
|
|
6641
8956
|
try {
|
|
6642
8957
|
return await Promise.race([
|
|
6643
8958
|
loadingTask.promise,
|
|
6644
|
-
new Promise((_,
|
|
8959
|
+
new Promise((_, reject2) => {
|
|
6645
8960
|
timer = setTimeout(() => {
|
|
6646
8961
|
loadingTask.destroy();
|
|
6647
|
-
|
|
8962
|
+
reject2(new KordocError(`PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (${timeoutSec}\uCD08 \uCD08\uACFC)`));
|
|
6648
8963
|
}, timeoutMs);
|
|
6649
8964
|
})
|
|
6650
8965
|
]);
|
|
@@ -6833,10 +9148,10 @@ async function parsePdfDocument(buffer, options) {
|
|
|
6833
9148
|
}
|
|
6834
9149
|
const { resolveOcrProvider: resolveOcrProvider2 } = await Promise.resolve().then(() => (init_resolve(), resolve_exports));
|
|
6835
9150
|
const { ocrPages: ocrPages2 } = await Promise.resolve().then(() => (init_provider(), provider_exports));
|
|
6836
|
-
const tryProvider = async (provider,
|
|
9151
|
+
const tryProvider = async (provider, filter2) => {
|
|
6837
9152
|
try {
|
|
6838
|
-
logger.log({ level: "debug", stage: "ocr", event: "progress", message: "OCR provider \uC2E4\uD589", meta: { filteredPages:
|
|
6839
|
-
return await ocrPages2(doc, provider,
|
|
9153
|
+
logger.log({ level: "debug", stage: "ocr", event: "progress", message: "OCR provider \uC2E4\uD589", meta: { filteredPages: filter2?.size } });
|
|
9154
|
+
return await ocrPages2(doc, provider, filter2, effectivePageCount, warnings, concurrency, options?.onProgress);
|
|
6840
9155
|
} catch {
|
|
6841
9156
|
logger.log({ level: "warn", stage: "ocr", event: "progress", message: "OCR provider \uC2E4\uD589 \uC2E4\uD328(\uBE48 \uACB0\uACFC\uB85C \uCC98\uB9AC)" });
|
|
6842
9157
|
return [];
|
|
@@ -7851,8 +10166,8 @@ function parseMergeRef(ref) {
|
|
|
7851
10166
|
if (!start || !end) return null;
|
|
7852
10167
|
return { startCol: start.col, startRow: start.row, endCol: end.col, endRow: end.row };
|
|
7853
10168
|
}
|
|
7854
|
-
function getElements(
|
|
7855
|
-
const nodes =
|
|
10169
|
+
function getElements(parent2, tagName) {
|
|
10170
|
+
const nodes = parent2.getElementsByTagName(tagName);
|
|
7856
10171
|
const result = [];
|
|
7857
10172
|
for (let i = 0; i < nodes.length; i++) result.push(nodes[i]);
|
|
7858
10173
|
return result;
|
|
@@ -7888,14 +10203,14 @@ function parseWorkbook(xml) {
|
|
|
7888
10203
|
}
|
|
7889
10204
|
function parseRels(xml) {
|
|
7890
10205
|
const doc = parseXml(xml);
|
|
7891
|
-
const
|
|
10206
|
+
const map2 = /* @__PURE__ */ new Map();
|
|
7892
10207
|
const rels = getElements(doc.documentElement, "Relationship");
|
|
7893
10208
|
for (const rel of rels) {
|
|
7894
10209
|
const id = rel.getAttribute("Id");
|
|
7895
10210
|
const target = rel.getAttribute("Target");
|
|
7896
|
-
if (id && target)
|
|
10211
|
+
if (id && target) map2.set(id, target);
|
|
7897
10212
|
}
|
|
7898
|
-
return
|
|
10213
|
+
return map2;
|
|
7899
10214
|
}
|
|
7900
10215
|
function parseWorksheet(xml, sharedStrings) {
|
|
7901
10216
|
const doc = parseXml(xml);
|
|
@@ -8153,9 +10468,9 @@ import JSZip4 from "jszip";
|
|
|
8153
10468
|
import { DOMParser as DOMParser3 } from "@xmldom/xmldom";
|
|
8154
10469
|
init_logger();
|
|
8155
10470
|
var MAX_DECOMPRESS_SIZE4 = 500 * 1024 * 1024;
|
|
8156
|
-
function getChildElements(
|
|
10471
|
+
function getChildElements(parent2, localName) {
|
|
8157
10472
|
const result = [];
|
|
8158
|
-
const children =
|
|
10473
|
+
const children = parent2.childNodes;
|
|
8159
10474
|
for (let i = 0; i < children.length; i++) {
|
|
8160
10475
|
const node = children[i];
|
|
8161
10476
|
if (node.nodeType === 1) {
|
|
@@ -8167,7 +10482,7 @@ function getChildElements(parent, localName) {
|
|
|
8167
10482
|
}
|
|
8168
10483
|
return result;
|
|
8169
10484
|
}
|
|
8170
|
-
function findElements(
|
|
10485
|
+
function findElements(parent2, localName) {
|
|
8171
10486
|
const result = [];
|
|
8172
10487
|
const walk = (node) => {
|
|
8173
10488
|
const children = node.childNodes;
|
|
@@ -8182,7 +10497,7 @@ function findElements(parent, localName) {
|
|
|
8182
10497
|
}
|
|
8183
10498
|
}
|
|
8184
10499
|
};
|
|
8185
|
-
walk(
|
|
10500
|
+
walk(parent2);
|
|
8186
10501
|
return result;
|
|
8187
10502
|
}
|
|
8188
10503
|
function getAttr(el, localName) {
|
|
@@ -8197,7 +10512,7 @@ function parseXml2(text) {
|
|
|
8197
10512
|
return new DOMParser3().parseFromString(text, "text/xml");
|
|
8198
10513
|
}
|
|
8199
10514
|
function buildElementIndex(root) {
|
|
8200
|
-
const
|
|
10515
|
+
const index2 = /* @__PURE__ */ new Map();
|
|
8201
10516
|
const walk = (node) => {
|
|
8202
10517
|
const children = node.childNodes;
|
|
8203
10518
|
for (let i = 0; i < children.length; i++) {
|
|
@@ -8206,10 +10521,10 @@ function buildElementIndex(root) {
|
|
|
8206
10521
|
const el = child;
|
|
8207
10522
|
const name = el.localName ?? "";
|
|
8208
10523
|
if (name) {
|
|
8209
|
-
let list =
|
|
10524
|
+
let list = index2.get(name);
|
|
8210
10525
|
if (!list) {
|
|
8211
10526
|
list = [];
|
|
8212
|
-
|
|
10527
|
+
index2.set(name, list);
|
|
8213
10528
|
}
|
|
8214
10529
|
list.push(el);
|
|
8215
10530
|
}
|
|
@@ -8218,7 +10533,7 @@ function buildElementIndex(root) {
|
|
|
8218
10533
|
}
|
|
8219
10534
|
};
|
|
8220
10535
|
walk(root);
|
|
8221
|
-
return
|
|
10536
|
+
return index2;
|
|
8222
10537
|
}
|
|
8223
10538
|
function parseStyles(xml) {
|
|
8224
10539
|
const doc = parseXml2(xml);
|
|
@@ -8284,14 +10599,14 @@ function parseNumbering(xml) {
|
|
|
8284
10599
|
}
|
|
8285
10600
|
function parseRels2(xml) {
|
|
8286
10601
|
const doc = parseXml2(xml);
|
|
8287
|
-
const
|
|
10602
|
+
const map2 = /* @__PURE__ */ new Map();
|
|
8288
10603
|
const rels = findElements(doc, "Relationship");
|
|
8289
10604
|
for (const rel of rels) {
|
|
8290
10605
|
const id = getAttr(rel, "Id");
|
|
8291
10606
|
const target = getAttr(rel, "Target");
|
|
8292
|
-
if (id && target)
|
|
10607
|
+
if (id && target) map2.set(id, target);
|
|
8293
10608
|
}
|
|
8294
|
-
return
|
|
10609
|
+
return map2;
|
|
8295
10610
|
}
|
|
8296
10611
|
function parseFootnotes(xml) {
|
|
8297
10612
|
const doc = parseXml2(xml);
|
|
@@ -10134,22 +12449,22 @@ function findCharPrByCharacteristic(charPrMap, characteristic) {
|
|
|
10134
12449
|
italic: { minHeight: 800, maxHeight: 1100, needBold: false },
|
|
10135
12450
|
normal: { minHeight: 900, maxHeight: 1100, needBold: false }
|
|
10136
12451
|
};
|
|
10137
|
-
const
|
|
10138
|
-
if (!
|
|
12452
|
+
const range2 = ranges[characteristic];
|
|
12453
|
+
if (!range2) return null;
|
|
10139
12454
|
let bestMatch = null;
|
|
10140
12455
|
let bestScore = 0;
|
|
10141
12456
|
for (const [id, prop] of charPrMap) {
|
|
10142
12457
|
let score = 0;
|
|
10143
12458
|
if (prop.height) {
|
|
10144
|
-
if (prop.height >=
|
|
12459
|
+
if (prop.height >= range2.minHeight && prop.height <= range2.maxHeight) {
|
|
10145
12460
|
score += 50;
|
|
10146
|
-
} else if (Math.abs(prop.height - (
|
|
12461
|
+
} else if (Math.abs(prop.height - (range2.minHeight + range2.maxHeight) / 2) < 100) {
|
|
10147
12462
|
score += 20;
|
|
10148
12463
|
}
|
|
10149
12464
|
}
|
|
10150
|
-
if (
|
|
10151
|
-
if (
|
|
10152
|
-
else if (!
|
|
12465
|
+
if (range2.needBold !== void 0) {
|
|
12466
|
+
if (range2.needBold && prop.bold) score += 30;
|
|
12467
|
+
else if (!range2.needBold && !prop.bold) score += 20;
|
|
10153
12468
|
}
|
|
10154
12469
|
if (characteristic === "italic" && prop.italic) score += 20;
|
|
10155
12470
|
if (score > bestScore) {
|
|
@@ -10988,10 +13303,10 @@ function mimeToExtension(mimeType) {
|
|
|
10988
13303
|
return "png";
|
|
10989
13304
|
}
|
|
10990
13305
|
function buildImageMap(images) {
|
|
10991
|
-
const
|
|
10992
|
-
if (!images) return
|
|
10993
|
-
for (const img of images)
|
|
10994
|
-
return
|
|
13306
|
+
const map2 = /* @__PURE__ */ new Map();
|
|
13307
|
+
if (!images) return map2;
|
|
13308
|
+
for (const img of images) map2.set(img.filename, img);
|
|
13309
|
+
return map2;
|
|
10995
13310
|
}
|
|
10996
13311
|
async function fillBodySheet(sheet, workbook, blocks, imageMap) {
|
|
10997
13312
|
sheet.getColumn(1).width = 80;
|
|
@@ -11193,8 +13508,8 @@ var ApiKeyRotationPool = class _ApiKeyRotationPool {
|
|
|
11193
13508
|
const s = this.find(keyId);
|
|
11194
13509
|
s.failureCount++;
|
|
11195
13510
|
s.consecutiveFailures++;
|
|
11196
|
-
const
|
|
11197
|
-
if (!
|
|
13511
|
+
const retryable2 = this.isRetryableFailure(opts.status, opts.timeout);
|
|
13512
|
+
if (!retryable2) return;
|
|
11198
13513
|
const exp = Math.max(0, s.consecutiveFailures - 1);
|
|
11199
13514
|
const backoff = Math.min(this.baseCooldownMs * 2 ** exp, this.maxCooldownMs);
|
|
11200
13515
|
const cooldown = Math.max(backoff, opts.retryAfterMs ?? 0);
|
|
@@ -11211,8 +13526,8 @@ var ApiKeyRotationPool = class _ApiKeyRotationPool {
|
|
|
11211
13526
|
cooldownUntil: s.cooldownUntil
|
|
11212
13527
|
}));
|
|
11213
13528
|
}
|
|
11214
|
-
isRetryableFailure(status,
|
|
11215
|
-
if (
|
|
13529
|
+
isRetryableFailure(status, timeout2) {
|
|
13530
|
+
if (timeout2) return true;
|
|
11216
13531
|
if (status === 429) return true;
|
|
11217
13532
|
if (typeof status === "number" && status >= 500) return true;
|
|
11218
13533
|
return false;
|
|
@@ -11226,12 +13541,172 @@ var ApiKeyRotationPool = class _ApiKeyRotationPool {
|
|
|
11226
13541
|
|
|
11227
13542
|
// src/pipeline/unified-ocr.ts
|
|
11228
13543
|
import { mkdir, readdir, readFile, stat, writeFile } from "fs/promises";
|
|
11229
|
-
import { basename as basename2, dirname as dirname3, extname, join as
|
|
13544
|
+
import { basename as basename2, dirname as dirname3, extname, join as join5, resolve as resolve3 } from "path";
|
|
11230
13545
|
import { spawn as spawn2 } from "child_process";
|
|
11231
13546
|
import { performance } from "perf_hooks";
|
|
11232
|
-
import libre from "libreoffice-convert";
|
|
11233
13547
|
init_logger();
|
|
11234
|
-
|
|
13548
|
+
|
|
13549
|
+
// src/setup/detect.ts
|
|
13550
|
+
import { spawnSync as spawnSync2 } from "child_process";
|
|
13551
|
+
import { existsSync } from "fs";
|
|
13552
|
+
import { join as join4 } from "path";
|
|
13553
|
+
var isWin = process.platform === "win32";
|
|
13554
|
+
function which(cmd) {
|
|
13555
|
+
const finder = isWin ? "where" : "which";
|
|
13556
|
+
const r = spawnSync2(finder, [cmd], { encoding: "utf8", shell: isWin });
|
|
13557
|
+
if (r.status !== 0) return void 0;
|
|
13558
|
+
return r.stdout.split(/\r?\n/).find(Boolean)?.trim();
|
|
13559
|
+
}
|
|
13560
|
+
function resolveCmd(cmd, envKey) {
|
|
13561
|
+
const override = process.env[envKey];
|
|
13562
|
+
if (override) return override;
|
|
13563
|
+
const found = which(cmd);
|
|
13564
|
+
if (found) return found;
|
|
13565
|
+
if (isWin) return findWinCandidate(cmd);
|
|
13566
|
+
return void 0;
|
|
13567
|
+
}
|
|
13568
|
+
function findWinCandidate(cmd) {
|
|
13569
|
+
const exe = cmd.endsWith(".exe") ? cmd : `${cmd}.exe`;
|
|
13570
|
+
const userProfile = process.env["USERPROFILE"] ?? "C:\\Users\\Default";
|
|
13571
|
+
const localAppData = process.env["LOCALAPPDATA"] ?? join4(userProfile, "AppData", "Local");
|
|
13572
|
+
const programFiles = process.env["ProgramFiles"] ?? "C:\\Program Files";
|
|
13573
|
+
const programFilesX86 = process.env["ProgramFiles(x86)"] ?? "C:\\Program Files (x86)";
|
|
13574
|
+
const isPopplerExe = ["pdftoppm.exe", "pdfinfo.exe", "pdftotext.exe"].includes(exe);
|
|
13575
|
+
const isSoffice = exe === "soffice.exe";
|
|
13576
|
+
if (isPopplerExe) return findPopplerWin(exe, { userProfile, localAppData, programFiles, programFilesX86 });
|
|
13577
|
+
if (isSoffice) return findSofficeWin({ programFiles, programFilesX86, localAppData });
|
|
13578
|
+
return void 0;
|
|
13579
|
+
}
|
|
13580
|
+
function findPopplerWin(exe, p) {
|
|
13581
|
+
const scoopPath = join4(p.userProfile, "scoop", "apps", "poppler", "current", "bin", exe);
|
|
13582
|
+
if (existsSync(scoopPath)) return scoopPath;
|
|
13583
|
+
const wingetBase = join4(p.localAppData, "Microsoft", "WinGet", "Packages");
|
|
13584
|
+
const wingetResult = globFirst(wingetBase, ["oschwartz10612.Poppler_*"], ["poppler-*", "Library", "bin", exe]);
|
|
13585
|
+
if (wingetResult) return wingetResult;
|
|
13586
|
+
const chocoBase = join4("C:", "ProgramData", "chocolatey", "lib", "poppler", "tools");
|
|
13587
|
+
const chocoResult = globFirst(chocoBase, ["poppler-*"], ["bin", exe]);
|
|
13588
|
+
if (chocoResult) return chocoResult;
|
|
13589
|
+
for (const base of [
|
|
13590
|
+
join4("C:", "poppler", "bin", exe),
|
|
13591
|
+
join4("C:", "tools", "poppler", "bin", exe),
|
|
13592
|
+
join4(p.programFiles, "poppler", "bin", exe),
|
|
13593
|
+
join4(p.programFilesX86, "poppler", "bin", exe),
|
|
13594
|
+
join4(p.localAppData, "Programs", "poppler", "bin", exe)
|
|
13595
|
+
]) {
|
|
13596
|
+
if (existsSync(base)) return base;
|
|
13597
|
+
}
|
|
13598
|
+
return void 0;
|
|
13599
|
+
}
|
|
13600
|
+
function findSofficeWin(p) {
|
|
13601
|
+
for (const candidate of [
|
|
13602
|
+
join4(p.programFiles, "LibreOffice", "program", "soffice.exe"),
|
|
13603
|
+
join4(p.programFilesX86, "LibreOffice", "program", "soffice.exe"),
|
|
13604
|
+
join4(p.localAppData, "Programs", "LibreOffice", "program", "soffice.exe"),
|
|
13605
|
+
// winget 설치는 Program Files와 동일
|
|
13606
|
+
join4(p.programFiles, "LibreOffice 24", "program", "soffice.exe"),
|
|
13607
|
+
join4(p.programFiles, "LibreOffice 25", "program", "soffice.exe")
|
|
13608
|
+
]) {
|
|
13609
|
+
if (existsSync(candidate)) return candidate;
|
|
13610
|
+
}
|
|
13611
|
+
return void 0;
|
|
13612
|
+
}
|
|
13613
|
+
function globFirst(base, wildcardSegments, rest) {
|
|
13614
|
+
if (!existsSync(base)) return void 0;
|
|
13615
|
+
let current = base;
|
|
13616
|
+
for (const seg of wildcardSegments) {
|
|
13617
|
+
if (!seg.includes("*")) {
|
|
13618
|
+
current = join4(current, seg);
|
|
13619
|
+
if (!existsSync(current)) return void 0;
|
|
13620
|
+
continue;
|
|
13621
|
+
}
|
|
13622
|
+
try {
|
|
13623
|
+
const { readdirSync } = __require("fs");
|
|
13624
|
+
const entries = readdirSync(current);
|
|
13625
|
+
const pattern = seg.replace(/\*/g, ".*");
|
|
13626
|
+
const re = new RegExp(`^${pattern}$`, "i");
|
|
13627
|
+
const match = entries.find((e) => re.test(e));
|
|
13628
|
+
if (!match) return void 0;
|
|
13629
|
+
current = join4(current, match);
|
|
13630
|
+
} catch {
|
|
13631
|
+
return void 0;
|
|
13632
|
+
}
|
|
13633
|
+
}
|
|
13634
|
+
const final = join4(current, ...rest);
|
|
13635
|
+
return existsSync(final) ? final : void 0;
|
|
13636
|
+
}
|
|
13637
|
+
function probe(cmd, envKey, versionArgs = ["--version"]) {
|
|
13638
|
+
const resolvedPath = resolveCmd(cmd, envKey);
|
|
13639
|
+
if (!resolvedPath) return { name: cmd, found: false };
|
|
13640
|
+
const v = spawnSync2(resolvedPath, versionArgs, { encoding: "utf8", shell: isWin });
|
|
13641
|
+
const versionLine = (v.stdout || v.stderr).split(/\r?\n/)[0]?.trim();
|
|
13642
|
+
return { name: cmd, found: true, path: resolvedPath, version: versionLine };
|
|
13643
|
+
}
|
|
13644
|
+
function probeOcrToolchain() {
|
|
13645
|
+
return {
|
|
13646
|
+
// poppler는 --version이 비표준이므로 -v 사용
|
|
13647
|
+
pdftoppm: probe("pdftoppm", "KORDOC_PDFTOPPM_PATH", ["-v"]),
|
|
13648
|
+
pdfinfo: probe("pdfinfo", "KORDOC_PDFINFO_PATH", ["-v"]),
|
|
13649
|
+
pdftotext: probe("pdftotext", "KORDOC_PDFTOTEXT_PATH", ["-v"]),
|
|
13650
|
+
soffice: probe("soffice", "KORDOC_SOFFICE_PATH", ["--version"])
|
|
13651
|
+
};
|
|
13652
|
+
}
|
|
13653
|
+
|
|
13654
|
+
// src/setup/pm.ts
|
|
13655
|
+
import { spawnSync as spawnSync3 } from "child_process";
|
|
13656
|
+
var isWin2 = process.platform === "win32";
|
|
13657
|
+
function which2(cmd) {
|
|
13658
|
+
const finder = isWin2 ? "where" : "which";
|
|
13659
|
+
const r = spawnSync3(finder, [cmd], { encoding: "utf8", shell: isWin2 });
|
|
13660
|
+
return r.status === 0;
|
|
13661
|
+
}
|
|
13662
|
+
function detectPackageManager() {
|
|
13663
|
+
if (process.platform === "darwin") {
|
|
13664
|
+
return which2("brew") ? "brew" : "unknown";
|
|
13665
|
+
}
|
|
13666
|
+
if (isWin2) {
|
|
13667
|
+
if (which2("winget")) return "winget";
|
|
13668
|
+
if (which2("scoop")) return "scoop";
|
|
13669
|
+
if (which2("choco")) return "choco";
|
|
13670
|
+
return "unknown";
|
|
13671
|
+
}
|
|
13672
|
+
if (which2("apt-get") || which2("apt")) return "apt";
|
|
13673
|
+
if (which2("dnf")) return "dnf";
|
|
13674
|
+
if (which2("yum")) return "yum";
|
|
13675
|
+
if (which2("pacman")) return "pacman";
|
|
13676
|
+
if (which2("zypper")) return "zypper";
|
|
13677
|
+
if (which2("apk")) return "apk";
|
|
13678
|
+
return "unknown";
|
|
13679
|
+
}
|
|
13680
|
+
|
|
13681
|
+
// src/setup/install-commands.ts
|
|
13682
|
+
var POPPLER_RECIPES = {
|
|
13683
|
+
brew: { pm: "brew", cmd: "brew install poppler", needsSudo: false },
|
|
13684
|
+
winget: { pm: "winget", cmd: "winget install --id oschwartz10612.Poppler", needsSudo: false, notes: "\uC2E4\uC874 \uD655\uC778\uB428 (winget-pkgs 25.07.0-0)" },
|
|
13685
|
+
scoop: { pm: "scoop", cmd: "scoop install poppler", needsSudo: false, notes: "main \uBC84\uD0B7 \uD3EC\uD568, PATH \uC790\uB3D9 \uB4F1\uB85D" },
|
|
13686
|
+
choco: { pm: "choco", cmd: "choco install poppler -y", needsSudo: true, notes: "\uAD00\uB9AC\uC790 PowerShell \uD544\uC694" },
|
|
13687
|
+
apt: { pm: "apt", cmd: "sudo apt-get install -y poppler-utils", needsSudo: true },
|
|
13688
|
+
dnf: { pm: "dnf", cmd: "sudo dnf install -y poppler-utils", needsSudo: true },
|
|
13689
|
+
yum: { pm: "yum", cmd: "sudo yum install -y poppler-utils", needsSudo: true },
|
|
13690
|
+
pacman: { pm: "pacman", cmd: "sudo pacman -S --noconfirm poppler", needsSudo: true },
|
|
13691
|
+
zypper: { pm: "zypper", cmd: "sudo zypper install -y poppler-tools", needsSudo: true },
|
|
13692
|
+
apk: { pm: "apk", cmd: "apk add --no-cache poppler-utils", needsSudo: false, notes: "Alpine/Docker \uCE5C\uD654" },
|
|
13693
|
+
unknown: null
|
|
13694
|
+
};
|
|
13695
|
+
var LIBREOFFICE_RECIPES = {
|
|
13696
|
+
brew: { pm: "brew", cmd: "brew install --cask libreoffice", needsSudo: false },
|
|
13697
|
+
winget: { pm: "winget", cmd: "winget install --id TheDocumentFoundation.LibreOffice", needsSudo: false, notes: "\uC2E4\uC874 \uD655\uC778\uB428" },
|
|
13698
|
+
scoop: { pm: "scoop", cmd: "scoop bucket add extras && scoop install libreoffice", needsSudo: false },
|
|
13699
|
+
choco: { pm: "choco", cmd: "choco install libreoffice-fresh -y", needsSudo: true, notes: "\uAD00\uB9AC\uC790 PowerShell \uD544\uC694" },
|
|
13700
|
+
apt: { pm: "apt", cmd: "sudo apt-get install -y libreoffice", needsSudo: true },
|
|
13701
|
+
dnf: { pm: "dnf", cmd: "sudo dnf install -y libreoffice", needsSudo: true },
|
|
13702
|
+
yum: { pm: "yum", cmd: "sudo yum install -y libreoffice", needsSudo: true },
|
|
13703
|
+
pacman: { pm: "pacman", cmd: "sudo pacman -S --noconfirm libreoffice-still", needsSudo: true },
|
|
13704
|
+
zypper: { pm: "zypper", cmd: "sudo zypper install -y libreoffice", needsSudo: true },
|
|
13705
|
+
apk: { pm: "apk", cmd: "apk add --no-cache libreoffice", needsSudo: false, notes: "Alpine \uBBF8\uC9C0\uC6D0 \uAC00\uB2A5 \u2014 node:20-slim(Debian) \uAD8C\uC7A5" },
|
|
13706
|
+
unknown: null
|
|
13707
|
+
};
|
|
13708
|
+
|
|
13709
|
+
// src/pipeline/unified-ocr.ts
|
|
11235
13710
|
var UnifiedOcrError = class extends Error {
|
|
11236
13711
|
code;
|
|
11237
13712
|
stage;
|
|
@@ -11305,13 +13780,13 @@ function elapsedMs(startAt) {
|
|
|
11305
13780
|
async function runUnifiedOcrPipeline(inputPath, options = {}) {
|
|
11306
13781
|
const absInput = resolve3(inputPath);
|
|
11307
13782
|
const stem = basename2(absInput, extname(absInput));
|
|
11308
|
-
const workspaceDir = resolve3(options.workspaceDir ??
|
|
11309
|
-
const imagesDir =
|
|
11310
|
-
const rawDir =
|
|
11311
|
-
const diffDir =
|
|
11312
|
-
const outputPath = resolve3(options.outputPath ??
|
|
11313
|
-
const reportPath =
|
|
11314
|
-
const modelCachePath =
|
|
13783
|
+
const workspaceDir = resolve3(options.workspaceDir ?? join5(dirname3(absInput), `${stem}_ocr_workspace`));
|
|
13784
|
+
const imagesDir = join5(workspaceDir, "images");
|
|
13785
|
+
const rawDir = join5(workspaceDir, "ocr", "raw");
|
|
13786
|
+
const diffDir = join5(workspaceDir, "ocr", "diff");
|
|
13787
|
+
const outputPath = resolve3(options.outputPath ?? join5(dirname3(absInput), `${stem}.md`));
|
|
13788
|
+
const reportPath = join5(workspaceDir, "run-report.json");
|
|
13789
|
+
const modelCachePath = join5(dirname3(absInput), ".kordoc-model-cache.json");
|
|
11315
13790
|
const baseUrl = options.baseUrl ?? "https://integrate.api.nvidia.com/v1/chat/completions";
|
|
11316
13791
|
const timeoutMs = options.timeoutMs ?? 6e4;
|
|
11317
13792
|
const maxRetriesPerPage = options.maxRetriesPerPage ?? 5;
|
|
@@ -11338,14 +13813,15 @@ async function runUnifiedOcrPipeline(inputPath, options = {}) {
|
|
|
11338
13813
|
};
|
|
11339
13814
|
try {
|
|
11340
13815
|
ensureSupportedInput(absInput);
|
|
13816
|
+
const isPdfInput = extname(absInput).toLowerCase() === ".pdf";
|
|
13817
|
+
await assertOcrToolchain(isPdfInput);
|
|
11341
13818
|
let workingPdfPath = absInput;
|
|
11342
13819
|
const convertStart = performance.now();
|
|
11343
13820
|
currentStage = "convert";
|
|
11344
13821
|
markStageStart("convert", "\uBB38\uC11C\uB97C PDF\uB85C \uBCC0\uD658 \uC911");
|
|
11345
13822
|
logStage("info", "convert", "start", "\uBB38\uC11C\uB97C PDF\uB85C \uBCC0\uD658 \uC2DC\uC791", { input: absInput });
|
|
11346
|
-
if (
|
|
11347
|
-
|
|
11348
|
-
workingPdfPath = join4(workspaceDir, `${stem}.pdf`);
|
|
13823
|
+
if (!isPdfInput) {
|
|
13824
|
+
workingPdfPath = join5(workspaceDir, `${stem}.pdf`);
|
|
11349
13825
|
const inputBuffer = await readFile(absInput);
|
|
11350
13826
|
const out = await convertWithLibreOffice(inputBuffer, ".pdf");
|
|
11351
13827
|
await writeFile(workingPdfPath, out);
|
|
@@ -11359,7 +13835,7 @@ async function runUnifiedOcrPipeline(inputPath, options = {}) {
|
|
|
11359
13835
|
logStage("info", "render", "start", "PDF \uD398\uC774\uC9C0 \uB80C\uB354\uB9C1 \uC2DC\uC791", { pdf: workingPdfPath, dpi });
|
|
11360
13836
|
const renderWithProgress = await renderPdfToPngWithProgress(
|
|
11361
13837
|
workingPdfPath,
|
|
11362
|
-
|
|
13838
|
+
join5(imagesDir, "page"),
|
|
11363
13839
|
dpi,
|
|
11364
13840
|
(current, total) => {
|
|
11365
13841
|
markStageProgress(
|
|
@@ -11398,10 +13874,10 @@ async function runUnifiedOcrPipeline(inputPath, options = {}) {
|
|
|
11398
13874
|
keyPool,
|
|
11399
13875
|
timeoutMs,
|
|
11400
13876
|
logger,
|
|
11401
|
-
onProbeResult: ({ index, model, result }) => {
|
|
13877
|
+
onProbeResult: ({ index: index2, model, result }) => {
|
|
11402
13878
|
probeDone += 1;
|
|
11403
13879
|
markStageProgress("probe", Math.round(probeDone / models.length * 100), probeDone, models.length, `\uBAA8\uB378 \uD504\uB85C\uBE0C ${probeDone}/${models.length}`);
|
|
11404
|
-
logStage("debug", "probe", "progress", "\uBAA8\uB378 \uD504\uB85C\uBE0C \uC9C4\uD589", { index:
|
|
13880
|
+
logStage("debug", "probe", "progress", "\uBAA8\uB378 \uD504\uB85C\uBE0C \uC9C4\uD589", { index: index2 + 1, total: models.length, model, result });
|
|
11405
13881
|
}
|
|
11406
13882
|
});
|
|
11407
13883
|
const selected = await probeRuns.firstSuccess;
|
|
@@ -11432,7 +13908,7 @@ async function runUnifiedOcrPipeline(inputPath, options = {}) {
|
|
|
11432
13908
|
maxRetriesPerPage,
|
|
11433
13909
|
logger
|
|
11434
13910
|
});
|
|
11435
|
-
const pagePath =
|
|
13911
|
+
const pagePath = join5(rawDir, `page_${String(i + 1).padStart(4, "0")}.md`);
|
|
11436
13912
|
await writeFile(pagePath, markdown, "utf-8");
|
|
11437
13913
|
rawPagePaths.push(pagePath);
|
|
11438
13914
|
markStageProgress("ocr", Math.round((i + 1) / images.length * 100), i + 1, images.length, `OCR ${i + 1}/${images.length}`, selectedModel);
|
|
@@ -11524,11 +14000,24 @@ function emitProgress(cb, stage, stagePercent, weights, extra) {
|
|
|
11524
14000
|
model: extra.model
|
|
11525
14001
|
});
|
|
11526
14002
|
}
|
|
14003
|
+
async function loadLibreConvert() {
|
|
14004
|
+
try {
|
|
14005
|
+
const m = await Promise.resolve().then(() => __toESM(require_libreoffice_convert(), 1));
|
|
14006
|
+
return (m.default ?? m).convert;
|
|
14007
|
+
} catch {
|
|
14008
|
+
throw new UnifiedOcrError(
|
|
14009
|
+
"LIBRE_NOT_INSTALLED",
|
|
14010
|
+
"convert",
|
|
14011
|
+
"libreoffice-convert npm \uD328\uD0A4\uC9C0\uAC00 \uC124\uCE58\uB418\uC5B4 \uC788\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4.\n npm install libreoffice-convert\n\uB610\uB294 npx kordoc setup \uC744 \uC2E4\uD589\uD558\uC138\uC694."
|
|
14012
|
+
);
|
|
14013
|
+
}
|
|
14014
|
+
}
|
|
11527
14015
|
async function convertWithLibreOffice(buffer, ext) {
|
|
11528
|
-
|
|
14016
|
+
const libreConvert = await loadLibreConvert();
|
|
14017
|
+
return await new Promise((resolvePromise, reject2) => {
|
|
11529
14018
|
libreConvert(buffer, ext, void 0, (err, done) => {
|
|
11530
14019
|
if (err || !done) {
|
|
11531
|
-
|
|
14020
|
+
reject2(new UnifiedOcrError("CONVERT_FAILED", "convert", err?.message ?? "LibreOffice \uBCC0\uD658 \uC2E4\uD328"));
|
|
11532
14021
|
return;
|
|
11533
14022
|
}
|
|
11534
14023
|
resolvePromise(done);
|
|
@@ -11586,21 +14075,21 @@ async function renderPdfToPngWithProgress(pdfPath, prefixPath, dpi, onPageDone)
|
|
|
11586
14075
|
return { emittedPerPageProgress: false, pageCountSource: "fallback" };
|
|
11587
14076
|
}
|
|
11588
14077
|
async function runCommand(cmd, args) {
|
|
11589
|
-
await new Promise((resolvePromise,
|
|
14078
|
+
await new Promise((resolvePromise, reject2) => {
|
|
11590
14079
|
const child = spawn2(cmd, args, { stdio: "pipe" });
|
|
11591
14080
|
let stderr = "";
|
|
11592
14081
|
child.stderr.on("data", (d) => {
|
|
11593
14082
|
stderr += String(d);
|
|
11594
14083
|
});
|
|
11595
|
-
child.on("error",
|
|
14084
|
+
child.on("error", reject2);
|
|
11596
14085
|
child.on("close", (code) => {
|
|
11597
14086
|
if (code === 0) resolvePromise();
|
|
11598
|
-
else
|
|
14087
|
+
else reject2(new Error(`${cmd} \uC2E4\uD328 (code=${code}): ${stderr.trim()}`));
|
|
11599
14088
|
});
|
|
11600
14089
|
});
|
|
11601
14090
|
}
|
|
11602
14091
|
async function runCommandWithStdout(cmd, args) {
|
|
11603
|
-
return await new Promise((resolvePromise,
|
|
14092
|
+
return await new Promise((resolvePromise, reject2) => {
|
|
11604
14093
|
const child = spawn2(cmd, args, { stdio: "pipe" });
|
|
11605
14094
|
let stdout = "";
|
|
11606
14095
|
let stderr = "";
|
|
@@ -11610,23 +14099,35 @@ async function runCommandWithStdout(cmd, args) {
|
|
|
11610
14099
|
child.stderr.on("data", (d) => {
|
|
11611
14100
|
stderr += String(d);
|
|
11612
14101
|
});
|
|
11613
|
-
child.on("error",
|
|
14102
|
+
child.on("error", reject2);
|
|
11614
14103
|
child.on("close", (code) => {
|
|
11615
14104
|
if (code === 0) resolvePromise(stdout);
|
|
11616
|
-
else
|
|
14105
|
+
else reject2(new Error(`${cmd} \uC2E4\uD328 (code=${code}): ${stderr.trim()}`));
|
|
11617
14106
|
});
|
|
11618
14107
|
});
|
|
11619
14108
|
}
|
|
11620
|
-
async function
|
|
11621
|
-
|
|
11622
|
-
|
|
11623
|
-
|
|
11624
|
-
|
|
11625
|
-
|
|
14109
|
+
async function assertOcrToolchain(isPdfInput = false) {
|
|
14110
|
+
const t = probeOcrToolchain();
|
|
14111
|
+
const pm = detectPackageManager();
|
|
14112
|
+
const missing = [];
|
|
14113
|
+
if (!t.pdftoppm.found || !t.pdfinfo.found) missing.push("poppler");
|
|
14114
|
+
if (!isPdfInput && !t.soffice.found) missing.push("libreoffice");
|
|
14115
|
+
if (missing.length === 0) return;
|
|
14116
|
+
const lines = ["OCR \uD30C\uC774\uD504\uB77C\uC778\uC5D0 \uD544\uC694\uD55C \uC2DC\uC2A4\uD15C \uB3C4\uAD6C\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4."];
|
|
14117
|
+
if (missing.includes("poppler")) {
|
|
14118
|
+
const r = POPPLER_RECIPES[pm];
|
|
14119
|
+
lines.push(` - poppler (pdftoppm/pdfinfo): ${r ? r.cmd : "OS\uBCC4 \uC124\uCE58 \uC548\uB0B4\uB294 README \uCC38\uACE0"}`);
|
|
14120
|
+
}
|
|
14121
|
+
if (missing.includes("libreoffice")) {
|
|
14122
|
+
const r = LIBREOFFICE_RECIPES[pm];
|
|
14123
|
+
lines.push(` - LibreOffice (soffice): ${r ? r.cmd : "OS\uBCC4 \uC124\uCE58 \uC548\uB0B4\uB294 README \uCC38\uACE0"}`);
|
|
14124
|
+
}
|
|
14125
|
+
lines.push("\uC790\uC138\uD55C \uC810\uAC80: npx kordoc doctor");
|
|
14126
|
+
throw new UnifiedOcrError("TOOLCHAIN_MISSING", "convert", lines.join("\n"));
|
|
11626
14127
|
}
|
|
11627
14128
|
async function listPageImages(imagesDir) {
|
|
11628
14129
|
const files = await readdir(imagesDir);
|
|
11629
|
-
return files.filter((f) => f.endsWith(".png")).sort((a, b) => naturalPageSort(a, b)).map((f) =>
|
|
14130
|
+
return files.filter((f) => f.endsWith(".png")).sort((a, b) => naturalPageSort(a, b)).map((f) => join5(imagesDir, f));
|
|
11630
14131
|
}
|
|
11631
14132
|
function naturalPageSort(a, b) {
|
|
11632
14133
|
const na = Number((a.match(/\d+/g) || ["0"]).at(-1) || 0);
|
|
@@ -11664,12 +14165,12 @@ function startParallelProbeRuns(input) {
|
|
|
11664
14165
|
let doneCount = 0;
|
|
11665
14166
|
let resolveFirst;
|
|
11666
14167
|
let rejectFirst;
|
|
11667
|
-
const firstSuccess = new Promise((resolve4,
|
|
14168
|
+
const firstSuccess = new Promise((resolve4, reject2) => {
|
|
11668
14169
|
resolveFirst = resolve4;
|
|
11669
|
-
rejectFirst =
|
|
14170
|
+
rejectFirst = reject2;
|
|
11670
14171
|
});
|
|
11671
14172
|
let lastErr = "\uC18D\uB3C4 \uD504\uB85C\uBE0C \uC2E4\uD328: \uC0AC\uC6A9 \uAC00\uB2A5\uD55C OCR \uBAA8\uB378\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.";
|
|
11672
|
-
const allResults = mapWithConcurrency(input.models, input.probeConcurrency, async (model,
|
|
14173
|
+
const allResults = mapWithConcurrency(input.models, input.probeConcurrency, async (model, index2) => {
|
|
11673
14174
|
const t0 = performance.now();
|
|
11674
14175
|
try {
|
|
11675
14176
|
await ocrImageViaNim({
|
|
@@ -11685,7 +14186,7 @@ function startParallelProbeRuns(input) {
|
|
|
11685
14186
|
stage: "probe"
|
|
11686
14187
|
});
|
|
11687
14188
|
const result = { model, durationMs: elapsedMs(t0), success: true };
|
|
11688
|
-
input.onProbeResult?.({ index, model, result });
|
|
14189
|
+
input.onProbeResult?.({ index: index2, model, result });
|
|
11689
14190
|
if (!firstResolved) {
|
|
11690
14191
|
firstResolved = true;
|
|
11691
14192
|
resolveFirst?.({ selectedModel: model, firstDurationMs: result.durationMs });
|
|
@@ -11699,7 +14200,7 @@ function startParallelProbeRuns(input) {
|
|
|
11699
14200
|
error: err instanceof Error ? err.message : String(err)
|
|
11700
14201
|
};
|
|
11701
14202
|
lastErr = result.error ?? lastErr;
|
|
11702
|
-
input.onProbeResult?.({ index, model, result });
|
|
14203
|
+
input.onProbeResult?.({ index: index2, model, result });
|
|
11703
14204
|
return result;
|
|
11704
14205
|
} finally {
|
|
11705
14206
|
doneCount += 1;
|
|
@@ -12106,5 +14607,14 @@ export {
|
|
|
12106
14607
|
|
|
12107
14608
|
cfb/cfb.js:
|
|
12108
14609
|
(*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com *)
|
|
14610
|
+
|
|
14611
|
+
tmp/lib/tmp.js:
|
|
14612
|
+
(*!
|
|
14613
|
+
* Tmp
|
|
14614
|
+
*
|
|
14615
|
+
* Copyright (c) 2011-2017 KARASZI Istvan <github@spam.raszi.hu>
|
|
14616
|
+
*
|
|
14617
|
+
* MIT Licensed
|
|
14618
|
+
*)
|
|
12109
14619
|
*/
|
|
12110
14620
|
//# sourceMappingURL=index.js.map
|