omni-compress 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +403 -0
- package/dist/childProcess-MS3KZ27Y.cjs +2 -0
- package/dist/childProcess-YP2BUBY7.js +2 -0
- package/dist/chunk-4VVOIQUC.cjs +1 -0
- package/dist/chunk-MGMH7JY3.cjs +1 -0
- package/dist/chunk-OXXIGMTX.js +1 -0
- package/dist/chunk-SHYTLD6H.js +1 -0
- package/dist/compat/compressor.cjs +1 -0
- package/dist/compat/compressor.d.cts +1 -0
- package/dist/compat/compressor.d.ts +1 -0
- package/dist/compat/compressor.js +1 -0
- package/dist/compressor-BVD2z3r0.d.cts +232 -0
- package/dist/compressor-BVD2z3r0.d.ts +232 -0
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +250 -0
- package/dist/index.d.ts +250 -0
- package/dist/index.js +1 -0
- package/dist/mainThread-2WMDRJ4L.js +1 -0
- package/dist/mainThread-UJUELO56.cjs +1 -0
- package/dist/workers/audio.worker.cjs +1 -0
- package/dist/workers/audio.worker.d.cts +2 -0
- package/dist/workers/audio.worker.d.ts +2 -0
- package/dist/workers/audio.worker.js +1 -0
- package/dist/workers/image.worker.cjs +4 -0
- package/dist/workers/image.worker.d.cts +2 -0
- package/dist/workers/image.worker.d.ts +2 -0
- package/dist/workers/image.worker.js +4 -0
- package/dist/workers/video.worker.cjs +1 -0
- package/dist/workers/video.worker.d.cts +2 -0
- package/dist/workers/video.worker.d.ts +2 -0
- package/dist/workers/video.worker.js +1 -0
- package/package.json +111 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
interface CompressorOptions$1 {
|
|
2
|
+
type: 'image' | 'audio' | 'video';
|
|
3
|
+
format: 'webp' | 'avif' | 'jpeg' | 'png' | 'opus' | 'mp3' | 'flac' | 'wav' | 'auto' | 'mp4' | 'webm' | string;
|
|
4
|
+
maxSizeMB?: number;
|
|
5
|
+
quality?: number;
|
|
6
|
+
onProgress?: (percent: number) => void;
|
|
7
|
+
originalFileName?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Explicitly force Web Worker usage (true) or Main Thread usage (false).
|
|
10
|
+
*/
|
|
11
|
+
useWorker?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* If the compressed file is larger than the original, return the original.
|
|
14
|
+
* Default: false.
|
|
15
|
+
*/
|
|
16
|
+
strict?: boolean;
|
|
17
|
+
maxWidth?: number;
|
|
18
|
+
maxHeight?: number;
|
|
19
|
+
preserveMetadata?: boolean;
|
|
20
|
+
bitrate?: string;
|
|
21
|
+
channels?: 1 | 2;
|
|
22
|
+
sampleRate?: number;
|
|
23
|
+
videoBitrate?: string;
|
|
24
|
+
fps?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The result of a v2.0 compression call.
|
|
28
|
+
* Replaces the raw `Blob` return from v1.x.
|
|
29
|
+
*/
|
|
30
|
+
interface CompressResult {
|
|
31
|
+
/** The compressed output blob, ready to save or upload. */
|
|
32
|
+
blob: Blob;
|
|
33
|
+
/** Size of the input file in bytes. */
|
|
34
|
+
originalSize: number;
|
|
35
|
+
/** Size of the output blob in bytes. */
|
|
36
|
+
compressedSize: number;
|
|
37
|
+
/** compressedSize / originalSize — values below 1.0 indicate actual compression. */
|
|
38
|
+
ratio: number;
|
|
39
|
+
/** The target format that was used (e.g. 'webp', 'opus'). */
|
|
40
|
+
format: string;
|
|
41
|
+
}
|
|
42
|
+
/** Options for compressImage(). */
|
|
43
|
+
interface ImageOptions {
|
|
44
|
+
/** Target output format. Default: 'auto' (converts PNG/JPEG to WebP). */
|
|
45
|
+
format?: 'webp' | 'avif' | 'jpeg' | 'png' | 'auto';
|
|
46
|
+
/** Encoder quality from 0.0 (worst) to 1.0 (best). Default: 0.8. */
|
|
47
|
+
quality?: number;
|
|
48
|
+
/** Resize output width to at most this many pixels (maintains aspect ratio). */
|
|
49
|
+
maxWidth?: number;
|
|
50
|
+
/** Resize output height to at most this many pixels (maintains aspect ratio). */
|
|
51
|
+
maxHeight?: number;
|
|
52
|
+
/** When true, EXIF/metadata is preserved in the output. Default: false (stripped). */
|
|
53
|
+
preserveMetadata?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* If the compressed image is larger than the original, return the original.
|
|
56
|
+
* Default: false.
|
|
57
|
+
*/
|
|
58
|
+
strict?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Explicitly force Web Worker usage (true) or Main Thread usage (false).
|
|
61
|
+
* If omitted, the library chooses based on file size and operation type.
|
|
62
|
+
*/
|
|
63
|
+
useWorker?: boolean;
|
|
64
|
+
/** Called with progress 0–100 during heavy-path (FFmpeg) operations. */
|
|
65
|
+
onProgress?: (percent: number) => void;
|
|
66
|
+
/** Cancel the operation. Throws AbortError when signalled. */
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
}
|
|
69
|
+
/** Options for compressAudio(). */
|
|
70
|
+
interface AudioOptions {
|
|
71
|
+
/** Target output format. Default: 'auto' (converts WAV/FLAC to MP3). */
|
|
72
|
+
format?: 'opus' | 'mp3' | 'flac' | 'wav' | 'aac' | 'auto';
|
|
73
|
+
/** Target bitrate, e.g. '128k', '192k'. Encoder default if omitted. */
|
|
74
|
+
bitrate?: string;
|
|
75
|
+
/** Output channel count. Defaults to input channel count. */
|
|
76
|
+
channels?: 1 | 2;
|
|
77
|
+
/** Output sample rate in Hz. Defaults to input sample rate. */
|
|
78
|
+
sampleRate?: number;
|
|
79
|
+
/** When true, audio tags/metadata is preserved. Default: false (stripped). */
|
|
80
|
+
preserveMetadata?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* If the compressed audio is larger than the original, return the original.
|
|
83
|
+
* Default: false.
|
|
84
|
+
*/
|
|
85
|
+
strict?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Explicitly force Web Worker usage (true) or Main Thread usage (false).
|
|
88
|
+
* If omitted, the library chooses based on file size and operation type.
|
|
89
|
+
*/
|
|
90
|
+
useWorker?: boolean;
|
|
91
|
+
/** Called with progress 0–100 during FFmpeg operations. */
|
|
92
|
+
onProgress?: (percent: number) => void;
|
|
93
|
+
/** Cancel the operation. Throws AbortError when signalled. */
|
|
94
|
+
signal?: AbortSignal;
|
|
95
|
+
}
|
|
96
|
+
/** Options for compressVideo(). */
|
|
97
|
+
interface VideoOptions {
|
|
98
|
+
/** Target output format. Default: 'mp4'. */
|
|
99
|
+
format?: 'mp4' | 'webm';
|
|
100
|
+
/** Target video bitrate, e.g. '1M', '2M'. Default: '1M'. */
|
|
101
|
+
bitrate?: string;
|
|
102
|
+
/** Resize output width to at most this many pixels (maintains aspect ratio). */
|
|
103
|
+
maxWidth?: number;
|
|
104
|
+
/** Resize output height to at most this many pixels (maintains aspect ratio). */
|
|
105
|
+
maxHeight?: number;
|
|
106
|
+
/** Output frames per second. Default: input FPS. */
|
|
107
|
+
fps?: number;
|
|
108
|
+
/** When true, metadata is preserved. Default: false (stripped). */
|
|
109
|
+
preserveMetadata?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* If the compressed video is larger than the original, return the original.
|
|
112
|
+
* Default: false.
|
|
113
|
+
*/
|
|
114
|
+
strict?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Explicitly force Web Worker usage (true) or Main Thread usage (false).
|
|
117
|
+
* If omitted, the library chooses based on file size and operation type.
|
|
118
|
+
*/
|
|
119
|
+
useWorker?: boolean;
|
|
120
|
+
/** Called with progress 0–100 during processing. */
|
|
121
|
+
onProgress?: (percent: number) => void;
|
|
122
|
+
/** Cancel the operation. Throws AbortError when signalled. */
|
|
123
|
+
signal?: AbortSignal;
|
|
124
|
+
}
|
|
125
|
+
/** A single file entry for the archive() / archiveStream() functions. */
|
|
126
|
+
interface ArchiveEntry {
|
|
127
|
+
/** Path/name of the file inside the ZIP (e.g. 'images/photo.webp'). */
|
|
128
|
+
name: string;
|
|
129
|
+
/** File contents. File and Blob are read via .arrayBuffer(). */
|
|
130
|
+
data: File | Blob | Uint8Array;
|
|
131
|
+
}
|
|
132
|
+
/** Options for archive() and archiveStream(). */
|
|
133
|
+
interface ArchiveOptions {
|
|
134
|
+
/** Archive format. Currently only 'zip'. Default: 'zip'. */
|
|
135
|
+
format?: 'zip';
|
|
136
|
+
/**
|
|
137
|
+
* fflate deflate compression level (0 = store, 1 = fastest, 9 = best compression).
|
|
138
|
+
* Default: 6.
|
|
139
|
+
*/
|
|
140
|
+
level?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
141
|
+
/**
|
|
142
|
+
* When true, image and audio files are automatically compressed to optimized
|
|
143
|
+
* formats (WebP/MP3) before being added to the archive.
|
|
144
|
+
* Default: false.
|
|
145
|
+
*/
|
|
146
|
+
smartOptimize?: boolean;
|
|
147
|
+
/** Called with progress 0–100 as entries are processed. */
|
|
148
|
+
onProgress?: (percent: number) => void;
|
|
149
|
+
/** Cancel the operation. Throws AbortError when signalled. */
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
}
|
|
152
|
+
/** Result of archive(). */
|
|
153
|
+
interface ArchiveResult {
|
|
154
|
+
/** The compressed ZIP blob. */
|
|
155
|
+
blob: Blob;
|
|
156
|
+
/** Total uncompressed size of all entries in bytes. */
|
|
157
|
+
originalSize: number;
|
|
158
|
+
/** Size of the ZIP output in bytes. */
|
|
159
|
+
compressedSize: number;
|
|
160
|
+
/** compressedSize / originalSize. */
|
|
161
|
+
ratio: number;
|
|
162
|
+
/** Always 'zip' for now. */
|
|
163
|
+
format: 'zip';
|
|
164
|
+
}
|
|
165
|
+
type Environment = 'browser' | 'node';
|
|
166
|
+
interface RouteContext {
|
|
167
|
+
env: Environment;
|
|
168
|
+
isFastPath: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* If true, the task should be dispatched to a Web Worker.
|
|
171
|
+
* If false, the task can run on the main thread for lower latency (small files).
|
|
172
|
+
*/
|
|
173
|
+
shouldUseWorker: boolean;
|
|
174
|
+
}
|
|
175
|
+
declare class Router {
|
|
176
|
+
static getEnvironment(): Environment;
|
|
177
|
+
static isFastPathSupported(options: CompressorOptions$1): boolean;
|
|
178
|
+
static evaluate(options: CompressorOptions$1, fileSize: number): RouteContext;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
interface CompressorOptions extends Omit<ImageOptions, 'format'> {
|
|
182
|
+
/**
|
|
183
|
+
* Output mime type (e.g., 'image/webp', 'image/jpeg')
|
|
184
|
+
* @default 'image/jpeg'
|
|
185
|
+
*/
|
|
186
|
+
mimeType?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Success callback (called with compressed Blob or File)
|
|
189
|
+
*/
|
|
190
|
+
success?: (result: Blob | File) => void;
|
|
191
|
+
/**
|
|
192
|
+
* Error callback (called with Error object)
|
|
193
|
+
*/
|
|
194
|
+
error?: (err: Error) => void;
|
|
195
|
+
/**
|
|
196
|
+
* If the compressed image is larger than the original, output the original.
|
|
197
|
+
* @default true
|
|
198
|
+
*/
|
|
199
|
+
strict?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Files larger than this (in bytes) will be converted to JPEGs.
|
|
202
|
+
* @default 5,000,000 (5 MB)
|
|
203
|
+
*/
|
|
204
|
+
convertSize?: number;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Compatibility shim for `compressorjs`.
|
|
208
|
+
*
|
|
209
|
+
* Provides an API identical to the `Compressor` class from the `compressorjs` package,
|
|
210
|
+
* but uses `omni-compress` under the hood to support AVIF and faster Web Workers.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* import Compressor from 'omni-compress/compat';
|
|
215
|
+
*
|
|
216
|
+
* new Compressor(file, {
|
|
217
|
+
* quality: 0.6,
|
|
218
|
+
* success(result) {
|
|
219
|
+
* // 'result' is the compressed Blob/File
|
|
220
|
+
* },
|
|
221
|
+
* error(err) {
|
|
222
|
+
* console.error(err.message);
|
|
223
|
+
* },
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
declare class Compressor {
|
|
228
|
+
constructor(file: File | Blob, options?: CompressorOptions);
|
|
229
|
+
private compress;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { type ArchiveEntry as A, type CompressorOptions$1 as C, type Environment as E, type ImageOptions as I, type RouteContext as R, type VideoOptions as V, type ArchiveOptions as a, type ArchiveResult as b, type AudioOptions as c, type CompressResult as d, Compressor as e, Router as f, type CompressorOptions as g };
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
interface CompressorOptions$1 {
|
|
2
|
+
type: 'image' | 'audio' | 'video';
|
|
3
|
+
format: 'webp' | 'avif' | 'jpeg' | 'png' | 'opus' | 'mp3' | 'flac' | 'wav' | 'auto' | 'mp4' | 'webm' | string;
|
|
4
|
+
maxSizeMB?: number;
|
|
5
|
+
quality?: number;
|
|
6
|
+
onProgress?: (percent: number) => void;
|
|
7
|
+
originalFileName?: string;
|
|
8
|
+
/**
|
|
9
|
+
* Explicitly force Web Worker usage (true) or Main Thread usage (false).
|
|
10
|
+
*/
|
|
11
|
+
useWorker?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* If the compressed file is larger than the original, return the original.
|
|
14
|
+
* Default: false.
|
|
15
|
+
*/
|
|
16
|
+
strict?: boolean;
|
|
17
|
+
maxWidth?: number;
|
|
18
|
+
maxHeight?: number;
|
|
19
|
+
preserveMetadata?: boolean;
|
|
20
|
+
bitrate?: string;
|
|
21
|
+
channels?: 1 | 2;
|
|
22
|
+
sampleRate?: number;
|
|
23
|
+
videoBitrate?: string;
|
|
24
|
+
fps?: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The result of a v2.0 compression call.
|
|
28
|
+
* Replaces the raw `Blob` return from v1.x.
|
|
29
|
+
*/
|
|
30
|
+
interface CompressResult {
|
|
31
|
+
/** The compressed output blob, ready to save or upload. */
|
|
32
|
+
blob: Blob;
|
|
33
|
+
/** Size of the input file in bytes. */
|
|
34
|
+
originalSize: number;
|
|
35
|
+
/** Size of the output blob in bytes. */
|
|
36
|
+
compressedSize: number;
|
|
37
|
+
/** compressedSize / originalSize — values below 1.0 indicate actual compression. */
|
|
38
|
+
ratio: number;
|
|
39
|
+
/** The target format that was used (e.g. 'webp', 'opus'). */
|
|
40
|
+
format: string;
|
|
41
|
+
}
|
|
42
|
+
/** Options for compressImage(). */
|
|
43
|
+
interface ImageOptions {
|
|
44
|
+
/** Target output format. Default: 'auto' (converts PNG/JPEG to WebP). */
|
|
45
|
+
format?: 'webp' | 'avif' | 'jpeg' | 'png' | 'auto';
|
|
46
|
+
/** Encoder quality from 0.0 (worst) to 1.0 (best). Default: 0.8. */
|
|
47
|
+
quality?: number;
|
|
48
|
+
/** Resize output width to at most this many pixels (maintains aspect ratio). */
|
|
49
|
+
maxWidth?: number;
|
|
50
|
+
/** Resize output height to at most this many pixels (maintains aspect ratio). */
|
|
51
|
+
maxHeight?: number;
|
|
52
|
+
/** When true, EXIF/metadata is preserved in the output. Default: false (stripped). */
|
|
53
|
+
preserveMetadata?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* If the compressed image is larger than the original, return the original.
|
|
56
|
+
* Default: false.
|
|
57
|
+
*/
|
|
58
|
+
strict?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Explicitly force Web Worker usage (true) or Main Thread usage (false).
|
|
61
|
+
* If omitted, the library chooses based on file size and operation type.
|
|
62
|
+
*/
|
|
63
|
+
useWorker?: boolean;
|
|
64
|
+
/** Called with progress 0–100 during heavy-path (FFmpeg) operations. */
|
|
65
|
+
onProgress?: (percent: number) => void;
|
|
66
|
+
/** Cancel the operation. Throws AbortError when signalled. */
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
}
|
|
69
|
+
/** Options for compressAudio(). */
|
|
70
|
+
interface AudioOptions {
|
|
71
|
+
/** Target output format. Default: 'auto' (converts WAV/FLAC to MP3). */
|
|
72
|
+
format?: 'opus' | 'mp3' | 'flac' | 'wav' | 'aac' | 'auto';
|
|
73
|
+
/** Target bitrate, e.g. '128k', '192k'. Encoder default if omitted. */
|
|
74
|
+
bitrate?: string;
|
|
75
|
+
/** Output channel count. Defaults to input channel count. */
|
|
76
|
+
channels?: 1 | 2;
|
|
77
|
+
/** Output sample rate in Hz. Defaults to input sample rate. */
|
|
78
|
+
sampleRate?: number;
|
|
79
|
+
/** When true, audio tags/metadata is preserved. Default: false (stripped). */
|
|
80
|
+
preserveMetadata?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* If the compressed audio is larger than the original, return the original.
|
|
83
|
+
* Default: false.
|
|
84
|
+
*/
|
|
85
|
+
strict?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Explicitly force Web Worker usage (true) or Main Thread usage (false).
|
|
88
|
+
* If omitted, the library chooses based on file size and operation type.
|
|
89
|
+
*/
|
|
90
|
+
useWorker?: boolean;
|
|
91
|
+
/** Called with progress 0–100 during FFmpeg operations. */
|
|
92
|
+
onProgress?: (percent: number) => void;
|
|
93
|
+
/** Cancel the operation. Throws AbortError when signalled. */
|
|
94
|
+
signal?: AbortSignal;
|
|
95
|
+
}
|
|
96
|
+
/** Options for compressVideo(). */
|
|
97
|
+
interface VideoOptions {
|
|
98
|
+
/** Target output format. Default: 'mp4'. */
|
|
99
|
+
format?: 'mp4' | 'webm';
|
|
100
|
+
/** Target video bitrate, e.g. '1M', '2M'. Default: '1M'. */
|
|
101
|
+
bitrate?: string;
|
|
102
|
+
/** Resize output width to at most this many pixels (maintains aspect ratio). */
|
|
103
|
+
maxWidth?: number;
|
|
104
|
+
/** Resize output height to at most this many pixels (maintains aspect ratio). */
|
|
105
|
+
maxHeight?: number;
|
|
106
|
+
/** Output frames per second. Default: input FPS. */
|
|
107
|
+
fps?: number;
|
|
108
|
+
/** When true, metadata is preserved. Default: false (stripped). */
|
|
109
|
+
preserveMetadata?: boolean;
|
|
110
|
+
/**
|
|
111
|
+
* If the compressed video is larger than the original, return the original.
|
|
112
|
+
* Default: false.
|
|
113
|
+
*/
|
|
114
|
+
strict?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Explicitly force Web Worker usage (true) or Main Thread usage (false).
|
|
117
|
+
* If omitted, the library chooses based on file size and operation type.
|
|
118
|
+
*/
|
|
119
|
+
useWorker?: boolean;
|
|
120
|
+
/** Called with progress 0–100 during processing. */
|
|
121
|
+
onProgress?: (percent: number) => void;
|
|
122
|
+
/** Cancel the operation. Throws AbortError when signalled. */
|
|
123
|
+
signal?: AbortSignal;
|
|
124
|
+
}
|
|
125
|
+
/** A single file entry for the archive() / archiveStream() functions. */
|
|
126
|
+
interface ArchiveEntry {
|
|
127
|
+
/** Path/name of the file inside the ZIP (e.g. 'images/photo.webp'). */
|
|
128
|
+
name: string;
|
|
129
|
+
/** File contents. File and Blob are read via .arrayBuffer(). */
|
|
130
|
+
data: File | Blob | Uint8Array;
|
|
131
|
+
}
|
|
132
|
+
/** Options for archive() and archiveStream(). */
|
|
133
|
+
interface ArchiveOptions {
|
|
134
|
+
/** Archive format. Currently only 'zip'. Default: 'zip'. */
|
|
135
|
+
format?: 'zip';
|
|
136
|
+
/**
|
|
137
|
+
* fflate deflate compression level (0 = store, 1 = fastest, 9 = best compression).
|
|
138
|
+
* Default: 6.
|
|
139
|
+
*/
|
|
140
|
+
level?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
|
|
141
|
+
/**
|
|
142
|
+
* When true, image and audio files are automatically compressed to optimized
|
|
143
|
+
* formats (WebP/MP3) before being added to the archive.
|
|
144
|
+
* Default: false.
|
|
145
|
+
*/
|
|
146
|
+
smartOptimize?: boolean;
|
|
147
|
+
/** Called with progress 0–100 as entries are processed. */
|
|
148
|
+
onProgress?: (percent: number) => void;
|
|
149
|
+
/** Cancel the operation. Throws AbortError when signalled. */
|
|
150
|
+
signal?: AbortSignal;
|
|
151
|
+
}
|
|
152
|
+
/** Result of archive(). */
|
|
153
|
+
interface ArchiveResult {
|
|
154
|
+
/** The compressed ZIP blob. */
|
|
155
|
+
blob: Blob;
|
|
156
|
+
/** Total uncompressed size of all entries in bytes. */
|
|
157
|
+
originalSize: number;
|
|
158
|
+
/** Size of the ZIP output in bytes. */
|
|
159
|
+
compressedSize: number;
|
|
160
|
+
/** compressedSize / originalSize. */
|
|
161
|
+
ratio: number;
|
|
162
|
+
/** Always 'zip' for now. */
|
|
163
|
+
format: 'zip';
|
|
164
|
+
}
|
|
165
|
+
type Environment = 'browser' | 'node';
|
|
166
|
+
interface RouteContext {
|
|
167
|
+
env: Environment;
|
|
168
|
+
isFastPath: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* If true, the task should be dispatched to a Web Worker.
|
|
171
|
+
* If false, the task can run on the main thread for lower latency (small files).
|
|
172
|
+
*/
|
|
173
|
+
shouldUseWorker: boolean;
|
|
174
|
+
}
|
|
175
|
+
declare class Router {
|
|
176
|
+
static getEnvironment(): Environment;
|
|
177
|
+
static isFastPathSupported(options: CompressorOptions$1): boolean;
|
|
178
|
+
static evaluate(options: CompressorOptions$1, fileSize: number): RouteContext;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
interface CompressorOptions extends Omit<ImageOptions, 'format'> {
|
|
182
|
+
/**
|
|
183
|
+
* Output mime type (e.g., 'image/webp', 'image/jpeg')
|
|
184
|
+
* @default 'image/jpeg'
|
|
185
|
+
*/
|
|
186
|
+
mimeType?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Success callback (called with compressed Blob or File)
|
|
189
|
+
*/
|
|
190
|
+
success?: (result: Blob | File) => void;
|
|
191
|
+
/**
|
|
192
|
+
* Error callback (called with Error object)
|
|
193
|
+
*/
|
|
194
|
+
error?: (err: Error) => void;
|
|
195
|
+
/**
|
|
196
|
+
* If the compressed image is larger than the original, output the original.
|
|
197
|
+
* @default true
|
|
198
|
+
*/
|
|
199
|
+
strict?: boolean;
|
|
200
|
+
/**
|
|
201
|
+
* Files larger than this (in bytes) will be converted to JPEGs.
|
|
202
|
+
* @default 5,000,000 (5 MB)
|
|
203
|
+
*/
|
|
204
|
+
convertSize?: number;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Compatibility shim for `compressorjs`.
|
|
208
|
+
*
|
|
209
|
+
* Provides an API identical to the `Compressor` class from the `compressorjs` package,
|
|
210
|
+
* but uses `omni-compress` under the hood to support AVIF and faster Web Workers.
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* ```ts
|
|
214
|
+
* import Compressor from 'omni-compress/compat';
|
|
215
|
+
*
|
|
216
|
+
* new Compressor(file, {
|
|
217
|
+
* quality: 0.6,
|
|
218
|
+
* success(result) {
|
|
219
|
+
* // 'result' is the compressed Blob/File
|
|
220
|
+
* },
|
|
221
|
+
* error(err) {
|
|
222
|
+
* console.error(err.message);
|
|
223
|
+
* },
|
|
224
|
+
* });
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
declare class Compressor {
|
|
228
|
+
constructor(file: File | Blob, options?: CompressorOptions);
|
|
229
|
+
private compress;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export { type ArchiveEntry as A, type CompressorOptions$1 as C, type Environment as E, type ImageOptions as I, type RouteContext as R, type VideoOptions as V, type ArchiveOptions as a, type ArchiveResult as b, type AudioOptions as c, type CompressResult as d, Compressor as e, Router as f, type CompressorOptions as g };
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';var chunk4VVOIQUC_cjs=require('./chunk-4VVOIQUC.cjs'),chunkMGMH7JY3_cjs=require('./chunk-MGMH7JY3.cjs');Object.defineProperty(exports,"Compressor",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.f}});Object.defineProperty(exports,"MT_SUPPORTED",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.c}});Object.defineProperty(exports,"OmniCompressor",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.j}});Object.defineProperty(exports,"Router",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.b}});Object.defineProperty(exports,"WorkerConfig",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.a}});Object.defineProperty(exports,"archive",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.d}});Object.defineProperty(exports,"archiveStream",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.e}});Object.defineProperty(exports,"compressAudio",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.h}});Object.defineProperty(exports,"compressImage",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.g}});Object.defineProperty(exports,"compressVideo",{enumerable:true,get:function(){return chunk4VVOIQUC_cjs.i}});Object.defineProperty(exports,"AbortError",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.h}});Object.defineProperty(exports,"EncoderError",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.i}});Object.defineProperty(exports,"FileTooLargeError",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.e}});Object.defineProperty(exports,"FormatNotSupportedError",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.f}});Object.defineProperty(exports,"InvalidOptionsError",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.g}});Object.defineProperty(exports,"OmniCompressError",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.d}});Object.defineProperty(exports,"SAFE_SIZE_LIMITS",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.m}});Object.defineProperty(exports,"arrayBufferToBlob",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.k}});Object.defineProperty(exports,"assertFileSizeWithinLimit",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.n}});Object.defineProperty(exports,"detectFormat",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.r}});Object.defineProperty(exports,"fileToArrayBuffer",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.j}});Object.defineProperty(exports,"getMimeType",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.l}});Object.defineProperty(exports,"isAudioFile",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.p}});Object.defineProperty(exports,"isImageFile",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.o}});Object.defineProperty(exports,"isVideoFile",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.q}});Object.defineProperty(exports,"logger",{enumerable:true,get:function(){return chunkMGMH7JY3_cjs.s}});
|