[frontend/mfm] Implement crop fn node

This commit is contained in:
pancakes 2024-11-10 18:59:18 +10:00 committed by Laura Hausmann
parent db5d6f469f
commit fec60a6b69
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -270,7 +270,7 @@ public static class MfmRenderer
"sparkle" => throw new NotImplementedException($"{node.Name}"),
"rotate" => MfmFnRotate(args, document),
"fade" => throw new NotImplementedException($"{node.Name}"),
"crop" => throw new NotImplementedException($"{node.Name}"),
"crop" => MfmFnCrop(args, document),
"position" => throw new NotImplementedException($"{node.Name}"),
"scale" => throw new NotImplementedException($"{node.Name}"),
"fg" => throw new NotImplementedException($"{node.Name}"),
@ -345,4 +345,14 @@ public static class MfmRenderer
return el;
}
private static INode MfmFnCrop(Dictionary<string, string?> args, IDocument document)
{
var el = document.CreateElement("span");
var inset = $"{args.GetValueOrDefault("top") ?? "0"}% {args.GetValueOrDefault("right") ?? "0"}% {args.GetValueOrDefault("bottom") ?? "0"}% {args.GetValueOrDefault("left") ?? "0"}%";
el.SetAttribute("style", $"display: inline-block; clip-path: inset({inset});");
return el;
}
}