kordoc 4.22.4 → 4.22.5

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 +8 -7
  2. package/dist/{-HAK3YFWW.js → -WFRWBH7T.js} +11 -11
  3. package/dist/{chunk-F3AWNFMO.js → chunk-2L3Q7REU.js} +3 -3
  4. package/dist/{chunk-CWBH66IQ.js → chunk-35ZHXEJA.js} +3 -3
  5. package/dist/{chunk-Q6SVCBMK.js → chunk-3BR7VKWL.js} +2 -2
  6. package/dist/{chunk-G2325K2F.js → chunk-3G3TLZDK.js} +2 -2
  7. package/dist/{chunk-36DK6AOX.js → chunk-3YEL7P4L.js} +2 -2
  8. package/dist/{chunk-S45M7IQH.cjs → chunk-4SUB43EJ.cjs} +24 -24
  9. package/dist/{chunk-S45M7IQH.cjs.map → chunk-4SUB43EJ.cjs.map} +1 -1
  10. package/dist/{chunk-5ARHF54C.js → chunk-4TWN7PWJ.js} +2 -2
  11. package/dist/{chunk-WCTC3LSV.js → chunk-52HIK4C2.js} +4 -3
  12. package/dist/chunk-52HIK4C2.js.map +1 -0
  13. package/dist/{chunk-3TUJ34V7.js → chunk-63N6CEJE.js} +2 -2
  14. package/dist/{chunk-DEFT7Z3B.js → chunk-6MCC2XNB.js} +2 -2
  15. package/dist/{chunk-C5J5LDWM.js → chunk-6MQKNB6K.js} +4 -3
  16. package/dist/chunk-6MQKNB6K.js.map +1 -0
  17. package/dist/{chunk-MJSHXESK.cjs → chunk-AS25R4EU.cjs} +2 -2
  18. package/dist/{chunk-MJSHXESK.cjs.map → chunk-AS25R4EU.cjs.map} +1 -1
  19. package/dist/{chunk-AYV5VRHL.js → chunk-C3REGEQO.js} +2 -2
  20. package/dist/{chunk-4X7AR4EH.cjs → chunk-C6B5GWN7.cjs} +24 -23
  21. package/dist/chunk-C6B5GWN7.cjs.map +1 -0
  22. package/dist/{chunk-A3SKXHAN.js → chunk-CO7O3ZT6.js} +2 -2
  23. package/dist/{chunk-WNW77CAY.js → chunk-CRSTBATY.js} +2 -2
  24. package/dist/{chunk-MYTMZSQO.js → chunk-CW67DAAH.js} +2 -2
  25. package/dist/{chunk-RPSILMQY.js → chunk-DN55FTJP.js} +2 -2
  26. package/dist/{chunk-HN3QMHTT.js → chunk-HLPMC7L4.js} +5 -4
  27. package/dist/chunk-HLPMC7L4.js.map +1 -0
  28. package/dist/{chunk-LVVSMYG4.js → chunk-LE4VHWIT.js} +4 -4
  29. package/dist/{chunk-VXQWAPC6.cjs → chunk-N6KXGIIN.cjs} +3 -3
  30. package/dist/{chunk-VXQWAPC6.cjs.map → chunk-N6KXGIIN.cjs.map} +1 -1
  31. package/dist/{chunk-G4KNI7EO.js → chunk-PSORL4PA.js} +11 -11
  32. package/dist/{chunk-FAFSBCU2.js → chunk-RYKDIUHT.js} +4 -4
  33. package/dist/{chunk-SSL3TKJY.js → chunk-SETAYS6P.js} +2 -2
  34. package/dist/{chunk-Q65HT2BL.js → chunk-T7OZ7X6A.js} +2 -2
  35. package/dist/{chunk-UJVVL6BI.js → chunk-TOUJCO2P.js} +2 -2
  36. package/dist/{chunk-EVL6HZQL.js → chunk-U3GUZQ54.js} +1286 -1279
  37. package/dist/chunk-U3GUZQ54.js.map +1 -0
  38. package/dist/{chunk-EYQLJ57Y.cjs → chunk-UCK6WGHY.cjs} +3 -3
  39. package/dist/{chunk-EYQLJ57Y.cjs.map → chunk-UCK6WGHY.cjs.map} +1 -1
  40. package/dist/{chunk-K2NWHLCD.cjs → chunk-YG4GFQB7.cjs} +6 -6
  41. package/dist/{chunk-K2NWHLCD.cjs.map → chunk-YG4GFQB7.cjs.map} +1 -1
  42. package/dist/chunks-NXABWR6G.js +10 -0
  43. package/dist/cli.js +30 -30
  44. package/dist/{formula-PWAUR5PF.js → formula-FSVHUQ6Y.js} +4 -4
  45. package/dist/{formula-KSTY73DQ.js → formula-L625ULJP.js} +3 -3
  46. package/dist/{formula-JGFYGFYX.cjs → formula-QZGTF3DZ.cjs} +9 -9
  47. package/dist/{formula-JGFYGFYX.cjs.map → formula-QZGTF3DZ.cjs.map} +1 -1
  48. package/dist/{image-ocr-UULNAC5Y.cjs → image-ocr-AELVAU75.cjs} +17 -17
  49. package/dist/{image-ocr-UULNAC5Y.cjs.map → image-ocr-AELVAU75.cjs.map} +1 -1
  50. package/dist/{image-ocr-RASJHOAK.js → image-ocr-KE3RUS3R.js} +6 -6
  51. package/dist/{image-ocr-RPBPO3VT.js → image-ocr-QTZNBP5V.js} +9 -9
  52. package/dist/index.cjs +790 -782
  53. package/dist/index.cjs.map +1 -1
  54. package/dist/index.js +249 -241
  55. package/dist/index.js.map +1 -1
  56. package/dist/mcp.js +22 -22
  57. package/dist/{model-bundle-ZPQ4IFT7.js → model-bundle-F6TU6ZAV.js} +5 -5
  58. package/dist/{models-YJQ5VHOR.js → models-ZHNNVH2W.js} +5 -5
  59. package/dist/{parse-worker-v2-7PNZYASF.js → parse-worker-v2-KQRG3NQO.js} +12 -12
  60. package/dist/{parser-ER3VLB37.js → parser-RVMH4PUB.js} +133 -20
  61. package/dist/parser-RVMH4PUB.js.map +1 -0
  62. package/dist/{parser-DR6ZHYEB.js → parser-WBKVRDPV.js} +129 -16
  63. package/dist/parser-WBKVRDPV.js.map +1 -0
  64. package/dist/{parser-ZFXVZZKQ.cjs → parser-WNDH2X6N.cjs} +397 -284
  65. package/dist/parser-WNDH2X6N.cjs.map +1 -0
  66. package/dist/pdf-ocr-IOUZTPPH.cjs +31 -0
  67. package/dist/{pdf-ocr-QWTGWYQT.cjs.map → pdf-ocr-IOUZTPPH.cjs.map} +1 -1
  68. package/dist/{pdf-ocr-BYT7XVID.js → pdf-ocr-X5XLGL5J.js} +6 -6
  69. package/dist/{pdf-ocr-DRQN5BXA.js → pdf-ocr-ZP2CUWSO.js} +9 -9
  70. package/dist/{profile-io-3QYTSPNH.js → profile-io-B4VSI4LW.js} +3 -3
  71. package/dist/{rasterize-LPLWCBXV.js → rasterize-Y7NVUVXU.js} +3 -3
  72. package/dist/{redact-doc-HDA6ZG3N.js → redact-doc-GIBTFWCO.js} +11 -11
  73. package/dist/{render-MYZGD3SB.js → render-JVCGYRRO.js} +7 -7
  74. package/dist/seal-WNX2ZJTK.js +10 -0
  75. package/dist/{setup-EF5TQVAI.js → setup-7L7EQPMG.js} +3 -3
  76. package/dist/visual-VPWPXIHN.js +21 -0
  77. package/dist/{watch-PM5PRSFW.js → watch-VYMFGX72.js} +12 -12
  78. package/package.json +1 -1
  79. package/dist/chunk-4X7AR4EH.cjs.map +0 -1
  80. package/dist/chunk-C5J5LDWM.js.map +0 -1
  81. package/dist/chunk-EVL6HZQL.js.map +0 -1
  82. package/dist/chunk-HN3QMHTT.js.map +0 -1
  83. package/dist/chunk-WCTC3LSV.js.map +0 -1
  84. package/dist/chunks-3N7OFSA4.js +0 -10
  85. package/dist/parser-DR6ZHYEB.js.map +0 -1
  86. package/dist/parser-ER3VLB37.js.map +0 -1
  87. package/dist/parser-ZFXVZZKQ.cjs.map +0 -1
  88. package/dist/pdf-ocr-QWTGWYQT.cjs +0 -31
  89. package/dist/seal-XA5V6A6V.js +0 -10
  90. package/dist/visual-DB7NJOID.js +0 -21
  91. /package/dist/{-HAK3YFWW.js.map → -WFRWBH7T.js.map} +0 -0
  92. /package/dist/{chunk-F3AWNFMO.js.map → chunk-2L3Q7REU.js.map} +0 -0
  93. /package/dist/{chunk-CWBH66IQ.js.map → chunk-35ZHXEJA.js.map} +0 -0
  94. /package/dist/{chunk-Q6SVCBMK.js.map → chunk-3BR7VKWL.js.map} +0 -0
  95. /package/dist/{chunk-G2325K2F.js.map → chunk-3G3TLZDK.js.map} +0 -0
  96. /package/dist/{chunk-36DK6AOX.js.map → chunk-3YEL7P4L.js.map} +0 -0
  97. /package/dist/{chunk-5ARHF54C.js.map → chunk-4TWN7PWJ.js.map} +0 -0
  98. /package/dist/{chunk-3TUJ34V7.js.map → chunk-63N6CEJE.js.map} +0 -0
  99. /package/dist/{chunk-DEFT7Z3B.js.map → chunk-6MCC2XNB.js.map} +0 -0
  100. /package/dist/{chunk-AYV5VRHL.js.map → chunk-C3REGEQO.js.map} +0 -0
  101. /package/dist/{chunk-A3SKXHAN.js.map → chunk-CO7O3ZT6.js.map} +0 -0
  102. /package/dist/{chunk-WNW77CAY.js.map → chunk-CRSTBATY.js.map} +0 -0
  103. /package/dist/{chunk-MYTMZSQO.js.map → chunk-CW67DAAH.js.map} +0 -0
  104. /package/dist/{chunk-RPSILMQY.js.map → chunk-DN55FTJP.js.map} +0 -0
  105. /package/dist/{chunk-LVVSMYG4.js.map → chunk-LE4VHWIT.js.map} +0 -0
  106. /package/dist/{chunk-G4KNI7EO.js.map → chunk-PSORL4PA.js.map} +0 -0
  107. /package/dist/{chunk-FAFSBCU2.js.map → chunk-RYKDIUHT.js.map} +0 -0
  108. /package/dist/{chunk-SSL3TKJY.js.map → chunk-SETAYS6P.js.map} +0 -0
  109. /package/dist/{chunk-Q65HT2BL.js.map → chunk-T7OZ7X6A.js.map} +0 -0
  110. /package/dist/{chunk-UJVVL6BI.js.map → chunk-TOUJCO2P.js.map} +0 -0
  111. /package/dist/{chunks-3N7OFSA4.js.map → chunks-NXABWR6G.js.map} +0 -0
  112. /package/dist/{formula-PWAUR5PF.js.map → formula-FSVHUQ6Y.js.map} +0 -0
  113. /package/dist/{formula-KSTY73DQ.js.map → formula-L625ULJP.js.map} +0 -0
  114. /package/dist/{image-ocr-RASJHOAK.js.map → image-ocr-KE3RUS3R.js.map} +0 -0
  115. /package/dist/{image-ocr-RPBPO3VT.js.map → image-ocr-QTZNBP5V.js.map} +0 -0
  116. /package/dist/{model-bundle-ZPQ4IFT7.js.map → model-bundle-F6TU6ZAV.js.map} +0 -0
  117. /package/dist/{models-YJQ5VHOR.js.map → models-ZHNNVH2W.js.map} +0 -0
  118. /package/dist/{parse-worker-v2-7PNZYASF.js.map → parse-worker-v2-KQRG3NQO.js.map} +0 -0
  119. /package/dist/{pdf-ocr-BYT7XVID.js.map → pdf-ocr-X5XLGL5J.js.map} +0 -0
  120. /package/dist/{pdf-ocr-DRQN5BXA.js.map → pdf-ocr-ZP2CUWSO.js.map} +0 -0
  121. /package/dist/{profile-io-3QYTSPNH.js.map → profile-io-B4VSI4LW.js.map} +0 -0
  122. /package/dist/{rasterize-LPLWCBXV.js.map → rasterize-Y7NVUVXU.js.map} +0 -0
  123. /package/dist/{redact-doc-HDA6ZG3N.js.map → redact-doc-GIBTFWCO.js.map} +0 -0
  124. /package/dist/{render-MYZGD3SB.js.map → render-JVCGYRRO.js.map} +0 -0
  125. /package/dist/{seal-XA5V6A6V.js.map → seal-WNX2ZJTK.js.map} +0 -0
  126. /package/dist/{setup-EF5TQVAI.js.map → setup-7L7EQPMG.js.map} +0 -0
  127. /package/dist/{visual-DB7NJOID.js.map → visual-VPWPXIHN.js.map} +0 -0
  128. /package/dist/{watch-PM5PRSFW.js.map → watch-VYMFGX72.js.map} +0 -0
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  loadSharp,
4
4
  rasterizePageSvg
5
- } from "./chunk-RPSILMQY.js";
5
+ } from "./chunk-DN55FTJP.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-AYV5VRHL.js";
19
+ } from "./chunk-C3REGEQO.js";
20
20
  import {
21
21
  MAX_COLS,
22
22
  MAX_ROWS,
@@ -27,7 +27,7 @@ import {
27
27
  flattenLayoutTables,
28
28
  mapPuaText,
29
29
  markNonLayoutTable
30
- } from "./chunk-Q6SVCBMK.js";
30
+ } from "./chunk-3BR7VKWL.js";
31
31
  import {
32
32
  DEFAULT_CHAR,
33
33
  DEFAULT_PARA_GEOM,
@@ -41,7 +41,7 @@ import {
41
41
  hwpxAppMajor,
42
42
  parseRenderStyles,
43
43
  readZipEntry
44
- } from "./chunk-WCTC3LSV.js";
44
+ } from "./chunk-52HIK4C2.js";
45
45
  import {
46
46
  KordocError,
47
47
  compareSectionPaths,
@@ -49,7 +49,7 @@ import {
49
49
  precheckZipSize,
50
50
  sanitizeHref,
51
51
  toArrayBuffer
52
- } from "./chunk-5ARHF54C.js";
52
+ } from "./chunk-4TWN7PWJ.js";
53
53
 
54
54
  // src/render/svg-render.ts
55
55
  import JSZip from "jszip";
@@ -10426,14 +10426,14 @@ function fontHasGlyph(face, cp) {
10426
10426
  if (!hasFontMetrics(face)) return false;
10427
10427
  return cp >= 32 && cp <= 126 || FONTS[face.trim()].ex[cp] !== void 0;
10428
10428
  }
10429
- var HANCOM_FALLBACK_W = { 8228: 173, 8231: 173, 8211: 430, 8680: 1e3, 8728: 500, 8227: 465, 12295: 1e3 };
10429
+ var HANCOM_FALLBACK_W = { 8228: 173, 8231: 173, 8211: 430, 8680: 1e3, 8728: 500, 8227: 465, 12295: 1e3, 61607: 937 / 2048 * 1e3, 61599: 937 / 2048 * 1e3, 61550: 1529 / 2048 * 1e3 };
10430
10430
  function isHanja(cp) {
10431
10431
  return cp >= 19968 && cp <= 40959 || cp >= 13312 && cp <= 19903 || cp >= 63744 && cp <= 64255;
10432
10432
  }
10433
- function fontWidthFn(face) {
10433
+ function fontWidthFn(face, fallback = true) {
10434
10434
  if (!hasFontMetrics(face)) return null;
10435
10435
  const m = FONTS[face.trim()];
10436
- return (cp) => cp >= 32 && cp <= 126 ? m.ascii[cp - 32] : m.ex[cp] ?? (HANCOM_FALLBACK_W[cp] ?? (isHalfwidthForm(cp) ? 500 : m.han !== void 0 && isHanja(cp) ? m.han : m.cjk));
10436
+ return (cp) => cp >= 32 && cp <= 126 ? m.ascii[cp - 32] : m.ex[cp] ?? ((fallback ? HANCOM_FALLBACK_W[cp] : void 0) ?? (isHalfwidthForm(cp) ? 500 : m.han !== void 0 && isHanja(cp) ? m.han : m.cjk));
10437
10437
  }
10438
10438
  function isHalfwidthForm(cp) {
10439
10439
  return cp >= 65377 && cp <= 65500 || cp >= 65512 && cp <= 65518;
@@ -10657,20 +10657,20 @@ function fixedPitchWidthEm1000(cp) {
10657
10657
  return cp < 128 || isHalfwidthForm(cp) ? 500 : 1e3;
10658
10658
  }
10659
10659
  var PUA_FULL = /* @__PURE__ */ new Set([983729, 983730, 983731, 983732, 983733, 983734, 983803]);
10660
- function widthFnOf(faceClass) {
10661
- const base = baseWidthFnOf(faceClass);
10660
+ function widthFnOf(faceClass, fallback = true) {
10661
+ const base = baseWidthFnOf(faceClass, fallback);
10662
10662
  const hcr = faceClass === "hcr" || faceClass === "font:\uD568\uCD08\uB86C\uB3CB\uC6C0" || faceClass === "font:\uD568\uCD08\uB86C\uBC14\uD0D5";
10663
10663
  const f = (cp) => cp >= 983040 ? PUA_FULL.has(cp) ? 1e3 : 500 : cp === 61600 ? base(32) : !hcr && cp >= 10102 && cp <= 10131 ? 1e3 : base(cp);
10664
- if (faceClass === "fixedPitch" || faceClass === "cjk") return (cp) => isZeroWidthCp(cp) ? 0 : HANCOM_FALLBACK_W[cp] ?? f(cp);
10664
+ if (fallback && (faceClass === "fixedPitch" || faceClass === "cjk")) return (cp) => isZeroWidthCp(cp) ? 0 : HANCOM_FALLBACK_W[cp] ?? f(cp);
10665
10665
  return (cp) => isZeroWidthCp(cp) ? 0 : f(cp);
10666
10666
  }
10667
- function baseWidthFnOf(faceClass) {
10667
+ function baseWidthFnOf(faceClass, fallback = true) {
10668
10668
  if (faceClass === "fixedPitch") return fixedPitchWidthEm1000;
10669
10669
  if (faceClass === "gothic") return (cp) => isHalfwidthForm(cp) ? 500 : gothicWidthEm1000(cp);
10670
10670
  if (faceClass === "cjk") return cjkWidthEm1000;
10671
10671
  if (faceClass?.startsWith("font:")) {
10672
10672
  const face = faceClass.slice(5);
10673
- return fontWidthFn(face) ?? gothicWidthEm1000;
10673
+ return fontWidthFn(face, fallback) ?? gothicWidthEm1000;
10674
10674
  }
10675
10675
  return charWidthEm1000;
10676
10676
  }
@@ -10693,7 +10693,7 @@ function mulDiv(a, b, c) {
10693
10693
  const e = a * b;
10694
10694
  return Math.trunc(e < 0 ? (e - c / 2) / c : (e + c / 2) / c);
10695
10695
  }
10696
- function hancomCharWidth(ch, height, ratioPct, spacingPct, faceClass, emAdd = 0) {
10696
+ function hancomCharWidth(ch, height, ratioPct, spacingPct, faceClass, emAdd = 0, fallback = true) {
10697
10697
  const cp = ch.codePointAt(0);
10698
10698
  let w;
10699
10699
  if (cp === 8197) {
@@ -10702,7 +10702,7 @@ function hancomCharWidth(ch, height, ratioPct, spacingPct, faceClass, emAdd = 0)
10702
10702
  } else if (isSpaceCp(cp)) {
10703
10703
  const s = Math.trunc(height / 8);
10704
10704
  w = 4 * (ratioPct === 100 ? s : mulDiv(s, ratioPct, 100));
10705
- } else return hancomEmWidth(widthFnOf(faceClass)(cp) + emAdd, height, ratioPct, spacingPct);
10705
+ } else return hancomEmWidth(widthFnOf(faceClass, fallback)(cp) + emAdd, height, ratioPct, spacingPct);
10706
10706
  if (spacingPct) w += 4 * mulDiv(Math.trunc(w / 4), spacingPct, 100);
10707
10707
  return w;
10708
10708
  }
@@ -11169,7 +11169,8 @@ function pushTextSlots(t, chars, prId, depth, del = { deleted: 0 }) {
11169
11169
  } else if (tag === "tab") {
11170
11170
  if (del.deleted) pushFillers(chars, 8, prId);
11171
11171
  else {
11172
- chars.push({ ch: "", prId, tab: true, tabW: num(el, "width"), ...el.getAttribute("type") === "2" ? { tabRight: true } : {} });
11172
+ const width = num(el, "width", -1);
11173
+ chars.push({ ch: "", prId, tab: true, ...width >= 0 ? { tabW: width } : {}, ...el.getAttribute("type") === "2" ? { tabRight: true } : {} });
11173
11174
  pushFillers(chars, 7, prId);
11174
11175
  }
11175
11176
  } else if (tag === "titleMark") {
@@ -11308,10 +11309,13 @@ function captionExtra(el) {
11308
11309
  return c && (c.side === "TOP" || c.side === "BOTTOM") ? c.h + c.gap : 0;
11309
11310
  }
11310
11311
  var DEFAULT_TAB_HU = 4e3;
11311
- function tabAdvance(x, firstLine, geom, saved = 0) {
11312
+ function paraHeadAdvance(head, offsetHeight, width) {
11313
+ return width + (head.offsetPct ? Math.trunc(offsetHeight * head.offset / 100) : head.offset);
11314
+ }
11315
+ function tabAdvance(x, firstLine, geom, saved) {
11312
11316
  const hang = geom && geom.marginIntent < 0 ? -geom.marginIntent : 0;
11313
11317
  if (firstLine && geom?.autoTabLeft && hang > 0 && x < hang - 0.5) return hang - x;
11314
- if (saved > 0) return saved;
11318
+ if (saved != null && saved >= 0) return saved;
11315
11319
  return (Math.floor(x / DEFAULT_TAB_HU) + 1) * DEFAULT_TAB_HU - x;
11316
11320
  }
11317
11321
  function cellColumns(sub) {
@@ -11617,10 +11621,8 @@ function cellRowRemainder(cells, row, avail, from, record, bases, carries, style
11617
11621
  const end = Math.max(...lines.map((l) => l[1]));
11618
11622
  const k = lines.findIndex((l) => c.marginT + l[1] > avail - c.marginB);
11619
11623
  if (k < 0) {
11620
- if (carry > 0) {
11621
- placed = true;
11622
- rem = Math.max(rem, c.marginT + carry + c.marginB);
11623
- }
11624
+ placed = true;
11625
+ if (carry > 0) rem = Math.max(rem, c.marginT + carry + c.marginB);
11624
11626
  cuts.push([c.el, base + end + 1, base]);
11625
11627
  continue;
11626
11628
  }
@@ -11958,12 +11960,12 @@ var LINESEG_FLAGS = "393216";
11958
11960
  var BASELINE_RATIO = 0.85;
11959
11961
  var FONT_LINE_METRICS = [
11960
11962
  [/^맑은 고딕/, 2230 / 2048, 496 / 2048, true],
11961
- [/^(바탕|돋움|굴림|궁서)(체)?$|^HY/, 1758 / 2048, 290 / 2048],
11963
+ [/^(바탕|돋움|굴림|궁서)(체)?$|^한컴바탕$|^HY/, 1758 / 2048, 290 / 2048],
11962
11964
  [/^휴먼명조$/, 0.859, 0.195],
11963
11965
  [/^KoPub(World)?(돋움|바탕)체 Light$/, 0.85, 0.25]
11964
11966
  ];
11965
- function fontLineMetrics(face) {
11966
- if (!face) return void 0;
11967
+ function fontLineMetrics(face, hft) {
11968
+ if (!face || hft && face.trim() === "\uD55C\uCEF4\uBC14\uD0D5") return void 0;
11967
11969
  for (const [re, a, d, up] of FONT_LINE_METRICS) if (re.test(face.trim())) return [a, d, up];
11968
11970
  return void 0;
11969
11971
  }
@@ -12003,7 +12005,7 @@ function hancomLangOf(cp) {
12003
12005
  if (cp >= 57344 && cp < 63744 || cp >= 983040) return "hangul";
12004
12006
  return "symbol";
12005
12007
  }
12006
- function glyphWidth(ch, st) {
12008
+ function glyphWidth(ch, st, fallback = true) {
12007
12009
  const cp = ch.codePointAt(0);
12008
12010
  const space = cp === 32 || cp === 160;
12009
12011
  const lang = space ? "hangul" : hancomLangOf(cp);
@@ -12029,8 +12031,8 @@ function glyphWidth(ch, st) {
12029
12031
  const b0 = hancomEmWidth(oldEm + bAdd, h, ratio, 0), w0 = spacing ? hancomEmWidth(oldEm + bAdd, h, ratio, spacing) : b0;
12030
12032
  return { w: w0, sp: w0 - b0 };
12031
12033
  }
12032
- const base = hancomCharWidth(ch, h, ratio, 0, fc, bAdd);
12033
- const w = spacing ? hancomCharWidth(ch, h, ratio, spacing, fc, bAdd) : base;
12034
+ const base = hancomCharWidth(ch, h, ratio, 0, fc, bAdd, fallback);
12035
+ const w = spacing ? hancomCharWidth(ch, h, ratio, spacing, fc, bAdd, fallback) : base;
12034
12036
  return { w, sp: w - base };
12035
12037
  }
12036
12038
  function pitchFor(height, geom) {
@@ -12159,12 +12161,10 @@ function reflowPara(p, doc, styles, areaW, startV, mode, zones = [], nums = /* @
12159
12161
  const avail = Math.max(1440, Math.floor(areaW / 4) * 4 - marginL - geom.marginRight);
12160
12162
  const firstWidth = avail;
12161
12163
  const bu = geom.bullet ?? (numText && geom.number ? { ch: numText, ...geom.number } : void 0);
12164
+ const bst = (bu?.charPrId != null ? styles.charPr.get(bu.charPrId) : void 0) ?? domChar;
12162
12165
  let headW = 0;
12163
- if (bu) {
12164
- const bst = (bu.charPrId != null ? styles.charPr.get(bu.charPrId) : void 0) ?? domChar;
12165
- for (const ch of bu.ch) headW += glyphWidth(ch, bst).w;
12166
- }
12167
- const bulletW = bu ? headW + (bu.offsetPct ? Math.trunc(height * bu.offset / 100) : bu.offset) : 0;
12166
+ if (bu) for (const ch of bu.ch) headW += glyphWidth(ch, bst, bu.useInstWidth !== false).w;
12167
+ const bulletW = bu ? paraHeadAdvance(bu, height, headW) : 0;
12168
12168
  const contBullet = bu?.autoIndent ? bulletW : 0;
12169
12169
  const squeeze = p.parentNode?.getAttribute?.("lineWrap") === "SQUEEZE" || !!geom.squeeze;
12170
12170
  const NO_WRAP = 1e9;
@@ -12402,7 +12402,8 @@ function reflowPara(p, doc, styles, areaW, startV, mode, zones = [], nums = /* @
12402
12402
  const st = c.prId != null ? styles.charPr.get(c.prId) : void 0;
12403
12403
  if (!st) continue;
12404
12404
  const cp = c.ch.codePointAt(0);
12405
- const fm = fontLineMetrics(c.ch !== " " && st.latin && isLatinCp(cp) ? st.latin.face : st.face);
12405
+ const font = c.ch !== " " && st.latin && isLatinCp(cp) ? st.latin : st;
12406
+ const fm = fontLineMetrics(font.face, font.hft);
12406
12407
  any = true;
12407
12408
  h = Math.max(h, fm ? Math.round(st.height * fm[0]) + (fm[2] ? Math.round : Math.trunc)(st.height * fm[1]) : st.height);
12408
12409
  b = Math.max(b, fm ? Math.round(st.height * fm[0]) : Math.round(st.height * BASELINE_RATIO));
@@ -12436,7 +12437,9 @@ function reflowPara(p, doc, styles, areaW, startV, mode, zones = [], nums = /* @
12436
12437
  }
12437
12438
  }
12438
12439
  const vertpos = v;
12439
- const occupiedH = Math.max(lineH, collisionHeights[li] ?? 0);
12440
+ const nextStart = textposOf[li + 1], nextChar = m.chars[nextStart];
12441
+ const boundaryH = !m.objs.length && !geom.fontLineHeight && nextChar?.ch.trim() && m.runs.some((r) => r.at === nextStart && r.prId === nextChar.prId) ? heightOf(nextChar.prId) : 0;
12442
+ const occupiedH = Math.max(lineH, collisionHeights[li] ?? 0, boundaryH);
12440
12443
  v += lineH + spacing;
12441
12444
  const isFirst = li === 0;
12442
12445
  const seg = doc.createElement("hp:lineseg");
@@ -12922,1314 +12925,1314 @@ function flowEndNotes(root, bodyH) {
12922
12925
  });
12923
12926
  }
12924
12927
 
12925
- // src/render/equation-text.ts
12926
- var SYMBOLS = {
12927
- alpha: "\u03B1",
12928
- beta: "\u03B2",
12929
- gamma: "\u03B3",
12930
- delta: "\u03B4",
12931
- epsilon: "\u03B5",
12932
- varepsilon: "\u03B5",
12933
- zeta: "\u03B6",
12934
- eta: "\u03B7",
12935
- theta: "\u03B8",
12936
- vartheta: "\u03D1",
12937
- iota: "\u03B9",
12938
- kappa: "\u03BA",
12939
- lambda: "\u03BB",
12940
- mu: "\u03BC",
12941
- nu: "\u03BD",
12942
- xi: "\u03BE",
12943
- pi: "\u03C0",
12944
- rho: "\u03C1",
12945
- sigma: "\u03C3",
12946
- tau: "\u03C4",
12947
- upsilon: "\u03C5",
12948
- phi: "\u03C6",
12949
- varphi: "\u03C6",
12950
- chi: "\u03C7",
12951
- psi: "\u03C8",
12952
- omega: "\u03C9",
12953
- Gamma: "\u0393",
12954
- Delta: "\u0394",
12955
- Theta: "\u0398",
12956
- Lambda: "\u039B",
12957
- Xi: "\u039E",
12958
- Pi: "\u03A0",
12959
- Sigma: "\u03A3",
12960
- Phi: "\u03A6",
12961
- Psi: "\u03A8",
12962
- Omega: "\u03A9",
12963
- times: "\xD7",
12964
- cdot: "\xB7",
12965
- div: "\xF7",
12966
- pm: "\xB1",
12967
- mp: "\u2213",
12968
- le: "\u2264",
12969
- leq: "\u2264",
12970
- ge: "\u2265",
12971
- geq: "\u2265",
12972
- ne: "\u2260",
12973
- neq: "\u2260",
12974
- approx: "\u2248",
12975
- equiv: "\u2261",
12976
- sim: "\u223C",
12977
- infty: "\u221E",
12978
- rightarrow: "\u2192",
12979
- leftarrow: "\u2190",
12980
- Rightarrow: "\u21D2",
12981
- Leftarrow: "\u21D0",
12982
- leftrightarrow: "\u2194",
12983
- Leftrightarrow: "\u21D4",
12984
- to: "\u2192",
12985
- angle: "\u2220",
12986
- triangle: "\u25B3",
12987
- perp: "\u22A5",
12988
- parallel: "\u2225",
12989
- circ: "\u2218",
12990
- degree: "\xB0",
12991
- sum: "\u03A3",
12992
- prod: "\u03A0",
12993
- int: "\u222B",
12994
- oint: "\u222E",
12995
- partial: "\u2202",
12996
- nabla: "\u2207",
12997
- in: "\u2208",
12998
- notin: "\u2209",
12999
- subset: "\u2282",
13000
- supset: "\u2283",
13001
- subseteq: "\u2286",
13002
- supseteq: "\u2287",
13003
- cup: "\u222A",
13004
- cap: "\u2229",
13005
- emptyset: "\u2205",
13006
- forall: "\u2200",
13007
- exists: "\u2203",
13008
- therefore: "\u2234",
13009
- because: "\u2235",
13010
- prime: "\u2032",
13011
- cdots: "\u22EF",
13012
- ldots: "\u2026",
13013
- dots: "\u2026",
13014
- vdots: "\u22EE",
13015
- lim: "lim",
13016
- log: "log",
13017
- ln: "ln",
13018
- sin: "sin",
13019
- cos: "cos",
13020
- tan: "tan",
13021
- sec: "sec",
13022
- csc: "csc",
13023
- cot: "cot",
13024
- exp: "exp",
13025
- max: "max",
13026
- min: "min",
13027
- quad: " ",
13028
- qquad: " ",
13029
- ",": " ",
13030
- ";": " ",
13031
- "!": "",
13032
- "{": "{",
13033
- "}": "}",
13034
- "|": "\u2016",
13035
- backslash: "\\",
13036
- lbrace: "{",
13037
- rbrace: "}",
13038
- langle: "\u27E8",
13039
- rangle: "\u27E9"
12928
+ // src/render/scene.ts
12929
+ function regionId(type, seq) {
12930
+ return `${type}-${String(seq).padStart(6, "0")}`;
12931
+ }
12932
+ function unionBBox(a, b) {
12933
+ const x = Math.min(a.x, b.x), y = Math.min(a.y, b.y);
12934
+ return { page: a.page, x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
12935
+ }
12936
+ var RegionCollector = class {
12937
+ regions = [];
12938
+ counters = /* @__PURE__ */ new Map();
12939
+ add(type, bbox, extra = {}) {
12940
+ const seq = (this.counters.get(type) ?? 0) + 1;
12941
+ this.counters.set(type, seq);
12942
+ const id = regionId(type, seq);
12943
+ const region = { id, type, page: bbox.page, regions: [bbox] };
12944
+ if (extra.sourceId) region.sourceId = extra.sourceId;
12945
+ if (extra.parentId) region.parentId = extra.parentId;
12946
+ this.regions.push(region);
12947
+ return id;
12948
+ }
12949
+ addFragment(id, bbox) {
12950
+ const r = this.regions.find((x) => x.id === id);
12951
+ if (!r) return;
12952
+ const same = r.regions.find((f) => f.page === bbox.page);
12953
+ if (same) Object.assign(same, unionBBox(same, bbox));
12954
+ else r.regions.push(bbox);
12955
+ }
13040
12956
  };
13041
- var SUP = { "0": "\u2070", "1": "\xB9", "2": "\xB2", "3": "\xB3", "4": "\u2074", "5": "\u2075", "6": "\u2076", "7": "\u2077", "8": "\u2078", "9": "\u2079", "+": "\u207A", "-": "\u207B", "=": "\u207C", "(": "\u207D", ")": "\u207E", n: "\u207F", i: "\u2071", x: "\u02E3", "\u2032": "\u2032" };
13042
- var SUB = { "0": "\u2080", "1": "\u2081", "2": "\u2082", "3": "\u2083", "4": "\u2084", "5": "\u2085", "6": "\u2086", "7": "\u2087", "8": "\u2088", "9": "\u2089", "+": "\u208A", "-": "\u208B", "=": "\u208C", "(": "\u208D", ")": "\u208E" };
13043
- function latexToPlain(latex) {
13044
- let i = 0;
13045
- const s = latex;
13046
- const skipWs = () => {
13047
- while (i < s.length && s[i] === " ") i++;
13048
- };
13049
- const arg = () => {
13050
- skipWs();
13051
- if (s[i] === "{") {
13052
- i++;
13053
- const v = seq("}");
13054
- i++;
13055
- return v;
13056
- }
13057
- return atom();
13058
- };
13059
- const wrap = (v) => v.length > 1 && !/^[\w.′]+$|^\(.*\)$/u.test(v) ? `(${v})` : v;
13060
- const script = (v, map, mark) => {
13061
- const t = v.trim();
13062
- return [...t].every((c) => map[c]) ? [...t].map((c) => map[c]).join("") : `${mark}${wrap(t)}`;
13063
- };
13064
- const atom = () => {
13065
- const c = s[i];
13066
- if (c === void 0) return "";
13067
- if (c === "\\") {
13068
- i++;
13069
- let name = "";
13070
- if (/[A-Za-z]/.test(s[i] ?? "")) while (/[A-Za-z]/.test(s[i] ?? "")) name += s[i++];
13071
- else name = s[i++] ?? "";
13072
- if (name === "frac") {
13073
- const a = arg(), b = arg();
13074
- return `${wrap(a.trim())}/${wrap(b.trim())}`;
13075
- }
13076
- if (name === "sqrt") {
13077
- skipWs();
13078
- let root = "";
13079
- if (s[i] === "[") {
13080
- i++;
13081
- root = seq("]");
13082
- i++;
12957
+
12958
+ // src/render/page-stories.ts
12959
+ function pageStories(root, masters, paraPages, pageCount, pageBase, geom) {
12960
+ const secPr = findFirst(root, "secPr"), visibility = secPr && findChildByLocalName(secPr, "visibility");
12961
+ const pagePr = secPr && findChildByLocalName(secPr, "pagePr"), margin = pagePr && findChildByLocalName(pagePr, "margin");
12962
+ const declarations = [];
12963
+ const hidden = /* @__PURE__ */ new Map();
12964
+ for (const p of elements(root)) if (ln(p) === "p") {
12965
+ const page = paraPages.get(p)?.[0] ?? 0;
12966
+ for (const run of elements(p)) if (ln(run) === "run") {
12967
+ for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
12968
+ for (const el of elements(ctrl)) {
12969
+ if (isDeletedControl(el)) continue;
12970
+ const kind = ln(el);
12971
+ if (kind === "header" || kind === "footer") declarations.push({ el, page, kind });
12972
+ else if (kind === "pageHiding") {
12973
+ const kinds = hidden.get(page) ?? /* @__PURE__ */ new Set();
12974
+ for (const name of ["Header", "Footer", "MasterPage"]) if (num(el, `hide${name}`)) kinds.add(name);
12975
+ hidden.set(page, kinds);
12976
+ }
13083
12977
  }
13084
- const a = arg();
13085
- return `${root ? script(root, SUP, "") : ""}\u221A${wrap(a.trim())}`;
13086
- }
13087
- if (name === "left" || name === "right" || name === "big" || name === "Big" || name === "bigg" || name === "Bigg") {
13088
- skipWs();
13089
- const d = s[i] === "\\" ? atom() : s[i++] ?? "";
13090
- return d === "." ? "" : d;
13091
- }
13092
- if (name === "overline" || name === "bar" || name === "hat" || name === "vec" || name === "dot" || name === "tilde") {
13093
- const a = arg().trim(), mark = { overline: "\u0305", bar: "\u0304", hat: "\u0302", vec: "\u20D7", dot: "\u0307", tilde: "\u0303" }[name];
13094
- return [...a].map((ch) => ch + mark).join("");
13095
12978
  }
13096
- if (name === "mathrm" || name === "text" || name === "rm" || name === "mathbf" || name === "it" || name === "mathit" || name === "operatorname") return name === "rm" || name === "it" ? "" : arg();
13097
- return SYMBOLS[name] ?? name;
13098
- }
13099
- i++;
13100
- if (c === "{") {
13101
- const v = seq("}");
13102
- i++;
13103
- return v;
13104
12979
  }
13105
- if (c === "^") return script(arg(), SUP, "^");
13106
- if (c === "_") return script(arg(), SUB, "_");
13107
- if (c === "~" || c === "`") return " ";
13108
- return c;
13109
- };
13110
- const seq = (end) => {
13111
- let out = "";
13112
- while (i < s.length && s[i] !== end) {
13113
- if (s[i] === " ") {
13114
- i++;
13115
- continue;
12980
+ }
12981
+ const parity = (type, n) => type === "BOTH" || type === "ODD" && n % 2 === 1 || type === "EVEN" && n % 2 === 0;
12982
+ const out = [];
12983
+ for (let page = 0; page < pageCount; page++) {
12984
+ const n = pageBase + page + 1;
12985
+ const hides = (name) => hidden.get(page)?.has(name) === true || page === 0 && num(visibility, `hideFirst${name}`) !== 0;
12986
+ if (!hides("MasterPage")) {
12987
+ const matching = masters.filter((m) => m.getAttribute("type") === (n % 2 ? "ODD" : "EVEN"));
12988
+ const both = masters.filter((m) => (m.getAttribute("type") || "BOTH") === "BOTH");
12989
+ const normal = (matching.length ? matching : both).slice(-1);
12990
+ const specific = masters.filter((m) => m.getAttribute("type") === "LAST_PAGE" ? page === pageCount - 1 : m.getAttribute("type") === "OPTIONAL_PAGE" && num(m, "pageNumber") === page + 1);
12991
+ const special = specific.slice(-1);
12992
+ const selected = special.length && !num(special[0], "pageDuplicate") ? special : [...normal, ...special];
12993
+ for (const master of selected) {
12994
+ const sub = findChildByLocalName(master, "subList");
12995
+ if (sub) out.push({ sub, page, x: geom.ML, y: geom.MT, width: geom.BODY_W, layer: num(master, "pageFront") ? 2 : -2 });
13116
12996
  }
13117
- out += atom();
13118
12997
  }
13119
- return out;
13120
- };
13121
- return seq("\0").replace(/\s+/g, " ").trim();
13122
- }
13123
-
13124
- // src/hwpx/equation.ts
13125
- var CONVERT_MAP = {
13126
- TIMES: "\\times",
13127
- times: "\\times",
13128
- LEFT: "\\left",
13129
- RIGHT: "\\right",
13130
- under: "\\underline",
13131
- SMALLSUM: "\\sum",
13132
- sum: "\\sum",
13133
- SMALLPROD: "\\prod",
13134
- prod: "\\prod",
13135
- SMALLINTER: "\\cap",
13136
- CUP: "\\cup",
13137
- OPLUS: "\\oplus",
13138
- OMINUS: "\\ominus",
13139
- OTIMES: "\\otimes",
13140
- ODIV: "\\oslash",
13141
- ODOT: "\\odot",
13142
- LOR: "\\lor",
13143
- LAND: "\\land",
13144
- SUBSET: "\\subset",
13145
- SUPERSET: "\\supset",
13146
- SUBSETEQ: "\\subseteq",
13147
- SUPSETEQ: "\\supseteq",
13148
- IN: "\\in",
13149
- OWNS: "\\owns",
13150
- NOTIN: "\\notin",
13151
- LEQ: "\\leq",
13152
- GEQ: "\\geq",
13153
- "<<": "\\ll",
13154
- ">>": "\\gg",
13155
- "<<<": "\\lll",
13156
- ">>>": "\\ggg",
13157
- PREC: "\\prec",
13158
- SUCC: "\\succ",
13159
- UPLUS: "\\uplus",
13160
- "\xB1": "\\pm",
13161
- "+-": "\\pm",
13162
- "-+": "\\mp",
13163
- "\xF7": "\\div",
13164
- cdot: "\\cdot",
13165
- CIRC: "\\circ",
13166
- BULLET: "\\bullet",
13167
- DEG: " ^\\circ",
13168
- AST: "\\ast",
13169
- STAR: "\\bigstar",
13170
- BIGCIRC: "\\bigcirc",
13171
- EMPTYSET: "\\emptyset",
13172
- THEREFORE: "\\therefore",
13173
- BECAUSE: "\\because",
13174
- EXIST: "\\exists",
13175
- // 한글 수식 편집기는 소문자 therefore·because 도 같은 기호로 그린다(#148) — 생성 쪽 정준형은 대문자(equation-generate COMMAND_MAP)
13176
- therefore: "\\therefore",
13177
- because: "\\because",
13178
- "!=": "\\neq",
13179
- SMCOPROD: "\\coprod",
13180
- coprod: "\\coprod",
13181
- SQCAP: "\\sqcap",
13182
- SQCUP: "\\sqcup",
13183
- SQSUBSET: "\\sqsubset",
13184
- SQSUBSETEQ: "\\sqsubseteq",
13185
- BIGSQCUP: "\\bigsqcup",
13186
- BIGOPLUS: "\\bigoplus",
13187
- BIGOTIMES: "\\bigotimes",
13188
- BIGODOT: "\\bigodot",
13189
- BIGUPLUS: "\\biguplus",
13190
- inter: "\\bigcap",
13191
- union: "\\bigcup",
13192
- BIGOMINUS: "{\\Large\\ominus}",
13193
- BIGODIV: "{\\Large\\oslash}",
13194
- UNDEROVER: "",
13195
- SIM: "\\sim",
13196
- APPROX: "\\approx",
13197
- SIMEQ: "\\simeq",
13198
- CONG: "\\cong",
13199
- "==": "\\equiv",
13200
- DIAMOND: "\\diamond",
13201
- FORALL: "\\forall",
13202
- prime: "'",
13203
- Partial: "\\partial",
13204
- INF: "\\infty",
13205
- PROPTO: "\\propto",
13206
- lim: "\\lim",
13207
- Lim: "\\lim",
13208
- larrow: "\\leftarrow",
13209
- "->": "\\rightarrow",
13210
- uparrow: "\\uparrow",
13211
- downarrow: "\\downarrow",
13212
- LARROW: "\\Leftarrow",
13213
- RARROW: "\\Rightarrow",
13214
- UPARROW: "\\Uparrow",
13215
- DOWNARROW: "\\Downarrow",
13216
- udarrow: "\\updownarrow",
13217
- "<->": "\\leftrightarrow",
13218
- UDARROW: "\\Updownarrow",
13219
- LRARROW: "\\Leftrightarrow",
13220
- NWARROW: "\\nwarrow",
13221
- SEARROW: "\\searrow",
13222
- NEARROW: "\\nearrow",
13223
- SWARROW: "\\swarrow",
13224
- HOOKLEFT: "\\hookleftarrow",
13225
- HOOKRIGHT: "\\hookrightarrow",
13226
- PVER: "\\|",
13227
- MAPSTO: "\\mapsto",
13228
- CDOTS: "\\cdots",
13229
- LDOTS: "\\ldots",
13230
- VDOTS: "\\vdots",
13231
- DDOTS: "\\ddots",
13232
- DAGGER: "\\dagger",
13233
- DDAGGER: "\\ddagger",
13234
- DOTEQ: "\\doteq",
13235
- image: "\\fallingdotseq",
13236
- REIMAGE: "\\risingdotseq",
13237
- ASYMP: "\\asymp",
13238
- ISO: "\\Bumpeq",
13239
- DSUM: "\\dotplus",
13240
- XOR: "\\veebar",
13241
- TRIANGLE: "\\triangle",
13242
- NABLA: "\\nabla",
13243
- ANGLE: "\\angle",
13244
- MSANGLE: "\\measuredangle",
13245
- SANGLE: "\\sphericalangle",
13246
- VDASH: "\\vdash",
13247
- DASHV: "\\dashv",
13248
- BOT: "\\bot",
13249
- TOP: "\\top",
13250
- MODELS: "\\models",
13251
- LAPLACE: "\\mathcal{L}",
13252
- CENTIGRADE: "^{\\circ}C",
13253
- FAHRENHEIT: "^{\\circ}F",
13254
- LSLANT: "\\diagup",
13255
- RSLANT: "\\diagdown",
13256
- sqrt: "\\sqrt",
13257
- int: "\\int",
13258
- dint: "\\iint",
13259
- tint: "\\iiint",
13260
- oint: "\\oint",
13261
- alpha: "\\alpha",
13262
- beta: "\\beta",
13263
- gamma: "\\gamma",
13264
- delta: "\\delta",
13265
- epsilon: "\\epsilon",
13266
- zeta: "\\zeta",
13267
- eta: "\\eta",
13268
- theta: "\\theta",
13269
- iota: "\\iota",
13270
- kappa: "\\kappa",
13271
- lambda: "\\lambda",
13272
- mu: "\\mu",
13273
- nu: "\\nu",
13274
- xi: "\\xi",
13275
- omicron: "\\omicron",
13276
- pi: "\\pi",
13277
- rho: "\\rho",
13278
- sigma: "\\sigma",
13279
- tau: "\\tau",
13280
- upsilon: "\\upsilon",
13281
- phi: "\\phi",
13282
- chi: "\\chi",
13283
- psi: "\\psi",
13284
- omega: "\\omega",
13285
- ALPHA: "A",
13286
- BETA: "B",
13287
- GAMMA: "\\Gamma",
13288
- DELTA: "\\Delta",
13289
- EPSILON: "E",
13290
- ZETA: "Z",
13291
- ETA: "H",
13292
- THETA: "\\Theta",
13293
- IOTA: "I",
13294
- KAPPA: "K",
13295
- LAMBDA: "\\Lambda",
13296
- MU: "M",
13297
- NU: "N",
13298
- XI: "\\Xi",
13299
- OMICRON: "O",
13300
- PI: "\\Pi",
13301
- RHO: "P",
13302
- SIGMA: "\\Sigma",
13303
- TAU: "T",
13304
- UPSILON: "\\Upsilon",
13305
- PHI: "\\Phi",
13306
- CHI: "X",
13307
- PSI: "\\Psi",
13308
- OMEGA: "\\Omega",
13309
- "\u2308": "\\lceil",
13310
- "\u2309": "\\rceil",
13311
- "\u230A": "\\lfloor",
13312
- "\u230B": "\\rfloor",
13313
- "\u2225": "\\|",
13314
- "\u2290": "\\sqsupset",
13315
- "\u2292": "\\sqsupseteq",
13316
- odint: "\\mathop \u222F",
13317
- otint: "\\mathop \u2230",
13318
- BIGSQCAP: "\\mathop \u2A05",
13319
- ATT: "\\mathop \u203B",
13320
- HUND: "\\mathop \u2030",
13321
- THOU: "\\mathop \u2031",
13322
- IDENTICAL: "\\mathop \u2237",
13323
- RTANGLE: "\\mathop \u22BE",
13324
- BASE: "\\mathop \u2302",
13325
- BENZENE: "\\mathop \u232C"
13326
- };
13327
- var MIDDLE_CONVERT_MAP = {
13328
- matrix: "HULKMATRIX",
13329
- pmatrix: "HULKPMATRIX",
13330
- bmatrix: "HULKBMATRIX",
13331
- dmatrix: "HULKDMATRIX",
13332
- eqalign: "HULKEQALIGN",
13333
- cases: "HULKCASE",
13334
- vec: "HULKVEC",
13335
- dyad: "HULKDYAD",
13336
- acute: "HULKACUTE",
13337
- grave: "HULKGRAVE",
13338
- dot: "HULKDOT",
13339
- ddot: "HULKDDOT",
13340
- bar: "HULKBAR",
13341
- hat: "HULKHAT",
13342
- check: "HULKCHECK",
13343
- arch: "HULKARCH",
13344
- tilde: "HULKTILDE",
13345
- BOX: "HULKBOX",
13346
- OVERBRACE: "HULKOVERBRACE",
13347
- UNDERBRACE: "HULKUNDERBRACE"
13348
- };
13349
- var BAR_CONVERT_MAP = {
13350
- HULKVEC: "\\overrightarrow",
13351
- HULKDYAD: "\\overleftrightarrow",
13352
- HULKACUTE: "\\acute",
13353
- HULKGRAVE: "\\grave",
13354
- HULKDOT: "\\dot",
13355
- HULKDDOT: "\\ddot",
13356
- HULKBAR: "\\overline",
13357
- HULKHAT: "\\widehat",
13358
- HULKCHECK: "\\check",
13359
- HULKARCH: "\\overset{\\frown}",
13360
- HULKTILDE: "\\widetilde",
13361
- HULKBOX: "\\boxed"
13362
- };
13363
- var MATRIX_CONVERT_MAP = {
13364
- HULKMATRIX: { begin: "\\begin{matrix}", end: "\\end{matrix}", removeOutterBrackets: true },
13365
- HULKPMATRIX: { begin: "\\begin{pmatrix}", end: "\\end{pmatrix}", removeOutterBrackets: true },
13366
- HULKBMATRIX: { begin: "\\begin{bmatrix}", end: "\\end{bmatrix}", removeOutterBrackets: true },
13367
- HULKDMATRIX: { begin: "\\begin{vmatrix}", end: "\\end{vmatrix}", removeOutterBrackets: true },
13368
- HULKCASE: { begin: "\\begin{cases}", end: "\\end{cases}", removeOutterBrackets: true },
13369
- HULKEQALIGN: { begin: "\\eqalign{", end: "}", removeOutterBrackets: false }
13370
- };
13371
- var BRACE_CONVERT_MAP = {
13372
- HULKOVERBRACE: "\\overbrace",
13373
- HULKUNDERBRACE: "\\underbrace"
13374
- };
13375
- function findBrackets(eqString, startIdx) {
13376
- const startCur = eqString.indexOf("{", startIdx);
13377
- if (startCur === -1) throw new Error("cannot find bracket");
13378
- let bracketCount = 1;
13379
- for (let i = startCur + 1; i < eqString.length; i++) {
13380
- const ch = eqString[i];
13381
- if (ch === "{") bracketCount += 1;
13382
- else if (ch === "}") bracketCount -= 1;
13383
- if (bracketCount === 0) return [startCur, i + 1];
12998
+ for (const kind of ["header", "footer"]) {
12999
+ if (hides(kind === "header" ? "Header" : "Footer")) continue;
13000
+ const eligible = declarations.filter((d) => d.kind === kind && d.page <= page && parity(d.el.getAttribute("applyPageType") || "BOTH", n));
13001
+ const decl = eligible[eligible.length - 1];
13002
+ const sub = decl && findChildByLocalName(decl.el, "subList");
13003
+ 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 });
13004
+ }
13384
13005
  }
13385
- throw new Error("cannot find bracket");
13006
+ return out;
13386
13007
  }
13387
- function findEnclosingBrackets(eqString, startIdx) {
13388
- let depth = 0;
13389
- for (let idx = startIdx - 1; idx >= 0; idx--) {
13390
- const ch = eqString[idx];
13391
- if (ch === "}") {
13392
- depth += 1;
13393
- } else if (ch === "{") {
13394
- if (depth > 0) {
13395
- depth -= 1;
13396
- continue;
13397
- }
13398
- try {
13399
- const [start, end] = findBrackets(eqString, idx);
13400
- if (start === idx && end > startIdx) return [start, end];
13401
- } catch {
13402
- return null;
13008
+ function footNoteStories(root, paraPages, geom) {
13009
+ const pr = findFirst(root, "footNotePr");
13010
+ const sp = pr ? findChildByLocalName(pr, "noteSpacing") : null, line = pr ? findChildByLocalName(pr, "noteLine") : null;
13011
+ const above = num(sp, "aboveLine", 850), below = num(sp, "belowLine", 567), between = num(sp, "betweenNotes", 283);
13012
+ const byPage = /* @__PURE__ */ new Map();
13013
+ for (const p of elements(root)) if (ln(p) === "p") {
13014
+ const page = paraPages.get(p)?.[0] ?? 0;
13015
+ for (const run of elements(p)) if (ln(run) === "run") {
13016
+ for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
13017
+ const fn = findChildByLocalName(ctrl, "footNote");
13018
+ const sub = fn && !isDeletedControl(fn) ? findChildByLocalName(fn, "subList") : null;
13019
+ if (!sub) continue;
13020
+ let h = 0;
13021
+ for (const q of elements(sub)) if (ln(q) === "p") {
13022
+ const lsa = findChildByLocalName(q, "linesegarray");
13023
+ for (const seg of lsa ? elements(lsa) : []) if (ln(seg) === "lineseg") h = Math.max(h, num(seg, "vertpos") + num(seg, "vertsize"));
13024
+ }
13025
+ const list = byPage.get(page) ?? [];
13026
+ list.push({ sub, h });
13027
+ byPage.set(page, list);
13403
13028
  }
13404
- return null;
13405
13029
  }
13406
13030
  }
13407
- return null;
13408
- }
13409
- function maskLiteralSpans(eqString) {
13410
- return eqString.replace(/"[^"]*"/g, (m) => "\uFFFF".repeat(m.length)).replace(/\\text\{[^}]*\}/g, (m) => "\uFFFF".repeat(m.length));
13411
- }
13412
- function findKeywordToken(eqString, word, from = 0) {
13413
- const masked = maskLiteralSpans(eqString);
13414
- for (let i = masked.indexOf(word, from); i !== -1; i = masked.indexOf(word, i + 1)) {
13415
- const okL = i === 0 || /\s/.test(masked[i - 1]);
13416
- const okR = i + word.length === masked.length || /\s/.test(masked[i + word.length]);
13417
- if (okL && okR) return i;
13031
+ const stories = [], rules = [];
13032
+ const lenAttr = num(line, "length", -1), widthMm = Number.parseFloat(line?.getAttribute("width") ?? "0.12") || 0.12;
13033
+ const lineType = line?.getAttribute("type") ?? "SOLID";
13034
+ for (const [page, notes] of byPage) {
13035
+ const area = above + below + notes.reduce((a, n) => a + n.h, 0) + between * (notes.length - 1);
13036
+ const top = geom.MT + geom.BODY_H - area;
13037
+ if (lineType !== "NONE") rules.push({ page, x: geom.ML, y: top + above, length: lenAttr > 0 ? lenAttr : 14173, widthMm, color: line?.getAttribute("color") ?? "#000000" });
13038
+ let y = top + above + below;
13039
+ for (const n of notes) {
13040
+ stories.push({ sub: n.sub, page, x: geom.ML, y, width: geom.BODY_W });
13041
+ y += n.h + between;
13042
+ }
13418
13043
  }
13419
- return -1;
13044
+ return { stories, rules };
13420
13045
  }
13421
- function replaceFrac(eqString) {
13422
- const hmlFrac = "over";
13423
- const masked = maskLiteralSpans(eqString);
13046
+ function endNoteLayout(root, paraPages, geom) {
13047
+ const notes = [];
13048
+ let last = null;
13049
+ let endColPr = null;
13050
+ for (const p of elements(root)) if (ln(p) === "p") {
13051
+ const lsa = findChildByLocalName(p, "linesegarray"), segs = lsa ? elements(lsa).filter((e) => ln(e) === "lineseg") : [];
13052
+ const pages = paraPages.get(p) ?? [];
13053
+ if (segs.length) last = { seg: segs[segs.length - 1], page: pages[segs.length - 1] ?? pages[0] ?? 0 };
13054
+ for (const run of elements(p)) if (ln(run) === "run") {
13055
+ for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
13056
+ endColPr = findChildByLocalName(ctrl, "colPr") ?? endColPr;
13057
+ const en = findChildByLocalName(ctrl, "endNote");
13058
+ const sub = en && !isDeletedControl(en) ? findChildByLocalName(en, "subList") : null;
13059
+ if (sub) notes.push(sub);
13060
+ }
13061
+ }
13062
+ }
13063
+ if (!notes.length || !last) return null;
13064
+ const pr = findFirst(root, "endNotePr");
13065
+ const sp = pr ? findChildByLocalName(pr, "noteSpacing") : null, line = pr ? findChildByLocalName(pr, "noteLine") : null;
13066
+ const above = num(sp, "aboveLine", 0), below = num(sp, "belowLine", 567), between = num(sp, "betweenNotes", 283);
13067
+ const colPr = endColPr ?? findFirst(root, "colPr"), nCol = Math.max(1, num(colPr, "colCount", 1)), gap = nCol > 1 ? num(colPr, "sameGap", 0) : 0;
13068
+ const colW = (geom.BODY_W - gap * (nCol - 1)) / nCol;
13069
+ let page = last.page;
13070
+ let col = nCol > 1 ? Math.min(nCol - 1, Math.max(0, Math.round(num(last.seg, "horzpos") / (colW + gap)))) : 0;
13071
+ let y = num(last.seg, "vertpos") + num(last.seg, "vertsize") + above;
13072
+ const rules = [];
13073
+ const lenAttr = num(line, "length", -1), widthMm = Number.parseFloat(line?.getAttribute("width") ?? "0.12") || 0.12;
13074
+ if ((line?.getAttribute("type") ?? "SOLID") !== "NONE") rules.push({ page, x: geom.ML + col * (colW + gap), y: geom.MT + y, length: lenAttr > 0 ? lenAttr : 14173, widthMm, color: line?.getAttribute("color") ?? "#000000" });
13075
+ y += below;
13076
+ const next = () => {
13077
+ if (++col >= nCol) {
13078
+ col = 0;
13079
+ page++;
13080
+ }
13081
+ y = 0;
13082
+ };
13424
13083
  const out = [];
13425
- let pos = 0;
13426
- for (let cursor = masked.indexOf(hmlFrac); cursor !== -1; cursor = masked.indexOf(hmlFrac, cursor + 1)) {
13427
- const okL = cursor === 0 || /\s/.test(masked[cursor - 1]);
13428
- const okR = cursor + hmlFrac.length === masked.length || /\s/.test(masked[cursor + hmlFrac.length]);
13429
- if (!okL || !okR) continue;
13430
- for (; pos < cursor; pos++) out.push(eqString[pos]);
13431
- let end = out.length;
13432
- while (end > 0 && /\s/.test(out[end - 1])) end--;
13433
- let numStart = end;
13434
- if (end > 0 && out[end - 1] === "}") {
13435
- let depth = 0;
13436
- for (numStart = end - 1; numStart >= 0; numStart--) {
13437
- if (out[numStart] === "}") depth++;
13438
- else if (out[numStart] === "{" && --depth === 0) break;
13084
+ notes.forEach((sub, ni) => {
13085
+ if (ni > 0) y += between;
13086
+ let base = y;
13087
+ let prevRaw = Number.NEGATIVE_INFINITY, flowEnd = y;
13088
+ for (const q of elements(sub)) if (ln(q) === "p") {
13089
+ const lsa = findChildByLocalName(q, "linesegarray"), segs = lsa ? elements(lsa).filter((e) => ln(e) === "lineseg") : [];
13090
+ const pages = [];
13091
+ for (const seg of segs) {
13092
+ const raw = num(seg, "vertpos");
13093
+ if (raw < prevRaw) base = flowEnd - raw;
13094
+ prevRaw = raw;
13095
+ let v = base + raw;
13096
+ const vs = num(seg, "vertsize");
13097
+ if (v + vs > geom.BODY_H && v > 0) {
13098
+ const shift = v;
13099
+ next();
13100
+ base -= shift;
13101
+ v = 0;
13102
+ }
13103
+ seg.setAttribute("vertpos", String(v));
13104
+ seg.setAttribute("horzpos", String(num(seg, "horzpos") + col * (colW + gap)));
13105
+ pages.push(page);
13106
+ y = v + vs;
13107
+ flowEnd = y + num(seg, "spacing");
13439
13108
  }
13440
- if (numStart < 0) break;
13441
- out.length = end;
13442
- out.splice(numStart, 0, "\\frac");
13443
- } else {
13444
- while (numStart > 0 && !/\s/.test(out[numStart - 1])) numStart--;
13445
- if (numStart === end) break;
13446
- out.length = end;
13447
- out.splice(numStart, 0, "\\frac", "{");
13448
- out.push("}");
13109
+ out.push({ p: q, pages });
13110
+ }
13111
+ });
13112
+ return { paras: out, rules, pageCount: page + 1 };
13113
+ }
13114
+
13115
+ // src/render/table-pages.ts
13116
+ function stackedFloats(c) {
13117
+ const out = [];
13118
+ for (const p of c.sub ? elements(c.sub) : []) if (ln(p) === "p") {
13119
+ for (const run of elements(p)) if (ln(run) === "run") for (const o of elements(run)) {
13120
+ if (ln(o) !== "pic") continue;
13121
+ const pos = findChildByLocalName(o, "pos");
13122
+ if (!pos || pos.getAttribute("treatAsChar") === "1" || (pos.getAttribute("vertRelTo") ?? "PARA") !== "PARA" || pos.getAttribute("allowOverlap") !== "0") continue;
13123
+ const wrap = o.getAttribute("textWrap") ?? "TOP_AND_BOTTOM";
13124
+ if (wrap !== "SQUARE" && wrap !== "TOP_AND_BOTTOM") continue;
13125
+ const om = findChildByLocalName(o, "outMargin"), raw = num(pos, "vertOffset");
13126
+ out.push({ el: o, vo: Math.max(0, raw >= 2 ** 31 ? raw - 2 ** 32 : raw), h: num(findChildByLocalName(o, "sz"), "height") + num(om, "top") + num(om, "bottom"), omT: num(om, "top") });
13449
13127
  }
13450
- pos = cursor + hmlFrac.length;
13451
13128
  }
13452
- return out.join("") + eqString.slice(pos);
13129
+ return out;
13453
13130
  }
13454
- function replaceRootOf(eqString) {
13455
- while (true) {
13456
- const rootCursor = findKeywordToken(eqString, "root");
13457
- if (rootCursor === -1) break;
13458
- try {
13459
- const elem1 = findBrackets(eqString, rootCursor);
13460
- const ofCursor = findKeywordToken(eqString, "of", elem1[1]);
13461
- if (ofCursor === -1) return eqString;
13462
- const elem2 = findBrackets(eqString, ofCursor);
13463
- const e1 = eqString.slice(elem1[0] + 1, elem1[1] - 1);
13464
- const e2 = eqString.slice(elem2[0] + 1, elem2[1] - 1);
13465
- eqString = eqString.slice(0, rootCursor) + "\\sqrt[" + e1 + "]{" + e2 + "}" + eqString.slice(elem2[1] + 1);
13466
- } catch {
13467
- return eqString;
13131
+ function cellLineBoxes(c) {
13132
+ const out = [];
13133
+ let shift = 0, prevV = Number.NEGATIVE_INFINITY, prevEnd = 0, part = 0;
13134
+ const cols = cellColumns(c.sub);
13135
+ for (const p of c.sub ? elements(c.sub) : []) if (ln(p) === "p") {
13136
+ const lsa = findChildByLocalName(p, "linesegarray");
13137
+ for (const sg of lsa ? elements(lsa) : []) if (ln(sg) === "lineseg") {
13138
+ const v = num(sg, "vertpos");
13139
+ if (v < prevV && !cols) {
13140
+ shift = prevEnd - v;
13141
+ part++;
13142
+ }
13143
+ prevV = v;
13144
+ const top = v + shift, bottom = top + num(sg, "vertsize");
13145
+ prevEnd = bottom + num(sg, "spacing");
13146
+ out.push({ seg: sg, top, bottom, part, origin: shift });
13468
13147
  }
13469
13148
  }
13470
- return eqString;
13149
+ return out;
13471
13150
  }
13472
- function replaceAllMatrix(eqString) {
13473
- const replaceElements = (bracketStr) => {
13474
- let inner = bracketStr.slice(1, -1);
13475
- inner = inner.replace(/#/g, " \\\\ ");
13476
- inner = inner.replace(/&amp;/g, "&");
13477
- return inner;
13478
- };
13479
- const replaceMatrix = (input, matStr, matElem) => {
13480
- while (true) {
13481
- const cursor = input.indexOf(matStr);
13482
- if (cursor === -1) break;
13483
- try {
13484
- const [eStart, eEnd] = findBrackets(input, cursor);
13485
- const elem = replaceElements(input.slice(eStart, eEnd));
13486
- let beforeMat;
13487
- let afterMat;
13488
- const outer = matElem.removeOutterBrackets ? findEnclosingBrackets(input, cursor) : null;
13489
- if (outer && outer[1] >= eEnd) {
13490
- const [bStart, bEnd] = outer;
13491
- beforeMat = input.slice(0, bStart);
13492
- afterMat = input.slice(bEnd);
13493
- } else {
13494
- beforeMat = input.slice(0, cursor);
13495
- afterMat = input.slice(eEnd);
13151
+ function cellLines(c) {
13152
+ return cellLineBoxes(c).map((b) => [b.top, b.bottom]);
13153
+ }
13154
+ function planTableRows(tbl, cells, rowH, ty, MT, BODY_H, slack = 0, floatSpan, nested = false) {
13155
+ if (nested) slack = 0;
13156
+ const nRows = rowH.length;
13157
+ const rowY = [0];
13158
+ for (const h of rowH) rowY.push(rowY[rowY.length - 1] + h);
13159
+ const plain = () => rowH.map((h, r) => [{ page: 0, y: ty + rowY[r], h }]);
13160
+ const pageBottom = MT + BODY_H;
13161
+ const stackOver = tbl.getAttribute("pageBreak") === "CELL" && rowH.some((h, r) => {
13162
+ const rc = cells.filter((c) => c.ra === r && c.rs === 1);
13163
+ if (rc.length !== 1) return false;
13164
+ const st = stackedFloats(rc[0]);
13165
+ return st.length >= 2 && st.reduce((a, f) => a + f.h, 0) > h;
13166
+ });
13167
+ if (BODY_H <= 0 || ty + rowY[nRows] <= pageBottom + slack && !stackOver) return plain();
13168
+ if (findChildByLocalName(tbl, "pos")?.getAttribute("treatAsChar") === "1") {
13169
+ const declared = num(findChildByLocalName(tbl, "sz"), "height") || rowY[nRows];
13170
+ if (ty - MT < 2e3 || ty + declared <= pageBottom + slack) return plain();
13171
+ return rowH.map((h, r) => [{ page: 1, y: MT + rowY[r], h }]);
13172
+ }
13173
+ let hdrRows = 0;
13174
+ if (tbl.getAttribute("repeatHeader") === "1") while (hdrRows < nRows && cells.some((c) => c.ra === hdrRows) && cells.filter((c) => c.ra === hdrRows).every((c) => c.el.getAttribute("header") === "1")) hdrRows++;
13175
+ const contTop = MT + num(findChildByLocalName(tbl, "outMargin"), "top") + rowY[hdrRows];
13176
+ const cellSplit = tbl.getAttribute("pageBreak") === "CELL";
13177
+ const out = [];
13178
+ let page = 0, y = ty, first = true;
13179
+ for (let r = 0; r < nRows; r++) {
13180
+ let h = rowH[r];
13181
+ const pieces = [];
13182
+ const rowCells = cells.filter((c) => c.ra === r && c.rs === 1);
13183
+ const splittable = cellSplit && r >= hdrRows && rowCells.length > 0;
13184
+ const stack = splittable && rowCells.length === 1 ? stackedFloats(rowCells[0]) : [];
13185
+ if (stack.length >= 2) {
13186
+ const c = rowCells[0];
13187
+ let top = y, bottom = y + c.marginT, k = 0;
13188
+ const pcs = [];
13189
+ let place = /* @__PURE__ */ new Map();
13190
+ for (const f of stack) {
13191
+ let at = k === 0 ? top + c.marginT + f.vo : bottom;
13192
+ if (k > 0 && at + f.h > pageBottom - c.marginB) {
13193
+ pcs.push({ page, y: top, h: bottom - top + c.marginB, range: /* @__PURE__ */ new Map([[c.el, pcs.length ? [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY] : [0, Number.POSITIVE_INFINITY]]]), place });
13194
+ page++;
13195
+ top = contTop;
13196
+ place = /* @__PURE__ */ new Map();
13197
+ at = top + c.marginT;
13198
+ bottom = at;
13496
13199
  }
13497
- input = beforeMat + matElem.begin + elem + matElem.end + afterMat;
13498
- } catch {
13499
- return input;
13200
+ place.set(f.el, at + f.omT);
13201
+ bottom = Math.max(bottom, at + f.h);
13202
+ k++;
13203
+ }
13204
+ if (pcs.length) {
13205
+ pcs.push({ page, y: top, h: bottom - top + c.marginB, range: /* @__PURE__ */ new Map([[c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]]]), place });
13206
+ out.push(pcs);
13207
+ y = bottom + c.marginB;
13208
+ first = false;
13209
+ continue;
13210
+ }
13211
+ }
13212
+ const boxes = splittable ? new Map(rowCells.map((c) => [c.el, cellLineBoxes(c)])) : void 0;
13213
+ const hParts = boxes ? Math.max(0, ...[...boxes.values()].flatMap((bs) => bs.map((b) => b.part))) : 0;
13214
+ if (boxes && hParts > 0) {
13215
+ const declared = num(findChildByLocalName(tbl, "sz"), "height");
13216
+ const led = /* @__PURE__ */ new Set();
13217
+ for (let k = 0; k <= hParts; k++) {
13218
+ if (k > 0 && floatSpan) {
13219
+ let lead = 0, place;
13220
+ for (const c of rowCells) {
13221
+ const b = (boxes.get(c.el) ?? []).find((x) => x.part === k);
13222
+ if (!b) continue;
13223
+ const f = floatSpan(b.seg, y + c.marginT);
13224
+ if (f?.el && f.pages > 0 && f.pages > lead && Math.abs(contTop + c.marginT + b.top - b.origin - f.endY) < 3e3) {
13225
+ lead = f.pages;
13226
+ place = /* @__PURE__ */ new Map([[f.el, y + c.marginT]]);
13227
+ led.add(b.seg);
13228
+ }
13229
+ }
13230
+ if (lead > 0) {
13231
+ const none = new Map(rowCells.map((c) => [c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]]));
13232
+ for (let e = 0; e < lead; e++) pieces.push({ page: page + e, y: contTop, h: pageBottom - contTop, range: none, place: e === 0 ? place : void 0 });
13233
+ page += lead;
13234
+ }
13235
+ }
13236
+ const range = /* @__PURE__ */ new Map();
13237
+ let ext = 0, toNext = 0;
13238
+ for (const c of rowCells) {
13239
+ const bs = boxes.get(c.el) ?? [];
13240
+ const inK = bs.filter((b) => b.part === k), next = bs.find((b) => b.part > k);
13241
+ const from = inK[0]?.origin ?? next?.origin ?? Number.POSITIVE_INFINITY;
13242
+ range.set(c.el, [from, next?.top ?? Number.POSITIVE_INFINITY]);
13243
+ if (inK.length) ext = Math.max(ext, inK[inK.length - 1].bottom - from + c.marginT + c.marginB);
13244
+ if (inK.length && next) toNext = Math.max(toNext, next.top - from + c.marginT + c.marginB);
13245
+ }
13246
+ const last = k === hParts;
13247
+ const firstH = declared > 0 && ty + declared - y >= ext ? Math.min(pageBottom - y, ty + declared - y) : pageBottom - y;
13248
+ const ph = last ? ext : k === 0 ? firstH : toNext > 0 ? Math.min(pageBottom - contTop, toNext) : pageBottom - contTop;
13249
+ pieces.push({ page, y, h: ph, range });
13250
+ if (!last) {
13251
+ let span = 0, spanEnd = 0;
13252
+ if (floatSpan) for (const c of rowCells) {
13253
+ const bs = (boxes.get(c.el) ?? []).filter((b) => b.part === k), from = bs[0]?.origin ?? 0;
13254
+ for (const b of bs) {
13255
+ if (led.has(b.seg)) continue;
13256
+ const f = floatSpan(b.seg, y + c.marginT + b.top - from);
13257
+ if (f && f.pages > span) {
13258
+ span = f.pages;
13259
+ spanEnd = f.endY;
13260
+ }
13261
+ }
13262
+ }
13263
+ if (span > 0) {
13264
+ const nextTop = Math.min(...rowCells.map((c) => {
13265
+ const b = (boxes.get(c.el) ?? []).find((x) => x.part === k + 1);
13266
+ return b ? contTop + c.marginT + b.top - b.origin : Number.POSITIVE_INFINITY;
13267
+ }));
13268
+ const skip = nextTop < spanEnd - 100 ? span + 1 : span;
13269
+ for (let e = 1; e < skip; e++) pieces.push({ page: page + e, y: contTop, h: pageBottom - contTop, range: new Map(rowCells.map((c) => [c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]])) });
13270
+ page += skip;
13271
+ } else page++;
13272
+ y = contTop;
13273
+ first = true;
13274
+ } else h = ph;
13275
+ }
13276
+ out.push(pieces);
13277
+ y += h;
13278
+ first = false;
13279
+ continue;
13280
+ }
13281
+ if (splittable && y + h > pageBottom) {
13282
+ const from = /* @__PURE__ */ new Map();
13283
+ const lines = new Map(rowCells.map((c) => [c.el, cellLines(c)]));
13284
+ while (y + h > pageBottom && BODY_H > rowY[hdrRows]) {
13285
+ const avail = pageBottom - y;
13286
+ let rem = 0, placed = false, allFit = true, blocked = false;
13287
+ const cuts = [];
13288
+ for (const c of rowCells) {
13289
+ const off = from.get(c.el) ?? 0;
13290
+ const ls = (lines.get(c.el) ?? []).filter((l) => l[0] >= off);
13291
+ if (!ls.length) {
13292
+ cuts.push([c.el, off, off]);
13293
+ continue;
13294
+ }
13295
+ const end = Math.max(...ls.map((l) => l[1]));
13296
+ const k = ls.findIndex((l) => c.marginT + (l[1] - off) > avail - c.marginB);
13297
+ if (k < 0) {
13298
+ cuts.push([c.el, off, end + 1]);
13299
+ continue;
13300
+ }
13301
+ allFit = false;
13302
+ if (k > 0) placed = true;
13303
+ else if (off === 0) blocked = true;
13304
+ cuts.push([c.el, off, ls[k][0]]);
13305
+ rem = Math.max(rem, end - ls[k][0] + c.marginT + c.marginB);
13306
+ }
13307
+ if (allFit) {
13308
+ if (!first && h <= pageBottom - contTop && rowCells.some((c) => cellContentExtent(c) + c.marginT + c.marginB > avail)) {
13309
+ page++;
13310
+ y = contTop;
13311
+ first = true;
13312
+ break;
13313
+ }
13314
+ if (nested && avail > 0) {
13315
+ pieces.push({ page, y, h: avail, range: new Map(rowCells.map((c) => [c.el, [from.get(c.el) ?? 0, Number.POSITIVE_INFINITY]])) });
13316
+ for (const c of rowCells) from.set(c.el, Number.POSITIVE_INFINITY);
13317
+ page++;
13318
+ y = contTop;
13319
+ first = true;
13320
+ h -= avail;
13321
+ continue;
13322
+ }
13323
+ h = avail;
13324
+ break;
13325
+ }
13326
+ if (blocked && !first) {
13327
+ page++;
13328
+ y = contTop;
13329
+ first = true;
13330
+ continue;
13331
+ }
13332
+ if (!placed) {
13333
+ if (first) break;
13334
+ page++;
13335
+ y = contTop;
13336
+ first = true;
13337
+ continue;
13338
+ }
13339
+ pieces.push({ page, y, h: avail, range: new Map(cuts.map(([el, a, b]) => [el, [a, b]])) });
13340
+ for (const [el, , b] of cuts) from.set(el, b);
13341
+ page++;
13342
+ y = contTop;
13343
+ first = true;
13344
+ h = rem;
13500
13345
  }
13346
+ pieces.push({ page, y, h, range: new Map(rowCells.map((c) => [c.el, [from.get(c.el) ?? 0, Number.POSITIVE_INFINITY]])) });
13347
+ out.push(pieces);
13348
+ y += h;
13349
+ first = false;
13350
+ continue;
13501
13351
  }
13502
- return input;
13503
- };
13504
- for (const [matKey, matElem] of Object.entries(MATRIX_CONVERT_MAP)) {
13505
- eqString = replaceMatrix(eqString, matKey, matElem);
13506
- }
13507
- return eqString;
13508
- }
13509
- function replaceAllBar(eqString) {
13510
- const replaceBar = (input, barStr, barElem) => {
13511
- while (true) {
13512
- const cursor = input.indexOf(barStr);
13513
- if (cursor === -1) break;
13514
- try {
13515
- const [eStart, eEnd] = findBrackets(input, cursor);
13516
- const elem = input.slice(eStart, eEnd);
13517
- const outer = findEnclosingBrackets(input, cursor);
13518
- const [replaceStart, replaceEnd] = outer && outer[1] >= eEnd ? outer : [cursor, eEnd];
13519
- const beforeBar = input.slice(0, replaceStart);
13520
- const afterBar = input.slice(replaceEnd);
13521
- input = beforeBar + barElem + elem + afterBar;
13522
- } catch {
13523
- return input;
13524
- }
13352
+ if (!first && y + h > pageBottom && r >= hdrRows) {
13353
+ page++;
13354
+ y = contTop;
13355
+ first = true;
13525
13356
  }
13526
- return input;
13527
- };
13528
- for (const [barKey, barElem] of Object.entries(BAR_CONVERT_MAP)) {
13529
- eqString = replaceBar(eqString, barKey, barElem);
13357
+ out.push([{ page, y, h }]);
13358
+ y += h;
13359
+ first = false;
13530
13360
  }
13531
- return eqString;
13361
+ return out;
13532
13362
  }
13533
- function replaceAllBrace(eqString) {
13534
- const replaceBrace = (input, braceStr, braceElem) => {
13535
- while (true) {
13536
- const cursor = input.indexOf(braceStr);
13537
- if (cursor === -1) break;
13538
- try {
13539
- const [eStart1, eEnd1] = findBrackets(input, cursor);
13540
- const [eStart2, eEnd2] = findBrackets(input, eEnd1);
13541
- const elem1 = input.slice(eStart1, eEnd1);
13542
- const elem2 = input.slice(eStart2, eEnd2);
13543
- const beforeBrace = input.slice(0, cursor);
13544
- const afterBrace = input.slice(eEnd2);
13545
- input = beforeBrace + braceElem + elem1 + "^" + elem2 + afterBrace;
13546
- } catch {
13547
- return input;
13548
- }
13363
+
13364
+ // src/render/shape-geometry.ts
13365
+ var pt = (u) => String(Math.round(u) / 100);
13366
+ var esc = (s) => s.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
13367
+ var SHAPE_TAGS = /* @__PURE__ */ new Set(["rect", "ellipse", "line", "polygon", "curv", "curve", "arc"]);
13368
+ function rotatedBounds(box, rotations) {
13369
+ if (!rotations.length) return box;
13370
+ 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]];
13371
+ for (let i = rotations.length - 1; i >= 0; i--) {
13372
+ const r = rotations[i];
13373
+ if (Array.isArray(r)) {
13374
+ points = points.map(([x2, y2]) => [r[0] * x2 + r[2] * y2 + r[4], r[1] * x2 + r[3] * y2 + r[5]]);
13375
+ continue;
13549
13376
  }
13550
- return input;
13551
- };
13552
- for (const [braceKey, braceElem] of Object.entries(BRACE_CONVERT_MAP)) {
13553
- eqString = replaceBrace(eqString, braceKey, braceElem);
13377
+ const { angle, cx, cy } = r;
13378
+ const a = angle * Math.PI / 180, c = Math.cos(a), s = Math.sin(a);
13379
+ points = points.map(([x2, y2]) => [cx + c * (x2 - cx) - s * (y2 - cy), cy + s * (x2 - cx) + c * (y2 - cy)]);
13554
13380
  }
13555
- return eqString;
13381
+ const x = Math.min(...points.map((p) => p[0])), y = Math.min(...points.map((p) => p[1]));
13382
+ return { x, y, w: Math.max(...points.map((p) => p[0])) - x, h: Math.max(...points.map((p) => p[1])) - y };
13556
13383
  }
13557
- function replaceBracket(strList) {
13558
- for (let i = 0; i < strList.length; i++) {
13559
- if (strList[i] === "{" && i > 0 && strList[i - 1] === "\\left") strList[i] = "\\{";
13560
- if (strList[i] === "}" && i > 0 && strList[i - 1] === "\\right") strList[i] = "\\}";
13561
- }
13562
- return strList;
13384
+ function mulAffine(m, n) {
13385
+ return [
13386
+ m[0] * n[0] + m[2] * n[1],
13387
+ m[1] * n[0] + m[3] * n[1],
13388
+ m[0] * n[2] + m[2] * n[3],
13389
+ m[1] * n[2] + m[3] * n[3],
13390
+ m[0] * n[4] + m[2] * n[5] + m[4],
13391
+ m[1] * n[4] + m[3] * n[5] + m[5]
13392
+ ];
13563
13393
  }
13564
- function hmlToLatex(hmlEqStr) {
13565
- if (!hmlEqStr) return "";
13566
- let s = hmlEqStr.replace(/[\r\n\t]+/g, " ").replace(/`/g, " ");
13567
- s = s.replace(/\{/g, " { ").replace(/\}/g, " } ").replace(/&/g, " & ");
13568
- let tokens = s.split(" ");
13569
- for (let i = 0; i < tokens.length; i++) {
13570
- const t = tokens[i];
13571
- if (Object.hasOwn(CONVERT_MAP, t)) tokens[i] = CONVERT_MAP[t];
13572
- else if (Object.hasOwn(MIDDLE_CONVERT_MAP, t)) tokens[i] = MIDDLE_CONVERT_MAP[t];
13573
- else {
13574
- const quoted = /^"(.+)"$/.exec(t);
13575
- if (quoted) tokens[i] = `\\text{${quoted[1]}}`;
13576
- }
13394
+ function renderingMatrix(el) {
13395
+ const info = findChildByLocalName(el, "renderingInfo");
13396
+ if (!info) return null;
13397
+ let m = null;
13398
+ for (const c of elements(info)) {
13399
+ const tag = ln(c);
13400
+ if (tag !== "transMatrix" && tag !== "scaMatrix" && tag !== "rotMatrix") continue;
13401
+ const n = [num(c, "e1", 1), num(c, "e4"), num(c, "e2"), num(c, "e5", 1), num(c, "e3"), num(c, "e6")];
13402
+ m = m ? mulAffine(m, n) : n;
13577
13403
  }
13578
- tokens = tokens.filter((tok) => tok.length !== 0);
13579
- tokens = replaceBracket(tokens);
13580
- let out = tokens.join(" ");
13581
- out = replaceFrac(out);
13582
- out = replaceRootOf(out);
13583
- out = replaceAllMatrix(out);
13584
- out = replaceAllBar(out);
13585
- out = replaceAllBrace(out);
13586
- return out;
13587
- }
13588
-
13589
- // src/hwp5/equation.ts
13590
- var WORD_ALIASES = {
13591
- // 삼각/로그 함수 — 정본 맵 부재
13592
- sin: "\\sin",
13593
- cos: "\\cos",
13594
- tan: "\\tan",
13595
- sec: "\\sec",
13596
- csc: "\\csc",
13597
- cot: "\\cot",
13598
- log: "\\log",
13599
- ln: "\\ln",
13600
- // 연산자·관계 기호 (정본은 대문자 키만 보유)
13601
- divide: "\\div",
13602
- div: "\\div",
13603
- le: "\\leq",
13604
- ge: "\\geq",
13605
- geq: "\\geq",
13606
- deg: "^\\circ",
13607
- rarrow: "\\rightarrow",
13608
- lrarrow: "\\leftrightarrow",
13609
- rightarrow: "\\rightarrow",
13610
- leftarrow: "\\leftarrow",
13611
- in: "\\in",
13612
- notin: "\\notin",
13613
- emptyset: "\\emptyset",
13614
- subset: "\\subset",
13615
- nsubset: "\\nsubseteq",
13616
- cup: "\\cup",
13617
- cap: "\\cap",
13618
- smallinter: "\\cap",
13619
- smallsum: "\\sum",
13620
- sim: "\\sim",
13621
- circ: "\\circ",
13622
- bot: "\\perp",
13623
- partial: "\\partial",
13624
- nabla: "\\nabla",
13625
- angle: "\\angle",
13626
- triangle: "\\triangle",
13627
- inf: "\\infty",
13628
- left: "\\left",
13629
- right: "\\right",
13630
- // 글꼴 지시자 — 제거
13631
- rm: "",
13632
- it: ""
13633
- };
13634
- var STRUCTURAL_FOLD = /* @__PURE__ */ new Set(["over", "root", "of"]);
13635
- function normalizeWords(input) {
13636
- return input.replace(/(?<![\\A-Za-z0-9])([A-Za-z][A-Za-z0-9]*)(?![A-Za-z0-9])/g, (word) => {
13637
- if (Object.hasOwn(CONVERT_MAP, word) || Object.hasOwn(MIDDLE_CONVERT_MAP, word)) return word;
13638
- const lower = word.toLowerCase();
13639
- if (STRUCTURAL_FOLD.has(lower)) return lower;
13640
- if (Object.hasOwn(WORD_ALIASES, lower)) return WORD_ALIASES[lower];
13641
- if (lower !== word && (Object.hasOwn(CONVERT_MAP, lower) || Object.hasOwn(MIDDLE_CONVERT_MAP, lower))) return lower;
13642
- return word;
13643
- });
13644
- }
13645
- function normalizeScripts(input) {
13646
- return input.replace(/\s*\^\s*/g, "^").replace(/\s*_\s*/g, "_").replace(/\^(?!\{)([^\s{}_^]+)/g, "^{$1}").replace(/_(?!\{)([^\s{}_^]+)/g, "_{$1}").replace(/([_^])/g, " $1 ");
13647
- }
13648
- function normalizeOperators(input) {
13649
- return input.replace(/\+-/g, " \\pm ").replace(/-\+/g, " \\mp ").replace(/\/\//g, " \\parallel ").replace(/!=/g, " \\neq ").replace(/<=/g, " \\leq ").replace(/>=/g, " \\geq ").replace(/==/g, " \\equiv ").replace(/△/g, " \\triangle ").replace(/□/g, " \\square ").replace(/‧/g, " \\cdot ");
13650
- }
13651
- function hwpEquationToLatex(equation) {
13652
- let s = equation.replace(/\0/g, "").replace(/\s+/g, " ").trim();
13653
- if (!s) return "";
13654
- s = normalizeScripts(s);
13655
- s = normalizeOperators(s);
13656
- s = normalizeWords(s);
13657
- s = s.replace(/\broot\s+(?!\{)(\S+)\s+of(?![A-Za-z0-9])/gi, "root { $1 } of");
13658
- return hmlToLatex(s).replace(/\s+/g, " ").trim();
13659
- }
13660
-
13661
- // src/render/scene.ts
13662
- function regionId(type, seq) {
13663
- return `${type}-${String(seq).padStart(6, "0")}`;
13664
- }
13665
- function unionBBox(a, b) {
13666
- const x = Math.min(a.x, b.x), y = Math.min(a.y, b.y);
13667
- return { page: a.page, x, y, width: Math.max(a.x + a.width, b.x + b.width) - x, height: Math.max(a.y + a.height, b.y + b.height) - y };
13404
+ return m;
13668
13405
  }
13669
- var RegionCollector = class {
13670
- regions = [];
13671
- counters = /* @__PURE__ */ new Map();
13672
- add(type, bbox, extra = {}) {
13673
- const seq = (this.counters.get(type) ?? 0) + 1;
13674
- this.counters.set(type, seq);
13675
- const id = regionId(type, seq);
13676
- const region = { id, type, page: bbox.page, regions: [bbox] };
13677
- if (extra.sourceId) region.sourceId = extra.sourceId;
13678
- if (extra.parentId) region.parentId = extra.parentId;
13679
- this.regions.push(region);
13680
- return id;
13681
- }
13682
- addFragment(id, bbox) {
13683
- const r = this.regions.find((x) => x.id === id);
13684
- if (!r) return;
13685
- const same = r.regions.find((f) => f.page === bbox.page);
13686
- if (same) Object.assign(same, unionBBox(same, bbox));
13687
- else r.regions.push(bbox);
13688
- }
13689
- };
13690
-
13691
- // src/render/page-stories.ts
13692
- function pageStories(root, masters, paraPages, pageCount, pageBase, geom) {
13693
- const secPr = findFirst(root, "secPr"), visibility = secPr && findChildByLocalName(secPr, "visibility");
13694
- const pagePr = secPr && findChildByLocalName(secPr, "pagePr"), margin = pagePr && findChildByLocalName(pagePr, "margin");
13695
- const declarations = [];
13696
- const hidden = /* @__PURE__ */ new Map();
13697
- for (const p of elements(root)) if (ln(p) === "p") {
13698
- const page = paraPages.get(p)?.[0] ?? 0;
13699
- for (const run of elements(p)) if (ln(run) === "run") {
13700
- for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
13701
- for (const el of elements(ctrl)) {
13702
- if (isDeletedControl(el)) continue;
13703
- const kind = ln(el);
13704
- if (kind === "header" || kind === "footer") declarations.push({ el, page, kind });
13705
- else if (kind === "pageHiding") {
13706
- const kinds = hidden.get(page) ?? /* @__PURE__ */ new Set();
13707
- for (const name of ["Header", "Footer", "MasterPage"]) if (num(el, `hide${name}`)) kinds.add(name);
13708
- hidden.set(page, kinds);
13709
- }
13710
- }
13711
- }
13406
+ function objectGeometry(el, x, y, w, h, boxW = w, boxH = h) {
13407
+ const rot = findChildByLocalName(el, "rotationInfo");
13408
+ const angle = num(rot, "angle") % 360;
13409
+ if (!angle) return { x, y, w, h, bbox: { x, y, w, h }, transform: "" };
13410
+ const cx = x + boxW / 2, cy = y + boxH / 2;
13411
+ const fx = cx - w / 2, fy = cy - h / 2;
13412
+ const rotation = { angle, cx: Math.round(cx), cy: Math.round(cy) };
13413
+ return { x: fx, y: fy, w, h, bbox: rotatedBounds({ x: fx, y: fy, w, h }, [rotation]), rotation, transform: `rotate(${angle} ${pt(cx)} ${pt(cy)})` };
13414
+ }
13415
+ function shapeFill(el, defs, images, warn) {
13416
+ const brush = findChildByLocalName(el, "fillBrush");
13417
+ const win = brush && findChildByLocalName(brush, "winBrush");
13418
+ const face = win?.getAttribute("faceColor");
13419
+ if (docColor(face)) return esc(face);
13420
+ const grad = brush && findChildByLocalName(brush, "gradation");
13421
+ if (grad) {
13422
+ const colors = elements(grad).filter((c) => ln(c) === "color").map((c) => docColor(c.getAttribute("value"), "#000000"));
13423
+ if (!colors.length) return "none";
13424
+ const type = grad.getAttribute("type") ?? "LINEAR";
13425
+ if (type !== "LINEAR" && type !== "RADIAL") {
13426
+ warn(`gradient:${type}`, `\uADF8\uB77C\uB370\uC774\uC158(${type}) \uBBF8\uC9C0\uC6D0 \u2014 \uCCAB \uC0C9\uC73C\uB85C \uCC44\uC6C0`);
13427
+ return esc(colors[0]);
13428
+ }
13429
+ const id = `paint${defs.length}`;
13430
+ const opacity = Math.max(0, Math.min(1, 1 - num(grad, "alpha") / 255));
13431
+ const stops = colors.map((color, i) => `<stop offset="${colors.length === 1 ? 0 : i / (colors.length - 1)}" stop-color="${esc(color)}" stop-opacity="${opacity}"/>`).join("");
13432
+ if (type === "RADIAL") defs.push(`<radialGradient id="${id}" cx="${num(grad, "centerX", 50)}%" cy="${num(grad, "centerY", 50)}%">${stops}</radialGradient>`);
13433
+ else {
13434
+ const a = num(grad, "angle") * Math.PI / 180, dx = Math.cos(a) / 2, dy = -Math.sin(a) / 2;
13435
+ defs.push(`<linearGradient id="${id}" x1="${0.5 - dx}" y1="${0.5 - dy}" x2="${0.5 + dx}" y2="${0.5 + dy}">${stops}</linearGradient>`);
13712
13436
  }
13437
+ return `url(#${id})`;
13713
13438
  }
13714
- const parity = (type, n) => type === "BOTH" || type === "ODD" && n % 2 === 1 || type === "EVEN" && n % 2 === 0;
13715
- const out = [];
13716
- for (let page = 0; page < pageCount; page++) {
13717
- const n = pageBase + page + 1;
13718
- const hides = (name) => hidden.get(page)?.has(name) === true || page === 0 && num(visibility, `hideFirst${name}`) !== 0;
13719
- if (!hides("MasterPage")) {
13720
- const matching = masters.filter((m) => m.getAttribute("type") === (n % 2 ? "ODD" : "EVEN"));
13721
- const both = masters.filter((m) => (m.getAttribute("type") || "BOTH") === "BOTH");
13722
- const normal = (matching.length ? matching : both).slice(-1);
13723
- const specific = masters.filter((m) => m.getAttribute("type") === "LAST_PAGE" ? page === pageCount - 1 : m.getAttribute("type") === "OPTIONAL_PAGE" && num(m, "pageNumber") === page + 1);
13724
- const special = specific.slice(-1);
13725
- const selected = special.length && !num(special[0], "pageDuplicate") ? special : [...normal, ...special];
13726
- for (const master of selected) {
13727
- const sub = findChildByLocalName(master, "subList");
13728
- if (sub) out.push({ sub, page, x: geom.ML, y: geom.MT, width: geom.BODY_W, layer: num(master, "pageFront") ? 2 : -2 });
13729
- }
13439
+ const imgBrush = brush && findChildByLocalName(brush, "imgBrush");
13440
+ const img = imgBrush && findChildByLocalName(imgBrush, "img");
13441
+ if (imgBrush && img) {
13442
+ const ref = img.getAttribute("binaryItemIDRef") ?? "";
13443
+ const loaded = images.get(ref);
13444
+ if (!loaded) {
13445
+ warn(`brush-image:${ref}`, `\uADF8\uB9BC \uCC44\uC6C0 \uC774\uBBF8\uC9C0(${ref}) \uC5C6\uC74C \u2014 \uCC44\uC6C0 \uC0DD\uB7B5`);
13446
+ return "none";
13730
13447
  }
13731
- for (const kind of ["header", "footer"]) {
13732
- if (hides(kind === "header" ? "Header" : "Footer")) continue;
13733
- const eligible = declarations.filter((d) => d.kind === kind && d.page <= page && parity(d.el.getAttribute("applyPageType") || "BOTH", n));
13734
- const decl = eligible[eligible.length - 1];
13735
- const sub = decl && findChildByLocalName(decl.el, "subList");
13736
- 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 });
13448
+ const mode = imgBrush.getAttribute("mode") ?? "TOTAL";
13449
+ if (mode !== "TOTAL") {
13450
+ warn(`brush-mode:${mode}`, `\uADF8\uB9BC \uCC44\uC6C0(${mode}) \uBBF8\uC9C0\uC6D0 \u2014 \uCC44\uC6C0 \uC0DD\uB7B5`);
13451
+ return "none";
13737
13452
  }
13453
+ if (loaded.paintId) return `url(#${loaded.paintId})`;
13454
+ const id = `paint${defs.length}`;
13455
+ defs.push(`<pattern id="${id}" width="1" height="1" patternContentUnits="objectBoundingBox"><image href="${esc(loaded.dataUri)}" width="1" height="1" preserveAspectRatio="none"/></pattern>`);
13456
+ loaded.paintId = id;
13457
+ return `url(#${id})`;
13738
13458
  }
13739
- return out;
13459
+ return "none";
13740
13460
  }
13741
- function footNoteStories(root, paraPages, geom) {
13742
- const pr = findFirst(root, "footNotePr");
13743
- const sp = pr ? findChildByLocalName(pr, "noteSpacing") : null, line = pr ? findChildByLocalName(pr, "noteLine") : null;
13744
- const above = num(sp, "aboveLine", 850), below = num(sp, "belowLine", 567), between = num(sp, "betweenNotes", 283);
13745
- const byPage = /* @__PURE__ */ new Map();
13746
- for (const p of elements(root)) if (ln(p) === "p") {
13747
- const page = paraPages.get(p)?.[0] ?? 0;
13748
- for (const run of elements(p)) if (ln(run) === "run") {
13749
- for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
13750
- const fn = findChildByLocalName(ctrl, "footNote");
13751
- const sub = fn && !isDeletedControl(fn) ? findChildByLocalName(fn, "subList") : null;
13752
- if (!sub) continue;
13753
- let h = 0;
13754
- for (const q of elements(sub)) if (ln(q) === "p") {
13755
- const lsa = findChildByLocalName(q, "linesegarray");
13756
- for (const seg of lsa ? elements(lsa) : []) if (ln(seg) === "lineseg") h = Math.max(h, num(seg, "vertpos") + num(seg, "vertsize"));
13461
+ function shapeGeometry(o, boxX, boxY, defs, images, warn, local = false) {
13462
+ const el = o.el, org = findChildByLocalName(el, "orgSz"), cur = findChildByLocalName(el, "curSz");
13463
+ const ow = num(org, "width"), oh = num(org, "height");
13464
+ const w = (local ? ow : num(cur, "width")) || ow || num(cur, "width") || o.width;
13465
+ const h = (local ? oh : num(cur, "height")) || oh || num(cur, "height") || o.height;
13466
+ const geometry = local ? { x: boxX, y: boxY, w, h, bbox: { x: boxX, y: boxY, w, h }, transform: "" } : objectGeometry(el, boxX, boxY, w, h, o.width || w, o.height || h);
13467
+ const { x, y } = geometry;
13468
+ const sx = ow > 0 ? w / ow : 1, sy = oh > 0 ? h / oh : 1;
13469
+ const line = findChildByLocalName(el, "lineShape"), style = line?.getAttribute("style") ?? "SOLID";
13470
+ const color = esc(docColor(line?.getAttribute("color"), "#000000"));
13471
+ const strokeW = style === "NONE" ? 0 : Math.max(0.2, num(line, "width", 33) / 100 * 2.834645);
13472
+ const dash = /DASH|DOT/.test(style) ? ` stroke-dasharray="${style.includes("DOT") ? "1,1.5" : "3,1.5"}"` : "";
13473
+ const keepWidth = local ? ` vector-effect="non-scaling-stroke"` : "";
13474
+ const stroke = strokeW ? ` stroke="${color}" stroke-width="${strokeW.toFixed(2)}"${dash}${keepWidth}` : "";
13475
+ const fill = ` fill="${shapeFill(el, defs, images, warn)}"`;
13476
+ let svg = "";
13477
+ if (o.tag === "rect") svg = `<rect x="${pt(x)}" y="${pt(y)}" width="${pt(w)}" height="${pt(h)}"${fill}${stroke}/>`;
13478
+ 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}/>`;
13479
+ else if (o.tag === "line") {
13480
+ const s = findChildByLocalName(el, "startPt"), e = findChildByLocalName(el, "endPt");
13481
+ 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}${keepWidth}/>`;
13482
+ } else if (o.tag === "polygon" || o.tag === "curv") {
13483
+ const pts = elements(el).filter((c) => ln(c) === "pt").map((c) => `${pt(x + num(c, "x") * sx)},${pt(y + num(c, "y") * sy)}`);
13484
+ if (pts.length >= 2) svg = `<polygon points="${pts.join(" ")}"${fill}${stroke}/>`;
13485
+ } else if (o.tag === "curve") {
13486
+ const segs = elements(el).filter((c) => ln(c) === "seg");
13487
+ if (segs.length) {
13488
+ let path = "", lastX, lastY;
13489
+ for (const s of segs) {
13490
+ const x1 = num(s, "x1"), y1 = num(s, "y1"), x2 = num(s, "x2"), y2 = num(s, "y2");
13491
+ if (x1 !== lastX || y1 !== lastY) path += `M${pt(x + x1 * sx)} ${pt(y + y1 * sy)}`;
13492
+ path += `L${pt(x + x2 * sx)} ${pt(y + y2 * sy)}`;
13493
+ lastX = x2;
13494
+ lastY = y2;
13495
+ }
13496
+ svg = `<path d="${path}"${fill}${stroke}/>`;
13497
+ }
13498
+ } 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"`}/>`;
13499
+ return { ...geometry, svg };
13500
+ }
13501
+
13502
+ // src/render/equation-text.ts
13503
+ var SYMBOLS = {
13504
+ alpha: "\u03B1",
13505
+ beta: "\u03B2",
13506
+ gamma: "\u03B3",
13507
+ delta: "\u03B4",
13508
+ epsilon: "\u03B5",
13509
+ varepsilon: "\u03B5",
13510
+ zeta: "\u03B6",
13511
+ eta: "\u03B7",
13512
+ theta: "\u03B8",
13513
+ vartheta: "\u03D1",
13514
+ iota: "\u03B9",
13515
+ kappa: "\u03BA",
13516
+ lambda: "\u03BB",
13517
+ mu: "\u03BC",
13518
+ nu: "\u03BD",
13519
+ xi: "\u03BE",
13520
+ pi: "\u03C0",
13521
+ rho: "\u03C1",
13522
+ sigma: "\u03C3",
13523
+ tau: "\u03C4",
13524
+ upsilon: "\u03C5",
13525
+ phi: "\u03C6",
13526
+ varphi: "\u03C6",
13527
+ chi: "\u03C7",
13528
+ psi: "\u03C8",
13529
+ omega: "\u03C9",
13530
+ Gamma: "\u0393",
13531
+ Delta: "\u0394",
13532
+ Theta: "\u0398",
13533
+ Lambda: "\u039B",
13534
+ Xi: "\u039E",
13535
+ Pi: "\u03A0",
13536
+ Sigma: "\u03A3",
13537
+ Phi: "\u03A6",
13538
+ Psi: "\u03A8",
13539
+ Omega: "\u03A9",
13540
+ times: "\xD7",
13541
+ cdot: "\xB7",
13542
+ div: "\xF7",
13543
+ pm: "\xB1",
13544
+ mp: "\u2213",
13545
+ le: "\u2264",
13546
+ leq: "\u2264",
13547
+ ge: "\u2265",
13548
+ geq: "\u2265",
13549
+ ne: "\u2260",
13550
+ neq: "\u2260",
13551
+ approx: "\u2248",
13552
+ equiv: "\u2261",
13553
+ sim: "\u223C",
13554
+ infty: "\u221E",
13555
+ rightarrow: "\u2192",
13556
+ leftarrow: "\u2190",
13557
+ Rightarrow: "\u21D2",
13558
+ Leftarrow: "\u21D0",
13559
+ leftrightarrow: "\u2194",
13560
+ Leftrightarrow: "\u21D4",
13561
+ to: "\u2192",
13562
+ angle: "\u2220",
13563
+ triangle: "\u25B3",
13564
+ perp: "\u22A5",
13565
+ parallel: "\u2225",
13566
+ circ: "\u2218",
13567
+ degree: "\xB0",
13568
+ sum: "\u03A3",
13569
+ prod: "\u03A0",
13570
+ int: "\u222B",
13571
+ oint: "\u222E",
13572
+ partial: "\u2202",
13573
+ nabla: "\u2207",
13574
+ in: "\u2208",
13575
+ notin: "\u2209",
13576
+ subset: "\u2282",
13577
+ supset: "\u2283",
13578
+ subseteq: "\u2286",
13579
+ supseteq: "\u2287",
13580
+ cup: "\u222A",
13581
+ cap: "\u2229",
13582
+ emptyset: "\u2205",
13583
+ forall: "\u2200",
13584
+ exists: "\u2203",
13585
+ therefore: "\u2234",
13586
+ because: "\u2235",
13587
+ prime: "\u2032",
13588
+ cdots: "\u22EF",
13589
+ ldots: "\u2026",
13590
+ dots: "\u2026",
13591
+ vdots: "\u22EE",
13592
+ lim: "lim",
13593
+ log: "log",
13594
+ ln: "ln",
13595
+ sin: "sin",
13596
+ cos: "cos",
13597
+ tan: "tan",
13598
+ sec: "sec",
13599
+ csc: "csc",
13600
+ cot: "cot",
13601
+ exp: "exp",
13602
+ max: "max",
13603
+ min: "min",
13604
+ quad: " ",
13605
+ qquad: " ",
13606
+ ",": " ",
13607
+ ";": " ",
13608
+ "!": "",
13609
+ "{": "{",
13610
+ "}": "}",
13611
+ "|": "\u2016",
13612
+ backslash: "\\",
13613
+ lbrace: "{",
13614
+ rbrace: "}",
13615
+ langle: "\u27E8",
13616
+ rangle: "\u27E9"
13617
+ };
13618
+ var SUP = { "0": "\u2070", "1": "\xB9", "2": "\xB2", "3": "\xB3", "4": "\u2074", "5": "\u2075", "6": "\u2076", "7": "\u2077", "8": "\u2078", "9": "\u2079", "+": "\u207A", "-": "\u207B", "=": "\u207C", "(": "\u207D", ")": "\u207E", n: "\u207F", i: "\u2071", x: "\u02E3", "\u2032": "\u2032" };
13619
+ var SUB = { "0": "\u2080", "1": "\u2081", "2": "\u2082", "3": "\u2083", "4": "\u2084", "5": "\u2085", "6": "\u2086", "7": "\u2087", "8": "\u2088", "9": "\u2089", "+": "\u208A", "-": "\u208B", "=": "\u208C", "(": "\u208D", ")": "\u208E" };
13620
+ function latexToPlain(latex) {
13621
+ let i = 0;
13622
+ const s = latex;
13623
+ const skipWs = () => {
13624
+ while (i < s.length && s[i] === " ") i++;
13625
+ };
13626
+ const arg = () => {
13627
+ skipWs();
13628
+ if (s[i] === "{") {
13629
+ i++;
13630
+ const v = seq("}");
13631
+ i++;
13632
+ return v;
13633
+ }
13634
+ return atom();
13635
+ };
13636
+ const wrap = (v) => v.length > 1 && !/^[\w.′]+$|^\(.*\)$/u.test(v) ? `(${v})` : v;
13637
+ const script = (v, map, mark) => {
13638
+ const t = v.trim();
13639
+ return [...t].every((c) => map[c]) ? [...t].map((c) => map[c]).join("") : `${mark}${wrap(t)}`;
13640
+ };
13641
+ const atom = () => {
13642
+ const c = s[i];
13643
+ if (c === void 0) return "";
13644
+ if (c === "\\") {
13645
+ i++;
13646
+ let name = "";
13647
+ if (/[A-Za-z]/.test(s[i] ?? "")) while (/[A-Za-z]/.test(s[i] ?? "")) name += s[i++];
13648
+ else name = s[i++] ?? "";
13649
+ if (name === "frac") {
13650
+ const a = arg(), b = arg();
13651
+ return `${wrap(a.trim())}/${wrap(b.trim())}`;
13652
+ }
13653
+ if (name === "sqrt") {
13654
+ skipWs();
13655
+ let root = "";
13656
+ if (s[i] === "[") {
13657
+ i++;
13658
+ root = seq("]");
13659
+ i++;
13757
13660
  }
13758
- const list = byPage.get(page) ?? [];
13759
- list.push({ sub, h });
13760
- byPage.set(page, list);
13661
+ const a = arg();
13662
+ return `${root ? script(root, SUP, "") : ""}\u221A${wrap(a.trim())}`;
13761
13663
  }
13762
- }
13763
- }
13764
- const stories = [], rules = [];
13765
- const lenAttr = num(line, "length", -1), widthMm = Number.parseFloat(line?.getAttribute("width") ?? "0.12") || 0.12;
13766
- const lineType = line?.getAttribute("type") ?? "SOLID";
13767
- for (const [page, notes] of byPage) {
13768
- const area = above + below + notes.reduce((a, n) => a + n.h, 0) + between * (notes.length - 1);
13769
- const top = geom.MT + geom.BODY_H - area;
13770
- if (lineType !== "NONE") rules.push({ page, x: geom.ML, y: top + above, length: lenAttr > 0 ? lenAttr : 14173, widthMm, color: line?.getAttribute("color") ?? "#000000" });
13771
- let y = top + above + below;
13772
- for (const n of notes) {
13773
- stories.push({ sub: n.sub, page, x: geom.ML, y, width: geom.BODY_W });
13774
- y += n.h + between;
13775
- }
13776
- }
13777
- return { stories, rules };
13778
- }
13779
- function endNoteLayout(root, paraPages, geom) {
13780
- const notes = [];
13781
- let last = null;
13782
- let endColPr = null;
13783
- for (const p of elements(root)) if (ln(p) === "p") {
13784
- const lsa = findChildByLocalName(p, "linesegarray"), segs = lsa ? elements(lsa).filter((e) => ln(e) === "lineseg") : [];
13785
- const pages = paraPages.get(p) ?? [];
13786
- if (segs.length) last = { seg: segs[segs.length - 1], page: pages[segs.length - 1] ?? pages[0] ?? 0 };
13787
- for (const run of elements(p)) if (ln(run) === "run") {
13788
- for (const ctrl of elements(run)) if (ln(ctrl) === "ctrl") {
13789
- endColPr = findChildByLocalName(ctrl, "colPr") ?? endColPr;
13790
- const en = findChildByLocalName(ctrl, "endNote");
13791
- const sub = en && !isDeletedControl(en) ? findChildByLocalName(en, "subList") : null;
13792
- if (sub) notes.push(sub);
13664
+ if (name === "left" || name === "right" || name === "big" || name === "Big" || name === "bigg" || name === "Bigg") {
13665
+ skipWs();
13666
+ const d = s[i] === "\\" ? atom() : s[i++] ?? "";
13667
+ return d === "." ? "" : d;
13668
+ }
13669
+ if (name === "overline" || name === "bar" || name === "hat" || name === "vec" || name === "dot" || name === "tilde") {
13670
+ const a = arg().trim(), mark = { overline: "\u0305", bar: "\u0304", hat: "\u0302", vec: "\u20D7", dot: "\u0307", tilde: "\u0303" }[name];
13671
+ return [...a].map((ch) => ch + mark).join("");
13793
13672
  }
13673
+ if (name === "mathrm" || name === "text" || name === "rm" || name === "mathbf" || name === "it" || name === "mathit" || name === "operatorname") return name === "rm" || name === "it" ? "" : arg();
13674
+ return SYMBOLS[name] ?? name;
13794
13675
  }
13795
- }
13796
- if (!notes.length || !last) return null;
13797
- const pr = findFirst(root, "endNotePr");
13798
- const sp = pr ? findChildByLocalName(pr, "noteSpacing") : null, line = pr ? findChildByLocalName(pr, "noteLine") : null;
13799
- const above = num(sp, "aboveLine", 0), below = num(sp, "belowLine", 567), between = num(sp, "betweenNotes", 283);
13800
- const colPr = endColPr ?? findFirst(root, "colPr"), nCol = Math.max(1, num(colPr, "colCount", 1)), gap = nCol > 1 ? num(colPr, "sameGap", 0) : 0;
13801
- const colW = (geom.BODY_W - gap * (nCol - 1)) / nCol;
13802
- let page = last.page;
13803
- let col = nCol > 1 ? Math.min(nCol - 1, Math.max(0, Math.round(num(last.seg, "horzpos") / (colW + gap)))) : 0;
13804
- let y = num(last.seg, "vertpos") + num(last.seg, "vertsize") + above;
13805
- const rules = [];
13806
- const lenAttr = num(line, "length", -1), widthMm = Number.parseFloat(line?.getAttribute("width") ?? "0.12") || 0.12;
13807
- if ((line?.getAttribute("type") ?? "SOLID") !== "NONE") rules.push({ page, x: geom.ML + col * (colW + gap), y: geom.MT + y, length: lenAttr > 0 ? lenAttr : 14173, widthMm, color: line?.getAttribute("color") ?? "#000000" });
13808
- y += below;
13809
- const next = () => {
13810
- if (++col >= nCol) {
13811
- col = 0;
13812
- page++;
13676
+ i++;
13677
+ if (c === "{") {
13678
+ const v = seq("}");
13679
+ i++;
13680
+ return v;
13813
13681
  }
13814
- y = 0;
13682
+ if (c === "^") return script(arg(), SUP, "^");
13683
+ if (c === "_") return script(arg(), SUB, "_");
13684
+ if (c === "~" || c === "`") return " ";
13685
+ return c;
13815
13686
  };
13816
- const out = [];
13817
- notes.forEach((sub, ni) => {
13818
- if (ni > 0) y += between;
13819
- let base = y;
13820
- let prevRaw = Number.NEGATIVE_INFINITY, flowEnd = y;
13821
- for (const q of elements(sub)) if (ln(q) === "p") {
13822
- const lsa = findChildByLocalName(q, "linesegarray"), segs = lsa ? elements(lsa).filter((e) => ln(e) === "lineseg") : [];
13823
- const pages = [];
13824
- for (const seg of segs) {
13825
- const raw = num(seg, "vertpos");
13826
- if (raw < prevRaw) base = flowEnd - raw;
13827
- prevRaw = raw;
13828
- let v = base + raw;
13829
- const vs = num(seg, "vertsize");
13830
- if (v + vs > geom.BODY_H && v > 0) {
13831
- const shift = v;
13832
- next();
13833
- base -= shift;
13834
- v = 0;
13835
- }
13836
- seg.setAttribute("vertpos", String(v));
13837
- seg.setAttribute("horzpos", String(num(seg, "horzpos") + col * (colW + gap)));
13838
- pages.push(page);
13839
- y = v + vs;
13840
- flowEnd = y + num(seg, "spacing");
13687
+ const seq = (end) => {
13688
+ let out = "";
13689
+ while (i < s.length && s[i] !== end) {
13690
+ if (s[i] === " ") {
13691
+ i++;
13692
+ continue;
13841
13693
  }
13842
- out.push({ p: q, pages });
13694
+ out += atom();
13843
13695
  }
13844
- });
13845
- return { paras: out, rules, pageCount: page + 1 };
13696
+ return out;
13697
+ };
13698
+ return seq("\0").replace(/\s+/g, " ").trim();
13846
13699
  }
13847
13700
 
13848
- // src/render/table-pages.ts
13849
- function stackedFloats(c) {
13850
- const out = [];
13851
- for (const p of c.sub ? elements(c.sub) : []) if (ln(p) === "p") {
13852
- for (const run of elements(p)) if (ln(run) === "run") for (const o of elements(run)) {
13853
- if (ln(o) !== "pic") continue;
13854
- const pos = findChildByLocalName(o, "pos");
13855
- if (!pos || pos.getAttribute("treatAsChar") === "1" || (pos.getAttribute("vertRelTo") ?? "PARA") !== "PARA" || pos.getAttribute("allowOverlap") !== "0") continue;
13856
- const wrap = o.getAttribute("textWrap") ?? "TOP_AND_BOTTOM";
13857
- if (wrap !== "SQUARE" && wrap !== "TOP_AND_BOTTOM") continue;
13858
- const om = findChildByLocalName(o, "outMargin"), raw = num(pos, "vertOffset");
13859
- out.push({ el: o, vo: Math.max(0, raw >= 2 ** 31 ? raw - 2 ** 32 : raw), h: num(findChildByLocalName(o, "sz"), "height") + num(om, "top") + num(om, "bottom"), omT: num(om, "top") });
13860
- }
13861
- }
13862
- return out;
13863
- }
13864
- function cellLineBoxes(c) {
13865
- const out = [];
13866
- let shift = 0, prevV = Number.NEGATIVE_INFINITY, prevEnd = 0, part = 0;
13867
- const cols = cellColumns(c.sub);
13868
- for (const p of c.sub ? elements(c.sub) : []) if (ln(p) === "p") {
13869
- const lsa = findChildByLocalName(p, "linesegarray");
13870
- for (const sg of lsa ? elements(lsa) : []) if (ln(sg) === "lineseg") {
13871
- const v = num(sg, "vertpos");
13872
- if (v < prevV && !cols) {
13873
- shift = prevEnd - v;
13874
- part++;
13875
- }
13876
- prevV = v;
13877
- const top = v + shift, bottom = top + num(sg, "vertsize");
13878
- prevEnd = bottom + num(sg, "spacing");
13879
- out.push({ seg: sg, top, bottom, part, origin: shift });
13880
- }
13701
+ // src/hwpx/equation.ts
13702
+ var CONVERT_MAP = {
13703
+ TIMES: "\\times",
13704
+ times: "\\times",
13705
+ LEFT: "\\left",
13706
+ RIGHT: "\\right",
13707
+ under: "\\underline",
13708
+ SMALLSUM: "\\sum",
13709
+ sum: "\\sum",
13710
+ SMALLPROD: "\\prod",
13711
+ prod: "\\prod",
13712
+ SMALLINTER: "\\cap",
13713
+ CUP: "\\cup",
13714
+ OPLUS: "\\oplus",
13715
+ OMINUS: "\\ominus",
13716
+ OTIMES: "\\otimes",
13717
+ ODIV: "\\oslash",
13718
+ ODOT: "\\odot",
13719
+ LOR: "\\lor",
13720
+ LAND: "\\land",
13721
+ SUBSET: "\\subset",
13722
+ SUPERSET: "\\supset",
13723
+ SUBSETEQ: "\\subseteq",
13724
+ SUPSETEQ: "\\supseteq",
13725
+ IN: "\\in",
13726
+ OWNS: "\\owns",
13727
+ NOTIN: "\\notin",
13728
+ LEQ: "\\leq",
13729
+ GEQ: "\\geq",
13730
+ "<<": "\\ll",
13731
+ ">>": "\\gg",
13732
+ "<<<": "\\lll",
13733
+ ">>>": "\\ggg",
13734
+ PREC: "\\prec",
13735
+ SUCC: "\\succ",
13736
+ UPLUS: "\\uplus",
13737
+ "\xB1": "\\pm",
13738
+ "+-": "\\pm",
13739
+ "-+": "\\mp",
13740
+ "\xF7": "\\div",
13741
+ cdot: "\\cdot",
13742
+ CIRC: "\\circ",
13743
+ BULLET: "\\bullet",
13744
+ DEG: " ^\\circ",
13745
+ AST: "\\ast",
13746
+ STAR: "\\bigstar",
13747
+ BIGCIRC: "\\bigcirc",
13748
+ EMPTYSET: "\\emptyset",
13749
+ THEREFORE: "\\therefore",
13750
+ BECAUSE: "\\because",
13751
+ EXIST: "\\exists",
13752
+ // 한글 수식 편집기는 소문자 therefore·because 도 같은 기호로 그린다(#148) — 생성 쪽 정준형은 대문자(equation-generate COMMAND_MAP)
13753
+ therefore: "\\therefore",
13754
+ because: "\\because",
13755
+ "!=": "\\neq",
13756
+ SMCOPROD: "\\coprod",
13757
+ coprod: "\\coprod",
13758
+ SQCAP: "\\sqcap",
13759
+ SQCUP: "\\sqcup",
13760
+ SQSUBSET: "\\sqsubset",
13761
+ SQSUBSETEQ: "\\sqsubseteq",
13762
+ BIGSQCUP: "\\bigsqcup",
13763
+ BIGOPLUS: "\\bigoplus",
13764
+ BIGOTIMES: "\\bigotimes",
13765
+ BIGODOT: "\\bigodot",
13766
+ BIGUPLUS: "\\biguplus",
13767
+ inter: "\\bigcap",
13768
+ union: "\\bigcup",
13769
+ BIGOMINUS: "{\\Large\\ominus}",
13770
+ BIGODIV: "{\\Large\\oslash}",
13771
+ UNDEROVER: "",
13772
+ SIM: "\\sim",
13773
+ APPROX: "\\approx",
13774
+ SIMEQ: "\\simeq",
13775
+ CONG: "\\cong",
13776
+ "==": "\\equiv",
13777
+ DIAMOND: "\\diamond",
13778
+ FORALL: "\\forall",
13779
+ prime: "'",
13780
+ Partial: "\\partial",
13781
+ INF: "\\infty",
13782
+ PROPTO: "\\propto",
13783
+ lim: "\\lim",
13784
+ Lim: "\\lim",
13785
+ larrow: "\\leftarrow",
13786
+ "->": "\\rightarrow",
13787
+ uparrow: "\\uparrow",
13788
+ downarrow: "\\downarrow",
13789
+ LARROW: "\\Leftarrow",
13790
+ RARROW: "\\Rightarrow",
13791
+ UPARROW: "\\Uparrow",
13792
+ DOWNARROW: "\\Downarrow",
13793
+ udarrow: "\\updownarrow",
13794
+ "<->": "\\leftrightarrow",
13795
+ UDARROW: "\\Updownarrow",
13796
+ LRARROW: "\\Leftrightarrow",
13797
+ NWARROW: "\\nwarrow",
13798
+ SEARROW: "\\searrow",
13799
+ NEARROW: "\\nearrow",
13800
+ SWARROW: "\\swarrow",
13801
+ HOOKLEFT: "\\hookleftarrow",
13802
+ HOOKRIGHT: "\\hookrightarrow",
13803
+ PVER: "\\|",
13804
+ MAPSTO: "\\mapsto",
13805
+ CDOTS: "\\cdots",
13806
+ LDOTS: "\\ldots",
13807
+ VDOTS: "\\vdots",
13808
+ DDOTS: "\\ddots",
13809
+ DAGGER: "\\dagger",
13810
+ DDAGGER: "\\ddagger",
13811
+ DOTEQ: "\\doteq",
13812
+ image: "\\fallingdotseq",
13813
+ REIMAGE: "\\risingdotseq",
13814
+ ASYMP: "\\asymp",
13815
+ ISO: "\\Bumpeq",
13816
+ DSUM: "\\dotplus",
13817
+ XOR: "\\veebar",
13818
+ TRIANGLE: "\\triangle",
13819
+ NABLA: "\\nabla",
13820
+ ANGLE: "\\angle",
13821
+ MSANGLE: "\\measuredangle",
13822
+ SANGLE: "\\sphericalangle",
13823
+ VDASH: "\\vdash",
13824
+ DASHV: "\\dashv",
13825
+ BOT: "\\bot",
13826
+ TOP: "\\top",
13827
+ MODELS: "\\models",
13828
+ LAPLACE: "\\mathcal{L}",
13829
+ CENTIGRADE: "^{\\circ}C",
13830
+ FAHRENHEIT: "^{\\circ}F",
13831
+ LSLANT: "\\diagup",
13832
+ RSLANT: "\\diagdown",
13833
+ sqrt: "\\sqrt",
13834
+ int: "\\int",
13835
+ dint: "\\iint",
13836
+ tint: "\\iiint",
13837
+ oint: "\\oint",
13838
+ alpha: "\\alpha",
13839
+ beta: "\\beta",
13840
+ gamma: "\\gamma",
13841
+ delta: "\\delta",
13842
+ epsilon: "\\epsilon",
13843
+ zeta: "\\zeta",
13844
+ eta: "\\eta",
13845
+ theta: "\\theta",
13846
+ iota: "\\iota",
13847
+ kappa: "\\kappa",
13848
+ lambda: "\\lambda",
13849
+ mu: "\\mu",
13850
+ nu: "\\nu",
13851
+ xi: "\\xi",
13852
+ omicron: "\\omicron",
13853
+ pi: "\\pi",
13854
+ rho: "\\rho",
13855
+ sigma: "\\sigma",
13856
+ tau: "\\tau",
13857
+ upsilon: "\\upsilon",
13858
+ phi: "\\phi",
13859
+ chi: "\\chi",
13860
+ psi: "\\psi",
13861
+ omega: "\\omega",
13862
+ ALPHA: "A",
13863
+ BETA: "B",
13864
+ GAMMA: "\\Gamma",
13865
+ DELTA: "\\Delta",
13866
+ EPSILON: "E",
13867
+ ZETA: "Z",
13868
+ ETA: "H",
13869
+ THETA: "\\Theta",
13870
+ IOTA: "I",
13871
+ KAPPA: "K",
13872
+ LAMBDA: "\\Lambda",
13873
+ MU: "M",
13874
+ NU: "N",
13875
+ XI: "\\Xi",
13876
+ OMICRON: "O",
13877
+ PI: "\\Pi",
13878
+ RHO: "P",
13879
+ SIGMA: "\\Sigma",
13880
+ TAU: "T",
13881
+ UPSILON: "\\Upsilon",
13882
+ PHI: "\\Phi",
13883
+ CHI: "X",
13884
+ PSI: "\\Psi",
13885
+ OMEGA: "\\Omega",
13886
+ "\u2308": "\\lceil",
13887
+ "\u2309": "\\rceil",
13888
+ "\u230A": "\\lfloor",
13889
+ "\u230B": "\\rfloor",
13890
+ "\u2225": "\\|",
13891
+ "\u2290": "\\sqsupset",
13892
+ "\u2292": "\\sqsupseteq",
13893
+ odint: "\\mathop \u222F",
13894
+ otint: "\\mathop \u2230",
13895
+ BIGSQCAP: "\\mathop \u2A05",
13896
+ ATT: "\\mathop \u203B",
13897
+ HUND: "\\mathop \u2030",
13898
+ THOU: "\\mathop \u2031",
13899
+ IDENTICAL: "\\mathop \u2237",
13900
+ RTANGLE: "\\mathop \u22BE",
13901
+ BASE: "\\mathop \u2302",
13902
+ BENZENE: "\\mathop \u232C"
13903
+ };
13904
+ var MIDDLE_CONVERT_MAP = {
13905
+ matrix: "HULKMATRIX",
13906
+ pmatrix: "HULKPMATRIX",
13907
+ bmatrix: "HULKBMATRIX",
13908
+ dmatrix: "HULKDMATRIX",
13909
+ eqalign: "HULKEQALIGN",
13910
+ cases: "HULKCASE",
13911
+ vec: "HULKVEC",
13912
+ dyad: "HULKDYAD",
13913
+ acute: "HULKACUTE",
13914
+ grave: "HULKGRAVE",
13915
+ dot: "HULKDOT",
13916
+ ddot: "HULKDDOT",
13917
+ bar: "HULKBAR",
13918
+ hat: "HULKHAT",
13919
+ check: "HULKCHECK",
13920
+ arch: "HULKARCH",
13921
+ tilde: "HULKTILDE",
13922
+ BOX: "HULKBOX",
13923
+ OVERBRACE: "HULKOVERBRACE",
13924
+ UNDERBRACE: "HULKUNDERBRACE"
13925
+ };
13926
+ var BAR_CONVERT_MAP = {
13927
+ HULKVEC: "\\overrightarrow",
13928
+ HULKDYAD: "\\overleftrightarrow",
13929
+ HULKACUTE: "\\acute",
13930
+ HULKGRAVE: "\\grave",
13931
+ HULKDOT: "\\dot",
13932
+ HULKDDOT: "\\ddot",
13933
+ HULKBAR: "\\overline",
13934
+ HULKHAT: "\\widehat",
13935
+ HULKCHECK: "\\check",
13936
+ HULKARCH: "\\overset{\\frown}",
13937
+ HULKTILDE: "\\widetilde",
13938
+ HULKBOX: "\\boxed"
13939
+ };
13940
+ var MATRIX_CONVERT_MAP = {
13941
+ HULKMATRIX: { begin: "\\begin{matrix}", end: "\\end{matrix}", removeOutterBrackets: true },
13942
+ HULKPMATRIX: { begin: "\\begin{pmatrix}", end: "\\end{pmatrix}", removeOutterBrackets: true },
13943
+ HULKBMATRIX: { begin: "\\begin{bmatrix}", end: "\\end{bmatrix}", removeOutterBrackets: true },
13944
+ HULKDMATRIX: { begin: "\\begin{vmatrix}", end: "\\end{vmatrix}", removeOutterBrackets: true },
13945
+ HULKCASE: { begin: "\\begin{cases}", end: "\\end{cases}", removeOutterBrackets: true },
13946
+ HULKEQALIGN: { begin: "\\eqalign{", end: "}", removeOutterBrackets: false }
13947
+ };
13948
+ var BRACE_CONVERT_MAP = {
13949
+ HULKOVERBRACE: "\\overbrace",
13950
+ HULKUNDERBRACE: "\\underbrace"
13951
+ };
13952
+ function findBrackets(eqString, startIdx) {
13953
+ const startCur = eqString.indexOf("{", startIdx);
13954
+ if (startCur === -1) throw new Error("cannot find bracket");
13955
+ let bracketCount = 1;
13956
+ for (let i = startCur + 1; i < eqString.length; i++) {
13957
+ const ch = eqString[i];
13958
+ if (ch === "{") bracketCount += 1;
13959
+ else if (ch === "}") bracketCount -= 1;
13960
+ if (bracketCount === 0) return [startCur, i + 1];
13881
13961
  }
13882
- return out;
13883
- }
13884
- function cellLines(c) {
13885
- return cellLineBoxes(c).map((b) => [b.top, b.bottom]);
13962
+ throw new Error("cannot find bracket");
13886
13963
  }
13887
- function planTableRows(tbl, cells, rowH, ty, MT, BODY_H, slack = 0, floatSpan, nested = false) {
13888
- if (nested) slack = 0;
13889
- const nRows = rowH.length;
13890
- const rowY = [0];
13891
- for (const h of rowH) rowY.push(rowY[rowY.length - 1] + h);
13892
- const plain = () => rowH.map((h, r) => [{ page: 0, y: ty + rowY[r], h }]);
13893
- const pageBottom = MT + BODY_H;
13894
- const stackOver = tbl.getAttribute("pageBreak") === "CELL" && rowH.some((h, r) => {
13895
- const rc = cells.filter((c) => c.ra === r && c.rs === 1);
13896
- if (rc.length !== 1) return false;
13897
- const st = stackedFloats(rc[0]);
13898
- return st.length >= 2 && st.reduce((a, f) => a + f.h, 0) > h;
13899
- });
13900
- if (BODY_H <= 0 || ty + rowY[nRows] <= pageBottom + slack && !stackOver) return plain();
13901
- if (findChildByLocalName(tbl, "pos")?.getAttribute("treatAsChar") === "1") {
13902
- const declared = num(findChildByLocalName(tbl, "sz"), "height") || rowY[nRows];
13903
- if (ty - MT < 2e3 || ty + declared <= pageBottom + slack) return plain();
13904
- return rowH.map((h, r) => [{ page: 1, y: MT + rowY[r], h }]);
13905
- }
13906
- let hdrRows = 0;
13907
- if (tbl.getAttribute("repeatHeader") === "1") while (hdrRows < nRows && cells.some((c) => c.ra === hdrRows) && cells.filter((c) => c.ra === hdrRows).every((c) => c.el.getAttribute("header") === "1")) hdrRows++;
13908
- const contTop = MT + num(findChildByLocalName(tbl, "outMargin"), "top") + rowY[hdrRows];
13909
- const cellSplit = tbl.getAttribute("pageBreak") === "CELL";
13910
- const out = [];
13911
- let page = 0, y = ty, first = true;
13912
- for (let r = 0; r < nRows; r++) {
13913
- let h = rowH[r];
13914
- const pieces = [];
13915
- const rowCells = cells.filter((c) => c.ra === r && c.rs === 1);
13916
- const splittable = cellSplit && r >= hdrRows && rowCells.length > 0;
13917
- const stack = splittable && rowCells.length === 1 ? stackedFloats(rowCells[0]) : [];
13918
- if (stack.length >= 2) {
13919
- const c = rowCells[0];
13920
- let top = y, bottom = y + c.marginT, k = 0;
13921
- const pcs = [];
13922
- let place = /* @__PURE__ */ new Map();
13923
- for (const f of stack) {
13924
- let at = k === 0 ? top + c.marginT + f.vo : bottom;
13925
- if (k > 0 && at + f.h > pageBottom - c.marginB) {
13926
- pcs.push({ page, y: top, h: bottom - top + c.marginB, range: /* @__PURE__ */ new Map([[c.el, pcs.length ? [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY] : [0, Number.POSITIVE_INFINITY]]]), place });
13927
- page++;
13928
- top = contTop;
13929
- place = /* @__PURE__ */ new Map();
13930
- at = top + c.marginT;
13931
- bottom = at;
13932
- }
13933
- place.set(f.el, at + f.omT);
13934
- bottom = Math.max(bottom, at + f.h);
13935
- k++;
13936
- }
13937
- if (pcs.length) {
13938
- pcs.push({ page, y: top, h: bottom - top + c.marginB, range: /* @__PURE__ */ new Map([[c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]]]), place });
13939
- out.push(pcs);
13940
- y = bottom + c.marginB;
13941
- first = false;
13964
+ function findEnclosingBrackets(eqString, startIdx) {
13965
+ let depth = 0;
13966
+ for (let idx = startIdx - 1; idx >= 0; idx--) {
13967
+ const ch = eqString[idx];
13968
+ if (ch === "}") {
13969
+ depth += 1;
13970
+ } else if (ch === "{") {
13971
+ if (depth > 0) {
13972
+ depth -= 1;
13942
13973
  continue;
13943
13974
  }
13975
+ try {
13976
+ const [start, end] = findBrackets(eqString, idx);
13977
+ if (start === idx && end > startIdx) return [start, end];
13978
+ } catch {
13979
+ return null;
13980
+ }
13981
+ return null;
13944
13982
  }
13945
- const boxes = splittable ? new Map(rowCells.map((c) => [c.el, cellLineBoxes(c)])) : void 0;
13946
- const hParts = boxes ? Math.max(0, ...[...boxes.values()].flatMap((bs) => bs.map((b) => b.part))) : 0;
13947
- if (boxes && hParts > 0) {
13948
- const declared = num(findChildByLocalName(tbl, "sz"), "height");
13949
- const led = /* @__PURE__ */ new Set();
13950
- for (let k = 0; k <= hParts; k++) {
13951
- if (k > 0 && floatSpan) {
13952
- let lead = 0, place;
13953
- for (const c of rowCells) {
13954
- const b = (boxes.get(c.el) ?? []).find((x) => x.part === k);
13955
- if (!b) continue;
13956
- const f = floatSpan(b.seg, y + c.marginT);
13957
- if (f?.el && f.pages > 0 && f.pages > lead && Math.abs(contTop + c.marginT + b.top - b.origin - f.endY) < 3e3) {
13958
- lead = f.pages;
13959
- place = /* @__PURE__ */ new Map([[f.el, y + c.marginT]]);
13960
- led.add(b.seg);
13961
- }
13962
- }
13963
- if (lead > 0) {
13964
- const none = new Map(rowCells.map((c) => [c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]]));
13965
- for (let e = 0; e < lead; e++) pieces.push({ page: page + e, y: contTop, h: pageBottom - contTop, range: none, place: e === 0 ? place : void 0 });
13966
- page += lead;
13967
- }
13968
- }
13969
- const range = /* @__PURE__ */ new Map();
13970
- let ext = 0, toNext = 0;
13971
- for (const c of rowCells) {
13972
- const bs = boxes.get(c.el) ?? [];
13973
- const inK = bs.filter((b) => b.part === k), next = bs.find((b) => b.part > k);
13974
- const from = inK[0]?.origin ?? next?.origin ?? Number.POSITIVE_INFINITY;
13975
- range.set(c.el, [from, next?.top ?? Number.POSITIVE_INFINITY]);
13976
- if (inK.length) ext = Math.max(ext, inK[inK.length - 1].bottom - from + c.marginT + c.marginB);
13977
- if (inK.length && next) toNext = Math.max(toNext, next.top - from + c.marginT + c.marginB);
13978
- }
13979
- const last = k === hParts;
13980
- const firstH = declared > 0 && ty + declared - y >= ext ? Math.min(pageBottom - y, ty + declared - y) : pageBottom - y;
13981
- const ph = last ? ext : k === 0 ? firstH : toNext > 0 ? Math.min(pageBottom - contTop, toNext) : pageBottom - contTop;
13982
- pieces.push({ page, y, h: ph, range });
13983
- if (!last) {
13984
- let span = 0, spanEnd = 0;
13985
- if (floatSpan) for (const c of rowCells) {
13986
- const bs = (boxes.get(c.el) ?? []).filter((b) => b.part === k), from = bs[0]?.origin ?? 0;
13987
- for (const b of bs) {
13988
- if (led.has(b.seg)) continue;
13989
- const f = floatSpan(b.seg, y + c.marginT + b.top - from);
13990
- if (f && f.pages > span) {
13991
- span = f.pages;
13992
- spanEnd = f.endY;
13993
- }
13994
- }
13995
- }
13996
- if (span > 0) {
13997
- const nextTop = Math.min(...rowCells.map((c) => {
13998
- const b = (boxes.get(c.el) ?? []).find((x) => x.part === k + 1);
13999
- return b ? contTop + c.marginT + b.top - b.origin : Number.POSITIVE_INFINITY;
14000
- }));
14001
- const skip = nextTop < spanEnd - 100 ? span + 1 : span;
14002
- for (let e = 1; e < skip; e++) pieces.push({ page: page + e, y: contTop, h: pageBottom - contTop, range: new Map(rowCells.map((c) => [c.el, [Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY]])) });
14003
- page += skip;
14004
- } else page++;
14005
- y = contTop;
14006
- first = true;
14007
- } else h = ph;
13983
+ }
13984
+ return null;
13985
+ }
13986
+ function maskLiteralSpans(eqString) {
13987
+ return eqString.replace(/"[^"]*"/g, (m) => "\uFFFF".repeat(m.length)).replace(/\\text\{[^}]*\}/g, (m) => "\uFFFF".repeat(m.length));
13988
+ }
13989
+ function findKeywordToken(eqString, word, from = 0) {
13990
+ const masked = maskLiteralSpans(eqString);
13991
+ for (let i = masked.indexOf(word, from); i !== -1; i = masked.indexOf(word, i + 1)) {
13992
+ const okL = i === 0 || /\s/.test(masked[i - 1]);
13993
+ const okR = i + word.length === masked.length || /\s/.test(masked[i + word.length]);
13994
+ if (okL && okR) return i;
13995
+ }
13996
+ return -1;
13997
+ }
13998
+ function replaceFrac(eqString) {
13999
+ const hmlFrac = "over";
14000
+ const masked = maskLiteralSpans(eqString);
14001
+ const out = [];
14002
+ let pos = 0;
14003
+ for (let cursor = masked.indexOf(hmlFrac); cursor !== -1; cursor = masked.indexOf(hmlFrac, cursor + 1)) {
14004
+ const okL = cursor === 0 || /\s/.test(masked[cursor - 1]);
14005
+ const okR = cursor + hmlFrac.length === masked.length || /\s/.test(masked[cursor + hmlFrac.length]);
14006
+ if (!okL || !okR) continue;
14007
+ for (; pos < cursor; pos++) out.push(eqString[pos]);
14008
+ let end = out.length;
14009
+ while (end > 0 && /\s/.test(out[end - 1])) end--;
14010
+ let numStart = end;
14011
+ if (end > 0 && out[end - 1] === "}") {
14012
+ let depth = 0;
14013
+ for (numStart = end - 1; numStart >= 0; numStart--) {
14014
+ if (out[numStart] === "}") depth++;
14015
+ else if (out[numStart] === "{" && --depth === 0) break;
14008
14016
  }
14009
- out.push(pieces);
14010
- y += h;
14011
- first = false;
14012
- continue;
14017
+ if (numStart < 0) break;
14018
+ out.length = end;
14019
+ out.splice(numStart, 0, "\\frac");
14020
+ } else {
14021
+ while (numStart > 0 && !/\s/.test(out[numStart - 1])) numStart--;
14022
+ if (numStart === end) break;
14023
+ out.length = end;
14024
+ out.splice(numStart, 0, "\\frac", "{");
14025
+ out.push("}");
14013
14026
  }
14014
- if (splittable && y + h > pageBottom) {
14015
- const from = /* @__PURE__ */ new Map();
14016
- const lines = new Map(rowCells.map((c) => [c.el, cellLines(c)]));
14017
- while (y + h > pageBottom && BODY_H > rowY[hdrRows]) {
14018
- const avail = pageBottom - y;
14019
- let rem = 0, placed = false, allFit = true, blocked = false;
14020
- const cuts = [];
14021
- for (const c of rowCells) {
14022
- const off = from.get(c.el) ?? 0;
14023
- const ls = (lines.get(c.el) ?? []).filter((l) => l[0] >= off);
14024
- if (!ls.length) {
14025
- cuts.push([c.el, off, off]);
14026
- continue;
14027
- }
14028
- const end = Math.max(...ls.map((l) => l[1]));
14029
- const k = ls.findIndex((l) => c.marginT + (l[1] - off) > avail - c.marginB);
14030
- if (k < 0) {
14031
- cuts.push([c.el, off, end + 1]);
14032
- continue;
14033
- }
14034
- allFit = false;
14035
- if (k > 0) placed = true;
14036
- else if (off === 0) blocked = true;
14037
- cuts.push([c.el, off, ls[k][0]]);
14038
- rem = Math.max(rem, end - ls[k][0] + c.marginT + c.marginB);
14039
- }
14040
- if (allFit) {
14041
- if (!first && h <= pageBottom - contTop && rowCells.some((c) => cellContentExtent(c) + c.marginT + c.marginB > avail)) {
14042
- page++;
14043
- y = contTop;
14044
- first = true;
14045
- break;
14046
- }
14047
- if (nested && avail > 0) {
14048
- pieces.push({ page, y, h: avail, range: new Map(rowCells.map((c) => [c.el, [from.get(c.el) ?? 0, Number.POSITIVE_INFINITY]])) });
14049
- for (const c of rowCells) from.set(c.el, Number.POSITIVE_INFINITY);
14050
- page++;
14051
- y = contTop;
14052
- first = true;
14053
- h -= avail;
14054
- continue;
14055
- }
14056
- h = avail;
14057
- break;
14058
- }
14059
- if (blocked && !first) {
14060
- page++;
14061
- y = contTop;
14062
- first = true;
14063
- continue;
14064
- }
14065
- if (!placed) {
14066
- if (first) break;
14067
- page++;
14068
- y = contTop;
14069
- first = true;
14070
- continue;
14027
+ pos = cursor + hmlFrac.length;
14028
+ }
14029
+ return out.join("") + eqString.slice(pos);
14030
+ }
14031
+ function replaceRootOf(eqString) {
14032
+ while (true) {
14033
+ const rootCursor = findKeywordToken(eqString, "root");
14034
+ if (rootCursor === -1) break;
14035
+ try {
14036
+ const elem1 = findBrackets(eqString, rootCursor);
14037
+ const ofCursor = findKeywordToken(eqString, "of", elem1[1]);
14038
+ if (ofCursor === -1) return eqString;
14039
+ const elem2 = findBrackets(eqString, ofCursor);
14040
+ const e1 = eqString.slice(elem1[0] + 1, elem1[1] - 1);
14041
+ const e2 = eqString.slice(elem2[0] + 1, elem2[1] - 1);
14042
+ eqString = eqString.slice(0, rootCursor) + "\\sqrt[" + e1 + "]{" + e2 + "}" + eqString.slice(elem2[1] + 1);
14043
+ } catch {
14044
+ return eqString;
14045
+ }
14046
+ }
14047
+ return eqString;
14048
+ }
14049
+ function replaceAllMatrix(eqString) {
14050
+ const replaceElements = (bracketStr) => {
14051
+ let inner = bracketStr.slice(1, -1);
14052
+ inner = inner.replace(/#/g, " \\\\ ");
14053
+ inner = inner.replace(/&amp;/g, "&");
14054
+ return inner;
14055
+ };
14056
+ const replaceMatrix = (input, matStr, matElem) => {
14057
+ while (true) {
14058
+ const cursor = input.indexOf(matStr);
14059
+ if (cursor === -1) break;
14060
+ try {
14061
+ const [eStart, eEnd] = findBrackets(input, cursor);
14062
+ const elem = replaceElements(input.slice(eStart, eEnd));
14063
+ let beforeMat;
14064
+ let afterMat;
14065
+ const outer = matElem.removeOutterBrackets ? findEnclosingBrackets(input, cursor) : null;
14066
+ if (outer && outer[1] >= eEnd) {
14067
+ const [bStart, bEnd] = outer;
14068
+ beforeMat = input.slice(0, bStart);
14069
+ afterMat = input.slice(bEnd);
14070
+ } else {
14071
+ beforeMat = input.slice(0, cursor);
14072
+ afterMat = input.slice(eEnd);
14071
14073
  }
14072
- pieces.push({ page, y, h: avail, range: new Map(cuts.map(([el, a, b]) => [el, [a, b]])) });
14073
- for (const [el, , b] of cuts) from.set(el, b);
14074
- page++;
14075
- y = contTop;
14076
- first = true;
14077
- h = rem;
14074
+ input = beforeMat + matElem.begin + elem + matElem.end + afterMat;
14075
+ } catch {
14076
+ return input;
14078
14077
  }
14079
- pieces.push({ page, y, h, range: new Map(rowCells.map((c) => [c.el, [from.get(c.el) ?? 0, Number.POSITIVE_INFINITY]])) });
14080
- out.push(pieces);
14081
- y += h;
14082
- first = false;
14083
- continue;
14084
- }
14085
- if (!first && y + h > pageBottom && r >= hdrRows) {
14086
- page++;
14087
- y = contTop;
14088
- first = true;
14089
14078
  }
14090
- out.push([{ page, y, h }]);
14091
- y += h;
14092
- first = false;
14079
+ return input;
14080
+ };
14081
+ for (const [matKey, matElem] of Object.entries(MATRIX_CONVERT_MAP)) {
14082
+ eqString = replaceMatrix(eqString, matKey, matElem);
14083
+ }
14084
+ return eqString;
14085
+ }
14086
+ function replaceAllBar(eqString) {
14087
+ const replaceBar = (input, barStr, barElem) => {
14088
+ while (true) {
14089
+ const cursor = input.indexOf(barStr);
14090
+ if (cursor === -1) break;
14091
+ try {
14092
+ const [eStart, eEnd] = findBrackets(input, cursor);
14093
+ const elem = input.slice(eStart, eEnd);
14094
+ const outer = findEnclosingBrackets(input, cursor);
14095
+ const [replaceStart, replaceEnd] = outer && outer[1] >= eEnd ? outer : [cursor, eEnd];
14096
+ const beforeBar = input.slice(0, replaceStart);
14097
+ const afterBar = input.slice(replaceEnd);
14098
+ input = beforeBar + barElem + elem + afterBar;
14099
+ } catch {
14100
+ return input;
14101
+ }
14102
+ }
14103
+ return input;
14104
+ };
14105
+ for (const [barKey, barElem] of Object.entries(BAR_CONVERT_MAP)) {
14106
+ eqString = replaceBar(eqString, barKey, barElem);
14093
14107
  }
14094
- return out;
14108
+ return eqString;
14095
14109
  }
14096
-
14097
- // src/render/shape-geometry.ts
14098
- var pt = (u) => String(Math.round(u) / 100);
14099
- var esc = (s) => s.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
14100
- var SHAPE_TAGS = /* @__PURE__ */ new Set(["rect", "ellipse", "line", "polygon", "curv", "curve", "arc"]);
14101
- function rotatedBounds(box, rotations) {
14102
- if (!rotations.length) return box;
14103
- 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]];
14104
- for (let i = rotations.length - 1; i >= 0; i--) {
14105
- const r = rotations[i];
14106
- if (Array.isArray(r)) {
14107
- points = points.map(([x2, y2]) => [r[0] * x2 + r[2] * y2 + r[4], r[1] * x2 + r[3] * y2 + r[5]]);
14108
- continue;
14110
+ function replaceAllBrace(eqString) {
14111
+ const replaceBrace = (input, braceStr, braceElem) => {
14112
+ while (true) {
14113
+ const cursor = input.indexOf(braceStr);
14114
+ if (cursor === -1) break;
14115
+ try {
14116
+ const [eStart1, eEnd1] = findBrackets(input, cursor);
14117
+ const [eStart2, eEnd2] = findBrackets(input, eEnd1);
14118
+ const elem1 = input.slice(eStart1, eEnd1);
14119
+ const elem2 = input.slice(eStart2, eEnd2);
14120
+ const beforeBrace = input.slice(0, cursor);
14121
+ const afterBrace = input.slice(eEnd2);
14122
+ input = beforeBrace + braceElem + elem1 + "^" + elem2 + afterBrace;
14123
+ } catch {
14124
+ return input;
14125
+ }
14109
14126
  }
14110
- const { angle, cx, cy } = r;
14111
- const a = angle * Math.PI / 180, c = Math.cos(a), s = Math.sin(a);
14112
- points = points.map(([x2, y2]) => [cx + c * (x2 - cx) - s * (y2 - cy), cy + s * (x2 - cx) + c * (y2 - cy)]);
14127
+ return input;
14128
+ };
14129
+ for (const [braceKey, braceElem] of Object.entries(BRACE_CONVERT_MAP)) {
14130
+ eqString = replaceBrace(eqString, braceKey, braceElem);
14113
14131
  }
14114
- const x = Math.min(...points.map((p) => p[0])), y = Math.min(...points.map((p) => p[1]));
14115
- return { x, y, w: Math.max(...points.map((p) => p[0])) - x, h: Math.max(...points.map((p) => p[1])) - y };
14116
- }
14117
- function mulAffine(m, n) {
14118
- return [
14119
- m[0] * n[0] + m[2] * n[1],
14120
- m[1] * n[0] + m[3] * n[1],
14121
- m[0] * n[2] + m[2] * n[3],
14122
- m[1] * n[2] + m[3] * n[3],
14123
- m[0] * n[4] + m[2] * n[5] + m[4],
14124
- m[1] * n[4] + m[3] * n[5] + m[5]
14125
- ];
14132
+ return eqString;
14126
14133
  }
14127
- function renderingMatrix(el) {
14128
- const info = findChildByLocalName(el, "renderingInfo");
14129
- if (!info) return null;
14130
- let m = null;
14131
- for (const c of elements(info)) {
14132
- const tag = ln(c);
14133
- if (tag !== "transMatrix" && tag !== "scaMatrix" && tag !== "rotMatrix") continue;
14134
- const n = [num(c, "e1", 1), num(c, "e4"), num(c, "e2"), num(c, "e5", 1), num(c, "e3"), num(c, "e6")];
14135
- m = m ? mulAffine(m, n) : n;
14134
+ function replaceBracket(strList) {
14135
+ for (let i = 0; i < strList.length; i++) {
14136
+ if (strList[i] === "{" && i > 0 && strList[i - 1] === "\\left") strList[i] = "\\{";
14137
+ if (strList[i] === "}" && i > 0 && strList[i - 1] === "\\right") strList[i] = "\\}";
14136
14138
  }
14137
- return m;
14138
- }
14139
- function objectGeometry(el, x, y, w, h, boxW = w, boxH = h) {
14140
- const rot = findChildByLocalName(el, "rotationInfo");
14141
- const angle = num(rot, "angle") % 360;
14142
- if (!angle) return { x, y, w, h, bbox: { x, y, w, h }, transform: "" };
14143
- const cx = x + boxW / 2, cy = y + boxH / 2;
14144
- const fx = cx - w / 2, fy = cy - h / 2;
14145
- const rotation = { angle, cx: Math.round(cx), cy: Math.round(cy) };
14146
- return { x: fx, y: fy, w, h, bbox: rotatedBounds({ x: fx, y: fy, w, h }, [rotation]), rotation, transform: `rotate(${angle} ${pt(cx)} ${pt(cy)})` };
14139
+ return strList;
14147
14140
  }
14148
- function shapeFill(el, defs, images, warn) {
14149
- const brush = findChildByLocalName(el, "fillBrush");
14150
- const win = brush && findChildByLocalName(brush, "winBrush");
14151
- const face = win?.getAttribute("faceColor");
14152
- if (docColor(face)) return esc(face);
14153
- const grad = brush && findChildByLocalName(brush, "gradation");
14154
- if (grad) {
14155
- const colors = elements(grad).filter((c) => ln(c) === "color").map((c) => docColor(c.getAttribute("value"), "#000000"));
14156
- if (!colors.length) return "none";
14157
- const type = grad.getAttribute("type") ?? "LINEAR";
14158
- if (type !== "LINEAR" && type !== "RADIAL") {
14159
- warn(`gradient:${type}`, `\uADF8\uB77C\uB370\uC774\uC158(${type}) \uBBF8\uC9C0\uC6D0 \u2014 \uCCAB \uC0C9\uC73C\uB85C \uCC44\uC6C0`);
14160
- return esc(colors[0]);
14161
- }
14162
- const id = `paint${defs.length}`;
14163
- const opacity = Math.max(0, Math.min(1, 1 - num(grad, "alpha") / 255));
14164
- const stops = colors.map((color, i) => `<stop offset="${colors.length === 1 ? 0 : i / (colors.length - 1)}" stop-color="${esc(color)}" stop-opacity="${opacity}"/>`).join("");
14165
- if (type === "RADIAL") defs.push(`<radialGradient id="${id}" cx="${num(grad, "centerX", 50)}%" cy="${num(grad, "centerY", 50)}%">${stops}</radialGradient>`);
14141
+ function hmlToLatex(hmlEqStr) {
14142
+ if (!hmlEqStr) return "";
14143
+ let s = hmlEqStr.replace(/[\r\n\t]+/g, " ").replace(/`/g, " ");
14144
+ s = s.replace(/\{/g, " { ").replace(/\}/g, " } ").replace(/&/g, " & ");
14145
+ let tokens = s.split(" ");
14146
+ for (let i = 0; i < tokens.length; i++) {
14147
+ const t = tokens[i];
14148
+ if (Object.hasOwn(CONVERT_MAP, t)) tokens[i] = CONVERT_MAP[t];
14149
+ else if (Object.hasOwn(MIDDLE_CONVERT_MAP, t)) tokens[i] = MIDDLE_CONVERT_MAP[t];
14166
14150
  else {
14167
- const a = num(grad, "angle") * Math.PI / 180, dx = Math.cos(a) / 2, dy = -Math.sin(a) / 2;
14168
- defs.push(`<linearGradient id="${id}" x1="${0.5 - dx}" y1="${0.5 - dy}" x2="${0.5 + dx}" y2="${0.5 + dy}">${stops}</linearGradient>`);
14169
- }
14170
- return `url(#${id})`;
14171
- }
14172
- const imgBrush = brush && findChildByLocalName(brush, "imgBrush");
14173
- const img = imgBrush && findChildByLocalName(imgBrush, "img");
14174
- if (imgBrush && img) {
14175
- const ref = img.getAttribute("binaryItemIDRef") ?? "";
14176
- const loaded = images.get(ref);
14177
- if (!loaded) {
14178
- warn(`brush-image:${ref}`, `\uADF8\uB9BC \uCC44\uC6C0 \uC774\uBBF8\uC9C0(${ref}) \uC5C6\uC74C \u2014 \uCC44\uC6C0 \uC0DD\uB7B5`);
14179
- return "none";
14180
- }
14181
- const mode = imgBrush.getAttribute("mode") ?? "TOTAL";
14182
- if (mode !== "TOTAL") {
14183
- warn(`brush-mode:${mode}`, `\uADF8\uB9BC \uCC44\uC6C0(${mode}) \uBBF8\uC9C0\uC6D0 \u2014 \uCC44\uC6C0 \uC0DD\uB7B5`);
14184
- return "none";
14151
+ const quoted = /^"(.+)"$/.exec(t);
14152
+ if (quoted) tokens[i] = `\\text{${quoted[1]}}`;
14185
14153
  }
14186
- if (loaded.paintId) return `url(#${loaded.paintId})`;
14187
- const id = `paint${defs.length}`;
14188
- defs.push(`<pattern id="${id}" width="1" height="1" patternContentUnits="objectBoundingBox"><image href="${esc(loaded.dataUri)}" width="1" height="1" preserveAspectRatio="none"/></pattern>`);
14189
- loaded.paintId = id;
14190
- return `url(#${id})`;
14191
14154
  }
14192
- return "none";
14155
+ tokens = tokens.filter((tok) => tok.length !== 0);
14156
+ tokens = replaceBracket(tokens);
14157
+ let out = tokens.join(" ");
14158
+ out = replaceFrac(out);
14159
+ out = replaceRootOf(out);
14160
+ out = replaceAllMatrix(out);
14161
+ out = replaceAllBar(out);
14162
+ out = replaceAllBrace(out);
14163
+ return out;
14193
14164
  }
14194
- function shapeGeometry(o, boxX, boxY, defs, images, warn, local = false) {
14195
- const el = o.el, org = findChildByLocalName(el, "orgSz"), cur = findChildByLocalName(el, "curSz");
14196
- const ow = num(org, "width"), oh = num(org, "height");
14197
- const w = (local ? ow : num(cur, "width")) || ow || num(cur, "width") || o.width;
14198
- const h = (local ? oh : num(cur, "height")) || oh || num(cur, "height") || o.height;
14199
- const geometry = local ? { x: boxX, y: boxY, w, h, bbox: { x: boxX, y: boxY, w, h }, transform: "" } : objectGeometry(el, boxX, boxY, w, h, o.width || w, o.height || h);
14200
- const { x, y } = geometry;
14201
- const sx = ow > 0 ? w / ow : 1, sy = oh > 0 ? h / oh : 1;
14202
- const line = findChildByLocalName(el, "lineShape"), style = line?.getAttribute("style") ?? "SOLID";
14203
- const color = esc(docColor(line?.getAttribute("color"), "#000000"));
14204
- const strokeW = style === "NONE" ? 0 : Math.max(0.2, num(line, "width", 33) / 100 * 2.834645);
14205
- const dash = /DASH|DOT/.test(style) ? ` stroke-dasharray="${style.includes("DOT") ? "1,1.5" : "3,1.5"}"` : "";
14206
- const keepWidth = local ? ` vector-effect="non-scaling-stroke"` : "";
14207
- const stroke = strokeW ? ` stroke="${color}" stroke-width="${strokeW.toFixed(2)}"${dash}${keepWidth}` : "";
14208
- const fill = ` fill="${shapeFill(el, defs, images, warn)}"`;
14209
- let svg = "";
14210
- if (o.tag === "rect") svg = `<rect x="${pt(x)}" y="${pt(y)}" width="${pt(w)}" height="${pt(h)}"${fill}${stroke}/>`;
14211
- 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}/>`;
14212
- else if (o.tag === "line") {
14213
- const s = findChildByLocalName(el, "startPt"), e = findChildByLocalName(el, "endPt");
14214
- 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}${keepWidth}/>`;
14215
- } else if (o.tag === "polygon" || o.tag === "curv") {
14216
- const pts = elements(el).filter((c) => ln(c) === "pt").map((c) => `${pt(x + num(c, "x") * sx)},${pt(y + num(c, "y") * sy)}`);
14217
- if (pts.length >= 2) svg = `<polygon points="${pts.join(" ")}"${fill}${stroke}/>`;
14218
- } else if (o.tag === "curve") {
14219
- const segs = elements(el).filter((c) => ln(c) === "seg");
14220
- if (segs.length) {
14221
- let path = "", lastX, lastY;
14222
- for (const s of segs) {
14223
- const x1 = num(s, "x1"), y1 = num(s, "y1"), x2 = num(s, "x2"), y2 = num(s, "y2");
14224
- if (x1 !== lastX || y1 !== lastY) path += `M${pt(x + x1 * sx)} ${pt(y + y1 * sy)}`;
14225
- path += `L${pt(x + x2 * sx)} ${pt(y + y2 * sy)}`;
14226
- lastX = x2;
14227
- lastY = y2;
14228
- }
14229
- svg = `<path d="${path}"${fill}${stroke}/>`;
14230
- }
14231
- } 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"`}/>`;
14232
- return { ...geometry, svg };
14165
+
14166
+ // src/hwp5/equation.ts
14167
+ var WORD_ALIASES = {
14168
+ // 삼각/로그 함수 — 정본 맵 부재
14169
+ sin: "\\sin",
14170
+ cos: "\\cos",
14171
+ tan: "\\tan",
14172
+ sec: "\\sec",
14173
+ csc: "\\csc",
14174
+ cot: "\\cot",
14175
+ log: "\\log",
14176
+ ln: "\\ln",
14177
+ // 연산자·관계 기호 (정본은 대문자 키만 보유)
14178
+ divide: "\\div",
14179
+ div: "\\div",
14180
+ le: "\\leq",
14181
+ ge: "\\geq",
14182
+ geq: "\\geq",
14183
+ deg: "^\\circ",
14184
+ rarrow: "\\rightarrow",
14185
+ lrarrow: "\\leftrightarrow",
14186
+ rightarrow: "\\rightarrow",
14187
+ leftarrow: "\\leftarrow",
14188
+ in: "\\in",
14189
+ notin: "\\notin",
14190
+ emptyset: "\\emptyset",
14191
+ subset: "\\subset",
14192
+ nsubset: "\\nsubseteq",
14193
+ cup: "\\cup",
14194
+ cap: "\\cap",
14195
+ smallinter: "\\cap",
14196
+ smallsum: "\\sum",
14197
+ sim: "\\sim",
14198
+ circ: "\\circ",
14199
+ bot: "\\perp",
14200
+ partial: "\\partial",
14201
+ nabla: "\\nabla",
14202
+ angle: "\\angle",
14203
+ triangle: "\\triangle",
14204
+ inf: "\\infty",
14205
+ left: "\\left",
14206
+ right: "\\right",
14207
+ // 글꼴 지시자 — 제거
14208
+ rm: "",
14209
+ it: ""
14210
+ };
14211
+ var STRUCTURAL_FOLD = /* @__PURE__ */ new Set(["over", "root", "of"]);
14212
+ function normalizeWords(input) {
14213
+ return input.replace(/(?<![\\A-Za-z0-9])([A-Za-z][A-Za-z0-9]*)(?![A-Za-z0-9])/g, (word) => {
14214
+ if (Object.hasOwn(CONVERT_MAP, word) || Object.hasOwn(MIDDLE_CONVERT_MAP, word)) return word;
14215
+ const lower = word.toLowerCase();
14216
+ if (STRUCTURAL_FOLD.has(lower)) return lower;
14217
+ if (Object.hasOwn(WORD_ALIASES, lower)) return WORD_ALIASES[lower];
14218
+ if (lower !== word && (Object.hasOwn(CONVERT_MAP, lower) || Object.hasOwn(MIDDLE_CONVERT_MAP, lower))) return lower;
14219
+ return word;
14220
+ });
14221
+ }
14222
+ function normalizeScripts(input) {
14223
+ return input.replace(/\s*\^\s*/g, "^").replace(/\s*_\s*/g, "_").replace(/\^(?!\{)([^\s{}_^]+)/g, "^{$1}").replace(/_(?!\{)([^\s{}_^]+)/g, "_{$1}").replace(/([_^])/g, " $1 ");
14224
+ }
14225
+ function normalizeOperators(input) {
14226
+ return input.replace(/\+-/g, " \\pm ").replace(/-\+/g, " \\mp ").replace(/\/\//g, " \\parallel ").replace(/!=/g, " \\neq ").replace(/<=/g, " \\leq ").replace(/>=/g, " \\geq ").replace(/==/g, " \\equiv ").replace(/△/g, " \\triangle ").replace(/□/g, " \\square ").replace(/‧/g, " \\cdot ");
14227
+ }
14228
+ function hwpEquationToLatex(equation) {
14229
+ let s = equation.replace(/\0/g, "").replace(/\s+/g, " ").trim();
14230
+ if (!s) return "";
14231
+ s = normalizeScripts(s);
14232
+ s = normalizeOperators(s);
14233
+ s = normalizeWords(s);
14234
+ s = s.replace(/\broot\s+(?!\{)(\S+)\s+of(?![A-Za-z0-9])/gi, "root { $1 } of");
14235
+ return hmlToLatex(s).replace(/\s+/g, " ").trim();
14233
14236
  }
14234
14237
 
14235
14238
  // src/render/object-anchor.ts
@@ -14275,7 +14278,7 @@ function anchorObject(o, ox, oy, baseV, areaW, ctx, anchorLineV, stayLine = fals
14275
14278
  return { x, y };
14276
14279
  }
14277
14280
 
14278
- // src/render/svg-render.ts
14281
+ // src/render/svg-content.ts
14279
14282
  function escapeXml(s) {
14280
14283
  return s.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g, "").replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
14281
14284
  }
@@ -14325,7 +14328,8 @@ function planLines(m, styles, numText = "") {
14325
14328
  const bu = geom?.bullet ?? (numText && geom?.number ? { ch: numText, ...geom.number } : void 0);
14326
14329
  const firstPr = m.chars.find((c) => c.ch !== "")?.prId ?? null;
14327
14330
  const bst = (bu?.charPrId != null ? styles.charPr.get(bu.charPrId) : firstPr != null ? styles.charPr.get(firstPr) : void 0) ?? DEFAULT_CHAR;
14328
- const bulletW = bu ? measureTextWidth(bu.ch, bst.height, bst.ratio, { spacingPct: bst.spacing, faceClass: faceClassOf(bst.face) }) + (bu.offsetPct ? Math.trunc(bst.height * bu.offset / 100) : bu.offset) : 0;
14331
+ const headW = bu?.useInstWidth === false ? [...bu.ch].reduce((w, ch) => w + glyphWidth(ch, bst, false).w, 0) : bu ? measureTextWidth(bu.ch, bst.height, bst.ratio, { spacingPct: bst.spacing, faceClass: faceClassOf(bst.face) }) : 0;
14332
+ const bulletW = bu ? paraHeadAdvance(bu, bst.height, headW) : 0;
14329
14333
  const plans = [];
14330
14334
  for (let i = 0; i < m.segs.length; i++) {
14331
14335
  const seg = m.segs[i];
@@ -14660,8 +14664,8 @@ function drawObject(o, x, y, baseV, areaW, ctx, depth) {
14660
14664
  x = ox;
14661
14665
  y = oy;
14662
14666
  }
14663
- if (o.tag === "tbl") drawTable(o.el, x, y, ctx, depth + 1);
14664
- else if (o.tag === "pic") drawPic(o.el, x, y, ctx);
14667
+ if (o.tag === "tbl") ctx.draw.table(o.el, x, y, ctx, depth + 1);
14668
+ else if (o.tag === "pic") ctx.draw.pic(o.el, x, y, ctx);
14665
14669
  else if (o.tag === "container") {
14666
14670
  if (drawGroupByMatrix(o, x, y, baseV, areaW, ctx, depth)) return;
14667
14671
  for (const ch of elements(o.el)) {
@@ -14717,7 +14721,7 @@ function drawGroupByMatrix(o, x, y, baseV, areaW, ctx, depth) {
14717
14721
  ctx.regionRotations.push(m);
14718
14722
  emit(ctx, `<g transform="matrix(${m.slice(0, 4).map((v) => Math.round(v * 1e6) / 1e6).join(" ")} ${pt2(m[4])} ${pt2(m[5])})">`);
14719
14723
  const sub = { el: leaf, tag, index: 0, inline: true, width: w, height: h, omL: 0, omR: 0 };
14720
- if (tag === "pic") drawPicFrame(leaf, 0, 0, w, h, "", ctx);
14724
+ if (tag === "pic") ctx.draw.picFrame(leaf, 0, 0, w, h, "", ctx);
14721
14725
  else if (SHAPE_TAGS.has(tag)) drawShape(sub, 0, 0, ctx, depth + 1, [Math.hypot(m[0], m[1]) || 1, Math.hypot(m[2], m[3]) || 1]);
14722
14726
  else drawObject(sub, 0, 0, baseV, areaW, ctx, depth + 1);
14723
14727
  emit(ctx, "</g>");
@@ -14765,6 +14769,8 @@ function drawShape(o, x, y, ctx, depth, groupScale) {
14765
14769
  ctx.parentStack.pop();
14766
14770
  emit(ctx, "</g>");
14767
14771
  }
14772
+
14773
+ // src/render/svg-render.ts
14768
14774
  function edgeLine(x1, y1, x2, y2, e) {
14769
14775
  const dash = /DASH|DOT/.test(e.type) ? ` stroke-dasharray="${e.type.includes("DOT") ? "1,1.5" : "3,1.5"}"` : "";
14770
14776
  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}/>`;
@@ -15379,6 +15385,7 @@ function drawPageNumbers(root, paraPages, ctx) {
15379
15385
  }
15380
15386
  function renderSectionRoots(sections, input) {
15381
15387
  const ctxBase = {
15388
+ draw: { table: drawTable, pic: drawPic, picFrame: drawPicFrame },
15382
15389
  styles: input.styles,
15383
15390
  images: input.images,
15384
15391
  defs: [],
@@ -19683,4 +19690,4 @@ export {
19683
19690
  cropRect,
19684
19691
  extractRenderedRegions
19685
19692
  };
19686
- //# sourceMappingURL=chunk-EVL6HZQL.js.map
19693
+ //# sourceMappingURL=chunk-U3GUZQ54.js.map