kordoc 4.25.21 → 4.25.22

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 +2 -2
  2. package/dist/{chunk-3AYNFK6J.js → chunk-2BC6IRWI.js} +2 -2
  3. package/dist/{chunk-ZO4P735U.js → chunk-2T27SM3Q.js} +2 -2
  4. package/dist/{chunk-KW4JO5CV.js → chunk-3ABE7X6L.js} +3 -3
  5. package/dist/{chunk-QOCUFTT4.js → chunk-5B2IKEEY.js} +5 -5
  6. package/dist/{chunk-6MCJHRSM.js → chunk-D57I7HNQ.js} +2 -2
  7. package/dist/{chunk-HQILGS2O.js → chunk-F64JL4SC.js} +2 -2
  8. package/dist/{chunk-S553BW45.js → chunk-FU2VJEA7.js} +6 -6
  9. package/dist/{chunk-MWCJYIJC.js → chunk-GEQU7GFI.js} +19 -19
  10. package/dist/{chunk-5ULHNZ3P.js → chunk-GG2M23FC.js} +3 -3
  11. package/dist/{chunk-PVOLFVXE.js → chunk-IKU7LVKA.js} +2 -2
  12. package/dist/{chunk-DHXKCDAU.js → chunk-IWPT63UP.js} +66 -9
  13. package/dist/chunk-IWPT63UP.js.map +7 -0
  14. package/dist/{chunk-LSUTK3DH.js → chunk-JY2OBKK2.js} +2 -2
  15. package/dist/{chunk-24LB25LZ.js → chunk-LNJUYPFX.js} +2 -2
  16. package/dist/{chunk-6I3X54AQ.js → chunk-LY235W6K.js} +2 -2
  17. package/dist/{chunk-QNJ2LMUO.js → chunk-M4V6DG5V.js} +8 -8
  18. package/dist/{chunk-B2SRYWEY.js → chunk-MJ2B3EXE.js} +19 -1
  19. package/dist/{chunk-B2SRYWEY.js.map → chunk-MJ2B3EXE.js.map} +2 -2
  20. package/dist/{chunk-W5AHXAUP.js → chunk-MNHHSFDQ.js} +7 -7
  21. package/dist/{chunk-PFNZQ3XI.js → chunk-OQX5GAZU.js} +2 -2
  22. package/dist/{chunk-GJORKM42.js → chunk-PTYOQBAD.js} +2 -2
  23. package/dist/{chunk-XUBBFY3H.js → chunk-RPMBH66S.js} +6 -6
  24. package/dist/{chunk-XUBBFY3H.js.map → chunk-RPMBH66S.js.map} +2 -2
  25. package/dist/{chunk-COJYQKGH.js → chunk-SBXUMTMQ.js} +4 -4
  26. package/dist/{chunk-FDSFXE2L.js → chunk-SZHSPADM.js} +2 -2
  27. package/dist/{chunk-ZCMMU34Z.js → chunk-U4IIEEPU.js} +2 -2
  28. package/dist/{chunk-TI6S3KZF.js → chunk-VE4T5RNY.js} +2 -2
  29. package/dist/{chunk-5MDRUEHP.js → chunk-VTFMNEQA.js} +3 -3
  30. package/dist/{chunk-DZOA5N5W.js → chunk-X4LW6P67.js} +2 -2
  31. package/dist/{chunk-TYJSNW4Z.js → chunk-XJWOBLDL.js} +131 -32
  32. package/dist/chunk-XJWOBLDL.js.map +7 -0
  33. package/dist/chunks-S5RQ5IVJ.js +10 -0
  34. package/dist/cli.js +38 -38
  35. package/dist/{formula-HMKT4BZL.js → formula-62KCIJTD.js} +4 -4
  36. package/dist/generator-OGG7G6RV.js +18 -0
  37. package/dist/{hancom-QWJBWOOE.js → hancom-SGF24IFE.js} +2 -2
  38. package/dist/{image-ocr-P5AIZNT3.js → image-ocr-ZGRESXDU.js} +11 -11
  39. package/dist/index.cjs +205 -28
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.d.cts +5 -0
  42. package/dist/index.d.ts +5 -0
  43. package/dist/index.js +22 -22
  44. package/dist/mcp.js +34 -34
  45. package/dist/memo-C6TAWLJY.js +15 -0
  46. package/dist/{model-bundle-5CXCIZHZ.js → model-bundle-ZB3IUIDI.js} +5 -5
  47. package/dist/{models-PS4L7NLP.js → models-JW4G7TAS.js} +5 -5
  48. package/dist/{page-images-QW7IUTUB.js → page-images-MW7EJGDY.js} +2 -2
  49. package/dist/{parse-worker-v2-PRH6KVKP.js → parse-worker-v2-24QWDLDW.js} +24 -24
  50. package/dist/{parser-OQIR5ZMI.js → parser-X74GRUEK.js} +14 -14
  51. package/dist/{pdf-ocr-ZH4JAUTR.js → pdf-ocr-5N4CHVYH.js} +9 -9
  52. package/dist/{profile-io-JFRAM2VE.js → profile-io-EDOARKYW.js} +3 -3
  53. package/dist/{rasterize-JJOMUTYX.js → rasterize-YHFV2XB4.js} +3 -3
  54. package/dist/{redact-doc-A7TW4MNF.js → redact-doc-YAQFZNBP.js} +23 -23
  55. package/dist/{render-VAOMAQV2.js → render-YKPIJ5XF.js} +10 -10
  56. package/dist/{rewrite-fallback-7PR7V3AZ.js → rewrite-fallback-W4SQTEKX.js} +13 -13
  57. package/dist/seal-IZ77VWF2.js +14 -0
  58. package/dist/{setup-6DXZJQCT.js → setup-GVWJ2UM5.js} +3 -3
  59. package/dist/{to-hwpx-A56R6H27.js → to-hwpx-LC7SM2NG.js} +7 -7
  60. package/dist/visual-FRQN5F77.js +42 -0
  61. package/dist/{watch-7W6CKGX7.js → watch-EHCJUHRO.js} +23 -23
  62. package/package.json +1 -1
  63. package/dist/chunk-DHXKCDAU.js.map +0 -7
  64. package/dist/chunk-TYJSNW4Z.js.map +0 -7
  65. package/dist/chunks-XX7RHVQF.js +0 -10
  66. package/dist/generator-HOY4SZ26.js +0 -18
  67. package/dist/memo-Q7772VJD.js +0 -15
  68. package/dist/seal-RZZNRJFL.js +0 -14
  69. package/dist/visual-25RY7EFI.js +0 -42
  70. /package/dist/{chunk-3AYNFK6J.js.map → chunk-2BC6IRWI.js.map} +0 -0
  71. /package/dist/{chunk-ZO4P735U.js.map → chunk-2T27SM3Q.js.map} +0 -0
  72. /package/dist/{chunk-KW4JO5CV.js.map → chunk-3ABE7X6L.js.map} +0 -0
  73. /package/dist/{chunk-QOCUFTT4.js.map → chunk-5B2IKEEY.js.map} +0 -0
  74. /package/dist/{chunk-6MCJHRSM.js.map → chunk-D57I7HNQ.js.map} +0 -0
  75. /package/dist/{chunk-HQILGS2O.js.map → chunk-F64JL4SC.js.map} +0 -0
  76. /package/dist/{chunk-S553BW45.js.map → chunk-FU2VJEA7.js.map} +0 -0
  77. /package/dist/{chunk-MWCJYIJC.js.map → chunk-GEQU7GFI.js.map} +0 -0
  78. /package/dist/{chunk-5ULHNZ3P.js.map → chunk-GG2M23FC.js.map} +0 -0
  79. /package/dist/{chunk-PVOLFVXE.js.map → chunk-IKU7LVKA.js.map} +0 -0
  80. /package/dist/{chunk-LSUTK3DH.js.map → chunk-JY2OBKK2.js.map} +0 -0
  81. /package/dist/{chunk-24LB25LZ.js.map → chunk-LNJUYPFX.js.map} +0 -0
  82. /package/dist/{chunk-6I3X54AQ.js.map → chunk-LY235W6K.js.map} +0 -0
  83. /package/dist/{chunk-QNJ2LMUO.js.map → chunk-M4V6DG5V.js.map} +0 -0
  84. /package/dist/{chunk-W5AHXAUP.js.map → chunk-MNHHSFDQ.js.map} +0 -0
  85. /package/dist/{chunk-PFNZQ3XI.js.map → chunk-OQX5GAZU.js.map} +0 -0
  86. /package/dist/{chunk-GJORKM42.js.map → chunk-PTYOQBAD.js.map} +0 -0
  87. /package/dist/{chunk-COJYQKGH.js.map → chunk-SBXUMTMQ.js.map} +0 -0
  88. /package/dist/{chunk-FDSFXE2L.js.map → chunk-SZHSPADM.js.map} +0 -0
  89. /package/dist/{chunk-ZCMMU34Z.js.map → chunk-U4IIEEPU.js.map} +0 -0
  90. /package/dist/{chunk-TI6S3KZF.js.map → chunk-VE4T5RNY.js.map} +0 -0
  91. /package/dist/{chunk-5MDRUEHP.js.map → chunk-VTFMNEQA.js.map} +0 -0
  92. /package/dist/{chunk-DZOA5N5W.js.map → chunk-X4LW6P67.js.map} +0 -0
  93. /package/dist/{chunks-XX7RHVQF.js.map → chunks-S5RQ5IVJ.js.map} +0 -0
  94. /package/dist/{formula-HMKT4BZL.js.map → formula-62KCIJTD.js.map} +0 -0
  95. /package/dist/{generator-HOY4SZ26.js.map → generator-OGG7G6RV.js.map} +0 -0
  96. /package/dist/{hancom-QWJBWOOE.js.map → hancom-SGF24IFE.js.map} +0 -0
  97. /package/dist/{image-ocr-P5AIZNT3.js.map → image-ocr-ZGRESXDU.js.map} +0 -0
  98. /package/dist/{memo-Q7772VJD.js.map → memo-C6TAWLJY.js.map} +0 -0
  99. /package/dist/{model-bundle-5CXCIZHZ.js.map → model-bundle-ZB3IUIDI.js.map} +0 -0
  100. /package/dist/{models-PS4L7NLP.js.map → models-JW4G7TAS.js.map} +0 -0
  101. /package/dist/{page-images-QW7IUTUB.js.map → page-images-MW7EJGDY.js.map} +0 -0
  102. /package/dist/{parse-worker-v2-PRH6KVKP.js.map → parse-worker-v2-24QWDLDW.js.map} +0 -0
  103. /package/dist/{parser-OQIR5ZMI.js.map → parser-X74GRUEK.js.map} +0 -0
  104. /package/dist/{pdf-ocr-ZH4JAUTR.js.map → pdf-ocr-5N4CHVYH.js.map} +0 -0
  105. /package/dist/{profile-io-JFRAM2VE.js.map → profile-io-EDOARKYW.js.map} +0 -0
  106. /package/dist/{rasterize-JJOMUTYX.js.map → rasterize-YHFV2XB4.js.map} +0 -0
  107. /package/dist/{redact-doc-A7TW4MNF.js.map → redact-doc-YAQFZNBP.js.map} +0 -0
  108. /package/dist/{render-VAOMAQV2.js.map → render-YKPIJ5XF.js.map} +0 -0
  109. /package/dist/{rewrite-fallback-7PR7V3AZ.js.map → rewrite-fallback-W4SQTEKX.js.map} +0 -0
  110. /package/dist/{seal-RZZNRJFL.js.map → seal-IZ77VWF2.js.map} +0 -0
  111. /package/dist/{setup-6DXZJQCT.js.map → setup-GVWJ2UM5.js.map} +0 -0
  112. /package/dist/{to-hwpx-A56R6H27.js.map → to-hwpx-LC7SM2NG.js.map} +0 -0
  113. /package/dist/{visual-25RY7EFI.js.map → visual-FRQN5F77.js.map} +0 -0
  114. /package/dist/{watch-7W6CKGX7.js.map → watch-EHCJUHRO.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.21" : "0.0.0-dev";
384
+ VERSION = true ? "4.25.22" : "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: "각주 텍스트 수정은 미지원 — 본문만 적용", before: bm[1], after: am[1] });
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
- var AUTOLINK, AUTONUM_PREFIX_RE, LAYOUT_MODE_MISMATCH;
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
 
@@ -81564,6 +81636,30 @@ var init_embedded_line_patch = __esm({
81564
81636
  }
81565
81637
  });
81566
81638
 
81639
+ // src/roundtrip/note-edit.ts
81640
+ function noteEditSplices(host2, xml, origNote, newNote) {
81641
+ if (!host2.notes?.length || xml === void 0) return NOTE_TEXT_UNSUPPORTED;
81642
+ const plan = planNoteEdits(origNote, newNote, host2.notes.map((paras) => paras.map((p) => p.text).join(" ")));
81643
+ if (typeof plan === "string") return plan;
81644
+ const out = [];
81645
+ for (const edit of plan) {
81646
+ const paras = host2.notes[edit.index].filter((p) => normForMatch(p.text) !== "");
81647
+ const one = noteParaEdit(paras.map((p) => normForMatch(p.text)), edit.before, edit.after);
81648
+ if (!one) return "각주의 여러 문단에 걸친 수정은 미지원 — 각주 글 수정 미적용";
81649
+ const sp = minimalTextSplices(paras[one.index], xml, one.before, one.after);
81650
+ if (!sp) return "각주 문단을 원문과 맞대지 못함 — 각주 글 수정 미적용";
81651
+ out.push(...sp);
81652
+ }
81653
+ return out;
81654
+ }
81655
+ var init_note_edit = __esm({
81656
+ "src/roundtrip/note-edit.ts"() {
81657
+ "use strict";
81658
+ init_inline_edit();
81659
+ init_markdown_units();
81660
+ }
81661
+ });
81662
+
81567
81663
  // src/roundtrip/table-patch.ts
81568
81664
  function patchGfmTable(table2, scanTable, orig, edited, ctx, skip) {
81569
81665
  const replica = replicateGfmTable(table2);
@@ -81815,17 +81911,31 @@ function patchTextChunkTable(table2, scanTable, orig, edited, ctx, skip) {
81815
81911
  return skip("표 렌더 경로 식별 실패");
81816
81912
  }
81817
81913
  function applyCellEdit(table2, scanTable, gridR, gridC, newLines, ctx, before2, after2, origLineCount) {
81914
+ let noteApplied = false;
81818
81915
  const skip = (reason) => {
81819
81916
  ctx.skipped.push({ reason, before: summarize(before2), after: summarize(after2) });
81820
- return 0;
81917
+ return noteApplied ? 1 : 0;
81821
81918
  };
81822
81919
  const cell2 = scanTable.cellByAnchor.get(`${gridR},${gridC}`);
81823
81920
  if (!cell2) return skip("셀 좌표 매핑 실패 (병합 영역의 빈 칸이거나 좌표 불일치)");
81824
81921
  const origLines = gfmCellLines(before2);
81825
81922
  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));
81923
+ const hosts = cell2.paragraphs.filter((p) => p.notes?.length);
81924
+ const notedLines = origLines.map((l, i) => /\(주: [\s\S]*\)$/.test(l) ? i : -1).filter((i) => i >= 0);
81925
+ const notes = newLines.map((l, i) => splitCellNote(origLines[i], l, ctx.skipped, (origNote, newNote) => {
81926
+ const host2 = hosts.length === notedLines.length ? hosts[notedLines.indexOf(i)] : void 0;
81927
+ if (!host2) return false;
81928
+ const sp = noteEditSplices(host2, ctx.scans[host2.sectionIndex]?.xml, origNote, newNote);
81929
+ if (typeof sp === "string") ctx.skipped.push({ reason: sp, before: origNote, after: newNote });
81930
+ else if (sp.length) {
81931
+ ctx.sectionSplices[host2.sectionIndex].push(...sp);
81932
+ noteApplied = true;
81933
+ }
81934
+ return true;
81935
+ }));
81827
81936
  newLines = notes.map((n) => n.after);
81828
81937
  before2 = notes.map((n) => n.before).join("<br>");
81938
+ if (notes.every((n) => normForMatch(n.before) === normForMatch(n.after))) return noteApplied ? 1 : 0;
81829
81939
  }
81830
81940
  const irCell = table2.cells[gridR]?.[gridC];
81831
81941
  const scanJoined = cell2.paragraphs.map((p) => p.text).filter((t) => normForMatch(t)).join("\n");
@@ -81936,7 +82046,7 @@ function applyCellEdit(table2, scanTable, gridR, gridC, newLines, ctx, before2,
81936
82046
  sectionIndex = nonEmpty[i].sectionIndex;
81937
82047
  }
81938
82048
  }
81939
- if (splices.length === 0) return 0;
82049
+ if (splices.length === 0) return noteApplied ? 1 : 0;
81940
82050
  ctx.sectionSplices[sectionIndex].push(...splices);
81941
82051
  if (emphMissed) ctx.skipped.push({ reason: EMPHASIS_NOTE, before: summarize(before2), after: summarize(after2), partial: true });
81942
82052
  return 1;
@@ -81953,6 +82063,7 @@ var init_table_patch = __esm({
81953
82063
  init_recognize();
81954
82064
  init_builder();
81955
82065
  init_click_here();
82066
+ init_note_edit();
81956
82067
  init_structure_edit();
81957
82068
  EMPHASIS_NOTE = "강조(굵게·밑줄 등) 추가·삭제는 미지원: 글만 적용, 원문 글자 모양 유지";
81958
82069
  CELL_TOKEN_RE = /!\[image\]\([^)]*\)|\[이미지: [^\]]*\]/g;
@@ -83261,6 +83372,17 @@ function scanSection(stream, sectionIndex, compressed) {
83261
83372
  paras.push(para2);
83262
83373
  parasByHeader.set(i, para2);
83263
83374
  }
83375
+ for (let i = 0; i < records.length; i++) {
83376
+ if (!isCtrl(records[i], CTRL_FN2) && !isCtrl(records[i], CTRL_EN2)) continue;
83377
+ const host2 = parent[i] >= 0 ? parasByHeader.get(parent[i]) : void 0;
83378
+ if (!host2) continue;
83379
+ const list = [];
83380
+ for (let j = i + 1; j < records.length && records[j].level > records[i].level; j++) {
83381
+ const np = parent[j] === i ? parasByHeader.get(j) : void 0;
83382
+ if (np) list.push(np);
83383
+ }
83384
+ (host2.notes ??= []).push(list);
83385
+ }
83264
83386
  const scanTable = (i, depth) => {
83265
83387
  const ctrlLevel = records[i].level;
83266
83388
  let rows = 0, cols = 0, tableIdx = -1;
@@ -83681,12 +83803,14 @@ function patchParagraph(block, orig, edited, ctx, skip) {
83681
83803
  return skip("다중줄 문단 수정에 <br> 없음 — 줄바꿈 위치 보존 불가로 미지원 (줄바꿈은 <br>로 표기)");
83682
83804
  }
83683
83805
  let noteEdited = false;
83806
+ let noteApplied = false;
83684
83807
  if (block.footnoteText) {
83685
83808
  const noteMatch = newPlain.match(/\s*\(주: ([\s\S]*)\)$/);
83686
83809
  if (noteMatch) {
83687
83810
  newPlain = newPlain.slice(0, noteMatch.index).trimEnd();
83688
83811
  if (normForMatch(noteMatch[1]) !== normForMatch(block.footnoteText)) {
83689
- ctx.skipped.push({ reason: "각주 텍스트 수정은 미지원 — 본문만 적용", before: block.footnoteText, after: noteMatch[1] });
83812
+ noteApplied = !block.footnoteBlocks && stageNoteEdit(mapping.para, block.footnoteText, noteMatch[1], ctx);
83813
+ if (block.footnoteBlocks) ctx.skipped.push({ reason: NOTE_TEXT_UNSUPPORTED, before: block.footnoteText, after: noteMatch[1] });
83690
83814
  noteEdited = true;
83691
83815
  }
83692
83816
  } else {
@@ -83705,9 +83829,9 @@ function patchParagraph(block, orig, edited, ctx, skip) {
83705
83829
  }
83706
83830
  let origPlain = block.text != null ? noScriptTags(block.text) : restoreBr(origStyled.plain);
83707
83831
  if (mapping.noteMarks?.length) origPlain = removeNoteMarks(origPlain, mapping.noteMarks).text;
83708
- if (newPlain === origPlain) return noteEdited ? 0 : skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
83832
+ if (newPlain === origPlain) return noteEdited ? noteApplied ? 1 : 0 : skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
83709
83833
  if (sanitizeText(newPlain) !== newPlain && sanitizeText(origPlain) === origPlain) {
83710
- return skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원");
83834
+ return Math.max(skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원"), noteApplied ? 1 : 0);
83711
83835
  }
83712
83836
  let origMd = restoreBr(origStyled.plain);
83713
83837
  if (block.footnoteText) origMd = origMd.replace(/\s*\(주: [\s\S]*\)$/, "");
@@ -83719,7 +83843,28 @@ function patchParagraph(block, orig, edited, ctx, skip) {
83719
83843
  if (n && (style2?.missed || style2 && restyledKept(origStyled, editedStyled, origStyled.plain, editedStyled.plain))) {
83720
83844
  ctx.skipped.push({ reason: EMPHASIS_NOTE, before: summarize(orig.raw), after: summarize(edited.raw), partial: true });
83721
83845
  }
83722
- return n;
83846
+ return Math.max(n, noteApplied ? 1 : 0);
83847
+ }
83848
+ function stageNoteEdit(host2, origNote, newNote, ctx) {
83849
+ const note = (reason) => {
83850
+ ctx.skipped.push({ reason, before: summarize(origNote), after: summarize(newNote) });
83851
+ return 0;
83852
+ };
83853
+ if (!host2.notes?.length) return note(NOTE_TEXT_UNSUPPORTED) > 0;
83854
+ const plan = planNoteEdits(origNote, newNote, host2.notes.map((paras) => paras.map((p) => p.rawText).join(" ")));
83855
+ if (typeof plan === "string") return note(plan) > 0;
83856
+ let staged = 0;
83857
+ for (const edit of plan) {
83858
+ const paras = host2.notes[edit.index].filter((p) => normForMatch(p.rawText) !== "");
83859
+ const one = noteParaEdit(paras.map((p) => normForMatch(p.rawText)), edit.before, edit.after);
83860
+ if (!one) {
83861
+ note("각주의 여러 문단에 걸친 수정은 미지원 — 각주 글 수정 미적용");
83862
+ continue;
83863
+ }
83864
+ const para2 = paras[one.index];
83865
+ staged += stageParaPatch(ctx.scans[para2.sectionIndex], para2, one.after, note, ctx.keepLineseg, one.before);
83866
+ }
83867
+ return staged > 0;
83723
83868
  }
83724
83869
  function patchGfmCells(scanTable, orig, edited, ctx, skip) {
83725
83870
  const origRows = parseGfmTable(orig.lines);
@@ -83750,18 +83895,27 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
83750
83895
  continue;
83751
83896
  }
83752
83897
  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
83898
  const para2 = cell2.paras[0];
83899
+ let noteDone = 0;
83900
+ const { before: before2, after: after2, noted } = splitCellNote(beforeEach.join("\n"), afterEach.join("\n"), ctx.skipped, (o, n) => {
83901
+ if (stageNoteEdit(para2, o, n, ctx)) noteDone = 1;
83902
+ return true;
83903
+ });
83904
+ if (before2 === after2) {
83905
+ applied += noteDone;
83906
+ continue;
83907
+ }
83756
83908
  if (normForMatch(para2.rawText) !== normForMatch(before2)) {
83757
83909
  cellSkip("셀 텍스트 불일치 — 소스맵 신뢰 불가");
83910
+ applied += noteDone;
83758
83911
  continue;
83759
83912
  }
83760
83913
  if (afterEach.some((l) => sanitizeText(l) !== l)) {
83761
83914
  cellSkip("공백 정규화 불안정 텍스트 — 미지원");
83915
+ applied += noteDone;
83762
83916
  continue;
83763
83917
  }
83764
- applied += stageParaPatch(
83918
+ applied += Math.max(noteDone, stageParaPatch(
83765
83919
  ctx.scans[para2.sectionIndex],
83766
83920
  para2,
83767
83921
  after2,
@@ -83770,7 +83924,7 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
83770
83924
  before2,
83771
83925
  // 바뀐 자리만 — 굵은 조각 등 run 유지
83772
83926
  noted ? void 0 : cellLineStyles(origRows[r][c], editedRows[r][c], ctx.charBook)(0, after2)
83773
- );
83927
+ ));
83774
83928
  continue;
83775
83929
  }
83776
83930
  if (beforeParts.length !== cell2.paras.length || afterParts.length !== cell2.paras.length) {
@@ -83785,22 +83939,32 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
83785
83939
  break;
83786
83940
  }
83787
83941
  if (rawBefore === rawAfter) continue;
83788
- const { before: before2, after: after2, noted } = splitCellNote(rawBefore, rawAfter, ctx.skipped);
83789
- if (before2 === after2) continue;
83942
+ const para2 = cell2.paras[k];
83943
+ let noteDone = 0;
83944
+ const { before: before2, after: after2, noted } = splitCellNote(rawBefore, rawAfter, ctx.skipped, (o, n) => {
83945
+ if (stageNoteEdit(para2, o, n, ctx)) noteDone = 1;
83946
+ return true;
83947
+ });
83948
+ if (before2 === after2) {
83949
+ applied += noteDone;
83950
+ continue;
83951
+ }
83790
83952
  if (after2.includes("\n")) {
83791
83953
  cellSkip("셀 내 줄바꿈 추가는 미지원 (v1)");
83954
+ applied += noteDone;
83792
83955
  break;
83793
83956
  }
83794
- const para2 = cell2.paras[k];
83795
83957
  if (normForMatch(para2.rawText) !== normForMatch(before2)) {
83796
83958
  cellSkip("셀 텍스트 불일치 — 소스맵 신뢰 불가");
83959
+ applied += noteDone;
83797
83960
  break;
83798
83961
  }
83799
83962
  if (sanitizeText(after2) !== after2) {
83800
83963
  cellSkip("공백 정규화 불안정 텍스트 — 미지원");
83964
+ applied += noteDone;
83801
83965
  break;
83802
83966
  }
83803
- applied += stageParaPatch(
83967
+ applied += Math.max(noteDone, stageParaPatch(
83804
83968
  ctx.scans[para2.sectionIndex],
83805
83969
  para2,
83806
83970
  after2,
@@ -83809,7 +83973,7 @@ function patchGfmCells(scanTable, orig, edited, ctx, skip) {
83809
83973
  before2,
83810
83974
  // 바뀐 자리만 — 굵은 조각 등 run 유지
83811
83975
  noted ? void 0 : cellLineStyles(origRows[r][c], editedRows[r][c], ctx.charBook)(k, after2)
83812
- );
83976
+ ));
83813
83977
  }
83814
83978
  }
83815
83979
  }
@@ -83992,7 +84156,7 @@ function compressWithTail(raw) {
83992
84156
  tail.writeUInt32LE(raw.length >>> 0, 4);
83993
84157
  return Buffer.concat([(0, import_zlib8.deflateRawSync)(raw), tail]);
83994
84158
  }
83995
- var import_zlib8, import_module3, require4, CFB3, TAG_PARA_LINE_SEG2, CTRL_TBL2, CTRL_GSO2, CRC_TABLE3;
84159
+ var import_zlib8, import_module3, require4, CFB3, TAG_PARA_LINE_SEG2, CTRL_TBL2, CTRL_GSO2, CTRL_FN2, CTRL_EN2, CRC_TABLE3;
83996
84160
  var init_hwp5_patch = __esm({
83997
84161
  "src/roundtrip/hwp5-patch.ts"() {
83998
84162
  "use strict";
@@ -84016,6 +84180,8 @@ var init_hwp5_patch = __esm({
84016
84180
  TAG_PARA_LINE_SEG2 = 69;
84017
84181
  CTRL_TBL2 = cid2("tbl ");
84018
84182
  CTRL_GSO2 = cid2("gso ");
84183
+ CTRL_FN2 = cid2("fn ");
84184
+ CTRL_EN2 = cid2("en ");
84019
84185
  CRC_TABLE3 = (() => {
84020
84186
  const t = new Uint32Array(256);
84021
84187
  for (let n = 0; n < 256; n++) {
@@ -84594,14 +84760,21 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
84594
84760
  let newPlain = newInline.plain;
84595
84761
  const segsUsable = !block.footnoteText && !mapping.noteMarks?.length && !mapping.prefixStripped;
84596
84762
  let noteEdited = false;
84763
+ let noteApplied = false;
84597
84764
  if (block.footnoteText) {
84598
- const origNote = block.footnoteBlocks ? origPlain.match(/\s*\(주: ([\s\S]*)\)$/)?.[1] : void 0;
84765
+ const mdNote = origPlain.match(/\s*\(주: ([\s\S]*)\)$/)?.[1];
84766
+ const origNote = block.footnoteBlocks ? mdNote : void 0;
84599
84767
  origPlain = origPlain.replace(/\s*\(주: [\s\S]*\)$/, "");
84600
84768
  const noteMatch = newPlain.match(/\s*\(주: ([\s\S]*)\)$/);
84601
84769
  if (noteMatch) {
84602
84770
  newPlain = newPlain.slice(0, noteMatch.index).trimEnd();
84603
84771
  if (normForMatch(noteMatch[1]) !== normForMatch(origNote ?? block.footnoteText)) {
84604
- ctx.skipped.push({ reason: "각주 텍스트 수정은 미지원 — 본문만 적용", before: block.footnoteText, after: noteMatch[1] });
84772
+ const sp = block.footnoteBlocks ? NOTE_TEXT_UNSUPPORTED : noteEditSplices(mapping.para, ctx.scans[mapping.para.sectionIndex]?.xml, mdNote ?? block.footnoteText, noteMatch[1]);
84773
+ if (typeof sp === "string") ctx.skipped.push({ reason: sp, before: block.footnoteText, after: noteMatch[1] });
84774
+ else if (sp.length) {
84775
+ ctx.sectionSplices[mapping.para.sectionIndex].push(...sp);
84776
+ noteApplied = true;
84777
+ }
84605
84778
  noteEdited = true;
84606
84779
  }
84607
84780
  } else {
@@ -84620,9 +84793,12 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
84620
84793
  newPlain = head.text;
84621
84794
  if (head.note) ctx.skipped.push({ reason: head.note, after: summarize(newPlain), partial: true });
84622
84795
  }
84623
- if (newPlain === origPlain) return noteEdited ? 0 : skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
84796
+ if (newPlain === origPlain) {
84797
+ if (!noteEdited) return skip("텍스트 외 변경(헤딩 레벨/서식)만 감지 — 스타일 변경은 미지원");
84798
+ return noteApplied ? 1 : 0;
84799
+ }
84624
84800
  if (sanitizeText(newPlain) !== newPlain && sanitizeText(origPlain) === origPlain) {
84625
- return skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원");
84801
+ return Math.max(skip("공백 정규화 불안정 텍스트 — 패치 시 원문 보존 불가로 미지원"), noteApplied ? 1 : 0);
84626
84802
  }
84627
84803
  const xml = ctx.scans[mapping.para.sectionIndex]?.xml;
84628
84804
  const book = ctx.charBook;
@@ -84635,7 +84811,7 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
84635
84811
  } : void 0;
84636
84812
  const minimal = xml ? minimalTextSplices(mapping.para, xml, origPlain, newPlain, segsUsable ? origInline.segs : void 0, segsUsable ? newInline.segs : void 0, style2) : null;
84637
84813
  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("문단에 텍스트 노드를 만들 수 없음");
84814
+ if (splices === null) return Math.max(skip("문단에 텍스트 노드를 만들 수 없음"), noteApplied ? 1 : 0);
84639
84815
  ctx.sectionSplices[mapping.para.sectionIndex].push(...splices);
84640
84816
  if (origInline.segs.length !== newInline.segs.length && (!minimal || !style2 || style2.missed || restyledKept(origInline, newInline, origInline.plain, newInline.plain))) {
84641
84817
  ctx.skipped.push({ reason: EMPHASIS_NOTE, before: summarize(orig.raw), after: summarize(edited.raw), partial: true });
@@ -84754,6 +84930,7 @@ var init_patcher = __esm({
84754
84930
  init_inline_edit();
84755
84931
  init_char_pr();
84756
84932
  init_click_here();
84933
+ init_note_edit();
84757
84934
  init_line_break_edit();
84758
84935
  init_text_fallback();
84759
84936
  init_parser_shared();