js.documents 14.6.6 → 14.6.8

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.
@@ -5,6 +5,7 @@ let pdf_codec_afm_widths = require("pdf-codec/afm-widths");
5
5
  //#region src/layout/reading-order.ts
6
6
  const MIN_COLUMN_LINES = 3;
7
7
  const MIN_PROSE_MEASURE_CHARS = 20;
8
+ const ROW_BASELINE_TOLERANCE_EM = 1 / 10;
8
9
  const SPACE_CHAR_CODE = 32;
9
10
  const AFM_UNITS_PER_EM = 1e3;
10
11
  /**
@@ -108,13 +109,28 @@ function findColumnSplit(lines) {
108
109
  if (run.hiPt - run.loPt <= Math.max(...runItems.map(spaceAdvancePt))) continue;
109
110
  const left = runItems.filter((item) => rightEdge(item) <= run.loPt);
110
111
  const right = runItems.filter((item) => item.xPt >= run.hiPt);
111
- if (isRunningProse(left, run.hiPt - run.loPt) && isRunningProse(right, run.hiPt - run.loPt)) return {
112
+ const gutterWidthPt = run.hiPt - run.loPt;
113
+ const leftIsProse = isRunningProse(left, gutterWidthPt);
114
+ const rightIsProse = isRunningProse(right, gutterWidthPt);
115
+ if (leftIsProse && rightIsProse || rightIsProse && isSidebarBeside(left, right) || leftIsProse && isSidebarBeside(right, left)) return {
112
116
  ...run,
113
117
  left,
114
118
  right
115
119
  };
116
120
  }
117
121
  }
122
+ function isSidebarBeside(side, prose) {
123
+ const sideLines = require_layout_reconstruct_lines.clusterIntoLines(side);
124
+ if (sideLines.length < MIN_COLUMN_LINES) return false;
125
+ const proseLines = require_layout_reconstruct_lines.clusterIntoLines(prose);
126
+ return sideLines.filter((line) => {
127
+ const anchor = line.items[0];
128
+ return !proseLines.some((proseLine) => setOnOneBaseline(anchor, proseLine.items[0]));
129
+ }).length * 2 > sideLines.length;
130
+ }
131
+ function setOnOneBaseline(a, b) {
132
+ return Math.abs(a.yPt - b.yPt) <= ROW_BASELINE_TOLERANCE_EM * Math.min(a.sizePt, b.sizePt);
133
+ }
118
134
  function isMeasurable(item) {
119
135
  return item.widthPt !== void 0 && item.writingMode === void 0 && (item.rotationDeg ?? 0) === 0;
120
136
  }
@@ -4,6 +4,7 @@ import { afmWidthOfCode } from "pdf-codec/afm-widths";
4
4
  //#region src/layout/reading-order.ts
5
5
  const MIN_COLUMN_LINES = 3;
6
6
  const MIN_PROSE_MEASURE_CHARS = 20;
7
+ const ROW_BASELINE_TOLERANCE_EM = 1 / 10;
7
8
  const SPACE_CHAR_CODE = 32;
8
9
  const AFM_UNITS_PER_EM = 1e3;
9
10
  /**
@@ -107,13 +108,28 @@ function findColumnSplit(lines) {
107
108
  if (run.hiPt - run.loPt <= Math.max(...runItems.map(spaceAdvancePt))) continue;
108
109
  const left = runItems.filter((item) => rightEdge(item) <= run.loPt);
109
110
  const right = runItems.filter((item) => item.xPt >= run.hiPt);
110
- if (isRunningProse(left, run.hiPt - run.loPt) && isRunningProse(right, run.hiPt - run.loPt)) return {
111
+ const gutterWidthPt = run.hiPt - run.loPt;
112
+ const leftIsProse = isRunningProse(left, gutterWidthPt);
113
+ const rightIsProse = isRunningProse(right, gutterWidthPt);
114
+ if (leftIsProse && rightIsProse || rightIsProse && isSidebarBeside(left, right) || leftIsProse && isSidebarBeside(right, left)) return {
111
115
  ...run,
112
116
  left,
113
117
  right
114
118
  };
115
119
  }
116
120
  }
121
+ function isSidebarBeside(side, prose) {
122
+ const sideLines = clusterIntoLines(side);
123
+ if (sideLines.length < MIN_COLUMN_LINES) return false;
124
+ const proseLines = clusterIntoLines(prose);
125
+ return sideLines.filter((line) => {
126
+ const anchor = line.items[0];
127
+ return !proseLines.some((proseLine) => setOnOneBaseline(anchor, proseLine.items[0]));
128
+ }).length * 2 > sideLines.length;
129
+ }
130
+ function setOnOneBaseline(a, b) {
131
+ return Math.abs(a.yPt - b.yPt) <= ROW_BASELINE_TOLERANCE_EM * Math.min(a.sizePt, b.sizePt);
132
+ }
117
133
  function isMeasurable(item) {
118
134
  return item.widthPt !== void 0 && item.writingMode === void 0 && (item.rotationDeg ?? 0) === 0;
119
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "js.documents",
3
- "version": "14.6.6",
3
+ "version": "14.6.8",
4
4
  "description": "Converts between docx, pptx, odt, odp, ods, odg, xlsx, csv, svg, markdown, rtf, doc, xls, ppt and PDF through one shared, Zod-typed content schema (wpd read-only), plus read+write editors for OOXML and OpenDocument. Worker-isomorphic.",
5
5
  "type": "module",
6
6
  "repository": {
@@ -86,7 +86,7 @@
86
86
  "markdown-codec": "11.2.1",
87
87
  "odf.js": "11.2.3",
88
88
  "ooxml.js": "12.2.33",
89
- "pdf-codec": "5.7.0",
89
+ "pdf-codec": "5.7.2",
90
90
  "ppt-codec": "2.2.24",
91
91
  "rtf-codec": "8.1.25",
92
92
  "temml": "0.13.4",