@laisuk/opencc-fmmseg-wasm 0.3.2 → 0.3.4
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 +40 -14
- package/bin/opencc.js +140 -25
- package/opencc_fmmseg_wasm.d.ts +6 -0
- package/opencc_fmmseg_wasm.js +59 -26
- package/opencc_fmmseg_wasm_bg.wasm +0 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -387,7 +387,9 @@ const cc = OpenccWasm.newWithCustomDicts("s2t", [
|
|
|
387
387
|
`Override` replaces the selected slot before inserting the provided pairs. It is powerful and should be used only when
|
|
388
388
|
the caller intentionally wants to discard built-in entries for that slot.
|
|
389
389
|
|
|
390
|
-
Custom dictionary specs
|
|
390
|
+
Custom dictionary specs identify the target dictionary slot by `DictSlot` name. Slot names are trimmed and normalized
|
|
391
|
+
case-insensitively for the known slots, so `"stphrases"`, `" STPhrases "`, and `"STPhrases"` all select
|
|
392
|
+
`STPhrases`. Canonical names are recommended in TypeScript code and docs:
|
|
391
393
|
|
|
392
394
|
```text
|
|
393
395
|
STPhrases
|
|
@@ -406,15 +408,15 @@ HKVariants
|
|
|
406
408
|
HKVariantsPhrases
|
|
407
409
|
HKVariantsRev
|
|
408
410
|
HKVariantsRevPhrases
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
JPVariantsRev
|
|
411
|
+
JPSCharacters
|
|
412
|
+
JPSCharactersRev
|
|
413
|
+
JPSPhrases
|
|
413
414
|
STPunctuations
|
|
414
415
|
TSPunctuations
|
|
415
416
|
```
|
|
416
417
|
|
|
417
|
-
Suffixes such as `.txt` are not accepted
|
|
418
|
+
Suffixes such as `.txt` are not accepted, even though case and surrounding whitespace are normalized. Use
|
|
419
|
+
`"STPhrases"` or `"stphrases"`, not `"STPhrases.txt"`.
|
|
418
420
|
|
|
419
421
|
Merge contract:
|
|
420
422
|
|
|
@@ -447,15 +449,17 @@ docx, xlsx, pptx, odt, ods, odp, epub
|
|
|
447
449
|
File size is limited by available browser or Node.js memory, but there is no upload or server-side limit. Font
|
|
448
450
|
preservation is supported with the `keepFont` option.
|
|
449
451
|
|
|
452
|
+
Use the instance method when possible. It reuses the converter configuration and any custom dictionaries already held by
|
|
453
|
+
the `OpenccWasm` instance.
|
|
454
|
+
|
|
450
455
|
```javascript
|
|
451
|
-
|
|
456
|
+
cc.convertOfficeBytes(inputBytes, format, punctuation, keepFont)
|
|
452
457
|
```
|
|
453
458
|
|
|
454
459
|
Parameters:
|
|
455
460
|
|
|
456
461
|
* `inputBytes`: `Uint8Array` document bytes
|
|
457
462
|
* `format`: `docx`, `xlsx`, `pptx`, `odt`, `ods`, `odp`, or `epub`
|
|
458
|
-
* `config`: OpenCC config string, such as `"s2t"`
|
|
459
463
|
* `punctuation`: whether to convert punctuation variants
|
|
460
464
|
* `keepFont`: whether to preserve font declarations where supported
|
|
461
465
|
|
|
@@ -463,20 +467,26 @@ Returns:
|
|
|
463
467
|
|
|
464
468
|
* converted output bytes
|
|
465
469
|
|
|
470
|
+
The older free function remains available for compatibility:
|
|
471
|
+
|
|
472
|
+
```javascript
|
|
473
|
+
convert_office_bytes(inputBytes, format, config, punctuation, keepFont)
|
|
474
|
+
```
|
|
475
|
+
|
|
466
476
|
### Browser Office Example
|
|
467
477
|
|
|
468
478
|
```javascript
|
|
469
|
-
import init, {
|
|
479
|
+
import init, {OpenccWasm} from "@laisuk/opencc-fmmseg-wasm";
|
|
470
480
|
|
|
471
481
|
await init();
|
|
472
482
|
|
|
483
|
+
const cc = new OpenccWasm("s2t");
|
|
473
484
|
const file = document.querySelector("input[type=file]").files[0];
|
|
474
485
|
const inputBytes = new Uint8Array(await file.arrayBuffer());
|
|
475
486
|
|
|
476
|
-
const outputBytes =
|
|
487
|
+
const outputBytes = cc.convertOfficeBytes(
|
|
477
488
|
inputBytes,
|
|
478
489
|
"docx",
|
|
479
|
-
"s2t",
|
|
480
490
|
true,
|
|
481
491
|
true
|
|
482
492
|
);
|
|
@@ -496,16 +506,16 @@ URL.revokeObjectURL(a.href);
|
|
|
496
506
|
|
|
497
507
|
```javascript
|
|
498
508
|
import fs from "fs";
|
|
499
|
-
import init, {
|
|
509
|
+
import init, {OpenccWasm} from "@laisuk/opencc-fmmseg-wasm";
|
|
500
510
|
|
|
501
511
|
await init();
|
|
502
512
|
|
|
513
|
+
const cc = new OpenccWasm("s2t");
|
|
503
514
|
const inputBytes = fs.readFileSync("input.docx");
|
|
504
515
|
|
|
505
|
-
const outputBytes =
|
|
516
|
+
const outputBytes = cc.convertOfficeBytes(
|
|
506
517
|
inputBytes,
|
|
507
518
|
"docx",
|
|
508
|
-
"s2t",
|
|
509
519
|
true,
|
|
510
520
|
true
|
|
511
521
|
);
|
|
@@ -574,6 +584,16 @@ The package includes a zero-dependency Node.js CLI:
|
|
|
574
584
|
opencc-fmmseg convert -i input.txt -o output.txt -c s2t -p
|
|
575
585
|
opencc-fmmseg convert -i input.txt -o output.txt -c t2s -p --detofu all
|
|
576
586
|
echo "别随便录影侵犯个人隐私权" | opencc-fmmseg convert -c s2hkp
|
|
587
|
+
echo "這個細路哥很靈活" | opencc-fmmseg convert -c hk2sp --custom-dict hkphrasesrev:append:my_hk_dict.txt
|
|
588
|
+
// 这个小男孩很灵活
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
my_hk_dict.txt:
|
|
592
|
+
|
|
593
|
+
```
|
|
594
|
+
# Custom Dictionary
|
|
595
|
+
|
|
596
|
+
細路哥 小男孩
|
|
577
597
|
```
|
|
578
598
|
|
|
579
599
|
```bash
|
|
@@ -590,6 +610,12 @@ opencc-fmmseg office -i input.docx -o output.docx -c s2t -p --keep-font
|
|
|
590
610
|
--detofu [level] Replace tofu-risk rare CJK extension chars after conversion
|
|
591
611
|
level: all | ext-b | ext-c | ext-d | ext-e | ext-f | ext-g | ext-h | ext-i
|
|
592
612
|
default when omitted value: all
|
|
613
|
+
--custom-dict <slot:mode:file>
|
|
614
|
+
Load a custom dictionary.
|
|
615
|
+
May be specified multiple times.
|
|
616
|
+
Examples:
|
|
617
|
+
--custom-dict hkphrasesrev:append:my_hk_dict.txt
|
|
618
|
+
--custom-dict stphrases:override:terms.txt
|
|
593
619
|
--in-enc <encoding> Input encoding
|
|
594
620
|
--out-enc <encoding> Output encoding
|
|
595
621
|
```
|
package/bin/opencc.js
CHANGED
|
@@ -6,8 +6,7 @@ import process from "process";
|
|
|
6
6
|
|
|
7
7
|
import init, {
|
|
8
8
|
OpenccWasm,
|
|
9
|
-
DetofuLevelWasm
|
|
10
|
-
convert_office_bytes
|
|
9
|
+
DetofuLevelWasm
|
|
11
10
|
} from "../opencc_fmmseg_wasm.js";
|
|
12
11
|
|
|
13
12
|
const OFFICE_FORMATS = new Set([
|
|
@@ -57,6 +56,13 @@ Convert options:
|
|
|
57
56
|
--detofu [level] Replace tofu-risk rare CJK extension chars after conversion
|
|
58
57
|
level: all | ext-b | ext-c | ext-d | ext-e | ext-f | ext-g | ext-h | ext-i
|
|
59
58
|
default when omitted value: all
|
|
59
|
+
--keep-ids Preserve complete IDS expressions during conversion (default: false)
|
|
60
|
+
--custom-dict <slot:mode:file>
|
|
61
|
+
Load a custom dictionary.
|
|
62
|
+
May be specified multiple times.
|
|
63
|
+
Examples:
|
|
64
|
+
--custom-dict hkphrasesrev:append:my_hk_dict.txt
|
|
65
|
+
--custom-dict stphrases:override:terms.txt
|
|
60
66
|
--in-enc <encoding> Input encoding (default: utf8)
|
|
61
67
|
--out-enc <encoding> Output encoding (default: utf8)
|
|
62
68
|
|
|
@@ -70,9 +76,15 @@ Office options:
|
|
|
70
76
|
-c, --config <conversion> Conversion config (default: s2t)
|
|
71
77
|
-p, --punct Enable punctuation conversion
|
|
72
78
|
--format <format> docx | xlsx | pptx | odt | ods | odp | epub
|
|
73
|
-
--
|
|
79
|
+
--convert-filename Convert generated output filename stem (default: false)
|
|
74
80
|
--keep-font Preserve font-family information (default)
|
|
75
81
|
--no-keep-font Do not preserve font-family information
|
|
82
|
+
--custom-dict <slot:mode:file>
|
|
83
|
+
Load a custom dictionary.
|
|
84
|
+
May be specified multiple times.
|
|
85
|
+
Examples:
|
|
86
|
+
--custom-dict hkphrasesrev:append:my_hk_dict.txt
|
|
87
|
+
--custom-dict stphrases:override:terms.txt
|
|
76
88
|
|
|
77
89
|
General options:
|
|
78
90
|
-h, --help Show help
|
|
@@ -84,9 +96,12 @@ Examples:
|
|
|
84
96
|
echo "别随便录影侵犯个人隐私权" | npx opencc-fmmseg convert -c s2hkp
|
|
85
97
|
npx opencc-fmmseg convert -i a.txt -o b.txt -c t2s --detofu
|
|
86
98
|
npx opencc-fmmseg convert -i a.txt -o b.txt -c t2s --detofu ext-c
|
|
99
|
+
echo "⿰氵漢" | npx opencc-fmmseg convert -c t2s
|
|
100
|
+
echo "⿰氵漢" | npx opencc-fmmseg convert -c t2s --keep-ids
|
|
87
101
|
|
|
88
102
|
npx opencc-fmmseg office -i a.docx -o b.docx -c s2t -p
|
|
89
|
-
npx opencc-fmmseg office -i a.epub -c s2tw
|
|
103
|
+
npx opencc-fmmseg office -i a.epub -c s2tw
|
|
104
|
+
npx opencc-fmmseg office -i 软件手册.docx -c s2t --convert-filename
|
|
90
105
|
`);
|
|
91
106
|
}
|
|
92
107
|
|
|
@@ -111,6 +126,91 @@ function getArg(args, shortName, longName, defaultValue = null) {
|
|
|
111
126
|
return defaultValue;
|
|
112
127
|
}
|
|
113
128
|
|
|
129
|
+
function getArgs(args, longName) {
|
|
130
|
+
const values = [];
|
|
131
|
+
|
|
132
|
+
for (let i = 0; i < args.length; i++) {
|
|
133
|
+
if (args[i] === longName && i + 1 < args.length) {
|
|
134
|
+
values.push(parseCustomDictSpec(args[i + 1]));
|
|
135
|
+
i++;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return values;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function parseCustomDictSpec(value) {
|
|
143
|
+
const first = value.indexOf(":");
|
|
144
|
+
const second = value.indexOf(":", first + 1);
|
|
145
|
+
|
|
146
|
+
if (first < 0 || second < 0) {
|
|
147
|
+
throw new Error(
|
|
148
|
+
`Invalid custom dictionary specification: ${value}\n` +
|
|
149
|
+
"Expected: <slot>:<append|override>:<file>"
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const slot = value.substring(0, first).trim();
|
|
154
|
+
const mode = value.substring(first + 1, second).trim();
|
|
155
|
+
const file = value.substring(second + 1).trim();
|
|
156
|
+
|
|
157
|
+
if (!slot) throw new Error("Custom dictionary slot is empty.");
|
|
158
|
+
if (!mode) throw new Error("Custom dictionary mode is empty.");
|
|
159
|
+
if (!file) throw new Error("Custom dictionary file is empty.");
|
|
160
|
+
|
|
161
|
+
return {
|
|
162
|
+
slot,
|
|
163
|
+
mode,
|
|
164
|
+
pairs: loadCustomDictPairs(file)
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function loadCustomDictPairs(file) {
|
|
169
|
+
if (!fs.existsSync(file)) {
|
|
170
|
+
throw new Error(`Custom dictionary file not found: ${file}`);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const text = fs.readFileSync(file, "utf8");
|
|
174
|
+
const lines = text.split(/\r?\n/);
|
|
175
|
+
const pairs = [];
|
|
176
|
+
|
|
177
|
+
for (let i = 0; i < lines.length; i++) {
|
|
178
|
+
let line = lines[i].replace(/\r$/, "");
|
|
179
|
+
|
|
180
|
+
if (i === 0 && line.charCodeAt(0) === 0xfeff) {
|
|
181
|
+
line = line.slice(1);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
line = line.trimEnd();
|
|
185
|
+
|
|
186
|
+
if (!line || line.startsWith("#")) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const tab = line.indexOf("\t");
|
|
191
|
+
|
|
192
|
+
if (tab < 0) {
|
|
193
|
+
throw new Error(
|
|
194
|
+
`Invalid custom dictionary file ${file}:${i + 1}: missing TAB separator`
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const source = line.substring(0, tab);
|
|
199
|
+
const values = line.substring(tab + 1).trim().split(/\s+/);
|
|
200
|
+
const target = values[0] || "";
|
|
201
|
+
|
|
202
|
+
if (!source || !target) {
|
|
203
|
+
throw new Error(
|
|
204
|
+
`Invalid custom dictionary file ${file}:${i + 1}: empty source or target`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
pairs.push([source, target]);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return pairs;
|
|
212
|
+
}
|
|
213
|
+
|
|
114
214
|
function hasFlag(args, shortName, longName) {
|
|
115
215
|
return (
|
|
116
216
|
(shortName && args.includes(shortName)) ||
|
|
@@ -166,24 +266,20 @@ function inferOfficeFormat(inputFile, explicitFormat) {
|
|
|
166
266
|
return ext;
|
|
167
267
|
}
|
|
168
268
|
|
|
169
|
-
function makeDefaultOfficeOutput(inputFile, officeFormat,
|
|
269
|
+
function makeDefaultOfficeOutput(inputFile, officeFormat, convertFilename, cc, config, punct) {
|
|
170
270
|
const parsed = path.parse(inputFile);
|
|
171
|
-
const
|
|
172
|
-
?
|
|
173
|
-
: parsed.
|
|
271
|
+
const stem = convertFilename
|
|
272
|
+
? cc.convert(parsed.name, punct)
|
|
273
|
+
: parsed.name;
|
|
174
274
|
|
|
175
275
|
return path.join(
|
|
176
276
|
parsed.dir || process.cwd(),
|
|
177
|
-
`${
|
|
277
|
+
`${stem}_converted.${officeFormat}`
|
|
178
278
|
);
|
|
179
279
|
}
|
|
180
280
|
|
|
181
|
-
function
|
|
182
|
-
if (
|
|
183
|
-
return outputFile;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
if (!OFFICE_FORMATS.has(officeFormat)) {
|
|
281
|
+
function applyOutputExtension(outputFile, officeFormat) {
|
|
282
|
+
if (path.extname(outputFile)) {
|
|
187
283
|
return outputFile;
|
|
188
284
|
}
|
|
189
285
|
|
|
@@ -247,6 +343,8 @@ async function runConvert(args) {
|
|
|
247
343
|
const inEnc = getArg(args, null, "--in-enc", "utf8");
|
|
248
344
|
const outEnc = getArg(args, null, "--out-enc", "utf8");
|
|
249
345
|
const punct = hasFlag(args, "-p", "--punct");
|
|
346
|
+
const keepIds = hasFlag(args, null, "--keep-ids");
|
|
347
|
+
const customDicts = getArgs(args, "--custom-dict");
|
|
250
348
|
|
|
251
349
|
const detofuIndex = args.indexOf("--detofu");
|
|
252
350
|
const detofuEnabled = detofuIndex !== -1;
|
|
@@ -264,7 +362,14 @@ async function runConvert(args) {
|
|
|
264
362
|
|
|
265
363
|
await ensureWasmInitialized();
|
|
266
364
|
|
|
267
|
-
const cc = new OpenccWasm(config);
|
|
365
|
+
// const cc = new OpenccWasm(config);
|
|
366
|
+
const cc = customDicts.length === 0
|
|
367
|
+
? new OpenccWasm(config)
|
|
368
|
+
: OpenccWasm.newWithCustomDicts(config, customDicts);
|
|
369
|
+
|
|
370
|
+
if (keepIds) {
|
|
371
|
+
cc.setPreserveIds(true);
|
|
372
|
+
}
|
|
268
373
|
|
|
269
374
|
// Prompt user if reading from interactive terminal
|
|
270
375
|
if (!input && process.stdin.isTTY) {
|
|
@@ -288,8 +393,12 @@ async function runConvert(args) {
|
|
|
288
393
|
console.error();
|
|
289
394
|
}
|
|
290
395
|
|
|
291
|
-
const
|
|
292
|
-
|
|
396
|
+
const suffixParts = [];
|
|
397
|
+
if (detofuEnabled) suffixParts.push("detofu");
|
|
398
|
+
if (keepIds) suffixParts.push("keep-ids");
|
|
399
|
+
|
|
400
|
+
const suffix = suffixParts.length ? `, ${suffixParts.join(", ")}` : "";
|
|
401
|
+
console.error(`Conversion completed (${cc.getConfig()}${suffix}): ${inFrom} -> ${outTo}`);
|
|
293
402
|
}
|
|
294
403
|
}
|
|
295
404
|
|
|
@@ -299,8 +408,9 @@ async function runOffice(args) {
|
|
|
299
408
|
const config = getArg(args, "-c", "--config", "s2t");
|
|
300
409
|
const explicitFormat = getArg(args, null, "--format");
|
|
301
410
|
const punct = hasFlag(args, "-p", "--punct");
|
|
302
|
-
const
|
|
411
|
+
const convertFilename = hasFlag(args, null, "--convert-filename");
|
|
303
412
|
const keepFont = !hasFlag(args, null, "--no-keep-font");
|
|
413
|
+
const customDicts = getArgs(args, "--custom-dict");
|
|
304
414
|
|
|
305
415
|
if (!input) {
|
|
306
416
|
throw new Error("Input file is missing.");
|
|
@@ -312,18 +422,23 @@ async function runOffice(args) {
|
|
|
312
422
|
|
|
313
423
|
const officeFormat = inferOfficeFormat(input, explicitFormat);
|
|
314
424
|
|
|
425
|
+
await ensureWasmInitialized();
|
|
426
|
+
|
|
427
|
+
// const cc = new OpenccWasm(config);
|
|
428
|
+
const cc = customDicts.length === 0
|
|
429
|
+
? new OpenccWasm(config)
|
|
430
|
+
: OpenccWasm.newWithCustomDicts(config, customDicts);
|
|
431
|
+
|
|
315
432
|
if (!output) {
|
|
316
|
-
output = makeDefaultOfficeOutput(input, officeFormat,
|
|
433
|
+
output = makeDefaultOfficeOutput(input, officeFormat, convertFilename, cc, config, punct);
|
|
317
434
|
console.error(`Output file not specified. Using: ${output}`);
|
|
318
435
|
} else {
|
|
319
|
-
output =
|
|
436
|
+
output = applyOutputExtension(output, officeFormat);
|
|
320
437
|
}
|
|
321
438
|
|
|
322
|
-
await ensureWasmInitialized();
|
|
323
|
-
|
|
324
439
|
const inputBytes = fs.readFileSync(input);
|
|
325
440
|
|
|
326
|
-
const outputBytes =
|
|
441
|
+
const outputBytes = cc.convertOfficeBytes(
|
|
327
442
|
inputBytes,
|
|
328
443
|
officeFormat,
|
|
329
444
|
config,
|
|
@@ -333,7 +448,7 @@ async function runOffice(args) {
|
|
|
333
448
|
|
|
334
449
|
fs.writeFileSync(output, outputBytes);
|
|
335
450
|
|
|
336
|
-
console.error(`Conversion completed (${
|
|
451
|
+
console.error(`Conversion completed (${cc.getConfig()}, ${officeFormat}): ${input} -> ${output}`);
|
|
337
452
|
}
|
|
338
453
|
|
|
339
454
|
async function main() {
|
package/opencc_fmmseg_wasm.d.ts
CHANGED
|
@@ -38,10 +38,12 @@ export class OpenccWasm {
|
|
|
38
38
|
[Symbol.dispose](): void;
|
|
39
39
|
convert(text: string, punctuation: boolean): string;
|
|
40
40
|
convertDetofu(text: string, punctuation: boolean, level: DetofuLevelWasm): string;
|
|
41
|
+
convertOfficeBytes(input: Uint8Array, format: string, punctuation: boolean, keep_font: boolean): Uint8Array;
|
|
41
42
|
debugPing(): string;
|
|
42
43
|
detofu(text: string, level: DetofuLevelWasm): string;
|
|
43
44
|
getConfig(): string;
|
|
44
45
|
getConfigId(): number;
|
|
46
|
+
getPreserveIds(): boolean;
|
|
45
47
|
static getSupportedConfigs(): string[];
|
|
46
48
|
static isValidConfig(config: string): boolean;
|
|
47
49
|
constructor(config?: string | null);
|
|
@@ -49,6 +51,7 @@ export class OpenccWasm {
|
|
|
49
51
|
static newWithEnum(config?: OpenccConfigWasm | null): OpenccWasm;
|
|
50
52
|
setConfig(config: string): boolean;
|
|
51
53
|
setConfigEnum(config: OpenccConfigWasm): void;
|
|
54
|
+
setPreserveIds(value: boolean): void;
|
|
52
55
|
static version(): string;
|
|
53
56
|
zhoCheck(text: string): number;
|
|
54
57
|
}
|
|
@@ -63,10 +66,12 @@ export interface InitOutput {
|
|
|
63
66
|
readonly convert_office_bytes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number, number];
|
|
64
67
|
readonly openccwasm_convert: (a: number, b: number, c: number, d: number) => [number, number];
|
|
65
68
|
readonly openccwasm_convertDetofu: (a: number, b: number, c: number, d: number, e: number) => [number, number];
|
|
69
|
+
readonly openccwasm_convertOfficeBytes: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number, number];
|
|
66
70
|
readonly openccwasm_debugPing: (a: number) => [number, number];
|
|
67
71
|
readonly openccwasm_detofu: (a: number, b: number, c: number, d: number) => [number, number];
|
|
68
72
|
readonly openccwasm_getConfig: (a: number) => [number, number];
|
|
69
73
|
readonly openccwasm_getConfigId: (a: number) => number;
|
|
74
|
+
readonly openccwasm_getPreserveIds: (a: number) => number;
|
|
70
75
|
readonly openccwasm_getSupportedConfigs: () => [number, number];
|
|
71
76
|
readonly openccwasm_isValidConfig: (a: number, b: number) => number;
|
|
72
77
|
readonly openccwasm_new: (a: number, b: number) => [number, number, number];
|
|
@@ -74,6 +79,7 @@ export interface InitOutput {
|
|
|
74
79
|
readonly openccwasm_newWithEnum: (a: number) => [number, number, number];
|
|
75
80
|
readonly openccwasm_setConfig: (a: number, b: number, c: number) => number;
|
|
76
81
|
readonly openccwasm_setConfigEnum: (a: number, b: number) => void;
|
|
82
|
+
readonly openccwasm_setPreserveIds: (a: number, b: number) => void;
|
|
77
83
|
readonly openccwasm_version: () => [number, number];
|
|
78
84
|
readonly openccwasm_zhoCheck: (a: number, b: number, c: number) => number;
|
|
79
85
|
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
package/opencc_fmmseg_wasm.js
CHANGED
|
@@ -94,6 +94,26 @@ export class OpenccWasm {
|
|
|
94
94
|
wasm.__wbindgen_free(deferred2_0, deferred2_1, 1);
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* @param {Uint8Array} input
|
|
99
|
+
* @param {string} format
|
|
100
|
+
* @param {boolean} punctuation
|
|
101
|
+
* @param {boolean} keep_font
|
|
102
|
+
* @returns {Uint8Array}
|
|
103
|
+
*/
|
|
104
|
+
convertOfficeBytes(input, format, punctuation, keep_font) {
|
|
105
|
+
const ptr0 = passArray8ToWasm0(input, wasm.__wbindgen_malloc);
|
|
106
|
+
const len0 = WASM_VECTOR_LEN;
|
|
107
|
+
const ptr1 = passStringToWasm0(format, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
108
|
+
const len1 = WASM_VECTOR_LEN;
|
|
109
|
+
const ret = wasm.openccwasm_convertOfficeBytes(this.__wbg_ptr, ptr0, len0, ptr1, len1, punctuation, keep_font);
|
|
110
|
+
if (ret[3]) {
|
|
111
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
112
|
+
}
|
|
113
|
+
var v3 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
|
|
114
|
+
wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
|
|
115
|
+
return v3;
|
|
116
|
+
}
|
|
97
117
|
/**
|
|
98
118
|
* @returns {string}
|
|
99
119
|
*/
|
|
@@ -150,6 +170,13 @@ export class OpenccWasm {
|
|
|
150
170
|
const ret = wasm.openccwasm_getConfigId(this.__wbg_ptr);
|
|
151
171
|
return ret >>> 0;
|
|
152
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* @returns {boolean}
|
|
175
|
+
*/
|
|
176
|
+
getPreserveIds() {
|
|
177
|
+
const ret = wasm.openccwasm_getPreserveIds(this.__wbg_ptr);
|
|
178
|
+
return ret !== 0;
|
|
179
|
+
}
|
|
153
180
|
/**
|
|
154
181
|
* @returns {string[]}
|
|
155
182
|
*/
|
|
@@ -224,6 +251,12 @@ export class OpenccWasm {
|
|
|
224
251
|
setConfigEnum(config) {
|
|
225
252
|
wasm.openccwasm_setConfigEnum(this.__wbg_ptr, config);
|
|
226
253
|
}
|
|
254
|
+
/**
|
|
255
|
+
* @param {boolean} value
|
|
256
|
+
*/
|
|
257
|
+
setPreserveIds(value) {
|
|
258
|
+
wasm.openccwasm_setPreserveIds(this.__wbg_ptr, value);
|
|
259
|
+
}
|
|
227
260
|
/**
|
|
228
261
|
* @returns {string}
|
|
229
262
|
*/
|
|
@@ -278,7 +311,7 @@ export function convert_office_bytes(input, format, config, punctuation, keep_fo
|
|
|
278
311
|
function __wbg_get_imports() {
|
|
279
312
|
const import0 = {
|
|
280
313
|
__proto__: null,
|
|
281
|
-
|
|
314
|
+
__wbg_Error_92b29b0548f8b746: function(arg0, arg1) {
|
|
282
315
|
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
283
316
|
return ret;
|
|
284
317
|
},
|
|
@@ -289,46 +322,46 @@ function __wbg_get_imports() {
|
|
|
289
322
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
290
323
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
291
324
|
},
|
|
292
|
-
|
|
325
|
+
__wbg___wbindgen_boolean_get_fa956cfa2d1bd751: function(arg0) {
|
|
293
326
|
const v = arg0;
|
|
294
327
|
const ret = typeof(v) === 'boolean' ? v : undefined;
|
|
295
328
|
return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
|
|
296
329
|
},
|
|
297
|
-
|
|
330
|
+
__wbg___wbindgen_debug_string_c25d447a39f5578f: function(arg0, arg1) {
|
|
298
331
|
const ret = debugString(arg1);
|
|
299
332
|
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
300
333
|
const len1 = WASM_VECTOR_LEN;
|
|
301
334
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
302
335
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
303
336
|
},
|
|
304
|
-
|
|
337
|
+
__wbg___wbindgen_in_aca499c5de7ff5e5: function(arg0, arg1) {
|
|
305
338
|
const ret = arg0 in arg1;
|
|
306
339
|
return ret;
|
|
307
340
|
},
|
|
308
|
-
|
|
341
|
+
__wbg___wbindgen_is_function_1ff95bcc5517c252: function(arg0) {
|
|
309
342
|
const ret = typeof(arg0) === 'function';
|
|
310
343
|
return ret;
|
|
311
344
|
},
|
|
312
|
-
|
|
345
|
+
__wbg___wbindgen_is_object_a27215656b807791: function(arg0) {
|
|
313
346
|
const val = arg0;
|
|
314
347
|
const ret = typeof(val) === 'object' && val !== null;
|
|
315
348
|
return ret;
|
|
316
349
|
},
|
|
317
|
-
|
|
350
|
+
__wbg___wbindgen_is_undefined_c05833b95a3cf397: function(arg0) {
|
|
318
351
|
const ret = arg0 === undefined;
|
|
319
352
|
return ret;
|
|
320
353
|
},
|
|
321
|
-
|
|
354
|
+
__wbg___wbindgen_jsval_loose_eq_db4c3b15f63fc170: function(arg0, arg1) {
|
|
322
355
|
const ret = arg0 == arg1;
|
|
323
356
|
return ret;
|
|
324
357
|
},
|
|
325
|
-
|
|
358
|
+
__wbg___wbindgen_number_get_394265ed1e1b84ee: function(arg0, arg1) {
|
|
326
359
|
const obj = arg1;
|
|
327
360
|
const ret = typeof(obj) === 'number' ? obj : undefined;
|
|
328
361
|
getDataViewMemory0().setFloat64(arg0 + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
|
|
329
362
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, !isLikeNone(ret), true);
|
|
330
363
|
},
|
|
331
|
-
|
|
364
|
+
__wbg___wbindgen_string_get_b0ca35b86a603356: function(arg0, arg1) {
|
|
332
365
|
const obj = arg1;
|
|
333
366
|
const ret = typeof(obj) === 'string' ? obj : undefined;
|
|
334
367
|
var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
@@ -336,22 +369,22 @@ function __wbg_get_imports() {
|
|
|
336
369
|
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
337
370
|
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
338
371
|
},
|
|
339
|
-
|
|
372
|
+
__wbg___wbindgen_throw_344f42d3211c4765: function(arg0, arg1) {
|
|
340
373
|
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
341
374
|
},
|
|
342
|
-
|
|
375
|
+
__wbg_call_8a2dd23819f8a60a: function() { return handleError(function (arg0, arg1) {
|
|
343
376
|
const ret = arg0.call(arg1);
|
|
344
377
|
return ret;
|
|
345
378
|
}, arguments); },
|
|
346
|
-
|
|
379
|
+
__wbg_done_89b2b13e91a60321: function(arg0) {
|
|
347
380
|
const ret = arg0.done;
|
|
348
381
|
return ret;
|
|
349
382
|
},
|
|
350
|
-
|
|
383
|
+
__wbg_get_c7eb1f358a7654df: function() { return handleError(function (arg0, arg1) {
|
|
351
384
|
const ret = Reflect.get(arg0, arg1);
|
|
352
385
|
return ret;
|
|
353
386
|
}, arguments); },
|
|
354
|
-
|
|
387
|
+
__wbg_get_unchecked_6e0ad6d2a41b06f6: function(arg0, arg1) {
|
|
355
388
|
const ret = arg0[arg1 >>> 0];
|
|
356
389
|
return ret;
|
|
357
390
|
},
|
|
@@ -359,7 +392,7 @@ function __wbg_get_imports() {
|
|
|
359
392
|
const ret = arg0[arg1];
|
|
360
393
|
return ret;
|
|
361
394
|
},
|
|
362
|
-
|
|
395
|
+
__wbg_instanceof_ArrayBuffer_4480b9e0068a8adb: function(arg0) {
|
|
363
396
|
let result;
|
|
364
397
|
try {
|
|
365
398
|
result = arg0 instanceof ArrayBuffer;
|
|
@@ -369,7 +402,7 @@ function __wbg_get_imports() {
|
|
|
369
402
|
const ret = result;
|
|
370
403
|
return ret;
|
|
371
404
|
},
|
|
372
|
-
|
|
405
|
+
__wbg_instanceof_Uint8Array_309b927aaf7a3fc7: function(arg0) {
|
|
373
406
|
let result;
|
|
374
407
|
try {
|
|
375
408
|
result = arg0 instanceof Uint8Array;
|
|
@@ -379,38 +412,38 @@ function __wbg_get_imports() {
|
|
|
379
412
|
const ret = result;
|
|
380
413
|
return ret;
|
|
381
414
|
},
|
|
382
|
-
|
|
415
|
+
__wbg_isArray_0677c962b281d01a: function(arg0) {
|
|
383
416
|
const ret = Array.isArray(arg0);
|
|
384
417
|
return ret;
|
|
385
418
|
},
|
|
386
|
-
|
|
419
|
+
__wbg_iterator_6f722e4a93058b71: function() {
|
|
387
420
|
const ret = Symbol.iterator;
|
|
388
421
|
return ret;
|
|
389
422
|
},
|
|
390
|
-
|
|
423
|
+
__wbg_length_1f0964f4a5e2c6d8: function(arg0) {
|
|
391
424
|
const ret = arg0.length;
|
|
392
425
|
return ret;
|
|
393
426
|
},
|
|
394
|
-
|
|
427
|
+
__wbg_length_370319915dc99107: function(arg0) {
|
|
395
428
|
const ret = arg0.length;
|
|
396
429
|
return ret;
|
|
397
430
|
},
|
|
398
|
-
|
|
431
|
+
__wbg_new_cd45aabdf6073e84: function(arg0) {
|
|
399
432
|
const ret = new Uint8Array(arg0);
|
|
400
433
|
return ret;
|
|
401
434
|
},
|
|
402
|
-
|
|
435
|
+
__wbg_next_6dbf2c0ac8cde20f: function(arg0) {
|
|
403
436
|
const ret = arg0.next;
|
|
404
437
|
return ret;
|
|
405
438
|
},
|
|
406
|
-
|
|
439
|
+
__wbg_next_71f2aa1cb3d1e37e: function() { return handleError(function (arg0) {
|
|
407
440
|
const ret = arg0.next();
|
|
408
441
|
return ret;
|
|
409
442
|
}, arguments); },
|
|
410
|
-
|
|
443
|
+
__wbg_prototypesetcall_4770620bbe4688a0: function(arg0, arg1, arg2) {
|
|
411
444
|
Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
|
|
412
445
|
},
|
|
413
|
-
|
|
446
|
+
__wbg_value_a5d5488a9589444a: function(arg0) {
|
|
414
447
|
const ret = arg0.value;
|
|
415
448
|
return ret;
|
|
416
449
|
},
|
|
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.3.
|
|
5
|
+
"version": "0.3.4",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|