acp-kernel 0.0.82 → 0.0.83

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
@@ -2403,18 +2403,30 @@ function mergeRangesToThreshold(ranges, minChars) {
2403
2403
  const result = [];
2404
2404
  let batch = [];
2405
2405
  let batchChars = 0;
2406
- for (const r of ranges) {
2407
- batch.push(r);
2408
- batchChars += rangeChars(r);
2409
- if (batchChars >= minChars) {
2410
- result.push(mergeBatch(batch));
2406
+ const closeBatch = () => {
2407
+ if (batch.length > 0) {
2408
+ if (batchChars >= minChars) result.push(mergeBatch(batch));
2411
2409
  batch = [];
2412
2410
  batchChars = 0;
2413
2411
  }
2412
+ };
2413
+ for (const r of ranges) {
2414
+ const prev = batch[batch.length - 1];
2415
+ if (prev && prev.endIndex !== void 0 && r.startIndex !== void 0 && r.startIndex > prev.endIndex + 1) {
2416
+ closeBatch();
2417
+ }
2418
+ batch.push(r);
2419
+ batchChars += rangeChars(r);
2420
+ if (batchChars >= minChars) closeBatch();
2414
2421
  }
2415
2422
  if (batch.length > 0 && result.length > 0) {
2416
2423
  const prev = result[result.length - 1];
2417
- result[result.length - 1] = mergeBatch([prev, ...batch]);
2424
+ const contiguous = prev.endIndex === void 0 || batch[0].startIndex === void 0 || batch[0].startIndex <= prev.endIndex + 1;
2425
+ if (contiguous) {
2426
+ result[result.length - 1] = mergeBatch([prev, ...batch]);
2427
+ } else if (batchChars >= minChars) {
2428
+ result.push(mergeBatch(batch));
2429
+ }
2418
2430
  }
2419
2431
  return result;
2420
2432
  }