kordoc 4.25.22 → 4.25.23
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 +2 -2
- package/dist/{chunk-IKU7LVKA.js → chunk-2PQMHHX4.js} +2 -2
- package/dist/{chunk-LY235W6K.js → chunk-377GAL46.js} +2 -2
- package/dist/{chunk-U4IIEEPU.js → chunk-3IVEGZI3.js} +2 -2
- package/dist/{chunk-GG2M23FC.js → chunk-7LW2HG7F.js} +3 -3
- package/dist/{chunk-JY2OBKK2.js → chunk-7S4KRBXC.js} +2 -2
- package/dist/{chunk-SBXUMTMQ.js → chunk-B3LK5RVY.js} +83 -4
- package/dist/chunk-B3LK5RVY.js.map +7 -0
- package/dist/{chunk-M4V6DG5V.js → chunk-BXHO5BB5.js} +8 -8
- package/dist/{chunk-F64JL4SC.js → chunk-GMYXTUSJ.js} +2 -2
- package/dist/{chunk-D57I7HNQ.js → chunk-GZX5UQ4P.js} +2 -2
- package/dist/{chunk-2BC6IRWI.js → chunk-IRR32NHL.js} +2 -2
- package/dist/{chunk-SZHSPADM.js → chunk-J4OTJFSW.js} +2 -2
- package/dist/{chunk-VE4T5RNY.js → chunk-K5ZUKPU3.js} +2 -2
- package/dist/{chunk-MNHHSFDQ.js → chunk-LTXF66N6.js} +6 -6
- package/dist/{chunk-XJWOBLDL.js → chunk-MMJIFTWZ.js} +10 -10
- package/dist/{chunk-GEQU7GFI.js → chunk-MPEWMDM2.js} +18 -18
- package/dist/{chunk-IWPT63UP.js → chunk-NFMC6FLB.js} +6 -6
- package/dist/{chunk-2T27SM3Q.js → chunk-PGBRNQAF.js} +2 -2
- package/dist/{chunk-OQX5GAZU.js → chunk-PQIIJRV2.js} +2 -2
- package/dist/{chunk-FU2VJEA7.js → chunk-QAQDSBAC.js} +6 -6
- package/dist/{chunk-RPMBH66S.js → chunk-QI7LT4AX.js} +5 -5
- package/dist/{chunk-5B2IKEEY.js → chunk-SE5HAJNL.js} +4 -4
- package/dist/{chunk-VTFMNEQA.js → chunk-SKZ2LLN5.js} +237 -4
- package/dist/chunk-SKZ2LLN5.js.map +1 -0
- package/dist/{chunk-3ABE7X6L.js → chunk-TYANRH6O.js} +3 -3
- package/dist/{chunk-X4LW6P67.js → chunk-WLHQL53U.js} +2 -2
- package/dist/{chunk-LNJUYPFX.js → chunk-YDOIXWSF.js} +2 -2
- package/dist/{chunk-PTYOQBAD.js → chunk-YWRAHQTV.js} +2 -2
- package/dist/chunks-A2NELZR2.js +10 -0
- package/dist/cli.js +37 -37
- package/dist/{formula-62KCIJTD.js → formula-LUPB363D.js} +4 -4
- package/dist/{generator-OGG7G6RV.js → generator-MK3VLXV2.js} +7 -7
- package/dist/{hancom-SGF24IFE.js → hancom-24SHJFWF.js} +2 -2
- package/dist/{image-ocr-ZGRESXDU.js → image-ocr-CSV7OLPX.js} +11 -11
- package/dist/index.cjs +313 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +21 -21
- package/dist/mcp.js +33 -33
- package/dist/memo-5G32P322.js +15 -0
- package/dist/{model-bundle-ZB3IUIDI.js → model-bundle-U6ONSDTJ.js} +5 -5
- package/dist/{models-JW4G7TAS.js → models-X4FVLSSQ.js} +5 -5
- package/dist/{page-images-MW7EJGDY.js → page-images-E67SJN3S.js} +2 -2
- package/dist/{parse-worker-v2-24QWDLDW.js → parse-worker-v2-3VY5X7SF.js} +23 -23
- package/dist/{parser-X74GRUEK.js → parser-6GFE6B42.js} +14 -14
- package/dist/{pdf-ocr-5N4CHVYH.js → pdf-ocr-MKQURNXT.js} +9 -9
- package/dist/{profile-io-EDOARKYW.js → profile-io-DAZZHP7S.js} +3 -3
- package/dist/{rasterize-YHFV2XB4.js → rasterize-BJTBPSDM.js} +3 -3
- package/dist/{redact-doc-YAQFZNBP.js → redact-doc-W6H7SXGB.js} +22 -22
- package/dist/{render-YKPIJ5XF.js → render-HJDMKGMV.js} +10 -10
- package/dist/{rewrite-fallback-W4SQTEKX.js → rewrite-fallback-VKA6BLLT.js} +12 -12
- package/dist/seal-5KR6SUIU.js +14 -0
- package/dist/{setup-GVWJ2UM5.js → setup-UGWQLJ5Z.js} +3 -3
- package/dist/{to-hwpx-LC7SM2NG.js → to-hwpx-WI5CGWDZ.js} +7 -7
- package/dist/visual-YDMDCB7Q.js +42 -0
- package/dist/{watch-EHCJUHRO.js → watch-CIO5522I.js} +22 -22
- package/package.json +1 -1
- package/dist/chunk-SBXUMTMQ.js.map +0 -7
- package/dist/chunk-VTFMNEQA.js.map +0 -1
- package/dist/chunks-S5RQ5IVJ.js +0 -10
- package/dist/memo-C6TAWLJY.js +0 -15
- package/dist/seal-IZ77VWF2.js +0 -14
- package/dist/visual-FRQN5F77.js +0 -42
- /package/dist/{chunk-IKU7LVKA.js.map → chunk-2PQMHHX4.js.map} +0 -0
- /package/dist/{chunk-LY235W6K.js.map → chunk-377GAL46.js.map} +0 -0
- /package/dist/{chunk-U4IIEEPU.js.map → chunk-3IVEGZI3.js.map} +0 -0
- /package/dist/{chunk-GG2M23FC.js.map → chunk-7LW2HG7F.js.map} +0 -0
- /package/dist/{chunk-JY2OBKK2.js.map → chunk-7S4KRBXC.js.map} +0 -0
- /package/dist/{chunk-M4V6DG5V.js.map → chunk-BXHO5BB5.js.map} +0 -0
- /package/dist/{chunk-F64JL4SC.js.map → chunk-GMYXTUSJ.js.map} +0 -0
- /package/dist/{chunk-D57I7HNQ.js.map → chunk-GZX5UQ4P.js.map} +0 -0
- /package/dist/{chunk-2BC6IRWI.js.map → chunk-IRR32NHL.js.map} +0 -0
- /package/dist/{chunk-SZHSPADM.js.map → chunk-J4OTJFSW.js.map} +0 -0
- /package/dist/{chunk-VE4T5RNY.js.map → chunk-K5ZUKPU3.js.map} +0 -0
- /package/dist/{chunk-MNHHSFDQ.js.map → chunk-LTXF66N6.js.map} +0 -0
- /package/dist/{chunk-XJWOBLDL.js.map → chunk-MMJIFTWZ.js.map} +0 -0
- /package/dist/{chunk-GEQU7GFI.js.map → chunk-MPEWMDM2.js.map} +0 -0
- /package/dist/{chunk-IWPT63UP.js.map → chunk-NFMC6FLB.js.map} +0 -0
- /package/dist/{chunk-2T27SM3Q.js.map → chunk-PGBRNQAF.js.map} +0 -0
- /package/dist/{chunk-OQX5GAZU.js.map → chunk-PQIIJRV2.js.map} +0 -0
- /package/dist/{chunk-FU2VJEA7.js.map → chunk-QAQDSBAC.js.map} +0 -0
- /package/dist/{chunk-RPMBH66S.js.map → chunk-QI7LT4AX.js.map} +0 -0
- /package/dist/{chunk-5B2IKEEY.js.map → chunk-SE5HAJNL.js.map} +0 -0
- /package/dist/{chunk-3ABE7X6L.js.map → chunk-TYANRH6O.js.map} +0 -0
- /package/dist/{chunk-X4LW6P67.js.map → chunk-WLHQL53U.js.map} +0 -0
- /package/dist/{chunk-LNJUYPFX.js.map → chunk-YDOIXWSF.js.map} +0 -0
- /package/dist/{chunk-PTYOQBAD.js.map → chunk-YWRAHQTV.js.map} +0 -0
- /package/dist/{chunks-S5RQ5IVJ.js.map → chunks-A2NELZR2.js.map} +0 -0
- /package/dist/{formula-62KCIJTD.js.map → formula-LUPB363D.js.map} +0 -0
- /package/dist/{generator-OGG7G6RV.js.map → generator-MK3VLXV2.js.map} +0 -0
- /package/dist/{hancom-SGF24IFE.js.map → hancom-24SHJFWF.js.map} +0 -0
- /package/dist/{image-ocr-ZGRESXDU.js.map → image-ocr-CSV7OLPX.js.map} +0 -0
- /package/dist/{memo-C6TAWLJY.js.map → memo-5G32P322.js.map} +0 -0
- /package/dist/{model-bundle-ZB3IUIDI.js.map → model-bundle-U6ONSDTJ.js.map} +0 -0
- /package/dist/{models-JW4G7TAS.js.map → models-X4FVLSSQ.js.map} +0 -0
- /package/dist/{page-images-MW7EJGDY.js.map → page-images-E67SJN3S.js.map} +0 -0
- /package/dist/{parse-worker-v2-24QWDLDW.js.map → parse-worker-v2-3VY5X7SF.js.map} +0 -0
- /package/dist/{parser-X74GRUEK.js.map → parser-6GFE6B42.js.map} +0 -0
- /package/dist/{pdf-ocr-5N4CHVYH.js.map → pdf-ocr-MKQURNXT.js.map} +0 -0
- /package/dist/{profile-io-EDOARKYW.js.map → profile-io-DAZZHP7S.js.map} +0 -0
- /package/dist/{rasterize-YHFV2XB4.js.map → rasterize-BJTBPSDM.js.map} +0 -0
- /package/dist/{redact-doc-YAQFZNBP.js.map → redact-doc-W6H7SXGB.js.map} +0 -0
- /package/dist/{render-YKPIJ5XF.js.map → render-HJDMKGMV.js.map} +0 -0
- /package/dist/{rewrite-fallback-W4SQTEKX.js.map → rewrite-fallback-VKA6BLLT.js.map} +0 -0
- /package/dist/{seal-IZ77VWF2.js.map → seal-5KR6SUIU.js.map} +0 -0
- /package/dist/{setup-GVWJ2UM5.js.map → setup-UGWQLJ5Z.js.map} +0 -0
- /package/dist/{to-hwpx-LC7SM2NG.js.map → to-hwpx-WI5CGWDZ.js.map} +0 -0
- /package/dist/{visual-FRQN5F77.js.map → visual-YDMDCB7Q.js.map} +0 -0
- /package/dist/{watch-EHCJUHRO.js.map → watch-CIO5522I.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -381,7 +381,7 @@ var VERSION, KordocError, MAX_UNZIP_ENV_MB, SAFE_HREF_RE, HREF_ESCAPE, BARE_URL,
|
|
|
381
381
|
var init_utils = __esm({
|
|
382
382
|
"src/utils.ts"() {
|
|
383
383
|
"use strict";
|
|
384
|
-
VERSION = true ? "4.25.
|
|
384
|
+
VERSION = true ? "4.25.23" : "0.0.0-dev";
|
|
385
385
|
KordocError = class extends Error {
|
|
386
386
|
constructor(message) {
|
|
387
387
|
super(message);
|
|
@@ -31140,6 +31140,220 @@ function stackedGlyphBands(gray, w, h, ink) {
|
|
|
31140
31140
|
const bands = splitRowBands(gray, w, h, ink, 0.45);
|
|
31141
31141
|
return bands.length >= 2 && bands.length <= 4 ? bands : null;
|
|
31142
31142
|
}
|
|
31143
|
+
function checkboxFrames(gray, w, h, ink) {
|
|
31144
|
+
if (!ink.darkInk || h < 12 || w < h) return [];
|
|
31145
|
+
const sorted = Uint8Array.from(gray).sort(), bg = sorted[sorted.length >> 1];
|
|
31146
|
+
let n = 0, sum = 0;
|
|
31147
|
+
for (let i = 0; i < gray.length; i++) if (gray[i] <= ink.threshold) {
|
|
31148
|
+
n++;
|
|
31149
|
+
sum += gray[i];
|
|
31150
|
+
}
|
|
31151
|
+
const dk = n ? sum / n : bg;
|
|
31152
|
+
if (bg - dk < 40) return [];
|
|
31153
|
+
const k = Math.max(2, Math.round(h * 0.05)), delta = Math.max(10, (bg - dk) * 0.12), mark = bg - (bg - dk) * 0.5;
|
|
31154
|
+
const at = (x, y) => gray[Math.min(h - 1, Math.max(0, y)) * w + Math.min(w - 1, Math.max(0, x))];
|
|
31155
|
+
const V = new Uint8Array(w * h), H = new Uint8Array(w * h);
|
|
31156
|
+
for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {
|
|
31157
|
+
const v = gray[y * w + x];
|
|
31158
|
+
if (v < Math.min(at(x - k, y), at(x + k, y)) - delta) V[y * w + x] = 1;
|
|
31159
|
+
if (v < Math.min(at(x, y - k), at(x, y + k)) - delta) H[y * w + x] = 1;
|
|
31160
|
+
}
|
|
31161
|
+
const inside2 = (x, y) => x >= 0 && x < w && y >= 0 && y < h;
|
|
31162
|
+
const vr = (x, y) => inside2(x, y) && V[y * w + x] === 1;
|
|
31163
|
+
const hr = (x, y) => inside2(x, y) && H[y * w + x] === 1;
|
|
31164
|
+
const dark = (x, y) => inside2(x, y) && gray[y * w + x] < mark;
|
|
31165
|
+
const sMin = Math.max(8, h * 0.15), sMax = h;
|
|
31166
|
+
const gap = Math.max(1, Math.round(h * 0.04));
|
|
31167
|
+
const vmap = (any) => {
|
|
31168
|
+
const src = any ? VD : V, m = new Uint8Array(w * h);
|
|
31169
|
+
for (let i = 0; i < w * h; i++) {
|
|
31170
|
+
const x = i % w;
|
|
31171
|
+
m[i] = src[i] | (x > 0 ? src[i - 1] : 0) | (x + 1 < w ? src[i + 1] : 0);
|
|
31172
|
+
}
|
|
31173
|
+
const p = new Int32Array(w * (h + 1));
|
|
31174
|
+
for (let x = 0; x < w; x++) for (let y = 0; y < h; y++) {
|
|
31175
|
+
let on = 0;
|
|
31176
|
+
for (let d = -gap; d <= gap && !on; d++) {
|
|
31177
|
+
const yy = y + d;
|
|
31178
|
+
if (yy >= 0 && yy < h && m[yy * w + x]) on = 1;
|
|
31179
|
+
}
|
|
31180
|
+
p[(y + 1) * w + x] = p[y * w + x] + on;
|
|
31181
|
+
}
|
|
31182
|
+
return p;
|
|
31183
|
+
};
|
|
31184
|
+
const hmap = (any) => {
|
|
31185
|
+
const src = any ? HD : H, m = new Uint8Array(w * h);
|
|
31186
|
+
for (let i = 0; i < w * h; i++) m[i] = src[i] | (i >= w ? src[i - w] : 0) | (i + w < w * h ? src[i + w] : 0);
|
|
31187
|
+
const p = new Int32Array((w + 1) * h);
|
|
31188
|
+
for (let y = 0; y < h; y++) for (let x = 0; x < w; x++) {
|
|
31189
|
+
let on = 0;
|
|
31190
|
+
for (let d = -gap; d <= gap && !on; d++) {
|
|
31191
|
+
const xx = x + d;
|
|
31192
|
+
if (xx >= 0 && xx < w && m[y * w + xx]) on = 1;
|
|
31193
|
+
}
|
|
31194
|
+
p[y * (w + 1) + x + 1] = p[y * (w + 1) + x] + on;
|
|
31195
|
+
}
|
|
31196
|
+
return p;
|
|
31197
|
+
};
|
|
31198
|
+
const VD = new Uint8Array(w * h), HD = new Uint8Array(w * h);
|
|
31199
|
+
for (let i = 0; i < w * h; i++) {
|
|
31200
|
+
const dk2 = gray[i] < mark ? 1 : 0;
|
|
31201
|
+
VD[i] = V[i] | dk2;
|
|
31202
|
+
HD[i] = H[i] | dk2;
|
|
31203
|
+
}
|
|
31204
|
+
const VA = vmap(true), VR = vmap(false), HA = hmap(true), HR = hmap(false);
|
|
31205
|
+
const vside = (x, ya, yb, any) => {
|
|
31206
|
+
const p = any ? VA : VR;
|
|
31207
|
+
return (p[(yb + 1) * w + x] - p[ya * w + x]) / (yb - ya + 1);
|
|
31208
|
+
};
|
|
31209
|
+
const hside = (xa, xb, y, any) => {
|
|
31210
|
+
if (y < 0 || y >= h) return 0;
|
|
31211
|
+
const p = any ? HA : HR;
|
|
31212
|
+
return (p[y * (w + 1) + xb + 1] - p[y * (w + 1) + xa]) / (xb - xa + 1);
|
|
31213
|
+
};
|
|
31214
|
+
const hbest = (xa, xb, y, any) => Math.max(hside(xa, xb, y - 2, any), hside(xa, xb, y - 1, any), hside(xa, xb, y, any), hside(xa, xb, y + 1, any), hside(xa, xb, y + 2, any));
|
|
31215
|
+
const strokes = [];
|
|
31216
|
+
for (let x = 0; x < w; x++) {
|
|
31217
|
+
let best = 0, bestTop = 0, start = -1, miss = 0;
|
|
31218
|
+
for (let y = 0; y <= h; y++) {
|
|
31219
|
+
if (y < h && (vr(x - 1, y) || vr(x, y) || vr(x + 1, y))) {
|
|
31220
|
+
if (start < 0) start = y;
|
|
31221
|
+
miss = 0;
|
|
31222
|
+
} else if (start >= 0 && (y === h || ++miss > gap)) {
|
|
31223
|
+
const l = (y === h ? h - 1 - miss : y - miss) - start + 1;
|
|
31224
|
+
if (l > best) {
|
|
31225
|
+
best = l;
|
|
31226
|
+
bestTop = start;
|
|
31227
|
+
}
|
|
31228
|
+
start = -1;
|
|
31229
|
+
miss = 0;
|
|
31230
|
+
}
|
|
31231
|
+
}
|
|
31232
|
+
if (best < sMin * 0.8) continue;
|
|
31233
|
+
const p = strokes[strokes.length - 1];
|
|
31234
|
+
if (p && x - p.x1 <= 1) {
|
|
31235
|
+
p.x1 = x;
|
|
31236
|
+
if (best > p.y1 - p.y0) {
|
|
31237
|
+
p.x = x;
|
|
31238
|
+
p.y0 = bestTop;
|
|
31239
|
+
p.y1 = bestTop + best;
|
|
31240
|
+
}
|
|
31241
|
+
} else strokes.push({ x0: x, x1: x, x, y0: bestTop, y1: bestTop + best });
|
|
31242
|
+
}
|
|
31243
|
+
const corner = (x, y) => {
|
|
31244
|
+
for (let dy = -1; dy <= 1; dy++) for (let dx = -1; dx <= 1; dx++) if (vr(x + dx, y + dy) || hr(x + dx, y + dy) || dark(x + dx, y + dy)) return true;
|
|
31245
|
+
return false;
|
|
31246
|
+
};
|
|
31247
|
+
const found = [], seen2 = /* @__PURE__ */ new Set();
|
|
31248
|
+
const lineStraight = (xc, y0, y1, outward, size) => {
|
|
31249
|
+
const ends = [];
|
|
31250
|
+
for (let y = y0 + 1; y <= y1 - 1; y++) for (let t = 3; t >= -3; t--) if (vr(xc + outward * t, y)) {
|
|
31251
|
+
ends.push(xc + outward * t);
|
|
31252
|
+
break;
|
|
31253
|
+
}
|
|
31254
|
+
if (ends.length < 3) return true;
|
|
31255
|
+
ends.sort((p, q) => p - q);
|
|
31256
|
+
return ends[Math.floor(ends.length * 0.9)] - ends[Math.floor(ends.length * 0.1)] <= Math.max(2, size * 0.06);
|
|
31257
|
+
};
|
|
31258
|
+
const tryBox = (lx, rx, ya, lw, rw) => {
|
|
31259
|
+
const d = rx - lx;
|
|
31260
|
+
const y0 = Math.max(0, ya), y1 = Math.min(h - 1, ya + d);
|
|
31261
|
+
if (d < sMin || d > sMax || lx < 0 || rx >= w || y1 - y0 < d * 0.8) return;
|
|
31262
|
+
const hook = Math.max(2, Math.round(d * 0.25));
|
|
31263
|
+
const lc = vside(lx, y0, y1, true), rc = vside(rx, y0, y1, true);
|
|
31264
|
+
if (lc < 0.75 || rc < 0.75) return;
|
|
31265
|
+
const tc2 = hbest(lx, rx, y0, true), bc = hbest(lx, rx, y1, true);
|
|
31266
|
+
const hooks = Math.min(hbest(lx, lx + hook, y0, true), hbest(rx - hook, rx, y0, true), hbest(lx, lx + hook, y1, true), hbest(rx - hook, rx, y1, true));
|
|
31267
|
+
const square = corner(lx, y0) && corner(rx, y0) && corner(lx, y1) && corner(rx, y1);
|
|
31268
|
+
const straight = (xc, outward) => lineStraight(xc, y0, y1, outward, d);
|
|
31269
|
+
const m = Math.max(2, Math.round(d * 0.2), lw + 2, rw + 2), ix0 = lx + m, ix1 = rx - m, iy0 = y0 + m, iy1 = y1 - m;
|
|
31270
|
+
if (ix1 <= ix0 || iy1 <= iy0) return;
|
|
31271
|
+
let c = 0, a = 0, mx0 = w, mx1 = -1;
|
|
31272
|
+
for (let y = iy0; y <= iy1; y++) for (let x = ix0; x <= ix1; x++) {
|
|
31273
|
+
a++;
|
|
31274
|
+
if (gray[y * w + x] < mark) {
|
|
31275
|
+
c++;
|
|
31276
|
+
if (x < mx0) mx0 = x;
|
|
31277
|
+
if (x > mx1) mx1 = x;
|
|
31278
|
+
}
|
|
31279
|
+
}
|
|
31280
|
+
const fill = c / a;
|
|
31281
|
+
if (fill >= 0.6) return;
|
|
31282
|
+
const checked = fill >= 0.06 && mx1 - mx0 + 1 >= (ix1 - ix0 + 1) * 0.35;
|
|
31283
|
+
const ink2 = (x, y) => vr(x, y) || hr(x, y);
|
|
31284
|
+
const any = (x, y) => ink2(x, y) || dark(x, y);
|
|
31285
|
+
const outer = (from, to, step, at2, ua, ub) => {
|
|
31286
|
+
for (let t = from; step > 0 ? t <= to : t >= to; t += step) for (let u = ua; u <= ub; u++) if (at2(t, u)) return t;
|
|
31287
|
+
return NaN;
|
|
31288
|
+
};
|
|
31289
|
+
const ex0 = Math.round(lx + d * 0.2), ex1 = Math.round(rx - d * 0.2), ey0 = Math.round(y0 + d * 0.2), ey1 = Math.round(y1 - d * 0.2);
|
|
31290
|
+
const top = outer(y0 - 3, y0 + 3, 1, (y, x) => ink2(x, y), ex0, ex1), bot = outer(y1 + 3, y1 - 3, -1, (y, x) => ink2(x, y), ex0, ex1);
|
|
31291
|
+
const lft = outer(lx - 3, lx + 3, 1, (x, y) => ink2(x, y), ey0, ey1), rgt = outer(rx + 3, rx - 3, -1, (x, y) => ink2(x, y), ey0, ey1);
|
|
31292
|
+
const cw = Math.max(1, Math.round(d * 0.1));
|
|
31293
|
+
const filled = (cx, cy, sx, sy) => {
|
|
31294
|
+
for (let i = 0; i < cw; i++) for (let j = 0; j < cw; j++) if (any(cx + sx * i, cy + sy * j)) return true;
|
|
31295
|
+
return false;
|
|
31296
|
+
};
|
|
31297
|
+
const corners2 = [top, bot, lft, rgt].some(isNaN) ? 0 : [filled(lft, top, 1, 1), filled(rgt, top, -1, 1), filled(lft, bot, 1, -1), filled(rgt, bot, -1, -1)].filter(Boolean).length;
|
|
31298
|
+
const kind = tc2 >= 0.75 && bc >= 0.75 ? corners2 >= (checked ? 2 : 3) ? "□" : null : square && hooks >= 0.6 && tc2 < 0.75 && bc < 0.75 && straight(lx, -1) && straight(rx, 1) ? "[]" : null;
|
|
31299
|
+
if (!kind) return;
|
|
31300
|
+
const ridge = kind === "□" ? [hbest(lx, rx, y0, false), hbest(lx, rx, y1, false)] : [Math.min(hbest(lx, lx + hook, y0, false), hbest(rx - hook, rx, y0, false)), Math.min(hbest(lx, lx + hook, y1, false), hbest(rx - hook, rx, y1, false))];
|
|
31301
|
+
const clear = [vside(lx, y0, y1, false), vside(rx, y0, y1, false), ...ridge].filter((v) => v >= 0.5).length >= 3;
|
|
31302
|
+
if (!clear) return;
|
|
31303
|
+
const key3 = `${lx - lw},${rx + rw},${y0}`;
|
|
31304
|
+
if (seen2.has(key3)) return;
|
|
31305
|
+
seen2.add(key3);
|
|
31306
|
+
found.push({ x0: Math.max(0, lx - lw), x1: Math.min(w - 1, rx + rw), y0, y1, kind, checked, score: lc + rc + Math.max(tc2 + bc, 2 * hooks) });
|
|
31307
|
+
};
|
|
31308
|
+
const tryBracket = (lx, rx, y0, y1, lw, rw) => {
|
|
31309
|
+
const len = y1 - y0, d = rx - lx, hook = Math.max(2, Math.round(len * 0.25)), gap2 = Math.max(1, Math.round(len * 0.08));
|
|
31310
|
+
if (vside(lx, y0, y1, false) < 0.75 || vside(rx, y0, y1, false) < 0.75) return;
|
|
31311
|
+
const hooks = Math.min(hbest(lx, lx + hook, y0, true), hbest(rx - hook, rx, y0, true), hbest(lx, lx + hook, y1, true), hbest(rx - hook, rx, y1, true));
|
|
31312
|
+
if (hooks < 0.6 || hbest(lx + hook + gap2, rx - hook - gap2, y0, true) >= 0.75 || hbest(lx + hook + gap2, rx - hook - gap2, y1, true) >= 0.75) return;
|
|
31313
|
+
const corners2 = [corner(lx, y0), corner(rx, y0), corner(lx, y1), corner(rx, y1)].every(Boolean);
|
|
31314
|
+
if (!corners2 || !lineStraight(lx, y0, y1, -1, len) || !lineStraight(rx, y0, y1, 1, len)) return;
|
|
31315
|
+
const m = Math.max(2, Math.round(len * 0.2), lw + 2, rw + 2), ix0 = lx + m, ix1 = rx - m, iy0 = y0 + m, iy1 = y1 - m;
|
|
31316
|
+
if (ix1 <= ix0 || iy1 <= iy0) return;
|
|
31317
|
+
let c = 0, a = 0, my0 = h, my1 = -1;
|
|
31318
|
+
for (let y = iy0; y <= iy1; y++) for (let x = ix0; x <= ix1; x++) {
|
|
31319
|
+
a++;
|
|
31320
|
+
if (gray[y * w + x] < mark) {
|
|
31321
|
+
c++;
|
|
31322
|
+
if (y < my0) my0 = y;
|
|
31323
|
+
if (y > my1) my1 = y;
|
|
31324
|
+
}
|
|
31325
|
+
}
|
|
31326
|
+
if (c / a >= 0.6) return;
|
|
31327
|
+
const checked = c / a >= 0.03 && my1 - my0 + 1 >= (iy1 - iy0 + 1) * 0.35;
|
|
31328
|
+
const key3 = `[${lx - lw},${rx + rw},${y0}`;
|
|
31329
|
+
if (seen2.has(key3)) return;
|
|
31330
|
+
seen2.add(key3);
|
|
31331
|
+
found.push({ x0: Math.max(0, lx - lw), x1: Math.min(w - 1, rx + rw), y0, y1, kind: "[]", checked, score: 2 + hooks * 2 });
|
|
31332
|
+
};
|
|
31333
|
+
for (let i = 0; i < strokes.length; i++) {
|
|
31334
|
+
const L = strokes[i], len = L.y1 - L.y0;
|
|
31335
|
+
for (let j = i + 1; j < strokes.length; j++) {
|
|
31336
|
+
const R = strokes[j], d = R.x - L.x;
|
|
31337
|
+
if (d < sMin) continue;
|
|
31338
|
+
if (d > sMax) break;
|
|
31339
|
+
if (L.x1 - L.x0 > d * 0.3 || R.x1 - R.x0 > d * 0.3) continue;
|
|
31340
|
+
for (const ya of /* @__PURE__ */ new Set([L.y0, R.y0, L.y1 - d, R.y1 - d])) tryBox(L.x, R.x, ya, L.x1 - L.x0, R.x1 - R.x0);
|
|
31341
|
+
}
|
|
31342
|
+
if (L.x1 - L.x0 <= len * 0.3) for (const d of [len - 1, len, len + 1]) {
|
|
31343
|
+
tryBox(L.x - d, L.x, L.y0, L.x1 - L.x0, L.x1 - L.x0);
|
|
31344
|
+
tryBox(L.x, L.x + d, L.y0, L.x1 - L.x0, L.x1 - L.x0);
|
|
31345
|
+
}
|
|
31346
|
+
for (let j = i + 1; j < strokes.length; j++) {
|
|
31347
|
+
const R = strokes[j], d = R.x - L.x, rlen = R.y1 - R.y0;
|
|
31348
|
+
if (d > len * 2.5) break;
|
|
31349
|
+
if (d < len * 0.6 || d < sMin || Math.abs(rlen - len) > len * 0.25) continue;
|
|
31350
|
+
const y0 = Math.max(L.y0, R.y0), y1 = Math.min(L.y1, R.y1) - 1;
|
|
31351
|
+
if (y1 - y0 < len * 0.8) continue;
|
|
31352
|
+
tryBracket(L.x, R.x, y0, y1, L.x1 - L.x0, R.x1 - R.x0);
|
|
31353
|
+
}
|
|
31354
|
+
}
|
|
31355
|
+
return found.sort((p, q) => q.score - p.score).map(({ score: _, ...f }) => f);
|
|
31356
|
+
}
|
|
31143
31357
|
var BRACKET_TAPER, BRACKET_SOLID, BRACKET_WIDE, BRACKET_LENS, STACK_INK_RATIO;
|
|
31144
31358
|
var init_line_split = __esm({
|
|
31145
31359
|
"src/ocr/line-split.ts"() {
|
|
@@ -31221,8 +31435,82 @@ function restoreGlyphs(rgba, pageW, box, text, steps, stepPx, note = {}, rings =
|
|
|
31221
31435
|
if (prev !== void 0) chars2[prev] += r.glyph;
|
|
31222
31436
|
else if (live.length) chars2[live[0]] = r.glyph + chars2[live[0]];
|
|
31223
31437
|
});
|
|
31438
|
+
checkboxes(c);
|
|
31224
31439
|
return chars2.join("");
|
|
31225
31440
|
}
|
|
31441
|
+
function checkboxes({ chars: chars2, cx, gray, w, h, ink }) {
|
|
31442
|
+
const live = chars2.map((_, i) => i).filter((i) => chars2[i].trim());
|
|
31443
|
+
if (!live.length) return;
|
|
31444
|
+
const d = [];
|
|
31445
|
+
for (let k = 0; k + 1 < live.length; k++) d.push(cx(live[k + 1]) - cx(live[k]));
|
|
31446
|
+
const pitch = d.length >= 2 ? d.sort((a, b) => a - b)[d.length >> 1] : h * 0.6;
|
|
31447
|
+
const taken = [];
|
|
31448
|
+
const pending = [];
|
|
31449
|
+
let sure = 0;
|
|
31450
|
+
for (const f of checkboxFrames(gray, w, h, ink)) {
|
|
31451
|
+
if (taken.some((o) => o.x0 <= f.x1 && f.x0 <= o.x1)) continue;
|
|
31452
|
+
const s = f.x1 - f.x0, mid = (f.x0 + f.x1) / 2;
|
|
31453
|
+
const own = live.filter((i) => Math.abs(cx(i) - mid) <= Math.max(pitch * 0.5, s / 2));
|
|
31454
|
+
const at = live.indexOf(own[0]), last = live.indexOf(own[own.length - 1]);
|
|
31455
|
+
const next = own.length ? live[last + 1] : live.find((i) => cx(i) > mid);
|
|
31456
|
+
if (next === void 0 || cx(next) > f.x1 + s * 3 || !/^[가-힣A-Za-z0-9(]/u.test(chars2[next])) continue;
|
|
31457
|
+
const before2 = at > 0 ? live[at - 1] : void 0;
|
|
31458
|
+
const wordHead = before2 === void 0 || before2 !== own[0] - 1 || !/[A-Za-z0-9가-힣]$/u.test(chars2[before2]);
|
|
31459
|
+
const read = own.map((i) => chars2[i]).join("");
|
|
31460
|
+
if (own.some((i) => !BOX_READ.test(chars2[i]))) continue;
|
|
31461
|
+
if (/^\(?1*\)?$/.test(read) && read && read !== "()") continue;
|
|
31462
|
+
if (/^[[\u3010\u3014]$/u.test(read) && chars2.slice(own[0] + 1).some((t) => /[\]\u3011\u3015]/u.test(t))) continue;
|
|
31463
|
+
if (/^[\]\u3011\u3015]$/u.test(read) && chars2.slice(0, own[0]).some((t) => /[[\u3010\u3014]/u.test(t))) continue;
|
|
31464
|
+
if (own.some((i) => BOX_LETTER.test(chars2[i])) && (!wordHead || next === own[own.length - 1] + 1 && /^[A-Za-z0-9]/.test(chars2[next]))) continue;
|
|
31465
|
+
if (BOX_KEPT.test(read)) {
|
|
31466
|
+
taken.push(f);
|
|
31467
|
+
if (!BOX_AMBIGUOUS.test(read)) sure++;
|
|
31468
|
+
continue;
|
|
31469
|
+
}
|
|
31470
|
+
if (/[\u221a\u2713\u2714\u2228\u03bd]/u.test(read) && !f.checked) continue;
|
|
31471
|
+
const glyph = f.kind === "□" ? f.checked ? "☑" : "□" : f.checked ? "[√]" : "[]";
|
|
31472
|
+
if (own.length) {
|
|
31473
|
+
taken.push(f);
|
|
31474
|
+
const put = () => {
|
|
31475
|
+
chars2[own[0]] = glyph;
|
|
31476
|
+
for (const i of own.slice(1)) chars2[i] = "";
|
|
31477
|
+
};
|
|
31478
|
+
if (BOX_AMBIGUOUS.test(read)) pending.push(put);
|
|
31479
|
+
else {
|
|
31480
|
+
sure++;
|
|
31481
|
+
put();
|
|
31482
|
+
}
|
|
31483
|
+
continue;
|
|
31484
|
+
}
|
|
31485
|
+
const prev = live[live.indexOf(next) - 1];
|
|
31486
|
+
if (prev !== void 0 && /(?:\u25a1|\[\])$/u.test(chars2[prev])) {
|
|
31487
|
+
taken.push(f);
|
|
31488
|
+
sure++;
|
|
31489
|
+
if (f.checked) chars2[prev] = chars2[prev].replace(/(?:\u25a1|\[\])$/u, glyph);
|
|
31490
|
+
continue;
|
|
31491
|
+
}
|
|
31492
|
+
if (f.checked || f.kind !== "□") continue;
|
|
31493
|
+
if (cx(next) < f.x1 + pitch * 0.5) continue;
|
|
31494
|
+
if (Math.abs((f.y0 + f.y1) / 2 - h / 2) > h * 0.25) continue;
|
|
31495
|
+
if (prev !== void 0 && /[.\u00b7\u2026]$/u.test(chars2[prev])) continue;
|
|
31496
|
+
const head = prev === void 0 ? leadingBullet(gray, w, h, ink, cx(next))?.mark : void 0;
|
|
31497
|
+
if (head && head !== "□") continue;
|
|
31498
|
+
if (prev === next - 1 && /[가-힣\u3131-\u318eA-Za-z0-9]$/u.test(chars2[prev]) && /^[가-힣A-Za-z0-9]/u.test(chars2[next])) continue;
|
|
31499
|
+
const m = Math.max(2, Math.round(s * 0.35)), dirty = (xa, xb) => {
|
|
31500
|
+
let k = 0, n = 0;
|
|
31501
|
+
for (let y = f.y0; y <= f.y1; y++) for (let x = Math.max(0, xa); x <= Math.min(w - 1, xb); x++) {
|
|
31502
|
+
n++;
|
|
31503
|
+
if (gray[y * w + x] <= ink.threshold) k++;
|
|
31504
|
+
}
|
|
31505
|
+
return !n || k / n > 0.05;
|
|
31506
|
+
};
|
|
31507
|
+
if (dirty(f.x0 - m, f.x0 - 1) || dirty(f.x1 + 1, f.x1 + m)) continue;
|
|
31508
|
+
taken.push(f);
|
|
31509
|
+
sure++;
|
|
31510
|
+
chars2[next] = glyph + " " + chars2[next];
|
|
31511
|
+
}
|
|
31512
|
+
if (sure) for (const put of pending) put();
|
|
31513
|
+
}
|
|
31226
31514
|
function trimInklessEnds(rgba, pageW, box, text, steps, stepPx) {
|
|
31227
31515
|
const chars2 = [...text], { w, h } = box;
|
|
31228
31516
|
if (chars2.length !== steps.length || steps.some((s) => (s + 0.5) * stepPx > w + stepPx)) return { text, steps };
|
|
@@ -31511,7 +31799,7 @@ function roman({ chars: chars2, cx, gray, w, h, ink }) {
|
|
|
31511
31799
|
s = e;
|
|
31512
31800
|
}
|
|
31513
31801
|
}
|
|
31514
|
-
var INKLESS_DELTA, RING_JAMO, RING_SYLLABLE;
|
|
31802
|
+
var INKLESS_DELTA, RING_JAMO, RING_SYLLABLE, BOX_READ, BOX_LETTER, BOX_AMBIGUOUS, BOX_KEPT;
|
|
31515
31803
|
var init_glyph_restore = __esm({
|
|
31516
31804
|
"src/ocr/glyph-restore.ts"() {
|
|
31517
31805
|
"use strict";
|
|
@@ -31519,6 +31807,10 @@ var init_glyph_restore = __esm({
|
|
|
31519
31807
|
INKLESS_DELTA = 32;
|
|
31520
31808
|
RING_JAMO = "ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋㅌㅍㅎ";
|
|
31521
31809
|
RING_SYLLABLE = "가나다라마바사아자차카타파하";
|
|
31810
|
+
BOX_READ = /^[\u25a1\u2610\u2611\u3141\u53e3[\]\u3010\u3011\u3014\u3015()|1VvNMCXx\u3137\u3134\u221a\u2713\u2714~\u2228\u03bd]+$/u;
|
|
31811
|
+
BOX_LETTER = /[1VvNMCXx]/;
|
|
31812
|
+
BOX_AMBIGUOUS = /[A-Za-z0-9()[\]\u3010\u3011\u3014\u3015|~]/u;
|
|
31813
|
+
BOX_KEPT = /^(?:\u25a1|\u3141|\u53e3|\[\]?|\])$/u;
|
|
31522
31814
|
}
|
|
31523
31815
|
});
|
|
31524
31816
|
|
|
@@ -38056,7 +38348,8 @@ function collapseEvenSpacing(text, whole = true) {
|
|
|
38056
38348
|
const tokens = text.split(" ");
|
|
38057
38349
|
const visible = tokens.map((t) => t.replace(/<\/?u>|~~/g, ""));
|
|
38058
38350
|
const singleCharCount = visible.filter((t) => t.length === 1).length;
|
|
38059
|
-
|
|
38351
|
+
const wordy = visible.reduce((n, t) => n + (t.match(/[가-힣]{3,}/g) ?? []).reduce((m, w) => m + w.length, 0), 0) >= singleCharCount && visible.every((t) => t.length !== 1 || /[가-힣]/.test(t));
|
|
38352
|
+
if (tokens.length >= 3 && singleCharCount / tokens.length >= 0.7 && !wordy && !isDateUnitBlank(visible)) return tokens.join("");
|
|
38060
38353
|
}
|
|
38061
38354
|
return text.replace(
|
|
38062
38355
|
/(?<![^\s>])[가-힣](?: [가-힣\d]){2,}(?![^\s<])/g,
|
|
@@ -38065,6 +38358,12 @@ function collapseEvenSpacing(text, whole = true) {
|
|
|
38065
38358
|
const after2 = text.slice(offset + match.length).replace(/^(?:<\/?u>|~~)+/, "");
|
|
38066
38359
|
if (/\S$/.test(before2) || /^\S/.test(after2)) return match;
|
|
38067
38360
|
if (isDateUnitBlank(match.split(" "))) return match;
|
|
38361
|
+
const edge = /^및 | 및$/.exec(match);
|
|
38362
|
+
if (edge) {
|
|
38363
|
+
const rest = match.replace(/^및 | 및$/, "");
|
|
38364
|
+
if (rest.split(" ").length < 3) return match;
|
|
38365
|
+
return match.startsWith("및 ") ? "및 " + rest.replace(/ /g, "") : rest.replace(/ /g, "") + " 및";
|
|
38366
|
+
}
|
|
38068
38367
|
const parts = match.split(/ 및 (?=[가-힣\d])/);
|
|
38069
38368
|
return parts.length > 1 ? parts.map((p) => p.replace(/ /g, "")).join(" 및 ") : match.replace(/ /g, "");
|
|
38070
38369
|
}
|
|
@@ -44934,6 +45233,17 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
44934
45233
|
}
|
|
44935
45234
|
}
|
|
44936
45235
|
}
|
|
45236
|
+
if (ocrItems && ocrSpan >= pageHeight * 0.5) {
|
|
45237
|
+
for (let i = grids.length - 1; i >= 0; i--) {
|
|
45238
|
+
const g3 = grids[i];
|
|
45239
|
+
const area = (b) => (b.x2 - b.x1) * (b.y2 - b.y1);
|
|
45240
|
+
if (g3.cells || area(g3.bbox) < pageWidth * pageHeight * 0.5) continue;
|
|
45241
|
+
const inner = grids.filter((o) => o !== g3 && !o.cells && o.bbox.x1 >= g3.bbox.x1 - 2 && o.bbox.x2 <= g3.bbox.x2 + 2 && o.bbox.y1 >= g3.bbox.y1 - 2 && o.bbox.y2 <= g3.bbox.y2 + 2);
|
|
45242
|
+
if (inner.length === 0 || inner.reduce((s, o) => s + area(o.bbox), 0) > area(g3.bbox) * 0.75) continue;
|
|
45243
|
+
const own = (vs, pick3) => vs.slice(1, -1).every((v) => inner.some((o) => pick3(o).some((w) => Math.abs(w - v) <= 4)));
|
|
45244
|
+
if (own(g3.colXs, (o) => o.colXs) && own(g3.rowYs, (o) => o.rowYs)) grids.splice(i, 1);
|
|
45245
|
+
}
|
|
45246
|
+
}
|
|
44937
45247
|
if (ocrItems && ocrSpan >= pageHeight * 0.5 && grids.length > 0 && grids.every((g3) => g3.rowYs.length === 2 && g3.colXs.length === 2 && !g3.cells && ((g3.bbox.x2 - g3.bbox.x1) * (g3.bbox.y2 - g3.bbox.y1) < pageWidth * pageHeight * 0.02 || g3.bbox.x2 - g3.bbox.x1 < pageWidth * 0.55))) {
|
|
44938
45248
|
return ruledColumnBlocks(items, horizontals, verticals, pageWidth, pageHeight, pageNum, detectTables, lex) ?? extractPageBlocksFallback(items, pageNum, true, detectTables, lex, figures());
|
|
44939
45249
|
}
|