kordoc 4.24.2 → 4.24.4

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 (128) hide show
  1. package/README.md +13 -11
  2. package/dist/{-SRNEV7LS.js → -WND2HWVH.js} +11 -11
  3. package/dist/{chunk-NJ5RUDCW.js → chunk-3LSHLWTX.js} +3 -3
  4. package/dist/{chunk-WDSTW3BD.js → chunk-44E52JJ7.js} +2 -2
  5. package/dist/{chunk-R2GIGE5H.js → chunk-47MTLP4U.js} +2 -2
  6. package/dist/{chunk-NMFFIUI6.js → chunk-4XVL3OBP.js} +2 -2
  7. package/dist/{chunk-C6ZVB547.js → chunk-5AHG3XY3.js} +11 -11
  8. package/dist/{chunk-PNSALBXH.cjs → chunk-6A4KYMQR.cjs} +2 -2
  9. package/dist/{chunk-PNSALBXH.cjs.map → chunk-6A4KYMQR.cjs.map} +1 -1
  10. package/dist/{chunk-LMEF7FN5.js → chunk-6CPBNK5O.js} +2 -2
  11. package/dist/{chunk-MHNJOJQV.js → chunk-A5JDO52L.js} +4 -4
  12. package/dist/{chunk-M46PB75E.js → chunk-AKIJTKEA.js} +2 -2
  13. package/dist/{chunk-IGG63DFK.cjs → chunk-BODFTRWA.cjs} +3 -3
  14. package/dist/{chunk-IGG63DFK.cjs.map → chunk-BODFTRWA.cjs.map} +1 -1
  15. package/dist/{chunk-VPSF5LEM.js → chunk-BYYZUFPC.js} +11 -8
  16. package/dist/chunk-BYYZUFPC.js.map +1 -0
  17. package/dist/{chunk-E6VBLBOO.js → chunk-D4YWVZHD.js} +2 -2
  18. package/dist/{chunk-E7B5CXYI.js → chunk-DTADAHJD.js} +2 -2
  19. package/dist/{chunk-JMOAMKAR.js → chunk-E7N6BUJT.js} +12 -9
  20. package/dist/chunk-E7N6BUJT.js.map +1 -0
  21. package/dist/{chunk-WJAFE3Z6.js → chunk-FK3JPTHI.js} +2 -2
  22. package/dist/{chunk-W24TJJNN.js → chunk-GGVHKYKZ.js} +2 -2
  23. package/dist/{chunk-RIRPLFPN.js → chunk-JHUW5PKO.js} +8 -7
  24. package/dist/chunk-JHUW5PKO.js.map +1 -0
  25. package/dist/{chunk-HLTPMSYW.cjs → chunk-KFQNG2EA.cjs} +3 -3
  26. package/dist/{chunk-HLTPMSYW.cjs.map → chunk-KFQNG2EA.cjs.map} +1 -1
  27. package/dist/{chunk-4745MFQU.js → chunk-LBOXKGAH.js} +3 -3
  28. package/dist/{chunk-UNICY546.cjs → chunk-LJ7U7MFN.cjs} +31 -28
  29. package/dist/chunk-LJ7U7MFN.cjs.map +1 -0
  30. package/dist/{chunk-3HN65YAL.js → chunk-MC4DPT4I.js} +2 -2
  31. package/dist/{chunk-TDMBTG7U.js → chunk-MMPBJGWQ.js} +2 -2
  32. package/dist/{chunk-4XC4O7FJ.js → chunk-QTJTBCTZ.js} +4 -4
  33. package/dist/{chunk-JFUUFJZW.cjs → chunk-TPKP3WQU.cjs} +6 -6
  34. package/dist/{chunk-JFUUFJZW.cjs.map → chunk-TPKP3WQU.cjs.map} +1 -1
  35. package/dist/{chunk-TW3V6FSH.js → chunk-VBY3JQL2.js} +2 -2
  36. package/dist/{chunk-7NTMM6PO.js → chunk-WMDGGQXJ.js} +2 -2
  37. package/dist/{chunk-PNX5FYHC.cjs → chunk-WN5X4DT3.cjs} +24 -24
  38. package/dist/{chunk-PNX5FYHC.cjs.map → chunk-WN5X4DT3.cjs.map} +1 -1
  39. package/dist/{chunk-KUC5I5MB.js → chunk-YBCW544D.js} +2 -2
  40. package/dist/{chunk-DHMBPMKC.js → chunk-YEYNBH5W.js} +244 -31
  41. package/dist/chunk-YEYNBH5W.js.map +1 -0
  42. package/dist/chunks-2UDUNVGQ.js +10 -0
  43. package/dist/cli.js +30 -30
  44. package/dist/{formula-HK2MNZ3Q.cjs → formula-6DJAY3KI.cjs} +9 -9
  45. package/dist/{formula-HK2MNZ3Q.cjs.map → formula-6DJAY3KI.cjs.map} +1 -1
  46. package/dist/{formula-U2LZ67KI.js → formula-MPBZ7OMN.js} +3 -3
  47. package/dist/{formula-DSB574H7.js → formula-NA3LD35B.js} +4 -4
  48. package/dist/{image-ocr-3QB2HLSI.js → image-ocr-6TGDXUAS.js} +9 -9
  49. package/dist/{image-ocr-QNIMVE5A.cjs → image-ocr-REM4LZKX.cjs} +17 -17
  50. package/dist/{image-ocr-QNIMVE5A.cjs.map → image-ocr-REM4LZKX.cjs.map} +1 -1
  51. package/dist/{image-ocr-J54Q3YWP.js → image-ocr-THA5BASF.js} +6 -6
  52. package/dist/index.cjs +870 -656
  53. package/dist/index.cjs.map +1 -1
  54. package/dist/index.js +250 -36
  55. package/dist/index.js.map +1 -1
  56. package/dist/mcp.js +23 -23
  57. package/dist/{model-bundle-CGWU4ALC.js → model-bundle-3YDTJ6EQ.js} +5 -5
  58. package/dist/{models-A3TF3BDV.js → models-M7AX7VIN.js} +5 -5
  59. package/dist/{parse-worker-v2-MNUD4WAR.js → parse-worker-v2-3ZMFWDFW.js} +12 -12
  60. package/dist/{parser-RPAHN3OR.cjs → parser-GIDYL5LH.cjs} +163 -159
  61. package/dist/parser-GIDYL5LH.cjs.map +1 -0
  62. package/dist/{parser-OBGWEWSU.js → parser-MNNJSFEZ.js} +15 -11
  63. package/dist/parser-MNNJSFEZ.js.map +1 -0
  64. package/dist/{parser-C3ARF26I.js → parser-TD4VZDGY.js} +18 -14
  65. package/dist/parser-TD4VZDGY.js.map +1 -0
  66. package/dist/{pdf-ocr-K53REDNY.js → pdf-ocr-5HEVZKG5.js} +6 -6
  67. package/dist/{pdf-ocr-ENLVEEYL.js → pdf-ocr-6BAOQ6CY.js} +9 -9
  68. package/dist/pdf-ocr-NOSNTEDS.cjs +31 -0
  69. package/dist/{pdf-ocr-GA5QJFNK.cjs.map → pdf-ocr-NOSNTEDS.cjs.map} +1 -1
  70. package/dist/{profile-io-ZGFEO7CB.js → profile-io-H4WQIGN6.js} +3 -3
  71. package/dist/{rasterize-QMC2SAUT.js → rasterize-EOPWJWBO.js} +3 -3
  72. package/dist/{redact-doc-JH6RZZBE.js → redact-doc-BBZVAA3I.js} +11 -11
  73. package/dist/{render-ZGKQLKPJ.js → render-ZZ4CGJ6J.js} +7 -7
  74. package/dist/seal-RRYFKTEQ.js +10 -0
  75. package/dist/{setup-LAQGCYQ2.js → setup-UIPKBNLA.js} +3 -3
  76. package/dist/visual-DLLRTF6C.js +21 -0
  77. package/dist/{watch-7YPB4TKC.js → watch-OXQ6O5HD.js} +12 -12
  78. package/package.json +1 -1
  79. package/dist/chunk-DHMBPMKC.js.map +0 -1
  80. package/dist/chunk-JMOAMKAR.js.map +0 -1
  81. package/dist/chunk-RIRPLFPN.js.map +0 -1
  82. package/dist/chunk-UNICY546.cjs.map +0 -1
  83. package/dist/chunk-VPSF5LEM.js.map +0 -1
  84. package/dist/chunks-AL4P5TO5.js +0 -10
  85. package/dist/parser-C3ARF26I.js.map +0 -1
  86. package/dist/parser-OBGWEWSU.js.map +0 -1
  87. package/dist/parser-RPAHN3OR.cjs.map +0 -1
  88. package/dist/pdf-ocr-GA5QJFNK.cjs +0 -31
  89. package/dist/seal-KMGYTJAV.js +0 -10
  90. package/dist/visual-4OYJFGXL.js +0 -21
  91. /package/dist/{-SRNEV7LS.js.map → -WND2HWVH.js.map} +0 -0
  92. /package/dist/{chunk-NJ5RUDCW.js.map → chunk-3LSHLWTX.js.map} +0 -0
  93. /package/dist/{chunk-WDSTW3BD.js.map → chunk-44E52JJ7.js.map} +0 -0
  94. /package/dist/{chunk-R2GIGE5H.js.map → chunk-47MTLP4U.js.map} +0 -0
  95. /package/dist/{chunk-NMFFIUI6.js.map → chunk-4XVL3OBP.js.map} +0 -0
  96. /package/dist/{chunk-C6ZVB547.js.map → chunk-5AHG3XY3.js.map} +0 -0
  97. /package/dist/{chunk-LMEF7FN5.js.map → chunk-6CPBNK5O.js.map} +0 -0
  98. /package/dist/{chunk-MHNJOJQV.js.map → chunk-A5JDO52L.js.map} +0 -0
  99. /package/dist/{chunk-M46PB75E.js.map → chunk-AKIJTKEA.js.map} +0 -0
  100. /package/dist/{chunk-E6VBLBOO.js.map → chunk-D4YWVZHD.js.map} +0 -0
  101. /package/dist/{chunk-E7B5CXYI.js.map → chunk-DTADAHJD.js.map} +0 -0
  102. /package/dist/{chunk-WJAFE3Z6.js.map → chunk-FK3JPTHI.js.map} +0 -0
  103. /package/dist/{chunk-W24TJJNN.js.map → chunk-GGVHKYKZ.js.map} +0 -0
  104. /package/dist/{chunk-4745MFQU.js.map → chunk-LBOXKGAH.js.map} +0 -0
  105. /package/dist/{chunk-3HN65YAL.js.map → chunk-MC4DPT4I.js.map} +0 -0
  106. /package/dist/{chunk-TDMBTG7U.js.map → chunk-MMPBJGWQ.js.map} +0 -0
  107. /package/dist/{chunk-4XC4O7FJ.js.map → chunk-QTJTBCTZ.js.map} +0 -0
  108. /package/dist/{chunk-TW3V6FSH.js.map → chunk-VBY3JQL2.js.map} +0 -0
  109. /package/dist/{chunk-7NTMM6PO.js.map → chunk-WMDGGQXJ.js.map} +0 -0
  110. /package/dist/{chunk-KUC5I5MB.js.map → chunk-YBCW544D.js.map} +0 -0
  111. /package/dist/{chunks-AL4P5TO5.js.map → chunks-2UDUNVGQ.js.map} +0 -0
  112. /package/dist/{formula-U2LZ67KI.js.map → formula-MPBZ7OMN.js.map} +0 -0
  113. /package/dist/{formula-DSB574H7.js.map → formula-NA3LD35B.js.map} +0 -0
  114. /package/dist/{image-ocr-3QB2HLSI.js.map → image-ocr-6TGDXUAS.js.map} +0 -0
  115. /package/dist/{image-ocr-J54Q3YWP.js.map → image-ocr-THA5BASF.js.map} +0 -0
  116. /package/dist/{model-bundle-CGWU4ALC.js.map → model-bundle-3YDTJ6EQ.js.map} +0 -0
  117. /package/dist/{models-A3TF3BDV.js.map → models-M7AX7VIN.js.map} +0 -0
  118. /package/dist/{parse-worker-v2-MNUD4WAR.js.map → parse-worker-v2-3ZMFWDFW.js.map} +0 -0
  119. /package/dist/{pdf-ocr-ENLVEEYL.js.map → pdf-ocr-5HEVZKG5.js.map} +0 -0
  120. /package/dist/{pdf-ocr-K53REDNY.js.map → pdf-ocr-6BAOQ6CY.js.map} +0 -0
  121. /package/dist/{profile-io-ZGFEO7CB.js.map → profile-io-H4WQIGN6.js.map} +0 -0
  122. /package/dist/{rasterize-QMC2SAUT.js.map → rasterize-EOPWJWBO.js.map} +0 -0
  123. /package/dist/{redact-doc-JH6RZZBE.js.map → redact-doc-BBZVAA3I.js.map} +0 -0
  124. /package/dist/{render-ZGKQLKPJ.js.map → render-ZZ4CGJ6J.js.map} +0 -0
  125. /package/dist/{seal-KMGYTJAV.js.map → seal-RRYFKTEQ.js.map} +0 -0
  126. /package/dist/{setup-LAQGCYQ2.js.map → setup-UIPKBNLA.js.map} +0 -0
  127. /package/dist/{visual-4OYJFGXL.js.map → visual-DLLRTF6C.js.map} +0 -0
  128. /package/dist/{watch-7YPB4TKC.js.map → watch-OXQ6O5HD.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  visibleText
4
- } from "./chunk-WDSTW3BD.js";
4
+ } from "./chunk-44E52JJ7.js";
5
5
 
6
6
  // src/script-tags.ts
7
7
  var LITERAL_TAG = /<(?=\/?(?:u|sup|sub)>)/g;
@@ -328,4 +328,4 @@ export {
328
328
  HEADING_RATIO_H2,
329
329
  HEADING_RATIO_H3
330
330
  };
331
- //# sourceMappingURL=chunk-KUC5I5MB.js.map
331
+ //# sourceMappingURL=chunk-YBCW544D.js.map
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  loadSharp,
4
4
  rasterizePageSvg
5
- } from "./chunk-E6VBLBOO.js";
5
+ } from "./chunk-D4YWVZHD.js";
6
6
  import {
7
7
  inlineImagesIntoMarkdown
8
8
  } from "./chunk-VKVDMH7X.js";
@@ -16,7 +16,7 @@ import {
16
16
  HEADING_RATIO_H3,
17
17
  tidyScriptTags,
18
18
  unframeLayoutTables
19
- } from "./chunk-KUC5I5MB.js";
19
+ } from "./chunk-YBCW544D.js";
20
20
  import {
21
21
  MAX_COLS,
22
22
  MAX_ROWS,
@@ -32,7 +32,7 @@ import {
32
32
  mapPuaText,
33
33
  markNonLayoutTable,
34
34
  romanNumeral
35
- } from "./chunk-WDSTW3BD.js";
35
+ } from "./chunk-44E52JJ7.js";
36
36
  import {
37
37
  DEFAULT_CHAR,
38
38
  DEFAULT_PARA_GEOM,
@@ -46,7 +46,7 @@ import {
46
46
  hwpxAppMajor,
47
47
  parseRenderStyles,
48
48
  readZipEntry
49
- } from "./chunk-RIRPLFPN.js";
49
+ } from "./chunk-JHUW5PKO.js";
50
50
  import {
51
51
  KordocError,
52
52
  compareSectionPaths,
@@ -54,7 +54,7 @@ import {
54
54
  precheckZipSize,
55
55
  sanitizeHref,
56
56
  toArrayBuffer
57
- } from "./chunk-LMEF7FN5.js";
57
+ } from "./chunk-6CPBNK5O.js";
58
58
 
59
59
  // src/render/svg-render.ts
60
60
  import JSZip from "jszip";
@@ -163,6 +163,12 @@ function solveRowHeights(cells, rowCount, maxTotal = Number.POSITIVE_INFINITY, s
163
163
  for (const r of missing) h[r] = each;
164
164
  return true;
165
165
  };
166
+ for (let r = 0; r < rowCount; r++) {
167
+ if (h[r] !== 0) continue;
168
+ let need = 0;
169
+ for (const { c, rows } of spans) if (rows[rows.length - 1] === r && rows.slice(0, -1).every((q) => h[q] > 0)) need = Math.max(need, c.height - rows.slice(0, -1).reduce((t, q) => t + h[q], 0));
170
+ if (need > 0) h[r] = need;
171
+ }
166
172
  for (let again = true; again; ) {
167
173
  again = false;
168
174
  for (let k = 0; k < spans.length; k++) if (!done.has(k) && solve(k, true)) again = true;
@@ -179,7 +185,8 @@ function solveRowHeights(cells, rowCount, maxTotal = Number.POSITIVE_INFINITY, s
179
185
  }
180
186
  const last = rowCount - 1, over = total - maxTotal;
181
187
  const lastCells = cells.filter((c) => c.rowAddr + c.rowSpan - 1 === last);
182
- if (shrinkLast && over > 0 && last >= 0 && lastCells.length && lastCells.every((c) => c.rowSpan === 1 && c.contentH != null && c.contentH <= h[last] - over)) h[last] -= over;
188
+ const spanH = (c) => h.slice(c.rowAddr, c.rowAddr + c.rowSpan).reduce((t, x) => t + x, 0);
189
+ if (shrinkLast && over > 0 && last >= 0 && lastCells.length && lastCells.every((c) => c.contentH != null && c.contentH <= (c.rowSpan === 1 ? h[last] : spanH(c)) - over)) h[last] -= over;
183
190
  return h;
184
191
  }
185
192
 
@@ -11450,7 +11457,7 @@ function cellContentExtent(cell, memo) {
11450
11457
  const pushed = baseV - (Math.max(0, vo) + num(om, "top") + o.height + num(om, "bottom"));
11451
11458
  const anchor = pushed >= (paraStart > 0 ? paraStart - 100 : -100) ? pushed : baseV - (memo?.paraGeom?.get(p.getAttribute("paraPrIDRef") ?? "")?.spaceBefore ?? 0);
11452
11459
  const oh = o.tag === "tbl" ? Math.max(o.height, measureTableHeight(o.el, memo)) : o.height;
11453
- ext = Math.max(ext, anchor + num(om, "top") + Math.max(0, vo) + oh);
11460
+ ext = Math.max(ext, anchor + num(om, "top") + Math.max(0, vo) + oh + num(om, "bottom"));
11454
11461
  }
11455
11462
  }
11456
11463
  memo?.cell.set(cell.el, ext);
@@ -11517,7 +11524,7 @@ function measureTableRowHeights(tbl, memo) {
11517
11524
  const rows = solveRowHeights(
11518
11525
  // 여러 행 칸은 내용(+ 칸 여백)이 저장 높이보다 크면 내용 높이로 — 솔버가 모자란 만큼 그 칸 마지막 행을 키운다
11519
11526
  // (같은 판 PDF: 두 줄 든 2행 병합 칸 내용 2882 > 저장 2564 → 둘째 행이 318 자라고 첫 행은 그대로)
11520
- cells.map((c) => ({ rowAddr: c.ra, rowSpan: c.rs, height: (c.rs > 1 ? Math.max(c.h, cellContentExtent(c, memo) + c.marginT + c.marginB) : c.h) - sp * (c.rs - 1), contentH: c.rs === 1 ? cellContentExtent(c, memo) + c.marginT + c.marginB : void 0 })),
11527
+ cells.map((c) => ({ rowAddr: c.ra, rowSpan: c.rs, height: (c.rs > 1 ? Math.max(c.h, cellContentExtent(c, memo) + c.marginT + c.marginB) : c.h) - sp * (c.rs - 1), contentH: cellContentExtent(c, memo) + c.marginT + c.marginB })),
11521
11528
  nRows,
11522
11529
  num(findChildByLocalName(tbl, "sz"), "height") - (sp > 0 ? sp * (nRows + 1) : 0) || Number.POSITIVE_INFINITY,
11523
11530
  !inCell(tbl) && !cells.some((c) => c.ra + c.rs === nRows && splitSaved(c))
@@ -11644,6 +11651,7 @@ function splitTableRows(tbl, top, lim, bodyH, styles, notes) {
11644
11651
  const fl = () => notes && nN > 0 ? Math.min(floor, bodyH - notes.area((moved ? 0 : notes.n0) + nN, (moved ? 0 : notes.s0) + nS)) : floor;
11645
11652
  const sp = num(tbl, "cellSpacing");
11646
11653
  const cells = mode === "CELL" ? collectCells(tbl) : [];
11654
+ const tableCells = mode === "TABLE" ? collectCells(tbl) : [];
11647
11655
  const record = mode === "CELL" ? /* @__PURE__ */ new Map() : void 0;
11648
11656
  const carries = /* @__PURE__ */ new Map();
11649
11657
  for (let r = 0; r < rows.length; r++) {
@@ -11672,7 +11680,20 @@ function splitTableRows(tbl, top, lim, bodyH, styles, notes) {
11672
11680
  y += h;
11673
11681
  continue;
11674
11682
  }
11675
- if (y + h + outB > fl() && !(moved && y === outT + headH)) {
11683
+ let need = h;
11684
+ if (!tableCells.some((c) => c.ra < r && c.ra + c.rs > r)) {
11685
+ let end = r + 1;
11686
+ for (let grown = true; grown; ) {
11687
+ grown = false;
11688
+ for (const c of tableCells) if (c.ra >= r && c.ra < end && c.ra + c.rs > end) {
11689
+ end = c.ra + c.rs;
11690
+ grown = true;
11691
+ }
11692
+ }
11693
+ const groupH = rows.slice(r, end).reduce((a, b) => a + b, 0);
11694
+ if (end > r + 1 && groupH <= bodyH - outT - outB - headH) need = groupH;
11695
+ }
11696
+ if (y + need + outB > fl() && !(moved && y === outT + headH)) {
11676
11697
  if (!moved && r === 0) splitWhole = true;
11677
11698
  y = outT + headH;
11678
11699
  floor = bodyH;
@@ -13052,6 +13073,53 @@ function flowEndNotes(root, bodyH) {
13052
13073
  });
13053
13074
  }
13054
13075
 
13076
+ // src/render/font-env.ts
13077
+ function hasKoPubSubst(headXml) {
13078
+ return /<hh:font\b[^>]*\bface="KoPub[^"]*"[^>]*\btype="TTF"[^>]*>\s*<hh:substFont\b/.test(headXml);
13079
+ }
13080
+ function lineStarts(root) {
13081
+ const out = [];
13082
+ for (const p of Array.from(root.getElementsByTagName("hp:p"))) {
13083
+ const lsa = elements(p).find((e) => ln(e) === "linesegarray");
13084
+ const segs = lsa ? elements(lsa).filter((e) => ln(e) === "lineseg") : [];
13085
+ out.push(segs.length >= 2 ? segs.map((s) => s.getAttribute("textpos") ?? "0").join(",") : null);
13086
+ }
13087
+ return out;
13088
+ }
13089
+ function matchCount(xml, saved, styles) {
13090
+ const root = createXmlParser().parseFromString(xml, "text/xml").documentElement;
13091
+ const pagePr = root.getElementsByTagName("hp:pagePr")[0];
13092
+ if (!pagePr) return 0;
13093
+ const margin = pagePr.getElementsByTagName("hp:margin")[0];
13094
+ let PW = num(pagePr, "width", 59528), PH = num(pagePr, "height", 84188);
13095
+ if (pagePr.getAttribute("landscape") === "NARROWLY" && PW < PH) [PW, PH] = [PH, PW];
13096
+ const gutterTB = pagePr.getAttribute("gutterType") === "TOP_BOTTOM", gutter = num(margin ?? null, "gutter", 0);
13097
+ const BODY_W = PW - num(margin ?? null, "left", 8504) - num(margin ?? null, "right", 8504) - (gutterTB ? 0 : gutter);
13098
+ const BODY_H = PH - num(margin ?? null, "top", 5668) - num(margin ?? null, "header", 0) - num(margin ?? null, "bottom", 4252) - num(margin ?? null, "footer", 0) - (gutterTB ? gutter : 0);
13099
+ for (const p of Array.from(root.getElementsByTagName("hp:p"))) {
13100
+ const lsa = elements(p).find((e) => ln(e) === "linesegarray");
13101
+ if (lsa) p.removeChild(lsa);
13102
+ }
13103
+ reflowSection(root, styles, { BODY_W, BODY_H });
13104
+ const got = lineStarts(root);
13105
+ let n = 0;
13106
+ saved.forEach((s, i) => {
13107
+ if (s !== null && s === got[i]) n++;
13108
+ });
13109
+ return n;
13110
+ }
13111
+ function kopubSubstituted(secXmls, base, alt) {
13112
+ let a = 0, b = 0, seen = 0;
13113
+ for (const xml of secXmls) {
13114
+ const saved = lineStarts(createXmlParser().parseFromString(xml, "text/xml").documentElement);
13115
+ a += matchCount(xml, saved, base);
13116
+ b += matchCount(xml, saved, alt);
13117
+ seen += saved.filter((x) => x !== null).length;
13118
+ if (seen >= 60) break;
13119
+ }
13120
+ return b >= a + 5 && b > a * 1.1;
13121
+ }
13122
+
13055
13123
  // src/render/scene.ts
13056
13124
  function regionId(type, seq) {
13057
13125
  return `${type}-${String(seq).padStart(6, "0")}`;
@@ -13280,6 +13348,26 @@ function cellLineBoxes(c) {
13280
13348
  function cellLines(c) {
13281
13349
  return cellLineBoxes(c).map((b) => [b.top, b.bottom]);
13282
13350
  }
13351
+ function spanPartRows(cells, rowY) {
13352
+ const out = /* @__PURE__ */ new Set();
13353
+ for (const c of cells) {
13354
+ if (c.rs < 2) continue;
13355
+ const bs = cellLineBoxes(c);
13356
+ const parts = bs.length ? bs[bs.length - 1].part : 0;
13357
+ let s = c.ra;
13358
+ for (let k = 0; k < parts; k++) {
13359
+ const inK = bs.filter((b) => b.part === k);
13360
+ if (!inK.length) break;
13361
+ const ext = Math.max(...inK.map((b) => b.bottom)) - inK[0].origin + c.marginT + c.marginB;
13362
+ let r = s + 1;
13363
+ while (r < c.ra + c.rs && rowY[r] - rowY[s] < ext - 100) r++;
13364
+ if (r >= c.ra + c.rs) break;
13365
+ out.add(r);
13366
+ s = r;
13367
+ }
13368
+ }
13369
+ return out;
13370
+ }
13283
13371
  function planTableRows(tbl, cells, rowH, ty, MT, BODY_H, slack = 0, floatSpan, nested = false, contMT = MT) {
13284
13372
  if (nested) slack = 0;
13285
13373
  const nRows = rowH.length;
@@ -13312,9 +13400,15 @@ function planTableRows(tbl, cells, rowH, ty, MT, BODY_H, slack = 0, floatSpan, n
13312
13400
  const out = [];
13313
13401
  const flows = (findChildByLocalName(tbl, "pos")?.getAttribute("vertRelTo") ?? "PARA") === "PARA";
13314
13402
  let page = 0, y = ty, first = !flows || ty - MT < 2e3;
13403
+ const spanStarts = cellSplit ? spanPartRows(cells, rowY) : /* @__PURE__ */ new Set();
13315
13404
  for (let r = 0; r < nRows; r++) {
13316
13405
  let h = rowH[r];
13317
13406
  const pieces = [];
13407
+ if (!first && r >= hdrRows && spanStarts.has(r)) {
13408
+ page++;
13409
+ y = contTop;
13410
+ first = true;
13411
+ }
13318
13412
  const rowCells = cells.filter((c) => c.ra === r && c.rs === 1);
13319
13413
  const splittable = cellSplit && r >= hdrRows && rowCells.length > 0;
13320
13414
  const stack = splittable && rowCells.length === 1 ? stackedFloats(rowCells[0]) : [];
@@ -13453,11 +13547,11 @@ function planTableRows(tbl, cells, rowH, ty, MT, BODY_H, slack = 0, floatSpan, n
13453
13547
  continue;
13454
13548
  }
13455
13549
  }
13456
- if (splittable && y + h > pageBottom) {
13550
+ if (splittable && y + h + outB > pageBottom) {
13457
13551
  const from = /* @__PURE__ */ new Map();
13458
13552
  const lines = new Map(rowCells.map((c) => [c.el, cellLines(c)]));
13459
- while (y + h > pageBottom && BODY_H > rowY[hdrRows]) {
13460
- const avail = pageBottom - y;
13553
+ while (y + h + outB > pageBottom && BODY_H > rowY[hdrRows]) {
13554
+ const avail = pageBottom - y - outB;
13461
13555
  let rem = 0, placed = false, allFit = true, blocked = false;
13462
13556
  const cuts = [];
13463
13557
  for (const c of rowCells) {
@@ -13529,6 +13623,21 @@ function planTableRows(tbl, cells, rowH, ty, MT, BODY_H, slack = 0, floatSpan, n
13529
13623
  page++;
13530
13624
  y = contTop;
13531
13625
  first = true;
13626
+ } else if (!first && tbl.getAttribute("pageBreak") === "TABLE" && r >= hdrRows && !cells.some((c) => c.ra < r && c.ra + c.rs > r)) {
13627
+ let end = r + 1;
13628
+ for (let grown = true; grown; ) {
13629
+ grown = false;
13630
+ for (const c of cells) if (c.ra >= r && c.ra < end && c.ra + c.rs > end) {
13631
+ end = c.ra + c.rs;
13632
+ grown = true;
13633
+ }
13634
+ }
13635
+ const groupH = rowY[Math.min(end, nRows)] - rowY[r];
13636
+ if (end > r + 1 && y + groupH + outB > pageBottom && groupH <= pageBottom - contTop) {
13637
+ page++;
13638
+ y = contTop;
13639
+ first = true;
13640
+ }
13532
13641
  }
13533
13642
  out.push([{ page, y, h }]);
13534
13643
  y += h;
@@ -13571,12 +13680,27 @@ function renderingMatrix(el) {
13571
13680
  const info = findChildByLocalName(el, "renderingInfo");
13572
13681
  if (!info) return null;
13573
13682
  let m = null;
13683
+ let pendingS = null;
13684
+ const apply = (n) => {
13685
+ m = m ? mulAffine(m, n) : n;
13686
+ };
13574
13687
  for (const c of elements(info)) {
13575
13688
  const tag = ln(c);
13576
13689
  if (tag !== "transMatrix" && tag !== "scaMatrix" && tag !== "rotMatrix") continue;
13577
13690
  const n = [num(c, "e1", 1), num(c, "e4"), num(c, "e2"), num(c, "e5", 1), num(c, "e3"), num(c, "e6")];
13578
- m = m ? mulAffine(m, n) : n;
13691
+ if (tag === "scaMatrix") {
13692
+ if (pendingS) apply(pendingS);
13693
+ pendingS = n;
13694
+ continue;
13695
+ }
13696
+ if (tag === "rotMatrix" && pendingS) {
13697
+ apply(mulAffine(n, pendingS));
13698
+ pendingS = null;
13699
+ continue;
13700
+ }
13701
+ apply(n);
13579
13702
  }
13703
+ if (pendingS) apply(pendingS);
13580
13704
  return m;
13581
13705
  }
13582
13706
  function objectGeometry(el, x, y, w, h, boxW = w, boxH = h) {
@@ -13683,7 +13807,7 @@ function linePushedBy(o, lineV, paraTop) {
13683
13807
  const raw = num(pos, "vertOffset"), vo = (pos?.getAttribute("vertRelTo") ?? "PARA") === "PARA" ? Math.max(0, raw >= 2 ** 31 ? raw - 2 ** 32 : raw) : 0;
13684
13808
  return Math.abs(lineV - (vo + num(om, "top") + o.height + num(om, "bottom")) - paraTop) <= 10;
13685
13809
  }
13686
- function anchorObject(o, ox, oy, baseV, areaW, ctx, anchorLineV, stayLine = false, paraStartV, lineH, lineSB = 0) {
13810
+ function anchorObject(o, ox, oy, baseV, areaW, ctx, anchorLineV, stayLine = false, paraStartV, lineH, lineSB = 0, anchorAt = "end") {
13687
13811
  const { PW, PH, ML, MT, BODY_W, BODY_H } = ctx.geom;
13688
13812
  const pos = findChildByLocalName(o.el, "pos");
13689
13813
  const om = findChildByLocalName(o.el, "outMargin");
@@ -13711,8 +13835,9 @@ function anchorObject(o, ox, oy, baseV, areaW, ctx, anchorLineV, stayLine = fals
13711
13835
  y = oy + anchor + omT + vo;
13712
13836
  } else {
13713
13837
  const origin = vrel === "PARA" && wrap === "SQUARE" ? paraStartV ?? baseV : baseV;
13714
- const later = vrel === "PARA" && wrap === "SQUARE" && anchorLineV !== void 0 && anchorLineV > baseV;
13715
- y = later ? oy + anchorLineV + vo + omT : oy + Math.max(origin + vo, wrap === "SQUARE" && anchorLineV !== void 0 ? anchorLineV : -Infinity) + omT;
13838
+ const later = vrel === "PARA" && wrap === "SQUARE" && anchorAt === "end" && anchorLineV !== void 0 && anchorLineV > baseV;
13839
+ const midLater = vrel === "PARA" && wrap === "SQUARE" && anchorAt === "top" && anchorLineV !== void 0 && anchorLineV > baseV;
13840
+ y = later ? oy + anchorLineV + vo + omT : oy + Math.max(origin + vo, wrap === "SQUARE" && !midLater && anchorLineV !== void 0 ? anchorLineV : -Infinity) + omT;
13716
13841
  }
13717
13842
  let x;
13718
13843
  const omL = num(om, "left"), omR = num(om, "right");
@@ -14572,30 +14697,53 @@ function planLines(m, styles, numText = "") {
14572
14697
  }
14573
14698
  }
14574
14699
  const stretch = align === "JUSTIFY" || align === "DISTRIBUTE" || align === "DISTRIBUTE_SPACE";
14575
- let spaceAdd = 0, spaceFrom = fixedTo;
14700
+ let spaceAdd = 0, spaceFrom = fixedTo, charAdd = 0;
14701
+ const squeeze = (spFrom) => {
14702
+ const short = nat.text - lastSp - avail;
14703
+ let nSp = 0, cap = 0, nG = 0;
14704
+ for (let k = spFrom; k < textEnd; k++) {
14705
+ const c = m.chars[k];
14706
+ if (c.ch === " ") {
14707
+ nSp++;
14708
+ cap += charW(c, styles, m.chars[k - 1]) * 0.2;
14709
+ } else if (c.ch && !c.tab) nG++;
14710
+ }
14711
+ if (nSp > 0) {
14712
+ spaceAdd = -Math.min(short, cap) / nSp;
14713
+ spaceFrom = spFrom;
14714
+ }
14715
+ if (short > cap && nG > 0) charAdd = -(short - (nSp > 0 ? cap : 0)) / nG;
14716
+ };
14576
14717
  if (nat.text > 0 && stretch && (!isLast || align === "DISTRIBUTE" || align === "DISTRIBUTE_SPACE")) {
14577
14718
  let nSp = 0, spFrom = fixedTo;
14578
- while (spFrom < textEnd && (m.chars[spFrom].ch === " " || m.chars[spFrom].ch === "")) spFrom++;
14719
+ while (spFrom < textEnd && (m.chars[spFrom].ch === " " || m.chars[spFrom].ch === "") && !m.chars[spFrom].ctrl) spFrom++;
14579
14720
  for (let k = spFrom; k < textEnd; k++) if (m.chars[k].ch === " ") nSp++;
14580
14721
  if (nSp > 0 && align !== "DISTRIBUTE") {
14581
14722
  spaceAdd = (avail - nat.text + lastSp) / nSp;
14582
14723
  spaceFrom = spFrom;
14724
+ if (spaceAdd < 0) squeeze(spFrom);
14583
14725
  } else scale = avail > 0 ? avail / nat.text : 1;
14584
14726
  } else if (nat.text + nat.obj > 0 && (isLast || !stretch)) {
14585
14727
  const w = nat.text + nat.obj - lastSp;
14586
14728
  if (align === "CENTER") xoff = Math.max(0, (lineW - w) / 2);
14587
14729
  else if (align === "RIGHT") xoff = Math.max(0, lineW - w);
14588
14730
  }
14731
+ if (spaceAdd === 0 && charAdd === 0 && scale === 1 && nat.text - lastSp > avail) {
14732
+ let spFrom = fixedTo;
14733
+ while (spFrom < textEnd && (m.chars[spFrom].ch === " " || m.chars[spFrom].ch === "") && !m.chars[spFrom].ctrl) spFrom++;
14734
+ squeeze(spFrom);
14735
+ }
14589
14736
  if (!Number.isFinite(scale) || scale <= 0) scale = 1;
14590
14737
  scale = Math.min(4, Math.max(0.25, scale));
14591
- plans.push({ seg, xoff: xoff + lead, scale, spaceAdd, spFrom: spaceFrom, start, end, tabs, fixedTo, textEnd, ...i === 0 && bu ? { bullet: { ch: bu.ch, w: bulletW, prId: bu.charPrId ?? firstPr } } : {} });
14738
+ plans.push({ seg, xoff: xoff + lead, scale, spaceAdd, spFrom: spaceFrom, ...charAdd ? { charAdd } : {}, start, end, tabs, fixedTo, textEnd, ...i === 0 && bu ? { bullet: { ch: bu.ch, w: bulletW, prId: bu.charPrId ?? firstPr } } : {} });
14592
14739
  }
14593
14740
  return plans;
14594
14741
  }
14595
14742
  function advanceTo(m, styles, plan, upto) {
14596
14743
  let x = 0;
14597
14744
  for (let i = plan.start; i < upto && i < m.chars.length; i++) {
14598
- x += m.chars[i].tab ? plan.tabs.get(i) ?? 0 : charW(m.chars[i], styles, m.chars[i - 1]) * (i < plan.fixedTo ? 1 : plan.scale) + (i >= plan.spFrom && i < plan.textEnd && m.chars[i].ch === " " ? plan.spaceAdd : 0);
14745
+ const c = m.chars[i], inStretch = i >= plan.spFrom && i < plan.textEnd;
14746
+ x += c.tab ? plan.tabs.get(i) ?? 0 : charW(c, styles, m.chars[i - 1]) * (i < plan.fixedTo ? 1 : plan.scale) + (inStretch && c.ch === " " ? plan.spaceAdd : 0) + (inStretch && plan.charAdd && c.ch && c.ch !== " " ? plan.charAdd : 0);
14599
14747
  }
14600
14748
  for (const o of m.objs) if (o.inline && o.index >= plan.start && o.index < upto) x += o.omL + o.width + o.omR;
14601
14749
  return x;
@@ -14713,7 +14861,7 @@ function drawPara(p, ox, oy, areaW, ctx, depth, segPages) {
14713
14861
  return n;
14714
14862
  };
14715
14863
  const renderSeg = (text, cx, hit) => {
14716
- const sw = measure(text) * scale + (plan.spaceAdd && i >= plan.fixedTo ? plan.spaceAdd * spacesIn(text) : 0);
14864
+ const sw = measure(text) * scale + (plan.spaceAdd && i >= plan.fixedTo ? plan.spaceAdd * spacesIn(text) : 0) + (plan.charAdd && i >= plan.fixedTo ? plan.charAdd * [...text].filter((ch) => ch !== " ").length : 0);
14717
14865
  if (st.shade) emit(ctx, `<rect x="${pt2(cx)}" y="${pt2(glyphY(st.height) - Math.round(st.height * 0.85))}" width="${pt2(sw)}" height="${pt2(st.height)}" fill="${escapeXml(st.shade)}"/>`);
14718
14866
  if (hit) {
14719
14867
  emit(ctx, `<rect x="${pt2(cx)}" y="${pt2(oy + seg.vertpos)}" width="${pt2(sw)}" height="${pt2(seg.textheight)}" fill="#ffd54f" fill-opacity="0.45"/>`);
@@ -14779,7 +14927,8 @@ function drawPara(p, ox, oy, areaW, ctx, depth, segPages) {
14779
14927
  const plan = plans[planIdx];
14780
14928
  if (segPages && segPages[planIdx] !== void 0) ctx.page = segPages[planIdx];
14781
14929
  const x = ox + plan.seg.horzpos + plan.xoff + advanceTo(m, ctx.styles, plan, o.index) + o.omL;
14782
- const eqAsc = o.tag === "equation" && Number(o.el.getAttribute("baseLine")) > 0 ? Math.round(o.height * Number(o.el.getAttribute("baseLine")) / 100) : o.tag === "pic" ? Math.round(o.height * 0.85) : o.height;
14930
+ const shadowed = o.tag === "pic" && !!findChildByLocalName(findChildByLocalName(o.el, "effects") ?? o.el, "shadow") && plan.seg.textheight > o.height && Math.abs(plan.seg.baseline - Math.round(plan.seg.textheight * 0.85)) <= 2;
14931
+ const eqAsc = o.tag === "equation" && Number(o.el.getAttribute("baseLine")) > 0 ? Math.round(o.height * Number(o.el.getAttribute("baseLine")) / 100) : shadowed ? Math.round(plan.seg.textheight * 0.85) : o.tag === "pic" ? Math.round(o.height * 0.85) : o.height;
14783
14932
  const iom = findChildByLocalName(o.el, "outMargin"), iomT = num(iom, "top"), iomB = num(iom, "bottom");
14784
14933
  const yTop = oy + plan.seg.vertpos + Math.max(iomT, plan.seg.baseline - eqAsc - iomB - captionExtra(o.el));
14785
14934
  drawObject(o, x, yTop, baseV, areaW, ctx, depth);
@@ -14793,10 +14942,16 @@ function drawPara(p, ox, oy, areaW, ctx, depth, segPages) {
14793
14942
  }
14794
14943
  let anchorLineV;
14795
14944
  let anchorLineH = 0;
14796
- for (const pl of plans) if (pl.start <= o.index) {
14797
- anchorLineV = pl.seg.vertpos;
14798
- anchorLineH = pl.seg.textheight;
14799
- }
14945
+ let anchorSeg;
14946
+ let anchorK = -1;
14947
+ plans.forEach((pl, k) => {
14948
+ if (pl.start <= o.index) {
14949
+ anchorLineV = pl.seg.vertpos;
14950
+ anchorLineH = pl.seg.textheight;
14951
+ anchorSeg = pl.seg;
14952
+ anchorK = k;
14953
+ }
14954
+ });
14800
14955
  let objBaseV = baseV;
14801
14956
  const pTop = depth === 0 ? ctx.paraTops?.get(p) : void 0;
14802
14957
  const wrapA = o.el.getAttribute("textWrap") ?? "TOP_AND_BOTTOM";
@@ -14806,14 +14961,40 @@ function drawPara(p, ox, oy, areaW, ctx, depth, segPages) {
14806
14961
  if (baseV > start + 100) {
14807
14962
  objBaseV = start;
14808
14963
  if (anchorLineV === baseV) anchorLineV = start;
14964
+ } else if (depth > 0 && start > top0 && Math.abs(baseV - start) <= 100) {
14965
+ objBaseV = top0;
14966
+ if (anchorLineV === baseV) anchorLineV = top0;
14809
14967
  }
14810
14968
  }
14811
14969
  const tbFloats = m.objs.filter((q) => !q.inline && (q.el.getAttribute("textWrap") ?? "TOP_AND_BOTTOM") === "TOP_AND_BOTTOM" && (findChildByLocalName(q.el, "pos")?.getAttribute("vertRelTo") ?? "PARA") === "PARA").length;
14812
14970
  let stay = tbFloats < 2 && !m.objs.some((q) => q.inline) && !m.chars.some((c) => c.ch !== "" && !c.nb && c.ch.trim() !== "");
14813
14971
  const sbA = m.paraPrId != null ? ctx.styles.paraGeom.get(m.paraPrId)?.spaceBefore ?? 0 : 0;
14814
14972
  if (stay && wrapA === "TOP_AND_BOTTOM" && linePushedBy(o, anchorLineV ?? baseV, pTop ?? (depth > 0 ? cellParaTop(p, ctx.styles.paraGeom) : void 0))) stay = false;
14973
+ let carried;
14974
+ if (segPages && anchorK > 0 && segPages[anchorK] !== segPages[0] && segPages[anchorK - 1] === segPages[0] && wrapA === "TOP_AND_BOTTOM" && (findChildByLocalName(o.el, "pos")?.getAttribute("vertRelTo") ?? "PARA") === "PARA") {
14975
+ const s0 = plans[anchorK - 1].seg;
14976
+ carried = s0.vertpos + s0.textheight + (s0.spacing ?? 0);
14977
+ }
14815
14978
  const firstLine = anchorLineV === void 0 || anchorLineV === baseV;
14816
- let { x, y } = anchorObject(o, ax, oy, objBaseV, aw, ctx, anchorLineV, stay ? sbA : false, (firstLine || wrapA === "SQUARE") && pTop !== void 0 && pTop < baseV ? pTop : void 0, anchorLineH, firstLine ? sbA : 0);
14979
+ let { x, y } = anchorObject(
14980
+ o,
14981
+ ax,
14982
+ oy,
14983
+ objBaseV,
14984
+ aw,
14985
+ ctx,
14986
+ anchorLineV,
14987
+ stay ? sbA : false,
14988
+ (firstLine || wrapA === "SQUARE") && pTop !== void 0 && pTop < baseV ? pTop : void 0,
14989
+ anchorLineH,
14990
+ firstLine ? sbA : 0,
14991
+ // 문단 중간 글자 앵커인데 첫 줄부터 앵커 줄만큼 좁게 저장됐으면 개체는 문단 위에 있다(같은 판 한컴 PDF: 둘째 줄 앵커 사진, 네 줄 모두 34602)
14992
+ m.chars.slice(o.index).some((c) => c.ch.trim() !== "") && !!anchorSeg && plans.length > 0 && plans[0].seg !== anchorSeg && Math.abs(plans[0].seg.horzsize - anchorSeg.horzsize) <= 100 && anchorSeg.horzpos + anchorSeg.horzsize < aw - 1e3 ? "top" : m.chars.slice(o.index).some((c) => c.ch.trim() !== "") ? "mid" : "end"
14993
+ );
14994
+ if (carried !== void 0) {
14995
+ const posC = findChildByLocalName(o.el, "pos"), rawC = num(posC, "vertOffset");
14996
+ y = oy + carried + num(findChildByLocalName(o.el, "outMargin"), "top") + Math.max(0, rawC >= 2 ** 31 ? rawC - 2 ** 32 : rawC);
14997
+ }
14817
14998
  let stackTop = depth === 0 ? pTop ?? 0 : cellParaTop(p, ctx.styles.paraGeom);
14818
14999
  if (tbFloats >= 2 && wrapA === "TOP_AND_BOTTOM" && stackTop !== void 0) {
14819
15000
  if (!tbStack) {
@@ -15068,10 +15249,28 @@ function drawTable(tbl, tx, ty, ctx, depth) {
15068
15249
  pcs.forEach((pc, k) => geom.push({ c, page: startPage + pc.page, ...xw(c), y: pc.y, h: pc.h, pieces: k === 0 ? pcs : [] }));
15069
15250
  continue;
15070
15251
  }
15252
+ if (c.rs > 1) {
15253
+ const span = plan.slice(c.ra, Math.min(c.ra + c.rs, nRows)).flat();
15254
+ const pages = [...new Set(span.map((pc) => pc.page))];
15255
+ if (pages.length > 1) {
15256
+ const bs = cellLineBoxes(c);
15257
+ const partTop = (k) => bs.find((b) => b.part === k);
15258
+ const groups = pages.map((pg, k) => {
15259
+ const on = span.filter((pc) => pc.page === pg);
15260
+ const y0 = Math.min(...on.map((pc) => pc.y)), y1 = Math.max(...on.map((pc) => pc.y + pc.h));
15261
+ const from = k === 0 ? 0 : partTop(k)?.origin ?? Number.POSITIVE_INFINITY;
15262
+ const to = k === pages.length - 1 ? Number.POSITIVE_INFINITY : partTop(k + 1)?.top ?? Number.POSITIVE_INFINITY;
15263
+ return { page: pg, y: y0, h: y1 - y0, range: /* @__PURE__ */ new Map([[c.el, [from, to]]]) };
15264
+ });
15265
+ groups.forEach((pc, k) => geom.push({ c, page: startPage + pc.page, ...xw(c), y: pc.y, h: pc.h, pieces: k === 0 ? groups : [] }));
15266
+ continue;
15267
+ }
15268
+ }
15071
15269
  const h = c.rs === 1 ? pcs[0].h : rowY[Math.min(c.ra + c.rs, nRows)] - rowY[c.ra];
15072
15270
  geom.push({ c, page: startPage + pcs[0].page, ...xw(c), y: pcs[0].y, h });
15073
15271
  }
15074
- for (const page of contPages) for (const c of cells) if (c.ra < hdrRows) geom.push({ c, page, ...xw(c), y: ctx.geom.MT + num(findChildByLocalName(tbl, "outMargin"), "top") + rowY[c.ra], h: rowY[Math.min(c.ra + c.rs, nRows)] - rowY[c.ra] });
15272
+ const contBase = depth !== 1 && ctx.splitContMT !== void 0 ? ctx.splitContMT : ctx.geom.MT;
15273
+ for (const page of contPages) for (const c of cells) if (c.ra < hdrRows) geom.push({ c, page, ...xw(c), y: contBase + num(findChildByLocalName(tbl, "outMargin"), "top") + rowY[c.ra], h: rowY[Math.min(c.ra + c.rs, nRows)] - rowY[c.ra] });
15075
15274
  for (const g of geom) {
15076
15275
  ctx.page = g.page;
15077
15276
  const bf = g.c.bfId != null ? ctx.styles.borderFill.get(g.c.bfId) : void 0;
@@ -15116,7 +15315,7 @@ function drawTable(tbl, tx, ty, ctx, depth) {
15116
15315
  });
15117
15316
  ctx.splitCell = splitHere;
15118
15317
  const contMTSaved = ctx.splitContMT;
15119
- ctx.splitContMT = ctx.geom.MT + num(findChildByLocalName(tbl, "outMargin"), "top") + rowY[hdrRows] + c.marginT;
15318
+ ctx.splitContMT = (depth > 1 && contMTSaved !== void 0 ? contMTSaved : ctx.geom.MT) + num(findChildByLocalName(tbl, "outMargin"), "top") + rowY[hdrRows] + c.marginT;
15120
15319
  drawPara(p, g.x + c.marginL, base, g.w - c.marginL - c.marginR, ctx, depth + 1, pages);
15121
15320
  ctx.splitContMT = contMTSaved;
15122
15321
  ctx.splitCell = false;
@@ -15704,7 +15903,8 @@ async function renderHwpxInternal(input, options) {
15704
15903
  const verFile = zip.file("version.xml");
15705
15904
  const verXml = verFile ? await readZipEntry(verFile, "text") : void 0;
15706
15905
  const appMajor = hwpxAppMajor(verXml), appBuild = hwpxAppBuild(verXml);
15707
- const styles = headFile ? parseRenderStyles(await readZipEntry(headFile, "text"), { appMajor, appBuild }) : { charPr: /* @__PURE__ */ new Map(), paraAlign: /* @__PURE__ */ new Map(), paraGeom: /* @__PURE__ */ new Map(), borderFill: /* @__PURE__ */ new Map() };
15906
+ const headXml = headFile ? await readZipEntry(headFile, "text") : void 0;
15907
+ let styles = headXml ? parseRenderStyles(headXml, { appMajor, appBuild }) : { charPr: /* @__PURE__ */ new Map(), paraAlign: /* @__PURE__ */ new Map(), paraGeom: /* @__PURE__ */ new Map(), borderFill: /* @__PURE__ */ new Map() };
15708
15908
  if (!headFile) warnings.push("header.xml \uC5C6\uC74C \u2014 \uAE30\uBCF8 \uC2A4\uD0C0\uC77C\uB85C \uB80C\uB354");
15709
15909
  const secXmls = [];
15710
15910
  for (const f of secFiles) {
@@ -15712,6 +15912,10 @@ async function renderHwpxInternal(input, options) {
15712
15912
  if (xml.length > MAX_DECOMPRESS_SIZE) throw new KordocError("\uC139\uC158 XML\uC774 \uD5C8\uC6A9 \uD06C\uAE30\uB97C \uCD08\uACFC");
15713
15913
  secXmls.push(xml);
15714
15914
  }
15915
+ if (headXml && hasKoPubSubst(headXml)) {
15916
+ const alt = parseRenderStyles(headXml, { appMajor, appBuild, substKoPub: true });
15917
+ if (kopubSubstituted(secXmls, styles, alt)) styles = alt;
15918
+ }
15715
15919
  const masterPages = /* @__PURE__ */ new Map();
15716
15920
  const masterXmls = [];
15717
15921
  for (const file of zip.file(/Contents\/masterpage[^/]*\.xml$/i)) {
@@ -15763,6 +15967,7 @@ async function renderHwpxInternal(input, options) {
15763
15967
  }
15764
15968
  const roots = [];
15765
15969
  let noCacheSkipped = false;
15970
+ const lastParity = /* @__PURE__ */ new Map();
15766
15971
  for (let si = 0; si < secXmls.length; si++) {
15767
15972
  const secXml = secXmls[si];
15768
15973
  const hasCache = /<(?:[A-Za-z][\w.-]*:)?linesegarray[\s/>]/.test(secXml);
@@ -15779,6 +15984,14 @@ async function renderHwpxInternal(input, options) {
15779
15984
  }
15780
15985
  const secPr = findFirst(root, "secPr");
15781
15986
  const referenced = secPr ? elements(secPr).filter((el) => ln(el) === "masterPage").map((el) => masterPages.get(el.getAttribute("idRef") || "")).filter((el) => !!el) : [];
15987
+ const typeOf = (m) => m.getAttribute("type") || "BOTH";
15988
+ const has = (t) => referenced.some((m) => typeOf(m) === t);
15989
+ if (!has("BOTH")) for (const [t, other] of [["EVEN", "ODD"], ["ODD", "EVEN"]]) {
15990
+ const prev = lastParity.get(t);
15991
+ if (prev && !has(t) && has(other)) referenced.unshift(prev);
15992
+ }
15993
+ for (const m of referenced) if (typeOf(m) === "EVEN" || typeOf(m) === "ODD") lastParity.set(typeOf(m), m);
15994
+ if (has("BOTH")) lastParity.clear();
15782
15995
  roots.push({ root, index: si, masterPages: referenced, hasDeletionMarkers: secXml.includes("deleteBegin") || secXml.includes("deleteEnd") });
15783
15996
  }
15784
15997
  if (roots.length === 0) {
@@ -19962,4 +20175,4 @@ export {
19962
20175
  cropRect,
19963
20176
  extractRenderedRegions
19964
20177
  };
19965
- //# sourceMappingURL=chunk-DHMBPMKC.js.map
20178
+ //# sourceMappingURL=chunk-YEYNBH5W.js.map