kordoc 4.25.19 → 4.25.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/README.md +3 -3
  2. package/dist/{chunk-CZFY7JGT.js → chunk-24LB25LZ.js} +2 -2
  3. package/dist/{chunk-HKO6HWYM.js → chunk-3AYNFK6J.js} +2 -2
  4. package/dist/{chunk-74QGGXVH.js → chunk-5MDRUEHP.js} +14 -4
  5. package/dist/chunk-5MDRUEHP.js.map +1 -0
  6. package/dist/{chunk-PCOKS4ZE.js → chunk-5PEMTYTM.js} +37 -10
  7. package/dist/chunk-5PEMTYTM.js.map +7 -0
  8. package/dist/{chunk-LQGZ3PBZ.js → chunk-5ULHNZ3P.js} +3 -3
  9. package/dist/{chunk-EFBIMFVT.js → chunk-6I3X54AQ.js} +2 -2
  10. package/dist/{chunk-HH5IOQTP.js → chunk-6MCJHRSM.js} +2 -2
  11. package/dist/{chunk-NCO7BAS7.js → chunk-COJYQKGH.js} +6 -4
  12. package/dist/{chunk-NCO7BAS7.js.map → chunk-COJYQKGH.js.map} +2 -2
  13. package/dist/{chunk-TPPL3OVT.js → chunk-DHXKCDAU.js} +50 -6
  14. package/dist/chunk-DHXKCDAU.js.map +7 -0
  15. package/dist/{chunk-UTLVAA7X.js → chunk-DZOA5N5W.js} +2 -2
  16. package/dist/{chunk-HCHWG3HO.js → chunk-FDSFXE2L.js} +3 -3
  17. package/dist/{chunk-ZCDTZZ3C.js → chunk-GJORKM42.js} +2 -2
  18. package/dist/{chunk-VOK3R4WW.js → chunk-HQILGS2O.js} +2 -2
  19. package/dist/{chunk-FCWPQZYU.js → chunk-KW4JO5CV.js} +3 -3
  20. package/dist/{chunk-EI4PBZW2.js → chunk-LSUTK3DH.js} +2 -2
  21. package/dist/{chunk-FZ7XCPHO.js → chunk-MWCJYIJC.js} +20 -20
  22. package/dist/{chunk-6YQ2LARO.js → chunk-PFNZQ3XI.js} +2 -2
  23. package/dist/{chunk-XCD6WLTU.js → chunk-PVOLFVXE.js} +3 -3
  24. package/dist/{chunk-FNMJ2DK4.js → chunk-QNJ2LMUO.js} +8 -8
  25. package/dist/{chunk-VVR2ZSFZ.js → chunk-QOCUFTT4.js} +4 -4
  26. package/dist/{chunk-3DX4GW75.js → chunk-S553BW45.js} +6 -6
  27. package/dist/{chunk-IUD535LX.js → chunk-TI6S3KZF.js} +2 -2
  28. package/dist/{chunk-RECWLRRB.js → chunk-TYJSNW4Z.js} +55 -46
  29. package/dist/chunk-TYJSNW4Z.js.map +7 -0
  30. package/dist/{chunk-LEWJRIVZ.js → chunk-W5AHXAUP.js} +6 -6
  31. package/dist/{chunk-TW6WYJD6.js → chunk-XUBBFY3H.js} +6 -6
  32. package/dist/{chunk-LXPFTU3C.js → chunk-ZCMMU34Z.js} +2 -2
  33. package/dist/{chunk-IVNUMREN.js → chunk-ZO4P735U.js} +2 -2
  34. package/dist/chunks-XX7RHVQF.js +10 -0
  35. package/dist/cli.js +38 -38
  36. package/dist/{formula-U2RXOOE4.js → formula-HMKT4BZL.js} +4 -4
  37. package/dist/{generator-K6I6IYOH.js → generator-HOY4SZ26.js} +7 -7
  38. package/dist/{hancom-ARDTLWD5.js → hancom-QWJBWOOE.js} +2 -2
  39. package/dist/{image-ocr-RDWOEEQ2.js → image-ocr-P5AIZNT3.js} +12 -12
  40. package/dist/index.cjs +211 -89
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.js +22 -22
  43. package/dist/mcp.js +34 -34
  44. package/dist/memo-Q7772VJD.js +15 -0
  45. package/dist/{model-bundle-A6C5PVSS.js → model-bundle-5CXCIZHZ.js} +5 -5
  46. package/dist/{models-KTY3IZU2.js → models-PS4L7NLP.js} +5 -5
  47. package/dist/{page-images-PVXQYU7Z.js → page-images-QW7IUTUB.js} +3 -3
  48. package/dist/{parse-worker-v2-E4T4427H.js → parse-worker-v2-PRH6KVKP.js} +24 -24
  49. package/dist/{parser-3F66AQAA.js → parser-OQIR5ZMI.js} +97 -58
  50. package/dist/{parser-3F66AQAA.js.map → parser-OQIR5ZMI.js.map} +2 -2
  51. package/dist/{pdf-ocr-C6DYPI2Q.js → pdf-ocr-ZH4JAUTR.js} +9 -9
  52. package/dist/{profile-io-LZ5YPCIW.js → profile-io-JFRAM2VE.js} +3 -3
  53. package/dist/{rasterize-K2VVPUGE.js → rasterize-JJOMUTYX.js} +3 -3
  54. package/dist/{redact-doc-A3M2YEXE.js → redact-doc-A7TW4MNF.js} +23 -23
  55. package/dist/{render-HS2YWRJE.js → render-VAOMAQV2.js} +11 -11
  56. package/dist/{rewrite-fallback-3YVRWPRM.js → rewrite-fallback-7PR7V3AZ.js} +13 -13
  57. package/dist/seal-RZZNRJFL.js +14 -0
  58. package/dist/{setup-YK2SCVLP.js → setup-6DXZJQCT.js} +3 -3
  59. package/dist/to-hwpx-A56R6H27.js +20 -0
  60. package/dist/visual-25RY7EFI.js +42 -0
  61. package/dist/{watch-CQX4TSVQ.js → watch-7W6CKGX7.js} +23 -23
  62. package/package.json +1 -1
  63. package/dist/chunk-74QGGXVH.js.map +0 -1
  64. package/dist/chunk-PCOKS4ZE.js.map +0 -7
  65. package/dist/chunk-RECWLRRB.js.map +0 -7
  66. package/dist/chunk-TPPL3OVT.js.map +0 -7
  67. package/dist/chunks-IDWF6IOZ.js +0 -10
  68. package/dist/memo-RND3VIEW.js +0 -15
  69. package/dist/seal-DYLPFEC6.js +0 -14
  70. package/dist/to-hwpx-XNBAWVNY.js +0 -20
  71. package/dist/visual-SQORG4IC.js +0 -42
  72. /package/dist/{chunk-CZFY7JGT.js.map → chunk-24LB25LZ.js.map} +0 -0
  73. /package/dist/{chunk-HKO6HWYM.js.map → chunk-3AYNFK6J.js.map} +0 -0
  74. /package/dist/{chunk-LQGZ3PBZ.js.map → chunk-5ULHNZ3P.js.map} +0 -0
  75. /package/dist/{chunk-EFBIMFVT.js.map → chunk-6I3X54AQ.js.map} +0 -0
  76. /package/dist/{chunk-HH5IOQTP.js.map → chunk-6MCJHRSM.js.map} +0 -0
  77. /package/dist/{chunk-UTLVAA7X.js.map → chunk-DZOA5N5W.js.map} +0 -0
  78. /package/dist/{chunk-HCHWG3HO.js.map → chunk-FDSFXE2L.js.map} +0 -0
  79. /package/dist/{chunk-ZCDTZZ3C.js.map → chunk-GJORKM42.js.map} +0 -0
  80. /package/dist/{chunk-VOK3R4WW.js.map → chunk-HQILGS2O.js.map} +0 -0
  81. /package/dist/{chunk-FCWPQZYU.js.map → chunk-KW4JO5CV.js.map} +0 -0
  82. /package/dist/{chunk-EI4PBZW2.js.map → chunk-LSUTK3DH.js.map} +0 -0
  83. /package/dist/{chunk-FZ7XCPHO.js.map → chunk-MWCJYIJC.js.map} +0 -0
  84. /package/dist/{chunk-6YQ2LARO.js.map → chunk-PFNZQ3XI.js.map} +0 -0
  85. /package/dist/{chunk-XCD6WLTU.js.map → chunk-PVOLFVXE.js.map} +0 -0
  86. /package/dist/{chunk-FNMJ2DK4.js.map → chunk-QNJ2LMUO.js.map} +0 -0
  87. /package/dist/{chunk-VVR2ZSFZ.js.map → chunk-QOCUFTT4.js.map} +0 -0
  88. /package/dist/{chunk-3DX4GW75.js.map → chunk-S553BW45.js.map} +0 -0
  89. /package/dist/{chunk-IUD535LX.js.map → chunk-TI6S3KZF.js.map} +0 -0
  90. /package/dist/{chunk-LEWJRIVZ.js.map → chunk-W5AHXAUP.js.map} +0 -0
  91. /package/dist/{chunk-TW6WYJD6.js.map → chunk-XUBBFY3H.js.map} +0 -0
  92. /package/dist/{chunk-LXPFTU3C.js.map → chunk-ZCMMU34Z.js.map} +0 -0
  93. /package/dist/{chunk-IVNUMREN.js.map → chunk-ZO4P735U.js.map} +0 -0
  94. /package/dist/{chunks-IDWF6IOZ.js.map → chunks-XX7RHVQF.js.map} +0 -0
  95. /package/dist/{formula-U2RXOOE4.js.map → formula-HMKT4BZL.js.map} +0 -0
  96. /package/dist/{generator-K6I6IYOH.js.map → generator-HOY4SZ26.js.map} +0 -0
  97. /package/dist/{hancom-ARDTLWD5.js.map → hancom-QWJBWOOE.js.map} +0 -0
  98. /package/dist/{image-ocr-RDWOEEQ2.js.map → image-ocr-P5AIZNT3.js.map} +0 -0
  99. /package/dist/{memo-RND3VIEW.js.map → memo-Q7772VJD.js.map} +0 -0
  100. /package/dist/{model-bundle-A6C5PVSS.js.map → model-bundle-5CXCIZHZ.js.map} +0 -0
  101. /package/dist/{models-KTY3IZU2.js.map → models-PS4L7NLP.js.map} +0 -0
  102. /package/dist/{page-images-PVXQYU7Z.js.map → page-images-QW7IUTUB.js.map} +0 -0
  103. /package/dist/{parse-worker-v2-E4T4427H.js.map → parse-worker-v2-PRH6KVKP.js.map} +0 -0
  104. /package/dist/{pdf-ocr-C6DYPI2Q.js.map → pdf-ocr-ZH4JAUTR.js.map} +0 -0
  105. /package/dist/{profile-io-LZ5YPCIW.js.map → profile-io-JFRAM2VE.js.map} +0 -0
  106. /package/dist/{rasterize-K2VVPUGE.js.map → rasterize-JJOMUTYX.js.map} +0 -0
  107. /package/dist/{redact-doc-A3M2YEXE.js.map → redact-doc-A7TW4MNF.js.map} +0 -0
  108. /package/dist/{render-HS2YWRJE.js.map → render-VAOMAQV2.js.map} +0 -0
  109. /package/dist/{rewrite-fallback-3YVRWPRM.js.map → rewrite-fallback-7PR7V3AZ.js.map} +0 -0
  110. /package/dist/{seal-DYLPFEC6.js.map → seal-RZZNRJFL.js.map} +0 -0
  111. /package/dist/{setup-YK2SCVLP.js.map → setup-6DXZJQCT.js.map} +0 -0
  112. /package/dist/{to-hwpx-XNBAWVNY.js.map → to-hwpx-A56R6H27.js.map} +0 -0
  113. /package/dist/{visual-SQORG4IC.js.map → visual-25RY7EFI.js.map} +0 -0
  114. /package/dist/{watch-CQX4TSVQ.js.map → watch-7W6CKGX7.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.19" : "0.0.0-dev";
384
+ VERSION = true ? "4.25.21" : "0.0.0-dev";
385
385
  KordocError = class extends Error {
386
386
  constructor(message) {
387
387
  super(message);
@@ -7180,20 +7180,43 @@ function chunk(type, data2) {
7180
7180
  return out;
7181
7181
  }
7182
7182
  function encodePng(width, height, rgba) {
7183
+ return assemblePng(width, height, (0, import_node_zlib.deflateSync)(pngScanlines(width, height, rgba, 4)));
7184
+ }
7185
+ async function encodePngAsync(width, height, pixels, channels = 4) {
7186
+ const raw = pngScanlines(width, height, pixels, channels);
7187
+ const idat = await deflateAsync(raw).catch(() => (0, import_node_zlib.deflateSync)(raw));
7188
+ return assemblePng(width, height, idat);
7189
+ }
7190
+ function pngScanlineBytes(width, height) {
7191
+ return (width * 4 + 1) * height;
7192
+ }
7193
+ function pngScanlines(width, height, pixels, channels) {
7194
+ const stride = width * 4;
7195
+ const raw = new Uint8Array(pngScanlineBytes(width, height));
7196
+ for (let y = 0; y < height; y++) {
7197
+ const rowStart = y * (stride + 1) + 1;
7198
+ if (channels === 4) {
7199
+ const source = y * stride;
7200
+ raw.set(pixels.subarray(source, source + stride), rowStart);
7201
+ } else {
7202
+ let source = y * width * 3;
7203
+ for (let dst = rowStart; dst < rowStart + stride; dst += 4, source += 3) {
7204
+ raw[dst] = pixels[source];
7205
+ raw[dst + 1] = pixels[source + 1];
7206
+ raw[dst + 2] = pixels[source + 2];
7207
+ raw[dst + 3] = 255;
7208
+ }
7209
+ }
7210
+ }
7211
+ return raw;
7212
+ }
7213
+ function assemblePng(width, height, idat) {
7183
7214
  const ihdr = new Uint8Array(13);
7184
7215
  const iv = new DataView(ihdr.buffer);
7185
7216
  iv.setUint32(0, width, false);
7186
7217
  iv.setUint32(4, height, false);
7187
7218
  ihdr[8] = 8;
7188
7219
  ihdr[9] = 6;
7189
- const stride = width * 4;
7190
- const raw = new Uint8Array((stride + 1) * height);
7191
- for (let y = 0; y < height; y++) {
7192
- const rowStart = y * (stride + 1);
7193
- raw[rowStart] = 0;
7194
- raw.set(rgba.subarray(y * stride, y * stride + stride), rowStart + 1);
7195
- }
7196
- const idat = (0, import_node_zlib.deflateSync)(raw);
7197
7220
  const ihdrChunk = chunk("IHDR", ihdr);
7198
7221
  const idatChunk = chunk("IDAT", idat);
7199
7222
  const iendChunk = chunk("IEND", new Uint8Array(0));
@@ -7234,11 +7257,13 @@ function inlineImagesIntoMarkdown(markdown, images, opts) {
7234
7257
  });
7235
7258
  return out;
7236
7259
  }
7237
- var import_node_zlib, CRC_TABLE, BI_RGB, BI_RLE8, BI_RLE4, BI_BITFIELDS, BI_ALPHABITFIELDS, MAX_DIM, MAX_PIXELS, PNG_SIGNATURE;
7260
+ var import_node_util, import_node_zlib, deflateAsync, CRC_TABLE, BI_RGB, BI_RLE8, BI_RLE4, BI_BITFIELDS, BI_ALPHABITFIELDS, MAX_DIM, MAX_PIXELS, PNG_SIGNATURE;
7238
7261
  var init_transcode = __esm({
7239
7262
  "src/image/transcode.ts"() {
7240
7263
  "use strict";
7264
+ import_node_util = require("node:util");
7241
7265
  import_node_zlib = require("node:zlib");
7266
+ deflateAsync = (0, import_node_util.promisify)(import_node_zlib.deflate);
7242
7267
  CRC_TABLE = (() => {
7243
7268
  const table2 = new Uint32Array(256);
7244
7269
  for (let n = 0; n < 256; n++) {
@@ -28118,6 +28143,47 @@ function editedFromVisual(keepMarkdown, visualMarkdown, editedMarkdown) {
28118
28143
  }
28119
28144
  return v > k;
28120
28145
  }
28146
+ function removeNoteMarks(text, marks) {
28147
+ let out = text;
28148
+ let cursor = 0;
28149
+ const missing = [];
28150
+ for (const mark of marks) {
28151
+ if (!mark) continue;
28152
+ let at = -1;
28153
+ for (let p = out.indexOf(mark, cursor); p !== -1; p = out.indexOf(mark, p + 1)) {
28154
+ if (p === 0 || !/\s/.test(out[p - 1])) {
28155
+ at = p;
28156
+ break;
28157
+ }
28158
+ if (at === -1) at = p;
28159
+ }
28160
+ if (at === -1) {
28161
+ missing.push(mark);
28162
+ continue;
28163
+ }
28164
+ out = out.slice(0, at) + out.slice(at + mark.length);
28165
+ cursor = at;
28166
+ }
28167
+ return { text: out, missing };
28168
+ }
28169
+ function noteMarksOf(footnoteText) {
28170
+ return footnoteText ? footnoteText.split("; ").map((s) => s.match(/^(\S+)\s/)?.[1] ?? "").filter(Boolean) : [];
28171
+ }
28172
+ function splitCellNote(before2, after2, skipped) {
28173
+ const re = /\s*\(주: ([\s\S]*)\)$/;
28174
+ const bm = before2.match(re);
28175
+ if (!bm) return { before: before2, after: after2, noted: false };
28176
+ const marks = noteMarksOf(bm[1]);
28177
+ const am = after2.match(re);
28178
+ let body = after2;
28179
+ if (am) {
28180
+ body = after2.slice(0, am.index).trimEnd();
28181
+ if (normForMatch(am[1]) !== normForMatch(bm[1])) skipped.push({ reason: "각주 텍스트 수정은 미지원 — 본문만 적용", before: bm[1], after: am[1] });
28182
+ } else skipped.push({ reason: "각주 표기 삭제는 미지원 — 각주 유지, 본문만 적용", before: `(주: ${bm[1]})` });
28183
+ const r = removeNoteMarks(body, marks);
28184
+ if (r.missing.length) skipped.push({ reason: "각주 참조 부호 삭제는 미지원 — 각주 유지, 본문만 적용", before: r.missing.join(" ") });
28185
+ return { before: removeNoteMarks(before2.slice(0, bm.index).trimEnd(), marks).text, after: r.text, noted: true };
28186
+ }
28121
28187
  var AUTOLINK, AUTONUM_PREFIX_RE, LAYOUT_MODE_MISMATCH;
28122
28188
  var init_markdown_units = __esm({
28123
28189
  "src/roundtrip/markdown-units.ts"() {
@@ -31395,6 +31461,8 @@ function restoreSymbols(text, ringDecided = false) {
31395
31461
  if (/[가-힣]/.test(s)) s = s.replace(/(\d)l(?![A-Za-z])/g, "$1ℓ");
31396
31462
  s = s.replace(/([((])\s?[A-Za-z@&]\s?(?=(?:0\d{1,2}-)?\d{3,4}-\d{4}\b)/g, "$1☎");
31397
31463
  if (!s.includes("]")) s = s.replace(/^\[(?=[\u2460-\u2473])/, "");
31464
+ s = s.replace(/%\u3002/g, "‰");
31465
+ if (/[\uac00-\ud7a3]/.test(s)) s = s.replace(/(?<=[\uac00-\ud7a3\d)])\u3002/g, ".");
31398
31466
  return smartQuotes(dateDots(dateCommas(joinDigitGroups(s))));
31399
31467
  }
31400
31468
  function dateCommas(s) {
@@ -38874,6 +38942,8 @@ function mapTextToCells(items, cells) {
38874
38942
  result.set(cell2, []);
38875
38943
  }
38876
38944
  const candidates = items.length * cells.length >= 5e3 ? cellBandLookup(cells) : () => cells;
38945
+ const tableTop = Math.min(...cells.map((c) => c.bbox.y1)), tableBottom = Math.max(...cells.map((c) => c.bbox.y2));
38946
+ const wide = new Set(cells.map((c) => c.col)).size >= 3;
38877
38947
  for (const item of items) {
38878
38948
  const pad = CELL_PADDING;
38879
38949
  let bestCell = null;
@@ -38892,6 +38962,10 @@ function mapTextToCells(items, cells) {
38892
38962
  bestCell = cell2;
38893
38963
  }
38894
38964
  }
38965
+ if (bestCell && item.fontName === "ocr" && wide) {
38966
+ const ih = item.h || item.fontSize, cy = item.y + ih / 2;
38967
+ if (ih < bestCell.bbox.y2 - bestCell.bbox.y1 && (cy < tableTop || cy > tableBottom)) continue;
38968
+ }
38895
38969
  if (bestCell && bestScore > 0.3) {
38896
38970
  result.get(bestCell).push(item);
38897
38971
  }
@@ -42533,7 +42607,11 @@ function refineDocumentStyleHeadings(blocks) {
42533
42607
  function shouldDemoteTable(table2) {
42534
42608
  const allCells = table2.cells.flatMap((row) => row.map((c) => c.text.trim())).filter(Boolean);
42535
42609
  const allText = allCells.join(" ");
42536
- if (table2.rows >= 2 && table2.cols >= 2 && table2.cells[0].every((c) => {
42610
+ const covered = /* @__PURE__ */ new Set();
42611
+ table2.cells[0]?.forEach((c, i) => {
42612
+ for (let k = 1; k < (c.colSpan || 1); k++) covered.add(i + k);
42613
+ });
42614
+ if (table2.rows >= 2 && table2.cols >= 2 && table2.cells[0].filter((_, i) => !covered.has(i)).every((c) => {
42537
42615
  const t = c.text.trim();
42538
42616
  return t.length > 0 && t.length <= 12 && !/[□■◆○●▶ㅇ<>]/.test(t);
42539
42617
  }) && table2.cells.slice(1).some((row) => row.some((c) => c.text.trim() !== ""))) return false;
@@ -81743,9 +81821,16 @@ function applyCellEdit(table2, scanTable, gridR, gridC, newLines, ctx, before2,
81743
81821
  };
81744
81822
  const cell2 = scanTable.cellByAnchor.get(`${gridR},${gridC}`);
81745
81823
  if (!cell2) return skip("셀 좌표 매핑 실패 (병합 영역의 빈 칸이거나 좌표 불일치)");
81824
+ const origLines = gfmCellLines(before2);
81825
+ if (origLines.some((l) => /\(주: [\s\S]*\)$/.test(l)) && origLines.length === newLines.length) {
81826
+ const notes = newLines.map((l, i) => splitCellNote(origLines[i], l, ctx.skipped));
81827
+ newLines = notes.map((n) => n.after);
81828
+ before2 = notes.map((n) => n.before).join("<br>");
81829
+ }
81746
81830
  const irCell = table2.cells[gridR]?.[gridC];
81747
81831
  const scanJoined = cell2.paragraphs.map((p) => p.text).filter((t) => normForMatch(t)).join("\n");
81748
- if (irCell && normForMatch(scanJoined) !== normForMatch(noScriptTags(stripCellTokens(irCell.text)))) {
81832
+ const noteless = (text) => text.split("\n").map((l) => splitCellNote(l, l, []).before).join("\n");
81833
+ if (irCell && normForMatch(scanJoined) !== normForMatch(noteless(noScriptTags(stripCellTokens(irCell.text))))) {
81749
81834
  if (normForMatch(irCell.text) !== "" || normForMatch(scanJoined) !== "") {
81750
81835
  const flatBlocks = (irCell.blocks ?? []).filter((b) => b.type === "paragraph" || b.type === "heading");
81751
81836
  const flatJoined = noScriptTags(flatBlocks.map((b) => b.text ?? "").join("\n"));
@@ -83410,6 +83495,7 @@ function resolveParaMappings(blocks, scans) {
83410
83495
  const text = noScriptTags(b.text);
83411
83496
  let key3 = normForMatch(text);
83412
83497
  let prefixStripped = false;
83498
+ let noteMarks;
83413
83499
  if (!buckets.has(key3)) {
83414
83500
  const sp = text.indexOf(" ");
83415
83501
  if (sp > 0) {
@@ -83420,6 +83506,15 @@ function resolveParaMappings(blocks, scans) {
83420
83506
  }
83421
83507
  }
83422
83508
  }
83509
+ const marks = noteMarksOf(b.footnoteText);
83510
+ if (!buckets.has(key3) && marks.length) {
83511
+ const r = removeNoteMarks(text, marks);
83512
+ const alt2 = r.missing.length ? "" : normForMatch(r.text);
83513
+ if (alt2 && buckets.has(alt2)) {
83514
+ key3 = alt2;
83515
+ noteMarks = marks;
83516
+ }
83517
+ }
83423
83518
  const found = buckets.get(key3);
83424
83519
  const list = found ? pairable(key3, found) : null;
83425
83520
  if (!list) {
@@ -83428,7 +83523,7 @@ function resolveParaMappings(blocks, scans) {
83428
83523
  }
83429
83524
  const occ = counters.get(key3) ?? 0;
83430
83525
  counters.set(key3, occ + 1);
83431
- result.set(i, occ < list.length ? { para: list[occ], prefixStripped } : {});
83526
+ result.set(i, occ < list.length ? { para: list[occ], prefixStripped, noteMarks } : {});
83432
83527
  }
83433
83528
  return result;
83434
83529
  }
@@ -83585,29 +83680,38 @@ function patchParagraph(block, orig, edited, ctx, skip) {
83585
83680
  if (block.text && block.text.includes("\n") && !newPlain.includes("\n")) {
83586
83681
  return skip("다중줄 문단 수정에 <br> 없음 — 줄바꿈 위치 보존 불가로 미지원 (줄바꿈은 <br>로 표기)");
83587
83682
  }
83683
+ let noteEdited = false;
83588
83684
  if (block.footnoteText) {
83589
83685
  const noteMatch = newPlain.match(/\s*\(주: ([\s\S]*)\)$/);
83590
83686
  if (noteMatch) {
83591
83687
  newPlain = newPlain.slice(0, noteMatch.index).trimEnd();
83592
83688
  if (normForMatch(noteMatch[1]) !== normForMatch(block.footnoteText)) {
83593
83689
  ctx.skipped.push({ reason: "각주 텍스트 수정은 미지원 — 본문만 적용", before: block.footnoteText, after: noteMatch[1] });
83690
+ noteEdited = true;
83594
83691
  }
83595
83692
  } else {
83596
83693
  ctx.skipped.push({ reason: "각주 표기 삭제는 미지원 — 각주 유지, 본문만 적용", before: `(주: ${block.footnoteText})` });
83597
83694
  }
83598
83695
  }
83696
+ if (mapping.noteMarks?.length) {
83697
+ const r = removeNoteMarks(newPlain, mapping.noteMarks);
83698
+ newPlain = r.text;
83699
+ if (r.missing.length) ctx.skipped.push({ reason: "각주 참조 부호 삭제는 미지원 — 각주 유지, 본문만 적용", before: r.missing.join(" ") });
83700
+ }
83599
83701
  if (mapping.prefixStripped) {
83600
83702
  const head = stripHeadMarker(block.text, newPlain);
83601
83703
  newPlain = head.text;
83602
83704
  if (head.note) ctx.skipped.push({ reason: head.note, after: summarize(newPlain), partial: true });
83603
83705
  }
83604
- const origPlain = block.text != null ? noScriptTags(block.text) : restoreBr(origStyled.plain);
83605
- if (newPlain === origPlain) return skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
83706
+ let origPlain = block.text != null ? noScriptTags(block.text) : restoreBr(origStyled.plain);
83707
+ if (mapping.noteMarks?.length) origPlain = removeNoteMarks(origPlain, mapping.noteMarks).text;
83708
+ if (newPlain === origPlain) return noteEdited ? 0 : skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
83606
83709
  if (sanitizeText(newPlain) !== newPlain && sanitizeText(origPlain) === origPlain) {
83607
83710
  return skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원");
83608
83711
  }
83609
83712
  let origMd = restoreBr(origStyled.plain);
83610
83713
  if (block.footnoteText) origMd = origMd.replace(/\s*\(주: [\s\S]*\)$/, "");
83714
+ if (mapping.noteMarks?.length) origMd = removeNoteMarks(origMd, mapping.noteMarks).text;
83611
83715
  if (mapping.prefixStripped) origMd = stripShownHeadMarker(block.text, origMd);
83612
83716
  const off = editedStyled.plain.length - newPlain.length;
83613
83717
  const style2 = ctx.charBook && off >= 0 && editedStyled.plain.endsWith(newPlain) && origStyled.plain.endsWith(origMd) ? { flags: flagsPerChar(editedStyled.segs, editedStyled.flags).slice(off), known: origStyled.flags.reduce((a, b) => a | b, 0), book: ctx.charBook } : void 0;
@@ -83645,8 +83749,8 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
83645
83749
  cellSkip("서식/링크/이미지 포함 셀 수정은 미지원 (v1)");
83646
83750
  continue;
83647
83751
  }
83648
- const before2 = beforeEach.join("\n");
83649
- const after2 = afterEach.join("\n");
83752
+ if (beforeEach.join("\n") === afterEach.join("\n")) continue;
83753
+ const { before: before2, after: after2, noted } = splitCellNote(beforeEach.join("\n"), afterEach.join("\n"), ctx.skipped);
83650
83754
  if (before2 === after2) continue;
83651
83755
  const para2 = cell2.paras[0];
83652
83756
  if (normForMatch(para2.rawText) !== normForMatch(before2)) {
@@ -83665,7 +83769,7 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
83665
83769
  ctx.keepLineseg,
83666
83770
  before2,
83667
83771
  // 바뀐 자리만 — 굵은 조각 등 run 유지
83668
- cellLineStyles(origRows[r][c], editedRows[r][c], ctx.charBook)(0, after2)
83772
+ noted ? void 0 : cellLineStyles(origRows[r][c], editedRows[r][c], ctx.charBook)(0, after2)
83669
83773
  );
83670
83774
  continue;
83671
83775
  }
@@ -83674,12 +83778,14 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
83674
83778
  continue;
83675
83779
  }
83676
83780
  for (let k = 0; k < cell2.paras.length; k++) {
83677
- const before2 = gfmCellToPlain(beforeParts[k]);
83678
- const after2 = gfmCellToPlain(afterParts[k]);
83679
- if (before2 === null || after2 === null) {
83781
+ const rawBefore = gfmCellToPlain(beforeParts[k]);
83782
+ const rawAfter = gfmCellToPlain(afterParts[k]);
83783
+ if (rawBefore === null || rawAfter === null) {
83680
83784
  cellSkip("서식/링크/이미지 포함 셀 수정은 미지원 (v1)");
83681
83785
  break;
83682
83786
  }
83787
+ if (rawBefore === rawAfter) continue;
83788
+ const { before: before2, after: after2, noted } = splitCellNote(rawBefore, rawAfter, ctx.skipped);
83683
83789
  if (before2 === after2) continue;
83684
83790
  if (after2.includes("\n")) {
83685
83791
  cellSkip("셀 내 줄바꿈 추가는 미지원 (v1)");
@@ -83702,7 +83808,7 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
83702
83808
  ctx.keepLineseg,
83703
83809
  before2,
83704
83810
  // 바뀐 자리만 — 굵은 조각 등 run 유지
83705
- cellLineStyles(origRows[r][c], editedRows[r][c], ctx.charBook)(k, after2)
83811
+ noted ? void 0 : cellLineStyles(origRows[r][c], editedRows[r][c], ctx.charBook)(k, after2)
83706
83812
  );
83707
83813
  }
83708
83814
  }
@@ -84344,29 +84450,6 @@ function textWithoutMarks(irKey, scanKey, marks) {
84344
84450
  }
84345
84451
  return j === scanKey.length && k === marks.length;
84346
84452
  }
84347
- function removeNoteMarks(text, marks) {
84348
- let out = text;
84349
- let cursor = 0;
84350
- const missing = [];
84351
- for (const mark of marks) {
84352
- if (!mark) continue;
84353
- let at = -1;
84354
- for (let p = out.indexOf(mark, cursor); p !== -1; p = out.indexOf(mark, p + 1)) {
84355
- if (p === 0 || !/\s/.test(out[p - 1])) {
84356
- at = p;
84357
- break;
84358
- }
84359
- if (at === -1) at = p;
84360
- }
84361
- if (at === -1) {
84362
- missing.push(mark);
84363
- continue;
84364
- }
84365
- out = out.slice(0, at) + out.slice(at + mark.length);
84366
- cursor = at;
84367
- }
84368
- return { text: out, missing };
84369
- }
84370
84453
  function fallbackPlain(raw, block) {
84371
84454
  const inline = block ? textUnitInline(raw, block, "\n") : raw.split("\n").map((l) => l.trim()).filter(Boolean).join("\n");
84372
84455
  return parseEmphasis(inline.replace(/!\[[^\]]*\]\([^)]*\)/g, " ").replace(/<br\s*\/?>/gi, "\n")).plain.replace(/<\/?(?:sup|sub)>/g, "");
@@ -84510,6 +84593,7 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
84510
84593
  let origPlain = origInline.plain;
84511
84594
  let newPlain = newInline.plain;
84512
84595
  const segsUsable = !block.footnoteText && !mapping.noteMarks?.length && !mapping.prefixStripped;
84596
+ let noteEdited = false;
84513
84597
  if (block.footnoteText) {
84514
84598
  const origNote = block.footnoteBlocks ? origPlain.match(/\s*\(주: ([\s\S]*)\)$/)?.[1] : void 0;
84515
84599
  origPlain = origPlain.replace(/\s*\(주: [\s\S]*\)$/, "");
@@ -84518,6 +84602,7 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
84518
84602
  newPlain = newPlain.slice(0, noteMatch.index).trimEnd();
84519
84603
  if (normForMatch(noteMatch[1]) !== normForMatch(origNote ?? block.footnoteText)) {
84520
84604
  ctx.skipped.push({ reason: "각주 텍스트 수정은 미지원 — 본문만 적용", before: block.footnoteText, after: noteMatch[1] });
84605
+ noteEdited = true;
84521
84606
  }
84522
84607
  } else {
84523
84608
  ctx.skipped.push({ reason: "각주 표기 삭제는 미지원 — 각주 유지, 본문만 적용", before: `(주: ${block.footnoteText})` });
@@ -84535,7 +84620,7 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
84535
84620
  newPlain = head.text;
84536
84621
  if (head.note) ctx.skipped.push({ reason: head.note, after: summarize(newPlain), partial: true });
84537
84622
  }
84538
- if (newPlain === origPlain) return skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
84623
+ if (newPlain === origPlain) return noteEdited ? 0 : skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
84539
84624
  if (sanitizeText(newPlain) !== newPlain && sanitizeText(origPlain) === origPlain) {
84540
84625
  return skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원");
84541
84626
  }
@@ -89204,7 +89289,7 @@ function resolveImgData(page, objId) {
89204
89289
  });
89205
89290
  }
89206
89291
  function createPdfImageState(webp, placement = false, dropBlank = false) {
89207
- return { imageIndex: 0, totalBytes: 0, seen: /* @__PURE__ */ new Map(), globalKeys: /* @__PURE__ */ new Map(), capWarned: false, webp, pending: [], pendingRaw: 0, renamed: /* @__PURE__ */ new Map(), oversize: 0, placement, dropBlank };
89292
+ return { imageIndex: 0, totalBytes: 0, seen: /* @__PURE__ */ new Map(), globalKeys: /* @__PURE__ */ new Map(), capWarned: false, webp, pending: [], pendingRaw: 0, renamed: /* @__PURE__ */ new Map(), oversize: 0, failed: /* @__PURE__ */ new Set(), placement, dropBlank };
89208
89293
  }
89209
89294
  function contentHash(data2) {
89210
89295
  return (0, import_node_crypto3.createHash)("sha1").update(data2).digest("hex");
@@ -89283,7 +89368,7 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
89283
89368
  imgData = argsArray[i]?.[0];
89284
89369
  }
89285
89370
  if (!imgData?.data || !imgData.width || !imgData.height) continue;
89286
- const { width: w, height: h } = imgData;
89371
+ const { width: w, height: h, kind, data: data2 } = imgData;
89287
89372
  if (w < MIN_DIM || h < MIN_DIM) continue;
89288
89373
  if (w * h > MAX_PIXELS3) {
89289
89374
  warnings.push({ page: pageNumber, message: `이미지 크기 초과로 추출 생략 (${w}×${h})`, code: "SKIPPED_IMAGE" });
@@ -89292,21 +89377,29 @@ async function extractPageImages(page, fnArray, argsArray, pageNumber, state, wa
89292
89377
  const globalId = dedupeId?.startsWith("g_") ? dedupeId : void 0;
89293
89378
  let hash = globalId ? state.globalKeys.get(globalId) : void 0;
89294
89379
  if (hash === void 0) {
89295
- hash = `${w}x${h}k${imgData.kind ?? "?"}h${contentHash(imgData.data)}${dedupeId ? "" : "inline"}`;
89380
+ hash = `${w}x${h}k${kind ?? "?"}h${contentHash(data2)}${dedupeId ? "" : "inline"}`;
89296
89381
  if (globalId) state.globalKeys.set(globalId, hash);
89297
89382
  }
89298
89383
  if (state.seen.has(hash)) continue;
89299
- const rgba = toRgba(imgData, withBytes || !!readQr || state.dropBlank);
89300
- if (!rgba) continue;
89301
- if (state.dropBlank && isBlankRgba(rgba)) {
89302
- state.seen.set(hash, "");
89303
- continue;
89384
+ const channels = kind === ImageKind.RGB_24BPP ? 3 : kind === ImageKind.RGBA_32BPP ? 4 : void 0;
89385
+ let pixels;
89386
+ if (channels && withBytes && !state.webp && !readQr && !state.dropBlank && pngScanlineBytes(w, h) >= MIN_ASYNC_PNG_BYTES) {
89387
+ if (data2.length < w * h * channels) continue;
89388
+ pixels = { data: data2, channels };
89389
+ } else {
89390
+ const rgba = toRgba(imgData, withBytes || !!readQr || state.dropBlank);
89391
+ if (!rgba) continue;
89392
+ if (state.dropBlank && isBlankRgba(rgba)) {
89393
+ state.seen.set(hash, "");
89394
+ continue;
89395
+ }
89396
+ pixels = { data: rgba };
89304
89397
  }
89305
89398
  state.imageIndex++;
89306
89399
  const filename = imageFilename(state, w, h);
89307
89400
  state.seen.set(hash, filename);
89308
- if (withBytes) await pushImage(state, filename, w, h, rgba, images);
89309
- const qr = readQr ? await readQr({ data: rgba, width: w, height: h }) : [];
89401
+ if (withBytes) await pushImage(state, filename, w, h, pixels, images);
89402
+ const qr = readQr && pixels.channels === void 0 ? await readQr({ data: pixels.data, width: w, height: h }) : [];
89310
89403
  blocks.push(placed({ type: "image", text: filename, pageNumber, ...qr.length ? { qr } : {} }, i));
89311
89404
  }
89312
89405
  return { blocks, images };
@@ -89320,47 +89413,74 @@ async function capReached(state, pageNumber, warnings) {
89320
89413
  }
89321
89414
  return true;
89322
89415
  }
89323
- async function pushImage(state, filename, w, h, rgba, images) {
89324
- if (!webpable(state, w, h)) {
89325
- if (state.webp) state.oversize++;
89326
- const png = encodePng(w, h, rgba);
89327
- state.totalBytes += png.length;
89328
- images.push({ filename, data: png, mimeType: "image/png" });
89416
+ async function pushImage(state, filename, w, h, pixels, images) {
89417
+ const webp = webpable(state, w, h) ? state.webp : void 0;
89418
+ const raw = webp ? pixels.data.length : pngScanlineBytes(w, h);
89419
+ const image = { filename, data: NO_BYTES, mimeType: webp ? "image/webp" : "image/png" };
89420
+ const save = (data2) => {
89421
+ image.data = data2;
89422
+ state.totalBytes += data2.length;
89423
+ if (!webp && state.webp) state.oversize++;
89424
+ };
89425
+ const fail = () => {
89426
+ state.failed.add(filename);
89427
+ };
89428
+ if (pixels.channels === void 0 && !webp && raw < MIN_ASYNC_PNG_BYTES) {
89429
+ try {
89430
+ save(encodePng(w, h, pixels.data));
89431
+ images.push(image);
89432
+ } catch {
89433
+ fail();
89434
+ }
89329
89435
  return;
89330
89436
  }
89331
- await drain(state, MAX_PENDING_RAW_BYTES - rgba.length);
89332
- const image = { filename, data: NO_BYTES, mimeType: "image/webp" };
89437
+ await drain(state, MAX_PENDING_RAW_BYTES - raw, webp ? void 0 : MAX_PENDING_PNG_IMAGES - 1);
89333
89438
  images.push(image);
89334
- const done = state.webp(rgba, w, h).then(
89335
- (webp) => {
89336
- image.data = webp;
89337
- state.totalBytes += webp.length;
89338
- },
89339
- // 실패해도 파싱은 계속한다 — 그 그림만 PNG 로. 블록의 이름은 flushPdfImages 가 바꾼다
89340
- () => {
89341
- image.data = encodePng(w, h, rgba);
89342
- image.mimeType = "image/png";
89343
- image.filename = filename.replace(/\.webp$/, ".png");
89344
- state.totalBytes += image.data.length;
89345
- state.renamed.set(filename, image.filename);
89346
- }
89347
- );
89348
- state.pending.push({ done, raw: rgba.length });
89349
- state.pendingRaw += rgba.length;
89439
+ const encoded = pixels.channels === void 0 && webp ? encodeWebpImage(webp, state, image, w, h, pixels.data) : encodePngAsync(w, h, pixels.data, pixels.channels);
89440
+ const done = encoded.then(save, fail);
89441
+ if (!webp && raw > MAX_PENDING_RAW_BYTES) {
89442
+ await done;
89443
+ return;
89444
+ }
89445
+ state.pending.push({ done, raw });
89446
+ state.pendingRaw += raw;
89447
+ }
89448
+ async function encodeWebpImage(webp, state, image, w, h, rgba) {
89449
+ try {
89450
+ return await webp(rgba, w, h);
89451
+ } catch {
89452
+ const png = encodePng(w, h, rgba);
89453
+ const filename = image.filename.replace(/\.webp$/, ".png");
89454
+ state.renamed.set(image.filename, filename);
89455
+ image.filename = filename;
89456
+ image.mimeType = "image/png";
89457
+ return png;
89458
+ }
89350
89459
  }
89351
- async function drain(state, keep) {
89352
- while (state.pending.length && state.pendingRaw > keep) {
89460
+ async function drain(state, keepRaw, keepCount = Infinity) {
89461
+ while (state.pendingRaw > keepRaw || state.pending.length > keepCount) {
89353
89462
  const p = state.pending.shift();
89354
- state.pendingRaw -= p.raw;
89463
+ if (!p) break;
89355
89464
  await p.done;
89465
+ state.pendingRaw -= p.raw;
89356
89466
  }
89357
89467
  }
89358
- async function flushPdfImages(state, warnings, pageImages) {
89468
+ async function flushPdfImages(state, warnings, pageImages, images) {
89359
89469
  await drain(state, 0);
89360
89470
  if (state.oversize) warnings.push({ message: `WebP 한도(가로·세로 16,383px)를 넘는 그림 ${state.oversize}개를 PNG 로 냈습니다`, code: "SKIPPED_IMAGE" });
89361
- if (!state.renamed.size) return;
89362
- for (const list of pageImages.values()) for (const b of list) b.text = state.renamed.get(b.text) ?? b.text;
89363
- warnings.push({ message: `WebP 인코딩 실패로 그림 ${state.renamed.size}개를 PNG 로 냈습니다`, code: "SKIPPED_IMAGE" });
89471
+ if (state.renamed.size) {
89472
+ for (const list of pageImages.values()) for (const b of list) if (b.text) b.text = state.renamed.get(b.text) ?? b.text;
89473
+ warnings.push({ message: `WebP 인코딩 실패로 그림 ${state.renamed.size}개를 PNG 로 냈습니다`, code: "SKIPPED_IMAGE" });
89474
+ }
89475
+ if (state.failed.size) {
89476
+ for (let i = images.length - 1; i >= 0; i--) if (state.failed.has(images[i].filename)) images.splice(i, 1);
89477
+ for (const [page, list] of pageImages) {
89478
+ const kept = list.filter((b) => !b.text || !state.failed.has(b.text));
89479
+ if (kept.length) pageImages.set(page, kept);
89480
+ else pageImages.delete(page);
89481
+ }
89482
+ warnings.push({ message: `PNG 인코딩 실패로 그림 ${state.failed.size}개를 추출하지 못했습니다`, code: "SKIPPED_IMAGE" });
89483
+ }
89364
89484
  }
89365
89485
  function injectPageImageBlocks(blocks, pageImages) {
89366
89486
  if (pageImages.size === 0) return;
@@ -89445,7 +89565,7 @@ function placeImagesInFlow(blocks, pageImages) {
89445
89565
  blocks.length = 0;
89446
89566
  for (const b of result) blocks.push(b);
89447
89567
  }
89448
- var import_node_crypto3, IMAGE_RESOLVE_TIMEOUT_MS, MIN_DIM, MAX_PIXELS3, MAX_IMAGES_PER_DOC, MAX_TOTAL_IMAGE_BYTES, MAX_PENDING_RAW_BYTES, NO_BYTES, WEBP_MAX_DIM2, webpable, imageFilename;
89568
+ var import_node_crypto3, IMAGE_RESOLVE_TIMEOUT_MS, MIN_DIM, MAX_PIXELS3, MAX_IMAGES_PER_DOC, MAX_TOTAL_IMAGE_BYTES, MAX_PENDING_RAW_BYTES, MAX_PENDING_PNG_IMAGES, MIN_ASYNC_PNG_BYTES, NO_BYTES, WEBP_MAX_DIM2, webpable, imageFilename;
89449
89569
  var init_image_extract = __esm({
89450
89570
  "src/pdf/image-extract.ts"() {
89451
89571
  "use strict";
@@ -89460,6 +89580,8 @@ var init_image_extract = __esm({
89460
89580
  MAX_IMAGES_PER_DOC = 200;
89461
89581
  MAX_TOTAL_IMAGE_BYTES = 128 * 1024 * 1024;
89462
89582
  MAX_PENDING_RAW_BYTES = 64 * 1024 * 1024;
89583
+ MAX_PENDING_PNG_IMAGES = 4;
89584
+ MIN_ASYNC_PNG_BYTES = 64 * 1024;
89463
89585
  NO_BYTES = new Uint8Array(0);
89464
89586
  WEBP_MAX_DIM2 = 16383;
89465
89587
  webpable = (state, w, h) => !!state.webp && w <= WEBP_MAX_DIM2 && h <= WEBP_MAX_DIM2;
@@ -93373,7 +93495,7 @@ async function parsePdfDocument(buffer, options) {
93373
93495
  splitContactTables(blocks);
93374
93496
  if (!options?.keepTrailingEmptyCols) trimTrailingEmptyTableCols(blocks);
93375
93497
  joinPageBreakWraps(blocks, wrapLexicon);
93376
- await flushPdfImages(imageState, warnings, pageImageBlocks);
93498
+ await flushPdfImages(imageState, warnings, pageImageBlocks, extractedImages);
93377
93499
  injectPageImageBlocks(blocks, pageImageBlocks);
93378
93500
  if (options?.formulaOcr && formulaBuffer) {
93379
93501
  try {