lingotweaker-wasm 0.2.2 → 0.2.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 +22 -12
- package/node/lt_wasm_bg.wasm +0 -0
- package/pack.d.ts +11 -12
- package/pack.js +27 -21
- package/package.json +2 -2
- package/web/lt_wasm_bg.wasm +0 -0
package/README.md
CHANGED
|
@@ -10,13 +10,19 @@ npm install lingotweaker-wasm@next
|
|
|
10
10
|
|
|
11
11
|
## Browser
|
|
12
12
|
|
|
13
|
+
The engine's language data packs must be served from your own server —
|
|
14
|
+
browsers block cross-origin fetches, so the data helper has no built-in CDN
|
|
15
|
+
default. Install the `lingotweaker-data-<lang>` npm packages for the languages
|
|
16
|
+
you want, copy their `packs/` directory into your static assets, and pass its
|
|
17
|
+
URL as `baseUrl`:
|
|
18
|
+
|
|
13
19
|
```js
|
|
14
20
|
import init, { LtEngine } from "lingotweaker-wasm";
|
|
15
21
|
import { fetchPack } from "lingotweaker-wasm/pack";
|
|
16
22
|
|
|
17
23
|
await init();
|
|
18
24
|
|
|
19
|
-
const pack = await fetchPack("en"
|
|
25
|
+
const pack = await fetchPack("en", { baseUrl: "/static/lingotweaker-packs" });
|
|
20
26
|
const engine = new LtEngine(
|
|
21
27
|
"en-US",
|
|
22
28
|
pack,
|
|
@@ -56,24 +62,28 @@ passed in and pinned for the engine's date filters.
|
|
|
56
62
|
## Data
|
|
57
63
|
|
|
58
64
|
The package ships **code only** and depends on the code-only
|
|
59
|
-
`lingotweaker-data` loader; the packs ship in one
|
|
65
|
+
`lingotweaker-data` loader; the packs ship in one package per language
|
|
60
66
|
(`lingotweaker-data-<lang>`). In Node.js the data helper resolves installed
|
|
61
|
-
`lingotweaker-data-<lang>` packages
|
|
62
|
-
|
|
67
|
+
`lingotweaker-data-<lang>` packages automatically. In the browser you serve
|
|
68
|
+
the packs yourself (see above) and pass the directory URL as `baseUrl`:
|
|
63
69
|
|
|
64
70
|
```js
|
|
65
71
|
import { fetchPack, packUrl, manifestUrl } from "lingotweaker-wasm/pack";
|
|
66
72
|
|
|
67
|
-
await fetchPack("en");
|
|
68
|
-
await fetchPack("gn", { baseUrl: "
|
|
69
|
-
packUrl("de");
|
|
73
|
+
await fetchPack("en"); // installed lingotweaker-data-en (Node.js)
|
|
74
|
+
await fetchPack("gn", { baseUrl: "/static/lingotweaker-packs" }); // browser: your own server
|
|
75
|
+
packUrl("de", "/static/lingotweaker-packs"); // build a URL yourself
|
|
70
76
|
```
|
|
71
77
|
|
|
72
|
-
`baseUrl` points at a directory
|
|
73
|
-
`
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
`baseUrl` points at a directory with the same layout as the
|
|
79
|
+
`lingotweaker-data-<lang>` packages: a `packs/` subdirectory containing
|
|
80
|
+
`<lang>.pack.gz` plus a `manifest.json` listing file sizes and sha256 hashes.
|
|
81
|
+
Same-origin is the usual choice; any CORS-enabled static server works. Packs
|
|
82
|
+
are downloaded individually per language, on demand.
|
|
83
|
+
|
|
84
|
+
LingoTweaker is an independent project and includes a port of the legacy
|
|
85
|
+
LanguageTool proofreading engine and its rule data. Upstream references and
|
|
86
|
+
licenses are kept; see `THIRD_PARTY_NOTICES.md` in the repository.
|
|
77
87
|
|
|
78
88
|
LingoTweaker is an independent project and includes a port of the legacy
|
|
79
89
|
LanguageTool proofreading engine and its rule data. Upstream references and
|
package/node/lt_wasm_bg.wasm
CHANGED
|
Binary file
|
package/pack.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
// Type definitions for the data-pack helpers in pack.js.
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
export
|
|
3
|
+
/** The URL of the data manifest (`{ <lang>: { file, bytes, sha256 } }`) under `baseUrl`. */
|
|
4
|
+
export function manifestUrl(baseUrl: string): string
|
|
5
5
|
|
|
6
|
-
/** The URL of the
|
|
7
|
-
export function
|
|
8
|
-
|
|
9
|
-
/** The URL of the gzipped pack for `lang`. */
|
|
10
|
-
export function packUrl(lang: string, baseUrl?: string): string
|
|
6
|
+
/** The URL of the gzipped pack for `lang` under `baseUrl`. */
|
|
7
|
+
export function packUrl(lang: string, baseUrl: string): string
|
|
11
8
|
|
|
12
9
|
/** Inflate a gzipped pack (browser `DecompressionStream`, else Node `zlib`). */
|
|
13
10
|
export function decompressPack(
|
|
@@ -15,12 +12,14 @@ export function decompressPack(
|
|
|
15
12
|
): Promise<Uint8Array>
|
|
16
13
|
|
|
17
14
|
/**
|
|
18
|
-
*
|
|
15
|
+
* Load and inflate the pack for `lang` (`en`, `de`, `gn`, …).
|
|
19
16
|
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* data
|
|
17
|
+
* Without `options.baseUrl` this resolves the pack from the locally
|
|
18
|
+
* installed `lingotweaker-data-<lang>` npm packages (Node.js only). In a
|
|
19
|
+
* browser you must pass `baseUrl` pointing at a directory you serve with the
|
|
20
|
+
* same layout as the `lingotweaker-data-<lang>` packages (a `packs/`
|
|
21
|
+
* subdirectory containing `<lang>.pack.gz`); same-origin is the usual choice,
|
|
22
|
+
* since browsers block cross-origin fetches.
|
|
24
23
|
*/
|
|
25
24
|
export function fetchPack(
|
|
26
25
|
lang: string,
|
package/pack.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
// Data helpers for the `lingotweaker-wasm` package.
|
|
2
2
|
//
|
|
3
3
|
// The engine itself is loaded from an in-memory data pack
|
|
4
|
-
// (`LtEngine(lang, pack, optionsJson)`); this module
|
|
5
|
-
//
|
|
4
|
+
// (`LtEngine(lang, pack, optionsJson)`); this module obtains those packs —
|
|
5
|
+
// either from the locally installed `lingotweaker-data-<lang>` npm packages
|
|
6
|
+
// (Node.js) or fetched from a `baseUrl` your server serves them from
|
|
7
|
+
// (browsers). Packs are gzip-compressed and inflated after loading.
|
|
6
8
|
//
|
|
7
9
|
// import { fetchPack } from "lingotweaker-wasm/pack";
|
|
8
|
-
// const pack = await fetchPack("en");
|
|
10
|
+
// const pack = await fetchPack("en", { baseUrl: "/static/lingotweaker-packs" });
|
|
9
11
|
// const engine = new LtEngine("en-US", pack, JSON.stringify({ today: new Date().toISOString() }));
|
|
12
|
+
//
|
|
13
|
+
// There is intentionally no built-in CDN default: pack files must be served
|
|
14
|
+
// from the same origin as the page (or any CORS-enabled server you pass as
|
|
15
|
+
// `baseUrl`), because browsers refuse cross-origin fetches otherwise.
|
|
10
16
|
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
"https://github.com/fiduswriter/LingoTweaker/releases/download/v0.2.2";
|
|
14
|
-
|
|
15
|
-
/** The URL of the release data manifest (`{ <lang>: { file, bytes, sha256 } }`). */
|
|
16
|
-
export function manifestUrl(baseUrl = DEFAULT_DATA_BASE_URL) {
|
|
17
|
+
/** The URL of the data manifest (`{ <lang>: { file, bytes, sha256 } }`) under `baseUrl`. */
|
|
18
|
+
export function manifestUrl(baseUrl) {
|
|
17
19
|
return `${baseUrl}/manifest.json`;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
|
-
/** The URL of the gzipped pack for `lang`. */
|
|
21
|
-
export function packUrl(lang, baseUrl
|
|
22
|
+
/** The URL of the gzipped pack for `lang` under `baseUrl`. */
|
|
23
|
+
export function packUrl(lang, baseUrl) {
|
|
22
24
|
return `${baseUrl}/packs/${lang}.pack.gz`;
|
|
23
25
|
}
|
|
24
26
|
|
|
@@ -34,21 +36,25 @@ export async function decompressPack(bytes) {
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
/**
|
|
37
|
-
*
|
|
39
|
+
* Load and inflate the pack for `lang` (`en`, `de`, `gn`, …).
|
|
38
40
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
41
|
+
* Without `options.baseUrl` this resolves the pack from the locally
|
|
42
|
+
* installed `lingotweaker-data-<lang>` npm packages (Node.js only). In a
|
|
43
|
+
* browser you must pass `baseUrl` pointing at a directory you serve with the
|
|
44
|
+
* same layout as the `lingotweaker-data-<lang>` packages (a `packs/`
|
|
45
|
+
* subdirectory containing `<lang>.pack.gz`); same-origin is the usual choice,
|
|
46
|
+
* since browsers block cross-origin fetches.
|
|
44
47
|
*/
|
|
45
48
|
export async function fetchPack(lang, options = {}) {
|
|
46
|
-
const { fetch: fetchImpl = fetch } = options;
|
|
47
|
-
let { baseUrl } = options;
|
|
49
|
+
const { fetch: fetchImpl = fetch, baseUrl } = options;
|
|
48
50
|
if (!baseUrl) {
|
|
49
51
|
const local = await localPack(lang);
|
|
50
52
|
if (local) return local;
|
|
51
|
-
|
|
53
|
+
throw new Error(
|
|
54
|
+
`lingotweaker-wasm: no locally installed lingotweaker-data-${lang} package; ` +
|
|
55
|
+
`serve the packs/ directory of the lingotweaker-data-${lang} npm package from your ` +
|
|
56
|
+
`server and pass its URL as the fetchPack baseUrl option`
|
|
57
|
+
);
|
|
52
58
|
}
|
|
53
59
|
const url = packUrl(lang, baseUrl);
|
|
54
60
|
const response = await fetchImpl(url);
|
|
@@ -75,4 +81,4 @@ export async function localPack(lang) {
|
|
|
75
81
|
} catch {
|
|
76
82
|
return null;
|
|
77
83
|
}
|
|
78
|
-
}
|
|
84
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lingotweaker-wasm",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "LingoTweaker proofreading engine compiled to WebAssembly (browser and Node)",
|
|
5
5
|
"license": "LGPL-2.1-or-later",
|
|
6
6
|
"repository": {
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"module": "./web/lt_wasm.js",
|
|
23
23
|
"types": "./web/lt_wasm.d.ts",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"lingotweaker-data": "0.2.
|
|
25
|
+
"lingotweaker-data": "0.2.4"
|
|
26
26
|
},
|
|
27
27
|
"exports": {
|
|
28
28
|
".": {
|
package/web/lt_wasm_bg.wasm
CHANGED
|
Binary file
|