libbitsub 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.
@@ -0,0 +1,880 @@
1
+ let wasm;
2
+
3
+ function getArrayU8FromWasm0(ptr, len) {
4
+ ptr = ptr >>> 0;
5
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
6
+ }
7
+
8
+ let cachedDataViewMemory0 = null;
9
+ function getDataViewMemory0() {
10
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
11
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
12
+ }
13
+ return cachedDataViewMemory0;
14
+ }
15
+
16
+ function getStringFromWasm0(ptr, len) {
17
+ ptr = ptr >>> 0;
18
+ return decodeText(ptr, len);
19
+ }
20
+
21
+ let cachedUint8ArrayMemory0 = null;
22
+ function getUint8ArrayMemory0() {
23
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
24
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
25
+ }
26
+ return cachedUint8ArrayMemory0;
27
+ }
28
+
29
+ function passArray8ToWasm0(arg, malloc) {
30
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
31
+ getUint8ArrayMemory0().set(arg, ptr / 1);
32
+ WASM_VECTOR_LEN = arg.length;
33
+ return ptr;
34
+ }
35
+
36
+ function passStringToWasm0(arg, malloc, realloc) {
37
+ if (realloc === undefined) {
38
+ const buf = cachedTextEncoder.encode(arg);
39
+ const ptr = malloc(buf.length, 1) >>> 0;
40
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
41
+ WASM_VECTOR_LEN = buf.length;
42
+ return ptr;
43
+ }
44
+
45
+ let len = arg.length;
46
+ let ptr = malloc(len, 1) >>> 0;
47
+
48
+ const mem = getUint8ArrayMemory0();
49
+
50
+ let offset = 0;
51
+
52
+ for (; offset < len; offset++) {
53
+ const code = arg.charCodeAt(offset);
54
+ if (code > 0x7F) break;
55
+ mem[ptr + offset] = code;
56
+ }
57
+ if (offset !== len) {
58
+ if (offset !== 0) {
59
+ arg = arg.slice(offset);
60
+ }
61
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
62
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
63
+ const ret = cachedTextEncoder.encodeInto(arg, view);
64
+
65
+ offset += ret.written;
66
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
67
+ }
68
+
69
+ WASM_VECTOR_LEN = offset;
70
+ return ptr;
71
+ }
72
+
73
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
74
+ cachedTextDecoder.decode();
75
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
76
+ let numBytesDecoded = 0;
77
+ function decodeText(ptr, len) {
78
+ numBytesDecoded += len;
79
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
80
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
81
+ cachedTextDecoder.decode();
82
+ numBytesDecoded = len;
83
+ }
84
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
85
+ }
86
+
87
+ const cachedTextEncoder = new TextEncoder();
88
+
89
+ if (!('encodeInto' in cachedTextEncoder)) {
90
+ cachedTextEncoder.encodeInto = function (arg, view) {
91
+ const buf = cachedTextEncoder.encode(arg);
92
+ view.set(buf);
93
+ return {
94
+ read: arg.length,
95
+ written: buf.length
96
+ };
97
+ }
98
+ }
99
+
100
+ let WASM_VECTOR_LEN = 0;
101
+
102
+ const PgsParserFinalization = (typeof FinalizationRegistry === 'undefined')
103
+ ? { register: () => {}, unregister: () => {} }
104
+ : new FinalizationRegistry(ptr => wasm.__wbg_pgsparser_free(ptr >>> 0, 1));
105
+
106
+ const RenderResultFinalization = (typeof FinalizationRegistry === 'undefined')
107
+ ? { register: () => {}, unregister: () => {} }
108
+ : new FinalizationRegistry(ptr => wasm.__wbg_renderresult_free(ptr >>> 0, 1));
109
+
110
+ const SubtitleCompositionFinalization = (typeof FinalizationRegistry === 'undefined')
111
+ ? { register: () => {}, unregister: () => {} }
112
+ : new FinalizationRegistry(ptr => wasm.__wbg_subtitlecomposition_free(ptr >>> 0, 1));
113
+
114
+ const SubtitleFrameFinalization = (typeof FinalizationRegistry === 'undefined')
115
+ ? { register: () => {}, unregister: () => {} }
116
+ : new FinalizationRegistry(ptr => wasm.__wbg_subtitleframe_free(ptr >>> 0, 1));
117
+
118
+ const SubtitleRendererFinalization = (typeof FinalizationRegistry === 'undefined')
119
+ ? { register: () => {}, unregister: () => {} }
120
+ : new FinalizationRegistry(ptr => wasm.__wbg_subtitlerenderer_free(ptr >>> 0, 1));
121
+
122
+ const VobSubFrameFinalization = (typeof FinalizationRegistry === 'undefined')
123
+ ? { register: () => {}, unregister: () => {} }
124
+ : new FinalizationRegistry(ptr => wasm.__wbg_vobsubframe_free(ptr >>> 0, 1));
125
+
126
+ const VobSubParserFinalization = (typeof FinalizationRegistry === 'undefined')
127
+ ? { register: () => {}, unregister: () => {} }
128
+ : new FinalizationRegistry(ptr => wasm.__wbg_vobsubparser_free(ptr >>> 0, 1));
129
+
130
+ /**
131
+ * PGS subtitle parser and renderer exposed to JavaScript.
132
+ */
133
+ export class PgsParser {
134
+ __destroy_into_raw() {
135
+ const ptr = this.__wbg_ptr;
136
+ this.__wbg_ptr = 0;
137
+ PgsParserFinalization.unregister(this);
138
+ return ptr;
139
+ }
140
+ free() {
141
+ const ptr = this.__destroy_into_raw();
142
+ wasm.__wbg_pgsparser_free(ptr, 0);
143
+ }
144
+ /**
145
+ * Clear the internal cache.
146
+ */
147
+ clearCache() {
148
+ wasm.pgsparser_clearCache(this.__wbg_ptr);
149
+ }
150
+ /**
151
+ * Get all timestamps in milliseconds as a Float64Array.
152
+ * @returns {Float64Array}
153
+ */
154
+ getTimestamps() {
155
+ const ret = wasm.pgsparser_getTimestamps(this.__wbg_ptr);
156
+ return ret;
157
+ }
158
+ /**
159
+ * Render subtitle at the given index and return RGBA data.
160
+ * Returns null if index is invalid or no subtitle data.
161
+ * @param {number} index
162
+ * @returns {SubtitleFrame | undefined}
163
+ */
164
+ renderAtIndex(index) {
165
+ const ret = wasm.pgsparser_renderAtIndex(this.__wbg_ptr, index);
166
+ return ret === 0 ? undefined : SubtitleFrame.__wrap(ret);
167
+ }
168
+ /**
169
+ * Find the display set index for a given timestamp in milliseconds.
170
+ * @param {number} time_ms
171
+ * @returns {number}
172
+ */
173
+ findIndexAtTimestamp(time_ms) {
174
+ const ret = wasm.pgsparser_findIndexAtTimestamp(this.__wbg_ptr, time_ms);
175
+ return ret;
176
+ }
177
+ /**
178
+ * Create a new PGS parser.
179
+ */
180
+ constructor() {
181
+ const ret = wasm.pgsparser_new();
182
+ this.__wbg_ptr = ret >>> 0;
183
+ PgsParserFinalization.register(this, this.__wbg_ptr, this);
184
+ return this;
185
+ }
186
+ /**
187
+ * Get the number of display sets.
188
+ * @returns {number}
189
+ */
190
+ get count() {
191
+ const ret = wasm.pgsparser_count(this.__wbg_ptr);
192
+ return ret >>> 0;
193
+ }
194
+ /**
195
+ * Parse a PGS file from binary data.
196
+ * Returns the number of display sets parsed.
197
+ * @param {Uint8Array} data
198
+ * @returns {number}
199
+ */
200
+ parse(data) {
201
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
202
+ const len0 = WASM_VECTOR_LEN;
203
+ const ret = wasm.pgsparser_parse(this.__wbg_ptr, ptr0, len0);
204
+ return ret >>> 0;
205
+ }
206
+ }
207
+ if (Symbol.dispose) PgsParser.prototype[Symbol.dispose] = PgsParser.prototype.free;
208
+
209
+ /**
210
+ * Unified render result for both formats.
211
+ */
212
+ export class RenderResult {
213
+ static __wrap(ptr) {
214
+ ptr = ptr >>> 0;
215
+ const obj = Object.create(RenderResult.prototype);
216
+ obj.__wbg_ptr = ptr;
217
+ RenderResultFinalization.register(obj, obj.__wbg_ptr, obj);
218
+ return obj;
219
+ }
220
+ __destroy_into_raw() {
221
+ const ptr = this.__wbg_ptr;
222
+ this.__wbg_ptr = 0;
223
+ RenderResultFinalization.unregister(this);
224
+ return ptr;
225
+ }
226
+ free() {
227
+ const ptr = this.__destroy_into_raw();
228
+ wasm.__wbg_renderresult_free(ptr, 0);
229
+ }
230
+ /**
231
+ * @returns {number}
232
+ */
233
+ get screenWidth() {
234
+ const ret = wasm.renderresult_screenWidth(this.__wbg_ptr);
235
+ return ret;
236
+ }
237
+ /**
238
+ * @returns {number}
239
+ */
240
+ get screenHeight() {
241
+ const ret = wasm.renderresult_screenHeight(this.__wbg_ptr);
242
+ return ret;
243
+ }
244
+ /**
245
+ * Get the number of composition elements.
246
+ * @returns {number}
247
+ */
248
+ get compositionCount() {
249
+ const ret = wasm.renderresult_compositionCount(this.__wbg_ptr);
250
+ return ret >>> 0;
251
+ }
252
+ /**
253
+ * Get composition X position at index.
254
+ * @param {number} index
255
+ * @returns {number}
256
+ */
257
+ getCompositionX(index) {
258
+ const ret = wasm.renderresult_getCompositionX(this.__wbg_ptr, index);
259
+ return ret;
260
+ }
261
+ /**
262
+ * Get composition Y position at index.
263
+ * @param {number} index
264
+ * @returns {number}
265
+ */
266
+ getCompositionY(index) {
267
+ const ret = wasm.renderresult_getCompositionY(this.__wbg_ptr, index);
268
+ return ret;
269
+ }
270
+ /**
271
+ * Get composition RGBA data at index.
272
+ * @param {number} index
273
+ * @returns {Uint8Array}
274
+ */
275
+ getCompositionRgba(index) {
276
+ const ret = wasm.renderresult_getCompositionRgba(this.__wbg_ptr, index);
277
+ return ret;
278
+ }
279
+ /**
280
+ * Get composition width at index.
281
+ * @param {number} index
282
+ * @returns {number}
283
+ */
284
+ getCompositionWidth(index) {
285
+ const ret = wasm.renderresult_getCompositionWidth(this.__wbg_ptr, index);
286
+ return ret;
287
+ }
288
+ /**
289
+ * Get composition height at index.
290
+ * @param {number} index
291
+ * @returns {number}
292
+ */
293
+ getCompositionHeight(index) {
294
+ const ret = wasm.renderresult_getCompositionHeight(this.__wbg_ptr, index);
295
+ return ret;
296
+ }
297
+ }
298
+ if (Symbol.dispose) RenderResult.prototype[Symbol.dispose] = RenderResult.prototype.free;
299
+
300
+ /**
301
+ * A single subtitle composition element.
302
+ */
303
+ export class SubtitleComposition {
304
+ static __wrap(ptr) {
305
+ ptr = ptr >>> 0;
306
+ const obj = Object.create(SubtitleComposition.prototype);
307
+ obj.__wbg_ptr = ptr;
308
+ SubtitleCompositionFinalization.register(obj, obj.__wbg_ptr, obj);
309
+ return obj;
310
+ }
311
+ __destroy_into_raw() {
312
+ const ptr = this.__wbg_ptr;
313
+ this.__wbg_ptr = 0;
314
+ SubtitleCompositionFinalization.unregister(this);
315
+ return ptr;
316
+ }
317
+ free() {
318
+ const ptr = this.__destroy_into_raw();
319
+ wasm.__wbg_subtitlecomposition_free(ptr, 0);
320
+ }
321
+ /**
322
+ * @returns {number}
323
+ */
324
+ get x() {
325
+ const ret = wasm.subtitlecomposition_x(this.__wbg_ptr);
326
+ return ret;
327
+ }
328
+ /**
329
+ * @returns {number}
330
+ */
331
+ get y() {
332
+ const ret = wasm.subtitlecomposition_y(this.__wbg_ptr);
333
+ return ret;
334
+ }
335
+ /**
336
+ * @returns {number}
337
+ */
338
+ get width() {
339
+ const ret = wasm.subtitlecomposition_width(this.__wbg_ptr);
340
+ return ret;
341
+ }
342
+ /**
343
+ * @returns {number}
344
+ */
345
+ get height() {
346
+ const ret = wasm.subtitlecomposition_height(this.__wbg_ptr);
347
+ return ret;
348
+ }
349
+ /**
350
+ * Get RGBA pixel data as Uint8Array.
351
+ * @returns {Uint8Array}
352
+ */
353
+ getRgba() {
354
+ const ret = wasm.subtitlecomposition_getRgba(this.__wbg_ptr);
355
+ return ret;
356
+ }
357
+ }
358
+ if (Symbol.dispose) SubtitleComposition.prototype[Symbol.dispose] = SubtitleComposition.prototype.free;
359
+
360
+ /**
361
+ * Subtitle format type.
362
+ * @enum {0 | 1}
363
+ */
364
+ export const SubtitleFormat = Object.freeze({
365
+ /**
366
+ * PGS (Blu-ray) subtitle format
367
+ */
368
+ Pgs: 0, "0": "Pgs",
369
+ /**
370
+ * VobSub (DVD) subtitle format
371
+ */
372
+ VobSub: 1, "1": "VobSub",
373
+ });
374
+
375
+ /**
376
+ * A complete subtitle frame with all compositions.
377
+ */
378
+ export class SubtitleFrame {
379
+ static __wrap(ptr) {
380
+ ptr = ptr >>> 0;
381
+ const obj = Object.create(SubtitleFrame.prototype);
382
+ obj.__wbg_ptr = ptr;
383
+ SubtitleFrameFinalization.register(obj, obj.__wbg_ptr, obj);
384
+ return obj;
385
+ }
386
+ __destroy_into_raw() {
387
+ const ptr = this.__wbg_ptr;
388
+ this.__wbg_ptr = 0;
389
+ SubtitleFrameFinalization.unregister(this);
390
+ return ptr;
391
+ }
392
+ free() {
393
+ const ptr = this.__destroy_into_raw();
394
+ wasm.__wbg_subtitleframe_free(ptr, 0);
395
+ }
396
+ /**
397
+ * Get a composition by index.
398
+ * @param {number} index
399
+ * @returns {SubtitleComposition | undefined}
400
+ */
401
+ getComposition(index) {
402
+ const ret = wasm.subtitleframe_getComposition(this.__wbg_ptr, index);
403
+ return ret === 0 ? undefined : SubtitleComposition.__wrap(ret);
404
+ }
405
+ /**
406
+ * Get the number of compositions.
407
+ * @returns {number}
408
+ */
409
+ get compositionCount() {
410
+ const ret = wasm.renderresult_compositionCount(this.__wbg_ptr);
411
+ return ret >>> 0;
412
+ }
413
+ /**
414
+ * @returns {number}
415
+ */
416
+ get width() {
417
+ const ret = wasm.renderresult_screenWidth(this.__wbg_ptr);
418
+ return ret;
419
+ }
420
+ /**
421
+ * @returns {number}
422
+ */
423
+ get height() {
424
+ const ret = wasm.renderresult_screenHeight(this.__wbg_ptr);
425
+ return ret;
426
+ }
427
+ }
428
+ if (Symbol.dispose) SubtitleFrame.prototype[Symbol.dispose] = SubtitleFrame.prototype.free;
429
+
430
+ /**
431
+ * Unified subtitle renderer for both PGS and VobSub formats.
432
+ */
433
+ export class SubtitleRenderer {
434
+ __destroy_into_raw() {
435
+ const ptr = this.__wbg_ptr;
436
+ this.__wbg_ptr = 0;
437
+ SubtitleRendererFinalization.unregister(this);
438
+ return ptr;
439
+ }
440
+ free() {
441
+ const ptr = this.__destroy_into_raw();
442
+ wasm.__wbg_subtitlerenderer_free(ptr, 0);
443
+ }
444
+ /**
445
+ * Clear internal caches.
446
+ */
447
+ clearCache() {
448
+ wasm.subtitlerenderer_clearCache(this.__wbg_ptr);
449
+ }
450
+ /**
451
+ * Load VobSub subtitle data from IDX and SUB.
452
+ * @param {string} idx_content
453
+ * @param {Uint8Array} sub_data
454
+ */
455
+ loadVobSub(idx_content, sub_data) {
456
+ const ptr0 = passStringToWasm0(idx_content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
457
+ const len0 = WASM_VECTOR_LEN;
458
+ const ptr1 = passArray8ToWasm0(sub_data, wasm.__wbindgen_malloc);
459
+ const len1 = WASM_VECTOR_LEN;
460
+ wasm.subtitlerenderer_loadVobSub(this.__wbg_ptr, ptr0, len0, ptr1, len1);
461
+ }
462
+ /**
463
+ * Get all timestamps in milliseconds.
464
+ * @returns {Float64Array}
465
+ */
466
+ getTimestamps() {
467
+ const ret = wasm.subtitlerenderer_getTimestamps(this.__wbg_ptr);
468
+ return ret;
469
+ }
470
+ /**
471
+ * Render subtitle at the given index.
472
+ * Returns a unified RenderResult or null.
473
+ * @param {number} index
474
+ * @returns {RenderResult | undefined}
475
+ */
476
+ renderAtIndex(index) {
477
+ const ret = wasm.subtitlerenderer_renderAtIndex(this.__wbg_ptr, index);
478
+ return ret === 0 ? undefined : RenderResult.__wrap(ret);
479
+ }
480
+ /**
481
+ * Load VobSub from SUB file only.
482
+ * @param {Uint8Array} sub_data
483
+ */
484
+ loadVobSubOnly(sub_data) {
485
+ const ptr0 = passArray8ToWasm0(sub_data, wasm.__wbindgen_malloc);
486
+ const len0 = WASM_VECTOR_LEN;
487
+ wasm.subtitlerenderer_loadVobSubOnly(this.__wbg_ptr, ptr0, len0);
488
+ }
489
+ /**
490
+ * Render subtitle at the given timestamp in seconds.
491
+ * @param {number} time_seconds
492
+ * @returns {RenderResult | undefined}
493
+ */
494
+ renderAtTimestamp(time_seconds) {
495
+ const ret = wasm.subtitlerenderer_renderAtTimestamp(this.__wbg_ptr, time_seconds);
496
+ return ret === 0 ? undefined : RenderResult.__wrap(ret);
497
+ }
498
+ /**
499
+ * Find the subtitle index for a given timestamp in milliseconds.
500
+ * @param {number} time_ms
501
+ * @returns {number}
502
+ */
503
+ findIndexAtTimestamp(time_ms) {
504
+ const ret = wasm.subtitlerenderer_findIndexAtTimestamp(this.__wbg_ptr, time_ms);
505
+ return ret;
506
+ }
507
+ /**
508
+ * Create a new subtitle renderer.
509
+ */
510
+ constructor() {
511
+ const ret = wasm.subtitlerenderer_new();
512
+ this.__wbg_ptr = ret >>> 0;
513
+ SubtitleRendererFinalization.register(this, this.__wbg_ptr, this);
514
+ return this;
515
+ }
516
+ /**
517
+ * Get the number of subtitle entries.
518
+ * @returns {number}
519
+ */
520
+ get count() {
521
+ const ret = wasm.subtitlerenderer_count(this.__wbg_ptr);
522
+ return ret >>> 0;
523
+ }
524
+ /**
525
+ * Get the current subtitle format.
526
+ * @returns {SubtitleFormat | undefined}
527
+ */
528
+ get format() {
529
+ const ret = wasm.subtitlerenderer_format(this.__wbg_ptr);
530
+ return ret === 2 ? undefined : ret;
531
+ }
532
+ /**
533
+ * Dispose of all resources.
534
+ */
535
+ dispose() {
536
+ wasm.subtitlerenderer_dispose(this.__wbg_ptr);
537
+ }
538
+ /**
539
+ * Load PGS subtitle data.
540
+ * @param {Uint8Array} data
541
+ * @returns {number}
542
+ */
543
+ loadPgs(data) {
544
+ const ptr0 = passArray8ToWasm0(data, wasm.__wbindgen_malloc);
545
+ const len0 = WASM_VECTOR_LEN;
546
+ const ret = wasm.subtitlerenderer_loadPgs(this.__wbg_ptr, ptr0, len0);
547
+ return ret >>> 0;
548
+ }
549
+ }
550
+ if (Symbol.dispose) SubtitleRenderer.prototype[Symbol.dispose] = SubtitleRenderer.prototype.free;
551
+
552
+ /**
553
+ * A VobSub subtitle frame.
554
+ */
555
+ export class VobSubFrame {
556
+ static __wrap(ptr) {
557
+ ptr = ptr >>> 0;
558
+ const obj = Object.create(VobSubFrame.prototype);
559
+ obj.__wbg_ptr = ptr;
560
+ VobSubFrameFinalization.register(obj, obj.__wbg_ptr, obj);
561
+ return obj;
562
+ }
563
+ __destroy_into_raw() {
564
+ const ptr = this.__wbg_ptr;
565
+ this.__wbg_ptr = 0;
566
+ VobSubFrameFinalization.unregister(this);
567
+ return ptr;
568
+ }
569
+ free() {
570
+ const ptr = this.__destroy_into_raw();
571
+ wasm.__wbg_vobsubframe_free(ptr, 0);
572
+ }
573
+ /**
574
+ * @returns {number}
575
+ */
576
+ get screenWidth() {
577
+ const ret = wasm.vobsubframe_screenWidth(this.__wbg_ptr);
578
+ return ret;
579
+ }
580
+ /**
581
+ * @returns {number}
582
+ */
583
+ get screenHeight() {
584
+ const ret = wasm.vobsubframe_screenHeight(this.__wbg_ptr);
585
+ return ret;
586
+ }
587
+ /**
588
+ * @returns {number}
589
+ */
590
+ get x() {
591
+ const ret = wasm.vobsubframe_x(this.__wbg_ptr);
592
+ return ret;
593
+ }
594
+ /**
595
+ * @returns {number}
596
+ */
597
+ get y() {
598
+ const ret = wasm.vobsubframe_y(this.__wbg_ptr);
599
+ return ret;
600
+ }
601
+ /**
602
+ * @returns {number}
603
+ */
604
+ get width() {
605
+ const ret = wasm.vobsubframe_width(this.__wbg_ptr);
606
+ return ret;
607
+ }
608
+ /**
609
+ * @returns {number}
610
+ */
611
+ get height() {
612
+ const ret = wasm.vobsubframe_height(this.__wbg_ptr);
613
+ return ret;
614
+ }
615
+ /**
616
+ * Get RGBA pixel data as Uint8Array.
617
+ * @returns {Uint8Array}
618
+ */
619
+ getRgba() {
620
+ const ret = wasm.vobsubframe_getRgba(this.__wbg_ptr);
621
+ return ret;
622
+ }
623
+ }
624
+ if (Symbol.dispose) VobSubFrame.prototype[Symbol.dispose] = VobSubFrame.prototype.free;
625
+
626
+ /**
627
+ * VobSub subtitle parser and renderer exposed to JavaScript.
628
+ */
629
+ export class VobSubParser {
630
+ __destroy_into_raw() {
631
+ const ptr = this.__wbg_ptr;
632
+ this.__wbg_ptr = 0;
633
+ VobSubParserFinalization.unregister(this);
634
+ return ptr;
635
+ }
636
+ free() {
637
+ const ptr = this.__destroy_into_raw();
638
+ wasm.__wbg_vobsubparser_free(ptr, 0);
639
+ }
640
+ /**
641
+ * Clear the internal cache.
642
+ */
643
+ clearCache() {
644
+ wasm.vobsubparser_clearCache(this.__wbg_ptr);
645
+ }
646
+ /**
647
+ * Get all timestamps in milliseconds as a Float64Array.
648
+ * @returns {Float64Array}
649
+ */
650
+ getTimestamps() {
651
+ const ret = wasm.vobsubparser_getTimestamps(this.__wbg_ptr);
652
+ return ret;
653
+ }
654
+ /**
655
+ * Load VobSub from IDX content and SUB data.
656
+ * @param {string} idx_content
657
+ * @param {Uint8Array} sub_data
658
+ */
659
+ loadFromData(idx_content, sub_data) {
660
+ const ptr0 = passStringToWasm0(idx_content, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
661
+ const len0 = WASM_VECTOR_LEN;
662
+ const ptr1 = passArray8ToWasm0(sub_data, wasm.__wbindgen_malloc);
663
+ const len1 = WASM_VECTOR_LEN;
664
+ wasm.vobsubparser_loadFromData(this.__wbg_ptr, ptr0, len0, ptr1, len1);
665
+ }
666
+ /**
667
+ * Render subtitle at the given index and return RGBA data.
668
+ * @param {number} index
669
+ * @returns {VobSubFrame | undefined}
670
+ */
671
+ renderAtIndex(index) {
672
+ const ret = wasm.vobsubparser_renderAtIndex(this.__wbg_ptr, index);
673
+ return ret === 0 ? undefined : VobSubFrame.__wrap(ret);
674
+ }
675
+ /**
676
+ * Load VobSub from SUB file only (scans for timestamps).
677
+ * @param {Uint8Array} sub_data
678
+ */
679
+ loadFromSubOnly(sub_data) {
680
+ const ptr0 = passArray8ToWasm0(sub_data, wasm.__wbindgen_malloc);
681
+ const len0 = WASM_VECTOR_LEN;
682
+ wasm.vobsubparser_loadFromSubOnly(this.__wbg_ptr, ptr0, len0);
683
+ }
684
+ /**
685
+ * Find the subtitle index for a given timestamp in milliseconds.
686
+ * Returns -1 if no subtitle should be displayed at this time.
687
+ * @param {number} time_ms
688
+ * @returns {number}
689
+ */
690
+ findIndexAtTimestamp(time_ms) {
691
+ const ret = wasm.vobsubparser_findIndexAtTimestamp(this.__wbg_ptr, time_ms);
692
+ return ret;
693
+ }
694
+ /**
695
+ * Create a new VobSub parser.
696
+ */
697
+ constructor() {
698
+ const ret = wasm.vobsubparser_new();
699
+ this.__wbg_ptr = ret >>> 0;
700
+ VobSubParserFinalization.register(this, this.__wbg_ptr, this);
701
+ return this;
702
+ }
703
+ /**
704
+ * Get the number of subtitle entries.
705
+ * @returns {number}
706
+ */
707
+ get count() {
708
+ const ret = wasm.vobsubparser_count(this.__wbg_ptr);
709
+ return ret >>> 0;
710
+ }
711
+ /**
712
+ * Dispose of all resources.
713
+ */
714
+ dispose() {
715
+ wasm.vobsubparser_dispose(this.__wbg_ptr);
716
+ }
717
+ }
718
+ if (Symbol.dispose) VobSubParser.prototype[Symbol.dispose] = VobSubParser.prototype.free;
719
+
720
+ /**
721
+ * Initialize the WASM module. Call this once before using other functions.
722
+ */
723
+ export function init() {
724
+ wasm.init();
725
+ }
726
+
727
+ const EXPECTED_RESPONSE_TYPES = new Set(['basic', 'cors', 'default']);
728
+
729
+ async function __wbg_load(module, imports) {
730
+ if (typeof Response === 'function' && module instanceof Response) {
731
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
732
+ try {
733
+ return await WebAssembly.instantiateStreaming(module, imports);
734
+ } catch (e) {
735
+ const validResponse = module.ok && EXPECTED_RESPONSE_TYPES.has(module.type);
736
+
737
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
738
+ 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);
739
+
740
+ } else {
741
+ throw e;
742
+ }
743
+ }
744
+ }
745
+
746
+ const bytes = await module.arrayBuffer();
747
+ return await WebAssembly.instantiate(bytes, imports);
748
+ } else {
749
+ const instance = await WebAssembly.instantiate(module, imports);
750
+
751
+ if (instance instanceof WebAssembly.Instance) {
752
+ return { instance, module };
753
+ } else {
754
+ return instance;
755
+ }
756
+ }
757
+ }
758
+
759
+ function __wbg_get_imports() {
760
+ const imports = {};
761
+ imports.wbg = {};
762
+ imports.wbg.__wbg___wbindgen_throw_dd24417ed36fc46e = function(arg0, arg1) {
763
+ throw new Error(getStringFromWasm0(arg0, arg1));
764
+ };
765
+ imports.wbg.__wbg_error_7534b8e9a36f1ab4 = function(arg0, arg1) {
766
+ let deferred0_0;
767
+ let deferred0_1;
768
+ try {
769
+ deferred0_0 = arg0;
770
+ deferred0_1 = arg1;
771
+ console.error(getStringFromWasm0(arg0, arg1));
772
+ } finally {
773
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
774
+ }
775
+ };
776
+ imports.wbg.__wbg_length_22ac23eaec9d8053 = function(arg0) {
777
+ const ret = arg0.length;
778
+ return ret;
779
+ };
780
+ imports.wbg.__wbg_new_8a6f238a6ece86ea = function() {
781
+ const ret = new Error();
782
+ return ret;
783
+ };
784
+ imports.wbg.__wbg_new_from_slice_f9c22b9153b26992 = function(arg0, arg1) {
785
+ const ret = new Uint8Array(getArrayU8FromWasm0(arg0, arg1));
786
+ return ret;
787
+ };
788
+ imports.wbg.__wbg_new_with_length_806b9e5b8290af7c = function(arg0) {
789
+ const ret = new Float64Array(arg0 >>> 0);
790
+ return ret;
791
+ };
792
+ imports.wbg.__wbg_new_with_length_aa5eaf41d35235e5 = function(arg0) {
793
+ const ret = new Uint8Array(arg0 >>> 0);
794
+ return ret;
795
+ };
796
+ imports.wbg.__wbg_prototypesetcall_dfe9b766cdc1f1fd = function(arg0, arg1, arg2) {
797
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
798
+ };
799
+ imports.wbg.__wbg_set_index_021489b2916af13e = function(arg0, arg1, arg2) {
800
+ arg0[arg1 >>> 0] = arg2;
801
+ };
802
+ imports.wbg.__wbg_stack_0ed75d68575b0f3c = function(arg0, arg1) {
803
+ const ret = arg1.stack;
804
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
805
+ const len1 = WASM_VECTOR_LEN;
806
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
807
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
808
+ };
809
+ imports.wbg.__wbindgen_init_externref_table = function() {
810
+ const table = wasm.__wbindgen_externrefs;
811
+ const offset = table.grow(4);
812
+ table.set(0, undefined);
813
+ table.set(offset + 0, undefined);
814
+ table.set(offset + 1, null);
815
+ table.set(offset + 2, true);
816
+ table.set(offset + 3, false);
817
+ };
818
+
819
+ return imports;
820
+ }
821
+
822
+ function __wbg_finalize_init(instance, module) {
823
+ wasm = instance.exports;
824
+ __wbg_init.__wbindgen_wasm_module = module;
825
+ cachedDataViewMemory0 = null;
826
+ cachedUint8ArrayMemory0 = null;
827
+
828
+
829
+ wasm.__wbindgen_start();
830
+ return wasm;
831
+ }
832
+
833
+ function initSync(module) {
834
+ if (wasm !== undefined) return wasm;
835
+
836
+
837
+ if (typeof module !== 'undefined') {
838
+ if (Object.getPrototypeOf(module) === Object.prototype) {
839
+ ({module} = module)
840
+ } else {
841
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
842
+ }
843
+ }
844
+
845
+ const imports = __wbg_get_imports();
846
+ if (!(module instanceof WebAssembly.Module)) {
847
+ module = new WebAssembly.Module(module);
848
+ }
849
+ const instance = new WebAssembly.Instance(module, imports);
850
+ return __wbg_finalize_init(instance, module);
851
+ }
852
+
853
+ async function __wbg_init(module_or_path) {
854
+ if (wasm !== undefined) return wasm;
855
+
856
+
857
+ if (typeof module_or_path !== 'undefined') {
858
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
859
+ ({module_or_path} = module_or_path)
860
+ } else {
861
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
862
+ }
863
+ }
864
+
865
+ if (typeof module_or_path === 'undefined') {
866
+ module_or_path = new URL('libbitsub_bg.wasm', import.meta.url);
867
+ }
868
+ const imports = __wbg_get_imports();
869
+
870
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
871
+ module_or_path = fetch(module_or_path);
872
+ }
873
+
874
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
875
+
876
+ return __wbg_finalize_init(instance, module);
877
+ }
878
+
879
+ export { initSync };
880
+ export default __wbg_init;