fix: Embedded image aspect ratio in Super notes (#2075)
This commit is contained in:
@@ -20,6 +20,7 @@ const ImagePreview: FunctionComponent<Props> = ({
|
|||||||
imageZoomLevel,
|
imageZoomLevel,
|
||||||
setImageZoomLevel,
|
setImageZoomLevel,
|
||||||
}) => {
|
}) => {
|
||||||
|
const [imageWidth, setImageWidth] = useState(0)
|
||||||
const [imageHeight, setImageHeight] = useState<number>(0)
|
const [imageHeight, setImageHeight] = useState<number>(0)
|
||||||
const [imageZoomPercent, setImageZoomPercent] = useState(imageZoomLevel ? imageZoomLevel : DefaultZoomPercent)
|
const [imageZoomPercent, setImageZoomPercent] = useState(imageZoomLevel ? imageZoomLevel : DefaultZoomPercent)
|
||||||
const [isZoomInputVisible, setIsZoomInputVisible] = useState(false)
|
const [isZoomInputVisible, setIsZoomInputVisible] = useState(false)
|
||||||
@@ -40,24 +41,26 @@ const ImagePreview: FunctionComponent<Props> = ({
|
|||||||
const image = new Image()
|
const image = new Image()
|
||||||
image.src = objectUrl
|
image.src = objectUrl
|
||||||
image.onload = () => {
|
image.onload = () => {
|
||||||
|
setImageWidth(image.width)
|
||||||
setImageHeight(image.height)
|
setImageHeight(image.height)
|
||||||
}
|
}
|
||||||
}, [objectUrl])
|
}, [objectUrl])
|
||||||
|
|
||||||
const heightIfEmbedded = imageHeight * (imageZoomPercent / PercentageDivisor)
|
const widthIfEmbedded = imageWidth * (imageZoomPercent / PercentageDivisor)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="group flex h-full min-h-0 w-full items-center justify-center">
|
<div className="group flex h-full min-h-0 w-full items-center justify-center">
|
||||||
<div
|
<div
|
||||||
className="relative flex h-full w-full items-center justify-center overflow-auto"
|
className="relative flex h-full w-full items-center justify-center overflow-auto"
|
||||||
style={{
|
style={{
|
||||||
height: isEmbeddedInSuper ? `${heightIfEmbedded}px` : '',
|
width: isEmbeddedInSuper ? `${widthIfEmbedded}px` : '',
|
||||||
|
aspectRatio: isEmbeddedInSuper ? `${imageWidth} / ${imageHeight}` : '',
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<img
|
<img
|
||||||
src={objectUrl}
|
src={objectUrl}
|
||||||
style={{
|
style={{
|
||||||
height: isEmbeddedInSuper ? `${heightIfEmbedded}px` : `${imageZoomPercent}%`,
|
height: isEmbeddedInSuper ? '100%' : `${imageZoomPercent}%`,
|
||||||
...(isEmbeddedInSuper
|
...(isEmbeddedInSuper
|
||||||
? {}
|
? {}
|
||||||
: imageZoomPercent <= DefaultZoomPercent
|
: imageZoomPercent <= DefaultZoomPercent
|
||||||
|
|||||||
Reference in New Issue
Block a user