@kotoshu/wasm 0.1.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/kotoshu_wasm.d.ts +39 -0
- package/kotoshu_wasm.js +9 -0
- package/kotoshu_wasm_bg.js +342 -0
- package/kotoshu_wasm_bg.wasm +0 -0
- package/package.json +27 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* One loaded dictionary: the JS twin of the `ruby` feature's
|
|
6
|
+
* `Kotoshu::Native::Dictionary` — same engine, same suggestion-row shape.
|
|
7
|
+
*/
|
|
8
|
+
export class KotoshuWasm {
|
|
9
|
+
free(): void;
|
|
10
|
+
[Symbol.dispose](): void;
|
|
11
|
+
/**
|
|
12
|
+
* Whether `word` is spelled correctly per this dictionary (the gem's
|
|
13
|
+
* `correct?`).
|
|
14
|
+
*/
|
|
15
|
+
correct(word: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Load a dictionary from the string CONTENTS of its `.aff` and `.dic`
|
|
18
|
+
* sources (wasm has no filesystem). Byte-symmetric with a path load:
|
|
19
|
+
* the pair is decoded per the `.aff` `SET` line exactly like
|
|
20
|
+
* [`Dictionary::load`], so hosts holding UTF-8 sources pass them
|
|
21
|
+
* through verbatim; hosts holding legacy-encoded dictionaries decode
|
|
22
|
+
* them per `SET` first (and hand the `.aff` over as UTF-8).
|
|
23
|
+
*
|
|
24
|
+
* Failures reject with the Rust error message.
|
|
25
|
+
*/
|
|
26
|
+
constructor(aff_source: string, dic_source: string);
|
|
27
|
+
/**
|
|
28
|
+
* Ranked suggestions for `word` (the gem's `suggest`): a plain array,
|
|
29
|
+
* one row per suggestion — see the module docs for the row shape.
|
|
30
|
+
* `limit` defaults to 5 when omitted.
|
|
31
|
+
*/
|
|
32
|
+
suggest(word: string, limit?: number | null): Array<any>;
|
|
33
|
+
/**
|
|
34
|
+
* The engine (kotoshu crate) version. The npm package version line is
|
|
35
|
+
* independent per package (parsanol policy) — its `package.json`
|
|
36
|
+
* governs the published version, not this constant.
|
|
37
|
+
*/
|
|
38
|
+
static readonly VERSION: string;
|
|
39
|
+
}
|
package/kotoshu_wasm.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One loaded dictionary: the JS twin of the `ruby` feature's
|
|
3
|
+
* `Kotoshu::Native::Dictionary` — same engine, same suggestion-row shape.
|
|
4
|
+
*/
|
|
5
|
+
export class KotoshuWasm {
|
|
6
|
+
__destroy_into_raw() {
|
|
7
|
+
const ptr = this.__wbg_ptr;
|
|
8
|
+
this.__wbg_ptr = 0;
|
|
9
|
+
KotoshuWasmFinalization.unregister(this);
|
|
10
|
+
return ptr;
|
|
11
|
+
}
|
|
12
|
+
free() {
|
|
13
|
+
const ptr = this.__destroy_into_raw();
|
|
14
|
+
wasm.__wbg_kotoshuwasm_free(ptr, 0);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* The engine (kotoshu crate) version. The npm package version line is
|
|
18
|
+
* independent per package (parsanol policy) — its `package.json`
|
|
19
|
+
* governs the published version, not this constant.
|
|
20
|
+
* @returns {string}
|
|
21
|
+
*/
|
|
22
|
+
static get VERSION() {
|
|
23
|
+
let deferred1_0;
|
|
24
|
+
let deferred1_1;
|
|
25
|
+
try {
|
|
26
|
+
const ret = wasm.kotoshuwasm_VERSION();
|
|
27
|
+
deferred1_0 = ret[0];
|
|
28
|
+
deferred1_1 = ret[1];
|
|
29
|
+
return getStringFromWasm0(ret[0], ret[1]);
|
|
30
|
+
} finally {
|
|
31
|
+
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Whether `word` is spelled correctly per this dictionary (the gem's
|
|
36
|
+
* `correct?`).
|
|
37
|
+
* @param {string} word
|
|
38
|
+
* @returns {boolean}
|
|
39
|
+
*/
|
|
40
|
+
correct(word) {
|
|
41
|
+
const ptr0 = passStringToWasm0(word, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
42
|
+
const len0 = WASM_VECTOR_LEN;
|
|
43
|
+
const ret = wasm.kotoshuwasm_correct(this.__wbg_ptr, ptr0, len0);
|
|
44
|
+
return ret !== 0;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Load a dictionary from the string CONTENTS of its `.aff` and `.dic`
|
|
48
|
+
* sources (wasm has no filesystem). Byte-symmetric with a path load:
|
|
49
|
+
* the pair is decoded per the `.aff` `SET` line exactly like
|
|
50
|
+
* [`Dictionary::load`], so hosts holding UTF-8 sources pass them
|
|
51
|
+
* through verbatim; hosts holding legacy-encoded dictionaries decode
|
|
52
|
+
* them per `SET` first (and hand the `.aff` over as UTF-8).
|
|
53
|
+
*
|
|
54
|
+
* Failures reject with the Rust error message.
|
|
55
|
+
* @param {string} aff_source
|
|
56
|
+
* @param {string} dic_source
|
|
57
|
+
*/
|
|
58
|
+
constructor(aff_source, dic_source) {
|
|
59
|
+
const ptr0 = passStringToWasm0(aff_source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
60
|
+
const len0 = WASM_VECTOR_LEN;
|
|
61
|
+
const ptr1 = passStringToWasm0(dic_source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
62
|
+
const len1 = WASM_VECTOR_LEN;
|
|
63
|
+
const ret = wasm.kotoshuwasm_new(ptr0, len0, ptr1, len1);
|
|
64
|
+
if (ret[2]) {
|
|
65
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
66
|
+
}
|
|
67
|
+
this.__wbg_ptr = ret[0];
|
|
68
|
+
KotoshuWasmFinalization.register(this, this.__wbg_ptr, this);
|
|
69
|
+
return this;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Ranked suggestions for `word` (the gem's `suggest`): a plain array,
|
|
73
|
+
* one row per suggestion — see the module docs for the row shape.
|
|
74
|
+
* `limit` defaults to 5 when omitted.
|
|
75
|
+
* @param {string} word
|
|
76
|
+
* @param {number | null} [limit]
|
|
77
|
+
* @returns {Array<any>}
|
|
78
|
+
*/
|
|
79
|
+
suggest(word, limit) {
|
|
80
|
+
const ptr0 = passStringToWasm0(word, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
81
|
+
const len0 = WASM_VECTOR_LEN;
|
|
82
|
+
const ret = wasm.kotoshuwasm_suggest(this.__wbg_ptr, ptr0, len0, isLikeNone(limit) ? Number.MAX_SAFE_INTEGER : (limit) >>> 0);
|
|
83
|
+
return ret;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (Symbol.dispose) KotoshuWasm.prototype[Symbol.dispose] = KotoshuWasm.prototype.free;
|
|
87
|
+
export function __wbg_Error_408e67f47ca7b58b(arg0, arg1) {
|
|
88
|
+
const ret = Error(getStringFromWasm0(arg0, arg1));
|
|
89
|
+
return ret;
|
|
90
|
+
}
|
|
91
|
+
export function __wbg___wbindgen_debug_string_a57024b9c6e4a48b(arg0, arg1) {
|
|
92
|
+
const ret = debugString(arg1);
|
|
93
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
94
|
+
const len1 = WASM_VECTOR_LEN;
|
|
95
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
96
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
97
|
+
}
|
|
98
|
+
export function __wbg___wbindgen_throw_bb96b2010945f0bc(arg0, arg1) {
|
|
99
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
100
|
+
}
|
|
101
|
+
export function __wbg_error_757e9472f8410341(arg0, arg1) {
|
|
102
|
+
let deferred0_0;
|
|
103
|
+
let deferred0_1;
|
|
104
|
+
try {
|
|
105
|
+
deferred0_0 = arg0;
|
|
106
|
+
deferred0_1 = arg1;
|
|
107
|
+
console.error(getStringFromWasm0(arg0, arg1));
|
|
108
|
+
} finally {
|
|
109
|
+
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
export function __wbg_new_116be93542d39019() {
|
|
113
|
+
const ret = new Array();
|
|
114
|
+
return ret;
|
|
115
|
+
}
|
|
116
|
+
export function __wbg_new_227d7c05414eb861() {
|
|
117
|
+
const ret = new Error();
|
|
118
|
+
return ret;
|
|
119
|
+
}
|
|
120
|
+
export function __wbg_new_ebe3e0f6837f0879() {
|
|
121
|
+
const ret = new Object();
|
|
122
|
+
return ret;
|
|
123
|
+
}
|
|
124
|
+
export function __wbg_push_adb0107829f02d75(arg0, arg1) {
|
|
125
|
+
const ret = arg0.push(arg1);
|
|
126
|
+
return ret;
|
|
127
|
+
}
|
|
128
|
+
export function __wbg_set_8155bb79a948541b() { return handleError(function (arg0, arg1, arg2) {
|
|
129
|
+
const ret = Reflect.set(arg0, arg1, arg2);
|
|
130
|
+
return ret;
|
|
131
|
+
}, arguments); }
|
|
132
|
+
export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
|
|
133
|
+
const ret = arg1.stack;
|
|
134
|
+
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
135
|
+
const len1 = WASM_VECTOR_LEN;
|
|
136
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
|
|
137
|
+
getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
|
|
138
|
+
}
|
|
139
|
+
export function __wbindgen_cast_0000000000000001(arg0) {
|
|
140
|
+
// Cast intrinsic for `F64 -> Externref`.
|
|
141
|
+
const ret = arg0;
|
|
142
|
+
return ret;
|
|
143
|
+
}
|
|
144
|
+
export function __wbindgen_cast_0000000000000002(arg0, arg1) {
|
|
145
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
146
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
147
|
+
return ret;
|
|
148
|
+
}
|
|
149
|
+
export function __wbindgen_init_externref_table() {
|
|
150
|
+
const table = wasm.__wbindgen_externrefs;
|
|
151
|
+
const offset = table.grow(4);
|
|
152
|
+
table.set(0, undefined);
|
|
153
|
+
table.set(offset + 0, undefined);
|
|
154
|
+
table.set(offset + 1, null);
|
|
155
|
+
table.set(offset + 2, true);
|
|
156
|
+
table.set(offset + 3, false);
|
|
157
|
+
}
|
|
158
|
+
const KotoshuWasmFinalization = (typeof FinalizationRegistry === 'undefined')
|
|
159
|
+
? { register: () => {}, unregister: () => {} }
|
|
160
|
+
: new FinalizationRegistry(ptr => wasm.__wbg_kotoshuwasm_free(ptr, 1));
|
|
161
|
+
|
|
162
|
+
function addToExternrefTable0(obj) {
|
|
163
|
+
const idx = wasm.__externref_table_alloc();
|
|
164
|
+
wasm.__wbindgen_externrefs.set(idx, obj);
|
|
165
|
+
return idx;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function debugString(val) {
|
|
169
|
+
// primitive types
|
|
170
|
+
const type = typeof val;
|
|
171
|
+
if (type == 'number' || type == 'boolean' || val == null) {
|
|
172
|
+
return `${val}`;
|
|
173
|
+
}
|
|
174
|
+
if (type == 'string') {
|
|
175
|
+
return `"${val}"`;
|
|
176
|
+
}
|
|
177
|
+
if (type == 'symbol') {
|
|
178
|
+
const description = val.description;
|
|
179
|
+
if (description == null) {
|
|
180
|
+
return 'Symbol';
|
|
181
|
+
} else {
|
|
182
|
+
return `Symbol(${description})`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (type == 'function') {
|
|
186
|
+
const name = val.name;
|
|
187
|
+
if (typeof name == 'string' && name.length > 0) {
|
|
188
|
+
return `Function(${name})`;
|
|
189
|
+
} else {
|
|
190
|
+
return 'Function';
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
// objects
|
|
194
|
+
if (Array.isArray(val)) {
|
|
195
|
+
const length = val.length;
|
|
196
|
+
let debug = '[';
|
|
197
|
+
if (length > 0) {
|
|
198
|
+
debug += debugString(val[0]);
|
|
199
|
+
}
|
|
200
|
+
for(let i = 1; i < length; i++) {
|
|
201
|
+
debug += ', ' + debugString(val[i]);
|
|
202
|
+
}
|
|
203
|
+
debug += ']';
|
|
204
|
+
return debug;
|
|
205
|
+
}
|
|
206
|
+
// Test for built-in
|
|
207
|
+
const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
|
|
208
|
+
let className;
|
|
209
|
+
if (builtInMatches && builtInMatches.length > 1) {
|
|
210
|
+
className = builtInMatches[1];
|
|
211
|
+
} else {
|
|
212
|
+
// Failed to match the standard '[object ClassName]'
|
|
213
|
+
return toString.call(val);
|
|
214
|
+
}
|
|
215
|
+
if (className == 'Object') {
|
|
216
|
+
// we're a user defined class or Object
|
|
217
|
+
// JSON.stringify avoids problems with cycles, and is generally much
|
|
218
|
+
// easier than looping through ownProperties of `val`.
|
|
219
|
+
try {
|
|
220
|
+
return 'Object(' + JSON.stringify(val) + ')';
|
|
221
|
+
} catch (_) {
|
|
222
|
+
return 'Object';
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// errors
|
|
226
|
+
if (val instanceof Error) {
|
|
227
|
+
return `${val.name}: ${val.message}\n${val.stack}`;
|
|
228
|
+
}
|
|
229
|
+
// TODO we could test for more things here, like `Set`s and `Map`s.
|
|
230
|
+
return className;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
let cachedDataViewMemory0 = null;
|
|
234
|
+
function getDataViewMemory0() {
|
|
235
|
+
if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
|
|
236
|
+
cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
|
|
237
|
+
}
|
|
238
|
+
return cachedDataViewMemory0;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function getStringFromWasm0(ptr, len) {
|
|
242
|
+
return decodeText(ptr >>> 0, len);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
let cachedUint8ArrayMemory0 = null;
|
|
246
|
+
function getUint8ArrayMemory0() {
|
|
247
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
248
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
249
|
+
}
|
|
250
|
+
return cachedUint8ArrayMemory0;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
function handleError(f, args) {
|
|
254
|
+
try {
|
|
255
|
+
return f.apply(this, args);
|
|
256
|
+
} catch (e) {
|
|
257
|
+
const idx = addToExternrefTable0(e);
|
|
258
|
+
wasm.__wbindgen_exn_store(idx);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function isLikeNone(x) {
|
|
263
|
+
return x === undefined || x === null;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
267
|
+
if (realloc === undefined) {
|
|
268
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
269
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
270
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
271
|
+
WASM_VECTOR_LEN = buf.length;
|
|
272
|
+
return ptr;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
let len = arg.length;
|
|
276
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
277
|
+
|
|
278
|
+
const mem = getUint8ArrayMemory0();
|
|
279
|
+
|
|
280
|
+
let offset = 0;
|
|
281
|
+
|
|
282
|
+
for (; offset < len; offset++) {
|
|
283
|
+
const code = arg.charCodeAt(offset);
|
|
284
|
+
if (code > 0x7F) break;
|
|
285
|
+
mem[ptr + offset] = code;
|
|
286
|
+
}
|
|
287
|
+
if (offset !== len) {
|
|
288
|
+
if (offset !== 0) {
|
|
289
|
+
arg = arg.slice(offset);
|
|
290
|
+
}
|
|
291
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
292
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
293
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
294
|
+
|
|
295
|
+
offset += ret.written;
|
|
296
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
WASM_VECTOR_LEN = offset;
|
|
300
|
+
return ptr;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
function takeFromExternrefTable0(idx) {
|
|
304
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
305
|
+
wasm.__externref_table_dealloc(idx);
|
|
306
|
+
return value;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
310
|
+
cachedTextDecoder.decode();
|
|
311
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
312
|
+
let numBytesDecoded = 0;
|
|
313
|
+
function decodeText(ptr, len) {
|
|
314
|
+
numBytesDecoded += len;
|
|
315
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
316
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
317
|
+
cachedTextDecoder.decode();
|
|
318
|
+
numBytesDecoded = len;
|
|
319
|
+
}
|
|
320
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const cachedTextEncoder = new TextEncoder();
|
|
324
|
+
|
|
325
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
326
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
327
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
328
|
+
view.set(buf);
|
|
329
|
+
return {
|
|
330
|
+
read: arg.length,
|
|
331
|
+
written: buf.length
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
let WASM_VECTOR_LEN = 0;
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
let wasm;
|
|
340
|
+
export function __wbg_set_wasm(val) {
|
|
341
|
+
wasm = val;
|
|
342
|
+
}
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kotoshu/wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"collaborators": [
|
|
5
|
+
"Ribose Inc. <open.source@ribose.com>"
|
|
6
|
+
],
|
|
7
|
+
"description": "npm @kotoshu/wasm packaging shim: wasm-pack build of the kotoshu engine's wasm-bindgen surface",
|
|
8
|
+
"version": "0.1.0",
|
|
9
|
+
"license": "BSD-2-Clause",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/kotoshu/kotoshu-rs"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"kotoshu_wasm_bg.wasm",
|
|
16
|
+
"kotoshu_wasm.js",
|
|
17
|
+
"kotoshu_wasm_bg.js",
|
|
18
|
+
"kotoshu_wasm.d.ts"
|
|
19
|
+
],
|
|
20
|
+
"main": "kotoshu_wasm.js",
|
|
21
|
+
"homepage": "https://github.com/kotoshu/kotoshu-rs",
|
|
22
|
+
"types": "kotoshu_wasm.d.ts",
|
|
23
|
+
"sideEffects": [
|
|
24
|
+
"./kotoshu_wasm.js",
|
|
25
|
+
"./snippets/*"
|
|
26
|
+
]
|
|
27
|
+
}
|