hdtrans 0.2.0 → 0.2.1
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 +13 -0
- package/dist/dictionary.json +4 -4
- package/dist/dicts.hdsnap +2 -2
- package/dist/dicts.txt +1 -1
- package/dist/hdtrans_engine.wasm +0 -0
- package/dist/index.d.ts +4 -2
- package/dist/index.js +10 -0
- package/dist/runtime.d.ts +9 -0
- package/dist/runtime.js +18 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,19 @@ try {
|
|
|
19
19
|
}
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
+
## Version information
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
const info = await HdTrans.getInfo();
|
|
26
|
+
console.log(info.version); // Actual engine build version
|
|
27
|
+
console.log(info.dictionaryVersion); // Loaded base dictionary version
|
|
28
|
+
console.log(info.runtime); // 'wasm'
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
`HdTrans.getInfo(options)` accepts the same options as `init()`. It loads the engine and dictionary, then closes its temporary translator; it does not just read package metadata. If loading fails, it rejects. Importing the package alone does not load the engine.
|
|
32
|
+
|
|
33
|
+
For an existing translator, `translator.getInfo()` returns the same fields synchronously. The existing `version`, `dictionaryVersion` and `runtime` properties remain available. Instance metadata is captured at initialization and remains readable after `close()`. User dictionary and Ehnd changes do not change the base dictionary version. TypeScript users can import the `HdTransInfo` type.
|
|
34
|
+
|
|
22
35
|
## Options and JSON
|
|
23
36
|
|
|
24
37
|
```js
|
package/dist/dictionary.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.2.
|
|
2
|
+
"version": "0.2.1+c9ab89c732ad",
|
|
3
3
|
"snapshot": {
|
|
4
4
|
"file": "dicts.hdsnap",
|
|
5
|
-
"sha256": "
|
|
6
|
-
"builtinFingerprint": "
|
|
7
|
-
"dataFingerprint": "
|
|
5
|
+
"sha256": "d282a66d43bde0f9508596e25b7fb83dd5232c4720908dba0f816e03ceba1235",
|
|
6
|
+
"builtinFingerprint": "6b14e235d8d87e3a331af888aeab1ce4f08134165267f645f340aa744c201db8",
|
|
7
|
+
"dataFingerprint": "4ed4667154767753f2beb615b07a3ba530cff99944069287401b684da6a64b40"
|
|
8
8
|
},
|
|
9
9
|
"files": []
|
|
10
10
|
}
|
package/dist/dicts.hdsnap
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/dist/dicts.hdsnap
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 36085943 bytes
|
|
4
|
+
sha256: d282a66d43bde0f9508596e25b7fb83dd5232c4720908dba0f816e03ceba1235
|
package/dist/dicts.txt
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.2.
|
|
1
|
+
0.2.1+c9ab89c732ad
|
package/dist/hdtrans_engine.wasm
CHANGED
|
Binary file
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { HdTrans as RuntimeHdTrans, type InitOptions as RuntimeInitOptions } from './runtime.js';
|
|
2
|
-
export type { UserDictPos, UserDictEntry, ChoiceSelection, TranslationChoice, TranslationResult, EhndFiles, } from './runtime.js';
|
|
1
|
+
import { HdTrans as RuntimeHdTrans, type HdTransInfo, type InitOptions as RuntimeInitOptions } from './runtime.js';
|
|
2
|
+
export type { UserDictPos, UserDictEntry, ChoiceSelection, TranslationChoice, TranslationResult, EhndFiles, HdTransInfo, } from './runtime.js';
|
|
3
3
|
export type InitOptions = Pick<RuntimeInitOptions, 'ehnd'>;
|
|
4
4
|
export type HdTrans = RuntimeHdTrans;
|
|
5
5
|
/** Uses the bundled engine and dictionary. Each call returns an independent translator. */
|
|
6
6
|
export declare const HdTrans: Readonly<{
|
|
7
|
+
/** Loads the bundled engine and dictionary, reads their metadata, then closes the temporary translator. */
|
|
8
|
+
getInfo(options?: InitOptions): Promise<HdTransInfo>;
|
|
7
9
|
init(options?: InitOptions): Promise<HdTrans>;
|
|
8
10
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,16 @@ async function loadModule() {
|
|
|
12
12
|
}
|
|
13
13
|
/** Uses the bundled engine and dictionary. Each call returns an independent translator. */
|
|
14
14
|
export const HdTrans = Object.freeze({
|
|
15
|
+
/** Loads the bundled engine and dictionary, reads their metadata, then closes the temporary translator. */
|
|
16
|
+
async getInfo(options = {}) {
|
|
17
|
+
const translator = await HdTrans.init(options);
|
|
18
|
+
try {
|
|
19
|
+
return translator.getInfo();
|
|
20
|
+
}
|
|
21
|
+
finally {
|
|
22
|
+
translator.close();
|
|
23
|
+
}
|
|
24
|
+
},
|
|
15
25
|
async init(options = {}) {
|
|
16
26
|
modulePromise ??= loadModule().catch((error) => {
|
|
17
27
|
modulePromise = undefined;
|
package/dist/runtime.d.ts
CHANGED
|
@@ -58,6 +58,11 @@ export interface WasmModule {
|
|
|
58
58
|
Translator: new () => Binding;
|
|
59
59
|
version(): string;
|
|
60
60
|
}
|
|
61
|
+
export interface HdTransInfo {
|
|
62
|
+
readonly version: string;
|
|
63
|
+
readonly dictionaryVersion: string;
|
|
64
|
+
readonly runtime: 'wasm';
|
|
65
|
+
}
|
|
61
66
|
export interface InitOptions {
|
|
62
67
|
/** Supply an instantiated module with its dictionary files already staged. */
|
|
63
68
|
module?: WasmModule | Promise<WasmModule>;
|
|
@@ -73,6 +78,10 @@ export declare class HdTrans {
|
|
|
73
78
|
private userDictRaw_;
|
|
74
79
|
private constructor();
|
|
75
80
|
static init(options?: InitOptions): Promise<HdTrans>;
|
|
81
|
+
/** Loads the engine and dictionaries, reads their metadata, then closes the temporary translator. */
|
|
82
|
+
static getInfo(options?: InitOptions): Promise<HdTransInfo>;
|
|
83
|
+
/** Metadata captured at initialization, also available after close(). */
|
|
84
|
+
getInfo(): HdTransInfo;
|
|
76
85
|
translate(text: string): string;
|
|
77
86
|
translate(text: string, options: {
|
|
78
87
|
json: true;
|
package/dist/runtime.js
CHANGED
|
@@ -35,6 +35,24 @@ export class HdTrans {
|
|
|
35
35
|
throw error;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
|
+
/** Loads the engine and dictionaries, reads their metadata, then closes the temporary translator. */
|
|
39
|
+
static async getInfo(options = {}) {
|
|
40
|
+
const translator = await HdTrans.init(options);
|
|
41
|
+
try {
|
|
42
|
+
return translator.getInfo();
|
|
43
|
+
}
|
|
44
|
+
finally {
|
|
45
|
+
translator.close();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** Metadata captured at initialization, also available after close(). */
|
|
49
|
+
getInfo() {
|
|
50
|
+
return {
|
|
51
|
+
version: this.version,
|
|
52
|
+
dictionaryVersion: this.dictionaryVersion,
|
|
53
|
+
runtime: this.runtime,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
38
56
|
translate(text, options = {}) {
|
|
39
57
|
const binding = this.binding();
|
|
40
58
|
if (typeof text !== 'string')
|