This repository has been archived by the owner on Mar 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hack-fix labels on safari when scrolling (#222)
Co-authored-by: danthe3rd <[email protected]>
- Loading branch information
Showing
4 changed files
with
49 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
|
||
export const IS_SAFARI = /^((?!chrome|android).)*safari/i.test(navigator.userAgent); | ||
|
||
export function redrawObject(fo: SVGForeignObjectElement) { | ||
const parent = fo.parentNode; | ||
parent.removeChild(fo); | ||
parent.appendChild(fo); | ||
|
||
} | ||
export function redrawAllForeignObjectsIfSafari() { | ||
if (!IS_SAFARI) { | ||
return; | ||
} | ||
const fo = document.getElementsByTagName("foreignObject"); | ||
Array.from(fo).forEach(redrawObject); | ||
} | ||
|
||
export function setupBrowserCompat(root: HTMLDivElement) { | ||
/** | ||
* Safari has a lot of trouble with foreignObjects inside canvas. Especially when we apply rotations, etc... | ||
* As it considers the parent of the objects inside the FO to be the canvas origin, and not the FO. | ||
* See https://stackoverflow.com/questions/51313873/svg-foreignobject-not-working-properly-on-safari | ||
* Applying the fix in the link above fixes their position upon scroll - we don't want that, so we | ||
* manually force-redraw them upon scroll. | ||
*/ | ||
if (IS_SAFARI) { | ||
root.addEventListener("wheel", redrawAllForeignObjectsIfSafari); | ||
} | ||
} |
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