import Lenis from "lenis"; import "lenis/dist/lenis.css"; import { REPO, chapters, componentCount, storyCount } from "./data"; import { icon } from "./icons"; import { preview } from "./preview"; import { onMode } from "./theme"; const FEATURED = { page: "forms", story: "input-textfield-clearableinput", title: "Input / TextField · ClearableInput" }; /** Folding tiles, a few facts, one component live. */ export function home(main: HTMLElement): () => void { document.title = "Ely · GPUI components"; main.innerHTML = ` Ely, a component library for GPUI.Every one of them runs here, live. ${componentCount} components in ${chapters.length} chapters, in light and dark, written in Rust and compiled to WebAssembly for this page. Browse components ${icon("ArrowRight")} ${icon("GitHub")}GitHub In numbers One crate, one theme, every part tested at 280 pixels wide. ${storyCount}stories, each its own page ${chapters.length}chapters, from primitives to maps 2modes, light and dark, from one palette 0screenshots: what you see is running Try one A text field, live. Type in it. `; const still = matchMedia("(prefers-reduced-motion: reduce)").matches; const lenis = still ? null : new Lenis({ autoRaf: true, anchors: true }); const hero = main.querySelector(".hero")!; // The pinned hero folds as it scrolls. const fold = () => Math.min(1, Math.max(0, scrollY / Math.max(hero.offsetHeight - innerHeight, 1))); let stops: Array<() => void> = []; let sceneStop = () => {}; // three.js loads only here. import("./scene").then(({ scene }) => { if (!hero.isConnected) return; const s = scene(main.querySelector("canvas")!, fold, still); sceneStop = s.stop; stops.push(onMode(() => s.paint())); }); const stage = main.querySelector(".home-stage")!; const lazy = new IntersectionObserver(([entry]) => { if (!entry.isIntersecting) return; lazy.disconnect(); stops.push(preview(stage, FEATURED.page, FEATURED.story, FEATURED.title)); }, { rootMargin: "200px" }); lazy.observe(stage); return () => { lenis?.destroy(); lazy.disconnect(); sceneStop(); stops.forEach((stop) => stop()); stops = []; }; }
${componentCount} components in ${chapters.length} chapters, in light and dark, written in Rust and compiled to WebAssembly for this page.