kordoc 4.25.4 → 4.25.6

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 (118) hide show
  1. package/NOTICE +27 -0
  2. package/README.md +4 -4
  3. package/dist/{chunk-E6GI46SG.js → chunk-24J4EDVI.js} +2 -2
  4. package/dist/{chunk-ZG6RALGH.js → chunk-2RBIZALD.js} +8 -8
  5. package/dist/{chunk-FDGWDXAD.js → chunk-2VNL3FDS.js} +2 -2
  6. package/dist/{chunk-RZOEJ5TZ.js → chunk-3URB7DI4.js} +2 -2
  7. package/dist/{chunk-T7CUC2NM.js → chunk-3Y76RPK3.js} +6 -6
  8. package/dist/{chunk-LQ3FFPJ6.js → chunk-6L3VEOCI.js} +5 -5
  9. package/dist/{chunk-UAUB6Y5Z.js → chunk-6ZUQ6D3B.js} +6 -6
  10. package/dist/{chunk-HR2KFPXI.js → chunk-767ACEVN.js} +10 -4
  11. package/dist/{chunk-HR2KFPXI.js.map → chunk-767ACEVN.js.map} +2 -2
  12. package/dist/{chunk-M2V4WP7W.js → chunk-D2WQC6ME.js} +314 -22
  13. package/dist/chunk-D2WQC6ME.js.map +7 -0
  14. package/dist/{chunk-4XD2IEF7.js → chunk-D6MGUFRQ.js} +10 -10
  15. package/dist/{chunk-JKWHGHNW.js → chunk-DTUCE7H2.js} +2 -2
  16. package/dist/{chunk-RVUX6HWM.js → chunk-EDCNR6QZ.js} +2 -2
  17. package/dist/{chunk-V2TGRTXA.js → chunk-HMTLJJEC.js} +2 -2
  18. package/dist/{chunk-JNRXFGHU.js → chunk-I7MD3WQR.js} +2 -2
  19. package/dist/{chunk-35WXNRU4.js → chunk-IKQMEXGU.js} +4 -4
  20. package/dist/{chunk-MGVESXR2.js → chunk-ILUYLDIW.js} +4 -4
  21. package/dist/{chunk-PVZRQRIE.js → chunk-IOADEIUV.js} +3 -3
  22. package/dist/{chunk-MQCNWXMU.js → chunk-K4YTD6RG.js} +55 -7
  23. package/dist/{chunk-MQCNWXMU.js.map → chunk-K4YTD6RG.js.map} +2 -2
  24. package/dist/{chunk-A5DP2XNA.js → chunk-O4XRI7EC.js} +6 -6
  25. package/dist/{chunk-CO2A2WC5.js → chunk-QQVTLNLV.js} +2 -2
  26. package/dist/{chunk-FLHUJYGP.js → chunk-S4NQTGXD.js} +2 -2
  27. package/dist/{chunk-XS7MBWUH.js → chunk-TH7SIDYM.js} +2 -2
  28. package/dist/{chunk-KLWTVM6B.js → chunk-VDF7ZVNW.js} +2 -2
  29. package/dist/{chunk-FVDYN3E7.js → chunk-VHZYGCS4.js} +3 -3
  30. package/dist/{chunk-TWAXYEO2.js → chunk-VLOQQJ2D.js} +2 -2
  31. package/dist/{chunk-SEX4BBAX.js → chunk-XI47ZEQB.js} +2 -2
  32. package/dist/{chunk-ERNLA4BH.js → chunk-ZEJCW4XP.js} +2 -2
  33. package/dist/chunks-GPCDFBSF.js +10 -0
  34. package/dist/cli.js +52 -39
  35. package/dist/cli.js.map +2 -2
  36. package/dist/{formula-TAHOTZCD.js → formula-R6LXXMAS.js} +4 -4
  37. package/dist/{generator-UNGTBZVD.js → generator-ERKQ7LUN.js} +7 -7
  38. package/dist/{hancom-Q3SEMBRZ.js → hancom-VQUG46NV.js} +2 -2
  39. package/dist/{image-ocr-E3KNVXGP.js → image-ocr-MWQ6UDGP.js} +11 -11
  40. package/dist/index.cjs +473 -36
  41. package/dist/index.cjs.map +4 -4
  42. package/dist/index.d.cts +83 -2
  43. package/dist/index.d.ts +83 -2
  44. package/dist/index.js +27 -20
  45. package/dist/mcp.js +39 -36
  46. package/dist/mcp.js.map +2 -2
  47. package/dist/memo-7UFH4MNW.js +15 -0
  48. package/dist/{model-bundle-SNYPWRM5.js → model-bundle-3F33HOS2.js} +5 -5
  49. package/dist/{models-EMLB76WT.js → models-PD6EQIHL.js} +5 -5
  50. package/dist/{page-images-HZ2DRJGX.js → page-images-MZECTCSJ.js} +2 -2
  51. package/dist/{parse-worker-v2-XQPQK5RR.js → parse-worker-v2-ZXURNYJZ.js} +25 -22
  52. package/dist/{parse-worker-v2-XQPQK5RR.js.map → parse-worker-v2-ZXURNYJZ.js.map} +1 -1
  53. package/dist/{parser-MAPRIHZS.js → parser-WAJNO5VU.js} +108 -18
  54. package/dist/parser-WAJNO5VU.js.map +7 -0
  55. package/dist/{pdf-ocr-GB3Z5UHQ.js → pdf-ocr-GTVOOQNV.js} +9 -9
  56. package/dist/{profile-io-EVGG3THS.js → profile-io-UQSLXMWG.js} +3 -3
  57. package/dist/{rasterize-7PQL2TCQ.js → rasterize-3QDKNJC3.js} +3 -3
  58. package/dist/{redact-XWZQ7XUF.js → redact-M5UJUA23.js} +2 -2
  59. package/dist/{redact-doc-364J2TKR.js → redact-doc-IBLP55CI.js} +41 -24
  60. package/dist/{redact-doc-364J2TKR.js.map → redact-doc-IBLP55CI.js.map} +2 -2
  61. package/dist/{render-AZ5YXHUA.js → render-EPOTL6LB.js} +10 -10
  62. package/dist/{rewrite-fallback-VTXOOSUU.js → rewrite-fallback-5GPUDXDK.js} +12 -12
  63. package/dist/seal-7YV46Q77.js +14 -0
  64. package/dist/{setup-6NQLZAV2.js → setup-CTWIURYW.js} +3 -3
  65. package/dist/{to-hwpx-ULUHUGBZ.js → to-hwpx-OJNCWBXT.js} +7 -7
  66. package/dist/visual-U7X4QE2V.js +42 -0
  67. package/dist/{watch-5FI3NIL2.js → watch-NXUTGUPA.js} +24 -22
  68. package/dist/{watch-5FI3NIL2.js.map → watch-NXUTGUPA.js.map} +1 -1
  69. package/package.json +1 -1
  70. package/dist/chunk-M2V4WP7W.js.map +0 -7
  71. package/dist/chunks-WSSD23QG.js +0 -10
  72. package/dist/memo-BK5AJ3GY.js +0 -15
  73. package/dist/parser-MAPRIHZS.js.map +0 -7
  74. package/dist/seal-A3HZQLN5.js +0 -14
  75. package/dist/visual-VXECTX4R.js +0 -39
  76. /package/dist/{chunk-E6GI46SG.js.map → chunk-24J4EDVI.js.map} +0 -0
  77. /package/dist/{chunk-ZG6RALGH.js.map → chunk-2RBIZALD.js.map} +0 -0
  78. /package/dist/{chunk-FDGWDXAD.js.map → chunk-2VNL3FDS.js.map} +0 -0
  79. /package/dist/{chunk-RZOEJ5TZ.js.map → chunk-3URB7DI4.js.map} +0 -0
  80. /package/dist/{chunk-T7CUC2NM.js.map → chunk-3Y76RPK3.js.map} +0 -0
  81. /package/dist/{chunk-LQ3FFPJ6.js.map → chunk-6L3VEOCI.js.map} +0 -0
  82. /package/dist/{chunk-UAUB6Y5Z.js.map → chunk-6ZUQ6D3B.js.map} +0 -0
  83. /package/dist/{chunk-4XD2IEF7.js.map → chunk-D6MGUFRQ.js.map} +0 -0
  84. /package/dist/{chunk-JKWHGHNW.js.map → chunk-DTUCE7H2.js.map} +0 -0
  85. /package/dist/{chunk-RVUX6HWM.js.map → chunk-EDCNR6QZ.js.map} +0 -0
  86. /package/dist/{chunk-V2TGRTXA.js.map → chunk-HMTLJJEC.js.map} +0 -0
  87. /package/dist/{chunk-JNRXFGHU.js.map → chunk-I7MD3WQR.js.map} +0 -0
  88. /package/dist/{chunk-35WXNRU4.js.map → chunk-IKQMEXGU.js.map} +0 -0
  89. /package/dist/{chunk-MGVESXR2.js.map → chunk-ILUYLDIW.js.map} +0 -0
  90. /package/dist/{chunk-PVZRQRIE.js.map → chunk-IOADEIUV.js.map} +0 -0
  91. /package/dist/{chunk-A5DP2XNA.js.map → chunk-O4XRI7EC.js.map} +0 -0
  92. /package/dist/{chunk-CO2A2WC5.js.map → chunk-QQVTLNLV.js.map} +0 -0
  93. /package/dist/{chunk-FLHUJYGP.js.map → chunk-S4NQTGXD.js.map} +0 -0
  94. /package/dist/{chunk-XS7MBWUH.js.map → chunk-TH7SIDYM.js.map} +0 -0
  95. /package/dist/{chunk-KLWTVM6B.js.map → chunk-VDF7ZVNW.js.map} +0 -0
  96. /package/dist/{chunk-FVDYN3E7.js.map → chunk-VHZYGCS4.js.map} +0 -0
  97. /package/dist/{chunk-TWAXYEO2.js.map → chunk-VLOQQJ2D.js.map} +0 -0
  98. /package/dist/{chunk-SEX4BBAX.js.map → chunk-XI47ZEQB.js.map} +0 -0
  99. /package/dist/{chunk-ERNLA4BH.js.map → chunk-ZEJCW4XP.js.map} +0 -0
  100. /package/dist/{chunks-WSSD23QG.js.map → chunks-GPCDFBSF.js.map} +0 -0
  101. /package/dist/{formula-TAHOTZCD.js.map → formula-R6LXXMAS.js.map} +0 -0
  102. /package/dist/{generator-UNGTBZVD.js.map → generator-ERKQ7LUN.js.map} +0 -0
  103. /package/dist/{hancom-Q3SEMBRZ.js.map → hancom-VQUG46NV.js.map} +0 -0
  104. /package/dist/{image-ocr-E3KNVXGP.js.map → image-ocr-MWQ6UDGP.js.map} +0 -0
  105. /package/dist/{memo-BK5AJ3GY.js.map → memo-7UFH4MNW.js.map} +0 -0
  106. /package/dist/{model-bundle-SNYPWRM5.js.map → model-bundle-3F33HOS2.js.map} +0 -0
  107. /package/dist/{models-EMLB76WT.js.map → models-PD6EQIHL.js.map} +0 -0
  108. /package/dist/{page-images-HZ2DRJGX.js.map → page-images-MZECTCSJ.js.map} +0 -0
  109. /package/dist/{pdf-ocr-GB3Z5UHQ.js.map → pdf-ocr-GTVOOQNV.js.map} +0 -0
  110. /package/dist/{profile-io-EVGG3THS.js.map → profile-io-UQSLXMWG.js.map} +0 -0
  111. /package/dist/{rasterize-7PQL2TCQ.js.map → rasterize-3QDKNJC3.js.map} +0 -0
  112. /package/dist/{redact-XWZQ7XUF.js.map → redact-M5UJUA23.js.map} +0 -0
  113. /package/dist/{render-AZ5YXHUA.js.map → render-EPOTL6LB.js.map} +0 -0
  114. /package/dist/{rewrite-fallback-VTXOOSUU.js.map → rewrite-fallback-5GPUDXDK.js.map} +0 -0
  115. /package/dist/{seal-A3HZQLN5.js.map → seal-7YV46Q77.js.map} +0 -0
  116. /package/dist/{setup-6NQLZAV2.js.map → setup-CTWIURYW.js.map} +0 -0
  117. /package/dist/{to-hwpx-ULUHUGBZ.js.map → to-hwpx-OJNCWBXT.js.map} +0 -0
  118. /package/dist/{visual-VXECTX4R.js.map → visual-U7X4QE2V.js.map} +0 -0
package/dist/index.cjs CHANGED
@@ -381,7 +381,7 @@ var VERSION, KordocError, MAX_UNZIP_ENV_MB, SAFE_HREF_RE, HREF_ESCAPE, BARE_URL,
381
381
  var init_utils = __esm({
382
382
  "src/utils.ts"() {
383
383
  "use strict";
384
- VERSION = true ? "4.25.4" : "0.0.0-dev";
384
+ VERSION = true ? "4.25.6" : "0.0.0-dev";
385
385
  KordocError = class extends Error {
386
386
  constructor(message) {
387
387
  super(message);
@@ -32522,7 +32522,7 @@ var init_engine = __esm({
32522
32522
  const keep = trim ? { ...trim, bg: median(gray) } : void 0;
32523
32523
  const leaders = tuning.splitLeaders ? leaderRuns(gray, b.w, b.h, ink, LEADER_MIN_DOTS) : [];
32524
32524
  if (leaders.length) {
32525
- const join8 = joins.length;
32525
+ const join9 = joins.length;
32526
32526
  joins.push({ box: b, parts: [], trailDots: false });
32527
32527
  let x0 = 0, dots = false;
32528
32528
  for (const [a, c] of [...leaders, [b.w, b.w]]) {
@@ -32530,12 +32530,12 @@ var init_engine = __esm({
32530
32530
  const end = c > a ? Math.min(c, a + Math.round(b.h * LEADER_CONTEXT)) : a;
32531
32531
  x0 = c;
32532
32532
  if (bare.w >= DET_MIN_SIZE && inkStats(grayCrop(rgba, width, bare)).contrast >= Math.max(1, tuning.minInkContrast)) {
32533
- jobs.push({ box: { ...bare, w: end - (bare.x - b.x) }, rot: 0, group: group++, join: join8, dotsBefore: dots, trimDots: end > a });
32533
+ jobs.push({ box: { ...bare, w: end - (bare.x - b.x) }, rot: 0, group: group++, join: join9, dotsBefore: dots, trimDots: end > a });
32534
32534
  dots = false;
32535
32535
  }
32536
32536
  if (c > a) dots = true;
32537
32537
  }
32538
- joins[join8].trailDots = dots;
32538
+ joins[join9].trailDots = dots;
32539
32539
  continue;
32540
32540
  }
32541
32541
  if (keep) jobs.push({ box: b, rot: 0, group, keep });
@@ -33938,8 +33938,8 @@ var init_pipeline = __esm({
33938
33938
  ortMod.InferenceSession.create(encPath, sessionOpts),
33939
33939
  ortMod.InferenceSession.create(decPath, sessionOpts)
33940
33940
  ]);
33941
- const { readFile: readFile7 } = await import("fs/promises");
33942
- const tokenizerJson = JSON.parse(await readFile7(tokPath, "utf-8"));
33941
+ const { readFile: readFile8 } = await import("fs/promises");
33942
+ const tokenizerJson = JSON.parse(await readFile8(tokPath, "utf-8"));
33943
33943
  const tokenizer = new hfMod.Tokenizer(tokenizerJson, {});
33944
33944
  const pdfium = await pdfiumMod.PDFiumLibrary.init();
33945
33945
  return new _FormulaPipeline({
@@ -39476,8 +39476,8 @@ function joinClusterCellLines(lines, box, lex) {
39476
39476
  let out = lines[0]?.text ?? "";
39477
39477
  for (let i = 1; i < lines.length; i++) {
39478
39478
  const a = lines[i - 1], b = lines[i];
39479
- const join8 = !a.spaceAfter && cellLineWraps(box, box.x1, a.right, a.fontSize, b.firstCharW) && a.left - box.x1 <= WRAP_INDENT_MAX * a.fontSize && b.left - box.x1 <= WRAP_INDENT_MAX * b.fontSize && /<\/u>$/.test(a.text) === /^<u>/.test(b.text) && !startsNewItem(out, b.text) && wrapJoiner(out, b.text, lex, false) === "";
39480
- out += (join8 ? "" : " ") + b.text;
39479
+ const join9 = !a.spaceAfter && cellLineWraps(box, box.x1, a.right, a.fontSize, b.firstCharW) && a.left - box.x1 <= WRAP_INDENT_MAX * a.fontSize && b.left - box.x1 <= WRAP_INDENT_MAX * b.fontSize && /<\/u>$/.test(a.text) === /^<u>/.test(b.text) && !startsNewItem(out, b.text) && wrapJoiner(out, b.text, lex, false) === "";
39480
+ out += (join9 ? "" : " ") + b.text;
39481
39481
  }
39482
39482
  return out;
39483
39483
  }
@@ -40615,7 +40615,7 @@ function xyCutOrder(items, gapThreshold, depth = 0, wrapped, columnGap = 0, lex)
40615
40615
  const vMinGap = Math.max(minGap, columnGap);
40616
40616
  const vCut = findVerticalCutWithOutlierFilter(items, vMinGap);
40617
40617
  const hValid = hCut.gap >= minGap;
40618
- const vValid = (vCut.gap >= vMinGap || vCut.gap >= PROSE_GUTTER_MIN_GAP && isProseGutter(items, vCut.position)) && !splitsSpacedLabel(items, vCut.position) && !splitsLoneRowTail(items, vCut.position);
40618
+ const vValid = (vCut.gap >= vMinGap || vCut.gap >= PROSE_GUTTER_MIN_GAP && isProseGutter(items, vCut.position)) && !splitsSpacedLabel(items, vCut.position) && !splitsLoneRowTail(items, vCut.position) && !splitsEmptyFieldRows(items, vCut.position);
40619
40619
  let useHorizontal;
40620
40620
  if (hValid && vValid) useHorizontal = (vCut.gap <= hCut.gap * 1.5 || staggeredSides(items, vCut.position)) && !gapInsideLongerColumn(items, hCut.position, hCut.gap, vCut.position);
40621
40621
  else if (hValid) useHorizontal = true;
@@ -40782,6 +40782,12 @@ function splitsLoneRowTail(items, x) {
40782
40782
  const text = [...head, ...tail].map((i) => i.text).join("");
40783
40783
  return !/[가-힣]/.test(text) && /[\u3040-\u30ff\u3400-\u9fff]/.test(text) && gap <= fs * 4 && fills && headBox.x <= box.x + fs;
40784
40784
  }
40785
+ function splitsEmptyFieldRows(items, x) {
40786
+ const left = groupByY(items.filter((i) => i.x + i.w / 2 < x)), right = groupByY(items.filter((i) => i.x + i.w / 2 >= x));
40787
+ const field = (row) => /[::]$/.test([...row].sort((a, b) => a.x - b.x).map((i) => i.text).join("").trim());
40788
+ if (left.length < 2 || !left.every(field)) return false;
40789
+ return right.filter((r) => field(r) && left.some((l) => Math.abs(l[0].y - r[0].y) <= 2)).length >= 2;
40790
+ }
40785
40791
  function wrappedLineBands(items, inherited, lex) {
40786
40792
  const rows = groupByY(items);
40787
40793
  const records = tocRecordBoundaries(rows);
@@ -76597,8 +76603,8 @@ var init_extract_profile = __esm({
76597
76603
  async function wasmBytes() {
76598
76604
  const url = new URL("./hayro-pdf.wasm", kordocModuleUrl);
76599
76605
  if (typeof process !== "undefined" && process.versions?.node) {
76600
- const { readFile: readFile7 } = await import("node:fs/promises");
76601
- return readFile7(url);
76606
+ const { readFile: readFile8 } = await import("node:fs/promises");
76607
+ return readFile8(url);
76602
76608
  }
76603
76609
  const res = await fetch(url);
76604
76610
  if (!res.ok) throw new Error(`hayro-pdf.wasm \uC744 \uBC1B\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4 (${res.status})`);
@@ -78159,7 +78165,7 @@ function spaceMappedDots(fnArray, argsArray, fontObj) {
78159
78165
  const cache = /* @__PURE__ */ new Map();
78160
78166
  let ctm = [1, 0, 0, 1, 0, 0], tm = null, font = "", size = 0;
78161
78167
  const stack = [];
78162
- const mul3 = (m, t) => [
78168
+ const mul4 = (m, t) => [
78163
78169
  m[0] * t[0] + m[2] * t[1],
78164
78170
  m[1] * t[0] + m[3] * t[1],
78165
78171
  m[0] * t[2] + m[2] * t[3],
@@ -78173,7 +78179,7 @@ function spaceMappedDots(fnArray, argsArray, fontObj) {
78173
78179
  else if (fn === OPS.restore) {
78174
78180
  const s = stack.pop();
78175
78181
  if (s) ({ ctm, font, size } = s);
78176
- } else if (fn === OPS.transform) ctm = mul3(ctm, args);
78182
+ } else if (fn === OPS.transform) ctm = mul4(ctm, args);
78177
78183
  else if (fn === OPS.setFont) {
78178
78184
  font = String(args[0]);
78179
78185
  size = Number(args[1]) || 0;
@@ -78202,7 +78208,7 @@ function spaceMappedDots(fnArray, argsArray, fontObj) {
78202
78208
  cache.set(key3, dot);
78203
78209
  }
78204
78210
  if (!cache.get(key3)) continue;
78205
- const m = mul3(ctm, at);
78211
+ const m = mul4(ctm, at);
78206
78212
  const fs = size * Math.hypot(m[2], m[3]);
78207
78213
  out.push({ str: "\xB7", transform: [fs, 0, 0, fs, m[4], m[5]], width: (Number(g3.width) || 0) / 1e3 * fs, height: fs });
78208
78214
  }
@@ -84478,7 +84484,20 @@ function nameOk(x, level, two = false, titled = false) {
84478
84484
  if (g(x, "given1")) return level === 2 || two && COMMON_SURNAMES.includes(g(x, "sur"));
84479
84485
  return level > 0 || COMMON_SURNAMES.includes(g(x, "sur"));
84480
84486
  }
84481
- var alt, spaced, SIDO, SIGUNGU, REGION, EUPMYEON, DONGRI, ROAD, ADDR_END, DETAIL, BLDG, LOT, ADDR_LABEL, REF_NOUN, REF, PLACEHOLDER_NO, realNumber, ADDRESS_VARIANTS, DOUBLE_SURNAMES, COMMON_SURNAMES, RARE_SURNAMES, ALL_SURNAMES, PARTICLE_ALWAYS, PARTICLE_COND, P_ALL, P_ALWAYS, NAME_AFTER_RE, NOT_NAME_FINAL, SURNAME_HANJA, DOUBLE_SURNAME_HANJA, LATIN_NAME, CJK_NAME, FOREIGN_FOLLOW, PARTY_ROLES, TITLES, RANKS, STOP_WORDS, PARTICLE_GIVEN, SUFFIX_FINAL, ORG_FINAL, REGION_WORDS, NON_NAME_END, FOREIGN_SYLLABLE, TITLE_SET, g, nameOf, span2, nextIs, afterName, closedAfter, parenAfter, dativeAfter, CELL_HEAD_RE, phoneCellOk, universityAbbr, NB, NOT_ORG_AFTER, NO_SPACING, titleAlt, ORG_TITLES, ORG_TITLE, NEXT_OK, tailPlain, tailRole, PHONE_NEXT, SEP, CELL_SEP, NOT_PERSON_OF, NAME_LABEL, TITLES_AFTER, NAME_MASK, ROLE_RE2, TITLE_RE, TITLE_AFTER_RE, NAME_ORG_TITLE, SPEAKER_MARK, SPEAKER_TITLE, SPEAKER_TITLE_AFTER, NAME_HEADER_RE, LIST_GAP_RE, hanjaMatches, clanName, NOT_TITLE_TAIL, sepHasColon, colonAfter, NAME_VARIANTS;
84487
+ function maskModelSpan(value2, norm2, rule, maskChar) {
84488
+ let keep = 0;
84489
+ if (rule === "address") keep = REGION_PREFIX_RE.exec(norm2)?.[0].length ?? 0;
84490
+ else {
84491
+ const first = norm2.search(new RegExp("\\p{L}", "u"));
84492
+ if (first >= 0 && norm2.replace(/\s/g, "").length >= 3) {
84493
+ keep = first + (DOUBLE_SURNAMES.some((d) => norm2.startsWith(d, first)) ? 2 : 1);
84494
+ }
84495
+ }
84496
+ let out = "";
84497
+ for (let i = 0; i < value2.length; i++) out += i >= keep && /[\p{L}\p{N}]/u.test(norm2[i]) ? maskChar : value2[i];
84498
+ return out;
84499
+ }
84500
+ var alt, spaced, SIDO, SIGUNGU, REGION, EUPMYEON, DONGRI, ROAD, ADDR_END, DETAIL, BLDG, LOT, ADDR_LABEL, REF_NOUN, REF, PLACEHOLDER_NO, realNumber, ADDRESS_VARIANTS, DOUBLE_SURNAMES, COMMON_SURNAMES, RARE_SURNAMES, ALL_SURNAMES, PARTICLE_ALWAYS, PARTICLE_COND, P_ALL, P_ALWAYS, NAME_AFTER_RE, NOT_NAME_FINAL, SURNAME_HANJA, DOUBLE_SURNAME_HANJA, LATIN_NAME, CJK_NAME, FOREIGN_FOLLOW, PARTY_ROLES, TITLES, RANKS, STOP_WORDS, PARTICLE_GIVEN, SUFFIX_FINAL, ORG_FINAL, REGION_WORDS, NON_NAME_END, FOREIGN_SYLLABLE, TITLE_SET, g, nameOf, span2, nextIs, afterName, closedAfter, parenAfter, dativeAfter, CELL_HEAD_RE, phoneCellOk, universityAbbr, NB, NOT_ORG_AFTER, NO_SPACING, titleAlt, ORG_TITLES, ORG_TITLE, NEXT_OK, tailPlain, tailRole, PHONE_NEXT, SEP, CELL_SEP, NOT_PERSON_OF, NAME_LABEL, TITLES_AFTER, NAME_MASK, ROLE_RE2, TITLE_RE, TITLE_AFTER_RE, NAME_ORG_TITLE, SPEAKER_MARK, SPEAKER_TITLE, SPEAKER_TITLE_AFTER, NAME_HEADER_RE, LIST_GAP_RE, hanjaMatches, clanName, NOT_TITLE_TAIL, sepHasColon, colonAfter, NAME_VARIANTS, REGION_PREFIX_RE, modelAddressOk;
84482
84501
  var init_redact_name_address = __esm({
84483
84502
  "src/redact-name-address.ts"() {
84484
84503
  "use strict";
@@ -86230,6 +86249,8 @@ var init_redact_name_address = __esm({
86230
86249
  }
86231
86250
  }
86232
86251
  ];
86252
+ REGION_PREFIX_RE = new RegExp(`^(?:${REGION})(?=\\s)`);
86253
+ modelAddressOk = (norm2) => !PLACEHOLDER_NO.test(norm2);
86233
86254
  }
86234
86255
  });
86235
86256
 
@@ -86640,12 +86661,23 @@ function assertMaskChar(maskChar) {
86640
86661
  throw new Error(`maskChar\uB294 \uC601\uC22B\uC790\xB7\uACF5\uBC31\xB7\uC81C\uC5B4/\uACB0\uD569 \uBB38\uC790\xB7\uAD6C\uBD84 \uAE30\uD638(|\\<>&"'._-@+:/,;)\uAC00 \uC544\uB2CC \uBCF4\uC774\uB294 1\uAE00\uC790\uC5EC\uC57C \uD568: ${JSON.stringify(maskChar)}`);
86641
86662
  }
86642
86663
  }
86643
- function detect(text, rules2, maskChar, headerAt) {
86664
+ function detect(text, rules2, maskChar, headerAt, modelSpans) {
86644
86665
  const norm2 = normalizeForDetect(text);
86645
86666
  const hits = [];
86646
86667
  const occupied = [];
86647
86668
  for (const rule of RULE_PRIORITY) {
86648
86669
  if (!rules2.includes(rule)) continue;
86670
+ for (const s of modelSpans ?? []) {
86671
+ if (s.rule !== rule) continue;
86672
+ const start = Math.max(0, s.index);
86673
+ const end = Math.min(text.length, s.index + s.length);
86674
+ if (end <= start || occupied.some((o) => start < o.end && end > o.start)) continue;
86675
+ if (rule === "address" && !modelAddressOk(norm2.slice(start, end))) continue;
86676
+ const masked = maskModelSpan(text.slice(start, end), norm2.slice(start, end), s.rule, maskChar);
86677
+ if (masked === text.slice(start, end)) continue;
86678
+ occupied.push({ start, end, ctx: () => NO_CTX, rule });
86679
+ hits.push({ rule, masked, index: start, length: end - start });
86680
+ }
86649
86681
  for (const v of RULES3[rule]) {
86650
86682
  const re = v.re;
86651
86683
  re.lastIndex = 0;
@@ -86711,7 +86743,7 @@ function redactText(text, options) {
86711
86743
  assertMaskChar(maskChar);
86712
86744
  const rules2 = options?.rules ?? DEFAULT_REDACT_RULES;
86713
86745
  if (text === "" || rules2.length === 0) return { text, hits: [] };
86714
- const hits = detect(text, rules2, maskChar);
86746
+ const hits = detect(text, rules2, maskChar, void 0, options?.modelSpans);
86715
86747
  return { text: applyHits(text, hits), hits };
86716
86748
  }
86717
86749
  function pipePositions(line) {
@@ -86798,9 +86830,9 @@ function mdMarkerRanges(line) {
86798
86830
  }
86799
86831
  return out.sort((a, b) => a[0] - b[0]);
86800
86832
  }
86801
- function detectMarkdownLine(line, rules2, maskChar, headerAt) {
86833
+ function detectMarkdownLine(line, rules2, maskChar, headerAt, modelSpans) {
86802
86834
  const markers = mdMarkerRanges(line);
86803
- if (markers.length === 0) return detect(line, rules2, maskChar, headerAt);
86835
+ if (markers.length === 0) return detect(line, rules2, maskChar, headerAt, modelSpans);
86804
86836
  let clean = "";
86805
86837
  const map = [];
86806
86838
  let cursor = 0;
@@ -86815,7 +86847,22 @@ function detectMarkdownLine(line, rules2, maskChar, headerAt) {
86815
86847
  cursor = me;
86816
86848
  }
86817
86849
  keep(line.length);
86818
- const hits = detect(clean, rules2, maskChar, headerAt ? (i) => headerAt(map[i] ?? i) : void 0);
86850
+ let cleanSpans;
86851
+ if (modelSpans?.length) {
86852
+ cleanSpans = [];
86853
+ for (const s of modelSpans) {
86854
+ let a = -1;
86855
+ let b = -1;
86856
+ for (let k = 0; k < map.length; k++) {
86857
+ if (map[k] < s.index) continue;
86858
+ if (map[k] >= s.index + s.length) break;
86859
+ if (a < 0) a = k;
86860
+ b = k + 1;
86861
+ }
86862
+ if (a >= 0) cleanSpans.push({ ...s, index: a, length: b - a });
86863
+ }
86864
+ }
86865
+ const hits = detect(clean, rules2, maskChar, headerAt ? (i) => headerAt(map[i] ?? i) : void 0, cleanSpans);
86819
86866
  return hits.map((h) => {
86820
86867
  const start = map[h.index];
86821
86868
  const end = map[h.index + h.length - 1] + 1;
@@ -86833,24 +86880,31 @@ function redactMarkdown(markdown, options) {
86833
86880
  const lines = markdown.split("\n");
86834
86881
  const headers = tableHeaderContext(lines);
86835
86882
  const hits = [];
86883
+ const spans = options?.modelSpans;
86836
86884
  let offset = 0;
86837
86885
  const outLines = lines.map((line, i) => {
86838
86886
  if (line.includes("data:image/") || line === "" || rules2.length === 0) {
86839
86887
  offset += line.length + 1;
86840
86888
  return line;
86841
86889
  }
86842
- const lineHits = detectMarkdownLine(line, rules2, maskChar, headers.get(i));
86890
+ const lineEnd = offset + line.length;
86891
+ const lineSpans = spans?.filter((s) => s.index < lineEnd && s.index + s.length > offset).map((s) => {
86892
+ const a = Math.max(s.index, offset);
86893
+ return { ...s, index: a - offset, length: Math.min(s.index + s.length, lineEnd) - a };
86894
+ });
86895
+ const lineHits = detectMarkdownLine(line, rules2, maskChar, headers.get(i), lineSpans);
86843
86896
  for (const h of lineHits) hits.push({ ...h, index: h.index + offset });
86844
86897
  offset += line.length + 1;
86845
86898
  return applyHits(line, lineHits);
86846
86899
  });
86847
86900
  return { text: outLines.join("\n"), hits };
86848
86901
  }
86849
- var DEFAULT_REDACT_RULES, ALL_REDACT_RULES, DASHES, SPACES, LIST_SEP_RE, isGfmRow, isGfmSep, MD_ALWAYS_MARKER_RE, MD_OPEN_RE, MD_CLOSE_RE;
86902
+ var DEFAULT_REDACT_RULES, ALL_REDACT_RULES, DASHES, SPACES, NO_CTX, LIST_SEP_RE, isGfmRow, isGfmSep, MD_ALWAYS_MARKER_RE, MD_OPEN_RE, MD_CLOSE_RE;
86850
86903
  var init_redact = __esm({
86851
86904
  "src/redact.ts"() {
86852
86905
  "use strict";
86853
86906
  init_redact_rules();
86907
+ init_redact_name_address();
86854
86908
  DEFAULT_REDACT_RULES = [
86855
86909
  "rrn",
86856
86910
  "phone",
@@ -86864,6 +86918,7 @@ var init_redact = __esm({
86864
86918
  ALL_REDACT_RULES = [...DEFAULT_REDACT_RULES, "crn", "ip", "name", "address"];
86865
86919
  DASHES = /* @__PURE__ */ new Set([8208, 8209, 8210, 8211, 8212, 8213, 8722, 65112, 65123, 65293, 9472, 9473, 12641, 12540]);
86866
86920
  SPACES = /* @__PURE__ */ new Set([160, 8194, 8195, 8196, 8197, 8198, 8199, 8200, 8201, 8202, 8239, 12288]);
86921
+ NO_CTX = /* @__PURE__ */ new Set();
86867
86922
  LIST_SEP_RE = /^\s{0,2}(?:[,;/·、]|및|또는)?\s{0,2}$/;
86868
86923
  isGfmRow = (l) => /^\s*\|.*\|\s*$/.test(l);
86869
86924
  isGfmSep = (l) => /^\s*\|(?:\s*:?-{3,}:?\s*\|)+\s*$/.test(l);
@@ -86879,6 +86934,285 @@ var init_redact = __esm({
86879
86934
  }
86880
86935
  });
86881
86936
 
86937
+ // src/redact-model.ts
86938
+ function getPiiModelsDir() {
86939
+ return getModelsDir("schift-pii");
86940
+ }
86941
+ async function loadPiiModel(options) {
86942
+ const variant = options?.variant ?? "int8";
86943
+ const v = VARIANTS[variant];
86944
+ if (!v) throw new Error(`\uC54C \uC218 \uC5C6\uB294 PII \uBAA8\uB378: ${variant} (int8 \xB7 q4)`);
86945
+ const dir = getPiiModelsDir();
86946
+ await ensureModelsIn(dir, [PII_TOKENIZER, v.spec], options?.onProgress);
86947
+ let ort;
86948
+ try {
86949
+ disableOrtTelemetry();
86950
+ ort = await import("onnxruntime-node");
86951
+ } catch (e) {
86952
+ throw new Error(
86953
+ `\uC778\uBA85\xB7\uC8FC\uC18C \uBAA8\uB378\uC744 \uC4F0\uB824\uBA74 optional dependency 'onnxruntime-node' \uAC00 \uD544\uC694\uD569\uB2C8\uB2E4. \`npm install onnxruntime-node\` \uD6C4 \uB2E4\uC2DC \uC2E4\uD589\uD558\uC138\uC694. \uC6D0\uC778: ${e.message}`
86954
+ );
86955
+ }
86956
+ const session = await ort.InferenceSession.create((0, import_path9.join)(dir, v.spec.filename), {
86957
+ graphOptimizationLevel: "all",
86958
+ executionProviders: ["cpu"],
86959
+ logSeverityLevel: 3,
86960
+ ...options?.threads ? { intraOpNumThreads: options.threads } : {}
86961
+ });
86962
+ const tokenizer = JSON.parse(await (0, import_promises8.readFile)((0, import_path9.join)(dir, PII_TOKENIZER.filename), "utf-8"));
86963
+ return createPiiModel({ ort, session, tokenizer, threshold: v.threshold, variant });
86964
+ }
86965
+ function createPiiModel(o) {
86966
+ const labels = o.labels ?? PII_MODEL_LABELS;
86967
+ if (labels[0] !== "O") throw new Error("labels \uCCAB \uD56D\uBAA9\uC740 O \uC5EC\uC57C \uD568");
86968
+ const tok = createWordPiece(o.tokenizer);
86969
+ const width = (o.maxTokens ?? 512) - 2;
86970
+ const overlap2 = o.overlapTokens ?? 64;
86971
+ if (width <= overlap2) throw new Error("maxTokens - 2 \uAC00 overlapTokens \uBCF4\uB2E4 \uCEE4\uC57C \uD568");
86972
+ const L = labels.length;
86973
+ async function window(ids, offsets) {
86974
+ const all = [tok.bos, ...ids, tok.eos];
86975
+ const n = all.length;
86976
+ const out = await o.session.run({
86977
+ input_ids: new o.ort.Tensor("int64", BigInt64Array.from(all, BigInt), [1, n]),
86978
+ attention_mask: new o.ort.Tensor("int64", new BigInt64Array(n).fill(1n), [1, n])
86979
+ });
86980
+ const logits = (out.logits ?? Object.values(out)[0]).data;
86981
+ if (logits.length !== n * L) throw new Error(`logits \uD06C\uAE30 ${logits.length} \u2260 ${n}\uD1A0\uD070 \xD7 ${L}\uB77C\uBCA8`);
86982
+ const tags = [];
86983
+ const conf = [];
86984
+ for (let k = 1; k < n - 1; k++) {
86985
+ let max = -Infinity;
86986
+ let arg = 0;
86987
+ for (let j = 0; j < L; j++) {
86988
+ const x = logits[k * L + j];
86989
+ if (x > max) {
86990
+ max = x;
86991
+ arg = j;
86992
+ }
86993
+ }
86994
+ let z = 0;
86995
+ for (let j = 0; j < L; j++) z += Math.exp(logits[k * L + j] - max);
86996
+ tags.push(arg);
86997
+ conf.push(1 / z);
86998
+ }
86999
+ return decodeBioes(tags, conf, offsets, labels).filter((s) => s[3] >= o.threshold);
87000
+ }
87001
+ return {
87002
+ variant: o.variant ?? "custom",
87003
+ async detect(text) {
87004
+ if (!text) return [];
87005
+ const { ids, offsets } = tok.encode(text);
87006
+ if (ids.length === 0) return [];
87007
+ const found = [];
87008
+ for (let i = 0; ; i += width - overlap2) {
87009
+ const end = Math.min(i + width, ids.length);
87010
+ found.push(...await window(ids.slice(i, end), offsets.slice(i, end)));
87011
+ if (end >= ids.length) break;
87012
+ }
87013
+ const u162 = utf16Index(text);
87014
+ found.sort((a, b) => a[0] - b[0] || b[1] - a[1]);
87015
+ const spans = [];
87016
+ let lastEnd = -1;
87017
+ for (const [s, e, group, score] of found) {
87018
+ const rule = GROUP_RULE[group];
87019
+ if (!rule || s < lastEnd) continue;
87020
+ spans.push({ rule, index: u162[s], length: u162[e] - u162[s], score });
87021
+ lastEnd = e;
87022
+ }
87023
+ return spans;
87024
+ },
87025
+ async release() {
87026
+ await o.session.release?.();
87027
+ }
87028
+ };
87029
+ }
87030
+ function decodeBioes(tags, conf, offsets, labels) {
87031
+ const spans = [];
87032
+ let open = null;
87033
+ tags.forEach((t, k) => {
87034
+ const [s, e] = offsets[k];
87035
+ if (t === 0 || e <= s) {
87036
+ open = null;
87037
+ return;
87038
+ }
87039
+ const dash = labels[t].indexOf("-");
87040
+ const pos = labels[t].slice(0, dash);
87041
+ const group = labels[t].slice(dash + 1);
87042
+ const p = conf[k];
87043
+ if (pos === "S") spans.push([s, e, group, p]);
87044
+ if (pos === "E" && open && open[1] === group) spans.push([open[0], e, group, Math.min(open[2], p)]);
87045
+ if (pos === "B") open = [s, group, p];
87046
+ else if (pos === "I" && open && open[1] === group) open = [open[0], group, Math.min(open[2], p)];
87047
+ else open = null;
87048
+ });
87049
+ return spans;
87050
+ }
87051
+ function utf16Index(text) {
87052
+ const idx = [0];
87053
+ let u = 0;
87054
+ for (const ch3 of text) {
87055
+ u += ch3.length;
87056
+ idx.push(u);
87057
+ }
87058
+ return idx;
87059
+ }
87060
+ function normalizeNfc(chars2, base) {
87061
+ const out = [];
87062
+ let i = 0;
87063
+ while (i < chars2.length) {
87064
+ let j = i + 1;
87065
+ while (j < chars2.length && continuesCluster(chars2[j])) j++;
87066
+ const norm2 = Array.from(chars2.slice(i, j).join("").normalize("NFC"));
87067
+ if (norm2.length === j - i) norm2.forEach((ch3, k) => out.push({ ch: ch3, from: base + i + k, to: base + i + k + 1 }));
87068
+ else norm2.forEach((ch3) => out.push({ ch: ch3, from: base + i, to: base + j }));
87069
+ i = j;
87070
+ }
87071
+ return out;
87072
+ }
87073
+ function createWordPiece(tj) {
87074
+ if (tj.model?.type !== "WordPiece") throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uD1A0\uD06C\uB098\uC774\uC800 \uBAA8\uB378: ${tj.model?.type}`);
87075
+ const normType = tj.normalizer?.type ?? null;
87076
+ if (normType !== null && normType !== "NFC") throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 \uC815\uADDC\uD654: ${normType}`);
87077
+ const vocab = new Map(Object.entries(tj.model.vocab));
87078
+ const unk = vocab.get(tj.model.unk_token);
87079
+ if (unk === void 0) throw new Error("unk_token \uC774 vocab \uC5D0 \uC5C6\uC74C");
87080
+ const prefix = tj.model.continuing_subword_prefix ?? "##";
87081
+ const maxChars = tj.model.max_input_chars_per_word ?? 100;
87082
+ const special = (tj.added_tokens ?? []).filter((a) => a.special).map((a) => ({ id: a.id, content: Array.from(a.content) })).sort((a, b) => b.content.length - a.content.length);
87083
+ const tmpl = tj.post_processor?.special_tokens ?? {};
87084
+ const bos = tmpl["<s>"]?.ids?.[0];
87085
+ const eos = tmpl["</s>"]?.ids?.[0];
87086
+ if (bos === void 0 || eos === void 0) throw new Error("tokenizer post_processor \uC5D0 <s>\xB7</s> \uAC00 \uC5C6\uC74C");
87087
+ function wordpiece(word, out) {
87088
+ const from = word[0].from;
87089
+ const to = word[word.length - 1].to;
87090
+ if (word.length > maxChars) {
87091
+ out.ids.push(unk);
87092
+ out.offsets.push([from, to]);
87093
+ return;
87094
+ }
87095
+ const chars2 = word.map((w) => w.ch);
87096
+ const pieces = [];
87097
+ let start = 0;
87098
+ while (start < chars2.length) {
87099
+ let end = chars2.length;
87100
+ let id;
87101
+ while (start < end) {
87102
+ id = vocab.get((start > 0 ? prefix : "") + chars2.slice(start, end).join(""));
87103
+ if (id !== void 0) break;
87104
+ end--;
87105
+ }
87106
+ if (id === void 0) {
87107
+ out.ids.push(unk);
87108
+ out.offsets.push([from, to]);
87109
+ return;
87110
+ }
87111
+ pieces.push([id, word[start].from, word[end - 1].to]);
87112
+ start = end;
87113
+ }
87114
+ for (const [id, s, e] of pieces) {
87115
+ out.ids.push(id);
87116
+ out.offsets.push([s, e]);
87117
+ }
87118
+ }
87119
+ function pretokenize(chars2, out) {
87120
+ let word = [];
87121
+ const flush = () => {
87122
+ if (word.length) wordpiece(word, out);
87123
+ word = [];
87124
+ };
87125
+ for (const c of chars2) {
87126
+ if (WHITESPACE.has(c.ch.codePointAt(0))) flush();
87127
+ else if (isPunct(c.ch)) {
87128
+ flush();
87129
+ wordpiece([c], out);
87130
+ } else word.push(c);
87131
+ }
87132
+ flush();
87133
+ }
87134
+ function encode2(text) {
87135
+ const chars2 = Array.from(text);
87136
+ const out = { ids: [], offsets: [] };
87137
+ let seg = 0;
87138
+ let i = 0;
87139
+ while (i < chars2.length) {
87140
+ const hit = special.find((s) => s.content.length <= chars2.length - i && s.content.every((ch3, k) => chars2[i + k] === ch3));
87141
+ if (hit) {
87142
+ pretokenize(normalizeNfc(chars2.slice(seg, i), seg), out);
87143
+ out.ids.push(hit.id);
87144
+ out.offsets.push([i, i + hit.content.length]);
87145
+ i += hit.content.length;
87146
+ seg = i;
87147
+ } else i++;
87148
+ }
87149
+ pretokenize(normalizeNfc(chars2.slice(seg), seg), out);
87150
+ return out;
87151
+ }
87152
+ return { encode: encode2, bos, eos };
87153
+ }
87154
+ var import_path9, import_promises8, REVISION, BASE, offline, PII_TOKENIZER, PII_MODEL_INT8, PII_MODEL_Q4, VARIANTS, PII_MODEL_LABELS, GROUP_RULE, WHITESPACE, ASCII_PUNCT, isPunct, continuesCluster;
87155
+ var init_redact_model = __esm({
87156
+ "src/redact-model.ts"() {
87157
+ "use strict";
87158
+ import_path9 = require("path");
87159
+ import_promises8 = require("fs/promises");
87160
+ init_models();
87161
+ init_runtime_env();
87162
+ REVISION = "d0fd48e688f383d5bca27f4b15e2f3b61a0b010e";
87163
+ BASE = `https://huggingface.co/schift-io/schift-ko-pii-ax-v1/resolve/${REVISION}/`;
87164
+ offline = (f) => `\uC628\uB77C\uC778 PC\uC5D0\uC11C ${BASE}\u2026 \uC758 \uD30C\uC77C\uC744 \uBC1B\uC544 \uC774 PC \uBAA8\uB378 \uCE90\uC2DC\uC758 schift-pii/${f} \uB85C \uBC18\uC785\uD558\uC138\uC694(SHA-256 \uC744 \uAC80\uC99D\uD55C\uB2E4)`;
87165
+ PII_TOKENIZER = {
87166
+ name: "schift-ko-pii-ax-v1 tokenizer",
87167
+ filename: "tokenizer.json",
87168
+ url: `${BASE}tokenizer.json`,
87169
+ sha256: "ef9bebca9c6529bdefa19909059e07dfdfd7c2f8afeefbf4d230a784a3847d64",
87170
+ sizeMb: 1.1,
87171
+ offlineHint: offline("tokenizer.json")
87172
+ };
87173
+ PII_MODEL_INT8 = {
87174
+ name: "schift-ko-pii-ax-v1 int8",
87175
+ filename: "pii_int8.onnx",
87176
+ url: `${BASE}onnx/pii_int8.onnx`,
87177
+ sha256: "9070138ab3d3d1ebb0d1c5211ff4a10f5db35c7c09ae17261001e1aa0084b81c",
87178
+ sizeMb: 151,
87179
+ offlineHint: offline("pii_int8.onnx")
87180
+ };
87181
+ PII_MODEL_Q4 = {
87182
+ name: "schift-ko-pii-ax-v1 q4",
87183
+ filename: "pii_q4b128.onnx",
87184
+ url: `${BASE}onnx/pii_q4b128.onnx`,
87185
+ sha256: "f58a873a6eb23bea6ab03f1cdd7b8b59cacf8fc688c9c1741d822e1661ed0be9",
87186
+ sizeMb: 81,
87187
+ offlineHint: offline("pii_q4b128.onnx")
87188
+ };
87189
+ VARIANTS = {
87190
+ int8: { spec: PII_MODEL_INT8, threshold: 0.625 },
87191
+ q4: { spec: PII_MODEL_Q4, threshold: 0.725 }
87192
+ };
87193
+ PII_MODEL_LABELS = [
87194
+ "O",
87195
+ "B-private_person",
87196
+ "I-private_person",
87197
+ "E-private_person",
87198
+ "S-private_person",
87199
+ "B-private_address",
87200
+ "I-private_address",
87201
+ "E-private_address",
87202
+ "S-private_address"
87203
+ ];
87204
+ GROUP_RULE = { private_person: "name", private_address: "address" };
87205
+ WHITESPACE = /* @__PURE__ */ new Set([9, 10, 11, 12, 13, 32, 133, 160, 5760, 8232, 8233, 8239, 8287, 12288]);
87206
+ for (let c = 8192; c <= 8202; c++) WHITESPACE.add(c);
87207
+ ASCII_PUNCT = new Set("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~");
87208
+ isPunct = (ch3) => ASCII_PUNCT.has(ch3) || new RegExp("\\p{P}", "u").test(ch3);
87209
+ continuesCluster = (ch3) => {
87210
+ const c = ch3.codePointAt(0);
87211
+ return new RegExp("\\p{M}", "u").test(ch3) || c >= 4448 && c <= 4607 || c >= 55216 && c <= 55295;
87212
+ };
87213
+ }
87214
+ });
87215
+
86882
87216
  // src/chunks.ts
86883
87217
  function listDepthOf(block) {
86884
87218
  if (block.listDepth !== void 0) return block.listDepth;
@@ -88225,7 +88559,7 @@ var init_pdf = __esm({
88225
88559
  async function loadBuffer(input) {
88226
88560
  if (typeof input === "string") {
88227
88561
  try {
88228
- return toArrayBuffer(await (0, import_promises8.readFile)(input));
88562
+ return toArrayBuffer(await (0, import_promises9.readFile)(input));
88229
88563
  } catch (err) {
88230
88564
  const code = err instanceof Error && "code" in err ? err.code : void 0;
88231
88565
  throw new KordocError(code === "ENOENT" ? `\uD30C\uC77C\uC744 \uCC3E\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4: ${input}` : `\uD30C\uC77C \uC77D\uAE30 \uC2E4\uD328: ${input}`);
@@ -88290,11 +88624,11 @@ async function renderDocument(input, options) {
88290
88624
  }
88291
88625
  return { scene, assets };
88292
88626
  }
88293
- var import_promises8;
88627
+ var import_promises9;
88294
88628
  var init_document = __esm({
88295
88629
  "src/render/document.ts"() {
88296
88630
  "use strict";
88297
- import_promises8 = require("node:fs/promises");
88631
+ import_promises9 = require("node:fs/promises");
88298
88632
  init_detect();
88299
88633
  init_utils();
88300
88634
  init_page_range();
@@ -88377,7 +88711,7 @@ function wantsCrop(kind, policy) {
88377
88711
  }
88378
88712
  async function extractTables(input, options = {}) {
88379
88713
  const policy = options.policy ?? "non-tabular-and-uncertain";
88380
- const buffer = typeof input === "string" ? toArrayBuffer(await (0, import_promises9.readFile)(input)) : Buffer.isBuffer(input) ? toArrayBuffer(input) : input;
88714
+ const buffer = typeof input === "string" ? toArrayBuffer(await (0, import_promises10.readFile)(input)) : Buffer.isBuffer(input) ? toArrayBuffer(input) : input;
88381
88715
  const parsed = await parse(buffer, { classifyTables: true, layoutTables: "keep" });
88382
88716
  if (!parsed.success) throw new KordocError(`\uD30C\uC2F1 \uC2E4\uD328: ${parsed.error}`);
88383
88717
  const blocks = collectTableBlocks(parsed.blocks);
@@ -88433,11 +88767,11 @@ async function extractTables(input, options = {}) {
88433
88767
  }
88434
88768
  return out;
88435
88769
  }
88436
- var import_promises9;
88770
+ var import_promises10;
88437
88771
  var init_visual = __esm({
88438
88772
  "src/table/visual.ts"() {
88439
88773
  "use strict";
88440
- import_promises9 = require("node:fs/promises");
88774
+ import_promises10 = require("node:fs/promises");
88441
88775
  init_index();
88442
88776
  init_document();
88443
88777
  init_regions();
@@ -90061,6 +90395,16 @@ function outlineOnly(pairs, cell2) {
90061
90395
  const filled = pairs.filter(([, d]) => hasContent(d.cell));
90062
90396
  return filled.length === 1 && outlineContinues(cell2(filled[0][0]), cell2(filled[0][1]));
90063
90397
  }
90398
+ function joinNestedParts(u, d) {
90399
+ const prev = u.blocks?.[u.blocks.length - 1], curr = d.blocks?.[0];
90400
+ if (!prev?.table || !curr?.table || !prev.pageNumber || curr.pageNumber !== prev.pageNumber + 1) return null;
90401
+ const px = TABLE_COLXS.get(prev.table), cx = TABLE_COLXS.get(curr.table);
90402
+ if (!px || !cx || !shiftedSame(px, cx, false) || curr.table.cells[0].filter((c) => c.text.trim()).length < 2 || repeatedHeaderRows(prev.table, curr.table) <= 0) return null;
90403
+ const table2 = joinClipParts(prev, curr);
90404
+ if (!table2 || table2.rows >= prev.table.rows + curr.table.rows) return null;
90405
+ markJoinedPages(table2, prev, curr);
90406
+ return { ...prev, table: table2 };
90407
+ }
90064
90408
  function mergeSplitRow(table2, owner, first, colXs, textOnly2 = false, cut = NO_CUT) {
90065
90409
  const last = first - 1;
90066
90410
  const pairs = [];
@@ -90104,8 +90448,9 @@ function mergeSplitRow(table2, owner, first, colXs, textOnly2 = false, cut = NO_
90104
90448
  if (cut.ruled && hasNumberedRowSequence(table2, owner, first)) return false;
90105
90449
  if (cut.ruled && matchesIndependentRowPair(table2, owner, first)) return false;
90106
90450
  const contentPairs = pairs.filter(([u, d]) => hasContent(u.cell) && hasContent(d.cell));
90451
+ const nested = !textOnly2 && pairs.length === 1 ? joinNestedParts(cell2(pairs[0][0]), cell2(pairs[0][1])) : null;
90107
90452
  const carriedSplit = !textOnly2 && carried && !newCell && (contentPairs.length <= 1 || contentPairs.every(([, d]) => d.rs > 1) || !cut.ruled && contentPairs.some(([u, d]) => wordOverflows(cell2(u), cell2(d), colXs[u.c], colXs[u.c + u.cs])));
90108
- if (!carriedSplit && !band) {
90453
+ if (!nested && !carriedSplit && !band) {
90109
90454
  const norm2 = (c) => flowText(c.text).replace(/\s+/g, "");
90110
90455
  const openCut = cut.open && !newCell;
90111
90456
  if (!openCut && pairs.some(([u, d]) => hasContent(d.cell) && norm2(cell2(d)) !== norm2(cell2(u)) && lineEnded(cell2(u), colXs[u.c], colXs[u.c + u.cs], cell2(d)))) return false;
@@ -90123,6 +90468,10 @@ function mergeSplitRow(table2, owner, first, colXs, textOnly2 = false, cut = NO_
90123
90468
  appendCell(table2.cells[u.r][u.c], table2.cells[d.r][d.c]);
90124
90469
  if (d.rs > 1) table2.cells[u.r][u.c].rowSpan = u.rs + d.rs;
90125
90470
  }
90471
+ if (nested) {
90472
+ const blocks = cell2(pairs[0][0]).blocks;
90473
+ blocks.splice(blocks.indexOf(cell2(pairs[0][1]).blocks[0]) - 1, 2, nested);
90474
+ }
90126
90475
  for (let r = 0; r < first; r++) for (let c = 0; c < table2.cols; c++) {
90127
90476
  const o = owner[r][c];
90128
90477
  if (o && o.r === r && o.c === c && r + table2.cells[r][c].rowSpan > first) table2.cells[r][c].rowSpan--;
@@ -90680,6 +91029,87 @@ var init_selection_context = __esm({
90680
91029
  }
90681
91030
  });
90682
91031
 
91032
+ // src/pdf/vector-bullets.ts
91033
+ function filledDots(fnArray, argsArray) {
91034
+ const dots = [];
91035
+ let ctm = [1, 0, 0, 1, 0, 0];
91036
+ const stack = [];
91037
+ let path = null;
91038
+ for (let i = 0; i < fnArray.length; i++) {
91039
+ const op = fnArray[i], args = argsArray[i];
91040
+ if (op === OPS.save) stack.push(ctm);
91041
+ else if (op === OPS.restore) ctm = stack.pop() ?? [1, 0, 0, 1, 0, 0];
91042
+ else if (op === OPS.paintFormXObjectBegin) {
91043
+ stack.push(ctm);
91044
+ const m = args?.[0];
91045
+ if (Array.isArray(m) && m.length >= 6) ctm = mul2(ctm, m);
91046
+ } else if (op === OPS.paintFormXObjectEnd) ctm = stack.pop() ?? [1, 0, 0, 1, 0, 0];
91047
+ else if (op === OPS.transform && Array.isArray(args) && args.length >= 6) ctm = mul2(ctm, args);
91048
+ else if (op === OPS.constructPath) {
91049
+ const [subOps, coords] = args;
91050
+ path = null;
91051
+ if (!Array.isArray(subOps) || subOps.length < 6 || subOps[0] !== OPS.moveTo || subOps[subOps.length - 1] !== OPS.closePath || subOps.slice(1, -1).some((s) => s !== OPS.curveTo)) continue;
91052
+ let x1 = Infinity, y1 = Infinity, x2 = -Infinity, y2 = -Infinity;
91053
+ for (let k = 0; k + 1 < coords.length; k += 2) {
91054
+ const x = ctm[0] * coords[k] + ctm[2] * coords[k + 1] + ctm[4], y = ctm[1] * coords[k] + ctm[3] * coords[k + 1] + ctm[5];
91055
+ x1 = Math.min(x1, x);
91056
+ x2 = Math.max(x2, x);
91057
+ y1 = Math.min(y1, y);
91058
+ y2 = Math.max(y2, y);
91059
+ }
91060
+ path = { x1, y1, x2, y2 };
91061
+ } else if (op === OPS.fill || op === OPS.eoFill) {
91062
+ if (path) {
91063
+ const w = path.x2 - path.x1, h = path.y2 - path.y1;
91064
+ if (w >= 1.2 && w <= 6 && h >= 1.2 && h <= 6 && Math.abs(w - h) <= Math.max(w, h) * 0.15) dots.push(path);
91065
+ }
91066
+ path = null;
91067
+ }
91068
+ }
91069
+ return dots;
91070
+ }
91071
+ function restoreVectorBullets(items, fnArray, argsArray) {
91072
+ const found = [];
91073
+ for (const dot of filledDots(fnArray, argsArray)) {
91074
+ const cy = (dot.y1 + dot.y2) / 2;
91075
+ const line = items.filter((it) => !it.isHidden && it.fontSize > 0 && it.text.trim() && it.x >= dot.x2 && it.x - dot.x2 <= it.fontSize * 1.2 && cy >= it.y - it.fontSize * 0.1 && cy <= it.y + it.fontSize * 0.7 && dot.y2 - dot.y1 <= it.fontSize * 0.6).sort((a, b) => a.x - b.x)[0];
91076
+ if (!line || !new RegExp("^\\p{L}", "u").test(line.text.trim())) continue;
91077
+ if (items.some((it) => it !== line && !it.isHidden && it.text.trim() && Math.abs(it.y - line.y) <= line.fontSize * 0.3 && it.x < dot.x2 && it.x + it.w > dot.x1 - line.fontSize * 2)) continue;
91078
+ found.push({ dot, line, lx: line.x });
91079
+ }
91080
+ let restored = 0;
91081
+ const used = /* @__PURE__ */ new Set();
91082
+ for (const f of found) {
91083
+ const w = f.dot.x2 - f.dot.x1;
91084
+ const repeated = found.some((o) => o !== f && o.line !== f.line && Math.abs(o.dot.x1 - f.dot.x1) <= 1 && Math.abs(o.dot.x2 - o.dot.x1 - w) <= 0.5 && Math.abs(o.lx - f.lx) <= 1);
91085
+ if (!repeated || used.has(f.line)) continue;
91086
+ used.add(f.line);
91087
+ const line = f.line;
91088
+ line.w += line.x - f.dot.x1;
91089
+ line.x = f.dot.x1;
91090
+ line.text = "\u2022 " + line.text;
91091
+ line.fx = void 0;
91092
+ line.fw = void 0;
91093
+ restored++;
91094
+ }
91095
+ return restored;
91096
+ }
91097
+ var mul2;
91098
+ var init_vector_bullets = __esm({
91099
+ "src/pdf/vector-bullets.ts"() {
91100
+ "use strict";
91101
+ init_ops();
91102
+ mul2 = (m, t) => [
91103
+ m[0] * t[0] + m[2] * t[1],
91104
+ m[1] * t[0] + m[3] * t[1],
91105
+ m[0] * t[2] + m[2] * t[3],
91106
+ m[1] * t[2] + m[3] * t[3],
91107
+ m[0] * t[4] + m[2] * t[5] + m[4],
91108
+ m[1] * t[4] + m[3] * t[5] + m[5]
91109
+ ];
91110
+ }
91111
+ });
91112
+
90683
91113
  // src/pdf/symbol-fonts.ts
90684
91114
  function symbolFontTable(fontName) {
90685
91115
  if (!fontName) return void 0;
@@ -91007,7 +91437,7 @@ function occludedTextItems(items, fnArray, argsArray) {
91007
91437
  if (fn === OPS.save || fn === OPS.paintFormXObjectBegin) {
91008
91438
  stack.push({ ctm: ctm.slice(), alpha, normalBlend, clip });
91009
91439
  const m = fn === OPS.paintFormXObjectBegin ? args[0] : null;
91010
- if (Array.isArray(m) && m.length >= 6) ctm = mul2(ctm, m);
91440
+ if (Array.isArray(m) && m.length >= 6) ctm = mul3(ctm, m);
91011
91441
  const bbox = fn === OPS.paintFormXObjectBegin ? args[1] : null;
91012
91442
  if (Array.isArray(bbox) && bbox.length === 4 && clip !== null) {
91013
91443
  const axisAligned = ctm[1] === 0 && ctm[2] === 0 || ctm[0] === 0 && ctm[3] === 0;
@@ -91017,7 +91447,7 @@ function occludedTextItems(items, fnArray, argsArray) {
91017
91447
  } else if (fn === OPS.restore || fn === OPS.paintFormXObjectEnd) {
91018
91448
  const s = stack.pop();
91019
91449
  if (s) ({ ctm, alpha, normalBlend, clip } = s);
91020
- } else if (fn === OPS.transform) ctm = mul2(ctm, args);
91450
+ } else if (fn === OPS.transform) ctm = mul3(ctm, args);
91021
91451
  else if (fn === OPS.setGState) {
91022
91452
  const entries = args[0];
91023
91453
  if (Array.isArray(entries)) for (const e of entries) {
@@ -91075,7 +91505,7 @@ function occludedTextItems(items, fnArray, argsArray) {
91075
91505
  }
91076
91506
  return hidden;
91077
91507
  }
91078
- function mul2(m, t) {
91508
+ function mul3(m, t) {
91079
91509
  return [
91080
91510
  m[0] * t[0] + m[2] * t[1],
91081
91511
  m[1] * t[0] + m[3] * t[1],
@@ -92422,6 +92852,7 @@ async function parsePdfDocument(buffer, options) {
92422
92852
  remapSymbolFontItems(visible, (loadedName) => fontObj(loadedName)?.name);
92423
92853
  remapControlGlyphs(visible, differencesOf);
92424
92854
  await restoreImageBullets(visible, imagePage2, opList.fnArray, opList.argsArray, imageBulletShapes);
92855
+ restoreVectorBullets(visible, opList.fnArray, opList.argsArray);
92425
92856
  const faces = /* @__PURE__ */ new Map();
92426
92857
  for (const it of visible) {
92427
92858
  if (!it.fontName) continue;
@@ -92801,6 +93232,7 @@ var init_parser9 = __esm({
92801
93232
  init_table_trim();
92802
93233
  init_selection_context();
92803
93234
  init_image_bullets();
93235
+ init_vector_bullets();
92804
93236
  init_flow_boxes();
92805
93237
  init_symbol_fonts2();
92806
93238
  init_equation_runs();
@@ -92876,6 +93308,7 @@ __export(index_exports, {
92876
93308
  flattenLayoutTables: () => flattenLayoutTables,
92877
93309
  formatFillValue: () => formatFillValue,
92878
93310
  formatGateFinding: () => formatGateFinding,
93311
+ getPiiModelsDir: () => getPiiModelsDir,
92879
93312
  gongmunGate: () => gongmunGate,
92880
93313
  gongmunLintWarnings: () => gongmunLintWarnings,
92881
93314
  hasStructuredCellContent: () => hasStructuredCellContent,
@@ -92897,6 +93330,7 @@ __export(index_exports, {
92897
93330
  lintMuncheText: () => lintMuncheText,
92898
93331
  lintSlopText: () => lintSlopText,
92899
93332
  loadAgencyPack: () => loadAgencyPack,
93333
+ loadPiiModel: () => loadPiiModel,
92900
93334
  logicLintWarnings: () => logicLintWarnings,
92901
93335
  markdownToHwpx: () => markdownToHwpx,
92902
93336
  markdownToPdf: () => markdownToPdf,
@@ -92957,7 +93391,7 @@ async function parse(input, options) {
92957
93391
  if (ocrOptionError) return { success: false, fileType: "unknown", error: ocrOptionError };
92958
93392
  if (typeof input === "string") {
92959
93393
  try {
92960
- const buf = await (0, import_promises10.readFile)(input);
93394
+ const buf = await (0, import_promises11.readFile)(input);
92961
93395
  buffer = toArrayBuffer(buf);
92962
93396
  } catch (err) {
92963
93397
  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}`;
@@ -93244,7 +93678,7 @@ async function parseHwpml(buffer, options) {
93244
93678
  async function fillForm(input, values, outputFormat = "markdown") {
93245
93679
  let buffer;
93246
93680
  if (typeof input === "string") {
93247
- const buf = await (0, import_promises10.readFile)(input);
93681
+ const buf = await (0, import_promises11.readFile)(input);
93248
93682
  buffer = toArrayBuffer(buf);
93249
93683
  } else if (Buffer.isBuffer(input)) {
93250
93684
  buffer = toArrayBuffer(input);
@@ -93284,7 +93718,7 @@ async function fillForm(input, values, outputFormat = "markdown") {
93284
93718
  }
93285
93719
  return { output: markdown, format: "markdown", fill };
93286
93720
  }
93287
- var import_promises10, MAX_PAGE_IMAGE_BYTES, MAX_MULTIPAGE_PIXELS, MIN_PAGE_PIXELS2;
93721
+ var import_promises11, MAX_PAGE_IMAGE_BYTES, MAX_MULTIPAGE_PIXELS, MIN_PAGE_PIXELS2;
93288
93722
  var init_index = __esm({
93289
93723
  "src/index.ts"() {
93290
93724
  init_script_tags();
@@ -93293,7 +93727,7 @@ var init_index = __esm({
93293
93727
  init_html_tables();
93294
93728
  init_html_cell_links();
93295
93729
  init_memo_notes();
93296
- import_promises10 = require("fs/promises");
93730
+ import_promises11 = require("fs/promises");
93297
93731
  init_detect();
93298
93732
  init_parser();
93299
93733
  init_parser2();
@@ -93351,6 +93785,7 @@ var init_index = __esm({
93351
93785
  init_hwp5_patch();
93352
93786
  init_validate();
93353
93787
  init_redact();
93788
+ init_redact_model();
93354
93789
  init_chunks();
93355
93790
  init_session();
93356
93791
  init_source_map();
@@ -93417,6 +93852,7 @@ init_index();
93417
93852
  flattenLayoutTables,
93418
93853
  formatFillValue,
93419
93854
  formatGateFinding,
93855
+ getPiiModelsDir,
93420
93856
  gongmunGate,
93421
93857
  gongmunLintWarnings,
93422
93858
  hasStructuredCellContent,
@@ -93438,6 +93874,7 @@ init_index();
93438
93874
  lintMuncheText,
93439
93875
  lintSlopText,
93440
93876
  loadAgencyPack,
93877
+ loadPiiModel,
93441
93878
  logicLintWarnings,
93442
93879
  markdownToHwpx,
93443
93880
  markdownToPdf,