From fec60a6b6921dedf88f51b8e7f99090ce7085a2a Mon Sep 17 00:00:00 2001 From: pancakes Date: Sun, 10 Nov 2024 18:59:18 +1000 Subject: [PATCH] [frontend/mfm] Implement crop fn node --- Iceshrimp.Frontend/Core/Miscellaneous/RenderMfm.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Iceshrimp.Frontend/Core/Miscellaneous/RenderMfm.cs b/Iceshrimp.Frontend/Core/Miscellaneous/RenderMfm.cs index 7c78d786..337750e7 100644 --- a/Iceshrimp.Frontend/Core/Miscellaneous/RenderMfm.cs +++ b/Iceshrimp.Frontend/Core/Miscellaneous/RenderMfm.cs @@ -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 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; + } } \ No newline at end of file