@napi-rs/webcodecs 1.3.1 → 1.4.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 (4) hide show
  1. package/README.md +17 -0
  2. package/index.d.ts +148 -170
  3. package/index.js +195 -84
  4. package/package.json +38 -52
package/README.md CHANGED
@@ -168,6 +168,11 @@ result.image.close()
168
168
  decoder.close()
169
169
  ```
170
170
 
171
+ When `data` is a `ReadableStream`, `ImageDecoder` accumulates every chunk so it
172
+ can re-probe the growing input. This buffer currently has no fixed limit, so
173
+ applications should bound or reject unexpectedly large streams before passing
174
+ them to the decoder.
175
+
171
176
  ### Container Demuxing
172
177
 
173
178
  Read encoded video/audio from MP4, WebM, or MKV containers:
@@ -283,6 +288,7 @@ import { Mp4Muxer } from '@napi-rs/webcodecs'
283
288
 
284
289
  const muxer = new Mp4Muxer({
285
290
  fragmented: true, // Required for MP4 streaming
291
+ // Maximum bytes returned by each read(); this is not a memory limit.
286
292
  streaming: { bufferCapacity: 256 * 1024 },
287
293
  })
288
294
 
@@ -303,6 +309,12 @@ if (muxer.isFinished) {
303
309
  }
304
310
  ```
305
311
 
312
+ Streaming writes are queued in a growable native buffer so `addVideoChunk()`
313
+ and `addAudioChunk()` never wait for JavaScript to call `read()`. Applications
314
+ must drain `read()` regularly; an indefinitely stalled consumer can retain the
315
+ entire muxed output in memory. `bufferCapacity` controls only the maximum size
316
+ of each returned read chunk.
317
+
306
318
  ### VideoFrame from Canvas
307
319
 
308
320
  Create VideoFrames from `@napi-rs/canvas` for graphics, text rendering, or image compositing:
@@ -683,6 +695,11 @@ For full API documentation, see the [W3C WebCodecs specification](https://w3c.gi
683
695
  - Node.js 18+
684
696
  - pnpm
685
697
 
698
+ The build downloads the pinned FFmpeg 9.0 release by default. If you opt out
699
+ of that download or set `FFMPEG_DIR`, the supplied FFmpeg headers and libraries
700
+ must be from FFmpeg 9.x; FFmpeg 8.x system/Homebrew installations are rejected
701
+ by the ABI guard.
702
+
686
703
  ### Build
687
704
 
688
705
  ```bash
package/index.d.ts CHANGED
@@ -111,32 +111,6 @@ export interface MuxerAudioTrackConfig {
111
111
  description?: Uint8Array
112
112
  }
113
113
 
114
- /** Init options for Mp4Muxer */
115
- export interface Mp4MuxerInit {
116
- /** Move moov atom to beginning (not compatible with streaming) */
117
- fastStart?: boolean
118
- /** Use fragmented MP4 for streaming */
119
- fragmented?: boolean
120
- /** Enable streaming output mode */
121
- streaming?: { bufferCapacity?: number }
122
- }
123
-
124
- /** Init options for WebMMuxer */
125
- export interface WebMMuxerInit {
126
- /** Enable live streaming mode */
127
- live?: boolean
128
- /** Enable streaming output mode */
129
- streaming?: { bufferCapacity?: number }
130
- }
131
-
132
- /** Init options for MkvMuxer */
133
- export interface MkvMuxerInit {
134
- /** Enable live streaming mode */
135
- live?: boolean
136
- /** Enable streaming output mode */
137
- streaming?: { bufferCapacity?: number }
138
- }
139
-
140
114
  // ============================================================================
141
115
  // Async Iterator Types
142
116
  // ============================================================================
@@ -539,7 +513,8 @@ export declare class EncodedVideoChunk {
539
513
  export declare class ImageDecoder {
540
514
  /**
541
515
  * Create a new ImageDecoder
542
- * Supports both Uint8Array and ReadableStream as data source per W3C spec
516
+ * Supports both Uint8Array and ReadableStream as data source per W3C spec.
517
+ * ReadableStream input is buffered without a fixed size limit.
543
518
  */
544
519
  constructor(init: ImageDecoderInit)
545
520
  /** Whether the data is fully buffered */
@@ -1272,9 +1247,9 @@ export declare class WebMMuxer {
1272
1247
 
1273
1248
  /** AAC bitstream format (W3C WebCodecs AAC Registration) */
1274
1249
  export type AacBitstreamFormat = /** Raw AAC frames - metadata in description */
1275
- | 'aac'
1276
- /** ADTS frames - metadata in each frame */
1277
- | 'adts'
1250
+ | 'aac'
1251
+ /** ADTS frames - metadata in each frame */
1252
+ | 'adts'
1278
1253
 
1279
1254
  /** AAC encoder configuration (W3C WebCodecs AAC Registration) */
1280
1255
  export interface AacEncoderConfig {
@@ -1294,9 +1269,9 @@ export interface AddEventListenerOptions {
1294
1269
  * Default is "discard" per spec
1295
1270
  */
1296
1271
  export type AlphaOption = /** Keep alpha channel if present */
1297
- | 'keep'
1298
- /** Discard alpha channel (default per W3C spec) */
1299
- | 'discard'
1272
+ | 'keep'
1273
+ /** Discard alpha channel (default per W3C spec) */
1274
+ | 'discard'
1300
1275
 
1301
1276
  /** Options for copyTo operation */
1302
1277
  export interface AudioDataCopyToOptions {
@@ -1379,27 +1354,27 @@ export interface AudioEncoderSupport {
1379
1354
 
1380
1355
  /** Audio sample format (WebCodecs spec) */
1381
1356
  export type AudioSampleFormat = /** Unsigned 8-bit integer samples| interleaved */
1382
- | 'u8'
1383
- /** Signed 16-bit integer samples| interleaved */
1384
- | 's16'
1385
- /** Signed 32-bit integer samples| interleaved */
1386
- | 's32'
1387
- /** 32-bit float samples| interleaved */
1388
- | 'f32'
1389
- /** Unsigned 8-bit integer samples| planar */
1390
- | 'u8-planar'
1391
- /** Signed 16-bit integer samples| planar */
1392
- | 's16-planar'
1393
- /** Signed 32-bit integer samples| planar */
1394
- | 's32-planar'
1395
- /** 32-bit float samples| planar */
1396
- | 'f32-planar'
1357
+ | 'u8'
1358
+ /** Signed 16-bit integer samples| interleaved */
1359
+ | 's16'
1360
+ /** Signed 32-bit integer samples| interleaved */
1361
+ | 's32'
1362
+ /** 32-bit float samples| interleaved */
1363
+ | 'f32'
1364
+ /** Unsigned 8-bit integer samples| planar */
1365
+ | 'u8-planar'
1366
+ /** Signed 16-bit integer samples| planar */
1367
+ | 's16-planar'
1368
+ /** Signed 32-bit integer samples| planar */
1369
+ | 's32-planar'
1370
+ /** 32-bit float samples| planar */
1371
+ | 'f32-planar'
1397
1372
 
1398
1373
  /** AVC (H.264) bitstream format (W3C WebCodecs AVC Registration) */
1399
1374
  export type AvcBitstreamFormat = /** AVC format with parameter sets in description (ISO 14496-15) */
1400
- | 'avc'
1401
- /** Annex B format with parameter sets in bitstream */
1402
- | 'annexb'
1375
+ | 'avc'
1376
+ /** Annex B format with parameter sets in bitstream */
1377
+ | 'annexb'
1403
1378
 
1404
1379
  /** AVC (H.264) encoder configuration (W3C WebCodecs AVC Registration) */
1405
1380
  export interface AvcEncoderConfig {
@@ -1409,23 +1384,23 @@ export interface AvcEncoderConfig {
1409
1384
 
1410
1385
  /** Bitrate mode for audio encoding (W3C WebCodecs spec) */
1411
1386
  export type BitrateMode = /** Variable bitrate (default) */
1412
- | 'variable'
1413
- /** Constant bitrate */
1414
- | 'constant'
1387
+ | 'variable'
1388
+ /** Constant bitrate */
1389
+ | 'constant'
1415
1390
 
1416
1391
  /** Encoder state per WebCodecs spec */
1417
1392
  export type CodecState = /** Encoder not configured */
1418
- | 'unconfigured'
1419
- /** Encoder configured and ready */
1420
- | 'configured'
1421
- /** Encoder closed */
1422
- | 'closed'
1393
+ | 'unconfigured'
1394
+ /** Encoder configured and ready */
1395
+ | 'configured'
1396
+ /** Encoder closed */
1397
+ | 'closed'
1423
1398
 
1424
1399
  /** ColorSpaceConversion for ImageDecoder (W3C WebCodecs spec) */
1425
1400
  export type ColorSpaceConversion = /** Apply default color space conversion (spec default) */
1426
- | 'default'
1427
- /** No color space conversion */
1428
- | 'none'
1401
+ | 'default'
1402
+ /** No color space conversion */
1403
+ | 'none'
1429
1404
 
1430
1405
  /** Audio decoder configuration exposed to JavaScript */
1431
1406
  export interface DemuxerAudioDecoderConfig {
@@ -1493,9 +1468,9 @@ export interface EncodedAudioChunkMetadataJs {
1493
1468
 
1494
1469
  /** Type of encoded audio chunk */
1495
1470
  export type EncodedAudioChunkType = /** Key chunk - can be decoded independently */
1496
- | 'key'
1497
- /** Delta chunk - depends on previous chunks */
1498
- | 'delta'
1471
+ | 'key'
1472
+ /** Delta chunk - depends on previous chunks */
1473
+ | 'delta'
1499
1474
 
1500
1475
  /** Output callback metadata per WebCodecs spec */
1501
1476
  export interface EncodedVideoChunkMetadata {
@@ -1523,9 +1498,9 @@ export interface EncodedVideoChunkMetadataJs {
1523
1498
 
1524
1499
  /** Type of encoded video chunk */
1525
1500
  export type EncodedVideoChunkType = /** Keyframe - can be decoded independently */
1526
- | 'key'
1527
- /** Delta frame - depends on previous frames */
1528
- | 'delta'
1501
+ | 'key'
1502
+ /** Delta frame - depends on previous frames */
1503
+ | 'delta'
1529
1504
 
1530
1505
  /** Options for removeEventListener (W3C DOM spec) */
1531
1506
  export interface EventListenerOptions {
@@ -1551,11 +1526,11 @@ export declare function getPreferredHardwareAccelerator(): string | null
1551
1526
 
1552
1527
  /** Hardware acceleration preference (W3C WebCodecs spec) */
1553
1528
  export type HardwareAcceleration = /** No preference - may use hardware or software */
1554
- | 'no-preference'
1555
- /** Prefer hardware acceleration */
1556
- | 'prefer-hardware'
1557
- /** Prefer software implementation */
1558
- | 'prefer-software'
1529
+ | 'no-preference'
1530
+ /** Prefer hardware acceleration */
1531
+ | 'prefer-hardware'
1532
+ /** Prefer software implementation */
1533
+ | 'prefer-software'
1559
1534
 
1560
1535
  /** Hardware accelerator information */
1561
1536
  export interface HardwareAccelerator {
@@ -1569,9 +1544,9 @@ export interface HardwareAccelerator {
1569
1544
 
1570
1545
  /** HEVC (H.265) bitstream format (W3C WebCodecs HEVC Registration) */
1571
1546
  export type HevcBitstreamFormat = /** HEVC format with parameter sets in description (ISO 14496-15) */
1572
- | 'hevc'
1573
- /** Annex B format with parameter sets in bitstream */
1574
- | 'annexb'
1547
+ | 'hevc'
1548
+ /** Annex B format with parameter sets in bitstream */
1549
+ | 'annexb'
1575
1550
 
1576
1551
  /** HEVC (H.265) encoder configuration (W3C WebCodecs HEVC Registration) */
1577
1552
  export interface HevcEncoderConfig {
@@ -1592,9 +1567,9 @@ export declare function isHardwareAcceleratorAvailable(name: string): boolean
1592
1567
 
1593
1568
  /** Latency mode for video encoding (W3C WebCodecs spec) */
1594
1569
  export type LatencyMode = /** Optimize for quality (default) */
1595
- | 'quality'
1596
- /** Optimize for low latency */
1597
- | 'realtime'
1570
+ | 'quality'
1571
+ /** Optimize for low latency */
1572
+ | 'realtime'
1598
1573
 
1599
1574
  /** Audio track configuration for MKV muxer */
1600
1575
  export interface MkvAudioTrackConfig {
@@ -1674,17 +1649,17 @@ export interface Mp4VideoTrackConfig {
1674
1649
 
1675
1650
  /** Opus application mode (W3C WebCodecs Opus Registration) */
1676
1651
  export type OpusApplication = /** Optimize for VoIP (speech intelligibility) */
1677
- | 'voip'
1678
- /** Optimize for audio fidelity (default) */
1679
- | 'audio'
1680
- /** Minimize coding delay */
1681
- | 'lowdelay'
1652
+ | 'voip'
1653
+ /** Optimize for audio fidelity (default) */
1654
+ | 'audio'
1655
+ /** Minimize coding delay */
1656
+ | 'lowdelay'
1682
1657
 
1683
1658
  /** Opus bitstream format (W3C WebCodecs Opus Registration) */
1684
1659
  export type OpusBitstreamFormat = /** Opus packets (RFC 6716) - no metadata needed for decoding */
1685
- | 'opus'
1686
- /** Ogg encapsulation (RFC 7845) - metadata in description */
1687
- | 'ogg'
1660
+ | 'opus'
1661
+ /** Ogg encapsulation (RFC 7845) - metadata in description */
1662
+ | 'ogg'
1688
1663
 
1689
1664
  /** Opus encoder configuration (W3C WebCodecs Opus Registration) */
1690
1665
  export interface OpusEncoderConfig {
@@ -1711,11 +1686,11 @@ export interface OpusEncoderConfig {
1711
1686
 
1712
1687
  /** Opus signal type hint (W3C WebCodecs Opus Registration) */
1713
1688
  export type OpusSignal = /** Auto-detect signal type */
1714
- | 'auto'
1715
- /** Music signal */
1716
- | 'music'
1717
- /** Voice/speech signal */
1718
- | 'voice'
1689
+ | 'auto'
1690
+ /** Music signal */
1691
+ | 'music'
1692
+ /** Voice/speech signal */
1693
+ | 'voice'
1719
1694
 
1720
1695
  /** Layout information for a single plane per WebCodecs spec */
1721
1696
  export interface PlaneLayout {
@@ -1738,7 +1713,10 @@ export declare function resetHardwareFallbackState(): void
1738
1713
 
1739
1714
  /** Streaming mode options for muxers */
1740
1715
  export interface StreamingMuxerOptions {
1741
- /** Buffer capacity for streaming output (default: 256KB) */
1716
+ /**
1717
+ * Maximum bytes returned by each streaming read (default: 256KB).
1718
+ * Muxer writes are queued without blocking the JavaScript consumer.
1719
+ */
1742
1720
  bufferCapacity?: number
1743
1721
  }
1744
1722
 
@@ -1756,15 +1734,15 @@ export interface SvcOutputMetadataJs {
1756
1734
 
1757
1735
  /** Video color primaries (W3C WebCodecs spec) */
1758
1736
  export type VideoColorPrimaries = /** BT.709 / sRGB primaries */
1759
- | 'bt709'
1760
- /** BT.470 BG (PAL) */
1761
- | 'bt470bg'
1762
- /** SMPTE 170M (NTSC) */
1763
- | 'smpte170m'
1764
- /** BT.2020 (UHD) */
1765
- | 'bt2020'
1766
- /** SMPTE 432 (DCI-P3) */
1767
- | 'smpte432'
1737
+ | 'bt709'
1738
+ /** BT.470 BG (PAL) */
1739
+ | 'bt470bg'
1740
+ /** SMPTE 170M (NTSC) */
1741
+ | 'smpte170m'
1742
+ /** BT.2020 (UHD) */
1743
+ | 'bt2020'
1744
+ /** SMPTE 432 (DCI-P3) */
1745
+ | 'smpte432'
1768
1746
 
1769
1747
  /** Options for addEventListener (W3C DOM spec) */
1770
1748
  export interface VideoDecoderAddEventListenerOptions {
@@ -1822,11 +1800,11 @@ export interface VideoDecoderSupport {
1822
1800
 
1823
1801
  /** Bitrate mode for video encoding (W3C WebCodecs spec) */
1824
1802
  export type VideoEncoderBitrateMode = /** Variable bitrate (default) */
1825
- | 'variable'
1826
- /** Constant bitrate */
1827
- | 'constant'
1828
- /** Use quantizer parameter from codec-specific options */
1829
- | 'quantizer'
1803
+ | 'variable'
1804
+ /** Constant bitrate */
1805
+ | 'constant'
1806
+ /** Use quantizer parameter from codec-specific options */
1807
+ | 'quantizer'
1830
1808
 
1831
1809
  /** Encode options per WebCodecs spec */
1832
1810
  export interface VideoEncoderEncodeOptions {
@@ -1922,75 +1900,75 @@ export interface VideoFrameRect {
1922
1900
 
1923
1901
  /** Video matrix coefficients (W3C WebCodecs spec) */
1924
1902
  export type VideoMatrixCoefficients = /** RGB (identity matrix) */
1925
- | 'rgb'
1926
- /** BT.709 */
1927
- | 'bt709'
1928
- /** BT.470 BG */
1929
- | 'bt470bg'
1930
- /** SMPTE 170M */
1931
- | 'smpte170m'
1932
- /** BT.2020 non-constant luminance */
1933
- | 'bt2020-ncl'
1903
+ | 'rgb'
1904
+ /** BT.709 */
1905
+ | 'bt709'
1906
+ /** BT.470 BG */
1907
+ | 'bt470bg'
1908
+ /** SMPTE 170M */
1909
+ | 'smpte170m'
1910
+ /** BT.2020 non-constant luminance */
1911
+ | 'bt2020-ncl'
1934
1912
 
1935
1913
  /** Video pixel format (WebCodecs spec) */
1936
1914
  export type VideoPixelFormat = /** Planar YUV 4:2:0| 12bpp| (1 Cr & Cb sample per 2x2 Y samples) */
1937
- | 'I420'
1938
- /** Planar YUV 4:2:0| 12bpp| with alpha plane */
1939
- | 'I420A'
1940
- /** Planar YUV 4:2:2| 16bpp */
1941
- | 'I422'
1942
- /** Planar YUV 4:2:2| 16bpp| with alpha plane */
1943
- | 'I422A'
1944
- /** Planar YUV 4:4:4| 24bpp */
1945
- | 'I444'
1946
- /** Planar YUV 4:4:4| 24bpp| with alpha plane */
1947
- | 'I444A'
1948
- /** Planar YUV 4:2:0| 10-bit */
1949
- | 'I420P10'
1950
- /** Planar YUV 4:2:0| 10-bit| with alpha plane */
1951
- | 'I420AP10'
1952
- /** Planar YUV 4:2:2| 10-bit */
1953
- | 'I422P10'
1954
- /** Planar YUV 4:2:2| 10-bit| with alpha plane */
1955
- | 'I422AP10'
1956
- /** Planar YUV 4:4:4| 10-bit */
1957
- | 'I444P10'
1958
- /** Planar YUV 4:4:4| 10-bit| with alpha plane */
1959
- | 'I444AP10'
1960
- /** Planar YUV 4:2:0| 12-bit */
1961
- | 'I420P12'
1962
- /** Planar YUV 4:2:2| 12-bit */
1963
- | 'I422P12'
1964
- /** Planar YUV 4:4:4| 12-bit */
1965
- | 'I444P12'
1966
- /** Semi-planar YUV 4:2:0| 12bpp (Y plane + interleaved UV) */
1967
- | 'NV12'
1968
- /** Semi-planar YUV 4:2:0| 12bpp (Y plane + interleaved VU) - per W3C WebCodecs spec */
1969
- | 'NV21'
1970
- /** RGBA 32bpp */
1971
- | 'RGBA'
1972
- /** RGBX 32bpp (alpha ignored) */
1973
- | 'RGBX'
1974
- /** BGRA 32bpp */
1975
- | 'BGRA'
1976
- /** BGRX 32bpp (alpha ignored) */
1977
- | 'BGRX'
1915
+ | 'I420'
1916
+ /** Planar YUV 4:2:0| 12bpp| with alpha plane */
1917
+ | 'I420A'
1918
+ /** Planar YUV 4:2:2| 16bpp */
1919
+ | 'I422'
1920
+ /** Planar YUV 4:2:2| 16bpp| with alpha plane */
1921
+ | 'I422A'
1922
+ /** Planar YUV 4:4:4| 24bpp */
1923
+ | 'I444'
1924
+ /** Planar YUV 4:4:4| 24bpp| with alpha plane */
1925
+ | 'I444A'
1926
+ /** Planar YUV 4:2:0| 10-bit */
1927
+ | 'I420P10'
1928
+ /** Planar YUV 4:2:0| 10-bit| with alpha plane */
1929
+ | 'I420AP10'
1930
+ /** Planar YUV 4:2:2| 10-bit */
1931
+ | 'I422P10'
1932
+ /** Planar YUV 4:2:2| 10-bit| with alpha plane */
1933
+ | 'I422AP10'
1934
+ /** Planar YUV 4:4:4| 10-bit */
1935
+ | 'I444P10'
1936
+ /** Planar YUV 4:4:4| 10-bit| with alpha plane */
1937
+ | 'I444AP10'
1938
+ /** Planar YUV 4:2:0| 12-bit */
1939
+ | 'I420P12'
1940
+ /** Planar YUV 4:2:2| 12-bit */
1941
+ | 'I422P12'
1942
+ /** Planar YUV 4:4:4| 12-bit */
1943
+ | 'I444P12'
1944
+ /** Semi-planar YUV 4:2:0| 12bpp (Y plane + interleaved UV) */
1945
+ | 'NV12'
1946
+ /** Semi-planar YUV 4:2:0| 12bpp (Y plane + interleaved VU) - per W3C WebCodecs spec */
1947
+ | 'NV21'
1948
+ /** RGBA 32bpp */
1949
+ | 'RGBA'
1950
+ /** RGBX 32bpp (alpha ignored) */
1951
+ | 'RGBX'
1952
+ /** BGRA 32bpp */
1953
+ | 'BGRA'
1954
+ /** BGRX 32bpp (alpha ignored) */
1955
+ | 'BGRX'
1978
1956
 
1979
1957
  /** Video transfer characteristics (W3C WebCodecs spec) */
1980
1958
  export type VideoTransferCharacteristics = /** BT.709 transfer */
1981
- | 'bt709'
1982
- /** SMPTE 170M transfer */
1983
- | 'smpte170m'
1984
- /** IEC 61966-2-1 (sRGB) - technical name */
1985
- | 'iec61966-2-1'
1986
- /** sRGB transfer (alias for iec61966-2-1) */
1987
- | 'srgb'
1988
- /** Linear transfer */
1989
- | 'linear'
1990
- /** Perceptual Quantizer (HDR) */
1991
- | 'pq'
1992
- /** Hybrid Log-Gamma (HDR) */
1993
- | 'hlg'
1959
+ | 'bt709'
1960
+ /** SMPTE 170M transfer */
1961
+ | 'smpte170m'
1962
+ /** IEC 61966-2-1 (sRGB) - technical name */
1963
+ | 'iec61966-2-1'
1964
+ /** sRGB transfer (alias for iec61966-2-1) */
1965
+ | 'srgb'
1966
+ /** Linear transfer */
1967
+ | 'linear'
1968
+ /** Perceptual Quantizer (HDR) */
1969
+ | 'pq'
1970
+ /** Hybrid Log-Gamma (HDR) */
1971
+ | 'hlg'
1994
1972
 
1995
1973
  /** Audio track configuration for WebM muxer */
1996
1974
  export interface WebMAudioTrackConfig {
package/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  // @ts-nocheck
4
4
  /* auto-generated by NAPI-RS */
5
5
 
6
- const { readFileSync } = require('node:fs')
6
+ const { readFileSync } = require('fs')
7
7
  let nativeBinding = null
8
8
  const loadErrors = []
9
9
 
@@ -33,7 +33,7 @@ const isMuslFromFilesystem = () => {
33
33
 
34
34
  const isMuslFromReport = () => {
35
35
  let report = null
36
- if (typeof process.report?.getReport === 'function') {
36
+ if (process.report && typeof process.report.getReport === 'function') {
37
37
  process.report.excludeNetwork = true
38
38
  report = process.report.getReport()
39
39
  }
@@ -78,12 +78,12 @@ function requireNative() {
78
78
  const binding = require('@napi-rs/webcodecs-android-arm64')
79
79
  const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm64/package.json').version
80
80
  if (
81
- bindingPackageVersion !== '1.3.1' &&
81
+ bindingPackageVersion !== '1.4.0' &&
82
82
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
83
83
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
84
84
  ) {
85
85
  throw new Error(
86
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
86
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
87
87
  )
88
88
  }
89
89
  return binding
@@ -100,12 +100,12 @@ function requireNative() {
100
100
  const binding = require('@napi-rs/webcodecs-android-arm-eabi')
101
101
  const bindingPackageVersion = require('@napi-rs/webcodecs-android-arm-eabi/package.json').version
102
102
  if (
103
- bindingPackageVersion !== '1.3.1' &&
103
+ bindingPackageVersion !== '1.4.0' &&
104
104
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
105
105
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
106
106
  ) {
107
107
  throw new Error(
108
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
108
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
109
109
  )
110
110
  }
111
111
  return binding
@@ -118,8 +118,8 @@ function requireNative() {
118
118
  } else if (process.platform === 'win32') {
119
119
  if (process.arch === 'x64') {
120
120
  if (
121
- process.config?.variables?.shlib_suffix === 'dll.a' ||
122
- process.config?.variables?.node_target_type === 'shared_library'
121
+ (process.config && process.config.variables && process.config.variables.shlib_suffix === 'dll.a') ||
122
+ (process.config && process.config.variables && process.config.variables.node_target_type === 'shared_library')
123
123
  ) {
124
124
  try {
125
125
  return require('./webcodecs.win32-x64-gnu.node')
@@ -130,12 +130,12 @@ function requireNative() {
130
130
  const binding = require('@napi-rs/webcodecs-win32-x64-gnu')
131
131
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-gnu/package.json').version
132
132
  if (
133
- bindingPackageVersion !== '1.3.1' &&
133
+ bindingPackageVersion !== '1.4.0' &&
134
134
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
135
135
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
136
136
  ) {
137
137
  throw new Error(
138
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
138
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
139
139
  )
140
140
  }
141
141
  return binding
@@ -152,12 +152,12 @@ function requireNative() {
152
152
  const binding = require('@napi-rs/webcodecs-win32-x64-msvc')
153
153
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-x64-msvc/package.json').version
154
154
  if (
155
- bindingPackageVersion !== '1.3.1' &&
155
+ bindingPackageVersion !== '1.4.0' &&
156
156
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
157
157
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
158
158
  ) {
159
159
  throw new Error(
160
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
160
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
161
161
  )
162
162
  }
163
163
  return binding
@@ -175,12 +175,12 @@ function requireNative() {
175
175
  const binding = require('@napi-rs/webcodecs-win32-ia32-msvc')
176
176
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-ia32-msvc/package.json').version
177
177
  if (
178
- bindingPackageVersion !== '1.3.1' &&
178
+ bindingPackageVersion !== '1.4.0' &&
179
179
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
180
180
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
181
181
  ) {
182
182
  throw new Error(
183
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
183
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
184
184
  )
185
185
  }
186
186
  return binding
@@ -197,12 +197,12 @@ function requireNative() {
197
197
  const binding = require('@napi-rs/webcodecs-win32-arm64-msvc')
198
198
  const bindingPackageVersion = require('@napi-rs/webcodecs-win32-arm64-msvc/package.json').version
199
199
  if (
200
- bindingPackageVersion !== '1.3.1' &&
200
+ bindingPackageVersion !== '1.4.0' &&
201
201
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
202
202
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
203
203
  ) {
204
204
  throw new Error(
205
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
205
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
206
206
  )
207
207
  }
208
208
  return binding
@@ -222,12 +222,12 @@ function requireNative() {
222
222
  const binding = require('@napi-rs/webcodecs-darwin-universal')
223
223
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-universal/package.json').version
224
224
  if (
225
- bindingPackageVersion !== '1.3.1' &&
225
+ bindingPackageVersion !== '1.4.0' &&
226
226
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
227
227
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
228
228
  ) {
229
229
  throw new Error(
230
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
230
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
231
231
  )
232
232
  }
233
233
  return binding
@@ -244,12 +244,12 @@ function requireNative() {
244
244
  const binding = require('@napi-rs/webcodecs-darwin-x64')
245
245
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-x64/package.json').version
246
246
  if (
247
- bindingPackageVersion !== '1.3.1' &&
247
+ bindingPackageVersion !== '1.4.0' &&
248
248
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
249
249
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
250
250
  ) {
251
251
  throw new Error(
252
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
252
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
253
253
  )
254
254
  }
255
255
  return binding
@@ -266,12 +266,12 @@ function requireNative() {
266
266
  const binding = require('@napi-rs/webcodecs-darwin-arm64')
267
267
  const bindingPackageVersion = require('@napi-rs/webcodecs-darwin-arm64/package.json').version
268
268
  if (
269
- bindingPackageVersion !== '1.3.1' &&
269
+ bindingPackageVersion !== '1.4.0' &&
270
270
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
271
271
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
272
272
  ) {
273
273
  throw new Error(
274
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
274
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
275
275
  )
276
276
  }
277
277
  return binding
@@ -292,12 +292,12 @@ function requireNative() {
292
292
  const binding = require('@napi-rs/webcodecs-freebsd-x64')
293
293
  const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-x64/package.json').version
294
294
  if (
295
- bindingPackageVersion !== '1.3.1' &&
295
+ bindingPackageVersion !== '1.4.0' &&
296
296
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
297
297
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
298
298
  ) {
299
299
  throw new Error(
300
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
300
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
301
301
  )
302
302
  }
303
303
  return binding
@@ -314,12 +314,12 @@ function requireNative() {
314
314
  const binding = require('@napi-rs/webcodecs-freebsd-arm64')
315
315
  const bindingPackageVersion = require('@napi-rs/webcodecs-freebsd-arm64/package.json').version
316
316
  if (
317
- bindingPackageVersion !== '1.3.1' &&
317
+ bindingPackageVersion !== '1.4.0' &&
318
318
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
319
319
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
320
320
  ) {
321
321
  throw new Error(
322
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
322
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
323
323
  )
324
324
  }
325
325
  return binding
@@ -341,12 +341,12 @@ function requireNative() {
341
341
  const binding = require('@napi-rs/webcodecs-linux-x64-musl')
342
342
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-musl/package.json').version
343
343
  if (
344
- bindingPackageVersion !== '1.3.1' &&
344
+ bindingPackageVersion !== '1.4.0' &&
345
345
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
346
346
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
347
347
  ) {
348
348
  throw new Error(
349
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
349
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
350
350
  )
351
351
  }
352
352
  return binding
@@ -363,12 +363,12 @@ function requireNative() {
363
363
  const binding = require('@napi-rs/webcodecs-linux-x64-gnu')
364
364
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-x64-gnu/package.json').version
365
365
  if (
366
- bindingPackageVersion !== '1.3.1' &&
366
+ bindingPackageVersion !== '1.4.0' &&
367
367
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
368
368
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
369
369
  ) {
370
370
  throw new Error(
371
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
371
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
372
372
  )
373
373
  }
374
374
  return binding
@@ -387,12 +387,12 @@ function requireNative() {
387
387
  const binding = require('@napi-rs/webcodecs-linux-arm64-musl')
388
388
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-musl/package.json').version
389
389
  if (
390
- bindingPackageVersion !== '1.3.1' &&
390
+ bindingPackageVersion !== '1.4.0' &&
391
391
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
392
392
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
393
393
  ) {
394
394
  throw new Error(
395
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
395
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
396
396
  )
397
397
  }
398
398
  return binding
@@ -409,12 +409,12 @@ function requireNative() {
409
409
  const binding = require('@napi-rs/webcodecs-linux-arm64-gnu')
410
410
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm64-gnu/package.json').version
411
411
  if (
412
- bindingPackageVersion !== '1.3.1' &&
412
+ bindingPackageVersion !== '1.4.0' &&
413
413
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
414
414
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
415
415
  ) {
416
416
  throw new Error(
417
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
417
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
418
418
  )
419
419
  }
420
420
  return binding
@@ -433,12 +433,12 @@ function requireNative() {
433
433
  const binding = require('@napi-rs/webcodecs-linux-arm-musleabihf')
434
434
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-musleabihf/package.json').version
435
435
  if (
436
- bindingPackageVersion !== '1.3.1' &&
436
+ bindingPackageVersion !== '1.4.0' &&
437
437
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
438
438
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
439
439
  ) {
440
440
  throw new Error(
441
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
441
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
442
442
  )
443
443
  }
444
444
  return binding
@@ -455,12 +455,12 @@ function requireNative() {
455
455
  const binding = require('@napi-rs/webcodecs-linux-arm-gnueabihf')
456
456
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-arm-gnueabihf/package.json').version
457
457
  if (
458
- bindingPackageVersion !== '1.3.1' &&
458
+ bindingPackageVersion !== '1.4.0' &&
459
459
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
460
460
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
461
461
  ) {
462
462
  throw new Error(
463
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
463
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
464
464
  )
465
465
  }
466
466
  return binding
@@ -479,12 +479,12 @@ function requireNative() {
479
479
  const binding = require('@napi-rs/webcodecs-linux-loong64-musl')
480
480
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-musl/package.json').version
481
481
  if (
482
- bindingPackageVersion !== '1.3.1' &&
482
+ bindingPackageVersion !== '1.4.0' &&
483
483
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
484
484
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
485
485
  ) {
486
486
  throw new Error(
487
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
487
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
488
488
  )
489
489
  }
490
490
  return binding
@@ -501,12 +501,12 @@ function requireNative() {
501
501
  const binding = require('@napi-rs/webcodecs-linux-loong64-gnu')
502
502
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-loong64-gnu/package.json').version
503
503
  if (
504
- bindingPackageVersion !== '1.3.1' &&
504
+ bindingPackageVersion !== '1.4.0' &&
505
505
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
506
506
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
507
507
  ) {
508
508
  throw new Error(
509
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
509
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
510
510
  )
511
511
  }
512
512
  return binding
@@ -525,12 +525,12 @@ function requireNative() {
525
525
  const binding = require('@napi-rs/webcodecs-linux-riscv64-musl')
526
526
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-musl/package.json').version
527
527
  if (
528
- bindingPackageVersion !== '1.3.1' &&
528
+ bindingPackageVersion !== '1.4.0' &&
529
529
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
530
530
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
531
531
  ) {
532
532
  throw new Error(
533
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
533
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
534
534
  )
535
535
  }
536
536
  return binding
@@ -547,12 +547,12 @@ function requireNative() {
547
547
  const binding = require('@napi-rs/webcodecs-linux-riscv64-gnu')
548
548
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-riscv64-gnu/package.json').version
549
549
  if (
550
- bindingPackageVersion !== '1.3.1' &&
550
+ bindingPackageVersion !== '1.4.0' &&
551
551
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
552
552
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
553
553
  ) {
554
554
  throw new Error(
555
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
555
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
556
556
  )
557
557
  }
558
558
  return binding
@@ -570,12 +570,12 @@ function requireNative() {
570
570
  const binding = require('@napi-rs/webcodecs-linux-ppc64-gnu')
571
571
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-ppc64-gnu/package.json').version
572
572
  if (
573
- bindingPackageVersion !== '1.3.1' &&
573
+ bindingPackageVersion !== '1.4.0' &&
574
574
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
575
575
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
576
576
  ) {
577
577
  throw new Error(
578
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
578
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
579
579
  )
580
580
  }
581
581
  return binding
@@ -592,12 +592,12 @@ function requireNative() {
592
592
  const binding = require('@napi-rs/webcodecs-linux-s390x-gnu')
593
593
  const bindingPackageVersion = require('@napi-rs/webcodecs-linux-s390x-gnu/package.json').version
594
594
  if (
595
- bindingPackageVersion !== '1.3.1' &&
595
+ bindingPackageVersion !== '1.4.0' &&
596
596
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
597
597
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
598
598
  ) {
599
599
  throw new Error(
600
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
600
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
601
601
  )
602
602
  }
603
603
  return binding
@@ -618,12 +618,12 @@ function requireNative() {
618
618
  const binding = require('@napi-rs/webcodecs-openharmony-arm64')
619
619
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm64/package.json').version
620
620
  if (
621
- bindingPackageVersion !== '1.3.1' &&
621
+ bindingPackageVersion !== '1.4.0' &&
622
622
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
623
623
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
624
624
  ) {
625
625
  throw new Error(
626
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
626
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
627
627
  )
628
628
  }
629
629
  return binding
@@ -640,12 +640,12 @@ function requireNative() {
640
640
  const binding = require('@napi-rs/webcodecs-openharmony-x64')
641
641
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-x64/package.json').version
642
642
  if (
643
- bindingPackageVersion !== '1.3.1' &&
643
+ bindingPackageVersion !== '1.4.0' &&
644
644
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
645
645
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
646
646
  ) {
647
647
  throw new Error(
648
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
648
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
649
649
  )
650
650
  }
651
651
  return binding
@@ -662,12 +662,12 @@ function requireNative() {
662
662
  const binding = require('@napi-rs/webcodecs-openharmony-arm')
663
663
  const bindingPackageVersion = require('@napi-rs/webcodecs-openharmony-arm/package.json').version
664
664
  if (
665
- bindingPackageVersion !== '1.3.1' &&
665
+ bindingPackageVersion !== '1.4.0' &&
666
666
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK &&
667
667
  process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0'
668
668
  ) {
669
669
  throw new Error(
670
- `Native binding package version mismatch, expected 1.3.1 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
670
+ `Native binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
671
671
  )
672
672
  }
673
673
  return binding
@@ -682,54 +682,165 @@ function requireNative() {
682
682
  }
683
683
  }
684
684
 
685
- nativeBinding = requireNative()
685
+ function createLoadErrorChain(errors) {
686
+ return errors.reduce((previous, current) => {
687
+ let message
688
+ try {
689
+ message = current && typeof current.message === 'string' ? current.message : String(current)
690
+ } catch {
691
+ message = 'Unknown error'
692
+ }
693
+ const error = new Error(message)
694
+ error.cause = previous
695
+ return error
696
+ }, null)
697
+ }
698
+
699
+ // NAPI_RS_FORCE_WASI is a tri-state flag:
700
+ // unset / any other value → native binding preferred, WASI is only a fallback
701
+ // 'true' → prefer WASI, but retain native as a lazy fallback
702
+ // 'error' → require WASI without initializing a native fallback
703
+ // Treating any non-empty string as truthy (the historical behavior) meant
704
+ // NAPI_RS_FORCE_WASI=false, NAPI_RS_FORCE_WASI=0, etc. inadvertently triggered
705
+ // the WASI path, causing ENOENT for packages shipped without a .wasi.cjs file.
706
+ //
707
+ // NAPI_RS_WASI_FLAVOR selects one exact generated flavor and implies strict
708
+ // WASI loading. It never crosses into another flavor or falls back to native.
709
+ const __napiWasiFlavors = ['wasm32-wasi']
710
+ const __napiWasiFlavor = process.env.NAPI_RS_WASI_FLAVOR
711
+ const __napiWasiFlavorRequested = typeof __napiWasiFlavor === 'string' && __napiWasiFlavor.length > 0
712
+ if (__napiWasiFlavorRequested && __napiWasiFlavors.indexOf(__napiWasiFlavor) === -1) {
713
+ throw new Error(
714
+ 'Unsupported WASI flavor "' + __napiWasiFlavor + '". Available flavors: ' + __napiWasiFlavors.join(', '),
715
+ )
716
+ }
717
+ const forceWasiError = process.env.NAPI_RS_FORCE_WASI === 'error'
718
+ const forceWasi = process.env.NAPI_RS_FORCE_WASI === 'true' || forceWasiError || __napiWasiFlavorRequested
686
719
 
687
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
720
+ if (!forceWasi) {
721
+ nativeBinding = requireNative()
722
+ }
723
+
724
+ if (!nativeBinding || forceWasi) {
688
725
  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
726
+ let wasiBindingLoaded = false
727
+ const wasiBindingErrors = []
728
+ const __napiWasiResolveCandidate = (specifier, isPackage, localArtifacts) => {
729
+ try {
730
+ require.resolve(specifier)
731
+ } catch (resolveError) {
732
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
733
+ throw resolveError
734
+ }
735
+ if (isPackage) {
736
+ try {
737
+ require.resolve(specifier + '/package.json')
738
+ } catch (packageError) {
739
+ if (packageError && packageError.code === 'MODULE_NOT_FOUND') {
740
+ return resolveError
741
+ }
742
+ // An exports restriction proves the package exists even when its
743
+ // package.json is not public. Preserve the root resolution failure.
744
+ throw resolveError
745
+ }
746
+ // The package exists but its main/export target is broken.
747
+ throw resolveError
748
+ }
749
+ return resolveError
696
750
  }
751
+ if (localArtifacts) {
752
+ let artifactError = null
753
+ for (let i = 0; i < localArtifacts.length; i++) {
754
+ try {
755
+ require.resolve(localArtifacts[i])
756
+ return null
757
+ } catch (resolveError) {
758
+ if (!resolveError || resolveError.code !== 'MODULE_NOT_FOUND') {
759
+ throw resolveError
760
+ }
761
+ artifactError = resolveError
762
+ }
763
+ }
764
+ return artifactError
765
+ }
766
+ return null
697
767
  }
698
- if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
768
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
769
+ let candidateError = null
770
+ let candidateFailed = false
699
771
  try {
700
- wasiBinding = require('@napi-rs/webcodecs-wasm32-wasi')
701
- nativeBinding = wasiBinding
772
+ candidateError = __napiWasiResolveCandidate('./webcodecs.wasi.cjs', false, [
773
+ './webcodecs.wasm32-wasi.debug.wasm',
774
+ './webcodecs.wasm32-wasi.wasm',
775
+ ])
776
+ candidateFailed = candidateError !== null
777
+ if (!candidateFailed) {
778
+ wasiBinding = require('./webcodecs.wasi.cjs')
779
+ nativeBinding = wasiBinding
780
+ wasiBindingLoaded = true
781
+ }
702
782
  } catch (err) {
703
- if (process.env.NAPI_RS_FORCE_WASI) {
704
- if (!wasiBindingError) {
705
- wasiBindingError = err
706
- } else {
707
- wasiBindingError.cause = err
783
+ candidateError = err
784
+ candidateFailed = true
785
+ }
786
+ if (candidateFailed) {
787
+ wasiBindingErrors.push(candidateError)
788
+ loadErrors.push(candidateError)
789
+ }
790
+ }
791
+ if (!wasiBindingLoaded && (!__napiWasiFlavorRequested || __napiWasiFlavor === 'wasm32-wasi')) {
792
+ let candidateError = null
793
+ let candidateFailed = false
794
+ try {
795
+ candidateError = __napiWasiResolveCandidate('@napi-rs/webcodecs-wasm32-wasi', true, undefined)
796
+ candidateFailed = candidateError !== null
797
+ if (!candidateFailed) {
798
+ if (process.env.NAPI_RS_ENFORCE_VERSION_CHECK && process.env.NAPI_RS_ENFORCE_VERSION_CHECK !== '0') {
799
+ const bindingPackageVersion = require('@napi-rs/webcodecs-wasm32-wasi/package.json').version
800
+ if (bindingPackageVersion !== '1.4.0') {
801
+ throw new Error(
802
+ `WASI binding package version mismatch, expected 1.4.0 but got ${bindingPackageVersion}. You can reinstall dependencies to fix this issue.`,
803
+ )
804
+ }
708
805
  }
709
- loadErrors.push(err)
806
+ wasiBinding = require('@napi-rs/webcodecs-wasm32-wasi')
807
+ nativeBinding = wasiBinding
808
+ wasiBindingLoaded = true
710
809
  }
810
+ } catch (err) {
811
+ candidateError = err
812
+ candidateFailed = true
711
813
  }
814
+ if (candidateFailed) {
815
+ wasiBindingErrors.push(candidateError)
816
+ loadErrors.push(candidateError)
817
+ }
818
+ }
819
+ if (!wasiBindingLoaded && forceWasi && !forceWasiError && !__napiWasiFlavorRequested) {
820
+ nativeBinding = requireNative()
712
821
  }
713
- if (process.env.NAPI_RS_FORCE_WASI === 'error' && !wasiBinding) {
714
- const error = new Error('WASI binding not found and NAPI_RS_FORCE_WASI is set to error')
715
- error.cause = wasiBindingError
822
+ if ((forceWasiError || __napiWasiFlavorRequested) && !wasiBindingLoaded) {
823
+ const error = new Error(
824
+ __napiWasiFlavorRequested
825
+ ? 'WASI binding for flavor "' + __napiWasiFlavor + '" not found'
826
+ : 'WASI binding not found and NAPI_RS_FORCE_WASI is set to error',
827
+ )
828
+ error.cause = createLoadErrorChain(wasiBindingErrors)
716
829
  throw error
717
830
  }
718
831
  }
719
832
 
720
833
  if (!nativeBinding) {
721
834
  if (loadErrors.length > 0) {
722
- throw new Error(
835
+ const error = new Error(
723
836
  `Cannot find native binding. ` +
724
837
  `npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). ` +
725
838
  'Please try `npm i` again after removing both package-lock.json and node_modules directory.',
726
- {
727
- cause: loadErrors.reduce((err, cur) => {
728
- cur.cause = err
729
- return cur
730
- }),
731
- },
732
839
  )
840
+ // assign instead of the `new Error(message, { cause })` options form,
841
+ // which Node < 16.9 silently ignores
842
+ error.cause = createLoadErrorChain(loadErrors)
843
+ throw error
733
844
  }
734
845
  throw new Error(`Failed to load native binding`)
735
846
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@napi-rs/webcodecs",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "WebCodecs API implementation for Node.js using FFmpeg",
5
5
  "keywords": [
6
6
  "N-API",
@@ -32,7 +32,6 @@
32
32
  "require": "./polyfill.js"
33
33
  }
34
34
  },
35
- "browser": "browser.js",
36
35
  "types": "index.d.ts",
37
36
  "files": [
38
37
  "index.d.ts",
@@ -53,7 +52,7 @@
53
52
  "prepublishOnly": "napi prepublish -t npm",
54
53
  "test": "ava",
55
54
  "demo": "cd example && vite",
56
- "typecheck": "tsc -b tsconfig.json && tsc ./index.d.ts",
55
+ "typecheck": "tsc -b tsconfig.json && tsc --ignoreConfig ./index.d.ts",
57
56
  "preversion": "oxnode ./build.ts --platform && git add .",
58
57
  "version": "napi version"
59
58
  },
@@ -63,31 +62,31 @@
63
62
  ]
64
63
  },
65
64
  "devDependencies": {
66
- "@emnapi/core": "^1.8.1",
67
- "@emnapi/runtime": "^1.8.1",
68
- "@napi-rs/canvas": "^0.1.88",
69
- "@napi-rs/cli": "^3.5.1",
70
- "@napi-rs/wasm-runtime": "^1.1.1",
71
- "@oxc-node/cli": "^0.0.35",
72
- "@oxc-node/core": "^0.0.35",
65
+ "@emnapi/core": "^1.11.3",
66
+ "@emnapi/runtime": "^1.11.3",
67
+ "@napi-rs/canvas": "^1.0.5",
68
+ "@napi-rs/cli": "^3.8.4",
69
+ "@napi-rs/wasm-runtime": "^1.2.2",
70
+ "@oxc-node/cli": "^0.1.0",
71
+ "@oxc-node/core": "^0.1.0",
73
72
  "@taplo/cli": "^0.7.0",
74
- "@tybys/wasm-util": "^0.10.1",
75
- "@types/node": "^25.0.10",
76
- "ava": "^6.4.1",
77
- "chalk": "^5.6.2",
78
- "emnapi": "^1.8.1",
73
+ "@tybys/wasm-util": "^0.10.3",
74
+ "@types/node": "^26.2.0",
75
+ "ava": "^8.0.1",
76
+ "chalk": "^6.0.0",
77
+ "emnapi": "^1.11.3",
79
78
  "husky": "^9.1.7",
80
- "lint-staged": "^16.2.7",
81
- "mediabunny": "1.30.1",
82
- "npm-run-all2": "^8.0.4",
83
- "oxfmt": "^0.26.0",
84
- "oxlint": "^1.41.0",
85
- "oxlint-tsgolint": "^0.11.1",
86
- "prettier": "^3.8.1",
87
- "tinybench": "^6.0.0",
88
- "typescript": "^5.9.3",
79
+ "lint-staged": "^17.3.0",
80
+ "mediabunny": "1.53.0",
81
+ "npm-run-all2": "^9.0.3",
82
+ "oxfmt": "^0.62.0",
83
+ "oxlint": "^1.77.0",
84
+ "oxlint-tsgolint": "^7.0.2001",
85
+ "prettier": "^3.9.6",
86
+ "tinybench": "^6.1.2",
87
+ "typescript": "^7.0.2",
89
88
  "webcodecs-polyfill": "^1.0.1",
90
- "vite-plugin-mkcert": "^1.17.9"
89
+ "vite-plugin-mkcert": "^2.1.0"
91
90
  },
92
91
  "peerDependencies": {
93
92
  "@napi-rs/canvas": ">=0.1.0"
@@ -113,14 +112,14 @@
113
112
  "armv7-unknown-linux-gnueabihf"
114
113
  ]
115
114
  },
116
- "packageManager": "pnpm@10.28.1",
115
+ "packageManager": "pnpm@11.21.0",
117
116
  "ava": {
118
117
  "environmentVariables": {
119
118
  "TS_NODE_PROJECT": "./tsconfig.json"
120
119
  },
121
- "extensions": {
122
- "ts": "module"
123
- },
120
+ "extensions": [
121
+ "ts"
122
+ ],
124
123
  "files": [
125
124
  "__test__/**/*.spec.ts"
126
125
  ],
@@ -132,34 +131,21 @@
132
131
  "workerThreads": false
133
132
  },
134
133
  "engines": {
135
- "node": ">= 10"
134
+ "node": "^22.20 || ^24.12 || >=25"
136
135
  },
137
136
  "publishConfig": {
138
137
  "access": "public",
139
138
  "registry": "https://registry.npmjs.org/"
140
139
  },
141
- "pnpm": {
142
- "onlyBuiltDependencies": [
143
- "node-av",
144
- "@seydx/node-av-darwin-arm64",
145
- "@seydx/node-av-darwin-x64",
146
- "@seydx/node-av-linux-arm64",
147
- "@seydx/node-av-linux-x64",
148
- "@seydx/node-av-win32-arm64-mingw",
149
- "@seydx/node-av-win32-arm64-msvc",
150
- "@seydx/node-av-win32-x64-mingw",
151
- "@seydx/node-av-win32-x64-msvc"
152
- ]
153
- },
154
140
  "optionalDependencies": {
155
- "@napi-rs/webcodecs-darwin-x64": "1.3.1",
156
- "@napi-rs/webcodecs-darwin-arm64": "1.3.1",
157
- "@napi-rs/webcodecs-linux-x64-gnu": "1.3.1",
158
- "@napi-rs/webcodecs-linux-x64-musl": "1.3.1",
159
- "@napi-rs/webcodecs-win32-x64-msvc": "1.3.1",
160
- "@napi-rs/webcodecs-linux-arm64-gnu": "1.3.1",
161
- "@napi-rs/webcodecs-linux-arm64-musl": "1.3.1",
162
- "@napi-rs/webcodecs-win32-arm64-msvc": "1.3.1",
163
- "@napi-rs/webcodecs-linux-arm-gnueabihf": "1.3.1"
141
+ "@napi-rs/webcodecs-darwin-x64": "1.4.0",
142
+ "@napi-rs/webcodecs-darwin-arm64": "1.4.0",
143
+ "@napi-rs/webcodecs-linux-x64-gnu": "1.4.0",
144
+ "@napi-rs/webcodecs-linux-x64-musl": "1.4.0",
145
+ "@napi-rs/webcodecs-win32-x64-msvc": "1.4.0",
146
+ "@napi-rs/webcodecs-linux-arm64-gnu": "1.4.0",
147
+ "@napi-rs/webcodecs-linux-arm64-musl": "1.4.0",
148
+ "@napi-rs/webcodecs-win32-arm64-msvc": "1.4.0",
149
+ "@napi-rs/webcodecs-linux-arm-gnueabihf": "1.4.0"
164
150
  }
165
151
  }