kordoc 3.0.0 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -1
- package/dist/{-K5SLEFZD.js → -5BWAV4ZY.js} +5 -3
- package/dist/{chunk-3WRJQQIO.cjs → chunk-NBJB6TJB.cjs} +2 -2
- package/dist/{chunk-3WRJQQIO.cjs.map → chunk-NBJB6TJB.cjs.map} +1 -1
- package/dist/{chunk-SA2PERJ5.js → chunk-O5P6EG5L.js} +2 -2
- package/dist/{chunk-NHXKJWR7.js → chunk-X3SCCO5Q.js} +2 -2
- package/dist/{chunk-326STEDU.js → chunk-X7VQVMXQ.js} +845 -12
- package/dist/chunk-X7VQVMXQ.js.map +1 -0
- package/dist/cli.js +9 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +964 -131
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +27 -1
- package/dist/index.d.ts +27 -1
- package/dist/index.js +844 -11
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +3 -3
- package/dist/{parser-AU2NLC44.js → parser-3N6FZSKU.js} +2 -2
- package/dist/{parser-5KHU732L.cjs → parser-5FZJVLQL.cjs} +14 -14
- package/dist/{parser-5KHU732L.cjs.map → parser-5FZJVLQL.cjs.map} +1 -1
- package/dist/{parser-4IVYHKSL.js → parser-LZH7ZELV.js} +2 -2
- package/dist/{watch-5DDN4BUI.js → watch-4FMRS7QU.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-326STEDU.js.map +0 -1
- /package/dist/{-K5SLEFZD.js.map → -5BWAV4ZY.js.map} +0 -0
- /package/dist/{chunk-SA2PERJ5.js.map → chunk-O5P6EG5L.js.map} +0 -0
- /package/dist/{chunk-NHXKJWR7.js.map → chunk-X3SCCO5Q.js.map} +0 -0
- /package/dist/{parser-AU2NLC44.js.map → parser-3N6FZSKU.js.map} +0 -0
- /package/dist/{parser-4IVYHKSL.js.map → parser-LZH7ZELV.js.map} +0 -0
- /package/dist/{watch-5DDN4BUI.js.map → watch-4FMRS7QU.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class; var _class2;
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
|
|
19
19
|
|
|
20
|
-
var
|
|
20
|
+
var _chunkNBJB6TJBcjs = require('./chunk-NBJB6TJB.cjs');
|
|
21
21
|
|
|
22
22
|
|
|
23
23
|
var _chunkMUOQXDZ4cjs = require('./chunk-MUOQXDZ4.cjs');
|
|
@@ -824,9 +824,9 @@ function createSectionShared() {
|
|
|
824
824
|
}
|
|
825
825
|
function createXmlParser(warnings) {
|
|
826
826
|
return new (0, _xmldom.DOMParser)({
|
|
827
|
-
onError(level,
|
|
828
|
-
if (level === "fatalError") throw new (0,
|
|
829
|
-
_optionalChain([warnings, 'optionalAccess', _3 => _3.push, 'call', _4 => _4({ code: "MALFORMED_XML", message: `XML ${level === "warn" ? "\uACBD\uACE0" : "\uC624\uB958"}: ${
|
|
827
|
+
onError(level, msg2) {
|
|
828
|
+
if (level === "fatalError") throw new (0, _chunkNBJB6TJBcjs.KordocError)(`XML \uD30C\uC2F1 \uC2E4\uD328: ${msg2}`);
|
|
829
|
+
_optionalChain([warnings, 'optionalAccess', _3 => _3.push, 'call', _4 => _4({ code: "MALFORMED_XML", message: `XML ${level === "warn" ? "\uACBD\uACE0" : "\uC624\uB958"}: ${msg2}` })]);
|
|
830
830
|
}
|
|
831
831
|
});
|
|
832
832
|
}
|
|
@@ -847,10 +847,10 @@ async function extractHwpxStyles(zip, decompressed) {
|
|
|
847
847
|
const xml = await file.async("text");
|
|
848
848
|
if (decompressed) {
|
|
849
849
|
decompressed.total += xml.length * 2;
|
|
850
|
-
if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0,
|
|
850
|
+
if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
|
|
851
851
|
}
|
|
852
852
|
const parser = createXmlParser();
|
|
853
|
-
const doc = parser.parseFromString(
|
|
853
|
+
const doc = parser.parseFromString(_chunkNBJB6TJBcjs.stripDtd.call(void 0, xml), "text/xml");
|
|
854
854
|
if (!doc.documentElement) continue;
|
|
855
855
|
parseCharProperties(doc, result.charProperties);
|
|
856
856
|
parseStyleElements(doc, result.styles);
|
|
@@ -1072,7 +1072,7 @@ function resolveParaHeading(paraEl, ctx) {
|
|
|
1072
1072
|
return { prefix, headingLevel };
|
|
1073
1073
|
}
|
|
1074
1074
|
async function parseHwpxDocument(buffer, options) {
|
|
1075
|
-
|
|
1075
|
+
_chunkNBJB6TJBcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE, MAX_ZIP_ENTRIES);
|
|
1076
1076
|
let zip;
|
|
1077
1077
|
try {
|
|
1078
1078
|
zip = await _jszip2.default.loadAsync(buffer);
|
|
@@ -1081,7 +1081,7 @@ async function parseHwpxDocument(buffer, options) {
|
|
|
1081
1081
|
}
|
|
1082
1082
|
const actualEntryCount = Object.keys(zip.files).length;
|
|
1083
1083
|
if (actualEntryCount > MAX_ZIP_ENTRIES) {
|
|
1084
|
-
throw new (0,
|
|
1084
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP \uC5D4\uD2B8\uB9AC \uC218 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
|
|
1085
1085
|
}
|
|
1086
1086
|
const manifestFile = zip.file("META-INF/manifest.xml");
|
|
1087
1087
|
if (manifestFile) {
|
|
@@ -1093,7 +1093,7 @@ async function parseHwpxDocument(buffer, options) {
|
|
|
1093
1093
|
return comResultToParseResult(pages, pageCount, warnings2);
|
|
1094
1094
|
}
|
|
1095
1095
|
}
|
|
1096
|
-
throw new (0,
|
|
1096
|
+
throw new (0, _chunkNBJB6TJBcjs.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.");
|
|
1097
1097
|
}
|
|
1098
1098
|
}
|
|
1099
1099
|
const decompressed = { total: 0 };
|
|
@@ -1102,7 +1102,7 @@ async function parseHwpxDocument(buffer, options) {
|
|
|
1102
1102
|
const styleMap = await extractHwpxStyles(zip, decompressed);
|
|
1103
1103
|
const warnings = [];
|
|
1104
1104
|
const sectionPaths = await resolveSectionPaths(zip);
|
|
1105
|
-
if (sectionPaths.length === 0) throw new (0,
|
|
1105
|
+
if (sectionPaths.length === 0) throw new (0, _chunkNBJB6TJBcjs.KordocError)("HWPX\uC5D0\uC11C \uC139\uC158 \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
1106
1106
|
metadata.pageCount = sectionPaths.length;
|
|
1107
1107
|
const pageFilter = _optionalChain([options, 'optionalAccess', _12 => _12.pages]) ? _chunkMUOQXDZ4cjs.parsePageRange.call(void 0, options.pages, sectionPaths.length) : null;
|
|
1108
1108
|
const totalTarget = pageFilter ? pageFilter.size : sectionPaths.length;
|
|
@@ -1116,12 +1116,12 @@ async function parseHwpxDocument(buffer, options) {
|
|
|
1116
1116
|
try {
|
|
1117
1117
|
const xml = await file.async("text");
|
|
1118
1118
|
decompressed.total += xml.length * 2;
|
|
1119
|
-
if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0,
|
|
1119
|
+
if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
|
|
1120
1120
|
blocks.push(...parseSectionXml(xml, styleMap, warnings, si + 1, shared));
|
|
1121
1121
|
parsedSections++;
|
|
1122
1122
|
_optionalChain([options, 'optionalAccess', _13 => _13.onProgress, 'optionalCall', _14 => _14(parsedSections, totalTarget)]);
|
|
1123
1123
|
} catch (secErr) {
|
|
1124
|
-
if (secErr instanceof
|
|
1124
|
+
if (secErr instanceof _chunkNBJB6TJBcjs.KordocError) throw secErr;
|
|
1125
1125
|
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" });
|
|
1126
1126
|
}
|
|
1127
1127
|
}
|
|
@@ -1129,7 +1129,7 @@ async function parseHwpxDocument(buffer, options) {
|
|
|
1129
1129
|
const images = await extractImagesFromZip(zip, blocks, decompressed, warnings);
|
|
1130
1130
|
detectHwpxHeadings(blocks, styleMap);
|
|
1131
1131
|
const outline = blocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
|
|
1132
|
-
const markdown =
|
|
1132
|
+
const markdown = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, blocks);
|
|
1133
1133
|
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 };
|
|
1134
1134
|
}
|
|
1135
1135
|
function applyPageText(blocks, shared) {
|
|
@@ -1218,13 +1218,13 @@ async function extractImagesFromZip(zip, blocks, decompressed, warnings) {
|
|
|
1218
1218
|
let found = false;
|
|
1219
1219
|
const allCandidates = resolvedPath ? [resolvedPath, ...candidates] : candidates;
|
|
1220
1220
|
for (const path of allCandidates) {
|
|
1221
|
-
if (
|
|
1221
|
+
if (_chunkNBJB6TJBcjs.isPathTraversal.call(void 0, path)) continue;
|
|
1222
1222
|
const file = zip.file(path);
|
|
1223
1223
|
if (!file) continue;
|
|
1224
1224
|
try {
|
|
1225
1225
|
const data = await file.async("uint8array");
|
|
1226
1226
|
decompressed.total += data.length;
|
|
1227
|
-
if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0,
|
|
1227
|
+
if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
|
|
1228
1228
|
const actualPath = path;
|
|
1229
1229
|
const ext = actualPath.includes(".") ? actualPath.split(".").pop() || "png" : "png";
|
|
1230
1230
|
const mimeType = imageExtToMime(ext);
|
|
@@ -1237,7 +1237,7 @@ async function extractImagesFromZip(zip, blocks, decompressed, warnings) {
|
|
|
1237
1237
|
found = true;
|
|
1238
1238
|
break;
|
|
1239
1239
|
} catch (err) {
|
|
1240
|
-
if (err instanceof
|
|
1240
|
+
if (err instanceof _chunkNBJB6TJBcjs.KordocError) throw err;
|
|
1241
1241
|
}
|
|
1242
1242
|
}
|
|
1243
1243
|
if (!found) {
|
|
@@ -1258,7 +1258,7 @@ async function extractHwpxMetadata(zip, metadata, decompressed) {
|
|
|
1258
1258
|
const xml = await file.async("text");
|
|
1259
1259
|
if (decompressed) {
|
|
1260
1260
|
decompressed.total += xml.length * 2;
|
|
1261
|
-
if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0,
|
|
1261
|
+
if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
|
|
1262
1262
|
}
|
|
1263
1263
|
parseDublinCoreMetadata(xml, metadata);
|
|
1264
1264
|
if (metadata.title || metadata.author) return;
|
|
@@ -1268,7 +1268,7 @@ async function extractHwpxMetadata(zip, metadata, decompressed) {
|
|
|
1268
1268
|
}
|
|
1269
1269
|
function parseDublinCoreMetadata(xml, metadata) {
|
|
1270
1270
|
const parser = createXmlParser();
|
|
1271
|
-
const doc = parser.parseFromString(
|
|
1271
|
+
const doc = parser.parseFromString(_chunkNBJB6TJBcjs.stripDtd.call(void 0, xml), "text/xml");
|
|
1272
1272
|
if (!doc.documentElement) return;
|
|
1273
1273
|
const getText = (tagNames) => {
|
|
1274
1274
|
for (const tag of tagNames) {
|
|
@@ -1328,7 +1328,7 @@ function extractFromBrokenZip(buffer) {
|
|
|
1328
1328
|
}
|
|
1329
1329
|
const nameBytes = data.slice(pos + 30, pos + 30 + nameLen);
|
|
1330
1330
|
const name = new TextDecoder().decode(nameBytes);
|
|
1331
|
-
if (
|
|
1331
|
+
if (_chunkNBJB6TJBcjs.isPathTraversal.call(void 0, name)) {
|
|
1332
1332
|
pos = fileStart + compSize;
|
|
1333
1333
|
continue;
|
|
1334
1334
|
}
|
|
@@ -1346,16 +1346,16 @@ function extractFromBrokenZip(buffer) {
|
|
|
1346
1346
|
continue;
|
|
1347
1347
|
}
|
|
1348
1348
|
totalDecompressed += content.length * 2;
|
|
1349
|
-
if (totalDecompressed > MAX_DECOMPRESS_SIZE) throw new (0,
|
|
1349
|
+
if (totalDecompressed > MAX_DECOMPRESS_SIZE) throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC");
|
|
1350
1350
|
sectionNum++;
|
|
1351
1351
|
blocks.push(...parseSectionXml(content, void 0, warnings, sectionNum, shared));
|
|
1352
1352
|
} catch (e13) {
|
|
1353
1353
|
continue;
|
|
1354
1354
|
}
|
|
1355
1355
|
}
|
|
1356
|
-
if (blocks.length === 0) throw new (0,
|
|
1356
|
+
if (blocks.length === 0) throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uC190\uC0C1\uB41C HWPX\uC5D0\uC11C \uC139\uC158 \uB370\uC774\uD130\uB97C \uBCF5\uAD6C\uD560 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
1357
1357
|
applyPageText(blocks, shared);
|
|
1358
|
-
const markdown =
|
|
1358
|
+
const markdown = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, blocks);
|
|
1359
1359
|
return { markdown, blocks, warnings: warnings.length > 0 ? warnings : void 0 };
|
|
1360
1360
|
}
|
|
1361
1361
|
async function resolveSectionPaths(zip) {
|
|
@@ -1373,7 +1373,7 @@ async function resolveSectionPaths(zip) {
|
|
|
1373
1373
|
}
|
|
1374
1374
|
function parseSectionPathsFromManifest(xml) {
|
|
1375
1375
|
const parser = createXmlParser();
|
|
1376
|
-
const doc = parser.parseFromString(
|
|
1376
|
+
const doc = parser.parseFromString(_chunkNBJB6TJBcjs.stripDtd.call(void 0, xml), "text/xml");
|
|
1377
1377
|
const items = doc.getElementsByTagName("opf:item");
|
|
1378
1378
|
const spine = doc.getElementsByTagName("opf:itemref");
|
|
1379
1379
|
const isSectionId = (id) => /^s/i.test(id) || id.toLowerCase().includes("section");
|
|
@@ -1421,9 +1421,9 @@ function detectHwpxHeadings(blocks, styleMap) {
|
|
|
1421
1421
|
let level = 0;
|
|
1422
1422
|
if (baseFontSize > 0 && _optionalChain([block, 'access', _25 => _25.style, 'optionalAccess', _26 => _26.fontSize])) {
|
|
1423
1423
|
const ratio = block.style.fontSize / baseFontSize;
|
|
1424
|
-
if (ratio >=
|
|
1425
|
-
else if (ratio >=
|
|
1426
|
-
else if (ratio >=
|
|
1424
|
+
if (ratio >= _chunkNBJB6TJBcjs.HEADING_RATIO_H1) level = 1;
|
|
1425
|
+
else if (ratio >= _chunkNBJB6TJBcjs.HEADING_RATIO_H2) level = 2;
|
|
1426
|
+
else if (ratio >= _chunkNBJB6TJBcjs.HEADING_RATIO_H3) level = 3;
|
|
1427
1427
|
}
|
|
1428
1428
|
const compactText = text.replace(/\s+/g, "");
|
|
1429
1429
|
if (/^제\d+[조장절편]/.test(compactText) && text.length <= 50) {
|
|
@@ -1436,7 +1436,7 @@ function detectHwpxHeadings(blocks, styleMap) {
|
|
|
1436
1436
|
}
|
|
1437
1437
|
}
|
|
1438
1438
|
function buildTableWithCellMeta(state) {
|
|
1439
|
-
const table =
|
|
1439
|
+
const table = _chunkNBJB6TJBcjs.buildTable.call(void 0, state.rows);
|
|
1440
1440
|
if (state.caption) table.caption = state.caption;
|
|
1441
1441
|
const claimed = /* @__PURE__ */ new Set();
|
|
1442
1442
|
for (const row of state.rows) {
|
|
@@ -1479,7 +1479,7 @@ function completeTable(newTable, tableStack, blocks, ctx) {
|
|
|
1479
1479
|
const cell = parentTable.cell;
|
|
1480
1480
|
(cell.blocks ??= []).push(block);
|
|
1481
1481
|
cell.hasStructure = true;
|
|
1482
|
-
let flat =
|
|
1482
|
+
let flat = _chunkNBJB6TJBcjs.convertTableToText.call(void 0, newTable.rows);
|
|
1483
1483
|
if (newTable.caption) flat = newTable.caption + (flat ? "\n" + flat : "");
|
|
1484
1484
|
if (flat) cell.text += (cell.text ? "\n" : "") + flat;
|
|
1485
1485
|
} else {
|
|
@@ -1489,7 +1489,7 @@ function completeTable(newTable, tableStack, blocks, ctx) {
|
|
|
1489
1489
|
}
|
|
1490
1490
|
function parseSectionXml(xml, styleMap, warnings, sectionNum, shared) {
|
|
1491
1491
|
const parser = createXmlParser(warnings);
|
|
1492
|
-
const doc = parser.parseFromString(
|
|
1492
|
+
const doc = parser.parseFromString(_chunkNBJB6TJBcjs.stripDtd.call(void 0, xml), "text/xml");
|
|
1493
1493
|
if (!doc.documentElement) return [];
|
|
1494
1494
|
const ctx = { styleMap, warnings, sectionNum, shared: _nullishCoalesce(shared, () => ( createSectionShared())) };
|
|
1495
1495
|
ctx.shared.track.deleteDepth = 0;
|
|
@@ -1580,8 +1580,8 @@ function walkSection(node, blocks, tableCtx, tableStack, ctx, depth = 0) {
|
|
|
1580
1580
|
const cs = isNaN(rawCs) ? 1 : rawCs;
|
|
1581
1581
|
const rawRs = parseInt(el.getAttribute("rowSpan") || "1", 10);
|
|
1582
1582
|
const rs = isNaN(rawRs) ? 1 : rawRs;
|
|
1583
|
-
tableCtx.cell.colSpan = clampSpan(cs,
|
|
1584
|
-
tableCtx.cell.rowSpan = clampSpan(rs,
|
|
1583
|
+
tableCtx.cell.colSpan = clampSpan(cs, _chunkNBJB6TJBcjs.MAX_COLS);
|
|
1584
|
+
tableCtx.cell.rowSpan = clampSpan(rs, _chunkNBJB6TJBcjs.MAX_ROWS);
|
|
1585
1585
|
}
|
|
1586
1586
|
break;
|
|
1587
1587
|
case "p": {
|
|
@@ -1803,7 +1803,7 @@ function extractHyperlinkHref(fieldBegin) {
|
|
|
1803
1803
|
let url = (ch.textContent || "").trim();
|
|
1804
1804
|
if (!url) continue;
|
|
1805
1805
|
url = url.replace(/^https?:\/\/(?=https?:\/\/)/i, "");
|
|
1806
|
-
const safe =
|
|
1806
|
+
const safe = _chunkNBJB6TJBcjs.sanitizeHref.call(void 0, url);
|
|
1807
1807
|
if (safe) return safe;
|
|
1808
1808
|
}
|
|
1809
1809
|
return void 0;
|
|
@@ -1938,7 +1938,7 @@ function extractParagraphInfo(para, styleMap, ctx) {
|
|
|
1938
1938
|
case "hyperlink": {
|
|
1939
1939
|
const url = child.getAttribute("url") || child.getAttribute("href") || "";
|
|
1940
1940
|
if (url) {
|
|
1941
|
-
const safe =
|
|
1941
|
+
const safe = _chunkNBJB6TJBcjs.sanitizeHref.call(void 0, url);
|
|
1942
1942
|
if (safe) href = safe;
|
|
1943
1943
|
}
|
|
1944
1944
|
walk(child);
|
|
@@ -2128,7 +2128,7 @@ function decompressStream(data) {
|
|
|
2128
2128
|
return _zlib.inflateRawSync.call(void 0, data, opts);
|
|
2129
2129
|
}
|
|
2130
2130
|
function parseFileHeader(data) {
|
|
2131
|
-
if (data.length < 40) throw new (0,
|
|
2131
|
+
if (data.length < 40) throw new (0, _chunkNBJB6TJBcjs.KordocError)("FileHeader\uAC00 \uB108\uBB34 \uC9E7\uC2B5\uB2C8\uB2E4 (\uCD5C\uC18C 40\uBC14\uC774\uD2B8)");
|
|
2132
2132
|
const sig = data.subarray(0, 32).toString("utf8").replace(/\0+$/, "");
|
|
2133
2133
|
return {
|
|
2134
2134
|
signature: sig,
|
|
@@ -3652,7 +3652,7 @@ function parseHwp5Document(buffer, options) {
|
|
|
3652
3652
|
lenientCfb = parseLenientCfb(buffer);
|
|
3653
3653
|
warnings.push({ message: "\uC190\uC0C1\uB41C CFB \uCEE8\uD14C\uC774\uB108 \u2014 lenient \uBAA8\uB4DC\uB85C \uBCF5\uAD6C", code: "LENIENT_CFB_RECOVERY" });
|
|
3654
3654
|
} catch (e20) {
|
|
3655
|
-
throw new (0,
|
|
3655
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("CFB \uCEE8\uD14C\uC774\uB108 \uD30C\uC2F1 \uC2E4\uD328 (strict \uBC0F lenient \uBAA8\uB450)");
|
|
3656
3656
|
}
|
|
3657
3657
|
}
|
|
3658
3658
|
const findStream = (path) => {
|
|
@@ -3663,11 +3663,11 @@ function parseHwp5Document(buffer, options) {
|
|
|
3663
3663
|
return lenientCfb.findStream(path);
|
|
3664
3664
|
};
|
|
3665
3665
|
const headerData = findStream("/FileHeader");
|
|
3666
|
-
if (!headerData) throw new (0,
|
|
3666
|
+
if (!headerData) throw new (0, _chunkNBJB6TJBcjs.KordocError)("FileHeader \uC2A4\uD2B8\uB9BC \uC5C6\uC74C");
|
|
3667
3667
|
const header = parseFileHeader(headerData);
|
|
3668
|
-
if (header.signature !== "HWP Document File") throw new (0,
|
|
3669
|
-
if (header.flags & FLAG_ENCRYPTED) throw new (0,
|
|
3670
|
-
if (header.flags & FLAG_DRM) throw new (0,
|
|
3668
|
+
if (header.signature !== "HWP Document File") throw new (0, _chunkNBJB6TJBcjs.KordocError)("HWP \uC2DC\uADF8\uB2C8\uCC98 \uBD88\uC77C\uCE58");
|
|
3669
|
+
if (header.flags & FLAG_ENCRYPTED) throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uC554\uD638\uD654\uB41C HWP\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
|
|
3670
|
+
if (header.flags & FLAG_DRM) throw new (0, _chunkNBJB6TJBcjs.KordocError)("DRM \uBCF4\uD638\uB41C HWP\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
|
|
3671
3671
|
const compressed = (header.flags & FLAG_COMPRESSED) !== 0;
|
|
3672
3672
|
const distribution = (header.flags & FLAG_DISTRIBUTION) !== 0;
|
|
3673
3673
|
const metadata = {
|
|
@@ -3676,7 +3676,7 @@ function parseHwp5Document(buffer, options) {
|
|
|
3676
3676
|
if (cfb) extractHwp5Metadata(cfb, metadata);
|
|
3677
3677
|
const docInfo = cfb ? parseDocInfoStream(cfb, compressed) : parseDocInfoFromStream(findStream("/DocInfo"), compressed);
|
|
3678
3678
|
const sections = distribution ? cfb ? findViewTextSections(cfb, compressed) : findViewTextSectionsLenient(lenientCfb, compressed) : cfb ? findSections(cfb) : findSectionsLenient(lenientCfb, compressed);
|
|
3679
|
-
if (sections.length === 0) throw new (0,
|
|
3679
|
+
if (sections.length === 0) throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uC139\uC158 \uC2A4\uD2B8\uB9BC\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
3680
3680
|
metadata.pageCount = sections.length;
|
|
3681
3681
|
const pageFilter = _optionalChain([options, 'optionalAccess', _51 => _51.pages]) ? _chunkMUOQXDZ4cjs.parsePageRange.call(void 0, options.pages, sections.length) : null;
|
|
3682
3682
|
const totalTarget = pageFilter ? pageFilter.size : sections.length;
|
|
@@ -3690,25 +3690,25 @@ function parseHwp5Document(buffer, options) {
|
|
|
3690
3690
|
const sectionData = sections[si];
|
|
3691
3691
|
const data = !distribution && compressed ? decompressStream(Buffer.from(sectionData)) : Buffer.from(sectionData);
|
|
3692
3692
|
totalDecompressed += data.length;
|
|
3693
|
-
if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0,
|
|
3693
|
+
if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
|
|
3694
3694
|
const records = readRecords(data);
|
|
3695
3695
|
const sectionBlocks = parseSection(records, docInfo, warnings, si + 1, doc);
|
|
3696
3696
|
bodyBlocks.push(...sectionBlocks);
|
|
3697
3697
|
parsedSections++;
|
|
3698
3698
|
_optionalChain([options, 'optionalAccess', _52 => _52.onProgress, 'optionalCall', _53 => _53(parsedSections, totalTarget)]);
|
|
3699
3699
|
} catch (secErr) {
|
|
3700
|
-
if (secErr instanceof
|
|
3700
|
+
if (secErr instanceof _chunkNBJB6TJBcjs.KordocError) throw secErr;
|
|
3701
3701
|
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" });
|
|
3702
3702
|
}
|
|
3703
3703
|
}
|
|
3704
3704
|
const blocks = [...doc.headerBlocks, ...bodyBlocks, ...doc.footerBlocks];
|
|
3705
3705
|
const images = cfb ? extractHwp5Images(cfb.FileIndex, blocks, warnings) : extractHwp5ImagesLenient(lenientCfb, blocks, warnings);
|
|
3706
|
-
const flatBlocks =
|
|
3706
|
+
const flatBlocks = _chunkNBJB6TJBcjs.flattenLayoutTables.call(void 0, blocks);
|
|
3707
3707
|
if (docInfo) {
|
|
3708
3708
|
detectHwp5Headings(flatBlocks, docInfo);
|
|
3709
3709
|
}
|
|
3710
3710
|
const outline = flatBlocks.filter((b) => b.type === "heading" && b.level && b.text).map((b) => ({ level: b.level, text: b.text, pageNumber: b.pageNumber }));
|
|
3711
|
-
const markdown =
|
|
3711
|
+
const markdown = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, flatBlocks);
|
|
3712
3712
|
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 };
|
|
3713
3713
|
}
|
|
3714
3714
|
function parseDocInfoStream(cfb, compressed) {
|
|
@@ -3768,9 +3768,9 @@ function detectHwp5Headings(blocks, docInfo) {
|
|
|
3768
3768
|
let level = 0;
|
|
3769
3769
|
if (_optionalChain([block, 'access', _58 => _58.style, 'optionalAccess', _59 => _59.fontSize]) && baseFontSize > 0) {
|
|
3770
3770
|
const ratio = block.style.fontSize / baseFontSize;
|
|
3771
|
-
if (ratio >=
|
|
3772
|
-
else if (ratio >=
|
|
3773
|
-
else if (ratio >=
|
|
3771
|
+
if (ratio >= _chunkNBJB6TJBcjs.HEADING_RATIO_H1) level = 1;
|
|
3772
|
+
else if (ratio >= _chunkNBJB6TJBcjs.HEADING_RATIO_H2) level = 2;
|
|
3773
|
+
else if (ratio >= _chunkNBJB6TJBcjs.HEADING_RATIO_H3) level = 3;
|
|
3774
3774
|
}
|
|
3775
3775
|
if (/^제\d+[장절편]\s/.test(text) && text.length <= 50) {
|
|
3776
3776
|
if (level === 0) level = 2;
|
|
@@ -3855,7 +3855,7 @@ function findSectionsLenient(lcfb, compressed) {
|
|
|
3855
3855
|
if (!raw) break;
|
|
3856
3856
|
const content = compressed ? decompressStream(raw) : raw;
|
|
3857
3857
|
totalDecompressed += content.length;
|
|
3858
|
-
if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0,
|
|
3858
|
+
if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
|
|
3859
3859
|
sections.push({ idx: i, content });
|
|
3860
3860
|
}
|
|
3861
3861
|
if (sections.length === 0) {
|
|
@@ -3867,7 +3867,7 @@ function findSectionsLenient(lcfb, compressed) {
|
|
|
3867
3867
|
if (raw) {
|
|
3868
3868
|
const content = compressed ? decompressStream(raw) : raw;
|
|
3869
3869
|
totalDecompressed += content.length;
|
|
3870
|
-
if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0,
|
|
3870
|
+
if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
|
|
3871
3871
|
sections.push({ idx, content });
|
|
3872
3872
|
}
|
|
3873
3873
|
}
|
|
@@ -3884,7 +3884,7 @@ function findViewTextSectionsLenient(lcfb, compressed) {
|
|
|
3884
3884
|
try {
|
|
3885
3885
|
const content = decryptViewText(raw, compressed);
|
|
3886
3886
|
totalDecompressed += content.length;
|
|
3887
|
-
if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0,
|
|
3887
|
+
if (totalDecompressed > MAX_TOTAL_DECOMPRESS) throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uCD1D \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (decompression bomb \uC758\uC2EC)");
|
|
3888
3888
|
sections.push({ idx: i, content });
|
|
3889
3889
|
} catch (e25) {
|
|
3890
3890
|
break;
|
|
@@ -3987,7 +3987,7 @@ function parseParagraph(records, start, end, ctx) {
|
|
|
3987
3987
|
const ctrl = ctrls[r.ctrlIdx];
|
|
3988
3988
|
if (!_optionalChain([ctrl, 'optionalAccess', _66 => _66.href]) || r.end <= r.start) continue;
|
|
3989
3989
|
if (applied.some(([s, e]) => r.start < e && r.end > s)) continue;
|
|
3990
|
-
const href =
|
|
3990
|
+
const href = _chunkNBJB6TJBcjs.sanitizeHref.call(void 0, ctrl.href);
|
|
3991
3991
|
if (!href) continue;
|
|
3992
3992
|
const anchor = text.slice(r.start, r.end);
|
|
3993
3993
|
if (!anchor.trim()) continue;
|
|
@@ -4220,8 +4220,8 @@ function parseTableControl(ctrl, records, ctx) {
|
|
|
4220
4220
|
let tableIdx = -1;
|
|
4221
4221
|
for (let i2 = childStart; i2 < childEnd; i2++) {
|
|
4222
4222
|
if (records[i2].tagId === TAG_TABLE && records[i2].data.length >= 8) {
|
|
4223
|
-
rows = Math.min(records[i2].data.readUInt16LE(4),
|
|
4224
|
-
cols = Math.min(records[i2].data.readUInt16LE(6),
|
|
4223
|
+
rows = Math.min(records[i2].data.readUInt16LE(4), _chunkNBJB6TJBcjs.MAX_ROWS);
|
|
4224
|
+
cols = Math.min(records[i2].data.readUInt16LE(6), _chunkNBJB6TJBcjs.MAX_COLS);
|
|
4225
4225
|
tableIdx = i2;
|
|
4226
4226
|
break;
|
|
4227
4227
|
}
|
|
@@ -4270,7 +4270,7 @@ function parseTableControl(ctrl, records, ctx) {
|
|
|
4270
4270
|
return table2;
|
|
4271
4271
|
}
|
|
4272
4272
|
const cellRows = arrangeCells(rows, cols, cells);
|
|
4273
|
-
const table =
|
|
4273
|
+
const table = _chunkNBJB6TJBcjs.buildTable.call(void 0, cellRows);
|
|
4274
4274
|
if (caption && table.rows > 0) table.caption = caption;
|
|
4275
4275
|
return table.rows > 0 ? table : null;
|
|
4276
4276
|
}
|
|
@@ -4287,8 +4287,8 @@ function parseCell(records, lhIdx, end, ctx) {
|
|
|
4287
4287
|
rowAddr = rec.data.readUInt16LE(10);
|
|
4288
4288
|
const cs = rec.data.readUInt16LE(12);
|
|
4289
4289
|
const rs = rec.data.readUInt16LE(14);
|
|
4290
|
-
if (cs > 0) colSpan = Math.min(cs,
|
|
4291
|
-
if (rs > 0) rowSpan = Math.min(rs,
|
|
4290
|
+
if (cs > 0) colSpan = Math.min(cs, _chunkNBJB6TJBcjs.MAX_COLS);
|
|
4291
|
+
if (rs > 0) rowSpan = Math.min(rs, _chunkNBJB6TJBcjs.MAX_ROWS);
|
|
4292
4292
|
}
|
|
4293
4293
|
const blocks = ctx.depth < MAX_NEST_DEPTH ? parseParagraphList(records, lhIdx + 1, end, { ...ctx, depth: ctx.depth + 1 }) : [];
|
|
4294
4294
|
const parts = [];
|
|
@@ -4298,7 +4298,7 @@ function parseCell(records, lhIdx, end, ctx) {
|
|
|
4298
4298
|
parts.push(``);
|
|
4299
4299
|
hasStructure = true;
|
|
4300
4300
|
} else if (b.type === "table" && b.table) {
|
|
4301
|
-
const flat =
|
|
4301
|
+
const flat = _chunkNBJB6TJBcjs.convertTableToText.call(void 0, b.table.cells);
|
|
4302
4302
|
if (flat) parts.push(flat);
|
|
4303
4303
|
hasStructure = true;
|
|
4304
4304
|
} else if (b.text) {
|
|
@@ -16501,8 +16501,8 @@ function parseHwp3Document(buffer, _options) {
|
|
|
16501
16501
|
try {
|
|
16502
16502
|
body = _zlib.inflateRawSync.call(void 0, tail);
|
|
16503
16503
|
} catch (err) {
|
|
16504
|
-
const
|
|
16505
|
-
throw new Error(`HWP3 \uC555\uCD95 \uD574\uC81C \uC2E4\uD328: ${
|
|
16504
|
+
const msg2 = err instanceof Error ? err.message : String(err);
|
|
16505
|
+
throw new Error(`HWP3 \uC555\uCD95 \uD574\uC81C \uC2E4\uD328: ${msg2}`);
|
|
16506
16506
|
}
|
|
16507
16507
|
} else {
|
|
16508
16508
|
body = tail;
|
|
@@ -16732,7 +16732,7 @@ function getTextContent(el) {
|
|
|
16732
16732
|
return _nullishCoalesce(_optionalChain([el, 'access', _79 => _79.textContent, 'optionalAccess', _80 => _80.trim, 'call', _81 => _81()]), () => ( ""));
|
|
16733
16733
|
}
|
|
16734
16734
|
function parseXml(text) {
|
|
16735
|
-
return new (0, _xmldom.DOMParser)().parseFromString(
|
|
16735
|
+
return new (0, _xmldom.DOMParser)().parseFromString(_chunkNBJB6TJBcjs.stripDtd.call(void 0, text), "text/xml");
|
|
16736
16736
|
}
|
|
16737
16737
|
function parseSharedStrings(xml) {
|
|
16738
16738
|
const doc = parseXml(xml);
|
|
@@ -16876,7 +16876,7 @@ function sheetToBlocks(sheetName, grid, merges, maxRow, maxCol, sheetIndex) {
|
|
|
16876
16876
|
cellRows.push(row);
|
|
16877
16877
|
}
|
|
16878
16878
|
if (cellRows.length > 0) {
|
|
16879
|
-
const table =
|
|
16879
|
+
const table = _chunkNBJB6TJBcjs.buildTable.call(void 0, cellRows);
|
|
16880
16880
|
if (table.rows > 0) {
|
|
16881
16881
|
blocks.push({ type: "table", table, pageNumber: sheetIndex + 1 });
|
|
16882
16882
|
}
|
|
@@ -16884,12 +16884,12 @@ function sheetToBlocks(sheetName, grid, merges, maxRow, maxCol, sheetIndex) {
|
|
|
16884
16884
|
return blocks;
|
|
16885
16885
|
}
|
|
16886
16886
|
async function parseXlsxDocument(buffer, options) {
|
|
16887
|
-
|
|
16887
|
+
_chunkNBJB6TJBcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE3);
|
|
16888
16888
|
const zip = await _jszip2.default.loadAsync(buffer);
|
|
16889
16889
|
const warnings = [];
|
|
16890
16890
|
const workbookFile = zip.file("xl/workbook.xml");
|
|
16891
16891
|
if (!workbookFile) {
|
|
16892
|
-
throw new (0,
|
|
16892
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 XLSX \uD30C\uC77C: xl/workbook.xml\uC774 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
16893
16893
|
}
|
|
16894
16894
|
let sharedStrings = [];
|
|
16895
16895
|
const ssFile = zip.file("xl/sharedStrings.xml");
|
|
@@ -16898,7 +16898,7 @@ async function parseXlsxDocument(buffer, options) {
|
|
|
16898
16898
|
}
|
|
16899
16899
|
const sheets = parseWorkbook(await workbookFile.async("text"));
|
|
16900
16900
|
if (sheets.length === 0) {
|
|
16901
|
-
throw new (0,
|
|
16901
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("XLSX \uD30C\uC77C\uC5D0 \uC2DC\uD2B8\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
16902
16902
|
}
|
|
16903
16903
|
let relsMap = /* @__PURE__ */ new Map();
|
|
16904
16904
|
const relsFile = zip.file("xl/_rels/workbook.xml.rels");
|
|
@@ -16970,7 +16970,7 @@ async function parseXlsxDocument(buffer, options) {
|
|
|
16970
16970
|
} catch (e26) {
|
|
16971
16971
|
}
|
|
16972
16972
|
}
|
|
16973
|
-
const markdown =
|
|
16973
|
+
const markdown = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, blocks);
|
|
16974
16974
|
return { markdown, blocks, metadata, warnings: warnings.length > 0 ? warnings : void 0 };
|
|
16975
16975
|
}
|
|
16976
16976
|
|
|
@@ -17377,11 +17377,11 @@ function processGlobals(records) {
|
|
|
17377
17377
|
let encrypted = false;
|
|
17378
17378
|
const firstBof = records[0];
|
|
17379
17379
|
if (!firstBof || firstBof.opcode !== OP_BOF) {
|
|
17380
|
-
throw new (0,
|
|
17380
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("XLS: \uCCAB \uB808\uCF54\uB4DC\uAC00 BOF\uAC00 \uC544\uB2D8");
|
|
17381
17381
|
}
|
|
17382
17382
|
const bof = decodeBof(firstBof.data);
|
|
17383
17383
|
if (!bof || bof.dt !== DT_GLOBALS) {
|
|
17384
|
-
throw new (0,
|
|
17384
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("XLS: Globals \uC11C\uBE0C\uC2A4\uD2B8\uB9BC BOF \uB204\uB77D");
|
|
17385
17385
|
}
|
|
17386
17386
|
let i = 1;
|
|
17387
17387
|
while (i < records.length) {
|
|
@@ -17496,7 +17496,7 @@ function sheetToBlocks2(sheetName, sheet, sheetIndex) {
|
|
|
17496
17496
|
cellRows.push(row);
|
|
17497
17497
|
}
|
|
17498
17498
|
if (cellRows.length > 0) {
|
|
17499
|
-
const table =
|
|
17499
|
+
const table = _chunkNBJB6TJBcjs.buildTable.call(void 0, cellRows);
|
|
17500
17500
|
if (table.rows > 0) {
|
|
17501
17501
|
blocks.push({ type: "table", table, pageNumber: sheetIndex + 1 });
|
|
17502
17502
|
}
|
|
@@ -17509,21 +17509,21 @@ async function parseXlsDocument(buffer, options) {
|
|
|
17509
17509
|
try {
|
|
17510
17510
|
cfb = parseLenientCfb(buf);
|
|
17511
17511
|
} catch (e) {
|
|
17512
|
-
throw new (0,
|
|
17512
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)(
|
|
17513
17513
|
`XLS: OLE2 \uC2DC\uADF8\uB2C8\uCC98 \uAC80\uC99D \uC2E4\uD328 \u2014 ${e instanceof Error ? e.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"}`
|
|
17514
17514
|
);
|
|
17515
17515
|
}
|
|
17516
17516
|
const wb = _nullishCoalesce(cfb.findStream("/Workbook"), () => ( cfb.findStream("/Book")));
|
|
17517
17517
|
if (!wb) {
|
|
17518
|
-
throw new (0,
|
|
17518
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("XLS: Workbook \uC2A4\uD2B8\uB9BC\uC774 \uC5C6\uC74C (BIFF5 \uB610\uB294 \uBE44\uD45C\uC900 \uD30C\uC77C)");
|
|
17519
17519
|
}
|
|
17520
17520
|
const records = readRecords2(wb);
|
|
17521
17521
|
if (records.length === 0) {
|
|
17522
|
-
throw new (0,
|
|
17522
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("XLS: \uC2DC\uADF8\uB2C8\uCC98 \uB808\uCF54\uB4DC\uAC00 \uC5C6\uC74C (Workbook \uC2A4\uD2B8\uB9BC \uC190\uC0C1)");
|
|
17523
17523
|
}
|
|
17524
17524
|
const firstBof = decodeBof(records[0].data);
|
|
17525
17525
|
if (firstBof && firstBof.vers !== 1536) {
|
|
17526
|
-
throw new (0,
|
|
17526
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)(
|
|
17527
17527
|
`XLS: BIFF8(0x0600)\uB9CC \uC9C0\uC6D0 \u2014 \uBCF8 \uD30C\uC77C\uC740 0x${firstBof.vers.toString(16)}`
|
|
17528
17528
|
);
|
|
17529
17529
|
}
|
|
@@ -17583,7 +17583,7 @@ async function parseXlsDocument(buffer, options) {
|
|
|
17583
17583
|
pageCount: totalSheets
|
|
17584
17584
|
};
|
|
17585
17585
|
return {
|
|
17586
|
-
markdown:
|
|
17586
|
+
markdown: _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, allBlocks),
|
|
17587
17587
|
blocks: allBlocks,
|
|
17588
17588
|
metadata,
|
|
17589
17589
|
warnings: warnings.length > 0 ? warnings : void 0
|
|
@@ -18009,7 +18009,7 @@ function getAttr(el, localName3) {
|
|
|
18009
18009
|
return null;
|
|
18010
18010
|
}
|
|
18011
18011
|
function parseXml2(text) {
|
|
18012
|
-
return new (0, _xmldom.DOMParser)().parseFromString(
|
|
18012
|
+
return new (0, _xmldom.DOMParser)().parseFromString(_chunkNBJB6TJBcjs.stripDtd.call(void 0, text), "text/xml");
|
|
18013
18013
|
}
|
|
18014
18014
|
function parseStyles(xml) {
|
|
18015
18015
|
const doc = parseXml2(xml);
|
|
@@ -18328,12 +18328,12 @@ async function extractImages(zip, rels, doc) {
|
|
|
18328
18328
|
return { blocks, images };
|
|
18329
18329
|
}
|
|
18330
18330
|
async function parseDocxDocument(buffer, options) {
|
|
18331
|
-
|
|
18331
|
+
_chunkNBJB6TJBcjs.precheckZipSize.call(void 0, buffer, MAX_DECOMPRESS_SIZE4);
|
|
18332
18332
|
const zip = await _jszip2.default.loadAsync(buffer);
|
|
18333
18333
|
const warnings = [];
|
|
18334
18334
|
const docFile = zip.file("word/document.xml");
|
|
18335
18335
|
if (!docFile) {
|
|
18336
|
-
throw new (0,
|
|
18336
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("\uC720\uD6A8\uD558\uC9C0 \uC54A\uC740 DOCX \uD30C\uC77C: word/document.xml\uC774 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
18337
18337
|
}
|
|
18338
18338
|
let rels = /* @__PURE__ */ new Map();
|
|
18339
18339
|
const relsFile = zip.file("word/_rels/document.xml.rels");
|
|
@@ -18368,7 +18368,7 @@ async function parseDocxDocument(buffer, options) {
|
|
|
18368
18368
|
const doc = parseXml2(docXml);
|
|
18369
18369
|
const body = findElements(doc, "body");
|
|
18370
18370
|
if (body.length === 0) {
|
|
18371
|
-
throw new (0,
|
|
18371
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("DOCX \uBCF8\uBB38(w:body)\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
18372
18372
|
}
|
|
18373
18373
|
const blocks = [];
|
|
18374
18374
|
const bodyEl = body[0];
|
|
@@ -18408,7 +18408,7 @@ async function parseDocxDocument(buffer, options) {
|
|
|
18408
18408
|
}
|
|
18409
18409
|
}
|
|
18410
18410
|
const outline = blocks.filter((b) => b.type === "heading").map((b) => ({ level: _nullishCoalesce(b.level, () => ( 2)), text: _nullishCoalesce(b.text, () => ( "")) }));
|
|
18411
|
-
const markdown =
|
|
18411
|
+
const markdown = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, blocks);
|
|
18412
18412
|
return {
|
|
18413
18413
|
markdown,
|
|
18414
18414
|
blocks,
|
|
@@ -18431,11 +18431,11 @@ function parseHwpmlDocument(buffer, options) {
|
|
|
18431
18431
|
}
|
|
18432
18432
|
const text = new TextDecoder("utf-8").decode(buffer).replace(/^\uFEFF/, "");
|
|
18433
18433
|
const normalized = text.replace(/ /g, " ");
|
|
18434
|
-
const xml =
|
|
18434
|
+
const xml = _chunkNBJB6TJBcjs.stripDtd.call(void 0, normalized);
|
|
18435
18435
|
const warnings = [];
|
|
18436
18436
|
const parser = new (0, _xmldom.DOMParser)({
|
|
18437
|
-
onError: (_level,
|
|
18438
|
-
warnings.push({ message: `HWPML XML \uD30C\uC2F1 \uACBD\uACE0: ${
|
|
18437
|
+
onError: (_level, msg2) => {
|
|
18438
|
+
warnings.push({ message: `HWPML XML \uD30C\uC2F1 \uACBD\uACE0: ${msg2}`, code: "MALFORMED_XML" });
|
|
18439
18439
|
}
|
|
18440
18440
|
});
|
|
18441
18441
|
const doc = parser.parseFromString(xml, "text/xml");
|
|
@@ -18471,7 +18471,7 @@ function parseHwpmlDocument(buffer, options) {
|
|
|
18471
18471
|
parseSection2(el, blocks, paraShapeMap, sectionIdx, warnings);
|
|
18472
18472
|
}
|
|
18473
18473
|
const outline = blocks.filter((b) => b.type === "heading" && b.text).map((b) => ({ level: _nullishCoalesce(b.level, () => ( 1)), text: b.text, pageNumber: b.pageNumber }));
|
|
18474
|
-
const markdown =
|
|
18474
|
+
const markdown = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, blocks);
|
|
18475
18475
|
return {
|
|
18476
18476
|
markdown,
|
|
18477
18477
|
blocks,
|
|
@@ -18613,7 +18613,7 @@ function parseTable2(el, blocks, paraShapeMap, sectionNum, warnings) {
|
|
|
18613
18613
|
const cellRows = grid.map(
|
|
18614
18614
|
(row) => row.map((cell) => _nullishCoalesce(cell, () => ( { text: "", colSpan: 1, rowSpan: 1 })))
|
|
18615
18615
|
);
|
|
18616
|
-
const table =
|
|
18616
|
+
const table = _chunkNBJB6TJBcjs.buildTable.call(void 0, cellRows);
|
|
18617
18617
|
blocks.push({ type: "table", table, pageNumber: sectionNum });
|
|
18618
18618
|
}
|
|
18619
18619
|
function extractCellText(cellEl) {
|
|
@@ -19014,7 +19014,7 @@ async function fillHwpx(hwpxBuffer, values) {
|
|
|
19014
19014
|
const normalizedValues = normalizeValues(values);
|
|
19015
19015
|
const sectionFiles = Object.keys(zip.files).filter((name) => /[Ss]ection\d+\.xml$/i.test(name)).sort();
|
|
19016
19016
|
if (sectionFiles.length === 0) {
|
|
19017
|
-
throw new (0,
|
|
19017
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("HWPX\uC5D0\uC11C \uC139\uC158 \uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
19018
19018
|
}
|
|
19019
19019
|
const xmlParser = new (0, _xmldom.DOMParser)();
|
|
19020
19020
|
const xmlSerializer = new (0, _xmldom.XMLSerializer)();
|
|
@@ -19022,7 +19022,7 @@ async function fillHwpx(hwpxBuffer, values) {
|
|
|
19022
19022
|
const zipEntry = zip.file(sectionPath);
|
|
19023
19023
|
if (!zipEntry) continue;
|
|
19024
19024
|
const rawXml = await zipEntry.async("text");
|
|
19025
|
-
const doc = xmlParser.parseFromString(
|
|
19025
|
+
const doc = xmlParser.parseFromString(_chunkNBJB6TJBcjs.stripDtd.call(void 0, rawXml), "text/xml");
|
|
19026
19026
|
if (!doc.documentElement) continue;
|
|
19027
19027
|
let modified = false;
|
|
19028
19028
|
const tables = findAllElements(doc.documentElement, "tbl");
|
|
@@ -20439,19 +20439,19 @@ function parseCentralDirectory(buf) {
|
|
|
20439
20439
|
}
|
|
20440
20440
|
}
|
|
20441
20441
|
}
|
|
20442
|
-
if (eocdOffset < 0) throw new (0,
|
|
20442
|
+
if (eocdOffset < 0) throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP EOCD\uB97C \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
20443
20443
|
const totalEntries = view.getUint16(eocdOffset + 10, true);
|
|
20444
20444
|
const cdSize = view.getUint32(eocdOffset + 12, true);
|
|
20445
20445
|
const cdOffset = view.getUint32(eocdOffset + 16, true);
|
|
20446
|
-
if (cdOffset === 4294967295 || totalEntries === 65535) throw new (0,
|
|
20446
|
+
if (cdOffset === 4294967295 || totalEntries === 65535) throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
|
|
20447
20447
|
if (eocdOffset >= 20 && view.getUint32(eocdOffset - 20, true) === ZIP64_EOCD_LOC_SIG) {
|
|
20448
|
-
throw new (0,
|
|
20448
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
|
|
20449
20449
|
}
|
|
20450
20450
|
const decoder = new TextDecoder("utf-8");
|
|
20451
20451
|
const entries = [];
|
|
20452
20452
|
let pos = cdOffset;
|
|
20453
20453
|
for (let i = 0; i < totalEntries; i++) {
|
|
20454
|
-
if (view.getUint32(pos, true) !== CD_SIG) throw new (0,
|
|
20454
|
+
if (view.getUint32(pos, true) !== CD_SIG) throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP Central Directory \uC190\uC0C1");
|
|
20455
20455
|
const flags = view.getUint16(pos + 8, true);
|
|
20456
20456
|
const method = view.getUint16(pos + 10, true);
|
|
20457
20457
|
const crc = view.getUint32(pos + 16, true);
|
|
@@ -20462,7 +20462,7 @@ function parseCentralDirectory(buf) {
|
|
|
20462
20462
|
const commentLen = view.getUint16(pos + 32, true);
|
|
20463
20463
|
const localOffset = view.getUint32(pos + 42, true);
|
|
20464
20464
|
if (compSize === 4294967295 || uncompSize === 4294967295 || localOffset === 4294967295) {
|
|
20465
|
-
throw new (0,
|
|
20465
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP64\uB294 \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
|
|
20466
20466
|
}
|
|
20467
20467
|
const name = decoder.decode(buf.subarray(pos + 46, pos + 46 + nameLen));
|
|
20468
20468
|
const cdEnd = pos + 46 + nameLen + extraLen + commentLen;
|
|
@@ -20491,7 +20491,7 @@ function patchZipEntries(original, replacements) {
|
|
|
20491
20491
|
const { entries, cdOffset, eocdOffset } = parseCentralDirectory(original);
|
|
20492
20492
|
const view = new DataView(original.buffer, original.byteOffset, original.byteLength);
|
|
20493
20493
|
for (const name of replacements.keys()) {
|
|
20494
|
-
if (!entries.some((e) => e.name === name)) throw new (0,
|
|
20494
|
+
if (!entries.some((e) => e.name === name)) throw new (0, _chunkNBJB6TJBcjs.KordocError)(`ZIP\uC5D0 \uC5C6\uB294 \uC5D4\uD2B8\uB9AC: ${name}`);
|
|
20495
20495
|
}
|
|
20496
20496
|
const byLocal = [...entries].sort((a, b) => a.localOffset - b.localOffset);
|
|
20497
20497
|
const segments = [];
|
|
@@ -20509,7 +20509,7 @@ function patchZipEntries(original, replacements) {
|
|
|
20509
20509
|
offset += seg.length;
|
|
20510
20510
|
continue;
|
|
20511
20511
|
}
|
|
20512
|
-
if (view.getUint32(e.localOffset, true) !== LOCAL_SIG) throw new (0,
|
|
20512
|
+
if (view.getUint32(e.localOffset, true) !== LOCAL_SIG) throw new (0, _chunkNBJB6TJBcjs.KordocError)("ZIP \uB85C\uCEEC \uD5E4\uB354 \uC2DC\uADF8\uB2C8\uCC98 \uBD88\uC77C\uCE58");
|
|
20513
20513
|
const nameLen = view.getUint16(e.localOffset + 26, true);
|
|
20514
20514
|
const extraLen = view.getUint16(e.localOffset + 28, true);
|
|
20515
20515
|
const headerLen = 30 + nameLen + extraLen;
|
|
@@ -20616,7 +20616,7 @@ function escapeGfm(text) {
|
|
|
20616
20616
|
}
|
|
20617
20617
|
var HWP_SHAPE_ALT_TEXT_RE = /(?:모서리가 둥근 |둥근 )?(?:사각형|직사각형|정사각형|원|타원|삼각형|이등변 삼각형|직각 삼각형|선|직선|곡선|화살표|굵은 화살표|이중 화살표|오각형|육각형|팔각형|별|[4-8]점별|십자|십자형|구름|구름형|마름모|도넛|평행사변형|사다리꼴|부채꼴|호|반원|물결|번개|하트|빗금|블록 화살표|수식|표|그림|개체|그리기\s?개체|묶음\s?개체|글상자|수식\s?개체|OLE\s?개체)\s?입니다\.?/g;
|
|
20618
20618
|
function sanitizeText(text) {
|
|
20619
|
-
let result =
|
|
20619
|
+
let result = _chunkNBJB6TJBcjs.mapPuaText.call(void 0, text).replace(/[\u{F0000}-\u{FFFFD}]/gu, "").replace(HWP_SHAPE_ALT_TEXT_RE, "").replace(/ +/g, " ").trim();
|
|
20620
20620
|
if (result.length <= 30 && result.includes(" ")) {
|
|
20621
20621
|
const tokens = result.split(" ");
|
|
20622
20622
|
const koreanSingleCharCount = tokens.filter((t) => t.length === 1 && /[가-ㄱ-ㆎ]/.test(t)).length;
|
|
@@ -21167,9 +21167,9 @@ function buildOrigUnits(blocks) {
|
|
|
21167
21167
|
if (block.type === "paragraph" && block.text && /^\[별표\s*\d+/.test(sanitizeText(block.text))) {
|
|
21168
21168
|
const next = blocks[i + 1];
|
|
21169
21169
|
if (_optionalChain([next, 'optionalAccess', _174 => _174.type]) === "paragraph" && next.text && /관련\)?$/.test(next.text)) consume = 2;
|
|
21170
|
-
chunk =
|
|
21170
|
+
chunk = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, blocks.slice(i, i + consume));
|
|
21171
21171
|
} else {
|
|
21172
|
-
chunk =
|
|
21172
|
+
chunk = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, [block]);
|
|
21173
21173
|
}
|
|
21174
21174
|
if (chunk) {
|
|
21175
21175
|
const subUnits = splitMarkdownUnits(chunk);
|
|
@@ -21465,6 +21465,838 @@ function sectionPathsFromManifest(xml) {
|
|
|
21465
21465
|
return Array.from(idToHref.entries()).filter(([id]) => isSectionId(id)).sort((a, b) => a[0].localeCompare(b[0])).map(([, href]) => href);
|
|
21466
21466
|
}
|
|
21467
21467
|
|
|
21468
|
+
// src/roundtrip/hwp5-patch.ts
|
|
21469
|
+
|
|
21470
|
+
|
|
21471
|
+
|
|
21472
|
+
// src/roundtrip/ole-surgeon.ts
|
|
21473
|
+
var SECTOR = 512;
|
|
21474
|
+
var MINI_SECTOR = 64;
|
|
21475
|
+
var MINI_CUTOFF = 4096;
|
|
21476
|
+
var FREESECT = 4294967295;
|
|
21477
|
+
var ENDOFCHAIN = 4294967294;
|
|
21478
|
+
var FATSECT = 4294967293;
|
|
21479
|
+
var OleSurgeonError = class extends Error {
|
|
21480
|
+
};
|
|
21481
|
+
function replaceOleStream(file, path, newData) {
|
|
21482
|
+
const surgeon = new Surgeon(file);
|
|
21483
|
+
surgeon.replace(path, newData);
|
|
21484
|
+
return surgeon.finish();
|
|
21485
|
+
}
|
|
21486
|
+
var Surgeon = (_class2 = class {
|
|
21487
|
+
|
|
21488
|
+
__init4() {this.fat = []}
|
|
21489
|
+
/** FAT 배열을 구성하는 섹터 번호들 (DIFAT 순서) */
|
|
21490
|
+
__init5() {this.fatSectors = []}
|
|
21491
|
+
__init6() {this.miniFat = []}
|
|
21492
|
+
__init7() {this.miniFatSectors = []}
|
|
21493
|
+
__init8() {this.dirSectors = []}
|
|
21494
|
+
__init9() {this.entries = []}
|
|
21495
|
+
constructor(file) {;_class2.prototype.__init4.call(this);_class2.prototype.__init5.call(this);_class2.prototype.__init6.call(this);_class2.prototype.__init7.call(this);_class2.prototype.__init8.call(this);_class2.prototype.__init9.call(this);
|
|
21496
|
+
if (file.length < SECTOR || file.readUInt32LE(0) !== 3759263696) {
|
|
21497
|
+
throw new OleSurgeonError("OLE \uC2DC\uADF8\uB2C8\uCC98\uAC00 \uC544\uB2D9\uB2C8\uB2E4");
|
|
21498
|
+
}
|
|
21499
|
+
if (file.readUInt16LE(26) !== 3 || file.readUInt16LE(30) !== 9) {
|
|
21500
|
+
throw new OleSurgeonError("CFB v3(512B \uC139\uD130)\uB9CC \uC9C0\uC6D0\uD569\uB2C8\uB2E4");
|
|
21501
|
+
}
|
|
21502
|
+
const padded = Math.ceil((file.length - SECTOR) / SECTOR) * SECTOR + SECTOR;
|
|
21503
|
+
this.buf = Buffer.alloc(padded);
|
|
21504
|
+
file.copy(this.buf);
|
|
21505
|
+
this.loadFat();
|
|
21506
|
+
this.loadMiniFat();
|
|
21507
|
+
this.loadDirectory();
|
|
21508
|
+
}
|
|
21509
|
+
// ── 로드 ──
|
|
21510
|
+
loadFat() {
|
|
21511
|
+
const difat = [];
|
|
21512
|
+
for (let i = 0; i < 109; i++) difat.push(this.buf.readUInt32LE(76 + i * 4));
|
|
21513
|
+
let difatSector = this.buf.readUInt32LE(68);
|
|
21514
|
+
let guard = 0;
|
|
21515
|
+
while (difatSector !== ENDOFCHAIN && difatSector !== FREESECT && guard++ < 1e6) {
|
|
21516
|
+
const off = this.sectorOffset(difatSector);
|
|
21517
|
+
for (let i = 0; i < 127; i++) difat.push(this.buf.readUInt32LE(off + i * 4));
|
|
21518
|
+
difatSector = this.buf.readUInt32LE(off + 127 * 4);
|
|
21519
|
+
}
|
|
21520
|
+
this.fatSectors = difat.filter((s) => s !== FREESECT);
|
|
21521
|
+
for (const s of this.fatSectors) {
|
|
21522
|
+
const off = this.sectorOffset(s);
|
|
21523
|
+
for (let i = 0; i < 128; i++) this.fat.push(this.buf.readUInt32LE(off + i * 4));
|
|
21524
|
+
}
|
|
21525
|
+
}
|
|
21526
|
+
loadMiniFat() {
|
|
21527
|
+
const start = this.buf.readUInt32LE(60);
|
|
21528
|
+
this.miniFatSectors = start === ENDOFCHAIN || start === FREESECT ? [] : this.chain(start);
|
|
21529
|
+
for (const s of this.miniFatSectors) {
|
|
21530
|
+
const off = this.sectorOffset(s);
|
|
21531
|
+
for (let i = 0; i < 128; i++) this.miniFat.push(this.buf.readUInt32LE(off + i * 4));
|
|
21532
|
+
}
|
|
21533
|
+
}
|
|
21534
|
+
loadDirectory() {
|
|
21535
|
+
this.dirSectors = this.chain(this.buf.readUInt32LE(48));
|
|
21536
|
+
for (let si = 0; si < this.dirSectors.length; si++) {
|
|
21537
|
+
const off = this.sectorOffset(this.dirSectors[si]);
|
|
21538
|
+
for (let i = 0; i < 4; i++) {
|
|
21539
|
+
const e = off + i * 128;
|
|
21540
|
+
const nameLen = this.buf.readUInt16LE(e + 64);
|
|
21541
|
+
const name = nameLen >= 2 ? this.buf.subarray(e, e + nameLen - 2).toString("utf16le") : "";
|
|
21542
|
+
this.entries.push({
|
|
21543
|
+
index: si * 4 + i,
|
|
21544
|
+
name,
|
|
21545
|
+
type: this.buf[e + 66],
|
|
21546
|
+
left: this.buf.readInt32LE(e + 68),
|
|
21547
|
+
right: this.buf.readInt32LE(e + 72),
|
|
21548
|
+
child: this.buf.readInt32LE(e + 76),
|
|
21549
|
+
start: this.buf.readUInt32LE(e + 116),
|
|
21550
|
+
size: this.buf.readUInt32LE(e + 120)
|
|
21551
|
+
});
|
|
21552
|
+
}
|
|
21553
|
+
}
|
|
21554
|
+
}
|
|
21555
|
+
// ── 헬퍼 ──
|
|
21556
|
+
sectorOffset(n) {
|
|
21557
|
+
const off = SECTOR + n * SECTOR;
|
|
21558
|
+
if (n >= 4294967290 || off + SECTOR > this.buf.length) throw new OleSurgeonError(`\uC139\uD130 \uBC94\uC704 \uCD08\uACFC: ${n}`);
|
|
21559
|
+
return off;
|
|
21560
|
+
}
|
|
21561
|
+
chain(start) {
|
|
21562
|
+
const out = [];
|
|
21563
|
+
let s = start;
|
|
21564
|
+
while (s !== ENDOFCHAIN) {
|
|
21565
|
+
if (s === FREESECT || s >= this.fat.length || out.length > this.fat.length) {
|
|
21566
|
+
throw new OleSurgeonError("FAT \uCCB4\uC778 \uC190\uC0C1");
|
|
21567
|
+
}
|
|
21568
|
+
out.push(s);
|
|
21569
|
+
s = this.fat[s];
|
|
21570
|
+
}
|
|
21571
|
+
return out;
|
|
21572
|
+
}
|
|
21573
|
+
miniChain(start) {
|
|
21574
|
+
const out = [];
|
|
21575
|
+
let s = start;
|
|
21576
|
+
while (s !== ENDOFCHAIN) {
|
|
21577
|
+
if (s === FREESECT || s >= this.miniFat.length || out.length > this.miniFat.length) {
|
|
21578
|
+
throw new OleSurgeonError("miniFAT \uCCB4\uC778 \uC190\uC0C1");
|
|
21579
|
+
}
|
|
21580
|
+
out.push(s);
|
|
21581
|
+
s = this.miniFat[s];
|
|
21582
|
+
}
|
|
21583
|
+
return out;
|
|
21584
|
+
}
|
|
21585
|
+
/** 디렉토리 트리에서 경로 해석 (형제 = L/R 이진 트리, 자식 = child) */
|
|
21586
|
+
findEntry(path) {
|
|
21587
|
+
const parts = path.replace(/^\//, "").split("/");
|
|
21588
|
+
let scope = _nullishCoalesce(_optionalChain([this, 'access', _181 => _181.entries, 'access', _182 => _182[0], 'optionalAccess', _183 => _183.child]), () => ( -1));
|
|
21589
|
+
let current;
|
|
21590
|
+
for (const part of parts) {
|
|
21591
|
+
const search = (idx) => {
|
|
21592
|
+
if (idx < 0 || idx >= this.entries.length) return void 0;
|
|
21593
|
+
const e = this.entries[idx];
|
|
21594
|
+
return _nullishCoalesce(_nullishCoalesce(search(e.left), () => ( (e.name === part ? e : void 0))), () => ( search(e.right)));
|
|
21595
|
+
};
|
|
21596
|
+
current = search(scope);
|
|
21597
|
+
if (!current) throw new OleSurgeonError(`\uC2A4\uD2B8\uB9BC \uC5C6\uC74C: ${path}`);
|
|
21598
|
+
scope = current.child;
|
|
21599
|
+
}
|
|
21600
|
+
if (!current || current.type !== 2) throw new OleSurgeonError(`\uC2A4\uD2B8\uB9BC\uC774 \uC544\uB2D8: ${path}`);
|
|
21601
|
+
return current;
|
|
21602
|
+
}
|
|
21603
|
+
rootEntry() {
|
|
21604
|
+
return this.entries[0];
|
|
21605
|
+
}
|
|
21606
|
+
// ── 할당 ──
|
|
21607
|
+
/**
|
|
21608
|
+
* FAT에서 빈 섹터 n개 확보 (부족하면 파일 끝에 추가) — 섹터 번호 목록 반환.
|
|
21609
|
+
* 확보 즉시 ENDOFCHAIN으로 마킹해 같은 수술 내 중복 할당을 방지한다 (체인 링크는
|
|
21610
|
+
* 호출자가 덮어씀).
|
|
21611
|
+
*/
|
|
21612
|
+
allocSectors(n) {
|
|
21613
|
+
const out = [];
|
|
21614
|
+
for (let i = 0; i < this.fat.length && out.length < n; i++) {
|
|
21615
|
+
if (this.fat[i] !== FREESECT) continue;
|
|
21616
|
+
if (SECTOR + (i + 1) * SECTOR > this.buf.length) continue;
|
|
21617
|
+
this.fat[i] = ENDOFCHAIN;
|
|
21618
|
+
out.push(i);
|
|
21619
|
+
}
|
|
21620
|
+
while (out.length < n) {
|
|
21621
|
+
this.ensureFatCapacity((this.buf.length - SECTOR) / SECTOR + 2);
|
|
21622
|
+
const idx = (this.buf.length - SECTOR) / SECTOR;
|
|
21623
|
+
this.buf = Buffer.concat([this.buf, Buffer.alloc(SECTOR)]);
|
|
21624
|
+
this.fat[idx] = ENDOFCHAIN;
|
|
21625
|
+
out.push(idx);
|
|
21626
|
+
}
|
|
21627
|
+
return out;
|
|
21628
|
+
}
|
|
21629
|
+
/** FAT 배열이 sectorCount개 엔트리를 담도록 확장 (FAT 섹터 추가 + DIFAT 갱신) */
|
|
21630
|
+
ensureFatCapacity(sectorCount) {
|
|
21631
|
+
while (this.fat.length < sectorCount) {
|
|
21632
|
+
const idx = (this.buf.length - SECTOR) / SECTOR;
|
|
21633
|
+
this.buf = Buffer.concat([this.buf, Buffer.alloc(SECTOR)]);
|
|
21634
|
+
for (let i = 0; i < 128; i++) this.fat.push(FREESECT);
|
|
21635
|
+
this.fat[idx] = FATSECT;
|
|
21636
|
+
this.fatSectors.push(idx);
|
|
21637
|
+
const slot = this.fatSectors.length - 1;
|
|
21638
|
+
if (slot >= 109) throw new OleSurgeonError("DIFAT \uCCB4\uC778 \uD655\uC7A5\uC740 \uBBF8\uC9C0\uC6D0 (7MB \uCD08\uACFC \uCEE8\uD14C\uC774\uB108 \uC131\uC7A5)");
|
|
21639
|
+
this.buf.writeUInt32LE(idx, 76 + slot * 4);
|
|
21640
|
+
this.buf.writeUInt32LE(this.fatSectors.length, 44);
|
|
21641
|
+
}
|
|
21642
|
+
}
|
|
21643
|
+
/** miniFAT에서 빈 미니섹터 n개 확보 (mini stream 용량/miniFAT 확장 포함) */
|
|
21644
|
+
allocMiniSectors(n) {
|
|
21645
|
+
const root = this.rootEntry();
|
|
21646
|
+
const rootChain = root.start === ENDOFCHAIN || root.size === 0 ? [] : this.chain(root.start);
|
|
21647
|
+
let capacity = rootChain.length * (SECTOR / MINI_SECTOR);
|
|
21648
|
+
const out = [];
|
|
21649
|
+
for (let i = 0; i < Math.min(this.miniFat.length, capacity) && out.length < n; i++) {
|
|
21650
|
+
if (this.miniFat[i] === FREESECT) {
|
|
21651
|
+
this.miniFat[i] = ENDOFCHAIN;
|
|
21652
|
+
out.push(i);
|
|
21653
|
+
}
|
|
21654
|
+
}
|
|
21655
|
+
let nextIdx = capacity;
|
|
21656
|
+
while (out.length < n) {
|
|
21657
|
+
if (nextIdx >= this.miniFat.length) {
|
|
21658
|
+
const [s] = this.allocSectors(1);
|
|
21659
|
+
if (this.miniFatSectors.length > 0) this.fat[this.miniFatSectors[this.miniFatSectors.length - 1]] = s;
|
|
21660
|
+
else this.buf.writeUInt32LE(s, 60);
|
|
21661
|
+
this.miniFatSectors.push(s);
|
|
21662
|
+
this.buf.writeUInt32LE(this.miniFatSectors.length, 64);
|
|
21663
|
+
for (let i = 0; i < 128; i++) this.miniFat.push(FREESECT);
|
|
21664
|
+
}
|
|
21665
|
+
if (nextIdx >= capacity) {
|
|
21666
|
+
const [s] = this.allocSectors(1);
|
|
21667
|
+
if (rootChain.length > 0) this.fat[rootChain[rootChain.length - 1]] = s;
|
|
21668
|
+
else {
|
|
21669
|
+
root.start = s;
|
|
21670
|
+
}
|
|
21671
|
+
rootChain.push(s);
|
|
21672
|
+
capacity = rootChain.length * (SECTOR / MINI_SECTOR);
|
|
21673
|
+
root.size = Math.max(root.size, rootChain.length * SECTOR);
|
|
21674
|
+
this.writeDirEntry(root);
|
|
21675
|
+
}
|
|
21676
|
+
this.miniFat[nextIdx] = ENDOFCHAIN;
|
|
21677
|
+
out.push(nextIdx);
|
|
21678
|
+
nextIdx++;
|
|
21679
|
+
}
|
|
21680
|
+
return out;
|
|
21681
|
+
}
|
|
21682
|
+
// ── 기록 ──
|
|
21683
|
+
writeDirEntry(e) {
|
|
21684
|
+
const sector = this.dirSectors[Math.floor(e.index / 4)];
|
|
21685
|
+
const off = this.sectorOffset(sector) + e.index % 4 * 128;
|
|
21686
|
+
this.buf.writeUInt32LE(e.start, off + 116);
|
|
21687
|
+
this.buf.writeUInt32LE(e.size, off + 120);
|
|
21688
|
+
}
|
|
21689
|
+
flushFat() {
|
|
21690
|
+
for (let i = 0; i < this.fatSectors.length; i++) {
|
|
21691
|
+
const off = this.sectorOffset(this.fatSectors[i]);
|
|
21692
|
+
for (let j = 0; j < 128; j++) {
|
|
21693
|
+
const idx = i * 128 + j;
|
|
21694
|
+
this.buf.writeUInt32LE(idx < this.fat.length ? this.fat[idx] : FREESECT, off + j * 4);
|
|
21695
|
+
}
|
|
21696
|
+
}
|
|
21697
|
+
for (let i = 0; i < this.miniFatSectors.length; i++) {
|
|
21698
|
+
const off = this.sectorOffset(this.miniFatSectors[i]);
|
|
21699
|
+
for (let j = 0; j < 128; j++) {
|
|
21700
|
+
const idx = i * 128 + j;
|
|
21701
|
+
this.buf.writeUInt32LE(idx < this.miniFat.length ? this.miniFat[idx] : FREESECT, off + j * 4);
|
|
21702
|
+
}
|
|
21703
|
+
}
|
|
21704
|
+
}
|
|
21705
|
+
/** 미니섹터 k의 파일 내 바이트 오프셋 (root 체인 경유) */
|
|
21706
|
+
miniOffset(k, rootChain) {
|
|
21707
|
+
const within = k * MINI_SECTOR;
|
|
21708
|
+
const sec = rootChain[Math.floor(within / SECTOR)];
|
|
21709
|
+
if (sec === void 0) throw new OleSurgeonError("mini stream \uBC94\uC704 \uCD08\uACFC");
|
|
21710
|
+
return this.sectorOffset(sec) + within % SECTOR;
|
|
21711
|
+
}
|
|
21712
|
+
// ── 메인 ──
|
|
21713
|
+
replace(path, newData) {
|
|
21714
|
+
const entry = this.findEntry(path);
|
|
21715
|
+
if (entry.size > 0 && entry.start !== ENDOFCHAIN) {
|
|
21716
|
+
if (entry.size < MINI_CUTOFF) {
|
|
21717
|
+
for (const s of this.miniChain(entry.start)) this.miniFat[s] = FREESECT;
|
|
21718
|
+
} else {
|
|
21719
|
+
for (const s of this.chain(entry.start)) this.fat[s] = FREESECT;
|
|
21720
|
+
}
|
|
21721
|
+
}
|
|
21722
|
+
if (newData.length < MINI_CUTOFF) {
|
|
21723
|
+
const count = Math.ceil(newData.length / MINI_SECTOR) || 1;
|
|
21724
|
+
const sectors = this.allocMiniSectors(count);
|
|
21725
|
+
const rootChain = this.chain(this.rootEntry().start);
|
|
21726
|
+
for (let i = 0; i < sectors.length; i++) {
|
|
21727
|
+
this.miniFat[sectors[i]] = i + 1 < sectors.length ? sectors[i + 1] : ENDOFCHAIN;
|
|
21728
|
+
const off = this.miniOffset(sectors[i], rootChain);
|
|
21729
|
+
this.buf.fill(0, off, off + MINI_SECTOR);
|
|
21730
|
+
newData.copy(this.buf, off, i * MINI_SECTOR, Math.min((i + 1) * MINI_SECTOR, newData.length));
|
|
21731
|
+
}
|
|
21732
|
+
entry.start = sectors[0];
|
|
21733
|
+
} else {
|
|
21734
|
+
const count = Math.ceil(newData.length / SECTOR);
|
|
21735
|
+
const sectors = this.allocSectors(count);
|
|
21736
|
+
for (let i = 0; i < sectors.length; i++) {
|
|
21737
|
+
this.fat[sectors[i]] = i + 1 < sectors.length ? sectors[i + 1] : ENDOFCHAIN;
|
|
21738
|
+
const off = this.sectorOffset(sectors[i]);
|
|
21739
|
+
this.buf.fill(0, off, off + SECTOR);
|
|
21740
|
+
newData.copy(this.buf, off, i * SECTOR, Math.min((i + 1) * SECTOR, newData.length));
|
|
21741
|
+
}
|
|
21742
|
+
entry.start = sectors[0];
|
|
21743
|
+
}
|
|
21744
|
+
entry.size = newData.length;
|
|
21745
|
+
this.writeDirEntry(entry);
|
|
21746
|
+
}
|
|
21747
|
+
finish() {
|
|
21748
|
+
this.flushFat();
|
|
21749
|
+
return this.buf;
|
|
21750
|
+
}
|
|
21751
|
+
}, _class2);
|
|
21752
|
+
|
|
21753
|
+
// src/roundtrip/hwp5-patch.ts
|
|
21754
|
+
var require3 = _module.createRequire.call(void 0, import.meta.url);
|
|
21755
|
+
var CFB2 = require3("cfb");
|
|
21756
|
+
var TAG_PARA_LINE_SEG = 69;
|
|
21757
|
+
function cid2(s) {
|
|
21758
|
+
return (s.charCodeAt(0) << 24 | s.charCodeAt(1) << 16 | s.charCodeAt(2) << 8 | s.charCodeAt(3)) >>> 0;
|
|
21759
|
+
}
|
|
21760
|
+
var CTRL_TBL2 = cid2("tbl ");
|
|
21761
|
+
var CTRL_GSO2 = cid2("gso ");
|
|
21762
|
+
function swap322(id) {
|
|
21763
|
+
return ((id & 255) << 24 | (id >>> 8 & 255) << 16 | (id >>> 16 & 255) << 8 | id >>> 24 & 255) >>> 0;
|
|
21764
|
+
}
|
|
21765
|
+
function isCtrl(rec, id) {
|
|
21766
|
+
if (rec.tagId !== TAG_CTRL_HEADER || rec.data.length < 4) return false;
|
|
21767
|
+
const raw = rec.data.readUInt32LE(0);
|
|
21768
|
+
return raw === id || swap322(raw) === id;
|
|
21769
|
+
}
|
|
21770
|
+
function readRecordsStrict(stream) {
|
|
21771
|
+
const recs = [];
|
|
21772
|
+
let off = 0;
|
|
21773
|
+
while (off < stream.length) {
|
|
21774
|
+
if (off + 4 > stream.length) return null;
|
|
21775
|
+
const h = stream.readUInt32LE(off);
|
|
21776
|
+
off += 4;
|
|
21777
|
+
const tagId = h & 1023;
|
|
21778
|
+
const level = h >>> 10 & 1023;
|
|
21779
|
+
let size = h >>> 20 & 4095;
|
|
21780
|
+
if (size === 4095) {
|
|
21781
|
+
if (off + 4 > stream.length) return null;
|
|
21782
|
+
size = stream.readUInt32LE(off);
|
|
21783
|
+
off += 4;
|
|
21784
|
+
}
|
|
21785
|
+
if (off + size > stream.length) return null;
|
|
21786
|
+
recs.push({ tagId, level, data: stream.subarray(off, off + size) });
|
|
21787
|
+
off += size;
|
|
21788
|
+
}
|
|
21789
|
+
return recs;
|
|
21790
|
+
}
|
|
21791
|
+
function serializeRecords(recs, repl) {
|
|
21792
|
+
const parts = [];
|
|
21793
|
+
for (let i = 0; i < recs.length; i++) {
|
|
21794
|
+
const data = _nullishCoalesce(_optionalChain([repl, 'optionalAccess', _184 => _184.get, 'call', _185 => _185(i)]), () => ( recs[i].data));
|
|
21795
|
+
const ext = data.length >= 4095;
|
|
21796
|
+
const header = Buffer.alloc(ext ? 8 : 4);
|
|
21797
|
+
header.writeUInt32LE((recs[i].tagId & 1023 | (recs[i].level & 1023) << 10 | (ext ? 4095 : data.length) << 20) >>> 0, 0);
|
|
21798
|
+
if (ext) header.writeUInt32LE(data.length, 4);
|
|
21799
|
+
parts.push(header, data);
|
|
21800
|
+
}
|
|
21801
|
+
return Buffer.concat(parts);
|
|
21802
|
+
}
|
|
21803
|
+
function scanSection(stream, sectionIndex, compressed) {
|
|
21804
|
+
const records = readRecordsStrict(stream);
|
|
21805
|
+
if (!records) return { records: [], safe: false, paras: [], tables: [], compressed, repl: /* @__PURE__ */ new Map() };
|
|
21806
|
+
const safe = serializeRecords(records).equals(stream);
|
|
21807
|
+
const parent = new Int32Array(records.length).fill(-1);
|
|
21808
|
+
const stack = [];
|
|
21809
|
+
for (let i = 0; i < records.length; i++) {
|
|
21810
|
+
while (stack.length > 0 && records[stack[stack.length - 1]].level >= records[i].level) stack.pop();
|
|
21811
|
+
parent[i] = stack.length > 0 ? stack[stack.length - 1] : -1;
|
|
21812
|
+
stack.push(i);
|
|
21813
|
+
}
|
|
21814
|
+
const ancestorCtrl = (i, id) => {
|
|
21815
|
+
for (let p = parent[i]; p >= 0; p = parent[p]) if (isCtrl(records[p], id)) return true;
|
|
21816
|
+
return false;
|
|
21817
|
+
};
|
|
21818
|
+
const paras = [];
|
|
21819
|
+
const parasByHeader = /* @__PURE__ */ new Map();
|
|
21820
|
+
for (let i = 0; i < records.length; i++) {
|
|
21821
|
+
const rec = records[i];
|
|
21822
|
+
if (rec.tagId !== TAG_PARA_HEADER || rec.data.length < 18) continue;
|
|
21823
|
+
let textIdx = -1;
|
|
21824
|
+
let charShapeIdx = -1;
|
|
21825
|
+
let lineSegIdx = -1;
|
|
21826
|
+
const state = createParaTextState();
|
|
21827
|
+
for (let j = i + 1; j < records.length && records[j].level > rec.level; j++) {
|
|
21828
|
+
if (records[j].level !== rec.level + 1) continue;
|
|
21829
|
+
const t = records[j].tagId;
|
|
21830
|
+
if (t === TAG_PARA_TEXT) {
|
|
21831
|
+
textIdx = textIdx === -1 ? j : -2;
|
|
21832
|
+
appendParaText(state, records[j].data);
|
|
21833
|
+
} else if (t === TAG_CHAR_SHAPE && charShapeIdx === -1) charShapeIdx = j;
|
|
21834
|
+
else if (t === TAG_PARA_LINE_SEG && lineSegIdx === -1) lineSegIdx = j;
|
|
21835
|
+
}
|
|
21836
|
+
let ctrlSeen = false, nonGso = false;
|
|
21837
|
+
for (let a = parent[i]; a >= 0; a = parent[a]) {
|
|
21838
|
+
if (records[a].tagId === TAG_CTRL_HEADER) {
|
|
21839
|
+
ctrlSeen = true;
|
|
21840
|
+
if (!isCtrl(records[a], CTRL_GSO2)) nonGso = true;
|
|
21841
|
+
}
|
|
21842
|
+
}
|
|
21843
|
+
const kind = !ctrlSeen || !nonGso ? "body" : "other";
|
|
21844
|
+
const para = {
|
|
21845
|
+
sectionIndex,
|
|
21846
|
+
headerIdx: i,
|
|
21847
|
+
kind,
|
|
21848
|
+
textIdx,
|
|
21849
|
+
charShapeIdx,
|
|
21850
|
+
lineSegIdx,
|
|
21851
|
+
rangeTagCount: rec.data.readUInt16LE(14),
|
|
21852
|
+
ctrlMask: rec.data.readUInt32LE(4),
|
|
21853
|
+
nCharsRaw: rec.data.readUInt32LE(0),
|
|
21854
|
+
rawText: state.text
|
|
21855
|
+
};
|
|
21856
|
+
paras.push(para);
|
|
21857
|
+
parasByHeader.set(i, para);
|
|
21858
|
+
}
|
|
21859
|
+
const tables = [];
|
|
21860
|
+
for (let i = 0; i < records.length; i++) {
|
|
21861
|
+
if (!isCtrl(records[i], CTRL_TBL2) || ancestorCtrl(i, CTRL_TBL2)) continue;
|
|
21862
|
+
const ctrlLevel = records[i].level;
|
|
21863
|
+
let rows = 0, cols = 0, tableIdx = -1;
|
|
21864
|
+
for (let j2 = i + 1; j2 < records.length && records[j2].level > ctrlLevel; j2++) {
|
|
21865
|
+
if (records[j2].level === ctrlLevel + 1 && records[j2].tagId === TAG_TABLE && records[j2].data.length >= 8) {
|
|
21866
|
+
rows = records[j2].data.readUInt16LE(4);
|
|
21867
|
+
cols = records[j2].data.readUInt16LE(6);
|
|
21868
|
+
tableIdx = j2;
|
|
21869
|
+
break;
|
|
21870
|
+
}
|
|
21871
|
+
}
|
|
21872
|
+
if (tableIdx < 0 || rows === 0 || cols === 0) continue;
|
|
21873
|
+
const cells = /* @__PURE__ */ new Map();
|
|
21874
|
+
let j = tableIdx + 1;
|
|
21875
|
+
while (j < records.length && records[j].level > ctrlLevel) {
|
|
21876
|
+
if (records[j].tagId !== TAG_LIST_HEADER) {
|
|
21877
|
+
j++;
|
|
21878
|
+
continue;
|
|
21879
|
+
}
|
|
21880
|
+
const lh = records[j];
|
|
21881
|
+
const cellLevel = lh.level;
|
|
21882
|
+
const cellParas = [];
|
|
21883
|
+
let k = j + 1;
|
|
21884
|
+
while (k < records.length) {
|
|
21885
|
+
const r = records[k];
|
|
21886
|
+
if (r.level < cellLevel) break;
|
|
21887
|
+
if (r.level === cellLevel && (r.tagId === TAG_LIST_HEADER || r.tagId === TAG_TABLE)) break;
|
|
21888
|
+
if (r.level === cellLevel && r.tagId === TAG_PARA_HEADER) {
|
|
21889
|
+
const cp = parasByHeader.get(k);
|
|
21890
|
+
if (cp) {
|
|
21891
|
+
cp.kind = "cell";
|
|
21892
|
+
cellParas.push(cp);
|
|
21893
|
+
}
|
|
21894
|
+
}
|
|
21895
|
+
k++;
|
|
21896
|
+
}
|
|
21897
|
+
if (lh.data.length >= 16) {
|
|
21898
|
+
cells.set(`${lh.data.readUInt16LE(10)},${lh.data.readUInt16LE(8)}`, { paras: cellParas });
|
|
21899
|
+
}
|
|
21900
|
+
j = k;
|
|
21901
|
+
}
|
|
21902
|
+
tables.push({ sectionIndex, rows, cols, cells });
|
|
21903
|
+
}
|
|
21904
|
+
return { records, safe, paras, tables, compressed, repl: /* @__PURE__ */ new Map() };
|
|
21905
|
+
}
|
|
21906
|
+
async function patchHwp(original, editedMarkdown, options) {
|
|
21907
|
+
const skipped = [];
|
|
21908
|
+
let applied = 0;
|
|
21909
|
+
const originalBuf = Buffer.from(original.buffer, original.byteOffset, original.byteLength);
|
|
21910
|
+
let cfb;
|
|
21911
|
+
try {
|
|
21912
|
+
cfb = CFB2.parse(originalBuf);
|
|
21913
|
+
} catch (err) {
|
|
21914
|
+
return fail(`CFB \uCEE8\uD14C\uC774\uB108 \uD30C\uC2F1 \uC2E4\uD328: ${msg(err)}`);
|
|
21915
|
+
}
|
|
21916
|
+
const fhEntry = CFB2.find(cfb, "/FileHeader");
|
|
21917
|
+
if (!_optionalChain([fhEntry, 'optionalAccess', _186 => _186.content])) return fail("FileHeader \uC2A4\uD2B8\uB9BC\uC774 \uC5C6\uC2B5\uB2C8\uB2E4 \u2014 HWP 5.x \uD30C\uC77C\uC774 \uC544\uB2D9\uB2C8\uB2E4");
|
|
21918
|
+
let flags;
|
|
21919
|
+
try {
|
|
21920
|
+
flags = parseFileHeader(Buffer.from(fhEntry.content)).flags;
|
|
21921
|
+
} catch (err) {
|
|
21922
|
+
return fail(`FileHeader \uD30C\uC2F1 \uC2E4\uD328: ${msg(err)}`);
|
|
21923
|
+
}
|
|
21924
|
+
if (flags & (FLAG_ENCRYPTED | FLAG_DISTRIBUTION | FLAG_DRM)) {
|
|
21925
|
+
return fail("\uC554\uD638\uD654/\uBC30\uD3EC\uC6A9/DRM \uBB38\uC11C\uB294 \uD328\uCE58\uB97C \uC9C0\uC6D0\uD558\uC9C0 \uC54A\uC2B5\uB2C8\uB2E4");
|
|
21926
|
+
}
|
|
21927
|
+
const compressed = (flags & FLAG_COMPRESSED) !== 0;
|
|
21928
|
+
let origBlocks;
|
|
21929
|
+
try {
|
|
21930
|
+
origBlocks = parseHwp5Document(originalBuf).blocks;
|
|
21931
|
+
} catch (err) {
|
|
21932
|
+
return fail(`\uC6D0\uBCF8 HWP \uD30C\uC2F1 \uC2E4\uD328: ${msg(err)}`);
|
|
21933
|
+
}
|
|
21934
|
+
const sectionPaths = cfb.FullPaths.map((p) => p.replace(/^Root Entry/, "")).filter((p) => /^\/BodyText\/Section\d+$/.test(p)).sort((a, b) => Number(a.match(/\d+$/)[0]) - Number(b.match(/\d+$/)[0]));
|
|
21935
|
+
if (sectionPaths.length === 0) return fail("BodyText \uC139\uC158 \uC2A4\uD2B8\uB9BC\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4");
|
|
21936
|
+
const scans = [];
|
|
21937
|
+
for (let i = 0; i < sectionPaths.length; i++) {
|
|
21938
|
+
const entry = CFB2.find(cfb, sectionPaths[i]);
|
|
21939
|
+
if (!_optionalChain([entry, 'optionalAccess', _187 => _187.content])) return fail(`\uC139\uC158 \uC2A4\uD2B8\uB9BC \uC77D\uAE30 \uC2E4\uD328: ${sectionPaths[i]}`);
|
|
21940
|
+
let stream;
|
|
21941
|
+
try {
|
|
21942
|
+
stream = compressed ? decompressStream(Buffer.from(entry.content)) : Buffer.from(entry.content);
|
|
21943
|
+
} catch (err) {
|
|
21944
|
+
return fail(`\uC139\uC158 \uC555\uCD95 \uD574\uC81C \uC2E4\uD328: ${msg(err)}`);
|
|
21945
|
+
}
|
|
21946
|
+
scans.push(scanSection(stream, i, compressed));
|
|
21947
|
+
}
|
|
21948
|
+
const origUnits = buildOrigUnits(origBlocks);
|
|
21949
|
+
const editedUnits = splitMarkdownUnits(editedMarkdown);
|
|
21950
|
+
const pairs = alignUnits(origUnits.map((u) => u.raw), editedUnits.map((u) => u.raw));
|
|
21951
|
+
const paraMap = resolveParaMappings(origBlocks, scans);
|
|
21952
|
+
const scanTables = scans.flatMap((s) => s.tables);
|
|
21953
|
+
const obTableOrdinals = /* @__PURE__ */ new Map();
|
|
21954
|
+
{
|
|
21955
|
+
let ordinal = 0;
|
|
21956
|
+
for (let i = 0; i < origBlocks.length; i++) {
|
|
21957
|
+
if (origBlocks[i].type === "table" && origBlocks[i].table) obTableOrdinals.set(i, ordinal++);
|
|
21958
|
+
}
|
|
21959
|
+
}
|
|
21960
|
+
for (const [oi, ei] of pairs) {
|
|
21961
|
+
if (oi !== null && ei !== null) {
|
|
21962
|
+
const orig = origUnits[oi];
|
|
21963
|
+
const edited = editedUnits[ei];
|
|
21964
|
+
if (orig.raw === edited.raw) continue;
|
|
21965
|
+
applied += handleModified(orig, edited, {
|
|
21966
|
+
origBlocks,
|
|
21967
|
+
paraMap,
|
|
21968
|
+
scans,
|
|
21969
|
+
scanTables,
|
|
21970
|
+
obTableOrdinals,
|
|
21971
|
+
skipped
|
|
21972
|
+
});
|
|
21973
|
+
} else if (oi !== null) {
|
|
21974
|
+
skipped.push({ reason: "\uBE14\uB85D \uC0AD\uC81C\uB294 \uBBF8\uC9C0\uC6D0 (v1) \u2014 \uC6D0\uBCF8 \uC720\uC9C0", before: summarize(origUnits[oi].raw) });
|
|
21975
|
+
} else if (ei !== null) {
|
|
21976
|
+
skipped.push({ reason: "\uBE14\uB85D \uCD94\uAC00\uB294 \uBBF8\uC9C0\uC6D0 (v1)", after: summarize(editedUnits[ei].raw) });
|
|
21977
|
+
}
|
|
21978
|
+
}
|
|
21979
|
+
let data;
|
|
21980
|
+
const dirty = scans.some((s) => s.repl.size > 0);
|
|
21981
|
+
if (!dirty) {
|
|
21982
|
+
data = new Uint8Array(original);
|
|
21983
|
+
} else {
|
|
21984
|
+
try {
|
|
21985
|
+
let out = originalBuf;
|
|
21986
|
+
for (let i = 0; i < scans.length; i++) {
|
|
21987
|
+
if (scans[i].repl.size === 0) continue;
|
|
21988
|
+
const newStream = serializeRecords(scans[i].records, scans[i].repl);
|
|
21989
|
+
const content = compressed ? _zlib.deflateRawSync.call(void 0, newStream) : newStream;
|
|
21990
|
+
out = replaceOleStream(out, sectionPaths[i], content);
|
|
21991
|
+
}
|
|
21992
|
+
data = new Uint8Array(out);
|
|
21993
|
+
} catch (err) {
|
|
21994
|
+
return { success: false, applied: 0, skipped, error: `HWP \uC139\uD130 \uC218\uC220 \uC2E4\uD328: ${msg(err)}` };
|
|
21995
|
+
}
|
|
21996
|
+
}
|
|
21997
|
+
let verification;
|
|
21998
|
+
if (_optionalChain([options, 'optionalAccess', _188 => _188.verify]) !== false) {
|
|
21999
|
+
try {
|
|
22000
|
+
const reparsed = parseHwp5Document(Buffer.from(data));
|
|
22001
|
+
verification = diffUnitLists(splitMarkdownUnits(reparsed.markdown), editedUnits);
|
|
22002
|
+
} catch (err) {
|
|
22003
|
+
return { success: false, applied, skipped, error: `\uD328\uCE58\uBCF8 \uC7AC\uD30C\uC2F1 \uC2E4\uD328 \u2014 \uD328\uCE58 \uC911\uB2E8: ${msg(err)}` };
|
|
22004
|
+
}
|
|
22005
|
+
}
|
|
22006
|
+
return { success: true, data, applied, skipped, verification };
|
|
22007
|
+
function fail(error) {
|
|
22008
|
+
return { success: false, applied: 0, skipped, error };
|
|
22009
|
+
}
|
|
22010
|
+
}
|
|
22011
|
+
function msg(err) {
|
|
22012
|
+
return err instanceof Error ? err.message : String(err);
|
|
22013
|
+
}
|
|
22014
|
+
function resolveParaMappings(blocks, scans) {
|
|
22015
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
22016
|
+
for (const scan of scans) {
|
|
22017
|
+
for (const para of scan.paras) {
|
|
22018
|
+
if (para.kind === "other") continue;
|
|
22019
|
+
const key = normForMatch(para.rawText);
|
|
22020
|
+
if (!key) continue;
|
|
22021
|
+
let list = buckets.get(key);
|
|
22022
|
+
if (!list) buckets.set(key, list = []);
|
|
22023
|
+
list.push(para);
|
|
22024
|
+
}
|
|
22025
|
+
}
|
|
22026
|
+
const usable = (list) => list.length === 1 || list.every((p) => p.kind === "body");
|
|
22027
|
+
const counters = /* @__PURE__ */ new Map();
|
|
22028
|
+
const result = /* @__PURE__ */ new Map();
|
|
22029
|
+
for (let i = 0; i < blocks.length; i++) {
|
|
22030
|
+
const b = blocks[i];
|
|
22031
|
+
if (b.type !== "paragraph" && b.type !== "heading" || !b.text) continue;
|
|
22032
|
+
let key = normForMatch(b.text);
|
|
22033
|
+
let prefixStripped = false;
|
|
22034
|
+
if (!buckets.has(key)) {
|
|
22035
|
+
const sp = b.text.indexOf(" ");
|
|
22036
|
+
if (sp > 0) {
|
|
22037
|
+
const alt = normForMatch(b.text.slice(sp + 1));
|
|
22038
|
+
if (alt && buckets.has(alt)) {
|
|
22039
|
+
key = alt;
|
|
22040
|
+
prefixStripped = true;
|
|
22041
|
+
}
|
|
22042
|
+
}
|
|
22043
|
+
}
|
|
22044
|
+
const list = buckets.get(key);
|
|
22045
|
+
if (!list || !usable(list)) {
|
|
22046
|
+
result.set(i, {});
|
|
22047
|
+
continue;
|
|
22048
|
+
}
|
|
22049
|
+
const occ = _nullishCoalesce(counters.get(key), () => ( 0));
|
|
22050
|
+
counters.set(key, occ + 1);
|
|
22051
|
+
result.set(i, occ < list.length ? { para: list[occ], prefixStripped } : {});
|
|
22052
|
+
}
|
|
22053
|
+
return result;
|
|
22054
|
+
}
|
|
22055
|
+
function handleModified(orig, edited, ctx) {
|
|
22056
|
+
const block = ctx.origBlocks[orig.blockIdx];
|
|
22057
|
+
const skip = (reason) => {
|
|
22058
|
+
ctx.skipped.push({ reason, before: summarize(orig.raw), after: summarize(edited.raw) });
|
|
22059
|
+
return 0;
|
|
22060
|
+
};
|
|
22061
|
+
if (orig.role === "caption") return skip("\uD45C \uCEA1\uC158 \uC218\uC815\uC740 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22062
|
+
if (orig.kind === "separator" || orig.kind === "image") return skip("\uC774\uBBF8\uC9C0/\uAD6C\uBD84\uC120 \uBCC0\uACBD\uC740 \uBBF8\uC9C0\uC6D0");
|
|
22063
|
+
if (!block) return skip("\uBE14\uB85D \uB9E4\uD551 \uC2E4\uD328");
|
|
22064
|
+
if (orig.fragment) return skip("\uBB38\uB2E8 \uBD84\uC808(\uAC15\uC81C \uC904\uBC14\uAFC8/\uBCD1\uD569 \uC720\uB2DB) \u2014 \uBD80\uBD84 \uC218\uC815\uC740 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22065
|
+
if (block.type === "table" && block.table) {
|
|
22066
|
+
if (orig.kind !== edited.kind) return skip("\uD45C \u2194 \uBE44\uD45C \uBCC0\uACBD\uC740 \uBBF8\uC9C0\uC6D0 (\uD45C \uAD6C\uC870 \uBCC0\uACBD)");
|
|
22067
|
+
if (ctx.obTableOrdinals.size !== ctx.scanTables.length) return skip("\uD45C \uAC1C\uC218 \uBD88\uC77C\uCE58 \u2014 \uC18C\uC2A4\uB9F5 \uC2E0\uB8B0 \uBD88\uAC00");
|
|
22068
|
+
const ordinal = ctx.obTableOrdinals.get(orig.blockIdx);
|
|
22069
|
+
const scanTable = ordinal !== void 0 ? ctx.scanTables[ordinal] : void 0;
|
|
22070
|
+
if (!scanTable) return skip("\uD45C \uC18C\uC2A4\uB9F5 \uB9E4\uD551 \uC2E4\uD328");
|
|
22071
|
+
if (orig.kind === "gfm-table") return patchGfmCells(scanTable, orig, edited, ctx, skip);
|
|
22072
|
+
if (orig.kind === "html-table") return skip("HTML \uD45C(\uBCD1\uD569/\uC904\uBC14\uAFC8 \uC140) \uC218\uC815\uC740 HWP5 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22073
|
+
return patchTextChunk5(block.table, scanTable, orig, edited, ctx, skip);
|
|
22074
|
+
}
|
|
22075
|
+
if ((block.type === "paragraph" || block.type === "heading") && orig.kind === "text" && edited.kind === "text") {
|
|
22076
|
+
return patchParagraph(block, orig, edited, ctx, skip);
|
|
22077
|
+
}
|
|
22078
|
+
return skip("\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uBE14\uB85D \uC720\uD615 \uBCC0\uACBD");
|
|
22079
|
+
}
|
|
22080
|
+
function patchParagraph(block, orig, edited, ctx, skip) {
|
|
22081
|
+
const mapping = ctx.paraMap.get(orig.blockIdx);
|
|
22082
|
+
if (!_optionalChain([mapping, 'optionalAccess', _189 => _189.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)");
|
|
22083
|
+
if (block.text && block.text.includes("\n")) {
|
|
22084
|
+
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)");
|
|
22085
|
+
}
|
|
22086
|
+
let newPlain = textUnitToPlain(edited.raw, block);
|
|
22087
|
+
if (block.footnoteText) {
|
|
22088
|
+
const noteMatch = newPlain.match(/\s*\(주: ([\s\S]*)\)$/);
|
|
22089
|
+
if (noteMatch) {
|
|
22090
|
+
newPlain = newPlain.slice(0, noteMatch.index).trimEnd();
|
|
22091
|
+
if (normForMatch(noteMatch[1]) !== normForMatch(block.footnoteText)) {
|
|
22092
|
+
ctx.skipped.push({ reason: "\uAC01\uC8FC \uD14D\uC2A4\uD2B8 \uC218\uC815\uC740 \uBBF8\uC9C0\uC6D0 \u2014 \uBCF8\uBB38\uB9CC \uC801\uC6A9", before: block.footnoteText, after: noteMatch[1] });
|
|
22093
|
+
}
|
|
22094
|
+
} else {
|
|
22095
|
+
ctx.skipped.push({ reason: "\uAC01\uC8FC \uD45C\uAE30 \uC0AD\uC81C\uB294 \uBBF8\uC9C0\uC6D0 \u2014 \uAC01\uC8FC \uC720\uC9C0, \uBCF8\uBB38\uB9CC \uC801\uC6A9", before: `(\uC8FC: ${block.footnoteText})` });
|
|
22096
|
+
}
|
|
22097
|
+
}
|
|
22098
|
+
if (mapping.prefixStripped) {
|
|
22099
|
+
const origPrefix = block.text.split(" ", 1)[0];
|
|
22100
|
+
const sp = newPlain.indexOf(" ");
|
|
22101
|
+
const newFirst = sp > 0 ? newPlain.slice(0, sp) : newPlain;
|
|
22102
|
+
if (newFirst === origPrefix || /^(?:[0-90-9a-zA-Z가-힣]{1,6}[.)\]:]|[([][0-90-9a-zA-Z가-힣]{1,6}[)\]][.:]?|[ⅰ-ⅹⅠ-Ⅹ①-⑮][.)\]:]?)$/u.test(newFirst)) {
|
|
22103
|
+
newPlain = sp > 0 ? newPlain.slice(sp + 1) : "";
|
|
22104
|
+
} else {
|
|
22105
|
+
ctx.skipped.push({ reason: "\uC790\uB3D9\uBC88\uD638 \uC811\uB450 \uC2DD\uBCC4 \uC2E4\uD328 \u2014 \uBC88\uD638 \uD3EC\uD568 \uD14D\uC2A4\uD2B8\uB85C \uC801\uC6A9 (\uBDF0\uC5B4\uC5D0\uC11C \uC911\uBCF5 \uD45C\uC2DC \uAC00\uB2A5)", after: summarize(newPlain) });
|
|
22106
|
+
}
|
|
22107
|
+
}
|
|
22108
|
+
const origPlain = textUnitToPlain(orig.raw, block);
|
|
22109
|
+
if (newPlain === origPlain) return skip("\uD14D\uC2A4\uD2B8 \uC678 \uBCC0\uACBD(\uD5E4\uB529 \uB808\uBCA8/\uC11C\uC2DD)\uB9CC \uAC10\uC9C0 \u2014 \uC2A4\uD0C0\uC77C \uBCC0\uACBD\uC740 \uBBF8\uC9C0\uC6D0");
|
|
22110
|
+
if (sanitizeText(newPlain) !== newPlain) {
|
|
22111
|
+
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");
|
|
22112
|
+
}
|
|
22113
|
+
return stageParaPatch(ctx.scans[mapping.para.sectionIndex], mapping.para, newPlain, skip);
|
|
22114
|
+
}
|
|
22115
|
+
function patchGfmCells(scanTable, orig, edited, ctx, skip) {
|
|
22116
|
+
const origRows = parseGfmTable(orig.lines);
|
|
22117
|
+
const editedRows = parseGfmTable(edited.lines);
|
|
22118
|
+
if (origRows.length !== editedRows.length || origRows.some((r, i) => r.length !== editedRows[i].length)) {
|
|
22119
|
+
return skip("\uD45C \uAD6C\uC870 \uBCC0\uACBD(\uD589/\uC5F4 \uC218)\uC740 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22120
|
+
}
|
|
22121
|
+
let applied = 0;
|
|
22122
|
+
for (let r = 0; r < origRows.length; r++) {
|
|
22123
|
+
for (let c = 0; c < origRows[r].length; c++) {
|
|
22124
|
+
if (origRows[r][c] === editedRows[r][c]) continue;
|
|
22125
|
+
const cellSkip = (reason) => {
|
|
22126
|
+
ctx.skipped.push({ reason, before: summarize(origRows[r][c]), after: summarize(editedRows[r][c]) });
|
|
22127
|
+
return 0;
|
|
22128
|
+
};
|
|
22129
|
+
const before = gfmCellToPlain(origRows[r][c]);
|
|
22130
|
+
const after = gfmCellToPlain(editedRows[r][c]);
|
|
22131
|
+
if (before === null || after === null) {
|
|
22132
|
+
cellSkip("\uC11C\uC2DD/\uB9C1\uD06C/\uC774\uBBF8\uC9C0 \uD3EC\uD568 \uC140 \uC218\uC815\uC740 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22133
|
+
continue;
|
|
22134
|
+
}
|
|
22135
|
+
if (after.includes("\n")) {
|
|
22136
|
+
cellSkip("\uC140 \uB0B4 \uC904\uBC14\uAFC8 \uCD94\uAC00\uB294 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22137
|
+
continue;
|
|
22138
|
+
}
|
|
22139
|
+
const cell = scanTable.cells.get(`${r},${c}`);
|
|
22140
|
+
if (!cell) {
|
|
22141
|
+
cellSkip("\uBCD1\uD569 \uC601\uC5ED \uC140 \u2014 \uC575\uCEE4 \uC140\uC774 \uC544\uB2C8\uBBC0\uB85C \uBBF8\uC9C0\uC6D0");
|
|
22142
|
+
continue;
|
|
22143
|
+
}
|
|
22144
|
+
if (cell.paras.length !== 1) {
|
|
22145
|
+
cellSkip("\uBCF5\uC218 \uBB38\uB2E8 \uC140 \uC218\uC815\uC740 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22146
|
+
continue;
|
|
22147
|
+
}
|
|
22148
|
+
const para = cell.paras[0];
|
|
22149
|
+
if (normForMatch(para.rawText) !== normForMatch(before)) {
|
|
22150
|
+
cellSkip("\uC140 \uD14D\uC2A4\uD2B8 \uBD88\uC77C\uCE58 \u2014 \uC18C\uC2A4\uB9F5 \uC2E0\uB8B0 \uBD88\uAC00");
|
|
22151
|
+
continue;
|
|
22152
|
+
}
|
|
22153
|
+
if (sanitizeText(after) !== after) {
|
|
22154
|
+
cellSkip("\uACF5\uBC31 \uC815\uADDC\uD654 \uBD88\uC548\uC815 \uD14D\uC2A4\uD2B8 \u2014 \uBBF8\uC9C0\uC6D0");
|
|
22155
|
+
continue;
|
|
22156
|
+
}
|
|
22157
|
+
applied += stageParaPatch(ctx.scans[para.sectionIndex], para, after, cellSkip);
|
|
22158
|
+
}
|
|
22159
|
+
}
|
|
22160
|
+
return applied;
|
|
22161
|
+
}
|
|
22162
|
+
function patchTextChunk5(table, scanTable, orig, edited, ctx, skip) {
|
|
22163
|
+
if (table.rows === 1 && table.cols === 1) {
|
|
22164
|
+
const content = sanitizeText(table.cells[0][0].text);
|
|
22165
|
+
const replicaLines = content.split(/\n/).map((line) => {
|
|
22166
|
+
const t = line.trim();
|
|
22167
|
+
if (!t) return "";
|
|
22168
|
+
if (/^\d+\.\s/.test(t)) return `**${escapeGfm(t)}**`;
|
|
22169
|
+
return escapeGfm(t);
|
|
22170
|
+
}).filter(Boolean);
|
|
22171
|
+
if (replicaLines.join("\n") !== orig.lines.join("\n")) return skip("\uD45C \uC88C\uD45C \uC7AC\uD604 \uBD88\uC77C\uCE58 \u2014 \uB9E4\uD551 \uC2E0\uB8B0 \uBD88\uAC00");
|
|
22172
|
+
if (extractCellTokens(orig.raw) !== extractCellTokens(edited.raw)) return skip("\uC140 \uB0B4 \uC774\uBBF8\uC9C0 \uBCC0\uACBD\uC740 \uBBF8\uC9C0\uC6D0");
|
|
22173
|
+
const newLines = edited.lines.map((l) => {
|
|
22174
|
+
const m = l.match(/^\*\*([\s\S]*)\*\*$/);
|
|
22175
|
+
const unwrap = m && /^\d+\.\s/.test(unescapeGfm(m[1]));
|
|
22176
|
+
return stripCellTokens(unescapeGfm(unwrap ? m[1] : l)).trim();
|
|
22177
|
+
}).filter(Boolean);
|
|
22178
|
+
return applyCellEdit5(table, scanTable, 0, 0, newLines, ctx, orig.raw, edited.raw, orig.lines.length);
|
|
22179
|
+
}
|
|
22180
|
+
if (table.cols === 1 && table.rows >= 2) {
|
|
22181
|
+
const replica = [];
|
|
22182
|
+
for (let r = 0; r < table.rows; r++) {
|
|
22183
|
+
const line = escapeGfm(sanitizeText(table.cells[r][0].text)).replace(/\n/g, " ");
|
|
22184
|
+
if (line) replica.push({ line, gridR: r });
|
|
22185
|
+
}
|
|
22186
|
+
if (replica.map((x) => x.line).join("\n") !== orig.lines.join("\n")) return skip("\uD45C \uC88C\uD45C \uC7AC\uD604 \uBD88\uC77C\uCE58 \u2014 \uB9E4\uD551 \uC2E0\uB8B0 \uBD88\uAC00");
|
|
22187
|
+
if (edited.lines.length !== replica.length) return skip("\uD45C \uD589 \uCD94\uAC00/\uC0AD\uC81C\uB294 \uBBF8\uC9C0\uC6D0 (\uD45C \uAD6C\uC870 \uBCC0\uACBD)");
|
|
22188
|
+
let applied = 0;
|
|
22189
|
+
for (let i = 0; i < replica.length; i++) {
|
|
22190
|
+
if (replica[i].line === edited.lines[i]) continue;
|
|
22191
|
+
if (extractCellTokens(replica[i].line) !== extractCellTokens(edited.lines[i])) {
|
|
22192
|
+
skip("\uC140 \uB0B4 \uC774\uBBF8\uC9C0 \uBCC0\uACBD\uC740 \uBBF8\uC9C0\uC6D0");
|
|
22193
|
+
continue;
|
|
22194
|
+
}
|
|
22195
|
+
const newLines = [stripCellTokens(unescapeGfm(edited.lines[i])).trim()].filter(Boolean);
|
|
22196
|
+
applied += applyCellEdit5(table, scanTable, replica[i].gridR, 0, newLines, ctx, replica[i].line, edited.lines[i], 1);
|
|
22197
|
+
}
|
|
22198
|
+
return applied;
|
|
22199
|
+
}
|
|
22200
|
+
return skip("\uD45C \uB80C\uB354 \uACBD\uB85C \uC2DD\uBCC4 \uC2E4\uD328");
|
|
22201
|
+
}
|
|
22202
|
+
function applyCellEdit5(table, scanTable, gridR, gridC, newLines, ctx, before, after, origLineCount) {
|
|
22203
|
+
const skip = (reason) => {
|
|
22204
|
+
ctx.skipped.push({ reason, before: summarize(before), after: summarize(after) });
|
|
22205
|
+
return 0;
|
|
22206
|
+
};
|
|
22207
|
+
const cell = scanTable.cells.get(`${gridR},${gridC}`);
|
|
22208
|
+
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)");
|
|
22209
|
+
const irCell = _optionalChain([table, 'access', _190 => _190.cells, 'access', _191 => _191[gridR], 'optionalAccess', _192 => _192[gridC]]);
|
|
22210
|
+
const scanJoined = cell.paras.map((p) => p.rawText).filter((t) => normForMatch(t)).join("\n");
|
|
22211
|
+
if (irCell && normForMatch(scanJoined) !== normForMatch(stripCellTokens(irCell.text))) {
|
|
22212
|
+
if (normForMatch(irCell.text) !== "" || normForMatch(scanJoined) !== "") {
|
|
22213
|
+
const flatBlocks = (_nullishCoalesce(irCell.blocks, () => ( []))).filter((b) => b.type === "paragraph" || b.type === "heading");
|
|
22214
|
+
const flatJoined = flatBlocks.map((b) => _nullishCoalesce(b.text, () => ( ""))).join("\n");
|
|
22215
|
+
if (normForMatch(scanJoined) !== normForMatch(flatJoined)) {
|
|
22216
|
+
return skip("\uC140 \uCF58\uD150\uCE20 \uAD6C\uC870 \uBCF5\uC7A1 (\uC911\uCCA9\uD45C/\uAE00\uC0C1\uC790) \u2014 \uB9E4\uD551 \uC2E0\uB8B0 \uBD88\uAC00");
|
|
22217
|
+
}
|
|
22218
|
+
}
|
|
22219
|
+
}
|
|
22220
|
+
const nonEmpty = cell.paras.filter((p) => normForMatch(p.rawText) !== "");
|
|
22221
|
+
if (origLineCount !== void 0 && nonEmpty.length > 0 && origLineCount !== nonEmpty.length) {
|
|
22222
|
+
return skip("\uC140 \uC904 \uACBD\uACC4 \uB9E4\uD551 \uBAA8\uD638 (\uBB38\uB2E8 \uB0B4 \uC904\uBC14\uAFC8) \u2014 \uBBF8\uC9C0\uC6D0");
|
|
22223
|
+
}
|
|
22224
|
+
const unstable = newLines.find((l) => sanitizeText(l) !== l);
|
|
22225
|
+
if (unstable !== void 0) 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");
|
|
22226
|
+
if (nonEmpty.length === 0) return skip("\uBE48 \uC140 \uD14D\uC2A4\uD2B8 \uCC44\uC6B0\uAE30\uB294 HWP5 \uBBF8\uC9C0\uC6D0 (v1) \u2014 \uBB38\uB2E8 \uC0DD\uC131 \uD544\uC694");
|
|
22227
|
+
const assigned = [];
|
|
22228
|
+
for (let i = 0; i < nonEmpty.length; i++) {
|
|
22229
|
+
if (i < newLines.length) {
|
|
22230
|
+
assigned.push(i === nonEmpty.length - 1 && newLines.length > nonEmpty.length ? newLines.slice(i).join(" ") : newLines[i]);
|
|
22231
|
+
} else {
|
|
22232
|
+
assigned.push("");
|
|
22233
|
+
}
|
|
22234
|
+
}
|
|
22235
|
+
if (newLines.length > nonEmpty.length) {
|
|
22236
|
+
ctx.skipped.push({ reason: "\uC140 \uB0B4 \uC904 \uCD94\uAC00\uB294 \uBB38\uB2E8 \uC0DD\uC131 \uBBF8\uC9C0\uC6D0 \u2014 \uB9C8\uC9C0\uB9C9 \uBB38\uB2E8\uC5D0 \uBCD1\uD569 \uC801\uC6A9", after: summarize(after) });
|
|
22237
|
+
}
|
|
22238
|
+
let staged = 0;
|
|
22239
|
+
for (let i = 0; i < nonEmpty.length; i++) {
|
|
22240
|
+
if (assigned[i] === nonEmpty[i].rawText || normForMatch(assigned[i]) === normForMatch(nonEmpty[i].rawText)) continue;
|
|
22241
|
+
staged += stageParaPatch(ctx.scans[nonEmpty[i].sectionIndex], nonEmpty[i], assigned[i], skip);
|
|
22242
|
+
}
|
|
22243
|
+
return staged > 0 ? 1 : 0;
|
|
22244
|
+
}
|
|
22245
|
+
function gfmCellToPlain(md2) {
|
|
22246
|
+
let t = md2.trim();
|
|
22247
|
+
const bold = t.match(/^\*\*([\s\S]+)\*\*$/);
|
|
22248
|
+
if (bold) t = bold[1];
|
|
22249
|
+
if (/[*`]|!\[|\]\(|<(?!br\s*\/?>)/i.test(t)) return null;
|
|
22250
|
+
return unescapeGfm(unescapeGfmCell(t));
|
|
22251
|
+
}
|
|
22252
|
+
var PARA_BREAK = Buffer.from([13, 0]);
|
|
22253
|
+
function stageParaPatch(scan, para, newPlain, skip) {
|
|
22254
|
+
if (!scan.safe) return skip("\uC139\uC158 \uB808\uCF54\uB4DC \uC7AC\uC9C1\uB82C\uD654 \uBD88\uC77C\uCE58 \u2014 \uC548\uC804\uC744 \uC704\uD574 \uC774 \uC139\uC158\uC740 \uBBF8\uC9C0\uC6D0");
|
|
22255
|
+
if (para.textIdx === -1) return skip("\uBE48 \uBB38\uB2E8 \uD14D\uC2A4\uD2B8 \uCD94\uAC00\uB294 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22256
|
+
if (para.textIdx === -2) return skip("\uBCF5\uC218 PARA_TEXT \uB808\uCF54\uB4DC \uBB38\uB2E8 \u2014 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22257
|
+
if (para.ctrlMask !== 0) return skip("\uCEE8\uD2B8\uB864 \uBB38\uC790 \uD3EC\uD568 \uBB38\uB2E8(\uD0ED/\uAC1C\uCCB4/\uD544\uB4DC/\uD2B9\uC218\uACF5\uBC31) \u2014 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22258
|
+
if (para.rangeTagCount > 0) return skip("\uBC94\uC704 \uD0DC\uADF8(\uD615\uAD11\uD39C/\uAD50\uC815\uBD80\uD638) \uBB38\uB2E8 \u2014 \uBBF8\uC9C0\uC6D0 (v1)");
|
|
22259
|
+
if (para.charShapeIdx < 0 || para.lineSegIdx < 0) return skip("\uBB38\uB2E8 \uB808\uCF54\uB4DC \uAD6C\uC131 \uBE44\uC815\uD615 \u2014 \uBBF8\uC9C0\uC6D0");
|
|
22260
|
+
if (scan.repl.has(para.headerIdx)) return skip("\uB3D9\uC77C \uBB38\uB2E8 \uC911\uBCF5 \uC218\uC815 \u2014 \uCCAB \uC218\uC815\uB9CC \uC801\uC6A9");
|
|
22261
|
+
if (/[\u0000-\u001f]/.test(newPlain)) return skip("\uC0C8 \uD14D\uC2A4\uD2B8\uC5D0 \uC81C\uC5B4\uBB38\uC790 \uD3EC\uD568 \u2014 \uBBF8\uC9C0\uC6D0");
|
|
22262
|
+
const records = scan.records;
|
|
22263
|
+
const headerRec = records[para.headerIdx];
|
|
22264
|
+
const textRec = records[para.textIdx];
|
|
22265
|
+
const charShapeRec = records[para.charShapeIdx];
|
|
22266
|
+
const lineSegRec = records[para.lineSegIdx];
|
|
22267
|
+
if (charShapeRec.data.length < 8 || lineSegRec.data.length < 36) {
|
|
22268
|
+
return skip("CHAR_SHAPE/LINE_SEG \uB808\uCF54\uB4DC \uBE44\uC815\uD615 \u2014 \uBBF8\uC9C0\uC6D0");
|
|
22269
|
+
}
|
|
22270
|
+
const hadBreak = textRec.data.length >= 2 && textRec.data.readUInt16LE(textRec.data.length - 2) === 13;
|
|
22271
|
+
const expect = hadBreak ? Buffer.concat([Buffer.from(para.rawText, "utf16le"), PARA_BREAK]) : Buffer.from(para.rawText, "utf16le");
|
|
22272
|
+
if (!expect.equals(textRec.data)) return skip("PARA_TEXT \uC7AC\uAD6C\uC131 \uBD88\uC77C\uCE58 \u2014 \uC6D0\uBB38 \uBCF4\uC874 \uBD88\uAC00\uB85C \uBBF8\uC9C0\uC6D0");
|
|
22273
|
+
const lead = para.rawText.match(/^\s*/)[0];
|
|
22274
|
+
const trail = para.rawText.match(/\s*$/)[0];
|
|
22275
|
+
const newRaw = para.rawText.trim() === para.rawText ? newPlain : lead + newPlain + trail;
|
|
22276
|
+
const newText = hadBreak ? Buffer.concat([Buffer.from(newRaw, "utf16le"), PARA_BREAK]) : Buffer.from(newRaw, "utf16le");
|
|
22277
|
+
scan.repl.set(para.textIdx, newText);
|
|
22278
|
+
const newHeader = Buffer.from(headerRec.data);
|
|
22279
|
+
const nChars = newRaw.length + (hadBreak ? 1 : 0);
|
|
22280
|
+
newHeader.writeUInt32LE((para.nCharsRaw & 2147483648 | nChars) >>> 0, 0);
|
|
22281
|
+
if (charShapeRec.data.length > 8) {
|
|
22282
|
+
newHeader.writeUInt16LE(1, 12);
|
|
22283
|
+
scan.repl.set(para.charShapeIdx, Buffer.from(charShapeRec.data.subarray(0, 8)));
|
|
22284
|
+
}
|
|
22285
|
+
const csData = _nullishCoalesce(scan.repl.get(para.charShapeIdx), () => ( Buffer.from(charShapeRec.data)));
|
|
22286
|
+
if (csData.readUInt32LE(0) !== 0) {
|
|
22287
|
+
csData.writeUInt32LE(0, 0);
|
|
22288
|
+
scan.repl.set(para.charShapeIdx, csData);
|
|
22289
|
+
}
|
|
22290
|
+
if (lineSegRec.data.length > 36 || lineSegRec.data.readUInt32LE(0) !== 0) {
|
|
22291
|
+
const seg = Buffer.from(lineSegRec.data.subarray(0, 36));
|
|
22292
|
+
seg.writeUInt32LE(0, 0);
|
|
22293
|
+
newHeader.writeUInt16LE(1, 16);
|
|
22294
|
+
scan.repl.set(para.lineSegIdx, seg);
|
|
22295
|
+
}
|
|
22296
|
+
scan.repl.set(para.headerIdx, newHeader);
|
|
22297
|
+
return 1;
|
|
22298
|
+
}
|
|
22299
|
+
|
|
21468
22300
|
// src/print/renderer.ts
|
|
21469
22301
|
var _fs = require('fs');
|
|
21470
22302
|
var _markdownit = require('markdown-it'); var _markdownit2 = _interopRequireDefault(_markdownit);
|
|
@@ -21514,11 +22346,11 @@ var md = new (0, _markdownit2.default)({
|
|
|
21514
22346
|
breaks: false
|
|
21515
22347
|
});
|
|
21516
22348
|
function renderHtml(markdown, options) {
|
|
21517
|
-
const preset = _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
21518
|
-
const css = PRESETS[preset] + (_nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
22349
|
+
const preset = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _193 => _193.preset]), () => ( "default"));
|
|
22350
|
+
const css = PRESETS[preset] + (_nullishCoalesce(_optionalChain([options, 'optionalAccess', _194 => _194.extraCss]), () => ( "")));
|
|
21519
22351
|
const body = md.render(markdown);
|
|
21520
|
-
const watermark = _optionalChain([options, 'optionalAccess',
|
|
21521
|
-
const watermarkCss = _optionalChain([options, 'optionalAccess',
|
|
22352
|
+
const watermark = _optionalChain([options, 'optionalAccess', _195 => _195.watermark]) ? `<div class="watermark">${escapeHtml(options.watermark)}</div>` : "";
|
|
22353
|
+
const watermarkCss = _optionalChain([options, 'optionalAccess', _196 => _196.watermark]) ? `
|
|
21522
22354
|
.watermark {
|
|
21523
22355
|
position: fixed;
|
|
21524
22356
|
top: 50%; left: 50%;
|
|
@@ -21549,13 +22381,13 @@ async function htmlToPdf(html, options) {
|
|
|
21549
22381
|
try {
|
|
21550
22382
|
puppeteer = await Promise.resolve().then(() => _interopRequireWildcard(require("puppeteer-core")));
|
|
21551
22383
|
} catch (e34) {
|
|
21552
|
-
throw new (0,
|
|
22384
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)(
|
|
21553
22385
|
"PDF \uC0DD\uC131\uC5D0 puppeteer-core\uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. \uC124\uCE58: npm install puppeteer-core"
|
|
21554
22386
|
);
|
|
21555
22387
|
}
|
|
21556
22388
|
const executablePath = _nullishCoalesce(process.env.PUPPETEER_EXECUTABLE_PATH, () => ( findChromiumPath()));
|
|
21557
22389
|
if (!executablePath) {
|
|
21558
|
-
throw new (0,
|
|
22390
|
+
throw new (0, _chunkNBJB6TJBcjs.KordocError)(
|
|
21559
22391
|
"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."
|
|
21560
22392
|
);
|
|
21561
22393
|
}
|
|
@@ -21567,10 +22399,10 @@ async function htmlToPdf(html, options) {
|
|
|
21567
22399
|
try {
|
|
21568
22400
|
const page = await browser.newPage();
|
|
21569
22401
|
await page.setContent(html, { waitUntil: "networkidle0" });
|
|
21570
|
-
const margin = _optionalChain([options, 'optionalAccess',
|
|
22402
|
+
const margin = _optionalChain([options, 'optionalAccess', _197 => _197.margin]);
|
|
21571
22403
|
const pdf = await page.pdf({
|
|
21572
|
-
format: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
21573
|
-
landscape: _optionalChain([options, 'optionalAccess',
|
|
22404
|
+
format: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _198 => _198.pageSize]), () => ( "A4")),
|
|
22405
|
+
landscape: _optionalChain([options, 'optionalAccess', _199 => _199.orientation]) === "landscape",
|
|
21574
22406
|
printBackground: true,
|
|
21575
22407
|
margin: margin ? {
|
|
21576
22408
|
top: toCss(margin.top),
|
|
@@ -21578,9 +22410,9 @@ async function htmlToPdf(html, options) {
|
|
|
21578
22410
|
bottom: toCss(margin.bottom),
|
|
21579
22411
|
left: toCss(margin.left)
|
|
21580
22412
|
} : void 0,
|
|
21581
|
-
displayHeaderFooter: !!(_optionalChain([options, 'optionalAccess',
|
|
21582
|
-
headerTemplate: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
21583
|
-
footerTemplate: _nullishCoalesce(_optionalChain([options, 'optionalAccess',
|
|
22413
|
+
displayHeaderFooter: !!(_optionalChain([options, 'optionalAccess', _200 => _200.header]) || _optionalChain([options, 'optionalAccess', _201 => _201.footer])),
|
|
22414
|
+
headerTemplate: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _202 => _202.header]), () => ( "<div></div>")),
|
|
22415
|
+
footerTemplate: _nullishCoalesce(_optionalChain([options, 'optionalAccess', _203 => _203.footer]), () => ( '<div style="font-size:8pt;width:100%;text-align:center;color:#777;"><span class="pageNumber"></span>/<span class="totalPages"></span></div>'))
|
|
21584
22416
|
});
|
|
21585
22417
|
return Buffer.from(pdf);
|
|
21586
22418
|
} finally {
|
|
@@ -21614,24 +22446,24 @@ async function markdownToPdf(markdown, options) {
|
|
|
21614
22446
|
return htmlToPdf(html, options);
|
|
21615
22447
|
}
|
|
21616
22448
|
async function blocksToPdf(blocks, options) {
|
|
21617
|
-
const markdown =
|
|
22449
|
+
const markdown = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, blocks);
|
|
21618
22450
|
return markdownToPdf(markdown, options);
|
|
21619
22451
|
}
|
|
21620
22452
|
|
|
21621
22453
|
// src/index.ts
|
|
21622
22454
|
async function parse(input, options) {
|
|
21623
22455
|
let buffer;
|
|
21624
|
-
const opts = typeof input === "string" && !_optionalChain([options, 'optionalAccess',
|
|
22456
|
+
const opts = typeof input === "string" && !_optionalChain([options, 'optionalAccess', _204 => _204.filePath]) ? { ...options, filePath: input } : options;
|
|
21625
22457
|
if (typeof input === "string") {
|
|
21626
22458
|
try {
|
|
21627
22459
|
const buf = await _promises.readFile.call(void 0, input);
|
|
21628
|
-
buffer =
|
|
22460
|
+
buffer = _chunkNBJB6TJBcjs.toArrayBuffer.call(void 0, buf);
|
|
21629
22461
|
} catch (err) {
|
|
21630
|
-
const
|
|
21631
|
-
return { success: false, fileType: "unknown", error:
|
|
22462
|
+
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}`;
|
|
22463
|
+
return { success: false, fileType: "unknown", error: msg2, code: "PARSE_ERROR" };
|
|
21632
22464
|
}
|
|
21633
22465
|
} else if (Buffer.isBuffer(input)) {
|
|
21634
|
-
buffer =
|
|
22466
|
+
buffer = _chunkNBJB6TJBcjs.toArrayBuffer.call(void 0, input);
|
|
21635
22467
|
} else {
|
|
21636
22468
|
buffer = input;
|
|
21637
22469
|
}
|
|
@@ -21666,21 +22498,21 @@ async function parseHwp3(buffer, options) {
|
|
|
21666
22498
|
const { markdown, blocks, metadata, outline, warnings } = parseHwp3Document(buffer, options);
|
|
21667
22499
|
return { success: true, fileType: "hwp3", markdown, blocks, metadata, outline, warnings };
|
|
21668
22500
|
} catch (err) {
|
|
21669
|
-
return { success: false, fileType: "hwp3", error: err instanceof Error ? err.message : "HWP3 \uD30C\uC2F1 \uC2E4\uD328", code:
|
|
22501
|
+
return { success: false, fileType: "hwp3", error: err instanceof Error ? err.message : "HWP3 \uD30C\uC2F1 \uC2E4\uD328", code: _chunkNBJB6TJBcjs.classifyError.call(void 0, err) };
|
|
21670
22502
|
}
|
|
21671
22503
|
}
|
|
21672
22504
|
async function parseHwpx(buffer, options) {
|
|
21673
22505
|
try {
|
|
21674
22506
|
const { markdown, blocks, metadata, outline, warnings, images } = await parseHwpxDocument(buffer, options);
|
|
21675
|
-
return { success: true, fileType: "hwpx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess',
|
|
22507
|
+
return { success: true, fileType: "hwpx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _205 => _205.length]) ? images : void 0 };
|
|
21676
22508
|
} catch (err) {
|
|
21677
|
-
return { success: false, fileType: "hwpx", error: err instanceof Error ? err.message : "HWPX \uD30C\uC2F1 \uC2E4\uD328", code:
|
|
22509
|
+
return { success: false, fileType: "hwpx", error: err instanceof Error ? err.message : "HWPX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkNBJB6TJBcjs.classifyError.call(void 0, err) };
|
|
21678
22510
|
}
|
|
21679
22511
|
}
|
|
21680
22512
|
async function parseHwp(buffer, options) {
|
|
21681
22513
|
try {
|
|
21682
22514
|
const { markdown, blocks, metadata, outline, warnings, images } = parseHwp5Document(Buffer.from(buffer), options);
|
|
21683
|
-
if (isDistributionSentinel(markdown) && isComFallbackAvailable() && _optionalChain([options, 'optionalAccess',
|
|
22515
|
+
if (isDistributionSentinel(markdown) && isComFallbackAvailable() && _optionalChain([options, 'optionalAccess', _206 => _206.filePath])) {
|
|
21684
22516
|
try {
|
|
21685
22517
|
const { pages, pageCount, warnings: comWarns } = extractTextViaCom(options.filePath);
|
|
21686
22518
|
if (pages.some((p) => p && p.trim().length > 0)) {
|
|
@@ -21697,15 +22529,15 @@ async function parseHwp(buffer, options) {
|
|
|
21697
22529
|
} catch (e35) {
|
|
21698
22530
|
}
|
|
21699
22531
|
}
|
|
21700
|
-
return { success: true, fileType: "hwp", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess',
|
|
22532
|
+
return { success: true, fileType: "hwp", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _207 => _207.length]) ? images : void 0 };
|
|
21701
22533
|
} catch (err) {
|
|
21702
|
-
return { success: false, fileType: "hwp", error: err instanceof Error ? err.message : "HWP \uD30C\uC2F1 \uC2E4\uD328", code:
|
|
22534
|
+
return { success: false, fileType: "hwp", error: err instanceof Error ? err.message : "HWP \uD30C\uC2F1 \uC2E4\uD328", code: _chunkNBJB6TJBcjs.classifyError.call(void 0, err) };
|
|
21703
22535
|
}
|
|
21704
22536
|
}
|
|
21705
22537
|
async function parsePdf(buffer, options) {
|
|
21706
22538
|
let parsePdfDocument;
|
|
21707
22539
|
try {
|
|
21708
|
-
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./parser-
|
|
22540
|
+
const mod = await Promise.resolve().then(() => _interopRequireWildcard(require("./parser-5FZJVLQL.cjs")));
|
|
21709
22541
|
parsePdfDocument = mod.parsePdfDocument;
|
|
21710
22542
|
} catch (e36) {
|
|
21711
22543
|
return {
|
|
@@ -21720,7 +22552,7 @@ async function parsePdf(buffer, options) {
|
|
|
21720
22552
|
return { success: true, fileType: "pdf", markdown, blocks, metadata, outline, warnings, isImageBased, pageQuality, qualitySummary };
|
|
21721
22553
|
} catch (err) {
|
|
21722
22554
|
const isImageBased = err instanceof Error && "isImageBased" in err ? true : void 0;
|
|
21723
|
-
return { success: false, fileType: "pdf", error: err instanceof Error ? err.message : "PDF \uD30C\uC2F1 \uC2E4\uD328", code:
|
|
22555
|
+
return { success: false, fileType: "pdf", error: err instanceof Error ? err.message : "PDF \uD30C\uC2F1 \uC2E4\uD328", code: _chunkNBJB6TJBcjs.classifyError.call(void 0, err), isImageBased };
|
|
21724
22556
|
}
|
|
21725
22557
|
}
|
|
21726
22558
|
async function parseXlsx(buffer, options) {
|
|
@@ -21728,7 +22560,7 @@ async function parseXlsx(buffer, options) {
|
|
|
21728
22560
|
const { markdown, blocks, metadata, warnings } = await parseXlsxDocument(buffer, options);
|
|
21729
22561
|
return { success: true, fileType: "xlsx", markdown, blocks, metadata, warnings };
|
|
21730
22562
|
} catch (err) {
|
|
21731
|
-
return { success: false, fileType: "xlsx", error: err instanceof Error ? err.message : "XLSX \uD30C\uC2F1 \uC2E4\uD328", code:
|
|
22563
|
+
return { success: false, fileType: "xlsx", error: err instanceof Error ? err.message : "XLSX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkNBJB6TJBcjs.classifyError.call(void 0, err) };
|
|
21732
22564
|
}
|
|
21733
22565
|
}
|
|
21734
22566
|
async function parseXls(buffer, options) {
|
|
@@ -21736,15 +22568,15 @@ async function parseXls(buffer, options) {
|
|
|
21736
22568
|
const { markdown, blocks, metadata, warnings } = await parseXlsDocument(buffer, options);
|
|
21737
22569
|
return { success: true, fileType: "xls", markdown, blocks, metadata, warnings };
|
|
21738
22570
|
} catch (err) {
|
|
21739
|
-
return { success: false, fileType: "xls", error: err instanceof Error ? err.message : "XLS \uD30C\uC2F1 \uC2E4\uD328", code:
|
|
22571
|
+
return { success: false, fileType: "xls", error: err instanceof Error ? err.message : "XLS \uD30C\uC2F1 \uC2E4\uD328", code: _chunkNBJB6TJBcjs.classifyError.call(void 0, err) };
|
|
21740
22572
|
}
|
|
21741
22573
|
}
|
|
21742
22574
|
async function parseDocx(buffer, options) {
|
|
21743
22575
|
try {
|
|
21744
22576
|
const { markdown, blocks, metadata, outline, warnings, images } = await parseDocxDocument(buffer, options);
|
|
21745
|
-
return { success: true, fileType: "docx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess',
|
|
22577
|
+
return { success: true, fileType: "docx", markdown, blocks, metadata, outline, warnings, images: _optionalChain([images, 'optionalAccess', _208 => _208.length]) ? images : void 0 };
|
|
21746
22578
|
} catch (err) {
|
|
21747
|
-
return { success: false, fileType: "docx", error: err instanceof Error ? err.message : "DOCX \uD30C\uC2F1 \uC2E4\uD328", code:
|
|
22579
|
+
return { success: false, fileType: "docx", error: err instanceof Error ? err.message : "DOCX \uD30C\uC2F1 \uC2E4\uD328", code: _chunkNBJB6TJBcjs.classifyError.call(void 0, err) };
|
|
21748
22580
|
}
|
|
21749
22581
|
}
|
|
21750
22582
|
async function parseHwpml(buffer, options) {
|
|
@@ -21752,16 +22584,16 @@ async function parseHwpml(buffer, options) {
|
|
|
21752
22584
|
const { markdown, blocks, metadata, outline, warnings } = parseHwpmlDocument(buffer, options);
|
|
21753
22585
|
return { success: true, fileType: "hwpml", markdown, blocks, metadata, outline, warnings };
|
|
21754
22586
|
} catch (err) {
|
|
21755
|
-
return { success: false, fileType: "hwpml", error: err instanceof Error ? err.message : "HWPML \uD30C\uC2F1 \uC2E4\uD328", code:
|
|
22587
|
+
return { success: false, fileType: "hwpml", error: err instanceof Error ? err.message : "HWPML \uD30C\uC2F1 \uC2E4\uD328", code: _chunkNBJB6TJBcjs.classifyError.call(void 0, err) };
|
|
21756
22588
|
}
|
|
21757
22589
|
}
|
|
21758
22590
|
async function fillForm(input, values, outputFormat = "markdown") {
|
|
21759
22591
|
let buffer;
|
|
21760
22592
|
if (typeof input === "string") {
|
|
21761
22593
|
const buf = await _promises.readFile.call(void 0, input);
|
|
21762
|
-
buffer =
|
|
22594
|
+
buffer = _chunkNBJB6TJBcjs.toArrayBuffer.call(void 0, buf);
|
|
21763
22595
|
} else if (Buffer.isBuffer(input)) {
|
|
21764
|
-
buffer =
|
|
22596
|
+
buffer = _chunkNBJB6TJBcjs.toArrayBuffer.call(void 0, input);
|
|
21765
22597
|
} else {
|
|
21766
22598
|
buffer = input;
|
|
21767
22599
|
}
|
|
@@ -21787,7 +22619,7 @@ async function fillForm(input, values, outputFormat = "markdown") {
|
|
|
21787
22619
|
throw new Error(`\uC11C\uC2DD \uD30C\uC2F1 \uC2E4\uD328: ${parsed.error}`);
|
|
21788
22620
|
}
|
|
21789
22621
|
const fill = fillFormFields(parsed.blocks, values);
|
|
21790
|
-
const markdown =
|
|
22622
|
+
const markdown = _chunkNBJB6TJBcjs.blocksToMarkdown.call(void 0, fill.blocks);
|
|
21791
22623
|
if (outputFormat === "hwpx") {
|
|
21792
22624
|
const hwpxBuffer = await markdownToHwpx(markdown);
|
|
21793
22625
|
return { output: hwpxBuffer, format: "hwpx", fill };
|
|
@@ -21825,5 +22657,6 @@ async function fillForm(input, values, outputFormat = "markdown") {
|
|
|
21825
22657
|
|
|
21826
22658
|
|
|
21827
22659
|
|
|
21828
|
-
|
|
22660
|
+
|
|
22661
|
+
exports.VERSION = _chunkNBJB6TJBcjs.VERSION; exports.blocksToMarkdown = _chunkNBJB6TJBcjs.blocksToMarkdown; exports.blocksToPdf = blocksToPdf; exports.compare = compare; exports.detectFormat = detectFormat; exports.detectOle2Format = detectOle2Format; exports.detectZipFormat = detectZipFormat; exports.diffBlocks = diffBlocks; exports.extractFormFields = extractFormFields; exports.fillForm = fillForm; exports.fillFormFields = fillFormFields; exports.fillHwpx = fillHwpx; exports.isHwpxFile = isHwpxFile; exports.isLabelCell = isLabelCell; exports.isOldHwpFile = isOldHwpFile; exports.isPdfFile = isPdfFile; exports.isZipFile = isZipFile; exports.markdownToHwpx = markdownToHwpx; exports.markdownToPdf = markdownToPdf; 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.renderHtml = renderHtml;
|
|
21829
22662
|
//# sourceMappingURL=index.cjs.map
|