{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cropper",
  "title": "Cropper",
  "author": "pqoqubbw <https://zriz.dev>",
  "description": "An image cropper with the feel of the crop tool in iOS Photos: handles, grid, zoom slider, straighten dial, rotate, flip and aspect ratios.",
  "dependencies": [
    "@zriz/react@^0.2.0",
    "@zriz/core@^0.2.0"
  ],
  "registryDependencies": [
    "button"
  ],
  "files": [
    {
      "path": "registry/new-york/ui/cropper.tsx",
      "content": "\"use client\";\n\nimport \"@zriz/react/styles.css\";\nimport { exportCrop } from \"@zriz/core/dom\";\nimport type { ExportOptions } from \"@zriz/core/dom\";\nimport type {\n  AspectGroupProps,\n  AspectItemProps,\n  CommitDetails,\n  CropValue,\n  Cropper as CropperApi,\n  DialProps,\n  FlipProps,\n  ResetProps,\n  RootProps,\n  RotateProps,\n  ViewportProps,\n  ZoomProps,\n  ZoomStepProps,\n} from \"@zriz/react\";\nimport * as CropperPrimitive from \"@zriz/react/cropper\";\nimport type { ComponentProps, ReactNode } from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { Button } from \"@/registry/new-york/ui/button\";\n\ntype Styled<P> = Omit<P, \"className\"> & { className?: string };\n\ntype CropperProps = Styled<RootProps>;\n\ntype CropperViewportProps = Styled<Omit<ViewportProps, \"children\">> & {\n  grid?: boolean;\n  handles?: boolean;\n  label?: string;\n};\n\ntype CropperZoomProps = Styled<Omit<ZoomProps, \"children\">>;\n\ntype CropperDialProps = Styled<Omit<DialProps, \"children\">>;\n\ntype CropperAspectItemProps = Styled<AspectItemProps>;\n\ntype CropFileOptions = ExportOptions & { name?: string };\n\ntype IconProps = { children: ReactNode };\n\nconst HANDLES = [\n  \"top-left\",\n  \"top\",\n  \"top-right\",\n  \"right\",\n  \"bottom-right\",\n  \"bottom\",\n  \"bottom-left\",\n  \"left\",\n] as const;\n\nconst EXTENSIONS: Record<string, string> = {\n  \"image/jpeg\": \"jpg\",\n  \"image/png\": \"png\",\n  \"image/webp\": \"webp\",\n};\n\nconst ZOOM_STEP = 1.25;\n\nconst INSTRUCTIONS =\n  \"Drag the photo to move it. Arrows move the crop. Alt and arrows resize it. Plus and minus zoom, and 0 resets.\";\n\nconst SPOKEN: Partial<Record<CommitDetails[\"reason\"], string>> = {\n  flip: \"Flipped\",\n  orientation: \"Orientation swapped\",\n  reset: \"Crop reset\",\n  \"rotate-90\": \"Turned 90 degrees\",\n};\n\nconst announce = (_: CropValue, details: CommitDetails): string | null =>\n  SPOKEN[details.reason] ?? null;\n\nconst MINUS = \"−\";\n\nconst formatAngle = (degrees: number): string => {\n  const rounded = Math.round(degrees);\n\n  return `${rounded < 0 ? MINUS : \"\"}${Math.abs(rounded)}°`;\n};\n\nconst cropToFile = async (\n  cropper: CropperApi,\n  { name = \"crop\", ...options }: CropFileOptions = {}\n): Promise<File> => {\n  const { blob, type } = await exportCrop(cropper, options);\n\n  return new File([blob], `${name}.${EXTENSIONS[type] ?? \"png\"}`, { type });\n};\n\nconst Icon = ({ children }: IconProps) => (\n  <svg\n    aria-hidden=\"true\"\n    fill=\"none\"\n    stroke=\"currentColor\"\n    strokeLinecap=\"round\"\n    strokeLinejoin=\"round\"\n    strokeWidth=\"1.5\"\n    viewBox=\"0 0 20 20\"\n  >\n    {children}\n  </svg>\n);\n\nconst Cropper = ({ children, className, ...props }: CropperProps) => (\n  <CropperPrimitive.Root\n    className={cn(\n      \"flex w-full min-w-0 flex-col gap-3 [--zriz-accent:var(--primary)] [--zriz-line:var(--foreground)] [--zriz-tick:var(--muted-foreground)]\",\n      className\n    )}\n    data-slot=\"cropper\"\n    {...props}\n  >\n    {children}\n    <CropperPrimitive.Instructions>\n      {INSTRUCTIONS}\n    </CropperPrimitive.Instructions>\n    <CropperPrimitive.Announcer announce={announce} />\n  </CropperPrimitive.Root>\n);\n\nconst CropperViewport = ({\n  className,\n  grid = true,\n  handles = true,\n  label = \"Crop area\",\n  ...props\n}: CropperViewportProps) => (\n  <CropperPrimitive.Viewport\n    className={cn(\n      \"relative aspect-square w-full rounded-lg bg-background p-5\",\n      className\n    )}\n    data-slot=\"cropper-viewport\"\n    {...props}\n  >\n    <CropperPrimitive.Image />\n    <CropperPrimitive.Mask />\n    <CropperPrimitive.Area aria-label={label}>\n      {grid ? <CropperPrimitive.Grid /> : null}\n      {handles\n        ? HANDLES.map((position) => (\n            <CropperPrimitive.Handle key={position} position={position} />\n          ))\n        : null}\n    </CropperPrimitive.Area>\n  </CropperPrimitive.Viewport>\n);\n\nconst CropperZoom = ({ className, ...props }: CropperZoomProps) => (\n  <CropperPrimitive.Zoom\n    aria-label=\"Zoom\"\n    className={cn(\n      \"group/zoom relative mx-1.5 h-5 min-w-0 flex-1 outline-none\",\n      className\n    )}\n    data-slot=\"cropper-zoom\"\n    {...props}\n  >\n    <span className=\"absolute -inset-x-1.5 top-1/2 h-1 -translate-y-1/2 overflow-hidden rounded-full bg-foreground/15\">\n      <span className=\"absolute inset-x-1.5 inset-y-0\">\n        <CropperPrimitive.ZoomThumb className=\"inset-y-0 w-0 before:absolute before:inset-y-0 before:end-0 before:w-[100vw] before:bg-primary\" />\n      </span>\n    </span>\n    <CropperPrimitive.ZoomThumb className=\"top-1/2 size-3 -translate-x-1/2 -translate-y-1/2 rounded-full border border-ring bg-white ring-ring/50 group-hover/zoom:ring-3 group-focus-visible/zoom:ring-3 rtl:translate-x-1/2\" />\n  </CropperPrimitive.Zoom>\n);\n\nconst CropperZoomOut = ({ children, ...props }: Partial<ZoomStepProps>) => (\n  <CropperPrimitive.ZoomStep\n    aria-label=\"Zoom out\"\n    factor={1 / ZOOM_STEP}\n    render={\n      <Button\n        className=\"aria-disabled:pointer-events-none aria-disabled:opacity-50\"\n        type=\"button\"\n        size=\"icon\"\n        variant=\"ghost\"\n      />\n    }\n    {...props}\n  >\n    {children ?? (\n      <Icon>\n        <path d=\"M5 10H15\" />\n      </Icon>\n    )}\n  </CropperPrimitive.ZoomStep>\n);\n\nconst CropperZoomIn = ({ children, ...props }: Partial<ZoomStepProps>) => (\n  <CropperPrimitive.ZoomStep\n    aria-label=\"Zoom in\"\n    factor={ZOOM_STEP}\n    render={\n      <Button\n        className=\"aria-disabled:pointer-events-none aria-disabled:opacity-50\"\n        type=\"button\"\n        size=\"icon\"\n        variant=\"ghost\"\n      />\n    }\n    {...props}\n  >\n    {children ?? (\n      <Icon>\n        <path d=\"M5 10H15M10 5V15\" />\n      </Icon>\n    )}\n  </CropperPrimitive.ZoomStep>\n);\n\nconst CropperDial = ({ className, ...props }: CropperDialProps) => (\n  <div\n    className={cn(\n      \"relative h-10 min-w-0 flex-1 rounded-md ring-ring/50 has-focus-visible:ring-3\",\n      className\n    )}\n    data-slot=\"cropper-dial\"\n  >\n    <div className=\"absolute inset-x-0 top-[11px]\">\n      <CropperPrimitive.Dial\n        aria-label=\"Straighten\"\n        className=\"w-full outline-none\"\n        {...props}\n      >\n        <CropperPrimitive.DialTicks />\n      </CropperPrimitive.Dial>\n    </div>\n  </div>\n);\n\nconst CropperAngle = ({ className, ...props }: ComponentProps<\"span\">) => (\n  <span\n    className={cn(\n      \"w-9 text-center text-xs text-muted-foreground tabular-nums\",\n      className\n    )}\n    data-slot=\"cropper-angle\"\n    {...props}\n  >\n    <CropperPrimitive.DialValue format={formatAngle} />\n  </span>\n);\n\nconst CropperRotate = ({ children, ...props }: RotateProps) => (\n  <CropperPrimitive.Rotate\n    aria-label=\"Rotate left\"\n    render={\n      <Button\n        className=\"aria-disabled:pointer-events-none aria-disabled:opacity-50\"\n        type=\"button\"\n        size=\"icon\"\n        variant=\"ghost\"\n      />\n    }\n    {...props}\n  >\n    {children ?? (\n      <Icon>\n        <path d=\"M5.5 9.5H10.5A1.5 1.5 0 0 1 12 11V15A1.5 1.5 0 0 1 10.5 16.5H5.5A1.5 1.5 0 0 1 4 15V11A1.5 1.5 0 0 1 5.5 9.5Z\" />\n        <path d=\"M16 12.5V9.5A4 4 0 0 0 12 5.5H9\" />\n        <path d=\"M11 3.5L9 5.5L11 7.5\" />\n      </Icon>\n    )}\n  </CropperPrimitive.Rotate>\n);\n\nconst CropperFlip = ({ children, ...props }: FlipProps) => (\n  <CropperPrimitive.Flip\n    aria-label=\"Flip\"\n    render={\n      <Button\n        className=\"aria-disabled:pointer-events-none aria-disabled:opacity-50\"\n        type=\"button\"\n        size=\"icon\"\n        variant=\"ghost\"\n      />\n    }\n    {...props}\n  >\n    {children ?? (\n      <Icon>\n        <path d=\"M8.5 4.5V15.5H3.5Z\" />\n        <path d=\"M11.5 4.5V15.5H16.5Z\" />\n      </Icon>\n    )}\n  </CropperPrimitive.Flip>\n);\n\nconst CropperReset = ({ children, ...props }: ResetProps) => (\n  <CropperPrimitive.Reset\n    render={\n      <Button\n        className=\"aria-disabled:pointer-events-none aria-disabled:opacity-50\"\n        type=\"button\"\n        size=\"sm\"\n        variant=\"ghost\"\n      />\n    }\n    {...props}\n  >\n    {children ?? \"Reset\"}\n  </CropperPrimitive.Reset>\n);\n\nconst CropperAspect = ({ className, ...props }: Styled<AspectGroupProps>) => (\n  <CropperPrimitive.AspectGroup\n    aria-label=\"Aspect ratio\"\n    className={cn(\n      \"inline-flex h-8 w-fit items-center rounded-lg bg-muted p-[3px] text-muted-foreground\",\n      className\n    )}\n    data-slot=\"cropper-aspect\"\n    {...props}\n  />\n);\n\nconst CropperAspectItem = ({ className, ...props }: CropperAspectItemProps) => (\n  <CropperPrimitive.AspectItem\n    className={cn(\n      \"inline-flex h-full items-center justify-center rounded-md border border-transparent px-2 text-sm font-medium whitespace-nowrap tabular-nums outline-none select-none hover:text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 data-checked:bg-background data-checked:text-foreground data-checked:shadow-sm\",\n      className\n    )}\n    data-slot=\"cropper-aspect-item\"\n    {...props}\n  />\n);\n\nexport type { CropFileOptions, CropperProps, CropperViewportProps };\nexport {\n  Cropper,\n  CropperAngle,\n  CropperAspect,\n  CropperAspectItem,\n  CropperDial,\n  CropperFlip,\n  CropperReset,\n  CropperRotate,\n  CropperViewport,\n  CropperZoom,\n  CropperZoomIn,\n  CropperZoomOut,\n  cropToFile,\n};\n",
      "type": "registry:ui"
    }
  ],
  "docs": "Needs Tailwind CSS v4, React 19 and shadcn/ui components on Radix or Base UI. Docs: https://zriz.dev/docs/shadcn",
  "categories": [
    "image",
    "cropper"
  ],
  "type": "registry:ui"
}