mecab-ko-wasm 0.3.0 → 0.4.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.
@@ -146,3 +146,52 @@ export class WasmToken {
146
146
  * It sets up panic hooks for better error messages in development.
147
147
  */
148
148
  export function init(): void;
149
+
150
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
151
+
152
+ export interface InitOutput {
153
+ readonly memory: WebAssembly.Memory;
154
+ readonly __wbg_mecab_free: (a: number, b: number) => void;
155
+ readonly __wbg_wasmtoken_free: (a: number, b: number) => void;
156
+ readonly mecab_morphs: (a: number, b: number, c: number, d: number) => void;
157
+ readonly mecab_new: (a: number) => void;
158
+ readonly mecab_nouns: (a: number, b: number, c: number, d: number) => void;
159
+ readonly mecab_pos: (a: number, b: number, c: number, d: number) => void;
160
+ readonly mecab_tokenize: (a: number, b: number, c: number, d: number) => void;
161
+ readonly mecab_wakati: (a: number, b: number, c: number, d: number) => void;
162
+ readonly wasmtoken_end: (a: number) => number;
163
+ readonly wasmtoken_lemma: (a: number, b: number) => void;
164
+ readonly wasmtoken_pos: (a: number, b: number) => void;
165
+ readonly wasmtoken_reading: (a: number, b: number) => void;
166
+ readonly wasmtoken_start: (a: number) => number;
167
+ readonly wasmtoken_surface: (a: number, b: number) => void;
168
+ readonly wasmtoken_toJSON: (a: number, b: number) => void;
169
+ readonly init: () => void;
170
+ readonly __wbindgen_export: (a: number, b: number, c: number) => void;
171
+ readonly __wbindgen_export2: (a: number, b: number) => number;
172
+ readonly __wbindgen_export3: (a: number, b: number, c: number, d: number) => number;
173
+ readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
174
+ readonly __wbindgen_start: () => void;
175
+ }
176
+
177
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
178
+
179
+ /**
180
+ * Instantiates the given `module`, which can either be bytes or
181
+ * a precompiled `WebAssembly.Module`.
182
+ *
183
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
184
+ *
185
+ * @returns {InitOutput}
186
+ */
187
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
188
+
189
+ /**
190
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
191
+ * for everything else, calls `WebAssembly.instantiate` directly.
192
+ *
193
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
194
+ *
195
+ * @returns {Promise<InitOutput>}
196
+ */
197
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
package/mecab_ko_wasm.js CHANGED
@@ -1,9 +1,648 @@
1
1
  /* @ts-self-types="./mecab_ko_wasm.d.ts" */
2
2
 
3
- import * as wasm from "./mecab_ko_wasm_bg.wasm";
4
- import { __wbg_set_wasm } from "./mecab_ko_wasm_bg.js";
5
- __wbg_set_wasm(wasm);
6
- wasm.__wbindgen_start();
7
- export {
8
- Mecab, WasmToken, init
9
- } from "./mecab_ko_wasm_bg.js";
3
+ /**
4
+ * The main MeCab-Ko tokenizer for WebAssembly
5
+ *
6
+ * This class provides Korean morphological analysis capabilities
7
+ * in JavaScript/TypeScript environments.
8
+ */
9
+ export class Mecab {
10
+ __destroy_into_raw() {
11
+ const ptr = this.__wbg_ptr;
12
+ this.__wbg_ptr = 0;
13
+ MecabFinalization.unregister(this);
14
+ return ptr;
15
+ }
16
+ free() {
17
+ const ptr = this.__destroy_into_raw();
18
+ wasm.__wbg_mecab_free(ptr, 0);
19
+ }
20
+ /**
21
+ * Extract morphemes (형태소) from text
22
+ *
23
+ * Returns an array of morpheme strings without POS information.
24
+ *
25
+ * # Example (JavaScript)
26
+ *
27
+ * ```javascript
28
+ * const morphs = mecab.morphs("안녕하세요");
29
+ * console.log(morphs); // ["안녕", "하", "세요"]
30
+ * ```
31
+ * @param {string} text
32
+ * @returns {string[]}
33
+ */
34
+ morphs(text) {
35
+ try {
36
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
37
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
38
+ const len0 = WASM_VECTOR_LEN;
39
+ wasm.mecab_morphs(retptr, this.__wbg_ptr, ptr0, len0);
40
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
41
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
42
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
43
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
44
+ return v2;
45
+ } finally {
46
+ wasm.__wbindgen_add_to_stack_pointer(16);
47
+ }
48
+ }
49
+ /**
50
+ * Create a new Mecab instance with the default dictionary
51
+ *
52
+ * # Example (JavaScript)
53
+ *
54
+ * ```javascript
55
+ * const mecab = new Mecab();
56
+ * ```
57
+ *
58
+ * # Errors
59
+ *
60
+ * Returns an error if tokenizer initialization fails
61
+ */
62
+ constructor() {
63
+ try {
64
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
65
+ wasm.mecab_new(retptr);
66
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
67
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
68
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
69
+ if (r2) {
70
+ throw takeObject(r1);
71
+ }
72
+ this.__wbg_ptr = r0 >>> 0;
73
+ MecabFinalization.register(this, this.__wbg_ptr, this);
74
+ return this;
75
+ } finally {
76
+ wasm.__wbindgen_add_to_stack_pointer(16);
77
+ }
78
+ }
79
+ /**
80
+ * Extract nouns (명사) from text
81
+ *
82
+ * Returns an array of noun strings.
83
+ *
84
+ * # Example (JavaScript)
85
+ *
86
+ * ```javascript
87
+ * const nouns = mecab.nouns("형태소 분석기입니다");
88
+ * console.log(nouns); // ["형태소", "분석기"]
89
+ * ```
90
+ * @param {string} text
91
+ * @returns {string[]}
92
+ */
93
+ nouns(text) {
94
+ try {
95
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
96
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
97
+ const len0 = WASM_VECTOR_LEN;
98
+ wasm.mecab_nouns(retptr, this.__wbg_ptr, ptr0, len0);
99
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
100
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
101
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
102
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
103
+ return v2;
104
+ } finally {
105
+ wasm.__wbindgen_add_to_stack_pointer(16);
106
+ }
107
+ }
108
+ /**
109
+ * Extract part-of-speech tagged pairs
110
+ *
111
+ * Returns a JSON string containing an array of [surface, pos] pairs.
112
+ *
113
+ * # Example (JavaScript)
114
+ *
115
+ * ```javascript
116
+ * const posJson = mecab.pos("안녕하세요");
117
+ * const pos = JSON.parse(posJson);
118
+ * console.log(pos); // [["안녕", "NNG"], ["하", "XSV"], ["세요", "EP+EF"]]
119
+ * ```
120
+ *
121
+ * # Errors
122
+ *
123
+ * Returns an error if JSON serialization fails
124
+ * @param {string} text
125
+ * @returns {string}
126
+ */
127
+ pos(text) {
128
+ let deferred3_0;
129
+ let deferred3_1;
130
+ try {
131
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
132
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
133
+ const len0 = WASM_VECTOR_LEN;
134
+ wasm.mecab_pos(retptr, this.__wbg_ptr, ptr0, len0);
135
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
136
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
137
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
138
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
139
+ var ptr2 = r0;
140
+ var len2 = r1;
141
+ if (r3) {
142
+ ptr2 = 0; len2 = 0;
143
+ throw takeObject(r2);
144
+ }
145
+ deferred3_0 = ptr2;
146
+ deferred3_1 = len2;
147
+ return getStringFromWasm0(ptr2, len2);
148
+ } finally {
149
+ wasm.__wbindgen_add_to_stack_pointer(16);
150
+ wasm.__wbindgen_export(deferred3_0, deferred3_1, 1);
151
+ }
152
+ }
153
+ /**
154
+ * Tokenize text and return detailed token information
155
+ *
156
+ * Returns an array of tokens with surface form, POS tag, and position information.
157
+ *
158
+ * # Example (JavaScript)
159
+ *
160
+ * ```javascript
161
+ * const tokens = mecab.tokenize("안녕하세요");
162
+ * tokens.forEach(token => {
163
+ * console.log(`${token.surface}: ${token.pos}`);
164
+ * });
165
+ * ```
166
+ * @param {string} text
167
+ * @returns {WasmToken[]}
168
+ */
169
+ tokenize(text) {
170
+ try {
171
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
172
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
173
+ const len0 = WASM_VECTOR_LEN;
174
+ wasm.mecab_tokenize(retptr, this.__wbg_ptr, ptr0, len0);
175
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
176
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
177
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
178
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
179
+ return v2;
180
+ } finally {
181
+ wasm.__wbindgen_add_to_stack_pointer(16);
182
+ }
183
+ }
184
+ /**
185
+ * Perform wakati (분리) tokenization
186
+ *
187
+ * Returns an array of morpheme strings, similar to `morphs()`.
188
+ *
189
+ * # Example (JavaScript)
190
+ *
191
+ * ```javascript
192
+ * const words = mecab.wakati("형태소 분석");
193
+ * console.log(words); // ["형태소", "분석"]
194
+ * ```
195
+ * @param {string} text
196
+ * @returns {string[]}
197
+ */
198
+ wakati(text) {
199
+ try {
200
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
201
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
202
+ const len0 = WASM_VECTOR_LEN;
203
+ wasm.mecab_wakati(retptr, this.__wbg_ptr, ptr0, len0);
204
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
205
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
206
+ var v2 = getArrayJsValueFromWasm0(r0, r1).slice();
207
+ wasm.__wbindgen_export(r0, r1 * 4, 4);
208
+ return v2;
209
+ } finally {
210
+ wasm.__wbindgen_add_to_stack_pointer(16);
211
+ }
212
+ }
213
+ }
214
+ if (Symbol.dispose) Mecab.prototype[Symbol.dispose] = Mecab.prototype.free;
215
+
216
+ /**
217
+ * A JavaScript-friendly token representation
218
+ */
219
+ export class WasmToken {
220
+ static __wrap(ptr) {
221
+ ptr = ptr >>> 0;
222
+ const obj = Object.create(WasmToken.prototype);
223
+ obj.__wbg_ptr = ptr;
224
+ WasmTokenFinalization.register(obj, obj.__wbg_ptr, obj);
225
+ return obj;
226
+ }
227
+ __destroy_into_raw() {
228
+ const ptr = this.__wbg_ptr;
229
+ this.__wbg_ptr = 0;
230
+ WasmTokenFinalization.unregister(this);
231
+ return ptr;
232
+ }
233
+ free() {
234
+ const ptr = this.__destroy_into_raw();
235
+ wasm.__wbg_wasmtoken_free(ptr, 0);
236
+ }
237
+ /**
238
+ * Get the end position in bytes
239
+ * @returns {number}
240
+ */
241
+ get end() {
242
+ const ret = wasm.wasmtoken_end(this.__wbg_ptr);
243
+ return ret >>> 0;
244
+ }
245
+ /**
246
+ * Get the lemma/base form (if available)
247
+ * @returns {string | undefined}
248
+ */
249
+ get lemma() {
250
+ try {
251
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
252
+ wasm.wasmtoken_lemma(retptr, this.__wbg_ptr);
253
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
254
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
255
+ let v1;
256
+ if (r0 !== 0) {
257
+ v1 = getStringFromWasm0(r0, r1).slice();
258
+ wasm.__wbindgen_export(r0, r1 * 1, 1);
259
+ }
260
+ return v1;
261
+ } finally {
262
+ wasm.__wbindgen_add_to_stack_pointer(16);
263
+ }
264
+ }
265
+ /**
266
+ * Get the part-of-speech tag (품사)
267
+ * @returns {string}
268
+ */
269
+ get pos() {
270
+ let deferred1_0;
271
+ let deferred1_1;
272
+ try {
273
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
274
+ wasm.wasmtoken_pos(retptr, this.__wbg_ptr);
275
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
276
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
277
+ deferred1_0 = r0;
278
+ deferred1_1 = r1;
279
+ return getStringFromWasm0(r0, r1);
280
+ } finally {
281
+ wasm.__wbindgen_add_to_stack_pointer(16);
282
+ wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
283
+ }
284
+ }
285
+ /**
286
+ * Get the reading (if available)
287
+ * @returns {string | undefined}
288
+ */
289
+ get reading() {
290
+ try {
291
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
292
+ wasm.wasmtoken_reading(retptr, this.__wbg_ptr);
293
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
294
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
295
+ let v1;
296
+ if (r0 !== 0) {
297
+ v1 = getStringFromWasm0(r0, r1).slice();
298
+ wasm.__wbindgen_export(r0, r1 * 1, 1);
299
+ }
300
+ return v1;
301
+ } finally {
302
+ wasm.__wbindgen_add_to_stack_pointer(16);
303
+ }
304
+ }
305
+ /**
306
+ * Get the start position in bytes
307
+ * @returns {number}
308
+ */
309
+ get start() {
310
+ const ret = wasm.wasmtoken_start(this.__wbg_ptr);
311
+ return ret >>> 0;
312
+ }
313
+ /**
314
+ * Get the surface form (표면형)
315
+ * @returns {string}
316
+ */
317
+ get surface() {
318
+ let deferred1_0;
319
+ let deferred1_1;
320
+ try {
321
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
322
+ wasm.wasmtoken_surface(retptr, this.__wbg_ptr);
323
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
324
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
325
+ deferred1_0 = r0;
326
+ deferred1_1 = r1;
327
+ return getStringFromWasm0(r0, r1);
328
+ } finally {
329
+ wasm.__wbindgen_add_to_stack_pointer(16);
330
+ wasm.__wbindgen_export(deferred1_0, deferred1_1, 1);
331
+ }
332
+ }
333
+ /**
334
+ * Convert to JSON string for easier JavaScript interop
335
+ *
336
+ * # Errors
337
+ *
338
+ * Returns an error if serialization fails
339
+ * @returns {string}
340
+ */
341
+ toJSON() {
342
+ let deferred2_0;
343
+ let deferred2_1;
344
+ try {
345
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
346
+ wasm.wasmtoken_toJSON(retptr, this.__wbg_ptr);
347
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
348
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
349
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
350
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
351
+ var ptr1 = r0;
352
+ var len1 = r1;
353
+ if (r3) {
354
+ ptr1 = 0; len1 = 0;
355
+ throw takeObject(r2);
356
+ }
357
+ deferred2_0 = ptr1;
358
+ deferred2_1 = len1;
359
+ return getStringFromWasm0(ptr1, len1);
360
+ } finally {
361
+ wasm.__wbindgen_add_to_stack_pointer(16);
362
+ wasm.__wbindgen_export(deferred2_0, deferred2_1, 1);
363
+ }
364
+ }
365
+ }
366
+ if (Symbol.dispose) WasmToken.prototype[Symbol.dispose] = WasmToken.prototype.free;
367
+
368
+ /**
369
+ * Initialize the WASM module
370
+ *
371
+ * This function should be called once before using the library.
372
+ * It sets up panic hooks for better error messages in development.
373
+ */
374
+ export function init() {
375
+ wasm.init();
376
+ }
377
+
378
+ function __wbg_get_imports() {
379
+ const import0 = {
380
+ __proto__: null,
381
+ __wbg___wbindgen_throw_6ddd609b62940d55: function(arg0, arg1) {
382
+ throw new Error(getStringFromWasm0(arg0, arg1));
383
+ },
384
+ __wbg_error_a6fa202b58aa1cd3: function(arg0, arg1) {
385
+ let deferred0_0;
386
+ let deferred0_1;
387
+ try {
388
+ deferred0_0 = arg0;
389
+ deferred0_1 = arg1;
390
+ console.error(getStringFromWasm0(arg0, arg1));
391
+ } finally {
392
+ wasm.__wbindgen_export(deferred0_0, deferred0_1, 1);
393
+ }
394
+ },
395
+ __wbg_new_227d7c05414eb861: function() {
396
+ const ret = new Error();
397
+ return addHeapObject(ret);
398
+ },
399
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
400
+ const ret = getObject(arg1).stack;
401
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_export2, wasm.__wbindgen_export3);
402
+ const len1 = WASM_VECTOR_LEN;
403
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
404
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
405
+ },
406
+ __wbg_wasmtoken_new: function(arg0) {
407
+ const ret = WasmToken.__wrap(arg0);
408
+ return addHeapObject(ret);
409
+ },
410
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
411
+ // Cast intrinsic for `Ref(String) -> Externref`.
412
+ const ret = getStringFromWasm0(arg0, arg1);
413
+ return addHeapObject(ret);
414
+ },
415
+ __wbindgen_object_drop_ref: function(arg0) {
416
+ takeObject(arg0);
417
+ },
418
+ };
419
+ return {
420
+ __proto__: null,
421
+ "./mecab_ko_wasm_bg.js": import0,
422
+ };
423
+ }
424
+
425
+ const MecabFinalization = (typeof FinalizationRegistry === 'undefined')
426
+ ? { register: () => {}, unregister: () => {} }
427
+ : new FinalizationRegistry(ptr => wasm.__wbg_mecab_free(ptr >>> 0, 1));
428
+ const WasmTokenFinalization = (typeof FinalizationRegistry === 'undefined')
429
+ ? { register: () => {}, unregister: () => {} }
430
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmtoken_free(ptr >>> 0, 1));
431
+
432
+ function addHeapObject(obj) {
433
+ if (heap_next === heap.length) heap.push(heap.length + 1);
434
+ const idx = heap_next;
435
+ heap_next = heap[idx];
436
+
437
+ heap[idx] = obj;
438
+ return idx;
439
+ }
440
+
441
+ function dropObject(idx) {
442
+ if (idx < 1028) return;
443
+ heap[idx] = heap_next;
444
+ heap_next = idx;
445
+ }
446
+
447
+ function getArrayJsValueFromWasm0(ptr, len) {
448
+ ptr = ptr >>> 0;
449
+ const mem = getDataViewMemory0();
450
+ const result = [];
451
+ for (let i = ptr; i < ptr + 4 * len; i += 4) {
452
+ result.push(takeObject(mem.getUint32(i, true)));
453
+ }
454
+ return result;
455
+ }
456
+
457
+ let cachedDataViewMemory0 = null;
458
+ function getDataViewMemory0() {
459
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
460
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
461
+ }
462
+ return cachedDataViewMemory0;
463
+ }
464
+
465
+ function getStringFromWasm0(ptr, len) {
466
+ ptr = ptr >>> 0;
467
+ return decodeText(ptr, len);
468
+ }
469
+
470
+ let cachedUint8ArrayMemory0 = null;
471
+ function getUint8ArrayMemory0() {
472
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
473
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
474
+ }
475
+ return cachedUint8ArrayMemory0;
476
+ }
477
+
478
+ function getObject(idx) { return heap[idx]; }
479
+
480
+ let heap = new Array(1024).fill(undefined);
481
+ heap.push(undefined, null, true, false);
482
+
483
+ let heap_next = heap.length;
484
+
485
+ function passStringToWasm0(arg, malloc, realloc) {
486
+ if (realloc === undefined) {
487
+ const buf = cachedTextEncoder.encode(arg);
488
+ const ptr = malloc(buf.length, 1) >>> 0;
489
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
490
+ WASM_VECTOR_LEN = buf.length;
491
+ return ptr;
492
+ }
493
+
494
+ let len = arg.length;
495
+ let ptr = malloc(len, 1) >>> 0;
496
+
497
+ const mem = getUint8ArrayMemory0();
498
+
499
+ let offset = 0;
500
+
501
+ for (; offset < len; offset++) {
502
+ const code = arg.charCodeAt(offset);
503
+ if (code > 0x7F) break;
504
+ mem[ptr + offset] = code;
505
+ }
506
+ if (offset !== len) {
507
+ if (offset !== 0) {
508
+ arg = arg.slice(offset);
509
+ }
510
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
511
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
512
+ const ret = cachedTextEncoder.encodeInto(arg, view);
513
+
514
+ offset += ret.written;
515
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
516
+ }
517
+
518
+ WASM_VECTOR_LEN = offset;
519
+ return ptr;
520
+ }
521
+
522
+ function takeObject(idx) {
523
+ const ret = getObject(idx);
524
+ dropObject(idx);
525
+ return ret;
526
+ }
527
+
528
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
529
+ cachedTextDecoder.decode();
530
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
531
+ let numBytesDecoded = 0;
532
+ function decodeText(ptr, len) {
533
+ numBytesDecoded += len;
534
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
535
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
536
+ cachedTextDecoder.decode();
537
+ numBytesDecoded = len;
538
+ }
539
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
540
+ }
541
+
542
+ const cachedTextEncoder = new TextEncoder();
543
+
544
+ if (!('encodeInto' in cachedTextEncoder)) {
545
+ cachedTextEncoder.encodeInto = function (arg, view) {
546
+ const buf = cachedTextEncoder.encode(arg);
547
+ view.set(buf);
548
+ return {
549
+ read: arg.length,
550
+ written: buf.length
551
+ };
552
+ };
553
+ }
554
+
555
+ let WASM_VECTOR_LEN = 0;
556
+
557
+ let wasmModule, wasm;
558
+ function __wbg_finalize_init(instance, module) {
559
+ wasm = instance.exports;
560
+ wasmModule = module;
561
+ cachedDataViewMemory0 = null;
562
+ cachedUint8ArrayMemory0 = null;
563
+ wasm.__wbindgen_start();
564
+ return wasm;
565
+ }
566
+
567
+ async function __wbg_load(module, imports) {
568
+ if (typeof Response === 'function' && module instanceof Response) {
569
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
570
+ try {
571
+ return await WebAssembly.instantiateStreaming(module, imports);
572
+ } catch (e) {
573
+ const validResponse = module.ok && expectedResponseType(module.type);
574
+
575
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
576
+ console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
577
+
578
+ } else { throw e; }
579
+ }
580
+ }
581
+
582
+ const bytes = await module.arrayBuffer();
583
+ return await WebAssembly.instantiate(bytes, imports);
584
+ } else {
585
+ const instance = await WebAssembly.instantiate(module, imports);
586
+
587
+ if (instance instanceof WebAssembly.Instance) {
588
+ return { instance, module };
589
+ } else {
590
+ return instance;
591
+ }
592
+ }
593
+
594
+ function expectedResponseType(type) {
595
+ switch (type) {
596
+ case 'basic': case 'cors': case 'default': return true;
597
+ }
598
+ return false;
599
+ }
600
+ }
601
+
602
+ function initSync(module) {
603
+ if (wasm !== undefined) return wasm;
604
+
605
+
606
+ if (module !== undefined) {
607
+ if (Object.getPrototypeOf(module) === Object.prototype) {
608
+ ({module} = module)
609
+ } else {
610
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
611
+ }
612
+ }
613
+
614
+ const imports = __wbg_get_imports();
615
+ if (!(module instanceof WebAssembly.Module)) {
616
+ module = new WebAssembly.Module(module);
617
+ }
618
+ const instance = new WebAssembly.Instance(module, imports);
619
+ return __wbg_finalize_init(instance, module);
620
+ }
621
+
622
+ async function __wbg_init(module_or_path) {
623
+ if (wasm !== undefined) return wasm;
624
+
625
+
626
+ if (module_or_path !== undefined) {
627
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
628
+ ({module_or_path} = module_or_path)
629
+ } else {
630
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
631
+ }
632
+ }
633
+
634
+ if (module_or_path === undefined) {
635
+ module_or_path = new URL('mecab_ko_wasm_bg.wasm', import.meta.url);
636
+ }
637
+ const imports = __wbg_get_imports();
638
+
639
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
640
+ module_or_path = fetch(module_or_path);
641
+ }
642
+
643
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
644
+
645
+ return __wbg_finalize_init(instance, module);
646
+ }
647
+
648
+ export { initSync, __wbg_init as default };
Binary file