kordoc 3.10.1 → 3.12.0
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/README.md +12 -0
- package/dist/{-LPEXY73L.js → -OPZIF3QT.js} +5 -5
- package/dist/{chunk-7UXZTZBJ.cjs → chunk-2C5GCXPJ.cjs} +2 -2
- package/dist/{chunk-7UXZTZBJ.cjs.map → chunk-2C5GCXPJ.cjs.map} +1 -1
- package/dist/{chunk-GFS4QWB6.js → chunk-7Z43WEML.js} +2 -2
- package/dist/{chunk-YXEE3DEQ.js → chunk-BUDM6ULT.js} +2 -2
- package/dist/{chunk-UR34PYAC.js → chunk-ILR7GF3W.js} +2 -2
- package/dist/{chunk-I6CX2RK4.js → chunk-NGKIAZ6G.js} +2 -2
- package/dist/{chunk-RMGYE4LT.js → chunk-RUYSNNYZ.js} +5 -5
- package/dist/cli.js +7 -7
- package/dist/index.cjs +118 -118
- package/dist/index.js +2 -2
- package/dist/mcp.js +5 -5
- package/dist/{parser-LJOS7VZM.js → parser-5FSEFR3R.js} +118 -3
- package/dist/parser-5FSEFR3R.js.map +1 -0
- package/dist/{parser-664URIIW.js → parser-AWEGMHHV.js} +117 -2
- package/dist/parser-AWEGMHHV.js.map +1 -0
- package/dist/{parser-AT22HMF5.cjs → parser-PCTX7LGN.cjs} +129 -14
- package/dist/parser-PCTX7LGN.cjs.map +1 -0
- package/dist/render-ATQNKOT2.js +9 -0
- package/dist/{watch-CZF6NA2V.js → watch-Y7BAYXJE.js} +5 -5
- package/package.json +1 -1
- package/dist/parser-664URIIW.js.map +0 -1
- package/dist/parser-AT22HMF5.cjs.map +0 -1
- package/dist/parser-LJOS7VZM.js.map +0 -1
- package/dist/render-XWOEGE3U.js +0 -9
- /package/dist/{-LPEXY73L.js.map → -OPZIF3QT.js.map} +0 -0
- /package/dist/{chunk-GFS4QWB6.js.map → chunk-7Z43WEML.js.map} +0 -0
- /package/dist/{chunk-YXEE3DEQ.js.map → chunk-BUDM6ULT.js.map} +0 -0
- /package/dist/{chunk-UR34PYAC.js.map → chunk-ILR7GF3W.js.map} +0 -0
- /package/dist/{chunk-I6CX2RK4.js.map → chunk-NGKIAZ6G.js.map} +0 -0
- /package/dist/{chunk-RMGYE4LT.js.map → chunk-RUYSNNYZ.js.map} +0 -0
- /package/dist/{render-XWOEGE3U.js.map → render-ATQNKOT2.js.map} +0 -0
- /package/dist/{watch-CZF6NA2V.js.map → watch-Y7BAYXJE.js.map} +0 -0
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
blocksToMarkdown,
|
|
7
7
|
safeMax,
|
|
8
8
|
safeMin
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-NGKIAZ6G.js";
|
|
10
10
|
import {
|
|
11
11
|
parsePageRange
|
|
12
12
|
} from "./chunk-GE43BE46.js";
|
|
@@ -198,10 +198,120 @@ function classifyAndAdd(seg, lineWidth, horizontals, verticals) {
|
|
|
198
198
|
function preprocessLines(horizontals, verticals) {
|
|
199
199
|
let h = horizontals.filter((l) => l.lineWidth <= MAX_LINE_WIDTH);
|
|
200
200
|
let v = verticals.filter((l) => l.lineWidth <= MAX_LINE_WIDTH);
|
|
201
|
+
h = dropShadingStacks(h, "h");
|
|
202
|
+
v = dropShadingStacks(v, "v");
|
|
201
203
|
h = mergeParallelLines(h, "h");
|
|
202
204
|
v = mergeParallelLines(v, "v");
|
|
203
205
|
return { horizontals: h, verticals: v };
|
|
204
206
|
}
|
|
207
|
+
var STACK_GAP = 2;
|
|
208
|
+
var STACK_MIN_LINES = 6;
|
|
209
|
+
function dropShadingStacks(lines, dir) {
|
|
210
|
+
if (lines.length < STACK_MIN_LINES) return lines;
|
|
211
|
+
const groups = /* @__PURE__ */ new Map();
|
|
212
|
+
for (const l of lines) {
|
|
213
|
+
const key = dir === "h" ? `${Math.round(l.x1)}:${Math.round(l.x2)}` : `${Math.round(l.y1)}:${Math.round(l.y2)}`;
|
|
214
|
+
const arr = groups.get(key);
|
|
215
|
+
if (arr) arr.push(l);
|
|
216
|
+
else groups.set(key, [l]);
|
|
217
|
+
}
|
|
218
|
+
const dropped = /* @__PURE__ */ new Set();
|
|
219
|
+
for (const group of groups.values()) {
|
|
220
|
+
if (group.length < STACK_MIN_LINES) continue;
|
|
221
|
+
group.sort((a, b) => dir === "h" ? a.y1 - b.y1 : a.x1 - b.x1);
|
|
222
|
+
let runStart = 0;
|
|
223
|
+
for (let i = 1; i <= group.length; i++) {
|
|
224
|
+
const gap = i < group.length ? dir === "h" ? group[i].y1 - group[i - 1].y1 : group[i].x1 - group[i - 1].x1 : Infinity;
|
|
225
|
+
if (gap < STACK_GAP) continue;
|
|
226
|
+
if (i - runStart >= STACK_MIN_LINES) {
|
|
227
|
+
for (let j = runStart; j < i; j++) dropped.add(group[j]);
|
|
228
|
+
}
|
|
229
|
+
runStart = i;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return dropped.size ? lines.filter((l) => !dropped.has(l)) : lines;
|
|
233
|
+
}
|
|
234
|
+
var EDGE_ALIGN_TOL = 3;
|
|
235
|
+
var EDGE_MIN_RULES = 3;
|
|
236
|
+
var EDGE_MIN_SPAN = 12;
|
|
237
|
+
var EDGE_INSET = 15;
|
|
238
|
+
var EDGE_NEAR = 10;
|
|
239
|
+
var EDGE_CONNECT_TOL = 5;
|
|
240
|
+
var CHAIN_Y_TOL = 1.5;
|
|
241
|
+
var CHAIN_GAP = 3;
|
|
242
|
+
function chainCollinearRules(horizontals) {
|
|
243
|
+
if (horizontals.length <= 1) return horizontals;
|
|
244
|
+
const sorted = [...horizontals].sort((a, b) => a.y1 - b.y1 || a.x1 - b.x1);
|
|
245
|
+
const rules = [];
|
|
246
|
+
let bandStart = 0;
|
|
247
|
+
const flushBand = (end) => {
|
|
248
|
+
const band = sorted.slice(bandStart, end).sort((a, b) => a.x1 - b.x1);
|
|
249
|
+
let cur = { ...band[0] };
|
|
250
|
+
for (let i = 1; i < band.length; i++) {
|
|
251
|
+
const seg = band[i];
|
|
252
|
+
if (seg.x1 - cur.x2 <= CHAIN_GAP) {
|
|
253
|
+
if (seg.x2 > cur.x2) cur.x2 = seg.x2;
|
|
254
|
+
if (seg.lineWidth > cur.lineWidth) cur.lineWidth = seg.lineWidth;
|
|
255
|
+
} else {
|
|
256
|
+
rules.push(cur);
|
|
257
|
+
cur = { ...seg };
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
rules.push(cur);
|
|
261
|
+
};
|
|
262
|
+
for (let i = 1; i <= sorted.length; i++) {
|
|
263
|
+
if (i === sorted.length || sorted[i].y1 - sorted[bandStart].y1 > CHAIN_Y_TOL) {
|
|
264
|
+
flushBand(i);
|
|
265
|
+
bandStart = i;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
return rules;
|
|
269
|
+
}
|
|
270
|
+
function closeOpenTableEdges(horizontals, verticals) {
|
|
271
|
+
if (horizontals.length < EDGE_MIN_RULES) return verticals;
|
|
272
|
+
const groups = [];
|
|
273
|
+
for (const hl of chainCollinearRules(horizontals)) {
|
|
274
|
+
let placed = false;
|
|
275
|
+
for (const g2 of groups) {
|
|
276
|
+
if (Math.abs(g2[0].x1 - hl.x1) <= EDGE_ALIGN_TOL && Math.abs(g2[0].x2 - hl.x2) <= EDGE_ALIGN_TOL) {
|
|
277
|
+
g2.push(hl);
|
|
278
|
+
placed = true;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
if (!placed) groups.push([hl]);
|
|
283
|
+
}
|
|
284
|
+
const synthesized = [];
|
|
285
|
+
for (const g2 of groups) {
|
|
286
|
+
if (g2.length < EDGE_MIN_RULES) continue;
|
|
287
|
+
let yMin = Infinity, yMax = -Infinity, x1 = 0, x2 = 0;
|
|
288
|
+
for (const hl of g2) {
|
|
289
|
+
if (hl.y1 < yMin) yMin = hl.y1;
|
|
290
|
+
if (hl.y1 > yMax) yMax = hl.y1;
|
|
291
|
+
x1 += hl.x1;
|
|
292
|
+
x2 += hl.x2;
|
|
293
|
+
}
|
|
294
|
+
x1 /= g2.length;
|
|
295
|
+
x2 /= g2.length;
|
|
296
|
+
if (yMax - yMin < EDGE_MIN_SPAN) continue;
|
|
297
|
+
const crossCount = (v) => {
|
|
298
|
+
let n = 0;
|
|
299
|
+
for (const hl of g2) {
|
|
300
|
+
if (v.x1 >= hl.x1 - EDGE_CONNECT_TOL && v.x1 <= hl.x2 + EDGE_CONNECT_TOL && hl.y1 >= v.y1 - EDGE_CONNECT_TOL && hl.y1 <= v.y2 + EDGE_CONNECT_TOL) n++;
|
|
301
|
+
}
|
|
302
|
+
return n;
|
|
303
|
+
};
|
|
304
|
+
const hasInterior = verticals.some((v) => v.x1 > x1 + EDGE_INSET && v.x1 < x2 - EDGE_INSET && crossCount(v) >= 2);
|
|
305
|
+
if (!hasInterior) continue;
|
|
306
|
+
for (const edgeX of [x1, x2]) {
|
|
307
|
+
const closed = verticals.some((v) => Math.abs(v.x1 - edgeX) <= EDGE_NEAR && v.y1 <= yMax + EDGE_CONNECT_TOL && v.y2 >= yMin - EDGE_CONNECT_TOL);
|
|
308
|
+
if (!closed) {
|
|
309
|
+
synthesized.push({ x1: edgeX, y1: yMin, x2: edgeX, y2: yMax, lineWidth: 0.5 });
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return synthesized.length ? [...verticals, ...synthesized] : verticals;
|
|
314
|
+
}
|
|
205
315
|
function mergeParallelLines(lines, dir) {
|
|
206
316
|
if (lines.length <= 1) return lines;
|
|
207
317
|
const sorted = [...lines].sort((a, b) => {
|
|
@@ -2215,6 +2325,10 @@ function detectHeadings(blocks, medianFontSize) {
|
|
|
2215
2325
|
function shouldDemoteTable(table) {
|
|
2216
2326
|
const allCells = table.cells.flatMap((row) => row.map((c) => c.text.trim())).filter(Boolean);
|
|
2217
2327
|
const allText = allCells.join(" ");
|
|
2328
|
+
if (table.rows >= 2 && table.cols >= 2 && table.cells[0].every((c) => {
|
|
2329
|
+
const t = c.text.trim();
|
|
2330
|
+
return t.length > 0 && t.length <= 12 && !/[□■◆○●▶ㅇ<>]/.test(t);
|
|
2331
|
+
}) && table.cells.slice(1).some((row) => row.some((c) => c.text.trim() !== ""))) return false;
|
|
2218
2332
|
if (table.rows <= 3 && table.cols <= 3) {
|
|
2219
2333
|
const totalCells2 = table.rows * table.cols;
|
|
2220
2334
|
const emptyCells2 = totalCells2 - allCells.length;
|
|
@@ -2552,6 +2666,7 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
2552
2666
|
let { horizontals, verticals } = extractLines(opList.fnArray, opList.argsArray);
|
|
2553
2667
|
({ horizontals, verticals } = filterPageBorderLines(horizontals, verticals, pageWidth, pageHeight));
|
|
2554
2668
|
({ horizontals, verticals } = preprocessLines(horizontals, verticals));
|
|
2669
|
+
verticals = closeOpenTableEdges(horizontals, verticals);
|
|
2555
2670
|
markStrikethroughItems(items, horizontals);
|
|
2556
2671
|
wrapStrikethroughRuns(items);
|
|
2557
2672
|
const grids = buildTableGrids(horizontals, verticals);
|
|
@@ -3356,4 +3471,4 @@ export {
|
|
|
3356
3471
|
parsePdfDocument,
|
|
3357
3472
|
removeHeaderFooterBlocks
|
|
3358
3473
|
};
|
|
3359
|
-
//# sourceMappingURL=parser-
|
|
3474
|
+
//# sourceMappingURL=parser-AWEGMHHV.js.map
|