2021-03-26 04:17:02 +04:30
|
|
|
/*
|
|
|
|
|
* Copyright (C) Contributors to the Suwayomi project
|
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
2021-03-18 21:46:24 +03:30
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
2023-05-18 13:17:41 +02:00
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
2021-03-18 21:46:24 +03:30
|
|
|
|
2024-03-08 00:24:01 +01:00
|
|
|
import { CSSProperties, forwardRef } from 'react';
|
2023-06-04 21:08:39 +02:00
|
|
|
import Box from '@mui/material/Box';
|
2024-01-26 11:51:08 -08:00
|
|
|
import { useTheme } from '@mui/material/styles';
|
2024-04-14 15:50:12 +02:00
|
|
|
import useMediaQuery from '@mui/material/useMediaQuery';
|
2024-01-21 13:33:13 -08:00
|
|
|
import { IReaderSettings, ReaderType } from '@/typings';
|
2023-10-28 00:32:02 +02:00
|
|
|
import { SpinnerImage } from '@/components/util/SpinnerImage';
|
2021-03-18 21:46:24 +03:30
|
|
|
|
2024-01-26 11:51:08 -08:00
|
|
|
export const isHorizontalReaderType = (readerType: ReaderType): boolean =>
|
|
|
|
|
['ContinuesHorizontalLTR', 'ContinuesHorizontalRTL'].includes(readerType);
|
2024-01-21 13:33:13 -08:00
|
|
|
|
2024-03-08 00:24:01 +01:00
|
|
|
export function imageStyle(settings: IReaderSettings): CSSProperties {
|
2024-02-21 02:42:07 +01:00
|
|
|
const isVertical = settings.readerType === 'ContinuesVertical';
|
2024-01-26 11:51:08 -08:00
|
|
|
const isHorizontal = isHorizontalReaderType(settings.readerType);
|
2024-03-08 00:24:01 +01:00
|
|
|
const baseStyling: CSSProperties = {
|
2024-02-21 02:42:07 +01:00
|
|
|
margin: 0,
|
2024-02-17 00:41:37 +01:00
|
|
|
width: `${settings.readerWidth}%`,
|
2024-01-26 11:51:08 -08:00
|
|
|
objectFit: 'contain',
|
2021-05-28 05:36:55 -07:00
|
|
|
};
|
2024-02-21 02:42:07 +01:00
|
|
|
|
2024-03-08 00:24:01 +01:00
|
|
|
const continuesVerticalStyling: CSSProperties = {
|
2024-02-21 02:42:07 +01:00
|
|
|
marginBottom: '15px',
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-08 00:24:01 +01:00
|
|
|
const continuesHorizontalStyling: CSSProperties = {
|
2024-02-21 02:42:07 +01:00
|
|
|
width: undefined,
|
|
|
|
|
minHeight: '100vh',
|
|
|
|
|
maxHeight: '100vh',
|
|
|
|
|
marginLeft: '7px',
|
|
|
|
|
marginRight: '7px',
|
|
|
|
|
};
|
|
|
|
|
|
2024-03-08 00:24:01 +01:00
|
|
|
const fitToPageStyling: CSSProperties = {
|
2024-02-21 02:42:07 +01:00
|
|
|
width: undefined,
|
|
|
|
|
height: undefined,
|
|
|
|
|
minWidth: settings.scalePage ? 'calc(100vw - (100vw - 100%))' : undefined,
|
|
|
|
|
maxWidth: 'calc(100vw - (100vw - 100%))',
|
|
|
|
|
minHeight: settings.scalePage ? '100vh' : undefined,
|
|
|
|
|
maxHeight: '100vh',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...baseStyling,
|
|
|
|
|
...(isHorizontal ? continuesHorizontalStyling : undefined),
|
|
|
|
|
...(isVertical ? continuesVerticalStyling : undefined),
|
|
|
|
|
...(settings.fitPageToWindow && !isHorizontal ? fitToPageStyling : undefined),
|
|
|
|
|
};
|
2021-05-28 05:36:55 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-18 21:46:24 +03:30
|
|
|
interface IProps {
|
2023-02-06 10:06:33 +01:00
|
|
|
src: string;
|
|
|
|
|
index: number;
|
|
|
|
|
onImageLoad: () => void;
|
|
|
|
|
settings: IReaderSettings;
|
2021-03-18 21:46:24 +03:30
|
|
|
}
|
|
|
|
|
|
2023-10-28 00:32:02 +02:00
|
|
|
export const Page = forwardRef((props: IProps, ref: any) => {
|
2023-02-06 10:06:33 +01:00
|
|
|
const { src, index, onImageLoad, settings } = props;
|
2021-03-23 03:50:55 +04:30
|
|
|
|
2024-01-26 11:51:08 -08:00
|
|
|
const theme = useTheme();
|
|
|
|
|
const isMobileWidth = useMediaQuery(theme.breakpoints.down('md'));
|
|
|
|
|
|
2021-12-01 03:06:06 +03:30
|
|
|
const imgStyle = imageStyle(settings);
|
2024-01-26 11:51:08 -08:00
|
|
|
const isDoublePageReader = ['DoubleRTL', 'DoubleLTR'].includes(settings.readerType);
|
2021-12-01 03:06:06 +03:30
|
|
|
|
2021-03-18 21:46:24 +03:30
|
|
|
return (
|
2024-01-26 11:51:08 -08:00
|
|
|
<Box
|
|
|
|
|
ref={ref}
|
2024-02-21 02:32:09 +01:00
|
|
|
sx={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
alignItems: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
minWidth: isDoublePageReader ? '100%' : undefined,
|
|
|
|
|
}}
|
2024-01-26 11:51:08 -08:00
|
|
|
>
|
2021-05-28 19:37:26 +04:30
|
|
|
<SpinnerImage
|
2023-05-18 13:25:19 +02:00
|
|
|
src={src}
|
2021-05-28 05:36:55 -07:00
|
|
|
onImageLoad={onImageLoad}
|
2021-05-28 19:37:26 +04:30
|
|
|
alt={`Page #${index}`}
|
2021-12-01 03:06:06 +03:30
|
|
|
spinnerStyle={{
|
|
|
|
|
...imgStyle,
|
|
|
|
|
height: '100vh',
|
2024-03-01 18:27:35 +01:00
|
|
|
// eslint-disable-next-line no-nested-ternary
|
|
|
|
|
width: isMobileWidth
|
|
|
|
|
? '100vw'
|
|
|
|
|
: isHorizontalReaderType(settings.readerType)
|
|
|
|
|
? '50vw'
|
|
|
|
|
: 'calc(100% * 0.5)',
|
2021-12-01 03:06:06 +03:30
|
|
|
backgroundColor: '#525252',
|
|
|
|
|
}}
|
|
|
|
|
imgStyle={imgStyle}
|
2021-05-15 18:26:40 +04:30
|
|
|
/>
|
2021-12-01 03:06:06 +03:30
|
|
|
</Box>
|
2021-03-18 21:46:24 +03:30
|
|
|
);
|
2021-05-18 02:26:45 +04:30
|
|
|
});
|