kordoc 4.17.2 → 4.17.3

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 (123) hide show
  1. package/dist/{-2UA2JHVA.js → -WP4ZCXHV.js} +11 -11
  2. package/dist/{chunk-HAW2VL62.cjs → chunk-2VMTMIGD.cjs} +12 -12
  3. package/dist/{chunk-HAW2VL62.cjs.map → chunk-2VMTMIGD.cjs.map} +1 -1
  4. package/dist/{chunk-5JZEY5IL.js → chunk-4PY2V33D.js} +2 -2
  5. package/dist/{chunk-A2W2JQ3S.js → chunk-5BDNDGUI.js} +2 -2
  6. package/dist/{chunk-O4CB7D2Q.js → chunk-5HIJXVED.js} +2 -2
  7. package/dist/chunk-BAEABKCB.js +170 -0
  8. package/dist/chunk-BAEABKCB.js.map +1 -0
  9. package/dist/{chunk-WJLICIYV.js → chunk-C3MC7HOB.js} +24 -21
  10. package/dist/{chunk-WJLICIYV.js.map → chunk-C3MC7HOB.js.map} +1 -1
  11. package/dist/{chunk-JY2NBFIG.js → chunk-CKF5HTM6.js} +6 -6
  12. package/dist/{chunk-YGKC6E6A.js → chunk-DPMDJYHX.js} +2 -2
  13. package/dist/chunk-DUHHMIPS.cjs +170 -0
  14. package/dist/chunk-DUHHMIPS.cjs.map +1 -0
  15. package/dist/{chunk-6OCKAXIS.js → chunk-EM2J3MAE.js} +2 -2
  16. package/dist/{chunk-GPC72VSF.cjs → chunk-HNPRQKLZ.cjs} +262 -171
  17. package/dist/chunk-HNPRQKLZ.cjs.map +1 -0
  18. package/dist/{chunk-MDCTITUG.js → chunk-JNCWHGJG.js} +2 -2
  19. package/dist/{chunk-C4MVZXB5.js → chunk-JORDNRVS.js} +2 -2
  20. package/dist/{chunk-ZDX5PIWR.js → chunk-JPQNRW7C.js} +2 -2
  21. package/dist/{chunk-WWMKIHF7.cjs → chunk-K2GXTJPK.cjs} +21 -21
  22. package/dist/{chunk-WWMKIHF7.cjs.map → chunk-K2GXTJPK.cjs.map} +1 -1
  23. package/dist/{chunk-4TSYMJDL.js → chunk-K7W5L4GI.js} +3 -3
  24. package/dist/{chunk-FGL4IGOT.js → chunk-OOUW3ROZ.js} +4 -4
  25. package/dist/{chunk-2XHXABCX.js → chunk-Q7SPGAAA.js} +2 -2
  26. package/dist/{chunk-XZA6X34R.js → chunk-TOPQ7T4N.js} +2 -2
  27. package/dist/{chunk-4HRJISJF.js → chunk-TTSXZO2A.js} +3 -3
  28. package/dist/{chunk-SDRKHEVT.js → chunk-UHGWEWZI.js} +255 -164
  29. package/dist/chunk-UHGWEWZI.js.map +1 -0
  30. package/dist/{chunk-VU26WGE5.js → chunk-UJZABAVA.js} +10 -10
  31. package/dist/{chunk-WL3BWROT.js → chunk-UTKVDI22.js} +22 -12
  32. package/dist/chunk-UTKVDI22.js.map +1 -0
  33. package/dist/{chunk-3N272C5L.js → chunk-VNDVI3MJ.js} +4 -4
  34. package/dist/{chunk-KQIYC2ZU.js → chunk-WFXZRYFS.js} +2 -2
  35. package/dist/{chunk-GYTL6WT3.js → chunk-YDWHS7FP.js} +3 -3
  36. package/dist/{chunk-6DOCSYEM.cjs → chunk-YKL7GP7E.cjs} +3 -3
  37. package/dist/{chunk-6DOCSYEM.cjs.map → chunk-YKL7GP7E.cjs.map} +1 -1
  38. package/dist/{chunk-KZVQK5NS.cjs → chunk-ZWPINXUX.cjs} +2 -2
  39. package/dist/{chunk-KZVQK5NS.cjs.map → chunk-ZWPINXUX.cjs.map} +1 -1
  40. package/dist/chunks-S7XODMX4.js +10 -0
  41. package/dist/cli.js +26 -26
  42. package/dist/{formula-MBLN2DG4.js → formula-H2NAOQHD.js} +4 -4
  43. package/dist/{formula-QZZDW5GW.js → formula-NZ7G4AXC.js} +3 -3
  44. package/dist/{formula-5RETDCIC.cjs → formula-Y3L3RPPI.cjs} +9 -9
  45. package/dist/{formula-5RETDCIC.cjs.map → formula-Y3L3RPPI.cjs.map} +1 -1
  46. package/dist/{image-ocr-EREKAS47.js → image-ocr-BGMQPELF.js} +6 -6
  47. package/dist/{image-ocr-PSPVRLB5.cjs → image-ocr-QYLWWB7R.cjs} +15 -15
  48. package/dist/{image-ocr-PSPVRLB5.cjs.map → image-ocr-QYLWWB7R.cjs.map} +1 -1
  49. package/dist/{image-ocr-CJSO3QSR.js → image-ocr-UTSJ2Q4Q.js} +9 -8
  50. package/dist/{image-ocr-CJSO3QSR.js.map → image-ocr-UTSJ2Q4Q.js.map} +1 -1
  51. package/dist/index.cjs +259 -259
  52. package/dist/index.cjs.map +1 -1
  53. package/dist/index.js +16 -16
  54. package/dist/mcp.js +22 -22
  55. package/dist/{model-bundle-MA4MMCRJ.js → model-bundle-QHZYIAUP.js} +5 -5
  56. package/dist/{models-SEJ7LNSN.js → models-MCBWWGBX.js} +5 -5
  57. package/dist/{parser-M5WHRX25.js → parser-72NGANOD.js} +11 -11
  58. package/dist/{parser-QILYPWSI.cjs → parser-BEPVGAMI.cjs} +114 -114
  59. package/dist/{parser-QILYPWSI.cjs.map → parser-BEPVGAMI.cjs.map} +1 -1
  60. package/dist/{parser-VH3F4EQU.js → parser-IGTNLJ6E.js} +12 -12
  61. package/dist/pdf-ocr-BW6RUT4H.cjs +16 -0
  62. package/dist/{pdf-ocr-3SZUM3CN.cjs.map → pdf-ocr-BW6RUT4H.cjs.map} +1 -1
  63. package/dist/pdf-ocr-EWG24RNY.js +15 -0
  64. package/dist/pdf-ocr-TCDSJFQT.js +19 -0
  65. package/dist/{profile-io-5YB627EO.js → profile-io-H2BCBNRL.js} +3 -3
  66. package/dist/{rasterize-V2XHHS2I.js → rasterize-HIEA3MGV.js} +3 -3
  67. package/dist/{redact-doc-5MK5L5IQ.js → redact-doc-MHIY4AWT.js} +11 -11
  68. package/dist/{render-SYZMHYK6.js → render-NIX6VP3C.js} +7 -7
  69. package/dist/seal-QTCJFT7G.js +10 -0
  70. package/dist/{setup-ZPLJENSK.js → setup-DU5WIHAX.js} +3 -3
  71. package/dist/visual-TU2BS63P.js +20 -0
  72. package/dist/{watch-FNWHVKK3.js → watch-XW6CSLL7.js} +12 -12
  73. package/package.json +1 -1
  74. package/dist/chunk-GPC72VSF.cjs.map +0 -1
  75. package/dist/chunk-SDRKHEVT.js.map +0 -1
  76. package/dist/chunk-UX3HHAWH.js +0 -248
  77. package/dist/chunk-UX3HHAWH.js.map +0 -1
  78. package/dist/chunk-WL3BWROT.js.map +0 -1
  79. package/dist/chunk-YIANW5QX.cjs +0 -248
  80. package/dist/chunk-YIANW5QX.cjs.map +0 -1
  81. package/dist/chunks-EBWJR55V.js +0 -10
  82. package/dist/pdf-ocr-3SZUM3CN.cjs +0 -16
  83. package/dist/pdf-ocr-QB2TB5W5.js +0 -18
  84. package/dist/pdf-ocr-XC33L43D.js +0 -15
  85. package/dist/seal-IPKIQHYB.js +0 -10
  86. package/dist/visual-RTTGNOAE.js +0 -20
  87. /package/dist/{-2UA2JHVA.js.map → -WP4ZCXHV.js.map} +0 -0
  88. /package/dist/{chunk-5JZEY5IL.js.map → chunk-4PY2V33D.js.map} +0 -0
  89. /package/dist/{chunk-A2W2JQ3S.js.map → chunk-5BDNDGUI.js.map} +0 -0
  90. /package/dist/{chunk-O4CB7D2Q.js.map → chunk-5HIJXVED.js.map} +0 -0
  91. /package/dist/{chunk-JY2NBFIG.js.map → chunk-CKF5HTM6.js.map} +0 -0
  92. /package/dist/{chunk-YGKC6E6A.js.map → chunk-DPMDJYHX.js.map} +0 -0
  93. /package/dist/{chunk-6OCKAXIS.js.map → chunk-EM2J3MAE.js.map} +0 -0
  94. /package/dist/{chunk-MDCTITUG.js.map → chunk-JNCWHGJG.js.map} +0 -0
  95. /package/dist/{chunk-C4MVZXB5.js.map → chunk-JORDNRVS.js.map} +0 -0
  96. /package/dist/{chunk-ZDX5PIWR.js.map → chunk-JPQNRW7C.js.map} +0 -0
  97. /package/dist/{chunk-4TSYMJDL.js.map → chunk-K7W5L4GI.js.map} +0 -0
  98. /package/dist/{chunk-FGL4IGOT.js.map → chunk-OOUW3ROZ.js.map} +0 -0
  99. /package/dist/{chunk-2XHXABCX.js.map → chunk-Q7SPGAAA.js.map} +0 -0
  100. /package/dist/{chunk-XZA6X34R.js.map → chunk-TOPQ7T4N.js.map} +0 -0
  101. /package/dist/{chunk-4HRJISJF.js.map → chunk-TTSXZO2A.js.map} +0 -0
  102. /package/dist/{chunk-VU26WGE5.js.map → chunk-UJZABAVA.js.map} +0 -0
  103. /package/dist/{chunk-3N272C5L.js.map → chunk-VNDVI3MJ.js.map} +0 -0
  104. /package/dist/{chunk-KQIYC2ZU.js.map → chunk-WFXZRYFS.js.map} +0 -0
  105. /package/dist/{chunk-GYTL6WT3.js.map → chunk-YDWHS7FP.js.map} +0 -0
  106. /package/dist/{chunks-EBWJR55V.js.map → chunks-S7XODMX4.js.map} +0 -0
  107. /package/dist/{formula-MBLN2DG4.js.map → formula-H2NAOQHD.js.map} +0 -0
  108. /package/dist/{formula-QZZDW5GW.js.map → formula-NZ7G4AXC.js.map} +0 -0
  109. /package/dist/{image-ocr-EREKAS47.js.map → image-ocr-BGMQPELF.js.map} +0 -0
  110. /package/dist/{model-bundle-MA4MMCRJ.js.map → model-bundle-QHZYIAUP.js.map} +0 -0
  111. /package/dist/{models-SEJ7LNSN.js.map → models-MCBWWGBX.js.map} +0 -0
  112. /package/dist/{parser-M5WHRX25.js.map → parser-72NGANOD.js.map} +0 -0
  113. /package/dist/{parser-VH3F4EQU.js.map → parser-IGTNLJ6E.js.map} +0 -0
  114. /package/dist/{pdf-ocr-QB2TB5W5.js.map → pdf-ocr-EWG24RNY.js.map} +0 -0
  115. /package/dist/{pdf-ocr-XC33L43D.js.map → pdf-ocr-TCDSJFQT.js.map} +0 -0
  116. /package/dist/{profile-io-5YB627EO.js.map → profile-io-H2BCBNRL.js.map} +0 -0
  117. /package/dist/{rasterize-V2XHHS2I.js.map → rasterize-HIEA3MGV.js.map} +0 -0
  118. /package/dist/{redact-doc-5MK5L5IQ.js.map → redact-doc-MHIY4AWT.js.map} +0 -0
  119. /package/dist/{render-SYZMHYK6.js.map → render-NIX6VP3C.js.map} +0 -0
  120. /package/dist/{seal-IPKIQHYB.js.map → seal-QTCJFT7G.js.map} +0 -0
  121. /package/dist/{setup-ZPLJENSK.js.map → setup-DU5WIHAX.js.map} +0 -0
  122. /package/dist/{visual-RTTGNOAE.js.map → visual-TU2BS63P.js.map} +0 -0
  123. /package/dist/{watch-FNWHVKK3.js.map → watch-XW6CSLL7.js.map} +0 -0
@@ -5,11 +5,11 @@ import {
5
5
  HEADING_RATIO_H2,
6
6
  HEADING_RATIO_H3,
7
7
  tidyScriptTags
8
- } from "./chunk-WL3BWROT.js";
8
+ } from "./chunk-UTKVDI22.js";
9
9
  import {
10
10
  safeMax,
11
11
  safeMin
12
- } from "./chunk-A2W2JQ3S.js";
12
+ } from "./chunk-5BDNDGUI.js";
13
13
 
14
14
  // src/pdf/line-extract.ts
15
15
  import { OPS } from "pdfjs-dist/legacy/build/pdf.mjs";
@@ -7404,4 +7404,4 @@ export {
7404
7404
  joinCellEdges,
7405
7405
  extractPageBlocksWithLines
7406
7406
  };
7407
- //# sourceMappingURL=chunk-4TSYMJDL.js.map
7407
+ //# sourceMappingURL=chunk-K7W5L4GI.js.map
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  extractPageBlocksWithLines
4
- } from "./chunk-4TSYMJDL.js";
4
+ } from "./chunk-K7W5L4GI.js";
5
5
  import {
6
6
  OCR_DET_MODEL,
7
7
  OCR_REC_DICT,
@@ -9,10 +9,10 @@ import {
9
9
  ensureOcrModels,
10
10
  getOcrModelsDir,
11
11
  parseCharacterDict
12
- } from "./chunk-KQIYC2ZU.js";
12
+ } from "./chunk-WFXZRYFS.js";
13
13
  import {
14
14
  OPTIONAL_DEP_INSTALL_HINT
15
- } from "./chunk-A2W2JQ3S.js";
15
+ } from "./chunk-5BDNDGUI.js";
16
16
 
17
17
  // src/ocr/ruling-lines.ts
18
18
  var INK_LUMA_MAX = 205;
@@ -2061,4 +2061,4 @@ export {
2061
2061
  runPdfOcr,
2062
2062
  ocrItemsToBlocks
2063
2063
  };
2064
- //# sourceMappingURL=chunk-FGL4IGOT.js.map
2064
+ //# sourceMappingURL=chunk-OOUW3ROZ.js.map
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  KordocError,
4
4
  unzipLimitBytes
5
- } from "./chunk-A2W2JQ3S.js";
5
+ } from "./chunk-5BDNDGUI.js";
6
6
 
7
7
  // src/hwpx/parser-shared.ts
8
8
  import { DOMParser } from "@xmldom/xmldom";
@@ -336,4 +336,4 @@ export {
336
336
  hwpFaceToCssStack,
337
337
  parseRenderStyles
338
338
  };
339
- //# sourceMappingURL=chunk-2XHXABCX.js.map
339
+ //# sourceMappingURL=chunk-Q7SPGAAA.js.map
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  assertNetworkAllowed
4
- } from "./chunk-6OCKAXIS.js";
4
+ } from "./chunk-EM2J3MAE.js";
5
5
 
6
6
  // src/pdf/formula/models.ts
7
7
  import { createHash as createHash2 } from "crypto";
@@ -294,4 +294,4 @@ export {
294
294
  ensureFormulaModels,
295
295
  ensureSingleModel
296
296
  };
297
- //# sourceMappingURL=chunk-XZA6X34R.js.map
297
+ //# sourceMappingURL=chunk-TOPQ7T4N.js.map
@@ -1,11 +1,11 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  parseRenderStyles
4
- } from "./chunk-2XHXABCX.js";
4
+ } from "./chunk-Q7SPGAAA.js";
5
5
  import {
6
6
  KordocError,
7
7
  precheckZipSize
8
- } from "./chunk-A2W2JQ3S.js";
8
+ } from "./chunk-5BDNDGUI.js";
9
9
 
10
10
  // src/form/seal.ts
11
11
  import JSZip from "jszip";
@@ -1057,4 +1057,4 @@ export {
1057
1057
  patchZipEntries,
1058
1058
  placeSealHwpx
1059
1059
  };
1060
- //# sourceMappingURL=chunk-4HRJISJF.js.map
1060
+ //# sourceMappingURL=chunk-TTSXZO2A.js.map
@@ -1,7 +1,49 @@
1
1
  import {
2
2
  escapeHtml,
3
3
  sanitizeHref
4
- } from "./chunk-YGKC6E6A.js";
4
+ } from "./chunk-DPMDJYHX.js";
5
+
6
+ // src/script-tags.ts
7
+ function wrapScript(text, kind) {
8
+ if (!kind) return text;
9
+ const m = /^(\s*)([\s\S]*?)(\s*)$/.exec(text);
10
+ return m[2] ? `${m[1]}<${kind}>${m[2]}</${kind}>${m[3]}` : text;
11
+ }
12
+ function tidyScriptTags(text) {
13
+ if (!text.includes("<su")) return text;
14
+ return text.replace(/<\/(sup|sub)><\1>/g, "").replace(/<(sup|sub)>(\s+)/g, "$2<$1>").replace(/(\s+)<\/(sup|sub)>/g, "</$2>$1").replace(/<(sup|sub)><\/\1>/g, "");
15
+ }
16
+ function plainScripts(md) {
17
+ if (!md.includes("<su")) return md;
18
+ return md.replace(/<(sup|sub)>([^<\n]*)<\/\1>/g, (_, kind, body) => {
19
+ const mark = kind === "sup" ? "^" : "_";
20
+ return /^(?:[+\-−]?[\p{L}\p{N}]+|[*∗†‡§¶]+)$/u.test(body) ? mark + body : `${mark}(${body})`;
21
+ });
22
+ }
23
+ var TAG_RE = /<\/?su[bp]>/g;
24
+ function stripScriptTags(r) {
25
+ const s = (t) => t.includes("<su") ? t.replace(TAG_RE, "") : t;
26
+ const walk = (bs) => {
27
+ for (const b of bs ?? []) {
28
+ if (b.text) b.text = s(b.text);
29
+ if (b.footnoteText) b.footnoteText = s(b.footnoteText);
30
+ for (const sp of b.spans ?? []) sp.text = s(sp.text);
31
+ walk(b.children);
32
+ if (b.table) {
33
+ if (b.table.caption) b.table.caption = s(b.table.caption);
34
+ walk(b.table.captionBlocks);
35
+ for (const row of b.table.cells) for (const c of row) {
36
+ c.text = s(c.text);
37
+ walk(c.blocks);
38
+ }
39
+ }
40
+ }
41
+ };
42
+ walk(r.blocks);
43
+ if (r.markdown) r.markdown = s(r.markdown);
44
+ for (const p of r.pages ?? []) p.markdown = s(p.markdown);
45
+ return r;
46
+ }
5
47
 
6
48
  // src/shared/symbol-fonts.ts
7
49
  var WINGDINGS = [
@@ -751,9 +793,9 @@ function blocksToMarkdown(blocks) {
751
793
  }
752
794
  continue;
753
795
  }
754
- if (block.type === "paragraph" && block.text) {
755
- let text = sanitizeText(block.text);
756
- if (!text) continue;
796
+ if (block.type === "paragraph" && (block.text || block.footnoteText)) {
797
+ let text = sanitizeText(block.text ?? "");
798
+ if (!text && !block.footnoteText) continue;
757
799
  if (/^\[별표\s*\d+/.test(text)) {
758
800
  const nextBlock = blocks[i + 1];
759
801
  if (nextBlock?.type === "paragraph" && nextBlock.text && /관련\)?$/.test(nextBlock.text)) {
@@ -802,13 +844,14 @@ function blocksToMarkdown(blocks) {
802
844
  return lines.join("\n").trim();
803
845
  }
804
846
  function captionToMarkdown(table) {
805
- if (table.captionBlocks?.some((b) => b.type === "table" && b.table)) {
847
+ if (table.captionBlocks?.length) {
806
848
  return table.captionBlocks.flatMap((b) => {
807
849
  if (b.type === "table" && b.table) {
808
850
  const md = tableToMarkdown(b.table);
809
851
  return [...captionToMarkdown(b.table), ...md ? [md, ""] : []];
810
852
  }
811
- const t = sanitizeText(b.text ?? "");
853
+ if (b.type === "image" && b.text) return [blocksToMarkdown([b]), ""];
854
+ const t = (sanitizeText(visibleText(b)) + noteSuffix(b)).trim();
812
855
  return t ? [`**${escapeGfm(t)}**`, ""] : [];
813
856
  });
814
857
  }
@@ -816,16 +859,7 @@ function captionToMarkdown(table) {
816
859
  return caption ? [`**${escapeGfm(caption)}**`, ""] : [];
817
860
  }
818
861
  function captionToHtml(table) {
819
- if (table.captionBlocks?.some((b) => b.type === "table" && b.table)) {
820
- return table.captionBlocks.map((b) => {
821
- if (b.type === "table" && b.table) {
822
- const cap2 = captionToHtml(b.table);
823
- return (cap2 ? cap2 + "<br>" : "") + tableToHtml(b.table);
824
- }
825
- const t = sanitizeText(b.text ?? "");
826
- return t ? escapeHtmlCellText(t).replace(/\n/g, "<br>") : "";
827
- }).filter(Boolean).join("<br>");
828
- }
862
+ if (table.captionBlocks?.length) return cellInnerHtml({ text: "", colSpan: 1, rowSpan: 1, blocks: table.captionBlocks });
829
863
  const cap = table.caption ? sanitizeText(table.caption) : "";
830
864
  return cap ? escapeHtmlCellText(cap).replace(/\n/g, "<br>") : "";
831
865
  }
@@ -846,7 +880,7 @@ function hasStructuredCellContent(table) {
846
880
  return false;
847
881
  }
848
882
  function noteSuffix(b) {
849
- return b.footnoteText && b.text ? ` (\uC8FC: ${b.footnoteText})` : "";
883
+ return b.footnoteText ? ` (\uC8FC: ${b.footnoteText})` : "";
850
884
  }
851
885
  function visibleText(b) {
852
886
  return b.spans?.some((s) => s.placeholder) ? b.spans.filter((s) => !s.placeholder).map((s) => s.text).join("") : b.text ?? "";
@@ -862,8 +896,8 @@ function cellInnerHtml(cell) {
862
896
  return (cap ? cap + "<br>" : "") + tableToHtml(b.table);
863
897
  }
864
898
  if (b.type === "image" && b.text) return `<img src="${escapeHtml(b.text, true)}" alt="image">`;
865
- const t = sanitizeText(visibleText(b));
866
- return t ? escapeHtmlCellText(t + noteSuffix(b)).replace(/\n/g, "<br>") : "";
899
+ const t = (sanitizeText(visibleText(b)) + noteSuffix(b)).trim();
900
+ return t ? escapeHtmlCellText(t).replace(/\n/g, "<br>") : "";
867
901
  }).filter(Boolean).join("<br>");
868
902
  }
869
903
  return escapeHtmlCellText(sanitizeText(cell.text)).replace(/\n/g, "<br>");
@@ -897,12 +931,22 @@ function tableToHtml(table) {
897
931
  lines.push("</table>");
898
932
  return lines.join("\n");
899
933
  }
934
+ function hasInlineCellBlocks(cell) {
935
+ return !!cell.blocks?.some((b) => b.spans?.length || b.footnoteText || b.type === "image" && b.text);
936
+ }
937
+ function cellToMarkdown(cell, separator) {
938
+ if (!hasInlineCellBlocks(cell)) return escapeGfm(sanitizeText(cell.text));
939
+ return cell.blocks.map((b) => b.type === "image" && b.text ? `![image](${b.text})` : b.spans?.length ? spansToMarkdown(b.spans) + escapeGfm(noteSuffix(b)) : escapeGfm(sanitizeText(b.text ?? "") + noteSuffix(b))).filter(Boolean).join(separator);
940
+ }
900
941
  function tableToMarkdown(table) {
901
942
  if (table.rows === 0 || table.cols === 0) return "";
902
943
  const { cells, rows: numRows, cols: numCols } = table;
903
944
  if (hasStructuredCellContent(table)) return tableToHtml(table);
904
945
  if (table.renderAsTable) return tableToHtml(table);
905
946
  if (hasMergedCells(table)) return tableToHtml(table);
947
+ if (numCols === 1 && cells.some((row) => row[0] && hasInlineCellBlocks(row[0]))) {
948
+ return cells.map((row) => cellToMarkdown(row[0], "\n")).filter(Boolean).join("\n");
949
+ }
906
950
  if (numRows === 1 && numCols === 1) {
907
951
  const content = sanitizeText(cells[0][0].text);
908
952
  if (!content) return "";
@@ -924,7 +968,7 @@ function tableToMarkdown(table) {
924
968
  if (skip.has(`${r},${c}`)) continue;
925
969
  const cell = cells[r]?.[c];
926
970
  if (!cell) continue;
927
- display[r][c] = (cell.blocks?.some((b) => b.spans || b.type === "image" && b.text) ? cell.blocks.map((b) => b.type === "image" && b.text ? `![image](${b.text})` : b.spans ? spansToMarkdown(b.spans) + escapeGfm(noteSuffix(b)) : escapeGfm(sanitizeText(b.text ?? "") + noteSuffix(b))).filter(Boolean).join("<br>") : escapeGfm(sanitizeText(cell.text))).replace(/\n/g, "<br>").replace(/(?<!\\)\|/g, "\\|");
971
+ display[r][c] = cellToMarkdown(cell, "<br>").replace(/\n/g, "<br>").replace(/(?<!\\)\|/g, "\\|");
928
972
  for (let dr = 0; dr < cell.rowSpan; dr++) {
929
973
  for (let dc = 0; dc < cell.colSpan; dc++) {
930
974
  if (dr === 0 && dc === 0) continue;
@@ -952,167 +996,211 @@ function tableToMarkdown(table) {
952
996
  return md.join("\n");
953
997
  }
954
998
 
955
- // src/page-markdown.ts
956
- function blocksToPages(blocks, render = blocksToMarkdown) {
957
- const firstNumbered = blocks.find((b) => typeof b.pageNumber === "number")?.pageNumber;
958
- if (firstNumbered === void 0) return void 0;
959
- const byPage = /* @__PURE__ */ new Map();
960
- let current = firstNumbered;
961
- for (const block of blocks) {
962
- if (typeof block.pageNumber === "number") current = block.pageNumber;
963
- const bucket = byPage.get(current);
964
- if (bucket) bucket.push(block);
965
- else byPage.set(current, [block]);
966
- }
967
- const numbers = [...byPage.keys()];
968
- const min = Math.min(...numbers);
969
- const max = Math.max(...numbers);
970
- const pages = [];
971
- for (let pageNumber = min; pageNumber <= max; pageNumber++) {
972
- const pageBlocks = byPage.get(pageNumber);
973
- pages.push({ pageNumber, markdown: pageBlocks ? render(pageBlocks) : "" });
999
+ // src/table/layout-frames.ts
1000
+ var CELL_EDGES = /* @__PURE__ */ new WeakMap();
1001
+ var CONTENT_CELLS = /* @__PURE__ */ new WeakSet();
1002
+ var FRACTION_MAX_CHARS = 40;
1003
+ function anchorsOf(t) {
1004
+ const out = [];
1005
+ const covered = /* @__PURE__ */ new Set();
1006
+ for (let r = 0; r < t.rows; r++) for (let c = 0; c < t.cols; c++) {
1007
+ if (covered.has(r * t.cols + c)) continue;
1008
+ const cell = t.cells[r]?.[c];
1009
+ if (!cell) continue;
1010
+ const rs = Math.max(1, Math.min(cell.rowSpan, t.rows - r)), cs = Math.max(1, Math.min(cell.colSpan, t.cols - c));
1011
+ for (let dr = 0; dr < rs; dr++) for (let dc = 0; dc < cs; dc++) covered.add((r + dr) * t.cols + c + dc);
1012
+ out.push({ r, c, rs, cs, cell });
974
1013
  }
975
- return pages;
1014
+ return out;
976
1015
  }
977
-
978
- // src/image/transcode.ts
979
- import { deflateSync } from "zlib";
980
- var CRC_TABLE = (() => {
981
- const table = new Uint32Array(256);
982
- for (let n = 0; n < 256; n++) {
983
- let c = n;
984
- for (let k = 0; k < 8; k++) {
985
- c = c & 1 ? 3988292384 ^ c >>> 1 : c >>> 1;
1016
+ function ruleGrids(t, anchors) {
1017
+ const H = Array.from({ length: t.rows + 1 }, () => new Array(t.cols).fill(false));
1018
+ const V = Array.from({ length: t.rows }, () => new Array(t.cols + 1).fill(false));
1019
+ for (const a of anchors) {
1020
+ const e = CELL_EDGES.get(a.cell) ?? { t: true, b: true, l: true, r: true };
1021
+ for (let c = a.c; c < a.c + a.cs; c++) {
1022
+ if (e.t) H[a.r][c] = true;
1023
+ if (e.b) H[a.r + a.rs][c] = true;
1024
+ }
1025
+ for (let r = a.r; r < a.r + a.rs; r++) {
1026
+ if (e.l) V[r][a.c] = true;
1027
+ if (e.r) V[r][a.c + a.cs] = true;
986
1028
  }
987
- table[n] = c >>> 0;
988
1029
  }
989
- return table;
990
- })();
991
- function crc32(bytes) {
992
- let c = 4294967295;
993
- for (let i = 0; i < bytes.length; i++) {
994
- c = CRC_TABLE[(c ^ bytes[i]) & 255] ^ c >>> 8;
1030
+ return { H, V };
1031
+ }
1032
+ function toTex(s) {
1033
+ return s.replace(/<\/?u>/g, "").replace(/([\\{}%#&_$])/g, "\\$1").replace(/<sup>(.*?)<\/sup>/g, "^{$1}").replace(/<sub>(.*?)<\/sub>/g, "_{$1}").replace(/[가-힣ㄱ-ㅎㅏ-ㅣ][가-힣ㄱ-ㅎㅏ-ㅣ\s·ㆍ]*/g, (m) => `\\text{${m.trim()}}`).trim();
1034
+ }
1035
+ function fractionPart(cell) {
1036
+ const t = cell.text.trim();
1037
+ return !!t && !t.includes("\n") && !cell.blocks?.length && t.replace(/<\/?(?:u|sup|sub)>/g, "").length <= FRACTION_MAX_CHARS && !/(?<!\\)\$/.test(t);
1038
+ }
1039
+ function mergeFractions(t, anchors, H, V) {
1040
+ const at = /* @__PURE__ */ new Map();
1041
+ for (const a of anchors) at.set(a.r * t.cols + a.c, a);
1042
+ let merged = false;
1043
+ for (const u of anchors) {
1044
+ const d = at.get((u.r + u.rs) * t.cols + u.c);
1045
+ if (!d || d.cs !== u.cs || u.rs !== 1 || d.rs !== 1 || !fractionPart(u.cell) || !fractionPart(d.cell)) continue;
1046
+ if (u.cs === t.cols && anchors.length !== 2) continue;
1047
+ const bar = d.r, c1 = u.c, c2 = u.c + u.cs;
1048
+ let ok = true;
1049
+ for (let c = c1; c < c2 && ok; c++) if (!H[bar][c]) ok = false;
1050
+ if (!ok || c1 > 0 && H[bar][c1 - 1] || c2 < t.cols && H[bar][c2]) continue;
1051
+ for (let c = c1; c < c2 && ok; c++) if (H[u.r][c] || H[d.r + d.rs][c]) ok = false;
1052
+ for (let r = u.r; r < d.r + d.rs && ok; r++) if (V[r][c1] || V[r][c2]) ok = false;
1053
+ if (!ok) continue;
1054
+ u.cell.text = `$\\frac{${toTex(u.cell.text)}}{${toTex(d.cell.text)}}$`;
1055
+ u.cell.rowSpan = u.rs + d.rs;
1056
+ t.cells[d.r][d.c] = { text: "", colSpan: 1, rowSpan: 1 };
1057
+ at.delete(d.r * t.cols + d.c);
1058
+ merged = true;
995
1059
  }
996
- return (c ^ 4294967295) >>> 0;
1060
+ return merged;
997
1061
  }
998
- var BI_RGB = 0;
999
- var MAX_DIM = 32767;
1000
- var MAX_PIXELS = 36e6;
1001
- function bmpToPng(bmp) {
1002
- if (bmp.length < 54) return null;
1003
- if (bmp[0] !== 66 || bmp[1] !== 77) return null;
1004
- const dv = new DataView(bmp.buffer, bmp.byteOffset, bmp.byteLength);
1005
- const dataOffset = dv.getUint32(10, true);
1006
- const headerSize = dv.getUint32(14, true);
1007
- if (headerSize < 40) return null;
1008
- const width = dv.getInt32(18, true);
1009
- const rawHeight = dv.getInt32(22, true);
1010
- const bitCount = dv.getUint16(28, true);
1011
- const compression = dv.getUint32(30, true);
1012
- if (compression !== BI_RGB) return null;
1013
- if (bitCount !== 24 && bitCount !== 32) return null;
1014
- if (width <= 0 || rawHeight === 0) return null;
1015
- if (width > MAX_DIM || Math.abs(rawHeight) > MAX_DIM) return null;
1016
- const topDown = rawHeight < 0;
1017
- const height = Math.abs(rawHeight);
1018
- if (width * height > MAX_PIXELS) return null;
1019
- const bytesPerPixel = bitCount >> 3;
1020
- const rowStride = width * bytesPerPixel + 3 & ~3;
1021
- if (dataOffset + rowStride * height > bmp.length) return null;
1022
- const rgba = new Uint8Array(width * height * 4);
1023
- let anyAlpha = 0;
1024
- for (let y = 0; y < height; y++) {
1025
- const srcRow = topDown ? y : height - 1 - y;
1026
- let src = dataOffset + srcRow * rowStride;
1027
- let dst = y * width * 4;
1028
- for (let x = 0; x < width; x++) {
1029
- rgba[dst] = bmp[src + 2];
1030
- rgba[dst + 1] = bmp[src + 1];
1031
- rgba[dst + 2] = bmp[src];
1032
- const a = bitCount === 32 ? bmp[src + 3] : 255;
1033
- rgba[dst + 3] = a;
1034
- anyAlpha |= a;
1035
- src += bytesPerPixel;
1036
- dst += 4;
1062
+ function ruledRows(t, anchors, H, V) {
1063
+ const inRow = new Array(t.rows).fill(0);
1064
+ for (const a of anchors) for (let r = a.r; r < a.r + a.rs; r++) inRow[r]++;
1065
+ return Array.from({ length: t.rows }, (_, r) => V[r].some(Boolean) || inRow[r] >= 2 && H[r].every(Boolean) && H[r + 1].every(Boolean));
1066
+ }
1067
+ function bandTable(t, anchors, V, H, r0, r1, keepEmptyCols) {
1068
+ let list = anchors.filter((a) => a.r >= r0 && a.r <= r1).map((a) => ({ ...a, rs: Math.min(a.rs, r1 - a.r + 1) }));
1069
+ const blank = (a) => {
1070
+ if (CONTENT_CELLS.has(a.cell)) return false;
1071
+ if (!a.cell.blocks?.length) return !a.cell.text.trim();
1072
+ return a.cell.blocks.every((b) => (b.type === "paragraph" || b.type === "heading") && !visibleText(b).trim() && !b.footnoteText);
1073
+ };
1074
+ let lo = Infinity, hi = -Infinity;
1075
+ for (let r = r0; r <= r1; r++) {
1076
+ for (let c = 0; c <= t.cols; c++) if (V[r][c]) {
1077
+ lo = Math.min(lo, c);
1078
+ hi = Math.max(hi, c);
1079
+ }
1080
+ for (const rr of [r, r + 1]) for (let c = 0; c < t.cols; c++) if (H[rr][c]) {
1081
+ lo = Math.min(lo, c);
1082
+ hi = Math.max(hi, c + 1);
1037
1083
  }
1038
1084
  }
1039
- if (bitCount === 32 && anyAlpha === 0) {
1040
- for (let i = 3; i < rgba.length; i += 4) rgba[i] = 255;
1085
+ if (Number.isFinite(lo)) list = list.filter((a) => a.c < hi && a.c + a.cs > lo || !blank(a));
1086
+ if (!list.length) return null;
1087
+ const drop = [];
1088
+ for (let r = r0; r <= r1; r++) {
1089
+ const starts = list.filter((a) => a.r === r);
1090
+ if (starts.length && (!H[r].some(Boolean) || !H[r + 1].some(Boolean)) && starts.every(blank)) drop.push(r);
1091
+ }
1092
+ if (drop.length) {
1093
+ const shift = (y) => y - drop.filter((d) => d < y).length;
1094
+ list = list.filter((a) => !drop.includes(a.r)).map((a) => ({ ...a, r: shift(a.r), rs: shift(a.r + a.rs) - shift(a.r) })).filter((a) => a.rs > 0);
1041
1095
  }
1042
- return encodePng(width, height, rgba);
1096
+ for (let right = keepEmptyCols ? 0 : Math.max(...list.map((a) => a.c + a.cs)); right > 1; ) {
1097
+ const starts = list.filter((a) => a.c === right - 1);
1098
+ if (!starts.length || !starts.every(blank)) break;
1099
+ list = list.filter((a) => a.c !== right - 1).map((a) => a.c + a.cs === right ? { ...a, cs: a.cs - 1 } : a);
1100
+ right--;
1101
+ }
1102
+ const colB = /* @__PURE__ */ new Set(), rowB = /* @__PURE__ */ new Set();
1103
+ for (const a of list) {
1104
+ colB.add(a.c);
1105
+ colB.add(a.c + a.cs);
1106
+ rowB.add(a.r);
1107
+ rowB.add(a.r + a.rs);
1108
+ }
1109
+ const cx = [...colB].sort((x, y) => x - y), rx = [...rowB].sort((x, y) => x - y);
1110
+ const cols = cx.length - 1, rows = rx.length - 1;
1111
+ if (cols < 1 || rows < 1) return null;
1112
+ const cells = Array.from({ length: rows }, () => Array.from({ length: cols }, () => ({ text: "", colSpan: 1, rowSpan: 1 })));
1113
+ for (const a of list) {
1114
+ const r = rx.indexOf(a.r), c = cx.indexOf(a.c);
1115
+ a.cell.rowSpan = rx.indexOf(a.r + a.rs) - r;
1116
+ a.cell.colSpan = cx.indexOf(a.c + a.cs) - c;
1117
+ cells[r][c] = a.cell;
1118
+ }
1119
+ return { rows, cols, cells, hasHeader: t.hasHeader };
1043
1120
  }
1044
- var PNG_SIGNATURE = Uint8Array.of(137, 80, 78, 71, 13, 10, 26, 10);
1045
- function chunk(type, data) {
1046
- const body = new Uint8Array(4 + data.length);
1047
- body[0] = type.charCodeAt(0);
1048
- body[1] = type.charCodeAt(1);
1049
- body[2] = type.charCodeAt(2);
1050
- body[3] = type.charCodeAt(3);
1051
- body.set(data, 4);
1052
- const out = new Uint8Array(8 + data.length + 4);
1053
- const dv = new DataView(out.buffer);
1054
- dv.setUint32(0, data.length, false);
1055
- out.set(body, 4);
1056
- dv.setUint32(8 + data.length, crc32(body), false);
1057
- return out;
1121
+ function textRow(row, out, pageNumber, keepEmptyCols) {
1122
+ const parts = [];
1123
+ const flush = () => {
1124
+ if (!parts.length) return;
1125
+ if (parts.length === 1) {
1126
+ for (const line of parts[0].split("\n")) if (line.trim()) out.push({ type: "paragraph", text: line.trim(), pageNumber });
1127
+ } else {
1128
+ const text = parts.map((p) => p.replace(/\s*\n\s*/g, " ").trim()).filter(Boolean).join(" ");
1129
+ if (text) out.push({ type: "paragraph", text, pageNumber });
1130
+ }
1131
+ parts.length = 0;
1132
+ };
1133
+ for (const a of row) {
1134
+ if (a.cell.blocks?.length) {
1135
+ flush();
1136
+ out.push(...unframeLayoutTables(a.cell.blocks, keepEmptyCols));
1137
+ continue;
1138
+ }
1139
+ if (a.cell.text.trim()) parts.push(a.cell.text.trim());
1140
+ }
1141
+ flush();
1058
1142
  }
1059
- function encodePng(width, height, rgba) {
1060
- const ihdr = new Uint8Array(13);
1061
- const iv = new DataView(ihdr.buffer);
1062
- iv.setUint32(0, width, false);
1063
- iv.setUint32(4, height, false);
1064
- ihdr[8] = 8;
1065
- ihdr[9] = 6;
1066
- const stride = width * 4;
1067
- const raw = new Uint8Array((stride + 1) * height);
1068
- for (let y = 0; y < height; y++) {
1069
- const rowStart = y * (stride + 1);
1070
- raw[rowStart] = 0;
1071
- raw.set(rgba.subarray(y * stride, y * stride + stride), rowStart + 1);
1143
+ function unframeTable(t, pageNumber, keepEmptyCols) {
1144
+ let anchors = anchorsOf(t);
1145
+ if (!anchors.some((a) => CELL_EDGES.has(a.cell))) return null;
1146
+ let { H, V } = ruleGrids(t, anchors);
1147
+ if (mergeFractions(t, anchors, H, V)) {
1148
+ anchors = anchorsOf(t);
1149
+ ({ H, V } = ruleGrids(t, anchors));
1150
+ }
1151
+ const ruled = ruledRows(t, anchors, H, V);
1152
+ if (ruled.every(Boolean)) {
1153
+ const whole = bandTable(t, anchors, V, H, 0, t.rows - 1, keepEmptyCols);
1154
+ if (!whole || whole.rows === t.rows && whole.cols === t.cols) return null;
1155
+ return [{ type: "table", table: { ...t, rows: whole.rows, cols: whole.cols, cells: whole.cells }, pageNumber }];
1156
+ }
1157
+ const out = [];
1158
+ if (t.captionBlocks?.length) out.push(...t.captionBlocks);
1159
+ else if (t.caption) out.push({ type: "paragraph", text: t.caption, pageNumber });
1160
+ for (let r = 0; r < t.rows; ) {
1161
+ if (ruled[r]) {
1162
+ let r1 = r;
1163
+ while (r1 + 1 < t.rows && ruled[r1 + 1]) r1++;
1164
+ const sub = bandTable(t, anchors, V, H, r, r1, keepEmptyCols);
1165
+ if (sub) out.push({ type: "table", table: sub, pageNumber });
1166
+ r = r1 + 1;
1167
+ continue;
1168
+ }
1169
+ textRow(anchors.filter((a) => a.r === r).sort((x, y) => x.c - y.c), out, pageNumber, keepEmptyCols);
1170
+ r++;
1072
1171
  }
1073
- const idat = deflateSync(raw);
1074
- const ihdrChunk = chunk("IHDR", ihdr);
1075
- const idatChunk = chunk("IDAT", idat);
1076
- const iendChunk = chunk("IEND", new Uint8Array(0));
1077
- const out = new Uint8Array(PNG_SIGNATURE.length + ihdrChunk.length + idatChunk.length + iendChunk.length);
1078
- let o = 0;
1079
- out.set(PNG_SIGNATURE, o);
1080
- o += PNG_SIGNATURE.length;
1081
- out.set(ihdrChunk, o);
1082
- o += ihdrChunk.length;
1083
- out.set(idatChunk, o);
1084
- o += idatChunk.length;
1085
- out.set(iendChunk, o);
1086
1172
  return out;
1087
1173
  }
1088
- function inlineImagesIntoMarkdown(markdown, images, opts) {
1089
- const compress = opts?.compress !== false;
1090
- const uris = /* @__PURE__ */ new Map();
1091
- for (const img of images) {
1092
- let bytes = img.data;
1093
- let mime = img.mimeType;
1094
- if (compress && mime === "image/bmp") {
1095
- const png = bmpToPng(img.data);
1096
- if (png) {
1097
- bytes = png;
1098
- mime = "image/png";
1174
+ function unframeLayoutTables(blocks, keepEmptyCols = false) {
1175
+ const out = [];
1176
+ for (const b of blocks) {
1177
+ if (b.type !== "table" || !b.table) {
1178
+ out.push(b);
1179
+ continue;
1180
+ }
1181
+ if (b.table.captionBlocks?.length) b.table.captionBlocks = unframeLayoutTables(b.table.captionBlocks, keepEmptyCols);
1182
+ const flat = unframeTable(b.table, b.pageNumber, keepEmptyCols);
1183
+ const kept = flat ?? [b];
1184
+ for (const k of kept) {
1185
+ if (k.type === "table" && k.table) {
1186
+ for (const row of k.table.cells) for (const cell of row) if (cell.blocks?.length) cell.blocks = unframeLayoutTables(cell.blocks, keepEmptyCols);
1099
1187
  }
1188
+ out.push(k);
1100
1189
  }
1101
- uris.set(img.filename, `data:${mime};base64,${Buffer.from(bytes).toString("base64")}`);
1102
1190
  }
1103
- if (uris.size === 0) return markdown;
1104
- let out = markdown.replace(/!\[image\]\((?:images\/)?([^()\s]+)\)/g, (m, name) => {
1105
- const uri = uris.get(name);
1106
- return uri !== void 0 ? `![image](${uri})` : m;
1107
- });
1108
- out = out.replace(/(<img\b[^>]*\bsrc=")(?:images\/)?([^"]*)(")/g, (m, pre, name, post) => {
1109
- const uri = uris.get(name);
1110
- return uri !== void 0 ? `${pre}${uri}${post}` : m;
1111
- });
1112
1191
  return out;
1113
1192
  }
1114
1193
 
1194
+ // src/types.ts
1195
+ var HEADING_RATIO_H1 = 1.5;
1196
+ var HEADING_RATIO_H2 = 1.3;
1197
+ var HEADING_RATIO_H3 = 1.15;
1198
+
1115
1199
  export {
1200
+ wrapScript,
1201
+ tidyScriptTags,
1202
+ plainScripts,
1203
+ stripScriptTags,
1116
1204
  WINGDINGS,
1117
1205
  mapPuaText,
1118
1206
  MAX_COLS,
@@ -1129,8 +1217,11 @@ export {
1129
1217
  hasStructuredCellContent,
1130
1218
  noteSuffix,
1131
1219
  escapeHtmlCellText,
1132
- encodePng,
1133
- inlineImagesIntoMarkdown,
1134
- blocksToPages
1220
+ CELL_EDGES,
1221
+ CONTENT_CELLS,
1222
+ unframeLayoutTables,
1223
+ HEADING_RATIO_H1,
1224
+ HEADING_RATIO_H2,
1225
+ HEADING_RATIO_H3
1135
1226
  };
1136
- //# sourceMappingURL=chunk-SDRKHEVT.js.map
1227
+ //# sourceMappingURL=chunk-UHGWEWZI.js.map