From 173f73407eb38e87564564d0c016917bc3c3dad6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 1 Dec 2026 20:33:14 +0000 Subject: [PATCH 1/3] feat(studio): add Desktop app showcase card, Catalog upsell, and Desktop header --- .../OpenInDesktopButton.dom.test.tsx | 152 ++-- .../src/components/OpenInDesktopButton.tsx | 272 ++++++-- .../src/components/StudioHeader.dom.test.tsx | 9 + .../studio/src/components/StudioHeader.tsx | 8 +- .../desktop-card/CatalogDesktopUpsell.tsx | 249 +++++++ .../desktop-card/DesktopAppCard.tsx | 221 ++++++ .../desktop-card/DesktopAppCardStage.tsx | 345 ++++++++++ .../desktop-card/DesktopInstallPill.tsx | 310 +++++++++ .../components/desktop-card/agentBrands.tsx | 144 ++++ .../src/components/desktop-card/auroraRing.ts | 410 +++++++++++ .../components/desktop-card/auroraTables.ts | 231 +++++++ .../desktop-card/cardChoreography.ts | 394 +++++++++++ .../src/components/desktop-card/cardMedia.ts | 81 +++ .../desktop-card/cardScenePlayers.ts | 420 ++++++++++++ .../components/desktop-card/cardStageTypes.ts | 89 +++ .../desktop-card/desktopCard.test.tsx | 209 ++++++ .../desktop-card/desktopCardStore.ts | 197 ++++++ .../editor/PropertyPanelEmptyState.tsx | 137 ++++ .../src/components/sidebar/BlocksTab.tsx | 7 +- .../src/components/ui/HyperframesLogo.tsx | 161 ++--- packages/studio/src/styles/components.css | 649 +++++++++++++++++- packages/studio/src/styles/theme.css | 145 ++++ 22 files changed, 4599 insertions(+), 241 deletions(-) create mode 100644 packages/studio/src/components/desktop-card/CatalogDesktopUpsell.tsx create mode 100644 packages/studio/src/components/desktop-card/DesktopAppCard.tsx create mode 100644 packages/studio/src/components/desktop-card/DesktopAppCardStage.tsx create mode 100644 packages/studio/src/components/desktop-card/DesktopInstallPill.tsx create mode 100644 packages/studio/src/components/desktop-card/agentBrands.tsx create mode 100644 packages/studio/src/components/desktop-card/auroraRing.ts create mode 100644 packages/studio/src/components/desktop-card/auroraTables.ts create mode 100644 packages/studio/src/components/desktop-card/cardChoreography.ts create mode 100644 packages/studio/src/components/desktop-card/cardMedia.ts create mode 100644 packages/studio/src/components/desktop-card/cardScenePlayers.ts create mode 100644 packages/studio/src/components/desktop-card/cardStageTypes.ts create mode 100644 packages/studio/src/components/desktop-card/desktopCard.test.tsx create mode 100644 packages/studio/src/components/desktop-card/desktopCardStore.ts diff --git a/packages/studio/src/components/OpenInDesktopButton.dom.test.tsx b/packages/studio/src/components/OpenInDesktopButton.dom.test.tsx index 5a0e2fdf38d..d7ef72fa704 100644 --- a/packages/studio/src/components/OpenInDesktopButton.dom.test.tsx +++ b/packages/studio/src/components/OpenInDesktopButton.dom.test.tsx @@ -1,8 +1,9 @@ // @vitest-environment happy-dom /** - * "Install the desktop app": shown where the preview server has the app or its download to offer. With the app ready a - * press opens the project in it; otherwise it opens the guide card (download, install, open). + * "Make editing easier" / "Open in desktop app": shown where the preview server has the app or its download to offer. + * With the app ready a press opens the project in it; otherwise in the header it shows the glowing aurora pill and + * 5-scene Desktop card (with install detection while open). */ import React, { act } from "react"; import { createRoot, type Root } from "react-dom/client"; @@ -11,7 +12,9 @@ import { afterEach, beforeEach, expect, it, vi } from "vitest"; (globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true; const showToast = vi.fn(); -vi.mock("../contexts/StudioContext", () => ({ useStudioShellContext: () => ({ showToast }) })); +vi.mock("../contexts/StudioContext", () => ({ + useStudioShellContext: () => ({ showToast, renderQueue: { jobs: [] } }), +})); const track = vi.fn(); vi.mock("../utils/studioTelemetry", () => ({ trackStudioEvent: track })); const FOLDER = "/work/launch-teaser"; @@ -24,6 +27,7 @@ vi.mock("../utils/clipboard", () => ({ })); const { OpenInDesktopButton } = await import("./OpenInDesktopButton"); +const { resetDesktopCardStore } = await import("./desktop-card/desktopCardStore"); const { resolveTabId } = await import("../telemetry/tabId"); const tagged = (url: string) => { const withId = new URL(url); @@ -63,10 +67,19 @@ async function mount(placement?: "storyboard"): Promise { const button = () => document.querySelector('[data-testid="header-open-in-desktop"]'); +const showcaseCard = () => document.querySelector('[data-testid="desktop-app-card"]'); +const showcaseCta = () => + document.querySelector('[data-testid="desktop-app-card-cta"]'); +const guide = () => document.querySelector('[data-testid="desktop-guide"]'); +const stepState = (n: number) => + guide()?.querySelector(`[data-step="${n}"]`)?.dataset.state ?? null; +const cardButton = (text: string) => + [...(guide()?.querySelectorAll("button") ?? [])].find((b) => b.textContent === text) ?? null; let reveal: (() => void) | null = null; beforeEach(() => { + resetDesktopCardStore(); showToast.mockReset(); track.mockReset(); reveal = null; @@ -87,16 +100,36 @@ beforeEach(() => { const events = (name: string) => track.mock.calls.filter(([event]) => event === name).map(([, props]) => props); const MAC = { os: "darwin", app_installed: true, download_available: true, placement: "header" }; +const noApp = { os: "darwin", app_installed: false, download_available: true, placement: "header" }; +const routeBody = (over: Record = {}) => ({ + ...noApp, + available: true, + handoff: false, + downloadUrl: DOWNLOAD, + installed: false, + ...over, +}); afterEach(() => { vi.unstubAllGlobals(); - if (!mounted) return; - const { root, host } = mounted; - mounted = null; - act(() => root.unmount()); - host.remove(); + if (mounted) { + const { root, host } = mounted; + mounted = null; + act(() => root.unmount()); + host.remove(); + } + resetDesktopCardStore(); }); +async function withFakeTimers(body: () => Promise) { + vi.useFakeTimers({ toFake: ["setInterval", "clearInterval", "setTimeout", "clearTimeout"] }); + try { + await body(); + } finally { + vi.useRealTimers(); + } +} + it("stays hidden where the server has no hand-off (the desktop's own Studio)", async () => { serve(null); await mount(); @@ -125,36 +158,11 @@ it("opens the project in an installed app that has no download (FreeBSD)", async expect(posts).toBe(1); }); -/** Runs `body` with the poll and slow-download timers under test control. */ -async function withFakeTimers(body: () => Promise) { - vi.useFakeTimers({ toFake: ["setInterval", "clearInterval", "setTimeout", "clearTimeout"] }); - try { - await body(); - } finally { - vi.useRealTimers(); - } -} - -const guide = () => document.querySelector('[data-testid="desktop-guide"]'); -const stepState = (n: number) => - guide()?.querySelector(`[data-step="${n}"]`)?.dataset.state ?? null; -const cardButton = (text: string) => - [...(guide()?.querySelectorAll("button") ?? [])].find((b) => b.textContent === text) ?? null; -const noApp = { os: "darwin", app_installed: false, download_available: true, placement: "header" }; -const routeBody = (over: Record = {}) => ({ - ...noApp, - available: true, - handoff: false, - downloadUrl: DOWNLOAD, - installed: false, - ...over, -}); - -it("reads 'Install the desktop app' beside Framey, and 'Open in desktop app' once the app takes projects", async () => { +it("reads 'Make editing easier' when not installed, and 'Open in desktop app' once the app takes projects", async () => { serve(Response.json(routeBody())); await mount(); - expect(button()!.textContent).toBe("Install the desktop app"); - expect(button()!.querySelector("svg .hf-framey-eye")).not.toBeNull(); + expect(button()!.getAttribute("aria-label")).toBe("Make editing easier"); + expect(button()!.className).toContain("hf-trim"); act(() => mounted!.root.unmount()); mounted = null; @@ -163,47 +171,48 @@ it("reads 'Install the desktop app' beside Framey, and 'Open in desktop app' onc expect(button()!.textContent).toBe("Open in desktop app"); }); -it("without the app, a press opens the guide at step 1 and hands nothing over", async () => { +it("without the app, a press opens the 5-scene Desktop card and hands nothing over", async () => { serve(Response.json(routeBody()), { opened: true }); await mount(); + expect(showcaseCard()!.dataset.open).toBe("false"); await act(async () => button()!.click()); - expect(guide()).not.toBeNull(); - expect([stepState(1), stepState(2), stepState(3)]).toEqual(["now", "todo", "todo"]); - expect(cardButton("Open in desktop app")!.disabled).toBe(true); + expect(showcaseCard()!.dataset.open).toBe("true"); + expect(showcaseCta()!.textContent).toBe("Download free for Mac"); + expect(document.querySelectorAll('[data-testid="desktop-app-card-segs"] button')).toHaveLength(5); expect(posts).toBe(0); - expect(events("desktop_cta_guide")).toEqual([{ step: "opened", ...noApp }]); + expect(events("desktop_cta_guide")).toEqual([{ step: "opened", ...noApp, source: "header" }]); }); -it("step 1 opens the tagged download in a new tab, then the button says what is left", async () => { +it("card CTA opens the tagged download in a new tab and switches to 'Download started'", async () => { const opened: string[] = []; const tab = { opener: {} as unknown }; vi.stubGlobal("open", (url: string) => (opened.push(url), tab)); serve(Response.json(routeBody())); await mount(); await act(async () => button()!.click()); - await act(async () => cardButton("Download for Mac")!.click()); + await act(async () => showcaseCta()!.click()); expect(opened).toEqual([tagged(DOWNLOAD)]); expect(tab.opener).toBeNull(); - expect([stepState(1), stepState(2)]).toEqual(["done", "now"]); - expect(guide()!.textContent).toContain("Looking for the app…"); - expect(button()!.textContent).toBe("Finish installing2 of 3"); - expect(events("desktop_cta_outcome")).toEqual([{ outcome: "sent_to_download", ...noApp }]); + expect(showcaseCta()!.textContent).toBe("Download started"); + expect(events("desktop_cta_outcome")).toEqual([ + { outcome: "sent_to_download", ...noApp, source: "header" }, + ]); expect(events("desktop_cta_guide").map((e) => (e as { step: string }).step)).toEqual([ "opened", "download_opened", ]); }); -it("names the download when the browser blocks the new tab, and leaves step 1 to do", async () => { +it("names the download when the browser blocks the new tab and leaves the CTA label intact", async () => { vi.stubGlobal("open", () => null); serve(Response.json(routeBody())); await mount(); await act(async () => button()!.click()); - await act(async () => cardButton("Download for Mac")!.click()); + await act(async () => showcaseCta()!.click()); expect(showToast).toHaveBeenCalledWith(`Get the HyperFrames desktop app at ${DOWNLOAD}`, "info"); - expect(stepState(1)).toBe("now"); + expect(showcaseCta()!.textContent).toBe("Download free for Mac"); expect(events("desktop_cta_outcome")).toEqual([ - { outcome: "failed", reason: "download_tab_blocked", ...noApp }, + { outcome: "failed", reason: "download_tab_blocked", ...noApp, source: "header" }, ]); }); @@ -226,7 +235,7 @@ it("finds the install only from the preview server, asking only while the card i expect(gets).toBe(1); await act(async () => button()!.click()); - await act(async () => cardButton("Download for Mac")!.click()); + await act(async () => showcaseCta()!.click()); await act(async () => vi.advanceTimersByTime(2000)); const asked = gets; expect(asked).toBeGreaterThan(1); @@ -236,10 +245,7 @@ it("finds the install only from the preview server, asking only while the card i answer = routeBody({ handoff: true, installed: true }); await act(async () => vi.advanceTimersByTime(2000)); - expect([stepState(2), stepState(3)]).toEqual(["done", "now"]); - expect(cardButton("Open in desktop app")!.disabled).toBe(false); expect(button()!.textContent).toBe("Open in desktop app"); - expect(guide()!.querySelector('svg[data-mood="found"]')).not.toBeNull(); const detected = events("desktop_cta_guide").filter( (e) => (e as { step: string }).step === "install_detected", ); @@ -272,16 +278,16 @@ it("records the install once per page, even when the app goes and comes back", ( await act(async () => button()!.click()); answer = routeBody({ handoff: true, installed: true }); await act(async () => vi.advanceTimersByTime(2000)); - expect(stepState(2)).toBe("done"); + expect(button()!.textContent).toBe("Open in desktop app"); - // The app is removed: the hand-off finds it gone, and the server stops reporting it. + // The app is removed: hand-off finds it gone and reopens the showcase card. answer = routeBody(); - await act(async () => cardButton("Open in desktop app")!.click()); - expect(stepState(2)).toBe("todo"); - // Installed again: the card finds it a second time. + await act(async () => button()!.click()); + expect(showcaseCard()!.dataset.open).toBe("true"); + // Installed again: detected without double-counting install_detected. answer = routeBody({ handoff: true, installed: true }); await act(async () => vi.advanceTimersByTime(2000)); - expect(stepState(2)).toBe("done"); + expect(button()!.textContent).toBe("Open in desktop app"); const detected = events("desktop_cta_guide").filter( (e) => (e as { step: string }).step === "install_detected", @@ -301,7 +307,7 @@ it("stops asking the preview server when the card closes", () => await act(async () => vi.advanceTimersByTime(4000)); expect(gets).toBeGreaterThan(2); await act(async () => button()!.click()); - expect(guide()).toBeNull(); + expect(showcaseCard()!.dataset.open).toBe("false"); const closedAt = gets; await act(async () => vi.advanceTimersByTime(10_000)); expect(gets).toBe(closedAt); @@ -353,7 +359,7 @@ it("a failed hand-off opens the card at step 3 with the folder to copy and Try a expect(posts).toBe(2); }); -it("a hand-off that finds the app gone goes back to the download step", async () => { +it("a hand-off that finds the app gone falls back to the Make editing easier pill and opens the card", async () => { serve(Response.json(routeBody({ handoff: true, installed: true })), { opened: false, reason: "not-installed", @@ -361,8 +367,8 @@ it("a hand-off that finds the app gone goes back to the download step", async () }); await mount(); await act(async () => button()!.click()); - expect([stepState(1), stepState(3)]).toEqual(["now", "todo"]); - expect(button()!.textContent).toBe("Install the desktop app"); + expect(button()!.getAttribute("aria-label")).toBe("Make editing easier"); + expect(showcaseCard()!.dataset.open).toBe("true"); }); it("where the app is installed but cannot take a project (Linux), step 3 shows the folder to drop in", async () => { @@ -387,7 +393,7 @@ it("where the app is installed but cannot take a project (Linux), step 3 shows t expect(posts).toBe(0); }); -it("on Windows, step 1 names the Windows download and opens it tagged", async () => { +it("on Windows, the card names 'Download free for Windows' and opens it tagged", async () => { const opened: string[] = []; vi.stubGlobal("open", (url: string) => (opened.push(url), { opener: {} })); serve( @@ -402,7 +408,8 @@ it("on Windows, step 1 names the Windows download and opens it tagged", async () await mount(); expect(button()).not.toBeNull(); await act(async () => button()!.click()); - await act(async () => cardButton("Download for Windows")!.click()); + expect(showcaseCta()!.textContent).toBe("Download free for Windows"); + await act(async () => showcaseCta()!.click()); expect(opened).toEqual([tagged(`${DOWNLOAD}?os=windows`)]); expect(events("desktop_cta_eligibility")).toEqual([ { @@ -581,9 +588,14 @@ it("records the download press as sent to the download, never as an install", as ); await mount(); await act(async () => button()!.click()); - await act(async () => cardButton("Download for Linux")!.click()); - expect(events("toolbar_action")).toEqual([{ action: "get_desktop_app", ...linux }]); - expect(events("desktop_cta_outcome")).toEqual([{ outcome: "sent_to_download", ...linux }]); + expect(showcaseCta()!.textContent).toBe("Download free for Linux"); + await act(async () => showcaseCta()!.click()); + expect(events("toolbar_action")).toEqual([ + { action: "get_desktop_app", ...linux, source: "header" }, + ]); + expect(events("desktop_cta_outcome")).toEqual([ + { outcome: "sent_to_download", ...linux, source: "header" }, + ]); const sent = JSON.stringify(track.mock.calls); expect(sent).not.toMatch(/"(outcome|step)":"[a-z_]*install/); expect(sent).not.toContain("/"); diff --git a/packages/studio/src/components/OpenInDesktopButton.tsx b/packages/studio/src/components/OpenInDesktopButton.tsx index 52e7040409a..49796c75471 100644 --- a/packages/studio/src/components/OpenInDesktopButton.tsx +++ b/packages/studio/src/components/OpenInDesktopButton.tsx @@ -1,9 +1,23 @@ import { useCallback, useEffect, useRef, useState } from "react"; import { useStudioShellContext } from "../contexts/StudioContext"; import { useFileManagerContextOptional } from "../contexts/FileManagerContext"; +import { usePlayerStore } from "../player"; import { resolveTabId } from "../telemetry/tabId"; import { studioApiFetch } from "../utils/studioApiFetch"; import { trackStudioEvent } from "../utils/studioTelemetry"; +import { DesktopAppCard } from "./desktop-card/DesktopAppCard"; +import { DesktopInstallPill } from "./desktop-card/DesktopInstallPill"; +import { + canShowDesktopUpsell, + closeDesktopCard, + launchDesktopDownload, + maybeAutoOpenDesktopCard, + openDesktopCard, + resolveDownloadOs, + setDesktopCardRoute, + useDesktopCardStore, + withDesktopCta, +} from "./desktop-card/desktopCardStore"; import { GuideCard, Swap, @@ -18,36 +32,22 @@ import { FrameyGlyph } from "./FrameyGlyph"; import { Button, Popover, cn } from "./ui"; // "Install the desktop app": the preview server (`/api/open-in-desktop`) says whether to show it, whether the app is -// here and whether it takes the project. With the app ready a press opens the project in it; otherwise the press -// opens a card where Framey walks through download, install and open. +// here and whether it takes the project. With the app ready a press opens the project in it; otherwise in the header +// it renders the glowing "Make editing easier" pill and 5-scene Desktop card (with once-a-week auto-open after +// watching or exporting). const ROUTE = "/api/open-in-desktop"; -/** How far the pupils travel towards the pointer, in the glyph's own units. */ const GAZE = 2.2; -/** Long enough for the flight to finish before the label comes back. */ const OPENING_MS = 1600; -/** While the card is open and the app is not here yet, how often to ask the preview server again. */ const POLL_MS = 2000; -/** After this long without the app turning up, the card asks whether the download finished. */ const SLOW_MS = 60_000; type OpenResult = { opened: true } | { opened: false; reason: string; downloadUrl: string }; - type Eligibility = "open_in_app" | "download" | "no_app_for_platform"; - -/** Every Guide step change, for the funnel: never a download counted as an install. */ type GuideStep = "opened" | "closed" | "download_opened" | "install_detected"; -/** The download, tagged with this page's telemetry `tab_id` so a later install can be matched to the press. */ -const withCta = (url: string): string => { - const tagged = new URL(url); - tagged.searchParams.set("hf_cta", resolveTabId()); - return tagged.toString(); -}; - const eligibilityOf = (route: DesktopRoute): Eligibility => route.handoff ? "open_in_app" : route.downloadUrl ? "download" : "no_app_for_platform"; -/** The preview server's answer, or null when there is none (the desktop's own Studio, or no server). */ async function readRoute(placement: DesktopCtaPlacement): Promise { const res = await studioApiFetch(ROUTE); if (!res.ok) return null; @@ -72,7 +72,6 @@ async function readRoute(placement: DesktopCtaPlacement): Promise(null); useEffect(() => { @@ -84,17 +83,32 @@ function useDesktopRoute(placement: DesktopCtaPlacement) { eligibility: eligibilityOf(answered), ...answered.context, }); - if (answered.handoff || answered.downloadUrl) setRoute(answered); + if (answered.handoff || answered.downloadUrl) { + setRoute(answered); + if (placement === "header") setDesktopCardRoute(answered); + } else if (placement === "header") { + setDesktopCardRoute(null); + } }) .catch(() => {}); return () => { live = false; + if (placement === "header") { + closeDesktopCard(); + setDesktopCardRoute(null); + } }; }, [placement]); - return [route, setRoute] as const; + const updateRoute = useCallback( + (next: DesktopRoute) => { + setRoute(next); + if (placement === "header") setDesktopCardRoute(next); + }, + [placement], + ); + return [route, updateRoute] as const; } -/** One impression per page, once the button is on screen. */ function useImpression(anchor: React.RefObject, route: DesktopRoute | null) { const shown = route !== null; const routeRef = useRef(route); @@ -120,7 +134,6 @@ function useImpression(anchor: React.RefObject, route: Deskt }, [anchor, shown]); } -/** Framey looks at the pointer: one listener, one write per frame, no re-render. */ function useGaze( anchor: React.RefObject, eye: React.RefObject, @@ -146,7 +159,6 @@ function useGaze( }, [anchor, eye]); } -/** While the card is open and the app is not here, ask the preview server again; stops on close or once found. */ function useInstallWatch( watching: boolean, placement: DesktopCtaPlacement, @@ -168,15 +180,91 @@ function useInstallWatch( }, [watching, placement, onAnswer]); } +function didPlaybackReachEnd( + wasPlaying: boolean, + prevTime: number, + next: { isPlaying: boolean; currentTime: number; duration: number }, +): boolean { + if (!wasPlaying || next.duration <= 0) return false; + if (!next.isPlaying) return Math.max(next.currentTime, prevTime) >= next.duration - 0.15; + return next.duration > 1 && prevTime >= next.duration - 0.25 && next.currentTime < 0.25; +} + +function completedRenderIds(rawJobs: unknown): Set { + const jobs = (rawJobs ?? []) as ReadonlyArray<{ id?: string; status?: string }>; + const ids = new Set(); + for (const job of jobs) { + if (job.status === "complete" && typeof job.id === "string") ids.add(job.id); + } + return ids; +} + +function hasUnseenId(next: Set, known: Set): boolean { + for (const id of next) { + if (!known.has(id)) return true; + } + return false; +} + +/** Auto-open the Desktop card (at most once a week) when playback finishes or an export completes. */ +function useAutoOpenTriggers(enabled: boolean): void { + const shell = useStudioShellContext(); + const rawJobs = shell.renderQueue?.jobs; + const knownCompleted = useRef | null>(null); + + useEffect(() => { + if (!enabled) return; + let wasPlaying = usePlayerStore.getState().isPlaying; + let prevTime = usePlayerStore.getState().currentTime; + return usePlayerStore.subscribe((next) => { + const reachedEnd = didPlaybackReachEnd(wasPlaying, prevTime, next); + wasPlaying = next.isPlaying; + prevTime = next.currentTime; + if (reachedEnd) maybeAutoOpenDesktopCard("auto_watch"); + }); + }, [enabled]); + + useEffect(() => { + const completedIds = completedRenderIds(rawJobs); + const prev = knownCompleted.current; + knownCompleted.current = completedIds; + if (enabled && prev !== null && hasUnseenId(completedIds, prev)) { + maybeAutoOpenDesktopCard("auto_export"); + } + }, [enabled, rawJobs]); +} + +function useShowcaseOpenTelemetry( + active: boolean, + route: DesktopRoute | null, + open: boolean, + source: string, +): void { + const prevOpen = useRef(false); + useEffect(() => { + if (!active || !route) { + prevOpen.current = false; + return; + } + if (open === prevOpen.current) return; + prevOpen.current = open; + trackStudioEvent("desktop_cta_guide", { + step: open ? "opened" : "closed", + ...route.context, + source, + }); + }, [active, route, open, source]); +} + const LOOK = "hf-framey-trigger gap-1.5 border border-accent/40 bg-accent/10 pl-1 font-semibold text-text-0 enabled:hover:bg-accent/20 hover:bg-accent/20"; const LOOK_FAILED = "border-danger/45 bg-danger/8 text-danger-ink enabled:hover:bg-danger/14"; -/** The guide's state and the two actions that move it: the download and the hand-off. */ function useGuide( route: DesktopRoute | null, setRoute: (route: DesktopRoute) => void, placement: DesktopCtaPlacement, + showcaseOpen: boolean, ) { const { showToast } = useStudioShellContext(); const [cardOpen, setCardOpen] = useState(false); @@ -186,7 +274,6 @@ function useGuide( const [slow, setSlow] = useState(false); const [arrived, setArrived] = useState(false); const installed = route?.context.app_installed === true; - // The funnel counts one install per page, even if the app is removed and found again. const installCounted = useRef(false); const onAnswer = useCallback( @@ -200,7 +287,7 @@ function useGuide( }, [setRoute], ); - useInstallWatch(cardOpen && route !== null && !installed, placement, onAnswer); + useInstallWatch((cardOpen || showcaseOpen) && route !== null && !installed, placement, onAnswer); useEffect(() => { if (!downloaded || installed) return; @@ -229,7 +316,7 @@ function useGuide( const download = () => { if (!route.downloadUrl) return; trackStudioEvent("toolbar_action", { action: "get_desktop_app", ...context }); - const tab = window.open(withCta(route.downloadUrl), "_blank"); + const tab = window.open(withDesktopCta(route.downloadUrl), "_blank"); if (!tab) { showToast(`Get the HyperFrames desktop app at ${route.downloadUrl}`, "info"); outcome("failed", "download_tab_blocked"); @@ -250,10 +337,15 @@ function useGuide( return; } outcome("failed", result.reason); - // The app is gone: back to the download. Anything else: say so where the person is, with a way through. - if (result.reason === "not-installed") + if (result.reason === "not-installed") { setRoute({ ...route, handoff: false, context: { ...context, app_installed: false } }); - else setFailed(true); + if (placement === "header") { + openDesktopCard(0, "header"); + return; + } + } else { + setFailed(true); + } showCard(true); }; @@ -281,30 +373,72 @@ function useGuide( }; const progress: Progress = { route, opening, failed, downloaded, slow, arrived }; - return { progress, cardOpen, showCard, download, open }; + return { progress, cardOpen, showCard, download, open, guideStep }; } -export function OpenInDesktopButton({ - placement = "header", +function HeaderShowcaseTrigger({ + placement, + route, + triggerRef, }: { - placement?: DesktopCtaPlacement; -} = {}) { - const projectDir = useFileManagerContextOptional()?.projectDir ?? null; - const [route, setRoute] = useDesktopRoute(placement); - const trigger = useRef(null); - const eye = useRef(null); - useGaze(trigger, eye); - useImpression(trigger, route); - const guide = useGuide(route, setRoute, placement); - if (!guide) return null; - const { progress, cardOpen, showCard, download, open } = guide; + placement: DesktopCtaPlacement; + route: DesktopRoute; + triggerRef: React.RefObject; +}) { + const { showToast } = useStudioShellContext(); + const store = useDesktopCardStore(); + const { key: osKey, label: osLabel } = resolveDownloadOs(route.context.os); + + return ( + <> + (store.open ? closeDesktopCard() : openDesktopCard(0, "header"))} + /> + launchDesktopDownload(route, store.source, showToast)} + onClose={closeDesktopCard} + /> + + ); +} + +function GuidePopoverTrigger({ + placement, + projectDir, + triggerRef, + eyeRef, + progress, + cardOpen, + showCard, + download, + open, +}: { + placement: DesktopCtaPlacement; + projectDir: string | null; + triggerRef: React.RefObject; + eyeRef: React.RefObject; + progress: Progress; + cardOpen: boolean; + showCard: (next: boolean) => void; + download: () => void; + open: () => Promise; +}) { const label = labelOf(progress); const waiting = isWaiting(progress); return ( { if (next && progress.route.handoff && !progress.failed) return void open(); showCard(next); @@ -315,7 +449,7 @@ export function OpenInDesktopButton({ className="w-[360px] overflow-hidden p-0" trigger={ + + ); +} diff --git a/packages/studio/src/components/desktop-card/DesktopAppCard.tsx b/packages/studio/src/components/desktop-card/DesktopAppCard.tsx new file mode 100644 index 00000000000..8a0b7085869 --- /dev/null +++ b/packages/studio/src/components/desktop-card/DesktopAppCard.tsx @@ -0,0 +1,221 @@ +import { useEffect, useRef, useState } from "react"; +import { createPortal } from "react-dom"; +import { PlatformMark, resolveDesktopCardAgent } from "./agentBrands"; +import { createCardChoreography, type CardChoreographyController } from "./cardChoreography"; +import { CARD_W, createEmptyStageElements, SECTIONS } from "./cardStageTypes"; +import { DesktopAppCardStage } from "./DesktopAppCardStage"; +import type { DesktopCardSceneIndex } from "./desktopCardStore"; + +export interface DesktopAppCardProps { + open: boolean; + initialScene: DesktopCardSceneIndex; + openSeq: number; + anchorRef: React.RefObject; + osKey: "mac" | "win" | "linux"; + osLabel: string; + downloaded: boolean; + onDownload: () => void; + onClose: () => void; +} + +function useCardAnchorPosition( + open: boolean, + anchorRef: React.RefObject, + openSeq: number, +) { + const [pos, setPos] = useState<{ left: number; top: number; originX: number }>({ + left: 16, + top: 44, + originX: CARD_W - 80, + }); + + useEffect(() => { + if (!open) return; + const place = () => { + const vw = window.innerWidth || 1440; + const anchor = anchorRef.current?.getBoundingClientRect(); + if (anchor && anchor.width > 0) { + const left = Math.max(8, Math.min(vw - CARD_W - 8, anchor.right - CARD_W)); + const top = Math.max(8, anchor.bottom + 7); + setPos({ left, top, originX: anchor.left + anchor.width / 2 - left }); + } else { + setPos({ left: Math.max(8, vw - CARD_W - 16), top: 44, originX: CARD_W - 80 }); + } + }; + place(); + window.addEventListener("resize", place); + return () => window.removeEventListener("resize", place); + }, [open, anchorRef, openSeq]); + + return pos; +} + +function useCardDismiss( + open: boolean, + cardRef: React.RefObject, + anchorRef: React.RefObject, + onClose: () => void, +) { + useEffect(() => { + if (!open) return; + const onPointerDown = (event: PointerEvent) => { + const target = event.target as Node | null; + if (!target || cardRef.current?.contains(target) || anchorRef.current?.contains(target)) { + return; + } + onClose(); + }; + const onKeyDown = (event: KeyboardEvent) => { + if (event.key === "Escape") onClose(); + }; + document.addEventListener("pointerdown", onPointerDown, true); + window.addEventListener("keydown", onKeyDown); + return () => { + document.removeEventListener("pointerdown", onPointerDown, true); + window.removeEventListener("keydown", onKeyDown); + }; + }, [open, cardRef, anchorRef, onClose]); +} + +function useCardChoreography(params: { + open: boolean; + initialScene: DesktopCardSceneIndex; + openSeq: number; + agentHeadline: string; + cardRef: React.RefObject; + stageRef: React.RefObject>; + lineBoxRef: React.RefObject; + segFillRefs: React.RefObject<(HTMLElement | null)[]>; +}) { + const { open, initialScene, openSeq, agentHeadline, cardRef, stageRef, lineBoxRef, segFillRefs } = + params; + const controllerRef = useRef(null); + + useEffect(() => { + const cardEl = cardRef.current; + if (!cardEl) return; + const ctrl = createCardChoreography({ + cardEl, + stage: stageRef.current, + lineBox: lineBoxRef.current, + segBars: segFillRefs.current, + agentHeadline, + }); + controllerRef.current = ctrl; + if (!ctrl) return; + if (open) ctrl.jump(initialScene); + else ctrl.stop(); + return () => { + controllerRef.current = null; + ctrl.stop(); + }; + }, [open, initialScene, openSeq, agentHeadline, cardRef, stageRef, lineBoxRef, segFillRefs]); + + return controllerRef; +} + +/** Floating 5-scene Desktop showcase card, matching the prototype's liquid glass and motion 1:1. */ +export function DesktopAppCard({ + open, + initialScene, + openSeq, + anchorRef, + osKey, + osLabel, + downloaded, + onDownload, + onClose, +}: DesktopAppCardProps) { + const cardRef = useRef(null); + const stageRef = useRef(createEmptyStageElements()); + const lineBoxRef = useRef(null); + const segFillRefs = useRef<(HTMLElement | null)[]>([]); + + const agent = resolveDesktopCardAgent(); + const pos = useCardAnchorPosition(open, anchorRef, openSeq); + useCardDismiss(open, cardRef, anchorRef, onClose); + const controllerRef = useCardChoreography({ + open, + initialScene, + openSeq, + agentHeadline: agent.headline, + cardRef, + stageRef, + lineBoxRef, + segFillRefs, + }); + + const content = ( +
+ + + + +
+ {SECTIONS.map((name, idx) => ( + + ))} +
+ +
+ {agent.headline} +
+ + +
+ ); + + return typeof document !== "undefined" ? createPortal(content, document.body) : null; +} diff --git a/packages/studio/src/components/desktop-card/DesktopAppCardStage.tsx b/packages/studio/src/components/desktop-card/DesktopAppCardStage.tsx new file mode 100644 index 00000000000..03a15a244fb --- /dev/null +++ b/packages/studio/src/components/desktop-card/DesktopAppCardStage.tsx @@ -0,0 +1,345 @@ +import { AGENT_LOGO_ROW, AgentBrandMark, type LogoBrandName } from "./agentBrands"; +import { CARD_MEDIA } from "./cardMedia"; +import { BUB_POS, PIN_POS, type CardStageElements } from "./cardStageTypes"; + +interface DesktopAppCardStageProps { + agentLogo: LogoBrandName | null; + stageRef: React.RefObject; + onDownload: () => void; +} + +/** Presentational 5-scene visual stage inside DesktopAppCard. */ +export function DesktopAppCardStage({ agentLogo, stageRef, onDownload }: DesktopAppCardStageProps) { + const brands = agentLogo ? [agentLogo] : AGENT_LOGO_ROW; + const s = stageRef.current; + + return ( +
+ {/* Scene 0: coding agent logos */} +
{ + s.layerP = el; + }} + className="hf-dc-layer hf-dc-layer-p" + > +
+ {brands.map((brand) => ( + + + + ))} +
+
+ + {/* Scene 1: Desktop editor with Draw / Comment & typed bubble */} +
{ + s.layerA = el; + }} + className="hf-dc-layer" + > +
{ + s.camA = el; + }} + className="hf-dc-cam hf-dc-editor" + > + + + +
{ + s.pin = el; + }} + className="hf-dc-pin" + style={{ left: `${PIN_POS.x + 6}px`, top: `${PIN_POS.y - 4}px` }} + > + 1 +
+
{ + s.bubble = el; + }} + className="hf-dc-bubble" + style={{ left: `${BUB_POS.x}px`, top: `${BUB_POS.y}px` }} + > + { + s.bubbleText = el; + }} + /> + { + s.bubbleSend = el; + }} + className="hf-dc-send" + /> +
+
+
+ + {/* Scenes 2 & 3: Desktop Home (Your Projects + For You motion library) */} +
{ + s.layerB = el; + }} + className="hf-dc-layer" + > +
{ + s.camB = el; + }} + className="hf-dc-cam" + > +
+ + {CARD_MEDIA.projects.map((item, i) => ( +
{ + s.projCards[i] = el; + }} + className="hf-dc-home-card" + > +
+ +
+
{item.title}
+
{item.meta}
+
+ ))} + {CARD_MEDIA.synced.map((item, i) => ( +
{ + s.syncCards[i] = el; + }} + className="hf-dc-home-card" + style={{ opacity: 0 }} + > +
+ +
+
{item.title}
+
{item.meta}
+
+ ))} +
{ + s.addBtn = el; + }} + className="hf-dc-hover-add" + aria-hidden="true" + > + + + + + Add as inspiration +
+
{ + s.wipe = el; + }} + className="hf-dc-wipe" + > +
+
+
+
+ + {/* Scene 4 payoff: Two-phone A-roll remix */} +
{ + s.layerR = el; + }} + className="hf-dc-layer hf-dc-layer-r" + > +
{ + s.phRefBox = el; + }} + className="hf-dc-phone" + > +
+
{ + s.phResBox = el; + }} + className="hf-dc-phone" + > +
+ { + s.arrow = el; + }} + className="hf-dc-arrow" + aria-hidden="true" + > + + + + +
+ + {/* Animated pointer cursor */} + { + s.cursor = el; + }} + className="hf-dc-cursor" + viewBox="0 0 24 24" + aria-hidden="true" + > + + +
+ ); +} diff --git a/packages/studio/src/components/desktop-card/DesktopInstallPill.tsx b/packages/studio/src/components/desktop-card/DesktopInstallPill.tsx new file mode 100644 index 00000000000..067171fd826 --- /dev/null +++ b/packages/studio/src/components/desktop-card/DesktopInstallPill.tsx @@ -0,0 +1,310 @@ +import { forwardRef, useEffect, useId, useRef } from "react"; +import { auroraColor, buildAuroraRing } from "./auroraRing"; + +// Hover electric crackle constants matching Jake's createTrim prototype 1:1. +const MORPH_MS = 180; +const GAP_MS = 120; +const SEG = 5; +const PAD = 12; + +interface PillSize { + W: number; + H: number; + P: number; +} + +interface CrackleArc { + k: number; + t: number; + span: number; + born: number; + life: number; +} + +interface Pt { + x: number; + y: number; +} + +function makeRng(seedInput: number): () => number { + let seed = seedInput; + return () => { + seed = (seed + 0x6d2b79f5) | 0; + let x = Math.imul(seed ^ (seed >>> 15), 1 | seed); + x = (x + Math.imul(x ^ (x >>> 7), 61 | x)) ^ x; + return ((x ^ (x >>> 14)) >>> 0) / 4294967296; + }; +} + +/** Standard CSS Color 4 sRGB string without `rgb()` / `#hex` literals. */ +function hueCss(u: number, white: number): string { + const [r, g, b] = auroraColor(Math.min(1, Math.max(0, u))); + const mix = (v: number) => ((v + (255 - v) * white) / 255).toFixed(4); + return `color(srgb ${mix(r)} ${mix(g)} ${mix(b)})`; +} + +function pointOnPill(size: PillSize, t: number, out: number): Pt { + const { W, H, P } = size; + const r = H / 2; + const flat = Math.max(0, W - H); + const per = 2 * flat + Math.PI * H; + let d = (((t % 1) + 1) % 1) * per; + if (d < flat) return { x: P + r + d, y: P - out }; + d -= flat; + if (d < Math.PI * r) { + const a = -Math.PI / 2 + d / r; + return { x: P + W - r + (r + out) * Math.cos(a), y: P + r + (r + out) * Math.sin(a) }; + } + d -= Math.PI * r; + if (d < flat) return { x: P + W - r - d, y: P + H + out }; + d -= flat; + const a = Math.PI / 2 + d / r; + return { x: P + r + (r + out) * Math.cos(a), y: P + r + (r + out) * Math.sin(a) }; +} + +function buildHoverMarkup( + size: PillSize, + ms: number, + base: number, +): { wisps: string; heat: string } { + const perim = 2 * Math.max(0, size.W - size.H) + Math.PI * size.H; + const flat = Math.max(0, size.W - size.H); + const cap = (Math.PI * (size.H / 2)) / perim; + + const capT = (r: () => number) => + r() < 0.5 ? flat / perim + r() * cap : (2 * flat + (Math.PI * size.H) / 2) / perim + r() * cap; + + const makeArc = (k: number): CrackleArc => { + const r = makeRng(base * 100003 + k * 7919 + 1); + const span = 0.04 + r() * 0.1; + const t = (r() < 0.45 ? capT(r) : r()) - span / 2; + return { k, t, span, born: (k + r() * 0.8) * GAP_MS, life: 240 + r() * 400 }; + }; + + const count = (w: CrackleArc) => Math.max(8, Math.round((w.span * perim) / 1.6)); + + const rise = (t: number, off: number): Pt => { + const p = pointOnPill(size, t, 0); + const q = pointOnPill(size, t, 1); + const nx = q.x - p.x; + const ny = -Math.max(0.35, 1 - Math.abs(nx)); + const k = Math.hypot(nx, ny) || 1; + return { x: p.x + (nx / k) * off, y: p.y + (ny / k) * off }; + }; + + const pose = (n: number, seed: number): number[] => { + const r = makeRng(seed); + let walk = 0; + return Array.from({ length: n + 1 }, (_, i) => { + walk = Math.max(-1, Math.min(5, walk + (r() - 0.38) * 1.4)); + const spike = r() < 0.12 ? 2.5 + r() * 4.5 : 0; + return ( + Math.pow(Math.max(0, Math.sin((Math.PI * i) / n)), 0.6) * (walk + (r() - 0.5) * 1.8 + spike) + ); + }); + }; + + const shape = (w: CrackleArc, s: number, age: number): Pt[] => { + const n = count(w); + const j = Math.floor(age / MORPH_MS); + const k = (age - j * MORPH_MS) / MORPH_MS; + const seed = (q: number) => base * 100003 + w.k * 7919 + s * 104729 + q * 1299709; + const a = pose(n, seed(j)); + const b = pose(n, seed(j + 1)); + const e = k * k * (3 - 2 * k); + return a.map((v, i) => rise(w.t + (w.span * i) / n, v + (b[i]! - v) * e)); + }; + + const line = (ps: Pt[]) => + ps.map((q, i) => `${i ? "L" : "M"}${q.x.toFixed(1)} ${q.y.toFixed(1)}`).join(""); + + const curve = (ps: Pt[]) => { + let d = `M${ps[0]!.x.toFixed(1)} ${ps[0]!.y.toFixed(1)}`; + for (let i = 1; i < ps.length - 1; i++) { + const a = ps[i]!; + const b = ps[i + 1]!; + d += ` Q${a.x.toFixed(1)} ${a.y.toFixed(1)} ${((a.x + b.x) / 2).toFixed(1)} ${((a.y + b.y) / 2).toFixed(1)}`; + } + const z = ps[ps.length - 1]!; + return `${d} L${z.x.toFixed(1)} ${z.y.toFixed(1)}`; + }; + + let wisps = ""; + let heat = ""; + const startK = Math.max(0, Math.floor((ms - 640) / GAP_MS) - 1); + for (let k = startK; k * GAP_MS <= ms; k++) { + const w = makeArc(k); + const age = ms - w.born; + if (age < 0 || age >= w.life) continue; + const fade = Math.sin((Math.PI * age) / w.life); + const u = (pointOnPill(size, w.t + w.span / 2, 0).x - size.P) / Math.max(1, size.W); + const strands: readonly [number, number][] = [ + [0.8, 1], + [0.5, 0.6], + ]; + strands.forEach(([width, op], s) => { + const ps = shape(w, s, age); + const n = ps.length - 1; + const o = op * (0.3 + 0.7 * fade); + for (let j = 0; j < SEG; j++) { + const c = hueCss((((u - 0.25 + s * 0.3 + (0.5 * j) / (SEG - 1)) % 1) + 1) % 1, 0.1); + const a = 0.6 + 0.4 * Math.sin((Math.PI * (j + 0.5)) / SEG); + const slice = ps.slice(Math.floor((n * j) / SEG), Math.ceil((n * (j + 1)) / SEG) + 1); + wisps += ``; + } + if (s === 0) { + const core = ps.slice(Math.floor(n * 0.35), Math.ceil(n * 0.65) + 1); + wisps += ``; + } + }); + const n = count(w); + const edgePts: Pt[] = []; + for (let i = 0; i <= n; i++) edgePts.push(pointOnPill(size, w.t + (w.span * i) / n, 0)); + heat += ``; + } + return { wisps, heat }; +} + +export interface DesktopInstallPillProps { + label?: string; + open: boolean; + onClick: () => void; + testId?: string; +} + +/** The header's glowing "Make editing easier" liquid-glass aurora pill. */ +export const DesktopInstallPill = forwardRef( + function DesktopInstallPill( + { label = "Make editing easier", open, onClick, testId = "header-open-in-desktop" }, + forwardedRef, + ) { + const innerRef = useRef(null); + const uid = `hf-trim-${useId().replace(/:/g, "")}`; + + const setRef = (node: HTMLButtonElement | null) => { + innerRef.current = node; + if (typeof forwardedRef === "function") forwardedRef(node); + else if (forwardedRef) forwardedRef.current = node; + }; + + useEffect(() => { + const btn = innerRef.current; + if (!btn) return; + const aurora = buildAuroraRing(btn); + let size: PillSize | null = null; + let timer = 0; + let live = true; + + const still = () => + typeof window.matchMedia === "function" && + window.matchMedia("(prefers-reduced-motion: reduce)").matches; + + const buildChrome = () => { + if (!live) return; + btn.querySelectorAll(".hf-trim-edge, .hf-trim-wisps").forEach((el) => el.remove()); + const W = btn.offsetWidth; + const H = btn.offsetHeight; + if (W <= 0 || H <= 0) return; + const FW = W + 2 * PAD; + const FH = H + 2 * PAD; + size = { W, H, P: PAD }; + const stops = Array.from( + { length: 11 }, + (_, i) => ``, + ).join(""); + btn.insertAdjacentHTML( + "beforeend", + ` + `, + ); + }; + + const drawHover = (ms: number, base: number) => { + if (!size) return; + const g = btn.querySelector(".hf-trim-wisps .hf-trim-w"); + const hot = btn.querySelector(".hf-trim-wisps .hf-trim-hot"); + if (!g || !hot) return; + const { wisps, heat } = buildHoverMarkup(size, ms, base); + g.innerHTML = wisps; + hot.innerHTML = heat; + }; + + const onEnter = () => { + if (still()) return; + window.clearInterval(timer); + if (!size) buildChrome(); + const start = performance.now(); + const base = Math.floor(Math.random() * 1e6); + drawHover(0, base); + timer = window.setInterval(() => drawHover(performance.now() - start, base), 40); + }; + + const onLeave = () => { + window.clearInterval(timer); + timer = 0; + btn.querySelectorAll(".hf-trim-wisps g").forEach((g) => { + g.innerHTML = ""; + }); + }; + + btn.addEventListener("mouseenter", onEnter); + btn.addEventListener("mouseleave", onLeave); + buildChrome(); + void document.fonts?.ready?.then(buildChrome); + + const ro = + typeof ResizeObserver === "function" ? new ResizeObserver(() => buildChrome()) : null; + ro?.observe(btn); + + return () => { + live = false; + window.clearInterval(timer); + ro?.disconnect(); + btn.removeEventListener("mouseenter", onEnter); + btn.removeEventListener("mouseleave", onLeave); + btn.querySelectorAll(".hf-trim-edge, .hf-trim-wisps").forEach((el) => el.remove()); + aurora.destroy(); + }; + }, [uid, label]); + + return ( + + ); + }, +); diff --git a/packages/studio/src/components/desktop-card/agentBrands.tsx b/packages/studio/src/components/desktop-card/agentBrands.tsx new file mode 100644 index 00000000000..df8df3a298c --- /dev/null +++ b/packages/studio/src/components/desktop-card/agentBrands.tsx @@ -0,0 +1,144 @@ +import { useId } from "react"; +import { resolveAgentRuntime } from "../../telemetry/agentRuntime"; + +// Coding agent brand marks (same vector paths Desktop uses) with tokenised fills. +const CLAUDE_PATH = + "M52.4285 162.873L98.7844 136.879L99.5485 134.602L98.7844 133.334H96.4921L88.7237 132.862L62.2346 132.153L39.3113 131.207L17.0249 130.026L11.4214 128.844L6.2 121.873L6.7094 118.447L11.4214 115.257L18.171 115.847L33.0711 116.911L55.485 118.447L71.6586 119.392L95.728 121.873H99.5485L100.058 120.337L98.7844 119.392L97.7656 118.447L74.5877 102.732L49.4995 86.1905L36.3823 76.62L29.3779 71.7757L25.8121 67.2858L24.2839 57.3608L30.6515 50.2716L39.3113 50.8623L41.4763 51.4531L50.2636 58.1879L68.9842 72.7209L93.4357 90.6804L97.0015 93.6343L98.4374 92.6652L98.6571 91.9801L97.0015 89.2625L83.757 65.2772L69.621 40.8192L63.2534 30.6579L61.5978 24.632C60.9565 22.1032 60.579 20.0111 60.579 17.4246L67.8381 7.49965L71.9133 6.19995L81.7193 7.49965L85.7946 11.0443L91.9074 24.9865L101.714 46.8451L116.996 76.62L121.453 85.4816L123.873 93.6343L124.764 96.1155H126.292V94.6976L127.566 77.9197L129.858 57.3608L132.15 30.8942L132.915 23.4505L136.608 14.4708L143.994 9.62643L149.725 12.344L154.437 19.0788L153.8 23.4505L150.998 41.6463L145.522 70.1215L141.957 89.2625H143.994L146.414 86.7813L156.093 74.0206L172.266 53.698L179.398 45.6635L187.803 36.802L193.152 32.5484H203.34L210.726 43.6549L207.415 55.1159L196.972 68.3492L188.312 79.5739L175.896 96.2095L168.191 109.585L168.882 110.689L170.738 110.53L198.755 104.504L213.91 101.787L231.994 98.7149L240.144 102.496L241.036 106.395L237.852 114.311L218.495 119.037L195.826 123.645L162.07 131.592L161.696 131.893L162.137 132.547L177.36 133.925L183.855 134.279H199.774L229.447 136.524L237.215 141.605L241.8 147.867L241.036 152.711L229.065 158.737L213.019 154.956L175.45 145.977L162.587 142.787H160.805V143.85L171.502 154.366L191.242 172.089L215.82 195.011L217.094 200.682L213.91 205.172L210.599 204.699L188.949 188.394L180.544 181.069L161.696 165.118H160.422V166.772L164.752 173.152L187.803 207.771L188.949 218.405L187.294 221.832L181.308 223.959L174.813 222.777L161.187 203.754L147.305 182.486L136.098 163.345L134.745 164.2L128.075 235.42L125.019 239.082L117.887 241.8L111.902 237.31L108.718 229.984L111.902 215.452L115.722 196.547L118.779 181.541L121.58 162.873L123.291 156.636L123.14 156.219L121.773 156.449L107.699 175.752L86.304 204.699L69.3663 222.777L65.291 224.431L58.2867 220.768L58.9235 214.27L62.8713 208.48L86.304 178.705L100.44 160.155L109.551 149.507L109.462 147.967L108.959 147.924L46.6977 188.512L35.6182 189.93L30.7788 185.44L31.4156 178.115L33.7079 175.752L52.4285 162.873Z"; + +const CODEX_MARK_PATH = + "M9.064 3.344a4.578 4.578 0 012.285-.312c1 .115 1.891.54 2.673 1.275.01.01.024.017.037.021a.09.09 0 00.043 0 4.55 4.55 0 013.046.275l.047.022.116.057a4.581 4.581 0 012.188 2.399c.209.51.313 1.041.315 1.595a4.24 4.24 0 01-.134 1.223.123.123 0 00.03.115c.594.607.988 1.33 1.183 2.17.289 1.425-.007 2.71-.887 3.854l-.136.166a4.548 4.548 0 01-2.201 1.388.123.123 0 00-.081.076c-.191.551-.383 1.023-.74 1.494-.9 1.187-2.222 1.846-3.711 1.838-1.187-.006-2.239-.44-3.157-1.302a.107.107 0 00-.105-.024c-.388.125-.78.143-1.204.138a4.441 4.441 0 01-1.945-.466 4.544 4.544 0 01-1.61-1.335c-.152-.202-.303-.392-.414-.617a5.81 5.81 0 01-.37-.961 4.582 4.582 0 01-.014-2.298.124.124 0 00.006-.056.085.085 0 00-.027-.048 4.467 4.467 0 01-1.034-1.651 3.896 3.896 0 01-.251-1.192 5.189 5.189 0 01.141-1.6c.337-1.112.982-1.985 1.933-2.618.212-.141.413-.251.601-.33.215-.089.43-.164.646-.227a.098.098 0 00.065-.066 4.51 4.51 0 01.829-1.615 4.535 4.535 0 011.837-1.388zm3.482 10.565a.637.637 0 000 1.272h3.636a.637.637 0 100-1.272h-3.636zM8.462 9.23a.637.637 0 00-1.106.631l1.272 2.224-1.266 2.136a.636.636 0 101.095.649l1.454-2.455a.636.636 0 00.005-.64L8.462 9.23z"; + +const CODEX_GLYPH_PATH = + "M12.546 13.909a.637.637 0 000 1.272h3.636a.637.637 0 100-1.272h-3.636zM8.462 9.23a.637.637 0 00-1.106.631l1.272 2.224-1.266 2.136a.636.636 0 101.095.649l1.454-2.455a.636.636 0 00.005-.64L8.462 9.23z"; + +const ANTIGRAVITY_PATH = + "M89.6992 93.695C94.3659 97.195 101.366 94.8617 94.9492 88.445C75.6992 69.7783 79.7825 18.445 55.8659 18.445C31.9492 18.445 36.0325 69.7783 16.7825 88.445C9.78251 95.445 17.3658 97.195 22.0325 93.695C40.1159 81.445 38.9492 59.8617 55.8659 59.8617C72.7825 59.8617 71.6159 81.445 89.6992 93.695Z"; + +const OPENCODE_FRAME_PATH = "M180 60H60V240H180V60ZM240 300H0V0H240V300Z"; +const OPENCODE_BLOCK_PATH = "M180 240H60V120H180V240Z"; + +const COPILOT_PATH = + "M662.29 384.036L659.741 382.761L653.252 350.394C661.015 330.772 663.063 308.563 663.063 286.469C663.063 252.827 658.119 218.142 636.295 190.486C613.932 162.174 578.59 147.072 531.081 141.78C484.499 136.604 443.711 143.093 417.369 171.328C415.476 173.375 413.661 175.5 412 177.663C410.339 175.5 408.524 173.375 406.631 171.328C380.289 143.093 339.501 136.604 292.919 141.78C245.41 147.072 210.069 162.174 187.705 190.486C165.882 218.142 160.938 252.827 160.938 286.469C160.938 308.563 162.985 330.772 170.748 350.394L164.259 382.761L161.71 384.036C125.712 402.035 103 438.806 103 479.053V527.875C103 537.145 106.322 544.793 109.026 549.776C111.922 555.067 115.553 559.857 119.029 563.913C125.982 572.024 134.634 579.865 142.398 586.315C150.316 592.92 158.118 598.752 163.912 602.924C173.143 609.606 182.645 615.747 192.533 621.464C204.391 628.301 221.424 637.261 242.591 646.261C284.731 664.144 344.213 682.375 412.039 682.375C479.864 682.375 539.347 664.144 581.487 646.261C602.653 637.3 619.687 628.301 631.545 621.464C641.433 615.786 650.934 609.606 660.166 602.924C665.921 598.752 673.762 592.92 681.68 586.315C689.443 579.865 698.095 572.024 705.048 563.913C708.524 559.857 712.155 555.067 715.052 549.776C717.756 544.793 721.077 537.145 721.077 527.875V479.053C721.077 438.806 698.327 402.035 662.367 384.036H662.29ZM233.166 226.407C242.205 214.974 259.933 203.773 299.331 199.37C339.655 194.889 356.805 202.885 364.26 210.88C372.139 219.3 378.126 237.068 373.607 273.221C370.092 301.263 361.942 320.73 349.737 333.167C338.188 344.947 319.455 354.063 286.469 354.063C250.857 354.063 237.029 346.377 230.772 339.385C223.858 331.66 218.875 317.06 218.875 286.469C218.875 256.882 223.626 238.497 233.166 226.407ZM605.125 569.784L602.614 571.251C592.456 577.122 577.508 585.002 558.814 592.92C521.309 608.833 469.706 624.399 412 624.399C354.294 624.399 302.73 608.833 265.186 592.92C246.531 585.002 231.583 577.084 221.386 571.251L218.875 569.784V405.202L219.763 400.722C238.69 408.833 261.285 411.962 286.469 411.962C330.733 411.962 366.036 399.293 391.143 373.684C399.601 365.032 406.477 355.376 412 344.986C417.562 355.376 424.399 365.032 432.858 373.684C457.964 399.331 493.228 411.962 537.531 411.962C562.715 411.962 585.31 408.795 604.237 400.722L605.125 405.202V569.784ZM593.229 339.385C586.971 346.377 573.144 354.063 537.531 354.063C504.546 354.063 485.812 344.947 474.264 333.167C462.097 320.73 453.908 301.263 450.393 273.221C445.874 237.068 451.861 219.3 459.741 210.88C467.195 202.885 484.345 194.889 524.669 199.37C564.067 203.734 581.796 214.974 590.834 226.407C600.374 238.497 605.125 256.882 605.125 286.469C605.125 317.06 600.142 331.699 593.229 339.385ZM373.375 479.594V537.532C373.375 553.522 360.397 566.5 344.406 566.5C328.416 566.5 315.438 553.522 315.438 537.532V479.594C315.438 463.603 328.416 450.625 344.406 450.625C360.397 450.625 373.375 463.603 373.375 479.594ZM508.563 479.594V537.532C508.563 553.522 495.585 566.5 479.594 566.5C463.603 566.5 450.625 553.522 450.625 537.532V479.594C450.625 463.603 463.603 450.625 479.594 450.625C495.585 450.625 508.563 463.603 508.563 479.594Z"; + +export type LogoBrandName = "Claude Code" | "Codex" | "Antigravity" | "OpenCode" | "GitHub Copilot"; + +export const AGENT_LOGO_ROW: readonly LogoBrandName[] = [ + "Claude Code", + "Codex", + "Antigravity", + "OpenCode", + "GitHub Copilot", +]; + +const PICKER_NAME: Readonly> = { + claude_code: "Claude Code", + claude_agent_sdk: "Claude Code", + codex: "Codex", + antigravity: "Antigravity", + opencode: "OpenCode", + copilot_cli: "GitHub Copilot", + copilot_agent: "GitHub Copilot", + hermes: "Hermes Agent", + grok: "Grok", + qoder: "Qoder", +}; + +const LOGO_SET = new Set(AGENT_LOGO_ROW); + +export function resolveDesktopCardAgent(runtime: string | null = resolveAgentRuntime()): { + name: string | null; + logo: LogoBrandName | null; + headline: string; +} { + const name = runtime ? (PICKER_NAME[runtime] ?? null) : null; + const logo = name && LOGO_SET.has(name) ? (name as LogoBrandName) : null; + return { + name, + logo, + headline: name ? `Keep using your ${name} subscription` : "Keep using your coding agent", + }; +} + +export function AgentBrandMark({ brand }: { brand: LogoBrandName }) { + const gradId = `hf-dc-codex-${useId().replace(/:/g, "")}`; + switch (brand) { + case "Claude Code": + return ( + + ); + case "Codex": + return ( + + ); + case "Antigravity": + return ( + + ); + case "OpenCode": + return ( + + ); + case "GitHub Copilot": + return ( + + ); + } +} + +export function PlatformMark({ os }: { os: "mac" | "win" | "linux" }) { + if (os === "win") { + return ( + + ); + } + if (os === "linux") { + return ( + + ); + } + return ( + + ); +} diff --git a/packages/studio/src/components/desktop-card/auroraRing.ts b/packages/studio/src/components/desktop-card/auroraRing.ts new file mode 100644 index 00000000000..b6d2c62ecc1 --- /dev/null +++ b/packages/studio/src/components/desktop-card/auroraRing.ts @@ -0,0 +1,410 @@ +// Aurora liquid fill canvas for the install pill and Catalog upsell card. +// Coordinates are normalized to pill width u (0..1) and height v (0..1) with a 3 s slosh period. + +import { getAuroraTables, sampleTable, smoothStep } from "./auroraTables"; + +const PERIOD = 3; +const DRIFT = 0.04; +const BASE: readonly [number, number, number] = [13, 6, 33]; +const MILK: readonly [number, number, number] = [152, 152, 154]; +const WHITE: readonly [number, number, number] = [238, 240, 241]; +const GLOW: readonly [number, number, number] = [54, 55, 60]; + +/** Sample the aurora's core RGB triplet at normalized horizontal position `u` (0..1). */ +export function auroraColor(u: number): [number, number, number] { + const out = sampleTable(getAuroraTables().core, Math.min(1, Math.max(0, u)), [0, 0, 0]); + return [Math.round(out[0]!), Math.round(out[1]!), Math.round(out[2]!)]; +} + +interface AuroraFillState { + level?: number; + wave?: number; + phase?: number; +} + +export interface AuroraController { + seek: (t: number, fill?: AuroraFillState) => void; + play: () => void; + setFill: (fill: AuroraFillState) => void; + destroy: () => void; +} + +const COL_KEYS = [ + "u", + "s", + "a", + "b", + "sig", + "lam", + "hold", + "phi", + "k0", + "ka", + "kb", + "K", + "S", + "cr", + "cg", + "cb", + "er", + "eg", + "eb", + "mr", + "mg", + "mb", +] as const; + +type AuroraCols = Record<(typeof COL_KEYS)[number], Float32Array>; + +interface InternalState { + host: HTMLElement; + canvas: HTMLCanvasElement; + ctx: CanvasRenderingContext2D; + res?: number; + radius?: number; + level: number; + wave: number; + phase: number; + W: number; + H: number; + t: number; + raf: number; + held: boolean; + visible: boolean; + img: ImageData | null; + alpha: Uint8ClampedArray; + add: Float32Array; + mix: Float32Array; + cols: AuroraCols; +} + +function roundedRectDist( + px: number, + py: number, + W: number, + H: number, + r: number, + rr: number, + len: number, +): [number, number] { + if (rr === r) { + const dist = r - len; + return [dist, dist / H]; + } + const qx = Math.abs(px - W / 2) - W / 2 + rr; + const qy = Math.abs(py - H / 2) - H / 2 + rr; + const dist = rr - Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) - Math.min(Math.max(qx, qy), 0); + const k = 0.035 * H; + const dh = + (-k * + Math.log( + Math.exp(-px / k) + Math.exp(-(W - px) / k) + Math.exp(-py / k) + Math.exp(-(H - py) / k), + )) / + H; + return [dist, dh]; +} + +function fillGeometryMasks(st: InternalState, W: number, H: number, dpr: number): void { + const n = W * H; + const r = H / 2; + const rimW = Math.max(0.6 * dpr, 0.011 * H); + const rr = st.radius == null ? r : Math.min(r, st.radius * dpr); + st.alpha = new Uint8ClampedArray(n); + st.add = new Float32Array(n); + st.mix = new Float32Array(n); + for (let y = 0, p = 0; y < H; y++) { + const py = y + 0.5; + for (let x = 0; x < W; x++, p++) { + const px = x + 0.5; + const dx = px - Math.min(W - r, Math.max(r, px)); + const dy = py - r; + const len = Math.hypot(dx, dy); + const nx = len ? dx / len : 0; + const ny = len ? dy / len : 0; + const [dist, dh] = roundedRectDist(px, py, W, H, r, rr, len); + st.alpha[p] = Math.round(255 * Math.min(1, Math.max(0, dist + 0.5))); + st.add[p] = Math.exp(-dh / 0.065) * (0.35 + 0.65 * Math.abs(nx)); + const bottom = + 0.85 * Math.exp(-Math.pow(Math.max(0, dh) / 0.09, 1.2)) * smoothStep(0.15, 0.8, ny); + const key = Math.max(0, -0.8 * nx - 0.6 * ny); + const lit = 0.07 + 0.3 * key * key + 0.82 * smoothStep(-0.5, 0.8, ny); + const rim = lit * Math.exp(-Math.pow(Math.max(0, dist) / rimW, 2)); + st.mix[p] = 1 - (1 - bottom) * (1 - rim); + } + } +} + +function fillColumnTables(cols: AuroraCols, W: number): void { + const T = getAuroraTables(); + const tmp3 = [0, 0, 0]; + const tmp1 = [0]; + for (const key of COL_KEYS) cols[key] = new Float32Array(W); + for (let i = 0; i < W; i++) { + const u = (i + 0.5) / W; + cols.u[i] = u; + sampleTable(T.surf, u, tmp3); + cols.s[i] = tmp3[0]!; + cols.a[i] = tmp3[1]!; + cols.b[i] = tmp3[2]!; + cols.sig[i] = sampleTable(T.sigma, u, tmp1)[0]!; + cols.lam[i] = sampleTable(T.lambda, u, tmp1)[0]!; + cols.hold[i] = sampleTable(T.hold, u, tmp1)[0]!; + sampleTable(T.depth, u, tmp3); + cols.k0[i] = tmp3[0]!; + cols.ka[i] = tmp3[1]!; + cols.kb[i] = tmp3[2]!; + cols.phi[i] = sampleTable(T.phi, u, tmp1)[0]!; + } +} + +function measure(st: InternalState): boolean { + const w = st.host.offsetWidth; + const h = st.host.offsetHeight; + if (w <= 0 || h <= 0) return false; + const dpr = st.res ?? Math.min(3, Math.max(1, window.devicePixelRatio || 1)); + const W = Math.max(1, Math.round(w * dpr)); + const H = Math.max(1, Math.round(h * dpr)); + if (W === st.W && H === st.H) return false; + st.W = W; + st.H = H; + st.canvas.width = W; + st.canvas.height = H; + st.img = st.ctx.createImageData(W, H); + fillGeometryMasks(st, W, H, dpr); + fillColumnTables(st.cols, W); + return true; +} + +function updateColumnFrame(st: InternalState, t: number): void { + const { W, cols, level, wave, phase } = st; + const T = getAuroraTables(); + const tmp = [0, 0, 0]; + const w = (2 * Math.PI) / PERIOD; + const sn = Math.sin(w * t); + const cs = 1 - Math.cos(w * t); + const drift = (DRIFT * cs) / 2; + const applyPour = level !== 1 || wave !== 0; + for (let i = 0; i < W; i++) { + const u = cols.u[i]!; + let sv = cols.s[i]! + cols.a[i]! * sn + cols.b[i]! * cs; + if (applyPour) { + sv = 1.12 + (sv - 1.12) * level + wave * Math.sin(2 * Math.PI * (1.5 * u + phase)); + } + cols.S[i] = sv; + cols.K[i] = Math.max(0.25, cols.k0[i]! + cols.ka[i]! * sn + cols.kb[i]! * cs); + const uc = u - drift * Math.max(0, 1 - Math.abs(u - 0.68) / 0.12); + sampleTable(T.core, uc, tmp); + cols.cr[i] = tmp[0]!; + cols.cg[i] = tmp[1]!; + cols.cb[i] = tmp[2]!; + sampleTable(T.edge, uc, tmp); + cols.er[i] = tmp[0]!; + cols.eg[i] = tmp[1]!; + cols.eb[i] = tmp[2]!; + sampleTable(T.mid, uc, tmp); + cols.mr[i] = tmp[0]! * cols.cr[i]!; + cols.mg[i] = tmp[1]! * cols.cg[i]!; + cols.mb[i] = tmp[2]! * cols.cb[i]!; + } +} + +function sampleLiquidRgb( + cols: AuroraCols, + x: number, + d: number, + out: [number, number, number], +): void { + if (d < 0) { + const k = Math.exp(d / cols.phi[x]!); + out[0] = BASE[0] + (cols.er[x]! - BASE[0]) * k; + out[1] = BASE[1] + (cols.eg[x]! - BASE[1]) * k; + out[2] = BASE[2] + (cols.eb[x]! - BASE[2]) * k; + return; + } + const sig = cols.sig[x]!; + if (d < sig) { + let k = d / sig; + k = k * k * (3 - 2 * k); + const k0 = (1 - k) * (1 - k); + const k1 = 2 * k * (1 - k); + const k2 = k * k; + out[0] = k0 * cols.er[x]! + k1 * cols.mr[x]! + k2 * cols.cr[x]!; + out[1] = k0 * cols.eg[x]! + k1 * cols.mg[x]! + k2 * cols.cg[x]!; + out[2] = k0 * cols.eb[x]! + k1 * cols.mb[x]! + k2 * cols.cb[x]!; + return; + } + const e = d - sig - cols.hold[x]! * cols.K[x]!; + const k = e <= 0 ? 1 : Math.exp(-e / (cols.lam[x]! * cols.K[x]!)); + out[0] = MILK[0] + (cols.cr[x]! - MILK[0]) * k; + out[1] = MILK[1] + (cols.cg[x]! - MILK[1]) * k; + out[2] = MILK[2] + (cols.cb[x]! - MILK[2]) * k; +} + +function draw(st: InternalState, t: number): void { + if (!st.img || st.W <= 0 || st.H <= 0) return; + const { W, H, img, alpha, add, mix, cols } = st; + const d8 = img.data; + updateColumnFrame(st, t); + const rgb: [number, number, number] = [0, 0, 0]; + for (let y = 0, p = 0; y < H; y++) { + const v = (y + 0.5) / H; + for (let x = 0; x < W; x++, p++) { + const q = p * 4; + const al = alpha[p]!; + if (!al) { + d8[q + 3] = 0; + continue; + } + sampleLiquidRgb(cols, x, v - cols.S[x]!, rgb); + const ad = add[p]!; + const m = mix[p]!; + const r = Math.max(rgb[0], BASE[0] + ad * GLOW[0]); + const g = Math.max(rgb[1], BASE[1] + ad * GLOW[1]); + const b = Math.max(rgb[2], BASE[2] + ad * GLOW[2]); + d8[q] = r + (WHITE[0] - r) * m; + d8[q + 1] = g + (WHITE[1] - g) * m; + d8[q + 2] = b + (WHITE[2] - b) * m; + d8[q + 3] = al; + } + } + st.ctx.putImageData(img, 0, 0); + st.t = t; +} + +const NOOP_CONTROLLER: AuroraController = { + seek: () => {}, + play: () => {}, + setFill: () => {}, + destroy: () => {}, +}; + +/** Attach the animated aurora canvas inside `host` (a pill button or rounded card). */ +export function buildAuroraRing( + host: HTMLElement, + opts: { res?: number; radius?: number; time?: number } = {}, +): AuroraController { + const canvas = document.createElement("canvas"); + canvas.className = "hf-aurora-fill"; + canvas.setAttribute("aria-hidden", "true"); + let ctx: CanvasRenderingContext2D | null = null; + try { + ctx = canvas.getContext("2d"); + } catch { + ctx = null; + } + if (!ctx) return NOOP_CONTROLLER; + + host.classList.add("hf-aurora"); + if (typeof getComputedStyle === "function" && getComputedStyle(host).position === "static") { + host.classList.add("hf-aurora-anchor"); + } + host.prepend(canvas); + + const reduce = + typeof window.matchMedia === "function" + ? window.matchMedia("(prefers-reduced-motion: reduce)") + : null; + + const emptyCols = Object.fromEntries(COL_KEYS.map((k) => [k, new Float32Array(0)])) as AuroraCols; + + const st: InternalState = { + host, + canvas, + ctx, + res: opts.res, + radius: opts.radius, + level: 1, + wave: 0, + phase: 0, + W: 0, + H: 0, + t: 0, + raf: 0, + held: false, + visible: true, + img: null, + alpha: new Uint8ClampedArray(0), + add: new Float32Array(0), + mix: new Float32Array(0), + cols: emptyCols, + }; + + const start = performance.now() - (opts.time ?? 0) * 1000; + const stop = () => { + cancelAnimationFrame(st.raf); + st.raf = 0; + }; + const loop = () => { + if (!st.raf && !st.held && st.visible && !(reduce?.matches ?? false)) { + st.raf = requestAnimationFrame(frame); + } + }; + const frame = (now: number) => { + st.raf = 0; + if (st.W === 0) measure(st); + draw(st, (now - start) / 1000); + loop(); + }; + + if (measure(st)) draw(st, opts.time ?? 0); + loop(); + + const ro = + typeof ResizeObserver === "function" + ? new ResizeObserver(() => { + if (measure(st)) draw(st, st.t); + }) + : null; + ro?.observe(host); + + const io = + typeof IntersectionObserver === "function" + ? new IntersectionObserver((entries) => { + const entry = entries[0]; + if (!entry) return; + st.visible = entry.isIntersecting; + if (st.visible) loop(); + else stop(); + }) + : null; + io?.observe(host); + + const onMotion = () => { + if (reduce?.matches) { + stop(); + draw(st, 0); + } else { + loop(); + } + }; + reduce?.addEventListener?.("change", onMotion); + + return { + seek(t: number, fill: AuroraFillState = {}) { + st.held = true; + stop(); + st.level = fill.level ?? 1; + st.wave = fill.wave ?? 0; + st.phase = fill.phase ?? 0; + if (st.W === 0) measure(st); + draw(st, t); + }, + play() { + st.held = false; + loop(); + }, + setFill(fill: AuroraFillState) { + if (fill.level !== undefined) st.level = fill.level; + if (fill.wave !== undefined) st.wave = fill.wave; + if (fill.phase !== undefined) st.phase = fill.phase; + }, + destroy() { + stop(); + ro?.disconnect(); + io?.disconnect(); + reduce?.removeEventListener?.("change", onMotion); + canvas.remove(); + host.classList.remove("hf-aurora", "hf-aurora-anchor"); + }, + }; +} diff --git a/packages/studio/src/components/desktop-card/auroraTables.ts b/packages/studio/src/components/desktop-card/auroraTables.ts new file mode 100644 index 00000000000..3631d28b706 --- /dev/null +++ b/packages/studio/src/components/desktop-card/auroraTables.ts @@ -0,0 +1,231 @@ +// Pre-baked faithful aurora lookup tables for the install pill and Catalog upsell card. + +const STEPS = 400; + +type KnotTable = ReadonlyArray; + +const SURF: KnotTable = [ + [0, 0.392, 0.012, -0.002], + [0.04, 0.406, 0.013, -0.005], + [0.08, 0.481, 0.008, -0.013], + [0.12, 0.536, 0.004, -0.022], + [0.16, 0.587, -0.002, -0.043], + [0.2, 0.609, -0.008, -0.059], + [0.24, 0.614, -0.01, -0.067], + [0.28, 0.597, -0.012, -0.062], + [0.32, 0.564, -0.014, -0.047], + [0.36, 0.494, -0.013, -0.034], + [0.4, 0.434, -0.016, -0.03], + [0.44, 0.374, -0.023, -0.021], + [0.48, 0.344, -0.035, -0.013], + [0.52, 0.33, -0.054, -0.01], + [0.56, 0.324, -0.061, -0.004], + [0.6, 0.334, -0.065, 0.003], + [0.64, 0.382, -0.066, -0.007], + [0.68, 0.403, -0.053, -0.002], + [0.72, 0.406, -0.039, 0.009], + [0.76, 0.397, -0.041, 0.029], + [0.8, 0.382, -0.05, 0.041], + [0.84, 0.371, -0.056, 0.051], + [0.88, 0.38, -0.051, 0.055], + [0.92, 0.414, -0.038, 0.049], + [0.96, 0.463, -0.025, 0.038], + [1, 0.477, -0.023, 0.035], +]; + +const PALETTE_FAITHFUL: { core: KnotTable; edge: KnotTable; mid: KnotTable } = { + core: [ + [0, 192, 112, 45], + [0.05, 178, 96, 14], + [0.1, 176, 118, 10], + [0.14, 177, 142, 24], + [0.17, 172, 164, 48], + [0.21, 152, 170, 60], + [0.25, 136, 174, 76], + [0.31, 114, 176, 90], + [0.38, 96, 173, 112], + [0.45, 40, 166, 126], + [0.53, 28, 156, 152], + [0.61, 8, 148, 176], + [0.66, 104, 114, 182], + [0.69, 146, 94, 178], + [0.73, 162, 68, 176], + [0.78, 168, 40, 173], + [0.83, 156, 14, 174], + [0.88, 136, 8, 176], + [0.93, 104, 5, 170], + [0.97, 96, 20, 172], + [1, 118, 50, 186], + ], + edge: [ + [0, 72, 22, 52], + [0.33, 70, 24, 54], + [0.37, 14, 52, 60], + [0.42, 5, 32, 64], + [0.62, 5, 32, 64], + [0.66, 30, 24, 76], + [0.7, 42, 14, 70], + [1, 38, 14, 72], + ], + mid: [ + [0, 0.5, 0.42, 0.05], + [0.3, 0.55, 0.5, 0.2], + [0.38, 0.5, 0.52, 0.5], + [0.62, 0.5, 0.55, 0.55], + [0.68, 0.72, 0.72, 0.72], + [1, 0.72, 0.72, 0.72], + ], +}; + +const SIGMA: KnotTable = [ + [0, 0.05], + [0.1, 0.05], + [0.13, 0.09], + [0.19, 0.09], + [0.22, 0.045], + [0.33, 0.05], + [0.37, 0.1], + [0.42, 0.17], + [0.6, 0.17], + [0.64, 0.07], + [0.68, 0.05], + [1, 0.05], +]; + +const LAMBDA: KnotTable = [ + [0, 0.2], + [0.06, 0.17], + [0.12, 0.12], + [0.18, 0.1], + [0.3, 0.09], + [0.45, 0.1], + [0.62, 0.1], + [0.7, 0.13], + [0.78, 0.15], + [0.86, 0.22], + [0.93, 0.26], + [1, 0.22], +]; + +const HOLD: KnotTable = [ + [0, 0.03], + [0.86, 0.03], + [0.92, 0.1], + [1, 0.1], +]; + +const DEPTH: KnotTable = [ + [0, 0.99, 0.002, 0.05], + [0.014, 0.99, 0.002, 0.05], + [0.037, 1.787, -0.041, 0.008], + [0.059, 1.489, -0.063, 0.053], + [0.082, 1.107, -0.042, 0.07], + [0.105, 0.864, 0.058, 0.021], + [0.127, 0.465, 0.04, 0.106], + [0.15, 0.3, 0.271, -0.009], + [0.172, 0.304, 0.287, 0.073], + [0.195, 0.505, 0.328, 0.125], + [0.218, 0.409, 0.398, 0.105], + [0.24, 0.78, 0.983, 0.132], + [0.263, 0.843, 0.641, 0.302], + [0.4, 1, 0.475, 0.111], + [0.5, 1, 0.354, -0.029], + [0.6, 1, 0.232, -0.169], + [0.737, 0.803, 0.066, -0.36], + [0.76, 0.878, -0.115, -0.286], + [0.782, 0.849, -0.218, -0.222], + [0.805, 0.901, -0.231, -0.224], + [0.828, 0.904, -0.121, -0.289], + [0.85, 1.018, -0.158, -0.226], + [0.873, 1.137, -0.135, -0.219], + [0.895, 1.121, -0.077, -0.229], + [0.918, 1.264, -0.082, -0.154], + [0.941, 1.332, -0.026, -0.179], + [0.963, 1.067, 0.08, -0.15], + [0.986, 1.05, 0.228, -0.284], + [1, 1.05, 0.228, -0.284], +]; + +const PHI: KnotTable = [ + [0, 0.05], + [0.33, 0.055], + [0.4, 0.06], + [0.62, 0.06], + [0.68, 0.035], + [1, 0.035], +]; + +export const smoothStep = (a: number, b: number, x: number): number => { + const k = Math.min(1, Math.max(0, (x - a) / (b - a))); + return k * k * (3 - 2 * k); +}; + +function buildFineTable(table: KnotTable, blur: number): Float32Array[] { + const n = table[0]!.length - 1; + const raw: number[][] = []; + for (let i = 0, j = 0; i <= STEPS; i++) { + const u = i / STEPS; + while (j < table.length - 2 && u > table[j + 1]![0]!) j++; + const a = table[j]!; + const b = table[j + 1]!; + const k = Math.min(1, Math.max(0, (u - a[0]!) / (b[0]! - a[0]!))); + raw.push(Array.from({ length: n }, (_, c) => a[c + 1]! + k * (b[c + 1]! - a[c + 1]!))); + } + const s = blur * STEPS; + const r = Math.ceil(3 * s); + const ker: number[] = []; + for (let k = -r; k <= r; k++) ker.push(Math.exp(-0.5 * (k / s) ** 2)); + return raw.map((_, i) => { + const out = new Float32Array(n); + let ws = 0; + for (let k = 0; k < ker.length; k++) { + const w = ker[k]!; + const src = raw[Math.min(STEPS, Math.max(0, i + k - r))]!; + ws += w; + for (let c = 0; c < n; c++) out[c] = out[c]! + w * src[c]!; + } + for (let c = 0; c < n; c++) out[c] = out[c]! / ws; + return out; + }); +} + +export function sampleTable(fine: Float32Array[], u: number, out: number[]): number[] { + const x = Math.min(STEPS, Math.max(0, u * STEPS)); + const i = Math.min(STEPS - 1, Math.floor(x)); + const k = x - i; + const a = fine[i]!; + const b = fine[i + 1]!; + for (let c = 0; c < out.length; c++) out[c] = a[c]! + k * (b[c]! - a[c]!); + return out; +} + +interface AuroraTables { + surf: Float32Array[]; + sigma: Float32Array[]; + lambda: Float32Array[]; + hold: Float32Array[]; + depth: Float32Array[]; + phi: Float32Array[]; + core: Float32Array[]; + edge: Float32Array[]; + mid: Float32Array[]; +} + +let cachedTables: AuroraTables | null = null; + +export function getAuroraTables(): AuroraTables { + if (!cachedTables) { + cachedTables = { + surf: buildFineTable(SURF, 0.018), + sigma: buildFineTable(SIGMA, 0.03), + lambda: buildFineTable(LAMBDA, 0.03), + hold: buildFineTable(HOLD, 0.03), + depth: buildFineTable(DEPTH, 0.03), + phi: buildFineTable(PHI, 0.03), + core: buildFineTable(PALETTE_FAITHFUL.core, 0.02), + edge: buildFineTable(PALETTE_FAITHFUL.edge, 0.02), + mid: buildFineTable(PALETTE_FAITHFUL.mid, 0.02), + }; + } + return cachedTables; +} diff --git a/packages/studio/src/components/desktop-card/cardChoreography.ts b/packages/studio/src/components/desktop-card/cardChoreography.ts new file mode 100644 index 00000000000..ec5e0e43bbc --- /dev/null +++ b/packages/studio/src/components/desktop-card/cardChoreography.ts @@ -0,0 +1,394 @@ +import { CARD_MEDIA } from "./cardMedia"; +import type { DesktopCardSceneIndex } from "./desktopCardStore"; +import { + SCENE_PLAYERS, + curT, + fillHomeCard, + placeSlot, + type CamState, + type HomeCardData, + type LayerKey, + type SceneContext, +} from "./cardScenePlayers"; +import { + DUR, + EASE, + PH, + REF_X, + SECTIONS, + VIS_H, + VIS_W, + type CardStageElements, +} from "./cardStageTypes"; + +const camT = (c: CamState) => `translate(${-c.x * c.s}px,${-c.y * c.s}px) scale(${c.s})`; + +const SEND_ARROW_SVG = + ''; + +function safeAnimate( + el: Element | null, + keyframes: Keyframe[], + options: KeyframeAnimationOptions, + bag: Animation[], + persistEnd = true, +): Animation | null { + if (!el) return null; + const last = keyframes[keyframes.length - 1]; + const applyFinal = () => { + if (!persistEnd || !last || !(el instanceof HTMLElement || el instanceof SVGElement)) return; + for (const [k, v] of Object.entries(last)) { + if (k !== "offset" && k !== "easing" && v !== undefined) { + (el.style as unknown as Record)[k] = String(v); + } + } + }; + if (typeof el.animate !== "function") { + applyFinal(); + return null; + } + try { + const a = el.animate(keyframes, options); + a.finished?.catch(() => {}); + bag.push(a); + if (persistEnd) { + a.onfinish = () => { + applyFinal(); + a.cancel(); + }; + } + return a; + } catch { + applyFinal(); + return null; + } +} + +function populateHomeGrid( + cards: (HTMLDivElement | null)[], + items: readonly HomeCardData[], + slots: number[], +): void { + items.forEach((item, i) => { + const el = cards[i] ?? null; + fillHomeCard(el, item); + placeSlot(el, i); + slots[i] = i; + if (el) el.style.opacity = "1"; + }); +} + +function updateHeadline( + box: HTMLDivElement | null, + text: string, + animate: boolean, + reduce: boolean, +): void { + if (!box) return; + const spans = [...box.querySelectorAll("span")]; + spans.slice(0, -1).forEach((s) => s.remove()); + const old = spans[spans.length - 1]; + const next = document.createElement("span"); + next.textContent = text; + box.appendChild(next); + if (!old) return; + if (!animate || reduce || typeof old.animate !== "function") { + old.remove(); + return; + } + const out = old.animate( + [ + { transform: "translateY(0)", opacity: 1 }, + { transform: "translateY(-6px)", opacity: 0 }, + ], + { duration: 200, easing: EASE.in, fill: "forwards" }, + ); + out.finished?.catch(() => {}); + out.onfinish = () => old.remove(); + out.oncancel = () => old.remove(); + const enter = next.animate( + [ + { transform: "translateY(8px)", opacity: 0 }, + { transform: "translateY(0)", opacity: 1 }, + ], + { + duration: 380, + delay: 200, + easing: "cubic-bezier(0.22, 1, 0.36, 1)", + fill: "backwards", + }, + ); + enter.finished?.catch(() => {}); +} + +export interface CardChoreographyController { + jump: (idx: DesktopCardSceneIndex) => void; + stop: () => void; +} + +export function createCardChoreography(params: { + cardEl: HTMLDivElement; + stage: CardStageElements; + lineBox: HTMLDivElement | null; + segBars: (HTMLElement | null)[]; + agentHeadline: string; +}): CardChoreographyController | null { + const { cardEl, stage, lineBox, segBars, agentHeadline } = params; + const { layerP, layerA, layerB, layerR, cursor } = stage; + if (!layerP || !layerA || !layerB || !layerR || !cursor) return null; + + const layers: Record = { P: layerP, A: layerA, B: layerB, R: layerR }; + const lines = [ + agentHeadline, + "Comment and draw on any frame", + "All your projects, available instantly", + "The motion library", + "Remix any video", + ]; + const reduce = + typeof window.matchMedia === "function" && + window.matchMedia("(prefers-reduced-motion: reduce)").matches; + + let timers: number[] = []; + let anims: Animation[] = []; + let curLayer: LayerKey = "P"; + let curPos = { x: 200, y: 300 }; + const cams: Record<"A" | "B", CamState> = { + A: { x: 0, y: 410, s: 1 }, + B: { x: 0, y: 0, s: 0.6 }, + }; + const projSlots = CARD_MEDIA.projects.map((_, i) => i); + const syncSlots = CARD_MEDIA.synced.map(() => 0); + + const at = (sec: number, fn: () => void) => { + timers.push(window.setTimeout(fn, sec * 1000)); + }; + const anim: SceneContext["anim"] = (el, kf, durSec, ease = EASE.out, delaySec = 0) => + safeAnimate( + el, + kf, + { + duration: reduce ? 0 : durSec * 1000, + easing: ease, + delay: reduce ? 0 : delaySec * 1000, + fill: "forwards", + }, + anims, + ); + const killAll = () => { + for (const t of timers) window.clearTimeout(t); + timers = []; + for (const a of anims) { + a.onfinish = null; + a.cancel(); + } + anims = []; + }; + const pauseVideos = (keep: HTMLVideoElement[] = []) => { + cardEl.querySelectorAll("video").forEach((v) => { + if (keep.includes(v)) return; + try { + v.pause(); + } catch { + // happy-dom stub + } + }); + }; + const setCam: SceneContext["setCam"] = (el, key, c) => { + cams[key] = c; + if (el) el.style.transform = camT(c); + }; + const setHomeTab = (forYou: boolean) => { + stage.tabProjects?.setAttribute("data-active", forYou ? "false" : "true"); + stage.tabForYou?.setAttribute("data-active", forYou ? "true" : "false"); + }; + + const resetP = () => { + layerP.querySelectorAll(".hf-dc-app-tile").forEach((t) => { + t.style.opacity = "0"; + t.style.transform = "translateX(0px)"; + }); + }; + const resetA = () => { + stage.drawBtn?.setAttribute("data-active", "false"); + stage.commentBtn?.setAttribute("data-active", "true"); + if (stage.stroke) stage.stroke.style.strokeDashoffset = "1"; + if (stage.pin) stage.pin.style.transform = "scale(0)"; + if (stage.bubble) { + stage.bubble.style.transform = "scale(0)"; + stage.bubble.style.opacity = "1"; + stage.bubble.classList.remove("hf-dc-sent"); + } + if (stage.bubbleText) stage.bubbleText.textContent = ""; + if (stage.bubbleSend) stage.bubbleSend.innerHTML = SEND_ARROW_SVG; + setCam(stage.camA, "A", { x: 0, y: 410, s: 1 }); + }; + const resetB = (mode: "projects" | "library") => { + setHomeTab(mode !== "projects"); + if (stage.wipe) stage.wipe.style.clipPath = "circle(0px at 50% 50%)"; + try { + stage.wipeVideo?.pause(); + } catch { + // ignore + } + if (stage.addBtn) stage.addBtn.style.opacity = "0"; + if (mode === "projects") { + populateHomeGrid(stage.projCards, CARD_MEDIA.projects, projSlots); + CARD_MEDIA.synced.forEach((item, i) => { + const el = stage.syncCards[i] ?? null; + fillHomeCard(el, item); + placeSlot(el, 0); + syncSlots[i] = 0; + if (el) el.style.opacity = "0"; + }); + setCam(stage.camB, "B", { x: 0, y: 0, s: 0.6 }); + } else { + stage.syncCards.forEach((el) => { + if (el) el.style.opacity = "0"; + }); + populateHomeGrid(stage.projCards, CARD_MEDIA.library, projSlots); + } + }; + const resetR = () => { + if (stage.phRefBox) stage.phRefBox.style.transform = `translate(${REF_X}px,${PH.top}px)`; + if (stage.phResBox) { + stage.phResBox.style.transform = `translate(${REF_X}px,${PH.top}px)`; + stage.phResBox.style.opacity = "0"; + } + if (stage.arrow) stage.arrow.style.transform = "scale(0)"; + layerR.querySelectorAll("video").forEach((v) => { + try { + v.pause(); + v.currentTime = 0; + } catch { + // ignore + } + }); + }; + + const ctx: SceneContext = { + cardEl, + stage, + layers, + cursor, + cams, + projSlots, + syncSlots, + getCurPos: () => curPos, + setCurPos: (p) => { + curPos = p; + }, + at, + anim, + pauseVideos, + setCam, + moveCam: (el, key, c, dur, ease = EASE.inOut2) => { + anim(el, [{ transform: camT(cams[key]) }, { transform: camT(c) }], dur, ease); + cams[key] = c; + }, + setCursor: (p) => { + curPos = p; + cursor.style.transform = curT(p); + }, + moveCursor: (p, dur, ease = EASE.out) => { + anim(cursor, [{ transform: curT(curPos) }, { transform: curT(p) }], dur, ease); + curPos = p; + }, + tap: () => { + anim( + cursor, + [ + { transform: curT(curPos) }, + { transform: curT(curPos, 0.84), offset: 0.31 }, + { transform: curT(curPos) }, + ], + 0.32, + "linear", + ); + }, + press: (el) => { + anim( + el, + [ + { transform: "scale(1)" }, + { transform: "scale(.94)", offset: 0.3 }, + { transform: "scale(1)" }, + ], + 0.32, + "linear", + ); + }, + toScreen: (key, p) => ({ + x: (p.x - cams[key].x) * cams[key].s, + y: (p.y - cams[key].y) * cams[key].s, + }), + setHomeTab, + showLayer: (k) => { + (Object.entries(layers) as [LayerKey, HTMLDivElement][]).forEach(([name, el]) => { + el.style.transform = name === k ? "translate(0px,0px)" : `translate(${VIS_W}px,0px)`; + }); + curLayer = k; + }, + slide: (toK, dir = "left") => { + const [ox, oy, ix, iy] = dir === "left" ? [-VIS_W, 0, VIS_W, 0] : [0, -VIS_H, 0, VIS_H]; + anim( + layers[curLayer], + [{ transform: "translate(0px,0px)" }, { transform: `translate(${ox}px,${oy}px)` }], + 0.8, + EASE.inOut, + ); + anim( + layers[toK], + [{ transform: `translate(${ix}px,${iy}px)` }, { transform: "translate(0px,0px)" }], + 0.8, + EASE.inOut, + ); + curLayer = toK; + }, + resetP, + resetA, + resetB, + resetR, + }; + + const fillSegs = (i: number) => { + segBars.forEach((bar, k) => { + if (!bar) return; + bar.getAnimations?.().forEach((a) => a.cancel()); + bar.style.width = k < i ? "100%" : "0%"; + }); + const activeBar = segBars[i]; + if (activeBar) { + safeAnimate( + activeBar, + [{ width: "0%" }, { width: "100%" }], + { duration: DUR[i]! * 1000, easing: "linear", fill: "forwards" }, + anims, + ); + } + }; + + const feature = (i: DesktopCardSceneIndex, fromSeam: boolean) => { + fillSegs(i); + updateHeadline(lineBox, lines[i] ?? "", fromSeam, reduce); + const tileVideos = [...cardEl.querySelectorAll(".hf-dc-tile-video")]; + pauseVideos(i >= 3 ? tileVideos : []); + SCENE_PLAYERS[i]!(ctx, fromSeam); + at(DUR[i]!, () => feature(((i + 1) % SECTIONS.length) as DesktopCardSceneIndex, true)); + }; + + return { + jump(idx: DesktopCardSceneIndex) { + killAll(); + resetP(); + resetA(); + resetB("projects"); + resetR(); + feature(idx, false); + }, + stop() { + killAll(); + pauseVideos(); + }, + }; +} diff --git a/packages/studio/src/components/desktop-card/cardMedia.ts b/packages/studio/src/components/desktop-card/cardMedia.ts new file mode 100644 index 00000000000..4e9265e2899 --- /dev/null +++ b/packages/studio/src/components/desktop-card/cardMedia.ts @@ -0,0 +1,81 @@ +// Public CDN assets for the Desktop app showcase card and Catalog upsell (no binaries in repo). +const CARD_ASSET_BASE = "https://static.heygen.ai/hyperframes-oss/studio/desktop-card/v1"; +const MOMENT_M1949_BASE = "https://static.heygen.ai/hyperframes-oss/desktop/moments/v6/M1949"; + +export const CARD_MEDIA = { + editorFrame: `${CARD_ASSET_BASE}/editor-frame.jpg`, + kimiRefVideo: `${CARD_ASSET_BASE}/kimi-ref.mp4`, + kimiRefPoster: `${CARD_ASSET_BASE}/kimi-ref.jpg`, + kimiResVideo: `${CARD_ASSET_BASE}/kimi-res.mp4`, + arollRefVideo: `${CARD_ASSET_BASE}/aroll-ref.mp4`, + arollRefPoster: `${CARD_ASSET_BASE}/aroll-ref.jpg`, + arollResVideo: `${CARD_ASSET_BASE}/aroll-res.mp4`, + arollResPoster: `${CARD_ASSET_BASE}/aroll-res.jpg`, + momentM1949Video: `${MOMENT_M1949_BASE}/clip.mp4`, + momentM1949Poster: `${MOMENT_M1949_BASE}/still.jpg`, + syncRetroMac: `${CARD_ASSET_BASE}/sync-retro-mac.jpg`, + syncCode2Video: `${CARD_ASSET_BASE}/sync-code2video.jpg`, + syncStreamClips: `${CARD_ASSET_BASE}/sync-stream-clips.jpg`, + projects: [ + { + src: `${CARD_ASSET_BASE}/proj-0.webp`, + title: "Upgrade Your Creative Skills", + meta: "Created Nov 3 · edited 2h ago", + }, + { + src: `${CARD_ASSET_BASE}/proj-1.webp`, + title: "Fenario Launch Video", + meta: "Created Oct 27 · edited 20h ago", + }, + { + src: `${CARD_ASSET_BASE}/proj-2.webp`, + title: "HeyGen Website Launch Video", + meta: "Created Nov 2 · edited 2d ago", + }, + { + src: `${CARD_ASSET_BASE}/proj-3.webp`, + title: "hf-studio-top5", + meta: "Created Oct 30 · edited 4d ago", + }, + { + src: `${CARD_ASSET_BASE}/proj-4.webp`, + title: "computer-use-launch", + meta: "Created Oct 30 · edited 5d ago", + }, + { + src: `${CARD_ASSET_BASE}/proj-5.webp`, + title: "Untitled 17", + meta: "Created Oct 30 · edited 5d ago", + }, + ], + synced: [ + { + src: `${CARD_ASSET_BASE}/sync-stream-clips.jpg`, + title: "stream-clips-launch", + meta: "Synced from the preview", + }, + { + src: `${CARD_ASSET_BASE}/sync-code2video.jpg`, + title: "code2video-arena-teaser", + meta: "Synced from the preview", + }, + { + src: `${CARD_ASSET_BASE}/sync-retro-mac.jpg`, + title: "retro-mac-breakdown", + meta: "Synced from the preview", + }, + ], + library: [ + { src: `${CARD_ASSET_BASE}/tile-elevenlabs.webp`, title: "ElevenLabs", meta: "24M views" }, + { src: `${CARD_ASSET_BASE}/tile-anvisha.webp`, title: "Anvisha", meta: "450K views" }, + { src: `${CARD_ASSET_BASE}/tile-relume.webp`, title: "Relume", meta: "757K views" }, + { src: `${CARD_ASSET_BASE}/tile-claudedevs.webp`, title: "ClaudeDevs", meta: "622K views" }, + { + src: `${CARD_ASSET_BASE}/kimi-ref.jpg`, + video: `${CARD_ASSET_BASE}/kimi-ref.mp4`, + title: "Kimi K3 teaser", + meta: "@Kimi_Moonshot", + }, + { src: `${CARD_ASSET_BASE}/tile-mirage.webp`, title: "Mirage", meta: "134K views" }, + ], +} as const; diff --git a/packages/studio/src/components/desktop-card/cardScenePlayers.ts b/packages/studio/src/components/desktop-card/cardScenePlayers.ts new file mode 100644 index 00000000000..9dcd271a0a9 --- /dev/null +++ b/packages/studio/src/components/desktop-card/cardScenePlayers.ts @@ -0,0 +1,420 @@ +import { CARD_MEDIA } from "./cardMedia"; +import { + BUB_POS, + CH, + CW, + EASE, + HOVER_S, + PH, + PICK_SLOT, + PIN_POS, + REF_X, + RES_X, + TAB_FOR_YOU_CENTER, + VIS_H, + VIS_W, + slotXY, + type CardStageElements, +} from "./cardStageTypes"; + +export interface CamState { + x: number; + y: number; + s: number; +} + +export type LayerKey = "P" | "A" | "B" | "R"; +export type HomeCardData = { src: string; title: string; meta: string; video?: string }; + +export const curT = (p: { x: number; y: number }, s = 1) => + `translate(${p.x - 4.2}px,${p.y - 2.8}px) scale(${s})`; + +const SEND_CHECK_SVG = + ''; + +function safePlay(v: HTMLVideoElement | null): void { + if (!v) return; + try { + v.muted = true; + const p = v.play(); + if (p && typeof p.catch === "function") p.catch(() => {}); + } catch { + // happy-dom stub + } +} + +export function placeSlot(el: HTMLDivElement | null, slot: number): void { + if (!el) return; + const p = slotXY(slot); + el.style.transform = `translate(${p.x}px,${p.y}px)`; +} + +export function fillHomeCard(el: HTMLDivElement | null, data: HomeCardData): void { + if (!el) return; + const img = el.querySelector("img"); + if (img) img.src = data.src; + el.querySelectorAll(".hf-dc-tile-video").forEach((v) => v.remove()); + if (data.video) { + const frame = el.querySelector(".hf-dc-home-thumb"); + if (frame) { + const v = document.createElement("video"); + v.className = "hf-dc-tile-video"; + v.src = data.video; + v.muted = true; + v.loop = true; + v.playsInline = true; + v.autoplay = true; + frame.appendChild(v); + safePlay(v); + } + } + const titleEl = el.querySelector(".hf-dc-home-title"); + const metaEl = el.querySelector(".hf-dc-home-meta"); + if (titleEl) titleEl.textContent = data.title; + if (metaEl) metaEl.textContent = data.meta; +} + +const picRectOfPick = () => { + const slot = slotXY(PICK_SLOT); + return { x: slot.x, y: slot.y, w: CW, h: 146, radius: "10px" }; +}; + +const pickCam = (): CamState => { + const g = slotXY(PICK_SLOT); + return { + x: g.x + CW / 2 - VIS_W / HOVER_S / 2, + y: g.y + CH / 2 - VIS_H / HOVER_S / 2, + s: HOVER_S, + }; +}; + +const hoverSpot = () => { + const r = picRectOfPick(); + return { x: r.x + 10, y: r.y + r.h - 36, cx: r.x + 78, cy: r.y + r.h - 23 }; +}; + +export interface SceneContext { + cardEl: HTMLDivElement; + stage: CardStageElements; + layers: Record; + cursor: SVGSVGElement; + cams: Record<"A" | "B", CamState>; + projSlots: number[]; + syncSlots: number[]; + getCurPos: () => { x: number; y: number }; + setCurPos: (p: { x: number; y: number }) => void; + at: (sec: number, fn: () => void) => void; + anim: ( + el: Element | null, + kf: Keyframe[], + durSec: number, + ease?: string, + delaySec?: number, + ) => Animation | null; + pauseVideos: (keep?: HTMLVideoElement[]) => void; + setCam: (el: HTMLDivElement | null, key: "A" | "B", c: CamState) => void; + moveCam: ( + el: HTMLDivElement | null, + key: "A" | "B", + c: CamState, + dur: number, + ease?: string, + ) => void; + setCursor: (p: { x: number; y: number }) => void; + moveCursor: (p: { x: number; y: number }, dur: number, ease?: string) => void; + tap: () => void; + press: (el: Element | null) => void; + toScreen: (key: "A" | "B", p: { x: number; y: number }) => { x: number; y: number }; + setHomeTab: (forYou: boolean) => void; + showLayer: (k: LayerKey) => void; + slide: (toK: LayerKey, dir?: "left" | "up") => void; + resetP: () => void; + resetA: () => void; + resetB: (mode: "projects" | "library") => void; + resetR: () => void; +} + +function playAgentScene(ctx: SceneContext, fromSeam: boolean): void { + ctx.resetP(); + if (fromSeam) ctx.slide("P"); + else ctx.showLayer("P"); + ctx.setCursor({ x: 420, y: 300 }); + ctx.layers.P.querySelectorAll(".hf-dc-app-tile").forEach((tile, k) => + ctx.at(0.25 + k * 0.08, () => { + tile.style.opacity = "1"; + ctx.anim( + tile, + [ + { transform: "translateX(240px)", opacity: 0 }, + { transform: "translateX(0px)", opacity: 1 }, + ], + 0.9, + EASE.back, + ); + }), + ); +} + +function playCommentScene(ctx: SceneContext, fromSeam: boolean): void { + const { stage, cursor } = ctx; + ctx.resetA(); + if (fromSeam) ctx.slide("A"); + else ctx.showLayer("A"); + ctx.setCursor({ x: 150, y: 290 }); + ctx.at(0.15, () => ctx.moveCursor(ctx.toScreen("A", { x: 117, y: 611 }), 0.8)); + ctx.at(0.95, () => { + ctx.tap(); + ctx.press(stage.drawBtn); + stage.drawBtn?.setAttribute("data-active", "true"); + stage.commentBtn?.setAttribute("data-active", "false"); + }); + ctx.at(1.25, () => { + ctx.moveCam(stage.camA, "A", { x: 0, y: 96, s: 1 }, 0.9); + ctx.moveCursor({ x: 44, y: 262 - 96 }, 0.9, EASE.inOut2); + }); + ctx.at(2.25, () => { + ctx.anim(stage.stroke, [{ strokeDashoffset: 1 }, { strokeDashoffset: 0 }], 0.9, EASE.sine); + const sp = stage.stroke; + if (sp && typeof sp.getTotalLength === "function") { + const total = sp.getTotalLength(); + const kf: Keyframe[] = []; + for (let k = 0; k <= 16; k++) { + const pt = sp.getPointAtLength((total * k) / 16); + kf.push({ transform: curT({ x: pt.x, y: pt.y - 96 }) }); + } + ctx.anim(cursor, kf, 0.9, EASE.sine); + } else { + ctx.moveCursor({ x: PIN_POS.x, y: PIN_POS.y - 96 }, 0.9, EASE.sine); + } + ctx.setCurPos({ x: PIN_POS.x, y: PIN_POS.y - 96 }); + }); + ctx.at(3.2, () => { + ctx.anim(stage.pin, [{ transform: "scale(0)" }, { transform: "scale(1)" }], 0.35, EASE.back); + ctx.anim( + stage.bubble, + [ + { transform: "scale(.6)", opacity: 0 }, + { transform: "scale(1)", opacity: 1 }, + ], + 0.45, + EASE.back, + ); + ctx.moveCursor({ x: 352, y: 214 }, 0.6, EASE.out); + }); + const words = "Make this bolder"; + for (let k = 1; k <= words.length; k++) { + ctx.at(3.5 + k * 0.055, () => { + if (stage.bubbleText) stage.bubbleText.textContent = words.slice(0, k); + }); + } + const sendAt = ctx.toScreen("A", { x: BUB_POS.x + 196 - 18, y: BUB_POS.y + 15 }); + ctx.at(4.65, () => ctx.moveCursor(sendAt, 0.45, EASE.out)); + ctx.at(5.15, () => { + ctx.tap(); + ctx.press(stage.bubbleSend); + stage.bubble?.classList.add("hf-dc-sent"); + if (stage.bubbleSend) stage.bubbleSend.innerHTML = SEND_CHECK_SVG; + }); + ctx.at(5.45, () => ctx.moveCursor({ x: 430, y: 300 }, 0.5, EASE.in)); +} + +function shiftSlot( + ctx: SceneContext, + el: HTMLDivElement | null, + slots: number[], + idx: number, +): void { + const from = slotXY(slots[idx]!); + slots[idx] = slots[idx]! + 1; + const to = slotXY(slots[idx]!); + ctx.anim( + el, + [ + { transform: `translate(${from.x}px,${from.y}px)` }, + { transform: `translate(${to.x}px,${to.y}px)` }, + ], + 0.7, + EASE.inOut, + ); +} + +function playSyncScene(ctx: SceneContext, fromSeam: boolean): void { + const { stage, projSlots, syncSlots } = ctx; + ctx.resetB("projects"); + if (fromSeam) ctx.slide("B"); + else ctx.showLayer("B"); + ctx.setCursor({ x: 150, y: 300 }); + CARD_MEDIA.synced.forEach((_, k) => + ctx.at(0.6 + k * 0.6, () => { + stage.projCards.forEach((el, idx) => shiftSlot(ctx, el, projSlots, idx)); + for (let s = 0; s < k; s++) shiftSlot(ctx, stage.syncCards[s] ?? null, syncSlots, s); + const el = stage.syncCards[k] ?? null; + const p = slotXY(0); + syncSlots[k] = 0; + if (el) el.style.opacity = "1"; + ctx.anim( + el, + [ + { transform: `translate(${p.x}px,${p.y - 18}px)`, opacity: 0 }, + { transform: `translate(${p.x}px,${p.y}px)`, opacity: 1 }, + ], + 0.75, + EASE.back, + ); + }), + ); + ctx.at(0.6, () => ctx.moveCam(stage.camB, "B", { x: 0, y: 30, s: 0.68 }, 1.8)); + ctx.at(3.2, () => ctx.moveCursor(ctx.toScreen("B", TAB_FOR_YOU_CENTER), 0.8)); +} + +function playLibraryScene(ctx: SceneContext, fromSeam: boolean): void { + const { stage, projSlots } = ctx; + if (!fromSeam) { + ctx.resetB("library"); + ctx.showLayer("B"); + ctx.setCam(stage.camB, "B", { x: 0, y: 30, s: 0.68 }); + ctx.setCursor(ctx.toScreen("B", { x: TAB_FOR_YOU_CENTER.x, y: 40 })); + } else { + ctx.tap(); + ctx.press(stage.tabForYou); + ctx.setHomeTab(true); + stage.syncCards.forEach((el) => ctx.anim(el, [{ opacity: 1 }, { opacity: 0 }], 0.2, EASE.in)); + CARD_MEDIA.library.forEach((item, k) => { + const el = stage.projCards[k] ?? null; + placeSlot(el, k); + projSlots[k] = k; + ctx.at(0.05 + k * 0.06, () => { + fillHomeCard(el, item); + const p = slotXY(k); + ctx.anim( + el, + [ + { transform: `translate(${p.x}px,${p.y + 14}px)`, opacity: 0 }, + { transform: `translate(${p.x}px,${p.y}px)`, opacity: 1 }, + ], + 0.5, + EASE.back, + ); + }); + }); + } + ctx.at(0.35, () => ctx.moveCam(stage.camB, "B", pickCam(), 2.2)); + ctx.at(0.6, () => ctx.moveCursor({ x: 300, y: 250 }, 0.9, EASE.out)); + ctx.at(1.9, () => { + const h = hoverSpot(); + const c = pickCam(); + ctx.moveCursor({ x: (h.cx - c.x) * c.s, y: (h.cy - c.y) * c.s }, 0.8, EASE.out); + }); + ctx.at(2.6, () => { + const h = hoverSpot(); + if (stage.addBtn) { + stage.addBtn.style.left = `${h.x}px`; + stage.addBtn.style.top = `${h.y}px`; + } + ctx.anim( + stage.addBtn, + [ + { opacity: 0, transform: "translateY(4px)" }, + { opacity: 1, transform: "translateY(0)" }, + ], + 0.3, + EASE.out, + ); + }); +} + +function playRemixScene(ctx: SceneContext, fromSeam: boolean): void { + const { stage } = ctx; + ctx.resetR(); + if (!fromSeam) { + ctx.resetB("library"); + ctx.showLayer("B"); + const c = pickCam(); + ctx.setCam(stage.camB, "B", c); + const h = hoverSpot(); + if (stage.addBtn) { + stage.addBtn.style.left = `${h.x}px`; + stage.addBtn.style.top = `${h.y}px`; + stage.addBtn.style.opacity = "1"; + } + ctx.setCursor({ x: (h.cx - c.x) * c.s, y: (h.cy - c.y) * c.s }); + } + ctx.tap(); + ctx.press(stage.addBtn); + const ir = picRectOfPick(); + if (stage.wipe) { + Object.assign(stage.wipe.style, { + left: `${ir.x}px`, + top: `${ir.y}px`, + width: `${ir.w}px`, + height: `${ir.h}px`, + borderRadius: ir.radius, + clipPath: "circle(0px at 20% 85%)", + }); + } + ctx.at(0.2, () => ctx.moveCursor({ x: ctx.getCurPos().x + 30, y: 300 }, 0.5, EASE.in)); + ctx.at(0.45, () => { + const s = Math.max(VIS_W / ir.w, VIS_H / ir.h); + ctx.moveCam( + stage.camB, + "B", + { x: ir.x + ir.w / 2 - VIS_W / s / 2, y: ir.y + ir.h / 2 - VIS_H / s / 2, s }, + 0.9, + ); + if (stage.wipeVideo) { + stage.wipeVideo.currentTime = 0; + safePlay(stage.wipeVideo); + } + ctx.anim( + stage.wipe, + [ + { clipPath: "circle(0px at 20% 85%)" }, + { clipPath: `circle(${Math.hypot(ir.w, ir.h) * 1.1}px at 20% 85%)` }, + ], + 0.9, + EASE.inOut2, + ); + ctx.anim(stage.addBtn, [{ opacity: 1 }, { opacity: 0 }], 0.2, EASE.in); + }); + ctx.at(2.9, () => { + ctx.slide("R", "up"); + safePlay(stage.phRefBox?.querySelector("video") ?? null); + }); + ctx.at(3.75, () => { + const refV = stage.phRefBox?.querySelector("video") ?? null; + const resV = stage.phResBox?.querySelector("video") ?? null; + ctx.pauseVideos([refV, resV].filter((v): v is HTMLVideoElement => v !== null)); + }); + ctx.at(4.0, () => { + if (stage.phResBox) stage.phResBox.style.opacity = "1"; + const resV = stage.phResBox?.querySelector("video") ?? null; + if (resV) { + resV.currentTime = 0; + safePlay(resV); + } + ctx.anim( + stage.phResBox, + [ + { transform: `translate(${REF_X}px,${PH.top}px)` }, + { transform: `translate(${RES_X}px,${PH.top}px)` }, + ], + 0.75, + EASE.back, + ); + ctx.anim( + stage.arrow, + [{ transform: "scale(0)" }, { transform: "scale(1)" }], + 0.35, + EASE.back, + 0.45, + ); + }); +} + +export const SCENE_PLAYERS: readonly ((ctx: SceneContext, fromSeam: boolean) => void)[] = [ + playAgentScene, + playCommentScene, + playSyncScene, + playLibraryScene, + playRemixScene, +]; diff --git a/packages/studio/src/components/desktop-card/cardStageTypes.ts b/packages/studio/src/components/desktop-card/cardStageTypes.ts new file mode 100644 index 00000000000..8c8f29c8bb9 --- /dev/null +++ b/packages/studio/src/components/desktop-card/cardStageTypes.ts @@ -0,0 +1,89 @@ +export const SECTIONS = ["agent", "comment", "sync", "library", "remix"] as const; +export const DUR = [3.0, 5.8, 4.1, 3.4, 7.6] as const; + +export const EASE = { + out: "cubic-bezier(.215,.61,.355,1)", + inOut: "cubic-bezier(.645,.045,.355,1)", + inOut2: "cubic-bezier(.455,.03,.515,.955)", + in: "cubic-bezier(.55,.055,.675,.19)", + back: "cubic-bezier(.34,1.45,.64,1)", + sine: "cubic-bezier(.37,0,.63,1)", +} as const; + +export const CARD_W = 404; +export const VIS_W = 376; +export const VIS_H = 235; +export const CW = 260; +export const CH = 189; +const GAP = 16; +const GX = 24; +const GY = 78; +export const PICK_SLOT = 4; +export const HOVER_S = 0.8; +export const PIN_POS = { x: 300, y: 256 }; +export const BUB_POS = { x: 108, y: 276 }; +export const TAB_FOR_YOU_CENTER = { x: 24 + 130.7 + 115.4 / 2, y: 18 + 22 }; +export const PH = { w: 115, h: 205, gap: 34, top: 15 }; +export const REF_X = (VIS_W - PH.w * 2 - PH.gap) / 2; +export const RES_X = REF_X + PH.w + PH.gap; + +export const slotXY = (i: number) => ({ + x: GX + (i % 3) * (CW + GAP), + y: GY + Math.floor(i / 3) * (CH + GAP), +}); + +export interface CardStageElements { + layerP: HTMLDivElement | null; + layerA: HTMLDivElement | null; + layerB: HTMLDivElement | null; + layerR: HTMLDivElement | null; + cursor: SVGSVGElement | null; + camA: HTMLDivElement | null; + drawBtn: HTMLButtonElement | null; + commentBtn: HTMLButtonElement | null; + stroke: SVGPathElement | null; + pin: HTMLDivElement | null; + bubble: HTMLDivElement | null; + bubbleText: HTMLElement | null; + bubbleSend: HTMLSpanElement | null; + camB: HTMLDivElement | null; + tabProjects: HTMLButtonElement | null; + tabForYou: HTMLButtonElement | null; + projCards: (HTMLDivElement | null)[]; + syncCards: (HTMLDivElement | null)[]; + addBtn: HTMLDivElement | null; + wipe: HTMLDivElement | null; + wipeVideo: HTMLVideoElement | null; + phRefBox: HTMLDivElement | null; + phResBox: HTMLDivElement | null; + arrow: HTMLSpanElement | null; +} + +export function createEmptyStageElements(): CardStageElements { + return { + layerP: null, + layerA: null, + layerB: null, + layerR: null, + cursor: null, + camA: null, + drawBtn: null, + commentBtn: null, + stroke: null, + pin: null, + bubble: null, + bubbleText: null, + bubbleSend: null, + camB: null, + tabProjects: null, + tabForYou: null, + projCards: [], + syncCards: [], + addBtn: null, + wipe: null, + wipeVideo: null, + phRefBox: null, + phResBox: null, + arrow: null, + }; +} diff --git a/packages/studio/src/components/desktop-card/desktopCard.test.tsx b/packages/studio/src/components/desktop-card/desktopCard.test.tsx new file mode 100644 index 00000000000..dd8e8e38fb8 --- /dev/null +++ b/packages/studio/src/components/desktop-card/desktopCard.test.tsx @@ -0,0 +1,209 @@ +// @vitest-environment happy-dom + +import React, { act } from "react"; +import { createRoot, type Root } from "react-dom/client"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { resolveDesktopCardAgent } from "./agentBrands"; +import { CatalogDesktopUpsell } from "./CatalogDesktopUpsell"; +import { + canAutoOpenDesktopCard, + DESKTOP_CARD_LAST_AUTO_KEY, + getDesktopCardSnapshot, + maybeAutoOpenDesktopCard, + ONE_WEEK_MS, + resetDesktopCardStore, + setDesktopCardRoute, +} from "./desktopCardStore"; +import { PropertyPanelEmptyState } from "../editor/PropertyPanelEmptyState"; +import type { DesktopRoute } from "../DesktopGuideCard"; + +(globalThis as unknown as { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT = true; + +const DOWNLOAD = "https://hyperframes.studio/studio/download?src=browser-editor"; + +const notInstalledRoute = (os: "darwin" | "win32" | "linux" = "darwin"): DesktopRoute => ({ + handoff: false, + downloadUrl: DOWNLOAD, + context: { + os, + app_installed: false, + download_available: true, + placement: "header", + }, +}); + +const installedRoute: DesktopRoute = { + handoff: true, + downloadUrl: DOWNLOAD, + context: { + os: "darwin", + app_installed: true, + download_available: true, + placement: "header", + }, +}; + +function makeStorage(): Pick { + const map = new Map(); + return { + getItem: (key) => map.get(key) ?? null, + setItem: (key, val) => { + map.set(key, val); + }, + }; +} + +let mounted: { root: Root; host: HTMLElement } | null = null; + +function renderInto(node: React.ReactElement): HTMLElement { + const host = document.createElement("div"); + document.body.append(host); + const root = createRoot(host); + mounted = { root, host }; + act(() => root.render(node)); + return host; +} + +beforeEach(() => { + resetDesktopCardStore(); +}); + +afterEach(() => { + vi.unstubAllGlobals(); + if (mounted) { + const { root, host } = mounted; + mounted = null; + act(() => root.unmount()); + host.remove(); + } + resetDesktopCardStore(); +}); + +describe("once-a-week auto-open rule", () => { + it("opens once after watching or exporting, then suppresses auto-open for 7 full days", () => { + const storage = makeStorage(); + const t0 = 1_700_000_000_000; + setDesktopCardRoute(notInstalledRoute("darwin")); + + expect(canAutoOpenDesktopCard(t0, storage)).toBe(true); + expect(maybeAutoOpenDesktopCard("auto_watch", t0, storage)).toBe(true); + expect(getDesktopCardSnapshot()).toMatchObject({ open: true, scene: 0, source: "auto_watch" }); + expect(storage.getItem(DESKTOP_CARD_LAST_AUTO_KEY)).toBe(String(t0)); + + // Close and try again 6 days later: must NOT auto-open. + resetDesktopCardStore(); + setDesktopCardRoute(notInstalledRoute("darwin")); + expect(maybeAutoOpenDesktopCard("auto_export", t0 + ONE_WEEK_MS - 1000, storage)).toBe(false); + expect(getDesktopCardSnapshot().open).toBe(false); + + // Exactly 7 days later: auto-open is allowed again. + expect(maybeAutoOpenDesktopCard("auto_export", t0 + ONE_WEEK_MS, storage)).toBe(true); + expect(getDesktopCardSnapshot()).toMatchObject({ open: true, scene: 0, source: "auto_export" }); + }); + + it("never auto-opens when Desktop is already installed or no route is offered", () => { + const storage = makeStorage(); + expect(maybeAutoOpenDesktopCard("auto_watch", 1000, storage)).toBe(false); + setDesktopCardRoute(installedRoute); + expect(maybeAutoOpenDesktopCard("auto_export", 1000, storage)).toBe(false); + expect(storage.getItem(DESKTOP_CARD_LAST_AUTO_KEY)).toBeNull(); + }); +}); + +describe("agent-tailored Scene 0 copy and mark", () => { + it("names known coding agents and falls back to generic coding agent for cursor/unknown", () => { + expect(resolveDesktopCardAgent("claude_code")).toEqual({ + name: "Claude Code", + logo: "Claude Code", + headline: "Keep using your Claude Code subscription", + }); + expect(resolveDesktopCardAgent("codex")).toEqual({ + name: "Codex", + logo: "Codex", + headline: "Keep using your Codex subscription", + }); + expect(resolveDesktopCardAgent("antigravity")).toEqual({ + name: "Antigravity", + logo: "Antigravity", + headline: "Keep using your Antigravity subscription", + }); + expect(resolveDesktopCardAgent("cursor")).toEqual({ + name: null, + logo: null, + headline: "Keep using your coding agent", + }); + expect(resolveDesktopCardAgent("human")).toEqual({ + name: null, + logo: null, + headline: "Keep using your coding agent", + }); + }); +}); + +describe("CatalogDesktopUpsell", () => { + it("renders the dark aurora upsell with 3 fanned videos and OS-aware CTA when Desktop is not installed", () => { + const opened: string[] = []; + vi.stubGlobal("open", (url: string) => (opened.push(url), { opener: {} })); + setDesktopCardRoute(notInstalledRoute("win32")); + const host = renderInto(); + + const card = host.querySelector('[data-testid="catalog-desktop-upsell"]'); + expect(card).not.toBeNull(); + expect(card!.textContent).toContain( + "Download the desktop app to give your agent access to thousands of videos.", + ); + expect(card!.querySelectorAll(".hf-up-tile video")).toHaveLength(3); + const cta = host.querySelector('[data-testid="catalog-desktop-upsell-cta"]'); + expect(cta!.textContent).toBe("Download free for Windows"); + + act(() => cta!.click()); + expect(opened).toHaveLength(1); + expect(opened[0]).toContain("hf_cta="); + expect(cta!.textContent).toBe("Download started"); + }); + + it("stays hidden when Desktop is already installed or no preview server route exists", () => { + const host = renderInto(); + expect(host.querySelector('[data-testid="catalog-desktop-upsell"]')).toBeNull(); + + act(() => setDesktopCardRoute(installedRoute)); + expect(host.querySelector('[data-testid="catalog-desktop-upsell"]')).toBeNull(); + }); +}); + +describe("PropertyPanelEmptyState Desktop-only options", () => { + it("shows the 5 Desktop-only rows (excluding Record a gesture) and opens each row's card scene", () => { + setDesktopCardRoute(notInstalledRoute("darwin")); + const host = renderInto(); + + const list = host.querySelector('[data-testid="empty-inspector-desktop-options"]'); + expect(list).not.toBeNull(); + expect(list!.textContent).not.toContain("Record a gesture"); + + const expected: readonly [string, number][] = [ + ["agent", 0], + ["draw", 1], + ["comment", 1], + ["library", 3], + ["remix", 4], + ]; + expect(list!.querySelectorAll("button")).toHaveLength(5); + + for (const [id, scene] of expected) { + const btn = list!.querySelector(`[data-desktop-option="${id}"]`); + expect(btn, `missing option ${id}`).not.toBeNull(); + act(() => btn!.click()); + expect(getDesktopCardSnapshot()).toMatchObject({ + open: true, + scene, + source: "empty_inspector", + }); + } + }); + + it("stays hidden when Desktop is installed so Desktop's own Studio never sees upsell rows", () => { + setDesktopCardRoute(installedRoute); + const host = renderInto(); + expect(host.querySelector('[data-testid="empty-inspector-desktop-options"]')).toBeNull(); + }); +}); diff --git a/packages/studio/src/components/desktop-card/desktopCardStore.ts b/packages/studio/src/components/desktop-card/desktopCardStore.ts new file mode 100644 index 00000000000..e6c1f18cb71 --- /dev/null +++ b/packages/studio/src/components/desktop-card/desktopCardStore.ts @@ -0,0 +1,197 @@ +import { useSyncExternalStore } from "react"; +import { resolveTabId } from "../../telemetry/tabId"; +import { trackStudioEvent } from "../../utils/studioTelemetry"; +import type { DesktopRoute } from "../DesktopGuideCard"; + +export const DESKTOP_CARD_LAST_AUTO_KEY = "hf_desktop_card_last_auto_at"; +export const ONE_WEEK_MS = 7 * 24 * 60 * 60 * 1000; + +export type DesktopCardSceneIndex = 0 | 1 | 2 | 3 | 4; + +export type DesktopCardSource = + | "header" + | "auto_watch" + | "auto_export" + | "empty_inspector" + | "catalog"; + +export interface DesktopCardSnapshot { + route: DesktopRoute | null; + open: boolean; + scene: DesktopCardSceneIndex; + openSeq: number; + source: DesktopCardSource; + downloaded: boolean; +} + +let state: DesktopCardSnapshot = { + route: null, + open: false, + scene: 0, + openSeq: 0, + source: "header", + downloaded: false, +}; + +const listeners = new Set<() => void>(); + +function emit(): void { + for (const listener of listeners) listener(); +} + +function subscribe(listener: () => void): () => void { + listeners.add(listener); + return () => listeners.delete(listener); +} + +export function getDesktopCardSnapshot(): DesktopCardSnapshot { + return state; +} + +export function useDesktopCardStore(): DesktopCardSnapshot { + return useSyncExternalStore(subscribe, getDesktopCardSnapshot, getDesktopCardSnapshot); +} + +/** Update the shared `/api/open-in-desktop` route discovered by OpenInDesktopButton. */ +export function setDesktopCardRoute(route: DesktopRoute | null): void { + if (state.route === route) return; + state = { ...state, route }; + emit(); +} + +export function openDesktopCard( + scene: DesktopCardSceneIndex = 0, + source: DesktopCardSource = "header", +): void { + state = { + ...state, + open: true, + scene, + openSeq: state.openSeq + 1, + source, + }; + emit(); +} + +export function closeDesktopCard(): void { + if (!state.open) return; + state = { ...state, open: false }; + emit(); +} + +function setDesktopCardDownloaded(downloaded: boolean): void { + if (state.downloaded === downloaded) return; + state = { ...state, downloaded }; + emit(); +} + +export function resetDesktopCardStore(): void { + state = { + route: null, + open: false, + scene: 0, + openSeq: 0, + source: "header", + downloaded: false, + }; + emit(); +} + +/** True when Desktop is not installed yet and a real download URL is offered by the preview server. */ +export function canShowDesktopUpsell(route: DesktopRoute | null): boolean { + return ( + route !== null && !route.context.app_installed && !route.handoff && route.downloadUrl !== null + ); +} + +export function resolveDownloadOs(os: string): { + key: "mac" | "win" | "linux"; + label: string; +} { + if (os === "win32") return { key: "win", label: "Download free for Windows" }; + if (os === "linux") return { key: "linux", label: "Download free for Linux" }; + return { key: "mac", label: "Download free for Mac" }; +} + +/** Tag the download URL with this page's telemetry tab id so installs are attributable. */ +export function withDesktopCta(url: string): string { + const tagged = new URL(url); + tagged.searchParams.set("hf_cta", resolveTabId()); + return tagged.toString(); +} + +export function launchDesktopDownload( + route: DesktopRoute, + source: DesktopCardSource, + showToast?: (message: string, tone?: "error" | "info") => void, +): boolean { + if (!route.downloadUrl) return false; + const ctx = { ...route.context, source }; + trackStudioEvent("toolbar_action", { action: "get_desktop_app", ...ctx }); + const tab = window.open(withDesktopCta(route.downloadUrl), "_blank"); + if (!tab) { + showToast?.(`Get the HyperFrames desktop app at ${route.downloadUrl}`, "info"); + trackStudioEvent("desktop_cta_outcome", { + outcome: "failed", + reason: "download_tab_blocked", + ...ctx, + }); + return false; + } + tab.opener = null; + setDesktopCardDownloaded(true); + trackStudioEvent("desktop_cta_outcome", { outcome: "sent_to_download", ...ctx }); + trackStudioEvent("desktop_cta_guide", { step: "download_opened", ...ctx }); + return true; +} + +function defaultStorage(): Pick | null { + try { + return typeof localStorage !== "undefined" ? localStorage : null; + } catch { + return null; + } +} + +/** At most once per week: true when no auto-open was recorded within the last 7 days. */ +export function canAutoOpenDesktopCard( + now = Date.now(), + storage: Pick | null = defaultStorage(), +): boolean { + if (!storage) return true; + try { + const raw = storage.getItem(DESKTOP_CARD_LAST_AUTO_KEY); + if (!raw) return true; + const last = Number(raw); + if (!Number.isFinite(last)) return true; + return now - last >= ONE_WEEK_MS; + } catch { + return true; + } +} + +function markDesktopCardAutoOpened( + now = Date.now(), + storage: Pick | null = defaultStorage(), +): void { + if (!storage) return; + try { + storage.setItem(DESKTOP_CARD_LAST_AUTO_KEY, String(now)); + } catch { + // Storage quota or private browsing; skip persistence without failing the open. + } +} + +/** Attempt an automatic open (playback ended / export complete), obeying the once-a-week cap. */ +export function maybeAutoOpenDesktopCard( + source: "auto_watch" | "auto_export", + now = Date.now(), + storage: Pick | null = defaultStorage(), +): boolean { + if (!canShowDesktopUpsell(state.route)) return false; + if (state.open) return false; + if (!canAutoOpenDesktopCard(now, storage)) return false; + markDesktopCardAutoOpened(now, storage); + openDesktopCard(0, source); + return true; +} diff --git a/packages/studio/src/components/editor/PropertyPanelEmptyState.tsx b/packages/studio/src/components/editor/PropertyPanelEmptyState.tsx index 6a466acdd83..fe4b7e34a98 100644 --- a/packages/studio/src/components/editor/PropertyPanelEmptyState.tsx +++ b/packages/studio/src/components/editor/PropertyPanelEmptyState.tsx @@ -2,8 +2,119 @@ import { Eye, Layers } from "../../icons/SystemIcons"; import type { DomEditSelection } from "./domEditingTypes"; import { canHideSelections } from "../../utils/timelineInspector"; import { useTrackDesignInput } from "../../contexts/DesignPanelInputContext"; +import { + canShowDesktopUpsell, + openDesktopCard, + useDesktopCardStore, + type DesktopCardSceneIndex, +} from "../desktop-card/desktopCardStore"; + +type DesktopOptionId = "agent" | "draw" | "comment" | "library" | "remix"; + +interface DesktopEmptyOption { + id: DesktopOptionId; + label: string; + iconClass: string; + shortcut?: (os: string) => string; + scene: DesktopCardSceneIndex; +} + +const DESKTOP_EMPTY_OPTIONS: readonly DesktopEmptyOption[] = [ + { + id: "agent", + label: "Describe a change to the agent", + iconClass: "text-accent-ink", + shortcut: (os) => (os === "darwin" ? "⌘K" : "Ctrl+K"), + scene: 0, + }, + { + id: "draw", + label: "Draw on any frame", + iconClass: "text-accent-ink", + shortcut: () => "D", + scene: 1, + }, + { + id: "comment", + label: "Comment on any frame", + iconClass: "text-accent-ink", + shortcut: () => "C", + scene: 1, + }, + { + id: "library", + label: "Browse the motion library", + iconClass: "text-panel-media", + scene: 3, + }, + { + id: "remix", + label: "Remix a reference video", + iconClass: "text-panel-container", + scene: 4, + }, +]; + +function DesktopOptionIcon({ id, className }: { id: DesktopOptionId; className: string }) { + const shared = { + width: 13, + height: 13, + viewBox: "0 0 16 16", + fill: "none", + stroke: "currentColor", + strokeWidth: 1.5, + strokeLinecap: "round" as const, + strokeLinejoin: "round" as const, + className: `shrink-0 ${className}`, + "aria-hidden": true as const, + }; + switch (id) { + case "agent": + return ( + + + + ); + case "draw": + return ( + + + + ); + case "comment": + return ( + + + + ); + case "library": + return ( + + + + + + + ); + case "remix": + return ( + + + + + ); + } +} function FlatEmptyState() { + const { route } = useDesktopCardStore(); + const showDesktopRows = canShowDesktopUpsell(route); + const os = route?.context.os ?? "darwin"; + return (
@@ -22,6 +133,32 @@ function FlatEmptyState() {
Click any element on the canvas to edit it, or drag to select several.
+ {showDesktopRows && ( +
+ {DESKTOP_EMPTY_OPTIONS.map((item) => ( + + ))} +
+ )}
); } diff --git a/packages/studio/src/components/sidebar/BlocksTab.tsx b/packages/studio/src/components/sidebar/BlocksTab.tsx index e91ae7c693a..dcace8d6583 100644 --- a/packages/studio/src/components/sidebar/BlocksTab.tsx +++ b/packages/studio/src/components/sidebar/BlocksTab.tsx @@ -2,6 +2,7 @@ import { memo, useState, useCallback, useRef, useEffect } from "react"; import { createPortal } from "react-dom"; import { SearchInput } from "../ui/SearchInput"; +import { CatalogDesktopUpsell } from "../desktop-card/CatalogDesktopUpsell"; import { PromptPreviewModal } from "./PromptPreviewModal"; import { useBlockCatalog } from "../../hooks/useBlockCatalog"; import { @@ -47,7 +48,9 @@ export const BlocksTab = memo(function BlocksTab({ onAddBlock, onPreviewBlock }: } return ( -
+
+ + {/* Search */}
{/* Block grid */} -
+
{category === "vfx" && (
VFX blocks use WebGL via HTML-in-Canvas. Enable{" "} diff --git a/packages/studio/src/components/ui/HyperframesLogo.tsx b/packages/studio/src/components/ui/HyperframesLogo.tsx index b170f0e7165..185596bd7c5 100644 --- a/packages/studio/src/components/ui/HyperframesLogo.tsx +++ b/packages/studio/src/components/ui/HyperframesLogo.tsx @@ -1,121 +1,48 @@ +import { useId } from "react"; + +// Desktop's HyperFrames mark: two cyan-to-green leaves beside the HyperFrames wordmark. +const LEAVES = { + left: { + d: "M10.1851 57.8021L33.1145 73.8313C36.2202 75.9978 41.5173 73.5433 42.4816 69.4984L51.7611 30.4271C52.7253 26.3822 48.5802 23.9277 44.4602 26.0942L13.917 42.1235C6.96677 45.7676 4.97564 54.1579 10.1851 57.8021Z", + gradient: { x1: 48.57, y1: 25, x2: 44.78, y2: 71.94 }, + }, + right: { + d: "M87.5129 57.5141L56.9696 73.5433C52.8371 75.7098 48.7046 73.2553 49.6688 69.2104L58.9483 30.1391C59.9125 26.0942 65.2097 23.6397 68.3154 25.8062L91.2447 41.8354C96.4668 45.4796 94.4631 53.8699 87.5129 57.5141Z", + gradient: { x1: 54.83, y1: 73.84, x2: 72.1, y2: 32.89 }, + }, +} as const; + export function HyperframesLogo() { - // Full logo from logo-dark.svg (263×79): heygen label + gradient mark + hyperframes wordmark. - // The wordmark paths take the text colour, so the logo reads in both themes. - const height = 28; - const width = Math.round(height * (263 / 79)); + const uid = useId().replace(/:/g, ""); + const leftId = `hf-leaf-l-${uid}`; + const rightId = `hf-leaf-r-${uid}`; return ( - - - - - - - - - - - - {/* heygen label */} - - - - - - - {/* gradient icon mark */} - - - {/* hyperframes wordmark */} - - - - - - - - - - - - + + + + HyperFrames + + ); } diff --git a/packages/studio/src/styles/components.css b/packages/studio/src/styles/components.css index b1f31c060d7..6025fcdc7c5 100644 --- a/packages/studio/src/styles/components.css +++ b/packages/studio/src/styles/components.css @@ -1194,7 +1194,654 @@ .hf-framey-mood .hf-framey-whole, .hf-framey-orbit, .hf-guide-swap, - .hf-guide-tick { + .hf-guide-tick, + .hf-trim-shine { animation: none; } + .hf-trim-shine { + display: none; + } +} + +.hf-logo-word { + font-family: var(--hf-dc-font-display); +} + +/* Aurora canvas host (install pill and Catalog upsell card). */ +.hf-aurora { + isolation: isolate; +} +.hf-aurora.hf-aurora-anchor { + position: relative; +} +.hf-aurora > canvas.hf-aurora-fill { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + z-index: -1; + border-radius: inherit; + pointer-events: none; +} + +/* Header glowing "Make editing easier" pill (1:1 with prototype createTrim). */ +.hf-trim { + position: relative; + z-index: 2; + display: inline-flex; + align-items: center; + height: 32px; + padding: 0 16px; + border: 0; + border-radius: 999px; + isolation: isolate; + background: var(--hf-dc-trim-bg); + color: var(--hf-dc-trim-fg); + font: 700 13.5px / 1 var(--hf-dc-font-display); + letter-spacing: 0.01em; + white-space: nowrap; + cursor: pointer; + transition: + transform 0.15s var(--hf-dc-ease), + text-shadow 0.3s var(--hf-dc-ease); + box-shadow: var(--hf-dc-trim-shadow); +} +.hf-trim:active { + transform: scale(0.97); +} +.hf-trim:hover { + text-shadow: var(--hf-dc-trim-hover-glow); +} +.hf-trim-label { + position: relative; +} +.hf-trim-shine { + position: absolute; + inset: 0; + color: transparent; + text-shadow: none; + pointer-events: none; + opacity: 0; + transition: opacity 0.5s var(--hf-dc-ease); + background: var(--hf-dc-trim-shine-bg) 120% 0 / 200% 100% no-repeat; + -webkit-background-clip: text; + background-clip: text; + animation: hf-trim-shine 4.8s cubic-bezier(0.37, 0, 0.63, 1) infinite paused; +} +.hf-trim:hover .hf-trim-shine { + opacity: 1; + animation-play-state: running; +} +@keyframes hf-trim-shine { + 0% { + background-position: 120% 0; + } + 75%, + 100% { + background-position: -20% 0; + } +} +.hf-trim-edge { + position: absolute; + z-index: -1; + overflow: visible; + pointer-events: none; +} +.hf-trim-heat { + opacity: 0; + transition: opacity 0.3s var(--hf-dc-ease); +} +.hf-trim:hover .hf-trim-heat { + opacity: 1; +} +.hf-trim-wisps { + position: absolute; + z-index: 2; + overflow: visible; + pointer-events: none; +} + +/* Floating 5-scene Desktop app card (liquid glass in both light and dark themes). */ +.hf-dc-card { + position: fixed; + z-index: 1000; + width: 404px; + padding: 14px; + border-radius: 16px; + font-family: var(--hf-dc-font-sans); + color: var(--hf-dc-card-fg); + background: var(--hf-dc-card-bg), var(--hf-dc-card-base); + -webkit-backdrop-filter: blur(28px) saturate(180%); + backdrop-filter: blur(28px) saturate(180%); + box-shadow: var(--hf-dc-card-shadow-dark); + transition: + opacity 0.18s var(--hf-dc-ease), + transform 0.18s var(--hf-dc-ease); +} +:root[data-theme="paper"] .hf-dc-card { + box-shadow: var(--hf-dc-card-shadow-light); +} +.hf-dc-card[data-open="false"] { + opacity: 0; + transform: scale(0.85); + pointer-events: none; +} +.hf-dc-card[data-open="true"] { + opacity: 1; + transform: none; + transition-duration: 0.25s; +} +.hf-dc-vis { + cursor: pointer; + position: relative; + width: 376px; + height: 235px; + border-radius: 12px; + overflow: hidden; + background: var(--hf-dc-paper); + box-shadow: var(--hf-dc-vis-ring); + font-family: var(--hf-dc-font-sans); + isolation: isolate; +} +.hf-dc-layer { + position: absolute; + inset: 0; + height: 235px; + overflow: hidden; + will-change: transform; +} +.hf-dc-layer-p, +.hf-dc-layer-r { + background: var(--hf-dc-paper); +} +.hf-dc-cam { + position: absolute; + left: 0; + top: 0; + transform-origin: 0 0; + will-change: transform; +} +.hf-dc-x { + position: absolute; + top: 22px; + right: 22px; + z-index: 5; + display: grid; + place-items: center; + width: 26px; + height: 26px; + padding: 0; + border: 0; + border-radius: 50%; + background: var(--hf-dc-close-bg); + -webkit-backdrop-filter: blur(8px); + backdrop-filter: blur(8px); + color: var(--hf-dc-close-fg); + cursor: pointer; +} +.hf-dc-x:hover { + background: var(--hf-dc-close-hover); +} +.hf-dc-segs { + display: grid; + grid-template-columns: repeat(5, 1fr); + gap: 6px; + margin: 12px 2px 0; +} +.hf-dc-seg { + position: relative; + height: 14px; + padding: 0; + border: 0; + background: none; + cursor: pointer; +} +.hf-dc-seg::before { + content: ""; + position: absolute; + left: 0; + right: 0; + top: 5px; + height: 3px; + border-radius: 999px; + background: var(--hf-dc-seg-track); +} +.hf-dc-seg i { + position: absolute; + left: 0; + top: 5px; + height: 3px; + width: 0; + border-radius: 999px; + background: var(--hf-dc-seg-fill); +} +.hf-dc-line { + position: relative; + height: 54px; + margin: 10px 2px 0; + overflow: hidden; +} +.hf-dc-line span { + position: absolute; + inset: 0; + display: flex; + align-items: center; + justify-content: center; + color: var(--hf-dc-card-fg); + font: 700 22px / 26px var(--hf-dc-font-display); + letter-spacing: -0.01em; + text-align: center; + text-wrap: balance; +} +.hf-dc-cta { + position: relative; + display: flex; + align-items: center; + justify-content: center; + gap: 9px; + width: 100%; + height: 44px; + margin-top: 12px; + padding: 0 28px; + border: 0; + border-radius: 999px; + background: var(--hf-dc-cta-bg); + color: var(--hf-dc-cta-fg); + font: 600 15px / 1 var(--hf-dc-font-sans); + cursor: pointer; + box-shadow: var(--hf-dc-cta-shadow); + transition: background-color 0.15s var(--hf-dc-ease); +} +.hf-dc-cta:hover { + background: var(--hf-dc-cta-hover); +} +.hf-dc-cta svg { + flex: none; +} + +/* Scene 0: Agent logo tiles */ +.hf-dc-logos { + position: absolute; + inset: 0; + display: flex; + align-items: center; + justify-content: center; + gap: 14px; +} +.hf-dc-app-tile { + display: grid; + place-items: center; + width: 60px; + height: 60px; + border-radius: 16px; + background: var(--hf-dc-tile-bg); + color: var(--hf-dc-ink); + box-shadow: var(--hf-dc-tile-shadow); +} +.hf-dc-app-tile.hf-dc-big { + width: 104px; + height: 104px; + border-radius: 26px; +} +.hf-dc-app-tile svg { + width: 56%; + height: 56%; +} + +/* Scene 1: Desktop editor preview with Draw/Comment dock and typed bubble */ +.hf-dc-editor { + position: relative; + width: 637px; + height: 637px; + background: var(--hf-dc-editor-bg); +} +.hf-dc-editor-frame { + position: absolute; + left: 14px; + top: 116px; + width: 609px; + height: 343px; + object-fit: cover; + border-radius: 8px; +} +.hf-dc-editor-dock { + position: absolute; + left: 14px; + top: 593px; + display: inline-flex; + align-items: center; + gap: 2px; + padding: 3px; + border-radius: 10px; + background: var(--hf-dc-editor-dock-bg); + box-shadow: var(--hf-dc-editor-dock-ring); +} +.hf-dc-editor-tool { + display: inline-flex; + align-items: center; + gap: 5px; + height: 30px; + padding: 0 9px; + border: 0; + border-radius: 8px; + background: transparent; + color: var(--hf-dc-editor-tool-idle); + font: 500 12px / 1 var(--hf-dc-font-sans); +} +.hf-dc-editor-tool[data-active="true"] { + background: var(--hf-dc-editor-tool-active-bg); + color: var(--hf-dc-editor-tool-active-fg); +} +.hf-dc-ink { + position: absolute; + left: 0; + top: 0; + overflow: visible; + pointer-events: none; +} +.hf-dc-pin { + position: absolute; + width: 20px; + height: 20px; + margin: -10px 0 0 -10px; + border-radius: 50%; + background: var(--hf-dc-mint); + color: var(--hf-dc-mint-ink); + display: grid; + place-items: center; + font: 700 11px / 1 var(--hf-dc-font-sans); + box-shadow: var(--hf-dc-pin-ring); +} +.hf-dc-bubble { + position: absolute; + display: flex; + align-items: center; + gap: 8px; + width: 196px; + padding: 6px 6px 6px 12px; + border-radius: 12px; + background: var(--hf-dc-bubble-bg); + box-shadow: var(--hf-dc-bubble-shadow); + transform-origin: 0 0; +} +.hf-dc-bubble b { + flex: 1; + font: 500 13px / 18px var(--hf-dc-font-sans); + color: var(--hf-dc-ink); + white-space: nowrap; + overflow: hidden; + text-align: left; +} +.hf-dc-bubble b::after { + content: ""; + display: inline-block; + width: 1px; + height: 14px; + margin-left: 1px; + vertical-align: -2px; + background: var(--hf-dc-ink); +} +.hf-dc-bubble.hf-dc-sent b::after { + display: none; +} +.hf-dc-send { + display: grid; + place-items: center; + width: 24px; + height: 24px; + border-radius: 50%; + background: var(--hf-dc-mint); + color: var(--hf-dc-mint-ink); +} + +/* Scenes 2 & 3: Desktop Home (Your Projects + For You motion library) */ +.hf-dc-home { + position: relative; + width: 860px; + height: 720px; + background: var(--hf-dc-home-bg); + color: var(--hf-dc-ink); + text-align: left; +} +.hf-dc-home-bar { + position: absolute; + left: 24px; + top: 18px; + display: inline-flex; + align-items: center; + gap: 4px; + height: 44px; +} +.hf-dc-home-tab { + display: inline-flex; + align-items: center; + gap: 7px; + height: 40px; + padding: 0 18px; + border: 0; + border-radius: 999px; + background: transparent; + color: var(--hf-dc-ink-muted); + font: 500 15px / 1 var(--hf-dc-font-sans); +} +.hf-dc-home-tab[data-active="true"] { + background: var(--hf-dc-home-tab-active-bg); + color: var(--hf-dc-ink); + font-weight: 600; +} +.hf-dc-home-badge { + display: inline-flex; + align-items: center; + justify-content: center; + height: 19px; + padding: 0 7px; + border-radius: 999px; + background: var(--hf-dc-cta-bg); + color: var(--hf-dc-cta-fg); + font: 700 11px / 1 var(--hf-dc-font-sans); +} +.hf-dc-home-card { + position: absolute; + left: 0; + top: 0; + width: 260px; + height: 189px; + will-change: transform; +} +.hf-dc-home-thumb { + position: relative; + width: 260px; + height: 146px; + border-radius: 10px; + overflow: hidden; + background: var(--hf-dc-paper); + box-shadow: var(--hf-dc-home-card-ring); +} +.hf-dc-home-thumb img, +.hf-dc-tile-video { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + object-fit: cover; +} +.hf-dc-home-title { + margin-top: 8px; + font: 600 13px / 16px var(--hf-dc-font-sans); + color: var(--hf-dc-ink); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.hf-dc-home-meta { + margin-top: 2px; + font: 400 11.5px / 15px var(--hf-dc-font-sans); + color: var(--hf-dc-ink-muted); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.hf-dc-hover-add { + position: absolute; + display: flex; + align-items: center; + gap: 6px; + height: 26px; + padding: 0 11px 0 9px; + border-radius: 999px; + background: var(--hf-dc-hover-add-bg); + box-shadow: var(--hf-dc-hover-add-shadow); + font: 500 12px / 1 var(--hf-dc-font-sans); + color: var(--hf-dc-ink); + white-space: nowrap; + opacity: 0; +} +.hf-dc-wipe { + position: absolute; + overflow: hidden; + clip-path: circle(0px at 50% 50%); +} +.hf-dc-wipe video { + position: absolute; + inset: 0; + width: 100%; + height: 100%; + object-fit: cover; +} + +/* Scene 4 payoff: A-roll two-phone remix */ +.hf-dc-phone { + position: absolute; + left: 0; + top: 0; + width: 115px; + height: 205px; + border-radius: 14px; + overflow: hidden; + background: var(--hf-dc-phone-bg); + box-shadow: var(--hf-dc-phone-shadow); +} +.hf-dc-phone video { + display: block; + width: 100%; + height: 100%; + object-fit: cover; +} +.hf-dc-arrow { + position: absolute; + left: 177px; + top: 106px; + display: grid; + place-items: center; + width: 22px; + height: 22px; + border-radius: 50%; + background: var(--hf-dc-mint); + color: var(--hf-dc-mint-ink); +} +.hf-dc-cursor { + position: absolute; + left: 0; + top: 0; + width: 20px; + height: 20px; + z-index: 4; + pointer-events: none; + transform-origin: 21% 14%; + filter: var(--hf-dc-cursor-shadow); + will-change: transform; +} + +/* Catalog tab aurora upsell card (1:1 with prototype createCatalog). */ +.hf-up { + position: relative; + flex: none; + display: flex; + flex-direction: column; + margin: 10px 12px 2px; + padding: 16px 14px 14px; + border-radius: 12px; + overflow: hidden; + background: var(--hf-dc-up-bg); + font-family: var(--hf-dc-font-sans); + color: var(--hf-dc-up-fg); + text-align: left; + box-shadow: var(--hf-dc-up-shadow); + transition: + opacity 0.3s var(--hf-dc-ease), + transform 0.3s var(--hf-dc-ease); +} +.hf-up::after { + content: ""; + position: absolute; + inset: 0; + border-radius: inherit; + pointer-events: none; + box-shadow: var(--hf-dc-up-rim); +} +.hf-up[data-open="false"] { + opacity: 0; + transform: scale(0.92); +} +.hf-up-title { + margin: 0 4px; + color: var(--hf-dc-up-title-fg); + text-align: center; + text-wrap: balance; + font: 700 19px / 22px var(--hf-dc-font-display); + letter-spacing: -0.01em; +} +.hf-up-fan { + position: relative; + height: 124px; + margin-top: 10px; +} +.hf-up-tile { + position: absolute; + left: 50%; + top: 0; + width: 66px; + height: 117px; + margin-left: -33px; + border-radius: 8px; + overflow: hidden; + background: var(--hf-dc-up-tile-bg); + transform-origin: 50% 100%; + box-shadow: var(--hf-dc-up-tile-shadow); +} +.hf-up-tile video { + display: block; + width: 100%; + height: 100%; + object-fit: cover; +} +.hf-up-tile-mid { + z-index: 2; +} +.hf-up-cta { + display: flex; + align-items: center; + justify-content: center; + gap: 8px; + height: 40px; + margin-top: 10px; + padding: 0 20px; + border: 0; + border-radius: 999px; + background: var(--hf-dc-cta-bg); + color: var(--hf-dc-cta-fg); + font: 600 14px / 1 var(--hf-dc-font-sans); + cursor: pointer; + box-shadow: var(--hf-dc-up-cta-shadow); + transition: background-color 0.15s var(--hf-dc-ease); +} +.hf-up-cta:hover { + background: var(--hf-dc-cta-hover); +} +.hf-up-cta:focus-visible { + outline: 2px solid var(--hf-dc-up-focus); + outline-offset: 2px; +} +.hf-up-cta svg { + flex: none; } diff --git a/packages/studio/src/styles/theme.css b/packages/studio/src/styles/theme.css index fc95e023864..8768f966d65 100644 --- a/packages/studio/src/styles/theme.css +++ b/packages/studio/src/styles/theme.css @@ -445,6 +445,151 @@ /* Framey, the desktop app's cursor mascot (hyperframes-internal packages/nib): the same in both themes. */ --color-framey: #3ce6ac; --color-framey-ink: #16121a; + + /* Coding agent brand marks for the Desktop app card. */ + --color-brand-claude: #d97757; + --color-brand-codex-from: #b1a7ff; + --color-brand-codex-mid: #7a9dff; + --color-brand-codex-to: #3941ff; + --color-brand-codex-eye: #ffffff; + + /* Desktop app card, glowing install pill, and Catalog upsell tokens (1:1 with design). */ + --hf-dc-font-sans: "TT Norms Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; + --hf-dc-font-display: "ABC Solar Display", "TT Norms Pro", system-ui, sans-serif; + --hf-dc-ease: cubic-bezier(0.22, 1, 0.36, 1); + --hf-dc-paper: #f2f0ed; + --hf-dc-ink: oklch(0.205 0.003 70); + --hf-dc-ink-muted: oklch(0.45 0.003 70); + --hf-dc-mint: oklch(0.82 0.159 164); + --hf-dc-mint-ink: oklch(0.2 0.043 164); + --hf-dc-cta-bg: oklch(0.536 0.114 164); + --hf-dc-cta-hover: oklch(0.486 0.114 164); + --hf-dc-cta-fg: #ffffff; + --hf-dc-cta-shadow: + inset 0 1px 0 rgb(255 255 255 / 0.22), 0 8px 18px -8px oklch(0.536 0.114 164 / 0.7); + --hf-dc-up-cta-shadow: + inset 0 1px 0 rgb(255 255 255 / 0.22), 0 8px 18px -8px oklch(0.536 0.114 164 / 0.8); + --hf-dc-card-fg: light-dark(oklch(0.205 0.003 70), oklch(0.965 0.004 70)); + --hf-dc-card-bg: light-dark( + linear-gradient(180deg, rgb(255 255 255 / 0.74), rgb(255 255 255 / 0.58)), + linear-gradient( + 180deg, + rgb(255 255 255 / 0.1), + rgb(255 255 255 / 0.035) 45%, + rgb(255 255 255 / 0.06) + ) + ); + --hf-dc-card-base: light-dark(transparent, rgb(30 29 28 / 0.5)); + --hf-dc-card-shadow: light-dark( + inset 0 1px 0 rgb(255 255 255 / 0.95), + inset 0 0.5px 0 rgb(255 255 255 / 0.42) + ); + --hf-dc-card-shadow-light: + inset 0 1px 0 rgb(255 255 255 / 0.95), inset 0 0 0 1px rgb(255 255 255 / 0.5), + 0 1px 2px oklch(0.2 0.01 70 / 0.06), 0 10px 30px oklch(0.2 0.01 70 / 0.1), + 0 34px 80px -34px oklch(0.2 0.01 70 / 0.38); + --hf-dc-card-shadow-dark: + inset 0 0.5px 0 rgb(255 255 255 / 0.42), inset 0 -0.5px 0 rgb(255 255 255 / 0.2), + inset 0 2px 4px -1px rgb(255 255 255 / 0.16), inset 0 -2px 4px -1px rgb(255 255 255 / 0.08), + 0 0 0 0.5px rgb(0 0 0 / 0.45), 0 2px 8px rgb(0 0 0 / 0.35), 0 34px 90px -24px rgb(0 0 0 / 0.75); + --hf-dc-vis-ring: light-dark(0 0 0 1px rgb(0 0 0 / 0.1), 0 0 0 1px rgb(255 255 255 / 0.1)); + --hf-dc-close-bg: rgb(20 20 20 / 0.42); + --hf-dc-close-hover: rgb(20 20 20 / 0.6); + --hf-dc-close-fg: #ffffff; + --hf-dc-seg-track: light-dark(oklch(0.205 0.003 70 / 0.1), rgb(255 255 255 / 0.16)); + --hf-dc-seg-fill: light-dark(oklch(0.205 0.003 70), #ffffff); + --hf-dc-tile-bg: #ffffff; + --hf-dc-tile-shadow: 0 1px 2px oklch(0.2 0.01 70 / 0.08), 0 10px 30px oklch(0.2 0.01 70 / 0.12); + --hf-dc-phone-bg: #111111; + --hf-dc-phone-shadow: 0 0 0 1px rgb(0 0 0 / 0.1), 0 10px 24px -10px rgb(0 0 0 / 0.45); + --hf-dc-cursor-fill: #ffffff; + --hf-dc-cursor-stroke: #111111; + --hf-dc-cursor-shadow: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.3)); + --hf-dc-pin-ring: 0 0 0 2px #0d0d0d; + --hf-dc-bubble-bg: #ffffff; + --hf-dc-bubble-shadow: 0 1px 2px oklch(0.2 0.01 70 / 0.12), 0 10px 30px oklch(0.2 0.01 70 / 0.25); + --hf-dc-hover-add-bg: rgb(255 255 255 / 0.94); + --hf-dc-hover-add-shadow: 0 1px 2px rgb(0 0 0 / 0.14), 0 6px 16px -4px rgb(0 0 0 / 0.25); + --hf-dc-editor-bg: #121212; + --hf-dc-editor-dock-bg: rgb(255 255 255 / 0.09); + --hf-dc-editor-dock-ring: 0 0 0 1px rgb(255 255 255 / 0.08); + --hf-dc-editor-tool-idle: rgba(255, 255, 255, 0.8); + --hf-dc-editor-tool-active-bg: rgb(13 125 96); + --hf-dc-editor-tool-active-fg: #ffffff; + --hf-dc-home-bg: oklch(0.987 0.005 70); + --hf-dc-home-tab-active-bg: rgb(0 0 0 / 0.07); + --hf-dc-home-card-ring: 0 0 0 1px rgb(0 0 0 / 0.08); + --hf-dc-trim-bg: #1c1c1e; + --hf-dc-trim-fg: #ffffff; + --hf-dc-trim-shadow: + inset 0 0.5px 0 rgb(255 255 255 / 0.3), inset 0 -0.5px 0 rgb(255 255 255 / 0.3), + inset 0 1.5px 2px -0.5px rgb(255 255 255 / 0.16), + inset 0 -1.5px 2px -0.5px rgb(255 255 255 / 0.16), 0 0 0 0.5px rgb(0 0 0 / 0.2), + 1.5px 0 0 -0.5px rgb(0 0 0 / 0.2), -1.5px 0 0 -0.5px rgb(0 0 0 / 0.2), + 0 1px 3px rgb(0 0 0 / 0.12); + --hf-dc-trim-hover-glow: 0 0 5px rgb(43 255 176 / 0.4); + --hf-dc-trim-shine-bg: linear-gradient( + 100deg, + transparent 41%, + #9ff5d6 45.5%, + #3ce6ac 50%, + #9ff5d6 54.5%, + transparent 59% + ); + --hf-dc-up-bg: rgb(13 6 33); + --hf-dc-up-fg: #ffffff; + --hf-dc-up-title-fg: oklch(0.985 0.002 70); + --hf-dc-up-shadow: + 0 0 0 0.5px rgb(0 0 0 / 0.4), 0 1px 3px rgb(0 0 0 / 0.16), 0 12px 28px -16px rgb(0 0 0 / 0.45); + --hf-dc-up-rim: inset 0 0.5px 0 rgb(255 255 255 / 0.42), inset 0 0 0 0.5px rgb(255 255 255 / 0.1); + --hf-dc-up-tile-bg: #111111; + --hf-dc-up-tile-shadow: 0 0 0 1px rgb(255 255 255 / 0.14), 0 10px 22px -8px rgb(0 0 0 / 0.6); + --hf-dc-up-focus: #ffffff; +} + +@font-face { + font-family: "TT Norms Pro"; + font-weight: 400; + font-style: normal; + font-display: swap; + src: url("https://static.heygen.ai/hyperframes-oss/homepage/v3/banners/fonts/TT_Norms_Pro_Normal.woff2") + format("woff2"); +} + +@font-face { + font-family: "TT Norms Pro"; + font-weight: 500; + font-style: normal; + font-display: swap; + src: url("https://static.heygen.ai/hyperframes-oss/homepage/v3/banners/fonts/TT_Norms_Pro_Normal.woff2") + format("woff2"); +} + +@font-face { + font-family: "TT Norms Pro"; + font-weight: 600; + font-style: normal; + font-display: swap; + src: url("https://static.heygen.ai/hyperframes-oss/homepage/v3/banners/fonts/TT_Norms_Pro_DemiBold.woff2") + format("woff2"); +} + +@font-face { + font-family: "TT Norms Pro"; + font-weight: 700; + font-style: normal; + font-display: swap; + src: url("https://static.heygen.ai/hyperframes-oss/homepage/v3/banners/fonts/TT_Norms_Pro_Bold.woff2") + format("woff2"); +} + +@font-face { + font-family: "ABC Solar Display"; + font-weight: 700; + font-style: normal; + font-display: swap; + src: url("https://static.heygen.ai/hyperframes-oss/homepage/v3/banners/fonts/ABCSolarDisplay-Bold.woff2") + format("woff2"); } /* The colour-scheme picks each token's light or dark half: dark unless the document element From 7e6418f412fb41905f87ff526da7b6a6673c2775 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 1 Dec 2026 21:01:24 +0000 Subject: [PATCH 2/3] chore(studio): raise packed size budget for Desktop showcase card --- scripts/package-size-budgets.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/package-size-budgets.json b/scripts/package-size-budgets.json index c7721bb51d1..8f0759ade7d 100644 --- a/scripts/package-size-budgets.json +++ b/scripts/package-size-budgets.json @@ -52,7 +52,7 @@ "unpacked": 642146 }, "@hyperframes/studio": { - "packed": 6589635, + "packed": 6700000, "unpacked": 26703858 }, "@hyperframes/studio-server": { From 0b3e3d07df0d439df6b564c064c8772f52ba38d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Tue, 1 Dec 2026 22:29:59 +0000 Subject: [PATCH 3/3] fix(studio): mark closed desktop card inert and lazy-mount stage media --- .../src/components/OpenInDesktopButton.tsx | 17 +--- .../desktop-card/DesktopAppCard.tsx | 91 ++++++++++++++----- .../desktop-card/desktopCard.test.tsx | 85 ++++++++++++++++- .../desktop-card/desktopCardStore.ts | 9 +- packages/studio/src/styles/components.css | 10 +- 5 files changed, 168 insertions(+), 44 deletions(-) diff --git a/packages/studio/src/components/OpenInDesktopButton.tsx b/packages/studio/src/components/OpenInDesktopButton.tsx index 49796c75471..8ce540245be 100644 --- a/packages/studio/src/components/OpenInDesktopButton.tsx +++ b/packages/studio/src/components/OpenInDesktopButton.tsx @@ -16,7 +16,6 @@ import { resolveDownloadOs, setDesktopCardRoute, useDesktopCardStore, - withDesktopCta, } from "./desktop-card/desktopCardStore"; import { GuideCard, @@ -243,6 +242,9 @@ function useShowcaseOpenTelemetry( const prevOpen = useRef(false); useEffect(() => { if (!active || !route) { + if (prevOpen.current && route) { + trackStudioEvent("desktop_cta_guide", { step: "closed", ...route.context, source }); + } prevOpen.current = false; return; } @@ -314,18 +316,7 @@ function useGuide( }; const download = () => { - if (!route.downloadUrl) return; - trackStudioEvent("toolbar_action", { action: "get_desktop_app", ...context }); - const tab = window.open(withDesktopCta(route.downloadUrl), "_blank"); - if (!tab) { - showToast(`Get the HyperFrames desktop app at ${route.downloadUrl}`, "info"); - outcome("failed", "download_tab_blocked"); - return; - } - tab.opener = null; - setDownloaded(true); - outcome("sent_to_download"); - guideStep("download_opened"); + if (launchDesktopDownload(route, undefined, showToast)) setDownloaded(true); }; const landed = async (result: OpenResult) => { diff --git a/packages/studio/src/components/desktop-card/DesktopAppCard.tsx b/packages/studio/src/components/desktop-card/DesktopAppCard.tsx index 8a0b7085869..af28cc7a8a4 100644 --- a/packages/studio/src/components/desktop-card/DesktopAppCard.tsx +++ b/packages/studio/src/components/desktop-card/DesktopAppCard.tsx @@ -56,6 +56,13 @@ function useCardDismiss( anchorRef: React.RefObject, onClose: () => void, ) { + useEffect(() => { + const cardEl = cardRef.current; + if (!cardEl) return; + if (open) cardEl.removeAttribute("inert"); + else cardEl.setAttribute("inert", ""); + }, [cardRef, open]); + useEffect(() => { if (!open) return; const onPointerDown = (event: PointerEvent) => { @@ -93,7 +100,7 @@ function useCardChoreography(params: { useEffect(() => { const cardEl = cardRef.current; - if (!cardEl) return; + if (!cardEl || openSeq === 0) return; const ctrl = createCardChoreography({ cardEl, stage: stageRef.current, @@ -114,6 +121,50 @@ function useCardChoreography(params: { return controllerRef; } +function DesktopAppCardStageSlot({ + openSeq, + agentLogo, + stageRef, + onDownload, +}: { + openSeq: number; + agentLogo: ReturnType["logo"]; + stageRef: React.RefObject>; + onDownload: () => void; +}) { + if (openSeq === 0) return