mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-02 08:15:56 +01:00
Merge pull request #304973 from yogeshwaran-c/fix/svg-zoom-no-dimensions-v2
fix: enable zoom for SVGs without explicit width/height dimensions
This commit is contained in:
@@ -89,6 +89,9 @@
|
||||
image.classList.remove('pixelated');
|
||||
// @ts-ignore Non-standard CSS property
|
||||
image.style.zoom = 'normal';
|
||||
// Clear explicit dimensions so the image can scale-to-fit naturally
|
||||
image.style.minWidth = '';
|
||||
image.style.minHeight = '';
|
||||
vscode.setState(undefined);
|
||||
} else {
|
||||
scale = clamp(newScale, MIN_SCALE, MAX_SCALE);
|
||||
@@ -102,6 +105,17 @@
|
||||
const dy = (window.scrollY + container.clientHeight / 2) / container.scrollHeight;
|
||||
|
||||
image.classList.remove('scale-to-fit');
|
||||
|
||||
// For images without intrinsic dimensions (e.g. SVGs with only
|
||||
// a viewBox), set explicit pixel dimensions so that CSS zoom has
|
||||
// something concrete to scale.
|
||||
if (!image.naturalWidth || !image.naturalHeight) {
|
||||
const baseWidth = image.clientWidth || container.clientWidth;
|
||||
const baseHeight = image.clientHeight || container.clientHeight;
|
||||
image.style.minWidth = baseWidth + 'px';
|
||||
image.style.minHeight = baseHeight + 'px';
|
||||
}
|
||||
|
||||
// @ts-ignore Non-standard CSS property
|
||||
image.style.zoom = scale;
|
||||
|
||||
@@ -142,7 +156,14 @@
|
||||
return;
|
||||
}
|
||||
|
||||
scale = image.clientWidth / image.naturalWidth;
|
||||
if (image.naturalWidth) {
|
||||
scale = image.clientWidth / image.naturalWidth;
|
||||
} else {
|
||||
// For images without intrinsic dimensions (e.g. SVGs with
|
||||
// only a viewBox), start at 1x since there is no meaningful
|
||||
// natural size to compute a ratio from.
|
||||
scale = 1;
|
||||
}
|
||||
updateScale(scale);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user