{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "image-edit",
  "title": "Image Edit",
  "author": "Zubeyr <https://zubeyr.dev>",
  "description": "A product image editor: light and colour adjustments, stackable filter presets, crop with aspect ratios, zoom, straighten, rotate, flip and drag to reposition, hold-to-compare, undo/redo and a floating Cancel and Save toolbar.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "https://tomei.zubeyr.dev/ui/r/sidebar.json",
    "https://tomei.zubeyr.dev/ui/r/button.json",
    "https://tomei.zubeyr.dev/ui/r/use-history.json",
    "https://tomei.zubeyr.dev/ui/r/toast.json"
  ],
  "files": [
    {
      "path": "registry/dashboard/pages/image-edit/image-edit.tsx",
      "content": "'use client'\n\nimport { useRef, useState } from 'react'\nimport {\n  BarChart3,\n  Eye,\n  Home,\n  ImageIcon,\n  Package,\n  Redo2,\n  Settings,\n  ShoppingBag,\n  Undo2,\n  Users,\n  X,\n} from 'lucide-react'\n\nimport { Button } from '@/registry/dashboard/components/button/button'\nimport {\n  Sidebar,\n  SidebarContent,\n  SidebarFooter,\n  SidebarGroup,\n  SidebarHeader,\n  SidebarItem,\n} from '@/registry/dashboard/components/sidebar/sidebar'\nimport { toast, Toaster } from '@/registry/dashboard/components/toast/toast'\nimport { useHistory } from '@/registry/dashboard/components/use-history/use-history'\nimport { cn } from '@/lib/utils'\n\nimport { defaultEdit, type Edit, type StageImage } from './edits'\nimport { Panel, type Tab } from './panel'\nimport { Stage } from './stage'\n\ntype Doc = { images: StageImage[]; edits: Record<string, Edit> }\n\nconst initial: Doc = {\n  images: [\n    { id: 'front', name: 'Front', background: '#ece4d8', fill: '#c2410c' },\n    { id: 'back', name: 'Back', background: '#dfe5e2', fill: '#3f6212' },\n    { id: 'detail', name: 'Detail', background: '#e7e0ef', fill: '#44403c', scale: 2.2 },\n  ],\n  edits: {\n    back: { ...defaultEdit, filter: 'warm', adjust: { ...defaultEdit.adjust, contrast: 12 } },\n  },\n}\n\nexport function ImageEdit() {\n  const history = useHistory(initial, { hotkeys: true })\n  const doc = history.value\n  const [saved, setSaved] = useState(initial)\n  const [active, setActive] = useState(0)\n  const [tab, setTab] = useState<Tab>('adjust')\n  const [comparing, setComparing] = useState(false)\n  const [justSaved, setJustSaved] = useState(false)\n  const gesture = useRef(0)\n\n  const index = Math.min(active, Math.max(0, doc.images.length - 1))\n  const image = doc.images[index]\n  const edit = (image && doc.edits[image.id]) ?? defaultEdit\n  const dirty = JSON.stringify(doc) !== JSON.stringify(saved)\n\n  const setEdit = (next: Edit, merge?: string) => {\n    if (!image) return\n    history.set(\n      (d) => ({ ...d, edits: { ...d.edits, [image.id]: next } }),\n      merge ? { merge: `${image.id}-${merge}-${gesture.current}` } : undefined,\n    )\n  }\n\n  const setImages = (images: StageImage[]) => {\n    history.set((d) => ({\n      images,\n      edits: Object.fromEntries(\n        Object.entries(d.edits).filter(([id]) => images.some((i) => i.id === id)),\n      ),\n    }))\n  }\n\n  const cancel = () => {\n    history.reset(saved)\n    setActive(0)\n  }\n\n  const save = () => {\n    setSaved(doc)\n    history.reset(doc)\n    setJustSaved(true)\n    setTimeout(() => setJustSaved(false), 1500)\n    toast.success('Images saved', {\n      description: `${doc.images.length} image${doc.images.length === 1 ? '' : 's'} updated.`,\n    })\n  }\n\n  return (\n    <div className=\"flex h-svh overflow-hidden bg-sidebar text-foreground\">\n      <Sidebar className=\"border-r-0 max-lg:hidden\">\n        <SidebarHeader\n          logo={<span className=\"size-8 rounded-lg bg-sidebar-primary-foreground\" />}\n          title=\"Tomei\"\n          subtitle=\"Store admin\"\n        />\n        <SidebarContent>\n          <SidebarGroup>\n            <SidebarItem icon={<Home />}>Home</SidebarItem>\n            <SidebarItem icon={<ShoppingBag />} count={4}>\n              Orders\n            </SidebarItem>\n            <SidebarItem\n              icon={<Package />}\n              active\n              submenu={\n                <>\n                  <SidebarItem>Collections</SidebarItem>\n                  <SidebarItem>Inventory</SidebarItem>\n                  <SidebarItem active>Media</SidebarItem>\n                  <SidebarItem>Gift cards</SidebarItem>\n                </>\n              }\n            >\n              Products\n            </SidebarItem>\n            <SidebarItem icon={<Users />}>Customers</SidebarItem>\n            <SidebarItem icon={<BarChart3 />}>Analytics</SidebarItem>\n          </SidebarGroup>\n        </SidebarContent>\n        <SidebarFooter>\n          <SidebarItem icon={<Settings />}>Settings</SidebarItem>\n        </SidebarFooter>\n      </Sidebar>\n\n      <main className=\"min-w-0 flex-1 overflow-y-auto bg-card lg:my-2 lg:mr-2 lg:rounded-2xl lg:border\">\n        <header className=\"sticky top-0 z-20 grid grid-cols-[1fr_auto_1fr] items-center gap-3 bg-card/90 px-4 py-3 backdrop-blur\">\n          <div className=\"flex min-w-0 items-center gap-2 text-sm\">\n            <ImageIcon className=\"size-4 shrink-0 text-muted-foreground\" />\n            <span className=\"truncate font-medium\">Wool Overshirt</span>\n            {image && (\n              <span className=\"truncate text-muted-foreground max-sm:hidden\">/ {image.name}</span>\n            )}\n            {dirty && (\n              <span className=\"text-amber-600 max-md:hidden dark:text-amber-400\">\n                · Unsaved changes\n              </span>\n            )}\n          </div>\n\n          <div\n            role=\"toolbar\"\n            aria-label=\"Edit actions\"\n            className=\"flex items-center gap-1 rounded-xl bg-primary p-1 text-primary-foreground shadow-lg\"\n          >\n            <button\n              type=\"button\"\n              disabled={!dirty}\n              onClick={cancel}\n              className=\"h-7 rounded-lg px-3 text-sm font-medium hover:bg-primary-foreground/10 disabled:opacity-40 disabled:hover:bg-transparent\"\n            >\n              Cancel\n            </button>\n            <button\n              type=\"button\"\n              disabled={!dirty}\n              onClick={save}\n              className={cn(\n                'h-7 rounded-lg bg-primary-foreground px-3 text-sm font-medium text-primary disabled:opacity-50',\n                justSaved && 'disabled:opacity-100',\n              )}\n            >\n              {justSaved ? 'Saved ✓' : 'Save'}\n            </button>\n          </div>\n\n          <div className=\"flex justify-end gap-1.5\">\n            <Button\n              size=\"icon\"\n              variant=\"ghost\"\n              aria-label=\"Undo\"\n              title=\"Undo (Ctrl+Z)\"\n              disabled={!history.canUndo}\n              onClick={history.undo}\n            >\n              <Undo2 />\n            </Button>\n            <Button\n              size=\"icon\"\n              variant=\"ghost\"\n              aria-label=\"Redo\"\n              title=\"Redo (Ctrl+Shift+Z)\"\n              disabled={!history.canRedo}\n              onClick={history.redo}\n            >\n              <Redo2 />\n            </Button>\n            <Button\n              size=\"icon\"\n              aria-label=\"Hold to compare with original\"\n              title=\"Hold to compare\"\n              aria-pressed={comparing}\n              disabled={!image}\n              onPointerDown={() => setComparing(true)}\n              onPointerUp={() => setComparing(false)}\n              onPointerLeave={() => setComparing(false)}\n              onKeyDown={(e) => e.key === ' ' && setComparing(true)}\n              onKeyUp={() => setComparing(false)}\n            >\n              <Eye />\n            </Button>\n            <Button size=\"icon\" variant=\"ghost\" aria-label=\"Close\">\n              <X />\n            </Button>\n          </div>\n        </header>\n\n        <div className=\"mx-auto grid max-w-[1200px] gap-10 px-6 pt-6 pb-16 lg:grid-cols-[minmax(0,1fr)_20rem]\">\n          <div\n            className=\"flex items-start justify-center rounded-3xl py-6\"\n            style={{\n              background:\n                'radial-gradient(circle at 50% 40%, color-mix(in oklab, var(--chart-5) 10%, transparent), transparent 65%)',\n            }}\n          >\n            <Stage\n              images={doc.images}\n              edits={doc.edits}\n              active={index}\n              cropping={tab === 'crop'}\n              comparing={comparing}\n              onSelect={setActive}\n              onImages={setImages}\n              onPan={(x, y, start) => {\n                if (start) gesture.current++\n                else setEdit({ ...edit, crop: { ...edit.crop, x, y } }, 'pan')\n              }}\n            />\n          </div>\n\n          <Panel\n            tab={tab}\n            image={image}\n            edit={edit}\n            onTab={setTab}\n            onEdit={setEdit}\n            onStart={() => gesture.current++}\n          />\n        </div>\n      </main>\n      <Toaster />\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/dashboard/image-edit/image-edit.tsx"
    },
    {
      "path": "registry/dashboard/pages/image-edit/edits.ts",
      "content": "export type Adjust = {\n  exposure: number\n  contrast: number\n  saturation: number\n  warmth: number\n  hue: number\n  fade: number\n  vignette: number\n}\n\nexport type Crop = {\n  aspect: string\n  zoom: number\n  x: number\n  y: number\n  straighten: number\n  turns: number\n  flipX: boolean\n  flipY: boolean\n}\n\nexport type Edit = { filter: string; adjust: Adjust; crop: Crop }\n\nexport type StageImage = {\n  id: string\n  name: string\n  src?: string\n  background?: string\n  fill?: string\n  scale?: number\n}\n\nexport const adjustments: { key: keyof Adjust; label: string; min: number; max: number }[] = [\n  { key: 'exposure', label: 'Exposure', min: -100, max: 100 },\n  { key: 'contrast', label: 'Contrast', min: -100, max: 100 },\n  { key: 'saturation', label: 'Saturation', min: -100, max: 100 },\n  { key: 'warmth', label: 'Warmth', min: -100, max: 100 },\n  { key: 'hue', label: 'Hue', min: -180, max: 180 },\n  { key: 'fade', label: 'Fade', min: 0, max: 100 },\n  { key: 'vignette', label: 'Vignette', min: 0, max: 100 },\n]\n\nexport const aspects = [\n  { id: 'original', label: 'Original', ratio: 4 / 5 },\n  { id: 'square', label: '1:1', ratio: 1 },\n  { id: 'portrait', label: '3:4', ratio: 3 / 4 },\n  { id: 'story', label: '9:16', ratio: 9 / 16 },\n  { id: 'wide', label: '16:9', ratio: 16 / 9 },\n]\n\nexport const filters: { id: string; label: string; adjust: Partial<Adjust> }[] = [\n  { id: 'none', label: 'None', adjust: {} },\n  { id: 'vivid', label: 'Vivid', adjust: { saturation: 35, contrast: 15 } },\n  { id: 'warm', label: 'Warm', adjust: { warmth: 45, exposure: 5 } },\n  { id: 'cool', label: 'Cool', adjust: { warmth: -45, saturation: -10 } },\n  { id: 'fade', label: 'Fade', adjust: { fade: 45, contrast: -15 } },\n  { id: 'mono', label: 'Mono', adjust: { saturation: -100, contrast: 20 } },\n  {\n    id: 'noir',\n    label: 'Noir',\n    adjust: { saturation: -100, contrast: 45, exposure: -15, vignette: 50 },\n  },\n]\n\nexport const defaultEdit: Edit = {\n  filter: 'none',\n  adjust: { exposure: 0, contrast: 0, saturation: 0, warmth: 0, hue: 0, fade: 0, vignette: 0 },\n  crop: {\n    aspect: 'original',\n    zoom: 1,\n    x: 0,\n    y: 0,\n    straighten: 0,\n    turns: 0,\n    flipX: false,\n    flipY: false,\n  },\n}\n\nconst clamp = (value: number, min: number, max: number) => Math.min(max, Math.max(min, value))\n\nexport function combined(edit: Edit): Adjust {\n  const preset = filters.find((f) => f.id === edit.filter)?.adjust ?? {}\n  const result = { ...edit.adjust }\n  for (const { key, min, max } of adjustments) {\n    result[key] = clamp(edit.adjust[key] + (preset[key] ?? 0), min, max)\n  }\n  return result\n}\n\nexport function ratioOf(edit: Edit) {\n  const ratio = aspects.find((a) => a.id === edit.crop.aspect)?.ratio ?? 4 / 5\n  return edit.crop.turns % 2 && edit.crop.aspect === 'original' ? 1 / ratio : ratio\n}\n\nexport function coverScale(edit: Edit) {\n  const r = ratioOf(edit)\n  const angle = ((edit.crop.turns * 90 + edit.crop.straighten) * Math.PI) / 180\n  const cos = Math.abs(Math.cos(angle))\n  const sin = Math.abs(Math.sin(angle))\n  return Math.max(cos + sin / r, sin * r + cos)\n}\n\nexport function panLimit(edit: Edit) {\n  return ((edit.crop.zoom * coverScale(edit) - 1) / 2) * 100\n}\n",
      "type": "registry:component",
      "target": "components/dashboard/image-edit/edits.ts"
    },
    {
      "path": "registry/dashboard/pages/image-edit/panel.tsx",
      "content": "'use client'\n\nimport {\n  Crop,\n  FlipHorizontal2,\n  FlipVertical2,\n  RotateCcw,\n  RotateCw,\n  Sparkles,\n  SunMedium,\n} from 'lucide-react'\n\nimport { Button } from '@/registry/dashboard/components/button/button'\nimport { cn } from '@/lib/utils'\n\nimport { adjustments, aspects, defaultEdit, filters, type Edit, type StageImage } from './edits'\nimport { Picture } from './picture'\nimport { Slider } from './slider'\n\nexport type Tab = 'adjust' | 'filters' | 'crop'\n\nconst tabs: { id: Tab; label: string; icon: React.ReactNode }[] = [\n  { id: 'adjust', label: 'Adjust', icon: <SunMedium /> },\n  { id: 'filters', label: 'Filters', icon: <Sparkles /> },\n  { id: 'crop', label: 'Crop', icon: <Crop /> },\n]\n\ntype PanelProps = {\n  tab: Tab\n  image?: StageImage\n  edit: Edit\n  onTab: (tab: Tab) => void\n  onEdit: (next: Edit, merge?: string) => void\n  onStart: () => void\n}\n\nfunction Section({ title, children }: { title: string; children: React.ReactNode }) {\n  return (\n    <section className=\"flex flex-col gap-4\">\n      <h3 className=\"text-xs font-medium tracking-wide text-muted-foreground uppercase\">{title}</h3>\n      {children}\n    </section>\n  )\n}\n\nexport function Panel({ tab, image, edit, onTab, onEdit, onStart }: PanelProps) {\n  const edited = JSON.stringify(edit) !== JSON.stringify(defaultEdit)\n  const crop = (patch: Partial<Edit['crop']>, merge?: string) =>\n    onEdit({ ...edit, crop: { ...edit.crop, ...patch } }, merge)\n\n  return (\n    <aside className=\"flex flex-col gap-6 lg:sticky lg:top-20 lg:self-start\">\n      <div\n        role=\"tablist\"\n        aria-label=\"Edit tools\"\n        className=\"grid grid-cols-3 gap-1 rounded-xl bg-muted p-1\"\n      >\n        {tabs.map((t) => (\n          <button\n            key={t.id}\n            type=\"button\"\n            role=\"tab\"\n            aria-selected={tab === t.id}\n            onClick={() => onTab(t.id)}\n            className={cn(\n              'flex h-8 items-center justify-center gap-1.5 rounded-lg text-sm font-medium transition-colors [&_svg]:size-3.5',\n              tab === t.id\n                ? 'bg-card text-foreground shadow-(--shadow-button)'\n                : 'text-muted-foreground hover:text-foreground',\n            )}\n          >\n            {t.icon}\n            {t.label}\n          </button>\n        ))}\n      </div>\n\n      {tab === 'adjust' && (\n        <Section title=\"Light & colour\">\n          {adjustments.map((a) => (\n            <Slider\n              key={a.key}\n              label={a.label}\n              min={a.min}\n              max={a.max}\n              value={edit.adjust[a.key]}\n              onStart={onStart}\n              onChange={(value) =>\n                onEdit({ ...edit, adjust: { ...edit.adjust, [a.key]: value } }, a.key)\n              }\n            />\n          ))}\n        </Section>\n      )}\n\n      {tab === 'filters' && (\n        <Section title=\"Presets\">\n          <div className=\"grid grid-cols-3 gap-3\">\n            {filters.map((f) => (\n              <button\n                key={f.id}\n                type=\"button\"\n                aria-pressed={edit.filter === f.id}\n                onClick={() => onEdit({ ...edit, filter: f.id })}\n                className=\"group flex flex-col gap-1.5 text-left\"\n              >\n                {image ? (\n                  <Picture\n                    image={image}\n                    edit={{ ...edit, filter: f.id }}\n                    crop={false}\n                    className={cn(\n                      'aspect-square w-full rounded-lg ring-offset-2 ring-offset-card transition',\n                      edit.filter === f.id ? 'ring-2 ring-foreground' : 'group-hover:opacity-90',\n                    )}\n                  />\n                ) : (\n                  <div className=\"aspect-square w-full rounded-lg bg-muted\" />\n                )}\n                <span\n                  className={cn(\n                    'text-xs',\n                    edit.filter === f.id ? 'font-medium text-foreground' : 'text-muted-foreground',\n                  )}\n                >\n                  {f.label}\n                </span>\n              </button>\n            ))}\n          </div>\n          <p className=\"text-xs text-muted-foreground\">Presets stack on top of your adjustments.</p>\n        </Section>\n      )}\n\n      {tab === 'crop' && (\n        <>\n          <Section title=\"Aspect ratio\">\n            <div className=\"flex flex-wrap gap-1.5\">\n              {aspects.map((a) => (\n                <button\n                  key={a.id}\n                  type=\"button\"\n                  aria-pressed={edit.crop.aspect === a.id}\n                  onClick={() => crop({ aspect: a.id, x: 0, y: 0 })}\n                  className={cn(\n                    'h-7 rounded-full border px-3 text-xs font-medium transition-colors',\n                    edit.crop.aspect === a.id\n                      ? 'border-foreground bg-foreground text-background'\n                      : 'text-muted-foreground hover:border-ring hover:text-foreground',\n                  )}\n                >\n                  {a.label}\n                </button>\n              ))}\n            </div>\n          </Section>\n          <Section title=\"Transform\">\n            <Slider\n              label=\"Zoom\"\n              min={1}\n              max={3}\n              step={0.05}\n              origin={1}\n              format={(v) => `${v.toFixed(2)}×`}\n              value={edit.crop.zoom}\n              onStart={onStart}\n              onChange={(zoom) => crop({ zoom, x: 0, y: 0 }, 'zoom')}\n            />\n            <Slider\n              label=\"Straighten\"\n              min={-45}\n              max={45}\n              format={(v) => `${v}°`}\n              value={edit.crop.straighten}\n              onStart={onStart}\n              onChange={(straighten) => crop({ straighten, x: 0, y: 0 }, 'straighten')}\n            />\n            <div className=\"grid grid-cols-4 gap-1.5\">\n              <Button\n                size=\"icon\"\n                className=\"w-full\"\n                aria-label=\"Rotate left\"\n                onClick={() => crop({ turns: (edit.crop.turns + 3) % 4, x: 0, y: 0 })}\n              >\n                <RotateCcw />\n              </Button>\n              <Button\n                size=\"icon\"\n                className=\"w-full\"\n                aria-label=\"Rotate right\"\n                onClick={() => crop({ turns: (edit.crop.turns + 1) % 4, x: 0, y: 0 })}\n              >\n                <RotateCw />\n              </Button>\n              <Button\n                size=\"icon\"\n                className=\"w-full\"\n                aria-label=\"Flip horizontal\"\n                aria-pressed={edit.crop.flipX}\n                onClick={() => crop({ flipX: !edit.crop.flipX })}\n              >\n                <FlipHorizontal2 />\n              </Button>\n              <Button\n                size=\"icon\"\n                className=\"w-full\"\n                aria-label=\"Flip vertical\"\n                aria-pressed={edit.crop.flipY}\n                onClick={() => crop({ flipY: !edit.crop.flipY })}\n              >\n                <FlipVertical2 />\n              </Button>\n            </div>\n            <p className=\"text-xs text-muted-foreground\">Drag the image to reposition it.</p>\n          </Section>\n        </>\n      )}\n\n      <div className=\"border-t pt-4\">\n        <Button\n          variant=\"ghost\"\n          className=\"w-full\"\n          disabled={!edited}\n          onClick={() => onEdit(defaultEdit)}\n        >\n          Reset all edits\n        </Button>\n      </div>\n    </aside>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/dashboard/image-edit/panel.tsx"
    },
    {
      "path": "registry/dashboard/pages/image-edit/picture.tsx",
      "content": "import { cn } from '@/lib/utils'\n\nimport { combined, coverScale, type Edit, type StageImage } from './edits'\n\nfunction Art({ image }: { image: StageImage }) {\n  if (image.src) {\n    return <img src={image.src} alt=\"\" draggable={false} className=\"size-full object-cover\" />\n  }\n  return (\n    <div className=\"size-full\" style={{ background: image.background }}>\n      <svg\n        viewBox=\"0 0 200 250\"\n        className=\"size-full\"\n        style={{ transform: `scale(${image.scale ?? 1})` }}\n        aria-hidden\n      >\n        <ellipse cx=\"100\" cy=\"228\" rx=\"70\" ry=\"8\" fill=\"rgb(0 0 0 / 0.12)\" />\n        <path\n          d=\"M72 34 L100 44 L128 34 L166 56 L182 112 L160 120 L154 98 L154 222 L46 222 L46 98 L40 120 L18 112 L34 56 Z\"\n          fill={image.fill}\n        />\n        <path d=\"M72 34 L100 64 L128 34\" fill=\"none\" stroke=\"rgb(0 0 0 / 0.25)\" strokeWidth=\"3\" />\n        <path d=\"M100 64 V222\" stroke=\"rgb(0 0 0 / 0.2)\" strokeWidth=\"2\" />\n        {[84, 112, 140, 168, 196].map((y) => (\n          <circle key={y} cx=\"104\" cy={y} r=\"2.5\" fill=\"rgb(255 255 255 / 0.6)\" />\n        ))}\n        <rect x=\"60\" y=\"92\" width=\"26\" height=\"28\" rx=\"3\" fill=\"rgb(0 0 0 / 0.12)\" />\n        <rect x=\"114\" y=\"92\" width=\"26\" height=\"28\" rx=\"3\" fill=\"rgb(0 0 0 / 0.12)\" />\n      </svg>\n    </div>\n  )\n}\n\nexport function Picture({\n  image,\n  edit,\n  crop = true,\n  className,\n}: {\n  image: StageImage\n  edit: Edit\n  crop?: boolean\n  className?: string\n}) {\n  const a = combined(edit)\n  const { zoom, x, y, straighten, turns, flipX, flipY } = edit.crop\n  const scale = crop ? zoom * coverScale(edit) : 1\n  const transform = crop\n    ? `translate(${x}%, ${y}%) rotate(${turns * 90 + straighten}deg) scale(${scale * (flipX ? -1 : 1)}, ${scale * (flipY ? -1 : 1)})`\n    : undefined\n  const filter = [\n    `brightness(${1 + a.exposure / 200})`,\n    `contrast(${1 + a.contrast / 100 - a.fade / 400})`,\n    `saturate(${1 + a.saturation / 100})`,\n    `hue-rotate(${a.hue}deg)`,\n  ].join(' ')\n\n  return (\n    <div className={cn('relative overflow-hidden', className)}>\n      <div className=\"absolute inset-0\" style={{ transform, filter }}>\n        <Art image={image} />\n      </div>\n      {a.warmth !== 0 && (\n        <div\n          className=\"absolute inset-0 mix-blend-soft-light\"\n          style={{\n            background: a.warmth > 0 ? '#ff8a00' : '#0066ff',\n            opacity: (Math.abs(a.warmth) / 100) * 0.6,\n          }}\n        />\n      )}\n      {a.fade > 0 && (\n        <div className=\"absolute inset-0 bg-white\" style={{ opacity: (a.fade / 100) * 0.3 }} />\n      )}\n      {a.vignette > 0 && (\n        <div\n          className=\"absolute inset-0\"\n          style={{\n            background: `radial-gradient(ellipse at center, transparent 45%, rgb(0 0 0 / ${(a.vignette / 100) * 0.75}))`,\n          }}\n        />\n      )}\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/dashboard/image-edit/picture.tsx"
    },
    {
      "path": "registry/dashboard/pages/image-edit/slider.tsx",
      "content": "'use client'\n\nimport { useRef } from 'react'\n\nimport { cn } from '@/lib/utils'\n\ntype SliderProps = {\n  label: string\n  value: number\n  min: number\n  max: number\n  step?: number\n  origin?: number\n  format?: (value: number) => string\n  onStart?: () => void\n  onChange: (value: number) => void\n}\n\nexport function Slider({\n  label,\n  value,\n  min,\n  max,\n  step = 1,\n  origin = Math.max(min, Math.min(max, 0)),\n  format = (v) => (v > 0 && min < 0 ? `+${v}` : `${v}`),\n  onStart,\n  onChange,\n}: SliderProps) {\n  const track = useRef<HTMLDivElement>(null)\n  const pct = (v: number) => ((v - min) / (max - min)) * 100\n  const snap = (v: number) => {\n    const next = Math.round(Math.min(max, Math.max(min, v)) / step) * step\n    return Number(next.toFixed(4))\n  }\n\n  const fromPointer = (clientX: number) => {\n    const rect = track.current!.getBoundingClientRect()\n    onChange(snap(min + ((clientX - rect.left) / rect.width) * (max - min)))\n  }\n\n  const from = Math.min(pct(value), pct(origin))\n  const to = Math.max(pct(value), pct(origin))\n\n  return (\n    <div className=\"flex flex-col gap-2\">\n      <div className=\"flex items-center justify-between text-sm\">\n        <span className=\"text-muted-foreground\">{label}</span>\n        <button\n          type=\"button\"\n          onClick={() => {\n            onStart?.()\n            onChange(origin)\n          }}\n          title=\"Reset\"\n          className={cn(\n            'rounded px-1 font-mono text-xs tabular-nums',\n            value === origin ? 'text-muted-foreground' : 'text-foreground hover:bg-muted',\n          )}\n        >\n          {format(value)}\n        </button>\n      </div>\n      <div\n        ref={track}\n        role=\"slider\"\n        tabIndex={0}\n        aria-label={label}\n        aria-valuemin={min}\n        aria-valuemax={max}\n        aria-valuenow={value}\n        aria-valuetext={format(value)}\n        onPointerDown={(e) => {\n          e.currentTarget.setPointerCapture(e.pointerId)\n          onStart?.()\n          fromPointer(e.clientX)\n        }}\n        onPointerMove={(e) => {\n          if (e.currentTarget.hasPointerCapture(e.pointerId)) fromPointer(e.clientX)\n        }}\n        onDoubleClick={() => {\n          onStart?.()\n          onChange(origin)\n        }}\n        onKeyDown={(e) => {\n          const big = (max - min) / 10\n          const moves: Record<string, number> = {\n            ArrowLeft: -step,\n            ArrowDown: -step,\n            ArrowRight: step,\n            ArrowUp: step,\n            PageDown: -big,\n            PageUp: big,\n          }\n          let next: number\n          if (e.key in moves) next = snap(value + moves[e.key] * (e.shiftKey ? 10 : 1))\n          else if (e.key === 'Home') next = min\n          else if (e.key === 'End') next = max\n          else return\n          e.preventDefault()\n          if (!e.repeat) onStart?.()\n          onChange(next)\n        }}\n        className=\"group relative flex h-5 cursor-pointer touch-none items-center rounded-full outline-none\"\n      >\n        <div className=\"absolute inset-x-0 h-1 rounded-full bg-muted\" />\n        <div\n          className=\"absolute h-1 rounded-full bg-foreground\"\n          style={{ left: `${from}%`, width: `${to - from}%` }}\n        />\n        {min < origin && (\n          <div\n            className=\"absolute h-2.5 w-px -translate-x-1/2 bg-muted-foreground/50\"\n            style={{ left: `${pct(origin)}%` }}\n          />\n        )}\n        <div\n          className=\"absolute size-4 -translate-x-1/2 rounded-full border bg-card shadow-sm transition-transform group-focus-visible:ring-2 group-focus-visible:ring-ring/60 group-active:scale-110\"\n          style={{ left: `${pct(value)}%` }}\n        />\n      </div>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/dashboard/image-edit/slider.tsx"
    },
    {
      "path": "registry/dashboard/pages/image-edit/stage.tsx",
      "content": "'use client'\n\nimport { useRef, useState } from 'react'\nimport { ImagePlus, Plus, Trash2, Upload } from 'lucide-react'\n\nimport { cn } from '@/lib/utils'\n\nimport { defaultEdit, panLimit, ratioOf, type Edit, type StageImage } from './edits'\nimport { Picture } from './picture'\n\ntype StageProps = {\n  images: StageImage[]\n  edits: Record<string, Edit>\n  active: number\n  cropping: boolean\n  comparing: boolean\n  onSelect: (index: number) => void\n  onImages: (images: StageImage[]) => void\n  onPan: (x: number, y: number, start: boolean) => void\n}\n\nconst fromFile = (file: File): StageImage => ({\n  id: `${file.name}-${file.lastModified}-${Math.random().toString(36).slice(2, 7)}`,\n  name: file.name.replace(/\\.[^.]+$/, ''),\n  src: URL.createObjectURL(file),\n})\n\nexport function Stage({\n  images,\n  edits,\n  active,\n  cropping,\n  comparing,\n  onSelect,\n  onImages,\n  onPan,\n}: StageProps) {\n  const replaceInput = useRef<HTMLInputElement>(null)\n  const addInput = useRef<HTMLInputElement>(null)\n  const drag = useRef<{ px: number; py: number; x: number; y: number } | null>(null)\n  const [dragging, setDragging] = useState(false)\n  const current = images[active]\n  const edit = (current && edits[current.id]) ?? defaultEdit\n  const shown = comparing ? defaultEdit : edit\n  const ratio = ratioOf(shown)\n\n  const replace = (file?: File) => {\n    if (!file?.type.startsWith('image/')) return\n    if (!current) return onImages([fromFile(file)])\n    onImages(images.map((image, i) => (i === active ? fromFile(file) : image)))\n  }\n\n  const add = (files: FileList | null) => {\n    const added = [...(files ?? [])].filter((f) => f.type.startsWith('image/')).map(fromFile)\n    if (!added.length) return\n    onImages([...images, ...added])\n    onSelect(images.length)\n  }\n\n  const remove = () => {\n    onImages(images.filter((_, i) => i !== active))\n    onSelect(Math.max(0, active - 1))\n  }\n\n  return (\n    <div className=\"flex w-full flex-col items-center gap-5\">\n      <div\n        onDragOver={(e) => {\n          e.preventDefault()\n          setDragging(true)\n        }}\n        onDragLeave={() => setDragging(false)}\n        onDrop={(e) => {\n          e.preventDefault()\n          setDragging(false)\n          replace(e.dataTransfer.files[0])\n        }}\n        className={cn(\n          'group relative overflow-hidden rounded-2xl bg-muted shadow-(--shadow-card) transition-[width,aspect-ratio] duration-300 motion-reduce:transition-none',\n          dragging && 'ring-2 ring-ring ring-offset-4',\n        )}\n        style={{ aspectRatio: ratio, width: `min(100%, calc(min(64svh, 600px) * ${ratio}))` }}\n      >\n        {current ? (\n          <div\n            className={cn('size-full', cropping && 'cursor-grab touch-none active:cursor-grabbing')}\n            onPointerDown={(e) => {\n              if (!cropping) return\n              e.currentTarget.setPointerCapture(e.pointerId)\n              drag.current = { px: e.clientX, py: e.clientY, x: edit.crop.x, y: edit.crop.y }\n              onPan(edit.crop.x, edit.crop.y, true)\n            }}\n            onPointerMove={(e) => {\n              if (!drag.current) return\n              const rect = e.currentTarget.getBoundingClientRect()\n              const limit = panLimit(edit)\n              const clamp = (v: number) =>\n                Math.round(Math.max(-limit, Math.min(limit, v)) * 10) / 10\n              onPan(\n                clamp(drag.current.x + ((e.clientX - drag.current.px) / rect.width) * 100),\n                clamp(drag.current.y + ((e.clientY - drag.current.py) / rect.height) * 100),\n                false,\n              )\n            }}\n            onPointerUp={() => (drag.current = null)}\n            onPointerCancel={() => (drag.current = null)}\n          >\n            <Picture image={current} edit={shown} className=\"size-full\" />\n          </div>\n        ) : (\n          <button\n            type=\"button\"\n            onClick={() => replaceInput.current?.click()}\n            className=\"flex size-full flex-col items-center justify-center gap-2 text-sm text-muted-foreground\"\n          >\n            <ImagePlus className=\"size-6\" />\n            Drop an image or click to upload\n          </button>\n        )}\n\n        {cropping && current && (\n          <div className=\"pointer-events-none absolute inset-0 grid grid-cols-3 grid-rows-3 border-2 border-white/80\">\n            {Array.from({ length: 9 }, (_, i) => (\n              <div key={i} className=\"border-[0.5px] border-white/40\" />\n            ))}\n          </div>\n        )}\n\n        {comparing && (\n          <span className=\"absolute top-3 left-3 rounded-md bg-black/60 px-2 py-1 text-xs font-medium text-white\">\n            Original\n          </span>\n        )}\n\n        {current && !cropping && (\n          <div className=\"absolute inset-x-0 bottom-0 flex justify-center gap-2 bg-gradient-to-t from-black/50 to-transparent p-4 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100\">\n            <button\n              type=\"button\"\n              onClick={() => replaceInput.current?.click()}\n              className=\"flex h-8 items-center gap-1.5 rounded-lg bg-white px-3 text-sm font-medium text-neutral-900\"\n            >\n              <Upload className=\"size-3.5\" /> Replace\n            </button>\n            <button\n              type=\"button\"\n              onClick={remove}\n              className=\"flex h-8 items-center gap-1.5 rounded-lg bg-white/90 px-3 text-sm font-medium text-red-600\"\n            >\n              <Trash2 className=\"size-3.5\" /> Remove\n            </button>\n          </div>\n        )}\n\n        {dragging && (\n          <div className=\"absolute inset-0 flex items-center justify-center bg-background/70 text-sm font-medium\">\n            Drop to replace\n          </div>\n        )}\n      </div>\n\n      <div className=\"flex flex-wrap justify-center gap-2\">\n        {images.map((image, i) => (\n          <button\n            key={image.id}\n            type=\"button\"\n            aria-label={`Edit ${image.name}`}\n            aria-pressed={i === active}\n            onClick={() => onSelect(i)}\n            className={cn(\n              'size-14 overflow-hidden rounded-lg ring-offset-2 ring-offset-card transition',\n              i === active ? 'ring-2 ring-foreground' : 'opacity-70 hover:opacity-100',\n            )}\n          >\n            <Picture image={image} edit={edits[image.id] ?? defaultEdit} className=\"size-full\" />\n          </button>\n        ))}\n        <button\n          type=\"button\"\n          aria-label=\"Add images\"\n          onClick={() => addInput.current?.click()}\n          className=\"flex size-14 items-center justify-center rounded-lg border border-dashed text-muted-foreground hover:border-ring hover:text-foreground\"\n        >\n          <Plus className=\"size-4\" />\n        </button>\n      </div>\n\n      <input\n        ref={replaceInput}\n        type=\"file\"\n        accept=\"image/*\"\n        hidden\n        onChange={(e) => {\n          replace(e.target.files?.[0])\n          e.target.value = ''\n        }}\n      />\n      <input\n        ref={addInput}\n        type=\"file\"\n        accept=\"image/*\"\n        multiple\n        hidden\n        onChange={(e) => {\n          add(e.target.files)\n          e.target.value = ''\n        }}\n      />\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/dashboard/image-edit/stage.tsx"
    }
  ],
  "meta": {
    "scenario": "dashboard",
    "kind": "pages"
  },
  "categories": [
    "dashboard",
    "media",
    "editor"
  ],
  "type": "registry:block"
}