@iyulab/unhwp 0.5.3

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 iyulab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # @iyulab/unhwp
2
+
3
+ WebAssembly bindings for [unhwp](https://github.com/iyulab/unhwp) — HWP/HWPX Korean document extraction.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @iyulab/unhwp
9
+ ```
10
+
11
+ ## Usage (ES Module / browser)
12
+
13
+ ```js
14
+ import init, { parse } from '@iyulab/unhwp';
15
+
16
+ await init();
17
+
18
+ const response = await fetch('document.hwp');
19
+ const data = new Uint8Array(await response.arrayBuffer());
20
+ const doc = parse(data);
21
+
22
+ console.log(doc.toMarkdown());
23
+ console.log(doc.toText());
24
+ console.log(doc.sectionCount(), doc.paragraphCount());
25
+ ```
26
+
27
+ ## API
28
+
29
+ ### `parse(data: Uint8Array): HwpDocument`
30
+
31
+ HWP 또는 HWPX 파일 바이트를 파싱합니다. 파싱 실패 시 오류를 던집니다.
32
+
33
+ ### `HwpDocument`
34
+
35
+ | Method | Returns | Description |
36
+ |--------|---------|-------------|
37
+ | `toMarkdown()` | `string` | Markdown 렌더링 |
38
+ | `toText()` | `string` | 평문 텍스트 |
39
+ | `toJson()` | `string` | 구조화된 JSON |
40
+ | `sectionCount()` | `number` | 섹션 수 |
41
+ | `paragraphCount()` | `number` | 단락 수 |
42
+
43
+ ### `ParseOptions`
44
+
45
+ ```js
46
+ import { parse, ParseOptions } from '@iyulab/unhwp';
47
+
48
+ const opts = new ParseOptions().lenient().textOnly();
49
+ const doc = parseWithOptions(data, opts);
50
+ ```
51
+
52
+ | Method | Description |
53
+ |--------|-------------|
54
+ | `lenient()` | 잘못된 섹션을 건너뛰고 파싱 계속 |
55
+ | `textOnly()` | 텍스트만 추출 (이미지 제외, 빠른 처리) |
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@iyulab/unhwp",
3
+ "type": "module",
4
+ "description": "HWP/HWPX extraction to Markdown, text, and JSON (WebAssembly)",
5
+ "version": "0.5.3",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/iyulab/unhwp"
10
+ },
11
+ "files": [
12
+ "unhwp_wasm_bg.wasm",
13
+ "unhwp_wasm.js",
14
+ "unhwp_wasm_bg.js",
15
+ "unhwp_wasm.d.ts"
16
+ ],
17
+ "main": "unhwp_wasm.js",
18
+ "types": "unhwp_wasm.d.ts",
19
+ "sideEffects": [
20
+ "./unhwp_wasm.js",
21
+ "./snippets/*"
22
+ ],
23
+ "keywords": [
24
+ "hwp",
25
+ "hwpx",
26
+ "korean",
27
+ "wasm",
28
+ "webassembly"
29
+ ]
30
+ }
@@ -0,0 +1,29 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ export class HwpDocument {
5
+ private constructor();
6
+ free(): void;
7
+ [Symbol.dispose](): void;
8
+ static fromBytes(data: Uint8Array): HwpDocument;
9
+ toMarkdown(): string;
10
+ sectionCount(): number;
11
+ paragraphCount(): number;
12
+ toJson(): string;
13
+ toText(): string;
14
+ }
15
+
16
+ export class ParseOptions {
17
+ free(): void;
18
+ [Symbol.dispose](): void;
19
+ constructor();
20
+ lenient(): ParseOptions;
21
+ textOnly(): ParseOptions;
22
+ }
23
+
24
+ export function parse(data: Uint8Array): HwpDocument;
25
+
26
+ /**
27
+ * Parse with options.
28
+ */
29
+ export function parseWithOptions(data: Uint8Array, opts: ParseOptions): HwpDocument;
package/unhwp_wasm.js ADDED
@@ -0,0 +1,5 @@
1
+ import * as wasm from "./unhwp_wasm_bg.wasm";
2
+ export * from "./unhwp_wasm_bg.js";
3
+ import { __wbg_set_wasm } from "./unhwp_wasm_bg.js";
4
+ __wbg_set_wasm(wasm);
5
+ wasm.__wbindgen_start();
@@ -0,0 +1,259 @@
1
+ let wasm;
2
+ export function __wbg_set_wasm(val) {
3
+ wasm = val;
4
+ }
5
+
6
+ function _assertClass(instance, klass) {
7
+ if (!(instance instanceof klass)) {
8
+ throw new Error(`expected instance of ${klass.name}`);
9
+ }
10
+ }
11
+
12
+ function getStringFromWasm0(ptr, len) {
13
+ ptr = ptr >>> 0;
14
+ return decodeText(ptr, len);
15
+ }
16
+
17
+ let cachedUint8ArrayMemory0 = null;
18
+ function getUint8ArrayMemory0() {
19
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
20
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
21
+ }
22
+ return cachedUint8ArrayMemory0;
23
+ }
24
+
25
+ function passArray8ToWasm0(arg, malloc) {
26
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
27
+ getUint8ArrayMemory0().set(arg, ptr / 1);
28
+ WASM_VECTOR_LEN = arg.length;
29
+ return ptr;
30
+ }
31
+
32
+ function takeFromExternrefTable0(idx) {
33
+ const value = wasm.__wbindgen_externrefs.get(idx);
34
+ wasm.__externref_table_dealloc(idx);
35
+ return value;
36
+ }
37
+
38
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
39
+ cachedTextDecoder.decode();
40
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
41
+ let numBytesDecoded = 0;
42
+ function decodeText(ptr, len) {
43
+ numBytesDecoded += len;
44
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
45
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
46
+ cachedTextDecoder.decode();
47
+ numBytesDecoded = len;
48
+ }
49
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
50
+ }
51
+
52
+ let WASM_VECTOR_LEN = 0;
53
+
54
+ const HwpDocumentFinalization = (typeof FinalizationRegistry === 'undefined')
55
+ ? { register: () => {}, unregister: () => {} }
56
+ : new FinalizationRegistry(ptr => wasm.__wbg_hwpdocument_free(ptr >>> 0, 1));
57
+
58
+ const ParseOptionsFinalization = (typeof FinalizationRegistry === 'undefined')
59
+ ? { register: () => {}, unregister: () => {} }
60
+ : new FinalizationRegistry(ptr => wasm.__wbg_parseoptions_free(ptr >>> 0, 1));
61
+
62
+ export class HwpDocument {
63
+ static __wrap(ptr) {
64
+ ptr = ptr >>> 0;
65
+ const obj = Object.create(HwpDocument.prototype);
66
+ obj.__wbg_ptr = ptr;
67
+ HwpDocumentFinalization.register(obj, obj.__wbg_ptr, obj);
68
+ return obj;
69
+ }
70
+ __destroy_into_raw() {
71
+ const ptr = this.__wbg_ptr;
72
+ this.__wbg_ptr = 0;
73
+ HwpDocumentFinalization.unregister(this);
74
+ return ptr;
75
+ }
76
+ free() {
77
+ const ptr = this.__destroy_into_raw();
78
+ wasm.__wbg_hwpdocument_free(ptr, 0);
79
+ }
80
+ /**
81
+ * @param {Uint8Array} data
82
+ * @returns {HwpDocument}
83
+ */
84
+ static fromBytes(data) {
85
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
86
+ const len0 = WASM_VECTOR_LEN;
87
+ const ret = wasm.hwpdocument_fromBytes(ptr0, len0);
88
+ if (ret[2]) {
89
+ throw takeFromExternrefTable0(ret[1]);
90
+ }
91
+ return HwpDocument.__wrap(ret[0]);
92
+ }
93
+ /**
94
+ * @returns {string}
95
+ */
96
+ toMarkdown() {
97
+ let deferred2_0;
98
+ let deferred2_1;
99
+ try {
100
+ const ret = wasm.hwpdocument_toMarkdown(this.__wbg_ptr);
101
+ var ptr1 = ret[0];
102
+ var len1 = ret[1];
103
+ if (ret[3]) {
104
+ ptr1 = 0; len1 = 0;
105
+ throw takeFromExternrefTable0(ret[2]);
106
+ }
107
+ deferred2_0 = ptr1;
108
+ deferred2_1 = len1;
109
+ return getStringFromWasm0(ptr1, len1);
110
+ } finally {
111
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
112
+ }
113
+ }
114
+ /**
115
+ * @returns {number}
116
+ */
117
+ sectionCount() {
118
+ const ret = wasm.hwpdocument_sectionCount(this.__wbg_ptr);
119
+ return ret >>> 0;
120
+ }
121
+ /**
122
+ * @returns {number}
123
+ */
124
+ paragraphCount() {
125
+ const ret = wasm.hwpdocument_paragraphCount(this.__wbg_ptr);
126
+ return ret >>> 0;
127
+ }
128
+ /**
129
+ * @returns {string}
130
+ */
131
+ toJson() {
132
+ let deferred2_0;
133
+ let deferred2_1;
134
+ try {
135
+ const ret = wasm.hwpdocument_toJson(this.__wbg_ptr);
136
+ var ptr1 = ret[0];
137
+ var len1 = ret[1];
138
+ if (ret[3]) {
139
+ ptr1 = 0; len1 = 0;
140
+ throw takeFromExternrefTable0(ret[2]);
141
+ }
142
+ deferred2_0 = ptr1;
143
+ deferred2_1 = len1;
144
+ return getStringFromWasm0(ptr1, len1);
145
+ } finally {
146
+ wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
147
+ }
148
+ }
149
+ /**
150
+ * @returns {string}
151
+ */
152
+ toText() {
153
+ let deferred1_0;
154
+ let deferred1_1;
155
+ try {
156
+ const ret = wasm.hwpdocument_toText(this.__wbg_ptr);
157
+ deferred1_0 = ret[0];
158
+ deferred1_1 = ret[1];
159
+ return getStringFromWasm0(ret[0], ret[1]);
160
+ } finally {
161
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
162
+ }
163
+ }
164
+ }
165
+ if (Symbol.dispose) HwpDocument.prototype[Symbol.dispose] = HwpDocument.prototype.free;
166
+
167
+ export class ParseOptions {
168
+ static __wrap(ptr) {
169
+ ptr = ptr >>> 0;
170
+ const obj = Object.create(ParseOptions.prototype);
171
+ obj.__wbg_ptr = ptr;
172
+ ParseOptionsFinalization.register(obj, obj.__wbg_ptr, obj);
173
+ return obj;
174
+ }
175
+ __destroy_into_raw() {
176
+ const ptr = this.__wbg_ptr;
177
+ this.__wbg_ptr = 0;
178
+ ParseOptionsFinalization.unregister(this);
179
+ return ptr;
180
+ }
181
+ free() {
182
+ const ptr = this.__destroy_into_raw();
183
+ wasm.__wbg_parseoptions_free(ptr, 0);
184
+ }
185
+ constructor() {
186
+ const ret = wasm.parseoptions_new();
187
+ this.__wbg_ptr = ret >>> 0;
188
+ ParseOptionsFinalization.register(this, this.__wbg_ptr, this);
189
+ return this;
190
+ }
191
+ /**
192
+ * @returns {ParseOptions}
193
+ */
194
+ lenient() {
195
+ const ptr = this.__destroy_into_raw();
196
+ const ret = wasm.parseoptions_lenient(ptr);
197
+ return ParseOptions.__wrap(ret);
198
+ }
199
+ /**
200
+ * @returns {ParseOptions}
201
+ */
202
+ textOnly() {
203
+ const ptr = this.__destroy_into_raw();
204
+ const ret = wasm.parseoptions_textOnly(ptr);
205
+ return ParseOptions.__wrap(ret);
206
+ }
207
+ }
208
+ if (Symbol.dispose) ParseOptions.prototype[Symbol.dispose] = ParseOptions.prototype.free;
209
+
210
+ /**
211
+ * @param {Uint8Array} data
212
+ * @returns {HwpDocument}
213
+ */
214
+ export function parse(data) {
215
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
216
+ const len0 = WASM_VECTOR_LEN;
217
+ const ret = wasm.parse(ptr0, len0);
218
+ if (ret[2]) {
219
+ throw takeFromExternrefTable0(ret[1]);
220
+ }
221
+ return HwpDocument.__wrap(ret[0]);
222
+ }
223
+
224
+ /**
225
+ * Parse with options.
226
+ * @param {Uint8Array} data
227
+ * @param {ParseOptions} opts
228
+ * @returns {HwpDocument}
229
+ */
230
+ export function parseWithOptions(data, opts) {
231
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
232
+ const len0 = WASM_VECTOR_LEN;
233
+ _assertClass(opts, ParseOptions);
234
+ const ret = wasm.parseWithOptions(ptr0, len0, opts.__wbg_ptr);
235
+ if (ret[2]) {
236
+ throw takeFromExternrefTable0(ret[1]);
237
+ }
238
+ return HwpDocument.__wrap(ret[0]);
239
+ }
240
+
241
+ export function __wbg___wbindgen_throw_dd24417ed36fc46e(arg0, arg1) {
242
+ throw new Error(getStringFromWasm0(arg0, arg1));
243
+ };
244
+
245
+ export function __wbindgen_cast_2241b6af4c4b2941(arg0, arg1) {
246
+ // Cast intrinsic for `Ref(String) -> Externref`.
247
+ const ret = getStringFromWasm0(arg0, arg1);
248
+ return ret;
249
+ };
250
+
251
+ export function __wbindgen_init_externref_table() {
252
+ const table = wasm.__wbindgen_externrefs;
253
+ const offset = table.grow(4);
254
+ table.set(0, undefined);
255
+ table.set(offset + 0, undefined);
256
+ table.set(offset + 1, null);
257
+ table.set(offset + 2, true);
258
+ table.set(offset + 3, false);
259
+ };
Binary file