chore(crop): Remove invalid crop area message and related validation logic (#7160)

Co-authored-by: Anthony Stirling <77850077+Frooodle@users.noreply.github.com>
This commit is contained in:
brios
2026-08-29 23:11:41 +01:00
committed by GitHub
co-authored by Anthony Stirling
parent 74be5bf0ad
commit 0b7b4e02c2
45 changed files with 32 additions and 88 deletions
@@ -3526,7 +3526,6 @@ label = "إحداثي Y"
[crop.error]
failed = "فشل قصّ PDF"
invalidArea = "منطقة القص تتجاوز حدود PDF"
[crop.preview]
title = "معاينة منطقة القص"
@@ -3526,7 +3526,6 @@ label = "Y mövqeyi"
[crop.error]
failed = "PDF-i kəsmək alınmadı"
invalidArea = "Kəsmə sahəsi PDF sərhədlərini aşır"
[crop.preview]
title = "Kəsmə sahəsinin seçimi"
@@ -3526,7 +3526,6 @@ label = "Y позиция"
[crop.error]
failed = "Неуспешно изрязване на PDF"
invalidArea = "Областта за изрязване излиза извън границите на PDF"
[crop.preview]
title = "Избор на област за изрязване"
@@ -3526,7 +3526,6 @@ label = "Yཡི་གནས་བབ།"
[crop.error]
failed = "སོན་བཟང་མ་འདང་བ། PDF"
invalidArea = "སོན་འདེབས་རྒྱ་ཁྱོན་དེ་PDFམཚམས་ཐིག་ལས་བརྒལ་ཡོད།"
[crop.preview]
title = "སོན་བཟང་ཁུལ་འདེམས་པ།"
@@ -3526,7 +3526,6 @@ label = "Posició Y"
[crop.error]
failed = "No s'ha pogut retallar el PDF"
invalidArea = "L'àrea de retall s'estén més enllà dels límits del PDF"
[crop.preview]
title = "Selecció de l'àrea de retall"
@@ -3526,7 +3526,6 @@ label = "Pozice Y"
[crop.error]
failed = "Oříznutí PDF se nezdařilo"
invalidArea = "Oblast ořezu přesahuje hranice PDF"
[crop.preview]
title = "Výběr oblasti ořezu"
@@ -3526,7 +3526,6 @@ label = "Y-position"
[crop.error]
failed = "Kunne ikke beskære PDF"
invalidArea = "Beskæringsområdet strækker sig ud over PDF'ens grænser"
[crop.preview]
title = "Valg af beskæringsområde"
@@ -3526,7 +3526,6 @@ label = "Y-Position"
[crop.error]
failed = "PDF zuschneiden fehlgeschlagen"
invalidArea = "Zuschneidebereich überschreitet die PDF-Grenzen"
[crop.preview]
title = "Zuschneidebereich-Auswahl"
@@ -3526,7 +3526,6 @@ label = "Θέση Y"
[crop.error]
failed = "Αποτυχία περικοπής του PDF"
invalidArea = "Η περιοχή περικοπής εκτείνεται πέρα από τα όρια του PDF"
[crop.preview]
title = "Επιλογή περιοχής περικοπής"
@@ -3526,7 +3526,6 @@ label = "Y Position"
[crop.error]
failed = "Failed to crop PDF"
invalidArea = "Crop area extends beyond PDF boundaries"
[crop.preview]
title = "Crop Area Selection"
@@ -3846,7 +3846,6 @@ label = "Y Position"
[crop.error]
failed = "Failed to crop PDF"
invalidArea = "Crop area extends beyond PDF boundaries"
[crop.preview]
title = "Crop Area Selection"
@@ -3526,7 +3526,6 @@ label = "Posición Y"
[crop.error]
failed = "Error al recortar PDF"
invalidArea = "El área de recorte se extiende más allá de los límites del PDF"
[crop.preview]
title = "Selección de Área de Recorte"
@@ -3526,7 +3526,6 @@ label = "Y posizioa"
[crop.error]
failed = "Huts egin du PDFa mozteak"
invalidArea = "Mozketa-area PDFaren mugak baino harago doa"
[crop.preview]
title = "Mozketa-arearen hautapena"
@@ -3526,7 +3526,6 @@ label = "موقعیت Y"
[crop.error]
failed = "برش PDF ناموفق بود"
invalidArea = "ناحیه برش از مرزهای PDF فراتر رفته است"
[crop.preview]
title = "انتخاب ناحیه برش"
@@ -3526,7 +3526,6 @@ label = "Position Y"
[crop.error]
failed = "Échec du recadrage du PDF"
invalidArea = "La zone de recadrage dépasse les limites du PDF"
[crop.preview]
title = "Sélection de la zone de recadrage"
@@ -3526,7 +3526,6 @@ label = "Suíomh Y"
[crop.error]
failed = "Theip ar an PDF a bhearradh"
invalidArea = "Téann an limistéar bearrtha thar theorainneacha an PDF"
[crop.preview]
title = "Roghnú Limistéir Bhearrtha"
@@ -3526,7 +3526,6 @@ label = "Y स्थान"
[crop.error]
failed = "PDF क्रॉप करने में विफल"
invalidArea = "क्रॉप क्षेत्र PDF सीमाओं से बाहर जा रहा है"
[crop.preview]
title = "क्रॉप क्षेत्र चयन"
@@ -3526,7 +3526,6 @@ label = "Y položaj"
[crop.error]
failed = "Izrezivanje PDF-a nije uspjelo"
invalidArea = "Područje izrezivanja prelazi granice PDF-a"
[crop.preview]
title = "Odabir područja izrezivanja"
@@ -3526,7 +3526,6 @@ label = "Y pozíció"
[crop.error]
failed = "A PDF vágása sikertelen"
invalidArea = "A vágási terület túlnyúlik a PDF határain"
[crop.preview]
title = "Vágási terület kiválasztása"
@@ -3526,7 +3526,6 @@ label = "Posisi Y"
[crop.error]
failed = "Gagal memangkas PDF"
invalidArea = "Area pangkas melampaui batas PDF"
[crop.preview]
title = "Pilihan Area Pangkas"
@@ -3526,7 +3526,6 @@ label = "Posizione Y"
[crop.error]
failed = "Impossibile ritagliare il PDF"
invalidArea = "Larea di ritaglio supera i limiti del PDF"
[crop.preview]
title = "Selezione area di ritaglio"
@@ -3526,7 +3526,6 @@ label = "Y 位置"
[crop.error]
failed = "PDF の切り抜きに失敗しました"
invalidArea = "切り抜き範囲が PDF の境界を超えています"
[crop.preview]
title = "切り抜き範囲の選択"
@@ -3526,7 +3526,6 @@ label = "Y 위치"
[crop.error]
failed = "PDF 자르기에 실패했습니다"
invalidArea = "자르기 영역이 PDF 경계를 벗어났습니다"
[crop.preview]
title = "자르기 영역 선택"
@@ -3526,7 +3526,6 @@ label = "Y സ്ഥാനം"
[crop.error]
failed = "PDF ക്രോപ്പ് ചെയ്യാൻ കഴിഞ്ഞില്ല"
invalidArea = "ക്രോപ്പ് ഏരിയ PDF അതിരുകൾക്ക് പുറത്തേക്ക് നീളുന്നു"
[crop.preview]
title = "ക്രോപ്പ് ഏരിയ തിരഞ്ഞെടുപ്പ്"
@@ -3526,7 +3526,6 @@ label = "Y-positie"
[crop.error]
failed = "PDF bijsnijden mislukt"
invalidArea = "Bijsnijgebied valt buiten PDF-randen"
[crop.preview]
title = "Selectie bijsnijgebied"
@@ -3526,7 +3526,6 @@ label = "Y-posisjon"
[crop.error]
failed = "Kunne ikke beskjære PDF"
invalidArea = "Beskjæringsområdet går utenfor PDF-grensene"
[crop.preview]
title = "Valg av beskjæringsområde"
@@ -3526,7 +3526,6 @@ label = "Pozycja Y"
[crop.error]
failed = "Nie udało się przyciąć PDF"
invalidArea = "Obszar przycięcia wykracza poza granice PDF"
[crop.preview]
title = "Wybór obszaru przycięcia"
@@ -3526,7 +3526,6 @@ label = "Posição Y"
[crop.error]
failed = "Falha ao recortar o PDF"
invalidArea = "A área de corte se estende além dos limites do PDF"
[crop.preview]
title = "Seleção da área de corte"
@@ -3526,7 +3526,6 @@ label = "Posição Y"
[crop.error]
failed = "Falha ao recortar o PDF"
invalidArea = "A área de recorte excede os limites do PDF"
[crop.preview]
title = "Seleção da área de recorte"
@@ -3526,7 +3526,6 @@ label = "Poziția Y"
[crop.error]
failed = "Nu s-a putut decupa PDF-ul"
invalidArea = "Zona de decupare depășește limitele PDF-ului"
[crop.preview]
title = "Selecție zonă de decupare"
@@ -3526,7 +3526,6 @@ label = "Положение Y"
[crop.error]
failed = "Не удалось обрезать PDF"
invalidArea = "Область обрезки выходит за границы PDF"
[crop.preview]
title = "Выбор области обрезки"
@@ -3526,7 +3526,6 @@ label = "Pozícia Y"
[crop.error]
failed = "Nepodarilo sa orezať PDF"
invalidArea = "Oblasť orezania presahuje hranice PDF"
[crop.preview]
title = "Výber oblasti orezania"
@@ -3526,7 +3526,6 @@ label = "Položaj Y"
[crop.error]
failed = "Obrezovanje PDF-ja ni uspelo"
invalidArea = "Območje obrezovanja presega meje PDF-ja"
[crop.preview]
title = "Izbira območja obrezovanja"
@@ -3526,7 +3526,6 @@ label = "Y pozicija"
[crop.error]
failed = "Nije uspelo isecanje PDF-a"
invalidArea = "Oblast isečka prelazi granice PDF-a"
[crop.preview]
title = "Izbor oblasti za isecanje"
@@ -3526,7 +3526,6 @@ label = "Y-position"
[crop.error]
failed = "Det gick inte att beskära PDF"
invalidArea = "Beskärningsområdet sträcker sig utanför PDF:ens gränser"
[crop.preview]
title = "Val av beskärningsområde"
@@ -3526,7 +3526,6 @@ label = "ตำแหน่ง Y"
[crop.error]
failed = "ครอบตัด PDF ไม่สำเร็จ"
invalidArea = "พื้นที่ครอบตัดเกินขอบเขตของ PDF"
[crop.preview]
title = "การเลือกพื้นที่ครอบตัด"
@@ -3526,7 +3526,6 @@ label = "Y Konumu"
[crop.error]
failed = "PDF kırpılamadı"
invalidArea = "Kırpma alanı PDF sınırlarının dışına taşıyor"
[crop.preview]
title = "Kırpma Alanı Seçimi"
@@ -3526,7 +3526,6 @@ label = "Позиція Y"
[crop.error]
failed = "Не вдалося обрізати PDF"
invalidArea = "Область обрізки виходить за межі PDF"
[crop.preview]
title = "Вибір області обрізки"
@@ -3526,7 +3526,6 @@ label = "Vị trí Y"
[crop.error]
failed = "Không cắt được PDF"
invalidArea = "Vùng cắt vượt quá ranh giới PDF"
[crop.preview]
title = "Chọn vùng cắt"
@@ -3526,7 +3526,6 @@ label = "Y 位置"
[crop.error]
failed = "裁剪 PDF 失败"
invalidArea = "裁剪区域超出 PDF 边界"
[crop.preview]
title = "裁剪区域选择"
@@ -3526,7 +3526,6 @@ label = "Y 位置"
[crop.error]
failed = "裁剪 PDF 失败"
invalidArea = "裁剪区域超出 PDF 边界"
[crop.preview]
title = "裁剪区域选择"
@@ -3526,7 +3526,6 @@ label = "Y 位置"
[crop.error]
failed = "裁切 PDF 失敗"
invalidArea = "裁切區域超出 PDF 邊界"
[crop.preview]
title = "裁切區域選擇"
@@ -1,13 +1,5 @@
import { useState, useEffect } from "react";
import {
Stack,
Text,
Box,
Group,
Center,
Alert,
Checkbox,
} from "@mantine/core";
import { Stack, Text, Box, Group, Center, Checkbox } from "@mantine/core";
import { ActionIcon } from "@app/ui/ActionIcon";
import { useTranslation } from "react-i18next";
import RestartAltIcon from "@mui/icons-material/RestartAlt";
@@ -161,7 +153,6 @@ const CropSettings = ({ parameters, disabled = false }: CropSettingsProps) => {
);
}
const isCropValid = parameters.isCropAreaValid(pdfBounds);
const isFullCrop = parameters.isFullPDFCrop(pdfBounds);
return (
@@ -239,18 +230,6 @@ const CropSettings = ({ parameters, disabled = false }: CropSettingsProps) => {
showAutomationInfo={false}
/>
)}
{/* Validation Alert - Only show when autoCrop is false */}
{!parameters.parameters.autoCrop && !isCropValid && (
<Alert color="red" variant="light">
<Text size="xs">
{t(
"crop.error.invalidArea",
"Crop area extends beyond PDF boundaries",
)}
</Text>
</Alert>
)}
</Stack>
);
};
@@ -8,6 +8,7 @@ import {
Rectangle,
PDFBounds,
constrainCropAreaToPDF,
createDefaultCropArea,
createFullPDFCropArea,
roundCropArea,
isRectangle,
@@ -29,6 +30,8 @@ export type CropParametersHook = BaseParametersHook<CropParameters> & {
setCropArea: (cropArea: Rectangle, pdfBounds?: PDFBounds) => void;
/** Get current crop area as CropArea object */
getCropArea: () => Rectangle;
/** Reset to default inset crop area inside PDF bounds */
resetToDefaultCropArea: (pdfBounds: PDFBounds) => void;
/** Reset to full PDF dimensions */
resetToFullPDF: (pdfBounds: PDFBounds) => void;
/** Check if current crop area is valid for the PDF */
@@ -76,6 +79,15 @@ export const useCropParameters = (): CropParametersHook => {
[baseHook],
);
// Reset to default crop area inside PDF bounds (10% inset)
const resetToDefaultCropArea = useCallback(
(pdfBounds: PDFBounds) => {
const defaultCropArea = createDefaultCropArea(pdfBounds);
setCropArea(defaultCropArea);
},
[setCropArea],
);
// Reset to cover entire PDF
const resetToFullPDF = useCallback(
(pdfBounds: PDFBounds) => {
@@ -85,31 +97,11 @@ export const useCropParameters = (): CropParametersHook => {
[setCropArea],
);
// Check if current crop area is valid for the given PDF bounds
// Check if current crop area is valid (dimensions must be non-zero; out-of-bounds coordinates clamp automatically)
const isCropAreaValid = useCallback(
(pdfBounds?: PDFBounds): boolean => {
(_pdfBounds?: PDFBounds): boolean => {
const cropArea = getCropArea();
// Basic validation
if (
cropArea.x < 0 ||
cropArea.y < 0 ||
cropArea.width <= 0 ||
cropArea.height <= 0
) {
return false;
}
// PDF bounds validation if provided
if (pdfBounds) {
const tolerance = 0.01; // Small tolerance for floating point precision
return (
cropArea.x + cropArea.width <= pdfBounds.actualWidth + tolerance &&
cropArea.y + cropArea.height <= pdfBounds.actualHeight + tolerance
);
}
return true;
return cropArea.width > 0 && cropArea.height > 0;
},
[getCropArea],
);
@@ -174,6 +166,7 @@ export const useCropParameters = (): CropParametersHook => {
validateParameters: () => validateParameters(),
setCropArea,
getCropArea,
resetToDefaultCropArea,
resetToFullPDF,
isCropAreaValid,
isFullPDFCrop,
@@ -204,7 +204,21 @@ export const isPointInThumbnail = (
};
/**
* Create a default crop area that covers the entire PDF
* Create a default crop area inside PDF bounds (10% inset from each edge, centered)
*/
export const createDefaultCropArea = (pdfBounds: PDFBounds): Rectangle => {
const insetX = pdfBounds.actualWidth * 0.1;
const insetY = pdfBounds.actualHeight * 0.1;
return {
x: Math.round(insetX * 10) / 10,
y: Math.round(insetY * 10) / 10,
width: Math.round((pdfBounds.actualWidth - insetX * 2) * 10) / 10,
height: Math.round((pdfBounds.actualHeight - insetY * 2) * 10) / 10,
};
};
/**
* Create a crop area that covers the entire PDF
*/
export const createFullPDFCropArea = (pdfBounds: PDFBounds): Rectangle => {
return {