reactcut-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/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "reactcut-wasm",
3
+ "type": "module",
4
+ "description": "WebAssembly bindings for ReactCut core engine",
5
+ "version": "0.1.0",
6
+ "license": "Apache-2.0",
7
+ "files": [
8
+ "reactcut_wasm_bg.wasm",
9
+ "reactcut_wasm.js",
10
+ "reactcut_wasm.d.ts"
11
+ ],
12
+ "main": "reactcut_wasm.js",
13
+ "types": "reactcut_wasm.d.ts",
14
+ "sideEffects": [
15
+ "./snippets/*"
16
+ ]
17
+ }
@@ -0,0 +1,64 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Get the computed animation style for a clip at a specific frame.
6
+ * Input: clip JSON string and absolute frame number.
7
+ * Returns a JSON object with computed style properties.
8
+ */
9
+ export function getAnimationState(clip_json: string, frame: number): any;
10
+
11
+ /**
12
+ * Interpolate between two values with easing.
13
+ */
14
+ export function interpolate(from: number, to: number, progress: number, easing: string): number;
15
+
16
+ /**
17
+ * Normalize a ReactCut project JSON string.
18
+ * Returns the normalized project as a JSON string.
19
+ */
20
+ export function normalizeProject(json: string): string;
21
+
22
+ /**
23
+ * Validate a ReactCut project JSON string.
24
+ * Returns a JSON object with `{ valid: bool, errors: string[], warnings: string[] }`.
25
+ */
26
+ export function validateProject(json: string): any;
27
+
28
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
29
+
30
+ export interface InitOutput {
31
+ readonly memory: WebAssembly.Memory;
32
+ readonly getAnimationState: (a: number, b: number, c: number) => [number, number, number];
33
+ readonly interpolate: (a: number, b: number, c: number, d: number, e: number) => number;
34
+ readonly normalizeProject: (a: number, b: number) => [number, number, number, number];
35
+ readonly validateProject: (a: number, b: number) => [number, number, number];
36
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
37
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
38
+ readonly __wbindgen_externrefs: WebAssembly.Table;
39
+ readonly __externref_table_dealloc: (a: number) => void;
40
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
41
+ readonly __wbindgen_start: () => void;
42
+ }
43
+
44
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
45
+
46
+ /**
47
+ * Instantiates the given `module`, which can either be bytes or
48
+ * a precompiled `WebAssembly.Module`.
49
+ *
50
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
51
+ *
52
+ * @returns {InitOutput}
53
+ */
54
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
55
+
56
+ /**
57
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
58
+ * for everything else, calls `WebAssembly.instantiate` directly.
59
+ *
60
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
61
+ *
62
+ * @returns {Promise<InitOutput>}
63
+ */
64
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
@@ -0,0 +1,341 @@
1
+ /* @ts-self-types="./reactcut_wasm.d.ts" */
2
+
3
+ /**
4
+ * Get the computed animation style for a clip at a specific frame.
5
+ * Input: clip JSON string and absolute frame number.
6
+ * Returns a JSON object with computed style properties.
7
+ * @param {string} clip_json
8
+ * @param {number} frame
9
+ * @returns {any}
10
+ */
11
+ export function getAnimationState(clip_json, frame) {
12
+ const ptr0 = passStringToWasm0(clip_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
13
+ const len0 = WASM_VECTOR_LEN;
14
+ const ret = wasm.getAnimationState(ptr0, len0, frame);
15
+ if (ret[2]) {
16
+ throw takeFromExternrefTable0(ret[1]);
17
+ }
18
+ return takeFromExternrefTable0(ret[0]);
19
+ }
20
+
21
+ /**
22
+ * Interpolate between two values with easing.
23
+ * @param {number} from
24
+ * @param {number} to
25
+ * @param {number} progress
26
+ * @param {string} easing
27
+ * @returns {number}
28
+ */
29
+ export function interpolate(from, to, progress, easing) {
30
+ const ptr0 = passStringToWasm0(easing, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
31
+ const len0 = WASM_VECTOR_LEN;
32
+ const ret = wasm.interpolate(from, to, progress, ptr0, len0);
33
+ return ret;
34
+ }
35
+
36
+ /**
37
+ * Normalize a ReactCut project JSON string.
38
+ * Returns the normalized project as a JSON string.
39
+ * @param {string} json
40
+ * @returns {string}
41
+ */
42
+ export function normalizeProject(json) {
43
+ let deferred3_0;
44
+ let deferred3_1;
45
+ try {
46
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
47
+ const len0 = WASM_VECTOR_LEN;
48
+ const ret = wasm.normalizeProject(ptr0, len0);
49
+ var ptr2 = ret[0];
50
+ var len2 = ret[1];
51
+ if (ret[3]) {
52
+ ptr2 = 0; len2 = 0;
53
+ throw takeFromExternrefTable0(ret[2]);
54
+ }
55
+ deferred3_0 = ptr2;
56
+ deferred3_1 = len2;
57
+ return getStringFromWasm0(ptr2, len2);
58
+ } finally {
59
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Validate a ReactCut project JSON string.
65
+ * Returns a JSON object with `{ valid: bool, errors: string[], warnings: string[] }`.
66
+ * @param {string} json
67
+ * @returns {any}
68
+ */
69
+ export function validateProject(json) {
70
+ const ptr0 = passStringToWasm0(json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
71
+ const len0 = WASM_VECTOR_LEN;
72
+ const ret = wasm.validateProject(ptr0, len0);
73
+ if (ret[2]) {
74
+ throw takeFromExternrefTable0(ret[1]);
75
+ }
76
+ return takeFromExternrefTable0(ret[0]);
77
+ }
78
+ function __wbg_get_imports() {
79
+ const import0 = {
80
+ __proto__: null,
81
+ __wbg_Error_bce6d499ff0a4aff: function(arg0, arg1) {
82
+ const ret = Error(getStringFromWasm0(arg0, arg1));
83
+ return ret;
84
+ },
85
+ __wbg_String_8564e559799eccda: function(arg0, arg1) {
86
+ const ret = String(arg1);
87
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
88
+ const len1 = WASM_VECTOR_LEN;
89
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
90
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
91
+ },
92
+ __wbg___wbindgen_is_string_dde0fd9020db4434: function(arg0) {
93
+ const ret = typeof(arg0) === 'string';
94
+ return ret;
95
+ },
96
+ __wbg___wbindgen_throw_9c31b086c2b26051: function(arg0, arg1) {
97
+ throw new Error(getStringFromWasm0(arg0, arg1));
98
+ },
99
+ __wbg_new_02d162bc6cf02f60: function() {
100
+ const ret = new Object();
101
+ return ret;
102
+ },
103
+ __wbg_new_070df68d66325372: function() {
104
+ const ret = new Map();
105
+ return ret;
106
+ },
107
+ __wbg_new_310879b66b6e95e1: function() {
108
+ const ret = new Array();
109
+ return ret;
110
+ },
111
+ __wbg_set_6be42768c690e380: function(arg0, arg1, arg2) {
112
+ arg0[arg1] = arg2;
113
+ },
114
+ __wbg_set_78ea6a19f4818587: function(arg0, arg1, arg2) {
115
+ arg0[arg1 >>> 0] = arg2;
116
+ },
117
+ __wbg_set_facb7a5914e0fa39: function(arg0, arg1, arg2) {
118
+ const ret = arg0.set(arg1, arg2);
119
+ return ret;
120
+ },
121
+ __wbindgen_cast_0000000000000001: function(arg0) {
122
+ // Cast intrinsic for `F64 -> Externref`.
123
+ const ret = arg0;
124
+ return ret;
125
+ },
126
+ __wbindgen_cast_0000000000000002: function(arg0) {
127
+ // Cast intrinsic for `I64 -> Externref`.
128
+ const ret = arg0;
129
+ return ret;
130
+ },
131
+ __wbindgen_cast_0000000000000003: function(arg0, arg1) {
132
+ // Cast intrinsic for `Ref(String) -> Externref`.
133
+ const ret = getStringFromWasm0(arg0, arg1);
134
+ return ret;
135
+ },
136
+ __wbindgen_cast_0000000000000004: function(arg0) {
137
+ // Cast intrinsic for `U64 -> Externref`.
138
+ const ret = BigInt.asUintN(64, arg0);
139
+ return ret;
140
+ },
141
+ __wbindgen_init_externref_table: function() {
142
+ const table = wasm.__wbindgen_externrefs;
143
+ const offset = table.grow(4);
144
+ table.set(0, undefined);
145
+ table.set(offset + 0, undefined);
146
+ table.set(offset + 1, null);
147
+ table.set(offset + 2, true);
148
+ table.set(offset + 3, false);
149
+ },
150
+ };
151
+ return {
152
+ __proto__: null,
153
+ "./reactcut_wasm_bg.js": import0,
154
+ };
155
+ }
156
+
157
+ let cachedDataViewMemory0 = null;
158
+ function getDataViewMemory0() {
159
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
160
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
161
+ }
162
+ return cachedDataViewMemory0;
163
+ }
164
+
165
+ function getStringFromWasm0(ptr, len) {
166
+ return decodeText(ptr >>> 0, len);
167
+ }
168
+
169
+ let cachedUint8ArrayMemory0 = null;
170
+ function getUint8ArrayMemory0() {
171
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
172
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
173
+ }
174
+ return cachedUint8ArrayMemory0;
175
+ }
176
+
177
+ function passStringToWasm0(arg, malloc, realloc) {
178
+ if (realloc === undefined) {
179
+ const buf = cachedTextEncoder.encode(arg);
180
+ const ptr = malloc(buf.length, 1) >>> 0;
181
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
182
+ WASM_VECTOR_LEN = buf.length;
183
+ return ptr;
184
+ }
185
+
186
+ let len = arg.length;
187
+ let ptr = malloc(len, 1) >>> 0;
188
+
189
+ const mem = getUint8ArrayMemory0();
190
+
191
+ let offset = 0;
192
+
193
+ for (; offset < len; offset++) {
194
+ const code = arg.charCodeAt(offset);
195
+ if (code > 0x7F) break;
196
+ mem[ptr + offset] = code;
197
+ }
198
+ if (offset !== len) {
199
+ if (offset !== 0) {
200
+ arg = arg.slice(offset);
201
+ }
202
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
203
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
204
+ const ret = cachedTextEncoder.encodeInto(arg, view);
205
+
206
+ offset += ret.written;
207
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
208
+ }
209
+
210
+ WASM_VECTOR_LEN = offset;
211
+ return ptr;
212
+ }
213
+
214
+ function takeFromExternrefTable0(idx) {
215
+ const value = wasm.__wbindgen_externrefs.get(idx);
216
+ wasm.__externref_table_dealloc(idx);
217
+ return value;
218
+ }
219
+
220
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
221
+ cachedTextDecoder.decode();
222
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
223
+ let numBytesDecoded = 0;
224
+ function decodeText(ptr, len) {
225
+ numBytesDecoded += len;
226
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
227
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
228
+ cachedTextDecoder.decode();
229
+ numBytesDecoded = len;
230
+ }
231
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
232
+ }
233
+
234
+ const cachedTextEncoder = new TextEncoder();
235
+
236
+ if (!('encodeInto' in cachedTextEncoder)) {
237
+ cachedTextEncoder.encodeInto = function (arg, view) {
238
+ const buf = cachedTextEncoder.encode(arg);
239
+ view.set(buf);
240
+ return {
241
+ read: arg.length,
242
+ written: buf.length
243
+ };
244
+ };
245
+ }
246
+
247
+ let WASM_VECTOR_LEN = 0;
248
+
249
+ let wasmModule, wasmInstance, wasm;
250
+ function __wbg_finalize_init(instance, module) {
251
+ wasmInstance = instance;
252
+ wasm = instance.exports;
253
+ wasmModule = module;
254
+ cachedDataViewMemory0 = null;
255
+ cachedUint8ArrayMemory0 = null;
256
+ wasm.__wbindgen_start();
257
+ return wasm;
258
+ }
259
+
260
+ async function __wbg_load(module, imports) {
261
+ if (typeof Response === 'function' && module instanceof Response) {
262
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
263
+ try {
264
+ return await WebAssembly.instantiateStreaming(module, imports);
265
+ } catch (e) {
266
+ const validResponse = module.ok && expectedResponseType(module.type);
267
+
268
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
269
+ 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);
270
+
271
+ } else { throw e; }
272
+ }
273
+ }
274
+
275
+ const bytes = await module.arrayBuffer();
276
+ return await WebAssembly.instantiate(bytes, imports);
277
+ } else {
278
+ const instance = await WebAssembly.instantiate(module, imports);
279
+
280
+ if (instance instanceof WebAssembly.Instance) {
281
+ return { instance, module };
282
+ } else {
283
+ return instance;
284
+ }
285
+ }
286
+
287
+ function expectedResponseType(type) {
288
+ switch (type) {
289
+ case 'basic': case 'cors': case 'default': return true;
290
+ }
291
+ return false;
292
+ }
293
+ }
294
+
295
+ function initSync(module) {
296
+ if (wasm !== undefined) return wasm;
297
+
298
+
299
+ if (module !== undefined) {
300
+ if (Object.getPrototypeOf(module) === Object.prototype) {
301
+ ({module} = module)
302
+ } else {
303
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
304
+ }
305
+ }
306
+
307
+ const imports = __wbg_get_imports();
308
+ if (!(module instanceof WebAssembly.Module)) {
309
+ module = new WebAssembly.Module(module);
310
+ }
311
+ const instance = new WebAssembly.Instance(module, imports);
312
+ return __wbg_finalize_init(instance, module);
313
+ }
314
+
315
+ async function __wbg_init(module_or_path) {
316
+ if (wasm !== undefined) return wasm;
317
+
318
+
319
+ if (module_or_path !== undefined) {
320
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
321
+ ({module_or_path} = module_or_path)
322
+ } else {
323
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
324
+ }
325
+ }
326
+
327
+ if (module_or_path === undefined) {
328
+ module_or_path = new URL('reactcut_wasm_bg.wasm', import.meta.url);
329
+ }
330
+ const imports = __wbg_get_imports();
331
+
332
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
333
+ module_or_path = fetch(module_or_path);
334
+ }
335
+
336
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
337
+
338
+ return __wbg_finalize_init(instance, module);
339
+ }
340
+
341
+ export { initSync, __wbg_init as default };
Binary file