import { type FC, type ReactNode, useEffect, useRef } from "react" import { useLocation, Route as WouterRoute } from "wouter" import { cn } from "../../libs/utils" export type SlideProps = { index: number route?: boolean children?: ReactNode } export const Slide: FC = ({ index, route = true, children }) => { const ref = useRef(null) const [location] = useLocation() // biome-ignore lint/correctness/useExhaustiveDependencies: when scale changes, we need to update the transform useEffect(() => { const root = document.querySelector("[data-presentation-root]") ?? window const onResize = () => { if (!ref.current) return resize(ref.current, root) } onResize() const observer = new ResizeObserver(onResize) if (root instanceof HTMLElement) { observer.observe(root) } else { root.addEventListener("resize", onResize) } return () => { if (root instanceof HTMLElement) { observer.disconnect() } else { root.removeEventListener("resize", onResize) } } }, [location]) return (
{children}
) } type RouteProps = { route: boolean path: string children: ReactNode } const Route: FC = ({ route, path, children }) => route ? {children} : children const resize = (el: HTMLElement, root: HTMLElement | typeof window) => { const elWidth = el?.offsetWidth const elHeight = el?.offsetHeight const viewportWidth = root instanceof HTMLElement ? root.offsetWidth : root.innerWidth const viewportHeight = root instanceof HTMLElement ? root.offsetHeight : root.innerHeight const widthScale = viewportWidth / elWidth const heightScale = viewportHeight / elHeight const scale = Math.min(widthScale, heightScale) el?.style.setProperty("--slide-scale", scale.toString()) }