kordoc 3.4.1 → 3.5.1

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 (85) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +590 -584
  3. package/dist/{-YOQGQ22S.js → -BNJMPTQ2.js} +9 -5
  4. package/dist/{chunk-X34YWRL5.cjs → chunk-DCZVOIEO.cjs} +1 -1
  5. package/dist/chunk-DCZVOIEO.cjs.map +1 -0
  6. package/dist/{chunk-AIQ3ISQU.js → chunk-GE43BE46.js} +1 -1
  7. package/dist/chunk-GE43BE46.js.map +1 -0
  8. package/dist/{chunk-CGHPBI3X.js → chunk-GMPDZD7Q.js} +206 -42
  9. package/dist/chunk-GMPDZD7Q.js.map +1 -0
  10. package/dist/chunk-GS7T56RP.cjs.map +1 -1
  11. package/dist/{chunk-FPFB7AFX.js → chunk-IKAXUVSU.js} +16 -2
  12. package/dist/chunk-IKAXUVSU.js.map +1 -0
  13. package/dist/{chunk-CFQLK3LM.js → chunk-MEPHGCPQ.js} +1 -1
  14. package/dist/chunk-MEPHGCPQ.js.map +1 -0
  15. package/dist/{chunk-3TBUDJDE.js → chunk-MOL7MDBG.js} +1 -1
  16. package/dist/chunk-MOL7MDBG.js.map +1 -0
  17. package/dist/{chunk-SE3KEL4G.js → chunk-OXOPDVNV.js} +16 -2
  18. package/dist/chunk-OXOPDVNV.js.map +1 -0
  19. package/dist/{chunk-W7JHJQ2O.cjs → chunk-RWSGBXSA.cjs} +25 -11
  20. package/dist/chunk-RWSGBXSA.cjs.map +1 -0
  21. package/dist/cli.js +10 -27
  22. package/dist/cli.js.map +1 -1
  23. package/dist/{detect-NTR2FUEG.js → detect-RI2MQ33K.js} +2 -2
  24. package/dist/{formula-ZYUDQHD3.cjs → formula-5NKVS2LR.cjs} +1 -1
  25. package/dist/formula-5NKVS2LR.cjs.map +1 -0
  26. package/dist/{formula-KOQV353G.js → formula-JCNF43NE.js} +1 -1
  27. package/dist/formula-JCNF43NE.js.map +1 -0
  28. package/dist/{formula-MEDGYQXS.js → formula-RXVSQPXI.js} +1 -1
  29. package/dist/formula-RXVSQPXI.js.map +1 -0
  30. package/dist/index.cjs +377 -213
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +9 -3
  33. package/dist/index.d.ts +9 -3
  34. package/dist/index.js +204 -40
  35. package/dist/index.js.map +1 -1
  36. package/dist/mcp.js +42 -6
  37. package/dist/mcp.js.map +1 -1
  38. package/dist/page-range-737B4EZW.js +8 -0
  39. package/dist/page-range-LNMXJU6W.js +7 -0
  40. package/dist/page-range-P7SDW6LR.cjs +8 -0
  41. package/dist/page-range-P7SDW6LR.cjs.map +1 -0
  42. package/dist/{parser-5HDZZWDH.js → parser-GHZMDUGG.js} +5 -5
  43. package/dist/parser-GHZMDUGG.js.map +1 -0
  44. package/dist/{parser-ET64VEEX.js → parser-XXQAMYGV.js} +5 -5
  45. package/dist/parser-XXQAMYGV.js.map +1 -0
  46. package/dist/{parser-JAZCZJI6.cjs → parser-ZLFOUVR4.cjs} +18 -18
  47. package/dist/parser-ZLFOUVR4.cjs.map +1 -0
  48. package/dist/{provider-H4WWSPOV.js → provider-4ZJKV3DC.js} +1 -1
  49. package/dist/provider-4ZJKV3DC.js.map +1 -0
  50. package/dist/{provider-7H4CPZYS.js → provider-AKROB7WQ.js} +1 -1
  51. package/dist/provider-AKROB7WQ.js.map +1 -0
  52. package/dist/{provider-5K7O3Z2O.cjs → provider-G4C2V2PD.cjs} +1 -1
  53. package/dist/provider-G4C2V2PD.cjs.map +1 -0
  54. package/dist/{setup-QSJ2INNS.js → setup-57FB3LSP.js} +1 -1
  55. package/dist/setup-57FB3LSP.js.map +1 -0
  56. package/dist/{watch-56GNC2YN.js → watch-IN3YN72W.js} +5 -5
  57. package/dist/watch-IN3YN72W.js.map +1 -0
  58. package/package.json +98 -98
  59. package/dist/chunk-3TBUDJDE.js.map +0 -1
  60. package/dist/chunk-AIQ3ISQU.js.map +0 -1
  61. package/dist/chunk-CFQLK3LM.js.map +0 -1
  62. package/dist/chunk-CGHPBI3X.js.map +0 -1
  63. package/dist/chunk-FPFB7AFX.js.map +0 -1
  64. package/dist/chunk-SE3KEL4G.js.map +0 -1
  65. package/dist/chunk-W7JHJQ2O.cjs.map +0 -1
  66. package/dist/chunk-X34YWRL5.cjs.map +0 -1
  67. package/dist/formula-KOQV353G.js.map +0 -1
  68. package/dist/formula-MEDGYQXS.js.map +0 -1
  69. package/dist/formula-ZYUDQHD3.cjs.map +0 -1
  70. package/dist/page-range-CIRRJPXJ.js +0 -7
  71. package/dist/page-range-OF5I4PQY.js +0 -8
  72. package/dist/page-range-TPIRSA3J.cjs +0 -8
  73. package/dist/page-range-TPIRSA3J.cjs.map +0 -1
  74. package/dist/parser-5HDZZWDH.js.map +0 -1
  75. package/dist/parser-ET64VEEX.js.map +0 -1
  76. package/dist/parser-JAZCZJI6.cjs.map +0 -1
  77. package/dist/provider-5K7O3Z2O.cjs.map +0 -1
  78. package/dist/provider-7H4CPZYS.js.map +0 -1
  79. package/dist/provider-H4WWSPOV.js.map +0 -1
  80. package/dist/setup-QSJ2INNS.js.map +0 -1
  81. package/dist/watch-56GNC2YN.js.map +0 -1
  82. /package/dist/{-YOQGQ22S.js.map → -BNJMPTQ2.js.map} +0 -0
  83. /package/dist/{detect-NTR2FUEG.js.map → detect-RI2MQ33K.js.map} +0 -0
  84. /package/dist/{page-range-CIRRJPXJ.js.map → page-range-737B4EZW.js.map} +0 -0
  85. /package/dist/{page-range-OF5I4PQY.js.map → page-range-LNMXJU6W.js.map} +0 -0
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  HwpxSession,
4
+ PRESET_ALIAS,
4
5
  applySplices,
5
6
  blocksToPdf,
6
7
  buildParagraphSplices,
@@ -16,6 +17,7 @@ import {
16
17
  isLabelCell,
17
18
  markdownToHwpx,
18
19
  markdownToPdf,
20
+ normalizeGongmunPreset,
19
21
  openHwpxDocument,
20
22
  parse,
21
23
  parseDocx,
@@ -31,7 +33,7 @@ import {
31
33
  patchHwpxBlocks,
32
34
  renderHtml,
33
35
  scanSectionXml
34
- } from "./chunk-CGHPBI3X.js";
36
+ } from "./chunk-GMPDZD7Q.js";
35
37
  import {
36
38
  detectFormat,
37
39
  detectOle2Format,
@@ -40,14 +42,15 @@ import {
40
42
  isOldHwpFile,
41
43
  isPdfFile,
42
44
  isZipFile
43
- } from "./chunk-CFQLK3LM.js";
45
+ } from "./chunk-MEPHGCPQ.js";
44
46
  import {
45
47
  VERSION,
46
48
  blocksToMarkdown
47
- } from "./chunk-FPFB7AFX.js";
48
- import "./chunk-3TBUDJDE.js";
49
+ } from "./chunk-IKAXUVSU.js";
50
+ import "./chunk-MOL7MDBG.js";
49
51
  export {
50
52
  HwpxSession,
53
+ PRESET_ALIAS,
51
54
  VERSION,
52
55
  applySplices,
53
56
  blocksToMarkdown,
@@ -72,6 +75,7 @@ export {
72
75
  isZipFile,
73
76
  markdownToHwpx,
74
77
  markdownToPdf,
78
+ normalizeGongmunPreset,
75
79
  openHwpxDocument,
76
80
  parse,
77
81
  parseDocx,
@@ -88,4 +92,4 @@ export {
88
92
  renderHtml,
89
93
  scanSectionXml
90
94
  };
91
- //# sourceMappingURL=-YOQGQ22S.js.map
95
+ //# sourceMappingURL=-BNJMPTQ2.js.map
@@ -30,4 +30,4 @@ function parsePageRange(spec, maxPages) {
30
30
 
31
31
 
32
32
  exports.parsePageRange = parsePageRange;
33
- //# sourceMappingURL=chunk-X34YWRL5.cjs.map
33
+ //# sourceMappingURL=chunk-DCZVOIEO.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/chris_gomdori/workspace/kordoc/dist/chunk-DCZVOIEO.cjs","../src/page-range.ts"],"names":[],"mappings":"AAAA;ACSO,SAAS,cAAA,CAAe,IAAA,EAAyB,QAAA,EAA+B;AACrF,EAAA,MAAM,OAAA,kBAAS,IAAI,GAAA,CAAY,CAAA;AAC/B,EAAA,GAAA,CAAI,SAAA,GAAY,CAAA,EAAG,OAAO,MAAA;AAE1B,EAAA,GAAA,CAAI,KAAA,CAAM,OAAA,CAAQ,IAAI,CAAA,EAAG;AACvB,IAAA,IAAA,CAAA,MAAW,EAAA,GAAK,IAAA,EAAM;AACpB,MAAA,MAAM,KAAA,EAAO,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA;AACzB,MAAA,GAAA,CAAI,KAAA,GAAQ,EAAA,GAAK,KAAA,GAAQ,QAAA,EAAU,MAAA,CAAO,GAAA,CAAI,IAAI,CAAA;AAAA,IACpD;AACA,IAAA,OAAO,MAAA;AAAA,EACT;AAEA,EAAA,GAAA,CAAI,OAAO,KAAA,IAAS,SAAA,GAAY,IAAA,CAAK,IAAA,CAAK,EAAA,IAAM,EAAA,EAAI,OAAO,MAAA;AAE3D,EAAA,MAAM,MAAA,EAAQ,IAAA,CAAK,KAAA,CAAM,GAAG,CAAA;AAC5B,EAAA,IAAA,CAAA,MAAW,KAAA,GAAQ,KAAA,EAAO;AACxB,IAAA,MAAM,QAAA,EAAU,IAAA,CAAK,IAAA,CAAK,CAAA;AAC1B,IAAA,GAAA,CAAI,CAAC,OAAA,EAAS,QAAA;AAEd,IAAA,MAAM,WAAA,EAAa,OAAA,CAAQ,KAAA,CAAM,qBAAqB,CAAA;AACtD,IAAA,GAAA,CAAI,UAAA,EAAY;AACd,MAAA,MAAM,MAAA,EAAQ,IAAA,CAAK,GAAA,CAAI,CAAA,EAAG,QAAA,CAAS,UAAA,CAAW,CAAC,CAAA,EAAG,EAAE,CAAC,CAAA;AACrD,MAAA,MAAM,IAAA,EAAM,IAAA,CAAK,GAAA,CAAI,QAAA,EAAU,QAAA,CAAS,UAAA,CAAW,CAAC,CAAA,EAAG,EAAE,CAAC,CAAA;AAC1D,MAAA,IAAA,CAAA,IAAS,EAAA,EAAI,KAAA,EAAO,EAAA,GAAK,GAAA,EAAK,CAAA,EAAA,EAAK,MAAA,CAAO,GAAA,CAAI,CAAC,CAAA;AAAA,IACjD,EAAA,KAAO;AACL,MAAA,MAAM,KAAA,EAAO,QAAA,CAAS,OAAA,EAAS,EAAE,CAAA;AACjC,MAAA,GAAA,CAAI,CAAC,KAAA,CAAM,IAAI,EAAA,GAAK,KAAA,GAAQ,EAAA,GAAK,KAAA,GAAQ,QAAA,EAAU,MAAA,CAAO,GAAA,CAAI,IAAI,CAAA;AAAA,IACpE;AAAA,EACF;AAEA,EAAA,OAAO,MAAA;AACT;ADZA;AACA;AACE;AACF,wCAAC","file":"/Users/chris_gomdori/workspace/kordoc/dist/chunk-DCZVOIEO.cjs","sourcesContent":[null,"/** 페이지/섹션 범위 파싱 유틸리티 */\n\n/**\n * 페이지 범위 지정을 1-based Set<number>로 변환.\n *\n * @param spec - [1,2,3] 또는 \"1-3\" 또는 \"1,3,5-7\"\n * @param maxPages - 최대 페이지 수 (클램핑 상한)\n * @returns 1-based 페이지 번호 Set\n */\nexport function parsePageRange(spec: number[] | string, maxPages: number): Set<number> {\n const result = new Set<number>()\n if (maxPages <= 0) return result\n\n if (Array.isArray(spec)) {\n for (const n of spec) {\n const page = Math.round(n)\n if (page >= 1 && page <= maxPages) result.add(page)\n }\n return result\n }\n\n if (typeof spec !== \"string\" || spec.trim() === \"\") return result\n\n const parts = spec.split(\",\")\n for (const part of parts) {\n const trimmed = part.trim()\n if (!trimmed) continue\n\n const rangeMatch = trimmed.match(/^(\\d+)\\s*-\\s*(\\d+)$/)\n if (rangeMatch) {\n const start = Math.max(1, parseInt(rangeMatch[1], 10))\n const end = Math.min(maxPages, parseInt(rangeMatch[2], 10))\n for (let i = start; i <= end; i++) result.add(i)\n } else {\n const page = parseInt(trimmed, 10)\n if (!isNaN(page) && page >= 1 && page <= maxPages) result.add(page)\n }\n }\n\n return result\n}\n"]}
@@ -30,4 +30,4 @@ function parsePageRange(spec, maxPages) {
30
30
  export {
31
31
  parsePageRange
32
32
  };
33
- //# sourceMappingURL=chunk-AIQ3ISQU.js.map
33
+ //# sourceMappingURL=chunk-GE43BE46.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/page-range.ts"],"sourcesContent":["/** 페이지/섹션 범위 파싱 유틸리티 */\n\n/**\n * 페이지 범위 지정을 1-based Set<number>로 변환.\n *\n * @param spec - [1,2,3] 또는 \"1-3\" 또는 \"1,3,5-7\"\n * @param maxPages - 최대 페이지 수 (클램핑 상한)\n * @returns 1-based 페이지 번호 Set\n */\nexport function parsePageRange(spec: number[] | string, maxPages: number): Set<number> {\n const result = new Set<number>()\n if (maxPages <= 0) return result\n\n if (Array.isArray(spec)) {\n for (const n of spec) {\n const page = Math.round(n)\n if (page >= 1 && page <= maxPages) result.add(page)\n }\n return result\n }\n\n if (typeof spec !== \"string\" || spec.trim() === \"\") return result\n\n const parts = spec.split(\",\")\n for (const part of parts) {\n const trimmed = part.trim()\n if (!trimmed) continue\n\n const rangeMatch = trimmed.match(/^(\\d+)\\s*-\\s*(\\d+)$/)\n if (rangeMatch) {\n const start = Math.max(1, parseInt(rangeMatch[1], 10))\n const end = Math.min(maxPages, parseInt(rangeMatch[2], 10))\n for (let i = start; i <= end; i++) result.add(i)\n } else {\n const page = parseInt(trimmed, 10)\n if (!isNaN(page) && page >= 1 && page <= maxPages) result.add(page)\n }\n }\n\n return result\n}\n"],"mappings":";AASO,SAAS,eAAe,MAAyB,UAA+B;AACrF,QAAM,SAAS,oBAAI,IAAY;AAC/B,MAAI,YAAY,EAAG,QAAO;AAE1B,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,eAAW,KAAK,MAAM;AACpB,YAAM,OAAO,KAAK,MAAM,CAAC;AACzB,UAAI,QAAQ,KAAK,QAAQ,SAAU,QAAO,IAAI,IAAI;AAAA,IACpD;AACA,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,SAAS,YAAY,KAAK,KAAK,MAAM,GAAI,QAAO;AAE3D,QAAM,QAAQ,KAAK,MAAM,GAAG;AAC5B,aAAW,QAAQ,OAAO;AACxB,UAAM,UAAU,KAAK,KAAK;AAC1B,QAAI,CAAC,QAAS;AAEd,UAAM,aAAa,QAAQ,MAAM,qBAAqB;AACtD,QAAI,YAAY;AACd,YAAM,QAAQ,KAAK,IAAI,GAAG,SAAS,WAAW,CAAC,GAAG,EAAE,CAAC;AACrD,YAAM,MAAM,KAAK,IAAI,UAAU,SAAS,WAAW,CAAC,GAAG,EAAE,CAAC;AAC1D,eAAS,IAAI,OAAO,KAAK,KAAK,IAAK,QAAO,IAAI,CAAC;AAAA,IACjD,OAAO;AACL,YAAM,OAAO,SAAS,SAAS,EAAE;AACjC,UAAI,CAAC,MAAM,IAAI,KAAK,QAAQ,KAAK,QAAQ,SAAU,QAAO,IAAI,IAAI;AAAA,IACpE;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -4,7 +4,7 @@ import {
4
4
  detectOle2Format,
5
5
  detectZipFormat,
6
6
  parseLenientCfb
7
- } from "./chunk-CFQLK3LM.js";
7
+ } from "./chunk-MEPHGCPQ.js";
8
8
  import {
9
9
  HEADING_RATIO_H1,
10
10
  HEADING_RATIO_H2,
@@ -15,18 +15,20 @@ import {
15
15
  blocksToMarkdown,
16
16
  buildTable,
17
17
  classifyError,
18
+ compareSectionPaths,
18
19
  convertTableToText,
19
20
  flattenLayoutTables,
20
21
  isPathTraversal,
21
22
  mapPuaText,
23
+ normalizeSectionHref,
22
24
  precheckZipSize,
23
25
  sanitizeHref,
24
26
  stripDtd,
25
27
  toArrayBuffer
26
- } from "./chunk-FPFB7AFX.js";
28
+ } from "./chunk-IKAXUVSU.js";
27
29
  import {
28
30
  parsePageRange
29
- } from "./chunk-3TBUDJDE.js";
31
+ } from "./chunk-MOL7MDBG.js";
30
32
 
31
33
  // src/index.ts
32
34
  import { readFile } from "fs/promises";
@@ -412,14 +414,27 @@ function findBrackets(eqString, startIdx, direction) {
412
414
  const [s, e] = findBrackets(flipped, newStartIdx, 1);
413
415
  return [flipped.length - e, flipped.length - s];
414
416
  }
415
- function findOutterBrackets(eqString, startIdx) {
416
- let idx = startIdx;
417
- while (true) {
418
- idx -= 1;
419
- if (idx < 0) throw new Error("cannot find bracket");
420
- if (eqString[idx] === "{") break;
417
+ function findEnclosingBrackets(eqString, startIdx) {
418
+ let depth = 0;
419
+ for (let idx = startIdx - 1; idx >= 0; idx--) {
420
+ const ch = eqString[idx];
421
+ if (ch === "}") {
422
+ depth += 1;
423
+ } else if (ch === "{") {
424
+ if (depth > 0) {
425
+ depth -= 1;
426
+ continue;
427
+ }
428
+ try {
429
+ const [start, end] = findBrackets(eqString, idx, 1);
430
+ if (start === idx && end > startIdx) return [start, end];
431
+ } catch {
432
+ return null;
433
+ }
434
+ return null;
435
+ }
421
436
  }
422
- return findBrackets(eqString, idx, 1);
437
+ return null;
423
438
  }
424
439
  function replaceFrac(eqString) {
425
440
  const hmlFrac = "over";
@@ -472,8 +487,9 @@ function replaceAllMatrix(eqString) {
472
487
  const elem = replaceElements(input.slice(eStart, eEnd));
473
488
  let beforeMat;
474
489
  let afterMat;
475
- if (matElem.removeOutterBrackets) {
476
- const [bStart, bEnd] = findOutterBrackets(input, cursor);
490
+ const outer = matElem.removeOutterBrackets ? findEnclosingBrackets(input, cursor) : null;
491
+ if (outer && outer[1] >= eEnd) {
492
+ const [bStart, bEnd] = outer;
477
493
  beforeMat = input.slice(0, bStart);
478
494
  afterMat = input.slice(bEnd);
479
495
  } else {
@@ -499,10 +515,11 @@ function replaceAllBar(eqString) {
499
515
  if (cursor === -1) break;
500
516
  try {
501
517
  const [eStart, eEnd] = findBrackets(input, cursor, 1);
502
- const [bStart, bEnd] = findOutterBrackets(input, cursor);
503
518
  const elem = input.slice(eStart, eEnd);
504
- const beforeBar = input.slice(0, bStart);
505
- const afterBar = input.slice(bEnd);
519
+ const outer = findEnclosingBrackets(input, cursor);
520
+ const [replaceStart, replaceEnd] = outer && outer[1] >= eEnd ? outer : [cursor, eEnd];
521
+ const beforeBar = input.slice(0, replaceStart);
522
+ const afterBar = input.slice(replaceEnd);
506
523
  input = beforeBar + barElem + elem + afterBar;
507
524
  } catch {
508
525
  return input;
@@ -1137,24 +1154,19 @@ async function resolveSectionPaths(zip) {
1137
1154
  if (paths.length > 0) return paths;
1138
1155
  }
1139
1156
  const sectionFiles = zip.file(/[Ss]ection\d+\.xml$/);
1140
- return sectionFiles.map((f) => f.name).sort();
1157
+ return sectionFiles.map((f) => f.name).sort(compareSectionPaths);
1141
1158
  }
1142
1159
  function parseSectionPathsFromManifest(xml) {
1143
1160
  const parser = createXmlParser();
1144
1161
  const doc = parser.parseFromString(stripDtd(xml), "text/xml");
1145
1162
  const items = doc.getElementsByTagName("opf:item");
1146
1163
  const spine = doc.getElementsByTagName("opf:itemref");
1147
- const isSectionId = (id) => /^s/i.test(id) || id.toLowerCase().includes("section");
1148
1164
  const idToHref = /* @__PURE__ */ new Map();
1149
1165
  for (let i = 0; i < items.length; i++) {
1150
1166
  const item = items[i];
1151
1167
  const id = item.getAttribute("id") || "";
1152
- let href = item.getAttribute("href") || "";
1153
- const mediaType = item.getAttribute("media-type") || "";
1154
- if (!isSectionId(id) && !mediaType.includes("xml")) continue;
1155
- if (!href.startsWith("/") && !href.startsWith("Contents/") && isSectionId(id))
1156
- href = "Contents/" + href;
1157
- idToHref.set(id, href);
1168
+ const href = normalizeSectionHref(item.getAttribute("href") || "");
1169
+ if (id && href) idToHref.set(id, href);
1158
1170
  }
1159
1171
  if (spine.length > 0) {
1160
1172
  const ordered = [];
@@ -1164,7 +1176,7 @@ function parseSectionPathsFromManifest(xml) {
1164
1176
  }
1165
1177
  if (ordered.length > 0) return ordered;
1166
1178
  }
1167
- return Array.from(idToHref.entries()).filter(([id]) => isSectionId(id)).sort((a, b) => a[0].localeCompare(b[0])).map(([, href]) => href);
1179
+ return Array.from(idToHref.values()).sort(compareSectionPaths);
1168
1180
  }
1169
1181
  function detectHwpxHeadings(blocks, styleMap) {
1170
1182
  if (blocks.some((b) => b.type === "heading")) return;
@@ -16689,7 +16701,7 @@ async function parseXlsxDocument(buffer, options) {
16689
16701
  }
16690
16702
  let pageFilter = null;
16691
16703
  if (options?.pages) {
16692
- const { parsePageRange: parsePageRange2 } = await import("./page-range-OF5I4PQY.js");
16704
+ const { parsePageRange: parsePageRange2 } = await import("./page-range-737B4EZW.js");
16693
16705
  pageFilter = parsePageRange2(options.pages, sheets.length);
16694
16706
  }
16695
16707
  const blocks = [];
@@ -17327,7 +17339,7 @@ async function parseXlsDocument(buffer, options) {
17327
17339
  const totalSheets = Math.min(globals.sheets.length, MAX_SHEETS2);
17328
17340
  let pageFilter = null;
17329
17341
  if (options?.pages) {
17330
- const { parsePageRange: parsePageRange2 } = await import("./page-range-OF5I4PQY.js");
17342
+ const { parsePageRange: parsePageRange2 } = await import("./page-range-737B4EZW.js");
17331
17343
  pageFilter = parsePageRange2(options.pages, totalSheets);
17332
17344
  }
17333
17345
  const allBlocks = [];
@@ -19792,8 +19804,30 @@ var PRESET_DEFAULTS = {
19792
19804
  notice: { bodyPt: 15, lineSpacing: 160, numbering: "standard" },
19793
19805
  minutes: { bodyPt: 14, lineSpacing: 130, numbering: "standard" }
19794
19806
  };
19807
+ var PRESET_ALIAS = {
19808
+ official: "official",
19809
+ \uAE30\uC548\uBB38: "official",
19810
+ \uC2DC\uD589\uBB38: "official",
19811
+ \uACF5\uBB38: "official",
19812
+ \uACF5\uBB38\uC11C: "official",
19813
+ report: "report",
19814
+ \uBCF4\uACE0\uC11C: "report",
19815
+ plan: "plan",
19816
+ \uACC4\uD68D\uC11C: "plan",
19817
+ \uACC4\uD68D: "plan",
19818
+ notice: "notice",
19819
+ \uD1B5\uC9C0: "notice",
19820
+ \uC54C\uB9BC: "notice",
19821
+ \uC548\uB0B4: "notice",
19822
+ minutes: "minutes",
19823
+ \uD68C\uC758\uB85D: "minutes"
19824
+ };
19825
+ function normalizeGongmunPreset(preset) {
19826
+ if (!preset) return "official";
19827
+ return PRESET_ALIAS[preset.trim()] ?? "official";
19828
+ }
19795
19829
  function resolveGongmun(opts) {
19796
- const preset = opts.preset ?? "official";
19830
+ const preset = normalizeGongmunPreset(opts.preset);
19797
19831
  const d = PRESET_DEFAULTS[preset];
19798
19832
  const bodyPt = opts.bodyPt ?? d.bodyPt;
19799
19833
  return {
@@ -21163,6 +21197,67 @@ function applyCellEdit(table, scanTable, gridR, gridC, newLines, ctx, before, af
21163
21197
  return 1;
21164
21198
  }
21165
21199
 
21200
+ // src/roundtrip/table-insert.ts
21201
+ var TABLE_USABLE_WIDTH = 44e3;
21202
+ var TABLE_ROW_HEIGHT = 1500;
21203
+ function collectMaxNumericId(xmls) {
21204
+ let max = -1;
21205
+ for (const xml of xmls) {
21206
+ for (const m of xml.matchAll(/\bid(?:Ref)?="(\d{1,10})"/g)) {
21207
+ const v = parseInt(m[1], 10);
21208
+ if (!isNaN(v) && v > max) max = v;
21209
+ }
21210
+ }
21211
+ return max;
21212
+ }
21213
+ function cellBorderFillXml(id) {
21214
+ return `<hh:borderFill id="${id}" threeD="0" shadow="0" centerLine="0" breakCellSeparateLine="0"><hh:slash type="NONE" Crooked="0" isCounter="0"/><hh:backSlash type="NONE" Crooked="0" isCounter="0"/><hh:leftBorder type="SOLID" width="0.12 mm" color="#000000"/><hh:rightBorder type="SOLID" width="0.12 mm" color="#000000"/><hh:topBorder type="SOLID" width="0.12 mm" color="#000000"/><hh:bottomBorder type="SOLID" width="0.12 mm" color="#000000"/><hh:diagonal type="NONE" width="0.1 mm" color="#000000"/><hh:fillInfo/></hh:borderFill>`;
21215
+ }
21216
+ function injectCellBorderFill(headerXml, newId) {
21217
+ const openM = headerXml.match(/<hh:borderFills\b([^>]*)>/);
21218
+ if (!openM || openM.index === void 0) return null;
21219
+ const closeIdx = headerXml.indexOf("</hh:borderFills>");
21220
+ if (closeIdx < 0) return null;
21221
+ const splices = [];
21222
+ const itemCntM = openM[1].match(/\bitemCnt="(\d+)"/);
21223
+ if (itemCntM && itemCntM.index !== void 0) {
21224
+ const cnt = parseInt(itemCntM[1], 10);
21225
+ const attrStart = openM.index + "<hh:borderFills".length + itemCntM.index;
21226
+ const valStart = attrStart + itemCntM[0].indexOf('"') + 1;
21227
+ const valEnd = valStart + String(cnt).length;
21228
+ splices.push({ start: valStart, end: valEnd, replacement: String(cnt + 1) });
21229
+ }
21230
+ splices.push({ start: closeIdx, end: closeIdx, replacement: cellBorderFillXml(newId) });
21231
+ return { borderFillId: newId, headerSplices: splices };
21232
+ }
21233
+ function cellPlainText(raw) {
21234
+ let t = unescapeGfmCell(raw);
21235
+ t = t.replace(/\*\*\*([^*]+)\*\*\*/g, "$1").replace(/\*\*([^*]+)\*\*/g, "$1").replace(/\*([^*]+)\*/g, "$1").replace(/`([^`]+)`/g, "$1");
21236
+ return t.replace(/\s*\n\s*/g, " ").trim();
21237
+ }
21238
+ function buildTableParagraphXml(rows, opts) {
21239
+ const { borderFillId, outerParaPrId, cellParaPrId, cellCharPrId, tableId } = opts;
21240
+ const rowCnt = rows.length;
21241
+ const colCnt = Math.max(...rows.map((r) => r.length), 1);
21242
+ const cellW = Math.floor(TABLE_USABLE_WIDTH / colCnt);
21243
+ const cellH = TABLE_ROW_HEIGHT;
21244
+ const tblW = cellW * colCnt;
21245
+ const tblH = cellH * rowCnt;
21246
+ const trElements = rows.map((row, rowIdx) => {
21247
+ const cells = row.length < colCnt ? [...row, ...Array(colCnt - row.length).fill("")] : row;
21248
+ const isHeaderRow = rowIdx === 0;
21249
+ const tdElements = cells.map((cell, colIdx) => {
21250
+ const text = escapeXmlText(cellPlainText(cell));
21251
+ const cellP = `<hp:p paraPrIDRef="${cellParaPrId}" styleIDRef="0"><hp:run charPrIDRef="${cellCharPrId}"><hp:t>${text}</hp:t></hp:run></hp:p>`;
21252
+ return `<hp:tc name="" header="${isHeaderRow ? 1 : 0}" hasMargin="0" protect="0" editable="1" dirty="0" borderFillIDRef="${borderFillId}"><hp:subList id="" textDirection="HORIZONTAL" lineWrap="BREAK" vertAlign="TOP" linkListIDRef="0" linkListNextIDRef="0" textWidth="0" textHeight="0" hasTextRef="0" hasNumRef="0">${cellP}</hp:subList><hp:cellAddr colAddr="${colIdx}" rowAddr="${rowIdx}"/><hp:cellSpan colSpan="1" rowSpan="1"/><hp:cellSz width="${cellW}" height="${cellH}"/><hp:cellMargin left="141" right="141" top="141" bottom="141"/></hp:tc>`;
21253
+ }).join("");
21254
+ return `<hp:tr>${tdElements}</hp:tr>`;
21255
+ }).join("");
21256
+ const tblInner = `<hp:sz width="${tblW}" widthRelTo="ABSOLUTE" height="${tblH}" heightRelTo="ABSOLUTE" protect="0"/><hp:pos treatAsChar="1" affectLSpacing="0" flowWithText="0" allowOverlap="0" holdAnchorAndSO="0" vertRelTo="PARA" horzRelTo="PARA" vertAlign="TOP" horzAlign="LEFT" vertOffset="0" horzOffset="0"/><hp:outMargin left="0" right="0" top="0" bottom="0"/><hp:inMargin left="510" right="510" top="141" bottom="141"/>` + trElements;
21257
+ const tbl = `<hp:tbl id="${tableId}" zOrder="0" numberingType="TABLE" pageBreak="CELL" repeatHeader="0" rowCnt="${rowCnt}" colCnt="${colCnt}" cellSpacing="0" borderFillIDRef="${borderFillId}" noShading="0">${tblInner}</hp:tbl>`;
21258
+ return `<hp:p paraPrIDRef="${outerParaPrId}" styleIDRef="0"><hp:run charPrIDRef="${cellCharPrId}">${tbl}</hp:run></hp:p>`;
21259
+ }
21260
+
21166
21261
  // src/roundtrip/hwpx-entries.ts
21167
21262
  async function resolveSectionEntryNames(zip) {
21168
21263
  for (const mp of ["Contents/content.hpf", "content.hpf"]) {
@@ -21172,10 +21267,9 @@ async function resolveSectionEntryNames(zip) {
21172
21267
  const paths = sectionPathsFromManifest(xml).filter((p) => zip.file(p) !== null);
21173
21268
  if (paths.length > 0) return paths;
21174
21269
  }
21175
- return Object.keys(zip.files).filter((n) => /[Ss]ection\d+\.xml$/.test(n)).sort();
21270
+ return Object.keys(zip.files).filter((n) => /[Ss]ection\d+\.xml$/.test(n)).sort(compareSectionPaths);
21176
21271
  }
21177
21272
  function sectionPathsFromManifest(xml) {
21178
- const isSectionId = (id) => /^s/i.test(id) || id.toLowerCase().includes("section");
21179
21273
  const attr = (tag, name) => {
21180
21274
  const m = tag.match(new RegExp(`(?:^|\\s)${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)')`));
21181
21275
  return m ? m[1] ?? m[2] : "";
@@ -21183,11 +21277,8 @@ function sectionPathsFromManifest(xml) {
21183
21277
  const idToHref = /* @__PURE__ */ new Map();
21184
21278
  for (const m of xml.matchAll(/<opf:item(\s(?:"[^"]*"|'[^']*'|[^>"'])*?)\/?>/g)) {
21185
21279
  const id = attr(m[1], "id");
21186
- let href = attr(m[1], "href");
21187
- const mediaType = attr(m[1], "media-type");
21188
- if (!isSectionId(id) && !mediaType.includes("xml")) continue;
21189
- if (!href.startsWith("/") && !href.startsWith("Contents/") && isSectionId(id)) href = "Contents/" + href;
21190
- if (id) idToHref.set(id, href);
21280
+ const href = normalizeSectionHref(attr(m[1], "href"));
21281
+ if (id && href) idToHref.set(id, href);
21191
21282
  }
21192
21283
  const ordered = [];
21193
21284
  for (const m of xml.matchAll(/<opf:itemref(\s(?:"[^"]*"|'[^']*'|[^>"'])*?)\/?>/g)) {
@@ -21195,7 +21286,7 @@ function sectionPathsFromManifest(xml) {
21195
21286
  if (href) ordered.push(href);
21196
21287
  }
21197
21288
  if (ordered.length > 0) return ordered;
21198
- return Array.from(idToHref.entries()).filter(([id]) => isSectionId(id)).sort((a, b) => a[0].localeCompare(b[0])).map(([, href]) => href);
21289
+ return Array.from(idToHref.values()).sort(compareSectionPaths);
21199
21290
  }
21200
21291
 
21201
21292
  // src/roundtrip/patcher.ts
@@ -21224,6 +21315,13 @@ async function patchHwpx(original, editedMarkdown, options) {
21224
21315
  const xml = await zip.file(sectionPaths[i]).async("text");
21225
21316
  scans.push(scanSectionXml(xml, i));
21226
21317
  }
21318
+ let tableInsert;
21319
+ const headerEntryName = await resolveHeaderEntryName(zip);
21320
+ if (headerEntryName) {
21321
+ const headerXml = await zip.file(headerEntryName).async("text");
21322
+ const maxId = collectMaxNumericId([...scans.map((s) => s.xml), headerXml]);
21323
+ tableInsert = { headerEntryName, headerXml, headerSplices: [], borderFillId: null, nextId: maxId + 1 };
21324
+ }
21227
21325
  const origUnits = buildOrigUnits(origBlocks);
21228
21326
  const editedUnits = splitMarkdownUnits(editedMarkdown);
21229
21327
  const pairs = alignUnits(origUnits.map((u) => u.raw), editedUnits.map((u) => u.raw));
@@ -21243,7 +21341,8 @@ async function patchHwpx(original, editedMarkdown, options) {
21243
21341
  scanTables,
21244
21342
  obTableOrdinals,
21245
21343
  sectionSplices,
21246
- skipped
21344
+ skipped,
21345
+ tableInsert
21247
21346
  });
21248
21347
  } else if (oi !== null) {
21249
21348
  skipped.push({ reason: "\uBE14\uB85D \uC0AD\uC81C\uB294 \uBBF8\uC9C0\uC6D0 (v1) \u2014 \uC6D0\uBCF8 \uC720\uC9C0", before: summarize(origUnits[oi].raw) });
@@ -21260,6 +21359,10 @@ async function patchHwpx(original, editedMarkdown, options) {
21260
21359
  const newXml = applySplices(scans[i].xml, sectionSplices[i]);
21261
21360
  replacements.set(sectionPaths[i], encoder.encode(newXml));
21262
21361
  }
21362
+ if (tableInsert && tableInsert.headerSplices.length > 0) {
21363
+ const newHeader = applySplices(tableInsert.headerXml, tableInsert.headerSplices);
21364
+ replacements.set(tableInsert.headerEntryName, encoder.encode(newHeader));
21365
+ }
21263
21366
  } catch (err) {
21264
21367
  return { success: false, applied: 0, skipped, error: `\uC18C\uC2A4\uB9F5 splice \uC2E4\uD328: ${err instanceof Error ? err.message : String(err)}` };
21265
21368
  }
@@ -21472,11 +21575,49 @@ function handleModifiedUnit(orig, edited, ctx) {
21472
21575
  if (orig.kind === "html-table") return patchHtmlTable(block.table, scanTable, orig, edited, ctx, skip);
21473
21576
  return patchTextChunkTable(block.table, scanTable, orig, edited, ctx, skip);
21474
21577
  }
21475
- if ((block.type === "paragraph" || block.type === "heading") && orig.kind === "text" && edited.kind === "text") {
21476
- return patchParagraphUnit(block, orig, edited, ctx, skip);
21578
+ if ((block.type === "paragraph" || block.type === "heading") && orig.kind === "text") {
21579
+ if (edited.kind === "text") return patchParagraphUnit(block, orig, edited, ctx, skip);
21580
+ if (edited.kind === "gfm-table") return convertParagraphToTable(block, orig, edited, ctx, skip);
21581
+ if (edited.kind === "html-table") return skip("\uBB38\uB2E8\u2192\uBCD1\uD569\uD45C(HTML) \uBCC0\uD658\uC740 \uBBF8\uC9C0\uC6D0 \u2014 GFM \uD45C(| \uD5E4\uB354 | \u2026 |)\uB85C \uC791\uC131\uD558\uC138\uC694");
21477
21582
  }
21478
21583
  return skip("\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uBE14\uB85D \uC720\uD615 \uBCC0\uACBD");
21479
21584
  }
21585
+ function extractParaPrIdRef(xml, start) {
21586
+ const gt = xml.indexOf(">", start);
21587
+ if (gt < 0) return null;
21588
+ const m = xml.slice(start, gt + 1).match(/paraPrIDRef="(\d+)"/);
21589
+ return m ? parseInt(m[1], 10) : null;
21590
+ }
21591
+ function convertParagraphToTable(block, orig, edited, ctx, skip) {
21592
+ const ti = ctx.tableInsert;
21593
+ if (!ti) return skip("\uBB38\uB2E8\u2192\uD45C \uBCC0\uD658 \uBD88\uAC00 \u2014 header \uC5D4\uD2B8\uB9AC(borderFills) \uD574\uC11D \uC2E4\uD328");
21594
+ const mapping = ctx.paraMap.get(orig.blockIdx);
21595
+ if (!mapping?.para) return skip("\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED) \u2014 \uD45C \uBCC0\uD658 \uBD88\uAC00");
21596
+ const para = mapping.para;
21597
+ if (para.kind !== "body") return skip("\uBCF8\uBB38 \uC678 \uC601\uC5ED(\uD45C \uC140/\uAE00\uC0C1\uC790) \uBB38\uB2E8\uC758 \uD45C \uBCC0\uD658\uC740 \uBBF8\uC9C0\uC6D0");
21598
+ const scan = ctx.scans[para.sectionIndex];
21599
+ if (!scan) return skip("\uC139\uC158 \uB9E4\uD551 \uC2E4\uD328");
21600
+ const pEnd = findElementEnd(scan.xml, para.start);
21601
+ if (pEnd < 0) return skip("\uBB38\uB2E8 \uB05D \uC704\uCE58 \uD0D0\uC0C9 \uC2E4\uD328");
21602
+ const rows = parseGfmTable(edited.lines);
21603
+ if (rows.length === 0 || rows.every((r) => r.length === 0)) return skip("\uD45C \uB0B4\uC6A9\uC774 \uBE44\uC5B4 \uC788\uC74C");
21604
+ if (ti.borderFillId === null) {
21605
+ const inj = injectCellBorderFill(ti.headerXml, ti.nextId++);
21606
+ if (!inj) return skip("header <hh:borderFills> \uAD6C\uC870\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC5B4 \uD45C \uD14C\uB450\uB9AC \uC0DD\uC131 \uBD88\uAC00");
21607
+ ti.borderFillId = inj.borderFillId;
21608
+ ti.headerSplices.push(...inj.headerSplices);
21609
+ }
21610
+ const outerParaPrId = extractParaPrIdRef(scan.xml, para.start) ?? 0;
21611
+ const tableXml = buildTableParagraphXml(rows, {
21612
+ borderFillId: ti.borderFillId,
21613
+ outerParaPrId,
21614
+ cellParaPrId: 0,
21615
+ cellCharPrId: 0,
21616
+ tableId: ti.nextId++
21617
+ });
21618
+ ctx.sectionSplices[para.sectionIndex].push({ start: para.start, end: pEnd, replacement: tableXml });
21619
+ return 1;
21620
+ }
21480
21621
  function patchParagraphUnit(block, orig, edited, ctx, skip) {
21481
21622
  const mapping = ctx.paraMap.get(orig.blockIdx);
21482
21623
  if (!mapping?.para) return skip("\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED\uC774\uAC70\uB098 \uD14D\uC2A4\uD2B8 \uBD88\uC77C\uCE58)");
@@ -21557,6 +21698,24 @@ function unitToBlock(u) {
21557
21698
  function u8ToArrayBuffer(u8) {
21558
21699
  return u8.buffer.slice(u8.byteOffset, u8.byteOffset + u8.byteLength);
21559
21700
  }
21701
+ async function resolveHeaderEntryName(zip) {
21702
+ for (const p of ["Contents/header.xml", "header.xml"]) {
21703
+ if (zip.file(p)) return p;
21704
+ }
21705
+ for (const mp of ["Contents/content.hpf", "content.hpf"]) {
21706
+ const f = zip.file(mp);
21707
+ if (!f) continue;
21708
+ const xml = await f.async("text");
21709
+ const m = xml.match(/<opf:item\b[^>]*\bid="header"[^>]*\bhref="([^"]+)"/i) || xml.match(/<opf:item\b[^>]*\bhref="([^"]*header[^"]*\.xml)"/i);
21710
+ if (m) {
21711
+ let href = m[1];
21712
+ if (!href.startsWith("/") && !href.startsWith("Contents/")) href = "Contents/" + href;
21713
+ if (zip.file(href)) return href;
21714
+ }
21715
+ }
21716
+ const found = Object.keys(zip.files).find((n) => /header\.xml$/i.test(n));
21717
+ return found ?? null;
21718
+ }
21560
21719
 
21561
21720
  // src/roundtrip/hwp5-patch.ts
21562
21721
  import { deflateRawSync as deflateRawSync2 } from "zlib";
@@ -22195,8 +22354,11 @@ function handleModified(orig, edited, ctx) {
22195
22354
  if (orig.kind === "html-table") return patchHtmlCells5(block.table, scanTable, orig, edited, ctx, skip);
22196
22355
  return patchTextChunk5(block.table, scanTable, orig, edited, ctx, skip);
22197
22356
  }
22198
- if ((block.type === "paragraph" || block.type === "heading") && orig.kind === "text" && edited.kind === "text") {
22199
- return patchParagraph(block, orig, edited, ctx, skip);
22357
+ if ((block.type === "paragraph" || block.type === "heading") && orig.kind === "text") {
22358
+ if (edited.kind === "text") return patchParagraph(block, orig, edited, ctx, skip);
22359
+ if (edited.kind === "gfm-table" || edited.kind === "html-table") {
22360
+ return skip("HWP5(.hwp) \uBC14\uC774\uB108\uB9AC\uB294 \uBB38\uB2E8\u2192\uD45C \uC778\uD50C\uB808\uC774\uC2A4 \uBCC0\uD658 \uBBF8\uC9C0\uC6D0 \u2014 generate\uB85C \uC0C8 \uBB38\uC11C\uB97C \uB9CC\uB4E4\uAC70\uB098, HWPX(.hwpx)\uB85C \uC800\uC7A5 \uD6C4 patch\uD558\uC138\uC694");
22361
+ }
22200
22362
  }
22201
22363
  return skip("\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uBE14\uB85D \uC720\uD615 \uBCC0\uACBD");
22202
22364
  }
@@ -23133,7 +23295,7 @@ async function parseHwp(buffer, options) {
23133
23295
  async function parsePdf(buffer, options) {
23134
23296
  let parsePdfDocument;
23135
23297
  try {
23136
- const mod = await import("./parser-ET64VEEX.js");
23298
+ const mod = await import("./parser-XXQAMYGV.js");
23137
23299
  parsePdfDocument = mod.parsePdfDocument;
23138
23300
  } catch {
23139
23301
  return {
@@ -23236,6 +23398,8 @@ export {
23236
23398
  buildRangeSplices,
23237
23399
  applySplices,
23238
23400
  fillHwpx,
23401
+ PRESET_ALIAS,
23402
+ normalizeGongmunPreset,
23239
23403
  markdownToHwpx,
23240
23404
  compare,
23241
23405
  diffBlocks,
@@ -23258,4 +23422,4 @@ export {
23258
23422
  parseHwpml,
23259
23423
  fillForm
23260
23424
  };
23261
- //# sourceMappingURL=chunk-CGHPBI3X.js.map
23425
+ //# sourceMappingURL=chunk-GMPDZD7Q.js.map