hwpkit-dev 0.0.1 → 0.0.2
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.
- package/ .npmignore +1 -0
- package/dist/index.d.mts +34 -3
- package/dist/index.d.ts +30 -3
- package/dist/index.js +2138 -245
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2134 -245
- package/dist/index.mjs.map +1 -1
- package/hwp-analyze.ts +90 -0
- package/inspect-doc.ts +57 -0
- package/output_test.hwp +0 -0
- package/package.json +3 -1
- package/src/decoders/docx/DocxDecoder.ts +155 -30
- package/src/decoders/hwp/HwpScanner.ts +258 -37
- package/src/decoders/hwpx/HwpxDecoder.ts +9 -1
- package/src/encoders/docx/DocxEncoder.ts +199 -158
- package/src/encoders/html/HtmlEncoder.ts +205 -0
- package/src/encoders/hwp/HwpEncoder.ts +864 -222
- package/src/encoders/hwpx/HwpxEncoder.ts +119 -59
- package/src/encoders/md/MdEncoder.ts +98 -16
- package/src/index.ts +1 -0
- package/src/model/builders.ts +4 -2
- package/src/model/doc-tree.ts +1 -1
- package/src/pipeline/Pipeline.ts +14 -1
- package/src/safety/StyleBridge.ts +1 -1
- package/test-docx-to-hwp.ts +45 -0
package/ .npmignore
CHANGED
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
type Align = 'left' | 'center' | 'right' | 'justify';
|
|
2
|
+
type ImgWrap = 'inline' | 'square' | 'tight' | 'through' | 'none' | 'behind' | 'front';
|
|
3
|
+
type ImgHorzAlign = 'left' | 'center' | 'right';
|
|
4
|
+
type ImgVertAlign = 'top' | 'center' | 'bottom';
|
|
5
|
+
type ImgHorzRelTo = 'margin' | 'column' | 'page' | 'para';
|
|
6
|
+
type ImgVertRelTo = 'margin' | 'line' | 'page' | 'para';
|
|
7
|
+
interface ImgLayout {
|
|
8
|
+
wrap: ImgWrap;
|
|
9
|
+
horzAlign?: ImgHorzAlign;
|
|
10
|
+
vertAlign?: ImgVertAlign;
|
|
11
|
+
horzRelTo?: ImgHorzRelTo;
|
|
12
|
+
vertRelTo?: ImgVertRelTo;
|
|
13
|
+
xPt?: number;
|
|
14
|
+
yPt?: number;
|
|
15
|
+
distT?: number;
|
|
16
|
+
distB?: number;
|
|
17
|
+
distL?: number;
|
|
18
|
+
distR?: number;
|
|
19
|
+
behindDoc?: boolean;
|
|
20
|
+
zOrder?: number;
|
|
21
|
+
}
|
|
2
22
|
type VAlign = 'top' | 'mid' | 'bot';
|
|
3
23
|
type Heading = 1 | 2 | 3 | 4 | 5 | 6;
|
|
4
24
|
type StrokeKind = 'solid' | 'dash' | 'dot' | 'double' | 'none';
|
|
@@ -75,6 +95,13 @@ interface DocMeta {
|
|
|
75
95
|
modified?: string;
|
|
76
96
|
}
|
|
77
97
|
declare const A4: PageDims;
|
|
98
|
+
declare const A4_LANDSCAPE: PageDims;
|
|
99
|
+
/**
|
|
100
|
+
* orient === 'landscape'일 때 wPt < hPt이면 swap,
|
|
101
|
+
* orient === 'portrait'일 때 wPt > hPt이면 swap하여
|
|
102
|
+
* 방향과 치수가 항상 일치하도록 정규화합니다.
|
|
103
|
+
*/
|
|
104
|
+
declare function normalizeDims(dims: PageDims): PageDims;
|
|
78
105
|
declare const DEFAULT_STROKE: Stroke;
|
|
79
106
|
|
|
80
107
|
type BlockTag = 'root' | 'sheet' | 'para' | 'span' | 'txt' | 'img' | 'link' | 'grid' | 'row' | 'cell' | 'br' | 'pb' | 'pagenum';
|
|
@@ -99,6 +126,7 @@ interface ImgNode {
|
|
|
99
126
|
w: number;
|
|
100
127
|
h: number;
|
|
101
128
|
alt?: string;
|
|
129
|
+
layout?: ImgLayout;
|
|
102
130
|
}
|
|
103
131
|
interface SpanNode {
|
|
104
132
|
tag: 'span';
|
|
@@ -125,6 +153,7 @@ interface CellNode {
|
|
|
125
153
|
interface RowNode {
|
|
126
154
|
tag: 'row';
|
|
127
155
|
kids: CellNode[];
|
|
156
|
+
heightPt?: number;
|
|
128
157
|
}
|
|
129
158
|
interface GridNode {
|
|
130
159
|
tag: 'grid';
|
|
@@ -202,11 +231,13 @@ declare function buildSheet(kids?: ContentNode[], dims?: PageDims, opts?: {
|
|
|
202
231
|
footer?: ParaNode[];
|
|
203
232
|
}): SheetNode;
|
|
204
233
|
declare function buildPageNum(format?: PageNumNode['format']): PageNumNode;
|
|
234
|
+
declare function buildBr(): BrNode;
|
|
235
|
+
declare function buildPb(): PbNode;
|
|
205
236
|
declare function buildPara(kids?: ParaNode['kids'], props?: ParaProps): ParaNode;
|
|
206
237
|
declare function buildSpan(content: string, props?: TextProps): SpanNode;
|
|
207
|
-
declare function buildImg(b64: string, mime: ImgNode['mime'], w: number, h: number, alt?: string): ImgNode;
|
|
238
|
+
declare function buildImg(b64: string, mime: ImgNode['mime'], w: number, h: number, alt?: string, layout?: ImgLayout): ImgNode;
|
|
208
239
|
declare function buildGrid(kids: RowNode[], props?: GridProps): GridNode;
|
|
209
|
-
declare function buildRow(kids: CellNode[]): RowNode;
|
|
240
|
+
declare function buildRow(kids: CellNode[], heightPt?: number): RowNode;
|
|
210
241
|
declare function buildCell(kids: ParaNode[], opts?: {
|
|
211
242
|
cs?: number;
|
|
212
243
|
rs?: number;
|
|
@@ -310,4 +341,4 @@ declare const TextKit: {
|
|
|
310
341
|
base64Decode(b64: string): Uint8Array;
|
|
311
342
|
};
|
|
312
343
|
|
|
313
|
-
export { A4, 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, 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, buildCell, buildGrid, buildImg, buildPageNum, buildPara, buildRoot, buildRow, buildSheet, buildSpan, countNodes, fail, registry, safeAlign, safeFont, safeFontToKr, safeHex, safeStrokeDocx, safeStrokeHwpx, succeed, validateRoot, walkNode };
|
|
344
|
+
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, 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, normalizeDims, registry, safeAlign, safeFont, safeFontToKr, safeHex, safeStrokeDocx, safeStrokeHwpx, succeed, validateRoot, walkNode };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,24 @@
|
|
|
1
1
|
type Align = 'left' | 'center' | 'right' | 'justify';
|
|
2
|
+
type ImgWrap = 'inline' | 'square' | 'tight' | 'through' | 'none' | 'behind' | 'front';
|
|
3
|
+
type ImgHorzAlign = 'left' | 'center' | 'right';
|
|
4
|
+
type ImgVertAlign = 'top' | 'center' | 'bottom';
|
|
5
|
+
type ImgHorzRelTo = 'margin' | 'column' | 'page' | 'para';
|
|
6
|
+
type ImgVertRelTo = 'margin' | 'line' | 'page' | 'para';
|
|
7
|
+
interface ImgLayout {
|
|
8
|
+
wrap: ImgWrap;
|
|
9
|
+
horzAlign?: ImgHorzAlign;
|
|
10
|
+
vertAlign?: ImgVertAlign;
|
|
11
|
+
horzRelTo?: ImgHorzRelTo;
|
|
12
|
+
vertRelTo?: ImgVertRelTo;
|
|
13
|
+
xPt?: number;
|
|
14
|
+
yPt?: number;
|
|
15
|
+
distT?: number;
|
|
16
|
+
distB?: number;
|
|
17
|
+
distL?: number;
|
|
18
|
+
distR?: number;
|
|
19
|
+
behindDoc?: boolean;
|
|
20
|
+
zOrder?: number;
|
|
21
|
+
}
|
|
2
22
|
type VAlign = 'top' | 'mid' | 'bot';
|
|
3
23
|
type Heading = 1 | 2 | 3 | 4 | 5 | 6;
|
|
4
24
|
type StrokeKind = 'solid' | 'dash' | 'dot' | 'double' | 'none';
|
|
@@ -76,6 +96,11 @@ interface DocMeta {
|
|
|
76
96
|
}
|
|
77
97
|
declare const A4: PageDims;
|
|
78
98
|
declare const A4_LANDSCAPE: PageDims;
|
|
99
|
+
/**
|
|
100
|
+
* orient === 'landscape'일 때 wPt < hPt이면 swap,
|
|
101
|
+
* orient === 'portrait'일 때 wPt > hPt이면 swap하여
|
|
102
|
+
* 방향과 치수가 항상 일치하도록 정규화합니다.
|
|
103
|
+
*/
|
|
79
104
|
declare function normalizeDims(dims: PageDims): PageDims;
|
|
80
105
|
declare const DEFAULT_STROKE: Stroke;
|
|
81
106
|
|
|
@@ -101,6 +126,7 @@ interface ImgNode {
|
|
|
101
126
|
w: number;
|
|
102
127
|
h: number;
|
|
103
128
|
alt?: string;
|
|
129
|
+
layout?: ImgLayout;
|
|
104
130
|
}
|
|
105
131
|
interface SpanNode {
|
|
106
132
|
tag: 'span';
|
|
@@ -127,6 +153,7 @@ interface CellNode {
|
|
|
127
153
|
interface RowNode {
|
|
128
154
|
tag: 'row';
|
|
129
155
|
kids: CellNode[];
|
|
156
|
+
heightPt?: number;
|
|
130
157
|
}
|
|
131
158
|
interface GridNode {
|
|
132
159
|
tag: 'grid';
|
|
@@ -208,9 +235,9 @@ declare function buildBr(): BrNode;
|
|
|
208
235
|
declare function buildPb(): PbNode;
|
|
209
236
|
declare function buildPara(kids?: ParaNode['kids'], props?: ParaProps): ParaNode;
|
|
210
237
|
declare function buildSpan(content: string, props?: TextProps): SpanNode;
|
|
211
|
-
declare function buildImg(b64: string, mime: ImgNode['mime'], w: number, h: number, alt?: string): ImgNode;
|
|
238
|
+
declare function buildImg(b64: string, mime: ImgNode['mime'], w: number, h: number, alt?: string, layout?: ImgLayout): ImgNode;
|
|
212
239
|
declare function buildGrid(kids: RowNode[], props?: GridProps): GridNode;
|
|
213
|
-
declare function buildRow(kids: CellNode[]): RowNode;
|
|
240
|
+
declare function buildRow(kids: CellNode[], heightPt?: number): RowNode;
|
|
214
241
|
declare function buildCell(kids: ParaNode[], opts?: {
|
|
215
242
|
cs?: number;
|
|
216
243
|
rs?: number;
|
|
@@ -314,4 +341,4 @@ declare const TextKit: {
|
|
|
314
341
|
base64Decode(b64: string): Uint8Array;
|
|
315
342
|
};
|
|
316
343
|
|
|
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,
|
|
344
|
+
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, 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, normalizeDims, registry, safeAlign, safeFont, safeFontToKr, safeHex, safeStrokeDocx, safeStrokeHwpx, succeed, validateRoot, walkNode };
|