@awesome-compressor/browser-compress-image
Version:
🚀 A powerful, lightweight browser image compression library with TypeScript support. Compress JPEG, PNG, GIF images with multiple output formats (Blob, File, Base64, ArrayBuffer) and zero dependencies.
767 lines (761 loc) • 30 kB
JavaScript
import { __esm, __export, __toCommonJS } from "./chunk-BaU5PcSi.js";
import { compressWithBrowserImageCompression, compressWithBrowserImageCompression_exports, init_compressWithBrowserImageCompression } from "./compressWithBrowserImageCompression-Blu1-K_Q.js";
import { compressWithCompressorJS, compressWithCompressorJS_exports, init_compressWithCompressorJS } from "./compressWithCompressorJS-BRiXulwq.js";
import { compressWithCanvas, compressWithCanvas_exports, init_compressWithCanvas } from "./compressWithCanvas-DmwJVirl.js";
import { compressWithGifsicle, compressWithGifsicle_exports, init_compressWithGifsicle } from "./compressWithGifsicle-K3v75iYA.js";
import { compressWithJsquash, compressWithJsquash_exports, init_compressWithJsquash } from "./compressWithJsquash-ClynBXBc.js";
import { LRUCache, clearTinyPngCache, compressWithTinyPng, compressWithTinyPng_exports, configureTinyPngCache, getTinyPngCacheInfo, getTinyPngCacheSize, init_compressWithTinyPng, init_lruCache } from "./compressWithTinyPng-BiwgPUd0.js";
//#region src/convertBlobToType.ts
async function convertBlobToType(blob, type, originalFileName) {
switch (type) {
case "blob": return blob;
case "file": return new File([blob], originalFileName || "compressed", { type: blob.type });
case "base64": return new Promise((resolve) => {
const reader = new FileReader();
reader.onloadend = () => resolve(reader.result);
reader.readAsDataURL(blob);
});
case "arrayBuffer": return blob.arrayBuffer();
default: throw new Error(`Unsupported type: ${type}`);
}
}
var init_convertBlobToType = __esm({ "src/convertBlobToType.ts"() {} });
//#endregion
//#region src/compress.ts
init_convertBlobToType();
async function getCompressorTool(tool) {
switch (tool) {
case "browser-image-compression": {
const { default: compressor } = await import("./compressWithBrowserImageCompression-CD_v43G4.js");
return compressor;
}
case "compressorjs": {
const { default: compressor } = await import("./compressWithCompressorJS-CKwOpFnJ.js");
return compressor;
}
case "gifsicle": {
const { default: compressor } = await import("./compressWithGifsicle-CgR5zMKh.js");
return compressor;
}
case "canvas": {
const { default: compressor } = await import("./compressWithCanvas-tL06U_uE.js");
return compressor;
}
case "jsquash": {
const { default: compressor } = await import("./compressWithJsquash-BLAg3kgh.js");
return compressor;
}
case "tinypng": {
const { compressWithTinyPng: compressWithTinyPng$1 } = await import("./compressWithTinyPng-DPXqGQlS.js");
return compressWithTinyPng$1;
}
default: throw new Error(`Unknown compression tool: ${tool}`);
}
}
const devLog$1 = {
log: (...args) => {
if (process.env.NODE_ENV === "development") console.log(...args);
},
warn: (...args) => {
if (process.env.NODE_ENV === "development") console.warn(...args);
},
table: (data) => {
if (process.env.NODE_ENV === "development") console.table(data);
}
};
const EXIF_SUPPORTED_TOOLS$1 = ["browser-image-compression", "compressorjs"];
/**
* 根据工具名称查找对应的配置
*/
function findToolConfig$1(toolName, toolConfigs) {
return toolConfigs.find((config) => config.name === toolName);
}
const toolsCollections = {
png: [
"jsquash",
"browser-image-compression",
"canvas",
"compressorjs"
],
gif: ["gifsicle"],
webp: [
"jsquash",
"canvas",
"browser-image-compression",
"compressorjs"
],
jpeg: [
"jsquash",
"compressorjs",
"canvas",
"browser-image-compression"
],
others: [
"jsquash",
"browser-image-compression",
"compressorjs",
"canvas"
]
};
async function compress(file, qualityOrOptions, type) {
let options;
if (typeof qualityOrOptions === "object") options = qualityOrOptions;
else options = {
quality: qualityOrOptions || .6,
mode: "keepSize",
type: type || "blob"
};
const { quality = .6, mode = "keepSize", targetWidth, targetHeight, maxWidth, maxHeight, preserveExif = false, returnAllResults = false, type: resultType = "blob", toolConfigs = [] } = options;
const compressionOptions = {
quality,
mode,
targetWidth,
targetHeight,
maxWidth,
maxHeight,
preserveExif,
toolConfigs
};
let tools = file.type.includes("png") ? toolsCollections["png"] : file.type.includes("gif") ? toolsCollections["gif"] : file.type.includes("webp") ? toolsCollections["webp"] : file.type.includes("jpeg") || file.type.includes("jpg") ? toolsCollections["jpeg"] : toolsCollections["others"];
const hasTinyPngConfig = toolConfigs.some((config) => config.name === "tinypng");
if (hasTinyPngConfig && [
"png",
"webp",
"jpeg",
"jpg"
].some((type$1) => file.type.includes(type$1))) tools = [...tools, "tinypng"];
if (returnAllResults) return await compressWithMultipleToolsAndReturnAll$1(file, compressionOptions, tools, resultType);
const bestResult = await compressWithMultipleTools$1(file, compressionOptions, tools);
return convertBlobToType(bestResult, resultType, file.name);
}
async function compressWithMultipleTools$1(file, options, tools) {
const totalStartTime = performance.now();
if (options.preserveExif) {
tools = tools.filter((tool) => EXIF_SUPPORTED_TOOLS$1.includes(tool));
if (tools.length === 0) throw new Error("No EXIF-supporting tools available for this file type. Please disable preserveExif or use a different file format.");
devLog$1.log("preserveExif=true, filtered tools:", tools);
}
const attempts = [];
const promises = tools.map(async (tool) => {
const startTime = performance.now();
try {
let compressedBlob;
const toolConfig = findToolConfig$1(tool, options.toolConfigs || []);
const toolOptions = {
quality: options.quality,
mode: options.mode,
targetWidth: options.targetWidth,
targetHeight: options.targetHeight,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
preserveExif: options.preserveExif,
...toolConfig
};
const compressorFunction = await getCompressorTool(tool);
compressedBlob = await compressorFunction(file, toolOptions);
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: compressedBlob,
size: compressedBlob.size,
success: true,
duration
};
} catch (error) {
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: file,
size: file.size,
success: false,
error: error instanceof Error ? error.message : String(error),
duration
};
}
});
const results = await Promise.allSettled(promises);
results.forEach((result) => {
if (result.status === "fulfilled") attempts.push(result.value);
else devLog$1.warn("Compression tool failed:", result.reason);
});
const successfulAttempts = attempts.filter((attempt) => attempt.success);
if (successfulAttempts.length === 0) {
devLog$1.warn("All compression attempts failed, returning original file");
return file;
}
const bestAttempt = successfulAttempts.reduce((best, current) => current.size < best.size ? current : best);
if (bestAttempt.size >= file.size * .98 && options.quality > .85) {
const totalEndTime$1 = performance.now();
const totalDuration$1 = Math.round(totalEndTime$1 - totalStartTime);
devLog$1.log(`Best compression (${bestAttempt.tool}) size: ${bestAttempt.size}, original: ${file.size}, using original (total: ${totalDuration$1}ms)`);
return file;
}
const totalEndTime = performance.now();
const totalDuration = Math.round(totalEndTime - totalStartTime);
devLog$1.log(`Best compression result: ${bestAttempt.tool} (${bestAttempt.size} bytes, ${((file.size - bestAttempt.size) / file.size * 100).toFixed(1)}% reduction, ${bestAttempt.duration}ms) - Total time: ${totalDuration}ms`);
if (successfulAttempts.length > 1) devLog$1.table(successfulAttempts.map((attempt) => ({
Tool: attempt.tool,
"Size (bytes)": attempt.size,
"Reduction (%)": `${((file.size - attempt.size) / file.size * 100).toFixed(1)}%`,
"Duration (ms)": attempt.duration,
"Speed (MB/s)": `${(file.size / 1024 / 1024 / (attempt.duration / 1e3)).toFixed(2)}`
})));
return bestAttempt.blob;
}
async function compressWithMultipleToolsAndReturnAll$1(file, options, tools, resultType) {
const totalStartTime = performance.now();
if (options.preserveExif) {
tools = tools.filter((tool) => EXIF_SUPPORTED_TOOLS$1.includes(tool));
if (tools.length === 0) throw new Error("No EXIF-supporting tools available for this file type. Please disable preserveExif or use a different file format.");
devLog$1.log("preserveExif=true, filtered tools:", tools);
}
const attempts = [];
const promises = tools.map(async (tool) => {
const startTime = performance.now();
try {
let compressedBlob;
const toolConfig = findToolConfig$1(tool, options.toolConfigs || []);
const toolOptions = {
quality: options.quality,
mode: options.mode,
targetWidth: options.targetWidth,
targetHeight: options.targetHeight,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
preserveExif: options.preserveExif,
...toolConfig
};
const compressorFunction = await getCompressorTool(tool);
compressedBlob = await compressorFunction(file, toolOptions);
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: compressedBlob,
size: compressedBlob.size,
success: true,
duration
};
} catch (error) {
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: file,
size: file.size,
success: false,
error: error instanceof Error ? error.message : String(error),
duration
};
}
});
const results = await Promise.allSettled(promises);
results.forEach((result) => {
if (result.status === "fulfilled") attempts.push(result.value);
else devLog$1.warn("Compression tool failed:", result.reason);
});
if (attempts.length === 0) throw new Error("All compression attempts failed");
const totalEndTime = performance.now();
const totalDuration = Math.round(totalEndTime - totalStartTime);
const allResults = await Promise.all(attempts.map(async (attempt) => {
const convertedResult = await convertBlobToType(attempt.blob, resultType, file.name);
return {
tool: attempt.tool,
result: convertedResult,
originalSize: file.size,
compressedSize: attempt.size,
compressionRatio: (file.size - attempt.size) / file.size * 100,
duration: attempt.duration,
success: attempt.success,
error: attempt.error
};
}));
const successfulAttempts = attempts.filter((attempt) => attempt.success);
let bestAttempt;
if (successfulAttempts.length > 0) {
bestAttempt = successfulAttempts.reduce((best, current) => current.size < best.size ? current : best);
if (bestAttempt.size >= file.size * .98 && options.quality > .85) bestAttempt = {
tool: "original",
blob: file,
size: file.size,
success: true,
duration: 0
};
} else bestAttempt = {
tool: "original",
blob: file,
size: file.size,
success: true,
duration: 0
};
const bestResult = await convertBlobToType(bestAttempt.blob, resultType, file.name);
devLog$1.log(`Best compression result: ${bestAttempt.tool} (${bestAttempt.size} bytes, ${((file.size - bestAttempt.size) / file.size * 100).toFixed(1)}% reduction) - Total time: ${totalDuration}ms`);
if (successfulAttempts.length > 1) devLog$1.table(successfulAttempts.map((attempt) => ({
Tool: attempt.tool,
"Size (bytes)": attempt.size,
"Reduction (%)": `${((file.size - attempt.size) / file.size * 100).toFixed(1)}%`,
"Duration (ms)": attempt.duration,
"Speed (MB/s)": `${(file.size / 1024 / 1024 / (attempt.duration / 1e3)).toFixed(2)}`
})));
return {
bestResult,
bestTool: bestAttempt.tool,
allResults,
totalDuration
};
}
async function compressWithStats(file, qualityOrOptions) {
return await compressWithMultipleToolsWithStats(file, {
quality: typeof qualityOrOptions === "object" ? qualityOrOptions.quality || .6 : qualityOrOptions || .6,
mode: typeof qualityOrOptions === "object" ? qualityOrOptions.mode || "keepSize" : "keepSize",
targetWidth: typeof qualityOrOptions === "object" ? qualityOrOptions.targetWidth : void 0,
targetHeight: typeof qualityOrOptions === "object" ? qualityOrOptions.targetHeight : void 0,
maxWidth: typeof qualityOrOptions === "object" ? qualityOrOptions.maxWidth : void 0,
maxHeight: typeof qualityOrOptions === "object" ? qualityOrOptions.maxHeight : void 0,
preserveExif: typeof qualityOrOptions === "object" ? qualityOrOptions.preserveExif || false : false,
toolConfigs: typeof qualityOrOptions === "object" ? qualityOrOptions.toolConfigs || [] : []
});
}
async function compressWithMultipleToolsWithStats(file, options) {
const totalStartTime = performance.now();
let tools = file.type.includes("png") ? toolsCollections["png"] : file.type.includes("gif") ? toolsCollections["gif"] : file.type.includes("webp") ? toolsCollections["webp"] : toolsCollections["others"];
const hasTinyPngConfig = options.toolConfigs?.some((config) => config.name === "tinypng");
if (hasTinyPngConfig && [
"png",
"webp",
"jpeg",
"jpg"
].some((type) => file.type.includes(type))) tools = [...tools, "tinypng"];
if (options.preserveExif) {
tools = tools.filter((tool) => EXIF_SUPPORTED_TOOLS$1.includes(tool));
if (tools.length === 0) throw new Error("No EXIF-supporting tools available for this file type. Please disable preserveExif or use a different file format.");
devLog$1.log("preserveExif=true, filtered tools:", tools);
}
const attempts = [];
const promises = tools.map(async (tool) => {
const startTime = performance.now();
try {
let compressedBlob;
const toolConfig = findToolConfig$1(tool, options.toolConfigs || []);
const toolOptions = {
quality: options.quality,
mode: options.mode,
targetWidth: options.targetWidth,
targetHeight: options.targetHeight,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
preserveExif: options.preserveExif,
...toolConfig
};
const compressorFunction = await getCompressorTool(tool);
compressedBlob = await compressorFunction(file, toolOptions);
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: compressedBlob,
size: compressedBlob.size,
success: true,
duration
};
} catch (error) {
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: file,
size: file.size,
success: false,
error: error instanceof Error ? error.message : String(error),
duration
};
}
});
const results = await Promise.allSettled(promises);
results.forEach((result) => {
if (result.status === "fulfilled") attempts.push(result.value);
});
const successfulAttempts = attempts.filter((attempt) => attempt.success);
const bestAttempt = successfulAttempts.length > 0 ? successfulAttempts.reduce((best, current) => current.size < best.size ? current : best) : {
tool: "none",
blob: file,
size: file.size,
success: false,
duration: 0
};
const totalEndTime = performance.now();
const totalDuration = Math.round(totalEndTime - totalStartTime);
return {
bestTool: bestAttempt.tool,
compressedFile: bestAttempt.blob,
originalSize: file.size,
compressedSize: bestAttempt.size,
compressionRatio: (file.size - bestAttempt.size) / file.size * 100,
totalDuration,
toolsUsed: attempts.map((attempt) => ({
tool: attempt.tool,
size: attempt.size,
duration: attempt.duration,
compressionRatio: (file.size - attempt.size) / file.size * 100,
success: attempt.success,
error: attempt.error
}))
};
}
//#endregion
//#region src/compressWithTools.ts
var compressWithTools_exports = {};
__export(compressWithTools_exports, {
ToolRegistry: () => ToolRegistry,
compressWithTools: () => compressWithTools,
globalToolRegistry: () => globalToolRegistry
});
/**
* 根据工具名称查找对应的配置
*/
function findToolConfig(toolName, toolConfigs) {
return toolConfigs.find((config) => config.name === toolName);
}
async function compressWithTools(file, options) {
const { quality = .6, mode = "keepSize", targetWidth, targetHeight, maxWidth, maxHeight, preserveExif = false, returnAllResults = false, type: resultType = "blob", toolConfigs = [], toolRegistry = globalToolRegistry } = options;
const compressionOptions = {
quality,
mode,
targetWidth,
targetHeight,
maxWidth,
maxHeight,
preserveExif,
toolConfigs
};
let tools = toolRegistry.getToolsForFileType(file.type);
const hasTinyPngConfig = toolConfigs.some((config) => config.name === "tinypng");
if (hasTinyPngConfig && toolRegistry.isToolRegistered("tinypng") && [
"png",
"webp",
"jpeg",
"jpg"
].some((type) => file.type.includes(type))) {
if (!tools.includes("tinypng")) tools = [...tools, "tinypng"];
}
tools = tools.filter((tool) => toolRegistry.isToolRegistered(tool));
if (tools.length === 0) throw new Error("No compression tools available. Please register at least one compression tool.");
if (returnAllResults) return await compressWithMultipleToolsAndReturnAll(file, compressionOptions, tools, resultType, toolRegistry);
const bestResult = await compressWithMultipleTools(file, compressionOptions, tools, toolRegistry);
return convertBlobToType(bestResult, resultType, file.name);
}
async function compressWithMultipleTools(file, options, tools, toolRegistry) {
const totalStartTime = performance.now();
if (options.preserveExif) {
tools = tools.filter((tool) => EXIF_SUPPORTED_TOOLS.includes(tool));
if (tools.length === 0) throw new Error("No EXIF-supporting tools available for this file type. Please disable preserveExif or use a different file format.");
devLog.log("preserveExif=true, filtered tools:", tools);
}
const attempts = [];
const promises = tools.map(async (tool) => {
const startTime = performance.now();
try {
const compressorFunction = toolRegistry.getTool(tool);
if (!compressorFunction) throw new Error(`Tool ${tool} not registered`);
const toolConfig = findToolConfig(tool, options.toolConfigs || []);
const toolOptions = {
quality: options.quality,
mode: options.mode,
targetWidth: options.targetWidth,
targetHeight: options.targetHeight,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
preserveExif: options.preserveExif,
...toolConfig
};
const compressedBlob = await compressorFunction(file, toolOptions);
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: compressedBlob,
size: compressedBlob.size,
success: true,
duration
};
} catch (error) {
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: file,
size: file.size,
success: false,
error: error instanceof Error ? error.message : String(error),
duration
};
}
});
const results = await Promise.allSettled(promises);
results.forEach((result) => {
if (result.status === "fulfilled") attempts.push(result.value);
else devLog.warn("Compression tool failed:", result.reason);
});
const successfulAttempts = attempts.filter((attempt) => attempt.success);
if (successfulAttempts.length === 0) {
devLog.warn("All compression attempts failed, returning original file");
return file;
}
const bestAttempt = successfulAttempts.reduce((best, current) => current.size < best.size ? current : best);
if (bestAttempt.size >= file.size * .98 && options.quality > .85) {
const totalEndTime$1 = performance.now();
const totalDuration$1 = Math.round(totalEndTime$1 - totalStartTime);
devLog.log(`Best compression (${bestAttempt.tool}) size: ${bestAttempt.size}, original: ${file.size}, using original (total: ${totalDuration$1}ms)`);
return file;
}
const totalEndTime = performance.now();
const totalDuration = Math.round(totalEndTime - totalStartTime);
devLog.log(`Best compression result: ${bestAttempt.tool} (${bestAttempt.size} bytes, ${((file.size - bestAttempt.size) / file.size * 100).toFixed(1)}% reduction, ${bestAttempt.duration}ms) - Total time: ${totalDuration}ms`);
if (successfulAttempts.length > 1) devLog.table(successfulAttempts.map((attempt) => ({
Tool: attempt.tool,
"Size (bytes)": attempt.size,
"Reduction (%)": `${((file.size - attempt.size) / file.size * 100).toFixed(1)}%`,
"Duration (ms)": attempt.duration,
"Speed (MB/s)": `${(file.size / 1024 / 1024 / (attempt.duration / 1e3)).toFixed(2)}`
})));
return bestAttempt.blob;
}
async function compressWithMultipleToolsAndReturnAll(file, options, tools, resultType, toolRegistry) {
const totalStartTime = performance.now();
if (options.preserveExif) {
tools = tools.filter((tool) => EXIF_SUPPORTED_TOOLS.includes(tool));
if (tools.length === 0) throw new Error("No EXIF-supporting tools available for this file type. Please disable preserveExif or use a different file format.");
devLog.log("preserveExif=true, filtered tools:", tools);
}
const attempts = [];
const promises = tools.map(async (tool) => {
const startTime = performance.now();
try {
const compressorFunction = toolRegistry.getTool(tool);
if (!compressorFunction) throw new Error(`Tool ${tool} not registered`);
const toolConfig = findToolConfig(tool, options.toolConfigs || []);
const toolOptions = {
quality: options.quality,
mode: options.mode,
targetWidth: options.targetWidth,
targetHeight: options.targetHeight,
maxWidth: options.maxWidth,
maxHeight: options.maxHeight,
preserveExif: options.preserveExif,
...toolConfig
};
const compressedBlob = await compressorFunction(file, toolOptions);
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: compressedBlob,
size: compressedBlob.size,
success: true,
duration
};
} catch (error) {
const endTime = performance.now();
const duration = Math.round(endTime - startTime);
return {
tool,
blob: file,
size: file.size,
success: false,
error: error instanceof Error ? error.message : String(error),
duration
};
}
});
const results = await Promise.allSettled(promises);
results.forEach((result) => {
if (result.status === "fulfilled") attempts.push(result.value);
else devLog.warn("Compression tool failed:", result.reason);
});
if (attempts.length === 0) throw new Error("All compression attempts failed");
const totalEndTime = performance.now();
const totalDuration = Math.round(totalEndTime - totalStartTime);
const allResults = await Promise.all(attempts.map(async (attempt) => {
const convertedResult = await convertBlobToType(attempt.blob, resultType, file.name);
return {
tool: attempt.tool,
result: convertedResult,
originalSize: file.size,
compressedSize: attempt.size,
compressionRatio: (file.size - attempt.size) / file.size * 100,
duration: attempt.duration,
success: attempt.success,
error: attempt.error
};
}));
const successfulAttempts = attempts.filter((attempt) => attempt.success);
let bestAttempt;
if (successfulAttempts.length > 0) {
bestAttempt = successfulAttempts.reduce((best, current) => current.size < best.size ? current : best);
if (bestAttempt.size >= file.size * .98 && options.quality > .85) bestAttempt = {
tool: "original",
blob: file,
size: file.size,
success: true,
duration: 0
};
} else bestAttempt = {
tool: "original",
blob: file,
size: file.size,
success: true,
duration: 0
};
const bestResult = await convertBlobToType(bestAttempt.blob, resultType, file.name);
devLog.log(`Best compression result: ${bestAttempt.tool} (${bestAttempt.size} bytes, ${((file.size - bestAttempt.size) / file.size * 100).toFixed(1)}% reduction) - Total time: ${totalDuration}ms`);
return {
bestResult,
bestTool: bestAttempt.tool,
allResults,
totalDuration
};
}
var devLog, ToolRegistry, globalToolRegistry, EXIF_SUPPORTED_TOOLS;
var init_compressWithTools = __esm({ "src/compressWithTools.ts"() {
init_convertBlobToType();
devLog = {
log: (...args) => {
if (process.env.NODE_ENV === "development") console.log(...args);
},
warn: (...args) => {
if (process.env.NODE_ENV === "development") console.warn(...args);
},
table: (data) => {
if (process.env.NODE_ENV === "development") console.table(data);
}
};
ToolRegistry = class {
tools = /* @__PURE__ */ new Map();
toolsCollections = {
png: [],
gif: [],
webp: [],
jpeg: [],
others: []
};
registerTool(name, func, formats) {
this.tools.set(name, func);
if (formats && formats.length > 0) formats.forEach((format) => {
if (this.toolsCollections[format]) {
if (!this.toolsCollections[format].includes(name)) this.toolsCollections[format].push(name);
}
});
else Object.keys(this.toolsCollections).forEach((format) => {
if (format !== "gif" && !this.toolsCollections[format].includes(name)) this.toolsCollections[format].push(name);
});
}
getTool(name) {
return this.tools.get(name);
}
getRegisteredTools() {
return Array.from(this.tools.keys());
}
getToolsForFileType(fileType) {
if (fileType.includes("png")) return [...this.toolsCollections.png];
if (fileType.includes("gif")) return [...this.toolsCollections.gif];
if (fileType.includes("webp")) return [...this.toolsCollections.webp];
if (fileType.includes("jpeg") || fileType.includes("jpg")) return [...this.toolsCollections.jpeg];
return [...this.toolsCollections.others];
}
setToolPriority(fileType, tools) {
if (this.toolsCollections[fileType]) {
const registeredTools = tools.filter((tool) => this.tools.has(tool));
this.toolsCollections[fileType] = registeredTools;
}
}
isToolRegistered(name) {
return this.tools.has(name);
}
};
globalToolRegistry = new ToolRegistry();
EXIF_SUPPORTED_TOOLS = ["browser-image-compression", "compressorjs"];
} });
//#endregion
//#region src/tools.ts
init_compressWithBrowserImageCompression();
init_compressWithCompressorJS();
init_compressWithCanvas();
init_compressWithGifsicle();
init_compressWithJsquash();
init_compressWithTinyPng();
init_compressWithTools();
function registerAllTools() {
const { globalToolRegistry: globalToolRegistry$1 } = (init_compressWithTools(), __toCommonJS(compressWithTools_exports));
globalToolRegistry$1.registerTool("browser-image-compression", (init_compressWithBrowserImageCompression(), __toCommonJS(compressWithBrowserImageCompression_exports)).default, [
"png",
"jpeg",
"webp",
"others"
]);
globalToolRegistry$1.registerTool("compressorjs", (init_compressWithCompressorJS(), __toCommonJS(compressWithCompressorJS_exports)).default, ["jpeg", "others"]);
globalToolRegistry$1.registerTool("canvas", (init_compressWithCanvas(), __toCommonJS(compressWithCanvas_exports)).default, [
"png",
"jpeg",
"webp",
"others"
]);
globalToolRegistry$1.registerTool("gifsicle", (init_compressWithGifsicle(), __toCommonJS(compressWithGifsicle_exports)).default, ["gif"]);
globalToolRegistry$1.registerTool("jsquash", (init_compressWithJsquash(), __toCommonJS(compressWithJsquash_exports)).default, [
"png",
"jpeg",
"webp",
"others"
]);
}
function registerBrowserImageCompression() {
const { globalToolRegistry: globalToolRegistry$1 } = (init_compressWithTools(), __toCommonJS(compressWithTools_exports));
globalToolRegistry$1.registerTool("browser-image-compression", (init_compressWithBrowserImageCompression(), __toCommonJS(compressWithBrowserImageCompression_exports)).default, [
"png",
"jpeg",
"webp",
"others"
]);
}
function registerCompressorJS() {
const { globalToolRegistry: globalToolRegistry$1 } = (init_compressWithTools(), __toCommonJS(compressWithTools_exports));
globalToolRegistry$1.registerTool("compressorjs", (init_compressWithCompressorJS(), __toCommonJS(compressWithCompressorJS_exports)).default, ["jpeg", "others"]);
}
function registerCanvas() {
const { globalToolRegistry: globalToolRegistry$1 } = (init_compressWithTools(), __toCommonJS(compressWithTools_exports));
globalToolRegistry$1.registerTool("canvas", (init_compressWithCanvas(), __toCommonJS(compressWithCanvas_exports)).default, [
"png",
"jpeg",
"webp",
"others"
]);
}
function registerGifsicle() {
const { globalToolRegistry: globalToolRegistry$1 } = (init_compressWithTools(), __toCommonJS(compressWithTools_exports));
globalToolRegistry$1.registerTool("gifsicle", (init_compressWithGifsicle(), __toCommonJS(compressWithGifsicle_exports)).default, ["gif"]);
}
function registerJsquash() {
const { globalToolRegistry: globalToolRegistry$1 } = (init_compressWithTools(), __toCommonJS(compressWithTools_exports));
globalToolRegistry$1.registerTool("jsquash", (init_compressWithJsquash(), __toCommonJS(compressWithJsquash_exports)).default, [
"png",
"jpeg",
"webp",
"others"
]);
}
function registerTinyPng() {
const { globalToolRegistry: globalToolRegistry$1 } = (init_compressWithTools(), __toCommonJS(compressWithTools_exports));
globalToolRegistry$1.registerTool("tinypng", (init_compressWithTinyPng(), __toCommonJS(compressWithTinyPng_exports)).compressWithTinyPng, [
"png",
"jpeg",
"webp"
]);
}
//#endregion
//#region src/index.ts
init_compressWithTools();
init_compressWithTinyPng();
init_lruCache();
//#endregion
export { LRUCache, ToolRegistry, clearTinyPngCache, compress, compressWithBrowserImageCompression, compressWithCanvas, compressWithCompressorJS, compressWithGifsicle, compressWithJsquash, compressWithStats, compressWithTinyPng, compressWithTools, configureTinyPngCache, getTinyPngCacheInfo, getTinyPngCacheSize, globalToolRegistry, registerAllTools, registerBrowserImageCompression, registerCanvas, registerCompressorJS, registerGifsicle, registerJsquash, registerTinyPng };