Skip to content

Create professional demos and 3D mockups in seconds, directly in your browser

feat: implement GetMediaMaskStyles function for dynamic mask styling; update ImageMaskEditor to utilize new function

CristianOlivera1e553ae9b9e36
diff --git a/app/components/ui/editor/GetMediaMaskStyles.tsx b/app/components/ui/editor/GetMediaMaskStyles.tsx
new file mode 100644
index 0000000..3e2c82f
--- /dev/null
+++ b/app/components/ui/editor/GetMediaMaskStyles.tsx
@@ -0,0 +1,32 @@
+import type { ImageMaskConfig } from "@/types/photo.types";
+
+export function GetMediaMaskStyles(maskConfig?: ImageMaskConfig | null): React.CSSProperties {
+ if (!maskConfig || !maskConfig.enabled) return {};
+
+ const masks: string[] = [];
+
+ if (maskConfig.top) {
+ masks.push(`linear-gradient(180deg, transparent ${maskConfig.top.from}%, black ${maskConfig.top.to ?? 100}%)`);
+ }
+ if (maskConfig.bottom) {
+ masks.push(`linear-gradient(0deg, transparent ${maskConfig.bottom.from}%, black ${maskConfig.bottom.to ?? 100}%)`);
+ }
+ if (maskConfig.left) {
+ masks.push(`linear-gradient(90deg, transparent ${maskConfig.left.from}%, black ${maskConfig.left.to ?? 100}%)`);
+ }
+ if (maskConfig.right) {
+ masks.push(`linear-gradient(270deg, transparent ${maskConfig.right.from}%, black ${maskConfig.right.to ?? 100}%)`);
+ }
+ if (maskConfig.angle !== undefined) {
+ masks.push(`linear-gradient(${maskConfig.angle}deg, transparent ${maskConfig.angleFrom ?? 0}%, black ${maskConfig.angleTo ?? 100}%)`);
+ }
+
+ if (masks.length === 0) return {};
+
+ return {
+ WebkitMaskImage: masks.join(', '),
+ WebkitMaskComposite: 'source-in',
+ maskImage: masks.join(', '),
+ maskComposite: 'intersect',
+ };
+}
\ No newline at end of file
diff --git a/app/components/ui/editor/ImageMaskEditor.tsx b/app/components/ui/editor/ImageMaskEditor.tsx
index 1001998..795f938 100644
--- a/app/components/ui/editor/ImageMaskEditor.tsx
+++ b/app/components/ui/editor/ImageMaskEditor.tsx
@@ -12,10 +12,10 @@ import {
PopoverTitle,
} from "@/components/ui/popover";
import type { ImageMaskConfig } from "@/types/photo.types";
-import { getMediaMaskStyles } from "./getMediaMaskStyles";
import { ImageMaskEditorProps, MaskPreset, MASK_PRESETS } from "@/types/ImageMask.types";
import { TooltipAction } from "@/components/ui/tooltip-action";
-import { useTranslations } from "next-intl";
+import { useTranslations } from "next-intl";
+import { GetMediaMaskStyles } from "./GetMediaMaskStyles";
export function ImageMaskEditor({
maskConfig,
@@ -24,7 +24,7 @@ export function ImageMaskEditor({
}: ImageMaskEditorProps) {
const [isOpen, setIsOpen] = useState(false);
const [activeTab, setActiveTab] = useState<"presets" | "custom">("presets");
-
+
const t = useTranslations("editor.imageMask");
const isPresetActive = (preset: MaskPreset) => {
@@ -66,7 +66,7 @@ export function ImageMaskEditor({
const getPreviewMaskStyles = (presetConfig: Partial<ImageMaskConfig>) => {
if (!presetConfig.enabled) return {};
- return getMediaMaskStyles({
+ return GetMediaMaskStyles({
enabled: true,
top: presetConfig.top,
bottom: presetConfig.bottom,
diff --git a/app/components/ui/editor/MockupMenu.tsx b/app/components/ui/editor/MockupMenu.tsx
index ee15fba..27ea22e 100644
--- a/app/components/ui/editor/MockupMenu.tsx
+++ b/app/components/ui/editor/MockupMenu.tsx
@@ -176,7 +176,7 @@ export function MockupMenu({
</div>
</div>
<div className="absolute inset-0 group-hover:bg-black/5 transition-colors pointer-events-none" />
- <div className="absolute bottom-0 left-0 bg-black/60 backdrop-blur-md border-t border-r border-white/10 px-2 py-1 text-[9px] text-white/80 font-bold tracking-tighter rounded-tr-md rounded-bl-lg z-30">
+ <div className="absolute bottom-0 left-0 bg-black/60 border-t border-r border-white/10 px-2 py-1 text-[9px] text-white/80 font-bold tracking-tighter rounded-tr-md rounded-bl-lg z-30">
{mockup.name}
</div>
{isActive && (