import type { ReactNode } from "react"; import { AlignBottom, AlignHorizontally, AlignLeft, AlignRight, AlignTop, AlignVertically, } from "iconsax-react"; import { useEditorStore, type EditorObject } from "../../../store/editorStore"; import type { AlignKind } from "./alignmentUtils"; import { deltasForAlign, pageBounds, unionBoundsOfAlignTargets, computeGroupFrameUpdate, updatesFromDeltas, } from "./alignmentUtils"; type AlignmentSettingsProps = { pageWidth: number; pageHeight: number; onUpdate: (id: string, updates: Partial) => void; }; type AlignButtonGroupProps = { children: ReactNode; }; type AlignButtonProps = { title: string; onClick: () => void; children: ReactNode; }; const AlignButtonGroup = ({ children }: AlignButtonGroupProps) => (
{children}
); const AlignButton = ({ title, onClick, children }: AlignButtonProps) => ( ); const alignIconProps = { size: 20, color: "currentColor" as const, variant: "Linear" as const }; const AlignmentSettings = ({ pageWidth, pageHeight, onUpdate, }: AlignmentSettingsProps) => { const applyAlign = (kind: AlignKind) => { useEditorStore.getState().commitObjectHistoryBeforeChange(); const { objects: objs, selectedObjectIds: ids, layerRef } = useEditorStore.getState(); const layer = layerRef?.current ?? null; const initial = new Map(); for (const id of ids) { const o = objs.find((x) => x.id === id); if (o && o.visible !== false) initial.set(id, { ...o }); } if (initial.size === 0) return; const initialList = [...initial.values()]; const useSelectionBounds = ids.length === 2; const target = useSelectionBounds && initialList.length === 2 ? unionBoundsOfAlignTargets(initialList, objs, layer) : pageBounds(pageWidth, pageHeight); if (!target) return; const alignedGroupIds = new Set(); for (const id of initial.keys()) { const obj = initial.get(id)!; const { dx, dy } = deltasForAlign(obj, kind, target, objs, layer); const updates = updatesFromDeltas(obj, dx, dy); if (Object.keys(updates).length === 0) continue; onUpdate(id, updates); if (obj.type === "group") { alignedGroupIds.add(id); } } const { updateObject } = useEditorStore.getState(); const afterObjects = useEditorStore.getState().objects; for (const gid of alignedGroupIds) { const patch = computeGroupFrameUpdate(gid, afterObjects, layer); if (patch) updateObject(gid, patch); } }; return (

ترازبندی

applyAlign("right")}> applyAlign("centerH")}> applyAlign("left")}> applyAlign("top")}> applyAlign("centerV")}> applyAlign("bottom")}>
); }; export default AlignmentSettings;