import opencodeWordmarkDark from "../asset/logo-ornate-dark.svg" import { query } from "@solidjs/router" import { createEffect, createMemo, createSignal, For, onCleanup, onMount, Show } from "solid-js" export type HeaderLink = { href: string; label: string } export const headerLinks = [ { href: "#top-models", label: "Top Models" }, { href: "#leaderboard", label: "Leaderboard" }, { href: "#session-cost", label: "Session Cost" }, { href: "#token-cost", label: "Token Cost" }, { href: "#cache-ratio", label: "Cache Ratio" }, { href: "#market-share", label: "Market Share" }, { href: "#geo-breakdown", label: "Geo Breakdown" }, ] as const export const githubLink = { href: "https://github.com/anomalyco/opencode", apiHref: "https://api.github.com/repos/anomalyco/opencode", label: "GitHub", fallbackStars: "150K", ariaLabel: "Star OpenCode on GitHub", } export const themePreferences = ["dark", "light", "system"] as const export const themeStorageKey = "opencode:stats-theme" export type ThemePreference = (typeof themePreferences)[number] const compactNumberFormatter = new Intl.NumberFormat("en", { notation: "compact", maximumFractionDigits: 1, }) const themePreferenceLabels = { dark: "Dark", light: "Light", system: "System", } as const export const getGitHubStars = query(async () => { "use server" return fetch(githubLink.apiHref, { headers: { Accept: "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28", }, }) .then((response) => (response.ok ? response.json() : undefined)) .then((body: unknown) => body && typeof body === "object" && "stargazers_count" in body && typeof body.stargazers_count === "number" ? compactNumberFormatter.format(body.stargazers_count) : githubLink.fallbackStars, ) .catch(() => githubLink.fallbackStars) }, "getGitHubStars") export function isThemePreference(value: string | null): value is ThemePreference { return value === "dark" || value === "light" || value === "system" } export function applyThemePreference(preference: ThemePreference) { if (typeof document === "undefined") return document.documentElement.dataset.statsTheme = preference if (preference === "system") { document.documentElement.style.removeProperty("color-scheme") return } document.documentElement.style.setProperty("color-scheme", preference) } export function Header(props: { githubStars: string; links?: readonly HeaderLink[]; brandHref?: string }) { const [menuOpen, setMenuOpen] = createSignal(false) const [menuViewport, setMenuViewport] = createSignal(false) const links = createMemo(() => props.links ?? headerLinks) createEffect(() => { if (typeof window === "undefined") return const media = window.matchMedia("(max-width: 89.999rem)") const update = () => setMenuViewport(media.matches) update() media.addEventListener("change", update) onCleanup(() => media.removeEventListener("change", update)) }) createEffect(() => { if (!menuOpen()) return if (!menuViewport()) return if (typeof document === "undefined") return const page = document.querySelector('[data-page="stats"]') const scrollbarWidth = window.innerWidth - document.documentElement.clientWidth const htmlOverflow = document.documentElement.style.overflow const pagePaddingRight = page?.style.paddingRight const bodyOverflow = document.body.style.overflow document.documentElement.style.overflow = "hidden" if (scrollbarWidth > 0 && page) page.style.paddingRight = `${scrollbarWidth}px` document.body.style.overflow = "hidden" onCleanup(() => { document.documentElement.style.overflow = htmlOverflow if (page && pagePaddingRight !== undefined) page.style.paddingRight = pagePaddingRight document.body.style.overflow = bodyOverflow }) }) return (
{githubLink.label} [{props.githubStars}] Try OpenCode
) } function DataWordmark() { return ( ) } function OpenCodeMark() { return ( ) } export function Footer(props: { themePreference: ThemePreference onThemePreferenceChange: (preference: ThemePreference) => void links?: readonly HeaderLink[] }) { const [subscribeOpen, setSubscribeOpen] = createSignal(false) const modelStats = props.links ?? [ { href: "#top-models", label: "Top Models" }, { href: "#leaderboard", label: "Leaderboard" }, { href: "#session-cost", label: "Session Cost" }, { href: "#token-cost", label: "Token Cost" }, { href: "#cache-ratio", label: "Cache Ratio" }, { href: "#market-share", label: "Market Share" }, { href: "#geo-breakdown", label: "Geo Breakdown" }, ] const legal = [ { href: "https://opencode.ai/legal/terms-of-service", label: "Terms of service" }, { href: "https://opencode.ai/legal/privacy-policy", label: "Privacy policy" }, ] const connect = [ { href: "mailto:hello@opencode.ai", label: "Contact us" }, { href: "https://opencode.ai/discord", label: "Community" }, { href: "https://x.com/opencode", label: "X" }, githubLink, { href: "https://www.youtube.com/@anomaly-co", label: "YouTube" }, ] return ( ) } function SectionBridge(props: { label: string; href: string }) { return ( LEAN MORE {props.label} ) } function ThemePreferenceIcon(props: { preference: ThemePreference }) { return ( ) } function SubscribeModal(props: { onClose: () => void }) { const [status, setStatus] = createSignal<"idle" | "pending" | "success" | "error">("idle") const [message, setMessage] = createSignal("") let input: HTMLInputElement | undefined onMount(() => { if (typeof document === "undefined") return const activeElement = document.activeElement instanceof HTMLElement ? document.activeElement : undefined const htmlOverflow = document.documentElement.style.overflow const bodyOverflow = document.body.style.overflow document.documentElement.style.overflow = "hidden" document.body.style.overflow = "hidden" const focusTimeout = window.setTimeout(() => input?.focus(), 0) const onKeyDown = (event: KeyboardEvent) => { if (event.key === "Escape") props.onClose() } document.addEventListener("keydown", onKeyDown) onCleanup(() => { window.clearTimeout(focusTimeout) document.documentElement.style.overflow = htmlOverflow document.body.style.overflow = bodyOverflow document.removeEventListener("keydown", onKeyDown) activeElement?.focus() }) }) return (
) } function newsletterErrorMessage(response: Response) { return response.json().then( (body: unknown) => body && typeof body === "object" && "error" in body && typeof body.error === "string" ? body.error : "Failed to subscribe", () => "Failed to subscribe", ) } function FooterColumn(props: { title: string; links: readonly { href: string; label: string }[] }) { return (

{props.title}

) }