From 358eb6ad8eaf86fc96494f0e36216608e0023357 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 11 Apr 2023 02:00:42 +0200 Subject: [PATCH] ImageZoom Fixes --- src/plugins/imageZoom/components/Magnifier.tsx | 6 +++--- src/plugins/imageZoom/constants.ts | 2 +- src/plugins/imageZoom/index.tsx | 6 ++++-- src/plugins/imageZoom/styles.css | 15 ++++----------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/plugins/imageZoom/components/Magnifier.tsx b/src/plugins/imageZoom/components/Magnifier.tsx index e61c5602a..75bd2e104 100644 --- a/src/plugins/imageZoom/components/Magnifier.tsx +++ b/src/plugins/imageZoom/components/Magnifier.tsx @@ -36,7 +36,6 @@ export interface MagnifierProps { export const Magnifier: React.FC = ({ instance, size: initialSize, zoom: initalZoom }) => { const [ready, setReady] = useState(false); - const [lensPosition, setLensPosition] = useState({ x: 0, y: 0 }); const [imagePosition, setImagePosition] = useState({ x: 0, y: 0 }); const [opacity, setOpacity] = useState(0); @@ -157,7 +156,7 @@ export const Magnifier: React.FC = ({ instance, size: initialSiz return (
= ({ instance, size: initialSiz }} width={`${box.width * zoom.current}px`} height={`${box.height * zoom.current}px`} - src={instance.props.src} alt="" + src={instance.props.src} + alt="" /> )}
diff --git a/src/plugins/imageZoom/constants.ts b/src/plugins/imageZoom/constants.ts index cfde60cf5..adaa5bfc7 100644 --- a/src/plugins/imageZoom/constants.ts +++ b/src/plugins/imageZoom/constants.ts @@ -16,4 +16,4 @@ * along with this program. If not, see . */ -export const ELEMENT_ID = "magnify-modal"; +export const ELEMENT_ID = "vc-imgzoom-magnify-modal"; diff --git a/src/plugins/imageZoom/index.tsx b/src/plugins/imageZoom/index.tsx index 7a1887b91..6014756a2 100644 --- a/src/plugins/imageZoom/index.tsx +++ b/src/plugins/imageZoom/index.tsx @@ -16,10 +16,9 @@ * along with this program. If not, see . */ -import "./styles.css"; - import { addContextMenuPatch, NavContextMenuPatchCallback, removeContextMenuPatch } from "@api/ContextMenu"; import { definePluginSettings } from "@api/settings"; +import { disableStyle, enableStyle } from "@api/Styles"; import { makeRange } from "@components/PluginSettings/components"; import { Devs } from "@utils/constants"; import { debounce } from "@utils/debounce"; @@ -29,6 +28,7 @@ import type { Root } from "react-dom/client"; import { Magnifier, MagnifierProps } from "./components/Magnifier"; import { ELEMENT_ID } from "./constants"; +import styles from "./styles.css?managed"; export const settings = definePluginSettings({ saveZoomValues: { @@ -219,6 +219,7 @@ export default definePlugin({ }, start() { + enableStyle(styles); addContextMenuPatch("image-context", imageContextMenuPatch); this.element = document.createElement("div"); this.element.classList.add("MagnifierContainer"); @@ -226,6 +227,7 @@ export default definePlugin({ }, stop() { + disableStyle(styles); // so componenetWillUnMount gets called if Magnifier component is still alive this.root && this.root.unmount(); this.element?.remove(); diff --git a/src/plugins/imageZoom/styles.css b/src/plugins/imageZoom/styles.css index 47e8a16f4..219bf6bf1 100644 --- a/src/plugins/imageZoom/styles.css +++ b/src/plugins/imageZoom/styles.css @@ -1,4 +1,4 @@ -.lens { +.vc-imgzoom-lens { position: absolute; inset: 0; z-index: 9999; @@ -11,26 +11,19 @@ pointer-events: none; } -.zoom img { - position: absolute; - top: 50%; - left: 50%; - transform: translate(-50%, -50%); -} - /* make the carousel take up less space so we can click the backdrop and exit out of it */ -[class^="focusLock"] > [class^="carouselModal"] { +[class|="carouselModal"] { height: fit-content; box-shadow: none; } -[class^="focusLock"] > [class^="carouselModal"] > div { +[class*="modalCarouselWrapper"] { height: fit-content; top: 50%; transform: translateY(-50%); } -#magnify-modal { +[class|="wrapper"]:has(> #vc-imgzoom-magnify-modal) { position: absolute; left: 50%; top: 50%;