kordoc 4.25.21 → 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 +3 -3
- package/dist/{chunk-PVOLFVXE.js → chunk-2PQMHHX4.js} +2 -2
- package/dist/{chunk-6I3X54AQ.js → chunk-377GAL46.js} +2 -2
- package/dist/{chunk-ZCMMU34Z.js → chunk-3IVEGZI3.js} +2 -2
- package/dist/{chunk-5ULHNZ3P.js → chunk-7LW2HG7F.js} +3 -3
- package/dist/{chunk-LSUTK3DH.js → chunk-7S4KRBXC.js} +2 -2
- package/dist/{chunk-COJYQKGH.js → chunk-B3LK5RVY.js} +83 -4
- package/dist/chunk-B3LK5RVY.js.map +7 -0
- package/dist/{chunk-QNJ2LMUO.js → chunk-BXHO5BB5.js} +8 -8
- package/dist/{chunk-HQILGS2O.js → chunk-GMYXTUSJ.js} +2 -2
- package/dist/{chunk-6MCJHRSM.js → chunk-GZX5UQ4P.js} +2 -2
- package/dist/{chunk-3AYNFK6J.js → chunk-IRR32NHL.js} +2 -2
- package/dist/{chunk-FDSFXE2L.js → chunk-J4OTJFSW.js} +2 -2
- package/dist/{chunk-TI6S3KZF.js → chunk-K5ZUKPU3.js} +2 -2
- package/dist/{chunk-W5AHXAUP.js → chunk-LTXF66N6.js} +7 -7
- package/dist/{chunk-B2SRYWEY.js → chunk-MJ2B3EXE.js} +19 -1
- package/dist/{chunk-B2SRYWEY.js.map → chunk-MJ2B3EXE.js.map} +2 -2
- package/dist/{chunk-TYJSNW4Z.js → chunk-MMJIFTWZ.js} +131 -32
- package/dist/chunk-MMJIFTWZ.js.map +7 -0
- package/dist/{chunk-MWCJYIJC.js → chunk-MPEWMDM2.js} +19 -19
- package/dist/{chunk-DHXKCDAU.js → chunk-NFMC6FLB.js} +66 -9
- package/dist/chunk-NFMC6FLB.js.map +7 -0
- package/dist/{chunk-ZO4P735U.js → chunk-PGBRNQAF.js} +2 -2
- package/dist/{chunk-PFNZQ3XI.js → chunk-PQIIJRV2.js} +2 -2
- package/dist/{chunk-S553BW45.js → chunk-QAQDSBAC.js} +6 -6
- package/dist/{chunk-XUBBFY3H.js → chunk-QI7LT4AX.js} +6 -6
- package/dist/{chunk-XUBBFY3H.js.map → chunk-QI7LT4AX.js.map} +2 -2
- package/dist/{chunk-QOCUFTT4.js → chunk-SE5HAJNL.js} +5 -5
- package/dist/{chunk-5MDRUEHP.js → chunk-SKZ2LLN5.js} +237 -4
- package/dist/chunk-SKZ2LLN5.js.map +1 -0
- package/dist/{chunk-KW4JO5CV.js → chunk-TYANRH6O.js} +3 -3
- package/dist/{chunk-DZOA5N5W.js → chunk-WLHQL53U.js} +2 -2
- package/dist/{chunk-24LB25LZ.js → chunk-YDOIXWSF.js} +2 -2
- package/dist/{chunk-GJORKM42.js → chunk-YWRAHQTV.js} +2 -2
- package/dist/chunks-A2NELZR2.js +10 -0
- package/dist/cli.js +38 -38
- package/dist/{formula-HMKT4BZL.js → formula-LUPB363D.js} +4 -4
- package/dist/generator-MK3VLXV2.js +18 -0
- package/dist/{hancom-QWJBWOOE.js → hancom-24SHJFWF.js} +2 -2
- package/dist/{image-ocr-P5AIZNT3.js → image-ocr-CSV7OLPX.js} +11 -11
- package/dist/index.cjs +517 -30
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +22 -22
- package/dist/mcp.js +34 -34
- package/dist/memo-5G32P322.js +15 -0
- package/dist/{model-bundle-5CXCIZHZ.js → model-bundle-U6ONSDTJ.js} +5 -5
- package/dist/{models-PS4L7NLP.js → models-X4FVLSSQ.js} +5 -5
- package/dist/{page-images-QW7IUTUB.js → page-images-E67SJN3S.js} +2 -2
- package/dist/{parse-worker-v2-PRH6KVKP.js → parse-worker-v2-3VY5X7SF.js} +24 -24
- package/dist/{parser-OQIR5ZMI.js → parser-6GFE6B42.js} +14 -14
- package/dist/{pdf-ocr-ZH4JAUTR.js → pdf-ocr-MKQURNXT.js} +9 -9
- package/dist/{profile-io-JFRAM2VE.js → profile-io-DAZZHP7S.js} +3 -3
- package/dist/{rasterize-JJOMUTYX.js → rasterize-BJTBPSDM.js} +3 -3
- package/dist/{redact-doc-A7TW4MNF.js → redact-doc-W6H7SXGB.js} +23 -23
- package/dist/{render-VAOMAQV2.js → render-HJDMKGMV.js} +10 -10
- package/dist/{rewrite-fallback-7PR7V3AZ.js → rewrite-fallback-VKA6BLLT.js} +13 -13
- package/dist/seal-5KR6SUIU.js +14 -0
- package/dist/{setup-6DXZJQCT.js → setup-UGWQLJ5Z.js} +3 -3
- package/dist/{to-hwpx-A56R6H27.js → to-hwpx-WI5CGWDZ.js} +7 -7
- package/dist/visual-YDMDCB7Q.js +42 -0
- package/dist/{watch-7W6CKGX7.js → watch-CIO5522I.js} +23 -23
- package/package.json +1 -1
- package/dist/chunk-5MDRUEHP.js.map +0 -1
- package/dist/chunk-COJYQKGH.js.map +0 -7
- package/dist/chunk-DHXKCDAU.js.map +0 -7
- package/dist/chunk-TYJSNW4Z.js.map +0 -7
- package/dist/chunks-XX7RHVQF.js +0 -10
- package/dist/generator-HOY4SZ26.js +0 -18
- package/dist/memo-Q7772VJD.js +0 -15
- package/dist/seal-RZZNRJFL.js +0 -14
- package/dist/visual-25RY7EFI.js +0 -42
- /package/dist/{chunk-PVOLFVXE.js.map → chunk-2PQMHHX4.js.map} +0 -0
- /package/dist/{chunk-6I3X54AQ.js.map → chunk-377GAL46.js.map} +0 -0
- /package/dist/{chunk-ZCMMU34Z.js.map → chunk-3IVEGZI3.js.map} +0 -0
- /package/dist/{chunk-5ULHNZ3P.js.map → chunk-7LW2HG7F.js.map} +0 -0
- /package/dist/{chunk-LSUTK3DH.js.map → chunk-7S4KRBXC.js.map} +0 -0
- /package/dist/{chunk-QNJ2LMUO.js.map → chunk-BXHO5BB5.js.map} +0 -0
- /package/dist/{chunk-HQILGS2O.js.map → chunk-GMYXTUSJ.js.map} +0 -0
- /package/dist/{chunk-6MCJHRSM.js.map → chunk-GZX5UQ4P.js.map} +0 -0
- /package/dist/{chunk-3AYNFK6J.js.map → chunk-IRR32NHL.js.map} +0 -0
- /package/dist/{chunk-FDSFXE2L.js.map → chunk-J4OTJFSW.js.map} +0 -0
- /package/dist/{chunk-TI6S3KZF.js.map → chunk-K5ZUKPU3.js.map} +0 -0
- /package/dist/{chunk-W5AHXAUP.js.map → chunk-LTXF66N6.js.map} +0 -0
- /package/dist/{chunk-MWCJYIJC.js.map → chunk-MPEWMDM2.js.map} +0 -0
- /package/dist/{chunk-ZO4P735U.js.map → chunk-PGBRNQAF.js.map} +0 -0
- /package/dist/{chunk-PFNZQ3XI.js.map → chunk-PQIIJRV2.js.map} +0 -0
- /package/dist/{chunk-S553BW45.js.map → chunk-QAQDSBAC.js.map} +0 -0
- /package/dist/{chunk-QOCUFTT4.js.map → chunk-SE5HAJNL.js.map} +0 -0
- /package/dist/{chunk-KW4JO5CV.js.map → chunk-TYANRH6O.js.map} +0 -0
- /package/dist/{chunk-DZOA5N5W.js.map → chunk-WLHQL53U.js.map} +0 -0
- /package/dist/{chunk-24LB25LZ.js.map → chunk-YDOIXWSF.js.map} +0 -0
- /package/dist/{chunk-GJORKM42.js.map → chunk-YWRAHQTV.js.map} +0 -0
- /package/dist/{chunks-XX7RHVQF.js.map → chunks-A2NELZR2.js.map} +0 -0
- /package/dist/{formula-HMKT4BZL.js.map → formula-LUPB363D.js.map} +0 -0
- /package/dist/{generator-HOY4SZ26.js.map → generator-MK3VLXV2.js.map} +0 -0
- /package/dist/{hancom-QWJBWOOE.js.map → hancom-24SHJFWF.js.map} +0 -0
- /package/dist/{image-ocr-P5AIZNT3.js.map → image-ocr-CSV7OLPX.js.map} +0 -0
- /package/dist/{memo-Q7772VJD.js.map → memo-5G32P322.js.map} +0 -0
- /package/dist/{model-bundle-5CXCIZHZ.js.map → model-bundle-U6ONSDTJ.js.map} +0 -0
- /package/dist/{models-PS4L7NLP.js.map → models-X4FVLSSQ.js.map} +0 -0
- /package/dist/{page-images-QW7IUTUB.js.map → page-images-E67SJN3S.js.map} +0 -0
- /package/dist/{parse-worker-v2-PRH6KVKP.js.map → parse-worker-v2-3VY5X7SF.js.map} +0 -0
- /package/dist/{parser-OQIR5ZMI.js.map → parser-6GFE6B42.js.map} +0 -0
- /package/dist/{pdf-ocr-ZH4JAUTR.js.map → pdf-ocr-MKQURNXT.js.map} +0 -0
- /package/dist/{profile-io-JFRAM2VE.js.map → profile-io-DAZZHP7S.js.map} +0 -0
- /package/dist/{rasterize-JJOMUTYX.js.map → rasterize-BJTBPSDM.js.map} +0 -0
- /package/dist/{redact-doc-A7TW4MNF.js.map → redact-doc-W6H7SXGB.js.map} +0 -0
- /package/dist/{render-VAOMAQV2.js.map → render-HJDMKGMV.js.map} +0 -0
- /package/dist/{rewrite-fallback-7PR7V3AZ.js.map → rewrite-fallback-VKA6BLLT.js.map} +0 -0
- /package/dist/{seal-RZZNRJFL.js.map → seal-5KR6SUIU.js.map} +0 -0
- /package/dist/{setup-6DXZJQCT.js.map → setup-UGWQLJ5Z.js.map} +0 -0
- /package/dist/{to-hwpx-A56R6H27.js.map → to-hwpx-WI5CGWDZ.js.map} +0 -0
- /package/dist/{visual-25RY7EFI.js.map → visual-YDMDCB7Q.js.map} +0 -0
- /package/dist/{watch-7W6CKGX7.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);
|
|
@@ -9575,7 +9575,7 @@ function detectHwp5Headings(blocks, docInfo, tocTexts) {
|
|
|
9575
9575
|
}
|
|
9576
9576
|
let maxWeight = 0;
|
|
9577
9577
|
for (const [size, weight] of sizeFreq) {
|
|
9578
|
-
if (weight > maxWeight) {
|
|
9578
|
+
if (weight > maxWeight || weight === maxWeight && size < baseFontSize) {
|
|
9579
9579
|
maxWeight = weight;
|
|
9580
9580
|
baseFontSize = size;
|
|
9581
9581
|
}
|
|
@@ -27026,6 +27026,15 @@ function scanSectionXml(xml, sectionIndex) {
|
|
|
27026
27026
|
const cellStack = [];
|
|
27027
27027
|
let pendingT = null;
|
|
27028
27028
|
const ctrlSubStack = [];
|
|
27029
|
+
const noteStack = [];
|
|
27030
|
+
const directlyInNote = () => {
|
|
27031
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
27032
|
+
const l = stack[i].local;
|
|
27033
|
+
if (NOTE_ELEMENT.has(l)) return true;
|
|
27034
|
+
if (l === "drawText" || PARA_CONTAINER.has(l)) return false;
|
|
27035
|
+
}
|
|
27036
|
+
return false;
|
|
27037
|
+
};
|
|
27029
27038
|
const classifyPara = () => {
|
|
27030
27039
|
let sawDrawText = false;
|
|
27031
27040
|
for (let i = stack.length - 1; i >= 0; i--) {
|
|
@@ -27107,6 +27116,8 @@ function scanSectionXml(xml, sectionIndex) {
|
|
|
27107
27116
|
else orphanTables.push(table2);
|
|
27108
27117
|
}
|
|
27109
27118
|
}
|
|
27119
|
+
} else if (NOTE_ELEMENT.has(local3)) {
|
|
27120
|
+
noteStack.pop();
|
|
27110
27121
|
} else if (local3 === "header" || local3 === "footer") {
|
|
27111
27122
|
const sub = ctrlSubStack[ctrlSubStack.length - 1];
|
|
27112
27123
|
if (sub) {
|
|
@@ -27174,6 +27185,7 @@ function scanSectionXml(xml, sectionIndex) {
|
|
|
27174
27185
|
const cls = classifyPara();
|
|
27175
27186
|
para2.kind = cls.kind;
|
|
27176
27187
|
if (cls.inTextbox) para2.inTextbox = true;
|
|
27188
|
+
if (cls.kind === "excluded" && noteStack.length && directlyInNote()) noteStack[noteStack.length - 1].push(para2);
|
|
27177
27189
|
stack.push({ local: local2, qname, contentStart });
|
|
27178
27190
|
paraStack.push(para2);
|
|
27179
27191
|
if (para2.kind === "body" || para2.kind === "draw") bodyParagraphs2.push(para2);
|
|
@@ -27183,6 +27195,11 @@ function scanSectionXml(xml, sectionIndex) {
|
|
|
27183
27195
|
} else if (para2.kind === "excluded") {
|
|
27184
27196
|
excludedParagraphs.push(para2);
|
|
27185
27197
|
}
|
|
27198
|
+
} else if (NOTE_ELEMENT.has(local2)) {
|
|
27199
|
+
const list = [];
|
|
27200
|
+
const host2 = paraStack[paraStack.length - 1];
|
|
27201
|
+
if (host2) (host2.notes ??= []).push(list);
|
|
27202
|
+
noteStack.push(list);
|
|
27186
27203
|
} else if (local2 === "run" || local2 === "r") {
|
|
27187
27204
|
const para2 = owningPara();
|
|
27188
27205
|
if (para2 && para2.runPrefix === void 0) para2.runPrefix = prefixOf(qname);
|
|
@@ -27578,7 +27595,7 @@ function applySplices(xml, splices) {
|
|
|
27578
27595
|
parts.push(xml.slice(cursor));
|
|
27579
27596
|
return parts.join("");
|
|
27580
27597
|
}
|
|
27581
|
-
var TAG_RE2, T_BARRIER, PARA_CONTAINER, TABLE_BARRIER, T_CHAR_TAG_RE, PUA_RE;
|
|
27598
|
+
var TAG_RE2, T_BARRIER, PARA_CONTAINER, NOTE_ELEMENT, TABLE_BARRIER, T_CHAR_TAG_RE, PUA_RE;
|
|
27582
27599
|
var init_source_map = __esm({
|
|
27583
27600
|
"src/roundtrip/source-map.ts"() {
|
|
27584
27601
|
"use strict";
|
|
@@ -27619,6 +27636,7 @@ var init_source_map = __esm({
|
|
|
27619
27636
|
"en"
|
|
27620
27637
|
// 각주/미주 — 파서는 호스트 블록 footnoteText로만 흡수
|
|
27621
27638
|
]);
|
|
27639
|
+
NOTE_ELEMENT = /* @__PURE__ */ new Set(["footNote", "endNote", "fn", "en"]);
|
|
27622
27640
|
TABLE_BARRIER = /* @__PURE__ */ new Set([
|
|
27623
27641
|
"tbl",
|
|
27624
27642
|
"ctrl",
|
|
@@ -28169,7 +28187,7 @@ function removeNoteMarks(text, marks) {
|
|
|
28169
28187
|
function noteMarksOf(footnoteText) {
|
|
28170
28188
|
return footnoteText ? footnoteText.split("; ").map((s) => s.match(/^(\S+)\s/)?.[1] ?? "").filter(Boolean) : [];
|
|
28171
28189
|
}
|
|
28172
|
-
function splitCellNote(before2, after2, skipped) {
|
|
28190
|
+
function splitCellNote(before2, after2, skipped, editNote) {
|
|
28173
28191
|
const re = /\s*\(주: ([\s\S]*)\)$/;
|
|
28174
28192
|
const bm = before2.match(re);
|
|
28175
28193
|
if (!bm) return { before: before2, after: after2, noted: false };
|
|
@@ -28178,13 +28196,66 @@ function splitCellNote(before2, after2, skipped) {
|
|
|
28178
28196
|
let body = after2;
|
|
28179
28197
|
if (am) {
|
|
28180
28198
|
body = after2.slice(0, am.index).trimEnd();
|
|
28181
|
-
if (normForMatch(am[1]) !== normForMatch(bm[1])) skipped.push({ reason:
|
|
28199
|
+
if (normForMatch(am[1]) !== normForMatch(bm[1]) && !editNote?.(bm[1], am[1])) skipped.push({ reason: NOTE_TEXT_UNSUPPORTED, before: bm[1], after: am[1] });
|
|
28182
28200
|
} else skipped.push({ reason: "각주 표기 삭제는 미지원 — 각주 유지, 본문만 적용", before: `(주: ${bm[1]})` });
|
|
28183
28201
|
const r = removeNoteMarks(body, marks);
|
|
28184
28202
|
if (r.missing.length) skipped.push({ reason: "각주 참조 부호 삭제는 미지원 — 각주 유지, 본문만 적용", before: r.missing.join(" ") });
|
|
28185
28203
|
return { before: removeNoteMarks(before2.slice(0, bm.index).trimEnd(), marks).text, after: r.text, noted: true };
|
|
28186
28204
|
}
|
|
28187
|
-
|
|
28205
|
+
function planNoteEdits(origNote, newNote, bodies) {
|
|
28206
|
+
const orig = normForMatch(origNote);
|
|
28207
|
+
const heads = [];
|
|
28208
|
+
let pos = 0;
|
|
28209
|
+
for (const body of bodies) {
|
|
28210
|
+
const key3 = normForMatch(body);
|
|
28211
|
+
const at = key3 ? orig.indexOf(key3, pos) : -1;
|
|
28212
|
+
if (at < 0) return NOTE_TEXT_UNSUPPORTED;
|
|
28213
|
+
heads.push(orig.slice(pos, at));
|
|
28214
|
+
pos = at + key3.length;
|
|
28215
|
+
}
|
|
28216
|
+
if (!bodies.length || pos !== orig.length || heads.some((h, k) => k > 0 && !h.startsWith("; "))) return NOTE_TEXT_UNSUPPORTED;
|
|
28217
|
+
const split = (text) => {
|
|
28218
|
+
const out = [];
|
|
28219
|
+
let p = 0;
|
|
28220
|
+
for (let k = 0; k < heads.length; k++) {
|
|
28221
|
+
if (!text.startsWith(heads[k], p)) return null;
|
|
28222
|
+
p += heads[k].length;
|
|
28223
|
+
const next = k + 1 < heads.length ? text.indexOf(heads[k + 1], p) : text.length;
|
|
28224
|
+
if (next < 0) return null;
|
|
28225
|
+
out.push(text.slice(p, next));
|
|
28226
|
+
p = next;
|
|
28227
|
+
}
|
|
28228
|
+
return out;
|
|
28229
|
+
};
|
|
28230
|
+
const before2 = split(orig);
|
|
28231
|
+
if (!before2 || before2.some((b, k) => b !== normForMatch(bodies[k]))) return NOTE_TEXT_UNSUPPORTED;
|
|
28232
|
+
const after2 = split(newNote.replace(/\s+/g, " ").trim());
|
|
28233
|
+
if (!after2) return "각주 번호 수정·각주 추가·삭제는 미지원 — 각주 글 수정 미적용";
|
|
28234
|
+
const edits = [];
|
|
28235
|
+
for (let k = 0; k < before2.length; k++) {
|
|
28236
|
+
if (normForMatch(after2[k]) === before2[k]) continue;
|
|
28237
|
+
if (!after2[k].trim()) return "각주 글 비우기는 미지원 — 각주 글 수정 미적용";
|
|
28238
|
+
if (sanitizeText(after2[k]) !== after2[k]) return "공백 정규화 불안정 텍스트 — 각주 글 수정 미적용";
|
|
28239
|
+
edits.push({ index: k, before: before2[k], after: after2[k] });
|
|
28240
|
+
}
|
|
28241
|
+
return edits;
|
|
28242
|
+
}
|
|
28243
|
+
function noteParaEdit(paraTexts, before2, after2) {
|
|
28244
|
+
if (paraTexts.length === 1) return { index: 0, before: before2, after: after2 };
|
|
28245
|
+
if (!paraTexts.length || before2 !== paraTexts.join(" ")) return null;
|
|
28246
|
+
let p = 0;
|
|
28247
|
+
while (p < before2.length && p < after2.length && before2[p] === after2[p]) p++;
|
|
28248
|
+
let s = 0;
|
|
28249
|
+
while (s < before2.length - p && s < after2.length - p && before2[before2.length - 1 - s] === after2[after2.length - 1 - s]) s++;
|
|
28250
|
+
let off = 0;
|
|
28251
|
+
for (let i = 0; i < paraTexts.length; i++) {
|
|
28252
|
+
const end = off + paraTexts[i].length;
|
|
28253
|
+
if (off <= p && before2.length - s <= end) return { index: i, before: paraTexts[i], after: after2.slice(off, after2.length - (before2.length - end)) };
|
|
28254
|
+
off = end + 1;
|
|
28255
|
+
}
|
|
28256
|
+
return null;
|
|
28257
|
+
}
|
|
28258
|
+
var AUTOLINK, AUTONUM_PREFIX_RE, LAYOUT_MODE_MISMATCH, NOTE_TEXT_UNSUPPORTED;
|
|
28188
28259
|
var init_markdown_units = __esm({
|
|
28189
28260
|
"src/roundtrip/markdown-units.ts"() {
|
|
28190
28261
|
"use strict";
|
|
@@ -28195,6 +28266,7 @@ var init_markdown_units = __esm({
|
|
|
28195
28266
|
AUTOLINK = /(?<!\\)<(https?:\/\/[^\s<>]*)>/gi;
|
|
28196
28267
|
AUTONUM_PREFIX_RE = /^(?:[0-90-9a-zA-Z가-힣]{1,6}[.)\]:]|[([][0-90-9a-zA-Z가-힣]{1,6}[)\]][.:]?|[ⅰ-ⅹⅠ-Ⅹ①-⑮][.)\]:]?)$/u;
|
|
28197
28268
|
LAYOUT_MODE_MISMATCH = '편집 마크다운이 기본(보이는 대로) 출력에서 나왔습니다. 이 문서에는 테두리가 안 보이는 틀 표가 있어 그 출력으로는 원본 위치를 찾을 수 없습니다 — `kordoc <원본> --keep-layout-tables`(API: parse(원본, { layoutTables: "keep" }))로 뽑은 마크다운을 고쳐 다시 패치하세요';
|
|
28269
|
+
NOTE_TEXT_UNSUPPORTED = "각주 텍스트 수정은 미지원 — 본문만 적용";
|
|
28198
28270
|
}
|
|
28199
28271
|
});
|
|
28200
28272
|
|
|
@@ -31068,6 +31140,220 @@ function stackedGlyphBands(gray, w, h, ink) {
|
|
|
31068
31140
|
const bands = splitRowBands(gray, w, h, ink, 0.45);
|
|
31069
31141
|
return bands.length >= 2 && bands.length <= 4 ? bands : null;
|
|
31070
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
|
+
}
|
|
31071
31357
|
var BRACKET_TAPER, BRACKET_SOLID, BRACKET_WIDE, BRACKET_LENS, STACK_INK_RATIO;
|
|
31072
31358
|
var init_line_split = __esm({
|
|
31073
31359
|
"src/ocr/line-split.ts"() {
|
|
@@ -31149,8 +31435,82 @@ function restoreGlyphs(rgba, pageW, box, text, steps, stepPx, note = {}, rings =
|
|
|
31149
31435
|
if (prev !== void 0) chars2[prev] += r.glyph;
|
|
31150
31436
|
else if (live.length) chars2[live[0]] = r.glyph + chars2[live[0]];
|
|
31151
31437
|
});
|
|
31438
|
+
checkboxes(c);
|
|
31152
31439
|
return chars2.join("");
|
|
31153
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
|
+
}
|
|
31154
31514
|
function trimInklessEnds(rgba, pageW, box, text, steps, stepPx) {
|
|
31155
31515
|
const chars2 = [...text], { w, h } = box;
|
|
31156
31516
|
if (chars2.length !== steps.length || steps.some((s) => (s + 0.5) * stepPx > w + stepPx)) return { text, steps };
|
|
@@ -31439,7 +31799,7 @@ function roman({ chars: chars2, cx, gray, w, h, ink }) {
|
|
|
31439
31799
|
s = e;
|
|
31440
31800
|
}
|
|
31441
31801
|
}
|
|
31442
|
-
var INKLESS_DELTA, RING_JAMO, RING_SYLLABLE;
|
|
31802
|
+
var INKLESS_DELTA, RING_JAMO, RING_SYLLABLE, BOX_READ, BOX_LETTER, BOX_AMBIGUOUS, BOX_KEPT;
|
|
31443
31803
|
var init_glyph_restore = __esm({
|
|
31444
31804
|
"src/ocr/glyph-restore.ts"() {
|
|
31445
31805
|
"use strict";
|
|
@@ -31447,6 +31807,10 @@ var init_glyph_restore = __esm({
|
|
|
31447
31807
|
INKLESS_DELTA = 32;
|
|
31448
31808
|
RING_JAMO = "ㄱㄴㄷㄹㅁㅂㅅㅇㅈㅊㅋㅌㅍㅎ";
|
|
31449
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;
|
|
31450
31814
|
}
|
|
31451
31815
|
});
|
|
31452
31816
|
|
|
@@ -37984,7 +38348,8 @@ function collapseEvenSpacing(text, whole = true) {
|
|
|
37984
38348
|
const tokens = text.split(" ");
|
|
37985
38349
|
const visible = tokens.map((t) => t.replace(/<\/?u>|~~/g, ""));
|
|
37986
38350
|
const singleCharCount = visible.filter((t) => t.length === 1).length;
|
|
37987
|
-
|
|
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("");
|
|
37988
38353
|
}
|
|
37989
38354
|
return text.replace(
|
|
37990
38355
|
/(?<![^\s>])[가-힣](?: [가-힣\d]){2,}(?![^\s<])/g,
|
|
@@ -37993,6 +38358,12 @@ function collapseEvenSpacing(text, whole = true) {
|
|
|
37993
38358
|
const after2 = text.slice(offset + match.length).replace(/^(?:<\/?u>|~~)+/, "");
|
|
37994
38359
|
if (/\S$/.test(before2) || /^\S/.test(after2)) return match;
|
|
37995
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
|
+
}
|
|
37996
38367
|
const parts = match.split(/ 및 (?=[가-힣\d])/);
|
|
37997
38368
|
return parts.length > 1 ? parts.map((p) => p.replace(/ /g, "")).join(" 및 ") : match.replace(/ /g, "");
|
|
37998
38369
|
}
|
|
@@ -44862,6 +45233,17 @@ function extractPageBlocksWithLines(items, pageNum, opList, pageWidth, pageHeigh
|
|
|
44862
45233
|
}
|
|
44863
45234
|
}
|
|
44864
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
|
+
}
|
|
44865
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))) {
|
|
44866
45248
|
return ruledColumnBlocks(items, horizontals, verticals, pageWidth, pageHeight, pageNum, detectTables, lex) ?? extractPageBlocksFallback(items, pageNum, true, detectTables, lex, figures());
|
|
44867
45249
|
}
|
|
@@ -81564,6 +81946,30 @@ var init_embedded_line_patch = __esm({
|
|
|
81564
81946
|
}
|
|
81565
81947
|
});
|
|
81566
81948
|
|
|
81949
|
+
// src/roundtrip/note-edit.ts
|
|
81950
|
+
function noteEditSplices(host2, xml, origNote, newNote) {
|
|
81951
|
+
if (!host2.notes?.length || xml === void 0) return NOTE_TEXT_UNSUPPORTED;
|
|
81952
|
+
const plan = planNoteEdits(origNote, newNote, host2.notes.map((paras) => paras.map((p) => p.text).join(" ")));
|
|
81953
|
+
if (typeof plan === "string") return plan;
|
|
81954
|
+
const out = [];
|
|
81955
|
+
for (const edit of plan) {
|
|
81956
|
+
const paras = host2.notes[edit.index].filter((p) => normForMatch(p.text) !== "");
|
|
81957
|
+
const one = noteParaEdit(paras.map((p) => normForMatch(p.text)), edit.before, edit.after);
|
|
81958
|
+
if (!one) return "각주의 여러 문단에 걸친 수정은 미지원 — 각주 글 수정 미적용";
|
|
81959
|
+
const sp = minimalTextSplices(paras[one.index], xml, one.before, one.after);
|
|
81960
|
+
if (!sp) return "각주 문단을 원문과 맞대지 못함 — 각주 글 수정 미적용";
|
|
81961
|
+
out.push(...sp);
|
|
81962
|
+
}
|
|
81963
|
+
return out;
|
|
81964
|
+
}
|
|
81965
|
+
var init_note_edit = __esm({
|
|
81966
|
+
"src/roundtrip/note-edit.ts"() {
|
|
81967
|
+
"use strict";
|
|
81968
|
+
init_inline_edit();
|
|
81969
|
+
init_markdown_units();
|
|
81970
|
+
}
|
|
81971
|
+
});
|
|
81972
|
+
|
|
81567
81973
|
// src/roundtrip/table-patch.ts
|
|
81568
81974
|
function patchGfmTable(table2, scanTable, orig, edited, ctx, skip) {
|
|
81569
81975
|
const replica = replicateGfmTable(table2);
|
|
@@ -81815,17 +82221,31 @@ function patchTextChunkTable(table2, scanTable, orig, edited, ctx, skip) {
|
|
|
81815
82221
|
return skip("표 렌더 경로 식별 실패");
|
|
81816
82222
|
}
|
|
81817
82223
|
function applyCellEdit(table2, scanTable, gridR, gridC, newLines, ctx, before2, after2, origLineCount) {
|
|
82224
|
+
let noteApplied = false;
|
|
81818
82225
|
const skip = (reason) => {
|
|
81819
82226
|
ctx.skipped.push({ reason, before: summarize(before2), after: summarize(after2) });
|
|
81820
|
-
return 0;
|
|
82227
|
+
return noteApplied ? 1 : 0;
|
|
81821
82228
|
};
|
|
81822
82229
|
const cell2 = scanTable.cellByAnchor.get(`${gridR},${gridC}`);
|
|
81823
82230
|
if (!cell2) return skip("셀 좌표 매핑 실패 (병합 영역의 빈 칸이거나 좌표 불일치)");
|
|
81824
82231
|
const origLines = gfmCellLines(before2);
|
|
81825
82232
|
if (origLines.some((l) => /\(주: [\s\S]*\)$/.test(l)) && origLines.length === newLines.length) {
|
|
81826
|
-
const
|
|
82233
|
+
const hosts = cell2.paragraphs.filter((p) => p.notes?.length);
|
|
82234
|
+
const notedLines = origLines.map((l, i) => /\(주: [\s\S]*\)$/.test(l) ? i : -1).filter((i) => i >= 0);
|
|
82235
|
+
const notes = newLines.map((l, i) => splitCellNote(origLines[i], l, ctx.skipped, (origNote, newNote) => {
|
|
82236
|
+
const host2 = hosts.length === notedLines.length ? hosts[notedLines.indexOf(i)] : void 0;
|
|
82237
|
+
if (!host2) return false;
|
|
82238
|
+
const sp = noteEditSplices(host2, ctx.scans[host2.sectionIndex]?.xml, origNote, newNote);
|
|
82239
|
+
if (typeof sp === "string") ctx.skipped.push({ reason: sp, before: origNote, after: newNote });
|
|
82240
|
+
else if (sp.length) {
|
|
82241
|
+
ctx.sectionSplices[host2.sectionIndex].push(...sp);
|
|
82242
|
+
noteApplied = true;
|
|
82243
|
+
}
|
|
82244
|
+
return true;
|
|
82245
|
+
}));
|
|
81827
82246
|
newLines = notes.map((n) => n.after);
|
|
81828
82247
|
before2 = notes.map((n) => n.before).join("<br>");
|
|
82248
|
+
if (notes.every((n) => normForMatch(n.before) === normForMatch(n.after))) return noteApplied ? 1 : 0;
|
|
81829
82249
|
}
|
|
81830
82250
|
const irCell = table2.cells[gridR]?.[gridC];
|
|
81831
82251
|
const scanJoined = cell2.paragraphs.map((p) => p.text).filter((t) => normForMatch(t)).join("\n");
|
|
@@ -81936,7 +82356,7 @@ function applyCellEdit(table2, scanTable, gridR, gridC, newLines, ctx, before2,
|
|
|
81936
82356
|
sectionIndex = nonEmpty[i].sectionIndex;
|
|
81937
82357
|
}
|
|
81938
82358
|
}
|
|
81939
|
-
if (splices.length === 0) return 0;
|
|
82359
|
+
if (splices.length === 0) return noteApplied ? 1 : 0;
|
|
81940
82360
|
ctx.sectionSplices[sectionIndex].push(...splices);
|
|
81941
82361
|
if (emphMissed) ctx.skipped.push({ reason: EMPHASIS_NOTE, before: summarize(before2), after: summarize(after2), partial: true });
|
|
81942
82362
|
return 1;
|
|
@@ -81953,6 +82373,7 @@ var init_table_patch = __esm({
|
|
|
81953
82373
|
init_recognize();
|
|
81954
82374
|
init_builder();
|
|
81955
82375
|
init_click_here();
|
|
82376
|
+
init_note_edit();
|
|
81956
82377
|
init_structure_edit();
|
|
81957
82378
|
EMPHASIS_NOTE = "강조(굵게·밑줄 등) 추가·삭제는 미지원: 글만 적용, 원문 글자 모양 유지";
|
|
81958
82379
|
CELL_TOKEN_RE = /!\[image\]\([^)]*\)|\[이미지: [^\]]*\]/g;
|
|
@@ -83261,6 +83682,17 @@ function scanSection(stream, sectionIndex, compressed) {
|
|
|
83261
83682
|
paras.push(para2);
|
|
83262
83683
|
parasByHeader.set(i, para2);
|
|
83263
83684
|
}
|
|
83685
|
+
for (let i = 0; i < records.length; i++) {
|
|
83686
|
+
if (!isCtrl(records[i], CTRL_FN2) && !isCtrl(records[i], CTRL_EN2)) continue;
|
|
83687
|
+
const host2 = parent[i] >= 0 ? parasByHeader.get(parent[i]) : void 0;
|
|
83688
|
+
if (!host2) continue;
|
|
83689
|
+
const list = [];
|
|
83690
|
+
for (let j = i + 1; j < records.length && records[j].level > records[i].level; j++) {
|
|
83691
|
+
const np = parent[j] === i ? parasByHeader.get(j) : void 0;
|
|
83692
|
+
if (np) list.push(np);
|
|
83693
|
+
}
|
|
83694
|
+
(host2.notes ??= []).push(list);
|
|
83695
|
+
}
|
|
83264
83696
|
const scanTable = (i, depth) => {
|
|
83265
83697
|
const ctrlLevel = records[i].level;
|
|
83266
83698
|
let rows = 0, cols = 0, tableIdx = -1;
|
|
@@ -83681,12 +84113,14 @@ function patchParagraph(block, orig, edited, ctx, skip) {
|
|
|
83681
84113
|
return skip("다중줄 문단 수정에 <br> 없음 — 줄바꿈 위치 보존 불가로 미지원 (줄바꿈은 <br>로 표기)");
|
|
83682
84114
|
}
|
|
83683
84115
|
let noteEdited = false;
|
|
84116
|
+
let noteApplied = false;
|
|
83684
84117
|
if (block.footnoteText) {
|
|
83685
84118
|
const noteMatch = newPlain.match(/\s*\(주: ([\s\S]*)\)$/);
|
|
83686
84119
|
if (noteMatch) {
|
|
83687
84120
|
newPlain = newPlain.slice(0, noteMatch.index).trimEnd();
|
|
83688
84121
|
if (normForMatch(noteMatch[1]) !== normForMatch(block.footnoteText)) {
|
|
83689
|
-
|
|
84122
|
+
noteApplied = !block.footnoteBlocks && stageNoteEdit(mapping.para, block.footnoteText, noteMatch[1], ctx);
|
|
84123
|
+
if (block.footnoteBlocks) ctx.skipped.push({ reason: NOTE_TEXT_UNSUPPORTED, before: block.footnoteText, after: noteMatch[1] });
|
|
83690
84124
|
noteEdited = true;
|
|
83691
84125
|
}
|
|
83692
84126
|
} else {
|
|
@@ -83705,9 +84139,9 @@ function patchParagraph(block, orig, edited, ctx, skip) {
|
|
|
83705
84139
|
}
|
|
83706
84140
|
let origPlain = block.text != null ? noScriptTags(block.text) : restoreBr(origStyled.plain);
|
|
83707
84141
|
if (mapping.noteMarks?.length) origPlain = removeNoteMarks(origPlain, mapping.noteMarks).text;
|
|
83708
|
-
if (newPlain === origPlain) return noteEdited ? 0 : skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
|
|
84142
|
+
if (newPlain === origPlain) return noteEdited ? noteApplied ? 1 : 0 : skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
|
|
83709
84143
|
if (sanitizeText(newPlain) !== newPlain && sanitizeText(origPlain) === origPlain) {
|
|
83710
|
-
return skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원");
|
|
84144
|
+
return Math.max(skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원"), noteApplied ? 1 : 0);
|
|
83711
84145
|
}
|
|
83712
84146
|
let origMd = restoreBr(origStyled.plain);
|
|
83713
84147
|
if (block.footnoteText) origMd = origMd.replace(/\s*\(주: [\s\S]*\)$/, "");
|
|
@@ -83719,7 +84153,28 @@ function patchParagraph(block, orig, edited, ctx, skip) {
|
|
|
83719
84153
|
if (n && (style2?.missed || style2 && restyledKept(origStyled, editedStyled, origStyled.plain, editedStyled.plain))) {
|
|
83720
84154
|
ctx.skipped.push({ reason: EMPHASIS_NOTE, before: summarize(orig.raw), after: summarize(edited.raw), partial: true });
|
|
83721
84155
|
}
|
|
83722
|
-
return n;
|
|
84156
|
+
return Math.max(n, noteApplied ? 1 : 0);
|
|
84157
|
+
}
|
|
84158
|
+
function stageNoteEdit(host2, origNote, newNote, ctx) {
|
|
84159
|
+
const note = (reason) => {
|
|
84160
|
+
ctx.skipped.push({ reason, before: summarize(origNote), after: summarize(newNote) });
|
|
84161
|
+
return 0;
|
|
84162
|
+
};
|
|
84163
|
+
if (!host2.notes?.length) return note(NOTE_TEXT_UNSUPPORTED) > 0;
|
|
84164
|
+
const plan = planNoteEdits(origNote, newNote, host2.notes.map((paras) => paras.map((p) => p.rawText).join(" ")));
|
|
84165
|
+
if (typeof plan === "string") return note(plan) > 0;
|
|
84166
|
+
let staged = 0;
|
|
84167
|
+
for (const edit of plan) {
|
|
84168
|
+
const paras = host2.notes[edit.index].filter((p) => normForMatch(p.rawText) !== "");
|
|
84169
|
+
const one = noteParaEdit(paras.map((p) => normForMatch(p.rawText)), edit.before, edit.after);
|
|
84170
|
+
if (!one) {
|
|
84171
|
+
note("각주의 여러 문단에 걸친 수정은 미지원 — 각주 글 수정 미적용");
|
|
84172
|
+
continue;
|
|
84173
|
+
}
|
|
84174
|
+
const para2 = paras[one.index];
|
|
84175
|
+
staged += stageParaPatch(ctx.scans[para2.sectionIndex], para2, one.after, note, ctx.keepLineseg, one.before);
|
|
84176
|
+
}
|
|
84177
|
+
return staged > 0;
|
|
83723
84178
|
}
|
|
83724
84179
|
function patchGfmCells(scanTable, orig, edited, ctx, skip) {
|
|
83725
84180
|
const origRows = parseGfmTable(orig.lines);
|
|
@@ -83750,18 +84205,27 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
|
|
|
83750
84205
|
continue;
|
|
83751
84206
|
}
|
|
83752
84207
|
if (beforeEach.join("\n") === afterEach.join("\n")) continue;
|
|
83753
|
-
const { before: before2, after: after2, noted } = splitCellNote(beforeEach.join("\n"), afterEach.join("\n"), ctx.skipped);
|
|
83754
|
-
if (before2 === after2) continue;
|
|
83755
84208
|
const para2 = cell2.paras[0];
|
|
84209
|
+
let noteDone = 0;
|
|
84210
|
+
const { before: before2, after: after2, noted } = splitCellNote(beforeEach.join("\n"), afterEach.join("\n"), ctx.skipped, (o, n) => {
|
|
84211
|
+
if (stageNoteEdit(para2, o, n, ctx)) noteDone = 1;
|
|
84212
|
+
return true;
|
|
84213
|
+
});
|
|
84214
|
+
if (before2 === after2) {
|
|
84215
|
+
applied += noteDone;
|
|
84216
|
+
continue;
|
|
84217
|
+
}
|
|
83756
84218
|
if (normForMatch(para2.rawText) !== normForMatch(before2)) {
|
|
83757
84219
|
cellSkip("셀 텍스트 불일치 — 소스맵 신뢰 불가");
|
|
84220
|
+
applied += noteDone;
|
|
83758
84221
|
continue;
|
|
83759
84222
|
}
|
|
83760
84223
|
if (afterEach.some((l) => sanitizeText(l) !== l)) {
|
|
83761
84224
|
cellSkip("공백 정규화 불안정 텍스트 — 미지원");
|
|
84225
|
+
applied += noteDone;
|
|
83762
84226
|
continue;
|
|
83763
84227
|
}
|
|
83764
|
-
applied += stageParaPatch(
|
|
84228
|
+
applied += Math.max(noteDone, stageParaPatch(
|
|
83765
84229
|
ctx.scans[para2.sectionIndex],
|
|
83766
84230
|
para2,
|
|
83767
84231
|
after2,
|
|
@@ -83770,7 +84234,7 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
|
|
|
83770
84234
|
before2,
|
|
83771
84235
|
// 바뀐 자리만 — 굵은 조각 등 run 유지
|
|
83772
84236
|
noted ? void 0 : cellLineStyles(origRows[r][c], editedRows[r][c], ctx.charBook)(0, after2)
|
|
83773
|
-
);
|
|
84237
|
+
));
|
|
83774
84238
|
continue;
|
|
83775
84239
|
}
|
|
83776
84240
|
if (beforeParts.length !== cell2.paras.length || afterParts.length !== cell2.paras.length) {
|
|
@@ -83785,22 +84249,32 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
|
|
|
83785
84249
|
break;
|
|
83786
84250
|
}
|
|
83787
84251
|
if (rawBefore === rawAfter) continue;
|
|
83788
|
-
const
|
|
83789
|
-
|
|
84252
|
+
const para2 = cell2.paras[k];
|
|
84253
|
+
let noteDone = 0;
|
|
84254
|
+
const { before: before2, after: after2, noted } = splitCellNote(rawBefore, rawAfter, ctx.skipped, (o, n) => {
|
|
84255
|
+
if (stageNoteEdit(para2, o, n, ctx)) noteDone = 1;
|
|
84256
|
+
return true;
|
|
84257
|
+
});
|
|
84258
|
+
if (before2 === after2) {
|
|
84259
|
+
applied += noteDone;
|
|
84260
|
+
continue;
|
|
84261
|
+
}
|
|
83790
84262
|
if (after2.includes("\n")) {
|
|
83791
84263
|
cellSkip("셀 내 줄바꿈 추가는 미지원 (v1)");
|
|
84264
|
+
applied += noteDone;
|
|
83792
84265
|
break;
|
|
83793
84266
|
}
|
|
83794
|
-
const para2 = cell2.paras[k];
|
|
83795
84267
|
if (normForMatch(para2.rawText) !== normForMatch(before2)) {
|
|
83796
84268
|
cellSkip("셀 텍스트 불일치 — 소스맵 신뢰 불가");
|
|
84269
|
+
applied += noteDone;
|
|
83797
84270
|
break;
|
|
83798
84271
|
}
|
|
83799
84272
|
if (sanitizeText(after2) !== after2) {
|
|
83800
84273
|
cellSkip("공백 정규화 불안정 텍스트 — 미지원");
|
|
84274
|
+
applied += noteDone;
|
|
83801
84275
|
break;
|
|
83802
84276
|
}
|
|
83803
|
-
applied += stageParaPatch(
|
|
84277
|
+
applied += Math.max(noteDone, stageParaPatch(
|
|
83804
84278
|
ctx.scans[para2.sectionIndex],
|
|
83805
84279
|
para2,
|
|
83806
84280
|
after2,
|
|
@@ -83809,7 +84283,7 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
|
|
|
83809
84283
|
before2,
|
|
83810
84284
|
// 바뀐 자리만 — 굵은 조각 등 run 유지
|
|
83811
84285
|
noted ? void 0 : cellLineStyles(origRows[r][c], editedRows[r][c], ctx.charBook)(k, after2)
|
|
83812
|
-
);
|
|
84286
|
+
));
|
|
83813
84287
|
}
|
|
83814
84288
|
}
|
|
83815
84289
|
}
|
|
@@ -83992,7 +84466,7 @@ function compressWithTail(raw) {
|
|
|
83992
84466
|
tail.writeUInt32LE(raw.length >>> 0, 4);
|
|
83993
84467
|
return Buffer.concat([(0, import_zlib8.deflateRawSync)(raw), tail]);
|
|
83994
84468
|
}
|
|
83995
|
-
var import_zlib8, import_module3, require4, CFB3, TAG_PARA_LINE_SEG2, CTRL_TBL2, CTRL_GSO2, CRC_TABLE3;
|
|
84469
|
+
var import_zlib8, import_module3, require4, CFB3, TAG_PARA_LINE_SEG2, CTRL_TBL2, CTRL_GSO2, CTRL_FN2, CTRL_EN2, CRC_TABLE3;
|
|
83996
84470
|
var init_hwp5_patch = __esm({
|
|
83997
84471
|
"src/roundtrip/hwp5-patch.ts"() {
|
|
83998
84472
|
"use strict";
|
|
@@ -84016,6 +84490,8 @@ var init_hwp5_patch = __esm({
|
|
|
84016
84490
|
TAG_PARA_LINE_SEG2 = 69;
|
|
84017
84491
|
CTRL_TBL2 = cid2("tbl ");
|
|
84018
84492
|
CTRL_GSO2 = cid2("gso ");
|
|
84493
|
+
CTRL_FN2 = cid2("fn ");
|
|
84494
|
+
CTRL_EN2 = cid2("en ");
|
|
84019
84495
|
CRC_TABLE3 = (() => {
|
|
84020
84496
|
const t = new Uint32Array(256);
|
|
84021
84497
|
for (let n = 0; n < 256; n++) {
|
|
@@ -84594,14 +85070,21 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
|
|
|
84594
85070
|
let newPlain = newInline.plain;
|
|
84595
85071
|
const segsUsable = !block.footnoteText && !mapping.noteMarks?.length && !mapping.prefixStripped;
|
|
84596
85072
|
let noteEdited = false;
|
|
85073
|
+
let noteApplied = false;
|
|
84597
85074
|
if (block.footnoteText) {
|
|
84598
|
-
const
|
|
85075
|
+
const mdNote = origPlain.match(/\s*\(주: ([\s\S]*)\)$/)?.[1];
|
|
85076
|
+
const origNote = block.footnoteBlocks ? mdNote : void 0;
|
|
84599
85077
|
origPlain = origPlain.replace(/\s*\(주: [\s\S]*\)$/, "");
|
|
84600
85078
|
const noteMatch = newPlain.match(/\s*\(주: ([\s\S]*)\)$/);
|
|
84601
85079
|
if (noteMatch) {
|
|
84602
85080
|
newPlain = newPlain.slice(0, noteMatch.index).trimEnd();
|
|
84603
85081
|
if (normForMatch(noteMatch[1]) !== normForMatch(origNote ?? block.footnoteText)) {
|
|
84604
|
-
|
|
85082
|
+
const sp = block.footnoteBlocks ? NOTE_TEXT_UNSUPPORTED : noteEditSplices(mapping.para, ctx.scans[mapping.para.sectionIndex]?.xml, mdNote ?? block.footnoteText, noteMatch[1]);
|
|
85083
|
+
if (typeof sp === "string") ctx.skipped.push({ reason: sp, before: block.footnoteText, after: noteMatch[1] });
|
|
85084
|
+
else if (sp.length) {
|
|
85085
|
+
ctx.sectionSplices[mapping.para.sectionIndex].push(...sp);
|
|
85086
|
+
noteApplied = true;
|
|
85087
|
+
}
|
|
84605
85088
|
noteEdited = true;
|
|
84606
85089
|
}
|
|
84607
85090
|
} else {
|
|
@@ -84620,9 +85103,12 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
|
|
|
84620
85103
|
newPlain = head.text;
|
|
84621
85104
|
if (head.note) ctx.skipped.push({ reason: head.note, after: summarize(newPlain), partial: true });
|
|
84622
85105
|
}
|
|
84623
|
-
if (newPlain === origPlain)
|
|
85106
|
+
if (newPlain === origPlain) {
|
|
85107
|
+
if (!noteEdited) return skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
|
|
85108
|
+
return noteApplied ? 1 : 0;
|
|
85109
|
+
}
|
|
84624
85110
|
if (sanitizeText(newPlain) !== newPlain && sanitizeText(origPlain) === origPlain) {
|
|
84625
|
-
return skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원");
|
|
85111
|
+
return Math.max(skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원"), noteApplied ? 1 : 0);
|
|
84626
85112
|
}
|
|
84627
85113
|
const xml = ctx.scans[mapping.para.sectionIndex]?.xml;
|
|
84628
85114
|
const book = ctx.charBook;
|
|
@@ -84635,7 +85121,7 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
|
|
|
84635
85121
|
} : void 0;
|
|
84636
85122
|
const minimal = xml ? minimalTextSplices(mapping.para, xml, origPlain, newPlain, segsUsable ? origInline.segs : void 0, segsUsable ? newInline.segs : void 0, style2) : null;
|
|
84637
85123
|
const splices = (xml ? clickHereEditSplices(mapping.para, xml, origPlain, newPlain) : null) ?? minimal ?? (xml ? markerRunSplices(mapping.para, xml, newPlain) : null) ?? buildParagraphSplices(mapping.para, newPlain, xml);
|
|
84638
|
-
if (splices === null) return skip("문단에 텍스트 노드를 만들 수 없음");
|
|
85124
|
+
if (splices === null) return Math.max(skip("문단에 텍스트 노드를 만들 수 없음"), noteApplied ? 1 : 0);
|
|
84639
85125
|
ctx.sectionSplices[mapping.para.sectionIndex].push(...splices);
|
|
84640
85126
|
if (origInline.segs.length !== newInline.segs.length && (!minimal || !style2 || style2.missed || restyledKept(origInline, newInline, origInline.plain, newInline.plain))) {
|
|
84641
85127
|
ctx.skipped.push({ reason: EMPHASIS_NOTE, before: summarize(orig.raw), after: summarize(edited.raw), partial: true });
|
|
@@ -84754,6 +85240,7 @@ var init_patcher = __esm({
|
|
|
84754
85240
|
init_inline_edit();
|
|
84755
85241
|
init_char_pr();
|
|
84756
85242
|
init_click_here();
|
|
85243
|
+
init_note_edit();
|
|
84757
85244
|
init_line_break_edit();
|
|
84758
85245
|
init_text_fallback();
|
|
84759
85246
|
init_parser_shared();
|