vtracer: bug fix in vtracer.ts file and code refactor

This commit is contained in:
Sahil 2025-08-13 17:55:45 +05:30
parent 2b784d1edc
commit 45a0540edf

View file

@ -22,70 +22,39 @@ export function convert(
// Build vtracer arguments // Build vtracer arguments
const args = ["--input", filePath, "--output", targetPath]; const args = ["--input", filePath, "--output", targetPath];
// Add option parameter if provided // Add optional parameter if provided
if (options && typeof options === "object") { if (options && typeof options === "object") {
const opts = options as Record<string, any>; const opts = options as Record<string, any>;
if (opts.colormode) { const validOptions = [
args.push("--colormode", opts.colormode); "colormode", "hierarchical", "mode", "filter_speckle",
} "color_precision", "layer_difference", "corner_threshold",
"length_threshold", "max_iterations", "splice_threshold",
"path_precision",
];
if (opts.hierarchical) { for (const option of validOptions) {
args.push("--hierarchical", opts.hierarchical); if(opts[option]){
args.push(`--${option}`, opts[option]);
} }
if (opts.mode) {
args.push("--mode", opts.mode);
} }
if (opts.filter_speckle) {
args.push("--filter_speckle", opts.filter_speckle);
}
if (opts.color_precision) {
args.push("--color_precision", opts.color_precision);
}
if (opts.layer_difference) {
args.push("--layer_difference", opts.layer_difference);
}
if (opts.corner_threshold) {
args.push("--corner_threshold", opts.corner_threshold);
}
if (opts.length_threshold) {
args.push("--length_threshold", opts.length_threshold);
}
if (opts.max_iterations) {
args.push("--max_iterations", opts.max_iterations);
}
if (opts.splice_threshold) {
args.push("--splice_threshold", opts.splice_threshold);
}
if (opts.path_precision) {
args.push("--path_precision", opts.path_precision);
} }
execFile("vtracer", args, (error, stdout, stderr) => { execFile("vtracer", args, (error, stdout, stderr) => {
if (error) { if(error){
reject(`error: ${error}${stderr ? `\nstderr: ${stderr}` : ''}`); reject(`error: ${error}${stderr ? `\nstderr: ${stderr}` : ''}`)
return; return;
} }
if (stdout) { if(stdout){
console.log(`stdout: ${stdout}`); console.log(`stdout: ${stdout}`)
} }
if (stderr) { if(stderr){
console.log(`stderr: ${stderr}`); console.log(`stderr: ${stderr}`)
} }
resolve("Done"); resolve("Done");
}); });
}
}); });
} }