From 45a0540edf5ba50eb69e14e036a2aae8e3f08ac3 Mon Sep 17 00:00:00 2001 From: Sahil Date: Wed, 13 Aug 2025 17:55:45 +0530 Subject: [PATCH] vtracer: bug fix in vtracer.ts file and code refactor --- src/converters/vtracer.ts | 89 +++++++++++++-------------------------- 1 file changed, 29 insertions(+), 60 deletions(-) diff --git a/src/converters/vtracer.ts b/src/converters/vtracer.ts index db9d037..1c0d706 100644 --- a/src/converters/vtracer.ts +++ b/src/converters/vtracer.ts @@ -22,70 +22,39 @@ export function convert( // Build vtracer arguments const args = ["--input", filePath, "--output", targetPath]; - // Add option parameter if provided + // Add optional parameter if provided if (options && typeof options === "object") { const opts = options as Record; - if (opts.colormode) { - args.push("--colormode", opts.colormode); + const validOptions = [ + "colormode", "hierarchical", "mode", "filter_speckle", + "color_precision", "layer_difference", "corner_threshold", + "length_threshold", "max_iterations", "splice_threshold", + "path_precision", + ]; + + for (const option of validOptions) { + if(opts[option]){ + args.push(`--${option}`, opts[option]); + } } - - if (opts.hierarchical) { - args.push("--hierarchical", opts.hierarchical); - } - - 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) => { - if (error) { - reject(`error: ${error}${stderr ? `\nstderr: ${stderr}` : ''}`); - return; - } - - if (stdout) { - console.log(`stdout: ${stdout}`); - } - - if (stderr) { - console.log(`stderr: ${stderr}`); - } - - resolve("Done"); - }); } + + execFile("vtracer", args, (error, stdout, stderr) => { + if(error){ + reject(`error: ${error}${stderr ? `\nstderr: ${stderr}` : ''}`) + return; + } + + if(stdout){ + console.log(`stdout: ${stdout}`) + } + + if(stderr){ + console.log(`stderr: ${stderr}`) + } + + resolve("Done"); + }); }); }