@clazic/kordoc 2.1.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.
@@ -0,0 +1,310 @@
1
+ /** kordoc 공통 타입 정의 */
2
+ interface CellContext {
3
+ text: string;
4
+ colSpan: number;
5
+ rowSpan: number;
6
+ /** HWP5 셀 열 주소 (0-based) — 병합 테이블 배치용 */
7
+ colAddr?: number;
8
+ /** HWP5 셀 행 주소 (0-based) — 병합 테이블 배치용 */
9
+ rowAddr?: number;
10
+ }
11
+ /** 블록 타입 — v2.0에서 heading, list, image, separator 추가 */
12
+ type IRBlockType = "paragraph" | "table" | "heading" | "list" | "image" | "separator";
13
+ interface IRBlock {
14
+ type: IRBlockType;
15
+ text?: string;
16
+ table?: IRTable;
17
+ /** 헤딩 레벨 (1-6), type="heading"일 때 사용 */
18
+ level?: number;
19
+ /** 원본 페이지 번호 (1-based) */
20
+ pageNumber?: number;
21
+ /** 바운딩 박스 — PDF에서만 제공 */
22
+ bbox?: BoundingBox;
23
+ /** 텍스트 스타일 정보 (선택) */
24
+ style?: InlineStyle;
25
+ /** 리스트 타입, type="list"일 때 사용 */
26
+ listType?: "ordered" | "unordered";
27
+ /** 중첩 리스트 아이템 */
28
+ children?: IRBlock[];
29
+ /** 하이퍼링크 URL */
30
+ href?: string;
31
+ /** 각주/미주 텍스트 (인라인 삽입용) */
32
+ footnoteText?: string;
33
+ /** 이미지 데이터 (type="image"일 때) */
34
+ imageData?: ImageData;
35
+ }
36
+ /** 추출된 이미지 바이너리 데이터 */
37
+ interface ImageData {
38
+ /** 이미지 바이너리 */
39
+ data: Uint8Array;
40
+ /** MIME 타입 (image/png, image/jpeg, image/gif, image/bmp, image/wmf, image/emf) */
41
+ mimeType: string;
42
+ /** 원본 파일명 (있는 경우) */
43
+ filename?: string;
44
+ }
45
+ /** 바운딩 박스 — PDF 포인트 단위 (72pt = 1인치) */
46
+ interface BoundingBox {
47
+ page: number;
48
+ x: number;
49
+ y: number;
50
+ width: number;
51
+ height: number;
52
+ }
53
+ /** 인라인 텍스트 스타일 */
54
+ interface InlineStyle {
55
+ bold?: boolean;
56
+ italic?: boolean;
57
+ fontSize?: number;
58
+ fontName?: string;
59
+ }
60
+ interface IRTable {
61
+ rows: number;
62
+ cols: number;
63
+ cells: IRCell[][];
64
+ /** 첫 행을 헤더로 렌더링할지 여부 (현재: rows > 1이면 true — 의미적 감지가 아닌 레이아웃 힌트) */
65
+ hasHeader: boolean;
66
+ }
67
+ interface IRCell {
68
+ text: string;
69
+ colSpan: number;
70
+ rowSpan: number;
71
+ }
72
+ /** 문서 메타데이터 — 각 포맷에서 추출 가능한 필드만 채워짐 */
73
+ interface DocumentMetadata {
74
+ /** 문서 제목 */
75
+ title?: string;
76
+ /** 작성자 */
77
+ author?: string;
78
+ /** 작성 프로그램 (예: "한글 2020", "Adobe Acrobat") */
79
+ creator?: string;
80
+ /** 생성일시 (ISO 8601) */
81
+ createdAt?: string;
82
+ /** 수정일시 (ISO 8601) */
83
+ modifiedAt?: string;
84
+ /** 페이지/섹션 수 */
85
+ pageCount?: number;
86
+ /** 문서 포맷 버전 (예: HWP "5.1.0.1") */
87
+ version?: string;
88
+ /** 설명 */
89
+ description?: string;
90
+ /** 키워드 */
91
+ keywords?: string[];
92
+ }
93
+ /** 파싱 옵션 — parse() 함수에 전달 */
94
+ interface ParseOptions {
95
+ /**
96
+ * 파싱할 페이지/섹션 범위 (1-based).
97
+ * - 배열: [1, 2, 3]
98
+ * - 문자열: "1-3", "1,3,5-7"
99
+ *
100
+ * PDF: 정확한 페이지 단위. HWP/HWPX: 섹션 단위 근사치.
101
+ */
102
+ pages?: number[] | string;
103
+ /** 이미지 기반 PDF용 OCR 프로바이더 (선택) */
104
+ ocr?: OcrProvider;
105
+ /** 진행률 콜백 — current: 현재 페이지/섹션, total: 전체 수 */
106
+ onProgress?: (current: number, total: number) => void;
107
+ /** PDF 머리글/바닥글 자동 제거 */
108
+ removeHeaderFooter?: boolean;
109
+ }
110
+ /** 파싱 중 스킵/실패한 요소 보고 */
111
+ interface ParseWarning {
112
+ /** 관련 페이지 번호 (알 수 있는 경우) */
113
+ page?: number;
114
+ /** 경고 메시지 */
115
+ message: string;
116
+ /** 구조화된 경고 코드 */
117
+ code: WarningCode;
118
+ }
119
+ 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";
120
+ /** 문서 구조 (헤딩 트리) */
121
+ interface OutlineItem {
122
+ level: number;
123
+ text: string;
124
+ pageNumber?: number;
125
+ }
126
+ /** 구조화된 에러 코드 — 프로그래밍적 에러 핸들링용 */
127
+ type ErrorCode = "EMPTY_INPUT" | "UNSUPPORTED_FORMAT" | "ENCRYPTED" | "DRM_PROTECTED" | "CORRUPTED" | "DECOMPRESSION_BOMB" | "ZIP_BOMB" | "IMAGE_BASED_PDF" | "NO_SECTIONS" | "PARSE_ERROR";
128
+ type FileType = "hwpx" | "hwp" | "pdf" | "xlsx" | "docx" | "unknown";
129
+ interface ParseResultBase {
130
+ fileType: FileType;
131
+ /** 페이지/섹션 수 — PDF: 실제 페이지 수, HWP/HWPX: 섹션 수, XLSX: 시트 수 */
132
+ pageCount?: number;
133
+ /** 이미지 기반 PDF 여부 (텍스트 추출 불가) */
134
+ isImageBased?: boolean;
135
+ }
136
+ interface ParseSuccess extends ParseResultBase {
137
+ success: true;
138
+ /** 추출된 마크다운 텍스트 */
139
+ markdown: string;
140
+ /** 중간 표현 블록 (구조화된 데이터 접근용) */
141
+ blocks: IRBlock[];
142
+ /** 문서 메타데이터 */
143
+ metadata?: DocumentMetadata;
144
+ /** 문서 구조 (헤딩 트리) — v2.0 */
145
+ outline?: OutlineItem[];
146
+ /** 파싱 중 발생한 경고 — v2.0 */
147
+ warnings?: ParseWarning[];
148
+ /** 추출된 이미지 목록 — 마크다운에서 파일명으로 참조됨 */
149
+ images?: ExtractedImage[];
150
+ }
151
+ /** 추출된 이미지 — ParseSuccess.images에 포함 */
152
+ interface ExtractedImage {
153
+ /** 마크다운에서 참조되는 파일명 (예: image_001.png) */
154
+ filename: string;
155
+ /** 이미지 바이너리 */
156
+ data: Uint8Array;
157
+ /** MIME 타입 */
158
+ mimeType: string;
159
+ }
160
+ interface ParseFailure extends ParseResultBase {
161
+ success: false;
162
+ /** 오류 메시지 */
163
+ error: string;
164
+ /** 구조화된 에러 코드 */
165
+ code?: ErrorCode;
166
+ }
167
+ type ParseResult = ParseSuccess | ParseFailure;
168
+ type DiffChangeType = "added" | "removed" | "modified" | "unchanged";
169
+ interface BlockDiff {
170
+ type: DiffChangeType;
171
+ /** 원본 블록 (added이면 undefined) */
172
+ before?: IRBlock;
173
+ /** 변경 후 블록 (removed이면 undefined) */
174
+ after?: IRBlock;
175
+ /** modified 테이블의 셀 단위 diff */
176
+ cellDiffs?: CellDiff[][];
177
+ /** 유사도 (0-1) */
178
+ similarity?: number;
179
+ }
180
+ interface CellDiff {
181
+ type: DiffChangeType;
182
+ before?: string;
183
+ after?: string;
184
+ }
185
+ interface DiffResult {
186
+ stats: {
187
+ added: number;
188
+ removed: number;
189
+ modified: number;
190
+ unchanged: number;
191
+ };
192
+ diffs: BlockDiff[];
193
+ }
194
+ interface FormField {
195
+ label: string;
196
+ value: string;
197
+ /** 0-based 소스 행 */
198
+ row: number;
199
+ /** 0-based 소스 열 */
200
+ col: number;
201
+ }
202
+ interface FormResult {
203
+ fields: FormField[];
204
+ /** 양식 확신도 (0-1) */
205
+ confidence: number;
206
+ }
207
+ /** 사용자 제공 OCR 함수 — 페이지 이미지를 받아 텍스트 반환 */
208
+ type OcrProvider = (pageImage: Uint8Array, pageNumber: number, mimeType: "image/png") => Promise<string>;
209
+ interface WatchOptions {
210
+ dir: string;
211
+ outDir?: string;
212
+ webhook?: string;
213
+ format?: "markdown" | "json";
214
+ pages?: string;
215
+ silent?: boolean;
216
+ }
217
+
218
+ /** 문서 비교 엔진 — IR 레벨 블록 비교로 신구대조표 생성 */
219
+
220
+ /**
221
+ * 두 문서를 비교하여 블록 단위 diff 생성.
222
+ * 크로스 포맷 지원 — HWP vs HWPX 비교 가능 (IR 레벨).
223
+ */
224
+ declare function compare(bufferA: ArrayBuffer, bufferB: ArrayBuffer, options?: ParseOptions): Promise<DiffResult>;
225
+ /** IRBlock[] 간 diff — LCS 기반 정렬 */
226
+ declare function diffBlocks(blocksA: IRBlock[], blocksB: IRBlock[]): DiffResult;
227
+
228
+ /** 양식(서식) 필드 인식 — 테이블 기반 label-value 패턴 매칭 */
229
+
230
+ /**
231
+ * IRBlock[]에서 양식 필드를 인식하여 추출.
232
+ * 테이블의 label-value 패턴을 감지.
233
+ */
234
+ declare function extractFormFields(blocks: IRBlock[]): FormResult;
235
+
236
+ /**
237
+ * Markdown → HWPX 역변환
238
+ *
239
+ * 지원: 단락, 헤딩(1-6), 테이블, 목록(ul/ol), 볼드/이탤릭 인라인, 코드
240
+ * hwpxskill 검증 템플릿 기반 — 실제 한/글과 동일한 파일 구조 사용
241
+ */
242
+
243
+ interface MarkdownToHwpxOptions {
244
+ templateArrayBuffer?: ArrayBuffer;
245
+ warnings?: string[];
246
+ images?: ExtractedImage[];
247
+ }
248
+ /**
249
+ * 마크다운 텍스트를 HWPX (ArrayBuffer)로 변환.
250
+ * @param markdown 마크다운 텍스트
251
+ * @param options 템플릿, 경고 수집 등
252
+ */
253
+ declare function markdownToHwpx(markdown: string, options?: MarkdownToHwpxOptions | ArrayBuffer): Promise<ArrayBuffer>;
254
+
255
+ /** 매직 바이트 기반 파일 포맷 감지 */
256
+
257
+ /** ZIP 파일 여부: PK\x03\x04 */
258
+ declare function isZipFile(buffer: ArrayBuffer): boolean;
259
+ /** HWPX (ZIP 기반 한컴 문서): PK\x03\x04 — 하위 호환용 */
260
+ declare function isHwpxFile(buffer: ArrayBuffer): boolean;
261
+ /** HWP 5.x (OLE2 바이너리 한컴 문서): \xD0\xCF\x11\xE0 */
262
+ declare function isOldHwpFile(buffer: ArrayBuffer): boolean;
263
+ /** PDF 문서: %PDF */
264
+ declare function isPdfFile(buffer: ArrayBuffer): boolean;
265
+ /** 동기 포맷 감지 — ZIP은 모두 "hwpx"로 반환 (하위 호환) */
266
+ declare function detectFormat(buffer: ArrayBuffer): FileType;
267
+ /**
268
+ * ZIP 내부 구조 기반 포맷 세분화.
269
+ * HWPX, XLSX, DOCX 모두 ZIP이므로 내부 파일로 구분.
270
+ */
271
+ declare function detectZipFormat(buffer: ArrayBuffer): Promise<"hwpx" | "xlsx" | "docx" | "unknown">;
272
+
273
+ /** 2-pass colSpan/rowSpan 테이블 빌더 및 Markdown 변환 */
274
+
275
+ declare function blocksToMarkdown(blocks: IRBlock[]): string;
276
+
277
+ /** kordoc 공용 유틸리티 */
278
+ declare const VERSION: string;
279
+
280
+ /**
281
+ * kordoc — 모두 파싱해버리겠다
282
+ *
283
+ * HWP, HWPX, PDF → Markdown 변환 통합 라이브러리
284
+ */
285
+
286
+ /**
287
+ * 파일 버퍼를 자동 감지하여 Markdown으로 변환
288
+ *
289
+ * @example
290
+ * ```ts
291
+ * import { parse } from "kordoc"
292
+ * // 파일 경로로 파싱
293
+ * const result = await parse("document.hwp")
294
+ * // 또는 Buffer로 파싱
295
+ * const result = await parse(buffer)
296
+ * ```
297
+ */
298
+ declare function parse(input: string | ArrayBuffer | Buffer, options?: ParseOptions): Promise<ParseResult>;
299
+ /** HWPX 파일을 Markdown으로 변환 */
300
+ declare function parseHwpx(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
301
+ /** HWP 5.x 바이너리 파일을 Markdown으로 변환 */
302
+ declare function parseHwp(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
303
+ /** PDF 파일에서 텍스트를 추출하여 Markdown으로 변환 */
304
+ declare function parsePdf(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
305
+ /** XLSX 파일을 Markdown으로 변환 */
306
+ declare function parseXlsx(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
307
+ /** DOCX 파일을 Markdown으로 변환 */
308
+ declare function parseDocx(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
309
+
310
+ export { type BlockDiff, type BoundingBox, type CellContext, type CellDiff, type DiffChangeType, type DiffResult, type DocumentMetadata, type ErrorCode, type ExtractedImage, type FileType, type FormField, type FormResult, type IRBlock, type IRBlockType, type IRCell, type IRTable, type ImageData, type InlineStyle, type OcrProvider, type OutlineItem, type ParseFailure, type ParseOptions, type ParseResult, type ParseSuccess, type ParseWarning, VERSION, type WarningCode, type WatchOptions, blocksToMarkdown, compare, detectFormat, detectZipFormat, diffBlocks, extractFormFields, isHwpxFile, isOldHwpFile, isPdfFile, isZipFile, markdownToHwpx, parse, parseDocx, parseHwp, parseHwpx, parsePdf, parseXlsx };
@@ -0,0 +1,310 @@
1
+ /** kordoc 공통 타입 정의 */
2
+ interface CellContext {
3
+ text: string;
4
+ colSpan: number;
5
+ rowSpan: number;
6
+ /** HWP5 셀 열 주소 (0-based) — 병합 테이블 배치용 */
7
+ colAddr?: number;
8
+ /** HWP5 셀 행 주소 (0-based) — 병합 테이블 배치용 */
9
+ rowAddr?: number;
10
+ }
11
+ /** 블록 타입 — v2.0에서 heading, list, image, separator 추가 */
12
+ type IRBlockType = "paragraph" | "table" | "heading" | "list" | "image" | "separator";
13
+ interface IRBlock {
14
+ type: IRBlockType;
15
+ text?: string;
16
+ table?: IRTable;
17
+ /** 헤딩 레벨 (1-6), type="heading"일 때 사용 */
18
+ level?: number;
19
+ /** 원본 페이지 번호 (1-based) */
20
+ pageNumber?: number;
21
+ /** 바운딩 박스 — PDF에서만 제공 */
22
+ bbox?: BoundingBox;
23
+ /** 텍스트 스타일 정보 (선택) */
24
+ style?: InlineStyle;
25
+ /** 리스트 타입, type="list"일 때 사용 */
26
+ listType?: "ordered" | "unordered";
27
+ /** 중첩 리스트 아이템 */
28
+ children?: IRBlock[];
29
+ /** 하이퍼링크 URL */
30
+ href?: string;
31
+ /** 각주/미주 텍스트 (인라인 삽입용) */
32
+ footnoteText?: string;
33
+ /** 이미지 데이터 (type="image"일 때) */
34
+ imageData?: ImageData;
35
+ }
36
+ /** 추출된 이미지 바이너리 데이터 */
37
+ interface ImageData {
38
+ /** 이미지 바이너리 */
39
+ data: Uint8Array;
40
+ /** MIME 타입 (image/png, image/jpeg, image/gif, image/bmp, image/wmf, image/emf) */
41
+ mimeType: string;
42
+ /** 원본 파일명 (있는 경우) */
43
+ filename?: string;
44
+ }
45
+ /** 바운딩 박스 — PDF 포인트 단위 (72pt = 1인치) */
46
+ interface BoundingBox {
47
+ page: number;
48
+ x: number;
49
+ y: number;
50
+ width: number;
51
+ height: number;
52
+ }
53
+ /** 인라인 텍스트 스타일 */
54
+ interface InlineStyle {
55
+ bold?: boolean;
56
+ italic?: boolean;
57
+ fontSize?: number;
58
+ fontName?: string;
59
+ }
60
+ interface IRTable {
61
+ rows: number;
62
+ cols: number;
63
+ cells: IRCell[][];
64
+ /** 첫 행을 헤더로 렌더링할지 여부 (현재: rows > 1이면 true — 의미적 감지가 아닌 레이아웃 힌트) */
65
+ hasHeader: boolean;
66
+ }
67
+ interface IRCell {
68
+ text: string;
69
+ colSpan: number;
70
+ rowSpan: number;
71
+ }
72
+ /** 문서 메타데이터 — 각 포맷에서 추출 가능한 필드만 채워짐 */
73
+ interface DocumentMetadata {
74
+ /** 문서 제목 */
75
+ title?: string;
76
+ /** 작성자 */
77
+ author?: string;
78
+ /** 작성 프로그램 (예: "한글 2020", "Adobe Acrobat") */
79
+ creator?: string;
80
+ /** 생성일시 (ISO 8601) */
81
+ createdAt?: string;
82
+ /** 수정일시 (ISO 8601) */
83
+ modifiedAt?: string;
84
+ /** 페이지/섹션 수 */
85
+ pageCount?: number;
86
+ /** 문서 포맷 버전 (예: HWP "5.1.0.1") */
87
+ version?: string;
88
+ /** 설명 */
89
+ description?: string;
90
+ /** 키워드 */
91
+ keywords?: string[];
92
+ }
93
+ /** 파싱 옵션 — parse() 함수에 전달 */
94
+ interface ParseOptions {
95
+ /**
96
+ * 파싱할 페이지/섹션 범위 (1-based).
97
+ * - 배열: [1, 2, 3]
98
+ * - 문자열: "1-3", "1,3,5-7"
99
+ *
100
+ * PDF: 정확한 페이지 단위. HWP/HWPX: 섹션 단위 근사치.
101
+ */
102
+ pages?: number[] | string;
103
+ /** 이미지 기반 PDF용 OCR 프로바이더 (선택) */
104
+ ocr?: OcrProvider;
105
+ /** 진행률 콜백 — current: 현재 페이지/섹션, total: 전체 수 */
106
+ onProgress?: (current: number, total: number) => void;
107
+ /** PDF 머리글/바닥글 자동 제거 */
108
+ removeHeaderFooter?: boolean;
109
+ }
110
+ /** 파싱 중 스킵/실패한 요소 보고 */
111
+ interface ParseWarning {
112
+ /** 관련 페이지 번호 (알 수 있는 경우) */
113
+ page?: number;
114
+ /** 경고 메시지 */
115
+ message: string;
116
+ /** 구조화된 경고 코드 */
117
+ code: WarningCode;
118
+ }
119
+ 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";
120
+ /** 문서 구조 (헤딩 트리) */
121
+ interface OutlineItem {
122
+ level: number;
123
+ text: string;
124
+ pageNumber?: number;
125
+ }
126
+ /** 구조화된 에러 코드 — 프로그래밍적 에러 핸들링용 */
127
+ type ErrorCode = "EMPTY_INPUT" | "UNSUPPORTED_FORMAT" | "ENCRYPTED" | "DRM_PROTECTED" | "CORRUPTED" | "DECOMPRESSION_BOMB" | "ZIP_BOMB" | "IMAGE_BASED_PDF" | "NO_SECTIONS" | "PARSE_ERROR";
128
+ type FileType = "hwpx" | "hwp" | "pdf" | "xlsx" | "docx" | "unknown";
129
+ interface ParseResultBase {
130
+ fileType: FileType;
131
+ /** 페이지/섹션 수 — PDF: 실제 페이지 수, HWP/HWPX: 섹션 수, XLSX: 시트 수 */
132
+ pageCount?: number;
133
+ /** 이미지 기반 PDF 여부 (텍스트 추출 불가) */
134
+ isImageBased?: boolean;
135
+ }
136
+ interface ParseSuccess extends ParseResultBase {
137
+ success: true;
138
+ /** 추출된 마크다운 텍스트 */
139
+ markdown: string;
140
+ /** 중간 표현 블록 (구조화된 데이터 접근용) */
141
+ blocks: IRBlock[];
142
+ /** 문서 메타데이터 */
143
+ metadata?: DocumentMetadata;
144
+ /** 문서 구조 (헤딩 트리) — v2.0 */
145
+ outline?: OutlineItem[];
146
+ /** 파싱 중 발생한 경고 — v2.0 */
147
+ warnings?: ParseWarning[];
148
+ /** 추출된 이미지 목록 — 마크다운에서 파일명으로 참조됨 */
149
+ images?: ExtractedImage[];
150
+ }
151
+ /** 추출된 이미지 — ParseSuccess.images에 포함 */
152
+ interface ExtractedImage {
153
+ /** 마크다운에서 참조되는 파일명 (예: image_001.png) */
154
+ filename: string;
155
+ /** 이미지 바이너리 */
156
+ data: Uint8Array;
157
+ /** MIME 타입 */
158
+ mimeType: string;
159
+ }
160
+ interface ParseFailure extends ParseResultBase {
161
+ success: false;
162
+ /** 오류 메시지 */
163
+ error: string;
164
+ /** 구조화된 에러 코드 */
165
+ code?: ErrorCode;
166
+ }
167
+ type ParseResult = ParseSuccess | ParseFailure;
168
+ type DiffChangeType = "added" | "removed" | "modified" | "unchanged";
169
+ interface BlockDiff {
170
+ type: DiffChangeType;
171
+ /** 원본 블록 (added이면 undefined) */
172
+ before?: IRBlock;
173
+ /** 변경 후 블록 (removed이면 undefined) */
174
+ after?: IRBlock;
175
+ /** modified 테이블의 셀 단위 diff */
176
+ cellDiffs?: CellDiff[][];
177
+ /** 유사도 (0-1) */
178
+ similarity?: number;
179
+ }
180
+ interface CellDiff {
181
+ type: DiffChangeType;
182
+ before?: string;
183
+ after?: string;
184
+ }
185
+ interface DiffResult {
186
+ stats: {
187
+ added: number;
188
+ removed: number;
189
+ modified: number;
190
+ unchanged: number;
191
+ };
192
+ diffs: BlockDiff[];
193
+ }
194
+ interface FormField {
195
+ label: string;
196
+ value: string;
197
+ /** 0-based 소스 행 */
198
+ row: number;
199
+ /** 0-based 소스 열 */
200
+ col: number;
201
+ }
202
+ interface FormResult {
203
+ fields: FormField[];
204
+ /** 양식 확신도 (0-1) */
205
+ confidence: number;
206
+ }
207
+ /** 사용자 제공 OCR 함수 — 페이지 이미지를 받아 텍스트 반환 */
208
+ type OcrProvider = (pageImage: Uint8Array, pageNumber: number, mimeType: "image/png") => Promise<string>;
209
+ interface WatchOptions {
210
+ dir: string;
211
+ outDir?: string;
212
+ webhook?: string;
213
+ format?: "markdown" | "json";
214
+ pages?: string;
215
+ silent?: boolean;
216
+ }
217
+
218
+ /** 문서 비교 엔진 — IR 레벨 블록 비교로 신구대조표 생성 */
219
+
220
+ /**
221
+ * 두 문서를 비교하여 블록 단위 diff 생성.
222
+ * 크로스 포맷 지원 — HWP vs HWPX 비교 가능 (IR 레벨).
223
+ */
224
+ declare function compare(bufferA: ArrayBuffer, bufferB: ArrayBuffer, options?: ParseOptions): Promise<DiffResult>;
225
+ /** IRBlock[] 간 diff — LCS 기반 정렬 */
226
+ declare function diffBlocks(blocksA: IRBlock[], blocksB: IRBlock[]): DiffResult;
227
+
228
+ /** 양식(서식) 필드 인식 — 테이블 기반 label-value 패턴 매칭 */
229
+
230
+ /**
231
+ * IRBlock[]에서 양식 필드를 인식하여 추출.
232
+ * 테이블의 label-value 패턴을 감지.
233
+ */
234
+ declare function extractFormFields(blocks: IRBlock[]): FormResult;
235
+
236
+ /**
237
+ * Markdown → HWPX 역변환
238
+ *
239
+ * 지원: 단락, 헤딩(1-6), 테이블, 목록(ul/ol), 볼드/이탤릭 인라인, 코드
240
+ * hwpxskill 검증 템플릿 기반 — 실제 한/글과 동일한 파일 구조 사용
241
+ */
242
+
243
+ interface MarkdownToHwpxOptions {
244
+ templateArrayBuffer?: ArrayBuffer;
245
+ warnings?: string[];
246
+ images?: ExtractedImage[];
247
+ }
248
+ /**
249
+ * 마크다운 텍스트를 HWPX (ArrayBuffer)로 변환.
250
+ * @param markdown 마크다운 텍스트
251
+ * @param options 템플릿, 경고 수집 등
252
+ */
253
+ declare function markdownToHwpx(markdown: string, options?: MarkdownToHwpxOptions | ArrayBuffer): Promise<ArrayBuffer>;
254
+
255
+ /** 매직 바이트 기반 파일 포맷 감지 */
256
+
257
+ /** ZIP 파일 여부: PK\x03\x04 */
258
+ declare function isZipFile(buffer: ArrayBuffer): boolean;
259
+ /** HWPX (ZIP 기반 한컴 문서): PK\x03\x04 — 하위 호환용 */
260
+ declare function isHwpxFile(buffer: ArrayBuffer): boolean;
261
+ /** HWP 5.x (OLE2 바이너리 한컴 문서): \xD0\xCF\x11\xE0 */
262
+ declare function isOldHwpFile(buffer: ArrayBuffer): boolean;
263
+ /** PDF 문서: %PDF */
264
+ declare function isPdfFile(buffer: ArrayBuffer): boolean;
265
+ /** 동기 포맷 감지 — ZIP은 모두 "hwpx"로 반환 (하위 호환) */
266
+ declare function detectFormat(buffer: ArrayBuffer): FileType;
267
+ /**
268
+ * ZIP 내부 구조 기반 포맷 세분화.
269
+ * HWPX, XLSX, DOCX 모두 ZIP이므로 내부 파일로 구분.
270
+ */
271
+ declare function detectZipFormat(buffer: ArrayBuffer): Promise<"hwpx" | "xlsx" | "docx" | "unknown">;
272
+
273
+ /** 2-pass colSpan/rowSpan 테이블 빌더 및 Markdown 변환 */
274
+
275
+ declare function blocksToMarkdown(blocks: IRBlock[]): string;
276
+
277
+ /** kordoc 공용 유틸리티 */
278
+ declare const VERSION: string;
279
+
280
+ /**
281
+ * kordoc — 모두 파싱해버리겠다
282
+ *
283
+ * HWP, HWPX, PDF → Markdown 변환 통합 라이브러리
284
+ */
285
+
286
+ /**
287
+ * 파일 버퍼를 자동 감지하여 Markdown으로 변환
288
+ *
289
+ * @example
290
+ * ```ts
291
+ * import { parse } from "kordoc"
292
+ * // 파일 경로로 파싱
293
+ * const result = await parse("document.hwp")
294
+ * // 또는 Buffer로 파싱
295
+ * const result = await parse(buffer)
296
+ * ```
297
+ */
298
+ declare function parse(input: string | ArrayBuffer | Buffer, options?: ParseOptions): Promise<ParseResult>;
299
+ /** HWPX 파일을 Markdown으로 변환 */
300
+ declare function parseHwpx(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
301
+ /** HWP 5.x 바이너리 파일을 Markdown으로 변환 */
302
+ declare function parseHwp(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
303
+ /** PDF 파일에서 텍스트를 추출하여 Markdown으로 변환 */
304
+ declare function parsePdf(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
305
+ /** XLSX 파일을 Markdown으로 변환 */
306
+ declare function parseXlsx(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
307
+ /** DOCX 파일을 Markdown으로 변환 */
308
+ declare function parseDocx(buffer: ArrayBuffer, options?: ParseOptions): Promise<ParseResult>;
309
+
310
+ export { type BlockDiff, type BoundingBox, type CellContext, type CellDiff, type DiffChangeType, type DiffResult, type DocumentMetadata, type ErrorCode, type ExtractedImage, type FileType, type FormField, type FormResult, type IRBlock, type IRBlockType, type IRCell, type IRTable, type ImageData, type InlineStyle, type OcrProvider, type OutlineItem, type ParseFailure, type ParseOptions, type ParseResult, type ParseSuccess, type ParseWarning, VERSION, type WarningCode, type WatchOptions, blocksToMarkdown, compare, detectFormat, detectZipFormat, diffBlocks, extractFormFields, isHwpxFile, isOldHwpFile, isPdfFile, isZipFile, markdownToHwpx, parse, parseDocx, parseHwp, parseHwpx, parsePdf, parseXlsx };