diff --git a/src/converters/main.ts b/src/converters/main.ts index 711b559..d3de413 100644 --- a/src/converters/main.ts +++ b/src/converters/main.ts @@ -282,6 +282,37 @@ export const getPossibleTargets = (from: string): Record => { return possibleTargets[fromClean] || {}; }; +// Reverse of possibleTargets: for a given output extension, which input +// extensions (across all converters) can produce it, grouped by converter. +const possibleSources: Record> = {}; + +for (const converterName in properties) { + const converterProperties = properties[converterName]?.properties; + if (!converterProperties) continue; + + for (const key in converterProperties.from) { + const fromList = converterProperties.from[key]; + const toList = converterProperties.to[key]; + + if (!fromList || !toList) continue; + + for (const target of toList) { + if (!possibleSources[target]) possibleSources[target] = {}; + + const existing = possibleSources[target][converterName]; + possibleSources[target][converterName] = existing + ? Array.from(new Set([...existing, ...fromList])) + : [...fromList]; + } + } +} + +export const getPossibleSources = (to: string): Record => { + const toClean = normalizeOutputFiletype(to); + + return possibleSources[toClean] || {}; +}; + const possibleInputs: string[] = []; for (const converterName in properties) { const converterProperties = properties[converterName]?.properties;