mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-11-16 01:21:16 +01:00
tails fix
This commit is contained in:
parent
addaf797cb
commit
559ba3ccab
@ -28,6 +28,7 @@ import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined';
|
|||||||
import UploadIcon from '@mui/icons-material/Upload';
|
import UploadIcon from '@mui/icons-material/Upload';
|
||||||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
||||||
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
import ExpandLessIcon from '@mui/icons-material/ExpandLess';
|
||||||
|
import CloseIcon from '@mui/icons-material/Close';
|
||||||
import { Rnd } from 'react-rnd';
|
import { Rnd } from 'react-rnd';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -235,6 +236,7 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => {
|
|||||||
onLoadJson,
|
onLoadJson,
|
||||||
onSelectPage,
|
onSelectPage,
|
||||||
onGroupEdit,
|
onGroupEdit,
|
||||||
|
onGroupDelete,
|
||||||
onImageTransform,
|
onImageTransform,
|
||||||
onImageReset,
|
onImageReset,
|
||||||
onReset,
|
onReset,
|
||||||
@ -749,6 +751,7 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => {
|
|||||||
|
|
||||||
const renderGroupContainer = (
|
const renderGroupContainer = (
|
||||||
groupId: string,
|
groupId: string,
|
||||||
|
pageIndex: number,
|
||||||
isActive: boolean,
|
isActive: boolean,
|
||||||
isChanged: boolean,
|
isChanged: boolean,
|
||||||
content: React.ReactNode,
|
content: React.ReactNode,
|
||||||
@ -757,8 +760,10 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => {
|
|||||||
<Box
|
<Box
|
||||||
component="div"
|
component="div"
|
||||||
style={{
|
style={{
|
||||||
width: '100%',
|
width: 'calc(100% + 4px)',
|
||||||
height: '100%',
|
height: 'calc(100% + 6px)',
|
||||||
|
marginLeft: '-2px',
|
||||||
|
marginTop: '-3px',
|
||||||
outline: isActive
|
outline: isActive
|
||||||
? '2px solid var(--mantine-color-blue-5)'
|
? '2px solid var(--mantine-color-blue-5)'
|
||||||
: isChanged
|
: isChanged
|
||||||
@ -773,7 +778,8 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => {
|
|||||||
display: 'flex',
|
display: 'flex',
|
||||||
alignItems: 'flex-start',
|
alignItems: 'flex-start',
|
||||||
justifyContent: 'flex-start',
|
justifyContent: 'flex-start',
|
||||||
padding: 0,
|
padding: '3px 2px 3px 2px',
|
||||||
|
position: 'relative',
|
||||||
}}
|
}}
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
@ -787,6 +793,29 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{content}
|
{content}
|
||||||
|
{isActive && editingGroupId !== groupId && (
|
||||||
|
<ActionIcon
|
||||||
|
size="xs"
|
||||||
|
variant="filled"
|
||||||
|
color="red"
|
||||||
|
radius="xl"
|
||||||
|
style={{
|
||||||
|
position: 'absolute',
|
||||||
|
top: -8,
|
||||||
|
right: -8,
|
||||||
|
zIndex: 10,
|
||||||
|
cursor: 'pointer',
|
||||||
|
}}
|
||||||
|
onClick={(event) => {
|
||||||
|
event.stopPropagation();
|
||||||
|
onGroupDelete(pageIndex, groupId);
|
||||||
|
setActiveGroupId(null);
|
||||||
|
setEditingGroupId(null);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<CloseIcon style={{ fontSize: 12 }} />
|
||||||
|
</ActionIcon>
|
||||||
|
)}
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -1352,6 +1381,7 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => {
|
|||||||
<Box key={group.id} style={containerStyle}>
|
<Box key={group.id} style={containerStyle}>
|
||||||
{renderGroupContainer(
|
{renderGroupContainer(
|
||||||
group.id,
|
group.id,
|
||||||
|
group.pageIndex,
|
||||||
true,
|
true,
|
||||||
changed,
|
changed,
|
||||||
<div
|
<div
|
||||||
@ -1440,6 +1470,7 @@ const PdfJsonEditorView = ({ data }: PdfJsonEditorViewProps) => {
|
|||||||
<Box key={group.id} style={containerStyle}>
|
<Box key={group.id} style={containerStyle}>
|
||||||
{renderGroupContainer(
|
{renderGroupContainer(
|
||||||
group.id,
|
group.id,
|
||||||
|
group.pageIndex,
|
||||||
isActive,
|
isActive,
|
||||||
changed,
|
changed,
|
||||||
<div
|
<div
|
||||||
|
|||||||
@ -576,6 +576,16 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
|
|||||||
);
|
);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleGroupDelete = useCallback((pageIndex: number, groupId: string) => {
|
||||||
|
setGroupsByPage((previous) =>
|
||||||
|
previous.map((groups, idx) =>
|
||||||
|
idx !== pageIndex
|
||||||
|
? groups
|
||||||
|
: groups.map((group) => (group.id === groupId ? { ...group, text: '' } : group))
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleImageTransform = useCallback(
|
const handleImageTransform = useCallback(
|
||||||
(
|
(
|
||||||
pageIndex: number,
|
pageIndex: number,
|
||||||
@ -913,8 +923,9 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const textContent = await page.getTextContent();
|
const textContent = await page.getTextContent();
|
||||||
const maskMarginX = Math.max(0.45 * scale, 0.45);
|
const maskMarginX = 0;
|
||||||
const maskMarginY = Math.max(0.85 * scale, 0.85);
|
const maskMarginTop = 0;
|
||||||
|
const maskMarginBottom = Math.max(3 * scale, 3);
|
||||||
context.save();
|
context.save();
|
||||||
context.globalCompositeOperation = 'destination-out';
|
context.globalCompositeOperation = 'destination-out';
|
||||||
context.fillStyle = '#000000';
|
context.fillStyle = '#000000';
|
||||||
@ -931,8 +942,8 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
|
|||||||
const width = (item.width || 0) * viewport.scale + maskMarginX * 2;
|
const width = (item.width || 0) * viewport.scale + maskMarginX * 2;
|
||||||
const fontHeight = Math.hypot(c, d);
|
const fontHeight = Math.hypot(c, d);
|
||||||
const rawHeight = item.height ? item.height * viewport.scale : fontHeight;
|
const rawHeight = item.height ? item.height * viewport.scale : fontHeight;
|
||||||
const height = Math.max(rawHeight + maskMarginY * 2, fontHeight + maskMarginY * 2);
|
const height = Math.max(rawHeight + maskMarginTop + maskMarginBottom, fontHeight + maskMarginTop + maskMarginBottom);
|
||||||
const baselineOffset = height - maskMarginY;
|
const baselineOffset = height - maskMarginBottom;
|
||||||
|
|
||||||
context.save();
|
context.save();
|
||||||
context.translate(e, f);
|
context.translate(e, f);
|
||||||
@ -984,6 +995,7 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
|
|||||||
onLoadJson: handleLoadFile,
|
onLoadJson: handleLoadFile,
|
||||||
onSelectPage: handleSelectPage,
|
onSelectPage: handleSelectPage,
|
||||||
onGroupEdit: handleGroupTextChange,
|
onGroupEdit: handleGroupTextChange,
|
||||||
|
onGroupDelete: handleGroupDelete,
|
||||||
onImageTransform: handleImageTransform,
|
onImageTransform: handleImageTransform,
|
||||||
onImageReset: handleImageReset,
|
onImageReset: handleImageReset,
|
||||||
onReset: handleResetEdits,
|
onReset: handleResetEdits,
|
||||||
@ -1001,6 +1013,7 @@ const PdfJsonEditor = ({ onComplete, onError }: BaseToolProps) => {
|
|||||||
handleDownloadJson,
|
handleDownloadJson,
|
||||||
handleGeneratePdf,
|
handleGeneratePdf,
|
||||||
handleGroupTextChange,
|
handleGroupTextChange,
|
||||||
|
handleGroupDelete,
|
||||||
handleImageReset,
|
handleImageReset,
|
||||||
handleLoadFile,
|
handleLoadFile,
|
||||||
handleResetEdits,
|
handleResetEdits,
|
||||||
|
|||||||
@ -199,6 +199,7 @@ export interface PdfJsonEditorViewData {
|
|||||||
onLoadJson: (file: File | null) => Promise<void> | void;
|
onLoadJson: (file: File | null) => Promise<void> | void;
|
||||||
onSelectPage: (pageIndex: number) => void;
|
onSelectPage: (pageIndex: number) => void;
|
||||||
onGroupEdit: (pageIndex: number, groupId: string, value: string) => void;
|
onGroupEdit: (pageIndex: number, groupId: string, value: string) => void;
|
||||||
|
onGroupDelete: (pageIndex: number, groupId: string) => void;
|
||||||
onImageTransform: (
|
onImageTransform: (
|
||||||
pageIndex: number,
|
pageIndex: number,
|
||||||
imageId: string,
|
imageId: string,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user