kordoc 3.9.0 → 3.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/README.md +27 -0
  2. package/dist/{-6CLKMLK2.js → -LPEXY73L.js} +18 -12
  3. package/dist/{chunk-VHXUD3PW.cjs → chunk-7UXZTZBJ.cjs} +2 -2
  4. package/dist/{chunk-VHXUD3PW.cjs.map → chunk-7UXZTZBJ.cjs.map} +1 -1
  5. package/dist/chunk-GFS4QWB6.js +124 -0
  6. package/dist/chunk-GFS4QWB6.js.map +1 -0
  7. package/dist/{chunk-EZ5GBTBE.js → chunk-I6CX2RK4.js} +2 -2
  8. package/dist/{chunk-EZ5GBTBE.js.map → chunk-I6CX2RK4.js.map} +1 -1
  9. package/dist/{chunk-ITPZD7XK.js → chunk-RMGYE4LT.js} +32 -313
  10. package/dist/chunk-RMGYE4LT.js.map +1 -0
  11. package/dist/chunk-UR34PYAC.js +938 -0
  12. package/dist/chunk-UR34PYAC.js.map +1 -0
  13. package/dist/{chunk-XKDA4FDM.js → chunk-YXEE3DEQ.js} +4 -120
  14. package/dist/chunk-YXEE3DEQ.js.map +1 -0
  15. package/dist/cli.js +33 -6
  16. package/dist/cli.js.map +1 -1
  17. package/dist/index.cjs +798 -174
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +40 -1
  20. package/dist/index.d.ts +40 -1
  21. package/dist/index.js +680 -56
  22. package/dist/index.js.map +1 -1
  23. package/dist/mcp.js +8 -5
  24. package/dist/mcp.js.map +1 -1
  25. package/dist/{parser-NCNME2Z6.js → parser-664URIIW.js} +2 -2
  26. package/dist/{parser-N4G5KQBE.cjs → parser-AT22HMF5.cjs} +14 -14
  27. package/dist/{parser-N4G5KQBE.cjs.map → parser-AT22HMF5.cjs.map} +1 -1
  28. package/dist/{parser-LVI45MVF.js → parser-LJOS7VZM.js} +8 -6
  29. package/dist/{parser-LVI45MVF.js.map → parser-LJOS7VZM.js.map} +1 -1
  30. package/dist/render-XWOEGE3U.js +9 -0
  31. package/dist/render-XWOEGE3U.js.map +1 -0
  32. package/dist/{watch-XSLV62BH.js → watch-CZF6NA2V.js} +6 -4
  33. package/dist/{watch-XSLV62BH.js.map → watch-CZF6NA2V.js.map} +1 -1
  34. package/package.json +2 -2
  35. package/dist/chunk-ITPZD7XK.js.map +0 -1
  36. package/dist/chunk-XKDA4FDM.js.map +0 -1
  37. /package/dist/{-6CLKMLK2.js.map → -LPEXY73L.js.map} +0 -0
  38. /package/dist/{parser-NCNME2Z6.js.map → parser-664URIIW.js.map} +0 -0
@@ -5,30 +5,46 @@ import {
5
5
  detectZipFormat,
6
6
  parseLenientCfb
7
7
  } from "./chunk-MEPHGCPQ.js";
8
+ import {
9
+ MAX_DECOMPRESS_SIZE,
10
+ MAX_XML_DEPTH,
11
+ MAX_ZIP_ENTRIES,
12
+ SPACE_EM_FIXED,
13
+ applyPageText,
14
+ charWidthEm1000,
15
+ clampSpan,
16
+ createSectionShared,
17
+ createXmlParser,
18
+ extractTextFromNode,
19
+ findChildByLocalName,
20
+ fitRatioForFewerLines
21
+ } from "./chunk-UR34PYAC.js";
8
22
  import {
9
23
  HEADING_RATIO_H1,
10
24
  HEADING_RATIO_H2,
11
25
  HEADING_RATIO_H3,
12
- KordocError,
13
26
  MAX_COLS,
14
27
  MAX_ROWS,
15
28
  blocksToMarkdown,
16
29
  buildTable,
17
- classifyError,
18
- compareSectionPaths,
19
30
  convertTableToText,
20
31
  flattenLayoutTables,
32
+ mapPuaText
33
+ } from "./chunk-YXEE3DEQ.js";
34
+ import {
35
+ parsePageRange
36
+ } from "./chunk-MOL7MDBG.js";
37
+ import {
38
+ KordocError,
39
+ classifyError,
40
+ compareSectionPaths,
21
41
  isPathTraversal,
22
- mapPuaText,
23
42
  normalizeSectionHref,
24
43
  precheckZipSize,
25
44
  sanitizeHref,
26
45
  stripDtd,
27
46
  toArrayBuffer
28
- } from "./chunk-XKDA4FDM.js";
29
- import {
30
- parsePageRange
31
- } from "./chunk-MOL7MDBG.js";
47
+ } from "./chunk-GFS4QWB6.js";
32
48
 
33
49
  // src/index.ts
34
50
  import { readFile } from "fs/promises";
@@ -143,57 +159,6 @@ function comResultToParseResult(pages, pageCount, warnings) {
143
159
  };
144
160
  }
145
161
 
146
- // src/hwpx/parser-shared.ts
147
- import { DOMParser } from "@xmldom/xmldom";
148
- var MAX_DECOMPRESS_SIZE = 100 * 1024 * 1024;
149
- var MAX_ZIP_ENTRIES = 500;
150
- function clampSpan(val, max) {
151
- return Math.max(1, Math.min(val, max));
152
- }
153
- var MAX_XML_DEPTH = 200;
154
- function createSectionShared() {
155
- return { numState: /* @__PURE__ */ new Map(), pageText: { headers: [], footers: [] }, track: { deleteDepth: 0, warned: false } };
156
- }
157
- function createXmlParser(warnings) {
158
- return new DOMParser({
159
- onError(level, msg2) {
160
- if (level === "fatalError") throw new KordocError(`XML \uD30C\uC2F1 \uC2E4\uD328: ${msg2}`);
161
- warnings?.push({ code: "MALFORMED_XML", message: `XML ${level === "warn" ? "\uACBD\uACE0" : "\uC624\uB958"}: ${msg2}` });
162
- }
163
- });
164
- }
165
- function applyPageText(blocks, shared) {
166
- const { headers, footers } = shared.pageText;
167
- if (headers.length > 0) {
168
- blocks.unshift(...headers.map((t) => ({ type: "paragraph", text: t, pageNumber: 1 })));
169
- }
170
- if (footers.length > 0) {
171
- blocks.push(...footers.map((t) => ({ type: "paragraph", text: t })));
172
- }
173
- }
174
- function findChildByLocalName(parent, name) {
175
- const children = parent.childNodes;
176
- if (!children) return null;
177
- for (let i = 0; i < children.length; i++) {
178
- const ch = children[i];
179
- if (ch.nodeType !== 1) continue;
180
- const tag = (ch.tagName || ch.localName || "").replace(/^[^:]+:/, "");
181
- if (tag === name) return ch;
182
- }
183
- return null;
184
- }
185
- function extractTextFromNode(node) {
186
- let result = "";
187
- const children = node.childNodes;
188
- if (!children) return result;
189
- for (let i = 0; i < children.length; i++) {
190
- const child = children[i];
191
- if (child.nodeType === 3) result += child.textContent || "";
192
- else if (child.nodeType === 1) result += extractTextFromNode(child);
193
- }
194
- return result.trim();
195
- }
196
-
197
162
  // src/hwpx/styles.ts
198
163
  async function extractHwpxStyles(zip, decompressed) {
199
164
  const result = {
@@ -16556,7 +16521,7 @@ function isDistributionSentinel(markdown) {
16556
16521
 
16557
16522
  // src/xlsx/parser.ts
16558
16523
  import JSZip3 from "jszip";
16559
- import { DOMParser as DOMParser2 } from "@xmldom/xmldom";
16524
+ import { DOMParser } from "@xmldom/xmldom";
16560
16525
  var MAX_SHEETS = 100;
16561
16526
  var MAX_DECOMPRESS_SIZE3 = 100 * 1024 * 1024;
16562
16527
  var MAX_ROWS2 = 1e4;
@@ -16596,7 +16561,7 @@ function getTextContent(el) {
16596
16561
  return el.textContent?.trim() ?? "";
16597
16562
  }
16598
16563
  function parseXml(text) {
16599
- return new DOMParser2().parseFromString(stripDtd(text), "text/xml");
16564
+ return new DOMParser().parseFromString(stripDtd(text), "text/xml");
16600
16565
  }
16601
16566
  function parseSharedStrings(xml) {
16602
16567
  const doc = parseXml(xml);
@@ -17456,7 +17421,7 @@ async function parseXlsDocument(buffer, options) {
17456
17421
 
17457
17422
  // src/docx/parser.ts
17458
17423
  import JSZip4 from "jszip";
17459
- import { DOMParser as DOMParser3 } from "@xmldom/xmldom";
17424
+ import { DOMParser as DOMParser2 } from "@xmldom/xmldom";
17460
17425
 
17461
17426
  // src/docx/equation.ts
17462
17427
  function lname(el) {
@@ -17885,7 +17850,7 @@ function getAttr(el, localName2) {
17885
17850
  return null;
17886
17851
  }
17887
17852
  function parseXml2(text) {
17888
- return new DOMParser3().parseFromString(stripDtd(text), "text/xml");
17853
+ return new DOMParser2().parseFromString(stripDtd(text), "text/xml");
17889
17854
  }
17890
17855
  function parseStyles(xml) {
17891
17856
  const doc = parseXml2(xml);
@@ -18322,7 +18287,7 @@ async function parseDocxDocument(buffer, options) {
18322
18287
  }
18323
18288
 
18324
18289
  // src/hwpml/parser.ts
18325
- import { DOMParser as DOMParser4 } from "@xmldom/xmldom";
18290
+ import { DOMParser as DOMParser3 } from "@xmldom/xmldom";
18326
18291
  var MAX_XML_DEPTH2 = 200;
18327
18292
  var MAX_TABLE_ROWS = 5e3;
18328
18293
  var MAX_TABLE_COLS = 500;
@@ -18335,7 +18300,7 @@ function parseHwpmlDocument(buffer, options) {
18335
18300
  const normalized = text.replace(/&nbsp;/g, "&#160;");
18336
18301
  const xml = stripDtd(normalized);
18337
18302
  const warnings = [];
18338
- const parser = new DOMParser4({
18303
+ const parser = new DOMParser3({
18339
18304
  onError: (_level, msg2) => {
18340
18305
  warnings.push({ message: `HWPML XML \uD30C\uC2F1 \uACBD\uACE0: ${msg2}`, code: "MALFORMED_XML" });
18341
18306
  }
@@ -20085,245 +20050,6 @@ async function fillHwpx(hwpxBuffer, values) {
20085
20050
  // src/hwpx/generator.ts
20086
20051
  import JSZip6 from "jszip";
20087
20052
 
20088
- // src/hwpx/text-metrics.ts
20089
- var ASCII_W = [
20090
- 300,
20091
- 320,
20092
- 320,
20093
- 610,
20094
- 610,
20095
- 830,
20096
- 724,
20097
- 320,
20098
- 320,
20099
- 320,
20100
- 550,
20101
- 550,
20102
- 320,
20103
- 550,
20104
- 320,
20105
- 550,
20106
- // 0x20-0x2F
20107
- 550,
20108
- 550,
20109
- 550,
20110
- 550,
20111
- 550,
20112
- 550,
20113
- 550,
20114
- 550,
20115
- 550,
20116
- 550,
20117
- 320,
20118
- 320,
20119
- 550,
20120
- 550,
20121
- 550,
20122
- 550,
20123
- // 0x30-0x3F
20124
- 830,
20125
- 706,
20126
- 605,
20127
- 685,
20128
- 719,
20129
- 627,
20130
- 617,
20131
- 683,
20132
- 734,
20133
- 305,
20134
- 315,
20135
- 660,
20136
- 605,
20137
- 839,
20138
- 734,
20139
- 732,
20140
- // 0x40-0x4F
20141
- 603,
20142
- 705,
20143
- 660,
20144
- 627,
20145
- 664,
20146
- 731,
20147
- 706,
20148
- 910,
20149
- 705,
20150
- 705,
20151
- 626,
20152
- 320,
20153
- 550,
20154
- 320,
20155
- 550,
20156
- 550,
20157
- // 0x50-0x5F
20158
- 320,
20159
- 569,
20160
- 597,
20161
- 552,
20162
- 597,
20163
- 536,
20164
- 356,
20165
- 562,
20166
- 635,
20167
- 287,
20168
- 288,
20169
- 582,
20170
- 287,
20171
- 907,
20172
- 635,
20173
- 588,
20174
- // 0x60-0x6F
20175
- 597,
20176
- 579,
20177
- 478,
20178
- 496,
20179
- 356,
20180
- 635,
20181
- 563,
20182
- 720,
20183
- 542,
20184
- 543,
20185
- 486,
20186
- 320,
20187
- 320,
20188
- 320,
20189
- 550,
20190
- 0
20191
- // 0x70-0x7E(+DEL)
20192
- ];
20193
- var SYM_W = {
20194
- 160: 300,
20195
- 163: 568,
20196
- 165: 707,
20197
- 167: 498,
20198
- 171: 440,
20199
- 172: 564,
20200
- 176: 291,
20201
- 177: 798,
20202
- 182: 606,
20203
- 183: 320,
20204
- 187: 440,
20205
- 215: 617,
20206
- 247: 678,
20207
- 8211: 625,
20208
- 8212: 875,
20209
- 8213: 875,
20210
- 8216: 320,
20211
- 8217: 320,
20212
- 8220: 480,
20213
- 8221: 480,
20214
- 8224: 558,
20215
- 8225: 438,
20216
- 8229: 640,
20217
- 8230: 960,
20218
- 8240: 988,
20219
- 8242: 335,
20220
- 8243: 474,
20221
- 8251: 770,
20222
- 8364: 656,
20223
- 9756: 1012,
20224
- 9758: 1012
20225
- };
20226
- function charWidthEm1000(cp) {
20227
- if (cp >= 32 && cp <= 126) return ASCII_W[cp - 32];
20228
- const sym = SYM_W[cp];
20229
- if (sym !== void 0) return sym;
20230
- if (cp >= 44032 && cp <= 55203) return 970;
20231
- if (cp >= 4352 && cp <= 4607) return 970;
20232
- if (cp >= 12593 && cp <= 12686) return 970;
20233
- if (cp >= 19968 && cp <= 40959 || cp >= 63744 && cp <= 64255) return 1e3;
20234
- if (cp >= 12296 && cp <= 12305 || cp >= 12308 && cp <= 12315) return 500;
20235
- if (cp === 12288) return 970;
20236
- if (cp >= 8592 && cp <= 8959) return 970;
20237
- if (cp >= 9312 && cp <= 9471) return 970;
20238
- if (cp >= 9632 && cp <= 9983) return 970;
20239
- if (cp >= 12800 && cp <= 13311) return 970;
20240
- if (cp >= 65281 && cp <= 65376) return 970;
20241
- return cp >= 11904 ? 970 : 550;
20242
- }
20243
- var SPACE_EM_FIXED = 500;
20244
- var SPACE_EM_FONT = 300;
20245
- function measureTextWidth(text, height, ratioPct, opts) {
20246
- const spaceEm = opts?.spaceEm ?? SPACE_EM_FIXED;
20247
- const spacing = opts?.spacingPct ?? 0;
20248
- let em = 0;
20249
- for (const ch of text) {
20250
- const cp = ch.codePointAt(0);
20251
- const w = cp === 32 ? spaceEm : charWidthEm1000(cp);
20252
- em += w * (1 + spacing / 100);
20253
- }
20254
- return em / 1e3 * height * (ratioPct / 100);
20255
- }
20256
- var FORBID_START = /* @__PURE__ */ new Set([..."!%),.:;?]}\xA2\xB0\u2032\u2033\u2103\u3009\u300B\u300D\u300F\u3011\u3015!%),.:;?]}\u20A9~\u2026\xB7\u3001\u3002\u3003"]);
20257
- var FORBID_END = /* @__PURE__ */ new Set([..."$([{\xA3\xA5\u3008\u300A\u300C\u300E\u3010\u3014$([{\u20A9"]);
20258
- function simulateWrap(text, firstWidth, contWidth, height, ratioPct, mode = "keep", opts) {
20259
- const EPS = 0.5;
20260
- const spaceEm = opts?.spaceEm ?? SPACE_EM_FIXED;
20261
- const spacing = opts?.spacingPct ?? 0;
20262
- const k = height * ratioPct / 100 / 1e3;
20263
- const cwCp = (cp) => (cp === 32 ? spaceEm : charWidthEm1000(cp)) * (1 + spacing / 100) * k;
20264
- const charW = (ch) => cwCp(ch.codePointAt(0));
20265
- const rangeW = (from, to) => {
20266
- let w = 0;
20267
- for (const ch of text.slice(from, to)) w += charW(ch);
20268
- return w;
20269
- };
20270
- const units = text.match(mode === "keep" ? / +|[^ ]+/g : / +|[^ ]/g) ?? [];
20271
- const starts = [0];
20272
- let lineW = 0;
20273
- let avail = firstWidth;
20274
- let pos = 0;
20275
- const lineStart = () => starts[starts.length - 1];
20276
- const breakBefore = (unitPos, w) => {
20277
- let bp = unitPos;
20278
- const u = text[unitPos];
20279
- if (u !== void 0 && FORBID_START.has(u) && bp - 1 > lineStart() && text[bp - 1] !== " ") bp--;
20280
- while (bp - 1 > lineStart() && FORBID_END.has(text[bp - 1])) bp--;
20281
- if (bp <= lineStart()) bp = unitPos;
20282
- starts.push(bp);
20283
- avail = contWidth;
20284
- lineW = rangeW(bp, unitPos) + w;
20285
- };
20286
- for (const u of units) {
20287
- if (u[0] === " ") {
20288
- lineW += charW(" ") * u.length;
20289
- pos += u.length;
20290
- continue;
20291
- }
20292
- const w = rangeW(pos, pos + u.length);
20293
- if (lineW + w <= avail + EPS) {
20294
- lineW += w;
20295
- pos += u.length;
20296
- continue;
20297
- }
20298
- if (lineW === 0 || w > contWidth + EPS) {
20299
- let sub = 0;
20300
- for (const ch of u) {
20301
- const c = charW(ch);
20302
- if (lineW + c > avail + EPS && lineW > 0) breakBefore(pos + sub, 0);
20303
- lineW += c;
20304
- sub += ch.length;
20305
- }
20306
- pos += u.length;
20307
- continue;
20308
- }
20309
- breakBefore(pos, w);
20310
- pos += u.length;
20311
- }
20312
- return { lines: starts.length, starts, lastLineWidth: lineW };
20313
- }
20314
- function simulateWrapKeepWord(text, firstWidth, contWidth, height, ratioPct, opts) {
20315
- return simulateWrap(text, firstWidth, contWidth, height, ratioPct, "keep", opts);
20316
- }
20317
- function fitRatioForFewerLines(text, firstWidth, contWidth, height, baseRatio, minRatio, opts) {
20318
- const base = simulateWrap(text, firstWidth, contWidth, height, baseRatio, "keep", opts);
20319
- if (base.lines < 2) return null;
20320
- for (let r = baseRatio - 1; r >= minRatio; r--) {
20321
- const sim = simulateWrap(text, firstWidth, contWidth, height, r, "keep", opts);
20322
- if (sim.lines < base.lines) return r;
20323
- }
20324
- return null;
20325
- }
20326
-
20327
20053
  // src/hwpx/gongmun.ts
20328
20054
  var OFFICIAL_MARGINS = { top: 20, bottom: 10, left: 20, right: 20 };
20329
20055
  var PRESET_DEFAULTS = {
@@ -24707,7 +24433,7 @@ async function parseHwp(buffer, options) {
24707
24433
  async function parsePdf(buffer, options) {
24708
24434
  let parsePdfDocument;
24709
24435
  try {
24710
- const mod = await import("./parser-LVI45MVF.js");
24436
+ const mod = await import("./parser-LJOS7VZM.js");
24711
24437
  parsePdfDocument = mod.parsePdfDocument;
24712
24438
  } catch {
24713
24439
  return {
@@ -24811,13 +24537,6 @@ export {
24811
24537
  buildRangeSplices,
24812
24538
  applySplices,
24813
24539
  fillHwpx,
24814
- charWidthEm1000,
24815
- SPACE_EM_FIXED,
24816
- SPACE_EM_FONT,
24817
- measureTextWidth,
24818
- simulateWrap,
24819
- simulateWrapKeepWord,
24820
- fitRatioForFewerLines,
24821
24540
  PRESET_ALIAS,
24822
24541
  normalizeGongmunPreset,
24823
24542
  markdownToHwpx,
@@ -24842,4 +24561,4 @@ export {
24842
24561
  parseHwpml,
24843
24562
  fillForm
24844
24563
  };
24845
- //# sourceMappingURL=chunk-ITPZD7XK.js.map
24564
+ //# sourceMappingURL=chunk-RMGYE4LT.js.map