mirror of
https://github.com/snapotter-hq/SnapOtter.git
synced 2026-08-03 07:46:42 +02:00
fix(lint): resolve all biome warnings across API, web, and image-engine
API: - Replace string concatenation with template literals (batch, pipeline, tool-factory, content-aware-resize, passport-photo, remove-background) - Remove unused imports (teams, color-adjustments, image-enhancement) - Replace non-null assertions with guard clauses in bg-effects and stitch - Use optional chaining in docs route Image-engine: - Remove unused OutputFormat imports (compress, convert) - Use local variables instead of reassigning parameters (optimize-for-web, sharpen) Web: - Fix useExhaustiveDependencies: remove genuinely redundant deps, add biome-ignore comments for intentional patterns (src prop, cleanup fns) - Replace non-null assertions with null-safe alternatives - Add accessible titles to inline SVGs (color-settings, image-enhancement-settings) - Fix noLabelWithoutControl: associate labels via htmlFor/id or use <span> (image-to-base64-settings, edit-metadata-settings, qr-generate-settings) - Replace div[role="button"] with <button> (pdf-to-image-settings) - Use stable keys instead of array indices (collage-preview, collage-settings) - Fix noStaticElementInteractions in collage-preview (role="none") - Remove unused function parameters and imports
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import sharp from "sharp";
|
||||
import type { CompressOptions, OutputFormat, Sharp } from "../types.js";
|
||||
import type { CompressOptions, Sharp } from "../types.js";
|
||||
|
||||
const FORMAT_MAP: Record<string, string> = {
|
||||
jpg: "jpeg",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { ConvertOptions, OutputFormat, Sharp } from "../types.js";
|
||||
import type { ConvertOptions, Sharp } from "../types.js";
|
||||
|
||||
/**
|
||||
* Maps user-facing format names to Sharp format strings.
|
||||
|
||||
@@ -10,9 +10,11 @@ export async function optimizeForWeb(image: Sharp, options: OptimizeForWebOption
|
||||
stripMetadata = true,
|
||||
} = options;
|
||||
|
||||
let pipeline = image;
|
||||
|
||||
// Step 1: Resize if max dimensions are set
|
||||
if (maxWidth || maxHeight) {
|
||||
image = image.resize({
|
||||
pipeline = pipeline.resize({
|
||||
width: maxWidth,
|
||||
height: maxHeight,
|
||||
fit: "inside",
|
||||
@@ -24,19 +26,19 @@ export async function optimizeForWeb(image: Sharp, options: OptimizeForWebOption
|
||||
// Sharp strips metadata by default on output, so we only need to act
|
||||
// when the user wants to KEEP metadata.
|
||||
if (!stripMetadata) {
|
||||
image = image.withMetadata();
|
||||
pipeline = pipeline.withMetadata();
|
||||
}
|
||||
|
||||
// Step 3: Convert to target format with optimized settings
|
||||
switch (format) {
|
||||
case "webp":
|
||||
return image.webp({ quality, effort: 4 });
|
||||
return pipeline.webp({ quality, effort: 4 });
|
||||
case "jpeg":
|
||||
return image.jpeg({ quality, progressive, mozjpeg: true });
|
||||
return pipeline.jpeg({ quality, progressive, mozjpeg: true });
|
||||
case "avif":
|
||||
return image.avif({ quality, effort: 4 });
|
||||
return pipeline.avif({ quality, effort: 4 });
|
||||
case "png":
|
||||
return image.png({ compressionLevel: 9, palette: true });
|
||||
return pipeline.png({ compressionLevel: 9, palette: true });
|
||||
default:
|
||||
throw new Error(`Unsupported format: ${format}`);
|
||||
}
|
||||
|
||||
@@ -27,20 +27,21 @@ export async function sharpenAdvanced(
|
||||
const { method, denoise } = options;
|
||||
|
||||
// Optional noise reduction pre-pass
|
||||
let pipeline = image;
|
||||
if (denoise && denoise !== "off") {
|
||||
const kernelSize = DENOISE_KERNEL[denoise];
|
||||
if (kernelSize) {
|
||||
image = image.median(kernelSize);
|
||||
pipeline = pipeline.median(kernelSize);
|
||||
}
|
||||
}
|
||||
|
||||
switch (method) {
|
||||
case "adaptive":
|
||||
return sharpenAdaptive(image, options);
|
||||
return sharpenAdaptive(pipeline, options);
|
||||
case "unsharp-mask":
|
||||
return sharpenUnsharpMask(image, options);
|
||||
return sharpenUnsharpMask(pipeline, options);
|
||||
case "high-pass":
|
||||
return sharpenHighPass(image, options);
|
||||
return sharpenHighPass(pipeline, options);
|
||||
default:
|
||||
throw new Error(`Unknown sharpening method: ${method}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user