export function isLocalWorkspaceHost(hostname: string) { return ( hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1" || hostname === "0.0.0.0" ); } export function isWorkspaceModeLocation(location: Pick & { search?: string }) { if (!isLocalWorkspaceHost(location.hostname)) return false; if (new URLSearchParams(location.search ?? "").has("reader")) return false; const pathname = normalizePathname(location.pathname); if (pathname === "workspace") return true; const segments = pathname.split("/").filter(Boolean); return segments.length === 2 && segments[1] === "preview"; } export function isPresentationModeLocation(location: Pick) { if (!isLocalWorkspaceHost(location.hostname)) return false; const pathname = normalizePathname(location.pathname); const segments = pathname.split("/").filter(Boolean); return segments.length === 2 && segments[1] === "present"; } export function isPrintModeLocation(location: Pick) { return new URLSearchParams(location.search).has("print"); } function normalizePathname(pathname: string) { return pathname.replace(/^\/+|\/+$/g, ""); }