pdf-skryba 0.9.0 → 0.9.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/CHANGELOG.md CHANGED
@@ -10,6 +10,16 @@ The package was named `skryba` from 0.1.0 to 0.6.2; `skryba` stays frozen at 0.6
10
10
  with the message « Renamed to pdf-skryba ». Before 0.1.0 the same reader was published as
11
11
  `@miksumia/reader`, which the registry no longer serves; those versions are not reconstructed here.
12
12
 
13
+ ## [0.9.1] - 2026-11-23
14
+
15
+ ### Fixed
16
+
17
+ - Faster on long pages: the size test of a drop cap reads a column's smallest line once, instead of
18
+ scanning every line for each short run.
19
+ - Less memory: the plan of each page is kept only when a caller asks for it (`onPagePlan`).
20
+ - The search for figures set aside skips a page that holds no picture.
21
+ - No change to what a document reads as: the published output is the same as 0.9.0.
22
+
13
23
  ## [0.9.0] - 2026-11-20
14
24
 
15
25
  ### Changed
@@ -12791,7 +12791,12 @@ var segmentsInDeclaredOrder = (allSegments, rankOf) => {
12791
12791
  };
12792
12792
 
12793
12793
  // src/extractor/pdf-page-plan.ts
12794
- var isCapOfColumn = (cap, line, inks) => isDropCap(cap, line) && inks.some((ink) => ink !== void 0 && ink.size * MIN_DROP_CAP_RATIO <= cap.fontSize);
12794
+ var isCapOfColumn = (cap, line, smallestInk) => isDropCap(cap, line) && smallestInk * MIN_DROP_CAP_RATIO <= cap.fontSize;
12795
+ var smallestInkOf = (inks) => {
12796
+ let smallest = Number.POSITIVE_INFINITY;
12797
+ for (const ink of inks) if (ink !== void 0 && ink.size < smallest) smallest = ink.size;
12798
+ return smallest;
12799
+ };
12795
12800
  var capTarget = (cap, line, lineIndex, inks) => {
12796
12801
  const seated = line.some(
12797
12802
  (it) => it !== cap && it.text.trim() !== "" && it.fontSize * MIN_DROP_CAP_RATIO <= cap.fontSize
@@ -12802,9 +12807,10 @@ var capTarget = (cap, line, lineIndex, inks) => {
12802
12807
  };
12803
12808
  var capsOfColumn = (lines, inks) => {
12804
12809
  const found = [];
12810
+ const smallestInk = smallestInkOf(inks);
12805
12811
  for (const [lineIndex, line] of lines.entries()) {
12806
12812
  for (const cap of line) {
12807
- if (isCapOfColumn(cap, line, inks))
12813
+ if (isCapOfColumn(cap, line, smallestInk))
12808
12814
  found.push({ cap, from: lineIndex, to: capTarget(cap, line, lineIndex, inks) });
12809
12815
  }
12810
12816
  }
@@ -13122,6 +13128,7 @@ var figureOf = (anchor, lines, toBlocks) => {
13122
13128
  };
13123
13129
  };
13124
13130
  var asideFigures = (items, anchors, toBlocks) => {
13131
+ if (anchors.length === 0) return { figures: [], taken: /* @__PURE__ */ new Set() };
13125
13132
  const lines = visualLines(items);
13126
13133
  const taken = /* @__PURE__ */ new Set();
13127
13134
  const figures = [];
@@ -14673,7 +14680,7 @@ var pageLayoutReader = (doc, pageIndex, pageItems, lostImageCounts, pagePlans) =
14673
14680
  top: c.yTop
14674
14681
  }));
14675
14682
  const planner = pagePlanReader(cut);
14676
- pagePlans.set(pageIndex, planner.plan);
14683
+ pagePlans?.set(pageIndex, planner.plan);
14677
14684
  laid = {
14678
14685
  ...markers,
14679
14686
  wordWidthAt: firstWordWidthReader(glyphsByPage[pageIndex]),
@@ -14693,10 +14700,10 @@ var pageLayoutReader = (doc, pageIndex, pageItems, lostImageCounts, pagePlans) =
14693
14700
  };
14694
14701
  };
14695
14702
  var reportPagePlans = (plans, onPagePlan) => {
14696
- if (onPagePlan === void 0) return;
14703
+ if (onPagePlan === void 0 || plans === void 0) return;
14697
14704
  for (const [pageIndex, plan] of [...plans].sort((a, b) => a[0] - b[0])) onPagePlan(pageIndex, plan);
14698
14705
  };
14699
- var layoutPages = (doc) => {
14706
+ var layoutPages = (doc, keepPlans) => {
14700
14707
  const { items, glyphsByPage, sourceRun, detected, bandsByPage, scale, source, declaredRankByPage } = doc;
14701
14708
  const pages = [];
14702
14709
  const scannedPageIndices = [];
@@ -14705,7 +14712,7 @@ var layoutPages = (doc) => {
14705
14712
  const lostImageCounts = /* @__PURE__ */ new Map();
14706
14713
  const tableBandsByPage = /* @__PURE__ */ new Map();
14707
14714
  const flattenedGridPages = [];
14708
- const pagePlans = /* @__PURE__ */ new Map();
14715
+ const pagePlans = keepPlans ? /* @__PURE__ */ new Map() : void 0;
14709
14716
  for (const [pageIndex, rawItems] of items.entries()) {
14710
14717
  const pageItems = rawItems;
14711
14718
  const keptGlyphs = glyphsByPage[pageIndex];
@@ -14881,7 +14888,7 @@ var extractPdf = async (bytes, pageLanguage = "en", opts) => {
14881
14888
  framed: opts?.framed ?? DEFAULT_FRAMED_BLOCKS,
14882
14889
  bandLayout: opts?.bands ?? DEFAULT_BAND_LAYOUT
14883
14890
  };
14884
- const laid = layoutPages(doc);
14891
+ const laid = layoutPages(doc, opts?.onPagePlan !== void 0);
14885
14892
  reportPagePlans(laid.pagePlans, opts?.onPagePlan);
14886
14893
  return assembleResult(doc, laid, readItems, opts?.limits, pageLanguage);
14887
14894
  };