feat: add show mask chip for tools

This commit is contained in:
2026-10-09 14:09:51 +05:00
parent a51e224d02
commit c22c6e5574
22 changed files with 521 additions and 30 deletions
+11
View File
@@ -24,6 +24,7 @@ import {
type Anchor9,
type FlipAxis,
} from "../../core/geometry";
import { renderPredicateMask } from "../../core/masks";
import { field, toolSchema, type Dimension } from "../../registry-schema";
import {
imgTool,
@@ -547,6 +548,10 @@ const centerByAlphaTool: Tool<EmptyParams> = {
schema: centerByAlphaSchema,
input: "image",
run: imgTool((img) => centerByAlpha(img)),
runMask: (ctx) =>
renderPredicateMask(requireSource(ctx), (_r, _g, _b, a) => a > 0, {
mode: "binary",
}),
};
interface SkewParams {
@@ -639,6 +644,12 @@ const trimEmptySpaceTool: Tool<TrimEmptySpaceParams> = {
schema: trimEmptySpaceSchema,
input: "image",
run: imgTool((img, p) => trimToContent(img, p.threshold)),
runMask: (ctx) =>
renderPredicateMask(
requireSource(ctx),
(_r, _g, _b, a) => a > ctx.params.threshold,
{ mode: "binary" },
),
};
type AspectRatio = "1:1" | "4:3" | "3:4" | "3:2" | "2:3" | "16:9" | "9:16";