formatferry 1.0.14 → 1.0.15

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.
Files changed (2) hide show
  1. package/dist/index.js +46 -26
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -22397,7 +22397,8 @@ function renderTextBlockEnhanced(items, medianPageFontSize, outlineTitles) {
22397
22397
  htmlBlocks.push(`<h${headingLevel}>${inlineHtml}</h${headingLevel}>`);
22398
22398
  } else {
22399
22399
  const hasWideGap = /( {3,}|\u00A0\u00A0|\t)/.test(normalizedPlain);
22400
- const isShort = normalizedPlain.length < 100 && !/[.,:;!?]$/.test(normalizedPlain) && !/\n/.test(normalizedPlain) && !hasWideGap;
22400
+ const looksLikeSentence = normalizedPlain.length > 40 && /^[A-Z]/.test(normalizedPlain);
22401
+ const isShort = normalizedPlain.length < 80 && !/[.,:;!?]$/.test(normalizedPlain) && !/\n/.test(normalizedPlain) && !hasWideGap && !looksLikeSentence;
22401
22402
  if (isShort && !hasAnyStyle) {
22402
22403
  htmlBlocks.push(`<p><strong>${inlineHtml}</strong></p>`);
22403
22404
  } else {
@@ -22528,7 +22529,15 @@ function isHeaderFooterItem(it, suppressSet, Y_TOLERANCE = 5) {
22528
22529
  const yBucket = Math.round(it.y / Y_TOLERANCE) * Y_TOLERANCE;
22529
22530
  return suppressSet.has(`${normalized}@${yBucket}`);
22530
22531
  }
22531
- var PDF_OP = { moveTo: 13, lineTo: 14, closePath: 18, rectangle: 92 };
22532
+ var PDF_OP = {
22533
+ moveTo: 13,
22534
+ lineTo: 14,
22535
+ closePath: 18,
22536
+ rectangle: 92,
22537
+ stroke: 19,
22538
+ closeStroke: 20,
22539
+ fillStroke: 37
22540
+ };
22532
22541
  function extractVectorLines(fnArray, argsArray, pageWidth, pageHeight) {
22533
22542
  const MIN_H_SPAN = pageWidth * 0.3;
22534
22543
  const MIN_V_SPAN = pageHeight * 0.3;
@@ -22537,22 +22546,28 @@ function extractVectorLines(fnArray, argsArray, pageWidth, pageHeight) {
22537
22546
  let curY = 0;
22538
22547
  let pathStartX = 0;
22539
22548
  let pathStartY = 0;
22540
- const pushIfSignificant = (x0, y0, x1, y1) => {
22541
- const dx = Math.abs(x1 - x0);
22542
- const dy = Math.abs(y1 - y0);
22543
- if (dy < 2 && dx >= MIN_H_SPAN) {
22544
- lines.push({
22545
- orientation: "h",
22546
- position: (y0 + y1) / 2,
22547
- span: [Math.min(x0, x1), Math.max(x0, x1)]
22548
- });
22549
- } else if (dx < 2 && dy >= MIN_V_SPAN) {
22550
- lines.push({
22551
- orientation: "v",
22552
- position: (x0 + x1) / 2,
22553
- span: [Math.min(y0, y1), Math.max(y0, y1)]
22554
- });
22549
+ let pending = [];
22550
+ const isPathOp = (op) => op === PDF_OP.moveTo || op === PDF_OP.lineTo || op === PDF_OP.closePath || op === PDF_OP.rectangle;
22551
+ const isStrokeOp = (op) => op === PDF_OP.stroke || op === PDF_OP.closeStroke || op === PDF_OP.fillStroke;
22552
+ const flushPending = () => {
22553
+ for (const p of pending) {
22554
+ const dx = Math.abs(p.x1 - p.x0);
22555
+ const dy = Math.abs(p.y1 - p.y0);
22556
+ if (dy < 2 && dx >= MIN_H_SPAN) {
22557
+ lines.push({
22558
+ orientation: "h",
22559
+ position: (p.y0 + p.y1) / 2,
22560
+ span: [Math.min(p.x0, p.x1), Math.max(p.x0, p.x1)]
22561
+ });
22562
+ } else if (dx < 2 && dy >= MIN_V_SPAN) {
22563
+ lines.push({
22564
+ orientation: "v",
22565
+ position: (p.x0 + p.x1) / 2,
22566
+ span: [Math.min(p.y0, p.y1), Math.max(p.y0, p.y1)]
22567
+ });
22568
+ }
22555
22569
  }
22570
+ pending = [];
22556
22571
  };
22557
22572
  for (let i = 0; i < fnArray.length; i++) {
22558
22573
  const op = fnArray[i];
@@ -22565,7 +22580,7 @@ function extractVectorLines(fnArray, argsArray, pageWidth, pageHeight) {
22565
22580
  } else if (op === PDF_OP.lineTo) {
22566
22581
  const nx = args[0] ?? 0;
22567
22582
  const ny = args[1] ?? 0;
22568
- pushIfSignificant(curX, curY, nx, ny);
22583
+ pending.push({ x0: curX, y0: curY, x1: nx, y1: ny });
22569
22584
  curX = nx;
22570
22585
  curY = ny;
22571
22586
  } else if (op === PDF_OP.rectangle) {
@@ -22573,14 +22588,18 @@ function extractVectorLines(fnArray, argsArray, pageWidth, pageHeight) {
22573
22588
  const ry = args[1] ?? 0;
22574
22589
  const rw = args[2] ?? 0;
22575
22590
  const rh = args[3] ?? 0;
22576
- pushIfSignificant(rx, ry, rx + rw, ry);
22577
- pushIfSignificant(rx, ry + rh, rx + rw, ry + rh);
22578
- pushIfSignificant(rx, ry, rx, ry + rh);
22579
- pushIfSignificant(rx + rw, ry, rx + rw, ry + rh);
22591
+ pending.push({ x0: rx, y0: ry, x1: rx + rw, y1: ry });
22592
+ pending.push({ x0: rx, y0: ry + rh, x1: rx + rw, y1: ry + rh });
22593
+ pending.push({ x0: rx, y0: ry, x1: rx, y1: ry + rh });
22594
+ pending.push({ x0: rx + rw, y0: ry, x1: rx + rw, y1: ry + rh });
22580
22595
  } else if (op === PDF_OP.closePath) {
22581
- pushIfSignificant(curX, curY, pathStartX, pathStartY);
22596
+ pending.push({ x0: curX, y0: curY, x1: pathStartX, y1: pathStartY });
22582
22597
  curX = pathStartX;
22583
22598
  curY = pathStartY;
22599
+ } else if (isStrokeOp(op)) {
22600
+ flushPending();
22601
+ } else if (!isPathOp(op)) {
22602
+ pending = [];
22584
22603
  }
22585
22604
  }
22586
22605
  return lines;
@@ -22703,7 +22722,8 @@ function renderPage(items, pageNum, nextPageNum, enableTableDetection, translate
22703
22722
  const hasWideGap = /( {3,}|\u00A0\u00A0|\t)/.test(trimmed);
22704
22723
  const isFirstPara = paraIdx === 1;
22705
22724
  const looksTabular = hasWideGap || isFirstPara && topRowLooksTabular;
22706
- const short = trimmed.length < 100 && !/[.,:;!?]$/.test(trimmed) && !/\n/.test(trimmed) && !looksTabular;
22725
+ const looksLikeSentence = trimmed.length > 40 && /^[A-Z]/.test(trimmed);
22726
+ const short = trimmed.length < 80 && !/[.,:;!?]$/.test(trimmed) && !/\n/.test(trimmed) && !looksTabular && !looksLikeSentence;
22707
22727
  if (short) {
22708
22728
  htmlBlocks.push(`<p><strong>${escapeHtml(trimmed)}</strong></p>`);
22709
22729
  } else {
@@ -25294,8 +25314,8 @@ import { readFileSync as readFileSync4 } from "fs";
25294
25314
  import { resolve, dirname as dirname3 } from "path";
25295
25315
  import { fileURLToPath } from "url";
25296
25316
  var getVersion = () => {
25297
- if ("1.0.14") {
25298
- return "1.0.14";
25317
+ if ("1.0.15") {
25318
+ return "1.0.15";
25299
25319
  }
25300
25320
  try {
25301
25321
  const __dirname = dirname3(fileURLToPath(import.meta.url));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "formatferry",
3
- "version": "1.0.14",
3
+ "version": "1.0.15",
4
4
  "description": "FormatFerry CLI — Convert HTML, DOCX, PDF, XLSX, CSV, JSON, XML, PPTX to Markdown",
5
5
  "keywords": [
6
6
  "markdown",