Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go
8.3 KB
Raw Blame
import type { Metadata, Viewport } from "next";
import Script from "next/script";
import { Inter, Geist_Mono, JetBrains_Mono, Source_Serif_4 } from "next/font/google";
import { ThemeProvider } from "@/components/theme-provider";
import { Toaster } from "@multica/ui/components/ui/sonner";
import { cn } from "@multica/ui/lib/utils";
import { WebProviders } from "@/components/web-providers";
import { getRequestLocale } from "@/lib/request-locale";
import { HTML_LANG } from "@/lib/html-lang";
import { SITE_TITLE, TITLE_TEMPLATE } from "@/platform/document-title";
import {
  resolveBrowserApiBaseUrl,
  resolveBrowserWsUrl,
  resolveDevRemoteApiUrl,
} from "@/config/runtime-urls";
import { resolveGoogleAnalyticsId } from "@/config/google-analytics";
import { GoogleAnalytics } from "@/components/google-analytics";
import "./globals.css";

// Inter is the Latin UI face. next/font produces a hashed family (`__Inter_xxx`)
// plus a synthetic size-adjusted fallback face to prevent FOUT layout shift —
// both are exposed under the `--font-inter` CSS variable.
//
// The full `--font-sans` stack (Inter + the per-locale CJK fallback chain) is
// assembled in static CSS in ./globals.css, not here: it must be overridable per
// `<html lang>` (Japanese Kanji are Han ideographs and need a Japanese-first CJK
// stack), and a hashed family name can only be referenced from CSS via a variable.
// Keeping the CJK chain in CSS also keeps it CSP-safe and in sync with the desktop
// app, which defines the same chain in apps/desktop/src/renderer/src/globals.css.
//
// Italic is loaded explicitly: `style` defaults to `["normal"]`, and without a real
// italic face the ~20 semantic italic labels (chat empty states, model-picker's
// "Managed by runtime", dashboard/squad placeholders) plus every markdown <em> and
// blockquote rendered as browser-synthesized oblique. Keep in sync with desktop's
// `@fontsource-variable/inter/opsz-italic.css` import.
//
// The `opsz` axis lets Inter draw each size with its own cut: 14px and below
// keep the open text design, while titles and headings get Inter Display's
// tighter spacing and finer details automatically (`font-optical-sizing: auto`
// is the CSS default). Keep in sync with desktop's `opsz.css` import.
const inter = Inter({
  subsets: ["latin"],
  style: ["normal", "italic"],
  axes: ["opsz"],
  variable: "--font-inter",
});
// Mono font has no explicit CJK fallback: CJK chars in code blocks are inherently
// non-aligned with a mono grid (Chinese is proportional), so listing CJK fonts
// here would falsely signal alignment guarantees. Browser default fallback handles
// the rare mixed case correctly. `--font-mono` itself is composed in
// ./globals.css so the Appearance code font can replace it without losing the
// Geist family, which the monospace UI font still uses.
const geistMono = Geist_Mono({
  subsets: ["latin"],
  variable: "--font-geist-mono",
});
// Optional code font from the Appearance settings. Not preloaded: the face is
// only fetched once something renders with it.
const jetbrainsMono = JetBrains_Mono({
  subsets: ["latin"],
  variable: "--font-jetbrains-mono",
  preload: false,
});
// Editorial serif used for onboarding headlines and the Appearance "Serif"
// font. Italic support for h1 em accents (e.g. "...on one shared board.").
// Only loaded on routes that render the font; layout-shift-prevention handled
// by next/font's synthetic fallback metrics, same as Inter. No `fallback`:
// next/font writes it into the variable, and the stacks built on it in
// ./globals.css differ in whether they may end with a generic family.
const sourceSerif = Source_Serif_4({
  subsets: ["latin"],
  style: ["normal", "italic"],
  variable: "--font-source-serif",
});

export const viewport: Viewport = {
  width: "device-width",
  initialScale: 1,
  // Draw under the camera, rounded corners and home indicator instead of
  // letterboxing the page inside the safe area. Without it iOS reports every
  // env(safe-area-inset-*) as 0. globals.css keeps content clear of those
  // regions.
  viewportFit: "cover",
  themeColor: [
    { media: "(prefers-color-scheme: light)", color: "#ffffff" },
    { media: "(prefers-color-scheme: dark)", color: "#05070b" },
  ],
};

export const metadata: Metadata = {
  metadataBase: new URL("https://www.multica.ai"),
  title: {
    default: SITE_TITLE,
    template: TITLE_TEMPLATE,
  },
  description:
    "Source-available platform that turns coding agents into real teammates. Assign tasks, track progress, compound skills.",
  icons: {
    icon: [{ url: "/favicon.svg", type: "image/svg+xml" }],
    shortcut: ["/favicon.svg"],
    // iOS never reads the manifest's icons for the home screen; it needs its
    // own opaque, full-bleed square and rounds the corners itself.
    apple: [{ url: "/icons/apple-touch-icon.png", sizes: "180x180" }],
  },
  // Home-screen behaviour: launch without browser chrome, and label the icon
  // "Multica" rather than the long SEO <title>. `capable` renders the
  // standardised `mobile-web-app-capable` tag — Next 16 no longer emits the
  // deprecated apple-prefixed spelling, so iOS standalone rides on the
  // manifest's `display` instead (honoured since iOS 16.4).
  appleWebApp: {
    capable: true,
    title: "Multica",
    // `default` keeps the web view below the status bar, which iOS paints in
    // the theme colour with legible text. `black-translucent` would put the
    // page under it too, but always draws the status text white, unreadable
    // on the light themes.
    statusBarStyle: "default",
  },
  openGraph: {
    type: "website",
    siteName: "Multica",
    locale: "en_US",
  },
  twitter: {
    card: "summary_large_image",
    site: "@multica_hq",
    creator: "@multica_hq",
  },
  alternates: {
    canonical: "/",
  },
  robots: {
    index: true,
    follow: true,
  },
};

export default async function RootLayout({
  children,
}: {
  children: React.ReactNode;
}) {
  const locale = await getRequestLocale();
  const apiBaseUrl = resolveBrowserApiBaseUrl(process.env);
  const wsUrl = resolveBrowserWsUrl(process.env);
  // Opt-in Google Analytics: omitted entirely unless GOOGLE_ANALYTICS_ID is set.
  const googleAnalyticsId = resolveGoogleAnalyticsId(process.env);
  // Dev toolbar: a status bar pinned to the bottom of the window. Opt-in per
  // developer with VITE_DEV_TOOLBAR=1, the same convention and var prefix as
  // react-grab below, so one variable enables it on web and desktop. Without
  // an explicit API URL the browser goes through the dev proxy, so the
  // toolbar reports the proxy's upstream.
  const devToolbarApiUrl =
    process.env.NODE_ENV === "development" && process.env.VITE_DEV_TOOLBAR
      ? apiBaseUrl || resolveDevRemoteApiUrl(process.env)
      : undefined;

  return (
    <html
      lang={HTML_LANG[locale]}
      suppressHydrationWarning
      className={cn("antialiased font-sans h-full", inter.variable, geistMono.variable, jetbrainsMono.variable, sourceSerif.variable)}
    >
      <body className="h-full overflow-hidden">
        {/*
          react-grab: dev-only element inspector. Hold ⌘C (Mac) / Ctrl+C and click
          any element to copy its source path + line + component stack for pasting
          to an AI. Opt-in per developer: only loads when VITE_REACT_GRAB is set in
          a local, gitignored apps/web/.env.local — it never activates for anyone
          else. Both guards are read server-side, so the <Script> is omitted from
          the HTML entirely unless you opted in. The VITE_ prefix is shared with the
          desktop renderer (apps/desktop/src/renderer/src/main.tsx), where Vite only
          exposes VITE_-prefixed vars to client code, so one var name covers both
          apps. See https://www.react-grab.com/
        */}
        {process.env.NODE_ENV === "development" && process.env.VITE_REACT_GRAB && (
          <Script
            src="//unpkg.com/react-grab/dist/index.global.js"
            crossOrigin="anonymous"
            strategy="beforeInteractive"
          />
        )}
        <ThemeProvider>
          <WebProviders
            locale={locale}
            apiBaseUrl={apiBaseUrl}
            wsUrl={wsUrl}
            devToolbarApiUrl={devToolbarApiUrl}
          >
            {children}
          </WebProviders>
          <Toaster />
        </ThemeProvider>
        {googleAnalyticsId && <GoogleAnalytics measurementId={googleAnalyticsId} />}
      </body>
    </html>
  );
}