Open source CapCut alternative.
TypeScript
site/donkeyvision: show the real screenshot with detection overlay
David Leba9b7cf34dbc
diff --git a/site/src/app/donkeyvision/VisionCompareSection.tsx b/site/src/app/donkeyvision/VisionCompareSection.tsxindex 4e12bd87..aa10cfcc 100644--- a/site/src/app/donkeyvision/VisionCompareSection.tsx+++ b/site/src/app/donkeyvision/VisionCompareSection.tsx@@ -4,75 +4,8 @@ import { ChevronLeft, ChevronRight } from "lucide-react";import Image from "next/image";import { useCallback, useRef, useState } from "react";-import {- VISION_DATASETS,- type VisionDataset,-} from "@/app/donkeyvision/visionData";--// Per-index palette (matches the worker overlay + the Mac app's vision overlay),-// so adjacent boxes read apart instead of sharing one color.-const PALETTE = [- "#FF3B30", "#FF9500", "#FFCC00", "#34C759",- "#00C7BE", "#30B0C7", "#007AFF", "#5856D6",- "#AF52DE", "#FF2D55", "#A2845E", "#8E8E93",-];--function textOn(hex: string): string {- const r = parseInt(hex.slice(1, 3), 16);- const g = parseInt(hex.slice(3, 5), 16);- const b = parseInt(hex.slice(5, 7), 16);- return 0.299 * r + 0.587 * g + 0.114 * b > 150 ? "#0F0E0D" : "#FFFFFF";-}--function Overlay({ dataset }: { dataset: VisionDataset }) {- const { width: W, height: H, elements } = dataset;- const fs = W / 85;- return (- <svg- className="absolute inset-0 h-full w-full"- viewBox={`0 0 ${W} ${H}`}- preserveAspectRatio="none"- aria-hidden="true"- >- {elements.map((el, i) => {- const color = PALETTE[i % PALETTE.length];- const x = el.box[0] * W;- const y = el.box[1] * H;- const w = (el.box[2] - el.box[0]) * W;- const h = (el.box[3] - el.box[1]) * H;- const text = `AI ${el.label}`.slice(0, 26);- const chipH = fs + 5;- const chipW = text.length * fs * 0.56 + 6;- const chipY = y - chipH >= 0 ? y - chipH : y;- return (- <g key={i}>- <rect- x={x}- y={y}- width={w}- height={h}- fill="none"- stroke={color}- strokeWidth={2}- vectorEffect="non-scaling-stroke"- />- <rect x={x} y={chipY} width={chipW} height={chipH} fill={color} />- <text- x={x + 3}- y={chipY + chipH - 4}- fontSize={fs}- fontFamily="-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"- fontWeight={600}- fill={textOn(color)}- >- {text}- </text>- </g>- );- })}- </svg>- );-}+import { VisionOverlay } from "@/app/donkeyvision/VisionOverlay";+import { VISION_DATASETS } from "@/app/donkeyvision/visionData";export function VisionCompareSection() {const [activeKey, setActiveKey] = useState(VISION_DATASETS[0].key);@@ -96,7 +29,7 @@ export function VisionCompareSection() {id="demo"className="border-y-2 border-[#0F0E0D] bg-[#F5EFE0] px-6 py-20 md:px-12">- <div className="mx-auto max-w-[1100px]">+ <div className="mx-auto max-w-[1400px]"><h2 className="max-w-3xl text-4xl font-semibold leading-none md:text-6xl">Drag to see what it reads.</h2>@@ -107,7 +40,6 @@ export function VisionCompareSection() {</p><div className="relative mt-10">- <div className="absolute inset-0 translate-x-2 translate-y-2 rounded-lg bg-[#0F0E0D]" /><div className="relative overflow-hidden rounded-lg border-2 border-[#0F0E0D] bg-[#FAF6EC]"><div className="flex items-center justify-between border-b-2 border-[#0F0E0D] bg-white px-4 py-3"><div className="flex items-center gap-2">@@ -147,22 +79,15 @@ export function VisionCompareSection() {className="absolute inset-0"style={{ clipPath: `inset(0 0 0 ${pos}%)` }}>- <Overlay dataset={active} />+ <VisionOverlay dataset={active} /></div>- <span className="absolute left-3 top-3 rounded border-2 border-[#0F0E0D] bg-white px-2 py-1 text-xs font-semibold">- Original- </span>- <span className="absolute right-3 top-3 rounded border-2 border-[#0F0E0D] bg-[#0F0E0D] px-2 py-1 text-xs font-semibold text-white">- AI overlay- </span>-{/* Divider + handle. */}<div- className="absolute inset-y-0 w-0.5 -translate-x-1/2 bg-[#0F0E0D]"+ className="absolute inset-y-0 w-0.5 -translate-x-1/2 bg-[#007AFF]"style={{ left: `${pos}%` }}>- <div className="absolute top-1/2 left-1/2 flex h-10 w-10 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border-2 border-[#0F0E0D] bg-white shadow-[2px_2px_0_0_#0F0E0D]">+ <div className="absolute top-1/2 left-1/2 flex h-10 w-10 -translate-x-1/2 -translate-y-1/2 items-center justify-center rounded-full border-2 border-[#007AFF] bg-white"><ChevronLeft size={16} aria-hidden="true" /><ChevronRight size={16} aria-hidden="true" /></div>@@ -191,9 +116,6 @@ export function VisionCompareSection() {}`}>{d.title}- <span className="ml-2 font-mono text-xs opacity-70">- {d.elements.length}- </span></button>);})}diff --git a/site/src/app/donkeyvision/VisionOverlay.tsx b/site/src/app/donkeyvision/VisionOverlay.tsxnew file mode 100644index 00000000..d187bf8b--- /dev/null+++ b/site/src/app/donkeyvision/VisionOverlay.tsx@@ -0,0 +1,66 @@+import type { VisionDataset } from "@/app/donkeyvision/visionData";++// Per-index palette (matches the worker overlay + the Mac app's vision overlay),+// so adjacent boxes read apart instead of sharing one color.+const PALETTE = [+ "#FF3B30", "#FF9500", "#FFCC00", "#34C759",+ "#00C7BE", "#30B0C7", "#007AFF", "#5856D6",+ "#AF52DE", "#FF2D55", "#A2845E", "#8E8E93",+];++function textOn(hex: string): string {+ const r = parseInt(hex.slice(1, 3), 16);+ const g = parseInt(hex.slice(3, 5), 16);+ const b = parseInt(hex.slice(5, 7), 16);+ return 0.299 * r + 0.587 * g + 0.114 * b > 150 ? "#0F0E0D" : "#FFFFFF";+}++export function VisionOverlay({ dataset }: { dataset: VisionDataset }) {+ const { width: W, height: H, elements } = dataset;+ const fs = W / 85;+ return (+ <svg+ className="absolute inset-0 h-full w-full"+ viewBox={`0 0 ${W} ${H}`}+ preserveAspectRatio="none"+ aria-hidden="true"+ >+ {elements.map((el, i) => {+ const color = PALETTE[i % PALETTE.length];+ const x = el.box[0] * W;+ const y = el.box[1] * H;+ const w = (el.box[2] - el.box[0]) * W;+ const h = (el.box[3] - el.box[1]) * H;+ const text = `AI ${el.label}`.slice(0, 26);+ const chipH = fs + 5;+ const chipW = text.length * fs * 0.56 + 6;+ const chipY = y - chipH >= 0 ? y - chipH : y;+ return (+ <g key={i}>+ <rect+ x={x}+ y={y}+ width={w}+ height={h}+ fill="none"+ stroke={color}+ strokeWidth={2}+ vectorEffect="non-scaling-stroke"+ />+ <rect x={x} y={chipY} width={chipW} height={chipH} fill={color} />+ <text+ x={x + 3}+ y={chipY + chipH - 4}+ fontSize={fs}+ fontFamily="-apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif"+ fontWeight={600}+ fill={textOn(color)}+ >+ {text}+ </text>+ </g>+ );+ })}+ </svg>+ );+}diff --git a/site/src/app/donkeyvision/VisionPreview.tsx b/site/src/app/donkeyvision/VisionPreview.tsxindex 74ded45d..2730b0d3 100644--- a/site/src/app/donkeyvision/VisionPreview.tsx+++ b/site/src/app/donkeyvision/VisionPreview.tsx@@ -1,15 +1,14 @@import Image from "next/image";-type DetectionRowProps = {- color: string;- label: string;- value: string;-};+import { VisionOverlay } from "@/app/donkeyvision/VisionOverlay";+import { VISION_DATASETS } from "@/app/donkeyvision/visionData";++const spotify =+ VISION_DATASETS.find((d) => d.key === "spotify") ?? VISION_DATASETS[0];export function VisionPreview() {return (<div className="relative w-full min-w-0 max-w-full self-center">- <div className="absolute inset-0 translate-x-2 translate-y-2 rounded-lg bg-[#0F0E0D]" /><div className="relative w-full max-w-full overflow-hidden rounded-lg border-2 border-[#0F0E0D] bg-[#FAF6EC]"><div className="flex items-center justify-between border-b-2 border-[#0F0E0D] bg-white px-4 py-3"><div className="flex items-center gap-2">@@ -17,63 +16,23 @@ export function VisionPreview() {<span className="h-3 w-3 rounded-full border-2 border-[#0F0E0D] bg-[#F5D875]" /><span className="h-3 w-3 rounded-full border-2 border-[#0F0E0D] bg-[#B7E4C7]" /></div>- <span className="text-sm font-semibold">vision frame</span>+ <span className="text-sm font-semibold">Spotify</span></div>- <div className="grid min-w-0 gap-4 p-4 md:grid-cols-[170px_minmax(0,1fr)]">- <div className="rounded-lg border-2 border-[#0F0E0D] bg-[#A8D5E8] p-3">- {["Inbox", "Projects", "Search", "Settings"].map((item, index) => (- <div- className="relative mb-3 rounded-md border-2 border-[#0F0E0D] bg-white px-3 py-2 text-sm font-semibold last:mb-0"- key={item}- >- {item}- {index < 3 ? (- <span className="absolute -right-1 -top-1 rounded bg-[#EC7868] px-1.5 py-0.5 text-[10px] font-semibold">- id- </span>- ) : null}- </div>- ))}- </div>- <div className="min-w-0 rounded-lg border-2 border-[#0F0E0D] bg-white p-4">- <div className="mb-4 flex items-center gap-3">- <Image- src="/donkey-app-icon.png"- alt=""- width={52}- height={52}- className="rounded-lg border-2 border-[#0F0E0D]"- priority- />- <div>- <div className="text-lg font-semibold">Detected controls</div>- <div className="text-sm text-[#666]">Boxes, labels, centers, IDs</div>- </div>- </div>- <div className="grid gap-3">- <DetectionRow color="bg-[#B7E4C7]" label="play button" value="639, 837" />- <DetectionRow color="bg-[#F5D875]" label="next button" value="1290, 840" />- <DetectionRow color="bg-[#F2B5C4]" label="search field" value="424, 112" />- </div>- <div className="mt-4 break-all rounded-md border-2 border-[#0F0E0D] bg-[#0F0E0D] p-3 font-mono text-xs leading-6 text-white">- {`element: { id: "n8x2p0", label: "Next" }`}<br />- {`box: [1248, 820, 84, 40] point: [1290, 840]`}- </div>- </div>+ <div+ className="relative w-full"+ style={{ aspectRatio: `${spotify.width} / ${spotify.height}` }}+ >+ <Image+ src={spotify.image}+ alt={`${spotify.title} screenshot with detected controls`}+ fill+ priority+ sizes="(max-width: 1100px) 100vw, 700px"+ className="object-cover"+ />+ <VisionOverlay dataset={spotify} /></div></div></div>);}--function DetectionRow({ color, label, value }: DetectionRowProps) {- return (- <div className="flex items-center justify-between gap-3 rounded-md border-2 border-[#0F0E0D] bg-[#FAF6EC] p-3">- <div className="flex min-w-0 items-center gap-3">- <span className={`h-7 w-7 shrink-0 rounded border-2 border-[#0F0E0D] ${color}`} />- <span className="truncate text-sm font-semibold">{label}</span>- </div>- <span className="shrink-0 font-mono text-xs text-[#666]">{value}</span>- </div>- );-}