Why UI Screenshots Make Cursor & Claude Hallucinate (And How I Built a 64KB Shadow-DOM Inspector to Fix It)

2026-11-29来源 dev.toEnglish

Whenever I see a clean bento card, navbar, or pricing layout on a site like Linear or Stripe and want to understand how it's built—or rebuild a similar pattern in my own app—two things always break the flow:

  1. Browser DevTools dumps 150–200+ computed CSS lines full of inherited defaults instead of clean utility classes.
  2. Screenshots make Cursor, Claude Code, and v0 guess wrong. Vision models eyeball padding: 22px as p-8, miss -0.02em font tracking, invent random hex grays, and flatten nested flexbox grids.

So over the past weeks (I'm a 17-year-old indie dev in Sweden), I built PRISM CSS—a ~64KB, zero-dependency vanilla JS inspection engine that runs 100% locally inside an isolated Shadow DOM.

How It Works Under the Hood

1. 60fps requestAnimationFrame Overlay Inside an Isolated Shadow DOM

Injecting inspector styles directly into a live website usually mutates or breaks the host page's CSS. PRISM mounts its entire HUD, box-model laser overlays, and dock inside an isolated Shadow root so host styles never bleed in—and PRISM never dirties the page's DOM.

2. Translating Computed Styles -> Clean Tailwind v4 + JSX

Instead of dumping getComputedStyle() verbatim, the engine compares an element against baseline tag defaults, collapses directional shorthands (padding-top/right/bottom/left -> p-6), snaps values to standard Tailwind scales (falling back to arbitrary rounded-[14px] or bg-[#0D1122] only when exact precision matters), and outputs clean React/JSX or HTML:

 jsx <div className="flex flex-col gap-4 p-6 rounded-2xl bg-[#0D1122] border border-white/10 shadow-2xl"> 

原文:https://www.a8q9.cn/en/article/why-ui-screenshots-make-cursor-claude-hallucinate-and-how-i-built-a-64kb-shadow--3241de.html

相关文章