@laisuk/opencc-fmmseg-wasm 0.2.5 → 0.3.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.
- package/README.md +205 -21
- package/bin/opencc.js +5 -0
- package/opencc_fmmseg_wasm.d.ts +7 -1
- package/opencc_fmmseg_wasm.js +230 -1
- package/opencc_fmmseg_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -24,6 +24,13 @@ Features:
|
|
|
24
24
|
* In-memory Office / EPUB document conversion
|
|
25
25
|
* Zero-dependency Node.js CLI
|
|
26
26
|
|
|
27
|
+
Package profile:
|
|
28
|
+
|
|
29
|
+
* 0 runtime dependencies
|
|
30
|
+
* 1 WASM file
|
|
31
|
+
* 18 conversion configs
|
|
32
|
+
* 100% offline
|
|
33
|
+
|
|
27
34
|
---
|
|
28
35
|
|
|
29
36
|
## Installation
|
|
@@ -66,35 +73,39 @@ import init, {
|
|
|
66
73
|
await init();
|
|
67
74
|
|
|
68
75
|
const cc = OpenccWasm.newWithEnum(
|
|
69
|
-
OpenccConfigWasm.
|
|
76
|
+
OpenccConfigWasm.S2hkp
|
|
70
77
|
);
|
|
71
78
|
|
|
72
|
-
console.log(cc.convert("
|
|
73
|
-
//
|
|
79
|
+
console.log(cc.convert("别随便录影侵犯个人隐私权", false));
|
|
80
|
+
// 別隨便錄影侵犯個人私隱權
|
|
74
81
|
```
|
|
75
82
|
|
|
76
83
|
---
|
|
77
84
|
|
|
78
85
|
## Supported Configs
|
|
79
86
|
|
|
80
|
-
| Config | Description
|
|
81
|
-
|
|
82
|
-
| `s2t` | Simplified Chinese → Traditional Chinese
|
|
83
|
-
| `s2tw` | Simplified Chinese → Taiwan Traditional
|
|
84
|
-
| `s2twp` | Simplified Chinese → Taiwan Traditional (phrases)
|
|
85
|
-
| `s2hk` | Simplified Chinese → Hong Kong Traditional
|
|
86
|
-
| `
|
|
87
|
-
| `
|
|
88
|
-
| `
|
|
89
|
-
| `
|
|
90
|
-
| `
|
|
91
|
-
| `
|
|
92
|
-
| `
|
|
93
|
-
| `
|
|
94
|
-
| `
|
|
95
|
-
| `
|
|
96
|
-
| `
|
|
97
|
-
| `
|
|
87
|
+
| Config | Enum | Description |
|
|
88
|
+
|---------|--------------------------|------------------------------------------------------|
|
|
89
|
+
| `s2t` | `OpenccConfigWasm.S2t` | Simplified Chinese → Traditional Chinese |
|
|
90
|
+
| `s2tw` | `OpenccConfigWasm.S2tw` | Simplified Chinese → Taiwan Traditional |
|
|
91
|
+
| `s2twp` | `OpenccConfigWasm.S2twp` | Simplified Chinese → Taiwan Traditional (phrases) |
|
|
92
|
+
| `s2hk` | `OpenccConfigWasm.S2hk` | Simplified Chinese → Hong Kong Traditional |
|
|
93
|
+
| `s2hkp` | `OpenccConfigWasm.S2hkp` | Simplified Chinese → Hong Kong Traditional (phrases) |
|
|
94
|
+
| `t2s` | `OpenccConfigWasm.T2s` | Traditional Chinese → Simplified Chinese |
|
|
95
|
+
| `t2tw` | `OpenccConfigWasm.T2tw` | Traditional Chinese → Taiwan Traditional |
|
|
96
|
+
| `t2twp` | `OpenccConfigWasm.T2twp` | Traditional Chinese → Taiwan Traditional (phrases) |
|
|
97
|
+
| `t2hk` | `OpenccConfigWasm.T2hk` | Traditional Chinese → Hong Kong Traditional |
|
|
98
|
+
| `tw2s` | `OpenccConfigWasm.Tw2s` | Taiwan Traditional → Simplified Chinese |
|
|
99
|
+
| `tw2sp` | `OpenccConfigWasm.Tw2sp` | Taiwan Traditional → Simplified Chinese (phrases) |
|
|
100
|
+
| `tw2t` | `OpenccConfigWasm.Tw2t` | Taiwan Traditional → Traditional Chinese |
|
|
101
|
+
| `tw2tp` | `OpenccConfigWasm.Tw2tp` | Taiwan Traditional → Traditional Chinese (phrases) |
|
|
102
|
+
| `hk2s` | `OpenccConfigWasm.Hk2s` | Hong Kong Traditional → Simplified Chinese |
|
|
103
|
+
| `hk2sp` | `OpenccConfigWasm.Hk2sp` | Hong Kong Traditional → Simplified Chinese (phrases) |
|
|
104
|
+
| `hk2t` | `OpenccConfigWasm.Hk2t` | Hong Kong Traditional → Traditional Chinese |
|
|
105
|
+
| `jp2t` | `OpenccConfigWasm.Jp2t` | Japanese Shinjitai → Traditional Chinese |
|
|
106
|
+
| `t2jp` | `OpenccConfigWasm.T2jp` | Traditional Chinese → Japanese Shinjitai |
|
|
107
|
+
|
|
108
|
+
The numeric enum values match the vendored Rust backend. Existing values are unchanged; `S2hkp = 17` and `Hk2sp = 18`.
|
|
98
109
|
|
|
99
110
|
---
|
|
100
111
|
|
|
@@ -117,6 +128,15 @@ Example:
|
|
|
117
128
|
const cc = new OpenccWasm("t2s");
|
|
118
129
|
```
|
|
119
130
|
|
|
131
|
+
Hong Kong phrase config example:
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
const cc = new OpenccWasm("s2hkp");
|
|
135
|
+
|
|
136
|
+
cc.convert("别随便录影侵犯个人隐私权", false);
|
|
137
|
+
// 別隨便錄影侵犯個人私隱權
|
|
138
|
+
```
|
|
139
|
+
|
|
120
140
|
---
|
|
121
141
|
|
|
122
142
|
### convert
|
|
@@ -260,6 +280,8 @@ OpenccWasm.getSupportedConfigs();
|
|
|
260
280
|
|
|
261
281
|
Returns all supported config strings.
|
|
262
282
|
|
|
283
|
+
Includes `s2hkp` and `hk2sp`.
|
|
284
|
+
|
|
263
285
|
---
|
|
264
286
|
|
|
265
287
|
### zhoCheck
|
|
@@ -280,6 +302,137 @@ Returns:
|
|
|
280
302
|
|
|
281
303
|
---
|
|
282
304
|
|
|
305
|
+
### newWithCustomDicts
|
|
306
|
+
|
|
307
|
+
Construct a converter with in-memory custom dictionary pairs.
|
|
308
|
+
|
|
309
|
+
```javascript
|
|
310
|
+
const cc = OpenccWasm.newWithCustomDicts(config, specs);
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
Parameters:
|
|
314
|
+
|
|
315
|
+
* `config`: OpenCC config string, such as `"s2t"`
|
|
316
|
+
* `specs`: array of custom dictionary specs
|
|
317
|
+
|
|
318
|
+
TypeScript-style spec shape:
|
|
319
|
+
|
|
320
|
+
```typescript
|
|
321
|
+
type WasmCustomDictSpec = {
|
|
322
|
+
slot: string;
|
|
323
|
+
mode?: "Append" | "Override";
|
|
324
|
+
pairs: Array<[string, string]>;
|
|
325
|
+
};
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
`mode` defaults to `"Append"` when omitted.
|
|
329
|
+
|
|
330
|
+
Each `pairs` entry is a `[source, target]` string tuple for the selected slot.
|
|
331
|
+
|
|
332
|
+
TypeScript example:
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import init, {OpenccWasm} from "@laisuk/opencc-fmmseg-wasm";
|
|
336
|
+
|
|
337
|
+
await init();
|
|
338
|
+
|
|
339
|
+
const specs: WasmCustomDictSpec[] = [
|
|
340
|
+
{
|
|
341
|
+
slot: "STPhrases",
|
|
342
|
+
pairs: [
|
|
343
|
+
["云端", "雲端"]
|
|
344
|
+
]
|
|
345
|
+
}
|
|
346
|
+
];
|
|
347
|
+
|
|
348
|
+
const cc = OpenccWasm.newWithCustomDicts("s2t", specs);
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
Practical example:
|
|
352
|
+
|
|
353
|
+
```javascript
|
|
354
|
+
import init, {OpenccWasm} from "@laisuk/opencc-fmmseg-wasm";
|
|
355
|
+
|
|
356
|
+
await init();
|
|
357
|
+
|
|
358
|
+
const cc = OpenccWasm.newWithCustomDicts("s2t", [
|
|
359
|
+
{
|
|
360
|
+
slot: "STPhrases",
|
|
361
|
+
mode: "Append",
|
|
362
|
+
pairs: [
|
|
363
|
+
["帕兰蒂尔", "柏蘭蒂爾"],
|
|
364
|
+
["软件", "軟體"]
|
|
365
|
+
]
|
|
366
|
+
}
|
|
367
|
+
]);
|
|
368
|
+
|
|
369
|
+
console.log(cc.convert("帕兰蒂尔软件", false));
|
|
370
|
+
// 柏蘭蒂爾軟體
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Override example:
|
|
374
|
+
|
|
375
|
+
```javascript
|
|
376
|
+
const cc = OpenccWasm.newWithCustomDicts("s2t", [
|
|
377
|
+
{
|
|
378
|
+
slot: "STPhrases",
|
|
379
|
+
mode: "Override",
|
|
380
|
+
pairs: [
|
|
381
|
+
["软件", "軟體"]
|
|
382
|
+
]
|
|
383
|
+
}
|
|
384
|
+
]);
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
`Override` replaces the selected slot before inserting the provided pairs. It is powerful and should be used only when
|
|
388
|
+
the caller intentionally wants to discard built-in entries for that slot.
|
|
389
|
+
|
|
390
|
+
Custom dictionary specs use strict canonical `DictSlot` names:
|
|
391
|
+
|
|
392
|
+
```text
|
|
393
|
+
STPhrases
|
|
394
|
+
TSPhrases
|
|
395
|
+
STCharacters
|
|
396
|
+
TSCharacters
|
|
397
|
+
TWPhrases
|
|
398
|
+
TWPhrasesRev
|
|
399
|
+
HKPhrases
|
|
400
|
+
HKPhrasesRev
|
|
401
|
+
TWVariants
|
|
402
|
+
TWVariantsPhrases
|
|
403
|
+
TWVariantsRev
|
|
404
|
+
TWVariantsRevPhrases
|
|
405
|
+
HKVariants
|
|
406
|
+
HKVariantsPhrases
|
|
407
|
+
HKVariantsRev
|
|
408
|
+
HKVariantsRevPhrases
|
|
409
|
+
JPShinjitaiCharacters
|
|
410
|
+
JPShinjitaiPhrases
|
|
411
|
+
JPVariants
|
|
412
|
+
JPVariantsRev
|
|
413
|
+
STPunctuations
|
|
414
|
+
TSPunctuations
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
Suffixes such as `.txt` are not accepted. Use `"STPhrases"`, not `"STPhrases.txt"`.
|
|
418
|
+
|
|
419
|
+
Merge contract:
|
|
420
|
+
|
|
421
|
+
* Custom dictionaries are loaded from in-memory pairs only; no file I/O is involved.
|
|
422
|
+
* The embedded compressed CBOR dictionary is loaded first.
|
|
423
|
+
* Custom specs are applied to `DictionaryMaxlength` before `OpenCC::from_dictionary(...)`.
|
|
424
|
+
* Conversion hot paths remain immutable after construction.
|
|
425
|
+
* `Append` mode merges into the selected slot.
|
|
426
|
+
* Duplicate or conflicting keys use last-wins semantics.
|
|
427
|
+
* `Override` mode clears the selected slot first, then inserts the provided custom pairs.
|
|
428
|
+
* Multiple specs are applied in array order.
|
|
429
|
+
|
|
430
|
+
This API is useful for browser apps, user-defined terminology, database-loaded terms, generated dictionaries,
|
|
431
|
+
`localStorage` or `IndexedDB` terms, testing, and embedded WASM environments. Customization happens at construction
|
|
432
|
+
time, not during conversion.
|
|
433
|
+
|
|
434
|
+
---
|
|
435
|
+
|
|
283
436
|
## Office / EPUB Conversion
|
|
284
437
|
|
|
285
438
|
Office and EPUB conversion runs fully locally in the browser or Node.js. Files are passed in and returned as bytes;
|
|
@@ -391,6 +544,26 @@ fs.writeFileSync("output.docx", outputBytes);
|
|
|
391
544
|
</html>
|
|
392
545
|
```
|
|
393
546
|
|
|
547
|
+
> **Note**
|
|
548
|
+
>
|
|
549
|
+
> The npm package automatically loads the bundled WebAssembly module when
|
|
550
|
+
> installed normally via npm.
|
|
551
|
+
>
|
|
552
|
+
> If you are running examples directly from a local repository checkout,
|
|
553
|
+
> you may need to initialize using explicit WASM bytes:
|
|
554
|
+
>
|
|
555
|
+
> ```javascript
|
|
556
|
+
> import fs from "fs";
|
|
557
|
+
> import init from "../pkg/opencc_fmmseg_wasm.js";
|
|
558
|
+
>
|
|
559
|
+
> const wasmBytes = fs.readFileSync(
|
|
560
|
+
> "../pkg/opencc_fmmseg_wasm_bg.wasm"
|
|
561
|
+
> );
|
|
562
|
+
>
|
|
563
|
+
> await init({ module: wasmBytes });
|
|
564
|
+
> ```
|
|
565
|
+
>
|
|
566
|
+
|
|
394
567
|
---
|
|
395
568
|
|
|
396
569
|
## Node.js CLI
|
|
@@ -400,6 +573,7 @@ The package includes a zero-dependency Node.js CLI:
|
|
|
400
573
|
```bash
|
|
401
574
|
opencc-fmmseg convert -i input.txt -o output.txt -c s2t -p
|
|
402
575
|
opencc-fmmseg convert -i input.txt -o output.txt -c t2s -p --detofu all
|
|
576
|
+
echo "别随便录影侵犯个人隐私权" | opencc-fmmseg convert -c s2hkp
|
|
403
577
|
```
|
|
404
578
|
|
|
405
579
|
```bash
|
|
@@ -420,6 +594,13 @@ opencc-fmmseg office -i input.docx -o output.docx -c s2t -p --keep-font
|
|
|
420
594
|
--out-enc <encoding> Output encoding
|
|
421
595
|
```
|
|
422
596
|
|
|
597
|
+
Supported conversion configs:
|
|
598
|
+
|
|
599
|
+
```text
|
|
600
|
+
s2t, s2tw, s2twp, s2hk, s2hkp, t2s, t2tw, t2twp, t2hk,
|
|
601
|
+
tw2s, tw2sp, tw2t, tw2tp, hk2s, hk2sp, hk2t, jp2t, t2jp
|
|
602
|
+
```
|
|
603
|
+
|
|
423
604
|
### Office / EPUB Options
|
|
424
605
|
|
|
425
606
|
```text
|
|
@@ -449,6 +630,9 @@ The package includes generated TypeScript definitions from `wasm-bindgen`.
|
|
|
449
630
|
|
|
450
631
|
The WASM-facing enum is exported as `OpenccConfigWasm`, alongside `OpenccWasm`.
|
|
451
632
|
|
|
633
|
+
`OpenccConfigWasm.S2hkp` and `OpenccConfigWasm.Hk2sp` are available for Hong Kong phrase conversions and map to backend
|
|
634
|
+
config IDs `17` and `18`.
|
|
635
|
+
|
|
452
636
|
---
|
|
453
637
|
|
|
454
638
|
## Performance Notes
|
package/bin/opencc.js
CHANGED
|
@@ -60,6 +60,10 @@ Convert options:
|
|
|
60
60
|
--in-enc <encoding> Input encoding (default: utf8)
|
|
61
61
|
--out-enc <encoding> Output encoding (default: utf8)
|
|
62
62
|
|
|
63
|
+
Supported configs:
|
|
64
|
+
s2t, s2tw, s2twp, s2hk, s2hkp, t2s, t2tw, t2twp, t2hk,
|
|
65
|
+
tw2s, tw2sp, tw2t, tw2tp, hk2s, hk2sp, hk2t, jp2t, t2jp
|
|
66
|
+
|
|
63
67
|
Office options:
|
|
64
68
|
-i, --input <file> Input Office / EPUB file
|
|
65
69
|
-o, --output <file> Output file
|
|
@@ -77,6 +81,7 @@ Examples:
|
|
|
77
81
|
npx opencc-fmmseg convert -i a.txt -o b.txt -c s2t
|
|
78
82
|
npx opencc-fmmseg convert -i a.txt -o b.txt -c s2tw -p
|
|
79
83
|
cat a.txt | npx opencc-fmmseg convert -c t2s
|
|
84
|
+
echo "别随便录影侵犯个人隐私权" | npx opencc-fmmseg convert -c s2hkp
|
|
80
85
|
npx opencc-fmmseg convert -i a.txt -o b.txt -c t2s --detofu
|
|
81
86
|
npx opencc-fmmseg convert -i a.txt -o b.txt -c t2s --detofu ext-c
|
|
82
87
|
|
package/opencc_fmmseg_wasm.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export enum OpenccConfigWasm {
|
|
|
29
29
|
Hk2t = 14,
|
|
30
30
|
Jp2t = 15,
|
|
31
31
|
T2jp = 16,
|
|
32
|
+
S2hkp = 17,
|
|
33
|
+
Hk2sp = 18,
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
export class OpenccWasm {
|
|
@@ -43,6 +45,7 @@ export class OpenccWasm {
|
|
|
43
45
|
static getSupportedConfigs(): string[];
|
|
44
46
|
static isValidConfig(config: string): boolean;
|
|
45
47
|
constructor(config?: string | null);
|
|
48
|
+
static newWithCustomDicts(config: string | null | undefined, specs: any): OpenccWasm;
|
|
46
49
|
static newWithEnum(config?: OpenccConfigWasm | null): OpenccWasm;
|
|
47
50
|
setConfig(config: string): boolean;
|
|
48
51
|
setConfigEnum(config: OpenccConfigWasm): void;
|
|
@@ -66,13 +69,16 @@ export interface InitOutput {
|
|
|
66
69
|
readonly openccwasm_getSupportedConfigs: () => [number, number];
|
|
67
70
|
readonly openccwasm_isValidConfig: (a: number, b: number) => number;
|
|
68
71
|
readonly openccwasm_new: (a: number, b: number) => [number, number, number];
|
|
72
|
+
readonly openccwasm_newWithCustomDicts: (a: number, b: number, c: any) => [number, number, number];
|
|
69
73
|
readonly openccwasm_newWithEnum: (a: number) => [number, number, number];
|
|
70
74
|
readonly openccwasm_setConfig: (a: number, b: number, c: number) => number;
|
|
71
75
|
readonly openccwasm_setConfigEnum: (a: number, b: number) => void;
|
|
72
76
|
readonly openccwasm_zhoCheck: (a: number, b: number, c: number) => number;
|
|
73
|
-
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
74
77
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
75
78
|
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
79
|
+
readonly __wbindgen_exn_store: (a: number) => void;
|
|
80
|
+
readonly __externref_table_alloc: () => number;
|
|
81
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
76
82
|
readonly __externref_table_dealloc: (a: number) => void;
|
|
77
83
|
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
78
84
|
readonly __externref_drop_slice: (a: number, b: number) => void;
|
package/opencc_fmmseg_wasm.js
CHANGED
|
@@ -15,7 +15,7 @@ export const DetofuLevelWasm = Object.freeze({
|
|
|
15
15
|
});
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
|
-
* @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16}
|
|
18
|
+
* @enum {1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18}
|
|
19
19
|
*/
|
|
20
20
|
export const OpenccConfigWasm = Object.freeze({
|
|
21
21
|
S2t: 1, "1": "S2t",
|
|
@@ -34,6 +34,8 @@ export const OpenccConfigWasm = Object.freeze({
|
|
|
34
34
|
Hk2t: 14, "14": "Hk2t",
|
|
35
35
|
Jp2t: 15, "15": "Jp2t",
|
|
36
36
|
T2jp: 16, "16": "T2jp",
|
|
37
|
+
S2hkp: 17, "17": "S2hkp",
|
|
38
|
+
Hk2sp: 18, "18": "Hk2sp",
|
|
37
39
|
});
|
|
38
40
|
|
|
39
41
|
export class OpenccWasm {
|
|
@@ -181,6 +183,20 @@ export class OpenccWasm {
|
|
|
181
183
|
OpenccWasmFinalization.register(this, this.__wbg_ptr, this);
|
|
182
184
|
return this;
|
|
183
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* @param {string | null | undefined} config
|
|
188
|
+
* @param {any} specs
|
|
189
|
+
* @returns {OpenccWasm}
|
|
190
|
+
*/
|
|
191
|
+
static newWithCustomDicts(config, specs) {
|
|
192
|
+
var ptr0 = isLikeNone(config) ? 0 : passStringToWasm0(config, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
193
|
+
var len0 = WASM_VECTOR_LEN;
|
|
194
|
+
const ret = wasm.openccwasm_newWithCustomDicts(ptr0, len0, specs);
|
|
195
|
+
if (ret[2]) {
|
|
196
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
197
|
+
}
|
|
198
|
+
return OpenccWasm.__wrap(ret[0]);
|
|
199
|
+
}
|
|
184
200
|
/**
|
|
185
201
|
* @param {OpenccConfigWasm | null} [config]
|
|
186
202
|
* @returns {OpenccWasm}
|
|
@@ -247,9 +263,142 @@ export function convert_office_bytes(input, format, config, punctuation, keep_fo
|
|
|
247
263
|
function __wbg_get_imports() {
|
|
248
264
|
const import0 = {
|
|
249
265
|
__proto__: null,
|
|
266
|
+
__wbg_Error_ef53bc310eb298a0: function(arg0, arg1) {
|
|
267
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
268
|
+
return ret;
|
|
269
|
+
},
|
|
270
|
+
__wbg_String_8564e559799eccda: function(arg0, arg1) {
|
|
271
|
+
const ret = String(arg1);
|
|
272
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
273
|
+
const len1 = WASM_VECTOR_LEN;
|
|
274
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
275
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
276
|
+
},
|
|
277
|
+
__wbg___wbindgen_boolean_get_1a45e2c38d4d41b9: function(arg0) {
|
|
278
|
+
const v = arg0;
|
|
279
|
+
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
280
|
+
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
281
|
+
},
|
|
282
|
+
__wbg___wbindgen_debug_string_0accd80f45e5faa2: function(arg0, arg1) {
|
|
283
|
+
const ret = debugString(arg1);
|
|
284
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
285
|
+
const len1 = WASM_VECTOR_LEN;
|
|
286
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
287
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
288
|
+
},
|
|
289
|
+
__wbg___wbindgen_in_70a403a56e771704: function(arg0, arg1) {
|
|
290
|
+
const ret = arg0 in arg1;
|
|
291
|
+
return ret;
|
|
292
|
+
},
|
|
293
|
+
__wbg___wbindgen_is_function_754e9f305ff6029e: function(arg0) {
|
|
294
|
+
const ret = typeof(arg0) === 'function';
|
|
295
|
+
return ret;
|
|
296
|
+
},
|
|
297
|
+
__wbg___wbindgen_is_object_56732c2bc353f41d: function(arg0) {
|
|
298
|
+
const val = arg0;
|
|
299
|
+
const ret = typeof(val) === 'object' && val !== null;
|
|
300
|
+
return ret;
|
|
301
|
+
},
|
|
302
|
+
__wbg___wbindgen_is_undefined_67b456be8673d3d7: function(arg0) {
|
|
303
|
+
const ret = arg0 === undefined;
|
|
304
|
+
return ret;
|
|
305
|
+
},
|
|
306
|
+
__wbg___wbindgen_jsval_loose_eq_2c56564c75129511: function(arg0, arg1) {
|
|
307
|
+
const ret = arg0 == arg1;
|
|
308
|
+
return ret;
|
|
309
|
+
},
|
|
310
|
+
__wbg___wbindgen_number_get_9bb1761122181af2: function(arg0, arg1) {
|
|
311
|
+
const obj = arg1;
|
|
312
|
+
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
313
|
+
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
314
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
315
|
+
},
|
|
316
|
+
__wbg___wbindgen_string_get_72bdf95d3ae505b1: function(arg0, arg1) {
|
|
317
|
+
const obj = arg1;
|
|
318
|
+
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
319
|
+
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
320
|
+
var len1 = WASM_VECTOR_LEN;
|
|
321
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
322
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
323
|
+
},
|
|
250
324
|
__wbg___wbindgen_throw_1506f2235d1bdba0: function(arg0, arg1) {
|
|
251
325
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
252
326
|
},
|
|
327
|
+
__wbg_call_8a89609d89f6608a: function() { return handleError(function (arg0, arg1) {
|
|
328
|
+
const ret = arg0.call(arg1);
|
|
329
|
+
return ret;
|
|
330
|
+
}, arguments); },
|
|
331
|
+
__wbg_done_60cf307fcc680536: function(arg0) {
|
|
332
|
+
const ret = arg0.done;
|
|
333
|
+
return ret;
|
|
334
|
+
},
|
|
335
|
+
__wbg_get_1f8f054ddbaa7db2: function() { return handleError(function (arg0, arg1) {
|
|
336
|
+
const ret = Reflect.get(arg0, arg1);
|
|
337
|
+
return ret;
|
|
338
|
+
}, arguments); },
|
|
339
|
+
__wbg_get_unchecked_33f6e5c9e2f2d6b2: function(arg0, arg1) {
|
|
340
|
+
const ret = arg0[arg1 >>> 0];
|
|
341
|
+
return ret;
|
|
342
|
+
},
|
|
343
|
+
__wbg_get_with_ref_key_6412cf3094599694: function(arg0, arg1) {
|
|
344
|
+
const ret = arg0[arg1];
|
|
345
|
+
return ret;
|
|
346
|
+
},
|
|
347
|
+
__wbg_instanceof_ArrayBuffer_8f49811467741499: function(arg0) {
|
|
348
|
+
let result;
|
|
349
|
+
try {
|
|
350
|
+
result = arg0 instanceof ArrayBuffer;
|
|
351
|
+
} catch (_) {
|
|
352
|
+
result = false;
|
|
353
|
+
}
|
|
354
|
+
const ret = result;
|
|
355
|
+
return ret;
|
|
356
|
+
},
|
|
357
|
+
__wbg_instanceof_Uint8Array_86f30649f63ef9c2: function(arg0) {
|
|
358
|
+
let result;
|
|
359
|
+
try {
|
|
360
|
+
result = arg0 instanceof Uint8Array;
|
|
361
|
+
} catch (_) {
|
|
362
|
+
result = false;
|
|
363
|
+
}
|
|
364
|
+
const ret = result;
|
|
365
|
+
return ret;
|
|
366
|
+
},
|
|
367
|
+
__wbg_isArray_67c2c9c4313f4448: function(arg0) {
|
|
368
|
+
const ret = Array.isArray(arg0);
|
|
369
|
+
return ret;
|
|
370
|
+
},
|
|
371
|
+
__wbg_iterator_8732428d309e270e: function() {
|
|
372
|
+
const ret = Symbol.iterator;
|
|
373
|
+
return ret;
|
|
374
|
+
},
|
|
375
|
+
__wbg_length_4a591ecaa01354d9: function(arg0) {
|
|
376
|
+
const ret = arg0.length;
|
|
377
|
+
return ret;
|
|
378
|
+
},
|
|
379
|
+
__wbg_length_66f1a4b2e9026940: function(arg0) {
|
|
380
|
+
const ret = arg0.length;
|
|
381
|
+
return ret;
|
|
382
|
+
},
|
|
383
|
+
__wbg_new_578aeef4b6b94378: function(arg0) {
|
|
384
|
+
const ret = new Uint8Array(arg0);
|
|
385
|
+
return ret;
|
|
386
|
+
},
|
|
387
|
+
__wbg_next_9e03acdf51c4960d: function(arg0) {
|
|
388
|
+
const ret = arg0.next;
|
|
389
|
+
return ret;
|
|
390
|
+
},
|
|
391
|
+
__wbg_next_eb8ca7351fa27906: function() { return handleError(function (arg0) {
|
|
392
|
+
const ret = arg0.next();
|
|
393
|
+
return ret;
|
|
394
|
+
}, arguments); },
|
|
395
|
+
__wbg_prototypesetcall_3249fc62a0fafa30: function(arg0, arg1, arg2) {
|
|
396
|
+
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
397
|
+
},
|
|
398
|
+
__wbg_value_f3625092ee4b37f4: function(arg0) {
|
|
399
|
+
const ret = arg0.value;
|
|
400
|
+
return ret;
|
|
401
|
+
},
|
|
253
402
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
254
403
|
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
255
404
|
const ret = getStringFromWasm0(arg0, arg1);
|
|
@@ -275,6 +424,77 @@ const OpenccWasmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
|
275
424
|
? { register: () => {}, unregister: () => {} }
|
|
276
425
|
: new FinalizationRegistry(ptr => wasm.__wbg_openccwasm_free(ptr, 1));
|
|
277
426
|
|
|
427
|
+
function addToExternrefTable0(obj) {
|
|
428
|
+
const idx = wasm.__externref_table_alloc();
|
|
429
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
430
|
+
return idx;
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
function debugString(val) {
|
|
434
|
+
// primitive types
|
|
435
|
+
const type = typeof val;
|
|
436
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
437
|
+
return `${val}`;
|
|
438
|
+
}
|
|
439
|
+
if (type == 'string') {
|
|
440
|
+
return `"${val}"`;
|
|
441
|
+
}
|
|
442
|
+
if (type == 'symbol') {
|
|
443
|
+
const description = val.description;
|
|
444
|
+
if (description == null) {
|
|
445
|
+
return 'Symbol';
|
|
446
|
+
} else {
|
|
447
|
+
return `Symbol(${description})`;
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
if (type == 'function') {
|
|
451
|
+
const name = val.name;
|
|
452
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
453
|
+
return `Function(${name})`;
|
|
454
|
+
} else {
|
|
455
|
+
return 'Function';
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
// objects
|
|
459
|
+
if (Array.isArray(val)) {
|
|
460
|
+
const length = val.length;
|
|
461
|
+
let debug = '[';
|
|
462
|
+
if (length > 0) {
|
|
463
|
+
debug += debugString(val[0]);
|
|
464
|
+
}
|
|
465
|
+
for(let i = 1; i < length; i++) {
|
|
466
|
+
debug += ', ' + debugString(val[i]);
|
|
467
|
+
}
|
|
468
|
+
debug += ']';
|
|
469
|
+
return debug;
|
|
470
|
+
}
|
|
471
|
+
// Test for built-in
|
|
472
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
473
|
+
let className;
|
|
474
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
475
|
+
className = builtInMatches[1];
|
|
476
|
+
} else {
|
|
477
|
+
// Failed to match the standard '[object ClassName]'
|
|
478
|
+
return toString.call(val);
|
|
479
|
+
}
|
|
480
|
+
if (className == 'Object') {
|
|
481
|
+
// we're a user defined class or Object
|
|
482
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
483
|
+
// easier than looping through ownProperties of `val`.
|
|
484
|
+
try {
|
|
485
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
486
|
+
} catch (_) {
|
|
487
|
+
return 'Object';
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
// errors
|
|
491
|
+
if (val instanceof Error) {
|
|
492
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
493
|
+
}
|
|
494
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
495
|
+
return className;
|
|
496
|
+
}
|
|
497
|
+
|
|
278
498
|
function getArrayJsValueFromWasm0(ptr, len) {
|
|
279
499
|
ptr = ptr >>> 0;
|
|
280
500
|
const mem = getDataViewMemory0();
|
|
@@ -311,6 +531,15 @@ function getUint8ArrayMemory0() {
|
|
|
311
531
|
return cachedUint8ArrayMemory0;
|
|
312
532
|
}
|
|
313
533
|
|
|
534
|
+
function handleError(f, args) {
|
|
535
|
+
try {
|
|
536
|
+
return f.apply(this, args);
|
|
537
|
+
} catch (e) {
|
|
538
|
+
const idx = addToExternrefTable0(e);
|
|
539
|
+
wasm.__wbindgen_exn_store(idx);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
314
543
|
function isLikeNone(x) {
|
|
315
544
|
return x === undefined || x === null;
|
|
316
545
|
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@laisuk/opencc-fmmseg-wasm",
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "WebAssembly bindings for opencc-fmmseg, a high-performance OpenCC-compatible Simplified/Traditional Chinese converter.",
|
|
5
|
-
"version": "0.
|
|
5
|
+
"version": "0.3.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|