hwpkit-dev 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,317 @@
1
+ type Align = 'left' | 'center' | 'right' | 'justify';
2
+ type VAlign = 'top' | 'mid' | 'bot';
3
+ type Heading = 1 | 2 | 3 | 4 | 5 | 6;
4
+ type StrokeKind = 'solid' | 'dash' | 'dot' | 'double' | 'none';
5
+ interface TextProps {
6
+ b?: boolean;
7
+ i?: boolean;
8
+ u?: boolean;
9
+ s?: boolean;
10
+ sup?: boolean;
11
+ sub?: boolean;
12
+ font?: string;
13
+ pt?: number;
14
+ color?: string;
15
+ bg?: string;
16
+ }
17
+ interface ParaProps {
18
+ align?: Align;
19
+ heading?: Heading;
20
+ indentPt?: number;
21
+ spaceBefore?: number;
22
+ spaceAfter?: number;
23
+ lineHeight?: number;
24
+ listLv?: number;
25
+ listOrd?: boolean;
26
+ listMark?: string;
27
+ }
28
+ interface Stroke {
29
+ kind: StrokeKind;
30
+ pt: number;
31
+ color: string;
32
+ }
33
+ interface CellProps {
34
+ top?: Stroke;
35
+ bot?: Stroke;
36
+ left?: Stroke;
37
+ right?: Stroke;
38
+ bg?: string;
39
+ padPt?: number;
40
+ align?: Align;
41
+ va?: VAlign;
42
+ isHeader?: boolean;
43
+ }
44
+ interface TableLook {
45
+ firstRow?: boolean;
46
+ lastRow?: boolean;
47
+ firstCol?: boolean;
48
+ lastCol?: boolean;
49
+ bandedRows?: boolean;
50
+ bandedCols?: boolean;
51
+ }
52
+ interface GridProps {
53
+ widthPct?: number;
54
+ colWidths?: number[];
55
+ defaultStroke?: Stroke;
56
+ look?: TableLook;
57
+ headerRow?: boolean;
58
+ }
59
+ interface PageDims {
60
+ wPt: number;
61
+ hPt: number;
62
+ mt: number;
63
+ mb: number;
64
+ ml: number;
65
+ mr: number;
66
+ orient?: 'portrait' | 'landscape';
67
+ }
68
+ interface DocMeta {
69
+ title?: string;
70
+ author?: string;
71
+ subject?: string;
72
+ desc?: string;
73
+ keywords?: string;
74
+ created?: string;
75
+ modified?: string;
76
+ }
77
+ declare const A4: PageDims;
78
+ declare const A4_LANDSCAPE: PageDims;
79
+ declare function normalizeDims(dims: PageDims): PageDims;
80
+ declare const DEFAULT_STROKE: Stroke;
81
+
82
+ type BlockTag = 'root' | 'sheet' | 'para' | 'span' | 'txt' | 'img' | 'link' | 'grid' | 'row' | 'cell' | 'br' | 'pb' | 'pagenum';
83
+ interface TxtNode {
84
+ tag: 'txt';
85
+ content: string;
86
+ }
87
+ interface BrNode {
88
+ tag: 'br';
89
+ }
90
+ interface PbNode {
91
+ tag: 'pb';
92
+ }
93
+ interface PageNumNode {
94
+ tag: 'pagenum';
95
+ format?: 'decimal' | 'roman' | 'romanCaps';
96
+ }
97
+ interface ImgNode {
98
+ tag: 'img';
99
+ b64: string;
100
+ mime: 'image/png' | 'image/jpeg' | 'image/gif' | 'image/bmp';
101
+ w: number;
102
+ h: number;
103
+ alt?: string;
104
+ }
105
+ interface SpanNode {
106
+ tag: 'span';
107
+ props: TextProps;
108
+ kids: (TxtNode | BrNode | PbNode | PageNumNode)[];
109
+ }
110
+ interface LinkNode {
111
+ tag: 'link';
112
+ href: string;
113
+ kids: SpanNode[];
114
+ }
115
+ interface ParaNode {
116
+ tag: 'para';
117
+ props: ParaProps;
118
+ kids: (SpanNode | ImgNode | LinkNode)[];
119
+ }
120
+ interface CellNode {
121
+ tag: 'cell';
122
+ cs: number;
123
+ rs: number;
124
+ props: CellProps;
125
+ kids: ParaNode[];
126
+ }
127
+ interface RowNode {
128
+ tag: 'row';
129
+ kids: CellNode[];
130
+ }
131
+ interface GridNode {
132
+ tag: 'grid';
133
+ props: GridProps;
134
+ kids: RowNode[];
135
+ }
136
+ type ContentNode = ParaNode | GridNode;
137
+ interface SheetNode {
138
+ tag: 'sheet';
139
+ dims: PageDims;
140
+ kids: ContentNode[];
141
+ header?: ParaNode[];
142
+ footer?: ParaNode[];
143
+ }
144
+ interface DocRoot {
145
+ tag: 'root';
146
+ meta: DocMeta;
147
+ kids: SheetNode[];
148
+ }
149
+ type AnyNode = DocRoot | SheetNode | ParaNode | SpanNode | TxtNode | ImgNode | LinkNode | GridNode | RowNode | CellNode | BrNode | PbNode | PageNumNode;
150
+
151
+ type Outcome<T> = Ok<T> | Fail;
152
+ interface Ok<T> {
153
+ ok: true;
154
+ data: T;
155
+ warns: string[];
156
+ }
157
+ interface Fail {
158
+ ok: false;
159
+ error: string;
160
+ warns: string[];
161
+ }
162
+ declare function succeed<T>(data: T, warns?: string[]): Ok<T>;
163
+ declare function fail(error: string, warns?: string[]): Fail;
164
+
165
+ interface Decoder {
166
+ readonly format: string;
167
+ decode(data: Uint8Array): Promise<Outcome<DocRoot>>;
168
+ }
169
+
170
+ interface Encoder {
171
+ readonly format: string;
172
+ encode(doc: DocRoot): Promise<Outcome<Uint8Array>>;
173
+ }
174
+
175
+ declare class Pipeline {
176
+ private raw;
177
+ private srcFmt;
178
+ private constructor();
179
+ /** 파일을 열고 포맷을 자동 감지하거나 명시 */
180
+ static open(input: Uint8Array | string, fmt?: string): Pipeline;
181
+ /** File/Blob 비동기 입력 */
182
+ static openAsync(input: File | Blob | Uint8Array | string, fmt?: string): Promise<Pipeline>;
183
+ /** 목표 포맷으로 변환 */
184
+ to(targetFmt: string): Promise<Outcome<Uint8Array>>;
185
+ /** DocRoot만 추출 (인코딩 없이) */
186
+ inspect(): Promise<Outcome<DocRoot>>;
187
+ }
188
+
189
+ declare class FormatRegistry {
190
+ private decoders;
191
+ private encoders;
192
+ registerDecoder(d: Decoder): void;
193
+ registerEncoder(e: Encoder): void;
194
+ getDecoder(fmt: string): Decoder | undefined;
195
+ getEncoder(fmt: string): Encoder | undefined;
196
+ supportedInputs(): string[];
197
+ supportedOutputs(): string[];
198
+ }
199
+ declare const registry: FormatRegistry;
200
+
201
+ declare function buildRoot(meta?: DocMeta, kids?: SheetNode[]): DocRoot;
202
+ declare function buildSheet(kids?: ContentNode[], dims?: PageDims, opts?: {
203
+ header?: ParaNode[];
204
+ footer?: ParaNode[];
205
+ }): SheetNode;
206
+ declare function buildPageNum(format?: PageNumNode['format']): PageNumNode;
207
+ declare function buildBr(): BrNode;
208
+ declare function buildPb(): PbNode;
209
+ declare function buildPara(kids?: ParaNode['kids'], props?: ParaProps): ParaNode;
210
+ declare function buildSpan(content: string, props?: TextProps): SpanNode;
211
+ declare function buildImg(b64: string, mime: ImgNode['mime'], w: number, h: number, alt?: string): ImgNode;
212
+ declare function buildGrid(kids: RowNode[], props?: GridProps): GridNode;
213
+ declare function buildRow(kids: CellNode[]): RowNode;
214
+ declare function buildCell(kids: ParaNode[], opts?: {
215
+ cs?: number;
216
+ rs?: number;
217
+ props?: CellProps;
218
+ }): CellNode;
219
+
220
+ declare class ShieldedParser {
221
+ private log;
222
+ /** 단일 요소 안전 파싱 */
223
+ guard<T>(fn: () => T, fallback: T, label: string): T;
224
+ /** 배열 각 요소 독립 파싱 (하나 실패해도 나머지 계속) */
225
+ guardAll<I, O>(items: I[], fn: (x: I, i: number) => O, fb: (x: I, i: number) => O, label: string): O[];
226
+ /**
227
+ * 표 전용 4단계 폴백
228
+ * Lv1: Full → Lv2: Grid → Lv3: Flat → Lv4: Text
229
+ */
230
+ guardGrid<T>(node: unknown, lv1Full: (n: unknown) => T, lv2Grid: (n: unknown) => T, lv3Flat: (n: unknown) => T, lv4Text: (n: unknown) => T, label: string): {
231
+ value: T;
232
+ level: 1 | 2 | 3 | 4;
233
+ };
234
+ /** 이미지 안전 파싱 */
235
+ guardImg<T>(node: unknown, fn: (n: unknown) => T, placeholder: (alt: string) => T, label: string): T;
236
+ private warn;
237
+ flush(): string[];
238
+ }
239
+
240
+ declare const Metric: {
241
+ readonly hwpToPt: (v: number) => number;
242
+ readonly ptToHwp: (v: number) => number;
243
+ readonly hwpToDxa: (v: number) => number;
244
+ readonly dxaToHwp: (v: number) => number;
245
+ readonly hwpToEmu: (v: number) => number;
246
+ readonly emuToHwp: (v: number) => number;
247
+ readonly dxaToPt: (v: number) => number;
248
+ readonly ptToDxa: (v: number) => number;
249
+ readonly dxaToEmu: (v: number) => number;
250
+ readonly emuToDxa: (v: number) => number;
251
+ readonly emuToPt: (v: number) => number;
252
+ readonly ptToEmu: (v: number) => number;
253
+ readonly hHeightToPt: (v: number) => number;
254
+ readonly ptToHHeight: (v: number) => number;
255
+ readonly halfPtToPt: (v: number) => number;
256
+ readonly ptToHalfPt: (v: number) => number;
257
+ };
258
+ declare function safeHex(raw: string | number | null | undefined): string | undefined;
259
+ declare function safeAlign(raw?: string): Align;
260
+ declare function safeStrokeHwpx(type?: string, w?: number, c?: string): Stroke;
261
+ declare function safeStrokeDocx(val?: string, sz?: number, c?: string): Stroke;
262
+ declare function safeFont(raw?: string): string;
263
+ declare function safeFontToKr(raw?: string): string;
264
+
265
+ type WalkCallback = (node: AnyNode, parent: AnyNode | null, depth: number) => void | 'stop';
266
+ declare function walkNode(node: AnyNode, cb: WalkCallback, parent?: AnyNode | null, depth?: number): boolean;
267
+ declare class TreeWalker {
268
+ walk(root: DocRoot, cb: WalkCallback): void;
269
+ findAll<T extends AnyNode>(root: DocRoot, predicate: (n: AnyNode) => n is T): T[];
270
+ extractText(root: DocRoot): string;
271
+ }
272
+
273
+ declare function countNodes(root: DocRoot): Record<string, number>;
274
+ declare function validateRoot(root: DocRoot): string[];
275
+
276
+ declare const XmlKit: {
277
+ /** @deprecated Use parseStrict instead */
278
+ parse(xml: string): Promise<unknown>;
279
+ parseStrict(xml: string): Promise<unknown>;
280
+ attr(node: Record<string, unknown>, key: string): string | undefined;
281
+ text(node: Record<string, unknown> | string | undefined): string;
282
+ };
283
+
284
+ interface ZipEntry {
285
+ name: string;
286
+ data: Uint8Array;
287
+ }
288
+ declare const ArchiveKit: {
289
+ inflate(compressed: Uint8Array): Promise<Uint8Array>;
290
+ deflate(data: Uint8Array): Promise<Uint8Array>;
291
+ unzip(zipData: Uint8Array): Promise<Map<string, Uint8Array>>;
292
+ zip(entries: ZipEntry[]): Promise<Uint8Array>;
293
+ };
294
+
295
+ /**
296
+ * OLE2 Compound File Binary Format (CFB) parser.
297
+ * Used for legacy HWP 5.0 files.
298
+ */
299
+ declare const BinaryKit: {
300
+ readU16LE(buf: Uint8Array, offset: number): number;
301
+ readU32LE(buf: Uint8Array, offset: number): number;
302
+ isOle2(data: Uint8Array): boolean;
303
+ parseCfb(data: Uint8Array): Map<string, Uint8Array>;
304
+ };
305
+
306
+ declare const TextKit: {
307
+ decode(data: Uint8Array, encoding?: string): string;
308
+ encode(text: string): Uint8Array;
309
+ escapeXml(s: string): string;
310
+ unescapeXml(s: string): string;
311
+ normalizeWhitespace(s: string): string;
312
+ stripControl(s: string): string;
313
+ base64Encode(data: Uint8Array): string;
314
+ base64Decode(b64: string): Uint8Array;
315
+ };
316
+
317
+ export { A4, A4_LANDSCAPE, type Align, type AnyNode, ArchiveKit, BinaryKit, type BlockTag, type BrNode, type CellNode, type CellProps, type ContentNode, DEFAULT_STROKE, type Decoder, type DocMeta, type DocRoot, type Encoder, type Fail, type GridNode, type GridProps, type Heading, type ImgNode, type LinkNode, Metric, normalizeDims, type Ok, type Outcome, type PageDims, type PageNumNode, type ParaNode, type ParaProps, type PbNode, Pipeline, type RowNode, type SheetNode, ShieldedParser, type SpanNode, type Stroke, type StrokeKind, type TableLook, TextKit, type TextProps, TreeWalker, type TxtNode, type VAlign, XmlKit, buildBr, buildCell, buildGrid, buildImg, buildPageNum, buildPara, buildPb, buildRoot, buildRow, buildSheet, buildSpan, countNodes, fail, registry, safeAlign, safeFont, safeFontToKr, safeHex, safeStrokeDocx, safeStrokeHwpx, succeed, validateRoot, walkNode };