@clazic/kordoc 2.5.0 → 2.5.1

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/index.js CHANGED
@@ -36,7 +36,6 @@ 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);
40
39
 
41
40
  // src/page-range.ts
42
41
  var page_range_exports = {};
@@ -127,9 +126,9 @@ function sanitizeMeta(meta, cfg) {
127
126
  }
128
127
  return out;
129
128
  }
130
- function parsePositiveInt(input, fallback2) {
129
+ function parsePositiveInt(input, fallback) {
131
130
  const n = Number(input);
132
- if (!Number.isFinite(n) || n < 0) return fallback2;
131
+ if (!Number.isFinite(n) || n < 0) return fallback;
133
132
  return Math.floor(n);
134
133
  }
135
134
  function limitText(input, maxLen) {
@@ -294,9 +293,9 @@ var init_logger = __esm({
294
293
  }
295
294
  });
296
295
 
297
- // ../../../node_modules/cfb/cfb.js
296
+ // node_modules/cfb/cfb.js
298
297
  var require_cfb = __commonJS({
299
- "../../../node_modules/cfb/cfb.js"(exports, module) {
298
+ "node_modules/cfb/cfb.js"(exports, module) {
300
299
  "use strict";
301
300
  var Base64_map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
302
301
  function Base64_encode(input) {
@@ -2476,7 +2475,7 @@ function createBatchCliProvider(mode, batchSize) {
2476
2475
  };
2477
2476
  }
2478
2477
  function spawnAsync(cmd, args, opts) {
2479
- return new Promise((resolve4, reject2) => {
2478
+ return new Promise((resolve4, reject) => {
2480
2479
  const child = spawn(cmd, args, {
2481
2480
  cwd: opts.cwd,
2482
2481
  env: process.env,
@@ -2510,14 +2509,14 @@ function spawnAsync(cmd, args, opts) {
2510
2509
  child.on("close", (code) => {
2511
2510
  clearTimeout(timer);
2512
2511
  if (killed) {
2513
- reject2(new Error(`\uD0C0\uC784\uC544\uC6C3 (${Math.round(opts.timeoutMs / 1e3)}\uCD08)`));
2512
+ reject(new Error(`\uD0C0\uC784\uC544\uC6C3 (${Math.round(opts.timeoutMs / 1e3)}\uCD08)`));
2514
2513
  } else {
2515
2514
  resolve4({ stdout, stderr, exitCode: code ?? 1 });
2516
2515
  }
2517
2516
  });
2518
2517
  child.on("error", (err) => {
2519
2518
  clearTimeout(timer);
2520
- reject2(err);
2519
+ reject(err);
2521
2520
  });
2522
2521
  });
2523
2522
  }
@@ -2935,9 +2934,9 @@ async function ocrPagesBatch(doc, provider, pageFilter, effectivePageCount, warn
2935
2934
  });
2936
2935
  }
2937
2936
  } catch (err) {
2938
- const range2 = `${batchPageNums[0]}-${batchPageNums[batchPageNums.length - 1]}`;
2937
+ const range = `${batchPageNums[0]}-${batchPageNums[batchPageNums.length - 1]}`;
2939
2938
  warnings?.push({
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`,
2939
+ message: `\uBC30\uCE58 OCR \uC2E4\uD328 (\uD398\uC774\uC9C0 ${range}): ${err instanceof Error ? err.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"} \u2014 \uB2E8\uC77C \uD398\uC774\uC9C0\uB85C \uC7AC\uC2DC\uB3C4`,
2941
2940
  code: "OCR_PAGE_FAILED"
2942
2941
  });
2943
2942
  for (const { image, pageNum } of batchImages) {
@@ -2982,2320 +2981,6 @@ var init_provider = __esm({
2982
2981
  }
2983
2982
  });
2984
2983
 
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
-
5299
2984
  // src/index.ts
5300
2985
  import { readFile as readFile2 } from "fs/promises";
5301
2986
 
@@ -5743,7 +3428,7 @@ async function extractHwpxStyles(zip, decompressed) {
5743
3428
  }
5744
3429
  return result;
5745
3430
  }
5746
- function parseCharProperties(doc, map2) {
3431
+ function parseCharProperties(doc, map) {
5747
3432
  const tagNames = ["hh:charPr", "charPr", "hp:charPr"];
5748
3433
  for (const tagName of tagNames) {
5749
3434
  const elements = doc.getElementsByTagName(tagName);
@@ -5770,11 +3455,11 @@ function parseCharProperties(doc, map2) {
5770
3455
  }
5771
3456
  }
5772
3457
  }
5773
- map2.set(id, prop);
3458
+ map.set(id, prop);
5774
3459
  }
5775
3460
  }
5776
3461
  }
5777
- function parseStyleElements(doc, map2) {
3462
+ function parseStyleElements(doc, map) {
5778
3463
  const tagNames = ["hh:style", "style", "hp:style"];
5779
3464
  for (const tagName of tagNames) {
5780
3465
  const elements = doc.getElementsByTagName(tagName);
@@ -5784,7 +3469,7 @@ function parseStyleElements(doc, map2) {
5784
3469
  const name = el.getAttribute("name") || el.getAttribute("engName") || "";
5785
3470
  const charPrId = el.getAttribute("charPrIDRef") || void 0;
5786
3471
  const paraPrId = el.getAttribute("paraPrIDRef") || void 0;
5787
- map2.set(id, { name, charPrId, paraPrId });
3472
+ map.set(id, { name, charPrId, paraPrId });
5788
3473
  }
5789
3474
  }
5790
3475
  }
@@ -6310,9 +3995,9 @@ function walkParagraphChildren(node, blocks, tableCtx, tableStack, styleMap, war
6310
3995
  if (depth > MAX_XML_DEPTH) return tableCtx;
6311
3996
  const children = node.childNodes;
6312
3997
  if (!children) return tableCtx;
6313
- const walkChildren = (parent2, d) => {
3998
+ const walkChildren = (parent, d) => {
6314
3999
  if (d > MAX_XML_DEPTH) return;
6315
- const kids = parent2.childNodes;
4000
+ const kids = parent.childNodes;
6316
4001
  if (!kids) return;
6317
4002
  for (let i = 0; i < kids.length; i++) {
6318
4003
  const el = kids[i];
@@ -8525,17 +6210,17 @@ function lineOverlapRatio(a1, a2, b1, b2) {
8525
6210
  return overlap / target;
8526
6211
  }
8527
6212
  function groupConnectedLines(lines) {
8528
- const parent2 = lines.map((_, i) => i);
6213
+ const parent = lines.map((_, i) => i);
8529
6214
  function find2(x) {
8530
- while (parent2[x] !== x) {
8531
- parent2[x] = parent2[parent2[x]];
8532
- x = parent2[x];
6215
+ while (parent[x] !== x) {
6216
+ parent[x] = parent[parent[x]];
6217
+ x = parent[x];
8533
6218
  }
8534
6219
  return x;
8535
6220
  }
8536
6221
  function union(a, b) {
8537
6222
  const ra = find2(a), rb = find2(b);
8538
- if (ra !== rb) parent2[ra] = rb;
6223
+ if (ra !== rb) parent[ra] = rb;
8539
6224
  }
8540
6225
  for (let i = 0; i < lines.length; i++) {
8541
6226
  for (let j = i + 1; j < lines.length; j++) {
@@ -8956,10 +6641,10 @@ async function loadPdfWithTimeout(buffer) {
8956
6641
  try {
8957
6642
  return await Promise.race([
8958
6643
  loadingTask.promise,
8959
- new Promise((_, reject2) => {
6644
+ new Promise((_, reject) => {
8960
6645
  timer = setTimeout(() => {
8961
6646
  loadingTask.destroy();
8962
- reject2(new KordocError(`PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (${timeoutSec}\uCD08 \uCD08\uACFC)`));
6647
+ reject(new KordocError(`PDF \uB85C\uB529 \uD0C0\uC784\uC544\uC6C3 (${timeoutSec}\uCD08 \uCD08\uACFC)`));
8963
6648
  }, timeoutMs);
8964
6649
  })
8965
6650
  ]);
@@ -9148,10 +6833,10 @@ async function parsePdfDocument(buffer, options) {
9148
6833
  }
9149
6834
  const { resolveOcrProvider: resolveOcrProvider2 } = await Promise.resolve().then(() => (init_resolve(), resolve_exports));
9150
6835
  const { ocrPages: ocrPages2 } = await Promise.resolve().then(() => (init_provider(), provider_exports));
9151
- const tryProvider = async (provider, filter2) => {
6836
+ const tryProvider = async (provider, filter) => {
9152
6837
  try {
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);
6838
+ logger.log({ level: "debug", stage: "ocr", event: "progress", message: "OCR provider \uC2E4\uD589", meta: { filteredPages: filter?.size } });
6839
+ return await ocrPages2(doc, provider, filter, effectivePageCount, warnings, concurrency, options?.onProgress);
9155
6840
  } catch {
9156
6841
  logger.log({ level: "warn", stage: "ocr", event: "progress", message: "OCR provider \uC2E4\uD589 \uC2E4\uD328(\uBE48 \uACB0\uACFC\uB85C \uCC98\uB9AC)" });
9157
6842
  return [];
@@ -10166,8 +7851,8 @@ function parseMergeRef(ref) {
10166
7851
  if (!start || !end) return null;
10167
7852
  return { startCol: start.col, startRow: start.row, endCol: end.col, endRow: end.row };
10168
7853
  }
10169
- function getElements(parent2, tagName) {
10170
- const nodes = parent2.getElementsByTagName(tagName);
7854
+ function getElements(parent, tagName) {
7855
+ const nodes = parent.getElementsByTagName(tagName);
10171
7856
  const result = [];
10172
7857
  for (let i = 0; i < nodes.length; i++) result.push(nodes[i]);
10173
7858
  return result;
@@ -10203,14 +7888,14 @@ function parseWorkbook(xml) {
10203
7888
  }
10204
7889
  function parseRels(xml) {
10205
7890
  const doc = parseXml(xml);
10206
- const map2 = /* @__PURE__ */ new Map();
7891
+ const map = /* @__PURE__ */ new Map();
10207
7892
  const rels = getElements(doc.documentElement, "Relationship");
10208
7893
  for (const rel of rels) {
10209
7894
  const id = rel.getAttribute("Id");
10210
7895
  const target = rel.getAttribute("Target");
10211
- if (id && target) map2.set(id, target);
7896
+ if (id && target) map.set(id, target);
10212
7897
  }
10213
- return map2;
7898
+ return map;
10214
7899
  }
10215
7900
  function parseWorksheet(xml, sharedStrings) {
10216
7901
  const doc = parseXml(xml);
@@ -10468,9 +8153,9 @@ import JSZip4 from "jszip";
10468
8153
  import { DOMParser as DOMParser3 } from "@xmldom/xmldom";
10469
8154
  init_logger();
10470
8155
  var MAX_DECOMPRESS_SIZE4 = 500 * 1024 * 1024;
10471
- function getChildElements(parent2, localName) {
8156
+ function getChildElements(parent, localName) {
10472
8157
  const result = [];
10473
- const children = parent2.childNodes;
8158
+ const children = parent.childNodes;
10474
8159
  for (let i = 0; i < children.length; i++) {
10475
8160
  const node = children[i];
10476
8161
  if (node.nodeType === 1) {
@@ -10482,7 +8167,7 @@ function getChildElements(parent2, localName) {
10482
8167
  }
10483
8168
  return result;
10484
8169
  }
10485
- function findElements(parent2, localName) {
8170
+ function findElements(parent, localName) {
10486
8171
  const result = [];
10487
8172
  const walk = (node) => {
10488
8173
  const children = node.childNodes;
@@ -10497,7 +8182,7 @@ function findElements(parent2, localName) {
10497
8182
  }
10498
8183
  }
10499
8184
  };
10500
- walk(parent2);
8185
+ walk(parent);
10501
8186
  return result;
10502
8187
  }
10503
8188
  function getAttr(el, localName) {
@@ -10512,7 +8197,7 @@ function parseXml2(text) {
10512
8197
  return new DOMParser3().parseFromString(text, "text/xml");
10513
8198
  }
10514
8199
  function buildElementIndex(root) {
10515
- const index2 = /* @__PURE__ */ new Map();
8200
+ const index = /* @__PURE__ */ new Map();
10516
8201
  const walk = (node) => {
10517
8202
  const children = node.childNodes;
10518
8203
  for (let i = 0; i < children.length; i++) {
@@ -10521,10 +8206,10 @@ function buildElementIndex(root) {
10521
8206
  const el = child;
10522
8207
  const name = el.localName ?? "";
10523
8208
  if (name) {
10524
- let list = index2.get(name);
8209
+ let list = index.get(name);
10525
8210
  if (!list) {
10526
8211
  list = [];
10527
- index2.set(name, list);
8212
+ index.set(name, list);
10528
8213
  }
10529
8214
  list.push(el);
10530
8215
  }
@@ -10533,7 +8218,7 @@ function buildElementIndex(root) {
10533
8218
  }
10534
8219
  };
10535
8220
  walk(root);
10536
- return index2;
8221
+ return index;
10537
8222
  }
10538
8223
  function parseStyles(xml) {
10539
8224
  const doc = parseXml2(xml);
@@ -10599,14 +8284,14 @@ function parseNumbering(xml) {
10599
8284
  }
10600
8285
  function parseRels2(xml) {
10601
8286
  const doc = parseXml2(xml);
10602
- const map2 = /* @__PURE__ */ new Map();
8287
+ const map = /* @__PURE__ */ new Map();
10603
8288
  const rels = findElements(doc, "Relationship");
10604
8289
  for (const rel of rels) {
10605
8290
  const id = getAttr(rel, "Id");
10606
8291
  const target = getAttr(rel, "Target");
10607
- if (id && target) map2.set(id, target);
8292
+ if (id && target) map.set(id, target);
10608
8293
  }
10609
- return map2;
8294
+ return map;
10610
8295
  }
10611
8296
  function parseFootnotes(xml) {
10612
8297
  const doc = parseXml2(xml);
@@ -12449,22 +10134,22 @@ function findCharPrByCharacteristic(charPrMap, characteristic) {
12449
10134
  italic: { minHeight: 800, maxHeight: 1100, needBold: false },
12450
10135
  normal: { minHeight: 900, maxHeight: 1100, needBold: false }
12451
10136
  };
12452
- const range2 = ranges[characteristic];
12453
- if (!range2) return null;
10137
+ const range = ranges[characteristic];
10138
+ if (!range) return null;
12454
10139
  let bestMatch = null;
12455
10140
  let bestScore = 0;
12456
10141
  for (const [id, prop] of charPrMap) {
12457
10142
  let score = 0;
12458
10143
  if (prop.height) {
12459
- if (prop.height >= range2.minHeight && prop.height <= range2.maxHeight) {
10144
+ if (prop.height >= range.minHeight && prop.height <= range.maxHeight) {
12460
10145
  score += 50;
12461
- } else if (Math.abs(prop.height - (range2.minHeight + range2.maxHeight) / 2) < 100) {
10146
+ } else if (Math.abs(prop.height - (range.minHeight + range.maxHeight) / 2) < 100) {
12462
10147
  score += 20;
12463
10148
  }
12464
10149
  }
12465
- if (range2.needBold !== void 0) {
12466
- if (range2.needBold && prop.bold) score += 30;
12467
- else if (!range2.needBold && !prop.bold) score += 20;
10150
+ if (range.needBold !== void 0) {
10151
+ if (range.needBold && prop.bold) score += 30;
10152
+ else if (!range.needBold && !prop.bold) score += 20;
12468
10153
  }
12469
10154
  if (characteristic === "italic" && prop.italic) score += 20;
12470
10155
  if (score > bestScore) {
@@ -13303,10 +10988,10 @@ function mimeToExtension(mimeType) {
13303
10988
  return "png";
13304
10989
  }
13305
10990
  function buildImageMap(images) {
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;
10991
+ const map = /* @__PURE__ */ new Map();
10992
+ if (!images) return map;
10993
+ for (const img of images) map.set(img.filename, img);
10994
+ return map;
13310
10995
  }
13311
10996
  async function fillBodySheet(sheet, workbook, blocks, imageMap) {
13312
10997
  sheet.getColumn(1).width = 80;
@@ -13508,8 +11193,8 @@ var ApiKeyRotationPool = class _ApiKeyRotationPool {
13508
11193
  const s = this.find(keyId);
13509
11194
  s.failureCount++;
13510
11195
  s.consecutiveFailures++;
13511
- const retryable2 = this.isRetryableFailure(opts.status, opts.timeout);
13512
- if (!retryable2) return;
11196
+ const retryable = this.isRetryableFailure(opts.status, opts.timeout);
11197
+ if (!retryable) return;
13513
11198
  const exp = Math.max(0, s.consecutiveFailures - 1);
13514
11199
  const backoff = Math.min(this.baseCooldownMs * 2 ** exp, this.maxCooldownMs);
13515
11200
  const cooldown = Math.max(backoff, opts.retryAfterMs ?? 0);
@@ -13526,8 +11211,8 @@ var ApiKeyRotationPool = class _ApiKeyRotationPool {
13526
11211
  cooldownUntil: s.cooldownUntil
13527
11212
  }));
13528
11213
  }
13529
- isRetryableFailure(status, timeout2) {
13530
- if (timeout2) return true;
11214
+ isRetryableFailure(status, timeout) {
11215
+ if (timeout) return true;
13531
11216
  if (status === 429) return true;
13532
11217
  if (typeof status === "number" && status >= 500) return true;
13533
11218
  return false;
@@ -13541,172 +11226,72 @@ var ApiKeyRotationPool = class _ApiKeyRotationPool {
13541
11226
 
13542
11227
  // src/pipeline/unified-ocr.ts
13543
11228
  import { mkdir, readdir, readFile, stat, writeFile } from "fs/promises";
13544
- import { basename as basename2, dirname as dirname3, extname, join as join5, resolve as resolve3 } from "path";
11229
+ import { basename as basename2, dirname as dirname3, extname, join as join4, resolve as resolve3 } from "path";
13545
11230
  import { spawn as spawn2 } from "child_process";
13546
11231
  import { performance } from "perf_hooks";
11232
+ import libre from "libreoffice-convert";
13547
11233
  init_logger();
13548
11234
 
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;
11235
+ // src/pipeline/bounded-queue.ts
11236
+ var QUEUE_DONE = /* @__PURE__ */ Symbol("QUEUE_DONE");
11237
+ var BoundedQueue = class {
11238
+ buffer = [];
11239
+ capacity;
11240
+ closed = false;
11241
+ producerWaiters = [];
11242
+ consumerWaiters = [];
11243
+ constructor(capacity) {
11244
+ if (capacity < 1) throw new RangeError("BoundedQueue capacity must be >= 1");
11245
+ this.capacity = capacity;
11246
+ }
11247
+ async enqueue(item) {
11248
+ if (this.closed) throw new Error("BoundedQueue: cannot enqueue after close()");
11249
+ if (this.consumerWaiters.length > 0) {
11250
+ const resolve4 = this.consumerWaiters.shift();
11251
+ resolve4(item);
11252
+ return;
13621
11253
  }
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;
11254
+ while (this.buffer.length >= this.capacity) {
11255
+ await new Promise((resolve4) => this.producerWaiters.push(resolve4));
11256
+ if (this.closed) throw new Error("BoundedQueue: closed while waiting to enqueue");
11257
+ }
11258
+ this.buffer.push(item);
11259
+ }
11260
+ async dequeue() {
11261
+ if (this.buffer.length > 0) {
11262
+ const item = this.buffer.shift();
11263
+ this._wakeProducer();
11264
+ return item;
11265
+ }
11266
+ if (this.closed) return QUEUE_DONE;
11267
+ return new Promise((resolve4) => {
11268
+ this.consumerWaiters.push(resolve4);
11269
+ });
11270
+ }
11271
+ close() {
11272
+ if (this.closed) return;
11273
+ this.closed = true;
11274
+ for (const resolve4 of this.consumerWaiters) {
11275
+ resolve4(QUEUE_DONE);
11276
+ }
11277
+ this.consumerWaiters = [];
11278
+ for (const wake of this.producerWaiters) {
11279
+ wake();
11280
+ }
11281
+ this.producerWaiters = [];
11282
+ }
11283
+ get size() {
11284
+ return this.buffer.length;
11285
+ }
11286
+ _wakeProducer() {
11287
+ if (this.producerWaiters.length > 0) {
11288
+ this.producerWaiters.shift()();
13632
11289
  }
13633
11290
  }
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
11291
  };
13708
11292
 
13709
11293
  // src/pipeline/unified-ocr.ts
11294
+ var libreConvert = libre.convert;
13710
11295
  var UnifiedOcrError = class extends Error {
13711
11296
  code;
13712
11297
  stage;
@@ -13737,11 +11322,11 @@ var DEFAULT_MODEL_MAX_TOKENS = {
13737
11322
  };
13738
11323
  var DEFAULT_STAGE_WEIGHTS = {
13739
11324
  convert: 15,
13740
- render: 20,
11325
+ render: 15,
13741
11326
  probe: 5,
13742
- ocr: 45,
11327
+ ocr: 55,
13743
11328
  proofread: 0,
13744
- merge: 5
11329
+ merge: 10
13745
11330
  };
13746
11331
  var OCR_PROMPT2 = [
13747
11332
  "\uC774 PDF \uD398\uC774\uC9C0 \uC774\uBBF8\uC9C0\uC5D0\uC11C \uD14D\uC2A4\uD2B8\uC640 \uD45C\uB97C \uCD94\uCD9C\uD558\uC5EC Markdown\uC73C\uB85C \uBCC0\uD658\uD558\uACE0, OCR \uC624\uC778\uC2DD \uC624\uB958\uB97C \uC989\uC2DC \uAD50\uC815\uD558\uC5EC \uCD5C\uC885 \uACB0\uACFC\uBB3C\uC744 \uCD9C\uB825\uD558\uC138\uC694.",
@@ -13780,13 +11365,13 @@ function elapsedMs(startAt) {
13780
11365
  async function runUnifiedOcrPipeline(inputPath, options = {}) {
13781
11366
  const absInput = resolve3(inputPath);
13782
11367
  const stem = basename2(absInput, extname(absInput));
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");
11368
+ const workspaceDir = resolve3(options.workspaceDir ?? join4(dirname3(absInput), `${stem}_ocr_workspace`));
11369
+ const imagesDir = join4(workspaceDir, "images");
11370
+ const rawDir = join4(workspaceDir, "ocr", "raw");
11371
+ const diffDir = join4(workspaceDir, "ocr", "diff");
11372
+ const outputPath = resolve3(options.outputPath ?? join4(dirname3(absInput), `${stem}.md`));
11373
+ const reportPath = join4(workspaceDir, "run-report.json");
11374
+ const modelCachePath = join4(dirname3(absInput), ".kordoc-model-cache.json");
13790
11375
  const baseUrl = options.baseUrl ?? "https://integrate.api.nvidia.com/v1/chat/completions";
13791
11376
  const timeoutMs = options.timeoutMs ?? 6e4;
13792
11377
  const maxRetriesPerPage = options.maxRetriesPerPage ?? 5;
@@ -13813,15 +11398,14 @@ async function runUnifiedOcrPipeline(inputPath, options = {}) {
13813
11398
  };
13814
11399
  try {
13815
11400
  ensureSupportedInput(absInput);
13816
- const isPdfInput = extname(absInput).toLowerCase() === ".pdf";
13817
- await assertOcrToolchain(isPdfInput);
13818
11401
  let workingPdfPath = absInput;
13819
11402
  const convertStart = performance.now();
13820
11403
  currentStage = "convert";
13821
11404
  markStageStart("convert", "\uBB38\uC11C\uB97C PDF\uB85C \uBCC0\uD658 \uC911");
13822
11405
  logStage("info", "convert", "start", "\uBB38\uC11C\uB97C PDF\uB85C \uBCC0\uD658 \uC2DC\uC791", { input: absInput });
13823
- if (!isPdfInput) {
13824
- workingPdfPath = join5(workspaceDir, `${stem}.pdf`);
11406
+ if (extname(absInput).toLowerCase() !== ".pdf") {
11407
+ await assertSofficeAvailable();
11408
+ workingPdfPath = join4(workspaceDir, `${stem}.pdf`);
13825
11409
  const inputBuffer = await readFile(absInput);
13826
11410
  const out = await convertWithLibreOffice(inputBuffer, ".pdf");
13827
11411
  await writeFile(workingPdfPath, out);
@@ -13831,39 +11415,19 @@ async function runUnifiedOcrPipeline(inputPath, options = {}) {
13831
11415
  logStage("info", "convert", "done", "PDF \uBCC0\uD658 \uC644\uB8CC", { elapsedMs: timingsMs.convert });
13832
11416
  const renderStart = performance.now();
13833
11417
  currentStage = "render";
11418
+ const totalPages = await getPdfPageCount(workingPdfPath).catch(() => 0);
11419
+ if (totalPages === 0) throw new UnifiedOcrError("RENDER_FAILED", "render", "\uD398\uC774\uC9C0 \uC218\uB97C \uD655\uC778\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4.");
13834
11420
  markStageStart("render", "PDF \uD398\uC774\uC9C0 \uC774\uBBF8\uC9C0 \uC0DD\uC131 \uC911");
13835
- logStage("info", "render", "start", "PDF \uD398\uC774\uC9C0 \uB80C\uB354\uB9C1 \uC2DC\uC791", { pdf: workingPdfPath, dpi });
13836
- const renderWithProgress = await renderPdfToPngWithProgress(
13837
- workingPdfPath,
13838
- join5(imagesDir, "page"),
13839
- dpi,
13840
- (current, total) => {
13841
- markStageProgress(
13842
- "render",
13843
- Math.round(current / total * 100),
13844
- current,
13845
- total,
13846
- `\uD398\uC774\uC9C0 ${current}/${total} \uB80C\uB354\uB9C1`
13847
- );
13848
- }
13849
- );
13850
- const images = await listPageImages(imagesDir);
13851
- if (images.length === 0) throw new UnifiedOcrError("RENDER_FAILED", "render", "\uD398\uC774\uC9C0 \uC774\uBBF8\uC9C0 \uC0DD\uC131 \uC2E4\uD328: \uACB0\uACFC \uC774\uBBF8\uC9C0\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.");
13852
- if (!renderWithProgress.emittedPerPageProgress) {
13853
- markStageProgress("render", 100, images.length, images.length, `\uD398\uC774\uC9C0 ${images.length}\uC7A5 \uC0DD\uC131`);
13854
- }
13855
- timingsMs.render = elapsedMs(renderStart);
13856
- markStageDone("render", "\uC774\uBBF8\uC9C0 \uC0DD\uC131 \uC644\uB8CC");
13857
- logStage("info", "render", "done", "\uD398\uC774\uC9C0 \uC774\uBBF8\uC9C0 \uC0DD\uC131 \uC644\uB8CC", {
13858
- pages: images.length,
13859
- elapsedMs: timingsMs.render,
13860
- pageCountSource: renderWithProgress.pageCountSource
13861
- });
11421
+ logStage("info", "render", "start", "PDF \uD398\uC774\uC9C0 \uB80C\uB354\uB9C1 \uC2DC\uC791", { pdf: workingPdfPath, dpi, totalPages });
11422
+ await runCommand("pdftoppm", ["-png", "-r", String(dpi), "-f", "1", "-l", "1", workingPdfPath, join4(imagesDir, "page")]);
11423
+ const firstFiles = (await readdir(imagesDir)).filter((f) => f.endsWith(".png")).sort((a, b) => naturalPageSort(a, b));
11424
+ if (firstFiles.length === 0) throw new UnifiedOcrError("RENDER_FAILED", "render", "\uCCAB \uD398\uC774\uC9C0 \uC774\uBBF8\uC9C0 \uC0DD\uC131 \uC2E4\uD328");
11425
+ const probeImage = join4(imagesDir, firstFiles[0]);
11426
+ markStageProgress("render", Math.round(1 / totalPages * 100), 1, totalPages, `\uD398\uC774\uC9C0 1/${totalPages} \uB80C\uB354\uB9C1`);
13862
11427
  const probeStart = performance.now();
13863
11428
  currentStage = "probe";
13864
11429
  markStageStart("probe", "\uBAA8\uB378 \uC18D\uB3C4 \uD504\uB85C\uBE0C \uC218\uD589 \uC911");
13865
11430
  logStage("info", "probe", "start", "\uBAA8\uB378 \uC18D\uB3C4 \uD504\uB85C\uBE0C \uC2DC\uC791", { models, probeConcurrency });
13866
- const probeImage = await pickRepresentativeImage(images);
13867
11431
  let probeDone = 0;
13868
11432
  const probeRuns = startParallelProbeRuns({
13869
11433
  models,
@@ -13874,10 +11438,10 @@ async function runUnifiedOcrPipeline(inputPath, options = {}) {
13874
11438
  keyPool,
13875
11439
  timeoutMs,
13876
11440
  logger,
13877
- onProbeResult: ({ index: index2, model, result }) => {
11441
+ onProbeResult: ({ index, model, result }) => {
13878
11442
  probeDone += 1;
13879
11443
  markStageProgress("probe", Math.round(probeDone / models.length * 100), probeDone, models.length, `\uBAA8\uB378 \uD504\uB85C\uBE0C ${probeDone}/${models.length}`);
13880
- logStage("debug", "probe", "progress", "\uBAA8\uB378 \uD504\uB85C\uBE0C \uC9C4\uD589", { index: index2 + 1, total: models.length, model, result });
11444
+ logStage("debug", "probe", "progress", "\uBAA8\uB378 \uD504\uB85C\uBE0C \uC9C4\uD589", { index: index + 1, total: models.length, model, result });
13881
11445
  }
13882
11446
  });
13883
11447
  const selected = await probeRuns.firstSuccess;
@@ -13890,33 +11454,74 @@ async function runUnifiedOcrPipeline(inputPath, options = {}) {
13890
11454
  await updateModelCache(modelCachePath, results);
13891
11455
  return results;
13892
11456
  });
11457
+ const concurrencyPerKey = Math.max(1, options.concurrencyPerKey ?? 2);
11458
+ const keyCount = keyPool.snapshot().length;
11459
+ const workerCount = Math.max(1, keyCount * concurrencyPerKey);
11460
+ const queueCapacity = workerCount * 2;
11461
+ const queue = new BoundedQueue(queueCapacity);
13893
11462
  const ocrStart = performance.now();
13894
11463
  currentStage = "ocr";
13895
- markStageStart("ocr", `OCR \uC9C4\uD589 \uC911 (${selectedModel})`);
13896
- logStage("info", "ocr", "start", "\uD398\uC774\uC9C0 OCR \uC2DC\uC791", { selectedModel, pageCount: images.length });
13897
- const rawPagePaths = [];
13898
- for (let i = 0; i < images.length; i++) {
13899
- const imagePath = images[i];
13900
- const markdown = await ocrImageWithFallback({
13901
- imagePath,
13902
- prompt: OCR_PROMPT2,
13903
- models: fallbackModelOrder,
13904
- modelMaxTokens,
13905
- baseUrl,
13906
- keyPool,
13907
- timeoutMs,
13908
- maxRetriesPerPage,
11464
+ markStageStart("ocr", `OCR \uC9C4\uD589 \uC911 (\uC6CC\uCEE4 ${workerCount}\uAC1C)`);
11465
+ logStage("info", "ocr", "start", "\uD398\uC774\uC9C0 OCR \uC2DC\uC791", { workerCount, keyCount, pageCount: totalPages });
11466
+ let renderDone = 1;
11467
+ const renderProducer = (async () => {
11468
+ try {
11469
+ await queue.enqueue({ pageNumber: 1, imagePath: probeImage });
11470
+ if (totalPages > 1) {
11471
+ for await (const item of renderPdfToPngStream(workingPdfPath, join4(imagesDir, "page"), dpi, totalPages, 2)) {
11472
+ await queue.enqueue(item);
11473
+ renderDone++;
11474
+ markStageProgress("render", Math.round(renderDone / totalPages * 100), renderDone, totalPages, `\uD398\uC774\uC9C0 ${renderDone}/${totalPages} \uB80C\uB354\uB9C1`);
11475
+ logStage("debug", "render", "progress", "\uD398\uC774\uC9C0 \uB80C\uB354 \uC644\uB8CC", { page: item.pageNumber });
11476
+ }
11477
+ }
11478
+ } finally {
11479
+ queue.close();
11480
+ timingsMs.render = elapsedMs(renderStart);
11481
+ markStageDone("render", "\uC774\uBBF8\uC9C0 \uC0DD\uC131 \uC644\uB8CC");
11482
+ logStage("info", "render", "done", "\uD398\uC774\uC9C0 \uC774\uBBF8\uC9C0 \uC0DD\uC131 \uC644\uB8CC", { pages: renderDone, elapsedMs: timingsMs.render });
11483
+ }
11484
+ })();
11485
+ const [, pageResultsMap] = await Promise.all([
11486
+ renderProducer,
11487
+ ocrWorkerPool({
11488
+ queue,
11489
+ workerCount,
11490
+ totalPages,
11491
+ ocrInput: {
11492
+ prompt: OCR_PROMPT2,
11493
+ models: fallbackModelOrder,
11494
+ modelMaxTokens,
11495
+ baseUrl,
11496
+ keyPool,
11497
+ timeoutMs,
11498
+ maxRetriesPerPage,
11499
+ logger
11500
+ },
11501
+ onPageDone: (pageNumber, completedCount, model) => {
11502
+ markStageProgress(
11503
+ "ocr",
11504
+ Math.round(completedCount / totalPages * 100),
11505
+ completedCount,
11506
+ totalPages,
11507
+ `OCR ${completedCount}/${totalPages}`,
11508
+ model || void 0
11509
+ );
11510
+ logStage("debug", "ocr", "progress", "\uD398\uC774\uC9C0 OCR \uC644\uB8CC", { page: pageNumber, total: totalPages, model });
11511
+ },
13909
11512
  logger
13910
- });
13911
- const pagePath = join5(rawDir, `page_${String(i + 1).padStart(4, "0")}.md`);
13912
- await writeFile(pagePath, markdown, "utf-8");
13913
- rawPagePaths.push(pagePath);
13914
- markStageProgress("ocr", Math.round((i + 1) / images.length * 100), i + 1, images.length, `OCR ${i + 1}/${images.length}`, selectedModel);
13915
- logStage("debug", "ocr", "progress", "\uD398\uC774\uC9C0 OCR \uC644\uB8CC", { page: i + 1, total: images.length });
13916
- }
11513
+ })
11514
+ ]);
13917
11515
  timingsMs.ocr = elapsedMs(ocrStart);
13918
11516
  markStageDone("ocr", "OCR \uC644\uB8CC");
13919
11517
  logStage("info", "ocr", "done", "\uD398\uC774\uC9C0 OCR \uC644\uB8CC", { elapsedMs: timingsMs.ocr });
11518
+ const sortedEntries = Array.from(pageResultsMap.entries()).sort((a, b) => a[0] - b[0]);
11519
+ const rawPagePaths = [];
11520
+ for (const [pageNum, markdown] of sortedEntries) {
11521
+ const pagePath = join4(rawDir, `page_${String(pageNum).padStart(4, "0")}.md`);
11522
+ await writeFile(pagePath, markdown, "utf-8");
11523
+ rawPagePaths.push(pagePath);
11524
+ }
13920
11525
  const mergeStart = performance.now();
13921
11526
  currentStage = "merge";
13922
11527
  markStageStart("merge", "\uCD5C\uC885 Markdown \uBCD1\uD569 \uC911");
@@ -13933,7 +11538,7 @@ async function runUnifiedOcrPipeline(inputPath, options = {}) {
13933
11538
  selectedModel,
13934
11539
  probeImage,
13935
11540
  probeResults: await probeResultsPromise,
13936
- pageCount: images.length,
11541
+ pageCount: totalPages,
13937
11542
  keyHealth: keyPool.snapshot(),
13938
11543
  timingsMs,
13939
11544
  modelCachePath
@@ -14000,37 +11605,17 @@ function emitProgress(cb, stage, stagePercent, weights, extra) {
14000
11605
  model: extra.model
14001
11606
  });
14002
11607
  }
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
- }
14015
11608
  async function convertWithLibreOffice(buffer, ext) {
14016
- const libreConvert = await loadLibreConvert();
14017
- return await new Promise((resolvePromise, reject2) => {
11609
+ return await new Promise((resolvePromise, reject) => {
14018
11610
  libreConvert(buffer, ext, void 0, (err, done) => {
14019
11611
  if (err || !done) {
14020
- reject2(new UnifiedOcrError("CONVERT_FAILED", "convert", err?.message ?? "LibreOffice \uBCC0\uD658 \uC2E4\uD328"));
11612
+ reject(new UnifiedOcrError("CONVERT_FAILED", "convert", err?.message ?? "LibreOffice \uBCC0\uD658 \uC2E4\uD328"));
14021
11613
  return;
14022
11614
  }
14023
11615
  resolvePromise(done);
14024
11616
  });
14025
11617
  });
14026
11618
  }
14027
- async function renderPdfToPng(pdfPath, prefixPath, dpi) {
14028
- try {
14029
- await runCommand("pdftoppm", ["-png", "-r", String(dpi), pdfPath, prefixPath]);
14030
- } catch (err) {
14031
- throw new UnifiedOcrError("RENDER_FAILED", "render", err instanceof Error ? err.message : String(err));
14032
- }
14033
- }
14034
11619
  async function getPdfPageCount(pdfPath) {
14035
11620
  const stdout = await runCommandWithStdout("pdfinfo", [pdfPath]);
14036
11621
  const m = stdout.match(/^\s*Pages:\s*(\d+)\s*$/mi);
@@ -14043,53 +11628,50 @@ async function getPdfPageCount(pdfPath) {
14043
11628
  }
14044
11629
  return n;
14045
11630
  }
14046
- async function renderPdfToPngWithProgress(pdfPath, prefixPath, dpi, onPageDone) {
14047
- let totalPages = 0;
14048
- try {
14049
- totalPages = await getPdfPageCount(pdfPath);
14050
- } catch {
14051
- totalPages = 0;
14052
- }
14053
- if (totalPages > 0) {
11631
+ async function* renderPdfToPngStream(pdfPath, prefixPath, dpi, totalPages, startPage = 1) {
11632
+ const imagesDir = dirname3(prefixPath);
11633
+ for (let page = startPage; page <= totalPages; page++) {
14054
11634
  try {
14055
- for (let page = 1; page <= totalPages; page++) {
14056
- await runCommand("pdftoppm", [
14057
- "-png",
14058
- "-r",
14059
- String(dpi),
14060
- "-f",
14061
- String(page),
14062
- "-l",
14063
- String(page),
14064
- pdfPath,
14065
- prefixPath
14066
- ]);
14067
- onPageDone(page, totalPages);
14068
- }
14069
- return { emittedPerPageProgress: true, pageCountSource: "pdfinfo" };
11635
+ await runCommand("pdftoppm", [
11636
+ "-png",
11637
+ "-r",
11638
+ String(dpi),
11639
+ "-f",
11640
+ String(page),
11641
+ "-l",
11642
+ String(page),
11643
+ pdfPath,
11644
+ prefixPath
11645
+ ]);
11646
+ const files = await readdir(imagesDir);
11647
+ const pageFiles = files.filter((f) => f.endsWith(".png")).sort((a, b) => naturalPageSort(a, b));
11648
+ const imagePath = join4(imagesDir, pageFiles[pageFiles.length - 1]);
11649
+ yield { pageNumber: page, imagePath };
14070
11650
  } catch (err) {
14071
- throw new UnifiedOcrError("RENDER_FAILED", "render", err instanceof Error ? err.message : String(err));
11651
+ yield {
11652
+ pageNumber: page,
11653
+ imagePath: null,
11654
+ error: err instanceof Error ? err : new Error(String(err))
11655
+ };
14072
11656
  }
14073
11657
  }
14074
- await renderPdfToPng(pdfPath, prefixPath, dpi);
14075
- return { emittedPerPageProgress: false, pageCountSource: "fallback" };
14076
11658
  }
14077
11659
  async function runCommand(cmd, args) {
14078
- await new Promise((resolvePromise, reject2) => {
11660
+ await new Promise((resolvePromise, reject) => {
14079
11661
  const child = spawn2(cmd, args, { stdio: "pipe" });
14080
11662
  let stderr = "";
14081
11663
  child.stderr.on("data", (d) => {
14082
11664
  stderr += String(d);
14083
11665
  });
14084
- child.on("error", reject2);
11666
+ child.on("error", reject);
14085
11667
  child.on("close", (code) => {
14086
11668
  if (code === 0) resolvePromise();
14087
- else reject2(new Error(`${cmd} \uC2E4\uD328 (code=${code}): ${stderr.trim()}`));
11669
+ else reject(new Error(`${cmd} \uC2E4\uD328 (code=${code}): ${stderr.trim()}`));
14088
11670
  });
14089
11671
  });
14090
11672
  }
14091
11673
  async function runCommandWithStdout(cmd, args) {
14092
- return await new Promise((resolvePromise, reject2) => {
11674
+ return await new Promise((resolvePromise, reject) => {
14093
11675
  const child = spawn2(cmd, args, { stdio: "pipe" });
14094
11676
  let stdout = "";
14095
11677
  let stderr = "";
@@ -14099,52 +11681,25 @@ async function runCommandWithStdout(cmd, args) {
14099
11681
  child.stderr.on("data", (d) => {
14100
11682
  stderr += String(d);
14101
11683
  });
14102
- child.on("error", reject2);
11684
+ child.on("error", reject);
14103
11685
  child.on("close", (code) => {
14104
11686
  if (code === 0) resolvePromise(stdout);
14105
- else reject2(new Error(`${cmd} \uC2E4\uD328 (code=${code}): ${stderr.trim()}`));
11687
+ else reject(new Error(`${cmd} \uC2E4\uD328 (code=${code}): ${stderr.trim()}`));
14106
11688
  });
14107
11689
  });
14108
11690
  }
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"));
14127
- }
14128
- async function listPageImages(imagesDir) {
14129
- const files = await readdir(imagesDir);
14130
- return files.filter((f) => f.endsWith(".png")).sort((a, b) => naturalPageSort(a, b)).map((f) => join5(imagesDir, f));
11691
+ async function assertSofficeAvailable() {
11692
+ try {
11693
+ await runCommand("soffice", ["--version"]);
11694
+ } catch {
11695
+ throw new UnifiedOcrError("SOFFICE_NOT_FOUND", "convert", "soffice\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. LibreOffice\uB97C \uC124\uCE58\uD574 \uC8FC\uC138\uC694.");
11696
+ }
14131
11697
  }
14132
11698
  function naturalPageSort(a, b) {
14133
11699
  const na = Number((a.match(/\d+/g) || ["0"]).at(-1) || 0);
14134
11700
  const nb = Number((b.match(/\d+/g) || ["0"]).at(-1) || 0);
14135
11701
  return na - nb;
14136
11702
  }
14137
- async function pickRepresentativeImage(images) {
14138
- const sample = images.slice(0, Math.min(images.length, 8));
14139
- const weighted = [];
14140
- for (const p of sample) {
14141
- const st = await stat(p);
14142
- if (st.size > 8 * 1024) weighted.push({ path: p, size: st.size });
14143
- }
14144
- const use = weighted.length > 0 ? weighted : await Promise.all(sample.map(async (p) => ({ path: p, size: (await stat(p)).size })));
14145
- use.sort((a, b) => a.size - b.size);
14146
- return use[Math.floor(use.length / 2)].path;
14147
- }
14148
11703
  async function mapWithConcurrency(items, concurrency, mapper) {
14149
11704
  const results = new Array(items.length);
14150
11705
  let nextIndex = 0;
@@ -14165,12 +11720,12 @@ function startParallelProbeRuns(input) {
14165
11720
  let doneCount = 0;
14166
11721
  let resolveFirst;
14167
11722
  let rejectFirst;
14168
- const firstSuccess = new Promise((resolve4, reject2) => {
11723
+ const firstSuccess = new Promise((resolve4, reject) => {
14169
11724
  resolveFirst = resolve4;
14170
- rejectFirst = reject2;
11725
+ rejectFirst = reject;
14171
11726
  });
14172
11727
  let lastErr = "\uC18D\uB3C4 \uD504\uB85C\uBE0C \uC2E4\uD328: \uC0AC\uC6A9 \uAC00\uB2A5\uD55C OCR \uBAA8\uB378\uC774 \uC5C6\uC2B5\uB2C8\uB2E4.";
14173
- const allResults = mapWithConcurrency(input.models, input.probeConcurrency, async (model, index2) => {
11728
+ const allResults = mapWithConcurrency(input.models, input.probeConcurrency, async (model, index) => {
14174
11729
  const t0 = performance.now();
14175
11730
  try {
14176
11731
  await ocrImageViaNim({
@@ -14186,7 +11741,7 @@ function startParallelProbeRuns(input) {
14186
11741
  stage: "probe"
14187
11742
  });
14188
11743
  const result = { model, durationMs: elapsedMs(t0), success: true };
14189
- input.onProbeResult?.({ index: index2, model, result });
11744
+ input.onProbeResult?.({ index, model, result });
14190
11745
  if (!firstResolved) {
14191
11746
  firstResolved = true;
14192
11747
  resolveFirst?.({ selectedModel: model, firstDurationMs: result.durationMs });
@@ -14200,7 +11755,7 @@ function startParallelProbeRuns(input) {
14200
11755
  error: err instanceof Error ? err.message : String(err)
14201
11756
  };
14202
11757
  lastErr = result.error ?? lastErr;
14203
- input.onProbeResult?.({ index: index2, model, result });
11758
+ input.onProbeResult?.({ index, model, result });
14204
11759
  return result;
14205
11760
  } finally {
14206
11761
  doneCount += 1;
@@ -14246,11 +11801,43 @@ async function updateModelCache(path, probes) {
14246
11801
  current.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
14247
11802
  await writeFile(path, JSON.stringify(current, null, 2), "utf-8");
14248
11803
  }
11804
+ async function ocrWorkerPool(input) {
11805
+ const { queue, workerCount, ocrInput, onPageDone } = input;
11806
+ const results = /* @__PURE__ */ new Map();
11807
+ let completedCount = 0;
11808
+ async function worker() {
11809
+ while (true) {
11810
+ const item = await queue.dequeue();
11811
+ if (item === QUEUE_DONE) break;
11812
+ const { pageNumber, imagePath, error } = item;
11813
+ if (imagePath === null) {
11814
+ input.logger?.log({
11815
+ level: "warn",
11816
+ stage: "ocr",
11817
+ event: "message",
11818
+ message: `\uD398\uC774\uC9C0 ${pageNumber} \uB80C\uB354 \uC2E4\uD328 \u2014 \uBE48 \uD398\uC774\uC9C0\uB85C \uCC98\uB9AC`,
11819
+ meta: { error: String(error) }
11820
+ });
11821
+ results.set(pageNumber, "");
11822
+ completedCount++;
11823
+ onPageDone(pageNumber, completedCount, "");
11824
+ continue;
11825
+ }
11826
+ const { markdown, model } = await ocrImageWithFallback({ ...ocrInput, imagePath });
11827
+ results.set(pageNumber, markdown);
11828
+ completedCount++;
11829
+ onPageDone(pageNumber, completedCount, model);
11830
+ }
11831
+ }
11832
+ const workers = Array.from({ length: workerCount }, () => worker());
11833
+ await Promise.all(workers);
11834
+ return results;
11835
+ }
14249
11836
  async function ocrImageWithFallback(input) {
14250
11837
  let lastErr = "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958";
14251
11838
  for (const model of input.models) {
14252
11839
  try {
14253
- return await ocrImageViaNim({
11840
+ const markdown = await ocrImageViaNim({
14254
11841
  imagePath: input.imagePath,
14255
11842
  prompt: input.prompt,
14256
11843
  model,
@@ -14262,6 +11849,7 @@ async function ocrImageWithFallback(input) {
14262
11849
  logger: input.logger,
14263
11850
  stage: "ocr"
14264
11851
  });
11852
+ return { markdown, model };
14265
11853
  } catch (err) {
14266
11854
  lastErr = err instanceof Error ? err.message : String(err);
14267
11855
  }
@@ -14607,14 +12195,5 @@ export {
14607
12195
 
14608
12196
  cfb/cfb.js:
14609
12197
  (*! 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
- *)
14619
12198
  */
14620
12199
  //# sourceMappingURL=index.js.map