kordoc 4.17.2 → 4.17.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 (142) hide show
  1. package/dist/{-2UA2JHVA.js → -SQRLFE4N.js} +11 -11
  2. package/dist/{chunk-4HRJISJF.js → chunk-4D52VUGA.js} +3 -3
  3. package/dist/{chunk-6OCKAXIS.js → chunk-6DXSRQ65.js} +2 -2
  4. package/dist/{chunk-XZA6X34R.js → chunk-7TE6TK52.js} +2 -2
  5. package/dist/{chunk-KQIYC2ZU.js → chunk-AAQR4RIX.js} +2 -2
  6. package/dist/{chunk-GPC72VSF.cjs → chunk-AFXX3YSP.cjs} +262 -171
  7. package/dist/chunk-AFXX3YSP.cjs.map +1 -0
  8. package/dist/{chunk-6DOCSYEM.cjs → chunk-AOONZC4S.cjs} +3 -3
  9. package/dist/chunk-AOONZC4S.cjs.map +1 -0
  10. package/dist/{chunk-A2W2JQ3S.js → chunk-DD6AY6EI.js} +2 -2
  11. package/dist/{chunk-KZVQK5NS.cjs → chunk-EXBZHI25.cjs} +2 -2
  12. package/dist/chunk-EXBZHI25.cjs.map +1 -0
  13. package/dist/{chunk-FGL4IGOT.js → chunk-FSCVZR4A.js} +4 -4
  14. package/dist/{chunk-HAW2VL62.cjs → chunk-GNORDND5.cjs} +12 -12
  15. package/dist/chunk-GNORDND5.cjs.map +1 -0
  16. package/dist/chunk-GS7T56RP.cjs.map +1 -1
  17. package/dist/{chunk-GYTL6WT3.js → chunk-HQ6TM2JE.js} +3 -3
  18. package/dist/{chunk-WJLICIYV.js → chunk-HY33WBAH.js} +24 -21
  19. package/dist/{chunk-WJLICIYV.js.map → chunk-HY33WBAH.js.map} +1 -1
  20. package/dist/{chunk-O4CB7D2Q.js → chunk-IERSVUW6.js} +2 -2
  21. package/dist/chunk-J55UQC5H.cjs.map +1 -1
  22. package/dist/chunk-KIYHQQVO.cjs +170 -0
  23. package/dist/chunk-KIYHQQVO.cjs.map +1 -0
  24. package/dist/{chunk-SDRKHEVT.js → chunk-NNNRN6BY.js} +255 -164
  25. package/dist/chunk-NNNRN6BY.js.map +1 -0
  26. package/dist/{chunk-MDCTITUG.js → chunk-O5T5OIJM.js} +2 -2
  27. package/dist/{chunk-WL3BWROT.js → chunk-ODVIUG6Q.js} +22 -12
  28. package/dist/chunk-ODVIUG6Q.js.map +1 -0
  29. package/dist/{chunk-C4MVZXB5.js → chunk-P2ZPPRM7.js} +2 -2
  30. package/dist/chunk-PNXJYEOR.js +170 -0
  31. package/dist/chunk-PNXJYEOR.js.map +1 -0
  32. package/dist/{chunk-YGKC6E6A.js → chunk-PTMYCK7R.js} +2 -2
  33. package/dist/{chunk-4TSYMJDL.js → chunk-PVJFCDND.js} +38 -13
  34. package/dist/chunk-PVJFCDND.js.map +1 -0
  35. package/dist/{chunk-ZDX5PIWR.js → chunk-RCS7WXOM.js} +2 -2
  36. package/dist/{chunk-VU26WGE5.js → chunk-SSY6FQLS.js} +200 -97
  37. package/dist/chunk-SSY6FQLS.js.map +1 -0
  38. package/dist/{chunk-JY2NBFIG.js → chunk-TMHMJUYU.js} +302 -75
  39. package/dist/chunk-TMHMJUYU.js.map +1 -0
  40. package/dist/{chunk-5JZEY5IL.js → chunk-VJP7O6BL.js} +2 -2
  41. package/dist/{chunk-2XHXABCX.js → chunk-W3OY3SLY.js} +3 -3
  42. package/dist/chunk-W3OY3SLY.js.map +1 -0
  43. package/dist/{chunk-WWMKIHF7.cjs → chunk-WNF3TSV3.cjs} +129 -104
  44. package/dist/chunk-WNF3TSV3.cjs.map +1 -0
  45. package/dist/{chunk-3N272C5L.js → chunk-YBIWPCUX.js} +39 -14
  46. package/dist/chunk-YBIWPCUX.js.map +1 -0
  47. package/dist/chunks-VNSLMJQD.js +10 -0
  48. package/dist/cli.js +26 -26
  49. package/dist/{formula-5RETDCIC.cjs → formula-U37MTMBD.cjs} +9 -9
  50. package/dist/formula-U37MTMBD.cjs.map +1 -0
  51. package/dist/{formula-MBLN2DG4.js → formula-U3MJXXIL.js} +4 -4
  52. package/dist/{formula-QZZDW5GW.js → formula-WZH5CMA3.js} +3 -3
  53. package/dist/{image-ocr-EREKAS47.js → image-ocr-HYWDBN72.js} +6 -6
  54. package/dist/{image-ocr-PSPVRLB5.cjs → image-ocr-OXU55EW3.cjs} +15 -15
  55. package/dist/image-ocr-OXU55EW3.cjs.map +1 -0
  56. package/dist/{image-ocr-CJSO3QSR.js → image-ocr-V6MICC6R.js} +9 -8
  57. package/dist/{image-ocr-CJSO3QSR.js.map → image-ocr-V6MICC6R.js.map} +1 -1
  58. package/dist/index.cjs +1194 -864
  59. package/dist/index.cjs.map +1 -1
  60. package/dist/index.js +531 -201
  61. package/dist/index.js.map +1 -1
  62. package/dist/mcp.js +22 -22
  63. package/dist/{model-bundle-MA4MMCRJ.js → model-bundle-AHBUQ6SD.js} +5 -5
  64. package/dist/{models-SEJ7LNSN.js → models-UF7B5LLG.js} +5 -5
  65. package/dist/page-range-QHHFTL7X.cjs.map +1 -1
  66. package/dist/{parser-M5WHRX25.js → parser-F6N6ID25.js} +22 -13
  67. package/dist/parser-F6N6ID25.js.map +1 -0
  68. package/dist/{parser-QILYPWSI.cjs → parser-IXRGUYZW.cjs} +207 -198
  69. package/dist/parser-IXRGUYZW.cjs.map +1 -0
  70. package/dist/{parser-VH3F4EQU.js → parser-T4FBG2FR.js} +23 -14
  71. package/dist/parser-T4FBG2FR.js.map +1 -0
  72. package/dist/pdf-ocr-2CITOAIG.cjs +16 -0
  73. package/dist/pdf-ocr-2CITOAIG.cjs.map +1 -0
  74. package/dist/pdf-ocr-RG2MFWBX.js +15 -0
  75. package/dist/pdf-ocr-U7Z4IUMA.js +19 -0
  76. package/dist/{profile-io-5YB627EO.js → profile-io-GM3NVLV3.js} +3 -3
  77. package/dist/{rasterize-V2XHHS2I.js → rasterize-4A3LJXTG.js} +3 -3
  78. package/dist/{redact-doc-5MK5L5IQ.js → redact-doc-SQ7C3LIG.js} +11 -11
  79. package/dist/{render-SYZMHYK6.js → render-6LTQZG4W.js} +7 -7
  80. package/dist/seal-ROSVLTRQ.js +10 -0
  81. package/dist/{setup-ZPLJENSK.js → setup-DGBJOROA.js} +3 -3
  82. package/dist/visual-6W34SFIW.js +20 -0
  83. package/dist/{watch-FNWHVKK3.js → watch-DJVJRSLE.js} +12 -12
  84. package/package.json +1 -1
  85. package/dist/chunk-2XHXABCX.js.map +0 -1
  86. package/dist/chunk-3N272C5L.js.map +0 -1
  87. package/dist/chunk-4TSYMJDL.js.map +0 -1
  88. package/dist/chunk-6DOCSYEM.cjs.map +0 -1
  89. package/dist/chunk-GPC72VSF.cjs.map +0 -1
  90. package/dist/chunk-HAW2VL62.cjs.map +0 -1
  91. package/dist/chunk-JY2NBFIG.js.map +0 -1
  92. package/dist/chunk-KZVQK5NS.cjs.map +0 -1
  93. package/dist/chunk-SDRKHEVT.js.map +0 -1
  94. package/dist/chunk-UX3HHAWH.js +0 -248
  95. package/dist/chunk-UX3HHAWH.js.map +0 -1
  96. package/dist/chunk-VU26WGE5.js.map +0 -1
  97. package/dist/chunk-WL3BWROT.js.map +0 -1
  98. package/dist/chunk-WWMKIHF7.cjs.map +0 -1
  99. package/dist/chunk-YIANW5QX.cjs +0 -248
  100. package/dist/chunk-YIANW5QX.cjs.map +0 -1
  101. package/dist/chunks-EBWJR55V.js +0 -10
  102. package/dist/formula-5RETDCIC.cjs.map +0 -1
  103. package/dist/image-ocr-PSPVRLB5.cjs.map +0 -1
  104. package/dist/parser-M5WHRX25.js.map +0 -1
  105. package/dist/parser-QILYPWSI.cjs.map +0 -1
  106. package/dist/parser-VH3F4EQU.js.map +0 -1
  107. package/dist/pdf-ocr-3SZUM3CN.cjs +0 -16
  108. package/dist/pdf-ocr-3SZUM3CN.cjs.map +0 -1
  109. package/dist/pdf-ocr-QB2TB5W5.js +0 -18
  110. package/dist/pdf-ocr-XC33L43D.js +0 -15
  111. package/dist/seal-IPKIQHYB.js +0 -10
  112. package/dist/visual-RTTGNOAE.js +0 -20
  113. /package/dist/{-2UA2JHVA.js.map → -SQRLFE4N.js.map} +0 -0
  114. /package/dist/{chunk-4HRJISJF.js.map → chunk-4D52VUGA.js.map} +0 -0
  115. /package/dist/{chunk-6OCKAXIS.js.map → chunk-6DXSRQ65.js.map} +0 -0
  116. /package/dist/{chunk-XZA6X34R.js.map → chunk-7TE6TK52.js.map} +0 -0
  117. /package/dist/{chunk-KQIYC2ZU.js.map → chunk-AAQR4RIX.js.map} +0 -0
  118. /package/dist/{chunk-A2W2JQ3S.js.map → chunk-DD6AY6EI.js.map} +0 -0
  119. /package/dist/{chunk-FGL4IGOT.js.map → chunk-FSCVZR4A.js.map} +0 -0
  120. /package/dist/{chunk-GYTL6WT3.js.map → chunk-HQ6TM2JE.js.map} +0 -0
  121. /package/dist/{chunk-O4CB7D2Q.js.map → chunk-IERSVUW6.js.map} +0 -0
  122. /package/dist/{chunk-MDCTITUG.js.map → chunk-O5T5OIJM.js.map} +0 -0
  123. /package/dist/{chunk-C4MVZXB5.js.map → chunk-P2ZPPRM7.js.map} +0 -0
  124. /package/dist/{chunk-YGKC6E6A.js.map → chunk-PTMYCK7R.js.map} +0 -0
  125. /package/dist/{chunk-ZDX5PIWR.js.map → chunk-RCS7WXOM.js.map} +0 -0
  126. /package/dist/{chunk-5JZEY5IL.js.map → chunk-VJP7O6BL.js.map} +0 -0
  127. /package/dist/{chunks-EBWJR55V.js.map → chunks-VNSLMJQD.js.map} +0 -0
  128. /package/dist/{formula-MBLN2DG4.js.map → formula-U3MJXXIL.js.map} +0 -0
  129. /package/dist/{formula-QZZDW5GW.js.map → formula-WZH5CMA3.js.map} +0 -0
  130. /package/dist/{image-ocr-EREKAS47.js.map → image-ocr-HYWDBN72.js.map} +0 -0
  131. /package/dist/{model-bundle-MA4MMCRJ.js.map → model-bundle-AHBUQ6SD.js.map} +0 -0
  132. /package/dist/{models-SEJ7LNSN.js.map → models-UF7B5LLG.js.map} +0 -0
  133. /package/dist/{pdf-ocr-QB2TB5W5.js.map → pdf-ocr-RG2MFWBX.js.map} +0 -0
  134. /package/dist/{pdf-ocr-XC33L43D.js.map → pdf-ocr-U7Z4IUMA.js.map} +0 -0
  135. /package/dist/{profile-io-5YB627EO.js.map → profile-io-GM3NVLV3.js.map} +0 -0
  136. /package/dist/{rasterize-V2XHHS2I.js.map → rasterize-4A3LJXTG.js.map} +0 -0
  137. /package/dist/{redact-doc-5MK5L5IQ.js.map → redact-doc-SQ7C3LIG.js.map} +0 -0
  138. /package/dist/{render-SYZMHYK6.js.map → render-6LTQZG4W.js.map} +0 -0
  139. /package/dist/{seal-IPKIQHYB.js.map → seal-ROSVLTRQ.js.map} +0 -0
  140. /package/dist/{setup-ZPLJENSK.js.map → setup-DGBJOROA.js.map} +0 -0
  141. /package/dist/{visual-RTTGNOAE.js.map → visual-6W34SFIW.js.map} +0 -0
  142. /package/dist/{watch-FNWHVKK3.js.map → watch-DJVJRSLE.js.map} +0 -0
@@ -9,7 +9,7 @@ import {
9
9
  HEADING_RATIO_H3,
10
10
  tidyScriptTags,
11
11
  unframeLayoutTables
12
- } from "./chunk-WL3BWROT.js";
12
+ } from "./chunk-ODVIUG6Q.js";
13
13
  import {
14
14
  parsePageRange
15
15
  } from "./chunk-VQFA55IC.js";
@@ -22,7 +22,7 @@ import {
22
22
  findChildByLocalName,
23
23
  hwpFaceToCssStack,
24
24
  parseRenderStyles
25
- } from "./chunk-2XHXABCX.js";
25
+ } from "./chunk-W3OY3SLY.js";
26
26
  import {
27
27
  MAX_COLS,
28
28
  MAX_ROWS,
@@ -33,18 +33,18 @@ import {
33
33
  flattenLayoutTables,
34
34
  mapPuaText,
35
35
  markNonLayoutTable
36
- } from "./chunk-WJLICIYV.js";
36
+ } from "./chunk-HY33WBAH.js";
37
37
  import {
38
38
  loadSharp,
39
39
  rasterizePageSvg
40
- } from "./chunk-MDCTITUG.js";
40
+ } from "./chunk-O5T5OIJM.js";
41
41
  import {
42
42
  KordocError,
43
43
  escapeHtml,
44
44
  precheckZipSize,
45
45
  sanitizeHref,
46
46
  toArrayBuffer
47
- } from "./chunk-A2W2JQ3S.js";
47
+ } from "./chunk-DD6AY6EI.js";
48
48
 
49
49
  // src/render/svg-render.ts
50
50
  import JSZip from "jszip";
@@ -1706,7 +1706,7 @@ function findFirst(el, name, depth = 0) {
1706
1706
  }
1707
1707
  return null;
1708
1708
  }
1709
- var OBJ_TAGS = /* @__PURE__ */ new Set(["tbl", "pic", "container", "equation", "rect", "ellipse", "polygon", "curv", "line", "arc", "ole", "textart"]);
1709
+ var OBJ_TAGS = /* @__PURE__ */ new Set(["tbl", "pic", "container", "equation", "rect", "ellipse", "polygon", "curv", "curve", "line", "arc", "ole", "textart"]);
1710
1710
  var CHAR_CTRL_1SLOT = /* @__PURE__ */ new Set(["lineBreak", "hyphen", "nbSpace", "fwSpace"]);
1711
1711
  function pushFillers(chars, n, prId) {
1712
1712
  for (let i = 0; i < n; i++) chars.push({ ch: "", prId });
@@ -1736,10 +1736,51 @@ function pushTextSlots(t, chars, prId, depth) {
1736
1736
  }
1737
1737
  }
1738
1738
  }
1739
+ var deletedStarts = /* @__PURE__ */ new WeakMap();
1740
+ var deletedControls = /* @__PURE__ */ new WeakMap();
1741
+ function isDeletedControl(el) {
1742
+ return deletedControls.get(el) === true;
1743
+ }
1744
+ function deletionDelta(ctrl, depth, xmlDepth = 0) {
1745
+ if (xmlDepth > 64) return depth;
1746
+ if (ln(ctrl) === "deleteBegin") return depth + 1;
1747
+ if (ln(ctrl) === "deleteEnd") return Math.max(0, depth - 1);
1748
+ if (ln(ctrl) === "ctrl") for (const ch of elements(ctrl)) depth = deletionDelta(ch, depth, xmlDepth + 1);
1749
+ return depth;
1750
+ }
1751
+ function prepareDeletedRanges(root, depth = 0) {
1752
+ if (depth > 64) return;
1753
+ let deleted = 0;
1754
+ for (const p of elements(root)) {
1755
+ if (ln(p) !== "p") continue;
1756
+ deletedStarts.set(p, deleted);
1757
+ const scan = (el, xmlDepth) => {
1758
+ if (xmlDepth > 64) return;
1759
+ if (ln(el) === "ctrl") for (const ch of elements(el)) scan(ch, xmlDepth + 1);
1760
+ else {
1761
+ if (ln(el) === "deleteBegin" || ln(el) === "deleteEnd") deleted = deletionDelta(el, deleted);
1762
+ deletedControls.set(el, deleted > 0);
1763
+ }
1764
+ };
1765
+ for (const ch of elements(p)) {
1766
+ if (ln(ch) === "run") for (const el of elements(ch)) scan(el, depth + 2);
1767
+ else if (ln(ch) === "deleteBegin" || ln(ch) === "deleteEnd") scan(ch, depth + 1);
1768
+ }
1769
+ }
1770
+ function nested(el, depth2) {
1771
+ if (depth2 > 64) return;
1772
+ for (const ch of elements(el)) {
1773
+ if (ln(ch) === "subList") prepareDeletedRanges(ch, depth2 + 1);
1774
+ else nested(ch, depth2 + 1);
1775
+ }
1776
+ }
1777
+ nested(root, depth);
1778
+ }
1739
1779
  function buildPara(p) {
1740
1780
  const chars = [];
1741
1781
  const objs = [];
1742
1782
  let segs = [];
1783
+ let deleted = deletedStarts.get(p) ?? 0;
1743
1784
  for (const runEl of elements(p)) {
1744
1785
  const tag = ln(runEl);
1745
1786
  if (tag === "run") {
@@ -1747,7 +1788,9 @@ function buildPara(p) {
1747
1788
  for (const ch of elements(runEl)) {
1748
1789
  const cn = ln(ch);
1749
1790
  if (cn === "t") {
1791
+ const start = chars.length;
1750
1792
  pushTextSlots(ch, chars, prId, 0);
1793
+ if (deleted) for (let i = start; i < chars.length; i++) chars[i] = { ch: "", prId };
1751
1794
  } else if (OBJ_TAGS.has(cn)) {
1752
1795
  const sz = findChildByLocalName(ch, "sz");
1753
1796
  const pos = findChildByLocalName(ch, "pos");
@@ -1755,7 +1798,7 @@ function buildPara(p) {
1755
1798
  const h = num(sz, "height") || num(findChildByLocalName(ch, "curSz"), "height") || num(findChildByLocalName(ch, "orgSz"), "height");
1756
1799
  const inline = pos?.getAttribute("treatAsChar") === "1";
1757
1800
  const om = inline && cn === "tbl" ? findChildByLocalName(ch, "outMargin") : null;
1758
- objs.push({
1801
+ if (!deleted) objs.push({
1759
1802
  el: ch,
1760
1803
  tag: cn,
1761
1804
  index: chars.length,
@@ -1767,9 +1810,12 @@ function buildPara(p) {
1767
1810
  });
1768
1811
  pushFillers(chars, 8, prId);
1769
1812
  } else {
1813
+ if (cn === "ctrl" || cn === "deleteBegin" || cn === "deleteEnd") deleted = deletionDelta(ch, deleted);
1770
1814
  pushFillers(chars, 8, prId);
1771
1815
  }
1772
1816
  }
1817
+ } else if (tag === "deleteBegin" || tag === "deleteEnd") {
1818
+ deleted = deletionDelta(runEl, deleted);
1773
1819
  } else if (tag === "linesegarray") {
1774
1820
  segs = elements(runEl).filter((s) => ln(s) === "lineseg").map((s) => ({
1775
1821
  textpos: num(s, "textpos"),
@@ -2106,18 +2152,179 @@ var RegionCollector = class {
2106
2152
  }
2107
2153
  };
2108
2154
 
2155
+ // src/render/page-stories.ts
2156
+ function pageStories(root, masters, paraPages, pageCount, pageBase, geom) {
2157
+ const secPr = findFirst(root, "secPr"), visibility = secPr && findChildByLocalName(secPr, "visibility");
2158
+ const pagePr = secPr && findChildByLocalName(secPr, "pagePr"), margin = pagePr && findChildByLocalName(pagePr, "margin");
2159
+ const declarations = [];
2160
+ const hidden = /* @__PURE__ */ new Map();
2161
+ for (const p of elements(root)) if (ln(p) === "p") {
2162
+ const page = paraPages.get(p)?.[0] ?? 0;
2163
+ for (const run of elements(p)) if (ln(run) === "run") {
2164
+ for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
2165
+ for (const el of elements(ctrl)) {
2166
+ if (isDeletedControl(el)) continue;
2167
+ const kind = ln(el);
2168
+ if (kind === "header" || kind === "footer") declarations.push({ el, page, kind });
2169
+ else if (kind === "pageHiding") {
2170
+ const kinds = hidden.get(page) ?? /* @__PURE__ */ new Set();
2171
+ for (const name of ["Header", "Footer", "MasterPage"]) if (num(el, `hide${name}`)) kinds.add(name);
2172
+ hidden.set(page, kinds);
2173
+ }
2174
+ }
2175
+ }
2176
+ }
2177
+ }
2178
+ const parity = (type, n) => type === "BOTH" || type === "ODD" && n % 2 === 1 || type === "EVEN" && n % 2 === 0;
2179
+ const out = [];
2180
+ for (let page = 0; page < pageCount; page++) {
2181
+ const n = pageBase + page + 1;
2182
+ const hides = (name) => hidden.get(page)?.has(name) === true || page === 0 && num(visibility, `hideFirst${name}`) !== 0;
2183
+ if (!hides("MasterPage")) {
2184
+ const matching = masters.filter((m) => m.getAttribute("type") === (n % 2 ? "ODD" : "EVEN"));
2185
+ const both = masters.filter((m) => (m.getAttribute("type") || "BOTH") === "BOTH");
2186
+ const normal = (matching.length ? matching : both).slice(-1);
2187
+ const specific = masters.filter((m) => m.getAttribute("type") === "LAST_PAGE" ? page === pageCount - 1 : m.getAttribute("type") === "OPTIONAL_PAGE" && num(m, "pageNumber") === page + 1);
2188
+ const special = specific.slice(-1);
2189
+ const selected = special.length && !num(special[0], "pageDuplicate") ? special : [...normal, ...special];
2190
+ for (const master of selected) {
2191
+ const sub = findChildByLocalName(master, "subList");
2192
+ if (sub) out.push({ sub, page, x: geom.ML, y: geom.MT, width: geom.BODY_W, layer: num(master, "pageFront") ? 2 : -2 });
2193
+ }
2194
+ }
2195
+ for (const kind of ["header", "footer"]) {
2196
+ if (hides(kind === "header" ? "Header" : "Footer")) continue;
2197
+ const eligible = declarations.filter((d) => d.kind === kind && d.page <= page && parity(d.el.getAttribute("applyPageType") || "BOTH", n));
2198
+ const decl = eligible[eligible.length - 1];
2199
+ const sub = decl && findChildByLocalName(decl.el, "subList");
2200
+ if (sub) out.push({ sub, page, x: geom.ML, y: kind === "header" ? num(margin, "top", 5668) : geom.PH - num(margin, "bottom", 4252) - num(margin, "footer"), width: geom.BODY_W });
2201
+ }
2202
+ }
2203
+ return out;
2204
+ }
2205
+
2206
+ // src/render/shape-geometry.ts
2207
+ var pt = (u) => String(Math.round(u) / 100);
2208
+ var esc = (s) => s.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2209
+ var SHAPE_TAGS = /* @__PURE__ */ new Set(["rect", "ellipse", "line", "polygon", "curv", "curve", "arc"]);
2210
+ function rotatedBounds(box, rotations) {
2211
+ if (!rotations.length) return box;
2212
+ let points = [[box.x, box.y], [box.x + box.w, box.y], [box.x + box.w, box.y + box.h], [box.x, box.y + box.h]];
2213
+ for (let i = rotations.length - 1; i >= 0; i--) {
2214
+ const { angle, cx, cy } = rotations[i];
2215
+ const a = angle * Math.PI / 180, c = Math.cos(a), s = Math.sin(a);
2216
+ points = points.map(([x2, y2]) => [cx + c * (x2 - cx) - s * (y2 - cy), cy + s * (x2 - cx) + c * (y2 - cy)]);
2217
+ }
2218
+ const x = Math.min(...points.map((p) => p[0])), y = Math.min(...points.map((p) => p[1]));
2219
+ return { x, y, w: Math.max(...points.map((p) => p[0])) - x, h: Math.max(...points.map((p) => p[1])) - y };
2220
+ }
2221
+ function objectGeometry(el, x, y, w, h) {
2222
+ const rot = findChildByLocalName(el, "rotationInfo");
2223
+ const angle = num(rot, "angle") % 360;
2224
+ if (!angle) return { x, y, w, h, bbox: { x, y, w, h }, transform: "" };
2225
+ const org = findChildByLocalName(el, "orgSz");
2226
+ const cx = x + num(rot, "centerX", num(org, "width", w) / 2) * (w / (num(org, "width") || w || 1));
2227
+ const cy = y + num(rot, "centerY", num(org, "height", h) / 2) * (h / (num(org, "height") || h || 1));
2228
+ const rotation = { angle, cx: Math.round(cx), cy: Math.round(cy) };
2229
+ return { x, y, w, h, bbox: rotatedBounds({ x, y, w, h }, [rotation]), rotation, transform: `rotate(${angle} ${pt(cx)} ${pt(cy)})` };
2230
+ }
2231
+ function shapeFill(el, defs, images, warn) {
2232
+ const brush = findChildByLocalName(el, "fillBrush");
2233
+ const win = brush && findChildByLocalName(brush, "winBrush");
2234
+ const face = win?.getAttribute("faceColor");
2235
+ if (face && face.toLowerCase() !== "none") return esc(face);
2236
+ const grad = brush && findChildByLocalName(brush, "gradation");
2237
+ if (grad) {
2238
+ const colors = elements(grad).filter((c) => ln(c) === "color").map((c) => c.getAttribute("value") || "#000000");
2239
+ if (!colors.length) return "none";
2240
+ const type = grad.getAttribute("type") ?? "LINEAR";
2241
+ if (type !== "LINEAR" && type !== "RADIAL") {
2242
+ warn(`gradient:${type}`, `\uADF8\uB77C\uB370\uC774\uC158(${type}) \uBBF8\uC9C0\uC6D0 \u2014 \uCCAB \uC0C9\uC73C\uB85C \uCC44\uC6C0`);
2243
+ return esc(colors[0]);
2244
+ }
2245
+ const id = `paint${defs.length}`;
2246
+ const opacity = Math.max(0, Math.min(1, 1 - num(grad, "alpha") / 255));
2247
+ const stops = colors.map((color, i) => `<stop offset="${colors.length === 1 ? 0 : i / (colors.length - 1)}" stop-color="${esc(color)}" stop-opacity="${opacity}"/>`).join("");
2248
+ if (type === "RADIAL") defs.push(`<radialGradient id="${id}" cx="${num(grad, "centerX", 50)}%" cy="${num(grad, "centerY", 50)}%">${stops}</radialGradient>`);
2249
+ else {
2250
+ const a = num(grad, "angle") * Math.PI / 180, dx = Math.cos(a) / 2, dy = -Math.sin(a) / 2;
2251
+ defs.push(`<linearGradient id="${id}" x1="${0.5 - dx}" y1="${0.5 - dy}" x2="${0.5 + dx}" y2="${0.5 + dy}">${stops}</linearGradient>`);
2252
+ }
2253
+ return `url(#${id})`;
2254
+ }
2255
+ const imgBrush = brush && findChildByLocalName(brush, "imgBrush");
2256
+ const img = imgBrush && findChildByLocalName(imgBrush, "img");
2257
+ if (imgBrush && img) {
2258
+ const ref = img.getAttribute("binaryItemIDRef") ?? "";
2259
+ const loaded = images.get(ref);
2260
+ if (!loaded) {
2261
+ warn(`brush-image:${ref}`, `\uADF8\uB9BC \uCC44\uC6C0 \uC774\uBBF8\uC9C0(${ref}) \uC5C6\uC74C \u2014 \uCC44\uC6C0 \uC0DD\uB7B5`);
2262
+ return "none";
2263
+ }
2264
+ const mode = imgBrush.getAttribute("mode") ?? "TOTAL";
2265
+ if (mode !== "TOTAL") {
2266
+ warn(`brush-mode:${mode}`, `\uADF8\uB9BC \uCC44\uC6C0(${mode}) \uBBF8\uC9C0\uC6D0 \u2014 \uCC44\uC6C0 \uC0DD\uB7B5`);
2267
+ return "none";
2268
+ }
2269
+ if (loaded.paintId) return `url(#${loaded.paintId})`;
2270
+ const id = `paint${defs.length}`;
2271
+ defs.push(`<pattern id="${id}" width="1" height="1" patternContentUnits="objectBoundingBox"><image href="${esc(loaded.dataUri)}" width="1" height="1" preserveAspectRatio="none"/></pattern>`);
2272
+ loaded.paintId = id;
2273
+ return `url(#${id})`;
2274
+ }
2275
+ return "none";
2276
+ }
2277
+ function shapeGeometry(o, x, y, defs, images, warn) {
2278
+ const el = o.el, org = findChildByLocalName(el, "orgSz"), cur = findChildByLocalName(el, "curSz");
2279
+ const ow = num(org, "width"), oh = num(org, "height");
2280
+ const w = num(cur, "width") || ow || o.width, h = num(cur, "height") || oh || o.height;
2281
+ const sx = ow > 0 ? w / ow : 1, sy = oh > 0 ? h / oh : 1;
2282
+ const line = findChildByLocalName(el, "lineShape"), style = line?.getAttribute("style") ?? "SOLID";
2283
+ const color = esc(line?.getAttribute("color") || "#000000");
2284
+ const strokeW = style === "NONE" ? 0 : Math.max(0.2, num(line, "width", 33) / 100 * 2.834645);
2285
+ const dash = /DASH|DOT/.test(style) ? ` stroke-dasharray="${style.includes("DOT") ? "1,1.5" : "3,1.5"}"` : "";
2286
+ const stroke = strokeW ? ` stroke="${color}" stroke-width="${strokeW.toFixed(2)}"${dash}` : "";
2287
+ const fill = ` fill="${shapeFill(el, defs, images, warn)}"`;
2288
+ let svg = "";
2289
+ if (o.tag === "rect") svg = `<rect x="${pt(x)}" y="${pt(y)}" width="${pt(w)}" height="${pt(h)}"${fill}${stroke}/>`;
2290
+ else if (o.tag === "ellipse") svg = `<ellipse cx="${pt(x + w / 2)}" cy="${pt(y + h / 2)}" rx="${pt(w / 2)}" ry="${pt(h / 2)}"${fill}${stroke}/>`;
2291
+ else if (o.tag === "line") {
2292
+ const s = findChildByLocalName(el, "startPt"), e = findChildByLocalName(el, "endPt");
2293
+ svg = `<line x1="${pt(x + num(s, "x") * sx)}" y1="${pt(y + num(s, "y") * sy)}" x2="${pt(x + num(e, "x") * sx)}" y2="${pt(y + num(e, "y") * sy)}" stroke="${color}" stroke-width="${(strokeW || 0.3).toFixed(2)}"${dash}/>`;
2294
+ } else if (o.tag === "polygon" || o.tag === "curv") {
2295
+ const pts = elements(el).filter((c) => ln(c) === "pt").map((c) => `${pt(x + num(c, "x") * sx)},${pt(y + num(c, "y") * sy)}`);
2296
+ if (pts.length >= 2) svg = `<polygon points="${pts.join(" ")}"${fill}${stroke}/>`;
2297
+ } else if (o.tag === "curve") {
2298
+ const segs = elements(el).filter((c) => ln(c) === "seg");
2299
+ if (segs.some((s) => s.getAttribute("type") !== "LINE")) warn("curve:bezier", "\uBE44\uC120\uD615 \uACE1\uC120 \uB80C\uB354 \uBBF8\uC9C0\uC6D0 \u2014 \uC0DD\uB7B5");
2300
+ else if (segs.length) {
2301
+ let path = "", lastX, lastY;
2302
+ for (const s of segs) {
2303
+ const x1 = num(s, "x1"), y1 = num(s, "y1"), x2 = num(s, "x2"), y2 = num(s, "y2");
2304
+ if (x1 !== lastX || y1 !== lastY) path += `M${pt(x + x1 * sx)} ${pt(y + y1 * sy)}`;
2305
+ path += `L${pt(x + x2 * sx)} ${pt(y + y2 * sy)}`;
2306
+ lastX = x2;
2307
+ lastY = y2;
2308
+ }
2309
+ svg = `<path d="${path}"${fill}${stroke}/>`;
2310
+ }
2311
+ } else if (o.tag === "arc") svg = `<ellipse cx="${pt(x + w / 2)}" cy="${pt(y + h / 2)}" rx="${pt(w / 2)}" ry="${pt(h / 2)}" fill="none"${stroke || ` stroke="${color}" stroke-width="0.3"`}/>`;
2312
+ return { ...objectGeometry(el, x, y, w, h), svg };
2313
+ }
2314
+
2109
2315
  // src/render/svg-render.ts
2110
2316
  function escapeXml(s) {
2111
2317
  return s.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
2112
2318
  }
2113
- var pt = (u) => String(Math.round(u) / 100);
2319
+ var pt2 = (u) => String(Math.round(u) / 100);
2114
2320
  var ptNum = (u) => Math.round(u) / 100;
2115
2321
  function pageNo(ctx) {
2116
2322
  return ctx.pageBase + ctx.page + 1;
2117
2323
  }
2118
2324
  function bboxOf(ctx, x, y, w, h) {
2119
- const clippedH = Math.max(0, Math.min(h, ctx.pageH - y));
2120
- return { page: pageNo(ctx), x: ptNum(x), y: ptNum(y), width: ptNum(Math.max(0, w)), height: ptNum(clippedH) };
2325
+ const b = rotatedBounds({ x, y, w, h }, ctx.regionRotations);
2326
+ const clippedH = Math.max(0, Math.min(b.h, ctx.pageH - b.y));
2327
+ return { page: pageNo(ctx), x: ptNum(b.x), y: ptNum(b.y), width: ptNum(Math.max(0, b.w)), height: ptNum(clippedH) };
2121
2328
  }
2122
2329
  function regionOpenTag(id, type, page) {
2123
2330
  return `<g data-kordoc-id="${id}" data-kordoc-type="${type}" data-kordoc-page="${page}">`;
@@ -2210,7 +2417,10 @@ function drawPara(p, ox, oy, areaW, ctx, depth, segPages) {
2210
2417
  if (m.chars.some((c) => c.ch !== "")) {
2211
2418
  warnOnce(ctx, "no-lineseg", "\uC870\uD310 \uCE90\uC2DC \uC5C6\uB294 \uBB38\uB2E8 \uD14D\uC2A4\uD2B8 \uC0DD\uB7B5 \u2014 reflow \uC635\uC158\uC73C\uB85C \uD569\uC131 \uAC00\uB2A5");
2212
2419
  }
2213
- for (const o of m.objs) drawObject(o, ox, oy, 0, areaW, ctx, depth);
2420
+ for (const o of m.objs) {
2421
+ const { x, y } = o.inline ? { x: ox, y: oy } : anchorObject(o, ox, oy, 0, areaW, ctx);
2422
+ drawObject(o, x, y, 0, areaW, ctx, depth);
2423
+ }
2214
2424
  return;
2215
2425
  }
2216
2426
  const plans = planLines(m, ctx.styles);
@@ -2269,13 +2479,13 @@ function drawPara(p, ox, oy, areaW, ctx, depth, segPages) {
2269
2479
  const renderSeg = (text, cx, hit) => {
2270
2480
  const sw = measureTextWidth(text, st.height, st.ratio, { spacingPct: st.spacing, faceClass: faceClassOf(st.face) }) * scale;
2271
2481
  if (hit) {
2272
- emit(ctx, `<rect x="${pt(cx)}" y="${pt(oy + seg.vertpos)}" width="${pt(sw)}" height="${pt(seg.textheight)}" fill="#ffd54f" fill-opacity="0.45"/>`);
2482
+ emit(ctx, `<rect x="${pt2(cx)}" y="${pt2(oy + seg.vertpos)}" width="${pt2(sw)}" height="${pt2(seg.textheight)}" fill="#ffd54f" fill-opacity="0.45"/>`);
2273
2483
  }
2274
2484
  if (text.trim().length > 0) {
2275
- const attrs = [`x="${pt(cx)}"`, `y="${pt(y)}"`, `font-size="${pt(st.height)}"`];
2485
+ const attrs = [`x="${pt2(cx)}"`, `y="${pt2(y)}"`, `font-size="${pt2(st.height)}"`];
2276
2486
  if (st.fontFamily) attrs.push(`font-family="${escapeXml(st.fontFamily)}"`);
2277
2487
  if ([...text].length > 1 && sw > 50) {
2278
- attrs.push(`textLength="${pt(sw)}"`, `lengthAdjust="${scale < 1 ? "spacingAndGlyphs" : "spacing"}"`);
2488
+ attrs.push(`textLength="${pt2(sw)}"`, `lengthAdjust="${scale < 1 ? "spacingAndGlyphs" : "spacing"}"`);
2279
2489
  }
2280
2490
  if (st.bold) attrs.push(`font-weight="bold"`);
2281
2491
  if (st.italic) attrs.push(`font-style="italic"`);
@@ -2377,6 +2587,19 @@ function anchorObject(o, ox, oy, baseV, areaW, ctx) {
2377
2587
  return { x, y };
2378
2588
  }
2379
2589
  function drawObject(o, x, y, baseV, areaW, ctx, depth) {
2590
+ if (!o.inline && depth === 0 && ctx.paintJobs) {
2591
+ const wrap = o.el.getAttribute("textWrap");
2592
+ const layer = wrap === "BEHIND_TEXT" ? -1 : wrap === "IN_FRONT_OF_TEXT" ? 1 : 0;
2593
+ const page = ctx.page, parents = [...ctx.parentStack];
2594
+ ctx.paintJobs.push({ page, layer, z: num(o.el, "zOrder"), draw: () => {
2595
+ ctx.page = page;
2596
+ const saved = ctx.parentStack;
2597
+ ctx.parentStack = parents;
2598
+ drawObject(o, x, y, baseV, areaW, ctx, depth);
2599
+ ctx.parentStack = saved;
2600
+ } });
2601
+ return;
2602
+ }
2380
2603
  if (o.tag === "tbl") drawTable(o.el, x, y, ctx, depth + 1);
2381
2604
  else if (o.tag === "pic") drawPic(o.el, x, y, ctx);
2382
2605
  else if (o.tag === "container") {
@@ -2396,62 +2619,29 @@ function drawObject(o, x, y, baseV, areaW, ctx, depth) {
2396
2619
  warnOnce(ctx, `shape:${o.tag}`, `\uAC1C\uCCB4(${o.tag}) \uB80C\uB354 \uBBF8\uC9C0\uC6D0 \u2014 \uC0DD\uB7B5`);
2397
2620
  }
2398
2621
  }
2399
- var SHAPE_TAGS = /* @__PURE__ */ new Set(["rect", "ellipse", "line", "polygon", "curv", "arc"]);
2400
- function shapeStrokePt(v) {
2401
- return Math.max(0.2, v / 100 * 2.834645);
2402
- }
2403
2622
  function drawShape(o, x, y, ctx, depth) {
2404
- const el = o.el;
2405
- const orgSz = findChildByLocalName(el, "orgSz");
2406
- const curSz = findChildByLocalName(el, "curSz");
2407
- const ow = num(orgSz, "width"), oh = num(orgSz, "height");
2408
- const w = num(curSz, "width") || ow || o.width;
2409
- const h = num(curSz, "height") || oh || o.height;
2410
- const sx = ow > 0 ? w / ow : 1;
2411
- const sy = oh > 0 ? h / oh : 1;
2412
- const lineShape = findChildByLocalName(el, "lineShape");
2413
- const lstyle = lineShape?.getAttribute("style") ?? "SOLID";
2414
- const strokeCol = lineShape?.getAttribute("color") || "#000000";
2415
- const hasStroke = lstyle !== "NONE";
2416
- const strokeW = hasStroke ? shapeStrokePt(lineShape ? num(lineShape, "width") : 33) : 0;
2417
- const dash = /DASH|DOT/.test(lstyle) ? ` stroke-dasharray="${lstyle.includes("DOT") ? "1,1.5" : "3,1.5"}"` : "";
2418
- const strokeAttr = hasStroke ? ` stroke="${escapeXml(strokeCol)}" stroke-width="${strokeW.toFixed(2)}"${dash}` : "";
2419
- const fillBrush = findChildByLocalName(el, "fillBrush");
2420
- const winBrush = fillBrush ? findChildByLocalName(fillBrush, "winBrush") : null;
2421
- const face = winBrush?.getAttribute("faceColor");
2422
- const fill = face && face.toLowerCase() !== "none" ? face : "none";
2423
- const fillAttr = ` fill="${fill === "none" ? "none" : escapeXml(fill)}"`;
2623
+ const geometry = shapeGeometry(o, x, y, ctx.defs, ctx.images, (key, msg) => warnOnce(ctx, key, msg));
2624
+ const b = geometry;
2625
+ if (geometry.rotation) ctx.regionRotations.push(geometry.rotation);
2424
2626
  ctx.stats.shapes++;
2425
- const shapeId = ctx.regions.add("shape", bboxOf(ctx, x, y, w, h), { parentId: parentId(ctx) });
2627
+ const shapeId = ctx.regions.add("shape", bboxOf(ctx, b.x, b.y, b.w, b.h), { parentId: parentId(ctx) });
2426
2628
  emit(ctx, regionOpenTag(shapeId, "shape", pageNo(ctx)));
2427
2629
  ctx.parentStack.push(shapeId);
2428
- if (o.tag === "rect") {
2429
- emit(ctx, `<rect x="${pt(x)}" y="${pt(y)}" width="${pt(w)}" height="${pt(h)}"${fillAttr}${strokeAttr}/>`);
2430
- } else if (o.tag === "ellipse") {
2431
- emit(ctx, `<ellipse cx="${pt(x + w / 2)}" cy="${pt(y + h / 2)}" rx="${pt(w / 2)}" ry="${pt(h / 2)}"${fillAttr}${strokeAttr}/>`);
2432
- } else if (o.tag === "line") {
2433
- const s = findChildByLocalName(el, "startPt"), e = findChildByLocalName(el, "endPt");
2434
- const x1 = x + num(s, "x") * sx, y1 = y + num(s, "y") * sy;
2435
- const x2 = x + num(e, "x") * sx, y2 = y + num(e, "y") * sy;
2436
- emit(ctx, `<line x1="${pt(x1)}" y1="${pt(y1)}" x2="${pt(x2)}" y2="${pt(y2)}" stroke="${escapeXml(strokeCol)}" stroke-width="${(strokeW || 0.3).toFixed(2)}"${dash}/>`);
2437
- } else if (o.tag === "polygon" || o.tag === "curv") {
2438
- const pts = [];
2439
- for (const c of elements(el)) if (ln(c) === "pt") pts.push(`${pt(x + num(c, "x") * sx)},${pt(y + num(c, "y") * sy)}`);
2440
- if (pts.length >= 2) emit(ctx, `<polygon points="${pts.join(" ")}"${fillAttr}${strokeAttr}/>`);
2441
- } else if (o.tag === "arc") {
2442
- emit(ctx, `<ellipse cx="${pt(x + w / 2)}" cy="${pt(y + h / 2)}" rx="${pt(w / 2)}" ry="${pt(h / 2)}" fill="none"${strokeAttr || ` stroke="${escapeXml(strokeCol)}" stroke-width="0.3"`}/>`);
2443
- }
2444
- const dt = findChildByLocalName(el, "drawText");
2630
+ if (geometry.transform) emit(ctx, `<g transform="${geometry.transform}">`);
2631
+ emit(ctx, geometry.svg);
2632
+ const dt = findChildByLocalName(o.el, "drawText");
2445
2633
  const sub = dt ? findChildByLocalName(dt, "subList") : null;
2446
2634
  if (sub) {
2447
- for (const p of elements(sub)) if (ln(p) === "p") drawPara(p, x, y, w, ctx, depth + 1);
2635
+ for (const p of elements(sub)) if (ln(p) === "p") drawPara(p, x, y, geometry.w, ctx, depth + 1);
2448
2636
  }
2637
+ if (geometry.rotation) ctx.regionRotations.pop();
2638
+ if (geometry.transform) emit(ctx, "</g>");
2449
2639
  ctx.parentStack.pop();
2450
2640
  emit(ctx, "</g>");
2451
2641
  }
2452
2642
  function edgeLine(x1, y1, x2, y2, e) {
2453
2643
  const dash = /DASH|DOT/.test(e.type) ? ` stroke-dasharray="${e.type.includes("DOT") ? "1,1.5" : "3,1.5"}"` : "";
2454
- return `<line x1="${pt(x1)}" y1="${pt(y1)}" x2="${pt(x2)}" y2="${pt(y2)}" stroke="${escapeXml(e.color)}" stroke-width="${e.widthPt.toFixed(2)}"${dash}/>`;
2644
+ return `<line x1="${pt2(x1)}" y1="${pt2(y1)}" x2="${pt2(x2)}" y2="${pt2(y2)}" stroke="${escapeXml(e.color)}" stroke-width="${e.widthPt.toFixed(2)}"${dash}/>`;
2455
2645
  }
2456
2646
  function drawTable(tbl, tx, ty, ctx, depth) {
2457
2647
  if (depth > 16) {
@@ -2486,7 +2676,7 @@ function drawTable(tbl, tx, ty, ctx, depth) {
2486
2676
  }));
2487
2677
  for (const g of geom) {
2488
2678
  const bf = g.c.bfId != null ? ctx.styles.borderFill.get(g.c.bfId) : void 0;
2489
- if (bf?.fill) emit(ctx, `<rect x="${pt(g.x)}" y="${pt(g.y)}" width="${pt(g.w)}" height="${pt(g.h)}" fill="${escapeXml(bf.fill)}"/>`);
2679
+ if (bf?.fill) emit(ctx, `<rect x="${pt2(g.x)}" y="${pt2(g.y)}" width="${pt2(g.w)}" height="${pt2(g.h)}" fill="${escapeXml(bf.fill)}"/>`);
2490
2680
  }
2491
2681
  for (const g of geom) {
2492
2682
  const { c } = g;
@@ -2531,7 +2721,7 @@ function drawPic(pic, x, y, ctx) {
2531
2721
  const imgId = ctx.regions.add("image", bboxOf(ctx, x, y, w, h), { sourceId: ref ?? void 0, parentId: parentId(ctx) });
2532
2722
  emit(ctx, regionOpenTag(imgId, "image", pageNo(ctx)));
2533
2723
  if (!loaded) {
2534
- emit(ctx, `<rect x="${pt(x)}" y="${pt(y)}" width="${pt(w)}" height="${pt(h)}" fill="#eee" stroke="#c00" stroke-width="0.5"/>`);
2724
+ emit(ctx, `<rect x="${pt2(x)}" y="${pt2(y)}" width="${pt2(w)}" height="${pt2(h)}" fill="#eee" stroke="#c00" stroke-width="0.5"/>`);
2535
2725
  warnOnce(ctx, `img:${ref}`, `\uC774\uBBF8\uC9C0 \uBC14\uC774\uB108\uB9AC \uB204\uB77D: ${ref ?? "(ref \uC5C6\uC74C)"}`);
2536
2726
  emit(ctx, "</g>");
2537
2727
  return;
@@ -2550,10 +2740,10 @@ function drawPic(pic, x, y, ctx) {
2550
2740
  if (cropped) {
2551
2741
  emit(
2552
2742
  ctx,
2553
- `<svg x="${pt(x)}" y="${pt(y)}" width="${pt(w)}" height="${pt(h)}" viewBox="${pt(cl)} ${pt(ct)} ${pt(cr - cl)} ${pt(cb - ct)}" preserveAspectRatio="none"><use href="#${symId}" x="0" y="0" width="${pt(refW)}" height="${pt(refH)}"/></svg>`
2743
+ `<svg x="${pt2(x)}" y="${pt2(y)}" width="${pt2(w)}" height="${pt2(h)}" viewBox="${pt2(cl)} ${pt2(ct)} ${pt2(cr - cl)} ${pt2(cb - ct)}" preserveAspectRatio="none"><use href="#${symId}" x="0" y="0" width="${pt2(refW)}" height="${pt2(refH)}"/></svg>`
2554
2744
  );
2555
2745
  } else {
2556
- emit(ctx, `<use href="#${symId}" x="${pt(x)}" y="${pt(y)}" width="${pt(w)}" height="${pt(h)}"/>`);
2746
+ emit(ctx, `<use href="#${symId}" x="${pt2(x)}" y="${pt2(y)}" width="${pt2(w)}" height="${pt2(h)}"/>`);
2557
2747
  }
2558
2748
  emit(ctx, "</g>");
2559
2749
  }
@@ -2581,8 +2771,9 @@ function readSectionGeom(root) {
2581
2771
  const BODY_W = PW - ML - num(margin, "right", 8504);
2582
2772
  return { PW, PH, ML, MT, BODY_W, BODY_H };
2583
2773
  }
2584
- function renderSectionToPages(root, geom, ctxBase, doReflow, reflowMode) {
2774
+ function renderSectionToPages(root, geom, ctxBase, doReflow, reflowMode, masters = [], hasDeletionMarkers = true) {
2585
2775
  const { PW, PH, ML, MT, BODY_W, BODY_H } = geom;
2776
+ if (hasDeletionMarkers) prepareDeletedRanges(root);
2586
2777
  if (doReflow) reflowSection(root, ctxBase.styles, { BODY_W, BODY_H }, reflowMode);
2587
2778
  const colPr = findFirst(root, "colPr");
2588
2779
  const multiCol = num(colPr, "colCount", 1) > 1;
@@ -2620,12 +2811,35 @@ function renderSectionToPages(root, geom, ctxBase, doReflow, reflowMode) {
2620
2811
  pages: Array.from({ length: nPages }, () => []),
2621
2812
  page: 0,
2622
2813
  geom,
2623
- pageH
2814
+ pageH,
2815
+ paintJobs: [],
2816
+ regionRotations: []
2624
2817
  };
2818
+ for (const story of pageStories(root, masters, paraSegPages, nPages, ctx.pageBase, geom)) {
2819
+ prepareDeletedRanges(story.sub);
2820
+ if (doReflow) reflowSection(story.sub, ctx.styles, { BODY_W: story.width, BODY_H: 0 }, reflowMode);
2821
+ const draw = () => {
2822
+ ctx.page = story.page;
2823
+ for (const p of elements(story.sub)) if (ln(p) === "p") drawPara(p, story.x, story.y, story.width, ctx, 0);
2824
+ };
2825
+ if (story.layer !== void 0) ctx.paintJobs.push({ page: story.page, layer: story.layer, z: 0, draw });
2826
+ else draw();
2827
+ }
2828
+ ctx.page = 0;
2625
2829
  for (const p of elements(root)) {
2626
2830
  if (ln(p) !== "p") continue;
2627
2831
  drawPara(p, ML, MT, BODY_W, ctx, 0, paraSegPages.get(p));
2628
2832
  }
2833
+ const normal = ctx.pages;
2834
+ const jobs = ctx.paintJobs;
2835
+ ctx.paintJobs = null;
2836
+ const behind = Array.from({ length: nPages }, () => []);
2837
+ const front = Array.from({ length: nPages }, () => []);
2838
+ for (const job of jobs.sort((a, b) => a.layer - b.layer || a.z - b.z)) {
2839
+ ctx.pages = job.layer < 0 ? behind : front;
2840
+ job.draw();
2841
+ }
2842
+ ctx.pages = normal.map((buf, page) => [...behind[page], ...buf, ...front[page]]);
2629
2843
  return { pages: ctx.pages, pageH };
2630
2844
  }
2631
2845
  function renderSectionRoots(sections, input) {
@@ -2643,9 +2857,9 @@ function renderSectionRoots(sections, input) {
2643
2857
  pageBase: 0
2644
2858
  };
2645
2859
  const rendered = [];
2646
- for (const { root, index } of sections) {
2860
+ for (const { root, index, masterPages, hasDeletionMarkers } of sections) {
2647
2861
  const geom = readSectionGeom(root);
2648
- const { pages, pageH } = renderSectionToPages(root, geom, ctxBase, input.reflow, input.reflowMode);
2862
+ const { pages, pageH } = renderSectionToPages(root, geom, ctxBase, input.reflow, input.reflowMode, masterPages, hasDeletionMarkers);
2649
2863
  rendered.push({ pages, PW: geom.PW, pageH, clipId: `pgclip${index}` });
2650
2864
  ctxBase.pageBase += pages.length;
2651
2865
  }
@@ -2675,6 +2889,17 @@ async function renderHwpxInternal(input, options) {
2675
2889
  if (xml.length > MAX_DECOMPRESS_SIZE) throw new KordocError("\uC139\uC158 XML\uC774 \uD5C8\uC6A9 \uD06C\uAE30\uB97C \uCD08\uACFC");
2676
2890
  secXmls.push(xml);
2677
2891
  }
2892
+ const masterPages = /* @__PURE__ */ new Map();
2893
+ const masterXmls = [];
2894
+ for (const file of zip.file(/Contents\/masterpage[^/]*\.xml$/i)) {
2895
+ const xml = await file.async("string");
2896
+ if (xml.length > MAX_DECOMPRESS_SIZE) throw new KordocError("\uBC14\uD0D5\uCABD XML\uC774 \uD5C8\uC6A9 \uD06C\uAE30\uB97C \uCD08\uACFC");
2897
+ const root = createXmlParser().parseFromString(xml, "text/xml").documentElement;
2898
+ if (root && ln(root) === "masterPage") {
2899
+ masterPages.set(root.getAttribute("id") || file.name.replace(/^.*\/|\.xml$/g, ""), root);
2900
+ masterXmls.push(xml);
2901
+ }
2902
+ }
2678
2903
  const binmap = /* @__PURE__ */ new Map();
2679
2904
  const hpf = zip.file(/content\.hpf$/i)[0];
2680
2905
  if (hpf) {
@@ -2686,7 +2911,7 @@ async function renderHwpxInternal(input, options) {
2686
2911
  const MAX_TOTAL_IMAGE_BYTES = 128 * 1024 * 1024;
2687
2912
  const images = /* @__PURE__ */ new Map();
2688
2913
  const refs = /* @__PURE__ */ new Set();
2689
- for (const xml of secXmls) for (const m of xml.matchAll(/binaryItemIDRef="([^"]+)"/g)) refs.add(m[1]);
2914
+ for (const xml of [...secXmls, ...masterXmls]) for (const m of xml.matchAll(/binaryItemIDRef="([^"]+)"/g)) refs.add(m[1]);
2690
2915
  let totalImgBytes = 0;
2691
2916
  for (const ref of refs) {
2692
2917
  if (images.size >= MAX_IMAGE_REFS) {
@@ -2729,7 +2954,9 @@ async function renderHwpxInternal(input, options) {
2729
2954
  warnings.push(`\uAD6C\uC5ED ${si} XML \uD30C\uC2F1 \uC2E4\uD328 \u2014 \uC0DD\uB7B5`);
2730
2955
  continue;
2731
2956
  }
2732
- roots.push({ root, index: si });
2957
+ const secPr = findFirst(root, "secPr");
2958
+ const referenced = secPr ? elements(secPr).filter((el) => ln(el) === "masterPage").map((el) => masterPages.get(el.getAttribute("idRef") || "")).filter((el) => !!el) : [];
2959
+ roots.push({ root, index: si, masterPages: referenced, hasDeletionMarkers: secXml.includes("deleteBegin") || secXml.includes("deleteEnd") });
2733
2960
  }
2734
2961
  if (roots.length === 0) {
2735
2962
  if (noCacheSkipped) {
@@ -2749,11 +2976,11 @@ async function renderHwpxToSvg(input, options) {
2749
2976
  let pageNo2 = 0;
2750
2977
  for (const rs of r.sections) {
2751
2978
  maxPW = Math.max(maxPW, rs.PW);
2752
- clipDefs.push(`<clipPath id="${rs.clipId}"><rect x="0" y="0" width="${pt(rs.PW)}" height="${pt(rs.pageH)}"/></clipPath>`);
2979
+ clipDefs.push(`<clipPath id="${rs.clipId}"><rect x="0" y="0" width="${pt2(rs.PW)}" height="${pt2(rs.pageH)}"/></clipPath>`);
2753
2980
  for (const buf of rs.pages) {
2754
2981
  pageNo2++;
2755
2982
  groups.push(
2756
- `<g data-page="${pageNo2}" transform="translate(0 ${pt(y)})"><rect width="${pt(rs.PW)}" height="${pt(rs.pageH)}" fill="white" stroke="#c9c7c4" stroke-width="0.75"/><g clip-path="url(#${rs.clipId})">
2983
+ `<g data-page="${pageNo2}" transform="translate(0 ${pt2(y)})"><rect width="${pt2(rs.PW)}" height="${pt2(rs.pageH)}" fill="white" stroke="#c9c7c4" stroke-width="0.75"/><g clip-path="url(#${rs.clipId})">
2757
2984
  ${buf.join("\n")}
2758
2985
  </g></g>`
2759
2986
  );
@@ -2761,7 +2988,7 @@ ${buf.join("\n")}
2761
2988
  }
2762
2989
  }
2763
2990
  const totalH = Math.max(0, y - GAP);
2764
- const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${pt(maxPW)} ${pt(totalH)}" width="${pt(maxPW)}pt" height="${pt(totalH)}pt" font-family="${SVG_FONT_FAMILY}" xml:space="preserve">
2991
+ const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${pt2(maxPW)} ${pt2(totalH)}" width="${pt2(maxPW)}pt" height="${pt2(totalH)}pt" font-family="${SVG_FONT_FAMILY}" xml:space="preserve">
2765
2992
  <defs>${clipDefs.join("")}${r.defs.join("")}</defs>
2766
2993
  ${groups.join("\n")}
2767
2994
  </svg>`;
@@ -2788,9 +3015,9 @@ function assemblePageSvgs(r, format, select) {
2788
3015
  const clipId = `pgclip${pageNo2}`;
2789
3016
  pageSvgs.set(
2790
3017
  pageNo2,
2791
- `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${pt(rs.PW)} ${pt(rs.pageH)}" width="${pt(rs.PW)}pt" height="${pt(rs.pageH)}pt" font-family="${SVG_FONT_FAMILY}" xml:space="preserve" data-page="${pageNo2}">
2792
- <defs><clipPath id="${clipId}"><rect x="0" y="0" width="${pt(rs.PW)}" height="${pt(rs.pageH)}"/></clipPath>${defs.join("")}</defs>
2793
- <rect width="${pt(rs.PW)}" height="${pt(rs.pageH)}" fill="white"/>
3018
+ `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${pt2(rs.PW)} ${pt2(rs.pageH)}" width="${pt2(rs.PW)}pt" height="${pt2(rs.pageH)}pt" font-family="${SVG_FONT_FAMILY}" xml:space="preserve" data-page="${pageNo2}">
3019
+ <defs><clipPath id="${clipId}"><rect x="0" y="0" width="${pt2(rs.PW)}" height="${pt2(rs.pageH)}"/></clipPath>${defs.join("")}</defs>
3020
+ <rect width="${pt2(rs.PW)}" height="${pt2(rs.pageH)}" fill="white"/>
2794
3021
  <g clip-path="url(#${clipId})">
2795
3022
  ${body}
2796
3023
  </g>
@@ -7387,4 +7614,4 @@ export {
7387
7614
  cropRect,
7388
7615
  extractRenderedRegions
7389
7616
  };
7390
- //# sourceMappingURL=chunk-JY2NBFIG.js.map
7617
+ //# sourceMappingURL=chunk-TMHMJUYU.js.map