"use client"; import type * as React from "react"; import { selectedItemBorderClassName } from "../../primitives/selection-state"; import { cn } from "../../../lib/utils"; import { formatStopPosition, getStopCssColor, parseStopPosition, type IndexedGradientStop, } from "./gradient-control-utils"; const gradientStopPinEdgeInset = 2; function getGradientStopPinLeftPosition(position: number): string { const stopPosition = formatStopPosition(position); const pixelOffset = gradientStopPinEdgeInset * (1 - position * 2); if (Math.abs(pixelOffset) < 0.01) { return stopPosition; } const offsetOperator = pixelOffset > 0 ? "+" : "-"; const offsetValue = Number(Math.abs(pixelOffset).toFixed(2)); return `calc(${stopPosition} ${offsetOperator} ${offsetValue}px)`; } function GradientStopPin({ isDragging, isSelected, onDoubleClick, onKeyDown, onPointerDown, stop, }: { isDragging: boolean; isSelected: boolean; onDoubleClick: (event: React.MouseEvent) => void; onKeyDown: (event: React.KeyboardEvent) => void; onPointerDown: (event: React.PointerEvent) => void; stop: IndexedGradientStop; }): React.JSX.Element { const stopPosition = parseStopPosition(stop.position); return ( ); } export function GradientStopsTrack({ gradient, onDragEnd, onPointerDown, onPointerMove, onRemoveStop, onRemoveStopByKey, onStartDrag, selectedIndex, stops, trackRef, draggingIndex, }: { gradient: string; draggingIndex: number | null; onDragEnd: () => void; onPointerDown: (event: React.PointerEvent) => void; onPointerMove: (event: React.PointerEvent) => void; onRemoveStop: ( index: number, event: React.MouseEvent, ) => void; onRemoveStopByKey: ( index: number, event: React.KeyboardEvent, ) => void; onStartDrag: ( index: number, event: React.PointerEvent, ) => void; selectedIndex: number | null; stops: readonly IndexedGradientStop[]; trackRef: React.RefObject; }): React.JSX.Element { return (
{stops.map((stop) => ( onRemoveStop(stop.originalIndex, event)} onKeyDown={(event) => onRemoveStopByKey(stop.originalIndex, event)} onPointerDown={(event) => onStartDrag(stop.originalIndex, event)} stop={stop} /> ))}
); }