taglib-wasm
Version:
TagLib for TypeScript platforms: Deno, Node.js, Bun, Electron, browsers, and Cloudflare Workers
252 lines (251 loc) • 5.27 kB
JavaScript
// index.ts
import {
AudioFileImpl,
createTagLib,
TagLib
} from "./src/taglib.js";
import {
EnvironmentError,
FileOperationError,
InvalidFormatError,
isEnvironmentError,
isFileOperationError,
isInvalidFormatError,
isMemoryError,
isMetadataError,
isTagLibError,
isUnsupportedFormatError,
MemoryError,
MetadataError,
SUPPORTED_FORMATS,
TagLibError,
TagLibInitializationError,
UnsupportedFormatError
} from "./src/errors.js";
import {
addPicture,
applyPictures,
applyTags,
clearPictures,
clearTags,
findPictureByType,
getCoverArt,
getFormat,
getPictureMetadata,
isValidAudioFile,
readMetadataBatch,
readPictures,
readProperties,
readPropertiesBatch,
readTags,
readTagsBatch,
replacePictureByType,
setCoverArt,
setWorkerPoolMode,
updateTags
} from "./src/simple.js";
import {
FormatMappings,
getAllProperties,
getAllPropertyKeys,
getAllTagNames,
getPropertiesByFormat,
getPropertyMetadata,
isValidProperty,
isValidTagName,
PROPERTIES,
Tags
} from "./src/constants.js";
import {
copyCoverArt,
exportAllPictures,
exportCoverArt,
exportPictureByType,
findCoverArtFiles,
importCoverArt,
importPictureWithType,
loadPictureFromFile,
savePictureToFile
} from "./src/file-utils.js";
import {
exportFolderMetadata,
findDuplicates,
scanFolder,
updateFolderTags
} from "./src/folder-api.js";
import {
canvasToPicture,
createPictureDownloadURL,
createPictureGallery,
dataURLToPicture,
displayPicture,
imageFileToPicture,
pictureToDataURL,
setCoverArtFromCanvas
} from "./src/web-utils.js";
import { PICTURE_TYPE_NAMES, PICTURE_TYPE_VALUES } from "./src/types.js";
import {
COMPLEX_PROPERTIES,
COMPLEX_PROPERTY_KEY
} from "./src/constants/complex-properties.js";
import {
clamp,
fromNormalized,
fromPercent,
fromPopm,
fromStars,
isValid,
RatingUtils,
toNormalized,
toPercent,
toPopm,
toStars
} from "./src/utils/rating.js";
import {
createWorkerPool,
getGlobalWorkerPool,
TagLibWorkerPool,
terminateGlobalWorkerPool
} from "./src/worker-pool.js";
async function loadTagLibModule(options) {
if (options?.legacyMode) {
return loadLegacyTagLibModule(options);
}
try {
const { loadUnifiedTagLibModule } = await import("./src/runtime/unified-loader.js");
return await loadUnifiedTagLibModule({
wasmBinary: options?.wasmBinary,
wasmUrl: options?.wasmUrl,
// These options exist in the v2 loader
debug: false,
useInlineWasm: false
});
} catch (error) {
console.warn(
`[TagLib] Unified loader failed, falling back to legacy mode: ${error}`
);
return loadLegacyTagLibModule(options || {});
}
}
async function loadLegacyTagLibModule(options) {
let createTagLibModule;
try {
const module2 = await import("./taglib-wrapper.js");
createTagLibModule = module2.default;
} catch {
try {
const module2 = await import("./dist/taglib-wrapper.js");
createTagLibModule = module2.default;
} catch {
throw new Error(
"Could not load taglib-wrapper.js from either ./build or ./dist"
);
}
}
const moduleConfig = {};
if (options?.wasmBinary) {
moduleConfig.wasmBinary = options.wasmBinary;
}
if (options?.wasmUrl) {
moduleConfig.locateFile = (path) => {
if (path.endsWith(".wasm")) {
return options.wasmUrl;
}
return path;
};
}
const module = await createTagLibModule(moduleConfig);
return module;
}
export {
AudioFileImpl as AudioFile,
COMPLEX_PROPERTIES,
COMPLEX_PROPERTY_KEY,
EnvironmentError,
FileOperationError,
FormatMappings,
InvalidFormatError,
MemoryError,
MetadataError,
PICTURE_TYPE_NAMES,
PICTURE_TYPE_VALUES,
PROPERTIES,
RatingUtils,
SUPPORTED_FORMATS,
TagLib,
TagLibError,
TagLibInitializationError,
TagLibWorkerPool,
Tags,
UnsupportedFormatError,
addPicture,
applyPictures,
applyTags,
canvasToPicture,
clamp as clampRating,
clearPictures,
clearTags,
copyCoverArt,
createPictureDownloadURL,
createPictureGallery,
createTagLib,
createWorkerPool,
dataURLToPicture,
displayPicture,
exportAllPictures,
exportCoverArt,
exportFolderMetadata,
exportPictureByType,
findCoverArtFiles,
findDuplicates,
findPictureByType,
fromNormalized,
fromPercent,
fromPopm,
fromStars,
getAllProperties,
getAllPropertyKeys,
getAllTagNames,
getCoverArt,
getFormat,
getGlobalWorkerPool,
getPictureMetadata,
getPropertiesByFormat,
getPropertyMetadata,
imageFileToPicture,
importCoverArt,
importPictureWithType,
isEnvironmentError,
isFileOperationError,
isInvalidFormatError,
isMemoryError,
isMetadataError,
isTagLibError,
isUnsupportedFormatError,
isValidAudioFile,
isValidProperty,
isValid as isValidRating,
isValidTagName,
loadPictureFromFile,
loadTagLibModule,
pictureToDataURL,
readMetadataBatch,
readPictures,
readProperties,
readPropertiesBatch,
readTags,
readTagsBatch,
replacePictureByType,
savePictureToFile,
scanFolder,
setCoverArt,
setCoverArtFromCanvas,
setWorkerPoolMode,
terminateGlobalWorkerPool,
toNormalized,
toPercent,
toPopm,
toStars,
updateFolderTags,
updateTags
};