kordoc 3.8.1 → 3.8.2

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 (32) hide show
  1. package/README.md +5 -0
  2. package/dist/{-LD4BZDDJ.js → -FEHSMPVO.js} +3 -3
  3. package/dist/{chunk-PELBIL4K.js → chunk-553VTUVP.js} +2 -2
  4. package/dist/{chunk-KT2BCHXI.js → chunk-DP37KF2X.js} +834 -822
  5. package/dist/chunk-DP37KF2X.js.map +1 -0
  6. package/dist/{chunk-IFYJFWD2.js → chunk-JHZUFBUV.js} +2 -2
  7. package/dist/{chunk-LFCS3UVG.cjs → chunk-YBPNKFJW.cjs} +2 -2
  8. package/dist/{chunk-LFCS3UVG.cjs.map → chunk-YBPNKFJW.cjs.map} +1 -1
  9. package/dist/cli.js +4 -4
  10. package/dist/index.cjs +946 -934
  11. package/dist/index.cjs.map +1 -1
  12. package/dist/index.d.cts +17 -8
  13. package/dist/index.d.ts +17 -8
  14. package/dist/index.js +833 -821
  15. package/dist/index.js.map +1 -1
  16. package/dist/mcp.js +3 -3
  17. package/dist/{parser-FFEBMLSH.js → parser-KNQDRLZQ.js} +60 -20
  18. package/dist/parser-KNQDRLZQ.js.map +1 -0
  19. package/dist/{parser-XEDROIM7.js → parser-NR2TYGO3.js} +60 -20
  20. package/dist/parser-NR2TYGO3.js.map +1 -0
  21. package/dist/{parser-IXK5V7YG.cjs → parser-NS4ZPD7B.cjs} +77 -35
  22. package/dist/parser-NS4ZPD7B.cjs.map +1 -0
  23. package/dist/{watch-MAWCDNFI.js → watch-XCWADLPU.js} +3 -3
  24. package/package.json +1 -1
  25. package/dist/chunk-KT2BCHXI.js.map +0 -1
  26. package/dist/parser-FFEBMLSH.js.map +0 -1
  27. package/dist/parser-IXK5V7YG.cjs.map +0 -1
  28. package/dist/parser-XEDROIM7.js.map +0 -1
  29. /package/dist/{-LD4BZDDJ.js.map → -FEHSMPVO.js.map} +0 -0
  30. /package/dist/{chunk-PELBIL4K.js.map → chunk-553VTUVP.js.map} +0 -0
  31. /package/dist/{chunk-IFYJFWD2.js.map → chunk-JHZUFBUV.js.map} +0 -0
  32. /package/dist/{watch-MAWCDNFI.js.map → watch-XCWADLPU.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
 
21
21
 
22
- var _chunkLFCS3UVGcjs = require('./chunk-LFCS3UVG.cjs');
22
+ var _chunkYBPNKFJWcjs = require('./chunk-YBPNKFJW.cjs');
23
23
 
24
24
 
25
25
  var _chunkDCZVOIEOcjs = require('./chunk-DCZVOIEO.cjs');
@@ -405,7 +405,7 @@ function createSectionShared() {
405
405
  function createXmlParser(warnings) {
406
406
  return new (0, _xmldom.DOMParser)({
407
407
  onError(level, msg2) {
408
- if (level === "fatalError") throw new (0, _chunkLFCS3UVGcjs.KordocError)(`XML \uD30C\uC2F1 \uC2E4\uD328: ${msg2}`);
408
+ if (level === "fatalError") throw new (0, _chunkYBPNKFJWcjs.KordocError)(`XML \uD30C\uC2F1 \uC2E4\uD328: ${msg2}`);
409
409
  _optionalChain([warnings, 'optionalAccess', _3 => _3.push, 'call', _4 => _4({ code: "MALFORMED_XML", message: `XML ${level === "warn" ? "\uACBD\uACE0" : "\uC624\uB958"}: ${msg2}` })]);
410
410
  }
411
411
  });
@@ -460,10 +460,10 @@ async function extractHwpxStyles(zip, decompressed) {
460
460
  const xml = await file.async("text");
461
461
  if (decompressed) {
462
462
  decompressed.total += xml.length * 2;
463
- if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
463
+ if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
464
464
  }
465
465
  const parser = createXmlParser();
466
- const doc = parser.parseFromString(_chunkLFCS3UVGcjs.stripDtd.call(void 0, xml), "text/xml");
466
+ const doc = parser.parseFromString(_chunkYBPNKFJWcjs.stripDtd.call(void 0, xml), "text/xml");
467
467
  if (!doc.documentElement) continue;
468
468
  parseCharProperties(doc, result.charProperties);
469
469
  parseStyleElements(doc, result.styles);
@@ -615,9 +615,9 @@ function detectHwpxHeadings(blocks, styleMap) {
615
615
  let level = 0;
616
616
  if (baseFontSize > 0 && _optionalChain([block, 'access', _7 => _7.style, 'optionalAccess', _8 => _8.fontSize])) {
617
617
  const ratio = block.style.fontSize / baseFontSize;
618
- if (ratio >= _chunkLFCS3UVGcjs.HEADING_RATIO_H1) level = 1;
619
- else if (ratio >= _chunkLFCS3UVGcjs.HEADING_RATIO_H2) level = 2;
620
- else if (ratio >= _chunkLFCS3UVGcjs.HEADING_RATIO_H3) level = 3;
618
+ if (ratio >= _chunkYBPNKFJWcjs.HEADING_RATIO_H1) level = 1;
619
+ else if (ratio >= _chunkYBPNKFJWcjs.HEADING_RATIO_H2) level = 2;
620
+ else if (ratio >= _chunkYBPNKFJWcjs.HEADING_RATIO_H3) level = 3;
621
621
  }
622
622
  const compactText = text.replace(/\s+/g, "");
623
623
  if (/^제\d+[조장절편]/.test(compactText) && text.length <= 50) {
@@ -1165,7 +1165,7 @@ function resolveParaHeading(paraEl, ctx) {
1165
1165
 
1166
1166
  // src/hwpx/table-build.ts
1167
1167
  function buildTableWithCellMeta(state) {
1168
- const table = _chunkLFCS3UVGcjs.buildTable.call(void 0, state.rows);
1168
+ const table = _chunkYBPNKFJWcjs.buildTable.call(void 0, state.rows);
1169
1169
  if (state.caption) table.caption = state.caption;
1170
1170
  const anchors = [];
1171
1171
  {
@@ -1235,7 +1235,7 @@ function completeTable(newTable, tableStack, blocks, ctx) {
1235
1235
  const cell = parentTable.cell;
1236
1236
  (cell.blocks ??= []).push(block);
1237
1237
  cell.hasStructure = true;
1238
- let flat = _chunkLFCS3UVGcjs.convertTableToText.call(void 0, newTable.rows);
1238
+ let flat = _chunkYBPNKFJWcjs.convertTableToText.call(void 0, newTable.rows);
1239
1239
  if (newTable.caption) flat = newTable.caption + (flat ? "\n" + flat : "");
1240
1240
  if (flat) cell.text += (cell.text ? "\n" : "") + flat;
1241
1241
  } else {
@@ -1247,7 +1247,7 @@ function completeTable(newTable, tableStack, blocks, ctx) {
1247
1247
  // src/hwpx/section-walker.ts
1248
1248
  function parseSectionXml(xml, styleMap, warnings, sectionNum, shared) {
1249
1249
  const parser = createXmlParser(warnings);
1250
- const doc = parser.parseFromString(_chunkLFCS3UVGcjs.stripDtd.call(void 0, xml), "text/xml");
1250
+ const doc = parser.parseFromString(_chunkYBPNKFJWcjs.stripDtd.call(void 0, xml), "text/xml");
1251
1251
  if (!doc.documentElement) return [];
1252
1252
  const ctx = { styleMap, warnings, sectionNum, shared: _nullishCoalesce(shared, () => ( createSectionShared())) };
1253
1253
  ctx.shared.track.deleteDepth = 0;
@@ -1338,8 +1338,8 @@ function walkSection(node, blocks, tableCtx, tableStack, ctx, depth = 0) {
1338
1338
  const cs = isNaN(rawCs) ? 1 : rawCs;
1339
1339
  const rawRs = parseInt(el.getAttribute("rowSpan") || "1", 10);
1340
1340
  const rs = isNaN(rawRs) ? 1 : rawRs;
1341
- tableCtx.cell.colSpan = clampSpan(cs, _chunkLFCS3UVGcjs.MAX_COLS);
1342
- tableCtx.cell.rowSpan = clampSpan(rs, _chunkLFCS3UVGcjs.MAX_ROWS);
1341
+ tableCtx.cell.colSpan = clampSpan(cs, _chunkYBPNKFJWcjs.MAX_COLS);
1342
+ tableCtx.cell.rowSpan = clampSpan(rs, _chunkYBPNKFJWcjs.MAX_ROWS);
1343
1343
  }
1344
1344
  break;
1345
1345
  case "p": {
@@ -1561,7 +1561,7 @@ function extractHyperlinkHref(fieldBegin) {
1561
1561
  let url = (ch.textContent || "").trim();
1562
1562
  if (!url) continue;
1563
1563
  url = url.replace(/^https?:\/\/(?=https?:\/\/)/i, "");
1564
- const safe = _chunkLFCS3UVGcjs.sanitizeHref.call(void 0, url);
1564
+ const safe = _chunkYBPNKFJWcjs.sanitizeHref.call(void 0, url);
1565
1565
  if (safe) return safe;
1566
1566
  }
1567
1567
  return void 0;
@@ -1696,7 +1696,7 @@ function extractParagraphInfo(para, styleMap, ctx) {
1696
1696
  case "hyperlink": {
1697
1697
  const url = child.getAttribute("url") || child.getAttribute("href") || "";
1698
1698
  if (url) {
1699
- const safe = _chunkLFCS3UVGcjs.sanitizeHref.call(void 0, url);
1699
+ const safe = _chunkYBPNKFJWcjs.sanitizeHref.call(void 0, url);
1700
1700
  if (safe) href = safe;
1701
1701
  }
1702
1702
  walk(child);
@@ -1882,13 +1882,13 @@ async function extractImagesFromZip(zip, blocks, decompressed, warnings) {
1882
1882
  }
1883
1883
  const allCandidates = resolvedPath ? [resolvedPath, ...candidates] : candidates;
1884
1884
  for (const path of allCandidates) {
1885
- if (_chunkLFCS3UVGcjs.isPathTraversal.call(void 0, path)) continue;
1885
+ if (_chunkYBPNKFJWcjs.isPathTraversal.call(void 0, path)) continue;
1886
1886
  const file = zip.file(path);
1887
1887
  if (!file) continue;
1888
1888
  try {
1889
1889
  const data = await file.async("uint8array");
1890
1890
  decompressed.total += data.length;
1891
- if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
1891
+ if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
1892
1892
  const ext = path.includes(".") ? path.split(".").pop() || "png" : "png";
1893
1893
  const mimeType = imageExtToMime(ext);
1894
1894
  imageIndex++;
@@ -1897,7 +1897,7 @@ async function extractImagesFromZip(zip, blocks, decompressed, warnings) {
1897
1897
  images.push(img);
1898
1898
  break;
1899
1899
  } catch (err) {
1900
- if (err instanceof _chunkLFCS3UVGcjs.KordocError) throw err;
1900
+ if (err instanceof _chunkYBPNKFJWcjs.KordocError) throw err;
1901
1901
  }
1902
1902
  }
1903
1903
  if (!img) _optionalChain([warnings, 'optionalAccess', _41 => _41.push, 'call', _42 => _42({ page: block.pageNumber, message: `\uC774\uBBF8\uC9C0 \uD30C\uC77C \uC5C6\uC74C: ${ref}`, code: "SKIPPED_IMAGE" })]);
@@ -1959,7 +1959,7 @@ function extractFromBrokenZip(buffer) {
1959
1959
  }
1960
1960
  const nameBytes = data.slice(pos + 30, pos + 30 + nameLen);
1961
1961
  const name = new TextDecoder().decode(nameBytes);
1962
- if (_chunkLFCS3UVGcjs.isPathTraversal.call(void 0, name)) {
1962
+ if (_chunkYBPNKFJWcjs.isPathTraversal.call(void 0, name)) {
1963
1963
  pos = fileStart + compSize;
1964
1964
  continue;
1965
1965
  }
@@ -1977,16 +1977,16 @@ function extractFromBrokenZip(buffer) {
1977
1977
  continue;
1978
1978
  }
1979
1979
  totalDecompressed += content.length * 2;
1980
- if (totalDecompressed > MAX_DECOMPRESS_SIZE) throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC");
1980
+ if (totalDecompressed > MAX_DECOMPRESS_SIZE) throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC");
1981
1981
  sectionNum++;
1982
1982
  blocks.push(...parseSectionXml(content, void 0, warnings, sectionNum, shared));
1983
1983
  } catch (e13) {
1984
1984
  continue;
1985
1985
  }
1986
1986
  }
1987
- if (blocks.length === 0) throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uC190\uC0C1\uB41C HWPX\uC5D0\uC11C \uC139\uC158 \uB370\uC774\uD130\uB97C \uBCF5\uAD6C\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
1987
+ if (blocks.length === 0) throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uC190\uC0C1\uB41C HWPX\uC5D0\uC11C \uC139\uC158 \uB370\uC774\uD130\uB97C \uBCF5\uAD6C\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
1988
1988
  applyPageText(blocks, shared);
1989
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, blocks);
1989
+ const markdown = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, blocks);
1990
1990
  return { markdown, blocks, warnings: warnings.length > 0 ? warnings : void 0 };
1991
1991
  }
1992
1992
  async function resolveSectionPaths(zip) {
@@ -2000,18 +2000,18 @@ async function resolveSectionPaths(zip) {
2000
2000
  if (paths.length > 0) return paths;
2001
2001
  }
2002
2002
  const sectionFiles = zip.file(/[Ss]ection\d+\.xml$/);
2003
- return sectionFiles.map((f) => f.name).sort(_chunkLFCS3UVGcjs.compareSectionPaths);
2003
+ return sectionFiles.map((f) => f.name).sort(_chunkYBPNKFJWcjs.compareSectionPaths);
2004
2004
  }
2005
2005
  function parseSectionPathsFromManifest(xml) {
2006
2006
  const parser = createXmlParser();
2007
- const doc = parser.parseFromString(_chunkLFCS3UVGcjs.stripDtd.call(void 0, xml), "text/xml");
2007
+ const doc = parser.parseFromString(_chunkYBPNKFJWcjs.stripDtd.call(void 0, xml), "text/xml");
2008
2008
  const items = doc.getElementsByTagName("opf:item");
2009
2009
  const spine = doc.getElementsByTagName("opf:itemref");
2010
2010
  const idToHref = /* @__PURE__ */ new Map();
2011
2011
  for (let i = 0; i < items.length; i++) {
2012
2012
  const item = items[i];
2013
2013
  const id = item.getAttribute("id") || "";
2014
- const href = _chunkLFCS3UVGcjs.normalizeSectionHref.call(void 0, item.getAttribute("href") || "");
2014
+ const href = _chunkYBPNKFJWcjs.normalizeSectionHref.call(void 0, item.getAttribute("href") || "");
2015
2015
  if (id && href) idToHref.set(id, href);
2016
2016
  }
2017
2017
  if (spine.length > 0) {
@@ -2022,7 +2022,7 @@ function parseSectionPathsFromManifest(xml) {
2022
2022
  }
2023
2023
  if (ordered.length > 0) return ordered;
2024
2024
  }
2025
- return Array.from(idToHref.values()).sort(_chunkLFCS3UVGcjs.compareSectionPaths);
2025
+ return Array.from(idToHref.values()).sort(_chunkYBPNKFJWcjs.compareSectionPaths);
2026
2026
  }
2027
2027
 
2028
2028
  // src/hwpx/metadata.ts
@@ -2035,7 +2035,7 @@ async function extractHwpxMetadata(zip, metadata, decompressed) {
2035
2035
  const xml = await file.async("text");
2036
2036
  if (decompressed) {
2037
2037
  decompressed.total += xml.length * 2;
2038
- if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
2038
+ if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
2039
2039
  }
2040
2040
  parseDublinCoreMetadata(xml, metadata);
2041
2041
  if (metadata.title || metadata.author) return;
@@ -2045,7 +2045,7 @@ async function extractHwpxMetadata(zip, metadata, decompressed) {
2045
2045
  }
2046
2046
  function parseDublinCoreMetadata(xml, metadata) {
2047
2047
  const parser = createXmlParser();
2048
- const doc = parser.parseFromString(_chunkLFCS3UVGcjs.stripDtd.call(void 0, xml), "text/xml");
2048
+ const doc = parser.parseFromString(_chunkYBPNKFJWcjs.stripDtd.call(void 0, xml), "text/xml");
2049
2049
  if (!doc.documentElement) return;
2050
2050
  const getText = (tagNames) => {
2051
2051
  for (const tag of tagNames) {
@@ -2070,7 +2070,7 @@ function parseDublinCoreMetadata(xml, metadata) {
2070
2070
 
2071
2071
  // src/hwpx/parser.ts
2072
2072
  async function parseHwpxDocument(buffer, options) {
2073
- _chunkLFCS3UVGcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE, MAX_ZIP_ENTRIES);
2073
+ _chunkYBPNKFJWcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE, MAX_ZIP_ENTRIES);
2074
2074
  let zip;
2075
2075
  try {
2076
2076
  zip = await _jszip2.default.loadAsync(buffer);
@@ -2079,7 +2079,7 @@ async function parseHwpxDocument(buffer, options) {
2079
2079
  }
2080
2080
  const actualEntryCount = Object.keys(zip.files).length;
2081
2081
  if (actualEntryCount > MAX_ZIP_ENTRIES) {
2082
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP \uC5D4\uD2B8\uB9AC \uC218 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
2082
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP \uC5D4\uD2B8\uB9AC \uC218 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
2083
2083
  }
2084
2084
  const manifestFile = zip.file("META-INF/manifest.xml");
2085
2085
  if (manifestFile) {
@@ -2091,7 +2091,7 @@ async function parseHwpxDocument(buffer, options) {
2091
2091
  return comResultToParseResult(pages, pageCount, warnings2);
2092
2092
  }
2093
2093
  }
2094
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("DRM \uC554\uD638\uD654\uB41C HWPX \uD30C\uC77C\uC785\uB2C8\uB2E4. Windows + \uD55C\uCEF4 \uC624\uD53C\uC2A4 \uC124\uCE58 \uC2DC \uC790\uB3D9 \uCD94\uCD9C\uB429\uB2C8\uB2E4.");
2094
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("DRM \uC554\uD638\uD654\uB41C HWPX \uD30C\uC77C\uC785\uB2C8\uB2E4. Windows + \uD55C\uCEF4 \uC624\uD53C\uC2A4 \uC124\uCE58 \uC2DC \uC790\uB3D9 \uCD94\uCD9C\uB429\uB2C8\uB2E4.");
2095
2095
  }
2096
2096
  }
2097
2097
  const decompressed = { total: 0 };
@@ -2100,7 +2100,7 @@ async function parseHwpxDocument(buffer, options) {
2100
2100
  const styleMap = await extractHwpxStyles(zip, decompressed);
2101
2101
  const warnings = [];
2102
2102
  const sectionPaths = await resolveSectionPaths(zip);
2103
- if (sectionPaths.length === 0) throw new (0, _chunkLFCS3UVGcjs.KordocError)("HWPX\uC5D0\uC11C \uC139\uC158 \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
2103
+ if (sectionPaths.length === 0) throw new (0, _chunkYBPNKFJWcjs.KordocError)("HWPX\uC5D0\uC11C \uC139\uC158 \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
2104
2104
  metadata.pageCount = sectionPaths.length;
2105
2105
  const pageFilter = _optionalChain([options, 'optionalAccess', _48 => _48.pages]) ? _chunkDCZVOIEOcjs.parsePageRange.call(void 0, options.pages, sectionPaths.length) : null;
2106
2106
  const totalTarget = pageFilter ? pageFilter.size : sectionPaths.length;
@@ -2114,12 +2114,12 @@ async function parseHwpxDocument(buffer, options) {
2114
2114
  try {
2115
2115
  const xml = await file.async("text");
2116
2116
  decompressed.total += xml.length * 2;
2117
- if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
2117
+ if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
2118
2118
  blocks.push(...parseSectionXml(xml, styleMap, warnings, si + 1, shared));
2119
2119
  parsedSections++;
2120
2120
  _optionalChain([options, 'optionalAccess', _49 => _49.onProgress, 'optionalCall', _50 => _50(parsedSections, totalTarget)]);
2121
2121
  } catch (secErr) {
2122
- if (secErr instanceof _chunkLFCS3UVGcjs.KordocError) throw secErr;
2122
+ if (secErr instanceof _chunkYBPNKFJWcjs.KordocError) throw secErr;
2123
2123
  warnings.push({ page: si + 1, message: `\uC139\uC158 ${si + 1} \uD30C\uC2F1 \uC2E4\uD328: ${secErr instanceof Error ? secErr.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"}`, code: "PARTIAL_PARSE" });
2124
2124
  }
2125
2125
  }
@@ -2127,7 +2127,7 @@ async function parseHwpxDocument(buffer, options) {
2127
2127
  const images = await extractImagesFromZip(zip, blocks, decompressed, warnings);
2128
2128
  detectHwpxHeadings(blocks, styleMap);
2129
2129
  const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
2130
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, blocks);
2130
+ const markdown = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, blocks);
2131
2131
  return { markdown, blocks, metadata, outline: outline.length > 0 ? outline : void 0, warnings: warnings.length > 0 ? warnings : void 0, images: images.length > 0 ? images : void 0 };
2132
2132
  }
2133
2133
 
@@ -2194,7 +2194,7 @@ function decompressStream(data) {
2194
2194
  return _zlib.inflateRawSync.call(void 0, data, opts);
2195
2195
  }
2196
2196
  function parseFileHeader(data) {
2197
- if (data.length < 40) throw new (0, _chunkLFCS3UVGcjs.KordocError)("FileHeader\uAC00 \uB108\uBB34 \uC9E7\uC2B5\uB2C8\uB2E4 (\uCD5C\uC18C 40\uBC14\uC774\uD2B8)");
2197
+ if (data.length < 40) throw new (0, _chunkYBPNKFJWcjs.KordocError)("FileHeader\uAC00 \uB108\uBB34 \uC9E7\uC2B5\uB2C8\uB2E4 (\uCD5C\uC18C 40\uBC14\uC774\uD2B8)");
2198
2198
  const sig = data.subarray(0, 32).toString("utf8").replace(/\0+$/, "");
2199
2199
  return {
2200
2200
  signature: sig,
@@ -3728,7 +3728,7 @@ function parseHwp5Document(buffer, options) {
3728
3728
  lenientCfb = parseLenientCfb(buffer);
3729
3729
  warnings.push({ message: "\uC190\uC0C1\uB41C CFB \uCEE8\uD14C\uC774\uB108 \u2014 lenient \uBAA8\uB4DC\uB85C \uBCF5\uAD6C", code: "LENIENT_CFB_RECOVERY" });
3730
3730
  } catch (e21) {
3731
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("CFB \uCEE8\uD14C\uC774\uB108 \uD30C\uC2F1 \uC2E4\uD328 (strict \uBC0F lenient \uBAA8\uB450)");
3731
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("CFB \uCEE8\uD14C\uC774\uB108 \uD30C\uC2F1 \uC2E4\uD328 (strict \uBC0F lenient \uBAA8\uB450)");
3732
3732
  }
3733
3733
  }
3734
3734
  const findStream = (path) => {
@@ -3739,11 +3739,11 @@ function parseHwp5Document(buffer, options) {
3739
3739
  return lenientCfb.findStream(path);
3740
3740
  };
3741
3741
  const headerData = findStream("/FileHeader");
3742
- if (!headerData) throw new (0, _chunkLFCS3UVGcjs.KordocError)("FileHeader \uC2A4\uD2B8\uB9BC \uC5C6\uC74C");
3742
+ if (!headerData) throw new (0, _chunkYBPNKFJWcjs.KordocError)("FileHeader \uC2A4\uD2B8\uB9BC \uC5C6\uC74C");
3743
3743
  const header = parseFileHeader(headerData);
3744
- if (header.signature !== "HWP Document File") throw new (0, _chunkLFCS3UVGcjs.KordocError)("HWP \uC2DC\uADF8\uB2C8\uCC98 \uBD88\uC77C\uCE58");
3745
- if (header.flags & FLAG_ENCRYPTED) throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uC554\uD638\uD654\uB41C HWP\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
3746
- if (header.flags & FLAG_DRM) throw new (0, _chunkLFCS3UVGcjs.KordocError)("DRM \uBCF4\uD638\uB41C HWP\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
3744
+ if (header.signature !== "HWP Document File") throw new (0, _chunkYBPNKFJWcjs.KordocError)("HWP \uC2DC\uADF8\uB2C8\uCC98 \uBD88\uC77C\uCE58");
3745
+ if (header.flags & FLAG_ENCRYPTED) throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uC554\uD638\uD654\uB41C HWP\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
3746
+ if (header.flags & FLAG_DRM) throw new (0, _chunkYBPNKFJWcjs.KordocError)("DRM \uBCF4\uD638\uB41C HWP\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
3747
3747
  const compressed = (header.flags & FLAG_COMPRESSED) !== 0;
3748
3748
  const distribution = (header.flags & FLAG_DISTRIBUTION) !== 0;
3749
3749
  const metadata = {
@@ -3752,7 +3752,7 @@ function parseHwp5Document(buffer, options) {
3752
3752
  if (cfb) extractHwp5Metadata(cfb, metadata);
3753
3753
  const docInfo = cfb ? parseDocInfoStream(cfb, compressed) : parseDocInfoFromStream(findStream("/DocInfo"), compressed);
3754
3754
  const sections = distribution ? cfb ? findViewTextSections(cfb, compressed) : findViewTextSectionsLenient(lenientCfb, compressed) : cfb ? findSections(cfb) : findSectionsLenient(lenientCfb, compressed);
3755
- if (sections.length === 0) throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uC139\uC158 \uC2A4\uD2B8\uB9BC\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
3755
+ if (sections.length === 0) throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uC139\uC158 \uC2A4\uD2B8\uB9BC\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
3756
3756
  metadata.pageCount = sections.length;
3757
3757
  const pageFilter = _optionalChain([options, 'optionalAccess', _54 => _54.pages]) ? _chunkDCZVOIEOcjs.parsePageRange.call(void 0, options.pages, sections.length) : null;
3758
3758
  const totalTarget = pageFilter ? pageFilter.size : sections.length;
@@ -3766,25 +3766,25 @@ function parseHwp5Document(buffer, options) {
3766
3766
  const sectionData = sections[si];
3767
3767
  const data = !distribution && compressed ? decompressStream(Buffer.from(sectionData)) : Buffer.from(sectionData);
3768
3768
  totalDecompressed += data.length;
3769
- if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
3769
+ if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
3770
3770
  const records = readRecords(data);
3771
3771
  const sectionBlocks = parseSection(records, docInfo, warnings, si + 1, doc);
3772
3772
  bodyBlocks.push(...sectionBlocks);
3773
3773
  parsedSections++;
3774
3774
  _optionalChain([options, 'optionalAccess', _55 => _55.onProgress, 'optionalCall', _56 => _56(parsedSections, totalTarget)]);
3775
3775
  } catch (secErr) {
3776
- if (secErr instanceof _chunkLFCS3UVGcjs.KordocError) throw secErr;
3776
+ if (secErr instanceof _chunkYBPNKFJWcjs.KordocError) throw secErr;
3777
3777
  warnings.push({ page: si + 1, message: `\uC139\uC158 ${si + 1} \uD30C\uC2F1 \uC2E4\uD328: ${secErr instanceof Error ? secErr.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"}`, code: "PARTIAL_PARSE" });
3778
3778
  }
3779
3779
  }
3780
3780
  const blocks = [...doc.headerBlocks, ...bodyBlocks, ...doc.footerBlocks];
3781
3781
  const images = cfb ? extractHwp5Images(cfb.FileIndex, blocks, warnings) : extractHwp5ImagesLenient(lenientCfb, blocks, warnings);
3782
- const flatBlocks = _chunkLFCS3UVGcjs.flattenLayoutTables.call(void 0, blocks);
3782
+ const flatBlocks = _chunkYBPNKFJWcjs.flattenLayoutTables.call(void 0, blocks);
3783
3783
  if (docInfo) {
3784
3784
  detectHwp5Headings(flatBlocks, docInfo);
3785
3785
  }
3786
3786
  const outline = flatBlocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
3787
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, flatBlocks);
3787
+ const markdown = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, flatBlocks);
3788
3788
  return { markdown, blocks: flatBlocks, metadata, outline: outline.length > 0 ? outline : void 0, warnings: warnings.length > 0 ? warnings : void 0, images: images.length > 0 ? images : void 0 };
3789
3789
  }
3790
3790
  function parseDocInfoStream(cfb, compressed) {
@@ -3844,9 +3844,9 @@ function detectHwp5Headings(blocks, docInfo) {
3844
3844
  let level = 0;
3845
3845
  if (_optionalChain([block, 'access', _61 => _61.style, 'optionalAccess', _62 => _62.fontSize]) && baseFontSize > 0) {
3846
3846
  const ratio = block.style.fontSize / baseFontSize;
3847
- if (ratio >= _chunkLFCS3UVGcjs.HEADING_RATIO_H1) level = 1;
3848
- else if (ratio >= _chunkLFCS3UVGcjs.HEADING_RATIO_H2) level = 2;
3849
- else if (ratio >= _chunkLFCS3UVGcjs.HEADING_RATIO_H3) level = 3;
3847
+ if (ratio >= _chunkYBPNKFJWcjs.HEADING_RATIO_H1) level = 1;
3848
+ else if (ratio >= _chunkYBPNKFJWcjs.HEADING_RATIO_H2) level = 2;
3849
+ else if (ratio >= _chunkYBPNKFJWcjs.HEADING_RATIO_H3) level = 3;
3850
3850
  }
3851
3851
  if (/^제\d+[장절편]\s/.test(text) && text.length <= 50) {
3852
3852
  if (level === 0) level = 2;
@@ -3931,7 +3931,7 @@ function findSectionsLenient(lcfb, compressed) {
3931
3931
  if (!raw) break;
3932
3932
  const content = compressed ? decompressStream(raw) : raw;
3933
3933
  totalDecompressed += content.length;
3934
- if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
3934
+ if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
3935
3935
  sections.push({ idx: i, content });
3936
3936
  }
3937
3937
  if (sections.length === 0) {
@@ -3943,7 +3943,7 @@ function findSectionsLenient(lcfb, compressed) {
3943
3943
  if (raw) {
3944
3944
  const content = compressed ? decompressStream(raw) : raw;
3945
3945
  totalDecompressed += content.length;
3946
- if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
3946
+ if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
3947
3947
  sections.push({ idx, content });
3948
3948
  }
3949
3949
  }
@@ -3960,7 +3960,7 @@ function findViewTextSectionsLenient(lcfb, compressed) {
3960
3960
  try {
3961
3961
  const content = decryptViewText(raw, compressed);
3962
3962
  totalDecompressed += content.length;
3963
- if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
3963
+ if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
3964
3964
  sections.push({ idx: i, content });
3965
3965
  } catch (e26) {
3966
3966
  break;
@@ -4063,7 +4063,7 @@ function parseParagraph(records, start, end, ctx) {
4063
4063
  const ctrl = ctrls[r.ctrlIdx];
4064
4064
  if (!_optionalChain([ctrl, 'optionalAccess', _69 => _69.href]) || r.end <= r.start) continue;
4065
4065
  if (applied.some(([s, e]) => r.start < e && r.end > s)) continue;
4066
- const href = _chunkLFCS3UVGcjs.sanitizeHref.call(void 0, ctrl.href);
4066
+ const href = _chunkYBPNKFJWcjs.sanitizeHref.call(void 0, ctrl.href);
4067
4067
  if (!href) continue;
4068
4068
  const anchor = text.slice(r.start, r.end);
4069
4069
  if (!anchor.trim()) continue;
@@ -4296,8 +4296,8 @@ function parseTableControl(ctrl, records, ctx) {
4296
4296
  let tableIdx = -1;
4297
4297
  for (let i2 = childStart; i2 < childEnd; i2++) {
4298
4298
  if (records[i2].tagId === TAG_TABLE && records[i2].data.length >= 8) {
4299
- rows = Math.min(records[i2].data.readUInt16LE(4), _chunkLFCS3UVGcjs.MAX_ROWS);
4300
- cols = Math.min(records[i2].data.readUInt16LE(6), _chunkLFCS3UVGcjs.MAX_COLS);
4299
+ rows = Math.min(records[i2].data.readUInt16LE(4), _chunkYBPNKFJWcjs.MAX_ROWS);
4300
+ cols = Math.min(records[i2].data.readUInt16LE(6), _chunkYBPNKFJWcjs.MAX_COLS);
4301
4301
  tableIdx = i2;
4302
4302
  break;
4303
4303
  }
@@ -4346,7 +4346,7 @@ function parseTableControl(ctrl, records, ctx) {
4346
4346
  return table2;
4347
4347
  }
4348
4348
  const cellRows = arrangeCells(rows, cols, cells);
4349
- const table = _chunkLFCS3UVGcjs.buildTable.call(void 0, cellRows);
4349
+ const table = _chunkYBPNKFJWcjs.buildTable.call(void 0, cellRows);
4350
4350
  if (caption && table.rows > 0) table.caption = caption;
4351
4351
  return table.rows > 0 ? table : null;
4352
4352
  }
@@ -4363,8 +4363,8 @@ function parseCell(records, lhIdx, end, ctx) {
4363
4363
  rowAddr = rec.data.readUInt16LE(10);
4364
4364
  const cs = rec.data.readUInt16LE(12);
4365
4365
  const rs = rec.data.readUInt16LE(14);
4366
- if (cs > 0) colSpan = Math.min(cs, _chunkLFCS3UVGcjs.MAX_COLS);
4367
- if (rs > 0) rowSpan = Math.min(rs, _chunkLFCS3UVGcjs.MAX_ROWS);
4366
+ if (cs > 0) colSpan = Math.min(cs, _chunkYBPNKFJWcjs.MAX_COLS);
4367
+ if (rs > 0) rowSpan = Math.min(rs, _chunkYBPNKFJWcjs.MAX_ROWS);
4368
4368
  }
4369
4369
  const blocks = ctx.depth < MAX_NEST_DEPTH ? parseParagraphList(records, lhIdx + 1, end, { ...ctx, depth: ctx.depth + 1 }) : [];
4370
4370
  const parts = [];
@@ -4374,7 +4374,7 @@ function parseCell(records, lhIdx, end, ctx) {
4374
4374
  parts.push(`![image](hwp5bin:${b.text})`);
4375
4375
  hasStructure = true;
4376
4376
  } else if (b.type === "table" && b.table) {
4377
- const flat = _chunkLFCS3UVGcjs.convertTableToText.call(void 0, b.table.cells);
4377
+ const flat = _chunkYBPNKFJWcjs.convertTableToText.call(void 0, b.table.cells);
4378
4378
  if (flat) parts.push(flat);
4379
4379
  hasStructure = true;
4380
4380
  } else if (b.text) {
@@ -16808,7 +16808,7 @@ function getTextContent(el) {
16808
16808
  return _nullishCoalesce(_optionalChain([el, 'access', _82 => _82.textContent, 'optionalAccess', _83 => _83.trim, 'call', _84 => _84()]), () => ( ""));
16809
16809
  }
16810
16810
  function parseXml(text) {
16811
- return new (0, _xmldom.DOMParser)().parseFromString(_chunkLFCS3UVGcjs.stripDtd.call(void 0, text), "text/xml");
16811
+ return new (0, _xmldom.DOMParser)().parseFromString(_chunkYBPNKFJWcjs.stripDtd.call(void 0, text), "text/xml");
16812
16812
  }
16813
16813
  function parseSharedStrings(xml) {
16814
16814
  const doc = parseXml(xml);
@@ -16952,7 +16952,7 @@ function sheetToBlocks(sheetName, grid, merges, maxRow, maxCol, sheetIndex) {
16952
16952
  cellRows.push(row);
16953
16953
  }
16954
16954
  if (cellRows.length > 0) {
16955
- const table = _chunkLFCS3UVGcjs.buildTable.call(void 0, cellRows);
16955
+ const table = _chunkYBPNKFJWcjs.buildTable.call(void 0, cellRows);
16956
16956
  if (table.rows > 0) {
16957
16957
  blocks.push({ type: "table", table, pageNumber: sheetIndex + 1 });
16958
16958
  }
@@ -16960,12 +16960,12 @@ function sheetToBlocks(sheetName, grid, merges, maxRow, maxCol, sheetIndex) {
16960
16960
  return blocks;
16961
16961
  }
16962
16962
  async function parseXlsxDocument(buffer, options) {
16963
- _chunkLFCS3UVGcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE3);
16963
+ _chunkYBPNKFJWcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE3);
16964
16964
  const zip = await _jszip2.default.loadAsync(buffer);
16965
16965
  const warnings = [];
16966
16966
  const workbookFile = zip.file("xl/workbook.xml");
16967
16967
  if (!workbookFile) {
16968
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 XLSX \uD30C\uC77C: xl/workbook.xml\uC774 \uC5C6\uC2B5\uB2C8\uB2E4");
16968
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 XLSX \uD30C\uC77C: xl/workbook.xml\uC774 \uC5C6\uC2B5\uB2C8\uB2E4");
16969
16969
  }
16970
16970
  let sharedStrings = [];
16971
16971
  const ssFile = zip.file("xl/sharedStrings.xml");
@@ -16974,7 +16974,7 @@ async function parseXlsxDocument(buffer, options) {
16974
16974
  }
16975
16975
  const sheets = parseWorkbook(await workbookFile.async("text"));
16976
16976
  if (sheets.length === 0) {
16977
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("XLSX \uD30C\uC77C\uC5D0 \uC2DC\uD2B8\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4");
16977
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("XLSX \uD30C\uC77C\uC5D0 \uC2DC\uD2B8\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4");
16978
16978
  }
16979
16979
  let relsMap = /* @__PURE__ */ new Map();
16980
16980
  const relsFile = zip.file("xl/_rels/workbook.xml.rels");
@@ -17046,7 +17046,7 @@ async function parseXlsxDocument(buffer, options) {
17046
17046
  } catch (e27) {
17047
17047
  }
17048
17048
  }
17049
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, blocks);
17049
+ const markdown = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, blocks);
17050
17050
  return { markdown, blocks, metadata, warnings: warnings.length > 0 ? warnings : void 0 };
17051
17051
  }
17052
17052
 
@@ -17453,11 +17453,11 @@ function processGlobals(records) {
17453
17453
  let encrypted = false;
17454
17454
  const firstBof = records[0];
17455
17455
  if (!firstBof || firstBof.opcode !== OP_BOF) {
17456
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("XLS: \uCCAB \uB808\uCF54\uB4DC\uAC00 BOF\uAC00 \uC544\uB2D8");
17456
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("XLS: \uCCAB \uB808\uCF54\uB4DC\uAC00 BOF\uAC00 \uC544\uB2D8");
17457
17457
  }
17458
17458
  const bof = decodeBof(firstBof.data);
17459
17459
  if (!bof || bof.dt !== DT_GLOBALS) {
17460
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("XLS: Globals \uC11C\uBE0C\uC2A4\uD2B8\uB9BC BOF \uB204\uB77D");
17460
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("XLS: Globals \uC11C\uBE0C\uC2A4\uD2B8\uB9BC BOF \uB204\uB77D");
17461
17461
  }
17462
17462
  let i = 1;
17463
17463
  while (i < records.length) {
@@ -17572,7 +17572,7 @@ function sheetToBlocks2(sheetName, sheet, sheetIndex) {
17572
17572
  cellRows.push(row);
17573
17573
  }
17574
17574
  if (cellRows.length > 0) {
17575
- const table = _chunkLFCS3UVGcjs.buildTable.call(void 0, cellRows);
17575
+ const table = _chunkYBPNKFJWcjs.buildTable.call(void 0, cellRows);
17576
17576
  if (table.rows > 0) {
17577
17577
  blocks.push({ type: "table", table, pageNumber: sheetIndex + 1 });
17578
17578
  }
@@ -17585,21 +17585,21 @@ async function parseXlsDocument(buffer, options) {
17585
17585
  try {
17586
17586
  cfb = parseLenientCfb(buf);
17587
17587
  } catch (e) {
17588
- throw new (0, _chunkLFCS3UVGcjs.KordocError)(
17588
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)(
17589
17589
  `XLS: OLE2 \uC2DC\uADF8\uB2C8\uCC98 \uAC80\uC99D \uC2E4\uD328 \u2014 ${e instanceof Error ? e.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"}`
17590
17590
  );
17591
17591
  }
17592
17592
  const wb = _nullishCoalesce(cfb.findStream("/Workbook"), () => ( cfb.findStream("/Book")));
17593
17593
  if (!wb) {
17594
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("XLS: Workbook \uC2A4\uD2B8\uB9BC\uC774 \uC5C6\uC74C (BIFF5 \uB610\uB294 \uBE44\uD45C\uC900 \uD30C\uC77C)");
17594
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("XLS: Workbook \uC2A4\uD2B8\uB9BC\uC774 \uC5C6\uC74C (BIFF5 \uB610\uB294 \uBE44\uD45C\uC900 \uD30C\uC77C)");
17595
17595
  }
17596
17596
  const records = readRecords2(wb);
17597
17597
  if (records.length === 0) {
17598
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("XLS: \uC2DC\uADF8\uB2C8\uCC98 \uB808\uCF54\uB4DC\uAC00 \uC5C6\uC74C (Workbook \uC2A4\uD2B8\uB9BC \uC190\uC0C1)");
17598
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("XLS: \uC2DC\uADF8\uB2C8\uCC98 \uB808\uCF54\uB4DC\uAC00 \uC5C6\uC74C (Workbook \uC2A4\uD2B8\uB9BC \uC190\uC0C1)");
17599
17599
  }
17600
17600
  const firstBof = decodeBof(records[0].data);
17601
17601
  if (firstBof && firstBof.vers !== 1536) {
17602
- throw new (0, _chunkLFCS3UVGcjs.KordocError)(
17602
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)(
17603
17603
  `XLS: BIFF8(0x0600)\uB9CC \uC9C0\uC6D0 \u2014 \uBCF8 \uD30C\uC77C\uC740 0x${firstBof.vers.toString(16)}`
17604
17604
  );
17605
17605
  }
@@ -17659,7 +17659,7 @@ async function parseXlsDocument(buffer, options) {
17659
17659
  pageCount: totalSheets
17660
17660
  };
17661
17661
  return {
17662
- markdown: _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, allBlocks),
17662
+ markdown: _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, allBlocks),
17663
17663
  blocks: allBlocks,
17664
17664
  metadata,
17665
17665
  warnings: warnings.length > 0 ? warnings : void 0
@@ -18097,7 +18097,7 @@ function getAttr(el, localName2) {
18097
18097
  return null;
18098
18098
  }
18099
18099
  function parseXml2(text) {
18100
- return new (0, _xmldom.DOMParser)().parseFromString(_chunkLFCS3UVGcjs.stripDtd.call(void 0, text), "text/xml");
18100
+ return new (0, _xmldom.DOMParser)().parseFromString(_chunkYBPNKFJWcjs.stripDtd.call(void 0, text), "text/xml");
18101
18101
  }
18102
18102
  function parseStyles(xml) {
18103
18103
  const doc = parseXml2(xml);
@@ -18420,12 +18420,12 @@ async function extractImages(zip, rels, doc, warnings) {
18420
18420
  return { blocks, images };
18421
18421
  }
18422
18422
  async function parseDocxDocument(buffer, options) {
18423
- _chunkLFCS3UVGcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE4);
18423
+ _chunkYBPNKFJWcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE4);
18424
18424
  const zip = await _jszip2.default.loadAsync(buffer);
18425
18425
  const warnings = [];
18426
18426
  const docFile = zip.file("word/document.xml");
18427
18427
  if (!docFile) {
18428
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 DOCX \uD30C\uC77C: word/document.xml\uC774 \uC5C6\uC2B5\uB2C8\uB2E4");
18428
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 DOCX \uD30C\uC77C: word/document.xml\uC774 \uC5C6\uC2B5\uB2C8\uB2E4");
18429
18429
  }
18430
18430
  let rels = /* @__PURE__ */ new Map();
18431
18431
  const relsFile = zip.file("word/_rels/document.xml.rels");
@@ -18472,7 +18472,7 @@ async function parseDocxDocument(buffer, options) {
18472
18472
  const doc = parseXml2(docXml);
18473
18473
  const body = findElements(doc, "body");
18474
18474
  if (body.length === 0) {
18475
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("DOCX \uBCF8\uBB38(w:body)\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
18475
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("DOCX \uBCF8\uBB38(w:body)\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
18476
18476
  }
18477
18477
  const blocks = [];
18478
18478
  const bodyEl = body[0];
@@ -18513,7 +18513,7 @@ async function parseDocxDocument(buffer, options) {
18513
18513
  }
18514
18514
  }
18515
18515
  const outline = blocks.filter((b) => b.type === "heading").map((b) => ({ level: _nullishCoalesce(b.level, () => ( 2)), text: _nullishCoalesce(b.text, () => ( "")) }));
18516
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, blocks);
18516
+ const markdown = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, blocks);
18517
18517
  return {
18518
18518
  markdown,
18519
18519
  blocks,
@@ -18536,7 +18536,7 @@ function parseHwpmlDocument(buffer, options) {
18536
18536
  }
18537
18537
  const text = new TextDecoder("utf-8").decode(buffer).replace(/^\uFEFF/, "");
18538
18538
  const normalized = text.replace(/&nbsp;/g, "&#160;");
18539
- const xml = _chunkLFCS3UVGcjs.stripDtd.call(void 0, normalized);
18539
+ const xml = _chunkYBPNKFJWcjs.stripDtd.call(void 0, normalized);
18540
18540
  const warnings = [];
18541
18541
  const parser = new (0, _xmldom.DOMParser)({
18542
18542
  onError: (_level, msg2) => {
@@ -18576,7 +18576,7 @@ function parseHwpmlDocument(buffer, options) {
18576
18576
  parseSection2(el, blocks, paraShapeMap, sectionIdx, warnings);
18577
18577
  }
18578
18578
  const outline = blocks.filter((b) => b.type === "heading" && b.text).map((b) => ({ level: _nullishCoalesce(b.level, () => ( 1)), text: b.text, pageNumber: b.pageNumber }));
18579
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, blocks);
18579
+ const markdown = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, blocks);
18580
18580
  return {
18581
18581
  markdown,
18582
18582
  blocks,
@@ -18718,7 +18718,7 @@ function parseTable2(el, blocks, paraShapeMap, sectionNum, warnings) {
18718
18718
  const cellRows = grid.map(
18719
18719
  (row) => row.map((cell) => _nullishCoalesce(cell, () => ( { text: "", colSpan: 1, rowSpan: 1 })))
18720
18720
  );
18721
- const table = _chunkLFCS3UVGcjs.buildTable.call(void 0, cellRows);
18721
+ const table = _chunkYBPNKFJWcjs.buildTable.call(void 0, cellRows);
18722
18722
  blocks.push({ type: "table", table, pageNumber: sectionNum });
18723
18723
  }
18724
18724
  function extractCellText(cellEl) {
@@ -19891,19 +19891,19 @@ function parseCentralDirectory(buf) {
19891
19891
  }
19892
19892
  }
19893
19893
  }
19894
- if (eocdOffset < 0) throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP EOCD\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
19894
+ if (eocdOffset < 0) throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP EOCD\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
19895
19895
  const totalEntries = view.getUint16(eocdOffset + 10, true);
19896
19896
  const cdSize = view.getUint32(eocdOffset + 12, true);
19897
19897
  const cdOffset = view.getUint32(eocdOffset + 16, true);
19898
- if (cdOffset === 4294967295 || totalEntries === 65535) throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19898
+ if (cdOffset === 4294967295 || totalEntries === 65535) throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19899
19899
  if (eocdOffset >= 20 && view.getUint32(eocdOffset - 20, true) === ZIP64_EOCD_LOC_SIG) {
19900
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19900
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19901
19901
  }
19902
19902
  const decoder = new TextDecoder("utf-8");
19903
19903
  const entries = [];
19904
19904
  let pos = cdOffset;
19905
19905
  for (let i = 0; i < totalEntries; i++) {
19906
- if (view.getUint32(pos, true) !== CD_SIG) throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP Central Directory \uC190\uC0C1");
19906
+ if (view.getUint32(pos, true) !== CD_SIG) throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP Central Directory \uC190\uC0C1");
19907
19907
  const flags = view.getUint16(pos + 8, true);
19908
19908
  const method = view.getUint16(pos + 10, true);
19909
19909
  const crc = view.getUint32(pos + 16, true);
@@ -19914,7 +19914,7 @@ function parseCentralDirectory(buf) {
19914
19914
  const commentLen = view.getUint16(pos + 32, true);
19915
19915
  const localOffset = view.getUint32(pos + 42, true);
19916
19916
  if (compSize === 4294967295 || uncompSize === 4294967295 || localOffset === 4294967295) {
19917
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19917
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19918
19918
  }
19919
19919
  const name = decoder.decode(buf.subarray(pos + 46, pos + 46 + nameLen));
19920
19920
  const cdEnd = pos + 46 + nameLen + extraLen + commentLen;
@@ -19943,7 +19943,7 @@ function patchZipEntries(original, replacements) {
19943
19943
  const { entries, cdOffset, eocdOffset } = parseCentralDirectory(original);
19944
19944
  const view = new DataView(original.buffer, original.byteOffset, original.byteLength);
19945
19945
  for (const name of replacements.keys()) {
19946
- if (!entries.some((e) => e.name === name)) throw new (0, _chunkLFCS3UVGcjs.KordocError)(`ZIP\uC5D0 \uC5C6\uB294 \uC5D4\uD2B8\uB9AC: ${name}`);
19946
+ if (!entries.some((e) => e.name === name)) throw new (0, _chunkYBPNKFJWcjs.KordocError)(`ZIP\uC5D0 \uC5C6\uB294 \uC5D4\uD2B8\uB9AC: ${name}`);
19947
19947
  }
19948
19948
  const byLocal = [...entries].sort((a, b) => a.localOffset - b.localOffset);
19949
19949
  const segments = [];
@@ -19961,7 +19961,7 @@ function patchZipEntries(original, replacements) {
19961
19961
  offset += seg.length;
19962
19962
  continue;
19963
19963
  }
19964
- if (view.getUint32(e.localOffset, true) !== LOCAL_SIG) throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP \uB85C\uCEEC \uD5E4\uB354 \uC2DC\uADF8\uB2C8\uCC98 \uBD88\uC77C\uCE58");
19964
+ if (view.getUint32(e.localOffset, true) !== LOCAL_SIG) throw new (0, _chunkYBPNKFJWcjs.KordocError)("ZIP \uB85C\uCEEC \uD5E4\uB354 \uC2DC\uADF8\uB2C8\uCC98 \uBD88\uC77C\uCE58");
19965
19965
  const nameLen = view.getUint16(e.localOffset + 26, true);
19966
19966
  const extraLen = view.getUint16(e.localOffset + 28, true);
19967
19967
  const headerLen = 30 + nameLen + extraLen;
@@ -20016,7 +20016,7 @@ async function fillHwpx(hwpxBuffer, values) {
20016
20016
  const zip = await _jszip2.default.loadAsync(hwpxBuffer);
20017
20017
  const sectionPaths = Object.keys(zip.files).filter((name) => /[Ss]ection\d+\.xml$/i.test(name)).sort();
20018
20018
  if (sectionPaths.length === 0) {
20019
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("HWPX\uC5D0\uC11C \uC139\uC158 \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
20019
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)("HWPX\uC5D0\uC11C \uC139\uC158 \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
20020
20020
  }
20021
20021
  const normalizedValues = normalizeValues(values);
20022
20022
  const cursor = new ValueCursor(normalizedValues);
@@ -20625,53 +20625,112 @@ function mmToHwpunit(mm) {
20625
20625
  return Math.round(mm * 7200 / 25.4);
20626
20626
  }
20627
20627
 
20628
- // src/diff/text-diff.ts
20629
- function similarity(a, b) {
20630
- if (a === b) return 1;
20631
- if (!a || !b) return 0;
20632
- const maxLen = Math.max(a.length, b.length);
20633
- if (maxLen === 0) return 1;
20634
- return 1 - levenshtein(a, b) / maxLen;
20628
+ // src/hwpx/gen-ids.ts
20629
+ var NS_SECTION = "http://www.hancom.co.kr/hwpml/2011/section";
20630
+ var NS_PARA = "http://www.hancom.co.kr/hwpml/2011/paragraph";
20631
+ var NS_HEAD = "http://www.hancom.co.kr/hwpml/2011/head";
20632
+ var NS_CORE = "http://www.hancom.co.kr/hwpml/2011/core";
20633
+ var NS_OPF = "http://www.idpf.org/2007/opf/";
20634
+ var NS_HPF = "http://www.hancom.co.kr/schema/2011/hpf";
20635
+ var NS_OCF = "urn:oasis:names:tc:opendocument:xmlns:container";
20636
+ var CHAR_NORMAL = 0;
20637
+ var CHAR_BOLD = 1;
20638
+ var CHAR_ITALIC = 2;
20639
+ var CHAR_BOLD_ITALIC = 3;
20640
+ var CHAR_CODE = 4;
20641
+ var CHAR_H1 = 5;
20642
+ var CHAR_H2 = 6;
20643
+ var CHAR_H3 = 7;
20644
+ var CHAR_H4 = 8;
20645
+ var CHAR_TABLE_HEADER = 9;
20646
+ var CHAR_QUOTE = 10;
20647
+ var PARA_NORMAL = 0;
20648
+ var PARA_H1 = 1;
20649
+ var PARA_H2 = 2;
20650
+ var PARA_H3 = 3;
20651
+ var PARA_H4 = 4;
20652
+ var PARA_CODE = 5;
20653
+ var PARA_QUOTE = 6;
20654
+ var PARA_LIST = 7;
20655
+ var DEFAULT_TEXT_COLOR = "#000000";
20656
+ function resolveTheme(theme) {
20657
+ return {
20658
+ h1: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _162 => _162.headingColors, 'optionalAccess', _163 => _163[1]]), () => ( DEFAULT_TEXT_COLOR)),
20659
+ h2: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _164 => _164.headingColors, 'optionalAccess', _165 => _165[2]]), () => ( DEFAULT_TEXT_COLOR)),
20660
+ h3: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _166 => _166.headingColors, 'optionalAccess', _167 => _167[3]]), () => ( DEFAULT_TEXT_COLOR)),
20661
+ h4: _nullishCoalesce(_nullishCoalesce(_optionalChain([theme, 'optionalAccess', _168 => _168.headingColors, 'optionalAccess', _169 => _169[4]]), () => ( _optionalChain([theme, 'optionalAccess', _170 => _170.headingColors, 'optionalAccess', _171 => _171[3]]))), () => ( DEFAULT_TEXT_COLOR)),
20662
+ body: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _172 => _172.bodyColor]), () => ( DEFAULT_TEXT_COLOR)),
20663
+ quote: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _173 => _173.quoteColor]), () => ( DEFAULT_TEXT_COLOR)),
20664
+ /** quoteColor가 명시되었는지 — blockquote charPr 분기에 사용 (baseline 호환) */
20665
+ hasQuoteOption: _optionalChain([theme, 'optionalAccess', _174 => _174.quoteColor]) !== void 0,
20666
+ tableHeader: _nullishCoalesce(_nullishCoalesce(_optionalChain([theme, 'optionalAccess', _175 => _175.tableHeaderColor]), () => ( _optionalChain([theme, 'optionalAccess', _176 => _176.bodyColor]))), () => ( DEFAULT_TEXT_COLOR)),
20667
+ tableHeaderBold: !!_optionalChain([theme, 'optionalAccess', _177 => _177.tableHeaderBold])
20668
+ };
20635
20669
  }
20636
- function normalizedSimilarity(a, b) {
20637
- return similarity(normalize(a), normalize(b));
20670
+ function escapeXml(text) {
20671
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
20638
20672
  }
20639
- function normalize(s) {
20640
- return s.replace(/\s+/g, " ").trim();
20673
+ function headingParaPrId(level) {
20674
+ if (level === 1) return PARA_H1;
20675
+ if (level === 2) return PARA_H2;
20676
+ if (level === 3) return PARA_H3;
20677
+ return PARA_H4;
20641
20678
  }
20642
- var MAX_LEVENSHTEIN_LEN = 1e4;
20643
- function levenshtein(a, b) {
20644
- if (a.length + b.length > MAX_LEVENSHTEIN_LEN) {
20645
- const sampleLen = Math.min(500, a.length, b.length);
20646
- let diffs = 0;
20647
- for (let i = 0; i < sampleLen; i++) if (a[i] !== b[i]) diffs++;
20648
- const sampleRate = sampleLen > 0 ? diffs / sampleLen : 1;
20649
- return Math.abs(a.length - b.length) + Math.round(Math.min(a.length, b.length) * sampleRate);
20650
- }
20651
- if (a.length > b.length) [a, b] = [b, a];
20652
- const m = a.length;
20653
- const n = b.length;
20654
- let prev = Array.from({ length: m + 1 }, (_, i) => i);
20655
- let curr = new Array(m + 1);
20656
- for (let j = 1; j <= n; j++) {
20657
- curr[0] = j;
20658
- for (let i = 1; i <= m; i++) {
20659
- if (a[i - 1] === b[j - 1]) {
20660
- curr[i] = prev[i - 1];
20661
- } else {
20662
- curr[i] = 1 + Math.min(prev[i - 1], prev[i], curr[i - 1]);
20663
- }
20664
- }
20665
- ;
20666
- [prev, curr] = [curr, prev];
20667
- }
20668
- return prev[m];
20679
+ function headingCharPrId(level) {
20680
+ if (level === 1) return CHAR_H1;
20681
+ if (level === 2) return CHAR_H2;
20682
+ if (level === 3) return CHAR_H3;
20683
+ return CHAR_H4;
20684
+ }
20685
+ function charPr(id, height, bold, italic, fontId = 0, textColor = DEFAULT_TEXT_COLOR, ratioPct = 100) {
20686
+ const boldAttr = bold ? ` bold="1"` : "";
20687
+ const italicAttr = italic ? ` italic="1"` : "";
20688
+ const effFont = bold ? 2 : fontId;
20689
+ return ` <hh:charPr id="${id}" height="${height}" textColor="${textColor}" shadeColor="none" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="1"${boldAttr}${italicAttr}>
20690
+ <hh:fontRef hangul="${effFont}" latin="${effFont}" hanja="${effFont}" japanese="${effFont}" other="${effFont}" symbol="${effFont}" user="${effFont}"/>
20691
+ <hh:ratio hangul="${ratioPct}" latin="${ratioPct}" hanja="${ratioPct}" japanese="100" other="100" symbol="100" user="100"/>
20692
+ <hh:spacing hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
20693
+ <hh:relSz hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
20694
+ <hh:offset hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
20695
+ </hh:charPr>`;
20696
+ }
20697
+ function paraPr(id, opts = {}) {
20698
+ const { align = "JUSTIFY", spaceBefore = 0, spaceAfter = 0, lineSpacing = 160, indent = 0, left = 0, keepWord = false } = opts;
20699
+ const breakNonLatin = keepWord ? "KEEP_WORD" : "BREAK_WORD";
20700
+ const snapGrid = keepWord ? "0" : "1";
20701
+ return ` <hh:paraPr id="${id}" tabPrIDRef="0" condense="0" fontLineHeight="0" snapToGrid="${snapGrid}" suppressLineNumbers="0" checked="0" textDir="AUTO">
20702
+ <hh:align horizontal="${align}" vertical="BASELINE"/>
20703
+ <hh:heading type="NONE" idRef="0" level="0"/>
20704
+ <hh:breakSetting breakLatinWord="KEEP_WORD" breakNonLatinWord="${breakNonLatin}" widowOrphan="0" keepWithNext="0" keepLines="0" pageBreakBefore="0" lineWrap="BREAK"/>
20705
+ <hh:autoSpacing eAsianEng="0" eAsianNum="0"/>
20706
+ <hh:margin><hc:intent value="${indent}" unit="HWPUNIT"/><hc:left value="${left}" unit="HWPUNIT"/><hc:right value="0" unit="HWPUNIT"/><hc:prev value="${spaceBefore}" unit="HWPUNIT"/><hc:next value="${spaceAfter}" unit="HWPUNIT"/></hh:margin>
20707
+ <hh:lineSpacing type="PERCENT" value="${lineSpacing}"/>
20708
+ <hh:border borderFillIDRef="1" offsetLeft="0" offsetRight="0" offsetTop="0" offsetBottom="0" connect="0" ignoreMargin="0"/>
20709
+ </hh:paraPr>`;
20669
20710
  }
20711
+ var GONGMUN_LIST_BASE = 8;
20712
+ var GONGMUN_LIST_LEVELS = 8;
20713
+ var GONGMUN_CENTER = GONGMUN_LIST_BASE + GONGMUN_LIST_LEVELS;
20714
+ var CHAR_VARIANT_BASE = 11;
20715
+ var GONGMUN_BODY_RATIO = 95;
20670
20716
 
20671
- // src/roundtrip/markdown-units.ts
20672
- function splitMarkdownUnits(md2) {
20717
+ // src/hwpx/md-runs.ts
20718
+ function buildPrvText(blocks) {
20719
+ const lines = [];
20720
+ let bytes = 0;
20721
+ for (const b of blocks) {
20722
+ let text = b.text || (b.rows ? b.rows.map((r) => r.join(" ")).join("\n") : "");
20723
+ if (b.type === "html_table") text = text.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
20724
+ if (!text) continue;
20725
+ lines.push(text);
20726
+ bytes += text.length * 3;
20727
+ if (bytes > 1024) break;
20728
+ }
20729
+ return lines.join("\n").slice(0, 1024);
20730
+ }
20731
+ function parseMarkdownToBlocks(md2) {
20673
20732
  const lines = md2.split("\n");
20674
- const units = [];
20733
+ const blocks = [];
20675
20734
  let i = 0;
20676
20735
  while (i < lines.length) {
20677
20736
  const line = lines[i];
@@ -20679,442 +20738,451 @@ function splitMarkdownUnits(md2) {
20679
20738
  i++;
20680
20739
  continue;
20681
20740
  }
20682
- if (line.trim().startsWith("<table>")) {
20683
- const collected2 = [];
20741
+ const fenceMatch = line.match(/^(`{3,}|~{3,})(.*)$/);
20742
+ if (fenceMatch) {
20743
+ const fence = fenceMatch[1];
20744
+ const lang = fenceMatch[2].trim();
20745
+ const codeLines = [];
20746
+ i++;
20747
+ while (i < lines.length && !lines[i].startsWith(fence)) {
20748
+ codeLines.push(lines[i]);
20749
+ i++;
20750
+ }
20751
+ if (i < lines.length) i++;
20752
+ blocks.push({ type: "code_block", text: codeLines.join("\n"), lang });
20753
+ continue;
20754
+ }
20755
+ if (/^(\*{3,}|-{3,}|_{3,})\s*$/.test(line.trim())) {
20756
+ blocks.push({ type: "hr" });
20757
+ i++;
20758
+ continue;
20759
+ }
20760
+ const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
20761
+ if (headingMatch) {
20762
+ blocks.push({ type: "heading", text: headingMatch[2].trim(), level: headingMatch[1].length });
20763
+ i++;
20764
+ continue;
20765
+ }
20766
+ if (/^<table[\s>]/i.test(line.trimStart())) {
20767
+ const htmlLines = [];
20684
20768
  let depth = 0;
20685
20769
  while (i < lines.length) {
20686
20770
  const l = lines[i];
20687
- collected2.push(l);
20688
- depth += (l.match(/<table>/g) || []).length;
20689
- depth -= (l.match(/<\/table>/g) || []).length;
20771
+ htmlLines.push(l);
20772
+ depth += (_nullishCoalesce(l.match(/<table[\s>]/gi), () => ( []))).length;
20773
+ depth -= (_nullishCoalesce(l.match(/<\/table>/gi), () => ( []))).length;
20690
20774
  i++;
20691
20775
  if (depth <= 0) break;
20692
20776
  }
20693
- units.push({ kind: "html-table", raw: collected2.join("\n"), lines: collected2 });
20777
+ blocks.push({ type: "html_table", text: htmlLines.join("\n") });
20694
20778
  continue;
20695
20779
  }
20696
20780
  if (line.trimStart().startsWith("|")) {
20697
- const collected2 = [];
20781
+ const tableRows = [];
20698
20782
  while (i < lines.length && lines[i].trimStart().startsWith("|")) {
20699
- collected2.push(lines[i]);
20783
+ const row = lines[i];
20784
+ if (/^[\s|:\-]+$/.test(row)) {
20785
+ i++;
20786
+ continue;
20787
+ }
20788
+ const cells = row.split("|").slice(1, -1).map((c) => c.trim());
20789
+ if (cells.length > 0) tableRows.push(cells);
20700
20790
  i++;
20701
20791
  }
20702
- units.push({ kind: "gfm-table", raw: collected2.join("\n"), lines: collected2 });
20792
+ if (tableRows.length > 0) blocks.push({ type: "table", rows: tableRows });
20703
20793
  continue;
20704
20794
  }
20705
- if (/^-{3,}\s*$/.test(line.trim())) {
20706
- units.push({ kind: "separator", raw: line.trim(), lines: [line.trim()] });
20707
- i++;
20795
+ if (line.trimStart().startsWith("> ")) {
20796
+ const quoteLines = [];
20797
+ while (i < lines.length && (lines[i].trimStart().startsWith("> ") || lines[i].trimStart().startsWith(">"))) {
20798
+ quoteLines.push(lines[i].replace(/^>\s?/, ""));
20799
+ i++;
20800
+ }
20801
+ for (const ql of quoteLines) {
20802
+ blocks.push({ type: "blockquote", text: ql.trim() || "" });
20803
+ }
20708
20804
  continue;
20709
20805
  }
20710
- if (/^!\[image\]\([^)]*\)\s*$/.test(line.trim())) {
20711
- units.push({ kind: "image", raw: line.trim(), lines: [line.trim()] });
20806
+ const listMatch = line.match(/^(\s*)([-*+]|\d+[.)]) (.+)$/);
20807
+ if (listMatch) {
20808
+ const indent = Math.floor(listMatch[1].length / 2);
20809
+ const ordered = /\d/.test(listMatch[2]);
20810
+ blocks.push({ type: "list_item", text: listMatch[3].trim(), ordered, indent });
20712
20811
  i++;
20713
20812
  continue;
20714
20813
  }
20715
- const collected = [];
20716
- while (i < lines.length && lines[i].trim() && !lines[i].trimStart().startsWith("|") && !lines[i].trim().startsWith("<table>")) {
20717
- collected.push(lines[i].trim());
20718
- i++;
20719
- }
20720
- units.push({ kind: "text", raw: collected.join("\n"), lines: collected });
20814
+ blocks.push({ type: "paragraph", text: line.trim() });
20815
+ i++;
20721
20816
  }
20722
- return units;
20817
+ return blocks;
20723
20818
  }
20724
- function alignUnits(a, b) {
20725
- const m = a.length, n = b.length;
20726
- if (m * n > 4e6) {
20727
- const result2 = [];
20728
- let pre = 0;
20729
- while (pre < m && pre < n && a[pre] === b[pre]) {
20730
- result2.push([pre, pre]);
20731
- pre++;
20819
+ function parseInlineMarkdown(text) {
20820
+ text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1");
20821
+ text = text.replace(/\[([^\]]*)\]\(([^)]*)\)/g, (_, t, u) => t || u);
20822
+ text = text.replace(/~~([^~]+)~~/g, "$1");
20823
+ const spans = [];
20824
+ const regex = /(`[^`]+`|\*{3}[^*]+\*{3}|\*{2}[^*]+\*{2}|\*[^*]+\*|_{2}[^_]+_{2}|_[^_]+_)/g;
20825
+ let lastIdx = 0;
20826
+ for (const match of text.matchAll(regex)) {
20827
+ const idx = match.index;
20828
+ if (idx > lastIdx) {
20829
+ spans.push({ text: text.slice(lastIdx, idx), bold: false, italic: false, code: false });
20732
20830
  }
20733
- let suf = 0;
20734
- while (suf < m - pre && suf < n - pre && a[m - 1 - suf] === b[n - 1 - suf]) suf++;
20735
- const aMid = m - pre - suf, bMid = n - pre - suf;
20736
- if (aMid === bMid) {
20737
- for (let i2 = 0; i2 < aMid; i2++) result2.push([pre + i2, pre + i2]);
20831
+ const raw = match[0];
20832
+ if (raw.startsWith("`")) {
20833
+ spans.push({ text: raw.slice(1, -1), bold: false, italic: false, code: true });
20834
+ } else if (raw.startsWith("***") || raw.startsWith("___")) {
20835
+ spans.push({ text: raw.slice(3, -3), bold: true, italic: true, code: false });
20836
+ } else if (raw.startsWith("**") || raw.startsWith("__")) {
20837
+ spans.push({ text: raw.slice(2, -2), bold: true, italic: false, code: false });
20738
20838
  } else {
20739
- for (let i2 = 0; i2 < aMid; i2++) result2.push([pre + i2, null]);
20740
- for (let j2 = 0; j2 < bMid; j2++) result2.push([null, pre + j2]);
20839
+ spans.push({ text: raw.slice(1, -1), bold: false, italic: true, code: false });
20741
20840
  }
20742
- for (let s = suf - 1; s >= 0; s--) result2.push([m - 1 - s, n - 1 - s]);
20743
- return result2;
20841
+ lastIdx = idx + raw.length;
20744
20842
  }
20745
- const dp = Array.from({ length: m + 1 }, () => new Int32Array(n + 1));
20746
- for (let i2 = 1; i2 <= m; i2++) {
20747
- for (let j2 = 1; j2 <= n; j2++) {
20748
- dp[i2][j2] = a[i2 - 1] === b[j2 - 1] ? dp[i2 - 1][j2 - 1] + 1 : Math.max(dp[i2 - 1][j2], dp[i2][j2 - 1]);
20749
- }
20843
+ if (lastIdx < text.length) {
20844
+ spans.push({ text: text.slice(lastIdx), bold: false, italic: false, code: false });
20750
20845
  }
20751
- const matches = [];
20752
- let i = m, j = n;
20753
- while (i > 0 && j > 0) {
20754
- if (a[i - 1] === b[j - 1] && dp[i][j] === dp[i - 1][j - 1] + 1) {
20755
- matches.push([i - 1, j - 1]);
20756
- i--;
20757
- j--;
20758
- } else if (dp[i - 1][j] >= dp[i][j - 1]) i--;
20759
- else j--;
20760
- }
20761
- matches.reverse();
20762
- const result = [];
20763
- let ai = 0, bi = 0;
20764
- const flushGap = (aEnd, bEnd) => {
20765
- if (aEnd - ai === bEnd - bi) {
20766
- while (ai < aEnd) result.push([ai++, bi++]);
20767
- return;
20768
- }
20769
- while (ai < aEnd && bi < bEnd) {
20770
- const sim = normalizedSimilarity(a[ai], b[bi]);
20771
- if (sim >= 0.4) {
20772
- if (aEnd - ai > bEnd - bi && bestSimInRange(a, ai + 1, ai + (aEnd - ai) - (bEnd - bi), b[bi]) > sim) {
20773
- result.push([ai++, null]);
20774
- } else if (bEnd - bi > aEnd - ai && bestSimInRange(b, bi + 1, bi + (bEnd - bi) - (aEnd - ai), a[ai]) > sim) {
20775
- result.push([null, bi++]);
20776
- } else {
20777
- result.push([ai++, bi++]);
20778
- }
20779
- } else if (aEnd - ai >= bEnd - bi) result.push([ai++, null]);
20780
- else result.push([null, bi++]);
20781
- }
20782
- while (ai < aEnd) result.push([ai++, null]);
20783
- while (bi < bEnd) result.push([null, bi++]);
20784
- };
20785
- for (const [pi, pj] of matches) {
20786
- flushGap(pi, pj);
20787
- result.push([ai++, bi++]);
20846
+ if (spans.length === 0) {
20847
+ spans.push({ text, bold: false, italic: false, code: false });
20788
20848
  }
20789
- flushGap(m, n);
20790
- return result;
20849
+ return spans;
20791
20850
  }
20792
- function bestSimInRange(arr, from, to, target) {
20793
- let best = 0;
20794
- for (let k = from; k <= to && k < arr.length; k++) {
20795
- const s = normalizedSimilarity(arr[k], target);
20796
- if (s > best) best = s;
20797
- }
20798
- return best;
20851
+ function spanToCharPrId(span) {
20852
+ if (span.code) return CHAR_CODE;
20853
+ if (span.bold && span.italic) return CHAR_BOLD_ITALIC;
20854
+ if (span.bold) return CHAR_BOLD;
20855
+ if (span.italic) return CHAR_ITALIC;
20856
+ return CHAR_NORMAL;
20799
20857
  }
20800
- function escapeGfm(text) {
20801
- return text.replace(/~/g, "\\~");
20858
+ function generateRuns(text, defaultCharPr = CHAR_NORMAL, mapCharId) {
20859
+ const spans = parseInlineMarkdown(text);
20860
+ return spans.map((span) => {
20861
+ let charId = span.code || span.bold || span.italic ? spanToCharPrId(span) : defaultCharPr;
20862
+ if (mapCharId) charId = mapCharId(charId);
20863
+ return `<hp:run charPrIDRef="${charId}"><hp:t>${escapeXml(span.text)}</hp:t></hp:run>`;
20864
+ }).join("");
20802
20865
  }
20803
- var HWP_SHAPE_ALT_TEXT_RE = /(?:모서리가 둥근 |둥근 )?(?:사각형|직사각형|정사각형|원|타원|삼각형|이등변 삼각형|직각 삼각형|선|직선|곡선|화살표|굵은 화살표|이중 화살표|오각형|육각형|팔각형|별|[4-8]점별|십자|십자형|구름|구름형|마름모|도넛|평행사변형|사다리꼴|부채꼴|호|반원|물결|번개|하트|빗금|블록 화살표|수식|표|그림|개체|그리기\s?개체|묶음\s?개체|글상자|수식\s?개체|OLE\s?개체)\s?입니다\.?/g;
20804
- function sanitizeText(text) {
20805
- let result = _chunkLFCS3UVGcjs.mapPuaText.call(void 0, text).replace(/[\u{F0000}-\u{FFFFD}]/gu, "").replace(HWP_SHAPE_ALT_TEXT_RE, "").replace(/ +/g, " ").trim();
20806
- if (result.length <= 30 && result.includes(" ")) {
20807
- const tokens = result.split(" ");
20808
- const koreanSingleCharCount = tokens.filter((t) => t.length === 1 && /[가-힯ㄱ-ㆎ]/.test(t)).length;
20809
- if (tokens.length >= 3 && koreanSingleCharCount / tokens.length >= 0.7) {
20810
- result = tokens.join("");
20811
- }
20866
+ function generateParagraph(text, paraPrId = PARA_NORMAL, charPrId = CHAR_NORMAL, mapCharId) {
20867
+ if (paraPrId === PARA_CODE) {
20868
+ return `<hp:p paraPrIDRef="${paraPrId}" styleIDRef="0"><hp:run charPrIDRef="${CHAR_CODE}"><hp:t>${escapeXml(text)}</hp:t></hp:run></hp:p>`;
20812
20869
  }
20813
- return result;
20814
- }
20815
- function normForMatch(text) {
20816
- return sanitizeText(text).replace(/\s+/g, " ").trim();
20870
+ const runs = generateRuns(text, charPrId, mapCharId);
20871
+ return `<hp:p paraPrIDRef="${paraPrId}" styleIDRef="0">${runs}</hp:p>`;
20817
20872
  }
20818
- function unescapeGfm(text) {
20819
- return text.replace(/\\~/g, "~");
20873
+
20874
+ // src/hwpx/gen-header.ts
20875
+ function generateContainerXml() {
20876
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
20877
+ <ocf:container xmlns:ocf="${NS_OCF}" xmlns:hpf="${NS_HPF}">
20878
+ <ocf:rootfiles>
20879
+ <ocf:rootfile full-path="Contents/content.hpf" media-type="application/hwpml-package+xml"/>
20880
+ </ocf:rootfiles>
20881
+ </ocf:container>`;
20820
20882
  }
20821
- function summarize(text) {
20822
- const t = text.replace(/\s+/g, " ").trim();
20823
- return t.length > 80 ? t.slice(0, 77) + "..." : t;
20883
+ function generateManifest() {
20884
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
20885
+ <opf:package xmlns:opf="${NS_OPF}" xmlns:hpf="${NS_HPF}" xmlns:hh="${NS_HEAD}">
20886
+ <opf:manifest>
20887
+ <opf:item id="header" href="Contents/header.xml" media-type="application/xml"/>
20888
+ <opf:item id="section0" href="Contents/section0.xml" media-type="application/xml"/>
20889
+ </opf:manifest>
20890
+ <opf:spine>
20891
+ <opf:itemref idref="header" linear="no"/>
20892
+ <opf:itemref idref="section0" linear="yes"/>
20893
+ </opf:spine>
20894
+ </opf:package>`;
20824
20895
  }
20825
- function replicateGfmTable(table) {
20826
- const { cells, rows: numRows, cols: numCols } = table;
20827
- if (numRows === 0 || numCols === 0) return null;
20828
- if (numRows === 1 && numCols === 1) return null;
20829
- if (numCols === 1) return null;
20830
- const display = Array.from({ length: numRows }, (_, r) => Array.from({ length: numCols }, (_2, c) => ({ text: "", gridR: r, gridC: c })));
20831
- const skip = /* @__PURE__ */ new Set();
20832
- for (let r = 0; r < numRows; r++) {
20833
- for (let c = 0; c < numCols; c++) {
20834
- if (skip.has(`${r},${c}`)) continue;
20835
- const cell = _optionalChain([cells, 'access', _162 => _162[r], 'optionalAccess', _163 => _163[c]]);
20836
- if (!cell) continue;
20837
- display[r][c] = {
20838
- text: escapeGfm(sanitizeText(cell.text)).replace(/\|/g, "\\|").replace(/\n/g, "<br>"),
20839
- gridR: r,
20840
- gridC: c
20841
- };
20842
- for (let dr = 0; dr < cell.rowSpan; dr++) {
20843
- for (let dc = 0; dc < cell.colSpan; dc++) {
20844
- if (dr === 0 && dc === 0) continue;
20845
- if (r + dr < numRows && c + dc < numCols) skip.add(`${r + dr},${c + dc}`);
20846
- }
20847
- }
20848
- c += cell.colSpan - 1;
20849
- }
20850
- }
20851
- const uniqueRows = [];
20852
- let pendingLabelRow = null;
20853
- for (let r = 0; r < display.length; r++) {
20854
- const row = display[r];
20855
- if (row.every((cell) => cell.text === "")) continue;
20856
- const nonEmptyCols = row.filter((cell) => cell.text !== "");
20857
- const hasSkipInRow = row.some((_, c) => skip.has(`${r},${c}`));
20858
- if (!hasSkipInRow && nonEmptyCols.length === 1 && row[0].text !== "" && row.slice(1).every((c) => c.text === "")) {
20859
- if (pendingLabelRow) uniqueRows.push(pendingLabelRow);
20860
- pendingLabelRow = row;
20861
- continue;
20862
- }
20863
- if (pendingLabelRow) {
20864
- if (row[0].text === "") row[0] = pendingLabelRow[0];
20865
- else uniqueRows.push(pendingLabelRow);
20866
- pendingLabelRow = null;
20867
- }
20868
- uniqueRows.push(row);
20896
+ function buildCharProperties(theme, gongmun, ratioVariants = []) {
20897
+ let body = 1e3, code = 900, h1 = 1800, h2 = 1400, h3 = 1200, h4 = 1100;
20898
+ if (gongmun) {
20899
+ body = gongmun.bodyHeight;
20900
+ code = Math.max(body - 200, 900);
20901
+ h1 = gongmun.preset === "report" || gongmun.preset === "plan" ? 2e3 : 1700;
20902
+ h2 = 1600;
20903
+ h3 = body;
20904
+ h4 = Math.max(body - 100, 1300);
20869
20905
  }
20870
- if (pendingLabelRow) uniqueRows.push(pendingLabelRow);
20871
- return uniqueRows.length > 0 ? uniqueRows : null;
20872
- }
20873
- function parseGfmTable(lines) {
20874
- const rows = [];
20875
- for (const line of lines) {
20876
- const trimmed = line.trim();
20877
- if (!trimmed.startsWith("|")) continue;
20878
- const cells = trimmed.split(/(?<!\\)\|/).slice(1, -1).map((c) => c.trim());
20879
- if (cells.length === 0) continue;
20880
- if (cells.every((c) => /^:?-{3,}:?$/.test(c))) continue;
20881
- rows.push(cells);
20906
+ const bodyRatio = gongmun ? GONGMUN_BODY_RATIO : 100;
20907
+ const rows = [
20908
+ charPr(0, body, false, false, 0, theme.body, bodyRatio),
20909
+ charPr(1, body, true, false, 0, theme.body, bodyRatio),
20910
+ charPr(2, body, false, true, 0, theme.body, bodyRatio),
20911
+ charPr(3, body, true, true, 0, theme.body, bodyRatio),
20912
+ charPr(4, code, false, false, 1),
20913
+ charPr(5, h1, true, false, 1, theme.h1),
20914
+ charPr(6, h2, true, false, 1, theme.h2),
20915
+ charPr(7, h3, true, false, 1, theme.h3),
20916
+ charPr(8, h4, true, false, 1, theme.h4),
20917
+ charPr(CHAR_TABLE_HEADER, body, theme.tableHeaderBold, false, 0, theme.tableHeader),
20918
+ charPr(CHAR_QUOTE, body, false, true, 0, theme.quote)
20919
+ ];
20920
+ for (const r of ratioVariants) {
20921
+ rows.push(
20922
+ charPr(rows.length, body, false, false, 0, theme.body, r),
20923
+ charPr(rows.length + 1, body, true, false, 0, theme.body, r),
20924
+ charPr(rows.length + 2, body, false, true, 0, theme.body, r),
20925
+ charPr(rows.length + 3, body, true, true, 0, theme.body, r)
20926
+ );
20882
20927
  }
20883
- return rows;
20884
- }
20885
- function unescapeGfmCell(text) {
20886
- return text.replace(/<br\s*\/?>/gi, "\n").replace(/\\\|/g, "|").replace(/\\~/g, "~");
20928
+ return `<hh:charProperties itemCnt="${rows.length}">
20929
+ ${rows.join("\n")}
20930
+ </hh:charProperties>`;
20887
20931
  }
20888
- function replicateCellInnerHtml(cell) {
20889
- if (_optionalChain([cell, 'access', _164 => _164.blocks, 'optionalAccess', _165 => _165.length])) {
20890
- return cell.blocks.map((b) => {
20891
- if (b.type === "table" && b.table) {
20892
- const cap = b.table.caption ? sanitizeText(b.table.caption) : "";
20893
- return (cap ? cap + "<br>" : "") + replicateTableToHtml(b.table);
20894
- }
20895
- if (b.type === "image" && b.text) return `<img src="${b.text}" alt="image">`;
20896
- const t = sanitizeText(_nullishCoalesce(b.text, () => ( "")));
20897
- return t ? t.replace(/\n/g, "<br>") : "";
20898
- }).filter(Boolean).join("<br>");
20932
+ function buildParaProperties(gongmun) {
20933
+ if (!gongmun) {
20934
+ const base2 = [
20935
+ paraPr(0),
20936
+ paraPr(1, { align: "LEFT", spaceBefore: 800, spaceAfter: 200, lineSpacing: 180 }),
20937
+ paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: 170 }),
20938
+ paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: 160 }),
20939
+ paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: 160 }),
20940
+ paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400 }),
20941
+ paraPr(6, { align: "LEFT", lineSpacing: 150, indent: 600 }),
20942
+ paraPr(7, { align: "LEFT", lineSpacing: 160, indent: 600 })
20943
+ ];
20944
+ return `<hh:paraProperties itemCnt="${base2.length}">
20945
+ ${base2.join("\n")}
20946
+ </hh:paraProperties>`;
20899
20947
  }
20900
- return sanitizeText(cell.text).replace(/\n/g, "<br>");
20901
- }
20902
- function replicateTableToHtml(table) {
20903
- const rows = replicateHtmlTable(table);
20904
- const lines = ["<table>"];
20905
- for (let r = 0; r < rows.length; r++) {
20906
- const tag = rows[r].tag;
20907
- const rowHtml = rows[r].cells.map((cell) => {
20908
- const attrs = [];
20909
- if (cell.colSpan > 1) attrs.push(`colspan="${cell.colSpan}"`);
20910
- if (cell.rowSpan > 1) attrs.push(`rowspan="${cell.rowSpan}"`);
20911
- const attrStr = attrs.length ? " " + attrs.join(" ") : "";
20912
- return `<${tag}${attrStr}>${cell.inner}</${tag}>`;
20913
- });
20914
- if (rowHtml.length) lines.push(`<tr>${rowHtml.join("")}</tr>`);
20948
+ const ls = gongmun.lineSpacing;
20949
+ const titleAlign = gongmun.centerTitle ? "CENTER" : "LEFT";
20950
+ const base = [
20951
+ paraPr(0, { lineSpacing: ls, keepWord: true }),
20952
+ paraPr(1, { align: titleAlign, spaceBefore: 400, spaceAfter: 400, lineSpacing: ls, keepWord: true }),
20953
+ paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: ls, keepWord: true }),
20954
+ paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
20955
+ paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
20956
+ paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400, keepWord: true }),
20957
+ paraPr(6, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true }),
20958
+ paraPr(7, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true })
20959
+ ];
20960
+ for (let d = 0; d < GONGMUN_LIST_LEVELS; d++) {
20961
+ const { left, indent } = levelIndent(d, gongmun.bodyHeight, gongmun.numbering);
20962
+ const sectionGap = gongmun.numbering === "report" && d === 0 ? Math.round(gongmun.bodyHeight * 0.5) : 0;
20963
+ base.push(paraPr(GONGMUN_LIST_BASE + d, { align: "JUSTIFY", lineSpacing: ls, left, indent, spaceBefore: sectionGap, keepWord: true }));
20915
20964
  }
20916
- lines.push("</table>");
20917
- return lines.join("\n");
20965
+ base.push(paraPr(GONGMUN_CENTER, { align: "CENTER", lineSpacing: ls, keepWord: true }));
20966
+ return `<hh:paraProperties itemCnt="${base.length}">
20967
+ ${base.join("\n")}
20968
+ </hh:paraProperties>`;
20918
20969
  }
20919
- function replicateHtmlTable(table) {
20920
- const { cells, rows: numRows, cols: numCols } = table;
20921
- const skip = /* @__PURE__ */ new Set();
20922
- const result = [];
20923
- for (let r = 0; r < numRows; r++) {
20924
- const tag = r === 0 ? "th" : "td";
20925
- const rowCells = [];
20926
- for (let c = 0; c < numCols; c++) {
20927
- if (skip.has(`${r},${c}`)) continue;
20928
- const cell = _optionalChain([cells, 'access', _166 => _166[r], 'optionalAccess', _167 => _167[c]]);
20929
- if (!cell) continue;
20930
- for (let dr = 0; dr < cell.rowSpan; dr++) {
20931
- for (let dc = 0; dc < cell.colSpan; dc++) {
20932
- if (dr === 0 && dc === 0) continue;
20933
- if (r + dr < numRows && c + dc < numCols) skip.add(`${r + dr},${c + dc}`);
20934
- }
20935
- }
20936
- rowCells.push({
20937
- inner: replicateCellInnerHtml(cell),
20938
- colSpan: cell.colSpan,
20939
- rowSpan: cell.rowSpan,
20940
- gridR: r,
20941
- gridC: c
20942
- });
20970
+ function generateHeaderXml(theme, gongmun, ratioVariants = []) {
20971
+ const bodyFace = _optionalChain([gongmun, 'optionalAccess', _178 => _178.bodyFont]) === "gothic" ? "\uB9D1\uC740 \uACE0\uB515" : "\uD568\uCD08\uB86C\uBC14\uD0D5";
20972
+ const charPropsXml = buildCharProperties(theme, gongmun, ratioVariants);
20973
+ const paraPropsXml = buildParaProperties(gongmun);
20974
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
20975
+ <hh:head xmlns:hh="${NS_HEAD}" xmlns:hp="${NS_PARA}" xmlns:hc="${NS_CORE}" version="1.4" secCnt="1">
20976
+ <hh:beginNum page="1" footnote="1" endnote="1" pic="1" tbl="1" equation="1"/>
20977
+ <hh:refList>
20978
+ <hh:fontfaces itemCnt="7">
20979
+ <hh:fontface lang="HANGUL" fontCnt="3">
20980
+ <hh:font id="0" face="${bodyFace}" type="TTF" isEmbedded="0">
20981
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
20982
+ </hh:font>
20983
+ <hh:font id="1" face="\uD568\uCD08\uB86C\uB3CB\uC6C0" type="TTF" isEmbedded="0">
20984
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
20985
+ </hh:font>
20986
+ <hh:font id="2" face="HY\uACAC\uACE0\uB515" type="TTF" isEmbedded="0">
20987
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="9" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
20988
+ </hh:font>
20989
+ </hh:fontface>
20990
+ <hh:fontface lang="LATIN" fontCnt="3">
20991
+ <hh:font id="0" face="Times New Roman" type="TTF" isEmbedded="0">
20992
+ <hh:typeInfo familyType="FCAT_OLDSTYLE" weight="5" proportion="4" contrast="2" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="4"/>
20993
+ </hh:font>
20994
+ <hh:font id="1" face="Consolas" type="TTF" isEmbedded="0">
20995
+ <hh:typeInfo familyType="FCAT_MODERN" weight="5" proportion="0" contrast="0" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="0"/>
20996
+ </hh:font>
20997
+ <hh:font id="2" face="Arial Black" type="TTF" isEmbedded="0">
20998
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="9" proportion="0" contrast="0" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="0"/>
20999
+ </hh:font>
21000
+ </hh:fontface>
21001
+ <hh:fontface lang="HANJA" fontCnt="1">
21002
+ <hh:font id="0" face="\uD568\uCD08\uB86C\uBC14\uD0D5" type="TTF" isEmbedded="0">
21003
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21004
+ </hh:font>
21005
+ </hh:fontface>
21006
+ <hh:fontface lang="JAPANESE" fontCnt="1">
21007
+ <hh:font id="0" face="\uAD74\uB9BC" type="TTF" isEmbedded="0">
21008
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21009
+ </hh:font>
21010
+ </hh:fontface>
21011
+ <hh:fontface lang="OTHER" fontCnt="1">
21012
+ <hh:font id="0" face="\uAD74\uB9BC" type="TTF" isEmbedded="0">
21013
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21014
+ </hh:font>
21015
+ </hh:fontface>
21016
+ <hh:fontface lang="SYMBOL" fontCnt="1">
21017
+ <hh:font id="0" face="Symbol" type="TTF" isEmbedded="0">
21018
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21019
+ </hh:font>
21020
+ </hh:fontface>
21021
+ <hh:fontface lang="USER" fontCnt="1">
21022
+ <hh:font id="0" face="\uAD74\uB9BC" type="TTF" isEmbedded="0">
21023
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21024
+ </hh:font>
21025
+ </hh:fontface>
21026
+ </hh:fontfaces>
21027
+ <hh:borderFills itemCnt="2">
21028
+ <hh:borderFill id="1" threeD="0" shadow="0" centerLine="NONE" breakCellSeparateLine="0">
21029
+ <hh:slash type="NONE" Crooked="0" isCounter="0"/>
21030
+ <hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
21031
+ <hh:leftBorder type="NONE" width="0.1 mm" color="#000000"/>
21032
+ <hh:rightBorder type="NONE" width="0.1 mm" color="#000000"/>
21033
+ <hh:topBorder type="NONE" width="0.1 mm" color="#000000"/>
21034
+ <hh:bottomBorder type="NONE" width="0.1 mm" color="#000000"/>
21035
+ </hh:borderFill>
21036
+ <hh:borderFill id="2" threeD="0" shadow="0" centerLine="NONE" breakCellSeparateLine="0">
21037
+ <hh:slash type="NONE" Crooked="0" isCounter="0"/>
21038
+ <hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
21039
+ <hh:leftBorder type="SOLID" width="0.12 mm" color="#000000"/>
21040
+ <hh:rightBorder type="SOLID" width="0.12 mm" color="#000000"/>
21041
+ <hh:topBorder type="SOLID" width="0.12 mm" color="#000000"/>
21042
+ <hh:bottomBorder type="SOLID" width="0.12 mm" color="#000000"/>
21043
+ </hh:borderFill>
21044
+ </hh:borderFills>
21045
+ ${charPropsXml}
21046
+ <hh:tabProperties itemCnt="0"/>
21047
+ <hh:numberings itemCnt="0"/>
21048
+ <hh:bullets itemCnt="0"/>
21049
+ ${paraPropsXml}
21050
+ <hh:styles itemCnt="1">
21051
+ <hh:style id="0" type="PARA" name="\uBC14\uD0D5\uAE00" engName="Normal" paraPrIDRef="0" charPrIDRef="0" nextStyleIDRef="0" langIDRef="1042" lockForm="0"/>
21052
+ </hh:styles>
21053
+ </hh:refList>
21054
+ <hh:compatibleDocument targetProgram="HWP2018"><hh:layoutCompatibility/></hh:compatibleDocument>
21055
+ </hh:head>`;
21056
+ }
21057
+
21058
+ // src/hwpx/gen-gongmun-fit.ts
21059
+ function plainRenderText(text) {
21060
+ return parseInlineMarkdown(text).map((s) => s.text).join("");
21061
+ }
21062
+ function computeGongmunFitPlan(blocks, gongmun, gongmunList) {
21063
+ const minRatio = gongmun.autoFitMinRatio;
21064
+ if (minRatio === null || minRatio >= GONGMUN_BODY_RATIO) return null;
21065
+ const pageW = 59528 - mmToHwpunit(gongmun.margins.left) - mmToHwpunit(gongmun.margins.right);
21066
+ const ratioByBlock = /* @__PURE__ */ new Map();
21067
+ const variants = [];
21068
+ for (let i = 0; i < blocks.length; i++) {
21069
+ const block = blocks[i];
21070
+ let text;
21071
+ let firstW;
21072
+ let contW;
21073
+ if (block.type === "list_item" && gongmunList.has(i)) {
21074
+ const { marker, depth } = gongmunList.get(i);
21075
+ const content = plainRenderText(block.text || "");
21076
+ text = marker ? `${marker} ${content}` : content;
21077
+ const { left, indent } = levelIndent(depth, gongmun.bodyHeight, gongmun.numbering);
21078
+ firstW = pageW - left - Math.max(indent, 0);
21079
+ contW = pageW - left - Math.max(-indent, 0);
21080
+ } else if (block.type === "paragraph") {
21081
+ const raw = (block.text || "").trim();
21082
+ if (/^<center>[\s\S]*<\/center>$/i.test(raw)) continue;
21083
+ text = plainRenderText(raw);
21084
+ firstW = contW = pageW;
21085
+ } else {
21086
+ continue;
20943
21087
  }
20944
- if (rowCells.length) result.push({ tag, cells: rowCells });
21088
+ if (!text) continue;
21089
+ const r = fitRatioForFewerLines(text, firstW, contW, gongmun.bodyHeight, GONGMUN_BODY_RATIO, minRatio);
21090
+ if (r === null) continue;
21091
+ ratioByBlock.set(i, r);
21092
+ if (!variants.includes(r)) variants.push(r);
20945
21093
  }
20946
- return result;
21094
+ return ratioByBlock.size > 0 ? { ratioByBlock, variants } : null;
20947
21095
  }
20948
- function parseHtmlTable(raw) {
20949
- const re = /<(\/?)(table|tr|td|th)((?:"[^"]*"|'[^']*'|[^>"'])*?)>/gi;
20950
- let depth = 0;
20951
- let currentRow = null;
20952
- let cellStart = -1;
20953
- let cellInfo = null;
20954
- const rows = [];
20955
- let m;
20956
- while ((m = re.exec(raw)) !== null) {
20957
- const isClose = m[1] === "/";
20958
- const tag = m[2].toLowerCase();
20959
- const attrs = m[3] || "";
20960
- if (tag === "table") {
20961
- depth += isClose ? -1 : 1;
20962
- if (depth < 0) return null;
21096
+ function variantMapper(fit, blockIdx) {
21097
+ const r = fit.ratioByBlock.get(blockIdx);
21098
+ if (r === void 0) return void 0;
21099
+ const vi = fit.variants.indexOf(r);
21100
+ return (id) => id >= 0 && id <= 3 ? CHAR_VARIANT_BASE + vi * 4 + id : id;
21101
+ }
21102
+ function precomputeGongmunList(blocks, gongmun) {
21103
+ const result = /* @__PURE__ */ new Map();
21104
+ let i = 0;
21105
+ while (i < blocks.length) {
21106
+ if (blocks[i].type !== "list_item") {
21107
+ i++;
20963
21108
  continue;
20964
21109
  }
20965
- if (depth !== 1) continue;
20966
- if (tag === "tr") {
20967
- if (!isClose) currentRow = [];
20968
- else if (currentRow) {
20969
- rows.push({ tag: rows.length === 0 ? "th" : "td", cells: currentRow });
20970
- currentRow = null;
21110
+ const run = [];
21111
+ while (i < blocks.length) {
21112
+ const t = blocks[i].type;
21113
+ if (t === "list_item") {
21114
+ run.push(i);
21115
+ i++;
21116
+ continue;
20971
21117
  }
20972
- } else {
20973
- if (!isClose) {
20974
- const cs = parseInt(_optionalChain([attrs, 'access', _168 => _168.match, 'call', _169 => _169(/colspan\s*=\s*"(\d+)"/i), 'optionalAccess', _170 => _170[1]]) || "1", 10);
20975
- const rs = parseInt(_optionalChain([attrs, 'access', _171 => _171.match, 'call', _172 => _172(/rowspan\s*=\s*"(\d+)"/i), 'optionalAccess', _173 => _173[1]]) || "1", 10);
20976
- cellStart = m.index + m[0].length;
20977
- cellInfo = { colSpan: isNaN(cs) ? 1 : cs, rowSpan: isNaN(rs) ? 1 : rs };
20978
- } else if (cellStart >= 0 && cellInfo && currentRow) {
20979
- currentRow.push({ inner: raw.slice(cellStart, m.index), colSpan: cellInfo.colSpan, rowSpan: cellInfo.rowSpan });
20980
- cellStart = -1;
20981
- cellInfo = null;
21118
+ if (t === "table" || t === "html_table") {
21119
+ let j = i + 1;
21120
+ while (j < blocks.length && (blocks[j].type === "table" || blocks[j].type === "html_table")) j++;
21121
+ if (j < blocks.length && blocks[j].type === "list_item") {
21122
+ i = j;
21123
+ continue;
21124
+ }
20982
21125
  }
21126
+ break;
20983
21127
  }
21128
+ const depths = run.map((bi) => Math.min(Math.max(blocks[bi].indent || 0, 0), GONGMUN_LIST_LEVELS - 1));
21129
+ const suppress = gongmun.numbering === "standard" ? computeSuppression(depths) : depths.map(() => false);
21130
+ const numberer = new GongmunNumberer(gongmun.numbering);
21131
+ run.forEach((bi, k) => {
21132
+ const marker = numberer.next(depths[k], suppress[k]);
21133
+ result.set(bi, { marker, depth: depths[k] });
21134
+ });
20984
21135
  }
20985
- if (depth !== 0) return null;
20986
- return rows;
21136
+ return result;
20987
21137
  }
20988
- var AUTONUM_PREFIX_RE = /^(?:[0-90-9a-zA-Z가-힣]{1,6}[.)\]:]|[([][0-90-9a-zA-Z가-힣]{1,6}[)\]][.:]?|[ⅰ-ⅹⅠ-Ⅹ①-⑮][.)\]:]?)$/u;
20989
- function htmlCellInnerToLines(inner) {
20990
- let hadNonText = false;
20991
- let work = inner;
20992
- if (/<table[\s>]/i.test(work)) {
20993
- hadNonText = true;
20994
- work = removeNestedTables(work);
20995
- }
20996
- if (/<img\s/i.test(work)) {
20997
- hadNonText = true;
20998
- work = work.replace(/<img\s(?:"[^"]*"|'[^']*'|[^>"'])*?>/gi, "");
20999
- }
21000
- const lines = work.split(/<br\s*\/?>/gi).map((s) => s.trim()).filter((s) => s.length > 0);
21001
- return { lines, hadNonText };
21138
+
21139
+ // src/diff/text-diff.ts
21140
+ function similarity(a, b) {
21141
+ if (a === b) return 1;
21142
+ if (!a || !b) return 0;
21143
+ const maxLen = Math.max(a.length, b.length);
21144
+ if (maxLen === 0) return 1;
21145
+ return 1 - levenshtein(a, b) / maxLen;
21002
21146
  }
21003
- function extractTopLevelTables(html) {
21004
- const result = [];
21005
- let depth = 0;
21006
- let start = -1;
21007
- const re = /<(\/?)table(?:[\s>]|>)/gi;
21008
- let m;
21009
- while ((m = re.exec(html)) !== null) {
21010
- if (m[1] !== "/") {
21011
- if (depth === 0) start = m.index;
21012
- depth++;
21013
- } else {
21014
- depth--;
21015
- if (depth === 0 && start >= 0) {
21016
- result.push(html.slice(start, m.index + m[0].length));
21017
- start = -1;
21018
- }
21019
- if (depth < 0) depth = 0;
21020
- }
21021
- }
21022
- return result;
21147
+ function normalizedSimilarity(a, b) {
21148
+ return similarity(normalize(a), normalize(b));
21023
21149
  }
21024
- function removeNestedTables(html) {
21025
- let result = "";
21026
- let depth = 0;
21027
- const re = /<(\/?)table(?:[\s>]|>)/gi;
21028
- let last = 0;
21029
- let m;
21030
- while ((m = re.exec(html)) !== null) {
21031
- if (m[1] !== "/") {
21032
- if (depth === 0) result += html.slice(last, m.index);
21033
- depth++;
21034
- } else {
21035
- depth--;
21036
- if (depth === 0) last = m.index + m[0].length;
21037
- if (depth < 0) depth = 0;
21150
+ function normalize(s) {
21151
+ return s.replace(/\s+/g, " ").trim();
21152
+ }
21153
+ var MAX_LEVENSHTEIN_LEN = 1e4;
21154
+ function levenshtein(a, b) {
21155
+ if (a.length + b.length > MAX_LEVENSHTEIN_LEN) {
21156
+ const sampleLen = Math.min(500, a.length, b.length);
21157
+ let diffs = 0;
21158
+ for (let i = 0; i < sampleLen; i++) if (a[i] !== b[i]) diffs++;
21159
+ const sampleRate = sampleLen > 0 ? diffs / sampleLen : 1;
21160
+ return Math.abs(a.length - b.length) + Math.round(Math.min(a.length, b.length) * sampleRate);
21161
+ }
21162
+ if (a.length > b.length) [a, b] = [b, a];
21163
+ const m = a.length;
21164
+ const n = b.length;
21165
+ let prev = Array.from({ length: m + 1 }, (_, i) => i);
21166
+ let curr = new Array(m + 1);
21167
+ for (let j = 1; j <= n; j++) {
21168
+ curr[0] = j;
21169
+ for (let i = 1; i <= m; i++) {
21170
+ if (a[i - 1] === b[j - 1]) {
21171
+ curr[i] = prev[i - 1];
21172
+ } else {
21173
+ curr[i] = 1 + Math.min(prev[i - 1], prev[i], curr[i - 1]);
21174
+ }
21038
21175
  }
21176
+ ;
21177
+ [prev, curr] = [curr, prev];
21039
21178
  }
21040
- if (depth === 0) result += html.slice(last);
21041
- return result;
21179
+ return prev[m];
21042
21180
  }
21043
21181
 
21044
- // src/hwpx/generator.ts
21045
- var NS_SECTION = "http://www.hancom.co.kr/hwpml/2011/section";
21046
- var NS_PARA = "http://www.hancom.co.kr/hwpml/2011/paragraph";
21047
- var NS_HEAD = "http://www.hancom.co.kr/hwpml/2011/head";
21048
- var NS_CORE = "http://www.hancom.co.kr/hwpml/2011/core";
21049
- var NS_OPF = "http://www.idpf.org/2007/opf/";
21050
- var NS_HPF = "http://www.hancom.co.kr/schema/2011/hpf";
21051
- var NS_OCF = "urn:oasis:names:tc:opendocument:xmlns:container";
21052
- var CHAR_NORMAL = 0;
21053
- var CHAR_BOLD = 1;
21054
- var CHAR_ITALIC = 2;
21055
- var CHAR_BOLD_ITALIC = 3;
21056
- var CHAR_CODE = 4;
21057
- var CHAR_H1 = 5;
21058
- var CHAR_H2 = 6;
21059
- var CHAR_H3 = 7;
21060
- var CHAR_H4 = 8;
21061
- var CHAR_TABLE_HEADER = 9;
21062
- var CHAR_QUOTE = 10;
21063
- var PARA_NORMAL = 0;
21064
- var PARA_H1 = 1;
21065
- var PARA_H2 = 2;
21066
- var PARA_H3 = 3;
21067
- var PARA_H4 = 4;
21068
- var PARA_CODE = 5;
21069
- var PARA_QUOTE = 6;
21070
- var PARA_LIST = 7;
21071
- var DEFAULT_TEXT_COLOR = "#000000";
21072
- function resolveTheme(theme) {
21073
- return {
21074
- h1: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _174 => _174.headingColors, 'optionalAccess', _175 => _175[1]]), () => ( DEFAULT_TEXT_COLOR)),
21075
- h2: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _176 => _176.headingColors, 'optionalAccess', _177 => _177[2]]), () => ( DEFAULT_TEXT_COLOR)),
21076
- h3: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _178 => _178.headingColors, 'optionalAccess', _179 => _179[3]]), () => ( DEFAULT_TEXT_COLOR)),
21077
- h4: _nullishCoalesce(_nullishCoalesce(_optionalChain([theme, 'optionalAccess', _180 => _180.headingColors, 'optionalAccess', _181 => _181[4]]), () => ( _optionalChain([theme, 'optionalAccess', _182 => _182.headingColors, 'optionalAccess', _183 => _183[3]]))), () => ( DEFAULT_TEXT_COLOR)),
21078
- body: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _184 => _184.bodyColor]), () => ( DEFAULT_TEXT_COLOR)),
21079
- quote: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _185 => _185.quoteColor]), () => ( DEFAULT_TEXT_COLOR)),
21080
- /** quoteColor가 명시되었는지 — blockquote charPr 분기에 사용 (baseline 호환) */
21081
- hasQuoteOption: _optionalChain([theme, 'optionalAccess', _186 => _186.quoteColor]) !== void 0,
21082
- tableHeader: _nullishCoalesce(_nullishCoalesce(_optionalChain([theme, 'optionalAccess', _187 => _187.tableHeaderColor]), () => ( _optionalChain([theme, 'optionalAccess', _188 => _188.bodyColor]))), () => ( DEFAULT_TEXT_COLOR)),
21083
- tableHeaderBold: !!_optionalChain([theme, 'optionalAccess', _189 => _189.tableHeaderBold])
21084
- };
21085
- }
21086
- async function markdownToHwpx(markdown, options) {
21087
- const theme = resolveTheme(_optionalChain([options, 'optionalAccess', _190 => _190.theme]));
21088
- const gongmun = _optionalChain([options, 'optionalAccess', _191 => _191.gongmun]) ? resolveGongmun(options.gongmun) : null;
21089
- const blocks = parseMarkdownToBlocks(markdown);
21090
- const gongmunList = gongmun ? precomputeGongmunList(blocks, gongmun) : null;
21091
- const fit = gongmun && gongmunList ? computeGongmunFitPlan(blocks, gongmun, gongmunList) : null;
21092
- const sectionXml = blocksToSectionXml(blocks, theme, gongmun, gongmunList, fit);
21093
- const zip = new (0, _jszip2.default)();
21094
- zip.file("mimetype", "application/hwp+zip", { compression: "STORE" });
21095
- zip.file("META-INF/container.xml", generateContainerXml());
21096
- zip.file("Contents/content.hpf", generateManifest());
21097
- zip.file("Contents/header.xml", generateHeaderXml(theme, gongmun, _nullishCoalesce(_optionalChain([fit, 'optionalAccess', _192 => _192.variants]), () => ( []))));
21098
- zip.file("Contents/section0.xml", sectionXml);
21099
- zip.file("Preview/PrvText.txt", buildPrvText(blocks));
21100
- return await zip.generateAsync({ type: "arraybuffer" });
21101
- }
21102
- function buildPrvText(blocks) {
21103
- const lines = [];
21104
- let bytes = 0;
21105
- for (const b of blocks) {
21106
- let text = b.text || (b.rows ? b.rows.map((r) => r.join(" ")).join("\n") : "");
21107
- if (b.type === "html_table") text = text.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
21108
- if (!text) continue;
21109
- lines.push(text);
21110
- bytes += text.length * 3;
21111
- if (bytes > 1024) break;
21112
- }
21113
- return lines.join("\n").slice(0, 1024);
21114
- }
21115
- function parseMarkdownToBlocks(md2) {
21182
+ // src/roundtrip/markdown-units.ts
21183
+ function splitMarkdownUnits(md2) {
21116
21184
  const lines = md2.split("\n");
21117
- const blocks = [];
21185
+ const units = [];
21118
21186
  let i = 0;
21119
21187
  while (i < lines.length) {
21120
21188
  const line = lines[i];
@@ -21122,420 +21190,369 @@ function parseMarkdownToBlocks(md2) {
21122
21190
  i++;
21123
21191
  continue;
21124
21192
  }
21125
- const fenceMatch = line.match(/^(`{3,}|~{3,})(.*)$/);
21126
- if (fenceMatch) {
21127
- const fence = fenceMatch[1];
21128
- const lang = fenceMatch[2].trim();
21129
- const codeLines = [];
21130
- i++;
21131
- while (i < lines.length && !lines[i].startsWith(fence)) {
21132
- codeLines.push(lines[i]);
21133
- i++;
21134
- }
21135
- if (i < lines.length) i++;
21136
- blocks.push({ type: "code_block", text: codeLines.join("\n"), lang });
21137
- continue;
21138
- }
21139
- if (/^(\*{3,}|-{3,}|_{3,})\s*$/.test(line.trim())) {
21140
- blocks.push({ type: "hr" });
21141
- i++;
21142
- continue;
21143
- }
21144
- const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
21145
- if (headingMatch) {
21146
- blocks.push({ type: "heading", text: headingMatch[2].trim(), level: headingMatch[1].length });
21147
- i++;
21148
- continue;
21149
- }
21150
- if (/^<table[\s>]/i.test(line.trimStart())) {
21151
- const htmlLines = [];
21193
+ if (line.trim().startsWith("<table>")) {
21194
+ const collected2 = [];
21152
21195
  let depth = 0;
21153
21196
  while (i < lines.length) {
21154
21197
  const l = lines[i];
21155
- htmlLines.push(l);
21156
- depth += (_nullishCoalesce(l.match(/<table[\s>]/gi), () => ( []))).length;
21157
- depth -= (_nullishCoalesce(l.match(/<\/table>/gi), () => ( []))).length;
21198
+ collected2.push(l);
21199
+ depth += (l.match(/<table>/g) || []).length;
21200
+ depth -= (l.match(/<\/table>/g) || []).length;
21158
21201
  i++;
21159
21202
  if (depth <= 0) break;
21160
21203
  }
21161
- blocks.push({ type: "html_table", text: htmlLines.join("\n") });
21204
+ units.push({ kind: "html-table", raw: collected2.join("\n"), lines: collected2 });
21162
21205
  continue;
21163
21206
  }
21164
21207
  if (line.trimStart().startsWith("|")) {
21165
- const tableRows = [];
21208
+ const collected2 = [];
21166
21209
  while (i < lines.length && lines[i].trimStart().startsWith("|")) {
21167
- const row = lines[i];
21168
- if (/^[\s|:\-]+$/.test(row)) {
21169
- i++;
21170
- continue;
21171
- }
21172
- const cells = row.split("|").slice(1, -1).map((c) => c.trim());
21173
- if (cells.length > 0) tableRows.push(cells);
21210
+ collected2.push(lines[i]);
21174
21211
  i++;
21175
21212
  }
21176
- if (tableRows.length > 0) blocks.push({ type: "table", rows: tableRows });
21213
+ units.push({ kind: "gfm-table", raw: collected2.join("\n"), lines: collected2 });
21177
21214
  continue;
21178
21215
  }
21179
- if (line.trimStart().startsWith("> ")) {
21180
- const quoteLines = [];
21181
- while (i < lines.length && (lines[i].trimStart().startsWith("> ") || lines[i].trimStart().startsWith(">"))) {
21182
- quoteLines.push(lines[i].replace(/^>\s?/, ""));
21183
- i++;
21184
- }
21185
- for (const ql of quoteLines) {
21186
- blocks.push({ type: "blockquote", text: ql.trim() || "" });
21187
- }
21216
+ if (/^-{3,}\s*$/.test(line.trim())) {
21217
+ units.push({ kind: "separator", raw: line.trim(), lines: [line.trim()] });
21218
+ i++;
21188
21219
  continue;
21189
21220
  }
21190
- const listMatch = line.match(/^(\s*)([-*+]|\d+[.)]) (.+)$/);
21191
- if (listMatch) {
21192
- const indent = Math.floor(listMatch[1].length / 2);
21193
- const ordered = /\d/.test(listMatch[2]);
21194
- blocks.push({ type: "list_item", text: listMatch[3].trim(), ordered, indent });
21221
+ if (/^!\[image\]\([^)]*\)\s*$/.test(line.trim())) {
21222
+ units.push({ kind: "image", raw: line.trim(), lines: [line.trim()] });
21195
21223
  i++;
21196
21224
  continue;
21197
21225
  }
21198
- blocks.push({ type: "paragraph", text: line.trim() });
21199
- i++;
21226
+ const collected = [];
21227
+ while (i < lines.length && lines[i].trim() && !lines[i].trimStart().startsWith("|") && !lines[i].trim().startsWith("<table>")) {
21228
+ collected.push(lines[i].trim());
21229
+ i++;
21230
+ }
21231
+ units.push({ kind: "text", raw: collected.join("\n"), lines: collected });
21200
21232
  }
21201
- return blocks;
21233
+ return units;
21202
21234
  }
21203
- function parseInlineMarkdown(text) {
21204
- text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1");
21205
- text = text.replace(/\[([^\]]*)\]\(([^)]*)\)/g, (_, t, u) => t || u);
21206
- text = text.replace(/~~([^~]+)~~/g, "$1");
21207
- const spans = [];
21208
- const regex = /(`[^`]+`|\*{3}[^*]+\*{3}|\*{2}[^*]+\*{2}|\*[^*]+\*|_{2}[^_]+_{2}|_[^_]+_)/g;
21209
- let lastIdx = 0;
21210
- for (const match of text.matchAll(regex)) {
21211
- const idx = match.index;
21212
- if (idx > lastIdx) {
21213
- spans.push({ text: text.slice(lastIdx, idx), bold: false, italic: false, code: false });
21235
+ function alignUnits(a, b) {
21236
+ const m = a.length, n = b.length;
21237
+ if (m * n > 4e6) {
21238
+ const result2 = [];
21239
+ let pre = 0;
21240
+ while (pre < m && pre < n && a[pre] === b[pre]) {
21241
+ result2.push([pre, pre]);
21242
+ pre++;
21214
21243
  }
21215
- const raw = match[0];
21216
- if (raw.startsWith("`")) {
21217
- spans.push({ text: raw.slice(1, -1), bold: false, italic: false, code: true });
21218
- } else if (raw.startsWith("***") || raw.startsWith("___")) {
21219
- spans.push({ text: raw.slice(3, -3), bold: true, italic: true, code: false });
21220
- } else if (raw.startsWith("**") || raw.startsWith("__")) {
21221
- spans.push({ text: raw.slice(2, -2), bold: true, italic: false, code: false });
21244
+ let suf = 0;
21245
+ while (suf < m - pre && suf < n - pre && a[m - 1 - suf] === b[n - 1 - suf]) suf++;
21246
+ const aMid = m - pre - suf, bMid = n - pre - suf;
21247
+ if (aMid === bMid) {
21248
+ for (let i2 = 0; i2 < aMid; i2++) result2.push([pre + i2, pre + i2]);
21222
21249
  } else {
21223
- spans.push({ text: raw.slice(1, -1), bold: false, italic: true, code: false });
21250
+ for (let i2 = 0; i2 < aMid; i2++) result2.push([pre + i2, null]);
21251
+ for (let j2 = 0; j2 < bMid; j2++) result2.push([null, pre + j2]);
21224
21252
  }
21225
- lastIdx = idx + raw.length;
21253
+ for (let s = suf - 1; s >= 0; s--) result2.push([m - 1 - s, n - 1 - s]);
21254
+ return result2;
21226
21255
  }
21227
- if (lastIdx < text.length) {
21228
- spans.push({ text: text.slice(lastIdx), bold: false, italic: false, code: false });
21256
+ const dp = Array.from({ length: m + 1 }, () => new Int32Array(n + 1));
21257
+ for (let i2 = 1; i2 <= m; i2++) {
21258
+ for (let j2 = 1; j2 <= n; j2++) {
21259
+ dp[i2][j2] = a[i2 - 1] === b[j2 - 1] ? dp[i2 - 1][j2 - 1] + 1 : Math.max(dp[i2 - 1][j2], dp[i2][j2 - 1]);
21260
+ }
21229
21261
  }
21230
- if (spans.length === 0) {
21231
- spans.push({ text, bold: false, italic: false, code: false });
21262
+ const matches = [];
21263
+ let i = m, j = n;
21264
+ while (i > 0 && j > 0) {
21265
+ if (a[i - 1] === b[j - 1] && dp[i][j] === dp[i - 1][j - 1] + 1) {
21266
+ matches.push([i - 1, j - 1]);
21267
+ i--;
21268
+ j--;
21269
+ } else if (dp[i - 1][j] >= dp[i][j - 1]) i--;
21270
+ else j--;
21232
21271
  }
21233
- return spans;
21234
- }
21235
- function spanToCharPrId(span) {
21236
- if (span.code) return CHAR_CODE;
21237
- if (span.bold && span.italic) return CHAR_BOLD_ITALIC;
21238
- if (span.bold) return CHAR_BOLD;
21239
- if (span.italic) return CHAR_ITALIC;
21240
- return CHAR_NORMAL;
21241
- }
21242
- function escapeXml(text) {
21243
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
21244
- }
21245
- function generateRuns(text, defaultCharPr = CHAR_NORMAL, mapCharId) {
21246
- const spans = parseInlineMarkdown(text);
21247
- return spans.map((span) => {
21248
- let charId = span.code || span.bold || span.italic ? spanToCharPrId(span) : defaultCharPr;
21249
- if (mapCharId) charId = mapCharId(charId);
21250
- return `<hp:run charPrIDRef="${charId}"><hp:t>${escapeXml(span.text)}</hp:t></hp:run>`;
21251
- }).join("");
21252
- }
21253
- function generateParagraph(text, paraPrId = PARA_NORMAL, charPrId = CHAR_NORMAL, mapCharId) {
21254
- if (paraPrId === PARA_CODE) {
21255
- return `<hp:p paraPrIDRef="${paraPrId}" styleIDRef="0"><hp:run charPrIDRef="${CHAR_CODE}"><hp:t>${escapeXml(text)}</hp:t></hp:run></hp:p>`;
21272
+ matches.reverse();
21273
+ const result = [];
21274
+ let ai = 0, bi = 0;
21275
+ const flushGap = (aEnd, bEnd) => {
21276
+ if (aEnd - ai === bEnd - bi) {
21277
+ while (ai < aEnd) result.push([ai++, bi++]);
21278
+ return;
21279
+ }
21280
+ while (ai < aEnd && bi < bEnd) {
21281
+ const sim = normalizedSimilarity(a[ai], b[bi]);
21282
+ if (sim >= 0.4) {
21283
+ if (aEnd - ai > bEnd - bi && bestSimInRange(a, ai + 1, ai + (aEnd - ai) - (bEnd - bi), b[bi]) > sim) {
21284
+ result.push([ai++, null]);
21285
+ } else if (bEnd - bi > aEnd - ai && bestSimInRange(b, bi + 1, bi + (bEnd - bi) - (aEnd - ai), a[ai]) > sim) {
21286
+ result.push([null, bi++]);
21287
+ } else {
21288
+ result.push([ai++, bi++]);
21289
+ }
21290
+ } else if (aEnd - ai >= bEnd - bi) result.push([ai++, null]);
21291
+ else result.push([null, bi++]);
21292
+ }
21293
+ while (ai < aEnd) result.push([ai++, null]);
21294
+ while (bi < bEnd) result.push([null, bi++]);
21295
+ };
21296
+ for (const [pi, pj] of matches) {
21297
+ flushGap(pi, pj);
21298
+ result.push([ai++, bi++]);
21256
21299
  }
21257
- const runs = generateRuns(text, charPrId, mapCharId);
21258
- return `<hp:p paraPrIDRef="${paraPrId}" styleIDRef="0">${runs}</hp:p>`;
21259
- }
21260
- function headingParaPrId(level) {
21261
- if (level === 1) return PARA_H1;
21262
- if (level === 2) return PARA_H2;
21263
- if (level === 3) return PARA_H3;
21264
- return PARA_H4;
21300
+ flushGap(m, n);
21301
+ return result;
21265
21302
  }
21266
- function headingCharPrId(level) {
21267
- if (level === 1) return CHAR_H1;
21268
- if (level === 2) return CHAR_H2;
21269
- if (level === 3) return CHAR_H3;
21270
- return CHAR_H4;
21303
+ function bestSimInRange(arr, from, to, target) {
21304
+ let best = 0;
21305
+ for (let k = from; k <= to && k < arr.length; k++) {
21306
+ const s = normalizedSimilarity(arr[k], target);
21307
+ if (s > best) best = s;
21308
+ }
21309
+ return best;
21271
21310
  }
21272
- function generateContainerXml() {
21273
- return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
21274
- <ocf:container xmlns:ocf="${NS_OCF}" xmlns:hpf="${NS_HPF}">
21275
- <ocf:rootfiles>
21276
- <ocf:rootfile full-path="Contents/content.hpf" media-type="application/hwpml-package+xml"/>
21277
- </ocf:rootfiles>
21278
- </ocf:container>`;
21311
+ function escapeGfm(text) {
21312
+ return text.replace(/~/g, "\\~");
21279
21313
  }
21280
- function generateManifest() {
21281
- return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
21282
- <opf:package xmlns:opf="${NS_OPF}" xmlns:hpf="${NS_HPF}" xmlns:hh="${NS_HEAD}">
21283
- <opf:manifest>
21284
- <opf:item id="header" href="Contents/header.xml" media-type="application/xml"/>
21285
- <opf:item id="section0" href="Contents/section0.xml" media-type="application/xml"/>
21286
- </opf:manifest>
21287
- <opf:spine>
21288
- <opf:itemref idref="header" linear="no"/>
21289
- <opf:itemref idref="section0" linear="yes"/>
21290
- </opf:spine>
21291
- </opf:package>`;
21314
+ var HWP_SHAPE_ALT_TEXT_RE = /(?:모서리가 둥근 |둥근 )?(?:사각형|직사각형|정사각형|원|타원|삼각형|이등변 삼각형|직각 삼각형|선|직선|곡선|화살표|굵은 화살표|이중 화살표|오각형|육각형|팔각형|별|[4-8]점별|십자|십자형|구름|구름형|마름모|도넛|평행사변형|사다리꼴|부채꼴|호|반원|물결|번개|하트|빗금|블록 화살표|수식|표|그림|개체|그리기\s?개체|묶음\s?개체|글상자|수식\s?개체|OLE\s?개체)\s?입니다\.?/g;
21315
+ function sanitizeText(text) {
21316
+ let result = _chunkYBPNKFJWcjs.mapPuaText.call(void 0, text).replace(/[\u{F0000}-\u{FFFFD}]/gu, "").replace(HWP_SHAPE_ALT_TEXT_RE, "").replace(/ +/g, " ").trim();
21317
+ if (result.length <= 30 && result.includes(" ")) {
21318
+ const tokens = result.split(" ");
21319
+ const koreanSingleCharCount = tokens.filter((t) => t.length === 1 && /[가-힯ㄱ-ㆎ]/.test(t)).length;
21320
+ if (tokens.length >= 3 && koreanSingleCharCount / tokens.length >= 0.7) {
21321
+ result = tokens.join("");
21322
+ }
21323
+ }
21324
+ return result;
21292
21325
  }
21293
- function charPr(id, height, bold, italic, fontId = 0, textColor = DEFAULT_TEXT_COLOR, ratioPct = 100) {
21294
- const boldAttr = bold ? ` bold="1"` : "";
21295
- const italicAttr = italic ? ` italic="1"` : "";
21296
- const effFont = bold ? 2 : fontId;
21297
- return ` <hh:charPr id="${id}" height="${height}" textColor="${textColor}" shadeColor="none" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="1"${boldAttr}${italicAttr}>
21298
- <hh:fontRef hangul="${effFont}" latin="${effFont}" hanja="${effFont}" japanese="${effFont}" other="${effFont}" symbol="${effFont}" user="${effFont}"/>
21299
- <hh:ratio hangul="${ratioPct}" latin="${ratioPct}" hanja="${ratioPct}" japanese="100" other="100" symbol="100" user="100"/>
21300
- <hh:spacing hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
21301
- <hh:relSz hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
21302
- <hh:offset hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
21303
- </hh:charPr>`;
21326
+ function normForMatch(text) {
21327
+ return sanitizeText(text).replace(/\s+/g, " ").trim();
21304
21328
  }
21305
- function paraPr(id, opts = {}) {
21306
- const { align = "JUSTIFY", spaceBefore = 0, spaceAfter = 0, lineSpacing = 160, indent = 0, left = 0, keepWord = false } = opts;
21307
- const breakNonLatin = keepWord ? "KEEP_WORD" : "BREAK_WORD";
21308
- const snapGrid = keepWord ? "0" : "1";
21309
- return ` <hh:paraPr id="${id}" tabPrIDRef="0" condense="0" fontLineHeight="0" snapToGrid="${snapGrid}" suppressLineNumbers="0" checked="0" textDir="AUTO">
21310
- <hh:align horizontal="${align}" vertical="BASELINE"/>
21311
- <hh:heading type="NONE" idRef="0" level="0"/>
21312
- <hh:breakSetting breakLatinWord="KEEP_WORD" breakNonLatinWord="${breakNonLatin}" widowOrphan="0" keepWithNext="0" keepLines="0" pageBreakBefore="0" lineWrap="BREAK"/>
21313
- <hh:autoSpacing eAsianEng="0" eAsianNum="0"/>
21314
- <hh:margin><hc:intent value="${indent}" unit="HWPUNIT"/><hc:left value="${left}" unit="HWPUNIT"/><hc:right value="0" unit="HWPUNIT"/><hc:prev value="${spaceBefore}" unit="HWPUNIT"/><hc:next value="${spaceAfter}" unit="HWPUNIT"/></hh:margin>
21315
- <hh:lineSpacing type="PERCENT" value="${lineSpacing}"/>
21316
- <hh:border borderFillIDRef="1" offsetLeft="0" offsetRight="0" offsetTop="0" offsetBottom="0" connect="0" ignoreMargin="0"/>
21317
- </hh:paraPr>`;
21329
+ function unescapeGfm(text) {
21330
+ return text.replace(/\\~/g, "~");
21318
21331
  }
21319
- var GONGMUN_LIST_BASE = 8;
21320
- var GONGMUN_LIST_LEVELS = 8;
21321
- var GONGMUN_CENTER = GONGMUN_LIST_BASE + GONGMUN_LIST_LEVELS;
21322
- var CHAR_VARIANT_BASE = 11;
21323
- var GONGMUN_BODY_RATIO = 95;
21324
- function plainRenderText(text) {
21325
- return parseInlineMarkdown(text).map((s) => s.text).join("");
21332
+ function summarize(text) {
21333
+ const t = text.replace(/\s+/g, " ").trim();
21334
+ return t.length > 80 ? t.slice(0, 77) + "..." : t;
21326
21335
  }
21327
- function computeGongmunFitPlan(blocks, gongmun, gongmunList) {
21328
- const minRatio = gongmun.autoFitMinRatio;
21329
- if (minRatio === null || minRatio >= GONGMUN_BODY_RATIO) return null;
21330
- const pageW = 59528 - mmToHwpunit(gongmun.margins.left) - mmToHwpunit(gongmun.margins.right);
21331
- const ratioByBlock = /* @__PURE__ */ new Map();
21332
- const variants = [];
21333
- for (let i = 0; i < blocks.length; i++) {
21334
- const block = blocks[i];
21335
- let text;
21336
- let firstW;
21337
- let contW;
21338
- if (block.type === "list_item" && gongmunList.has(i)) {
21339
- const { marker, depth } = gongmunList.get(i);
21340
- const content = plainRenderText(block.text || "");
21341
- text = marker ? `${marker} ${content}` : content;
21342
- const { left, indent } = levelIndent(depth, gongmun.bodyHeight, gongmun.numbering);
21343
- firstW = pageW - left - Math.max(indent, 0);
21344
- contW = pageW - left - Math.max(-indent, 0);
21345
- } else if (block.type === "paragraph") {
21346
- const raw = (block.text || "").trim();
21347
- if (/^<center>[\s\S]*<\/center>$/i.test(raw)) continue;
21348
- text = plainRenderText(raw);
21349
- firstW = contW = pageW;
21350
- } else {
21336
+ function replicateGfmTable(table) {
21337
+ const { cells, rows: numRows, cols: numCols } = table;
21338
+ if (numRows === 0 || numCols === 0) return null;
21339
+ if (numRows === 1 && numCols === 1) return null;
21340
+ if (numCols === 1) return null;
21341
+ const display = Array.from({ length: numRows }, (_, r) => Array.from({ length: numCols }, (_2, c) => ({ text: "", gridR: r, gridC: c })));
21342
+ const skip = /* @__PURE__ */ new Set();
21343
+ for (let r = 0; r < numRows; r++) {
21344
+ for (let c = 0; c < numCols; c++) {
21345
+ if (skip.has(`${r},${c}`)) continue;
21346
+ const cell = _optionalChain([cells, 'access', _179 => _179[r], 'optionalAccess', _180 => _180[c]]);
21347
+ if (!cell) continue;
21348
+ display[r][c] = {
21349
+ text: escapeGfm(sanitizeText(cell.text)).replace(/\|/g, "\\|").replace(/\n/g, "<br>"),
21350
+ gridR: r,
21351
+ gridC: c
21352
+ };
21353
+ for (let dr = 0; dr < cell.rowSpan; dr++) {
21354
+ for (let dc = 0; dc < cell.colSpan; dc++) {
21355
+ if (dr === 0 && dc === 0) continue;
21356
+ if (r + dr < numRows && c + dc < numCols) skip.add(`${r + dr},${c + dc}`);
21357
+ }
21358
+ }
21359
+ c += cell.colSpan - 1;
21360
+ }
21361
+ }
21362
+ const uniqueRows = [];
21363
+ let pendingLabelRow = null;
21364
+ for (let r = 0; r < display.length; r++) {
21365
+ const row = display[r];
21366
+ if (row.every((cell) => cell.text === "")) continue;
21367
+ const nonEmptyCols = row.filter((cell) => cell.text !== "");
21368
+ const hasSkipInRow = row.some((_, c) => skip.has(`${r},${c}`));
21369
+ if (!hasSkipInRow && nonEmptyCols.length === 1 && row[0].text !== "" && row.slice(1).every((c) => c.text === "")) {
21370
+ if (pendingLabelRow) uniqueRows.push(pendingLabelRow);
21371
+ pendingLabelRow = row;
21351
21372
  continue;
21352
21373
  }
21353
- if (!text) continue;
21354
- const r = fitRatioForFewerLines(text, firstW, contW, gongmun.bodyHeight, GONGMUN_BODY_RATIO, minRatio);
21355
- if (r === null) continue;
21356
- ratioByBlock.set(i, r);
21357
- if (!variants.includes(r)) variants.push(r);
21374
+ if (pendingLabelRow) {
21375
+ if (row[0].text === "") row[0] = pendingLabelRow[0];
21376
+ else uniqueRows.push(pendingLabelRow);
21377
+ pendingLabelRow = null;
21378
+ }
21379
+ uniqueRows.push(row);
21358
21380
  }
21359
- return ratioByBlock.size > 0 ? { ratioByBlock, variants } : null;
21381
+ if (pendingLabelRow) uniqueRows.push(pendingLabelRow);
21382
+ return uniqueRows.length > 0 ? uniqueRows : null;
21360
21383
  }
21361
- function variantMapper(fit, blockIdx) {
21362
- const r = fit.ratioByBlock.get(blockIdx);
21363
- if (r === void 0) return void 0;
21364
- const vi = fit.variants.indexOf(r);
21365
- return (id) => id >= 0 && id <= 3 ? CHAR_VARIANT_BASE + vi * 4 + id : id;
21384
+ function parseGfmTable(lines) {
21385
+ const rows = [];
21386
+ for (const line of lines) {
21387
+ const trimmed = line.trim();
21388
+ if (!trimmed.startsWith("|")) continue;
21389
+ const cells = trimmed.split(/(?<!\\)\|/).slice(1, -1).map((c) => c.trim());
21390
+ if (cells.length === 0) continue;
21391
+ if (cells.every((c) => /^:?-{3,}:?$/.test(c))) continue;
21392
+ rows.push(cells);
21393
+ }
21394
+ return rows;
21366
21395
  }
21367
- function buildCharProperties(theme, gongmun, ratioVariants = []) {
21368
- let body = 1e3, code = 900, h1 = 1800, h2 = 1400, h3 = 1200, h4 = 1100;
21369
- if (gongmun) {
21370
- body = gongmun.bodyHeight;
21371
- code = Math.max(body - 200, 900);
21372
- h1 = gongmun.preset === "report" || gongmun.preset === "plan" ? 2e3 : 1700;
21373
- h2 = 1600;
21374
- h3 = body;
21375
- h4 = Math.max(body - 100, 1300);
21396
+ function unescapeGfmCell(text) {
21397
+ return text.replace(/<br\s*\/?>/gi, "\n").replace(/\\\|/g, "|").replace(/\\~/g, "~");
21398
+ }
21399
+ function replicateCellInnerHtml(cell) {
21400
+ if (_optionalChain([cell, 'access', _181 => _181.blocks, 'optionalAccess', _182 => _182.length])) {
21401
+ return cell.blocks.map((b) => {
21402
+ if (b.type === "table" && b.table) {
21403
+ const cap = b.table.caption ? sanitizeText(b.table.caption) : "";
21404
+ return (cap ? cap + "<br>" : "") + replicateTableToHtml(b.table);
21405
+ }
21406
+ if (b.type === "image" && b.text) return `<img src="${b.text}" alt="image">`;
21407
+ const t = sanitizeText(_nullishCoalesce(b.text, () => ( "")));
21408
+ return t ? t.replace(/\n/g, "<br>") : "";
21409
+ }).filter(Boolean).join("<br>");
21376
21410
  }
21377
- const bodyRatio = gongmun ? GONGMUN_BODY_RATIO : 100;
21378
- const rows = [
21379
- charPr(0, body, false, false, 0, theme.body, bodyRatio),
21380
- charPr(1, body, true, false, 0, theme.body, bodyRatio),
21381
- charPr(2, body, false, true, 0, theme.body, bodyRatio),
21382
- charPr(3, body, true, true, 0, theme.body, bodyRatio),
21383
- charPr(4, code, false, false, 1),
21384
- charPr(5, h1, true, false, 1, theme.h1),
21385
- charPr(6, h2, true, false, 1, theme.h2),
21386
- charPr(7, h3, true, false, 1, theme.h3),
21387
- charPr(8, h4, true, false, 1, theme.h4),
21388
- charPr(CHAR_TABLE_HEADER, body, theme.tableHeaderBold, false, 0, theme.tableHeader),
21389
- charPr(CHAR_QUOTE, body, false, true, 0, theme.quote)
21390
- ];
21391
- for (const r of ratioVariants) {
21392
- rows.push(
21393
- charPr(rows.length, body, false, false, 0, theme.body, r),
21394
- charPr(rows.length + 1, body, true, false, 0, theme.body, r),
21395
- charPr(rows.length + 2, body, false, true, 0, theme.body, r),
21396
- charPr(rows.length + 3, body, true, true, 0, theme.body, r)
21397
- );
21411
+ return sanitizeText(cell.text).replace(/\n/g, "<br>");
21412
+ }
21413
+ function replicateTableToHtml(table) {
21414
+ const rows = replicateHtmlTable(table);
21415
+ const lines = ["<table>"];
21416
+ for (let r = 0; r < rows.length; r++) {
21417
+ const tag = rows[r].tag;
21418
+ const rowHtml = rows[r].cells.map((cell) => {
21419
+ const attrs = [];
21420
+ if (cell.colSpan > 1) attrs.push(`colspan="${cell.colSpan}"`);
21421
+ if (cell.rowSpan > 1) attrs.push(`rowspan="${cell.rowSpan}"`);
21422
+ const attrStr = attrs.length ? " " + attrs.join(" ") : "";
21423
+ return `<${tag}${attrStr}>${cell.inner}</${tag}>`;
21424
+ });
21425
+ if (rowHtml.length) lines.push(`<tr>${rowHtml.join("")}</tr>`);
21426
+ }
21427
+ lines.push("</table>");
21428
+ return lines.join("\n");
21429
+ }
21430
+ function replicateHtmlTable(table) {
21431
+ const { cells, rows: numRows, cols: numCols } = table;
21432
+ const skip = /* @__PURE__ */ new Set();
21433
+ const result = [];
21434
+ for (let r = 0; r < numRows; r++) {
21435
+ const tag = r === 0 ? "th" : "td";
21436
+ const rowCells = [];
21437
+ for (let c = 0; c < numCols; c++) {
21438
+ if (skip.has(`${r},${c}`)) continue;
21439
+ const cell = _optionalChain([cells, 'access', _183 => _183[r], 'optionalAccess', _184 => _184[c]]);
21440
+ if (!cell) continue;
21441
+ for (let dr = 0; dr < cell.rowSpan; dr++) {
21442
+ for (let dc = 0; dc < cell.colSpan; dc++) {
21443
+ if (dr === 0 && dc === 0) continue;
21444
+ if (r + dr < numRows && c + dc < numCols) skip.add(`${r + dr},${c + dc}`);
21445
+ }
21446
+ }
21447
+ rowCells.push({
21448
+ inner: replicateCellInnerHtml(cell),
21449
+ colSpan: cell.colSpan,
21450
+ rowSpan: cell.rowSpan,
21451
+ gridR: r,
21452
+ gridC: c
21453
+ });
21454
+ }
21455
+ if (rowCells.length) result.push({ tag, cells: rowCells });
21456
+ }
21457
+ return result;
21458
+ }
21459
+ function parseHtmlTable(raw) {
21460
+ const re = /<(\/?)(table|tr|td|th)((?:"[^"]*"|'[^']*'|[^>"'])*?)>/gi;
21461
+ let depth = 0;
21462
+ let currentRow = null;
21463
+ let cellStart = -1;
21464
+ let cellInfo = null;
21465
+ const rows = [];
21466
+ let m;
21467
+ while ((m = re.exec(raw)) !== null) {
21468
+ const isClose = m[1] === "/";
21469
+ const tag = m[2].toLowerCase();
21470
+ const attrs = m[3] || "";
21471
+ if (tag === "table") {
21472
+ depth += isClose ? -1 : 1;
21473
+ if (depth < 0) return null;
21474
+ continue;
21475
+ }
21476
+ if (depth !== 1) continue;
21477
+ if (tag === "tr") {
21478
+ if (!isClose) currentRow = [];
21479
+ else if (currentRow) {
21480
+ rows.push({ tag: rows.length === 0 ? "th" : "td", cells: currentRow });
21481
+ currentRow = null;
21482
+ }
21483
+ } else {
21484
+ if (!isClose) {
21485
+ const cs = parseInt(_optionalChain([attrs, 'access', _185 => _185.match, 'call', _186 => _186(/colspan\s*=\s*"(\d+)"/i), 'optionalAccess', _187 => _187[1]]) || "1", 10);
21486
+ const rs = parseInt(_optionalChain([attrs, 'access', _188 => _188.match, 'call', _189 => _189(/rowspan\s*=\s*"(\d+)"/i), 'optionalAccess', _190 => _190[1]]) || "1", 10);
21487
+ cellStart = m.index + m[0].length;
21488
+ cellInfo = { colSpan: isNaN(cs) ? 1 : cs, rowSpan: isNaN(rs) ? 1 : rs };
21489
+ } else if (cellStart >= 0 && cellInfo && currentRow) {
21490
+ currentRow.push({ inner: raw.slice(cellStart, m.index), colSpan: cellInfo.colSpan, rowSpan: cellInfo.rowSpan });
21491
+ cellStart = -1;
21492
+ cellInfo = null;
21493
+ }
21494
+ }
21398
21495
  }
21399
- return `<hh:charProperties itemCnt="${rows.length}">
21400
- ${rows.join("\n")}
21401
- </hh:charProperties>`;
21496
+ if (depth !== 0) return null;
21497
+ return rows;
21402
21498
  }
21403
- function buildParaProperties(gongmun) {
21404
- if (!gongmun) {
21405
- const base2 = [
21406
- paraPr(0),
21407
- paraPr(1, { align: "LEFT", spaceBefore: 800, spaceAfter: 200, lineSpacing: 180 }),
21408
- paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: 170 }),
21409
- paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: 160 }),
21410
- paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: 160 }),
21411
- paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400 }),
21412
- paraPr(6, { align: "LEFT", lineSpacing: 150, indent: 600 }),
21413
- paraPr(7, { align: "LEFT", lineSpacing: 160, indent: 600 })
21414
- ];
21415
- return `<hh:paraProperties itemCnt="${base2.length}">
21416
- ${base2.join("\n")}
21417
- </hh:paraProperties>`;
21499
+ var AUTONUM_PREFIX_RE = /^(?:[0-90-9a-zA-Z가-힣]{1,6}[.)\]:]|[([][0-90-9a-zA-Z가-힣]{1,6}[)\]][.:]?|[ⅰ-ⅹⅠ-Ⅹ①-⑮][.)\]:]?)$/u;
21500
+ function htmlCellInnerToLines(inner) {
21501
+ let hadNonText = false;
21502
+ let work = inner;
21503
+ if (/<table[\s>]/i.test(work)) {
21504
+ hadNonText = true;
21505
+ work = removeNestedTables(work);
21418
21506
  }
21419
- const ls = gongmun.lineSpacing;
21420
- const titleAlign = gongmun.centerTitle ? "CENTER" : "LEFT";
21421
- const base = [
21422
- paraPr(0, { lineSpacing: ls, keepWord: true }),
21423
- paraPr(1, { align: titleAlign, spaceBefore: 400, spaceAfter: 400, lineSpacing: ls, keepWord: true }),
21424
- paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: ls, keepWord: true }),
21425
- paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
21426
- paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
21427
- paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400, keepWord: true }),
21428
- paraPr(6, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true }),
21429
- paraPr(7, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true })
21430
- ];
21431
- for (let d = 0; d < GONGMUN_LIST_LEVELS; d++) {
21432
- const { left, indent } = levelIndent(d, gongmun.bodyHeight, gongmun.numbering);
21433
- const sectionGap = gongmun.numbering === "report" && d === 0 ? Math.round(gongmun.bodyHeight * 0.5) : 0;
21434
- base.push(paraPr(GONGMUN_LIST_BASE + d, { align: "JUSTIFY", lineSpacing: ls, left, indent, spaceBefore: sectionGap, keepWord: true }));
21507
+ if (/<img\s/i.test(work)) {
21508
+ hadNonText = true;
21509
+ work = work.replace(/<img\s(?:"[^"]*"|'[^']*'|[^>"'])*?>/gi, "");
21435
21510
  }
21436
- base.push(paraPr(GONGMUN_CENTER, { align: "CENTER", lineSpacing: ls, keepWord: true }));
21437
- return `<hh:paraProperties itemCnt="${base.length}">
21438
- ${base.join("\n")}
21439
- </hh:paraProperties>`;
21511
+ const lines = work.split(/<br\s*\/?>/gi).map((s) => s.trim()).filter((s) => s.length > 0);
21512
+ return { lines, hadNonText };
21440
21513
  }
21441
- function generateHeaderXml(theme, gongmun, ratioVariants = []) {
21442
- const bodyFace = _optionalChain([gongmun, 'optionalAccess', _193 => _193.bodyFont]) === "gothic" ? "\uB9D1\uC740 \uACE0\uB515" : "\uD568\uCD08\uB86C\uBC14\uD0D5";
21443
- const charPropsXml = buildCharProperties(theme, gongmun, ratioVariants);
21444
- const paraPropsXml = buildParaProperties(gongmun);
21445
- return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
21446
- <hh:head xmlns:hh="${NS_HEAD}" xmlns:hp="${NS_PARA}" xmlns:hc="${NS_CORE}" version="1.4" secCnt="1">
21447
- <hh:beginNum page="1" footnote="1" endnote="1" pic="1" tbl="1" equation="1"/>
21448
- <hh:refList>
21449
- <hh:fontfaces itemCnt="7">
21450
- <hh:fontface lang="HANGUL" fontCnt="3">
21451
- <hh:font id="0" face="${bodyFace}" type="TTF" isEmbedded="0">
21452
- <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21453
- </hh:font>
21454
- <hh:font id="1" face="\uD568\uCD08\uB86C\uB3CB\uC6C0" type="TTF" isEmbedded="0">
21455
- <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21456
- </hh:font>
21457
- <hh:font id="2" face="HY\uACAC\uACE0\uB515" type="TTF" isEmbedded="0">
21458
- <hh:typeInfo familyType="FCAT_GOTHIC" weight="9" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21459
- </hh:font>
21460
- </hh:fontface>
21461
- <hh:fontface lang="LATIN" fontCnt="3">
21462
- <hh:font id="0" face="Times New Roman" type="TTF" isEmbedded="0">
21463
- <hh:typeInfo familyType="FCAT_OLDSTYLE" weight="5" proportion="4" contrast="2" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="4"/>
21464
- </hh:font>
21465
- <hh:font id="1" face="Consolas" type="TTF" isEmbedded="0">
21466
- <hh:typeInfo familyType="FCAT_MODERN" weight="5" proportion="0" contrast="0" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="0"/>
21467
- </hh:font>
21468
- <hh:font id="2" face="Arial Black" type="TTF" isEmbedded="0">
21469
- <hh:typeInfo familyType="FCAT_GOTHIC" weight="9" proportion="0" contrast="0" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="0"/>
21470
- </hh:font>
21471
- </hh:fontface>
21472
- <hh:fontface lang="HANJA" fontCnt="1">
21473
- <hh:font id="0" face="\uD568\uCD08\uB86C\uBC14\uD0D5" type="TTF" isEmbedded="0">
21474
- <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21475
- </hh:font>
21476
- </hh:fontface>
21477
- <hh:fontface lang="JAPANESE" fontCnt="1">
21478
- <hh:font id="0" face="\uAD74\uB9BC" type="TTF" isEmbedded="0">
21479
- <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21480
- </hh:font>
21481
- </hh:fontface>
21482
- <hh:fontface lang="OTHER" fontCnt="1">
21483
- <hh:font id="0" face="\uAD74\uB9BC" type="TTF" isEmbedded="0">
21484
- <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21485
- </hh:font>
21486
- </hh:fontface>
21487
- <hh:fontface lang="SYMBOL" fontCnt="1">
21488
- <hh:font id="0" face="Symbol" type="TTF" isEmbedded="0">
21489
- <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21490
- </hh:font>
21491
- </hh:fontface>
21492
- <hh:fontface lang="USER" fontCnt="1">
21493
- <hh:font id="0" face="\uAD74\uB9BC" type="TTF" isEmbedded="0">
21494
- <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21495
- </hh:font>
21496
- </hh:fontface>
21497
- </hh:fontfaces>
21498
- <hh:borderFills itemCnt="2">
21499
- <hh:borderFill id="1" threeD="0" shadow="0" centerLine="NONE" breakCellSeparateLine="0">
21500
- <hh:slash type="NONE" Crooked="0" isCounter="0"/>
21501
- <hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
21502
- <hh:leftBorder type="NONE" width="0.1 mm" color="#000000"/>
21503
- <hh:rightBorder type="NONE" width="0.1 mm" color="#000000"/>
21504
- <hh:topBorder type="NONE" width="0.1 mm" color="#000000"/>
21505
- <hh:bottomBorder type="NONE" width="0.1 mm" color="#000000"/>
21506
- </hh:borderFill>
21507
- <hh:borderFill id="2" threeD="0" shadow="0" centerLine="NONE" breakCellSeparateLine="0">
21508
- <hh:slash type="NONE" Crooked="0" isCounter="0"/>
21509
- <hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
21510
- <hh:leftBorder type="SOLID" width="0.12 mm" color="#000000"/>
21511
- <hh:rightBorder type="SOLID" width="0.12 mm" color="#000000"/>
21512
- <hh:topBorder type="SOLID" width="0.12 mm" color="#000000"/>
21513
- <hh:bottomBorder type="SOLID" width="0.12 mm" color="#000000"/>
21514
- </hh:borderFill>
21515
- </hh:borderFills>
21516
- ${charPropsXml}
21517
- <hh:tabProperties itemCnt="0"/>
21518
- <hh:numberings itemCnt="0"/>
21519
- <hh:bullets itemCnt="0"/>
21520
- ${paraPropsXml}
21521
- <hh:styles itemCnt="1">
21522
- <hh:style id="0" type="PARA" name="\uBC14\uD0D5\uAE00" engName="Normal" paraPrIDRef="0" charPrIDRef="0" nextStyleIDRef="0" langIDRef="1042" lockForm="0"/>
21523
- </hh:styles>
21524
- </hh:refList>
21525
- <hh:compatibleDocument targetProgram="HWP2018"><hh:layoutCompatibility/></hh:compatibleDocument>
21526
- </hh:head>`;
21514
+ function extractTopLevelTables(html) {
21515
+ const result = [];
21516
+ let depth = 0;
21517
+ let start = -1;
21518
+ const re = /<(\/?)table(?:[\s>]|>)/gi;
21519
+ let m;
21520
+ while ((m = re.exec(html)) !== null) {
21521
+ if (m[1] !== "/") {
21522
+ if (depth === 0) start = m.index;
21523
+ depth++;
21524
+ } else {
21525
+ depth--;
21526
+ if (depth === 0 && start >= 0) {
21527
+ result.push(html.slice(start, m.index + m[0].length));
21528
+ start = -1;
21529
+ }
21530
+ if (depth < 0) depth = 0;
21531
+ }
21532
+ }
21533
+ return result;
21527
21534
  }
21528
- function generateSecPr(gongmun) {
21529
- const m = gongmun ? {
21530
- top: mmToHwpunit(gongmun.margins.top),
21531
- bottom: mmToHwpunit(gongmun.margins.bottom),
21532
- left: mmToHwpunit(gongmun.margins.left),
21533
- right: mmToHwpunit(gongmun.margins.right),
21534
- header: 0,
21535
- footer: 0
21536
- } : { top: 8504, bottom: 4252, left: 5670, right: 4252, header: 2835, footer: 2835 };
21537
- return `<hp:secPr textDirection="HORIZONTAL" spaceColumns="1134" tabStop="8000" outlineShapeIDRef="0" memoShapeIDRef="0" textVerticalWidthHead="0" masterPageCnt="0"><hp:grid lineGrid="0" charGrid="0" wonggojiFormat="0"/><hp:startNum pageStartsOn="BOTH" page="0" pic="0" tbl="0" equation="0"/><hp:visibility hideFirstHeader="0" hideFirstFooter="0" hideFirstMasterPage="0" border="SHOW_ALL" fill="SHOW_ALL" hideFirstPageNum="0" hideFirstEmptyLine="0" showLineNumber="0"/><hp:pagePr landscape="WIDELY" width="59528" height="84188" gutterType="LEFT_ONLY"><hp:margin header="${m.header}" footer="${m.footer}" gutter="0" left="${m.left}" right="${m.right}" top="${m.top}" bottom="${m.bottom}"/></hp:pagePr><hp:footNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="-1" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="283" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="EACH_COLUMN" beneathText="0"/></hp:footNotePr><hp:endNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="14692344" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="0" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="END_OF_DOCUMENT" beneathText="0"/></hp:endNotePr></hp:secPr>`;
21535
+ function removeNestedTables(html) {
21536
+ let result = "";
21537
+ let depth = 0;
21538
+ const re = /<(\/?)table(?:[\s>]|>)/gi;
21539
+ let last = 0;
21540
+ let m;
21541
+ while ((m = re.exec(html)) !== null) {
21542
+ if (m[1] !== "/") {
21543
+ if (depth === 0) result += html.slice(last, m.index);
21544
+ depth++;
21545
+ } else {
21546
+ depth--;
21547
+ if (depth === 0) last = m.index + m[0].length;
21548
+ if (depth < 0) depth = 0;
21549
+ }
21550
+ }
21551
+ if (depth === 0) result += html.slice(last);
21552
+ return result;
21538
21553
  }
21554
+
21555
+ // src/hwpx/gen-table.ts
21539
21556
  var TABLE_ID_BASE = 1e3;
21540
21557
  var tableIdCounter = TABLE_ID_BASE;
21541
21558
  function nextTableId() {
@@ -21625,41 +21642,18 @@ function generateHtmlTableXml(rawHtml, theme, totalWidth = 44e3) {
21625
21642
  }
21626
21643
  return `<hp:tbl id="${tblId}" zOrder="0" numberingType="TABLE" pageBreak="CELL" repeatHeader="0" rowCnt="${rowCnt}" colCnt="${colCnt}" cellSpacing="0" borderFillIDRef="2" noShading="0"><hp:sz width="${tblW}" widthRelTo="ABSOLUTE" height="${cellH * rowCnt}" 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"/>` + trXmls.join("") + `</hp:tbl>`;
21627
21644
  }
21628
- function precomputeGongmunList(blocks, gongmun) {
21629
- const result = /* @__PURE__ */ new Map();
21630
- let i = 0;
21631
- while (i < blocks.length) {
21632
- if (blocks[i].type !== "list_item") {
21633
- i++;
21634
- continue;
21635
- }
21636
- const run = [];
21637
- while (i < blocks.length) {
21638
- const t = blocks[i].type;
21639
- if (t === "list_item") {
21640
- run.push(i);
21641
- i++;
21642
- continue;
21643
- }
21644
- if (t === "table" || t === "html_table") {
21645
- let j = i + 1;
21646
- while (j < blocks.length && (blocks[j].type === "table" || blocks[j].type === "html_table")) j++;
21647
- if (j < blocks.length && blocks[j].type === "list_item") {
21648
- i = j;
21649
- continue;
21650
- }
21651
- }
21652
- break;
21653
- }
21654
- const depths = run.map((bi) => Math.min(Math.max(blocks[bi].indent || 0, 0), GONGMUN_LIST_LEVELS - 1));
21655
- const suppress = gongmun.numbering === "standard" ? computeSuppression(depths) : depths.map(() => false);
21656
- const numberer = new GongmunNumberer(gongmun.numbering);
21657
- run.forEach((bi, k) => {
21658
- const marker = numberer.next(depths[k], suppress[k]);
21659
- result.set(bi, { marker, depth: depths[k] });
21660
- });
21661
- }
21662
- return result;
21645
+
21646
+ // src/hwpx/gen-section.ts
21647
+ function generateSecPr(gongmun) {
21648
+ const m = gongmun ? {
21649
+ top: mmToHwpunit(gongmun.margins.top),
21650
+ bottom: mmToHwpunit(gongmun.margins.bottom),
21651
+ left: mmToHwpunit(gongmun.margins.left),
21652
+ right: mmToHwpunit(gongmun.margins.right),
21653
+ header: 0,
21654
+ footer: 0
21655
+ } : { top: 8504, bottom: 4252, left: 5670, right: 4252, header: 2835, footer: 2835 };
21656
+ return `<hp:secPr textDirection="HORIZONTAL" spaceColumns="1134" tabStop="8000" outlineShapeIDRef="0" memoShapeIDRef="0" textVerticalWidthHead="0" masterPageCnt="0"><hp:grid lineGrid="0" charGrid="0" wonggojiFormat="0"/><hp:startNum pageStartsOn="BOTH" page="0" pic="0" tbl="0" equation="0"/><hp:visibility hideFirstHeader="0" hideFirstFooter="0" hideFirstMasterPage="0" border="SHOW_ALL" fill="SHOW_ALL" hideFirstPageNum="0" hideFirstEmptyLine="0" showLineNumber="0"/><hp:pagePr landscape="WIDELY" width="59528" height="84188" gutterType="LEFT_ONLY"><hp:margin header="${m.header}" footer="${m.footer}" gutter="0" left="${m.left}" right="${m.right}" top="${m.top}" bottom="${m.bottom}"/></hp:pagePr><hp:footNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="-1" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="283" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="EACH_COLUMN" beneathText="0"/></hp:footNotePr><hp:endNotePr><hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/><hp:noteLine length="14692344" type="SOLID" width="0.12 mm" color="#000000"/><hp:noteSpacing betweenNotes="0" belowLine="567" aboveLine="850"/><hp:numbering type="CONTINUOUS" newNum="1"/><hp:placement place="END_OF_DOCUMENT" beneathText="0"/></hp:endNotePr></hp:secPr>`;
21663
21657
  }
21664
21658
  function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? precomputeGongmunList(blocks, gongmun) : null, fit = null) {
21665
21659
  const paraXmls = [];
@@ -21706,8 +21700,8 @@ function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? prec
21706
21700
  case "list_item": {
21707
21701
  if (gongmun && gongmunList) {
21708
21702
  const info = gongmunList.get(blockIdx);
21709
- const depth = _nullishCoalesce(_optionalChain([info, 'optionalAccess', _194 => _194.depth]), () => ( 0));
21710
- const marker2 = _nullishCoalesce(_optionalChain([info, 'optionalAccess', _195 => _195.marker]), () => ( ""));
21703
+ const depth = _nullishCoalesce(_optionalChain([info, 'optionalAccess', _191 => _191.depth]), () => ( 0));
21704
+ const marker2 = _nullishCoalesce(_optionalChain([info, 'optionalAccess', _192 => _192.marker]), () => ( ""));
21711
21705
  const content = block.text || "";
21712
21706
  const text = marker2 ? `${marker2} ${content}` : content;
21713
21707
  const listCharPr = gongmun.numbering === "report" && depth === 0 ? CHAR_BOLD : CHAR_NORMAL;
@@ -21782,6 +21776,24 @@ function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? prec
21782
21776
  </hs:sec>`;
21783
21777
  }
21784
21778
 
21779
+ // src/hwpx/generator.ts
21780
+ async function markdownToHwpx(markdown, options) {
21781
+ const theme = resolveTheme(_optionalChain([options, 'optionalAccess', _193 => _193.theme]));
21782
+ const gongmun = _optionalChain([options, 'optionalAccess', _194 => _194.gongmun]) ? resolveGongmun(options.gongmun) : null;
21783
+ const blocks = parseMarkdownToBlocks(markdown);
21784
+ const gongmunList = gongmun ? precomputeGongmunList(blocks, gongmun) : null;
21785
+ const fit = gongmun && gongmunList ? computeGongmunFitPlan(blocks, gongmun, gongmunList) : null;
21786
+ const sectionXml = blocksToSectionXml(blocks, theme, gongmun, gongmunList, fit);
21787
+ const zip = new (0, _jszip2.default)();
21788
+ zip.file("mimetype", "application/hwp+zip", { compression: "STORE" });
21789
+ zip.file("META-INF/container.xml", generateContainerXml());
21790
+ zip.file("Contents/content.hpf", generateManifest());
21791
+ zip.file("Contents/header.xml", generateHeaderXml(theme, gongmun, _nullishCoalesce(_optionalChain([fit, 'optionalAccess', _195 => _195.variants]), () => ( []))));
21792
+ zip.file("Contents/section0.xml", sectionXml);
21793
+ zip.file("Preview/PrvText.txt", buildPrvText(blocks));
21794
+ return await zip.generateAsync({ type: "arraybuffer" });
21795
+ }
21796
+
21785
21797
  // src/diff/compare.ts
21786
21798
  var SIMILARITY_THRESHOLD = 0.4;
21787
21799
  async function compare(bufferA, bufferB, options) {
@@ -22520,7 +22532,7 @@ async function resolveSectionEntryNames(zip) {
22520
22532
  const paths = sectionPathsFromManifest(xml).filter((p) => zip.file(p) !== null);
22521
22533
  if (paths.length > 0) return paths;
22522
22534
  }
22523
- return Object.keys(zip.files).filter((n) => /[Ss]ection\d+\.xml$/.test(n)).sort(_chunkLFCS3UVGcjs.compareSectionPaths);
22535
+ return Object.keys(zip.files).filter((n) => /[Ss]ection\d+\.xml$/.test(n)).sort(_chunkYBPNKFJWcjs.compareSectionPaths);
22524
22536
  }
22525
22537
  function sectionPathsFromManifest(xml) {
22526
22538
  const attr = (tag, name) => {
@@ -22530,7 +22542,7 @@ function sectionPathsFromManifest(xml) {
22530
22542
  const idToHref = /* @__PURE__ */ new Map();
22531
22543
  for (const m of xml.matchAll(/<opf:item(\s(?:"[^"]*"|'[^']*'|[^>"'])*?)\/?>/g)) {
22532
22544
  const id = attr(m[1], "id");
22533
- const href = _chunkLFCS3UVGcjs.normalizeSectionHref.call(void 0, attr(m[1], "href"));
22545
+ const href = _chunkYBPNKFJWcjs.normalizeSectionHref.call(void 0, attr(m[1], "href"));
22534
22546
  if (id && href) idToHref.set(id, href);
22535
22547
  }
22536
22548
  const ordered = [];
@@ -22539,7 +22551,7 @@ function sectionPathsFromManifest(xml) {
22539
22551
  if (href) ordered.push(href);
22540
22552
  }
22541
22553
  if (ordered.length > 0) return ordered;
22542
- return Array.from(idToHref.values()).sort(_chunkLFCS3UVGcjs.compareSectionPaths);
22554
+ return Array.from(idToHref.values()).sort(_chunkYBPNKFJWcjs.compareSectionPaths);
22543
22555
  }
22544
22556
 
22545
22557
  // src/roundtrip/patcher.ts
@@ -22650,9 +22662,9 @@ function buildOrigUnits(blocks) {
22650
22662
  if (block.type === "paragraph" && block.text && /^\[별표\s*\d+/.test(sanitizeText(block.text))) {
22651
22663
  const next = blocks[i + 1];
22652
22664
  if (_optionalChain([next, 'optionalAccess', _220 => _220.type]) === "paragraph" && next.text && /관련\)?$/.test(next.text)) consume = 2;
22653
- chunk = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, blocks.slice(i, i + consume));
22665
+ chunk = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, blocks.slice(i, i + consume));
22654
22666
  } else {
22655
- chunk = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, [block]);
22667
+ chunk = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, [block]);
22656
22668
  }
22657
22669
  if (chunk) {
22658
22670
  const subUnits = splitMarkdownUnits(chunk);
@@ -24350,13 +24362,13 @@ async function htmlToPdf(html, options) {
24350
24362
  try {
24351
24363
  puppeteer = await Promise.resolve().then(() => _interopRequireWildcard(require("puppeteer-core")));
24352
24364
  } catch (e30) {
24353
- throw new (0, _chunkLFCS3UVGcjs.KordocError)(
24365
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)(
24354
24366
  "PDF \uC0DD\uC131\uC5D0 puppeteer-core\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. \uC124\uCE58: npm install puppeteer-core"
24355
24367
  );
24356
24368
  }
24357
24369
  const executablePath = _nullishCoalesce(process.env.PUPPETEER_EXECUTABLE_PATH, () => ( findChromiumPath()));
24358
24370
  if (!executablePath) {
24359
- throw new (0, _chunkLFCS3UVGcjs.KordocError)(
24371
+ throw new (0, _chunkYBPNKFJWcjs.KordocError)(
24360
24372
  "Chromium \uC2E4\uD589 \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4. PUPPETEER_EXECUTABLE_PATH \uD658\uACBD\uBCC0\uC218\uB97C \uC124\uC815\uD558\uC138\uC694."
24361
24373
  );
24362
24374
  }
@@ -24415,7 +24427,7 @@ async function markdownToPdf(markdown, options) {
24415
24427
  return htmlToPdf(html, options);
24416
24428
  }
24417
24429
  async function blocksToPdf(blocks, options) {
24418
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, blocks);
24430
+ const markdown = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, blocks);
24419
24431
  return markdownToPdf(markdown, options);
24420
24432
  }
24421
24433
 
@@ -24426,13 +24438,13 @@ async function parse(input, options) {
24426
24438
  if (typeof input === "string") {
24427
24439
  try {
24428
24440
  const buf = await _promises.readFile.call(void 0, input);
24429
- buffer = _chunkLFCS3UVGcjs.toArrayBuffer.call(void 0, buf);
24441
+ buffer = _chunkYBPNKFJWcjs.toArrayBuffer.call(void 0, buf);
24430
24442
  } catch (err) {
24431
24443
  const msg2 = err instanceof Error && "code" in err && err.code === "ENOENT" ? `\uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${input}` : `\uD30C\uC77C \uC77D\uAE30 \uC2E4\uD328: ${input}`;
24432
24444
  return { success: false, fileType: "unknown", error: msg2, code: "PARSE_ERROR" };
24433
24445
  }
24434
24446
  } else if (Buffer.isBuffer(input)) {
24435
- buffer = _chunkLFCS3UVGcjs.toArrayBuffer.call(void 0, input);
24447
+ buffer = _chunkYBPNKFJWcjs.toArrayBuffer.call(void 0, input);
24436
24448
  } else {
24437
24449
  buffer = input;
24438
24450
  }
@@ -24467,7 +24479,7 @@ async function parseHwp3(buffer, options) {
24467
24479
  const { markdown, blocks, metadata, outline, warnings } = parseHwp3Document(buffer, options);
24468
24480
  return { success: true, fileType: "hwp3", markdown, blocks, metadata, outline, warnings };
24469
24481
  } catch (err) {
24470
- return { success: false, fileType: "hwp3", error: err instanceof Error ? err.message : "HWP3 \uD30C\uC2F1 \uC2E4\uD328", code: _chunkLFCS3UVGcjs.classifyError.call(void 0, err) };
24482
+ return { success: false, fileType: "hwp3", error: err instanceof Error ? err.message : "HWP3 \uD30C\uC2F1 \uC2E4\uD328", code: _chunkYBPNKFJWcjs.classifyError.call(void 0, err) };
24471
24483
  }
24472
24484
  }
24473
24485
  async function parseHwpx(buffer, options) {
@@ -24475,7 +24487,7 @@ async function parseHwpx(buffer, options) {
24475
24487
  const { markdown, blocks, metadata, outline, warnings, images } = await parseHwpxDocument(buffer, options);
24476
24488
  return { success: true, fileType: "hwpx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _280 => _280.length]) ? images : void 0 };
24477
24489
  } catch (err) {
24478
- return { success: false, fileType: "hwpx", error: err instanceof Error ? err.message : "HWPX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkLFCS3UVGcjs.classifyError.call(void 0, err) };
24490
+ return { success: false, fileType: "hwpx", error: err instanceof Error ? err.message : "HWPX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkYBPNKFJWcjs.classifyError.call(void 0, err) };
24479
24491
  }
24480
24492
  }
24481
24493
  async function parseHwp(buffer, options) {
@@ -24500,13 +24512,13 @@ async function parseHwp(buffer, options) {
24500
24512
  }
24501
24513
  return { success: true, fileType: "hwp", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _282 => _282.length]) ? images : void 0 };
24502
24514
  } catch (err) {
24503
- return { success: false, fileType: "hwp", error: err instanceof Error ? err.message : "HWP \uD30C\uC2F1 \uC2E4\uD328", code: _chunkLFCS3UVGcjs.classifyError.call(void 0, err) };
24515
+ return { success: false, fileType: "hwp", error: err instanceof Error ? err.message : "HWP \uD30C\uC2F1 \uC2E4\uD328", code: _chunkYBPNKFJWcjs.classifyError.call(void 0, err) };
24504
24516
  }
24505
24517
  }
24506
24518
  async function parsePdf(buffer, options) {
24507
24519
  let parsePdfDocument;
24508
24520
  try {
24509
- const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./parser-IXK5V7YG.cjs")));
24521
+ const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./parser-NS4ZPD7B.cjs")));
24510
24522
  parsePdfDocument = mod.parsePdfDocument;
24511
24523
  } catch (e32) {
24512
24524
  return {
@@ -24521,7 +24533,7 @@ async function parsePdf(buffer, options) {
24521
24533
  return { success: true, fileType: "pdf", markdown, blocks, metadata, outline, warnings, isImageBased, pageQuality, qualitySummary };
24522
24534
  } catch (err) {
24523
24535
  const isImageBased = err instanceof Error && "isImageBased" in err ? true : void 0;
24524
- return { success: false, fileType: "pdf", error: err instanceof Error ? err.message : "PDF \uD30C\uC2F1 \uC2E4\uD328", code: _chunkLFCS3UVGcjs.classifyError.call(void 0, err), isImageBased };
24536
+ return { success: false, fileType: "pdf", error: err instanceof Error ? err.message : "PDF \uD30C\uC2F1 \uC2E4\uD328", code: _chunkYBPNKFJWcjs.classifyError.call(void 0, err), isImageBased };
24525
24537
  }
24526
24538
  }
24527
24539
  async function parseXlsx(buffer, options) {
@@ -24529,7 +24541,7 @@ async function parseXlsx(buffer, options) {
24529
24541
  const { markdown, blocks, metadata, warnings } = await parseXlsxDocument(buffer, options);
24530
24542
  return { success: true, fileType: "xlsx", markdown, blocks, metadata, warnings };
24531
24543
  } catch (err) {
24532
- return { success: false, fileType: "xlsx", error: err instanceof Error ? err.message : "XLSX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkLFCS3UVGcjs.classifyError.call(void 0, err) };
24544
+ return { success: false, fileType: "xlsx", error: err instanceof Error ? err.message : "XLSX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkYBPNKFJWcjs.classifyError.call(void 0, err) };
24533
24545
  }
24534
24546
  }
24535
24547
  async function parseXls(buffer, options) {
@@ -24537,7 +24549,7 @@ async function parseXls(buffer, options) {
24537
24549
  const { markdown, blocks, metadata, warnings } = await parseXlsDocument(buffer, options);
24538
24550
  return { success: true, fileType: "xls", markdown, blocks, metadata, warnings };
24539
24551
  } catch (err) {
24540
- return { success: false, fileType: "xls", error: err instanceof Error ? err.message : "XLS \uD30C\uC2F1 \uC2E4\uD328", code: _chunkLFCS3UVGcjs.classifyError.call(void 0, err) };
24552
+ return { success: false, fileType: "xls", error: err instanceof Error ? err.message : "XLS \uD30C\uC2F1 \uC2E4\uD328", code: _chunkYBPNKFJWcjs.classifyError.call(void 0, err) };
24541
24553
  }
24542
24554
  }
24543
24555
  async function parseDocx(buffer, options) {
@@ -24545,7 +24557,7 @@ async function parseDocx(buffer, options) {
24545
24557
  const { markdown, blocks, metadata, outline, warnings, images } = await parseDocxDocument(buffer, options);
24546
24558
  return { success: true, fileType: "docx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _283 => _283.length]) ? images : void 0 };
24547
24559
  } catch (err) {
24548
- return { success: false, fileType: "docx", error: err instanceof Error ? err.message : "DOCX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkLFCS3UVGcjs.classifyError.call(void 0, err) };
24560
+ return { success: false, fileType: "docx", error: err instanceof Error ? err.message : "DOCX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkYBPNKFJWcjs.classifyError.call(void 0, err) };
24549
24561
  }
24550
24562
  }
24551
24563
  async function parseHwpml(buffer, options) {
@@ -24553,16 +24565,16 @@ async function parseHwpml(buffer, options) {
24553
24565
  const { markdown, blocks, metadata, outline, warnings } = parseHwpmlDocument(buffer, options);
24554
24566
  return { success: true, fileType: "hwpml", markdown, blocks, metadata, outline, warnings };
24555
24567
  } catch (err) {
24556
- return { success: false, fileType: "hwpml", error: err instanceof Error ? err.message : "HWPML \uD30C\uC2F1 \uC2E4\uD328", code: _chunkLFCS3UVGcjs.classifyError.call(void 0, err) };
24568
+ return { success: false, fileType: "hwpml", error: err instanceof Error ? err.message : "HWPML \uD30C\uC2F1 \uC2E4\uD328", code: _chunkYBPNKFJWcjs.classifyError.call(void 0, err) };
24557
24569
  }
24558
24570
  }
24559
24571
  async function fillForm(input, values, outputFormat = "markdown") {
24560
24572
  let buffer;
24561
24573
  if (typeof input === "string") {
24562
24574
  const buf = await _promises.readFile.call(void 0, input);
24563
- buffer = _chunkLFCS3UVGcjs.toArrayBuffer.call(void 0, buf);
24575
+ buffer = _chunkYBPNKFJWcjs.toArrayBuffer.call(void 0, buf);
24564
24576
  } else if (Buffer.isBuffer(input)) {
24565
- buffer = _chunkLFCS3UVGcjs.toArrayBuffer.call(void 0, input);
24577
+ buffer = _chunkYBPNKFJWcjs.toArrayBuffer.call(void 0, input);
24566
24578
  } else {
24567
24579
  buffer = input;
24568
24580
  }
@@ -24588,7 +24600,7 @@ async function fillForm(input, values, outputFormat = "markdown") {
24588
24600
  throw new Error(`\uC11C\uC2DD \uD30C\uC2F1 \uC2E4\uD328: ${parsed.error}`);
24589
24601
  }
24590
24602
  const fill = fillFormFields(parsed.blocks, values);
24591
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, fill.blocks);
24603
+ const markdown = _chunkYBPNKFJWcjs.blocksToMarkdown.call(void 0, fill.blocks);
24592
24604
  if (outputFormat === "hwpx") {
24593
24605
  const hwpxBuffer = await markdownToHwpx(markdown);
24594
24606
  return { output: hwpxBuffer, format: "hwpx", fill };
@@ -24646,5 +24658,5 @@ async function fillForm(input, values, outputFormat = "markdown") {
24646
24658
 
24647
24659
 
24648
24660
 
24649
- exports.HwpxSession = HwpxSession; exports.PRESET_ALIAS = PRESET_ALIAS; exports.SPACE_EM_FIXED = SPACE_EM_FIXED; exports.SPACE_EM_FONT = SPACE_EM_FONT; exports.VERSION = _chunkLFCS3UVGcjs.VERSION; exports.ValueCursor = ValueCursor; exports.applySplices = applySplices; exports.blocksToMarkdown = _chunkLFCS3UVGcjs.blocksToMarkdown; exports.blocksToPdf = blocksToPdf; exports.buildParagraphSplices = buildParagraphSplices; exports.buildRangeSplices = buildRangeSplices; exports.charWidthEm1000 = charWidthEm1000; exports.compare = compare; exports.detectFormat = detectFormat; exports.detectOle2Format = detectOle2Format; exports.detectZipFormat = detectZipFormat; exports.diffBlocks = diffBlocks; exports.extractFormFields = extractFormFields; exports.extractFormSchema = extractFormSchema; exports.fillForm = fillForm; exports.fillFormFields = fillFormFields; exports.fillHwpx = fillHwpx; exports.fitRatioForFewerLines = fitRatioForFewerLines; exports.inferFieldType = inferFieldType; exports.isHwpxFile = isHwpxFile; exports.isLabelCell = isLabelCell; exports.isOldHwpFile = isOldHwpFile; exports.isPdfFile = isPdfFile; exports.isZipFile = isZipFile; exports.markdownToHwpx = markdownToHwpx; exports.markdownToPdf = markdownToPdf; exports.measureTextWidth = measureTextWidth; exports.normalizeGongmunPreset = normalizeGongmunPreset; exports.openHwpxDocument = openHwpxDocument; exports.parse = parse; exports.parseDocx = parseDocx; exports.parseHwp = parseHwp; exports.parseHwp3 = parseHwp3; exports.parseHwpml = parseHwpml; exports.parseHwpx = parseHwpx; exports.parsePdf = parsePdf; exports.parseXls = parseXls; exports.parseXlsx = parseXlsx; exports.patchHwp = patchHwp; exports.patchHwpx = patchHwpx; exports.patchHwpxBlocks = patchHwpxBlocks; exports.renderHtml = renderHtml; exports.scanSectionXml = scanSectionXml; exports.simulateWrap = simulateWrap; exports.simulateWrapKeepWord = simulateWrapKeepWord;
24661
+ exports.HwpxSession = HwpxSession; exports.PRESET_ALIAS = PRESET_ALIAS; exports.SPACE_EM_FIXED = SPACE_EM_FIXED; exports.SPACE_EM_FONT = SPACE_EM_FONT; exports.VERSION = _chunkYBPNKFJWcjs.VERSION; exports.ValueCursor = ValueCursor; exports.applySplices = applySplices; exports.blocksToMarkdown = _chunkYBPNKFJWcjs.blocksToMarkdown; exports.blocksToPdf = blocksToPdf; exports.buildParagraphSplices = buildParagraphSplices; exports.buildRangeSplices = buildRangeSplices; exports.charWidthEm1000 = charWidthEm1000; exports.compare = compare; exports.detectFormat = detectFormat; exports.detectOle2Format = detectOle2Format; exports.detectZipFormat = detectZipFormat; exports.diffBlocks = diffBlocks; exports.extractFormFields = extractFormFields; exports.extractFormSchema = extractFormSchema; exports.fillForm = fillForm; exports.fillFormFields = fillFormFields; exports.fillHwpx = fillHwpx; exports.fitRatioForFewerLines = fitRatioForFewerLines; exports.inferFieldType = inferFieldType; exports.isHwpxFile = isHwpxFile; exports.isLabelCell = isLabelCell; exports.isOldHwpFile = isOldHwpFile; exports.isPdfFile = isPdfFile; exports.isZipFile = isZipFile; exports.markdownToHwpx = markdownToHwpx; exports.markdownToPdf = markdownToPdf; exports.measureTextWidth = measureTextWidth; exports.normalizeGongmunPreset = normalizeGongmunPreset; exports.openHwpxDocument = openHwpxDocument; exports.parse = parse; exports.parseDocx = parseDocx; exports.parseHwp = parseHwp; exports.parseHwp3 = parseHwp3; exports.parseHwpml = parseHwpml; exports.parseHwpx = parseHwpx; exports.parsePdf = parsePdf; exports.parseXls = parseXls; exports.parseXlsx = parseXlsx; exports.patchHwp = patchHwp; exports.patchHwpx = patchHwpx; exports.patchHwpxBlocks = patchHwpxBlocks; exports.renderHtml = renderHtml; exports.scanSectionXml = scanSectionXml; exports.simulateWrap = simulateWrap; exports.simulateWrapKeepWord = simulateWrapKeepWord;
24650
24662
  //# sourceMappingURL=index.cjs.map