mirror of
				https://github.com/C4illin/ConvertX.git
				synced 2025-11-04 05:53:45 +00:00 
			
		
		
		
	vtracer: bug fix in vtracer.ts file and code refactor
This commit is contained in:
		@@ -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",
 | 
				
			||||||
 | 
					      ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      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");
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user