This commit completely removes document conversion functionality to focus exclusively on media file conversions (video, audio, images). Changes: - Remove all document converter services (pandocService.ts, pdfService.ts, docxService.ts) - Uninstall document-related packages: marked, turndown, dompurify, jspdf, pdfjs-dist, docx, mammoth, @types/turndown - Remove document formats (PDF, DOCX, Markdown, HTML, TXT) from formatMappings.ts - Remove pandoc converter from FileConverter.tsx - Remove pandoc loader and references from wasmLoader.ts - Update TypeScript types to remove 'pandoc' from ConverterEngine and 'document' from FileCategory - Remove pandoc from WASMModuleState interface - Update README.md to remove all document conversion documentation - Update UI descriptions to reflect media-only conversions Supported conversions now: - Video: MP4, WebM, AVI, MOV, MKV, GIF - Audio: MP3, WAV, OGG, AAC, FLAC - Images: PNG, JPG, WebP, GIF, BMP, TIFF, SVG 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
122 lines
2.8 KiB
TypeScript
122 lines
2.8 KiB
TypeScript
import type { FFmpeg } from '@ffmpeg/ffmpeg';
|
|
import type { ConverterEngine, WASMModuleState } from '@/types/conversion';
|
|
|
|
/**
|
|
* WASM module loading state
|
|
*/
|
|
const moduleState: WASMModuleState = {
|
|
ffmpeg: false,
|
|
imagemagick: false,
|
|
};
|
|
|
|
/**
|
|
* Cached WASM instances
|
|
*/
|
|
let ffmpegInstance: FFmpeg | null = null;
|
|
let imagemagickInstance: any = null;
|
|
|
|
/**
|
|
* Load FFmpeg WASM module
|
|
*/
|
|
export async function loadFFmpeg(): Promise<FFmpeg> {
|
|
if (ffmpegInstance && moduleState.ffmpeg) {
|
|
return ffmpegInstance;
|
|
}
|
|
|
|
try {
|
|
const { FFmpeg } = await import('@ffmpeg/ffmpeg');
|
|
const { toBlobURL } = await import('@ffmpeg/util');
|
|
|
|
ffmpegInstance = new FFmpeg();
|
|
|
|
// Load core and dependencies
|
|
const baseURL = 'https://unpkg.com/@ffmpeg/core@0.12.6/dist/umd';
|
|
|
|
ffmpegInstance.on('log', ({ message }) => {
|
|
console.log('[FFmpeg]', message);
|
|
});
|
|
|
|
await ffmpegInstance.load({
|
|
coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, 'text/javascript'),
|
|
wasmURL: await toBlobURL(`${baseURL}/ffmpeg-core.wasm`, 'application/wasm'),
|
|
});
|
|
|
|
moduleState.ffmpeg = true;
|
|
console.log('FFmpeg loaded successfully');
|
|
|
|
return ffmpegInstance;
|
|
} catch (error) {
|
|
console.error('Failed to load FFmpeg:', error);
|
|
throw new Error('Failed to load FFmpeg WASM module');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Load ImageMagick WASM module
|
|
*/
|
|
export async function loadImageMagick(): Promise<any> {
|
|
if (imagemagickInstance && moduleState.imagemagick) {
|
|
return imagemagickInstance;
|
|
}
|
|
|
|
try {
|
|
const ImageMagick = await import('@imagemagick/magick-wasm');
|
|
|
|
imagemagickInstance = ImageMagick;
|
|
moduleState.imagemagick = true;
|
|
console.log('ImageMagick loaded successfully');
|
|
|
|
return imagemagickInstance;
|
|
} catch (error) {
|
|
console.error('Failed to load ImageMagick:', error);
|
|
throw new Error('Failed to load ImageMagick WASM module');
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get loaded module state
|
|
*/
|
|
export function getModuleState(): WASMModuleState {
|
|
return { ...moduleState };
|
|
}
|
|
|
|
/**
|
|
* Check if a specific module is loaded
|
|
*/
|
|
export function isModuleLoaded(engine: ConverterEngine): boolean {
|
|
return moduleState[engine];
|
|
}
|
|
|
|
/**
|
|
* Load appropriate WASM module for converter engine
|
|
*/
|
|
export async function loadModule(engine: ConverterEngine): Promise<any> {
|
|
switch (engine) {
|
|
case 'ffmpeg':
|
|
return loadFFmpeg();
|
|
case 'imagemagick':
|
|
return loadImageMagick();
|
|
default:
|
|
throw new Error(`Unknown converter engine: ${engine}`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Unload all WASM modules and free memory
|
|
*/
|
|
export function unloadAll(): void {
|
|
if (ffmpegInstance) {
|
|
// FFmpeg doesn't have an explicit unload method
|
|
// Just null the instance
|
|
ffmpegInstance = null;
|
|
moduleState.ffmpeg = false;
|
|
}
|
|
|
|
if (imagemagickInstance) {
|
|
imagemagickInstance = null;
|
|
moduleState.imagemagick = false;
|
|
}
|
|
|
|
console.log('All WASM modules unloaded');
|
|
}
|