kordoc 4.0.8 → 4.2.0

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 (122) hide show
  1. package/README.md +50 -16
  2. package/dist/{-LE4RLXVA.js → -SXQIZHYA.js} +24 -10
  3. package/dist/{parser-TCTCSBYZ.js → chunk-26AJJCFF.js} +1427 -2027
  4. package/dist/chunk-26AJJCFF.js.map +1 -0
  5. package/dist/{parser-KMMUS73Q.js → chunk-4JPPLIIV.js} +1425 -2025
  6. package/dist/chunk-4JPPLIIV.js.map +1 -0
  7. package/dist/chunk-4VNLZ2GZ.js +13 -0
  8. package/dist/chunk-4VNLZ2GZ.js.map +1 -0
  9. package/dist/{chunk-2DZQF6YJ.js → chunk-6SHO3BNV.js} +24 -15
  10. package/dist/chunk-6SHO3BNV.js.map +1 -0
  11. package/dist/chunk-7FCNOKOR.js +144 -0
  12. package/dist/chunk-7FCNOKOR.js.map +1 -0
  13. package/dist/{chunk-6XAAYAWL.cjs → chunk-CMN3SYZ3.js} +62 -304
  14. package/dist/chunk-CMN3SYZ3.js.map +1 -0
  15. package/dist/chunk-DZIXKL7E.js +145 -0
  16. package/dist/chunk-DZIXKL7E.js.map +1 -0
  17. package/dist/chunk-ELOV2GIJ.js +82 -0
  18. package/dist/chunk-ELOV2GIJ.js.map +1 -0
  19. package/dist/chunk-F2HYH62H.cjs +130 -0
  20. package/dist/chunk-F2HYH62H.cjs.map +1 -0
  21. package/dist/{chunk-HMUEU7D7.js → chunk-FSXLSHCW.js} +3 -3
  22. package/dist/{chunk-HMUEU7D7.js.map → chunk-FSXLSHCW.js.map} +1 -1
  23. package/dist/chunk-GEPINOL6.js +83 -0
  24. package/dist/chunk-GEPINOL6.js.map +1 -0
  25. package/dist/chunk-H7OWEYH2.cjs +243 -0
  26. package/dist/chunk-H7OWEYH2.cjs.map +1 -0
  27. package/dist/{chunk-7S3M4N4E.js → chunk-IGGRLWT5.js} +683 -226
  28. package/dist/chunk-IGGRLWT5.js.map +1 -0
  29. package/dist/chunk-J2RZ444H.js +243 -0
  30. package/dist/chunk-J2RZ444H.js.map +1 -0
  31. package/dist/chunk-JP5YH3Z4.js +130 -0
  32. package/dist/chunk-JP5YH3Z4.js.map +1 -0
  33. package/dist/{parser-ITMU2WN5.cjs → chunk-LHROM2BO.cjs} +1409 -2012
  34. package/dist/chunk-LHROM2BO.cjs.map +1 -0
  35. package/dist/chunk-NNDVFNMJ.js +246 -0
  36. package/dist/chunk-NNDVFNMJ.js.map +1 -0
  37. package/dist/{chunk-RROH5WHO.js → chunk-PLIY23LY.js} +2 -2
  38. package/dist/{chunk-BNU5QGIZ.js → chunk-V6U6YS5B.js} +12 -4
  39. package/dist/chunk-V6U6YS5B.js.map +1 -0
  40. package/dist/{chunk-UEIYETCQ.js → chunk-WF2E5P2G.js} +40 -35
  41. package/dist/chunk-WF2E5P2G.js.map +1 -0
  42. package/dist/{chunk-D35VBACN.js → chunk-WQLHPOMJ.js} +7 -4
  43. package/dist/chunk-WQLHPOMJ.js.map +1 -0
  44. package/dist/{chunk-OQPILS7B.js → chunk-XTCT6KQ5.cjs} +79 -183
  45. package/dist/chunk-XTCT6KQ5.cjs.map +1 -0
  46. package/dist/{chunk-MEPHGCPQ.js → chunk-YOO6ET6M.js} +7 -3
  47. package/dist/chunk-YOO6ET6M.js.map +1 -0
  48. package/dist/chunks-ZQEFAZNC.js +10 -0
  49. package/dist/cli.js +228 -36
  50. package/dist/cli.js.map +1 -1
  51. package/dist/{detect-RI2MQ33K.js → detect-YEZX2XCF.js} +2 -2
  52. package/dist/{formula-RXVSQPXI.js → formula-KSNAEBZ2.js} +23 -232
  53. package/dist/formula-KSNAEBZ2.js.map +1 -0
  54. package/dist/{formula-5NKVS2LR.cjs → formula-SB3NHDUM.cjs} +30 -240
  55. package/dist/formula-SB3NHDUM.cjs.map +1 -0
  56. package/dist/{formula-JCNF43NE.js → formula-SXC6LRRC.js} +23 -233
  57. package/dist/formula-SXC6LRRC.js.map +1 -0
  58. package/dist/index.cjs +1280 -589
  59. package/dist/index.cjs.map +1 -1
  60. package/dist/index.d.cts +112 -4
  61. package/dist/index.d.ts +112 -4
  62. package/dist/index.js +929 -238
  63. package/dist/index.js.map +1 -1
  64. package/dist/mcp.js +278 -68
  65. package/dist/mcp.js.map +1 -1
  66. package/dist/models-KA4GLQK5.js +25 -0
  67. package/dist/parser-ND2YGQZR.js +800 -0
  68. package/dist/parser-ND2YGQZR.js.map +1 -0
  69. package/dist/parser-RBZHA6SY.js +804 -0
  70. package/dist/parser-RBZHA6SY.js.map +1 -0
  71. package/dist/parser-WDZOMDG4.cjs +803 -0
  72. package/dist/parser-WDZOMDG4.cjs.map +1 -0
  73. package/dist/pdf-ocr-2Z7VZIFI.cjs +439 -0
  74. package/dist/pdf-ocr-2Z7VZIFI.cjs.map +1 -0
  75. package/dist/pdf-ocr-FJFXFADQ.js +438 -0
  76. package/dist/pdf-ocr-FJFXFADQ.js.map +1 -0
  77. package/dist/pdf-ocr-VYE4DHD4.js +386 -0
  78. package/dist/pdf-ocr-VYE4DHD4.js.map +1 -0
  79. package/dist/{profile-io-SLN4P76T.js → profile-io-TWHDIVPL.js} +3 -3
  80. package/dist/rasterize-W2NEZUSW.js +40 -0
  81. package/dist/rasterize-W2NEZUSW.js.map +1 -0
  82. package/dist/redact-7ILEAUTS.js +12 -0
  83. package/dist/redact-7ILEAUTS.js.map +1 -0
  84. package/dist/render-4MG5QUDG.js +10 -0
  85. package/dist/render-4MG5QUDG.js.map +1 -0
  86. package/dist/seal-D2QNXJVO.js +10 -0
  87. package/dist/seal-D2QNXJVO.js.map +1 -0
  88. package/dist/{setup-57FB3LSP.js → setup-Q2PRE7UA.js} +5 -3
  89. package/dist/setup-Q2PRE7UA.js.map +1 -0
  90. package/dist/{watch-OHQWSVPE.js → watch-VWXJZT2R.js} +78 -23
  91. package/dist/watch-VWXJZT2R.js.map +1 -0
  92. package/package.json +2 -1
  93. package/dist/chunk-2DZQF6YJ.js.map +0 -1
  94. package/dist/chunk-6XAAYAWL.cjs.map +0 -1
  95. package/dist/chunk-7S3M4N4E.js.map +0 -1
  96. package/dist/chunk-BNU5QGIZ.js.map +0 -1
  97. package/dist/chunk-D35VBACN.js.map +0 -1
  98. package/dist/chunk-MEPHGCPQ.js.map +0 -1
  99. package/dist/chunk-OQPILS7B.js.map +0 -1
  100. package/dist/chunk-UEIYETCQ.js.map +0 -1
  101. package/dist/formula-5NKVS2LR.cjs.map +0 -1
  102. package/dist/formula-JCNF43NE.js.map +0 -1
  103. package/dist/formula-RXVSQPXI.js.map +0 -1
  104. package/dist/parser-ITMU2WN5.cjs.map +0 -1
  105. package/dist/parser-KMMUS73Q.js.map +0 -1
  106. package/dist/parser-TCTCSBYZ.js.map +0 -1
  107. package/dist/provider-4ZJKV3DC.js +0 -37
  108. package/dist/provider-4ZJKV3DC.js.map +0 -1
  109. package/dist/provider-AKROB7WQ.js +0 -39
  110. package/dist/provider-AKROB7WQ.js.map +0 -1
  111. package/dist/provider-G4C2V2PD.cjs +0 -39
  112. package/dist/provider-G4C2V2PD.cjs.map +0 -1
  113. package/dist/render-25BT623I.js +0 -10
  114. package/dist/seal-R4TETA4C.js +0 -10
  115. package/dist/setup-57FB3LSP.js.map +0 -1
  116. package/dist/watch-OHQWSVPE.js.map +0 -1
  117. /package/dist/{-LE4RLXVA.js.map → -SXQIZHYA.js.map} +0 -0
  118. /package/dist/{chunk-RROH5WHO.js.map → chunk-PLIY23LY.js.map} +0 -0
  119. /package/dist/{detect-RI2MQ33K.js.map → chunks-ZQEFAZNC.js.map} +0 -0
  120. /package/dist/{profile-io-SLN4P76T.js.map → detect-YEZX2XCF.js.map} +0 -0
  121. /package/dist/{render-25BT623I.js.map → models-KA4GLQK5.js.map} +0 -0
  122. /package/dist/{seal-R4TETA4C.js.map → profile-io-TWHDIVPL.js.map} +0 -0
package/dist/index.d.cts CHANGED
@@ -134,12 +134,20 @@ interface ParseOptions {
134
134
  * PDF: 정확한 페이지 단위. HWP/HWPX: 섹션 단위 근사치.
135
135
  */
136
136
  pages?: number[] | string;
137
- /** 이미지 기반 PDF OCR 프로바이더 (선택) */
138
- ocr?: OcrProvider;
137
+ /** 이미지 기반 PDF OCR (선택).
138
+ * - `true`: 내장 엔진(PP-OCRv5 korean, ~18MB 자동 다운로드)으로 OCR 필요 판정
139
+ * 페이지만 인식 (스캔 페이지·글꼴 매핑 깨진 페이지). 정상 페이지는 파싱 결과 유지.
140
+ * - `"force"`: 전 페이지를 내장 엔진으로 강제 OCR.
141
+ * - 함수: 사용자 제공 OcrProvider (Claude Vision·Tesseract 등) — 판정은 `true`와 동일. */
142
+ ocr?: boolean | "force" | OcrProvider;
139
143
  /** 진행률 콜백 — current: 현재 페이지/섹션, total: 전체 수 */
140
144
  onProgress?: (current: number, total: number) => void;
141
145
  /** PDF 머리글/바닥글 자동 제거 */
142
146
  removeHeaderFooter?: boolean;
147
+ /** 표 오른쪽 끝의 빈 열(서식 문서의 입력란) 보존 (#47).
148
+ * 기본 false: 마크다운 가독성을 위해 후행 빈 열을 트림.
149
+ * 양식 인식 경로(parse_form·fill)는 내부적으로 항상 켠다. */
150
+ keepTrailingEmptyCols?: boolean;
143
151
  /** 원본 파일 경로 (DRM COM fallback에 필요, 내부 전용) */
144
152
  filePath?: string;
145
153
  /**
@@ -186,7 +194,7 @@ interface ParseWarning {
186
194
  /** 구조화된 경고 코드 */
187
195
  code: WarningCode;
188
196
  }
189
- type WarningCode = "SKIPPED_IMAGE" | "SKIPPED_OLE" | "TRUNCATED_TABLE" | "OCR_FALLBACK" | "UNSUPPORTED_ELEMENT" | "BROKEN_ZIP_RECOVERY" | "HIDDEN_TEXT_FILTERED" | "MALFORMED_XML" | "PARTIAL_PARSE" | "LENIENT_CFB_RECOVERY" | "NEEDS_OCR" | "COM_EMPTY" | "DRM_COM_FALLBACK";
197
+ type WarningCode = "SKIPPED_IMAGE" | "SKIPPED_OLE" | "TRUNCATED_TABLE" | "OCR_FALLBACK" | "UNSUPPORTED_ELEMENT" | "BROKEN_ZIP_RECOVERY" | "HIDDEN_TEXT_FILTERED" | "MALFORMED_XML" | "PARTIAL_PARSE" | "LENIENT_CFB_RECOVERY" | "NEEDS_OCR" | "OCR_FAILED" | "OCR_APPLIED" | "COM_EMPTY" | "DRM_COM_FALLBACK";
190
198
  /** 문서 구조 (헤딩 트리) */
191
199
  interface OutlineItem {
192
200
  level: number;
@@ -466,6 +474,8 @@ interface FillResult {
466
474
  filled: FormField[];
467
475
  /** 매칭 실패한 라벨 (입력에는 있지만 서식에서 못 찾은 것) */
468
476
  unmatched: string[];
477
+ /** 비치명 경고 (입력 라벨 정규화 충돌 등) — 없으면 생략 */
478
+ warnings?: string[];
469
479
  }
470
480
  /**
471
481
  * IRBlock[]에서 양식 필드를 찾아 값을 교체.
@@ -522,6 +532,8 @@ interface HwpxFillResult {
522
532
  filled: FormField[];
523
533
  /** 매칭 실패한 라벨 */
524
534
  unmatched: string[];
535
+ /** 비치명 경고 (입력 라벨 정규화 충돌 등) — 없으면 생략 */
536
+ warnings?: string[];
525
537
  }
526
538
  /**
527
539
  * HWPX 원본을 직접 수정하여 서식 필드를 채움 — 스타일 100% 보존.
@@ -1260,6 +1272,102 @@ interface ValidateResult {
1260
1272
  /** HWPX 버퍼의 컨테이너 구조를 검증한다. 문제가 없으면 ok=true. */
1261
1273
  declare function validateHwpx(buffer: ArrayBuffer | Uint8Array): Promise<ValidateResult>;
1262
1274
 
1275
+ /**
1276
+ * 한국 공문서 PII(개인정보) 탐지·마스킹 순수 로직.
1277
+ *
1278
+ * 텍스트 in → 마스킹된 텍스트 + 히트 리포트 out. 문서 파싱/patch는 기존 인프라가
1279
+ * 담당하고 여기서는 텍스트만 다룬다 (CLI/MCP 배선은 별도).
1280
+ *
1281
+ * 원칙:
1282
+ * - 서식 보존 마스킹 — 자릿수·구분자를 유지해 마스킹 전후 길이가 동일
1283
+ * - 히트 리포트에 원본 PII를 절대 담지 않는다 (`masked` 필드만 존재)
1284
+ * - 룰 우선순위 겹침 처리 — 우선순위순으로 매치를 수집하고, 이미 점유된
1285
+ * 구간과 겹치는 하위 룰 매치는 스킵 (RULE_PRIORITY 참조)
1286
+ * - 정규식은 모듈 로드 시 1회 컴파일 (matchAll은 내부 클론이라 lastIndex 안전)
1287
+ */
1288
+ type RedactRule = "rrn" | "phone" | "email" | "card" | "account" | "passport" | "driver";
1289
+ interface RedactHit {
1290
+ rule: RedactRule;
1291
+ /** 마스킹 후 문자열 — 원본 PII는 리포트에 담지 않는다 */
1292
+ masked: string;
1293
+ /** 원문 내 시작 오프셋 (UTF-16 단위) */
1294
+ index: number;
1295
+ /** 매치 길이 (서식 보존이라 마스킹 전후 동일) */
1296
+ length: number;
1297
+ }
1298
+ interface RedactTextResult {
1299
+ text: string;
1300
+ hits: RedactHit[];
1301
+ }
1302
+ interface RedactOptions {
1303
+ /** 적용할 룰 (기본: DEFAULT_REDACT_RULES — passport·driver는 기본 OFF) */
1304
+ rules?: RedactRule[];
1305
+ /** 마스크 문자 — 1글자(UTF-16 1단위), 영숫자 금지. 기본 "●" (마크다운 특수문자 아님) */
1306
+ maskChar?: string;
1307
+ }
1308
+ /** 기본 적용 룰 — passport(여권)·driver(운전면허)는 오탐 여지가 있어 opt-in */
1309
+ declare const DEFAULT_REDACT_RULES: readonly RedactRule[];
1310
+ /**
1311
+ * 텍스트에서 PII를 탐지해 서식 보존 마스킹.
1312
+ *
1313
+ * @param text - 대상 텍스트 (마크다운 포함)
1314
+ * @param options - 룰 선택·마스크 문자 (기본: rrn·phone·email·card·account, "●")
1315
+ * @returns 마스킹된 텍스트 + 히트 리포트 (index 오름차순, 원본 PII 미포함)
1316
+ */
1317
+ declare function redactText(text: string, options?: RedactOptions): RedactTextResult;
1318
+ /**
1319
+ * 마크다운 문서 전용 래퍼 — base64 이미지(data URI) 라인은 마스킹에서 제외한다.
1320
+ * base64 페이로드의 숫자열이 phone 등에 오탐되면 이미지가 깨지기 때문.
1321
+ * hits의 index는 문서 전체 기준 절대 오프셋으로 환산된다.
1322
+ */
1323
+ declare function redactMarkdown(markdown: string, options?: RedactOptions): RedactTextResult;
1324
+
1325
+ /**
1326
+ * RAG용 구조 보존 청킹 — IRBlock[] → DocChunk[].
1327
+ *
1328
+ * 문서의 위계(마크다운 헤딩 스택 + 개조식 리스트 깊이)를 breadcrumb으로 보존한
1329
+ * 청크 목록을 만든다. 토큰 상한·오버랩 등 자르기 정책은 의도적으로 없다 —
1330
+ * "구조 트리 제공"까지가 이 모듈의 몫이고 실제 분할은 소비자(RAG 파이프라인)가 한다.
1331
+ *
1332
+ * breadcrumb 규칙:
1333
+ * - 헤딩(level 1~6)은 스택 구조 — 같거나 깊은 level을 팝하고 push, 리스트 위계 리셋
1334
+ * - 리스트 항목은 깊이 d 등장 시 depth>=d를 팝하고 push — 하위 항목이 뒤따르면
1335
+ * 그 breadcrumb으로 승격되고, 자식이 없으면 다음 형제/헤딩이 팝해 자연 소멸
1336
+ * - 깊이는 IR의 listDepth 그대로. listDepth가 없는 개조식 선두 부호 문단
1337
+ * (□·○·- / 1.·가.·1) 등)은 depth 0 항목으로 취급 — IR에 없는 깊이는 지어내지 않는다
1338
+ * - 청크의 breadcrumb은 자기 자신을 제외한 상위 경로다
1339
+ */
1340
+
1341
+ interface DocChunk {
1342
+ /** "c0001" 순번 id — 같은 입력이면 같은 출력 (결정적) */
1343
+ id: string;
1344
+ type: "text" | "table" | "heading";
1345
+ /** 상위 헤딩 + 리스트 위계 경로 (예: ["1. 개요", "가. 목적"]) */
1346
+ breadcrumb: string[];
1347
+ /** 청크 본문 마크다운 — 표는 GFM/HTML 그대로 (blocksToMarkdown 재사용) */
1348
+ text: string;
1349
+ /** 원본 페이지/섹션 번호 (1-based) — IR에 없으면 생략 */
1350
+ page?: number;
1351
+ /** 원본 IRBlock 인덱스 범위 [start, end] (양끝 포함) — 출처 앵커 */
1352
+ blockRange: [number, number];
1353
+ /** 표 청크 전용 구조 요약 — cells는 includeTableCells 옵션 시에만 */
1354
+ table?: {
1355
+ rows: number;
1356
+ cols: number;
1357
+ cells?: string[][];
1358
+ };
1359
+ }
1360
+ interface ChunkOptions {
1361
+ /** 표 청크에 셀 텍스트 행렬 포함 여부 (기본 false) */
1362
+ includeTableCells?: boolean;
1363
+ /**
1364
+ * "section"(기본): 같은 breadcrumb 아래 연속 텍스트 블록을 하나로 병합,
1365
+ * "block": IRBlock 1개 = 청크 1개
1366
+ */
1367
+ granularity?: "block" | "section";
1368
+ }
1369
+ declare function blocksToChunks(blocks: IRBlock[], options?: ChunkOptions): DocChunk[];
1370
+
1263
1371
  /**
1264
1372
  * HWPX 문서 세션 — 에디터 통합용 블록 단위 증분 패치 API (v3.1).
1265
1373
  *
@@ -1556,4 +1664,4 @@ interface FillFormOutput {
1556
1664
  */
1557
1665
  declare function fillForm(input: string | ArrayBuffer | Buffer, values: Record<string, FillInput>, outputFormat?: FillOutputFormat): Promise<FillFormOutput>;
1558
1666
 
1559
- export { type BlockCapability, type BlockCapabilityInfo, type BlockDiff, type BlockEdit, type BlockSourceRef, type BorderDef, type BorderFillDef, type BoundingBox, type CellCapability, type CellContext, type CellDiff, type CellProfile, type CharPrDef, type DiffChangeType, type DiffResult, type DocumentMetadata, type DocumentQualitySummary, type ErrorCode, type ExtractedImage, type FileType, type FillFormOutput, type FillInput, type FillOutputFormat, type FillResult, type FillValue, type FormField, type FormFieldSchema, type FormFieldType, type FormResult, type FormSchemaResult, type FormatProfile, type GongmunFont, type GongmunLintFinding, type GongmunNumbering, type GongmunOptions, type GongmunPreset, type GongmunPresetInput, type HwpxFillResult, HwpxSession, type HwpxTheme, type IRBlock, type IRBlockType, type IRCell, type IRTable, type ImageData, type InlineStyle, type MarkdownToHwpxOptions, type MeasureOptions, type OcrProvider, type OutlineItem, PRESET_ALIAS, type PageMargin, type PageQuality, type ParseFailure, type ParseOptions, type ParseResult, type ParseSuccess, type ParseWarning, type PatchOptions, type PatchResult, type PatchSkip, type PlaceSealResult, type PrintOptions, type PrintPreset, type RenderSvgOptions, type RenderSvgResult, SPACE_EM_FIXED, SPACE_EM_FONT, type ScanCell, type ScanParaKind, type ScanParagraph, type ScanTable, type SealOp, type SealPlacement, type SectionScan, type SpliceEdit, type TRange, type TableProfile, VERSION, type ValidateIssue, type ValidateResult, ValueCursor, type WarningCode, type WatchOptions, type WrapMode, type WrapResult, applySplices, blocksToMarkdown, blocksToPdf, buildParagraphSplices, buildRangeSplices, charWidthEm1000, compare, detectFormat, detectOle2Format, detectZipFormat, diffBlocks, extractFormFields, extractFormSchema, fillForm, fillFormFields, fillHwpx, fillWithUniqueGuard, fitRatioForFewerLines, formatFillValue, gongmunLintWarnings, hwpxToProfile, incompatibleGongmunWarnings, inferFieldType, isHwpxFile, isKnownFont, isLabelCell, isOldHwpFile, isPdfFile, isZipFile, lintGongmunText, markdownToHwpx, markdownToPdf, measureTextWidth, normalizeGongmunPreset, openHwpxDocument, parse, parseDocx, parseHwp, parseHwp3, parseHwpml, parseHwpx, parsePdf, parseXls, parseXlsx, patchHwp, patchHwpx, patchHwpxBlocks, placeSealHwpx, renderHtml, renderHwpxToSvg, scanSectionXml, simulateWrap, simulateWrapKeepWord, unknownFontWarnings, validateHwpx };
1667
+ export { type BlockCapability, type BlockCapabilityInfo, type BlockDiff, type BlockEdit, type BlockSourceRef, type BorderDef, type BorderFillDef, type BoundingBox, type CellCapability, type CellContext, type CellDiff, type CellProfile, type CharPrDef, type ChunkOptions, DEFAULT_REDACT_RULES, type DiffChangeType, type DiffResult, type DocChunk, type DocumentMetadata, type DocumentQualitySummary, type ErrorCode, type ExtractedImage, type FileType, type FillFormOutput, type FillInput, type FillOutputFormat, type FillResult, type FillValue, type FormField, type FormFieldSchema, type FormFieldType, type FormResult, type FormSchemaResult, type FormatProfile, type GongmunFont, type GongmunLintFinding, type GongmunNumbering, type GongmunOptions, type GongmunPreset, type GongmunPresetInput, type HwpxFillResult, HwpxSession, type HwpxTheme, type IRBlock, type IRBlockType, type IRCell, type IRTable, type ImageData, type InlineStyle, type MarkdownToHwpxOptions, type MeasureOptions, type OcrProvider, type OutlineItem, PRESET_ALIAS, type PageMargin, type PageQuality, type ParseFailure, type ParseOptions, type ParseResult, type ParseSuccess, type ParseWarning, type PatchOptions, type PatchResult, type PatchSkip, type PlaceSealResult, type PrintOptions, type PrintPreset, type RedactHit, type RedactOptions, type RedactRule, type RedactTextResult, type RenderSvgOptions, type RenderSvgResult, SPACE_EM_FIXED, SPACE_EM_FONT, type ScanCell, type ScanParaKind, type ScanParagraph, type ScanTable, type SealOp, type SealPlacement, type SectionScan, type SpliceEdit, type TRange, type TableProfile, VERSION, type ValidateIssue, type ValidateResult, ValueCursor, type WarningCode, type WatchOptions, type WrapMode, type WrapResult, applySplices, blocksToChunks, blocksToMarkdown, blocksToPdf, buildParagraphSplices, buildRangeSplices, charWidthEm1000, compare, detectFormat, detectOle2Format, detectZipFormat, diffBlocks, extractFormFields, extractFormSchema, fillForm, fillFormFields, fillHwpx, fillWithUniqueGuard, fitRatioForFewerLines, formatFillValue, gongmunLintWarnings, hwpxToProfile, incompatibleGongmunWarnings, inferFieldType, isHwpxFile, isKnownFont, isLabelCell, isOldHwpFile, isPdfFile, isZipFile, lintGongmunText, markdownToHwpx, markdownToPdf, measureTextWidth, normalizeGongmunPreset, openHwpxDocument, parse, parseDocx, parseHwp, parseHwp3, parseHwpml, parseHwpx, parsePdf, parseXls, parseXlsx, patchHwp, patchHwpx, patchHwpxBlocks, placeSealHwpx, redactMarkdown, redactText, renderHtml, renderHwpxToSvg, scanSectionXml, simulateWrap, simulateWrapKeepWord, unknownFontWarnings, validateHwpx };
package/dist/index.d.ts CHANGED
@@ -134,12 +134,20 @@ interface ParseOptions {
134
134
  * PDF: 정확한 페이지 단위. HWP/HWPX: 섹션 단위 근사치.
135
135
  */
136
136
  pages?: number[] | string;
137
- /** 이미지 기반 PDF OCR 프로바이더 (선택) */
138
- ocr?: OcrProvider;
137
+ /** 이미지 기반 PDF OCR (선택).
138
+ * - `true`: 내장 엔진(PP-OCRv5 korean, ~18MB 자동 다운로드)으로 OCR 필요 판정
139
+ * 페이지만 인식 (스캔 페이지·글꼴 매핑 깨진 페이지). 정상 페이지는 파싱 결과 유지.
140
+ * - `"force"`: 전 페이지를 내장 엔진으로 강제 OCR.
141
+ * - 함수: 사용자 제공 OcrProvider (Claude Vision·Tesseract 등) — 판정은 `true`와 동일. */
142
+ ocr?: boolean | "force" | OcrProvider;
139
143
  /** 진행률 콜백 — current: 현재 페이지/섹션, total: 전체 수 */
140
144
  onProgress?: (current: number, total: number) => void;
141
145
  /** PDF 머리글/바닥글 자동 제거 */
142
146
  removeHeaderFooter?: boolean;
147
+ /** 표 오른쪽 끝의 빈 열(서식 문서의 입력란) 보존 (#47).
148
+ * 기본 false: 마크다운 가독성을 위해 후행 빈 열을 트림.
149
+ * 양식 인식 경로(parse_form·fill)는 내부적으로 항상 켠다. */
150
+ keepTrailingEmptyCols?: boolean;
143
151
  /** 원본 파일 경로 (DRM COM fallback에 필요, 내부 전용) */
144
152
  filePath?: string;
145
153
  /**
@@ -186,7 +194,7 @@ interface ParseWarning {
186
194
  /** 구조화된 경고 코드 */
187
195
  code: WarningCode;
188
196
  }
189
- type WarningCode = "SKIPPED_IMAGE" | "SKIPPED_OLE" | "TRUNCATED_TABLE" | "OCR_FALLBACK" | "UNSUPPORTED_ELEMENT" | "BROKEN_ZIP_RECOVERY" | "HIDDEN_TEXT_FILTERED" | "MALFORMED_XML" | "PARTIAL_PARSE" | "LENIENT_CFB_RECOVERY" | "NEEDS_OCR" | "COM_EMPTY" | "DRM_COM_FALLBACK";
197
+ type WarningCode = "SKIPPED_IMAGE" | "SKIPPED_OLE" | "TRUNCATED_TABLE" | "OCR_FALLBACK" | "UNSUPPORTED_ELEMENT" | "BROKEN_ZIP_RECOVERY" | "HIDDEN_TEXT_FILTERED" | "MALFORMED_XML" | "PARTIAL_PARSE" | "LENIENT_CFB_RECOVERY" | "NEEDS_OCR" | "OCR_FAILED" | "OCR_APPLIED" | "COM_EMPTY" | "DRM_COM_FALLBACK";
190
198
  /** 문서 구조 (헤딩 트리) */
191
199
  interface OutlineItem {
192
200
  level: number;
@@ -466,6 +474,8 @@ interface FillResult {
466
474
  filled: FormField[];
467
475
  /** 매칭 실패한 라벨 (입력에는 있지만 서식에서 못 찾은 것) */
468
476
  unmatched: string[];
477
+ /** 비치명 경고 (입력 라벨 정규화 충돌 등) — 없으면 생략 */
478
+ warnings?: string[];
469
479
  }
470
480
  /**
471
481
  * IRBlock[]에서 양식 필드를 찾아 값을 교체.
@@ -522,6 +532,8 @@ interface HwpxFillResult {
522
532
  filled: FormField[];
523
533
  /** 매칭 실패한 라벨 */
524
534
  unmatched: string[];
535
+ /** 비치명 경고 (입력 라벨 정규화 충돌 등) — 없으면 생략 */
536
+ warnings?: string[];
525
537
  }
526
538
  /**
527
539
  * HWPX 원본을 직접 수정하여 서식 필드를 채움 — 스타일 100% 보존.
@@ -1260,6 +1272,102 @@ interface ValidateResult {
1260
1272
  /** HWPX 버퍼의 컨테이너 구조를 검증한다. 문제가 없으면 ok=true. */
1261
1273
  declare function validateHwpx(buffer: ArrayBuffer | Uint8Array): Promise<ValidateResult>;
1262
1274
 
1275
+ /**
1276
+ * 한국 공문서 PII(개인정보) 탐지·마스킹 순수 로직.
1277
+ *
1278
+ * 텍스트 in → 마스킹된 텍스트 + 히트 리포트 out. 문서 파싱/patch는 기존 인프라가
1279
+ * 담당하고 여기서는 텍스트만 다룬다 (CLI/MCP 배선은 별도).
1280
+ *
1281
+ * 원칙:
1282
+ * - 서식 보존 마스킹 — 자릿수·구분자를 유지해 마스킹 전후 길이가 동일
1283
+ * - 히트 리포트에 원본 PII를 절대 담지 않는다 (`masked` 필드만 존재)
1284
+ * - 룰 우선순위 겹침 처리 — 우선순위순으로 매치를 수집하고, 이미 점유된
1285
+ * 구간과 겹치는 하위 룰 매치는 스킵 (RULE_PRIORITY 참조)
1286
+ * - 정규식은 모듈 로드 시 1회 컴파일 (matchAll은 내부 클론이라 lastIndex 안전)
1287
+ */
1288
+ type RedactRule = "rrn" | "phone" | "email" | "card" | "account" | "passport" | "driver";
1289
+ interface RedactHit {
1290
+ rule: RedactRule;
1291
+ /** 마스킹 후 문자열 — 원본 PII는 리포트에 담지 않는다 */
1292
+ masked: string;
1293
+ /** 원문 내 시작 오프셋 (UTF-16 단위) */
1294
+ index: number;
1295
+ /** 매치 길이 (서식 보존이라 마스킹 전후 동일) */
1296
+ length: number;
1297
+ }
1298
+ interface RedactTextResult {
1299
+ text: string;
1300
+ hits: RedactHit[];
1301
+ }
1302
+ interface RedactOptions {
1303
+ /** 적용할 룰 (기본: DEFAULT_REDACT_RULES — passport·driver는 기본 OFF) */
1304
+ rules?: RedactRule[];
1305
+ /** 마스크 문자 — 1글자(UTF-16 1단위), 영숫자 금지. 기본 "●" (마크다운 특수문자 아님) */
1306
+ maskChar?: string;
1307
+ }
1308
+ /** 기본 적용 룰 — passport(여권)·driver(운전면허)는 오탐 여지가 있어 opt-in */
1309
+ declare const DEFAULT_REDACT_RULES: readonly RedactRule[];
1310
+ /**
1311
+ * 텍스트에서 PII를 탐지해 서식 보존 마스킹.
1312
+ *
1313
+ * @param text - 대상 텍스트 (마크다운 포함)
1314
+ * @param options - 룰 선택·마스크 문자 (기본: rrn·phone·email·card·account, "●")
1315
+ * @returns 마스킹된 텍스트 + 히트 리포트 (index 오름차순, 원본 PII 미포함)
1316
+ */
1317
+ declare function redactText(text: string, options?: RedactOptions): RedactTextResult;
1318
+ /**
1319
+ * 마크다운 문서 전용 래퍼 — base64 이미지(data URI) 라인은 마스킹에서 제외한다.
1320
+ * base64 페이로드의 숫자열이 phone 등에 오탐되면 이미지가 깨지기 때문.
1321
+ * hits의 index는 문서 전체 기준 절대 오프셋으로 환산된다.
1322
+ */
1323
+ declare function redactMarkdown(markdown: string, options?: RedactOptions): RedactTextResult;
1324
+
1325
+ /**
1326
+ * RAG용 구조 보존 청킹 — IRBlock[] → DocChunk[].
1327
+ *
1328
+ * 문서의 위계(마크다운 헤딩 스택 + 개조식 리스트 깊이)를 breadcrumb으로 보존한
1329
+ * 청크 목록을 만든다. 토큰 상한·오버랩 등 자르기 정책은 의도적으로 없다 —
1330
+ * "구조 트리 제공"까지가 이 모듈의 몫이고 실제 분할은 소비자(RAG 파이프라인)가 한다.
1331
+ *
1332
+ * breadcrumb 규칙:
1333
+ * - 헤딩(level 1~6)은 스택 구조 — 같거나 깊은 level을 팝하고 push, 리스트 위계 리셋
1334
+ * - 리스트 항목은 깊이 d 등장 시 depth>=d를 팝하고 push — 하위 항목이 뒤따르면
1335
+ * 그 breadcrumb으로 승격되고, 자식이 없으면 다음 형제/헤딩이 팝해 자연 소멸
1336
+ * - 깊이는 IR의 listDepth 그대로. listDepth가 없는 개조식 선두 부호 문단
1337
+ * (□·○·- / 1.·가.·1) 등)은 depth 0 항목으로 취급 — IR에 없는 깊이는 지어내지 않는다
1338
+ * - 청크의 breadcrumb은 자기 자신을 제외한 상위 경로다
1339
+ */
1340
+
1341
+ interface DocChunk {
1342
+ /** "c0001" 순번 id — 같은 입력이면 같은 출력 (결정적) */
1343
+ id: string;
1344
+ type: "text" | "table" | "heading";
1345
+ /** 상위 헤딩 + 리스트 위계 경로 (예: ["1. 개요", "가. 목적"]) */
1346
+ breadcrumb: string[];
1347
+ /** 청크 본문 마크다운 — 표는 GFM/HTML 그대로 (blocksToMarkdown 재사용) */
1348
+ text: string;
1349
+ /** 원본 페이지/섹션 번호 (1-based) — IR에 없으면 생략 */
1350
+ page?: number;
1351
+ /** 원본 IRBlock 인덱스 범위 [start, end] (양끝 포함) — 출처 앵커 */
1352
+ blockRange: [number, number];
1353
+ /** 표 청크 전용 구조 요약 — cells는 includeTableCells 옵션 시에만 */
1354
+ table?: {
1355
+ rows: number;
1356
+ cols: number;
1357
+ cells?: string[][];
1358
+ };
1359
+ }
1360
+ interface ChunkOptions {
1361
+ /** 표 청크에 셀 텍스트 행렬 포함 여부 (기본 false) */
1362
+ includeTableCells?: boolean;
1363
+ /**
1364
+ * "section"(기본): 같은 breadcrumb 아래 연속 텍스트 블록을 하나로 병합,
1365
+ * "block": IRBlock 1개 = 청크 1개
1366
+ */
1367
+ granularity?: "block" | "section";
1368
+ }
1369
+ declare function blocksToChunks(blocks: IRBlock[], options?: ChunkOptions): DocChunk[];
1370
+
1263
1371
  /**
1264
1372
  * HWPX 문서 세션 — 에디터 통합용 블록 단위 증분 패치 API (v3.1).
1265
1373
  *
@@ -1556,4 +1664,4 @@ interface FillFormOutput {
1556
1664
  */
1557
1665
  declare function fillForm(input: string | ArrayBuffer | Buffer, values: Record<string, FillInput>, outputFormat?: FillOutputFormat): Promise<FillFormOutput>;
1558
1666
 
1559
- export { type BlockCapability, type BlockCapabilityInfo, type BlockDiff, type BlockEdit, type BlockSourceRef, type BorderDef, type BorderFillDef, type BoundingBox, type CellCapability, type CellContext, type CellDiff, type CellProfile, type CharPrDef, type DiffChangeType, type DiffResult, type DocumentMetadata, type DocumentQualitySummary, type ErrorCode, type ExtractedImage, type FileType, type FillFormOutput, type FillInput, type FillOutputFormat, type FillResult, type FillValue, type FormField, type FormFieldSchema, type FormFieldType, type FormResult, type FormSchemaResult, type FormatProfile, type GongmunFont, type GongmunLintFinding, type GongmunNumbering, type GongmunOptions, type GongmunPreset, type GongmunPresetInput, type HwpxFillResult, HwpxSession, type HwpxTheme, type IRBlock, type IRBlockType, type IRCell, type IRTable, type ImageData, type InlineStyle, type MarkdownToHwpxOptions, type MeasureOptions, type OcrProvider, type OutlineItem, PRESET_ALIAS, type PageMargin, type PageQuality, type ParseFailure, type ParseOptions, type ParseResult, type ParseSuccess, type ParseWarning, type PatchOptions, type PatchResult, type PatchSkip, type PlaceSealResult, type PrintOptions, type PrintPreset, type RenderSvgOptions, type RenderSvgResult, SPACE_EM_FIXED, SPACE_EM_FONT, type ScanCell, type ScanParaKind, type ScanParagraph, type ScanTable, type SealOp, type SealPlacement, type SectionScan, type SpliceEdit, type TRange, type TableProfile, VERSION, type ValidateIssue, type ValidateResult, ValueCursor, type WarningCode, type WatchOptions, type WrapMode, type WrapResult, applySplices, blocksToMarkdown, blocksToPdf, buildParagraphSplices, buildRangeSplices, charWidthEm1000, compare, detectFormat, detectOle2Format, detectZipFormat, diffBlocks, extractFormFields, extractFormSchema, fillForm, fillFormFields, fillHwpx, fillWithUniqueGuard, fitRatioForFewerLines, formatFillValue, gongmunLintWarnings, hwpxToProfile, incompatibleGongmunWarnings, inferFieldType, isHwpxFile, isKnownFont, isLabelCell, isOldHwpFile, isPdfFile, isZipFile, lintGongmunText, markdownToHwpx, markdownToPdf, measureTextWidth, normalizeGongmunPreset, openHwpxDocument, parse, parseDocx, parseHwp, parseHwp3, parseHwpml, parseHwpx, parsePdf, parseXls, parseXlsx, patchHwp, patchHwpx, patchHwpxBlocks, placeSealHwpx, renderHtml, renderHwpxToSvg, scanSectionXml, simulateWrap, simulateWrapKeepWord, unknownFontWarnings, validateHwpx };
1667
+ export { type BlockCapability, type BlockCapabilityInfo, type BlockDiff, type BlockEdit, type BlockSourceRef, type BorderDef, type BorderFillDef, type BoundingBox, type CellCapability, type CellContext, type CellDiff, type CellProfile, type CharPrDef, type ChunkOptions, DEFAULT_REDACT_RULES, type DiffChangeType, type DiffResult, type DocChunk, type DocumentMetadata, type DocumentQualitySummary, type ErrorCode, type ExtractedImage, type FileType, type FillFormOutput, type FillInput, type FillOutputFormat, type FillResult, type FillValue, type FormField, type FormFieldSchema, type FormFieldType, type FormResult, type FormSchemaResult, type FormatProfile, type GongmunFont, type GongmunLintFinding, type GongmunNumbering, type GongmunOptions, type GongmunPreset, type GongmunPresetInput, type HwpxFillResult, HwpxSession, type HwpxTheme, type IRBlock, type IRBlockType, type IRCell, type IRTable, type ImageData, type InlineStyle, type MarkdownToHwpxOptions, type MeasureOptions, type OcrProvider, type OutlineItem, PRESET_ALIAS, type PageMargin, type PageQuality, type ParseFailure, type ParseOptions, type ParseResult, type ParseSuccess, type ParseWarning, type PatchOptions, type PatchResult, type PatchSkip, type PlaceSealResult, type PrintOptions, type PrintPreset, type RedactHit, type RedactOptions, type RedactRule, type RedactTextResult, type RenderSvgOptions, type RenderSvgResult, SPACE_EM_FIXED, SPACE_EM_FONT, type ScanCell, type ScanParaKind, type ScanParagraph, type ScanTable, type SealOp, type SealPlacement, type SectionScan, type SpliceEdit, type TRange, type TableProfile, VERSION, type ValidateIssue, type ValidateResult, ValueCursor, type WarningCode, type WatchOptions, type WrapMode, type WrapResult, applySplices, blocksToChunks, blocksToMarkdown, blocksToPdf, buildParagraphSplices, buildRangeSplices, charWidthEm1000, compare, detectFormat, detectOle2Format, detectZipFormat, diffBlocks, extractFormFields, extractFormSchema, fillForm, fillFormFields, fillHwpx, fillWithUniqueGuard, fitRatioForFewerLines, formatFillValue, gongmunLintWarnings, hwpxToProfile, incompatibleGongmunWarnings, inferFieldType, isHwpxFile, isKnownFont, isLabelCell, isOldHwpFile, isPdfFile, isZipFile, lintGongmunText, markdownToHwpx, markdownToPdf, measureTextWidth, normalizeGongmunPreset, openHwpxDocument, parse, parseDocx, parseHwp, parseHwp3, parseHwpml, parseHwpx, parsePdf, parseXls, parseXlsx, patchHwp, patchHwpx, patchHwpxBlocks, placeSealHwpx, redactMarkdown, redactText, renderHtml, renderHwpxToSvg, scanSectionXml, simulateWrap, simulateWrapKeepWord, unknownFontWarnings, validateHwpx };