@sansavision/vidra-player 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.
@@ -0,0 +1,368 @@
1
+ /* @ts-self-types="./vidra_wasm.d.ts" */
2
+
3
+ /**
4
+ * Get project metadata from IR JSON.
5
+ *
6
+ * Returns a JSON string: { width, height, fps, totalFrames, totalDuration, sceneCount }
7
+ * @param {string} ir_json
8
+ * @returns {string}
9
+ */
10
+ export function get_project_info(ir_json) {
11
+ let deferred3_0;
12
+ let deferred3_1;
13
+ try {
14
+ const ptr0 = passStringToWasm0(ir_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
15
+ const len0 = WASM_VECTOR_LEN;
16
+ const ret = wasm.get_project_info(ptr0, len0);
17
+ var ptr2 = ret[0];
18
+ var len2 = ret[1];
19
+ if (ret[3]) {
20
+ ptr2 = 0; len2 = 0;
21
+ throw takeFromExternrefTable0(ret[2]);
22
+ }
23
+ deferred3_0 = ptr2;
24
+ deferred3_1 = len2;
25
+ return getStringFromWasm0(ptr2, len2);
26
+ } finally {
27
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Initialize the WASM module. Call this once before rendering.
33
+ */
34
+ export function init() {
35
+ wasm.init();
36
+ }
37
+
38
+ /**
39
+ * Load an image asset (as raw bytes) into the renderer cache.
40
+ *
41
+ * Call this before rendering frames that reference the asset.
42
+ * @param {string} asset_id
43
+ * @param {Uint8Array} data
44
+ */
45
+ export function load_image_asset(asset_id, data) {
46
+ const ptr0 = passStringToWasm0(asset_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
47
+ const len0 = WASM_VECTOR_LEN;
48
+ const ptr1 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
49
+ const len1 = WASM_VECTOR_LEN;
50
+ wasm.load_image_asset(ptr0, len0, ptr1, len1);
51
+ }
52
+
53
+ /**
54
+ * Parse VidraScript source and compile to IR JSON.
55
+ *
56
+ * Returns a JSON string representing the project IR.
57
+ * Throws a JS error if parsing fails.
58
+ * @param {string} source
59
+ * @returns {string}
60
+ */
61
+ export function parse_and_compile(source) {
62
+ let deferred3_0;
63
+ let deferred3_1;
64
+ try {
65
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
66
+ const len0 = WASM_VECTOR_LEN;
67
+ const ret = wasm.parse_and_compile(ptr0, len0);
68
+ var ptr2 = ret[0];
69
+ var len2 = ret[1];
70
+ if (ret[3]) {
71
+ ptr2 = 0; len2 = 0;
72
+ throw takeFromExternrefTable0(ret[2]);
73
+ }
74
+ deferred3_0 = ptr2;
75
+ deferred3_1 = len2;
76
+ return getStringFromWasm0(ptr2, len2);
77
+ } finally {
78
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Render a single frame and return RGBA pixel data.
84
+ *
85
+ * Returns a `Vec<u8>` of length `width * height * 4`.
86
+ * @param {string} ir_json
87
+ * @param {number} frame_index
88
+ * @returns {Uint8Array}
89
+ */
90
+ export function render_frame(ir_json, frame_index) {
91
+ const ptr0 = passStringToWasm0(ir_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
92
+ const len0 = WASM_VECTOR_LEN;
93
+ const ret = wasm.render_frame(ptr0, len0, frame_index);
94
+ if (ret[3]) {
95
+ throw takeFromExternrefTable0(ret[2]);
96
+ }
97
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
98
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
99
+ return v2;
100
+ }
101
+
102
+ /**
103
+ * Render a single frame from VidraScript source directly.
104
+ *
105
+ * Convenience method that combines parse + compile + render.
106
+ * @param {string} source
107
+ * @param {number} frame_index
108
+ * @returns {Uint8Array}
109
+ */
110
+ export function render_frame_from_source(source, frame_index) {
111
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
112
+ const len0 = WASM_VECTOR_LEN;
113
+ const ret = wasm.render_frame_from_source(ptr0, len0, frame_index);
114
+ if (ret[3]) {
115
+ throw takeFromExternrefTable0(ret[2]);
116
+ }
117
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
118
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
119
+ return v2;
120
+ }
121
+
122
+ /**
123
+ * Get the version string.
124
+ * @returns {string}
125
+ */
126
+ export function version() {
127
+ let deferred1_0;
128
+ let deferred1_1;
129
+ try {
130
+ const ret = wasm.version();
131
+ deferred1_0 = ret[0];
132
+ deferred1_1 = ret[1];
133
+ return getStringFromWasm0(ret[0], ret[1]);
134
+ } finally {
135
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
136
+ }
137
+ }
138
+
139
+ function __wbg_get_imports() {
140
+ const import0 = {
141
+ __proto__: null,
142
+ __wbg_getRandomValues_3dda8830c2565714: function() { return handleError(function (arg0, arg1) {
143
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
144
+ }, arguments); },
145
+ __wbindgen_cast_0000000000000001: function(arg0, arg1) {
146
+ // Cast intrinsic for `Ref(String) -> Externref`.
147
+ const ret = getStringFromWasm0(arg0, arg1);
148
+ return ret;
149
+ },
150
+ __wbindgen_init_externref_table: function() {
151
+ const table = wasm.__wbindgen_externrefs;
152
+ const offset = table.grow(4);
153
+ table.set(0, undefined);
154
+ table.set(offset + 0, undefined);
155
+ table.set(offset + 1, null);
156
+ table.set(offset + 2, true);
157
+ table.set(offset + 3, false);
158
+ },
159
+ };
160
+ return {
161
+ __proto__: null,
162
+ "./vidra_wasm_bg.js": import0,
163
+ };
164
+ }
165
+
166
+ function addToExternrefTable0(obj) {
167
+ const idx = wasm.__externref_table_alloc();
168
+ wasm.__wbindgen_externrefs.set(idx, obj);
169
+ return idx;
170
+ }
171
+
172
+ function getArrayU8FromWasm0(ptr, len) {
173
+ ptr = ptr >>> 0;
174
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
175
+ }
176
+
177
+ function getStringFromWasm0(ptr, len) {
178
+ ptr = ptr >>> 0;
179
+ return decodeText(ptr, len);
180
+ }
181
+
182
+ let cachedUint8ArrayMemory0 = null;
183
+ function getUint8ArrayMemory0() {
184
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
185
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
186
+ }
187
+ return cachedUint8ArrayMemory0;
188
+ }
189
+
190
+ function handleError(f, args) {
191
+ try {
192
+ return f.apply(this, args);
193
+ } catch (e) {
194
+ const idx = addToExternrefTable0(e);
195
+ wasm.__wbindgen_exn_store(idx);
196
+ }
197
+ }
198
+
199
+ function passArray8ToWasm0(arg, malloc) {
200
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
201
+ getUint8ArrayMemory0().set(arg, ptr / 1);
202
+ WASM_VECTOR_LEN = arg.length;
203
+ return ptr;
204
+ }
205
+
206
+ function passStringToWasm0(arg, malloc, realloc) {
207
+ if (realloc === undefined) {
208
+ const buf = cachedTextEncoder.encode(arg);
209
+ const ptr = malloc(buf.length, 1) >>> 0;
210
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
211
+ WASM_VECTOR_LEN = buf.length;
212
+ return ptr;
213
+ }
214
+
215
+ let len = arg.length;
216
+ let ptr = malloc(len, 1) >>> 0;
217
+
218
+ const mem = getUint8ArrayMemory0();
219
+
220
+ let offset = 0;
221
+
222
+ for (; offset < len; offset++) {
223
+ const code = arg.charCodeAt(offset);
224
+ if (code > 0x7F) break;
225
+ mem[ptr + offset] = code;
226
+ }
227
+ if (offset !== len) {
228
+ if (offset !== 0) {
229
+ arg = arg.slice(offset);
230
+ }
231
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
232
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
233
+ const ret = cachedTextEncoder.encodeInto(arg, view);
234
+
235
+ offset += ret.written;
236
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
237
+ }
238
+
239
+ WASM_VECTOR_LEN = offset;
240
+ return ptr;
241
+ }
242
+
243
+ function takeFromExternrefTable0(idx) {
244
+ const value = wasm.__wbindgen_externrefs.get(idx);
245
+ wasm.__externref_table_dealloc(idx);
246
+ return value;
247
+ }
248
+
249
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
250
+ cachedTextDecoder.decode();
251
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
252
+ let numBytesDecoded = 0;
253
+ function decodeText(ptr, len) {
254
+ numBytesDecoded += len;
255
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
256
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
257
+ cachedTextDecoder.decode();
258
+ numBytesDecoded = len;
259
+ }
260
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
261
+ }
262
+
263
+ const cachedTextEncoder = new TextEncoder();
264
+
265
+ if (!('encodeInto' in cachedTextEncoder)) {
266
+ cachedTextEncoder.encodeInto = function (arg, view) {
267
+ const buf = cachedTextEncoder.encode(arg);
268
+ view.set(buf);
269
+ return {
270
+ read: arg.length,
271
+ written: buf.length
272
+ };
273
+ };
274
+ }
275
+
276
+ let WASM_VECTOR_LEN = 0;
277
+
278
+ let wasmModule, wasm;
279
+ function __wbg_finalize_init(instance, module) {
280
+ wasm = instance.exports;
281
+ wasmModule = module;
282
+ cachedUint8ArrayMemory0 = null;
283
+ wasm.__wbindgen_start();
284
+ return wasm;
285
+ }
286
+
287
+ async function __wbg_load(module, imports) {
288
+ if (typeof Response === 'function' && module instanceof Response) {
289
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
290
+ try {
291
+ return await WebAssembly.instantiateStreaming(module, imports);
292
+ } catch (e) {
293
+ const validResponse = module.ok && expectedResponseType(module.type);
294
+
295
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
296
+ 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);
297
+
298
+ } else { throw e; }
299
+ }
300
+ }
301
+
302
+ const bytes = await module.arrayBuffer();
303
+ return await WebAssembly.instantiate(bytes, imports);
304
+ } else {
305
+ const instance = await WebAssembly.instantiate(module, imports);
306
+
307
+ if (instance instanceof WebAssembly.Instance) {
308
+ return { instance, module };
309
+ } else {
310
+ return instance;
311
+ }
312
+ }
313
+
314
+ function expectedResponseType(type) {
315
+ switch (type) {
316
+ case 'basic': case 'cors': case 'default': return true;
317
+ }
318
+ return false;
319
+ }
320
+ }
321
+
322
+ function initSync(module) {
323
+ if (wasm !== undefined) return wasm;
324
+
325
+
326
+ if (module !== undefined) {
327
+ if (Object.getPrototypeOf(module) === Object.prototype) {
328
+ ({module} = module)
329
+ } else {
330
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
331
+ }
332
+ }
333
+
334
+ const imports = __wbg_get_imports();
335
+ if (!(module instanceof WebAssembly.Module)) {
336
+ module = new WebAssembly.Module(module);
337
+ }
338
+ const instance = new WebAssembly.Instance(module, imports);
339
+ return __wbg_finalize_init(instance, module);
340
+ }
341
+
342
+ async function __wbg_init(module_or_path) {
343
+ if (wasm !== undefined) return wasm;
344
+
345
+
346
+ if (module_or_path !== undefined) {
347
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
348
+ ({module_or_path} = module_or_path)
349
+ } else {
350
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
351
+ }
352
+ }
353
+
354
+ if (module_or_path === undefined) {
355
+ module_or_path = new URL('vidra_wasm_bg.wasm', import.meta.url);
356
+ }
357
+ const imports = __wbg_get_imports();
358
+
359
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
360
+ module_or_path = fetch(module_or_path);
361
+ }
362
+
363
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
364
+
365
+ return __wbg_finalize_init(instance, module);
366
+ }
367
+
368
+ export { initSync, __wbg_init as default };
Binary file
@@ -0,0 +1,18 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const get_project_info: (a: number, b: number) => [number, number, number, number];
5
+ export const load_image_asset: (a: number, b: number, c: number, d: number) => void;
6
+ export const parse_and_compile: (a: number, b: number) => [number, number, number, number];
7
+ export const render_frame: (a: number, b: number, c: number) => [number, number, number, number];
8
+ export const render_frame_from_source: (a: number, b: number, c: number) => [number, number, number, number];
9
+ export const version: () => [number, number];
10
+ export const init: () => void;
11
+ export const __wbindgen_exn_store: (a: number) => void;
12
+ export const __externref_table_alloc: () => number;
13
+ export const __wbindgen_externrefs: WebAssembly.Table;
14
+ export const __wbindgen_malloc: (a: number, b: number) => number;
15
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
16
+ export const __externref_table_dealloc: (a: number) => void;
17
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
18
+ export const __wbindgen_start: () => void;