@napi-rs/webcodecs 0.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/index.js ADDED
@@ -0,0 +1,772 @@
1
+ // prettier-ignore
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ const { readFileSync } = require('node:fs')
7
+ let nativeBinding = null
8
+ const loadErrors = []
9
+
10
+ const isMusl = () => {
11
+ let musl = false
12
+ if (process.platform === 'linux') {
13
+ musl = isMuslFromFilesystem()
14
+ if (musl === null) {
15
+ musl = isMuslFromReport()
16
+ }
17
+ if (musl === null) {
18
+ musl = isMuslFromChildProcess()
19
+ }
20
+ }
21
+ return musl
22
+ }
23
+
24
+ const isFileMusl = (f) => f.includes('libc.musl-') || f.includes('ld-musl-')
25
+
26
+ const isMuslFromFilesystem = () => {
27
+ try {
28
+ return readFileSync('/usr/bin/ldd', 'utf-8').includes('musl')
29
+ } catch {
30
+ return null
31
+ }
32
+ }
33
+
34
+ const isMuslFromReport = () => {
35
+ let report = null
36
+ if (typeof process.report?.getReport === 'function') {
37
+ process.report.excludeNetwork = true
38
+ report = process.report.getReport()
39
+ }
40
+ if (!report) {
41
+ return null
42
+ }
43
+ if (report.header && report.header.glibcVersionRuntime) {
44
+ return false
45
+ }
46
+ if (Array.isArray(report.sharedObjects)) {
47
+ if (report.sharedObjects.some(isFileMusl)) {
48
+ return true
49
+ }
50
+ }
51
+ return false
52
+ }
53
+
54
+ const isMuslFromChildProcess = () => {
55
+ try {
56
+ return require('child_process').execSync('ldd --version', { encoding: 'utf8' }).includes('musl')
57
+ } catch (e) {
58
+ // If we reach this case, we don't know if the system is musl or not, so is better to just fallback to false
59
+ return false
60
+ }
61
+ }
62
+
63
+ function requireNative() {
64
+ if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
65
+ try {
66
+ return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
67
+ } catch (err) {
68
+ loadErrors.push(err)
69
+ }
70
+ } else if (process.platform === 'android') {
71
+ if (process.arch === 'arm64') {
72
+ try {
73
+ return require('./webcodecs.android-arm64.node')
74
+ } catch (e) {
75
+ loadErrors.push(e)
76
+ }
77
+ try {
78
+ const binding = require('@napi-rs/webcodecs-android-arm64')
79
+ const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm64/package.json').version
80
+ if (
81
+ bindingPackageVersion !== '0.0.0' &&
82
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
83
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
84
+ ) {
85
+ throw new Error(
86
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
87
+ )
88
+ }
89
+ return binding
90
+ } catch (e) {
91
+ loadErrors.push(e)
92
+ }
93
+ } else if (process.arch === 'arm') {
94
+ try {
95
+ return require('./webcodecs.android-arm-eabi.node')
96
+ } catch (e) {
97
+ loadErrors.push(e)
98
+ }
99
+ try {
100
+ const binding = require('@napi-rs/webcodecs-android-arm-eabi')
101
+ const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm-eabi/package.json').version
102
+ if (
103
+ bindingPackageVersion !== '0.0.0' &&
104
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
105
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
106
+ ) {
107
+ throw new Error(
108
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
109
+ )
110
+ }
111
+ return binding
112
+ } catch (e) {
113
+ loadErrors.push(e)
114
+ }
115
+ } else {
116
+ loadErrors.push(new Error(`Unsupported architecture on Android ${process.arch}`))
117
+ }
118
+ } else if (process.platform === 'win32') {
119
+ if (process.arch === 'x64') {
120
+ if (
121
+ process.config?.variables?.shlib_suffix === 'dll.a' ||
122
+ process.config?.variables?.node_target_type === 'shared_library'
123
+ ) {
124
+ try {
125
+ return require('./webcodecs.win32-x64-gnu.node')
126
+ } catch (e) {
127
+ loadErrors.push(e)
128
+ }
129
+ try {
130
+ const binding = require('@napi-rs/webcodecs-win32-x64-gnu')
131
+ const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-gnu/package.json').version
132
+ if (
133
+ bindingPackageVersion !== '0.0.0' &&
134
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
135
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
136
+ ) {
137
+ throw new Error(
138
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
139
+ )
140
+ }
141
+ return binding
142
+ } catch (e) {
143
+ loadErrors.push(e)
144
+ }
145
+ } else {
146
+ try {
147
+ return require('./webcodecs.win32-x64-msvc.node')
148
+ } catch (e) {
149
+ loadErrors.push(e)
150
+ }
151
+ try {
152
+ const binding = require('@napi-rs/webcodecs-win32-x64-msvc')
153
+ const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-msvc/package.json').version
154
+ if (
155
+ bindingPackageVersion !== '0.0.0' &&
156
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
157
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
158
+ ) {
159
+ throw new Error(
160
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
161
+ )
162
+ }
163
+ return binding
164
+ } catch (e) {
165
+ loadErrors.push(e)
166
+ }
167
+ }
168
+ } else if (process.arch === 'ia32') {
169
+ try {
170
+ return require('./webcodecs.win32-ia32-msvc.node')
171
+ } catch (e) {
172
+ loadErrors.push(e)
173
+ }
174
+ try {
175
+ const binding = require('@napi-rs/webcodecs-win32-ia32-msvc')
176
+ const bindingPackageVersion = require('@napi-rs/webcodecs-win32-ia32-msvc/package.json').version
177
+ if (
178
+ bindingPackageVersion !== '0.0.0' &&
179
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
180
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
181
+ ) {
182
+ throw new Error(
183
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
184
+ )
185
+ }
186
+ return binding
187
+ } catch (e) {
188
+ loadErrors.push(e)
189
+ }
190
+ } else if (process.arch === 'arm64') {
191
+ try {
192
+ return require('./webcodecs.win32-arm64-msvc.node')
193
+ } catch (e) {
194
+ loadErrors.push(e)
195
+ }
196
+ try {
197
+ const binding = require('@napi-rs/webcodecs-win32-arm64-msvc')
198
+ const bindingPackageVersion = require('@napi-rs/webcodecs-win32-arm64-msvc/package.json').version
199
+ if (
200
+ bindingPackageVersion !== '0.0.0' &&
201
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
202
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
203
+ ) {
204
+ throw new Error(
205
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
206
+ )
207
+ }
208
+ return binding
209
+ } catch (e) {
210
+ loadErrors.push(e)
211
+ }
212
+ } else {
213
+ loadErrors.push(new Error(`Unsupported architecture on Windows: ${process.arch}`))
214
+ }
215
+ } else if (process.platform === 'darwin') {
216
+ try {
217
+ return require('./webcodecs.darwin-universal.node')
218
+ } catch (e) {
219
+ loadErrors.push(e)
220
+ }
221
+ try {
222
+ const binding = require('@napi-rs/webcodecs-darwin-universal')
223
+ const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-universal/package.json').version
224
+ if (
225
+ bindingPackageVersion !== '0.0.0' &&
226
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
227
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
228
+ ) {
229
+ throw new Error(
230
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
231
+ )
232
+ }
233
+ return binding
234
+ } catch (e) {
235
+ loadErrors.push(e)
236
+ }
237
+ if (process.arch === 'x64') {
238
+ try {
239
+ return require('./webcodecs.darwin-x64.node')
240
+ } catch (e) {
241
+ loadErrors.push(e)
242
+ }
243
+ try {
244
+ const binding = require('@napi-rs/webcodecs-darwin-x64')
245
+ const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-x64/package.json').version
246
+ if (
247
+ bindingPackageVersion !== '0.0.0' &&
248
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
249
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
250
+ ) {
251
+ throw new Error(
252
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
253
+ )
254
+ }
255
+ return binding
256
+ } catch (e) {
257
+ loadErrors.push(e)
258
+ }
259
+ } else if (process.arch === 'arm64') {
260
+ try {
261
+ return require('./webcodecs.darwin-arm64.node')
262
+ } catch (e) {
263
+ loadErrors.push(e)
264
+ }
265
+ try {
266
+ const binding = require('@napi-rs/webcodecs-darwin-arm64')
267
+ const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-arm64/package.json').version
268
+ if (
269
+ bindingPackageVersion !== '0.0.0' &&
270
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
271
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
272
+ ) {
273
+ throw new Error(
274
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
275
+ )
276
+ }
277
+ return binding
278
+ } catch (e) {
279
+ loadErrors.push(e)
280
+ }
281
+ } else {
282
+ loadErrors.push(new Error(`Unsupported architecture on macOS: ${process.arch}`))
283
+ }
284
+ } else if (process.platform === 'freebsd') {
285
+ if (process.arch === 'x64') {
286
+ try {
287
+ return require('./webcodecs.freebsd-x64.node')
288
+ } catch (e) {
289
+ loadErrors.push(e)
290
+ }
291
+ try {
292
+ const binding = require('@napi-rs/webcodecs-freebsd-x64')
293
+ const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-x64/package.json').version
294
+ if (
295
+ bindingPackageVersion !== '0.0.0' &&
296
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
297
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
298
+ ) {
299
+ throw new Error(
300
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
301
+ )
302
+ }
303
+ return binding
304
+ } catch (e) {
305
+ loadErrors.push(e)
306
+ }
307
+ } else if (process.arch === 'arm64') {
308
+ try {
309
+ return require('./webcodecs.freebsd-arm64.node')
310
+ } catch (e) {
311
+ loadErrors.push(e)
312
+ }
313
+ try {
314
+ const binding = require('@napi-rs/webcodecs-freebsd-arm64')
315
+ const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-arm64/package.json').version
316
+ if (
317
+ bindingPackageVersion !== '0.0.0' &&
318
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
319
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
320
+ ) {
321
+ throw new Error(
322
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
323
+ )
324
+ }
325
+ return binding
326
+ } catch (e) {
327
+ loadErrors.push(e)
328
+ }
329
+ } else {
330
+ loadErrors.push(new Error(`Unsupported architecture on FreeBSD: ${process.arch}`))
331
+ }
332
+ } else if (process.platform === 'linux') {
333
+ if (process.arch === 'x64') {
334
+ if (isMusl()) {
335
+ try {
336
+ return require('./webcodecs.linux-x64-musl.node')
337
+ } catch (e) {
338
+ loadErrors.push(e)
339
+ }
340
+ try {
341
+ const binding = require('@napi-rs/webcodecs-linux-x64-musl')
342
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-musl/package.json').version
343
+ if (
344
+ bindingPackageVersion !== '0.0.0' &&
345
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
346
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
347
+ ) {
348
+ throw new Error(
349
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
350
+ )
351
+ }
352
+ return binding
353
+ } catch (e) {
354
+ loadErrors.push(e)
355
+ }
356
+ } else {
357
+ try {
358
+ return require('./webcodecs.linux-x64-gnu.node')
359
+ } catch (e) {
360
+ loadErrors.push(e)
361
+ }
362
+ try {
363
+ const binding = require('@napi-rs/webcodecs-linux-x64-gnu')
364
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-gnu/package.json').version
365
+ if (
366
+ bindingPackageVersion !== '0.0.0' &&
367
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
368
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
369
+ ) {
370
+ throw new Error(
371
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
372
+ )
373
+ }
374
+ return binding
375
+ } catch (e) {
376
+ loadErrors.push(e)
377
+ }
378
+ }
379
+ } else if (process.arch === 'arm64') {
380
+ if (isMusl()) {
381
+ try {
382
+ return require('./webcodecs.linux-arm64-musl.node')
383
+ } catch (e) {
384
+ loadErrors.push(e)
385
+ }
386
+ try {
387
+ const binding = require('@napi-rs/webcodecs-linux-arm64-musl')
388
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-musl/package.json').version
389
+ if (
390
+ bindingPackageVersion !== '0.0.0' &&
391
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
392
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
393
+ ) {
394
+ throw new Error(
395
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
396
+ )
397
+ }
398
+ return binding
399
+ } catch (e) {
400
+ loadErrors.push(e)
401
+ }
402
+ } else {
403
+ try {
404
+ return require('./webcodecs.linux-arm64-gnu.node')
405
+ } catch (e) {
406
+ loadErrors.push(e)
407
+ }
408
+ try {
409
+ const binding = require('@napi-rs/webcodecs-linux-arm64-gnu')
410
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-gnu/package.json').version
411
+ if (
412
+ bindingPackageVersion !== '0.0.0' &&
413
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
414
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
415
+ ) {
416
+ throw new Error(
417
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
418
+ )
419
+ }
420
+ return binding
421
+ } catch (e) {
422
+ loadErrors.push(e)
423
+ }
424
+ }
425
+ } else if (process.arch === 'arm') {
426
+ if (isMusl()) {
427
+ try {
428
+ return require('./webcodecs.linux-arm-musleabihf.node')
429
+ } catch (e) {
430
+ loadErrors.push(e)
431
+ }
432
+ try {
433
+ const binding = require('@napi-rs/webcodecs-linux-arm-musleabihf')
434
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-musleabihf/package.json').version
435
+ if (
436
+ bindingPackageVersion !== '0.0.0' &&
437
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
438
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
439
+ ) {
440
+ throw new Error(
441
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
442
+ )
443
+ }
444
+ return binding
445
+ } catch (e) {
446
+ loadErrors.push(e)
447
+ }
448
+ } else {
449
+ try {
450
+ return require('./webcodecs.linux-arm-gnueabihf.node')
451
+ } catch (e) {
452
+ loadErrors.push(e)
453
+ }
454
+ try {
455
+ const binding = require('@napi-rs/webcodecs-linux-arm-gnueabihf')
456
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-gnueabihf/package.json').version
457
+ if (
458
+ bindingPackageVersion !== '0.0.0' &&
459
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
460
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
461
+ ) {
462
+ throw new Error(
463
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
464
+ )
465
+ }
466
+ return binding
467
+ } catch (e) {
468
+ loadErrors.push(e)
469
+ }
470
+ }
471
+ } else if (process.arch === 'loong64') {
472
+ if (isMusl()) {
473
+ try {
474
+ return require('./webcodecs.linux-loong64-musl.node')
475
+ } catch (e) {
476
+ loadErrors.push(e)
477
+ }
478
+ try {
479
+ const binding = require('@napi-rs/webcodecs-linux-loong64-musl')
480
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-musl/package.json').version
481
+ if (
482
+ bindingPackageVersion !== '0.0.0' &&
483
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
484
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
485
+ ) {
486
+ throw new Error(
487
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
488
+ )
489
+ }
490
+ return binding
491
+ } catch (e) {
492
+ loadErrors.push(e)
493
+ }
494
+ } else {
495
+ try {
496
+ return require('./webcodecs.linux-loong64-gnu.node')
497
+ } catch (e) {
498
+ loadErrors.push(e)
499
+ }
500
+ try {
501
+ const binding = require('@napi-rs/webcodecs-linux-loong64-gnu')
502
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-gnu/package.json').version
503
+ if (
504
+ bindingPackageVersion !== '0.0.0' &&
505
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
506
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
507
+ ) {
508
+ throw new Error(
509
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
510
+ )
511
+ }
512
+ return binding
513
+ } catch (e) {
514
+ loadErrors.push(e)
515
+ }
516
+ }
517
+ } else if (process.arch === 'riscv64') {
518
+ if (isMusl()) {
519
+ try {
520
+ return require('./webcodecs.linux-riscv64-musl.node')
521
+ } catch (e) {
522
+ loadErrors.push(e)
523
+ }
524
+ try {
525
+ const binding = require('@napi-rs/webcodecs-linux-riscv64-musl')
526
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-musl/package.json').version
527
+ if (
528
+ bindingPackageVersion !== '0.0.0' &&
529
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
530
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
531
+ ) {
532
+ throw new Error(
533
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
534
+ )
535
+ }
536
+ return binding
537
+ } catch (e) {
538
+ loadErrors.push(e)
539
+ }
540
+ } else {
541
+ try {
542
+ return require('./webcodecs.linux-riscv64-gnu.node')
543
+ } catch (e) {
544
+ loadErrors.push(e)
545
+ }
546
+ try {
547
+ const binding = require('@napi-rs/webcodecs-linux-riscv64-gnu')
548
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-gnu/package.json').version
549
+ if (
550
+ bindingPackageVersion !== '0.0.0' &&
551
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
552
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
553
+ ) {
554
+ throw new Error(
555
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
556
+ )
557
+ }
558
+ return binding
559
+ } catch (e) {
560
+ loadErrors.push(e)
561
+ }
562
+ }
563
+ } else if (process.arch === 'ppc64') {
564
+ try {
565
+ return require('./webcodecs.linux-ppc64-gnu.node')
566
+ } catch (e) {
567
+ loadErrors.push(e)
568
+ }
569
+ try {
570
+ const binding = require('@napi-rs/webcodecs-linux-ppc64-gnu')
571
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-ppc64-gnu/package.json').version
572
+ if (
573
+ bindingPackageVersion !== '0.0.0' &&
574
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
575
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
576
+ ) {
577
+ throw new Error(
578
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
579
+ )
580
+ }
581
+ return binding
582
+ } catch (e) {
583
+ loadErrors.push(e)
584
+ }
585
+ } else if (process.arch === 's390x') {
586
+ try {
587
+ return require('./webcodecs.linux-s390x-gnu.node')
588
+ } catch (e) {
589
+ loadErrors.push(e)
590
+ }
591
+ try {
592
+ const binding = require('@napi-rs/webcodecs-linux-s390x-gnu')
593
+ const bindingPackageVersion = require('@napi-rs/webcodecs-linux-s390x-gnu/package.json').version
594
+ if (
595
+ bindingPackageVersion !== '0.0.0' &&
596
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
597
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
598
+ ) {
599
+ throw new Error(
600
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
601
+ )
602
+ }
603
+ return binding
604
+ } catch (e) {
605
+ loadErrors.push(e)
606
+ }
607
+ } else {
608
+ loadErrors.push(new Error(`Unsupported architecture on Linux: ${process.arch}`))
609
+ }
610
+ } else if (process.platform === 'openharmony') {
611
+ if (process.arch === 'arm64') {
612
+ try {
613
+ return require('./webcodecs.openharmony-arm64.node')
614
+ } catch (e) {
615
+ loadErrors.push(e)
616
+ }
617
+ try {
618
+ const binding = require('@napi-rs/webcodecs-openharmony-arm64')
619
+ const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm64/package.json').version
620
+ if (
621
+ bindingPackageVersion !== '0.0.0' &&
622
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
623
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
624
+ ) {
625
+ throw new Error(
626
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
627
+ )
628
+ }
629
+ return binding
630
+ } catch (e) {
631
+ loadErrors.push(e)
632
+ }
633
+ } else if (process.arch === 'x64') {
634
+ try {
635
+ return require('./webcodecs.openharmony-x64.node')
636
+ } catch (e) {
637
+ loadErrors.push(e)
638
+ }
639
+ try {
640
+ const binding = require('@napi-rs/webcodecs-openharmony-x64')
641
+ const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-x64/package.json').version
642
+ if (
643
+ bindingPackageVersion !== '0.0.0' &&
644
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
645
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
646
+ ) {
647
+ throw new Error(
648
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
649
+ )
650
+ }
651
+ return binding
652
+ } catch (e) {
653
+ loadErrors.push(e)
654
+ }
655
+ } else if (process.arch === 'arm') {
656
+ try {
657
+ return require('./webcodecs.openharmony-arm.node')
658
+ } catch (e) {
659
+ loadErrors.push(e)
660
+ }
661
+ try {
662
+ const binding = require('@napi-rs/webcodecs-openharmony-arm')
663
+ const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm/package.json').version
664
+ if (
665
+ bindingPackageVersion !== '0.0.0' &&
666
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
667
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
668
+ ) {
669
+ throw new Error(
670
+ `Native binding package version mismatch, expected 0.0.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
671
+ )
672
+ }
673
+ return binding
674
+ } catch (e) {
675
+ loadErrors.push(e)
676
+ }
677
+ } else {
678
+ loadErrors.push(new Error(`Unsupported architecture on OpenHarmony: ${process.arch}`))
679
+ }
680
+ } else {
681
+ loadErrors.push(new Error(`Unsupported OS: ${process.platform}, architecture: ${process.arch}`))
682
+ }
683
+ }
684
+
685
+ nativeBinding = requireNative()
686
+
687
+ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
688
+ let wasiBinding = null
689
+ let wasiBindingError = null
690
+ try {
691
+ wasiBinding = require('./webcodecs.wasi.cjs')
692
+ nativeBinding = wasiBinding
693
+ } catch (err) {
694
+ if (process.env.NAPI_RS_FORCE_WASI) {
695
+ wasiBindingError = err
696
+ }
697
+ }
698
+ if (!nativeBinding) {
699
+ try {
700
+ wasiBinding = require('@napi-rs/webcodecs-wasm32-wasi')
701
+ nativeBinding = wasiBinding
702
+ } catch (err) {
703
+ if (process.env.NAPI_RS_FORCE_WASI) {
704
+ wasiBindingError.cause = err
705
+ loadErrors.push(err)
706
+ }
707
+ }
708
+ }
709
+ if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
710
+ const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
711
+ error.cause = wasiBindingError
712
+ throw error
713
+ }
714
+ }
715
+
716
+ if (!nativeBinding) {
717
+ if (loadErrors.length > 0) {
718
+ throw new Error(
719
+ `Cannot find native binding. ` +
720
+ `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
721
+ 'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
722
+ {
723
+ cause: loadErrors.reduce((err, cur) => {
724
+ cur.cause = err
725
+ return cur
726
+ }),
727
+ },
728
+ )
729
+ }
730
+ throw new Error(`Failed to load native binding`)
731
+ }
732
+
733
+ module.exports = nativeBinding
734
+ module.exports.AudioData = nativeBinding.AudioData
735
+ module.exports.AudioDecoder = nativeBinding.AudioDecoder
736
+ module.exports.AudioEncoder = nativeBinding.AudioEncoder
737
+ module.exports.DOMRectReadOnly = nativeBinding.DOMRectReadOnly
738
+ module.exports.EncodedAudioChunk = nativeBinding.EncodedAudioChunk
739
+ module.exports.EncodedVideoChunk = nativeBinding.EncodedVideoChunk
740
+ module.exports.ImageDecoder = nativeBinding.ImageDecoder
741
+ module.exports.ImageDecodeResult = nativeBinding.ImageDecodeResult
742
+ module.exports.ImageTrack = nativeBinding.ImageTrack
743
+ module.exports.ImageTrackList = nativeBinding.ImageTrackList
744
+ module.exports.VideoColorSpace = nativeBinding.VideoColorSpace
745
+ module.exports.VideoDecoder = nativeBinding.VideoDecoder
746
+ module.exports.VideoEncoder = nativeBinding.VideoEncoder
747
+ module.exports.VideoFrame = nativeBinding.VideoFrame
748
+ module.exports.AacBitstreamFormat = nativeBinding.AacBitstreamFormat
749
+ module.exports.AlphaOption = nativeBinding.AlphaOption
750
+ module.exports.AudioSampleFormat = nativeBinding.AudioSampleFormat
751
+ module.exports.AvcBitstreamFormat = nativeBinding.AvcBitstreamFormat
752
+ module.exports.BitrateMode = nativeBinding.BitrateMode
753
+ module.exports.CodecState = nativeBinding.CodecState
754
+ module.exports.ColorSpaceConversion = nativeBinding.ColorSpaceConversion
755
+ module.exports.EncodedAudioChunkType = nativeBinding.EncodedAudioChunkType
756
+ module.exports.EncodedVideoChunkType = nativeBinding.EncodedVideoChunkType
757
+ module.exports.getAvailableHardwareAccelerators = nativeBinding.getAvailableHardwareAccelerators
758
+ module.exports.getHardwareAccelerators = nativeBinding.getHardwareAccelerators
759
+ module.exports.getPreferredHardwareAccelerator = nativeBinding.getPreferredHardwareAccelerator
760
+ module.exports.HardwareAcceleration = nativeBinding.HardwareAcceleration
761
+ module.exports.HevcBitstreamFormat = nativeBinding.HevcBitstreamFormat
762
+ module.exports.isHardwareAcceleratorAvailable = nativeBinding.isHardwareAcceleratorAvailable
763
+ module.exports.LatencyMode = nativeBinding.LatencyMode
764
+ module.exports.OpusApplication = nativeBinding.OpusApplication
765
+ module.exports.OpusBitstreamFormat = nativeBinding.OpusBitstreamFormat
766
+ module.exports.OpusSignal = nativeBinding.OpusSignal
767
+ module.exports.resetHardwareFallbackState = nativeBinding.resetHardwareFallbackState
768
+ module.exports.VideoColorPrimaries = nativeBinding.VideoColorPrimaries
769
+ module.exports.VideoEncoderBitrateMode = nativeBinding.VideoEncoderBitrateMode
770
+ module.exports.VideoMatrixCoefficients = nativeBinding.VideoMatrixCoefficients
771
+ module.exports.VideoPixelFormat = nativeBinding.VideoPixelFormat
772
+ module.exports.VideoTransferCharacteristics = nativeBinding.VideoTransferCharacteristics