-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
76c1a4e
commit e143a54
Showing
7 changed files
with
52 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,35 @@ | ||
import "./SvgPanZoomUi.css"; | ||
import { SvgPanZoomUi } from "svg-pan-zoom-gesture"; | ||
|
||
// @ts-expect-error | ||
const theme = document.querySelector("html")!.attributes["data-theme"]?.value; | ||
|
||
const themeSelector = document.querySelector( | ||
"starlight-theme-select select" | ||
) as HTMLSelectElement; | ||
|
||
document.querySelectorAll(".beoe").forEach((container) => { | ||
const svg = container.querySelector("svg"); | ||
const img = container.querySelector(`img.beoe-${theme.toString()}`); | ||
if (!svg && !img) return; | ||
|
||
// @ts-expect-error | ||
new SvgPanZoomUi({ element: container.querySelector("svg"), container }).on(); | ||
let instance = new SvgPanZoomUi({ element: svg || img, container }); | ||
instance.on(); | ||
|
||
// workaround for selector based dark mode - when there are 2 images. I don't like it | ||
// maybe allow to pass array to element? | ||
// TODO: `off()` needs to reset zoom level | ||
if (img && themeSelector) { | ||
themeSelector.addEventListener("change", () => { | ||
instance.off(); | ||
const theme = | ||
// @ts-expect-error | ||
document.querySelector("html")!.attributes["data-theme"]?.value; | ||
const img = container.querySelector(`img.beoe-${theme.toString()}`); | ||
// @ts-expect-error | ||
instance = new SvgPanZoomUi({ element: img, container }); | ||
instance.on(); | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters