@napi-rs/webcodecs 1.4.1 → 1.5.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.
Files changed (45) hide show
  1. package/LICENSES.md +40 -0
  2. package/README.md +45 -8
  3. package/SOURCE_DISTRIBUTION.md +111 -0
  4. package/THIRD_PARTY_NOTICES.md +87 -0
  5. package/index.d.ts +93 -32
  6. package/index.js +193 -55
  7. package/licenses/aom-LICENSE.txt +27 -0
  8. package/licenses/aom-PATENTS.txt +108 -0
  9. package/licenses/brotli-LICENSE.txt +19 -0
  10. package/licenses/dav1d-COPYING.txt +23 -0
  11. package/licenses/ffmpeg-COPYING.GPLv2.txt +339 -0
  12. package/licenses/ffmpeg-COPYING.GPLv3.txt +674 -0
  13. package/licenses/ffmpeg-COPYING.LGPLv2.1.txt +502 -0
  14. package/licenses/ffmpeg-COPYING.LGPLv3.txt +165 -0
  15. package/licenses/ffmpeg-LICENSE.md.txt +127 -0
  16. package/licenses/highway-LICENSE-BSD3.txt +26 -0
  17. package/licenses/highway-LICENSE.txt +201 -0
  18. package/licenses/lame-COPYING.txt +481 -0
  19. package/licenses/lame-LICENSE.txt +13 -0
  20. package/licenses/lcms2-LICENSE.txt +22 -0
  21. package/licenses/lcms2-windows-LICENSE.txt +22 -0
  22. package/licenses/libjpeg-turbo-CHROMIUM_LICENSE.txt +27 -0
  23. package/licenses/libjpeg-turbo-LICENSE.md.txt +135 -0
  24. package/licenses/libjpeg-turbo-README.ijg.txt +260 -0
  25. package/licenses/libjpeg-turbo-jsimdext.inc.txt +542 -0
  26. package/licenses/libjxl-LICENSE.txt +27 -0
  27. package/licenses/libjxl-PATENTS.txt +22 -0
  28. package/licenses/libvpx-LICENSE.txt +31 -0
  29. package/licenses/libvpx-PATENTS.txt +23 -0
  30. package/licenses/libwebp-COPYING.txt +30 -0
  31. package/licenses/libwebp-PATENTS.txt +23 -0
  32. package/licenses/manifest.json +343 -0
  33. package/licenses/nv-codec-headers-nvEncodeAPI.h.txt +26 -0
  34. package/licenses/ogg-COPYING.txt +28 -0
  35. package/licenses/ogg-windows-COPYING.txt +28 -0
  36. package/licenses/opus-COPYING.txt +44 -0
  37. package/licenses/rav1e-LICENSE.txt +25 -0
  38. package/licenses/rav1e-PATENTS.txt +108 -0
  39. package/licenses/vorbis-COPYING.txt +28 -0
  40. package/licenses/x264-COPYING.txt +340 -0
  41. package/licenses/x264-x264.h.txt +26 -0
  42. package/licenses/x265-COPYING.txt +343 -0
  43. package/licenses/x265-source-x265.h.txt +23 -0
  44. package/licenses/zlib-LICENSE.txt +22 -0
  45. package/package.json +29 -23
package/index.js CHANGED
@@ -4,6 +4,15 @@
4
4
 
5
5
  const { readFileSync } = require('fs')
6
6
  let nativeBinding = null
7
+ // Which artifact actually loaded. The WASI fallback chain overwrites it with
8
+ // the flavor it resolved; the late native retry below leaves it alone because
9
+ // it only runs while no WASI candidate has been loaded. The take-over check
10
+ // after the load-failure block can also set it.
11
+ let __napiLoadedBindingTarget = 'native'
12
+ // What this loader's own `requireNative()` calls returned. The check after
13
+ // the load-failure block compares it with `nativeBinding` to tell a binding
14
+ // this loader loaded from one that code outside it put in its place.
15
+ let __napiRequiredNativeBinding = null
7
16
  const loadErrors = []
8
17
 
9
18
  const isMusl = () => {
@@ -62,7 +71,16 @@ const isMuslFromChildProcess = () => {
62
71
  function requireNative() {
63
72
  if (process.env.NAPI_RS_NATIVE_LIBRARY_PATH) {
64
73
  try {
65
- return require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
74
+ const overrideBinding = require(process.env.NAPI_RS_NATIVE_LIBRARY_PATH)
75
+ // The override may be a generated WASI loader, which already reports its
76
+ // own flavor. Adopt it: `module.exports` aliases this object, so claiming
77
+ // 'native' would both misreport the artifact and overwrite the loader's
78
+ // marker through the alias.
79
+ __napiLoadedBindingTarget =
80
+ overrideBinding && typeof overrideBinding.__napiBindingTarget === 'string'
81
+ ? overrideBinding.__napiBindingTarget
82
+ : 'native'
83
+ return overrideBinding
66
84
  } catch (err) {
67
85
  loadErrors.push(err)
68
86
  }
@@ -77,12 +95,12 @@ function requireNative() {
77
95
  const binding = require('@napi-rs/webcodecs-android-arm64')
78
96
  const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm64/package.json').version
79
97
  if (
80
- bindingPackageVersion !== '1.4.1' &&
98
+ bindingPackageVersion !== '1.5.0' &&
81
99
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
82
100
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
83
101
  ) {
84
102
  throw new Error(
85
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
103
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
86
104
  )
87
105
  }
88
106
  return binding
@@ -99,12 +117,12 @@ function requireNative() {
99
117
  const binding = require('@napi-rs/webcodecs-android-arm-eabi')
100
118
  const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm-eabi/package.json').version
101
119
  if (
102
- bindingPackageVersion !== '1.4.1' &&
120
+ bindingPackageVersion !== '1.5.0' &&
103
121
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
104
122
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
105
123
  ) {
106
124
  throw new Error(
107
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
125
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
108
126
  )
109
127
  }
110
128
  return binding
@@ -129,12 +147,12 @@ function requireNative() {
129
147
  const binding = require('@napi-rs/webcodecs-win32-x64-gnu')
130
148
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-gnu/package.json').version
131
149
  if (
132
- bindingPackageVersion !== '1.4.1' &&
150
+ bindingPackageVersion !== '1.5.0' &&
133
151
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
134
152
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
135
153
  ) {
136
154
  throw new Error(
137
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
155
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
138
156
  )
139
157
  }
140
158
  return binding
@@ -151,12 +169,12 @@ function requireNative() {
151
169
  const binding = require('@napi-rs/webcodecs-win32-x64-msvc')
152
170
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-msvc/package.json').version
153
171
  if (
154
- bindingPackageVersion !== '1.4.1' &&
172
+ bindingPackageVersion !== '1.5.0' &&
155
173
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
156
174
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
157
175
  ) {
158
176
  throw new Error(
159
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
177
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
160
178
  )
161
179
  }
162
180
  return binding
@@ -174,12 +192,12 @@ function requireNative() {
174
192
  const binding = require('@napi-rs/webcodecs-win32-ia32-msvc')
175
193
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-ia32-msvc/package.json').version
176
194
  if (
177
- bindingPackageVersion !== '1.4.1' &&
195
+ bindingPackageVersion !== '1.5.0' &&
178
196
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
179
197
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
180
198
  ) {
181
199
  throw new Error(
182
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
200
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
183
201
  )
184
202
  }
185
203
  return binding
@@ -196,12 +214,12 @@ function requireNative() {
196
214
  const binding = require('@napi-rs/webcodecs-win32-arm64-msvc')
197
215
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-arm64-msvc/package.json').version
198
216
  if (
199
- bindingPackageVersion !== '1.4.1' &&
217
+ bindingPackageVersion !== '1.5.0' &&
200
218
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
201
219
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
202
220
  ) {
203
221
  throw new Error(
204
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
222
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
205
223
  )
206
224
  }
207
225
  return binding
@@ -221,12 +239,12 @@ function requireNative() {
221
239
  const binding = require('@napi-rs/webcodecs-darwin-universal')
222
240
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-universal/package.json').version
223
241
  if (
224
- bindingPackageVersion !== '1.4.1' &&
242
+ bindingPackageVersion !== '1.5.0' &&
225
243
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
226
244
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
227
245
  ) {
228
246
  throw new Error(
229
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
247
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
230
248
  )
231
249
  }
232
250
  return binding
@@ -243,12 +261,12 @@ function requireNative() {
243
261
  const binding = require('@napi-rs/webcodecs-darwin-x64')
244
262
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-x64/package.json').version
245
263
  if (
246
- bindingPackageVersion !== '1.4.1' &&
264
+ bindingPackageVersion !== '1.5.0' &&
247
265
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
248
266
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
249
267
  ) {
250
268
  throw new Error(
251
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
269
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
252
270
  )
253
271
  }
254
272
  return binding
@@ -265,12 +283,12 @@ function requireNative() {
265
283
  const binding = require('@napi-rs/webcodecs-darwin-arm64')
266
284
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-arm64/package.json').version
267
285
  if (
268
- bindingPackageVersion !== '1.4.1' &&
286
+ bindingPackageVersion !== '1.5.0' &&
269
287
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
270
288
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
271
289
  ) {
272
290
  throw new Error(
273
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
291
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
274
292
  )
275
293
  }
276
294
  return binding
@@ -291,12 +309,12 @@ function requireNative() {
291
309
  const binding = require('@napi-rs/webcodecs-freebsd-x64')
292
310
  const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-x64/package.json').version
293
311
  if (
294
- bindingPackageVersion !== '1.4.1' &&
312
+ bindingPackageVersion !== '1.5.0' &&
295
313
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
296
314
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
297
315
  ) {
298
316
  throw new Error(
299
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
317
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
300
318
  )
301
319
  }
302
320
  return binding
@@ -313,12 +331,34 @@ function requireNative() {
313
331
  const binding = require('@napi-rs/webcodecs-freebsd-arm64')
314
332
  const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-arm64/package.json').version
315
333
  if (
316
- bindingPackageVersion !== '1.4.1' &&
334
+ bindingPackageVersion !== '1.5.0' &&
317
335
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
318
336
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
319
337
  ) {
320
338
  throw new Error(
321
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
339
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
340
+ )
341
+ }
342
+ return binding
343
+ } catch (e) {
344
+ loadErrors.push(e)
345
+ }
346
+ } else if (process.arch === 'ppc64') {
347
+ try {
348
+ return require('./webcodecs.freebsd-ppc64.node')
349
+ } catch (e) {
350
+ loadErrors.push(e)
351
+ }
352
+ try {
353
+ const binding = require('@napi-rs/webcodecs-freebsd-ppc64')
354
+ const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-ppc64/package.json').version
355
+ if (
356
+ bindingPackageVersion !== '1.5.0' &&
357
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
358
+ process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
359
+ ) {
360
+ throw new Error(
361
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
322
362
  )
323
363
  }
324
364
  return binding
@@ -340,12 +380,12 @@ function requireNative() {
340
380
  const binding = require('@napi-rs/webcodecs-linux-x64-musl')
341
381
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-musl/package.json').version
342
382
  if (
343
- bindingPackageVersion !== '1.4.1' &&
383
+ bindingPackageVersion !== '1.5.0' &&
344
384
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
345
385
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
346
386
  ) {
347
387
  throw new Error(
348
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
388
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
349
389
  )
350
390
  }
351
391
  return binding
@@ -362,12 +402,12 @@ function requireNative() {
362
402
  const binding = require('@napi-rs/webcodecs-linux-x64-gnu')
363
403
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-gnu/package.json').version
364
404
  if (
365
- bindingPackageVersion !== '1.4.1' &&
405
+ bindingPackageVersion !== '1.5.0' &&
366
406
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
367
407
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
368
408
  ) {
369
409
  throw new Error(
370
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
410
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
371
411
  )
372
412
  }
373
413
  return binding
@@ -386,12 +426,12 @@ function requireNative() {
386
426
  const binding = require('@napi-rs/webcodecs-linux-arm64-musl')
387
427
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-musl/package.json').version
388
428
  if (
389
- bindingPackageVersion !== '1.4.1' &&
429
+ bindingPackageVersion !== '1.5.0' &&
390
430
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
391
431
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
392
432
  ) {
393
433
  throw new Error(
394
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
434
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
395
435
  )
396
436
  }
397
437
  return binding
@@ -408,12 +448,12 @@ function requireNative() {
408
448
  const binding = require('@napi-rs/webcodecs-linux-arm64-gnu')
409
449
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-gnu/package.json').version
410
450
  if (
411
- bindingPackageVersion !== '1.4.1' &&
451
+ bindingPackageVersion !== '1.5.0' &&
412
452
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
413
453
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
414
454
  ) {
415
455
  throw new Error(
416
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
456
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
417
457
  )
418
458
  }
419
459
  return binding
@@ -432,12 +472,12 @@ function requireNative() {
432
472
  const binding = require('@napi-rs/webcodecs-linux-arm-musleabihf')
433
473
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-musleabihf/package.json').version
434
474
  if (
435
- bindingPackageVersion !== '1.4.1' &&
475
+ bindingPackageVersion !== '1.5.0' &&
436
476
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
437
477
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
438
478
  ) {
439
479
  throw new Error(
440
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
480
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
441
481
  )
442
482
  }
443
483
  return binding
@@ -454,12 +494,12 @@ function requireNative() {
454
494
  const binding = require('@napi-rs/webcodecs-linux-arm-gnueabihf')
455
495
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-gnueabihf/package.json').version
456
496
  if (
457
- bindingPackageVersion !== '1.4.1' &&
497
+ bindingPackageVersion !== '1.5.0' &&
458
498
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
459
499
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
460
500
  ) {
461
501
  throw new Error(
462
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
502
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
463
503
  )
464
504
  }
465
505
  return binding
@@ -478,12 +518,12 @@ function requireNative() {
478
518
  const binding = require('@napi-rs/webcodecs-linux-loong64-musl')
479
519
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-musl/package.json').version
480
520
  if (
481
- bindingPackageVersion !== '1.4.1' &&
521
+ bindingPackageVersion !== '1.5.0' &&
482
522
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
483
523
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
484
524
  ) {
485
525
  throw new Error(
486
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
526
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
487
527
  )
488
528
  }
489
529
  return binding
@@ -500,12 +540,12 @@ function requireNative() {
500
540
  const binding = require('@napi-rs/webcodecs-linux-loong64-gnu')
501
541
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-gnu/package.json').version
502
542
  if (
503
- bindingPackageVersion !== '1.4.1' &&
543
+ bindingPackageVersion !== '1.5.0' &&
504
544
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
505
545
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
506
546
  ) {
507
547
  throw new Error(
508
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
548
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
509
549
  )
510
550
  }
511
551
  return binding
@@ -524,12 +564,12 @@ function requireNative() {
524
564
  const binding = require('@napi-rs/webcodecs-linux-riscv64-musl')
525
565
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-musl/package.json').version
526
566
  if (
527
- bindingPackageVersion !== '1.4.1' &&
567
+ bindingPackageVersion !== '1.5.0' &&
528
568
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
529
569
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
530
570
  ) {
531
571
  throw new Error(
532
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
572
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
533
573
  )
534
574
  }
535
575
  return binding
@@ -546,12 +586,12 @@ function requireNative() {
546
586
  const binding = require('@napi-rs/webcodecs-linux-riscv64-gnu')
547
587
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-gnu/package.json').version
548
588
  if (
549
- bindingPackageVersion !== '1.4.1' &&
589
+ bindingPackageVersion !== '1.5.0' &&
550
590
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
551
591
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
552
592
  ) {
553
593
  throw new Error(
554
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
594
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
555
595
  )
556
596
  }
557
597
  return binding
@@ -569,12 +609,12 @@ function requireNative() {
569
609
  const binding = require('@napi-rs/webcodecs-linux-ppc64-gnu')
570
610
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-ppc64-gnu/package.json').version
571
611
  if (
572
- bindingPackageVersion !== '1.4.1' &&
612
+ bindingPackageVersion !== '1.5.0' &&
573
613
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
574
614
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
575
615
  ) {
576
616
  throw new Error(
577
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
617
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
578
618
  )
579
619
  }
580
620
  return binding
@@ -591,12 +631,12 @@ function requireNative() {
591
631
  const binding = require('@napi-rs/webcodecs-linux-s390x-gnu')
592
632
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-s390x-gnu/package.json').version
593
633
  if (
594
- bindingPackageVersion !== '1.4.1' &&
634
+ bindingPackageVersion !== '1.5.0' &&
595
635
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
596
636
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
597
637
  ) {
598
638
  throw new Error(
599
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
639
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
600
640
  )
601
641
  }
602
642
  return binding
@@ -617,12 +657,12 @@ function requireNative() {
617
657
  const binding = require('@napi-rs/webcodecs-openharmony-arm64')
618
658
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm64/package.json').version
619
659
  if (
620
- bindingPackageVersion !== '1.4.1' &&
660
+ bindingPackageVersion !== '1.5.0' &&
621
661
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
622
662
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
623
663
  ) {
624
664
  throw new Error(
625
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
665
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
626
666
  )
627
667
  }
628
668
  return binding
@@ -639,12 +679,12 @@ function requireNative() {
639
679
  const binding = require('@napi-rs/webcodecs-openharmony-x64')
640
680
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-x64/package.json').version
641
681
  if (
642
- bindingPackageVersion !== '1.4.1' &&
682
+ bindingPackageVersion !== '1.5.0' &&
643
683
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
644
684
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
645
685
  ) {
646
686
  throw new Error(
647
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
687
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
648
688
  )
649
689
  }
650
690
  return binding
@@ -661,12 +701,12 @@ function requireNative() {
661
701
  const binding = require('@napi-rs/webcodecs-openharmony-arm')
662
702
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm/package.json').version
663
703
  if (
664
- bindingPackageVersion !== '1.4.1' &&
704
+ bindingPackageVersion !== '1.5.0' &&
665
705
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
666
706
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
667
707
  ) {
668
708
  throw new Error(
669
- `Native binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
709
+ `Native binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
670
710
  )
671
711
  }
672
712
  return binding
@@ -718,6 +758,7 @@ const forceWasi = process.env.NAPI_RS_FORCE_WASI === 'true' || forceWasiError ||
718
758
 
719
759
  if (!forceWasi) {
720
760
  nativeBinding = requireNative()
761
+ __napiRequiredNativeBinding = nativeBinding
721
762
  }
722
763
 
723
764
  if (!nativeBinding || forceWasi) {
@@ -776,6 +817,7 @@ if (!nativeBinding || forceWasi) {
776
817
  if (!candidateFailed) {
777
818
  wasiBinding = require('./webcodecs.wasi.cjs')
778
819
  nativeBinding = wasiBinding
820
+ __napiLoadedBindingTarget = 'wasm32-wasi'
779
821
  wasiBindingLoaded = true
780
822
  }
781
823
  } catch (err) {
@@ -796,14 +838,15 @@ if (!nativeBinding || forceWasi) {
796
838
  if (!candidateFailed) {
797
839
  if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
798
840
  const bindingPackageVersion = require('@napi-rs/webcodecs-wasm32-wasi/package.json').version
799
- if (bindingPackageVersion !== '1.4.1') {
841
+ if (bindingPackageVersion !== '1.5.0') {
800
842
  throw new Error(
801
- `WASI binding package version mismatch, expected 1.4.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
843
+ `WASI binding package version mismatch, expected 1.5.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
802
844
  )
803
845
  }
804
846
  }
805
847
  wasiBinding = require('@napi-rs/webcodecs-wasm32-wasi')
806
848
  nativeBinding = wasiBinding
849
+ __napiLoadedBindingTarget = 'wasm32-wasi'
807
850
  wasiBindingLoaded = true
808
851
  }
809
852
  } catch (err) {
@@ -817,6 +860,7 @@ if (!nativeBinding || forceWasi) {
817
860
  }
818
861
  if (!wasiBindingLoaded && forceWasi && !forceWasiError && !__napiWasiFlavorRequested) {
819
862
  nativeBinding = requireNative()
863
+ __napiRequiredNativeBinding = nativeBinding
820
864
  }
821
865
  if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
822
866
  const error = new Error(
@@ -844,6 +888,96 @@ if (!nativeBinding) {
844
888
  throw new Error(`Failed to load native binding`)
845
889
  }
846
890
 
891
+ // A package can patch its own fallback in front of the load-failure check
892
+ // above, e.g. a WebContainer download through `napi-postinstall/fallback`.
893
+ // That fallback swaps `nativeBinding` for a generated WASI loader, which has
894
+ // already stamped its own flavor, while the target above still says 'native'.
895
+ // Take that flavor over, or the CommonJS stamp throws a conflict and the ESM
896
+ // export reports the wrong artifact. Three limits keep the conflict check:
897
+ // - only a binding this loader did not load itself, so a native addon whose
898
+ // `#[napi(module_exports)]` hook claims the name is still rejected;
899
+ // - only an own data property, read through its descriptor, so no addon
900
+ // getter runs here, and it must read back the same, as the stamp reads it;
901
+ // - only a flavor in `__napiWasiFlavors`, the ones this loader's own WASI
902
+ // chain can report ('wasm32-wasi' for a package without a WASI target).
903
+ // This is metadata and never fails a load: a throwing Proxy trap keeps 'native'.
904
+ if (__napiLoadedBindingTarget === 'native' && nativeBinding !== __napiRequiredNativeBinding) {
905
+ try {
906
+ const __napiBindingTargetDescriptor = Object.getOwnPropertyDescriptor(nativeBinding, '__napiBindingTarget')
907
+ if (
908
+ __napiBindingTargetDescriptor &&
909
+ __napiWasiFlavors.indexOf(__napiBindingTargetDescriptor.value) !== -1 &&
910
+ nativeBinding.__napiBindingTarget === __napiBindingTargetDescriptor.value
911
+ ) {
912
+ __napiLoadedBindingTarget = __napiBindingTargetDescriptor.value
913
+ }
914
+ } catch {
915
+ // keep 'native'
916
+ }
917
+ }
918
+
919
+ function __napiStampBindingTarget(exportsObject, target) {
920
+ if (Object.prototype.hasOwnProperty.call(exportsObject, '__napiBindingTarget')) {
921
+ if (exportsObject.__napiBindingTarget === target) {
922
+ // Already ours: the root entry aliases the object it loaded, so a WASI
923
+ // fallback candidate — or a `NAPI_RS_NATIVE_LIBRARY_PATH` override that
924
+ // is a generated loader — arrives already stamped with this same value.
925
+ return target
926
+ }
927
+ const error = new Error(
928
+ '`__napiBindingTarget` is reserved by the generated binding loader, but the loaded binding already exports it. Rename the export, e.g. #[napi(js_name = "...")].',
929
+ )
930
+ error.code = 'ERR_NAPI_BINDING_TARGET_CONFLICT'
931
+ throw error
932
+ }
933
+ if (!Object.isExtensible(exportsObject)) {
934
+ // A `#[napi(module_exports)]` hook may seal or freeze this object
935
+ // (`Object::seal` / `Object::freeze`). Reporting the artifact is metadata,
936
+ // never a reason to fail an otherwise successful load, so the stamp is
937
+ // skipped. What a consumer still sees then follows the entry point: the
938
+ // browser and deferred loaders declare `__napiBindingTarget` at module
939
+ // level and go on reporting it, while the CommonJS entries hand back this
940
+ // very object as `module.exports`, so there the value is absent.
941
+ return target
942
+ }
943
+ try {
944
+ // [[Define]], not [[Set]]: an ordinary assignment walks the prototype
945
+ // chain, so an inherited accessor could swallow the value or throw and
946
+ // fail an otherwise successful load. The descriptor is what a successful
947
+ // assignment would have produced.
948
+ Object.defineProperty(exportsObject, '__napiBindingTarget', {
949
+ configurable: true,
950
+ enumerable: true,
951
+ value: target,
952
+ writable: true,
953
+ })
954
+ } catch {
955
+ // Same rule as the non-extensible skip above: reporting the artifact is
956
+ // metadata, never a reason to fail an otherwise successful load. An exotic
957
+ // object (a Proxy whose defineProperty trap refuses) is skipped, not
958
+ // thrown over.
959
+ }
960
+ // The CommonJS loaders assign this return value so `cjs-module-lexer` — and
961
+ // therefore Node's CJS -> ESM named export detection — can see
962
+ // `__napiBindingTarget` statically.
963
+ return target
964
+ }
965
+ // Stamp before the alias, not after. The guard only reads `nativeBinding`
966
+ // (`hasOwnProperty` plus a comparison), which is safe against any addon
967
+ // accessor; an assignment is not, because a `#[napi(module_exports)]` hook can
968
+ // expose a getter reporting this very value and a setter that throws. So the
969
+ // assignment lands on the loader's own `module.exports`, still the original
970
+ // object here, and the alias below replaces it.
971
+ //
972
+ // The assignment is what keeps the marker a statically visible CommonJS export:
973
+ // `cjs-module-lexer` is Node's CJS -> ESM named export detection, it cannot see
974
+ // a bare call, and the later `module.exports = nativeBinding` does not undo the
975
+ // detection. The assignment itself always succeeds — its target is this
976
+ // loader's own, still extensible `module.exports` — and the alias below then
977
+ // discards the value it wrote. What a consumer reads is whatever the guard put
978
+ // on `nativeBinding`, so on a frozen binding, where the guard skips, the
979
+ // linked import resolves to `undefined`.
980
+ module.exports.__napiBindingTarget = __napiStampBindingTarget(nativeBinding, __napiLoadedBindingTarget)
847
981
  module.exports = nativeBinding
848
982
  module.exports.AudioData = nativeBinding.AudioData
849
983
  module.exports.AudioDecoder = nativeBinding.AudioDecoder
@@ -872,6 +1006,8 @@ module.exports.AvcBitstreamFormat = nativeBinding.AvcBitstreamFormat
872
1006
  module.exports.BitrateMode = nativeBinding.BitrateMode
873
1007
  module.exports.CodecState = nativeBinding.CodecState
874
1008
  module.exports.ColorSpaceConversion = nativeBinding.ColorSpaceConversion
1009
+ module.exports.copyVideoFrameRGBA16Float = nativeBinding.copyVideoFrameRGBA16Float
1010
+ module.exports.createVideoFrameFromRGBA16Float = nativeBinding.createVideoFrameFromRGBA16Float
875
1011
  module.exports.EncodedAudioChunkType = nativeBinding.EncodedAudioChunkType
876
1012
  module.exports.EncodedVideoChunkType = nativeBinding.EncodedVideoChunkType
877
1013
  module.exports.getAvailableHardwareAccelerators = nativeBinding.getAvailableHardwareAccelerators
@@ -885,6 +1021,8 @@ module.exports.LatencyMode = nativeBinding.LatencyMode
885
1021
  module.exports.OpusApplication = nativeBinding.OpusApplication
886
1022
  module.exports.OpusBitstreamFormat = nativeBinding.OpusBitstreamFormat
887
1023
  module.exports.OpusSignal = nativeBinding.OpusSignal
1024
+ module.exports.PredefinedColorSpace = nativeBinding.PredefinedColorSpace
1025
+ module.exports.registerVideoFrameCloseObserver = nativeBinding.registerVideoFrameCloseObserver
888
1026
  module.exports.resetHardwareFallbackState = nativeBinding.resetHardwareFallbackState
889
1027
  module.exports.VideoColorPrimaries = nativeBinding.VideoColorPrimaries
890
1028
  module.exports.VideoEncoderBitrateMode = nativeBinding.VideoEncoderBitrateMode
@@ -0,0 +1,27 @@
1
+ Copyright (c) 2016, Alliance for Open Media. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright
8
+ notice, this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in
12
+ the documentation and/or other materials provided with the
13
+ distribution.
14
+
15
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19
+ COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26
+ POSSIBILITY OF SUCH DAMAGE.
27
+