mingli-wasm-bazi 1.0.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 +17 -0
- package/mingli_wasm.d.ts +54 -0
- package/mingli_wasm.js +262 -0
- package/mingli_wasm_bg.wasm +0 -0
- package/mingli_wasm_bg.wasm.d.ts +11 -0
- package/package.json +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# mingli-wasm-bazi
|
|
2
|
+
|
|
3
|
+
Four Pillars of Destiny alone.
|
|
4
|
+
|
|
5
|
+
```js
|
|
6
|
+
import init, { cast_one } from 'mingli-wasm-bazi';
|
|
7
|
+
await init();
|
|
8
|
+
const chart = JSON.parse(cast_one('bazi', JSON.stringify({
|
|
9
|
+
year: 1990, month: 6, day: 15, hour: 14, minute: 30, tz: 8.0
|
|
10
|
+
})));
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Module size: 198777 bytes before compression. Every published profile has a byte
|
|
14
|
+
budget checked in at `scripts/wasm-budget.txt`; CI fails on a regression.
|
|
15
|
+
|
|
16
|
+
Same algorithms as the `mingli` crates on crates.io — one source, two shapes.
|
|
17
|
+
See https://github.com/goliajp/mingli.
|
package/mingli_wasm.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 全叶排盘(含 id/name/family/确定性谱/盘面)。入参为 [`mingli_contract::Query`] 的 JSON。
|
|
6
|
+
*
|
|
7
|
+
* # Errors
|
|
8
|
+
* query JSON 解析失败时返回错误。
|
|
9
|
+
*/
|
|
10
|
+
export function cast(query_json: string): string;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 只排单片叶(按 id),省去其余叶(非占星叶还省掉 VSOP87)。未知 id 返回 `"null"`。
|
|
14
|
+
*
|
|
15
|
+
* # Errors
|
|
16
|
+
* query JSON 解析失败时返回错误。
|
|
17
|
+
*/
|
|
18
|
+
export function cast_one(id: string, query_json: string): string;
|
|
19
|
+
|
|
20
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
21
|
+
|
|
22
|
+
export interface InitOutput {
|
|
23
|
+
readonly memory: WebAssembly.Memory;
|
|
24
|
+
readonly cast: (a: number, b: number) => [number, number, number, number];
|
|
25
|
+
readonly cast_one: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
26
|
+
readonly __wbindgen_externrefs: WebAssembly.Table;
|
|
27
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
28
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
29
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
30
|
+
readonly __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
31
|
+
readonly __wbindgen_start: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
38
|
+
* a precompiled `WebAssembly.Module`.
|
|
39
|
+
*
|
|
40
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
41
|
+
*
|
|
42
|
+
* @returns {InitOutput}
|
|
43
|
+
*/
|
|
44
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
48
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
49
|
+
*
|
|
50
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
51
|
+
*
|
|
52
|
+
* @returns {Promise<InitOutput>}
|
|
53
|
+
*/
|
|
54
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/mingli_wasm.js
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
/* @ts-self-types="./mingli_wasm.d.ts" */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 全叶排盘(含 id/name/family/确定性谱/盘面)。入参为 [`mingli_contract::Query`] 的 JSON。
|
|
5
|
+
*
|
|
6
|
+
* # Errors
|
|
7
|
+
* query JSON 解析失败时返回错误。
|
|
8
|
+
* @param {string} query_json
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
export function cast(query_json) {
|
|
12
|
+
let deferred3_0;
|
|
13
|
+
let deferred3_1;
|
|
14
|
+
try {
|
|
15
|
+
const ptr0 = passStringToWasm0(query_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
16
|
+
const len0 = WASM_VECTOR_LEN;
|
|
17
|
+
const ret = wasm.cast(ptr0, len0);
|
|
18
|
+
var ptr2 = ret[0];
|
|
19
|
+
var len2 = ret[1];
|
|
20
|
+
if (ret[3]) {
|
|
21
|
+
ptr2 = 0; len2 = 0;
|
|
22
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
23
|
+
}
|
|
24
|
+
deferred3_0 = ptr2;
|
|
25
|
+
deferred3_1 = len2;
|
|
26
|
+
return getStringFromWasm0(ptr2, len2);
|
|
27
|
+
} finally {
|
|
28
|
+
wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 只排单片叶(按 id),省去其余叶(非占星叶还省掉 VSOP87)。未知 id 返回 `"null"`。
|
|
34
|
+
*
|
|
35
|
+
* # Errors
|
|
36
|
+
* query JSON 解析失败时返回错误。
|
|
37
|
+
* @param {string} id
|
|
38
|
+
* @param {string} query_json
|
|
39
|
+
* @returns {string}
|
|
40
|
+
*/
|
|
41
|
+
export function cast_one(id, query_json) {
|
|
42
|
+
let deferred4_0;
|
|
43
|
+
let deferred4_1;
|
|
44
|
+
try {
|
|
45
|
+
const ptr0 = passStringToWasm0(id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
46
|
+
const len0 = WASM_VECTOR_LEN;
|
|
47
|
+
const ptr1 = passStringToWasm0(query_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
48
|
+
const len1 = WASM_VECTOR_LEN;
|
|
49
|
+
const ret = wasm.cast_one(ptr0, len0, ptr1, len1);
|
|
50
|
+
var ptr3 = ret[0];
|
|
51
|
+
var len3 = ret[1];
|
|
52
|
+
if (ret[3]) {
|
|
53
|
+
ptr3 = 0; len3 = 0;
|
|
54
|
+
throw takeFromExternrefTable0(ret[2]);
|
|
55
|
+
}
|
|
56
|
+
deferred4_0 = ptr3;
|
|
57
|
+
deferred4_1 = len3;
|
|
58
|
+
return getStringFromWasm0(ptr3, len3);
|
|
59
|
+
} finally {
|
|
60
|
+
wasm.__wbindgen_free(deferred4_0, deferred4_1, 1);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function __wbg_get_imports() {
|
|
64
|
+
const import0 = {
|
|
65
|
+
__proto__: null,
|
|
66
|
+
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
67
|
+
// Cast intrinsic for `Ref(String) -> Externref`.
|
|
68
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
69
|
+
return ret;
|
|
70
|
+
},
|
|
71
|
+
__wbindgen_init_externref_table: function() {
|
|
72
|
+
const table = wasm.__wbindgen_externrefs;
|
|
73
|
+
const offset = table.grow(4);
|
|
74
|
+
table.set(0, undefined);
|
|
75
|
+
table.set(offset + 0, undefined);
|
|
76
|
+
table.set(offset + 1, null);
|
|
77
|
+
table.set(offset + 2, true);
|
|
78
|
+
table.set(offset + 3, false);
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
return {
|
|
82
|
+
__proto__: null,
|
|
83
|
+
"./mingli_wasm_bg.js": import0,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getStringFromWasm0(ptr, len) {
|
|
88
|
+
return decodeText(ptr >>> 0, len);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
let cachedUint8ArrayMemory0 = null;
|
|
92
|
+
function getUint8ArrayMemory0() {
|
|
93
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
94
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
95
|
+
}
|
|
96
|
+
return cachedUint8ArrayMemory0;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
100
|
+
if (realloc === undefined) {
|
|
101
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
102
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
103
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
104
|
+
WASM_VECTOR_LEN = buf.length;
|
|
105
|
+
return ptr;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let len = arg.length;
|
|
109
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
110
|
+
|
|
111
|
+
const mem = getUint8ArrayMemory0();
|
|
112
|
+
|
|
113
|
+
let offset = 0;
|
|
114
|
+
|
|
115
|
+
for (; offset < len; offset++) {
|
|
116
|
+
const code = arg.charCodeAt(offset);
|
|
117
|
+
if (code > 0x7F) break;
|
|
118
|
+
mem[ptr + offset] = code;
|
|
119
|
+
}
|
|
120
|
+
if (offset !== len) {
|
|
121
|
+
if (offset !== 0) {
|
|
122
|
+
arg = arg.slice(offset);
|
|
123
|
+
}
|
|
124
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
125
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
126
|
+
const ret = cachedTextEncoder.encodeInto(arg, view);
|
|
127
|
+
|
|
128
|
+
offset += ret.written;
|
|
129
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
WASM_VECTOR_LEN = offset;
|
|
133
|
+
return ptr;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function takeFromExternrefTable0(idx) {
|
|
137
|
+
const value = wasm.__wbindgen_externrefs.get(idx);
|
|
138
|
+
wasm.__externref_table_dealloc(idx);
|
|
139
|
+
return value;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
143
|
+
cachedTextDecoder.decode();
|
|
144
|
+
const MAX_SAFARI_DECODE_BYTES = 2146435072;
|
|
145
|
+
let numBytesDecoded = 0;
|
|
146
|
+
function decodeText(ptr, len) {
|
|
147
|
+
numBytesDecoded += len;
|
|
148
|
+
if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
|
|
149
|
+
cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
150
|
+
cachedTextDecoder.decode();
|
|
151
|
+
numBytesDecoded = len;
|
|
152
|
+
}
|
|
153
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
const cachedTextEncoder = new TextEncoder();
|
|
157
|
+
|
|
158
|
+
if (!('encodeInto' in cachedTextEncoder)) {
|
|
159
|
+
cachedTextEncoder.encodeInto = function (arg, view) {
|
|
160
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
161
|
+
view.set(buf);
|
|
162
|
+
return {
|
|
163
|
+
read: arg.length,
|
|
164
|
+
written: buf.length
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
let WASM_VECTOR_LEN = 0;
|
|
170
|
+
|
|
171
|
+
let wasmModule, wasmInstance, wasm;
|
|
172
|
+
function __wbg_finalize_init(instance, module) {
|
|
173
|
+
wasmInstance = instance;
|
|
174
|
+
wasm = instance.exports;
|
|
175
|
+
wasmModule = module;
|
|
176
|
+
cachedUint8ArrayMemory0 = null;
|
|
177
|
+
wasm.__wbindgen_start();
|
|
178
|
+
return wasm;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async function __wbg_load(module, imports) {
|
|
182
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
183
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
184
|
+
try {
|
|
185
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
186
|
+
} catch (e) {
|
|
187
|
+
const validResponse = module.ok && expectedResponseType(module.type);
|
|
188
|
+
|
|
189
|
+
if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
|
|
190
|
+
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);
|
|
191
|
+
|
|
192
|
+
} else { throw e; }
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const bytes = await module.arrayBuffer();
|
|
197
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
198
|
+
} else {
|
|
199
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
200
|
+
|
|
201
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
202
|
+
return { instance, module };
|
|
203
|
+
} else {
|
|
204
|
+
return instance;
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function expectedResponseType(type) {
|
|
209
|
+
switch (type) {
|
|
210
|
+
case 'basic': case 'cors': case 'default': return true;
|
|
211
|
+
}
|
|
212
|
+
return false;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function initSync(module) {
|
|
217
|
+
if (wasm !== undefined) return wasm;
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
if (module !== undefined) {
|
|
221
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
222
|
+
({module} = module)
|
|
223
|
+
} else {
|
|
224
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const imports = __wbg_get_imports();
|
|
229
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
230
|
+
module = new WebAssembly.Module(module);
|
|
231
|
+
}
|
|
232
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
233
|
+
return __wbg_finalize_init(instance, module);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function __wbg_init(module_or_path) {
|
|
237
|
+
if (wasm !== undefined) return wasm;
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
if (module_or_path !== undefined) {
|
|
241
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
242
|
+
({module_or_path} = module_or_path)
|
|
243
|
+
} else {
|
|
244
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (module_or_path === undefined) {
|
|
249
|
+
module_or_path = new URL('mingli_wasm_bg.wasm', import.meta.url);
|
|
250
|
+
}
|
|
251
|
+
const imports = __wbg_get_imports();
|
|
252
|
+
|
|
253
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
254
|
+
module_or_path = fetch(module_or_path);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
258
|
+
|
|
259
|
+
return __wbg_finalize_init(instance, module);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
export { initSync, __wbg_init as default };
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
export const memory: WebAssembly.Memory;
|
|
4
|
+
export const cast: (a: number, b: number) => [number, number, number, number];
|
|
5
|
+
export const cast_one: (a: number, b: number, c: number, d: number) => [number, number, number, number];
|
|
6
|
+
export const __wbindgen_externrefs: WebAssembly.Table;
|
|
7
|
+
export const __wbindgen_malloc: (a: number, b: number) => number;
|
|
8
|
+
export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
9
|
+
export const __externref_table_dealloc: (a: number) => void;
|
|
10
|
+
export const __wbindgen_free: (a: number, b: number, c: number) => void;
|
|
11
|
+
export const __wbindgen_start: () => void;
|
package/package.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mingli-wasm-bazi",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Four Pillars of Destiny alone.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": { "type": "git", "url": "git+https://github.com/goliajp/mingli.git" },
|
|
7
|
+
"keywords": ["bazi", "four-pillars", "chinese", "astrology", "wasm"],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "mingli_wasm.js",
|
|
10
|
+
"module": "mingli_wasm.js",
|
|
11
|
+
"types": "mingli_wasm.d.ts",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"files": ["mingli_wasm.js", "mingli_wasm_bg.wasm", "mingli_wasm.d.ts", "mingli_wasm_bg.wasm.d.ts", "README.md"]
|
|
14
|
+
}
|