From 3cb6ed82ce400963ad46efafcb0d6e63fa17914c Mon Sep 17 00:00:00 2001 From: Vanilagy <1696106+Vanilagy@users.noreply.github.com> Date: Wed, 12 Nov 2025 13:11:18 +0100 Subject: [PATCH] Fix globals not being treeshakable by some bundlers (fixes #172) --- src/encode.ts | 10 +++++----- src/flac/flac-muxer.ts | 2 +- src/input-format.ts | 18 +++++++++--------- src/isobmff/isobmff-boxes.ts | 6 +++--- src/matroska/ebml.ts | 2 +- src/matroska/matroska-demuxer.ts | 2 +- src/matroska/matroska-muxer.ts | 4 ++-- src/misc.ts | 12 ++++++------ src/ogg/ogg-reader.ts | 2 +- src/packet.ts | 2 +- src/source.ts | 2 +- src/writer.ts | 6 +++--- 12 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/encode.ts b/src/encode.ts index bf7834b..81b3167 100644 --- a/src/encode.ts +++ b/src/encode.ts @@ -403,31 +403,31 @@ export class Quality { * @group Encoding * @public */ -export const QUALITY_VERY_LOW = new Quality(0.3); +export const QUALITY_VERY_LOW = /* #__PURE__ */ new Quality(0.3); /** * Represents a low media quality. * @group Encoding * @public */ -export const QUALITY_LOW = new Quality(0.6); +export const QUALITY_LOW = /* #__PURE__ */ new Quality(0.6); /** * Represents a medium media quality. * @group Encoding * @public */ -export const QUALITY_MEDIUM = new Quality(1); +export const QUALITY_MEDIUM = /* #__PURE__ */ new Quality(1); /** * Represents a high media quality. * @group Encoding * @public */ -export const QUALITY_HIGH = new Quality(2); +export const QUALITY_HIGH = /* #__PURE__ */ new Quality(2); /** * Represents a very high media quality. * @group Encoding * @public */ -export const QUALITY_VERY_HIGH = new Quality(4); +export const QUALITY_VERY_HIGH = /* #__PURE__ */ new Quality(4); /** * Checks if the browser is able to encode the given codec. diff --git a/src/flac/flac-muxer.ts b/src/flac/flac-muxer.ts index fdda1d0..782234a 100644 --- a/src/flac/flac-muxer.ts +++ b/src/flac/flac-muxer.ts @@ -28,7 +28,7 @@ import { readCodedNumber, } from './flac-misc'; -const FLAC_HEADER = new Uint8Array([0x66, 0x4c, 0x61, 0x43]); // 'fLaC' +const FLAC_HEADER = /* #__PURE__ */ new Uint8Array([0x66, 0x4c, 0x61, 0x43]); // 'fLaC' const STREAMINFO_SIZE = 38; const STREAMINFO_BLOCK_SIZE = 34; diff --git a/src/input-format.ts b/src/input-format.ts index ed57825..1748f27 100644 --- a/src/input-format.ts +++ b/src/input-format.ts @@ -481,56 +481,56 @@ export class AdtsInputFormat extends InputFormat { * @group Input formats * @public */ -export const MP4 = new Mp4InputFormat(); +export const MP4 = /* #__PURE__ */ new Mp4InputFormat(); /** * QuickTime File Format input format singleton. * @group Input formats * @public */ -export const QTFF = new QuickTimeInputFormat(); +export const QTFF = /* #__PURE__ */ new QuickTimeInputFormat(); /** * Matroska input format singleton. * @group Input formats * @public */ -export const MATROSKA = new MatroskaInputFormat(); +export const MATROSKA = /* #__PURE__ */ new MatroskaInputFormat(); /** * WebM input format singleton. * @group Input formats * @public */ -export const WEBM = new WebMInputFormat(); +export const WEBM = /* #__PURE__ */ new WebMInputFormat(); /** * MP3 input format singleton. * @group Input formats * @public */ -export const MP3 = new Mp3InputFormat(); +export const MP3 = /* #__PURE__ */ new Mp3InputFormat(); /** * WAVE input format singleton. * @group Input formats * @public */ -export const WAVE = new WaveInputFormat(); +export const WAVE = /* #__PURE__ */ new WaveInputFormat(); /** * Ogg input format singleton. * @group Input formats * @public */ -export const OGG = new OggInputFormat(); +export const OGG = /* #__PURE__ */ new OggInputFormat(); /** * ADTS input format singleton. * @group Input formats * @public */ -export const ADTS = new AdtsInputFormat(); +export const ADTS = /* #__PURE__ */ new AdtsInputFormat(); /** * FLAC input format singleton. * @group Input formats * @public */ -export const FLAC = new FlacInputFormat(); +export const FLAC = /* #__PURE__ */ new FlacInputFormat(); /** * List of all input format singletons. If you don't need to support all input formats, you should specify the diff --git a/src/isobmff/isobmff-boxes.ts b/src/isobmff/isobmff-boxes.ts index d7a5a38..f2fccc4 100644 --- a/src/isobmff/isobmff-boxes.ts +++ b/src/isobmff/isobmff-boxes.ts @@ -135,8 +135,8 @@ export class IsobmffBoxWriter { } } -const bytes = new Uint8Array(8); -const view = new DataView(bytes.buffer); +const bytes = /* #__PURE__ */ new Uint8Array(8); +const view = /* #__PURE__ */ new DataView(bytes.buffer); const u8 = (value: number) => { return [(value % 0x100 + 0x100) % 0x100]; @@ -243,7 +243,7 @@ const rotationMatrix = (rotationInDegrees: number): TransformationMatrix => { 0, 0, 1, ]; }; -const IDENTITY_MATRIX = rotationMatrix(0); +const IDENTITY_MATRIX = /* #__PURE__ */ rotationMatrix(0); const matrixToBytes = (matrix: TransformationMatrix) => { return [ diff --git a/src/matroska/ebml.ts b/src/matroska/ebml.ts index 4fc70bd..5097b77 100644 --- a/src/matroska/ebml.ts +++ b/src/matroska/ebml.ts @@ -463,7 +463,7 @@ export class EBMLWriter { export const MAX_VAR_INT_SIZE = 8; export const MIN_HEADER_SIZE = 2; // 1-byte ID and 1-byte size -export const MAX_HEADER_SIZE = 2 * MAX_VAR_INT_SIZE; // 8-byte ID and 8-byte size +export const MAX_HEADER_SIZE = /* #__PURE__ */ 2 * MAX_VAR_INT_SIZE; // 8-byte ID and 8-byte size export const readVarIntSize = (slice: FileSlice) => { const firstByte = readU8(slice); diff --git a/src/matroska/matroska-demuxer.ts b/src/matroska/matroska-demuxer.ts index e4e6c11..32880d5 100644 --- a/src/matroska/matroska-demuxer.ts +++ b/src/matroska/matroska-demuxer.ts @@ -228,7 +228,7 @@ const METADATA_ELEMENTS = [ { id: EBMLId.Tracks, flag: 'tracksSeen' }, { id: EBMLId.Cues, flag: 'cuesSeen' }, ] as const; -const MAX_RESYNC_LENGTH = 10 * 2 ** 20; // 10 MiB +const MAX_RESYNC_LENGTH = /* #__PURE__ */ 10 * 2 ** 20; // 10 MiB export class MatroskaDemuxer extends Demuxer { reader: Reader; diff --git a/src/matroska/matroska-muxer.ts b/src/matroska/matroska-muxer.ts index b12b95a..deff3e0 100644 --- a/src/matroska/matroska-muxer.ts +++ b/src/matroska/matroska-muxer.ts @@ -65,8 +65,8 @@ import { EncodedPacket } from '../packet'; import { parseOpusIdentificationHeader } from '../codec-data'; import { AttachedFile } from '../tags'; -const MIN_CLUSTER_TIMESTAMP_MS = -(2 ** 15); -const MAX_CLUSTER_TIMESTAMP_MS = 2 ** 15 - 1; +const MIN_CLUSTER_TIMESTAMP_MS = /* #__PURE__ */ -(2 ** 15); +const MAX_CLUSTER_TIMESTAMP_MS = /* #__PURE__ */ 2 ** 15 - 1; const APP_NAME = 'Mediabunny'; const SEGMENT_SIZE_BYTES = 6; const CLUSTER_SIZE_BYTES = 5; diff --git a/src/misc.ts b/src/misc.ts index c6f5119..fa682cd 100644 --- a/src/misc.ts +++ b/src/misc.ts @@ -174,8 +174,8 @@ export const toDataView = (source: AllowSharedBufferSource) => { } }; -export const textDecoder = new TextDecoder(); -export const textEncoder = new TextEncoder(); +export const textDecoder = /* #__PURE__ */ new TextDecoder(); +export const textEncoder = /* #__PURE__ */ new TextEncoder(); export const isIso88591Compatible = (text: string) => { for (let i = 0; i < text.length; i++) { @@ -201,7 +201,7 @@ export const COLOR_PRIMARIES_MAP = { bt2020: 9, // ITU-R BT.202 smpte432: 12, // SMPTE EG 432-1 }; -export const COLOR_PRIMARIES_MAP_INVERSE = invertObject(COLOR_PRIMARIES_MAP); +export const COLOR_PRIMARIES_MAP_INVERSE = /* #__PURE__ */ invertObject(COLOR_PRIMARIES_MAP); export const TRANSFER_CHARACTERISTICS_MAP = { 'bt709': 1, // ITU-R BT.709 @@ -211,7 +211,7 @@ export const TRANSFER_CHARACTERISTICS_MAP = { 'pq': 16, // Rec. ITU-R BT.2100-2 perceptual quantization (PQ) system 'hlg': 18, // Rec. ITU-R BT.2100-2 hybrid loggamma (HLG) system }; -export const TRANSFER_CHARACTERISTICS_MAP_INVERSE = invertObject(TRANSFER_CHARACTERISTICS_MAP); +export const TRANSFER_CHARACTERISTICS_MAP_INVERSE = /* #__PURE__ */ invertObject(TRANSFER_CHARACTERISTICS_MAP); export const MATRIX_COEFFICIENTS_MAP = { 'rgb': 0, // Identity @@ -220,7 +220,7 @@ export const MATRIX_COEFFICIENTS_MAP = { 'smpte170m': 6, // SMPTE 170M 'bt2020-ncl': 9, // ITU-R BT.2020-2 (non-constant luminance) }; -export const MATRIX_COEFFICIENTS_MAP_INVERSE = invertObject(MATRIX_COEFFICIENTS_MAP); +export const MATRIX_COEFFICIENTS_MAP_INVERSE = /* #__PURE__ */ invertObject(MATRIX_COEFFICIENTS_MAP); export type RequiredNonNull = { [K in keyof T]-?: NonNullable; @@ -510,7 +510,7 @@ export const isIso639Dash2LanguageCode = (x: string) => { }; // Since the result will be truncated, add a bit of eps to compensate for floating point errors -export const SECOND_TO_MICROSECOND_FACTOR = 1e6 * (1 + Number.EPSILON); +export const SECOND_TO_MICROSECOND_FACTOR = /* #__PURE__ */ 1e6 * (1 + Number.EPSILON); /** * Sets all keys K of T to be required. diff --git a/src/ogg/ogg-reader.ts b/src/ogg/ogg-reader.ts index 011b126..13963cf 100644 --- a/src/ogg/ogg-reader.ts +++ b/src/ogg/ogg-reader.ts @@ -11,7 +11,7 @@ import { OGGS } from './ogg-misc'; export const MIN_PAGE_HEADER_SIZE = 27; export const MAX_PAGE_HEADER_SIZE = 27 + 255; -export const MAX_PAGE_SIZE = MAX_PAGE_HEADER_SIZE + 255 * 255; +export const MAX_PAGE_SIZE = /* #__PURE__ */ MAX_PAGE_HEADER_SIZE + 255 * 255; export type Page = { headerStartPos: number; diff --git a/src/packet.ts b/src/packet.ts index f5de60e..4f9b749 100644 --- a/src/packet.ts +++ b/src/packet.ts @@ -8,7 +8,7 @@ import { SECOND_TO_MICROSECOND_FACTOR } from './misc'; -export const PLACEHOLDER_DATA = new Uint8Array(0); +export const PLACEHOLDER_DATA = /* #__PURE__ */ new Uint8Array(0); /** * The type of a packet. Key packets can be decoded without previous packets, while delta packets depend on previous diff --git a/src/source.ts b/src/source.ts index 68ebac1..212ee6b 100644 --- a/src/source.ts +++ b/src/source.ts @@ -269,7 +269,7 @@ export class BlobSource extends Source { } } -const URL_SOURCE_MIN_LOAD_AMOUNT = 0.5 * 2 ** 20; // 0.5 MiB +const URL_SOURCE_MIN_LOAD_AMOUNT = /* #__PURE__ */ 0.5 * 2 ** 20; // 0.5 MiB const DEFAULT_RETRY_DELAY = ((previousAttempts, error, src) => { // Check if this could be a CORS error. If so, we cannot recover from it and diff --git a/src/writer.ts b/src/writer.ts index 30de003..3846dcd 100644 --- a/src/writer.ts +++ b/src/writer.ts @@ -89,8 +89,8 @@ export abstract class Writer { } } -const ARRAY_BUFFER_INITIAL_SIZE = 2 ** 16; -const ARRAY_BUFFER_MAX_SIZE = 2 ** 32; +const ARRAY_BUFFER_INITIAL_SIZE = /* #__PURE__ */ 2 ** 16; +const ARRAY_BUFFER_MAX_SIZE = /* #__PURE__ */ 2 ** 32; export class BufferTargetWriter extends Writer { private pos = 0; @@ -184,7 +184,7 @@ export class BufferTargetWriter extends Writer { } } -const DEFAULT_CHUNK_SIZE = 2 ** 24; +const DEFAULT_CHUNK_SIZE = /* #__PURE__ */ 2 ** 24; const MAX_CHUNKS_AT_ONCE = 2; interface Chunk {