Skip to content

Commit

Permalink
fix: SVG enlarge issue - refs 277454
Browse files Browse the repository at this point in the history
  • Loading branch information
dobri1408 authored Sep 19, 2024
1 parent e6ac5cd commit a4dace4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/Embed.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ function Embed({ data, screen, block }) {
}, [screen, mobile]);

useEffect(() => {
if (isSvg)
if (isSvg && data?.preview_image?.download) {
fetch(data.preview_image.download)
.then((res) => {
return res.text();
})
.then((res) => res.text())
.then((data) => {
setSVG(data);
});
})
.catch((_) => {});
}
}, [data, isSvg]);

useEffect(() => {
Expand Down
28 changes: 21 additions & 7 deletions src/Enlarge.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,32 @@ const Enlarge = ({ children, className, onClick, ref, block }) => {
)?.firstElementChild;

if (svg2) {
let modal = document.getElementsByClassName('enlarge-modal')?.[0];
let width = svg2.getAttribute('width');
let height = svg2.getAttribute('height');

svg2.setAttribute(
'viewBox',
`0 0 ${svg2.getAttribute('width')} ${svg2.getAttribute('height')}`,
);
if (!width || !height) {
const viewBox = svg2.getAttribute('viewBox');
if (viewBox) {
const viewBoxValues = viewBox.split(' ');
if (viewBoxValues.length === 4) {
width = viewBoxValues[2]; // width from viewBox
height = viewBoxValues[3]; // height from viewBox
}
}
}

svg2.setAttribute('height', modal.clientHeight - 10);
svg2.setAttribute('width', '100%');
if (width && height) {
svg2.setAttribute(
'viewBox',
`0 0 ${parseFloat(width)} ${parseFloat(height)}`,
);
svg2.setAttribute('height', '100%');
svg2.setAttribute('width', '100%');
}
}
}
}, [block, isOpen]);

return (
<div className="enlarge">
<button
Expand Down

0 comments on commit a4dace4

Please sign in to comment.