/*
Copyright (C) 2025 QuantumNous
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
For commercial licensing, please contact support@quantumnous.com
*/
import React, { useState, useCallback, useEffect } from 'react';
import { Modal } from '@douyinfe/semi-ui';
import { Download, ZoomIn, ZoomOut, X, RotateCw } from 'lucide-react';
const ImagePreviewModal = ({ visible, imageUrl, onClose }) => {
const [scale, setScale] = useState(1);
useEffect(() => {
setScale(1);
}, [imageUrl]);
const handleZoomIn = () => setScale((s) => Math.min(s + 0.25, 3));
const handleZoomOut = () => setScale((s) => Math.max(s - 0.25, 0.25));
const handleResetZoom = () => setScale(1);
const handleDownload = useCallback(async () => {
try {
const response = await fetch(imageUrl);
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `image-${Date.now()}.png`;
document.body.appendChild(link);
link.click();
requestAnimationFrame(() => {
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
});
} catch {
window.open(imageUrl, '_blank');
}
}, [imageUrl]);
const handleClose = useCallback(() => {
setScale(1);
onClose();
}, [onClose]);
if (!imageUrl) return null;
const btnClass =
'w-9 h-9 flex items-center justify-center rounded-lg bg-white/10 hover:bg-white/20 text-white/80 hover:text-white transition-all';
return (
{/* Toolbar — 顶部安全区(刘海屏 / 状态栏)和左右安全区都用 env() 兜底,
没有刘海的设备拿到的是 0,行为一致 */}