libchai 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/README.md +3 -0
- package/libchai.d.ts +33 -0
- package/libchai.js +116 -0
- package/libchai_bg.wasm +0 -0
- package/package.json +17 -0
package/README.md
ADDED
package/libchai.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
*/
|
|
5
|
+
export function greet(): void;
|
|
6
|
+
|
|
7
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
8
|
+
|
|
9
|
+
export interface InitOutput {
|
|
10
|
+
readonly memory: WebAssembly.Memory;
|
|
11
|
+
readonly greet: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
15
|
+
/**
|
|
16
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
17
|
+
* a precompiled `WebAssembly.Module`.
|
|
18
|
+
*
|
|
19
|
+
* @param {SyncInitInput} module
|
|
20
|
+
*
|
|
21
|
+
* @returns {InitOutput}
|
|
22
|
+
*/
|
|
23
|
+
export function initSync(module: SyncInitInput): InitOutput;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
27
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
28
|
+
*
|
|
29
|
+
* @param {InitInput | Promise<InitInput>} module_or_path
|
|
30
|
+
*
|
|
31
|
+
* @returns {Promise<InitOutput>}
|
|
32
|
+
*/
|
|
33
|
+
export default function __wbg_init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/libchai.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
4
|
+
|
|
5
|
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
6
|
+
|
|
7
|
+
let cachedUint8Memory0 = null;
|
|
8
|
+
|
|
9
|
+
function getUint8Memory0() {
|
|
10
|
+
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
|
|
11
|
+
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
12
|
+
}
|
|
13
|
+
return cachedUint8Memory0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getStringFromWasm0(ptr, len) {
|
|
17
|
+
ptr = ptr >>> 0;
|
|
18
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
*/
|
|
22
|
+
export function greet() {
|
|
23
|
+
wasm.greet();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async function __wbg_load(module, imports) {
|
|
27
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
28
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
29
|
+
try {
|
|
30
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
31
|
+
|
|
32
|
+
} catch (e) {
|
|
33
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
34
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
35
|
+
|
|
36
|
+
} else {
|
|
37
|
+
throw e;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const bytes = await module.arrayBuffer();
|
|
43
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
44
|
+
|
|
45
|
+
} else {
|
|
46
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
47
|
+
|
|
48
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
49
|
+
return { instance, module };
|
|
50
|
+
|
|
51
|
+
} else {
|
|
52
|
+
return instance;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function __wbg_get_imports() {
|
|
58
|
+
const imports = {};
|
|
59
|
+
imports.wbg = {};
|
|
60
|
+
imports.wbg.__wbg_alert_bc2b46846616b07c = function(arg0, arg1) {
|
|
61
|
+
alert(getStringFromWasm0(arg0, arg1));
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
return imports;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function __wbg_init_memory(imports, maybe_memory) {
|
|
68
|
+
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function __wbg_finalize_init(instance, module) {
|
|
72
|
+
wasm = instance.exports;
|
|
73
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
74
|
+
cachedUint8Memory0 = null;
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
return wasm;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function initSync(module) {
|
|
81
|
+
if (wasm !== undefined) return wasm;
|
|
82
|
+
|
|
83
|
+
const imports = __wbg_get_imports();
|
|
84
|
+
|
|
85
|
+
__wbg_init_memory(imports);
|
|
86
|
+
|
|
87
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
88
|
+
module = new WebAssembly.Module(module);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
92
|
+
|
|
93
|
+
return __wbg_finalize_init(instance, module);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async function __wbg_init(input) {
|
|
97
|
+
if (wasm !== undefined) return wasm;
|
|
98
|
+
|
|
99
|
+
if (typeof input === 'undefined') {
|
|
100
|
+
input = new URL('libchai_bg.wasm', import.meta.url);
|
|
101
|
+
}
|
|
102
|
+
const imports = __wbg_get_imports();
|
|
103
|
+
|
|
104
|
+
if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) {
|
|
105
|
+
input = fetch(input);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
__wbg_init_memory(imports);
|
|
109
|
+
|
|
110
|
+
const { instance, module } = await __wbg_load(await input, imports);
|
|
111
|
+
|
|
112
|
+
return __wbg_finalize_init(instance, module);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export { initSync }
|
|
116
|
+
export default __wbg_init;
|
package/libchai_bg.wasm
ADDED
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "libchai",
|
|
3
|
+
"collaborators": [
|
|
4
|
+
"Songchen Tan <i@tansongchen.com>"
|
|
5
|
+
],
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"files": [
|
|
8
|
+
"libchai_bg.wasm",
|
|
9
|
+
"libchai.js",
|
|
10
|
+
"libchai.d.ts"
|
|
11
|
+
],
|
|
12
|
+
"module": "libchai.js",
|
|
13
|
+
"types": "libchai.d.ts",
|
|
14
|
+
"sideEffects": [
|
|
15
|
+
"./snippets/*"
|
|
16
|
+
]
|
|
17
|
+
}
|