feat(clipboard): adiciona funcionalidade de copiar imagem transformada para a área de transferência
continuous-integration/webhook Deploy concluído (VPS4)

This commit is contained in:
VPS 4 Deploy Agent
2026-06-01 01:30:18 +02:00
parent 52fe81f1cd
commit 1dbdcfdb58
@@ -246,6 +246,49 @@ export default function ImageDetailsPage() {
img.src = url;
};
const copyImageToClipboard = () => {
const url = imageUrl;
const img = new Image();
img.crossOrigin = 'anonymous';
img.onload = () => {
try {
const w = img.naturalWidth, h = img.naturalHeight;
const deg = totalRotation;
const fH = baseFlipH;
const fV = baseFlipV;
const rad = (deg * Math.PI) / 180;
const cos = Math.abs(Math.cos(rad)), sin = Math.abs(Math.sin(rad));
const cw = Math.round(w * cos + h * sin);
const ch = Math.round(w * sin + h * cos);
const canvas = document.createElement('canvas');
canvas.width = cw; canvas.height = ch;
const ctx = canvas.getContext('2d');
ctx.translate(cw / 2, ch / 2);
ctx.scale(fH ? -1 : 1, fV ? -1 : 1);
ctx.rotate(rad);
ctx.drawImage(img, -w / 2, -h / 2);
canvas.toBlob(async (blob) => {
try {
await navigator.clipboard.write([
new ClipboardItem({
'image/png': blob
})
]);
showToast('Imagem copiada para a área de transferência!', 'success');
} catch (err) {
showToast('Erro ao copiar imagem para clipboard.', 'error');
console.error(err);
}
}, 'image/png');
} catch (e) {
showToast('Erro ao processar imagem para cópia.', 'error');
console.error(e);
}
};
img.onerror = () => showToast('Erro ao carregar imagem para cópia.', 'error');
img.src = url;
};
const markGtoSent = async (gtoId, sent) => {
try {
await api.post(`/gtos/${gtoId}/sent`, { sent });
@@ -502,6 +545,14 @@ export default function ImageDetailsPage() {
>
{saving ? '⏳ Salvando Alterações...' : '💾 Salvar'}
</button>
<button
type="button"
className="btn btn-secondary"
onClick={copyImageToClipboard}
style={{ width: '100%', height: 44, marginTop: 12, fontSize: '1rem', fontWeight: 600, display: 'flex', gap: 8, alignItems: 'center', justifyContent: 'center' }}
>
📋 Copiar Imagem (Área de Transferência)
</button>
</div>
</div>
</div>