import Document, { DocumentContext, Head, Html, Main, NextScript, DocumentProps } from "next/document"; type Props = Record & DocumentProps; function toRunBeforeReactOnClient() { window.sessionStorage.setItem("calEmbedMode", String(location.search.includes("embed="))); window.isEmbed = () => { return window.sessionStorage.getItem("calEmbedMode") === "true"; }; window.getEmbedTheme = () => { const url = new URL(document.URL); return url.searchParams.get("theme") as "dark" | "light"; }; window.getEmbedNamespace = () => { const url = new URL(document.URL); const namespace = url.searchParams.get("embed"); return namespace; }; } class MyDocument extends Document { static async getInitialProps(ctx: DocumentContext) { const initialProps = await Document.getInitialProps(ctx); return { ...initialProps }; } render() { const { locale } = this.props.__NEXT_DATA__; const dir = locale === "ar" || locale === "he" ? "rtl" : "ltr"; return ( {/* Define isEmbed here so that it can be shared with App(embed-iframe) as well as the following code to change background and hide body Persist the embed mode in sessionStorage because query param might get lost during browsing. */}