Device Morph
A design canvas switches a frame between desktop, tablet and phone layouts.
Source
components/kuchi/device-morph.tsx
1"use client";23import { loadFont } from "@remotion/google-fonts/Geist";4import { loadFont as loadMono } from "@remotion/google-fonts/GeistMono";5import type React from "react";6import {7 AbsoluteFill,8 Easing,9 Img,10 interpolate,11 interpolateColors,12 spring,13 useCurrentFrame,14 useVideoConfig,15} from "remotion";16import type { GradientParams } from "@/lib/kuchi/gsh/gradient-engine";17import { GshGround } from "@/lib/kuchi/gsh/gsh-ground";18import type { GshPresetId } from "@/lib/kuchi/gsh/presets";1920const { fontFamily: sans } = loadFont("normal", {21 weights: ["300", "400"],22 subsets: ["latin"],23});24const { fontFamily: mono } = loadMono("normal", {25 weights: ["400"],26 subsets: ["latin"],27});282930export interface DeviceStop {31 label: string;32 width: number;33 height: number;34}3536export interface DeviceMorphProps {37 /** Your own responsive UI; it is laid out at the live viewport width every frame. */38 children?: React.ReactNode;39 /** A screenshot to show instead of the built-in dashboard (no reflow). */40 src?: string;41 /** Exactly three stops: desktop, tablet, phone. */42 stops?: DeviceStop[];43 /** Phone to desktop instead of desktop to phone. */44 reverse?: boolean;45 /** Product name in the built-in dashboard's sidebar and phone header. */46 brand?: string;47 /** Greeting at the top of the built-in dashboard. */48 greeting?: string;49 /** Label of the built-in dashboard's primary button. */50 ctaLabel?: string;51 /** Replaces the acme mark in the built-in dashboard's sidebar. */52 logo?: React.ReactNode;53 accent?: string;54 /** Text color of the device label; overrides the theme ink. */55 ink?: string;56 /** Solid fill in place of the gradient ground; "transparent" drops it. */57 background?: string;58 /** Typeface for the scene and dashboard. Load it yourself; Geist by default. */59 fontFamily?: string;60 /** Size of the device, label and switcher, around the frame's center. */61 scale?: number;62 /** Frames to hold the first frame before anything moves. */63 delay?: number;64 speed?: number;65 theme?: "light" | "dark";66 /** Thumbnails for the six project cards. */67 images?: string[];68 /** gradients.sh preset for the ground. Defaults to "europa" (dark) or "paper-crease" (light). */69 ground?: GshPresetId;70 groundParams?: Partial<GradientParams>;71}7273const DEFAULT_STOPS: DeviceStop[] = [74 { label: "Desktop", width: 1440, height: 900 },75 { label: "Tablet", width: 834, height: 1112 },76 { label: "Phone", width: 390, height: 844 },77];7879const LAYOUT = {80 wide: { dw: 1280, dh: 720, maxW: 820, maxH: 500, cy: 322, segY: 618 },81 tall: { dw: 720, dh: 1280, maxW: 640, maxH: 700, cy: 700, segY: 1140 },82};83const CLICK_A = 50;84const CLICK_B = 124;85const MORPH = 44;8687const inOut = Easing.bezier(0.65, 0, 0.35, 1);88const MORPH_SPRING = { damping: 200 };89const HEAVY = { mass: 1, damping: 26, stiffness: 120 };90const CARD = { mass: 0.8, damping: 18, stiffness: 160 };91const CHIP = { mass: 0.5, damping: 12, stiffness: 200 };92const ease = Easing.bezier(0.22, 1, 0.36, 1);93const clamp01 = {94 extrapolateLeft: "clamp",95 extrapolateRight: "clamp",96} as const;97const lerp = (a: number, b: number, t: number) => a + (b - a) * t;98const seg = (t: number, a: number, b: number, c: number) =>99 t <= 1 ? lerp(a, b, t) : lerp(b, c, t - 1);100const range = (t: number, a: number, b: number) =>101 interpolate(t, [a, b], [0, 1], clamp01);102103function withAlpha(color: string, alpha: number) {104 const hex = color.replace("#", "");105 const full = hex.length === 3 ? hex.replace(/(.)/g, "$1$1") : hex;106 if (!/^[0-9a-fA-F]{6}$/.test(full)) return color;107 const n = Number.parseInt(full, 16);108 return `rgba(${(n >> 16) & 255}, ${(n >> 8) & 255}, ${n & 255}, ${alpha})`;109}110111const PALETTES = {112 light: {113 canvas: "#F1F1F2",114 dot: "rgba(0,0,0,0.09)",115 chrome: "#F4F4F5",116 app: "#FFFFFF",117 side: "#FAFAFA",118 border: "#EAEAEE",119 text: "#111113",120 muted: "#6E6E78",121 faint: "#B9B9C2",122 chip: "#F2F2F4",123 pill: "#FFFFFF",124 good: "#16A34A",125 },126 dark: {127 canvas: "#09090A",128 dot: "rgba(255,255,255,0.07)",129 chrome: "#1A1A1D",130 app: "#0F0F11",131 side: "#0C0C0E",132 border: "#232327",133 text: "#EDEDEF",134 muted: "#8E8E98",135 faint: "#4A4A52",136 chip: "#1C1C20",137 pill: "#17171A",138 good: "#22C55E",139 },140};141type Palette = (typeof PALETTES)["light"];142143const PATHS: Record<string, string> = {144 home: "M4 11l8-7 8 7v9h-5v-6H9v6H4z",145 folder: "M3 6h7l2 2h9v11H3z",146 grid: "M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z",147 play: "M6 4l14 8-14 8z",148 image: "M4 5h16v14H4zM4 15l5-5 4 4 3-3 4 4",149 gear: "M12 9a3 3 0 1 0 0 6 3 3 0 0 0 0-6zM12 2v3M12 19v3M4.2 4.2l2.1 2.1M17.7 17.7l2.1 2.1M2 12h3M19 12h3M4.2 19.8l2.1-2.1M17.7 6.3l2.1-2.1",150 search: "M11 4a7 7 0 1 0 0 14 7 7 0 0 0 0-14zM20 20l-4-4",151 bell: "M6 16V11a6 6 0 0 1 12 0v5l2 2H4zM10 20a2 2 0 0 0 4 0",152 plus: "M12 5v14M5 12h14",153 menu: "M4 7h16M4 12h16M4 17h16",154 monitor: "M3 4h18v12H3zM8 20h8M12 16v4",155 tablet: "M6 3h12v18H6zM11 18h2",156 phone: "M8 3h8v18H8zM11 18h2",157};158159function G({160 n,161 color,162 size = 18,163 sw = 1.5,164}: {165 n: string;166 color: string;167 size?: number;168 sw?: number;169}) {170 return (171 <svg172 width={size}173 height={size}174 viewBox="0 0 24 24"175 aria-hidden="true"176 style={{ display: "block", flexShrink: 0 }}177 >178 <path179 d={PATHS[n]}180 fill="none"181 stroke={color}182 strokeWidth={sw}183 strokeLinecap="round"184 strokeLinejoin="round"185 />186 </svg>187 );188}189190const NAV = [191 { icon: "home", label: "Home" },192 { icon: "folder", label: "Projects" },193 { icon: "grid", label: "Templates" },194 { icon: "play", label: "Renders" },195 { icon: "image", label: "Assets" },196 { icon: "gear", label: "Settings" },197];198199const KPIS = [200 {201 label: "Renders this week",202 value: "128",203 delta: "+18%",204 pts: [4, 6, 5, 8, 7, 11, 14],205 },206 {207 label: "Minutes rendered",208 value: "342",209 delta: "+9%",210 pts: [6, 5, 7, 6, 9, 8, 10],211 },212 {213 label: "Avg. render time",214 value: "41s",215 delta: "−12%",216 pts: [12, 11, 12, 9, 8, 8, 6],217 },218];219220const PROJECTS = [221 {222 title: "Launch teaser",223 meta: "Edited 2h ago · 1080p",224 dur: "0:24",225 },226 {227 title: "Onboarding walkthrough",228 meta: "Edited yesterday · 4K",229 dur: "1:12",230 },231 {232 title: "Changelog 2.4",233 meta: "Edited Mon · 1080p",234 dur: "0:38",235 },236 {237 title: "Customer story: Fernway",238 meta: "Edited Sep 28 · 1080p",239 dur: "2:05",240 },241 {242 title: "Pricing explainer",243 meta: "Edited Sep 24 · 720p",244 dur: "0:45",245 },246 {247 title: "Feature drop: Captions",248 meta: "Edited Sep 19 · 1080p",249 dur: "0:31",250 },251];252253const DEFAULT_IMAGES = [1, 2, 3, 4, 5, 6].map((n) =>254 `https://kuchi-media.kalarislabs.com/components/art/art-${String(((n - 1) % 12) + 1).padStart(2, "0")}.svg`,255);256257function Thumb({258 p,259 i,260 src,261 accent,262}: {263 p: (typeof PROJECTS)[number];264 i: number;265 src: string;266 accent: string;267}) {268 const rendering = i === 1;269 return (270 <div271 style={{272 position: "absolute",273 inset: 0,274 background: "#1A1A1D",275 overflow: "hidden",276 }}277 >278 <Img279 src={src}280 style={{281 width: "100%",282 height: "100%",283 objectFit: "cover",284 display: "block",285 filter: rendering ? "saturate(0.6) brightness(0.8)" : undefined,286 }}287 />288 <div289 style={{290 position: "absolute",291 right: 10,292 bottom: rendering ? 16 : 10,293 padding: "3px 8px",294 borderRadius: 6,295 background: "rgba(10,10,12,0.66)",296 color: "#fff",297 fontSize: 12.5,298 fontWeight: 400,299 fontVariantNumeric: "tabular-nums",300 }}301 >302 {rendering ? "Rendering 64%" : p.dur}303 </div>304 {rendering ? (305 <div306 style={{307 position: "absolute",308 left: 0,309 right: 0,310 bottom: 0,311 height: 4,312 background: "rgba(255,255,255,0.25)",313 }}314 >315 <div style={{ width: "64%", height: "100%", background: accent }} />316 </div>317 ) : null}318 </div>319 );320}321322function Dashboard({323 t,324 vw,325 vh,326 c,327 accent,328 images,329 brand,330 greeting,331 ctaLabel,332 logo,333}: {334 t: number;335 vw: number;336 vh: number;337 c: Palette;338 accent: string;339 images: string[];340 brand: string;341 greeting: string;342 ctaLabel: string;343 logo?: React.ReactNode;344}) {345 const tp = range(t, 1, 2);346 const label = 1 - range(t, 0, 0.55);347 const statusH = seg(t, 0, 24, 46);348 const topH = seg(t, 64, 60, 54);349 const sideW = seg(t, 232, 72, 0);350 const pad = seg(t, 32, 24, 16);351 const cx = sideW + pad;352 const cw = vw - sideW - 2 * pad;353 const top0 = statusH + topH + pad;354 const gap = seg(t, 16, 16, 12);355 const third = (cw - 2 * gap) / 3;356 const kpiW = lerp(third, cw * 0.72, ease(tp));357 const kpiH = 108;358 const secY = top0 + 72 + kpiH + 30;359 const gridY = secY + 38;360 const layoutAt = (n: number) =>361 PROJECTS.map((_, i) => {362 const w = (cw - (n - 1) * gap) / n;363 const h = (w * 9) / 16 + 62;364 return {365 x: cx + (i % n) * (w + gap),366 y: gridY + Math.floor(i / n) * (h + gap),367 w,368 };369 });370 const [from, to, u] =371 t <= 1 ? [layoutAt(3), layoutAt(2), t] : [layoutAt(2), layoutAt(1), t - 1];372 const kAt = (i: number) => inOut(range(u, i * 0.05, 0.75 + i * 0.05));373 const rightPad = seg(t, 24, 20, 16);374 const avatarX = vw - rightPad - 32;375 const btnW = seg(t, 116, 116, 34);376 const btnX = avatarX - 12 - btnW;377 const bellX = btnX - 12 - 34;378 const searchW = seg(t, 260, 34, 0);379 const searchX = bellX - 10 - searchW;380 const phoneOnly = range(t, 1.35, 1.9);381 const txt = { position: "absolute" as const, whiteSpace: "nowrap" as const };382383 return (384 <div385 style={{386 position: "absolute",387 inset: 0,388 background: c.app,389 color: c.text,390 overflow: "hidden",391 }}392 >393 <div394 style={{395 ...txt,396 left: 0,397 top: 0,398 width: vw,399 height: statusH,400 display: "flex",401 alignItems: "center",402 justifyContent: "space-between",403 padding: `0 ${seg(t, 20, 20, 30)}px`,404 boxSizing: "border-box",405 fontSize: seg(t, 12, 13, 16),406 fontWeight: 400,407 opacity: range(t, 0.5, 1),408 }}409 >410 <span>9:41</span>411 <span style={{ display: "flex", gap: 5, alignItems: "center" }}>412 <span413 style={{414 width: 17,415 height: 10,416 borderRadius: 2,417 background: `linear-gradient(90deg, ${c.text} 0 20%, transparent 20% 30%, ${c.text} 30% 50%, transparent 50% 60%, ${c.text} 60% 80%, transparent 80%)`,418 }}419 />420 <span421 style={{422 width: 24,423 height: 11,424 borderRadius: 3,425 border: `1.5px solid ${c.text}`,426 boxSizing: "border-box",427 padding: 1,428 }}429 >430 <span431 style={{432 display: "block",433 width: "70%",434 height: "100%",435 borderRadius: 1,436 background: c.text,437 }}438 />439 </span>440 </span>441 </div>442 <div443 style={{444 position: "absolute",445 left: 0,446 top: statusH,447 width: Math.max(sideW, 0.01),448 bottom: 0,449 background: c.side,450 borderRight: sideW > 1 ? `1px solid ${c.border}` : "none",451 overflow: "hidden",452 }}453 >454 <div455 style={{456 position: "absolute",457 left: lerp(22, 20, label) - 80 * tp,458 top: 18,459 display: "flex",460 alignItems: "center",461 gap: 10,462 }}463 >464 <div465 style={{466 width: 28,467 height: 28,468 borderRadius: 8,469 background: accent,470 display: "flex",471 alignItems: "center",472 justifyContent: "center",473 }}474 >475 {logo ?? (476 <svg viewBox="0 0 124.06 134.26" height={14} aria-hidden>477 <circle cx="62.03" cy="67.13" r="56" fill="#fff" />478 </svg>479 )}480 </div>481 <span482 style={{483 fontSize: 17,484 fontWeight: 400,485 letterSpacing: -0.3,486 opacity: label,487 }}488 >489 {brand}490 </span>491 </div>492 {NAV.map((n, i) => {493 const y = 76 + i * 42;494 const active = i === 1;495 const pillW = lerp(48, sideW - 24, label);496 const shift = -80 * tp;497 return (498 <div key={n.label}>499 {active && (500 <div501 style={{502 position: "absolute",503 left: 12 + shift,504 top: y - 9,505 width: pillW,506 height: 36,507 borderRadius: 9,508 background: withAlpha(accent, 0.1),509 }}510 />511 )}512 <div513 style={{514 position: "absolute",515 left: lerp(27, 24, label) + shift,516 top: y,517 display: "flex",518 alignItems: "center",519 gap: 12,520 }}521 >522 <G n={n.icon} color={active ? accent : c.muted} />523 <span524 style={{525 fontSize: 14.5,526 fontWeight: 400,527 color: active ? c.text : c.muted,528 opacity: label,529 }}530 >531 {n.label}532 </span>533 </div>534 </div>535 );536 })}537 <div538 style={{539 position: "absolute",540 left: 16,541 right: 16,542 bottom: 20,543 padding: 14,544 borderRadius: 12,545 border: `1px solid ${c.border}`,546 background: c.app,547 opacity: label,548 fontSize: 13,549 }}550 >551 <div style={{ fontWeight: 400 }}>Render minutes</div>552 <div style={{ color: c.muted, marginTop: 3 }}>312 of 500 used</div>553 <div554 style={{555 marginTop: 10,556 height: 6,557 borderRadius: 6,558 background: c.chip,559 }}560 >561 <div562 style={{563 width: "62%",564 height: "100%",565 borderRadius: 6,566 background: accent,567 }}568 />569 </div>570 </div>571 </div>572 <div573 style={{574 position: "absolute",575 left: sideW,576 top: statusH,577 right: 0,578 height: topH,579 borderBottom: `1px solid ${c.border}`,580 }}581 >582 <div583 style={{584 ...txt,585 left: pad,586 top: topH / 2 - 10,587 fontSize: 14.5,588 fontWeight: 400,589 color: c.muted,590 opacity: 1 - range(t, 1.05, 1.5),591 }}592 >593 Projects <span style={{ color: c.faint, margin: "0 6px" }}>/</span>594 <span style={{ color: c.text }}>All projects</span>595 </div>596 <div597 style={{598 ...txt,599 left: pad,600 top: topH / 2 - 12,601 display: "flex",602 alignItems: "center",603 gap: 12,604 opacity: phoneOnly,605 transform: `translateX(${(1 - phoneOnly) * -12}px)`,606 }}607 >608 <G n="menu" color={c.text} size={24} />609 <span style={{ fontSize: 19, fontWeight: 400, letterSpacing: -0.3 }}>610 {brand}611 </span>612 </div>613 </div>614 <div615 style={{616 position: "absolute",617 left: searchX,618 top: statusH + topH / 2 - 18,619 width: searchW + 2,620 height: 36,621 borderRadius: 9,622 border: `1px solid ${c.border}`,623 display: "flex",624 alignItems: "center",625 gap: 8,626 paddingLeft: 8,627 boxSizing: "border-box",628 overflow: "hidden",629 opacity: 1 - range(t, 1, 1.4),630 fontSize: 13.5,631 color: c.muted,632 whiteSpace: "nowrap",633 }}634 >635 <G n="search" color={c.muted} size={17} />636 <span style={{ opacity: label, flex: 1 }}>Search projects…</span>637 <span638 style={{639 opacity: label,640 fontSize: 11.5,641 padding: "2px 6px",642 marginRight: 8,643 borderRadius: 5,644 background: c.chip,645 }}646 >647 ⌘K648 </span>649 </div>650 <div651 style={{652 position: "absolute",653 left: bellX + 8,654 top: statusH + topH / 2 - 9,655 opacity: 1 - range(t, 1, 1.4),656 }}657 >658 <G n="bell" color={c.muted} />659 </div>660 <div661 style={{662 position: "absolute",663 left: btnX,664 top: statusH + topH / 2 - 17,665 width: btnW,666 height: 34,667 borderRadius: 9,668 background: accent,669 color: "#fff",670 display: "flex",671 alignItems: "center",672 justifyContent: "center",673 gap: 6,674 fontSize: 13.5,675 fontWeight: 400,676 overflow: "hidden",677 whiteSpace: "nowrap",678 }}679 >680 <G n="plus" color="#fff" size={16} sw={2.2} />681 <span682 style={{683 opacity: 1 - range(t, 1.2, 1.6),684 display: btnW < 60 ? "none" : "inline",685 }}686 >687 {ctaLabel}688 </span>689 </div>690 <div691 style={{692 position: "absolute",693 left: avatarX,694 top: statusH + topH / 2 - 16,695 width: 32,696 height: 32,697 borderRadius: 99,698 background: "#B86A52",699 color: "#fff",700 fontSize: 12,701 fontWeight: 400,702 display: "flex",703 alignItems: "center",704 justifyContent: "center",705 }}706 >707 MC708 </div>709 <div style={{ ...txt, left: cx, top: top0 }}>710 <div711 style={{712 fontSize: seg(t, 26, 25, 23),713 fontWeight: 400,714 letterSpacing: -0.6,715 }}716 >717 {greeting}718 </div>719 <div style={{ fontSize: 14.5, color: c.muted, marginTop: 6 }}>720 3 renders finished overnight.721 </div>722 </div>723 {KPIS.map((m, i) => {724 const x = cx + i * (kpiW + gap);725 const max = Math.max(...m.pts);726 const d = m.pts727 .map(728 (v, j) => `${j === 0 ? "M" : "L"}${j * 12} ${30 - (v / max) * 26}`,729 )730 .join(" ");731 return (732 <div733 key={m.label}734 style={{735 position: "absolute",736 left: x,737 top: top0 + 72,738 width: kpiW,739 height: kpiH,740 borderRadius: 12,741 border: `1px solid ${c.border}`,742 background: c.app,743 boxSizing: "border-box",744 padding: 16,745 overflow: "hidden",746 }}747 >748 <div style={{ fontSize: 13, color: c.muted, whiteSpace: "nowrap" }}>749 {m.label}750 </div>751 <div752 style={{753 display: "flex",754 alignItems: "baseline",755 gap: 8,756 marginTop: 10,757 }}758 >759 <span760 style={{ fontSize: 28, fontWeight: 400, letterSpacing: -0.6 }}761 >762 {m.value}763 </span>764 <span style={{ fontSize: 12, fontWeight: 400, color: c.good }}>765 {m.delta}766 </span>767 </div>768 <svg769 width={74}770 height={32}771 style={{772 position: "absolute",773 right: 16,774 bottom: 18,775 overflow: "visible",776 }}777 aria-hidden="true"778 >779 <path780 d={d}781 fill="none"782 stroke={accent}783 strokeWidth={2}784 strokeLinecap="round"785 strokeLinejoin="round"786 />787 </svg>788 </div>789 );790 })}791 <div792 style={{793 ...txt,794 left: cx,795 top: secY,796 width: cw,797 display: "flex",798 justifyContent: "space-between",799 alignItems: "center",800 }}801 >802 <span style={{ fontSize: 17, fontWeight: 400 }}>Recent projects</span>803 <span style={{ fontSize: 13.5, color: c.muted, fontWeight: 400 }}>804 View all805 </span>806 </div>807 {PROJECTS.map((p, i) => {808 const k = kAt(i);809 const nFrom = t <= 1 ? 3 : 2;810 const hops =811 Math.floor(i / nFrom) !== Math.floor(i / (nFrom - 1)) &&812 to[i].x < from[i].x - 1;813 const at = hops ? (k < 0.5 ? 0 : 1) : k;814 const x = lerp(from[i].x, to[i].x, at);815 const y = lerp(from[i].y, to[i].y, hops ? at : k);816 const w = lerp(from[i].w, to[i].w, k);817 const hop = !hops818 ? 1819 : k < 0.5820 ? 1 - k * 2821 : interpolate(u, [0.5, 0.8], [0, 1], clamp01);822 return (823 <div824 key={p.title}825 style={{826 position: "absolute",827 left: x,828 top: y,829 width: w,830 height: (w * 9) / 16 + 62,831 borderRadius: 12,832 border: `1px solid ${c.border}`,833 background: c.app,834 overflow: "hidden",835 boxSizing: "border-box",836 opacity: hop,837 transform: `scale(${0.96 + 0.04 * hop})`,838 }}839 >840 <div style={{ position: "relative", height: (w * 9) / 16 }}>841 <Thumb842 p={p}843 i={i}844 src={images[i % images.length]}845 accent={accent}846 />847 </div>848 <div style={{ padding: "11px 14px", whiteSpace: "nowrap" }}>849 <div style={{ fontSize: 14.5, fontWeight: 400 }}>{p.title}</div>850 <div style={{ fontSize: 12.5, color: c.muted, marginTop: 4 }}>851 {p.meta}852 </div>853 </div>854 </div>855 );856 })}857 {tp > 0 && (858 <div859 style={{860 position: "absolute",861 left: 0,862 top: vh - 84 + (1 - ease(tp)) * 96,863 width: vw,864 height: 84,865 background: withAlpha(c.app, 0.94),866 borderTop: `1px solid ${c.border}`,867 display: "flex",868 justifyContent: "space-around",869 paddingTop: 10,870 boxSizing: "border-box",871 }}872 >873 {NAV.filter((_, i) => i !== 2).map((n, i) => (874 <div875 key={n.label}876 style={{877 display: "flex",878 flexDirection: "column",879 alignItems: "center",880 gap: 4,881 fontSize: 11,882 fontWeight: 400,883 color: i === 1 ? accent : c.muted,884 }}885 >886 <G n={n.icon} color={i === 1 ? accent : c.muted} size={22} />887 {n.label}888 </div>889 ))}890 <div891 style={{892 position: "absolute",893 left: vw / 2 - 66,894 bottom: 8,895 width: 132,896 height: 5,897 borderRadius: 5,898 background: c.text,899 opacity: 0.85,900 }}901 />902 </div>903 )}904 </div>905 );906}907908function Cursor({909 x,910 y,911 press,912 opacity,913}: {914 x: number;915 y: number;916 press: number;917 opacity: number;918}) {919 return (920 <svg921 width={22}922 height={26}923 viewBox="0 0 20 24"924 style={{925 position: "absolute",926 left: x - 2.2,927 top: y - 2.2,928 opacity,929 transformOrigin: "2px 2px",930 transform: `scale(${1 - 0.04 * press})`,931 filter: "drop-shadow(0 2px 4px rgba(0,0,0,0.3))",932 overflow: "visible",933 }}934 >935 <path936 d="M2 2 L2 19.5 L6.6 15.4 L9.8 22.4 L12.9 21 L9.8 14.2 L16 14.2 Z"937 fill="#FFFFFF"938 stroke="#111114"939 strokeWidth={1.2}940 strokeLinejoin="round"941 />942 </svg>943 );944}945946/** The foreground at `scale`, around the frame's center; nothing extra at 1. */947function ScaleLayer({948 scale,949 children,950}: {951 scale: number;952 children: React.ReactNode;953}) {954 if (scale === 1) return children;955 return (956 <AbsoluteFill style={{ transform: `scale(${scale})` }}>957 {children}958 </AbsoluteFill>959 );960}961962export function DeviceMorph({963 children,964 src,965 stops = DEFAULT_STOPS,966 reverse = false,967 brand = "acme",968 greeting = "Good morning, Maya",969 ctaLabel = "New video",970 logo,971 accent = "#3B5BFD",972 ink,973 background,974 fontFamily = sans,975 scale = 1,976 delay = 0,977 speed = 1,978 theme = "light",979 images = DEFAULT_IMAGES,980 ground,981 groundParams,982}: DeviceMorphProps) {983 const frame = Math.max(0, useCurrentFrame() - delay) * speed;984 const { width: W, height: H, fps } = useVideoConfig();985 const tall = H > W * 1.2;986 const L = tall ? LAYOUT.tall : LAYOUT.wide;987 const k = W / L.dw;988 const c = PALETTES[theme];989 const fg = ink ?? c.text;990 const dark = theme === "dark";991 const [s0, s1, s2] = [992 stops[0] ?? DEFAULT_STOPS[0],993 stops[1] ?? DEFAULT_STOPS[1],994 stops[2] ?? DEFAULT_STOPS[2],995 ];996997 const morphAt = (at: number) =>998 spring({999 frame: frame - at - 2,1000 fps,1001 config: MORPH_SPRING,1002 durationInFrames: MORPH,1003 });1004 const stepA = morphAt(CLICK_A);1005 const stepB = morphAt(CLICK_B);1006 const t = reverse ? 2 - stepA - stepB : stepA + stepB;10071008 const fit = (s: DeviceStop, chrome: number) =>1009 Math.min(L.maxW / s.width, (L.maxH - chrome) / s.height);1010 const vw = seg(t, s0.width, s1.width, s2.width);1011 const vh = seg(t, s0.height, s1.height, s2.height);1012 const sc = seg(t, fit(s0, 34), fit(s1, 24), fit(s2, 20));1013 const screenW = vw * sc;1014 const screenH = vh * sc;1015 const barH = seg(t, 34, 0, 0);1016 const bezel = seg(t, 0, 12, 10);1017 const radius = seg(t, 12, 30, 42);1018 const outerW = screenW + 2 * bezel;1019 const outerH = screenH + barH + 2 * bezel;1020 const fx = L.dw / 2 - outerW / 2;1021 const fy = L.cy - outerH / 2;1022 const enter = spring({ frame, fps, config: HEAVY });1023 const chromeIn = spring({ frame: frame - 6, fps, config: CARD });10241025 const chipW = 168;1026 const segW = chipW * 3 + 8;1027 const segX = L.dw / 2 - segW / 2;1028 const segY = L.segY;1029 const chipCenter = (i: number) => ({1030 x: segX + 4 + i * chipW + chipW / 2,1031 y: segY + 24,1032 });1033 const [firstTarget, secondTarget] = reverse ? [1, 0] : [1, 2];1034 const a = chipCenter(firstTarget);1035 const b = chipCenter(secondTarget);1036 const keys = [1037 { f: 20, x: L.dw * 0.74, y: segY - 80 },1038 { f: CLICK_A - 3, x: a.x + 8, y: a.y + 4 },1039 { f: CLICK_A + 14, x: a.x + 8, y: a.y + 4 },1040 { f: CLICK_A + 34, x: a.x + 30, y: a.y - 40 },1041 { f: CLICK_B - 24, x: a.x + 30, y: a.y - 40 },1042 { f: CLICK_B - 3, x: b.x + 8, y: b.y + 4 },1043 { f: CLICK_B + 14, x: b.x + 8, y: b.y + 4 },1044 { f: CLICK_B + 40, x: b.x + 120, y: b.y - 30 },1045 ];1046 let cur = keys[keys.length - 1];1047 for (let i = 1; i < keys.length; i++) {1048 if (frame <= keys[i].f) {1049 const p = ease(range(frame, keys[i - 1].f, keys[i].f));1050 cur = {1051 f: 0,1052 x: lerp(keys[i - 1].x, keys[i].x, p),1053 y: lerp(keys[i - 1].y, keys[i].y, p) - Math.sin(p * Math.PI) * 22,1054 };1055 break;1056 }1057 }1058 const pressAt = (at: number) =>1059 spring({ frame: frame - (at - 2), fps, config: CHIP }) -1060 spring({ frame: frame - (at + 2), fps, config: CHIP });1061 const pressA = pressAt(CLICK_A);1062 const pressB = pressAt(CLICK_B);1063 const press = pressA + pressB;1064 const curOpacity =1065 range(frame, 18, 24) * (1 - range(frame, CLICK_B + 30, CLICK_B + 40));1066 const deviceBg = interpolateColors(1067 t,1068 [0, 0.35, 0.7],1069 [c.chrome, "#0B0B0D", "#0B0B0D"],1070 );1071 const nearest = Math.round(t);1072 const handle = (x: number, y: number) => (1073 <div1074 key={`${x}-${y}`}1075 style={{1076 position: "absolute",1077 left: x - 3.5,1078 top: y - 3.5,1079 width: 7,1080 height: 7,1081 background: "#fff",1082 border: `1px solid ${accent}`,1083 boxSizing: "border-box",1084 borderRadius: 1.5,1085 }}1086 />1087 );1088 const o = 8;1089 const dims = `${Math.round(vw)} × ${Math.round(vh)}`;10901091 return (1092 <AbsoluteFill1093 style={{1094 background:1095 background === undefined ? (dark ? "#01040a" : "#eeece8") : undefined,1096 overflow: "hidden",1097 }}1098 >1099 {background === undefined ? (1100 <AbsoluteFill style={{ transform: `scale(${1.04 + 0.03 * (t / 2)})` }}>1101 <GshGround1102 preset={ground ?? (dark ? "europa" : "paper-crease")}1103 params={groundParams}1104 timeOffset={4}1105 timeScale={0.5}1106 />1107 </AbsoluteFill>1108 ) : (1109 <AbsoluteFill1110 style={{1111 background: background === "transparent" ? undefined : background,1112 }}1113 />1114 )}1115 <ScaleLayer scale={scale}>1116 <div1117 style={{1118 position: "absolute",1119 left: 0,1120 top: 0,1121 width: L.dw,1122 height: L.dh,1123 transform: `scale(${k})`,1124 transformOrigin: "0 0",1125 fontFamily,1126 color: fg,1127 WebkitFontSmoothing: "antialiased",1128 }}1129 >1130 {tall ? (1131 <div1132 style={{1133 position: "absolute",1134 left: 64,1135 right: 64,1136 top: 150,1137 opacity: chromeIn,1138 transform: `translateY(${(1 - chromeIn) * 24}px)`,1139 }}1140 >1141 <div1142 style={{1143 position: "relative",1144 height: 96,1145 fontSize: 88,1146 fontWeight: 300,1147 lineHeight: 1,1148 letterSpacing: "-0.04em",1149 color: fg,1150 }}1151 >1152 {[s0, s1, s2].map((s, i) => {1153 const vis = Math.max(0, 1 - Math.abs(t - i) * 2);1154 if (vis <= 0.001) return null;1155 return (1156 <div1157 key={s.label}1158 style={{1159 position: "absolute",1160 left: 0,1161 top: 0,1162 opacity: vis,1163 transform: `translateY(${(t - i) * -40}px)`,1164 filter: `blur(${(1 - vis) * 8}px)`,1165 }}1166 >1167 {s.label}1168 </div>1169 );1170 })}1171 </div>1172 <div1173 style={{1174 marginTop: 18,1175 fontFamily: mono,1176 fontSize: 28,1177 color: c.muted,1178 fontVariantNumeric: "tabular-nums",1179 }}1180 >1181 {dims}1182 </div>1183 </div>1184 ) : (1185 <div1186 style={{1187 position: "absolute",1188 left: fx - o,1189 top: fy - o - 28,1190 fontFamily: mono,1191 fontSize: 16,1192 color: c.muted,1193 whiteSpace: "nowrap",1194 fontVariantNumeric: "tabular-nums",1195 opacity: chromeIn,1196 }}1197 >1198 <span style={{ color: fg }}>{[s0, s1, s2][nearest].label}</span>1199 {" "}1200 {dims}1201 </div>1202 )}12031204 <div1205 style={{1206 position: "absolute",1207 left: fx - o,1208 top: fy - o,1209 width: outerW + 2 * o,1210 height: outerH + 2 * o,1211 border: `1px solid ${withAlpha(accent, 0.6)}`,1212 borderRadius: radius + o,1213 boxSizing: "border-box",1214 opacity: chromeIn,1215 }}1216 >1217 {[1218 [0, 0],1219 [1, 0],1220 [0, 1],1221 [1, 1],1222 ].map(([u, v]) =>1223 handle(u * (outerW + 2 * o), v * (outerH + 2 * o)),1224 )}1225 </div>12261227 <div1228 style={{1229 position: "absolute",1230 left: fx,1231 top: fy + (1 - enter) * 36,1232 width: outerW,1233 height: outerH,1234 borderRadius: radius,1235 background: deviceBg,1236 padding: bezel,1237 boxSizing: "border-box",1238 boxShadow: dark1239 ? "0 0 0 1px rgba(255,255,255,0.1), 0 40px 80px -24px rgba(0,0,0,0.85)"1240 : "0 0 0 1px rgba(16,24,40,0.08), 0 2px 6px rgba(16,24,40,0.06), 0 40px 80px -28px rgba(16,24,40,0.4)",1241 opacity: interpolate(enter, [0, 0.4], [0, 1], clamp01),1242 transform: `scale(${0.96 + 0.04 * enter})`,1243 }}1244 >1245 {barH > 0.5 && (1246 <div1247 style={{1248 position: "relative",1249 height: barH,1250 overflow: "hidden",1251 opacity: 1 - range(t, 0, 0.2),1252 }}1253 >1254 {[0, 1, 2].map((i) => (1255 <div1256 key={i}1257 style={{1258 position: "absolute",1259 left: 14 + i * 18,1260 top: barH / 2 - 6,1261 width: 12,1262 height: 12,1263 borderRadius: 12,1264 background: dark ? "#3A3A40" : "#D4D4D8",1265 }}1266 />1267 ))}1268 <div1269 style={{1270 position: "absolute",1271 left: "50%",1272 top: barH / 2 - 11,1273 width: 300,1274 marginLeft: -150,1275 height: 22,1276 borderRadius: 7,1277 background: dark ? "#0F0F11" : "#FFFFFF",1278 boxShadow: `inset 0 0 0 1px ${c.border}`,1279 fontSize: 12,1280 color: c.muted,1281 display: "flex",1282 alignItems: "center",1283 justifyContent: "center",1284 }}1285 >1286 acme.dev/projects1287 </div>1288 </div>1289 )}1290 <div1291 style={{1292 position: "relative",1293 width: screenW,1294 height: screenH,1295 borderRadius: Math.max(0, radius - bezel) * range(t, 0, 0.5),1296 overflow: "hidden",1297 background: c.app,1298 }}1299 >1300 <div1301 style={{1302 position: "absolute",1303 left: 0,1304 top: 0,1305 width: vw,1306 height: vh,1307 transform: `scale(${sc})`,1308 transformOrigin: "0 0",1309 }}1310 >1311 {children ? (1312 <div style={{ position: "absolute", inset: 0 }}>1313 {children}1314 </div>1315 ) : src ? (1316 <Img1317 src={src}1318 style={{1319 width: "100%",1320 height: "100%",1321 objectFit: "cover",1322 objectPosition: "top",1323 }}1324 />1325 ) : (1326 <Dashboard1327 t={t}1328 vw={vw}1329 vh={vh}1330 c={c}1331 accent={accent}1332 images={images}1333 brand={brand}1334 greeting={greeting}1335 ctaLabel={ctaLabel}1336 logo={logo}1337 />1338 )}1339 </div>1340 <div1341 style={{1342 position: "absolute",1343 left: screenW / 2 - 40,1344 top: 8,1345 width: 80,1346 height: 22,1347 borderRadius: 20,1348 background: "#000",1349 opacity: range(t, 1.45, 1.9),1350 transform: `scale(${0.6 + 0.4 * range(t, 1.45, 1.9)})`,1351 }}1352 />1353 </div>1354 <div1355 style={{1356 position: "absolute",1357 left: outerW / 2 - 3,1358 top: bezel / 2 - 3,1359 width: 6,1360 height: 6,1361 borderRadius: 6,1362 background: "#2A2A2E",1363 opacity: range(t, 0.5, 1) * (1 - range(t, 1.2, 1.5)),1364 }}1365 />1366 </div>13671368 <div1369 style={{1370 position: "absolute",1371 left: segX,1372 top: segY,1373 width: segW,1374 height: 48,1375 borderRadius: 13,1376 background: c.pill,1377 boxSizing: "border-box",1378 boxShadow: dark1379 ? "inset 0 0 0 1px rgba(255,255,255,0.08), inset 0 1px 0 rgba(255,255,255,0.05), 0 12px 32px -12px rgba(0,0,0,0.7)"1380 : "0 0 0 1px rgba(16,24,40,0.06), 0 1px 2px rgba(16,24,40,0.06), 0 12px 32px -12px rgba(16,24,40,0.25)",1381 opacity: chromeIn,1382 transform: `translateY(${(1 - chromeIn) * 16}px)`,1383 }}1384 >1385 <div1386 style={{1387 position: "absolute",1388 left: 4 + t * chipW,1389 top: 4,1390 width: chipW,1391 height: 40,1392 borderRadius: 9,1393 background: withAlpha(accent, dark ? 0.22 : 0.1),1394 }}1395 />1396 {[s0, s1, s2].map((s, i) => {1397 const on = 1 - Math.min(1, Math.abs(t - i));1398 const pressed =1399 (i === firstTarget ? pressA : 0) +1400 (i === secondTarget ? pressB : 0);1401 return (1402 <div1403 key={s.label}1404 style={{1405 position: "absolute",1406 left: 4 + i * chipW,1407 top: 4,1408 width: chipW,1409 height: 40,1410 display: "flex",1411 alignItems: "center",1412 justifyContent: "center",1413 gap: 8,1414 fontSize: 16,1415 fontWeight: 400,1416 color: interpolateColors(on, [0, 1], [c.muted, c.text]),1417 transform: `scale(${1 - 0.04 * pressed})`,1418 }}1419 >1420 <G1421 n={["monitor", "tablet", "phone"][i]}1422 color={on > 0.5 ? accent : c.muted}1423 size={17}1424 sw={1.5}1425 />1426 {s.label}1427 <span1428 style={{1429 fontFamily: mono,1430 fontSize: 16,1431 color: c.muted,1432 fontVariantNumeric: "tabular-nums",1433 }}1434 >1435 {s.width}1436 </span>1437 </div>1438 );1439 })}1440 </div>1441 <Cursor x={cur.x} y={cur.y} press={press} opacity={curOpacity} />1442 </div>1443 </ScaleLayer>1444 </AbsoluteFill>1445 );1446}









