"use client"; import { useRef, useState } from "react"; import { useTranslations } from "next-intl"; import { ArrowDown, ArrowUp, Trash2 } from "lucide-react"; import { AspectRatioLockButton, PanelSection, PropertyNumberInput, } from "@/components/studio/properties/PropertyControls"; import { useLayerUpdater } from "@/components/studio/properties/useLayerUpdater"; import type { Layer } from "@/lib/studio-types"; import { useStudioStore } from "@/lib/studio-store"; interface CommonLayerControlsProps { layer: Layer; } export function CommonLayerControls({ layer }: CommonLayerControlsProps) { const t = useTranslations("auto.componentsStudioPropertiesCommonLayerControls"); const [aspectLocked, setAspectLocked] = useState(false); const aspectRatioRef = useRef(layer.width / layer.height || 1); const { update } = useLayerUpdater(layer); const deleteLayer = useStudioStore((state) => state.deleteLayer); const moveLayerToFront = useStudioStore((state) => state.moveLayerToFront); const moveLayerToBack = useStudioStore((state) => state.moveLayerToBack); const aspectRatio = aspectRatioRef.current; const setWidth = (width: number) => { if (aspectLocked) { update({ width, height: Math.max(8, width / aspectRatio) }); return; } update({ width: Math.max(8, width) }); }; const setHeight = (height: number) => { if (aspectLocked) { update({ height, width: Math.max(8, height * aspectRatio) }); return; } update({ height: Math.max(8, height) }); }; return ( <>
update({ x })} /> update({ y })} />
{ setAspectLocked((locked) => { if (!locked) { aspectRatioRef.current = layer.width / layer.height || 1; } return !locked; }); }} />
update({ rotation })} />
); }