import { ActionIcon, Flex, NumberInput, Stack, Text } from "@mantine/core" import { IconMinus, IconPlus, IconRefresh } from "@tabler/icons-react" import paper from "paper" import { useMemo } from "react" import { useKeyEventStore } from "../store" import { usePaperStore } from "../usePaperStore" import { useTopToolsStore } from "../useTopToolsStore" const ScaleToolContainer = () => { const { scale, setScale } = useTopToolsStore() const { setFocusInput } = useKeyEventStore() const displayNumber = useMemo(() => { return Number((scale * 100).toFixed(0)) }, [scale]) const setCurrentScale = (n: number) => { const currentScale = n / 100 const group = usePaperStore.getState().group if (!group) return group.scaling = new paper.Point(currentScale, currentScale) setScale(currentScale) } const handleReset = () => { const group = usePaperStore.getState().group if (!group) return const rasterList = group.getItems({ data: { name: "pic", }, }) if (!rasterList || !rasterList.length) return const currentRaster = rasterList[0] group.position = currentRaster.position setCurrentScale(100) } const handleEnter = (e: any) => { const num = Number(e.target.value) if (isNaN(num)) return if (num > 9999 || num < 0) return setCurrentScale(num) } return ( { setCurrentScale( displayNumber + 10 <= 9999 ? displayNumber + 10 : 9999 ) }} style={{ width: 32, height: 32 }}> { if (e.key === "Enter") { handleEnter(e) } }} onFocus={() => { setFocusInput(true) }} onBlur={() => { setFocusInput(false) }} hideControls /> % { setCurrentScale(displayNumber - 10 >= 0 ? displayNumber - 10 : 1) }} style={{ width: 32, height: 32 }}> ) } export default ScaleToolContainer