kordoc 3.8.1 → 3.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +12 -0
  2. package/dist/{-LD4BZDDJ.js → -F5IXBLQQ.js} +3 -3
  3. package/dist/{chunk-PELBIL4K.js → chunk-7J73IGMK.js} +2 -2
  4. package/dist/{chunk-KT2BCHXI.js → chunk-B27QMVL7.js} +872 -825
  5. package/dist/chunk-B27QMVL7.js.map +1 -0
  6. package/dist/{chunk-IFYJFWD2.js → chunk-KIWKBRCJ.js} +2 -2
  7. package/dist/{chunk-LFCS3UVG.cjs → chunk-XL6O3VAY.cjs} +2 -2
  8. package/dist/{chunk-LFCS3UVG.cjs.map → chunk-XL6O3VAY.cjs.map} +1 -1
  9. package/dist/cli.js +4 -4
  10. package/dist/index.cjs +1065 -1018
  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 +871 -824
  15. package/dist/index.js.map +1 -1
  16. package/dist/mcp.js +3 -3
  17. package/dist/{parser-FFEBMLSH.js → parser-6GP535ZB.js} +211 -25
  18. package/dist/parser-6GP535ZB.js.map +1 -0
  19. package/dist/{parser-XEDROIM7.js → parser-TM3AS25T.js} +211 -25
  20. package/dist/parser-TM3AS25T.js.map +1 -0
  21. package/dist/{parser-IXK5V7YG.cjs → parser-WWKYMRGJ.cjs} +240 -52
  22. package/dist/parser-WWKYMRGJ.cjs.map +1 -0
  23. package/dist/{watch-MAWCDNFI.js → watch-HETTZ7BO.js} +3 -3
  24. package/package.json +2 -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 → -F5IXBLQQ.js.map} +0 -0
  30. /package/dist/{chunk-PELBIL4K.js.map → chunk-7J73IGMK.js.map} +0 -0
  31. /package/dist/{chunk-IFYJFWD2.js.map → chunk-KIWKBRCJ.js.map} +0 -0
  32. /package/dist/{watch-MAWCDNFI.js.map → watch-HETTZ7BO.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 _chunkXL6O3VAYcjs = require('./chunk-XL6O3VAY.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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(_chunkXL6O3VAYcjs.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 >= _chunkXL6O3VAYcjs.HEADING_RATIO_H1) level = 1;
619
+ else if (ratio >= _chunkXL6O3VAYcjs.HEADING_RATIO_H2) level = 2;
620
+ else if (ratio >= _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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(_chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.MAX_COLS);
1342
+ tableCtx.cell.rowSpan = clampSpan(rs, _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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 (_chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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 _chunkXL6O3VAYcjs.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 (_chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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(_chunkXL6O3VAYcjs.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(_chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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(_chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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(_chunkXL6O3VAYcjs.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
+ _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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 _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.KordocError)("HWP \uC2DC\uADF8\uB2C8\uCC98 \uBD88\uC77C\uCE58");
3745
+ if (header.flags & FLAG_ENCRYPTED) throw new (0, _chunkXL6O3VAYcjs.KordocError)("\uC554\uD638\uD654\uB41C HWP\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
3746
+ if (header.flags & FLAG_DRM) throw new (0, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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 _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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 >= _chunkXL6O3VAYcjs.HEADING_RATIO_H1) level = 1;
3848
+ else if (ratio >= _chunkXL6O3VAYcjs.HEADING_RATIO_H2) level = 2;
3849
+ else if (ratio >= _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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), _chunkXL6O3VAYcjs.MAX_ROWS);
4300
+ cols = Math.min(records[i2].data.readUInt16LE(6), _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.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, _chunkXL6O3VAYcjs.MAX_COLS);
4367
+ if (rs > 0) rowSpan = Math.min(rs, _chunkXL6O3VAYcjs.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 = _chunkXL6O3VAYcjs.convertTableToText.call(void 0, b.table.cells);
4378
4378
  if (flat) parts.push(flat);
4379
4379
  hasStructure = true;
4380
4380
  } else if (b.text) {
@@ -16802,13 +16802,16 @@ function getElements(parent, tagName) {
16802
16802
  const nodes = parent.getElementsByTagName(tagName);
16803
16803
  const result = [];
16804
16804
  for (let i = 0; i < nodes.length; i++) result.push(nodes[i]);
16805
+ if (result.length > 0) return result;
16806
+ const nsNodes = _optionalChain([parent, 'access', _82 => _82.getElementsByTagNameNS, 'optionalCall', _83 => _83("*", tagName)]);
16807
+ if (nsNodes) for (let i = 0; i < nsNodes.length; i++) result.push(nsNodes[i]);
16805
16808
  return result;
16806
16809
  }
16807
16810
  function getTextContent(el) {
16808
- return _nullishCoalesce(_optionalChain([el, 'access', _82 => _82.textContent, 'optionalAccess', _83 => _83.trim, 'call', _84 => _84()]), () => ( ""));
16811
+ return _nullishCoalesce(_optionalChain([el, 'access', _84 => _84.textContent, 'optionalAccess', _85 => _85.trim, 'call', _86 => _86()]), () => ( ""));
16809
16812
  }
16810
16813
  function parseXml(text) {
16811
- return new (0, _xmldom.DOMParser)().parseFromString(_chunkLFCS3UVGcjs.stripDtd.call(void 0, text), "text/xml");
16814
+ return new (0, _xmldom.DOMParser)().parseFromString(_chunkXL6O3VAYcjs.stripDtd.call(void 0, text), "text/xml");
16812
16815
  }
16813
16816
  function parseSharedStrings(xml) {
16814
16817
  const doc = parseXml(xml);
@@ -16945,14 +16948,14 @@ function sheetToBlocks(sheetName, grid, merges, maxRow, maxCol, sheetIndex) {
16945
16948
  const merge = mergeMap.get(key);
16946
16949
  row.push({
16947
16950
  text,
16948
- colSpan: _nullishCoalesce(_optionalChain([merge, 'optionalAccess', _85 => _85.colSpan]), () => ( 1)),
16949
- rowSpan: _nullishCoalesce(_optionalChain([merge, 'optionalAccess', _86 => _86.rowSpan]), () => ( 1))
16951
+ colSpan: _nullishCoalesce(_optionalChain([merge, 'optionalAccess', _87 => _87.colSpan]), () => ( 1)),
16952
+ rowSpan: _nullishCoalesce(_optionalChain([merge, 'optionalAccess', _88 => _88.rowSpan]), () => ( 1))
16950
16953
  });
16951
16954
  }
16952
16955
  cellRows.push(row);
16953
16956
  }
16954
16957
  if (cellRows.length > 0) {
16955
- const table = _chunkLFCS3UVGcjs.buildTable.call(void 0, cellRows);
16958
+ const table = _chunkXL6O3VAYcjs.buildTable.call(void 0, cellRows);
16956
16959
  if (table.rows > 0) {
16957
16960
  blocks.push({ type: "table", table, pageNumber: sheetIndex + 1 });
16958
16961
  }
@@ -16960,12 +16963,12 @@ function sheetToBlocks(sheetName, grid, merges, maxRow, maxCol, sheetIndex) {
16960
16963
  return blocks;
16961
16964
  }
16962
16965
  async function parseXlsxDocument(buffer, options) {
16963
- _chunkLFCS3UVGcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE3);
16966
+ _chunkXL6O3VAYcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE3);
16964
16967
  const zip = await _jszip2.default.loadAsync(buffer);
16965
16968
  const warnings = [];
16966
16969
  const workbookFile = zip.file("xl/workbook.xml");
16967
16970
  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");
16971
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 XLSX \uD30C\uC77C: xl/workbook.xml\uC774 \uC5C6\uC2B5\uB2C8\uB2E4");
16969
16972
  }
16970
16973
  let sharedStrings = [];
16971
16974
  const ssFile = zip.file("xl/sharedStrings.xml");
@@ -16974,7 +16977,7 @@ async function parseXlsxDocument(buffer, options) {
16974
16977
  }
16975
16978
  const sheets = parseWorkbook(await workbookFile.async("text"));
16976
16979
  if (sheets.length === 0) {
16977
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("XLSX \uD30C\uC77C\uC5D0 \uC2DC\uD2B8\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4");
16980
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("XLSX \uD30C\uC77C\uC5D0 \uC2DC\uD2B8\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4");
16978
16981
  }
16979
16982
  let relsMap = /* @__PURE__ */ new Map();
16980
16983
  const relsFile = zip.file("xl/_rels/workbook.xml.rels");
@@ -16982,7 +16985,7 @@ async function parseXlsxDocument(buffer, options) {
16982
16985
  relsMap = parseRels(await relsFile.async("text"));
16983
16986
  }
16984
16987
  let pageFilter = null;
16985
- if (_optionalChain([options, 'optionalAccess', _87 => _87.pages])) {
16988
+ if (_optionalChain([options, 'optionalAccess', _89 => _89.pages])) {
16986
16989
  const { parsePageRange: parsePageRange2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./page-range-P7SDW6LR.cjs")));
16987
16990
  pageFilter = parsePageRange2(options.pages, sheets.length);
16988
16991
  }
@@ -16991,7 +16994,7 @@ async function parseXlsxDocument(buffer, options) {
16991
16994
  for (let i = 0; i < processedSheets; i++) {
16992
16995
  if (pageFilter && !pageFilter.has(i + 1)) continue;
16993
16996
  const sheet = sheets[i];
16994
- _optionalChain([options, 'optionalAccess', _88 => _88.onProgress, 'optionalCall', _89 => _89(i + 1, processedSheets)]);
16997
+ _optionalChain([options, 'optionalAccess', _90 => _90.onProgress, 'optionalCall', _91 => _91(i + 1, processedSheets)]);
16995
16998
  let sheetPath = relsMap.get(sheet.rId);
16996
16999
  if (sheetPath) {
16997
17000
  if (!sheetPath.startsWith("xl/") && !sheetPath.startsWith("/")) {
@@ -17046,7 +17049,7 @@ async function parseXlsxDocument(buffer, options) {
17046
17049
  } catch (e27) {
17047
17050
  }
17048
17051
  }
17049
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, blocks);
17052
+ const markdown = _chunkXL6O3VAYcjs.blocksToMarkdown.call(void 0, blocks);
17050
17053
  return { markdown, blocks, metadata, warnings: warnings.length > 0 ? warnings : void 0 };
17051
17054
  }
17052
17055
 
@@ -17453,11 +17456,11 @@ function processGlobals(records) {
17453
17456
  let encrypted = false;
17454
17457
  const firstBof = records[0];
17455
17458
  if (!firstBof || firstBof.opcode !== OP_BOF) {
17456
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("XLS: \uCCAB \uB808\uCF54\uB4DC\uAC00 BOF\uAC00 \uC544\uB2D8");
17459
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("XLS: \uCCAB \uB808\uCF54\uB4DC\uAC00 BOF\uAC00 \uC544\uB2D8");
17457
17460
  }
17458
17461
  const bof = decodeBof(firstBof.data);
17459
17462
  if (!bof || bof.dt !== DT_GLOBALS) {
17460
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("XLS: Globals \uC11C\uBE0C\uC2A4\uD2B8\uB9BC BOF \uB204\uB77D");
17463
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("XLS: Globals \uC11C\uBE0C\uC2A4\uD2B8\uB9BC BOF \uB204\uB77D");
17461
17464
  }
17462
17465
  let i = 1;
17463
17466
  while (i < records.length) {
@@ -17565,14 +17568,14 @@ function sheetToBlocks2(sheetName, sheet, sheetIndex) {
17565
17568
  const merge = mergeMap.get(key);
17566
17569
  row.push({
17567
17570
  text: grid[r][c],
17568
- colSpan: _nullishCoalesce(_optionalChain([merge, 'optionalAccess', _90 => _90.colSpan]), () => ( 1)),
17569
- rowSpan: _nullishCoalesce(_optionalChain([merge, 'optionalAccess', _91 => _91.rowSpan]), () => ( 1))
17571
+ colSpan: _nullishCoalesce(_optionalChain([merge, 'optionalAccess', _92 => _92.colSpan]), () => ( 1)),
17572
+ rowSpan: _nullishCoalesce(_optionalChain([merge, 'optionalAccess', _93 => _93.rowSpan]), () => ( 1))
17570
17573
  });
17571
17574
  }
17572
17575
  cellRows.push(row);
17573
17576
  }
17574
17577
  if (cellRows.length > 0) {
17575
- const table = _chunkLFCS3UVGcjs.buildTable.call(void 0, cellRows);
17578
+ const table = _chunkXL6O3VAYcjs.buildTable.call(void 0, cellRows);
17576
17579
  if (table.rows > 0) {
17577
17580
  blocks.push({ type: "table", table, pageNumber: sheetIndex + 1 });
17578
17581
  }
@@ -17585,21 +17588,21 @@ async function parseXlsDocument(buffer, options) {
17585
17588
  try {
17586
17589
  cfb = parseLenientCfb(buf);
17587
17590
  } catch (e) {
17588
- throw new (0, _chunkLFCS3UVGcjs.KordocError)(
17591
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)(
17589
17592
  `XLS: OLE2 \uC2DC\uADF8\uB2C8\uCC98 \uAC80\uC99D \uC2E4\uD328 \u2014 ${e instanceof Error ? e.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"}`
17590
17593
  );
17591
17594
  }
17592
17595
  const wb = _nullishCoalesce(cfb.findStream("/Workbook"), () => ( cfb.findStream("/Book")));
17593
17596
  if (!wb) {
17594
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("XLS: Workbook \uC2A4\uD2B8\uB9BC\uC774 \uC5C6\uC74C (BIFF5 \uB610\uB294 \uBE44\uD45C\uC900 \uD30C\uC77C)");
17597
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("XLS: Workbook \uC2A4\uD2B8\uB9BC\uC774 \uC5C6\uC74C (BIFF5 \uB610\uB294 \uBE44\uD45C\uC900 \uD30C\uC77C)");
17595
17598
  }
17596
17599
  const records = readRecords2(wb);
17597
17600
  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)");
17601
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("XLS: \uC2DC\uADF8\uB2C8\uCC98 \uB808\uCF54\uB4DC\uAC00 \uC5C6\uC74C (Workbook \uC2A4\uD2B8\uB9BC \uC190\uC0C1)");
17599
17602
  }
17600
17603
  const firstBof = decodeBof(records[0].data);
17601
17604
  if (firstBof && firstBof.vers !== 1536) {
17602
- throw new (0, _chunkLFCS3UVGcjs.KordocError)(
17605
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)(
17603
17606
  `XLS: BIFF8(0x0600)\uB9CC \uC9C0\uC6D0 \u2014 \uBCF8 \uD30C\uC77C\uC740 0x${firstBof.vers.toString(16)}`
17604
17607
  );
17605
17608
  }
@@ -17620,7 +17623,7 @@ async function parseXlsDocument(buffer, options) {
17620
17623
  }
17621
17624
  const totalSheets = Math.min(globals.sheets.length, MAX_SHEETS2);
17622
17625
  let pageFilter = null;
17623
- if (_optionalChain([options, 'optionalAccess', _92 => _92.pages])) {
17626
+ if (_optionalChain([options, 'optionalAccess', _94 => _94.pages])) {
17624
17627
  const { parsePageRange: parsePageRange2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("./page-range-P7SDW6LR.cjs")));
17625
17628
  pageFilter = parsePageRange2(options.pages, totalSheets);
17626
17629
  }
@@ -17629,7 +17632,7 @@ async function parseXlsDocument(buffer, options) {
17629
17632
  if (pageFilter && !pageFilter.has(i + 1)) continue;
17630
17633
  const meta = globals.sheets[i];
17631
17634
  if (meta.dt !== 0) continue;
17632
- _optionalChain([options, 'optionalAccess', _93 => _93.onProgress, 'optionalCall', _94 => _94(i + 1, totalSheets)]);
17635
+ _optionalChain([options, 'optionalAccess', _95 => _95.onProgress, 'optionalCall', _96 => _96(i + 1, totalSheets)]);
17633
17636
  const bofIdx = findSheetBofIndex(records, meta.lbPlyPos);
17634
17637
  if (bofIdx < 0) {
17635
17638
  warnings.push({
@@ -17659,7 +17662,7 @@ async function parseXlsDocument(buffer, options) {
17659
17662
  pageCount: totalSheets
17660
17663
  };
17661
17664
  return {
17662
- markdown: _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, allBlocks),
17665
+ markdown: _chunkXL6O3VAYcjs.blocksToMarkdown.call(void 0, allBlocks),
17663
17666
  blocks: allBlocks,
17664
17667
  metadata,
17665
17668
  warnings: warnings.length > 0 ? warnings : void 0
@@ -17672,7 +17675,7 @@ async function parseXlsDocument(buffer, options) {
17672
17675
 
17673
17676
  // src/docx/equation.ts
17674
17677
  function lname(el) {
17675
- return el.localName || _optionalChain([el, 'access', _95 => _95.tagName, 'optionalAccess', _96 => _96.replace, 'call', _97 => _97(/^[^:]+:/, "")]) || "";
17678
+ return el.localName || _optionalChain([el, 'access', _97 => _97.tagName, 'optionalAccess', _98 => _98.replace, 'call', _99 => _99(/^[^:]+:/, "")]) || "";
17676
17679
  }
17677
17680
  function kids(parent, name) {
17678
17681
  const out = [];
@@ -18045,7 +18048,7 @@ function isDisplayMath(el) {
18045
18048
  // src/docx/parser.ts
18046
18049
  var MAX_DECOMPRESS_SIZE4 = 100 * 1024 * 1024;
18047
18050
  function matchesLocal(el, localName2) {
18048
- return el.localName === localName2 || (_nullishCoalesce(_optionalChain([el, 'access', _98 => _98.tagName, 'optionalAccess', _99 => _99.endsWith, 'call', _100 => _100(`:${localName2}`)]), () => ( false)));
18051
+ return el.localName === localName2 || (_nullishCoalesce(_optionalChain([el, 'access', _100 => _100.tagName, 'optionalAccess', _101 => _101.endsWith, 'call', _102 => _102(`:${localName2}`)]), () => ( false)));
18049
18052
  }
18050
18053
  function effectiveChildElements(parent) {
18051
18054
  const result = [];
@@ -18078,7 +18081,7 @@ function findElements(parent, localName2) {
18078
18081
  const child = children[i];
18079
18082
  if (child.nodeType === 1) {
18080
18083
  const el = child;
18081
- if (el.localName === localName2 || _optionalChain([el, 'access', _101 => _101.tagName, 'optionalAccess', _102 => _102.endsWith, 'call', _103 => _103(`:${localName2}`)])) {
18084
+ if (el.localName === localName2 || _optionalChain([el, 'access', _103 => _103.tagName, 'optionalAccess', _104 => _104.endsWith, 'call', _105 => _105(`:${localName2}`)])) {
18082
18085
  result.push(el);
18083
18086
  }
18084
18087
  walk(el);
@@ -18097,7 +18100,7 @@ function getAttr(el, localName2) {
18097
18100
  return null;
18098
18101
  }
18099
18102
  function parseXml2(text) {
18100
- return new (0, _xmldom.DOMParser)().parseFromString(_chunkLFCS3UVGcjs.stripDtd.call(void 0, text), "text/xml");
18103
+ return new (0, _xmldom.DOMParser)().parseFromString(_chunkXL6O3VAYcjs.stripDtd.call(void 0, text), "text/xml");
18101
18104
  }
18102
18105
  function parseStyles(xml) {
18103
18106
  const doc = parseXml2(xml);
@@ -18199,7 +18202,7 @@ function collectOmmlRoots(p) {
18199
18202
  const child = children[i];
18200
18203
  if (child.nodeType !== 1) continue;
18201
18204
  const el = child;
18202
- const tag = el.localName || _optionalChain([el, 'access', _104 => _104.tagName, 'optionalAccess', _105 => _105.replace, 'call', _106 => _106(/^[^:]+:/, "")]) || "";
18205
+ const tag = el.localName || _optionalChain([el, 'access', _106 => _106.tagName, 'optionalAccess', _107 => _107.replace, 'call', _108 => _108(/^[^:]+:/, "")]) || "";
18203
18206
  if (tag === "oMath" || tag === "oMathPara") {
18204
18207
  out.push(el);
18205
18208
  } else {
@@ -18288,7 +18291,7 @@ function parseParagraph2(p, styles, numbering, footnotes, rels) {
18288
18291
  const text = parts.join("").replace(/[ \t]{2,}/g, " ").trim();
18289
18292
  if (!text) return null;
18290
18293
  const style = styles.get(styleId);
18291
- if (_optionalChain([style, 'optionalAccess', _107 => _107.outlineLevel]) !== void 0 && style.outlineLevel >= 0 && style.outlineLevel <= 5) {
18294
+ if (_optionalChain([style, 'optionalAccess', _109 => _109.outlineLevel]) !== void 0 && style.outlineLevel >= 0 && style.outlineLevel <= 5) {
18292
18295
  return {
18293
18296
  type: "heading",
18294
18297
  text,
@@ -18297,8 +18300,8 @@ function parseParagraph2(p, styles, numbering, footnotes, rels) {
18297
18300
  }
18298
18301
  if (numId && numId !== "0") {
18299
18302
  const numDef = numbering.get(numId);
18300
- const levelInfo = _optionalChain([numDef, 'optionalAccess', _108 => _108.get, 'call', _109 => _109(ilvl)]);
18301
- const listType = _optionalChain([levelInfo, 'optionalAccess', _110 => _110.numFmt]) === "bullet" ? "unordered" : "ordered";
18303
+ const levelInfo = _optionalChain([numDef, 'optionalAccess', _110 => _110.get, 'call', _111 => _111(ilvl)]);
18304
+ const listType = _optionalChain([levelInfo, 'optionalAccess', _112 => _112.numFmt]) === "bullet" ? "unordered" : "ordered";
18302
18305
  return { type: "list", text, listType };
18303
18306
  }
18304
18307
  const block = { type: "paragraph", text };
@@ -18339,7 +18342,7 @@ function parseTable(tbl, styles, numbering, footnotes, rels) {
18339
18342
  const pElements = getChildElements(tc, "p");
18340
18343
  for (const p of pElements) {
18341
18344
  const block = parseParagraph2(p, styles, numbering, footnotes, rels);
18342
- if (_optionalChain([block, 'optionalAccess', _111 => _111.text])) cellTexts.push(block.text);
18345
+ if (_optionalChain([block, 'optionalAccess', _113 => _113.text])) cellTexts.push(block.text);
18343
18346
  }
18344
18347
  row.push({ text: cellTexts.join("\n"), colSpan, rowSpan });
18345
18348
  }
@@ -18352,7 +18355,7 @@ function parseTable(tbl, styles, numbering, footnotes, rels) {
18352
18355
  if (!cell || cell.rowSpan === 0) continue;
18353
18356
  let span = 1;
18354
18357
  for (let nr = r + 1; nr < rows.length; nr++) {
18355
- if (_optionalChain([rows, 'access', _112 => _112[nr], 'access', _113 => _113[c], 'optionalAccess', _114 => _114.rowSpan]) === 0) span++;
18358
+ if (_optionalChain([rows, 'access', _114 => _114[nr], 'access', _115 => _115[c], 'optionalAccess', _116 => _116.rowSpan]) === 0) span++;
18356
18359
  else break;
18357
18360
  }
18358
18361
  cell.rowSpan = span;
@@ -18396,7 +18399,7 @@ async function extractImages(zip, rels, doc, warnings) {
18396
18399
  try {
18397
18400
  const data = await imgFile.async("uint8array");
18398
18401
  imgIdx++;
18399
- const ext = _nullishCoalesce(_optionalChain([imgPath, 'access', _115 => _115.split, 'call', _116 => _116("."), 'access', _117 => _117.pop, 'call', _118 => _118(), 'optionalAccess', _119 => _119.toLowerCase, 'call', _120 => _120()]), () => ( "png"));
18402
+ const ext = _nullishCoalesce(_optionalChain([imgPath, 'access', _117 => _117.split, 'call', _118 => _118("."), 'access', _119 => _119.pop, 'call', _120 => _120(), 'optionalAccess', _121 => _121.toLowerCase, 'call', _122 => _122()]), () => ( "png"));
18400
18403
  const mimeMap = {
18401
18404
  png: "image/png",
18402
18405
  jpg: "image/jpeg",
@@ -18420,12 +18423,12 @@ async function extractImages(zip, rels, doc, warnings) {
18420
18423
  return { blocks, images };
18421
18424
  }
18422
18425
  async function parseDocxDocument(buffer, options) {
18423
- _chunkLFCS3UVGcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE4);
18426
+ _chunkXL6O3VAYcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE4);
18424
18427
  const zip = await _jszip2.default.loadAsync(buffer);
18425
18428
  const warnings = [];
18426
18429
  const docFile = zip.file("word/document.xml");
18427
18430
  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");
18431
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 DOCX \uD30C\uC77C: word/document.xml\uC774 \uC5C6\uC2B5\uB2C8\uB2E4");
18429
18432
  }
18430
18433
  let rels = /* @__PURE__ */ new Map();
18431
18434
  const relsFile = zip.file("word/_rels/document.xml.rels");
@@ -18472,13 +18475,13 @@ async function parseDocxDocument(buffer, options) {
18472
18475
  const doc = parseXml2(docXml);
18473
18476
  const body = findElements(doc, "body");
18474
18477
  if (body.length === 0) {
18475
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("DOCX \uBCF8\uBB38(w:body)\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
18478
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("DOCX \uBCF8\uBB38(w:body)\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
18476
18479
  }
18477
18480
  const blocks = [];
18478
18481
  const bodyEl = body[0];
18479
18482
  const topLevel = effectiveChildElements(bodyEl);
18480
18483
  for (const el of topLevel) {
18481
- const localName2 = _nullishCoalesce(el.localName, () => ( _optionalChain([el, 'access', _121 => _121.tagName, 'optionalAccess', _122 => _122.split, 'call', _123 => _123(":"), 'access', _124 => _124.pop, 'call', _125 => _125()])));
18484
+ const localName2 = _nullishCoalesce(el.localName, () => ( _optionalChain([el, 'access', _123 => _123.tagName, 'optionalAccess', _124 => _124.split, 'call', _125 => _125(":"), 'access', _126 => _126.pop, 'call', _127 => _127()])));
18482
18485
  if (localName2 === "p") {
18483
18486
  const block = parseParagraph2(el, styles, numbering, footnotes, rels);
18484
18487
  if (block) blocks.push(block);
@@ -18513,7 +18516,7 @@ async function parseDocxDocument(buffer, options) {
18513
18516
  }
18514
18517
  }
18515
18518
  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);
18519
+ const markdown = _chunkXL6O3VAYcjs.blocksToMarkdown.call(void 0, blocks);
18517
18520
  return {
18518
18521
  markdown,
18519
18522
  blocks,
@@ -18536,7 +18539,7 @@ function parseHwpmlDocument(buffer, options) {
18536
18539
  }
18537
18540
  const text = new TextDecoder("utf-8").decode(buffer).replace(/^\uFEFF/, "");
18538
18541
  const normalized = text.replace(/&nbsp;/g, "&#160;");
18539
- const xml = _chunkLFCS3UVGcjs.stripDtd.call(void 0, normalized);
18542
+ const xml = _chunkXL6O3VAYcjs.stripDtd.call(void 0, normalized);
18540
18543
  const warnings = [];
18541
18544
  const parser = new (0, _xmldom.DOMParser)({
18542
18545
  onError: (_level, msg2) => {
@@ -18564,7 +18567,7 @@ function parseHwpmlDocument(buffer, options) {
18564
18567
  return { markdown: "", blocks: [], metadata, warnings };
18565
18568
  }
18566
18569
  const blocks = [];
18567
- const pageFilter = _optionalChain([options, 'optionalAccess', _126 => _126.pages]) ? _chunkDCZVOIEOcjs.parsePageRange.call(void 0, options.pages, countSections(body)) : null;
18570
+ const pageFilter = _optionalChain([options, 'optionalAccess', _128 => _128.pages]) ? _chunkDCZVOIEOcjs.parsePageRange.call(void 0, options.pages, countSections(body)) : null;
18568
18571
  let sectionIdx = 0;
18569
18572
  const children = body.childNodes;
18570
18573
  for (let i = 0; i < children.length; i++) {
@@ -18576,7 +18579,7 @@ function parseHwpmlDocument(buffer, options) {
18576
18579
  parseSection2(el, blocks, paraShapeMap, sectionIdx, warnings);
18577
18580
  }
18578
18581
  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);
18582
+ const markdown = _chunkXL6O3VAYcjs.blocksToMarkdown.call(void 0, blocks);
18580
18583
  return {
18581
18584
  markdown,
18582
18585
  blocks,
@@ -18625,6 +18628,7 @@ function walkContent(node, blocks, paraShapeMap, sectionNum, warnings, inHeaderF
18625
18628
  if (tag === "P") {
18626
18629
  if (!inHeaderFooter) {
18627
18630
  parseParagraph3(el, blocks, paraShapeMap, sectionNum);
18631
+ walkTablesInP(el, blocks, paraShapeMap, sectionNum, warnings);
18628
18632
  }
18629
18633
  continue;
18630
18634
  }
@@ -18641,12 +18645,27 @@ function walkContent(node, blocks, paraShapeMap, sectionNum, warnings, inHeaderF
18641
18645
  walkContent(el, blocks, paraShapeMap, sectionNum, warnings, inHeaderFooter, depth + 1);
18642
18646
  }
18643
18647
  }
18648
+ function walkTablesInP(node, blocks, paraShapeMap, sectionNum, warnings, depth = 0) {
18649
+ if (depth > MAX_XML_DEPTH2) return;
18650
+ const children = node.childNodes;
18651
+ for (let i = 0; i < children.length; i++) {
18652
+ const el = children[i];
18653
+ if (el.nodeType !== 1) continue;
18654
+ const tag = localName(el);
18655
+ if (tag === "TABLE") {
18656
+ parseTable2(el, blocks, paraShapeMap, sectionNum, warnings);
18657
+ continue;
18658
+ }
18659
+ if (tag === "FOOTNOTE" || tag === "ENDNOTE" || tag === "HEADER" || tag === "FOOTER") continue;
18660
+ walkTablesInP(el, blocks, paraShapeMap, sectionNum, warnings, depth + 1);
18661
+ }
18662
+ }
18644
18663
  function parseParagraph3(el, blocks, paraShapeMap, sectionNum) {
18645
18664
  const paraShapeId = _nullishCoalesce(el.getAttribute("ParaShape"), () => ( ""));
18646
18665
  const shapeInfo = paraShapeMap.get(paraShapeId);
18647
18666
  const text = extractParagraphText(el);
18648
18667
  if (!text) return;
18649
- if (_optionalChain([shapeInfo, 'optionalAccess', _127 => _127.headingLevel]) != null) {
18668
+ if (_optionalChain([shapeInfo, 'optionalAccess', _129 => _129.headingLevel]) != null) {
18650
18669
  blocks.push({ type: "heading", text, level: shapeInfo.headingLevel, pageNumber: sectionNum });
18651
18670
  } else {
18652
18671
  blocks.push({ type: "paragraph", text, pageNumber: sectionNum });
@@ -18718,7 +18737,7 @@ function parseTable2(el, blocks, paraShapeMap, sectionNum, warnings) {
18718
18737
  const cellRows = grid.map(
18719
18738
  (row) => row.map((cell) => _nullishCoalesce(cell, () => ( { text: "", colSpan: 1, rowSpan: 1 })))
18720
18739
  );
18721
- const table = _chunkLFCS3UVGcjs.buildTable.call(void 0, cellRows);
18740
+ const table = _chunkXL6O3VAYcjs.buildTable.call(void 0, cellRows);
18722
18741
  blocks.push({ type: "table", table, pageNumber: sectionNum });
18723
18742
  }
18724
18743
  function extractCellText(cellEl) {
@@ -18736,13 +18755,29 @@ function collectCellText(node, parts, depth) {
18736
18755
  if (tag === "P") {
18737
18756
  const t = extractParagraphText(el);
18738
18757
  if (t) parts.push(t);
18758
+ collectNestedTableText(el, parts, depth + 1);
18739
18759
  } else if (tag === "TABLE") {
18740
- parts.push("[\uC911\uCCA9 \uD14C\uC774\uBE14]");
18760
+ collectCellText(el, parts, depth + 1);
18741
18761
  } else {
18742
18762
  collectCellText(el, parts, depth + 1);
18743
18763
  }
18744
18764
  }
18745
18765
  }
18766
+ function collectNestedTableText(node, parts, depth) {
18767
+ if (depth > 20) return;
18768
+ const children = node.childNodes;
18769
+ for (let i = 0; i < children.length; i++) {
18770
+ const el = children[i];
18771
+ if (el.nodeType !== 1) continue;
18772
+ const tag = localName(el);
18773
+ if (tag === "TABLE") {
18774
+ collectCellText(el, parts, depth + 1);
18775
+ continue;
18776
+ }
18777
+ if (tag === "FOOTNOTE" || tag === "ENDNOTE" || tag === "HEADER" || tag === "FOOTER") continue;
18778
+ collectNestedTableText(el, parts, depth + 1);
18779
+ }
18780
+ }
18746
18781
  function localName(el) {
18747
18782
  return (el.tagName || el.localName || "").replace(/^[^:]+:/, "");
18748
18783
  }
@@ -19079,8 +19114,8 @@ function extractFromTable(table) {
19079
19114
  if (table.cols >= 2) {
19080
19115
  for (let r = 0; r < table.rows; r++) {
19081
19116
  for (let c = 0; c < table.cols - 1; c++) {
19082
- const labelCell = _optionalChain([table, 'access', _128 => _128.cells, 'access', _129 => _129[r], 'optionalAccess', _130 => _130[c]]);
19083
- const valueCell = _optionalChain([table, 'access', _131 => _131.cells, 'access', _132 => _132[r], 'optionalAccess', _133 => _133[c + 1]]);
19117
+ const labelCell = _optionalChain([table, 'access', _130 => _130.cells, 'access', _131 => _131[r], 'optionalAccess', _132 => _132[c]]);
19118
+ const valueCell = _optionalChain([table, 'access', _133 => _133.cells, 'access', _134 => _134[r], 'optionalAccess', _135 => _135[c + 1]]);
19084
19119
  if (!labelCell || !valueCell) continue;
19085
19120
  if (isLabelCell(labelCell.text)) {
19086
19121
  fields.push({
@@ -19102,8 +19137,8 @@ function extractFromTable(table) {
19102
19137
  if (allLabels) {
19103
19138
  for (let r = 1; r < table.rows; r++) {
19104
19139
  for (let c = 0; c < table.cols; c++) {
19105
- const label = _nullishCoalesce(_optionalChain([headerRow, 'access', _134 => _134[c], 'optionalAccess', _135 => _135.text, 'access', _136 => _136.trim, 'call', _137 => _137()]), () => ( ""));
19106
- const value = _nullishCoalesce(_optionalChain([table, 'access', _138 => _138.cells, 'access', _139 => _139[r], 'optionalAccess', _140 => _140[c], 'optionalAccess', _141 => _141.text, 'access', _142 => _142.trim, 'call', _143 => _143()]), () => ( ""));
19140
+ const label = _nullishCoalesce(_optionalChain([headerRow, 'access', _136 => _136[c], 'optionalAccess', _137 => _137.text, 'access', _138 => _138.trim, 'call', _139 => _139()]), () => ( ""));
19141
+ const value = _nullishCoalesce(_optionalChain([table, 'access', _140 => _140.cells, 'access', _141 => _141[r], 'optionalAccess', _142 => _142[c], 'optionalAccess', _143 => _143.text, 'access', _144 => _144.trim, 'call', _145 => _145()]), () => ( ""));
19107
19142
  if (label && value) {
19108
19143
  fields.push({ label, value, row: r, col: c });
19109
19144
  }
@@ -19196,7 +19231,7 @@ function fillFormFields(blocks, values) {
19196
19231
  for (const table of allTables) {
19197
19232
  for (let r = 0; r < table.rows; r++) {
19198
19233
  for (let c = 0; c < table.cols; c++) {
19199
- const cell = _optionalChain([table, 'access', _144 => _144.cells, 'access', _145 => _145[r], 'optionalAccess', _146 => _146[c]]);
19234
+ const cell = _optionalChain([table, 'access', _146 => _146.cells, 'access', _147 => _147[r], 'optionalAccess', _148 => _148[c]]);
19200
19235
  if (!cell) continue;
19201
19236
  const result = fillInCellPatterns(cell.text, cursor, matchedLabels);
19202
19237
  if (result) {
@@ -19228,7 +19263,7 @@ function collectIRTables(blocks, depth) {
19228
19263
  out.push(block.table);
19229
19264
  for (const row of block.table.cells) {
19230
19265
  for (const cell of row) {
19231
- if (_optionalChain([cell, 'optionalAccess', _147 => _147.blocks, 'optionalAccess', _148 => _148.length])) out.push(...collectIRTables(cell.blocks, depth + 1));
19266
+ if (_optionalChain([cell, 'optionalAccess', _149 => _149.blocks, 'optionalAccess', _150 => _150.length])) out.push(...collectIRTables(cell.blocks, depth + 1));
19232
19267
  }
19233
19268
  }
19234
19269
  }
@@ -19239,7 +19274,7 @@ function coveredPositions(table) {
19239
19274
  for (let r = 0; r < table.rows; r++) {
19240
19275
  for (let c = 0; c < table.cols; c++) {
19241
19276
  if (covered.has(`${r},${c}`)) continue;
19242
- const cell = _optionalChain([table, 'access', _149 => _149.cells, 'access', _150 => _150[r], 'optionalAccess', _151 => _151[c]]);
19277
+ const cell = _optionalChain([table, 'access', _151 => _151.cells, 'access', _152 => _152[r], 'optionalAccess', _153 => _153[c]]);
19243
19278
  if (!cell) continue;
19244
19279
  for (let dr = 0; dr < cell.rowSpan; dr++) {
19245
19280
  for (let dc = 0; dc < cell.colSpan; dc++) {
@@ -19273,7 +19308,7 @@ function fillTable(table, values, filled, matchedLabels, patternFilledCells) {
19273
19308
  if (matchKey === void 0) continue;
19274
19309
  const newValue = values.consume(matchKey);
19275
19310
  if (newValue === void 0) continue;
19276
- if (_optionalChain([patternFilledCells, 'optionalAccess', _152 => _152.has, 'call', _153 => _153(valueCell)])) {
19311
+ if (_optionalChain([patternFilledCells, 'optionalAccess', _154 => _154.has, 'call', _155 => _155(valueCell)])) {
19277
19312
  valueCell.text = newValue + " " + valueCell.text;
19278
19313
  } else {
19279
19314
  valueCell.text = newValue;
@@ -19298,7 +19333,7 @@ function fillTable(table, values, filled, matchedLabels, patternFilledCells) {
19298
19333
  for (let c = 0; c < table.cols; c++) {
19299
19334
  if (covered.has(`${r},${c}`)) continue;
19300
19335
  const headerCell = headerRow[c];
19301
- const valueCell = _optionalChain([table, 'access', _154 => _154.cells, 'access', _155 => _155[r], 'optionalAccess', _156 => _156[c]]);
19336
+ const valueCell = _optionalChain([table, 'access', _156 => _156.cells, 'access', _157 => _157[r], 'optionalAccess', _158 => _158[c]]);
19302
19337
  if (!headerCell || !valueCell) continue;
19303
19338
  const headerLabel = normalizeLabel(headerCell.text);
19304
19339
  const matchKey = findMatchingKey(headerLabel, values);
@@ -19891,19 +19926,19 @@ function parseCentralDirectory(buf) {
19891
19926
  }
19892
19927
  }
19893
19928
  }
19894
- if (eocdOffset < 0) throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP EOCD\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
19929
+ if (eocdOffset < 0) throw new (0, _chunkXL6O3VAYcjs.KordocError)("ZIP EOCD\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
19895
19930
  const totalEntries = view.getUint16(eocdOffset + 10, true);
19896
19931
  const cdSize = view.getUint32(eocdOffset + 12, true);
19897
19932
  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");
19933
+ if (cdOffset === 4294967295 || totalEntries === 65535) throw new (0, _chunkXL6O3VAYcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19899
19934
  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");
19935
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19901
19936
  }
19902
19937
  const decoder = new TextDecoder("utf-8");
19903
19938
  const entries = [];
19904
19939
  let pos = cdOffset;
19905
19940
  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");
19941
+ if (view.getUint32(pos, true) !== CD_SIG) throw new (0, _chunkXL6O3VAYcjs.KordocError)("ZIP Central Directory \uC190\uC0C1");
19907
19942
  const flags = view.getUint16(pos + 8, true);
19908
19943
  const method = view.getUint16(pos + 10, true);
19909
19944
  const crc = view.getUint32(pos + 16, true);
@@ -19914,7 +19949,7 @@ function parseCentralDirectory(buf) {
19914
19949
  const commentLen = view.getUint16(pos + 32, true);
19915
19950
  const localOffset = view.getUint32(pos + 42, true);
19916
19951
  if (compSize === 4294967295 || uncompSize === 4294967295 || localOffset === 4294967295) {
19917
- throw new (0, _chunkLFCS3UVGcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19952
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
19918
19953
  }
19919
19954
  const name = decoder.decode(buf.subarray(pos + 46, pos + 46 + nameLen));
19920
19955
  const cdEnd = pos + 46 + nameLen + extraLen + commentLen;
@@ -19943,7 +19978,7 @@ function patchZipEntries(original, replacements) {
19943
19978
  const { entries, cdOffset, eocdOffset } = parseCentralDirectory(original);
19944
19979
  const view = new DataView(original.buffer, original.byteOffset, original.byteLength);
19945
19980
  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}`);
19981
+ if (!entries.some((e) => e.name === name)) throw new (0, _chunkXL6O3VAYcjs.KordocError)(`ZIP\uC5D0 \uC5C6\uB294 \uC5D4\uD2B8\uB9AC: ${name}`);
19947
19982
  }
19948
19983
  const byLocal = [...entries].sort((a, b) => a.localOffset - b.localOffset);
19949
19984
  const segments = [];
@@ -19961,7 +19996,7 @@ function patchZipEntries(original, replacements) {
19961
19996
  offset += seg.length;
19962
19997
  continue;
19963
19998
  }
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");
19999
+ if (view.getUint32(e.localOffset, true) !== LOCAL_SIG) throw new (0, _chunkXL6O3VAYcjs.KordocError)("ZIP \uB85C\uCEEC \uD5E4\uB354 \uC2DC\uADF8\uB2C8\uCC98 \uBD88\uC77C\uCE58");
19965
20000
  const nameLen = view.getUint16(e.localOffset + 26, true);
19966
20001
  const extraLen = view.getUint16(e.localOffset + 28, true);
19967
20002
  const headerLen = 30 + nameLen + extraLen;
@@ -20016,7 +20051,7 @@ async function fillHwpx(hwpxBuffer, values) {
20016
20051
  const zip = await _jszip2.default.loadAsync(hwpxBuffer);
20017
20052
  const sectionPaths = Object.keys(zip.files).filter((name) => /[Ss]ection\d+\.xml$/i.test(name)).sort();
20018
20053
  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");
20054
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)("HWPX\uC5D0\uC11C \uC139\uC158 \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
20020
20055
  }
20021
20056
  const normalizedValues = normalizeValues(values);
20022
20057
  const cursor = new ValueCursor(normalizedValues);
@@ -20175,7 +20210,7 @@ async function fillHwpx(hwpxBuffer, values) {
20175
20210
  }
20176
20211
  for (const para of [...scan.bodyParagraphs, ...scan.excludedParagraphs]) {
20177
20212
  const existing = ledger.get(para);
20178
- if (_optionalChain([existing, 'optionalAccess', _157 => _157.fullText]) !== void 0) continue;
20213
+ if (_optionalChain([existing, 'optionalAccess', _159 => _159.fullText]) !== void 0) continue;
20179
20214
  const text = matchText(para);
20180
20215
  for (const seg of scanInlineSegments(text)) {
20181
20216
  const matchKey = findMatchingKey(normalizeLabel(seg.label), cursor);
@@ -20414,8 +20449,8 @@ function charWidthEm1000(cp) {
20414
20449
  var SPACE_EM_FIXED = 500;
20415
20450
  var SPACE_EM_FONT = 300;
20416
20451
  function measureTextWidth(text, height, ratioPct, opts) {
20417
- const spaceEm = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _158 => _158.spaceEm]), () => ( SPACE_EM_FIXED));
20418
- const spacing = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _159 => _159.spacingPct]), () => ( 0));
20452
+ const spaceEm = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _160 => _160.spaceEm]), () => ( SPACE_EM_FIXED));
20453
+ const spacing = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _161 => _161.spacingPct]), () => ( 0));
20419
20454
  let em = 0;
20420
20455
  for (const ch of text) {
20421
20456
  const cp = ch.codePointAt(0);
@@ -20428,8 +20463,8 @@ var FORBID_START = /* @__PURE__ */ new Set([..."!%),.:;?]}\xA2\xB0\u2032\u2033\u
20428
20463
  var FORBID_END = /* @__PURE__ */ new Set([..."$([{\xA3\xA5\u3008\u300A\u300C\u300E\u3010\u3014$([{\u20A9"]);
20429
20464
  function simulateWrap(text, firstWidth, contWidth, height, ratioPct, mode = "keep", opts) {
20430
20465
  const EPS = 0.5;
20431
- const spaceEm = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _160 => _160.spaceEm]), () => ( SPACE_EM_FIXED));
20432
- const spacing = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _161 => _161.spacingPct]), () => ( 0));
20466
+ const spaceEm = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _162 => _162.spaceEm]), () => ( SPACE_EM_FIXED));
20467
+ const spacing = _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _163 => _163.spacingPct]), () => ( 0));
20433
20468
  const k = height * ratioPct / 100 / 1e3;
20434
20469
  const cwCp = (cp) => (cp === 32 ? spaceEm : charWidthEm1000(cp)) * (1 + spacing / 100) * k;
20435
20470
  const charW = (ch) => cwCp(ch.codePointAt(0));
@@ -20625,53 +20660,112 @@ function mmToHwpunit(mm) {
20625
20660
  return Math.round(mm * 7200 / 25.4);
20626
20661
  }
20627
20662
 
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;
20663
+ // src/hwpx/gen-ids.ts
20664
+ var NS_SECTION = "http://www.hancom.co.kr/hwpml/2011/section";
20665
+ var NS_PARA = "http://www.hancom.co.kr/hwpml/2011/paragraph";
20666
+ var NS_HEAD = "http://www.hancom.co.kr/hwpml/2011/head";
20667
+ var NS_CORE = "http://www.hancom.co.kr/hwpml/2011/core";
20668
+ var NS_OPF = "http://www.idpf.org/2007/opf/";
20669
+ var NS_HPF = "http://www.hancom.co.kr/schema/2011/hpf";
20670
+ var NS_OCF = "urn:oasis:names:tc:opendocument:xmlns:container";
20671
+ var CHAR_NORMAL = 0;
20672
+ var CHAR_BOLD = 1;
20673
+ var CHAR_ITALIC = 2;
20674
+ var CHAR_BOLD_ITALIC = 3;
20675
+ var CHAR_CODE = 4;
20676
+ var CHAR_H1 = 5;
20677
+ var CHAR_H2 = 6;
20678
+ var CHAR_H3 = 7;
20679
+ var CHAR_H4 = 8;
20680
+ var CHAR_TABLE_HEADER = 9;
20681
+ var CHAR_QUOTE = 10;
20682
+ var PARA_NORMAL = 0;
20683
+ var PARA_H1 = 1;
20684
+ var PARA_H2 = 2;
20685
+ var PARA_H3 = 3;
20686
+ var PARA_H4 = 4;
20687
+ var PARA_CODE = 5;
20688
+ var PARA_QUOTE = 6;
20689
+ var PARA_LIST = 7;
20690
+ var DEFAULT_TEXT_COLOR = "#000000";
20691
+ function resolveTheme(theme) {
20692
+ return {
20693
+ h1: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _164 => _164.headingColors, 'optionalAccess', _165 => _165[1]]), () => ( DEFAULT_TEXT_COLOR)),
20694
+ h2: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _166 => _166.headingColors, 'optionalAccess', _167 => _167[2]]), () => ( DEFAULT_TEXT_COLOR)),
20695
+ h3: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _168 => _168.headingColors, 'optionalAccess', _169 => _169[3]]), () => ( DEFAULT_TEXT_COLOR)),
20696
+ h4: _nullishCoalesce(_nullishCoalesce(_optionalChain([theme, 'optionalAccess', _170 => _170.headingColors, 'optionalAccess', _171 => _171[4]]), () => ( _optionalChain([theme, 'optionalAccess', _172 => _172.headingColors, 'optionalAccess', _173 => _173[3]]))), () => ( DEFAULT_TEXT_COLOR)),
20697
+ body: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _174 => _174.bodyColor]), () => ( DEFAULT_TEXT_COLOR)),
20698
+ quote: _nullishCoalesce(_optionalChain([theme, 'optionalAccess', _175 => _175.quoteColor]), () => ( DEFAULT_TEXT_COLOR)),
20699
+ /** quoteColor가 명시되었는지 — blockquote charPr 분기에 사용 (baseline 호환) */
20700
+ hasQuoteOption: _optionalChain([theme, 'optionalAccess', _176 => _176.quoteColor]) !== void 0,
20701
+ tableHeader: _nullishCoalesce(_nullishCoalesce(_optionalChain([theme, 'optionalAccess', _177 => _177.tableHeaderColor]), () => ( _optionalChain([theme, 'optionalAccess', _178 => _178.bodyColor]))), () => ( DEFAULT_TEXT_COLOR)),
20702
+ tableHeaderBold: !!_optionalChain([theme, 'optionalAccess', _179 => _179.tableHeaderBold])
20703
+ };
20635
20704
  }
20636
- function normalizedSimilarity(a, b) {
20637
- return similarity(normalize(a), normalize(b));
20705
+ function escapeXml(text) {
20706
+ return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
20638
20707
  }
20639
- function normalize(s) {
20640
- return s.replace(/\s+/g, " ").trim();
20708
+ function headingParaPrId(level) {
20709
+ if (level === 1) return PARA_H1;
20710
+ if (level === 2) return PARA_H2;
20711
+ if (level === 3) return PARA_H3;
20712
+ return PARA_H4;
20641
20713
  }
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];
20714
+ function headingCharPrId(level) {
20715
+ if (level === 1) return CHAR_H1;
20716
+ if (level === 2) return CHAR_H2;
20717
+ if (level === 3) return CHAR_H3;
20718
+ return CHAR_H4;
20719
+ }
20720
+ function charPr(id, height, bold, italic, fontId = 0, textColor = DEFAULT_TEXT_COLOR, ratioPct = 100) {
20721
+ const boldAttr = bold ? ` bold="1"` : "";
20722
+ const italicAttr = italic ? ` italic="1"` : "";
20723
+ const effFont = bold ? 2 : fontId;
20724
+ return ` <hh:charPr id="${id}" height="${height}" textColor="${textColor}" shadeColor="none" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="1"${boldAttr}${italicAttr}>
20725
+ <hh:fontRef hangul="${effFont}" latin="${effFont}" hanja="${effFont}" japanese="${effFont}" other="${effFont}" symbol="${effFont}" user="${effFont}"/>
20726
+ <hh:ratio hangul="${ratioPct}" latin="${ratioPct}" hanja="${ratioPct}" japanese="100" other="100" symbol="100" user="100"/>
20727
+ <hh:spacing hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
20728
+ <hh:relSz hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
20729
+ <hh:offset hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
20730
+ </hh:charPr>`;
20731
+ }
20732
+ function paraPr(id, opts = {}) {
20733
+ const { align = "JUSTIFY", spaceBefore = 0, spaceAfter = 0, lineSpacing = 160, indent = 0, left = 0, keepWord = false } = opts;
20734
+ const breakNonLatin = keepWord ? "KEEP_WORD" : "BREAK_WORD";
20735
+ const snapGrid = keepWord ? "0" : "1";
20736
+ return ` <hh:paraPr id="${id}" tabPrIDRef="0" condense="0" fontLineHeight="0" snapToGrid="${snapGrid}" suppressLineNumbers="0" checked="0" textDir="AUTO">
20737
+ <hh:align horizontal="${align}" vertical="BASELINE"/>
20738
+ <hh:heading type="NONE" idRef="0" level="0"/>
20739
+ <hh:breakSetting breakLatinWord="KEEP_WORD" breakNonLatinWord="${breakNonLatin}" widowOrphan="0" keepWithNext="0" keepLines="0" pageBreakBefore="0" lineWrap="BREAK"/>
20740
+ <hh:autoSpacing eAsianEng="0" eAsianNum="0"/>
20741
+ <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>
20742
+ <hh:lineSpacing type="PERCENT" value="${lineSpacing}"/>
20743
+ <hh:border borderFillIDRef="1" offsetLeft="0" offsetRight="0" offsetTop="0" offsetBottom="0" connect="0" ignoreMargin="0"/>
20744
+ </hh:paraPr>`;
20669
20745
  }
20746
+ var GONGMUN_LIST_BASE = 8;
20747
+ var GONGMUN_LIST_LEVELS = 8;
20748
+ var GONGMUN_CENTER = GONGMUN_LIST_BASE + GONGMUN_LIST_LEVELS;
20749
+ var CHAR_VARIANT_BASE = 11;
20750
+ var GONGMUN_BODY_RATIO = 95;
20670
20751
 
20671
- // src/roundtrip/markdown-units.ts
20672
- function splitMarkdownUnits(md2) {
20752
+ // src/hwpx/md-runs.ts
20753
+ function buildPrvText(blocks) {
20754
+ const lines = [];
20755
+ let bytes = 0;
20756
+ for (const b of blocks) {
20757
+ let text = b.text || (b.rows ? b.rows.map((r) => r.join(" ")).join("\n") : "");
20758
+ if (b.type === "html_table") text = text.replace(/<[^>]+>/g, " ").replace(/\s+/g, " ").trim();
20759
+ if (!text) continue;
20760
+ lines.push(text);
20761
+ bytes += text.length * 3;
20762
+ if (bytes > 1024) break;
20763
+ }
20764
+ return lines.join("\n").slice(0, 1024);
20765
+ }
20766
+ function parseMarkdownToBlocks(md2) {
20673
20767
  const lines = md2.split("\n");
20674
- const units = [];
20768
+ const blocks = [];
20675
20769
  let i = 0;
20676
20770
  while (i < lines.length) {
20677
20771
  const line = lines[i];
@@ -20679,442 +20773,451 @@ function splitMarkdownUnits(md2) {
20679
20773
  i++;
20680
20774
  continue;
20681
20775
  }
20682
- if (line.trim().startsWith("<table>")) {
20683
- const collected2 = [];
20776
+ const fenceMatch = line.match(/^(`{3,}|~{3,})(.*)$/);
20777
+ if (fenceMatch) {
20778
+ const fence = fenceMatch[1];
20779
+ const lang = fenceMatch[2].trim();
20780
+ const codeLines = [];
20781
+ i++;
20782
+ while (i < lines.length && !lines[i].startsWith(fence)) {
20783
+ codeLines.push(lines[i]);
20784
+ i++;
20785
+ }
20786
+ if (i < lines.length) i++;
20787
+ blocks.push({ type: "code_block", text: codeLines.join("\n"), lang });
20788
+ continue;
20789
+ }
20790
+ if (/^(\*{3,}|-{3,}|_{3,})\s*$/.test(line.trim())) {
20791
+ blocks.push({ type: "hr" });
20792
+ i++;
20793
+ continue;
20794
+ }
20795
+ const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
20796
+ if (headingMatch) {
20797
+ blocks.push({ type: "heading", text: headingMatch[2].trim(), level: headingMatch[1].length });
20798
+ i++;
20799
+ continue;
20800
+ }
20801
+ if (/^<table[\s>]/i.test(line.trimStart())) {
20802
+ const htmlLines = [];
20684
20803
  let depth = 0;
20685
20804
  while (i < lines.length) {
20686
20805
  const l = lines[i];
20687
- collected2.push(l);
20688
- depth += (l.match(/<table>/g) || []).length;
20689
- depth -= (l.match(/<\/table>/g) || []).length;
20806
+ htmlLines.push(l);
20807
+ depth += (_nullishCoalesce(l.match(/<table[\s>]/gi), () => ( []))).length;
20808
+ depth -= (_nullishCoalesce(l.match(/<\/table>/gi), () => ( []))).length;
20690
20809
  i++;
20691
20810
  if (depth <= 0) break;
20692
20811
  }
20693
- units.push({ kind: "html-table", raw: collected2.join("\n"), lines: collected2 });
20812
+ blocks.push({ type: "html_table", text: htmlLines.join("\n") });
20694
20813
  continue;
20695
20814
  }
20696
20815
  if (line.trimStart().startsWith("|")) {
20697
- const collected2 = [];
20816
+ const tableRows = [];
20698
20817
  while (i < lines.length && lines[i].trimStart().startsWith("|")) {
20699
- collected2.push(lines[i]);
20818
+ const row = lines[i];
20819
+ if (/^[\s|:\-]+$/.test(row)) {
20820
+ i++;
20821
+ continue;
20822
+ }
20823
+ const cells = row.split("|").slice(1, -1).map((c) => c.trim());
20824
+ if (cells.length > 0) tableRows.push(cells);
20700
20825
  i++;
20701
20826
  }
20702
- units.push({ kind: "gfm-table", raw: collected2.join("\n"), lines: collected2 });
20827
+ if (tableRows.length > 0) blocks.push({ type: "table", rows: tableRows });
20703
20828
  continue;
20704
20829
  }
20705
- if (/^-{3,}\s*$/.test(line.trim())) {
20706
- units.push({ kind: "separator", raw: line.trim(), lines: [line.trim()] });
20707
- i++;
20830
+ if (line.trimStart().startsWith("> ")) {
20831
+ const quoteLines = [];
20832
+ while (i < lines.length && (lines[i].trimStart().startsWith("> ") || lines[i].trimStart().startsWith(">"))) {
20833
+ quoteLines.push(lines[i].replace(/^>\s?/, ""));
20834
+ i++;
20835
+ }
20836
+ for (const ql of quoteLines) {
20837
+ blocks.push({ type: "blockquote", text: ql.trim() || "" });
20838
+ }
20708
20839
  continue;
20709
20840
  }
20710
- if (/^!\[image\]\([^)]*\)\s*$/.test(line.trim())) {
20711
- units.push({ kind: "image", raw: line.trim(), lines: [line.trim()] });
20841
+ const listMatch = line.match(/^(\s*)([-*+]|\d+[.)]) (.+)$/);
20842
+ if (listMatch) {
20843
+ const indent = Math.floor(listMatch[1].length / 2);
20844
+ const ordered = /\d/.test(listMatch[2]);
20845
+ blocks.push({ type: "list_item", text: listMatch[3].trim(), ordered, indent });
20712
20846
  i++;
20713
20847
  continue;
20714
20848
  }
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 });
20849
+ blocks.push({ type: "paragraph", text: line.trim() });
20850
+ i++;
20721
20851
  }
20722
- return units;
20852
+ return blocks;
20723
20853
  }
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++;
20854
+ function parseInlineMarkdown(text) {
20855
+ text = text.replace(/!\[([^\]]*)\]\([^)]*\)/g, "$1");
20856
+ text = text.replace(/\[([^\]]*)\]\(([^)]*)\)/g, (_, t, u) => t || u);
20857
+ text = text.replace(/~~([^~]+)~~/g, "$1");
20858
+ const spans = [];
20859
+ const regex = /(`[^`]+`|\*{3}[^*]+\*{3}|\*{2}[^*]+\*{2}|\*[^*]+\*|_{2}[^_]+_{2}|_[^_]+_)/g;
20860
+ let lastIdx = 0;
20861
+ for (const match of text.matchAll(regex)) {
20862
+ const idx = match.index;
20863
+ if (idx > lastIdx) {
20864
+ spans.push({ text: text.slice(lastIdx, idx), bold: false, italic: false, code: false });
20732
20865
  }
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]);
20866
+ const raw = match[0];
20867
+ if (raw.startsWith("`")) {
20868
+ spans.push({ text: raw.slice(1, -1), bold: false, italic: false, code: true });
20869
+ } else if (raw.startsWith("***") || raw.startsWith("___")) {
20870
+ spans.push({ text: raw.slice(3, -3), bold: true, italic: true, code: false });
20871
+ } else if (raw.startsWith("**") || raw.startsWith("__")) {
20872
+ spans.push({ text: raw.slice(2, -2), bold: true, italic: false, code: false });
20738
20873
  } 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]);
20741
- }
20742
- for (let s = suf - 1; s >= 0; s--) result2.push([m - 1 - s, n - 1 - s]);
20743
- return result2;
20744
- }
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]);
20874
+ spans.push({ text: raw.slice(1, -1), bold: false, italic: true, code: false });
20749
20875
  }
20876
+ lastIdx = idx + raw.length;
20750
20877
  }
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--;
20878
+ if (lastIdx < text.length) {
20879
+ spans.push({ text: text.slice(lastIdx), bold: false, italic: false, code: false });
20760
20880
  }
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++]);
20881
+ if (spans.length === 0) {
20882
+ spans.push({ text, bold: false, italic: false, code: false });
20788
20883
  }
20789
- flushGap(m, n);
20790
- return result;
20884
+ return spans;
20791
20885
  }
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;
20886
+ function spanToCharPrId(span) {
20887
+ if (span.code) return CHAR_CODE;
20888
+ if (span.bold && span.italic) return CHAR_BOLD_ITALIC;
20889
+ if (span.bold) return CHAR_BOLD;
20890
+ if (span.italic) return CHAR_ITALIC;
20891
+ return CHAR_NORMAL;
20799
20892
  }
20800
- function escapeGfm(text) {
20801
- return text.replace(/~/g, "\\~");
20893
+ function generateRuns(text, defaultCharPr = CHAR_NORMAL, mapCharId) {
20894
+ const spans = parseInlineMarkdown(text);
20895
+ return spans.map((span) => {
20896
+ let charId = span.code || span.bold || span.italic ? spanToCharPrId(span) : defaultCharPr;
20897
+ if (mapCharId) charId = mapCharId(charId);
20898
+ return `<hp:run charPrIDRef="${charId}"><hp:t>${escapeXml(span.text)}</hp:t></hp:run>`;
20899
+ }).join("");
20802
20900
  }
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
- }
20901
+ function generateParagraph(text, paraPrId = PARA_NORMAL, charPrId = CHAR_NORMAL, mapCharId) {
20902
+ if (paraPrId === PARA_CODE) {
20903
+ return `<hp:p paraPrIDRef="${paraPrId}" styleIDRef="0"><hp:run charPrIDRef="${CHAR_CODE}"><hp:t>${escapeXml(text)}</hp:t></hp:run></hp:p>`;
20812
20904
  }
20813
- return result;
20814
- }
20815
- function normForMatch(text) {
20816
- return sanitizeText(text).replace(/\s+/g, " ").trim();
20905
+ const runs = generateRuns(text, charPrId, mapCharId);
20906
+ return `<hp:p paraPrIDRef="${paraPrId}" styleIDRef="0">${runs}</hp:p>`;
20817
20907
  }
20818
- function unescapeGfm(text) {
20819
- return text.replace(/\\~/g, "~");
20908
+
20909
+ // src/hwpx/gen-header.ts
20910
+ function generateContainerXml() {
20911
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
20912
+ <ocf:container xmlns:ocf="${NS_OCF}" xmlns:hpf="${NS_HPF}">
20913
+ <ocf:rootfiles>
20914
+ <ocf:rootfile full-path="Contents/content.hpf" media-type="application/hwpml-package+xml"/>
20915
+ </ocf:rootfiles>
20916
+ </ocf:container>`;
20820
20917
  }
20821
- function summarize(text) {
20822
- const t = text.replace(/\s+/g, " ").trim();
20823
- return t.length > 80 ? t.slice(0, 77) + "..." : t;
20918
+ function generateManifest() {
20919
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
20920
+ <opf:package xmlns:opf="${NS_OPF}" xmlns:hpf="${NS_HPF}" xmlns:hh="${NS_HEAD}">
20921
+ <opf:manifest>
20922
+ <opf:item id="header" href="Contents/header.xml" media-type="application/xml"/>
20923
+ <opf:item id="section0" href="Contents/section0.xml" media-type="application/xml"/>
20924
+ </opf:manifest>
20925
+ <opf:spine>
20926
+ <opf:itemref idref="header" linear="no"/>
20927
+ <opf:itemref idref="section0" linear="yes"/>
20928
+ </opf:spine>
20929
+ </opf:package>`;
20824
20930
  }
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
- }
20931
+ function buildCharProperties(theme, gongmun, ratioVariants = []) {
20932
+ let body = 1e3, code = 900, h1 = 1800, h2 = 1400, h3 = 1200, h4 = 1100;
20933
+ if (gongmun) {
20934
+ body = gongmun.bodyHeight;
20935
+ code = Math.max(body - 200, 900);
20936
+ h1 = gongmun.preset === "report" || gongmun.preset === "plan" ? 2e3 : 1700;
20937
+ h2 = 1600;
20938
+ h3 = body;
20939
+ h4 = Math.max(body - 100, 1300);
20850
20940
  }
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);
20941
+ const bodyRatio = gongmun ? GONGMUN_BODY_RATIO : 100;
20942
+ const rows = [
20943
+ charPr(0, body, false, false, 0, theme.body, bodyRatio),
20944
+ charPr(1, body, true, false, 0, theme.body, bodyRatio),
20945
+ charPr(2, body, false, true, 0, theme.body, bodyRatio),
20946
+ charPr(3, body, true, true, 0, theme.body, bodyRatio),
20947
+ charPr(4, code, false, false, 1),
20948
+ charPr(5, h1, true, false, 1, theme.h1),
20949
+ charPr(6, h2, true, false, 1, theme.h2),
20950
+ charPr(7, h3, true, false, 1, theme.h3),
20951
+ charPr(8, h4, true, false, 1, theme.h4),
20952
+ charPr(CHAR_TABLE_HEADER, body, theme.tableHeaderBold, false, 0, theme.tableHeader),
20953
+ charPr(CHAR_QUOTE, body, false, true, 0, theme.quote)
20954
+ ];
20955
+ for (const r of ratioVariants) {
20956
+ rows.push(
20957
+ charPr(rows.length, body, false, false, 0, theme.body, r),
20958
+ charPr(rows.length + 1, body, true, false, 0, theme.body, r),
20959
+ charPr(rows.length + 2, body, false, true, 0, theme.body, r),
20960
+ charPr(rows.length + 3, body, true, true, 0, theme.body, r)
20961
+ );
20869
20962
  }
20870
- if (pendingLabelRow) uniqueRows.push(pendingLabelRow);
20871
- return uniqueRows.length > 0 ? uniqueRows : null;
20963
+ return `<hh:charProperties itemCnt="${rows.length}">
20964
+ ${rows.join("\n")}
20965
+ </hh:charProperties>`;
20872
20966
  }
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);
20967
+ function buildParaProperties(gongmun) {
20968
+ if (!gongmun) {
20969
+ const base2 = [
20970
+ paraPr(0),
20971
+ paraPr(1, { align: "LEFT", spaceBefore: 800, spaceAfter: 200, lineSpacing: 180 }),
20972
+ paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: 170 }),
20973
+ paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: 160 }),
20974
+ paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: 160 }),
20975
+ paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400 }),
20976
+ paraPr(6, { align: "LEFT", lineSpacing: 150, indent: 600 }),
20977
+ paraPr(7, { align: "LEFT", lineSpacing: 160, indent: 600 })
20978
+ ];
20979
+ return `<hh:paraProperties itemCnt="${base2.length}">
20980
+ ${base2.join("\n")}
20981
+ </hh:paraProperties>`;
20882
20982
  }
20883
- return rows;
20884
- }
20885
- function unescapeGfmCell(text) {
20886
- return text.replace(/<br\s*\/?>/gi, "\n").replace(/\\\|/g, "|").replace(/\\~/g, "~");
20983
+ const ls = gongmun.lineSpacing;
20984
+ const titleAlign = gongmun.centerTitle ? "CENTER" : "LEFT";
20985
+ const base = [
20986
+ paraPr(0, { lineSpacing: ls, keepWord: true }),
20987
+ paraPr(1, { align: titleAlign, spaceBefore: 400, spaceAfter: 400, lineSpacing: ls, keepWord: true }),
20988
+ paraPr(2, { align: "LEFT", spaceBefore: 600, spaceAfter: 150, lineSpacing: ls, keepWord: true }),
20989
+ paraPr(3, { align: "LEFT", spaceBefore: 400, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
20990
+ paraPr(4, { align: "LEFT", spaceBefore: 300, spaceAfter: 100, lineSpacing: ls, keepWord: true }),
20991
+ paraPr(5, { align: "LEFT", lineSpacing: 130, indent: 400, keepWord: true }),
20992
+ paraPr(6, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true }),
20993
+ paraPr(7, { align: "LEFT", lineSpacing: ls, indent: 600, keepWord: true })
20994
+ ];
20995
+ for (let d = 0; d < GONGMUN_LIST_LEVELS; d++) {
20996
+ const { left, indent } = levelIndent(d, gongmun.bodyHeight, gongmun.numbering);
20997
+ const sectionGap = gongmun.numbering === "report" && d === 0 ? Math.round(gongmun.bodyHeight * 0.5) : 0;
20998
+ base.push(paraPr(GONGMUN_LIST_BASE + d, { align: "JUSTIFY", lineSpacing: ls, left, indent, spaceBefore: sectionGap, keepWord: true }));
20999
+ }
21000
+ base.push(paraPr(GONGMUN_CENTER, { align: "CENTER", lineSpacing: ls, keepWord: true }));
21001
+ return `<hh:paraProperties itemCnt="${base.length}">
21002
+ ${base.join("\n")}
21003
+ </hh:paraProperties>`;
20887
21004
  }
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>");
20899
- }
20900
- return sanitizeText(cell.text).replace(/\n/g, "<br>");
21005
+ function generateHeaderXml(theme, gongmun, ratioVariants = []) {
21006
+ const bodyFace = _optionalChain([gongmun, 'optionalAccess', _180 => _180.bodyFont]) === "gothic" ? "\uB9D1\uC740 \uACE0\uB515" : "\uD568\uCD08\uB86C\uBC14\uD0D5";
21007
+ const charPropsXml = buildCharProperties(theme, gongmun, ratioVariants);
21008
+ const paraPropsXml = buildParaProperties(gongmun);
21009
+ return `<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
21010
+ <hh:head xmlns:hh="${NS_HEAD}" xmlns:hp="${NS_PARA}" xmlns:hc="${NS_CORE}" version="1.4" secCnt="1">
21011
+ <hh:beginNum page="1" footnote="1" endnote="1" pic="1" tbl="1" equation="1"/>
21012
+ <hh:refList>
21013
+ <hh:fontfaces itemCnt="7">
21014
+ <hh:fontface lang="HANGUL" fontCnt="3">
21015
+ <hh:font id="0" face="${bodyFace}" type="TTF" isEmbedded="0">
21016
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21017
+ </hh:font>
21018
+ <hh:font id="1" face="\uD568\uCD08\uB86C\uB3CB\uC6C0" type="TTF" isEmbedded="0">
21019
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21020
+ </hh:font>
21021
+ <hh:font id="2" face="HY\uACAC\uACE0\uB515" type="TTF" isEmbedded="0">
21022
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="9" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21023
+ </hh:font>
21024
+ </hh:fontface>
21025
+ <hh:fontface lang="LATIN" fontCnt="3">
21026
+ <hh:font id="0" face="Times New Roman" type="TTF" isEmbedded="0">
21027
+ <hh:typeInfo familyType="FCAT_OLDSTYLE" weight="5" proportion="4" contrast="2" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="4"/>
21028
+ </hh:font>
21029
+ <hh:font id="1" face="Consolas" type="TTF" isEmbedded="0">
21030
+ <hh:typeInfo familyType="FCAT_MODERN" weight="5" proportion="0" contrast="0" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="0"/>
21031
+ </hh:font>
21032
+ <hh:font id="2" face="Arial Black" type="TTF" isEmbedded="0">
21033
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="9" proportion="0" contrast="0" strokeVariation="0" armStyle="0" letterform="0" midline="0" xHeight="0"/>
21034
+ </hh:font>
21035
+ </hh:fontface>
21036
+ <hh:fontface lang="HANJA" fontCnt="1">
21037
+ <hh:font id="0" face="\uD568\uCD08\uB86C\uBC14\uD0D5" type="TTF" isEmbedded="0">
21038
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="4" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21039
+ </hh:font>
21040
+ </hh:fontface>
21041
+ <hh:fontface lang="JAPANESE" fontCnt="1">
21042
+ <hh:font id="0" face="\uAD74\uB9BC" type="TTF" isEmbedded="0">
21043
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21044
+ </hh:font>
21045
+ </hh:fontface>
21046
+ <hh:fontface lang="OTHER" fontCnt="1">
21047
+ <hh:font id="0" face="\uAD74\uB9BC" type="TTF" isEmbedded="0">
21048
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21049
+ </hh:font>
21050
+ </hh:fontface>
21051
+ <hh:fontface lang="SYMBOL" fontCnt="1">
21052
+ <hh:font id="0" face="Symbol" type="TTF" isEmbedded="0">
21053
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21054
+ </hh:font>
21055
+ </hh:fontface>
21056
+ <hh:fontface lang="USER" fontCnt="1">
21057
+ <hh:font id="0" face="\uAD74\uB9BC" type="TTF" isEmbedded="0">
21058
+ <hh:typeInfo familyType="FCAT_GOTHIC" weight="6" proportion="0" contrast="0" strokeVariation="1" armStyle="1" letterform="1" midline="1" xHeight="1"/>
21059
+ </hh:font>
21060
+ </hh:fontface>
21061
+ </hh:fontfaces>
21062
+ <hh:borderFills itemCnt="2">
21063
+ <hh:borderFill id="1" threeD="0" shadow="0" centerLine="NONE" breakCellSeparateLine="0">
21064
+ <hh:slash type="NONE" Crooked="0" isCounter="0"/>
21065
+ <hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
21066
+ <hh:leftBorder type="NONE" width="0.1 mm" color="#000000"/>
21067
+ <hh:rightBorder type="NONE" width="0.1 mm" color="#000000"/>
21068
+ <hh:topBorder type="NONE" width="0.1 mm" color="#000000"/>
21069
+ <hh:bottomBorder type="NONE" width="0.1 mm" color="#000000"/>
21070
+ </hh:borderFill>
21071
+ <hh:borderFill id="2" threeD="0" shadow="0" centerLine="NONE" breakCellSeparateLine="0">
21072
+ <hh:slash type="NONE" Crooked="0" isCounter="0"/>
21073
+ <hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
21074
+ <hh:leftBorder type="SOLID" width="0.12 mm" color="#000000"/>
21075
+ <hh:rightBorder type="SOLID" width="0.12 mm" color="#000000"/>
21076
+ <hh:topBorder type="SOLID" width="0.12 mm" color="#000000"/>
21077
+ <hh:bottomBorder type="SOLID" width="0.12 mm" color="#000000"/>
21078
+ </hh:borderFill>
21079
+ </hh:borderFills>
21080
+ ${charPropsXml}
21081
+ <hh:tabProperties itemCnt="0"/>
21082
+ <hh:numberings itemCnt="0"/>
21083
+ <hh:bullets itemCnt="0"/>
21084
+ ${paraPropsXml}
21085
+ <hh:styles itemCnt="1">
21086
+ <hh:style id="0" type="PARA" name="\uBC14\uD0D5\uAE00" engName="Normal" paraPrIDRef="0" charPrIDRef="0" nextStyleIDRef="0" langIDRef="1042" lockForm="0"/>
21087
+ </hh:styles>
21088
+ </hh:refList>
21089
+ <hh:compatibleDocument targetProgram="HWP2018"><hh:layoutCompatibility/></hh:compatibleDocument>
21090
+ </hh:head>`;
20901
21091
  }
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>`);
20915
- }
20916
- lines.push("</table>");
20917
- return lines.join("\n");
21092
+
21093
+ // src/hwpx/gen-gongmun-fit.ts
21094
+ function plainRenderText(text) {
21095
+ return parseInlineMarkdown(text).map((s) => s.text).join("");
20918
21096
  }
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
- });
21097
+ function computeGongmunFitPlan(blocks, gongmun, gongmunList) {
21098
+ const minRatio = gongmun.autoFitMinRatio;
21099
+ if (minRatio === null || minRatio >= GONGMUN_BODY_RATIO) return null;
21100
+ const pageW = 59528 - mmToHwpunit(gongmun.margins.left) - mmToHwpunit(gongmun.margins.right);
21101
+ const ratioByBlock = /* @__PURE__ */ new Map();
21102
+ const variants = [];
21103
+ for (let i = 0; i < blocks.length; i++) {
21104
+ const block = blocks[i];
21105
+ let text;
21106
+ let firstW;
21107
+ let contW;
21108
+ if (block.type === "list_item" && gongmunList.has(i)) {
21109
+ const { marker, depth } = gongmunList.get(i);
21110
+ const content = plainRenderText(block.text || "");
21111
+ text = marker ? `${marker} ${content}` : content;
21112
+ const { left, indent } = levelIndent(depth, gongmun.bodyHeight, gongmun.numbering);
21113
+ firstW = pageW - left - Math.max(indent, 0);
21114
+ contW = pageW - left - Math.max(-indent, 0);
21115
+ } else if (block.type === "paragraph") {
21116
+ const raw = (block.text || "").trim();
21117
+ if (/^<center>[\s\S]*<\/center>$/i.test(raw)) continue;
21118
+ text = plainRenderText(raw);
21119
+ firstW = contW = pageW;
21120
+ } else {
21121
+ continue;
20943
21122
  }
20944
- if (rowCells.length) result.push({ tag, cells: rowCells });
21123
+ if (!text) continue;
21124
+ const r = fitRatioForFewerLines(text, firstW, contW, gongmun.bodyHeight, GONGMUN_BODY_RATIO, minRatio);
21125
+ if (r === null) continue;
21126
+ ratioByBlock.set(i, r);
21127
+ if (!variants.includes(r)) variants.push(r);
20945
21128
  }
20946
- return result;
21129
+ return ratioByBlock.size > 0 ? { ratioByBlock, variants } : null;
20947
21130
  }
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;
21131
+ function variantMapper(fit, blockIdx) {
21132
+ const r = fit.ratioByBlock.get(blockIdx);
21133
+ if (r === void 0) return void 0;
21134
+ const vi = fit.variants.indexOf(r);
21135
+ return (id) => id >= 0 && id <= 3 ? CHAR_VARIANT_BASE + vi * 4 + id : id;
21136
+ }
21137
+ function precomputeGongmunList(blocks, gongmun) {
21138
+ const result = /* @__PURE__ */ new Map();
21139
+ let i = 0;
21140
+ while (i < blocks.length) {
21141
+ if (blocks[i].type !== "list_item") {
21142
+ i++;
20963
21143
  continue;
20964
21144
  }
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;
21145
+ const run = [];
21146
+ while (i < blocks.length) {
21147
+ const t = blocks[i].type;
21148
+ if (t === "list_item") {
21149
+ run.push(i);
21150
+ i++;
21151
+ continue;
20971
21152
  }
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;
21153
+ if (t === "table" || t === "html_table") {
21154
+ let j = i + 1;
21155
+ while (j < blocks.length && (blocks[j].type === "table" || blocks[j].type === "html_table")) j++;
21156
+ if (j < blocks.length && blocks[j].type === "list_item") {
21157
+ i = j;
21158
+ continue;
21159
+ }
20982
21160
  }
21161
+ break;
20983
21162
  }
21163
+ const depths = run.map((bi) => Math.min(Math.max(blocks[bi].indent || 0, 0), GONGMUN_LIST_LEVELS - 1));
21164
+ const suppress = gongmun.numbering === "standard" ? computeSuppression(depths) : depths.map(() => false);
21165
+ const numberer = new GongmunNumberer(gongmun.numbering);
21166
+ run.forEach((bi, k) => {
21167
+ const marker = numberer.next(depths[k], suppress[k]);
21168
+ result.set(bi, { marker, depth: depths[k] });
21169
+ });
20984
21170
  }
20985
- if (depth !== 0) return null;
20986
- return rows;
20987
- }
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 };
21002
- }
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;
21023
- }
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;
21038
- }
21039
- }
21040
- if (depth === 0) result += html.slice(last);
21041
- return result;
21171
+ return result;
21042
21172
  }
21043
21173
 
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
- };
21174
+ // src/diff/text-diff.ts
21175
+ function similarity(a, b) {
21176
+ if (a === b) return 1;
21177
+ if (!a || !b) return 0;
21178
+ const maxLen = Math.max(a.length, b.length);
21179
+ if (maxLen === 0) return 1;
21180
+ return 1 - levenshtein(a, b) / maxLen;
21085
21181
  }
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" });
21182
+ function normalizedSimilarity(a, b) {
21183
+ return similarity(normalize(a), normalize(b));
21101
21184
  }
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;
21185
+ function normalize(s) {
21186
+ return s.replace(/\s+/g, " ").trim();
21187
+ }
21188
+ var MAX_LEVENSHTEIN_LEN = 1e4;
21189
+ function levenshtein(a, b) {
21190
+ if (a.length + b.length > MAX_LEVENSHTEIN_LEN) {
21191
+ const sampleLen = Math.min(500, a.length, b.length);
21192
+ let diffs = 0;
21193
+ for (let i = 0; i < sampleLen; i++) if (a[i] !== b[i]) diffs++;
21194
+ const sampleRate = sampleLen > 0 ? diffs / sampleLen : 1;
21195
+ return Math.abs(a.length - b.length) + Math.round(Math.min(a.length, b.length) * sampleRate);
21112
21196
  }
21113
- return lines.join("\n").slice(0, 1024);
21197
+ if (a.length > b.length) [a, b] = [b, a];
21198
+ const m = a.length;
21199
+ const n = b.length;
21200
+ let prev = Array.from({ length: m + 1 }, (_, i) => i);
21201
+ let curr = new Array(m + 1);
21202
+ for (let j = 1; j <= n; j++) {
21203
+ curr[0] = j;
21204
+ for (let i = 1; i <= m; i++) {
21205
+ if (a[i - 1] === b[j - 1]) {
21206
+ curr[i] = prev[i - 1];
21207
+ } else {
21208
+ curr[i] = 1 + Math.min(prev[i - 1], prev[i], curr[i - 1]);
21209
+ }
21210
+ }
21211
+ ;
21212
+ [prev, curr] = [curr, prev];
21213
+ }
21214
+ return prev[m];
21114
21215
  }
21115
- function parseMarkdownToBlocks(md2) {
21216
+
21217
+ // src/roundtrip/markdown-units.ts
21218
+ function splitMarkdownUnits(md2) {
21116
21219
  const lines = md2.split("\n");
21117
- const blocks = [];
21220
+ const units = [];
21118
21221
  let i = 0;
21119
21222
  while (i < lines.length) {
21120
21223
  const line = lines[i];
@@ -21122,420 +21225,369 @@ function parseMarkdownToBlocks(md2) {
21122
21225
  i++;
21123
21226
  continue;
21124
21227
  }
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 = [];
21228
+ if (line.trim().startsWith("<table>")) {
21229
+ const collected2 = [];
21152
21230
  let depth = 0;
21153
21231
  while (i < lines.length) {
21154
21232
  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;
21233
+ collected2.push(l);
21234
+ depth += (l.match(/<table>/g) || []).length;
21235
+ depth -= (l.match(/<\/table>/g) || []).length;
21158
21236
  i++;
21159
21237
  if (depth <= 0) break;
21160
21238
  }
21161
- blocks.push({ type: "html_table", text: htmlLines.join("\n") });
21239
+ units.push({ kind: "html-table", raw: collected2.join("\n"), lines: collected2 });
21162
21240
  continue;
21163
21241
  }
21164
21242
  if (line.trimStart().startsWith("|")) {
21165
- const tableRows = [];
21243
+ const collected2 = [];
21166
21244
  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);
21245
+ collected2.push(lines[i]);
21174
21246
  i++;
21175
21247
  }
21176
- if (tableRows.length > 0) blocks.push({ type: "table", rows: tableRows });
21248
+ units.push({ kind: "gfm-table", raw: collected2.join("\n"), lines: collected2 });
21177
21249
  continue;
21178
21250
  }
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
- }
21251
+ if (/^-{3,}\s*$/.test(line.trim())) {
21252
+ units.push({ kind: "separator", raw: line.trim(), lines: [line.trim()] });
21253
+ i++;
21188
21254
  continue;
21189
21255
  }
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 });
21256
+ if (/^!\[image\]\([^)]*\)\s*$/.test(line.trim())) {
21257
+ units.push({ kind: "image", raw: line.trim(), lines: [line.trim()] });
21195
21258
  i++;
21196
21259
  continue;
21197
21260
  }
21198
- blocks.push({ type: "paragraph", text: line.trim() });
21199
- i++;
21261
+ const collected = [];
21262
+ while (i < lines.length && lines[i].trim() && !lines[i].trimStart().startsWith("|") && !lines[i].trim().startsWith("<table>")) {
21263
+ collected.push(lines[i].trim());
21264
+ i++;
21265
+ }
21266
+ units.push({ kind: "text", raw: collected.join("\n"), lines: collected });
21200
21267
  }
21201
- return blocks;
21268
+ return units;
21202
21269
  }
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 });
21270
+ function alignUnits(a, b) {
21271
+ const m = a.length, n = b.length;
21272
+ if (m * n > 4e6) {
21273
+ const result2 = [];
21274
+ let pre = 0;
21275
+ while (pre < m && pre < n && a[pre] === b[pre]) {
21276
+ result2.push([pre, pre]);
21277
+ pre++;
21214
21278
  }
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 });
21279
+ let suf = 0;
21280
+ while (suf < m - pre && suf < n - pre && a[m - 1 - suf] === b[n - 1 - suf]) suf++;
21281
+ const aMid = m - pre - suf, bMid = n - pre - suf;
21282
+ if (aMid === bMid) {
21283
+ for (let i2 = 0; i2 < aMid; i2++) result2.push([pre + i2, pre + i2]);
21222
21284
  } else {
21223
- spans.push({ text: raw.slice(1, -1), bold: false, italic: true, code: false });
21285
+ for (let i2 = 0; i2 < aMid; i2++) result2.push([pre + i2, null]);
21286
+ for (let j2 = 0; j2 < bMid; j2++) result2.push([null, pre + j2]);
21224
21287
  }
21225
- lastIdx = idx + raw.length;
21226
- }
21227
- if (lastIdx < text.length) {
21228
- spans.push({ text: text.slice(lastIdx), bold: false, italic: false, code: false });
21288
+ for (let s = suf - 1; s >= 0; s--) result2.push([m - 1 - s, n - 1 - s]);
21289
+ return result2;
21229
21290
  }
21230
- if (spans.length === 0) {
21231
- spans.push({ text, bold: false, italic: false, code: false });
21291
+ const dp = Array.from({ length: m + 1 }, () => new Int32Array(n + 1));
21292
+ for (let i2 = 1; i2 <= m; i2++) {
21293
+ for (let j2 = 1; j2 <= n; j2++) {
21294
+ 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]);
21295
+ }
21232
21296
  }
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;
21297
+ const matches = [];
21298
+ let i = m, j = n;
21299
+ while (i > 0 && j > 0) {
21300
+ if (a[i - 1] === b[j - 1] && dp[i][j] === dp[i - 1][j - 1] + 1) {
21301
+ matches.push([i - 1, j - 1]);
21302
+ i--;
21303
+ j--;
21304
+ } else if (dp[i - 1][j] >= dp[i][j - 1]) i--;
21305
+ else j--;
21306
+ }
21307
+ matches.reverse();
21308
+ const result = [];
21309
+ let ai = 0, bi = 0;
21310
+ const flushGap = (aEnd, bEnd) => {
21311
+ if (aEnd - ai === bEnd - bi) {
21312
+ while (ai < aEnd) result.push([ai++, bi++]);
21313
+ return;
21314
+ }
21315
+ while (ai < aEnd && bi < bEnd) {
21316
+ const sim = normalizedSimilarity(a[ai], b[bi]);
21317
+ if (sim >= 0.4) {
21318
+ if (aEnd - ai > bEnd - bi && bestSimInRange(a, ai + 1, ai + (aEnd - ai) - (bEnd - bi), b[bi]) > sim) {
21319
+ result.push([ai++, null]);
21320
+ } else if (bEnd - bi > aEnd - ai && bestSimInRange(b, bi + 1, bi + (bEnd - bi) - (aEnd - ai), a[ai]) > sim) {
21321
+ result.push([null, bi++]);
21322
+ } else {
21323
+ result.push([ai++, bi++]);
21324
+ }
21325
+ } else if (aEnd - ai >= bEnd - bi) result.push([ai++, null]);
21326
+ else result.push([null, bi++]);
21327
+ }
21328
+ while (ai < aEnd) result.push([ai++, null]);
21329
+ while (bi < bEnd) result.push([null, bi++]);
21330
+ };
21331
+ for (const [pi, pj] of matches) {
21332
+ flushGap(pi, pj);
21333
+ result.push([ai++, bi++]);
21334
+ }
21335
+ flushGap(m, n);
21336
+ return result;
21241
21337
  }
21242
- function escapeXml(text) {
21243
- return text.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;");
21338
+ function bestSimInRange(arr, from, to, target) {
21339
+ let best = 0;
21340
+ for (let k = from; k <= to && k < arr.length; k++) {
21341
+ const s = normalizedSimilarity(arr[k], target);
21342
+ if (s > best) best = s;
21343
+ }
21344
+ return best;
21244
21345
  }
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("");
21346
+ function escapeGfm(text) {
21347
+ return text.replace(/~/g, "\\~");
21252
21348
  }
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>`;
21349
+ var HWP_SHAPE_ALT_TEXT_RE = /(?:모서리가 둥근 |둥근 )?(?:사각형|직사각형|정사각형|원|타원|삼각형|이등변 삼각형|직각 삼각형|선|직선|곡선|화살표|굵은 화살표|이중 화살표|오각형|육각형|팔각형|별|[4-8]점별|십자|십자형|구름|구름형|마름모|도넛|평행사변형|사다리꼴|부채꼴|호|반원|물결|번개|하트|빗금|블록 화살표|수식|표|그림|개체|그리기\s?개체|묶음\s?개체|글상자|수식\s?개체|OLE\s?개체)\s?입니다\.?/g;
21350
+ function sanitizeText(text) {
21351
+ let result = _chunkXL6O3VAYcjs.mapPuaText.call(void 0, text).replace(/[\u{F0000}-\u{FFFFD}]/gu, "").replace(HWP_SHAPE_ALT_TEXT_RE, "").replace(/ +/g, " ").trim();
21352
+ if (result.length <= 30 && result.includes(" ")) {
21353
+ const tokens = result.split(" ");
21354
+ const koreanSingleCharCount = tokens.filter((t) => t.length === 1 && /[가-힯ㄱ-ㆎ]/.test(t)).length;
21355
+ if (tokens.length >= 3 && koreanSingleCharCount / tokens.length >= 0.7) {
21356
+ result = tokens.join("");
21357
+ }
21256
21358
  }
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;
21359
+ return result;
21265
21360
  }
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;
21361
+ function normForMatch(text) {
21362
+ return sanitizeText(text).replace(/\s+/g, " ").trim();
21271
21363
  }
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>`;
21364
+ function unescapeGfm(text) {
21365
+ return text.replace(/\\~/g, "~");
21279
21366
  }
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>`;
21367
+ function summarize(text) {
21368
+ const t = text.replace(/\s+/g, " ").trim();
21369
+ return t.length > 80 ? t.slice(0, 77) + "..." : t;
21292
21370
  }
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>`;
21371
+ function replicateGfmTable(table) {
21372
+ const { cells, rows: numRows, cols: numCols } = table;
21373
+ if (numRows === 0 || numCols === 0) return null;
21374
+ if (numRows === 1 && numCols === 1) return null;
21375
+ if (numCols === 1) return null;
21376
+ const display = Array.from({ length: numRows }, (_, r) => Array.from({ length: numCols }, (_2, c) => ({ text: "", gridR: r, gridC: c })));
21377
+ const skip = /* @__PURE__ */ new Set();
21378
+ for (let r = 0; r < numRows; r++) {
21379
+ for (let c = 0; c < numCols; c++) {
21380
+ if (skip.has(`${r},${c}`)) continue;
21381
+ const cell = _optionalChain([cells, 'access', _181 => _181[r], 'optionalAccess', _182 => _182[c]]);
21382
+ if (!cell) continue;
21383
+ display[r][c] = {
21384
+ text: escapeGfm(sanitizeText(cell.text)).replace(/\|/g, "\\|").replace(/\n/g, "<br>"),
21385
+ gridR: r,
21386
+ gridC: c
21387
+ };
21388
+ for (let dr = 0; dr < cell.rowSpan; dr++) {
21389
+ for (let dc = 0; dc < cell.colSpan; dc++) {
21390
+ if (dr === 0 && dc === 0) continue;
21391
+ if (r + dr < numRows && c + dc < numCols) skip.add(`${r + dr},${c + dc}`);
21392
+ }
21393
+ }
21394
+ c += cell.colSpan - 1;
21395
+ }
21396
+ }
21397
+ const uniqueRows = [];
21398
+ let pendingLabelRow = null;
21399
+ for (let r = 0; r < display.length; r++) {
21400
+ const row = display[r];
21401
+ if (row.every((cell) => cell.text === "")) continue;
21402
+ const nonEmptyCols = row.filter((cell) => cell.text !== "");
21403
+ const hasSkipInRow = row.some((_, c) => skip.has(`${r},${c}`));
21404
+ if (!hasSkipInRow && nonEmptyCols.length === 1 && row[0].text !== "" && row.slice(1).every((c) => c.text === "")) {
21405
+ if (pendingLabelRow) uniqueRows.push(pendingLabelRow);
21406
+ pendingLabelRow = row;
21407
+ continue;
21408
+ }
21409
+ if (pendingLabelRow) {
21410
+ if (row[0].text === "") row[0] = pendingLabelRow[0];
21411
+ else uniqueRows.push(pendingLabelRow);
21412
+ pendingLabelRow = null;
21413
+ }
21414
+ uniqueRows.push(row);
21415
+ }
21416
+ if (pendingLabelRow) uniqueRows.push(pendingLabelRow);
21417
+ return uniqueRows.length > 0 ? uniqueRows : null;
21304
21418
  }
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>`;
21419
+ function parseGfmTable(lines) {
21420
+ const rows = [];
21421
+ for (const line of lines) {
21422
+ const trimmed = line.trim();
21423
+ if (!trimmed.startsWith("|")) continue;
21424
+ const cells = trimmed.split(/(?<!\\)\|/).slice(1, -1).map((c) => c.trim());
21425
+ if (cells.length === 0) continue;
21426
+ if (cells.every((c) => /^:?-{3,}:?$/.test(c))) continue;
21427
+ rows.push(cells);
21428
+ }
21429
+ return rows;
21318
21430
  }
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("");
21431
+ function unescapeGfmCell(text) {
21432
+ return text.replace(/<br\s*\/?>/gi, "\n").replace(/\\\|/g, "|").replace(/\\~/g, "~");
21326
21433
  }
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 {
21351
- continue;
21352
- }
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);
21434
+ function replicateCellInnerHtml(cell) {
21435
+ if (_optionalChain([cell, 'access', _183 => _183.blocks, 'optionalAccess', _184 => _184.length])) {
21436
+ return cell.blocks.map((b) => {
21437
+ if (b.type === "table" && b.table) {
21438
+ const cap = b.table.caption ? sanitizeText(b.table.caption) : "";
21439
+ return (cap ? cap + "<br>" : "") + replicateTableToHtml(b.table);
21440
+ }
21441
+ if (b.type === "image" && b.text) return `<img src="${b.text}" alt="image">`;
21442
+ const t = sanitizeText(_nullishCoalesce(b.text, () => ( "")));
21443
+ return t ? t.replace(/\n/g, "<br>") : "";
21444
+ }).filter(Boolean).join("<br>");
21358
21445
  }
21359
- return ratioByBlock.size > 0 ? { ratioByBlock, variants } : null;
21446
+ return sanitizeText(cell.text).replace(/\n/g, "<br>");
21360
21447
  }
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;
21448
+ function replicateTableToHtml(table) {
21449
+ const rows = replicateHtmlTable(table);
21450
+ const lines = ["<table>"];
21451
+ for (let r = 0; r < rows.length; r++) {
21452
+ const tag = rows[r].tag;
21453
+ const rowHtml = rows[r].cells.map((cell) => {
21454
+ const attrs = [];
21455
+ if (cell.colSpan > 1) attrs.push(`colspan="${cell.colSpan}"`);
21456
+ if (cell.rowSpan > 1) attrs.push(`rowspan="${cell.rowSpan}"`);
21457
+ const attrStr = attrs.length ? " " + attrs.join(" ") : "";
21458
+ return `<${tag}${attrStr}>${cell.inner}</${tag}>`;
21459
+ });
21460
+ if (rowHtml.length) lines.push(`<tr>${rowHtml.join("")}</tr>`);
21461
+ }
21462
+ lines.push("</table>");
21463
+ return lines.join("\n");
21366
21464
  }
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);
21465
+ function replicateHtmlTable(table) {
21466
+ const { cells, rows: numRows, cols: numCols } = table;
21467
+ const skip = /* @__PURE__ */ new Set();
21468
+ const result = [];
21469
+ for (let r = 0; r < numRows; r++) {
21470
+ const tag = r === 0 ? "th" : "td";
21471
+ const rowCells = [];
21472
+ for (let c = 0; c < numCols; c++) {
21473
+ if (skip.has(`${r},${c}`)) continue;
21474
+ const cell = _optionalChain([cells, 'access', _185 => _185[r], 'optionalAccess', _186 => _186[c]]);
21475
+ if (!cell) continue;
21476
+ for (let dr = 0; dr < cell.rowSpan; dr++) {
21477
+ for (let dc = 0; dc < cell.colSpan; dc++) {
21478
+ if (dr === 0 && dc === 0) continue;
21479
+ if (r + dr < numRows && c + dc < numCols) skip.add(`${r + dr},${c + dc}`);
21480
+ }
21481
+ }
21482
+ rowCells.push({
21483
+ inner: replicateCellInnerHtml(cell),
21484
+ colSpan: cell.colSpan,
21485
+ rowSpan: cell.rowSpan,
21486
+ gridR: r,
21487
+ gridC: c
21488
+ });
21489
+ }
21490
+ if (rowCells.length) result.push({ tag, cells: rowCells });
21376
21491
  }
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
- );
21492
+ return result;
21493
+ }
21494
+ function parseHtmlTable(raw) {
21495
+ const re = /<(\/?)(table|tr|td|th)((?:"[^"]*"|'[^']*'|[^>"'])*?)>/gi;
21496
+ let depth = 0;
21497
+ let currentRow = null;
21498
+ let cellStart = -1;
21499
+ let cellInfo = null;
21500
+ const rows = [];
21501
+ let m;
21502
+ while ((m = re.exec(raw)) !== null) {
21503
+ const isClose = m[1] === "/";
21504
+ const tag = m[2].toLowerCase();
21505
+ const attrs = m[3] || "";
21506
+ if (tag === "table") {
21507
+ depth += isClose ? -1 : 1;
21508
+ if (depth < 0) return null;
21509
+ continue;
21510
+ }
21511
+ if (depth !== 1) continue;
21512
+ if (tag === "tr") {
21513
+ if (!isClose) currentRow = [];
21514
+ else if (currentRow) {
21515
+ rows.push({ tag: rows.length === 0 ? "th" : "td", cells: currentRow });
21516
+ currentRow = null;
21517
+ }
21518
+ } else {
21519
+ if (!isClose) {
21520
+ const cs = parseInt(_optionalChain([attrs, 'access', _187 => _187.match, 'call', _188 => _188(/colspan\s*=\s*"(\d+)"/i), 'optionalAccess', _189 => _189[1]]) || "1", 10);
21521
+ const rs = parseInt(_optionalChain([attrs, 'access', _190 => _190.match, 'call', _191 => _191(/rowspan\s*=\s*"(\d+)"/i), 'optionalAccess', _192 => _192[1]]) || "1", 10);
21522
+ cellStart = m.index + m[0].length;
21523
+ cellInfo = { colSpan: isNaN(cs) ? 1 : cs, rowSpan: isNaN(rs) ? 1 : rs };
21524
+ } else if (cellStart >= 0 && cellInfo && currentRow) {
21525
+ currentRow.push({ inner: raw.slice(cellStart, m.index), colSpan: cellInfo.colSpan, rowSpan: cellInfo.rowSpan });
21526
+ cellStart = -1;
21527
+ cellInfo = null;
21528
+ }
21529
+ }
21398
21530
  }
21399
- return `<hh:charProperties itemCnt="${rows.length}">
21400
- ${rows.join("\n")}
21401
- </hh:charProperties>`;
21531
+ if (depth !== 0) return null;
21532
+ return rows;
21402
21533
  }
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>`;
21534
+ var AUTONUM_PREFIX_RE = /^(?:[0-90-9a-zA-Z가-힣]{1,6}[.)\]:]|[([][0-90-9a-zA-Z가-힣]{1,6}[)\]][.:]?|[ⅰ-ⅹⅠ-Ⅹ①-⑮][.)\]:]?)$/u;
21535
+ function htmlCellInnerToLines(inner) {
21536
+ let hadNonText = false;
21537
+ let work = inner;
21538
+ if (/<table[\s>]/i.test(work)) {
21539
+ hadNonText = true;
21540
+ work = removeNestedTables(work);
21418
21541
  }
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 }));
21542
+ if (/<img\s/i.test(work)) {
21543
+ hadNonText = true;
21544
+ work = work.replace(/<img\s(?:"[^"]*"|'[^']*'|[^>"'])*?>/gi, "");
21435
21545
  }
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>`;
21546
+ const lines = work.split(/<br\s*\/?>/gi).map((s) => s.trim()).filter((s) => s.length > 0);
21547
+ return { lines, hadNonText };
21440
21548
  }
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>`;
21549
+ function extractTopLevelTables(html) {
21550
+ const result = [];
21551
+ let depth = 0;
21552
+ let start = -1;
21553
+ const re = /<(\/?)table(?:[\s>]|>)/gi;
21554
+ let m;
21555
+ while ((m = re.exec(html)) !== null) {
21556
+ if (m[1] !== "/") {
21557
+ if (depth === 0) start = m.index;
21558
+ depth++;
21559
+ } else {
21560
+ depth--;
21561
+ if (depth === 0 && start >= 0) {
21562
+ result.push(html.slice(start, m.index + m[0].length));
21563
+ start = -1;
21564
+ }
21565
+ if (depth < 0) depth = 0;
21566
+ }
21567
+ }
21568
+ return result;
21527
21569
  }
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>`;
21570
+ function removeNestedTables(html) {
21571
+ let result = "";
21572
+ let depth = 0;
21573
+ const re = /<(\/?)table(?:[\s>]|>)/gi;
21574
+ let last = 0;
21575
+ let m;
21576
+ while ((m = re.exec(html)) !== null) {
21577
+ if (m[1] !== "/") {
21578
+ if (depth === 0) result += html.slice(last, m.index);
21579
+ depth++;
21580
+ } else {
21581
+ depth--;
21582
+ if (depth === 0) last = m.index + m[0].length;
21583
+ if (depth < 0) depth = 0;
21584
+ }
21585
+ }
21586
+ if (depth === 0) result += html.slice(last);
21587
+ return result;
21538
21588
  }
21589
+
21590
+ // src/hwpx/gen-table.ts
21539
21591
  var TABLE_ID_BASE = 1e3;
21540
21592
  var tableIdCounter = TABLE_ID_BASE;
21541
21593
  function nextTableId() {
@@ -21625,41 +21677,18 @@ function generateHtmlTableXml(rawHtml, theme, totalWidth = 44e3) {
21625
21677
  }
21626
21678
  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
21679
  }
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;
21680
+
21681
+ // src/hwpx/gen-section.ts
21682
+ function generateSecPr(gongmun) {
21683
+ const m = gongmun ? {
21684
+ top: mmToHwpunit(gongmun.margins.top),
21685
+ bottom: mmToHwpunit(gongmun.margins.bottom),
21686
+ left: mmToHwpunit(gongmun.margins.left),
21687
+ right: mmToHwpunit(gongmun.margins.right),
21688
+ header: 0,
21689
+ footer: 0
21690
+ } : { top: 8504, bottom: 4252, left: 5670, right: 4252, header: 2835, footer: 2835 };
21691
+ 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
21692
  }
21664
21693
  function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? precomputeGongmunList(blocks, gongmun) : null, fit = null) {
21665
21694
  const paraXmls = [];
@@ -21706,8 +21735,8 @@ function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? prec
21706
21735
  case "list_item": {
21707
21736
  if (gongmun && gongmunList) {
21708
21737
  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]), () => ( ""));
21738
+ const depth = _nullishCoalesce(_optionalChain([info, 'optionalAccess', _193 => _193.depth]), () => ( 0));
21739
+ const marker2 = _nullishCoalesce(_optionalChain([info, 'optionalAccess', _194 => _194.marker]), () => ( ""));
21711
21740
  const content = block.text || "";
21712
21741
  const text = marker2 ? `${marker2} ${content}` : content;
21713
21742
  const listCharPr = gongmun.numbering === "report" && depth === 0 ? CHAR_BOLD : CHAR_NORMAL;
@@ -21782,6 +21811,24 @@ function blocksToSectionXml(blocks, theme, gongmun, gongmunList = gongmun ? prec
21782
21811
  </hs:sec>`;
21783
21812
  }
21784
21813
 
21814
+ // src/hwpx/generator.ts
21815
+ async function markdownToHwpx(markdown, options) {
21816
+ const theme = resolveTheme(_optionalChain([options, 'optionalAccess', _195 => _195.theme]));
21817
+ const gongmun = _optionalChain([options, 'optionalAccess', _196 => _196.gongmun]) ? resolveGongmun(options.gongmun) : null;
21818
+ const blocks = parseMarkdownToBlocks(markdown);
21819
+ const gongmunList = gongmun ? precomputeGongmunList(blocks, gongmun) : null;
21820
+ const fit = gongmun && gongmunList ? computeGongmunFitPlan(blocks, gongmun, gongmunList) : null;
21821
+ const sectionXml = blocksToSectionXml(blocks, theme, gongmun, gongmunList, fit);
21822
+ const zip = new (0, _jszip2.default)();
21823
+ zip.file("mimetype", "application/hwp+zip", { compression: "STORE" });
21824
+ zip.file("META-INF/container.xml", generateContainerXml());
21825
+ zip.file("Contents/content.hpf", generateManifest());
21826
+ zip.file("Contents/header.xml", generateHeaderXml(theme, gongmun, _nullishCoalesce(_optionalChain([fit, 'optionalAccess', _197 => _197.variants]), () => ( []))));
21827
+ zip.file("Contents/section0.xml", sectionXml);
21828
+ zip.file("Preview/PrvText.txt", buildPrvText(blocks));
21829
+ return await zip.generateAsync({ type: "arraybuffer" });
21830
+ }
21831
+
21785
21832
  // src/diff/compare.ts
21786
21833
  var SIMILARITY_THRESHOLD = 0.4;
21787
21834
  async function compare(bufferA, bufferB, options) {
@@ -21924,7 +21971,7 @@ var ROW_OBJECT_RE = /<(?:[A-Za-z0-9_]+:)?(?:tbl|pic|equation|ole|container|shape
21924
21971
  var TAG_AT_RE = /<[A-Za-z0-9_:]+(?:"[^"]*"|'[^']*'|[^>"'])*>/y;
21925
21972
  function patchTableRows(input) {
21926
21973
  const { table, scanTable, ctx, skip, origKeys, editedKeys } = input;
21927
- const xml = _optionalChain([ctx, 'access', _196 => _196.scans, 'access', _197 => _197[scanTable.sectionIndex], 'optionalAccess', _198 => _198.xml]);
21974
+ const xml = _optionalChain([ctx, 'access', _198 => _198.scans, 'access', _199 => _199[scanTable.sectionIndex], 'optionalAccess', _200 => _200.xml]);
21928
21975
  if (!xml) return skip("\uC139\uC158 XML \uB9E4\uD551 \uC2E4\uD328");
21929
21976
  const numRows = table.rows;
21930
21977
  if (origKeys.length !== numRows) return skip("\uD45C \uD589 \uC88C\uD45C \uBD88\uC77C\uCE58 \u2014 \uD589 \uCD94\uAC00/\uC0AD\uC81C \uBBF8\uC9C0\uC6D0");
@@ -22091,7 +22138,7 @@ function buildRowFragment(xml, scanTable, template, cells, finalRow, hasExplicit
22091
22138
  const rr = scanTable.rowRanges[template];
22092
22139
  const wrapped = FRAG_OPEN + xml.slice(rr.start, rr.end) + FRAG_CLOSE;
22093
22140
  const scan = scanSectionXml(wrapped, 0);
22094
- const row = _optionalChain([scan, 'access', _199 => _199.tables, 'access', _200 => _200[0], 'optionalAccess', _201 => _201.rows, 'access', _202 => _202[0]]);
22141
+ const row = _optionalChain([scan, 'access', _201 => _201.tables, 'access', _202 => _202[0], 'optionalAccess', _203 => _203.rows, 'access', _204 => _204[0]]);
22095
22142
  if (!row || row.length !== cells.length) return null;
22096
22143
  const splices = allLinesegRemovalSplices(wrapped);
22097
22144
  for (let i = 0; i < cells.length; i++) {
@@ -22134,7 +22181,7 @@ function rowHeightOf(fragment) {
22134
22181
  }
22135
22182
  function tableSzHeightSplice(xml, scanTable, tblOpenLen, delta) {
22136
22183
  const from = scanTable.start + tblOpenLen;
22137
- const to = _nullishCoalesce(_optionalChain([scanTable, 'access', _203 => _203.rowRanges, 'access', _204 => _204[0], 'optionalAccess', _205 => _205.start]), () => ( from));
22184
+ const to = _nullishCoalesce(_optionalChain([scanTable, 'access', _205 => _205.rowRanges, 'access', _206 => _206[0], 'optionalAccess', _207 => _207.start]), () => ( from));
22138
22185
  const slice = xml.slice(from, to);
22139
22186
  const szM = slice.match(/<(?:[A-Za-z0-9_]+:)?sz\b(?:"[^"]*"|'[^']*'|[^>"'])*>/);
22140
22187
  if (!szM || szM.index === void 0) return null;
@@ -22323,9 +22370,9 @@ function patchHtmlTableRows(table, scanTable, replica, editedRows, ctx, skip, de
22323
22370
  });
22324
22371
  }
22325
22372
  function patchNestedTables(table, scanTable, oc, origTables, editedTables, ctx, skip, depth) {
22326
- const irCell = _optionalChain([table, 'access', _206 => _206.cells, 'access', _207 => _207[oc.gridR], 'optionalAccess', _208 => _208[oc.gridC]]);
22373
+ const irCell = _optionalChain([table, 'access', _208 => _208.cells, 'access', _209 => _209[oc.gridR], 'optionalAccess', _210 => _210[oc.gridC]]);
22327
22374
  const scanCell = scanTable.cellByAnchor.get(`${oc.gridR},${oc.gridC}`);
22328
- const nestedIRs = (_nullishCoalesce(_optionalChain([irCell, 'optionalAccess', _209 => _209.blocks]), () => ( []))).filter((b) => b.type === "table" && b.table).map((b) => b.table);
22375
+ const nestedIRs = (_nullishCoalesce(_optionalChain([irCell, 'optionalAccess', _211 => _211.blocks]), () => ( []))).filter((b) => b.type === "table" && b.table).map((b) => b.table);
22329
22376
  if (!scanCell || nestedIRs.length !== origTables.length || scanCell.tables.length !== origTables.length) {
22330
22377
  return skip("\uC911\uCCA9\uD45C \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328");
22331
22378
  }
@@ -22393,7 +22440,7 @@ function applyCellEdit(table, scanTable, gridR, gridC, newLines, ctx, before, af
22393
22440
  };
22394
22441
  const cell = scanTable.cellByAnchor.get(`${gridR},${gridC}`);
22395
22442
  if (!cell) return skip("\uC140 \uC88C\uD45C \uB9E4\uD551 \uC2E4\uD328 (\uBCD1\uD569 \uC601\uC5ED\uC758 \uBE48 \uCE78\uC774\uAC70\uB098 \uC88C\uD45C \uBD88\uC77C\uCE58)");
22396
- const irCell = _optionalChain([table, 'access', _210 => _210.cells, 'access', _211 => _211[gridR], 'optionalAccess', _212 => _212[gridC]]);
22443
+ const irCell = _optionalChain([table, 'access', _212 => _212.cells, 'access', _213 => _213[gridR], 'optionalAccess', _214 => _214[gridC]]);
22397
22444
  const scanJoined = cell.paragraphs.map((p) => p.text).filter((t) => normForMatch(t)).join("\n");
22398
22445
  if (irCell && normForMatch(scanJoined) !== normForMatch(stripCellTokens(irCell.text))) {
22399
22446
  if (normForMatch(irCell.text) !== "" || normForMatch(scanJoined) !== "") {
@@ -22416,7 +22463,7 @@ function applyCellEdit(table, scanTable, gridR, gridC, newLines, ctx, before, af
22416
22463
  if (newLines.length === 0) return 0;
22417
22464
  const target = cell.paragraphs[0];
22418
22465
  if (!target) return skip("\uBE48 \uC140\uC5D0 \uBB38\uB2E8\uC774 \uC5C6\uC5B4 \uD14D\uC2A4\uD2B8 \uC0BD\uC785 \uBD88\uAC00");
22419
- const sp = buildParagraphSplices(target, newLines.join(" "), _optionalChain([ctx, 'access', _213 => _213.scans, 'access', _214 => _214[target.sectionIndex], 'optionalAccess', _215 => _215.xml]));
22466
+ const sp = buildParagraphSplices(target, newLines.join(" "), _optionalChain([ctx, 'access', _215 => _215.scans, 'access', _216 => _216[target.sectionIndex], 'optionalAccess', _217 => _217.xml]));
22420
22467
  if (sp === null) return skip("\uC140 \uBB38\uB2E8\uC5D0 \uD14D\uC2A4\uD2B8 \uB178\uB4DC\uB97C \uB9CC\uB4E4 \uC218 \uC5C6\uC74C");
22421
22468
  splices.push(...sp);
22422
22469
  sectionIndex = target.sectionIndex;
@@ -22439,7 +22486,7 @@ function applyCellEdit(table, scanTable, gridR, gridC, newLines, ctx, before, af
22439
22486
  }
22440
22487
  for (let i = 0; i < nonEmpty.length; i++) {
22441
22488
  if (assigned[i] === nonEmpty[i].text || normForMatch(assigned[i]) === normForMatch(nonEmpty[i].text)) continue;
22442
- const sp = buildParagraphSplices(nonEmpty[i], assigned[i], _optionalChain([ctx, 'access', _216 => _216.scans, 'access', _217 => _217[nonEmpty[i].sectionIndex], 'optionalAccess', _218 => _218.xml]));
22489
+ const sp = buildParagraphSplices(nonEmpty[i], assigned[i], _optionalChain([ctx, 'access', _218 => _218.scans, 'access', _219 => _219[nonEmpty[i].sectionIndex], 'optionalAccess', _220 => _220.xml]));
22443
22490
  if (sp === null) return skip("\uC140 \uBB38\uB2E8\uC5D0 \uD14D\uC2A4\uD2B8 \uB178\uB4DC\uB97C \uB9CC\uB4E4 \uC218 \uC5C6\uC74C");
22444
22491
  splices.push(...sp);
22445
22492
  sectionIndex = nonEmpty[i].sectionIndex;
@@ -22520,7 +22567,7 @@ async function resolveSectionEntryNames(zip) {
22520
22567
  const paths = sectionPathsFromManifest(xml).filter((p) => zip.file(p) !== null);
22521
22568
  if (paths.length > 0) return paths;
22522
22569
  }
22523
- return Object.keys(zip.files).filter((n) => /[Ss]ection\d+\.xml$/.test(n)).sort(_chunkLFCS3UVGcjs.compareSectionPaths);
22570
+ return Object.keys(zip.files).filter((n) => /[Ss]ection\d+\.xml$/.test(n)).sort(_chunkXL6O3VAYcjs.compareSectionPaths);
22524
22571
  }
22525
22572
  function sectionPathsFromManifest(xml) {
22526
22573
  const attr = (tag, name) => {
@@ -22530,7 +22577,7 @@ function sectionPathsFromManifest(xml) {
22530
22577
  const idToHref = /* @__PURE__ */ new Map();
22531
22578
  for (const m of xml.matchAll(/<opf:item(\s(?:"[^"]*"|'[^']*'|[^>"'])*?)\/?>/g)) {
22532
22579
  const id = attr(m[1], "id");
22533
- const href = _chunkLFCS3UVGcjs.normalizeSectionHref.call(void 0, attr(m[1], "href"));
22580
+ const href = _chunkXL6O3VAYcjs.normalizeSectionHref.call(void 0, attr(m[1], "href"));
22534
22581
  if (id && href) idToHref.set(id, href);
22535
22582
  }
22536
22583
  const ordered = [];
@@ -22539,7 +22586,7 @@ function sectionPathsFromManifest(xml) {
22539
22586
  if (href) ordered.push(href);
22540
22587
  }
22541
22588
  if (ordered.length > 0) return ordered;
22542
- return Array.from(idToHref.values()).sort(_chunkLFCS3UVGcjs.compareSectionPaths);
22589
+ return Array.from(idToHref.values()).sort(_chunkXL6O3VAYcjs.compareSectionPaths);
22543
22590
  }
22544
22591
 
22545
22592
  // src/roundtrip/patcher.ts
@@ -22631,7 +22678,7 @@ async function patchHwpx(original, editedMarkdown, options) {
22631
22678
  }
22632
22679
  }
22633
22680
  let verification;
22634
- if (_optionalChain([options, 'optionalAccess', _219 => _219.verify]) !== false) {
22681
+ if (_optionalChain([options, 'optionalAccess', _221 => _221.verify]) !== false) {
22635
22682
  try {
22636
22683
  const reparsed = await parseHwpxDocument(u8ToArrayBuffer(data));
22637
22684
  verification = diffUnitLists(splitMarkdownUnits(reparsed.markdown), editedUnits);
@@ -22649,17 +22696,17 @@ function buildOrigUnits(blocks) {
22649
22696
  let chunk;
22650
22697
  if (block.type === "paragraph" && block.text && /^\[별표\s*\d+/.test(sanitizeText(block.text))) {
22651
22698
  const next = blocks[i + 1];
22652
- 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));
22699
+ if (_optionalChain([next, 'optionalAccess', _222 => _222.type]) === "paragraph" && next.text && /관련\)?$/.test(next.text)) consume = 2;
22700
+ chunk = _chunkXL6O3VAYcjs.blocksToMarkdown.call(void 0, blocks.slice(i, i + consume));
22654
22701
  } else {
22655
- chunk = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, [block]);
22702
+ chunk = _chunkXL6O3VAYcjs.blocksToMarkdown.call(void 0, [block]);
22656
22703
  }
22657
22704
  if (chunk) {
22658
22705
  const subUnits = splitMarkdownUnits(chunk);
22659
22706
  const isFragment = consume === 2 || (block.type === "paragraph" || block.type === "heading") && subUnits.length > 1;
22660
22707
  for (let s = 0; s < subUnits.length; s++) {
22661
22708
  const u = { ...subUnits[s], blockIdx: i, fragment: isFragment || void 0 };
22662
- if (block.type === "table" && _optionalChain([block, 'access', _221 => _221.table, 'optionalAccess', _222 => _222.caption]) && s === 0 && subUnits.length > 1 && u.kind === "text" && u.raw.startsWith("**")) {
22709
+ if (block.type === "table" && _optionalChain([block, 'access', _223 => _223.table, 'optionalAccess', _224 => _224.caption]) && s === 0 && subUnits.length > 1 && u.kind === "text" && u.raw.startsWith("**")) {
22663
22710
  u.role = "caption";
22664
22711
  }
22665
22712
  units.push(u);
@@ -22770,7 +22817,7 @@ function convertParagraphToTable(block, orig, edited, ctx, skip) {
22770
22817
  const ti = ctx.tableInsert;
22771
22818
  if (!ti) return skip("\uBB38\uB2E8\u2192\uD45C \uBCC0\uD658 \uBD88\uAC00 \u2014 header \uC5D4\uD2B8\uB9AC(borderFills) \uD574\uC11D \uC2E4\uD328");
22772
22819
  const mapping = ctx.paraMap.get(orig.blockIdx);
22773
- if (!_optionalChain([mapping, 'optionalAccess', _223 => _223.para])) return skip("\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED) \u2014 \uD45C \uBCC0\uD658 \uBD88\uAC00");
22820
+ if (!_optionalChain([mapping, 'optionalAccess', _225 => _225.para])) return skip("\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED) \u2014 \uD45C \uBCC0\uD658 \uBD88\uAC00");
22774
22821
  const para = mapping.para;
22775
22822
  if (para.kind !== "body") return skip("\uBCF8\uBB38 \uC678 \uC601\uC5ED(\uD45C \uC140/\uAE00\uC0C1\uC790) \uBB38\uB2E8\uC758 \uD45C \uBCC0\uD658\uC740 \uBBF8\uC9C0\uC6D0");
22776
22823
  const scan = ctx.scans[para.sectionIndex];
@@ -22798,7 +22845,7 @@ function convertParagraphToTable(block, orig, edited, ctx, skip) {
22798
22845
  }
22799
22846
  function patchParagraphUnit(block, orig, edited, ctx, skip) {
22800
22847
  const mapping = ctx.paraMap.get(orig.blockIdx);
22801
- if (!_optionalChain([mapping, 'optionalAccess', _224 => _224.para])) return skip("\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED\uC774\uAC70\uB098 \uD14D\uC2A4\uD2B8 \uBD88\uC77C\uCE58)");
22848
+ if (!_optionalChain([mapping, 'optionalAccess', _226 => _226.para])) return skip("\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED\uC774\uAC70\uB098 \uD14D\uC2A4\uD2B8 \uBD88\uC77C\uCE58)");
22802
22849
  if (block.text && block.text.includes("\n")) {
22803
22850
  return skip("\uBB38\uB2E8 \uB0B4 \uAC15\uC81C \uC904\uBC14\uAFC8 \uD3EC\uD568 \u2014 \uC218\uC815 \uC2DC \uC904\uBC14\uAFC8 \uBCF4\uC874 \uBD88\uAC00\uB85C \uBBF8\uC9C0\uC6D0 (v1)");
22804
22851
  }
@@ -22829,7 +22876,7 @@ function patchParagraphUnit(block, orig, edited, ctx, skip) {
22829
22876
  if (sanitizeText(newPlain) !== newPlain) {
22830
22877
  return skip("\uACF5\uBC31 \uC815\uADDC\uD654 \uBD88\uC548\uC815 \uD14D\uC2A4\uD2B8 \u2014 \uD328\uCE58 \uC2DC \uC6D0\uBB38 \uBCF4\uC874 \uBD88\uAC00\uB85C \uBBF8\uC9C0\uC6D0");
22831
22878
  }
22832
- const splices = buildParagraphSplices(mapping.para, newPlain, _optionalChain([ctx, 'access', _225 => _225.scans, 'access', _226 => _226[mapping.para.sectionIndex], 'optionalAccess', _227 => _227.xml]));
22879
+ const splices = buildParagraphSplices(mapping.para, newPlain, _optionalChain([ctx, 'access', _227 => _227.scans, 'access', _228 => _228[mapping.para.sectionIndex], 'optionalAccess', _229 => _229.xml]));
22833
22880
  if (splices === null) return skip("\uBB38\uB2E8\uC5D0 \uD14D\uC2A4\uD2B8 \uB178\uB4DC\uB97C \uB9CC\uB4E4 \uC218 \uC5C6\uC74C");
22834
22881
  ctx.sectionSplices[mapping.para.sectionIndex].push(...splices);
22835
22882
  return 1;
@@ -23015,7 +23062,7 @@ var Surgeon = (_class4 = class {
23015
23062
  /** 디렉토리 트리에서 경로 해석 (형제 = L/R 이진 트리, 자식 = child) */
23016
23063
  findEntry(path) {
23017
23064
  const parts = path.replace(/^\//, "").split("/");
23018
- let scope = _nullishCoalesce(_optionalChain([this, 'access', _228 => _228.entries, 'access', _229 => _229[0], 'optionalAccess', _230 => _230.child]), () => ( -1));
23065
+ let scope = _nullishCoalesce(_optionalChain([this, 'access', _230 => _230.entries, 'access', _231 => _231[0], 'optionalAccess', _232 => _232.child]), () => ( -1));
23019
23066
  let current;
23020
23067
  for (const part of parts) {
23021
23068
  const search = (idx) => {
@@ -23228,8 +23275,8 @@ function serializeRecords(recs, repl, inserts) {
23228
23275
  parts.push(header, data);
23229
23276
  };
23230
23277
  for (let i = 0; i < recs.length; i++) {
23231
- for (const ins of _nullishCoalesce(_optionalChain([inserts, 'optionalAccess', _231 => _231.get, 'call', _232 => _232(i)]), () => ( []))) push(ins.tagId, ins.level, ins.data);
23232
- push(recs[i].tagId, recs[i].level, _nullishCoalesce(_optionalChain([repl, 'optionalAccess', _233 => _233.get, 'call', _234 => _234(i)]), () => ( recs[i].data)));
23278
+ for (const ins of _nullishCoalesce(_optionalChain([inserts, 'optionalAccess', _233 => _233.get, 'call', _234 => _234(i)]), () => ( []))) push(ins.tagId, ins.level, ins.data);
23279
+ push(recs[i].tagId, recs[i].level, _nullishCoalesce(_optionalChain([repl, 'optionalAccess', _235 => _235.get, 'call', _236 => _236(i)]), () => ( recs[i].data)));
23233
23280
  }
23234
23281
  return Buffer.concat(parts);
23235
23282
  }
@@ -23347,7 +23394,7 @@ async function patchHwp(original, editedMarkdown, options) {
23347
23394
  return fail(`CFB \uCEE8\uD14C\uC774\uB108 \uD30C\uC2F1 \uC2E4\uD328: ${msg(err)}`);
23348
23395
  }
23349
23396
  const fhEntry = CFB2.find(cfb, "/FileHeader");
23350
- if (!_optionalChain([fhEntry, 'optionalAccess', _235 => _235.content])) return fail("FileHeader \uC2A4\uD2B8\uB9BC\uC774 \uC5C6\uC2B5\uB2C8\uB2E4 \u2014 HWP 5.x \uD30C\uC77C\uC774 \uC544\uB2D9\uB2C8\uB2E4");
23397
+ if (!_optionalChain([fhEntry, 'optionalAccess', _237 => _237.content])) return fail("FileHeader \uC2A4\uD2B8\uB9BC\uC774 \uC5C6\uC2B5\uB2C8\uB2E4 \u2014 HWP 5.x \uD30C\uC77C\uC774 \uC544\uB2D9\uB2C8\uB2E4");
23351
23398
  let flags;
23352
23399
  try {
23353
23400
  flags = parseFileHeader(Buffer.from(fhEntry.content)).flags;
@@ -23369,7 +23416,7 @@ async function patchHwp(original, editedMarkdown, options) {
23369
23416
  const scans = [];
23370
23417
  for (let i = 0; i < sectionPaths.length; i++) {
23371
23418
  const entry = CFB2.find(cfb, sectionPaths[i]);
23372
- if (!_optionalChain([entry, 'optionalAccess', _236 => _236.content])) return fail(`\uC139\uC158 \uC2A4\uD2B8\uB9BC \uC77D\uAE30 \uC2E4\uD328: ${sectionPaths[i]}`);
23419
+ if (!_optionalChain([entry, 'optionalAccess', _238 => _238.content])) return fail(`\uC139\uC158 \uC2A4\uD2B8\uB9BC \uC77D\uAE30 \uC2E4\uD328: ${sectionPaths[i]}`);
23373
23420
  let stream;
23374
23421
  try {
23375
23422
  stream = compressed ? decompressStream(Buffer.from(entry.content)) : Buffer.from(entry.content);
@@ -23420,7 +23467,7 @@ async function patchHwp(original, editedMarkdown, options) {
23420
23467
  }
23421
23468
  }
23422
23469
  let verification;
23423
- if (_optionalChain([options, 'optionalAccess', _237 => _237.verify]) !== false) {
23470
+ if (_optionalChain([options, 'optionalAccess', _239 => _239.verify]) !== false) {
23424
23471
  try {
23425
23472
  const reparsed = parseHwp5Document(Buffer.from(data));
23426
23473
  verification = diffUnitLists(splitMarkdownUnits(reparsed.markdown), editedUnits);
@@ -23509,7 +23556,7 @@ function tableContentScore(irTable, scanTable) {
23509
23556
  for (const [key, scanCell] of scanTable.cells) {
23510
23557
  const comma = key.indexOf(",");
23511
23558
  const r = Number(key.slice(0, comma)), c = Number(key.slice(comma + 1));
23512
- const irCell = _optionalChain([irTable, 'access', _238 => _238.cells, 'access', _239 => _239[r], 'optionalAccess', _240 => _240[c]]);
23559
+ const irCell = _optionalChain([irTable, 'access', _240 => _240.cells, 'access', _241 => _241[r], 'optionalAccess', _242 => _242[c]]);
23513
23560
  if (!irCell) continue;
23514
23561
  const a = normForMatch(scanCell.paras.map((p) => p.rawText).join(" "));
23515
23562
  const b = normForMatch(stripCellTokens(irCell.text));
@@ -23545,7 +23592,7 @@ function handleModified(orig, edited, ctx) {
23545
23592
  }
23546
23593
  function patchParagraph(block, orig, edited, ctx, skip) {
23547
23594
  const mapping = ctx.paraMap.get(orig.blockIdx);
23548
- if (!_optionalChain([mapping, 'optionalAccess', _241 => _241.para])) return skip("\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED\uC774\uAC70\uB098 \uD14D\uC2A4\uD2B8 \uBD88\uC77C\uCE58)");
23595
+ if (!_optionalChain([mapping, 'optionalAccess', _243 => _243.para])) return skip("\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED\uC774\uAC70\uB098 \uD14D\uC2A4\uD2B8 \uBD88\uC77C\uCE58)");
23549
23596
  if (block.text && block.text.includes("\n")) {
23550
23597
  return skip("\uBB38\uB2E8 \uB0B4 \uAC15\uC81C \uC904\uBC14\uAFC8 \uD3EC\uD568 \u2014 \uC218\uC815 \uC2DC \uC904\uBC14\uAFC8 \uBCF4\uC874 \uBD88\uAC00\uB85C \uBBF8\uC9C0\uC6D0 (v1)");
23551
23598
  }
@@ -23721,7 +23768,7 @@ function applyCellEdit5(table, scanTable, gridR, gridC, newLines, ctx, before, a
23721
23768
  };
23722
23769
  const cell = scanTable.cells.get(`${gridR},${gridC}`);
23723
23770
  if (!cell) return skip("\uC140 \uC88C\uD45C \uB9E4\uD551 \uC2E4\uD328 (\uBCD1\uD569 \uC601\uC5ED\uC758 \uBE48 \uCE78\uC774\uAC70\uB098 \uC88C\uD45C \uBD88\uC77C\uCE58)");
23724
- const irCell = _optionalChain([table, 'access', _242 => _242.cells, 'access', _243 => _243[gridR], 'optionalAccess', _244 => _244[gridC]]);
23771
+ const irCell = _optionalChain([table, 'access', _244 => _244.cells, 'access', _245 => _245[gridR], 'optionalAccess', _246 => _246[gridC]]);
23725
23772
  const scanJoined = cell.paras.map((p) => p.rawText).filter((t) => normForMatch(t)).join("\n");
23726
23773
  if (irCell && normForMatch(scanJoined) !== normForMatch(stripCellTokens(irCell.text))) {
23727
23774
  if (normForMatch(irCell.text) !== "" || normForMatch(scanJoined) !== "") {
@@ -23996,7 +24043,7 @@ var HwpxSession = (_class5 = class _HwpxSession {
23996
24043
  const block = st.blocks[blockIndex];
23997
24044
  if (!block) return void 0;
23998
24045
  if (block.type === "paragraph" || block.type === "heading") {
23999
- const para = _optionalChain([st, 'access', _245 => _245.paraMap, 'access', _246 => _246.get, 'call', _247 => _247(blockIndex), 'optionalAccess', _248 => _248.para]);
24046
+ const para = _optionalChain([st, 'access', _247 => _247.paraMap, 'access', _248 => _248.get, 'call', _249 => _249(blockIndex), 'optionalAccess', _250 => _250.para]);
24000
24047
  if (!para) return void 0;
24001
24048
  return { kind: "paragraph", sectionIndex: para.sectionIndex, xmlStart: para.start };
24002
24049
  }
@@ -24021,7 +24068,7 @@ var HwpxSession = (_class5 = class _HwpxSession {
24021
24068
  if (block.text && block.text.includes("\n")) {
24022
24069
  return { capability: "locked", reason: "\uBB38\uB2E8 \uB0B4 \uAC15\uC81C \uC904\uBC14\uAFC8 \uD3EC\uD568 \u2014 \uC218\uC815 \uC2DC \uC904\uBC14\uAFC8 \uBCF4\uC874 \uBD88\uAC00\uB85C \uBBF8\uC9C0\uC6D0 (v1)" };
24023
24070
  }
24024
- if (!_optionalChain([st, 'access', _249 => _249.paraMap, 'access', _250 => _250.get, 'call', _251 => _251(blockIndex), 'optionalAccess', _252 => _252.para])) {
24071
+ if (!_optionalChain([st, 'access', _251 => _251.paraMap, 'access', _252 => _252.get, 'call', _253 => _253(blockIndex), 'optionalAccess', _254 => _254.para])) {
24025
24072
  return { capability: "locked", reason: "\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED\uC774\uAC70\uB098 \uD14D\uC2A4\uD2B8 \uBD88\uC77C\uCE58)" };
24026
24073
  }
24027
24074
  return { capability: "text" };
@@ -24087,7 +24134,7 @@ var HwpxSession = (_class5 = class _HwpxSession {
24087
24134
  continue;
24088
24135
  }
24089
24136
  if (block.type === "table" && block.table) {
24090
- if (!_optionalChain([edit, 'access', _253 => _253.cells, 'optionalAccess', _254 => _254.length])) {
24137
+ if (!_optionalChain([edit, 'access', _255 => _255.cells, 'optionalAccess', _256 => _256.length])) {
24091
24138
  skipped.push({ reason: "\uD45C \uBE14\uB85D\uC5D0\uB294 cells \uD3B8\uC9D1\uB9CC \uC9C0\uC6D0", before: summarize(_nullishCoalesce(block.table.caption, () => ( "(\uD45C)"))) });
24092
24139
  continue;
24093
24140
  }
@@ -24107,7 +24154,7 @@ var HwpxSession = (_class5 = class _HwpxSession {
24107
24154
  skipped.push({ reason: "\uAC19\uC740 \uC140\uC5D0 \uC911\uBCF5 \uD3B8\uC9D1 \u2014 \uBA3C\uC800 \uC801\uC6A9\uB41C \uD3B8\uC9D1 \uC720\uC9C0", after: summarize(cellEdit.text) });
24108
24155
  continue;
24109
24156
  }
24110
- const irCell = _optionalChain([block, 'access', _255 => _255.table, 'access', _256 => _256.cells, 'access', _257 => _257[cellEdit.row], 'optionalAccess', _258 => _258[cellEdit.col]]);
24157
+ const irCell = _optionalChain([block, 'access', _257 => _257.table, 'access', _258 => _258.cells, 'access', _259 => _259[cellEdit.row], 'optionalAccess', _260 => _260[cellEdit.col]]);
24111
24158
  if (!irCell) {
24112
24159
  skipped.push({ reason: `\uC140 \uC88C\uD45C \uBC94\uC704 \uBC16: ${cellEdit.row},${cellEdit.col}`, after: summarize(cellEdit.text) });
24113
24160
  continue;
@@ -24163,7 +24210,7 @@ var HwpxSession = (_class5 = class _HwpxSession {
24163
24210
  }
24164
24211
  if (replacements.size === 0) {
24165
24212
  let changes2;
24166
- if (_optionalChain([options, 'optionalAccess', _259 => _259.verify]) !== false) {
24213
+ if (_optionalChain([options, 'optionalAccess', _261 => _261.verify]) !== false) {
24167
24214
  const units = splitMarkdownUnits(st.markdown);
24168
24215
  changes2 = diffUnitLists(units, units);
24169
24216
  }
@@ -24184,7 +24231,7 @@ var HwpxSession = (_class5 = class _HwpxSession {
24184
24231
  }
24185
24232
  this.state = newState;
24186
24233
  let changes;
24187
- if (_optionalChain([options, 'optionalAccess', _260 => _260.verify]) !== false) {
24234
+ if (_optionalChain([options, 'optionalAccess', _262 => _262.verify]) !== false) {
24188
24235
  changes = diffUnitLists(splitMarkdownUnits(beforeMarkdown), splitMarkdownUnits(newState.markdown));
24189
24236
  }
24190
24237
  return { success: true, data: new Uint8Array(data), applied, skipped, changes };
@@ -24204,7 +24251,7 @@ var HwpxSession = (_class5 = class _HwpxSession {
24204
24251
  return skip("\uBB38\uB2E8 \uB0B4 \uAC15\uC81C \uC904\uBC14\uAFC8 \uD3EC\uD568 \u2014 \uC218\uC815 \uC2DC \uC904\uBC14\uAFC8 \uBCF4\uC874 \uBD88\uAC00\uB85C \uBBF8\uC9C0\uC6D0 (v1)");
24205
24252
  }
24206
24253
  const mapping = st.paraMap.get(blockIndex);
24207
- if (!_optionalChain([mapping, 'optionalAccess', _261 => _261.para])) {
24254
+ if (!_optionalChain([mapping, 'optionalAccess', _263 => _263.para])) {
24208
24255
  return skip("\uBB38\uB2E8 \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328 (\uBA38\uB9AC\uB9D0/\uAE00\uC0C1\uC790/\uCEA1\uC158 \uC601\uC5ED\uC774\uAC70\uB098 \uD14D\uC2A4\uD2B8 \uBD88\uC77C\uCE58)");
24209
24256
  }
24210
24257
  let newPlain = newTextRaw.split("\n").map((l) => l.trim()).filter(Boolean).join(" ");
@@ -24224,14 +24271,14 @@ var HwpxSession = (_class5 = class _HwpxSession {
24224
24271
  if (sanitizeText(newPlain) !== newPlain) {
24225
24272
  return skip("\uACF5\uBC31 \uC815\uADDC\uD654 \uBD88\uC548\uC815 \uD14D\uC2A4\uD2B8 \u2014 \uD328\uCE58 \uC2DC \uC6D0\uBB38 \uBCF4\uC874 \uBD88\uAC00\uB85C \uBBF8\uC9C0\uC6D0");
24226
24273
  }
24227
- const splices = buildParagraphSplices(mapping.para, newPlain, _optionalChain([st, 'access', _262 => _262.scans, 'access', _263 => _263[mapping.para.sectionIndex], 'optionalAccess', _264 => _264.xml]));
24274
+ const splices = buildParagraphSplices(mapping.para, newPlain, _optionalChain([st, 'access', _264 => _264.scans, 'access', _265 => _265[mapping.para.sectionIndex], 'optionalAccess', _266 => _266.xml]));
24228
24275
  if (splices === null) return skip("\uBB38\uB2E8\uC5D0 \uD14D\uC2A4\uD2B8 \uB178\uB4DC\uB97C \uB9CC\uB4E4 \uC218 \uC5C6\uC74C");
24229
24276
  sectionSplices[mapping.para.sectionIndex].push(...splices);
24230
24277
  return 1;
24231
24278
  }
24232
24279
  }, _class5);
24233
24280
  function cellStaticCheck(table, scanTable, r, c) {
24234
- const irCell = _optionalChain([table, 'access', _265 => _265.cells, 'access', _266 => _266[r], 'optionalAccess', _267 => _267[c]]);
24281
+ const irCell = _optionalChain([table, 'access', _267 => _267.cells, 'access', _268 => _268[r], 'optionalAccess', _269 => _269[c]]);
24235
24282
  if (!irCell) return { editable: false, reason: "\uC140 \uC88C\uD45C \uBC94\uC704 \uBC16" };
24236
24283
  const cell = scanTable.cellByAnchor.get(`${r},${c}`);
24237
24284
  if (!cell) return { editable: false, reason: "\uBCD1\uD569 \uC601\uC5ED\uC758 \uBE48 \uCE78\uC774\uAC70\uB098 \uC88C\uD45C \uBD88\uC77C\uCE58" };
@@ -24315,11 +24362,11 @@ var md = new (0, _markdownit2.default)({
24315
24362
  breaks: false
24316
24363
  });
24317
24364
  function renderHtml(markdown, options) {
24318
- const preset = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _268 => _268.preset]), () => ( "default"));
24319
- const css = PRESETS[preset] + (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _269 => _269.extraCss]), () => ( "")));
24365
+ const preset = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _270 => _270.preset]), () => ( "default"));
24366
+ const css = PRESETS[preset] + (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _271 => _271.extraCss]), () => ( "")));
24320
24367
  const body = md.render(markdown);
24321
- const watermark = _optionalChain([options, 'optionalAccess', _270 => _270.watermark]) ? `<div class="watermark">${escapeHtml(options.watermark)}</div>` : "";
24322
- const watermarkCss = _optionalChain([options, 'optionalAccess', _271 => _271.watermark]) ? `
24368
+ const watermark = _optionalChain([options, 'optionalAccess', _272 => _272.watermark]) ? `<div class="watermark">${escapeHtml(options.watermark)}</div>` : "";
24369
+ const watermarkCss = _optionalChain([options, 'optionalAccess', _273 => _273.watermark]) ? `
24323
24370
  .watermark {
24324
24371
  position: fixed;
24325
24372
  top: 50%; left: 50%;
@@ -24350,13 +24397,13 @@ async function htmlToPdf(html, options) {
24350
24397
  try {
24351
24398
  puppeteer = await Promise.resolve().then(() => _interopRequireWildcard(require("puppeteer-core")));
24352
24399
  } catch (e30) {
24353
- throw new (0, _chunkLFCS3UVGcjs.KordocError)(
24400
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)(
24354
24401
  "PDF \uC0DD\uC131\uC5D0 puppeteer-core\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. \uC124\uCE58: npm install puppeteer-core"
24355
24402
  );
24356
24403
  }
24357
24404
  const executablePath = _nullishCoalesce(process.env.PUPPETEER_EXECUTABLE_PATH, () => ( findChromiumPath()));
24358
24405
  if (!executablePath) {
24359
- throw new (0, _chunkLFCS3UVGcjs.KordocError)(
24406
+ throw new (0, _chunkXL6O3VAYcjs.KordocError)(
24360
24407
  "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
24408
  );
24362
24409
  }
@@ -24368,10 +24415,10 @@ async function htmlToPdf(html, options) {
24368
24415
  try {
24369
24416
  const page = await browser.newPage();
24370
24417
  await page.setContent(html, { waitUntil: "networkidle0" });
24371
- const margin = _optionalChain([options, 'optionalAccess', _272 => _272.margin]);
24418
+ const margin = _optionalChain([options, 'optionalAccess', _274 => _274.margin]);
24372
24419
  const pdf = await page.pdf({
24373
- format: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _273 => _273.pageSize]), () => ( "A4")),
24374
- landscape: _optionalChain([options, 'optionalAccess', _274 => _274.orientation]) === "landscape",
24420
+ format: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _275 => _275.pageSize]), () => ( "A4")),
24421
+ landscape: _optionalChain([options, 'optionalAccess', _276 => _276.orientation]) === "landscape",
24375
24422
  printBackground: true,
24376
24423
  margin: margin ? {
24377
24424
  top: toCss(margin.top),
@@ -24379,9 +24426,9 @@ async function htmlToPdf(html, options) {
24379
24426
  bottom: toCss(margin.bottom),
24380
24427
  left: toCss(margin.left)
24381
24428
  } : void 0,
24382
- displayHeaderFooter: !!(_optionalChain([options, 'optionalAccess', _275 => _275.header]) || _optionalChain([options, 'optionalAccess', _276 => _276.footer])),
24383
- headerTemplate: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _277 => _277.header]), () => ( "<div></div>")),
24384
- footerTemplate: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _278 => _278.footer]), () => ( '<div style="font-size:8pt;width:100%;text-align:center;color:#777;"><span class="pageNumber"></span>/<span class="totalPages"></span></div>'))
24429
+ displayHeaderFooter: !!(_optionalChain([options, 'optionalAccess', _277 => _277.header]) || _optionalChain([options, 'optionalAccess', _278 => _278.footer])),
24430
+ headerTemplate: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _279 => _279.header]), () => ( "<div></div>")),
24431
+ footerTemplate: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _280 => _280.footer]), () => ( '<div style="font-size:8pt;width:100%;text-align:center;color:#777;"><span class="pageNumber"></span>/<span class="totalPages"></span></div>'))
24385
24432
  });
24386
24433
  return Buffer.from(pdf);
24387
24434
  } finally {
@@ -24415,24 +24462,24 @@ async function markdownToPdf(markdown, options) {
24415
24462
  return htmlToPdf(html, options);
24416
24463
  }
24417
24464
  async function blocksToPdf(blocks, options) {
24418
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, blocks);
24465
+ const markdown = _chunkXL6O3VAYcjs.blocksToMarkdown.call(void 0, blocks);
24419
24466
  return markdownToPdf(markdown, options);
24420
24467
  }
24421
24468
 
24422
24469
  // src/index.ts
24423
24470
  async function parse(input, options) {
24424
24471
  let buffer;
24425
- const opts = typeof input === "string" && !_optionalChain([options, 'optionalAccess', _279 => _279.filePath]) ? { ...options, filePath: input } : options;
24472
+ const opts = typeof input === "string" && !_optionalChain([options, 'optionalAccess', _281 => _281.filePath]) ? { ...options, filePath: input } : options;
24426
24473
  if (typeof input === "string") {
24427
24474
  try {
24428
24475
  const buf = await _promises.readFile.call(void 0, input);
24429
- buffer = _chunkLFCS3UVGcjs.toArrayBuffer.call(void 0, buf);
24476
+ buffer = _chunkXL6O3VAYcjs.toArrayBuffer.call(void 0, buf);
24430
24477
  } catch (err) {
24431
24478
  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
24479
  return { success: false, fileType: "unknown", error: msg2, code: "PARSE_ERROR" };
24433
24480
  }
24434
24481
  } else if (Buffer.isBuffer(input)) {
24435
- buffer = _chunkLFCS3UVGcjs.toArrayBuffer.call(void 0, input);
24482
+ buffer = _chunkXL6O3VAYcjs.toArrayBuffer.call(void 0, input);
24436
24483
  } else {
24437
24484
  buffer = input;
24438
24485
  }
@@ -24467,21 +24514,21 @@ async function parseHwp3(buffer, options) {
24467
24514
  const { markdown, blocks, metadata, outline, warnings } = parseHwp3Document(buffer, options);
24468
24515
  return { success: true, fileType: "hwp3", markdown, blocks, metadata, outline, warnings };
24469
24516
  } 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) };
24517
+ return { success: false, fileType: "hwp3", error: err instanceof Error ? err.message : "HWP3 \uD30C\uC2F1 \uC2E4\uD328", code: _chunkXL6O3VAYcjs.classifyError.call(void 0, err) };
24471
24518
  }
24472
24519
  }
24473
24520
  async function parseHwpx(buffer, options) {
24474
24521
  try {
24475
24522
  const { markdown, blocks, metadata, outline, warnings, images } = await parseHwpxDocument(buffer, options);
24476
- return { success: true, fileType: "hwpx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _280 => _280.length]) ? images : void 0 };
24523
+ return { success: true, fileType: "hwpx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _282 => _282.length]) ? images : void 0 };
24477
24524
  } 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) };
24525
+ return { success: false, fileType: "hwpx", error: err instanceof Error ? err.message : "HWPX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkXL6O3VAYcjs.classifyError.call(void 0, err) };
24479
24526
  }
24480
24527
  }
24481
24528
  async function parseHwp(buffer, options) {
24482
24529
  try {
24483
24530
  const { markdown, blocks, metadata, outline, warnings, images } = parseHwp5Document(Buffer.from(buffer), options);
24484
- if (isDistributionSentinel(markdown) && isComFallbackAvailable() && _optionalChain([options, 'optionalAccess', _281 => _281.filePath])) {
24531
+ if (isDistributionSentinel(markdown) && isComFallbackAvailable() && _optionalChain([options, 'optionalAccess', _283 => _283.filePath])) {
24485
24532
  try {
24486
24533
  const { pages, pageCount, warnings: comWarns } = extractTextViaCom(options.filePath);
24487
24534
  if (pages.some((p) => p && p.trim().length > 0)) {
@@ -24498,15 +24545,15 @@ async function parseHwp(buffer, options) {
24498
24545
  } catch (e31) {
24499
24546
  }
24500
24547
  }
24501
- return { success: true, fileType: "hwp", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _282 => _282.length]) ? images : void 0 };
24548
+ return { success: true, fileType: "hwp", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _284 => _284.length]) ? images : void 0 };
24502
24549
  } 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) };
24550
+ return { success: false, fileType: "hwp", error: err instanceof Error ? err.message : "HWP \uD30C\uC2F1 \uC2E4\uD328", code: _chunkXL6O3VAYcjs.classifyError.call(void 0, err) };
24504
24551
  }
24505
24552
  }
24506
24553
  async function parsePdf(buffer, options) {
24507
24554
  let parsePdfDocument;
24508
24555
  try {
24509
- const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./parser-IXK5V7YG.cjs")));
24556
+ const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./parser-WWKYMRGJ.cjs")));
24510
24557
  parsePdfDocument = mod.parsePdfDocument;
24511
24558
  } catch (e32) {
24512
24559
  return {
@@ -24521,7 +24568,7 @@ async function parsePdf(buffer, options) {
24521
24568
  return { success: true, fileType: "pdf", markdown, blocks, metadata, outline, warnings, isImageBased, pageQuality, qualitySummary };
24522
24569
  } catch (err) {
24523
24570
  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 };
24571
+ return { success: false, fileType: "pdf", error: err instanceof Error ? err.message : "PDF \uD30C\uC2F1 \uC2E4\uD328", code: _chunkXL6O3VAYcjs.classifyError.call(void 0, err), isImageBased };
24525
24572
  }
24526
24573
  }
24527
24574
  async function parseXlsx(buffer, options) {
@@ -24529,7 +24576,7 @@ async function parseXlsx(buffer, options) {
24529
24576
  const { markdown, blocks, metadata, warnings } = await parseXlsxDocument(buffer, options);
24530
24577
  return { success: true, fileType: "xlsx", markdown, blocks, metadata, warnings };
24531
24578
  } 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) };
24579
+ return { success: false, fileType: "xlsx", error: err instanceof Error ? err.message : "XLSX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkXL6O3VAYcjs.classifyError.call(void 0, err) };
24533
24580
  }
24534
24581
  }
24535
24582
  async function parseXls(buffer, options) {
@@ -24537,15 +24584,15 @@ async function parseXls(buffer, options) {
24537
24584
  const { markdown, blocks, metadata, warnings } = await parseXlsDocument(buffer, options);
24538
24585
  return { success: true, fileType: "xls", markdown, blocks, metadata, warnings };
24539
24586
  } 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) };
24587
+ return { success: false, fileType: "xls", error: err instanceof Error ? err.message : "XLS \uD30C\uC2F1 \uC2E4\uD328", code: _chunkXL6O3VAYcjs.classifyError.call(void 0, err) };
24541
24588
  }
24542
24589
  }
24543
24590
  async function parseDocx(buffer, options) {
24544
24591
  try {
24545
24592
  const { markdown, blocks, metadata, outline, warnings, images } = await parseDocxDocument(buffer, options);
24546
- return { success: true, fileType: "docx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _283 => _283.length]) ? images : void 0 };
24593
+ return { success: true, fileType: "docx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _285 => _285.length]) ? images : void 0 };
24547
24594
  } 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) };
24595
+ return { success: false, fileType: "docx", error: err instanceof Error ? err.message : "DOCX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkXL6O3VAYcjs.classifyError.call(void 0, err) };
24549
24596
  }
24550
24597
  }
24551
24598
  async function parseHwpml(buffer, options) {
@@ -24553,16 +24600,16 @@ async function parseHwpml(buffer, options) {
24553
24600
  const { markdown, blocks, metadata, outline, warnings } = parseHwpmlDocument(buffer, options);
24554
24601
  return { success: true, fileType: "hwpml", markdown, blocks, metadata, outline, warnings };
24555
24602
  } 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) };
24603
+ return { success: false, fileType: "hwpml", error: err instanceof Error ? err.message : "HWPML \uD30C\uC2F1 \uC2E4\uD328", code: _chunkXL6O3VAYcjs.classifyError.call(void 0, err) };
24557
24604
  }
24558
24605
  }
24559
24606
  async function fillForm(input, values, outputFormat = "markdown") {
24560
24607
  let buffer;
24561
24608
  if (typeof input === "string") {
24562
24609
  const buf = await _promises.readFile.call(void 0, input);
24563
- buffer = _chunkLFCS3UVGcjs.toArrayBuffer.call(void 0, buf);
24610
+ buffer = _chunkXL6O3VAYcjs.toArrayBuffer.call(void 0, buf);
24564
24611
  } else if (Buffer.isBuffer(input)) {
24565
- buffer = _chunkLFCS3UVGcjs.toArrayBuffer.call(void 0, input);
24612
+ buffer = _chunkXL6O3VAYcjs.toArrayBuffer.call(void 0, input);
24566
24613
  } else {
24567
24614
  buffer = input;
24568
24615
  }
@@ -24588,7 +24635,7 @@ async function fillForm(input, values, outputFormat = "markdown") {
24588
24635
  throw new Error(`\uC11C\uC2DD \uD30C\uC2F1 \uC2E4\uD328: ${parsed.error}`);
24589
24636
  }
24590
24637
  const fill = fillFormFields(parsed.blocks, values);
24591
- const markdown = _chunkLFCS3UVGcjs.blocksToMarkdown.call(void 0, fill.blocks);
24638
+ const markdown = _chunkXL6O3VAYcjs.blocksToMarkdown.call(void 0, fill.blocks);
24592
24639
  if (outputFormat === "hwpx") {
24593
24640
  const hwpxBuffer = await markdownToHwpx(markdown);
24594
24641
  return { output: hwpxBuffer, format: "hwpx", fill };
@@ -24646,5 +24693,5 @@ async function fillForm(input, values, outputFormat = "markdown") {
24646
24693
 
24647
24694
 
24648
24695
 
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;
24696
+ exports.HwpxSession = HwpxSession; exports.PRESET_ALIAS = PRESET_ALIAS; exports.SPACE_EM_FIXED = SPACE_EM_FIXED; exports.SPACE_EM_FONT = SPACE_EM_FONT; exports.VERSION = _chunkXL6O3VAYcjs.VERSION; exports.ValueCursor = ValueCursor; exports.applySplices = applySplices; exports.blocksToMarkdown = _chunkXL6O3VAYcjs.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
24697
  //# sourceMappingURL=index.cjs.map