|
import { useEffect } from "react"; |
|
|
|
|
|
|
|
|
|
const usePageOrientation = () => { |
|
useEffect(() => { |
|
const updatePageOrientation = () => { |
|
const pages = document.querySelectorAll(".comic-page"); |
|
const styleEl = document.createElement("style"); |
|
|
|
|
|
document.head.appendChild(styleEl); |
|
|
|
|
|
const styleSheet = styleEl.sheet as CSSStyleSheet; |
|
|
|
if (pages.length >= 2) { |
|
styleSheet.insertRule("@page { size: landscape }", 0); |
|
} else { |
|
styleSheet.insertRule("@page { size: portrait }", 0); |
|
} |
|
}; |
|
|
|
|
|
updatePageOrientation(); |
|
|
|
|
|
window.addEventListener("resize", updatePageOrientation); |
|
|
|
|
|
return () => { |
|
window.removeEventListener("resize", updatePageOrientation); |
|
}; |
|
}, []); |
|
}; |
|
|
|
export default usePageOrientation; |