|
| 1 | +import type React from "react"; |
| 2 | + |
| 3 | +// Editor primary color (themeable via --hf-accent). Applied through inline |
| 4 | +// style because CSS var() isn't valid in SVG presentation attributes. |
| 5 | +export const ACCENT = "var(--hf-accent, #3CE6AC)"; |
| 6 | + |
| 7 | +/** One path node: a diamond (matching the timeline keyframe), a wider transparent |
| 8 | + * grab target (when editable), and a hover-revealed × delete badge (when removable). */ |
| 9 | +export function MotionPathNode(props: { |
| 10 | + cx: number; |
| 11 | + cy: number; |
| 12 | + r: number; |
| 13 | + interactive: boolean; |
| 14 | + removable: boolean; |
| 15 | + grabbing: boolean; |
| 16 | + selected: boolean; |
| 17 | + onEnter: () => void; |
| 18 | + onLeave: () => void; |
| 19 | + onPointerDown: (e: React.PointerEvent) => void; |
| 20 | + onPointerMove: (e: React.PointerEvent) => void; |
| 21 | + onPointerUp: (e: React.PointerEvent) => void; |
| 22 | + onRemove: (e: React.PointerEvent) => void; |
| 23 | + onContextMenu?: (e: React.MouseEvent) => void; |
| 24 | +}) { |
| 25 | + const { cx, cy, r, interactive, removable, grabbing, selected } = props; |
| 26 | + const bx = cx + r * 1.8; |
| 27 | + const by = cy - r * 1.8; |
| 28 | + const k = r * 0.55; |
| 29 | + // Diamond matching the timeline keyframe (a 45°-rotated rounded square). |
| 30 | + // `side` is chosen so the diamond's points reach ~`r` from center, matching the |
| 31 | + // old dot's footprint; selection is shown by enlarging it (no extra shape). |
| 32 | + const side = (selected ? r * 1.5 : r) * 1.414; |
| 33 | + return ( |
| 34 | + <g onPointerEnter={props.onEnter} onPointerLeave={props.onLeave}> |
| 35 | + <rect |
| 36 | + x={cx - side / 2} |
| 37 | + y={cy - side / 2} |
| 38 | + width={side} |
| 39 | + height={side} |
| 40 | + rx={side * 0.17} |
| 41 | + transform={`rotate(45 ${cx} ${cy})`} |
| 42 | + stroke="#0b0f1a" |
| 43 | + strokeWidth={1.5} |
| 44 | + vectorEffect="non-scaling-stroke" |
| 45 | + style={{ fill: ACCENT }} |
| 46 | + /> |
| 47 | + {interactive && ( |
| 48 | + <circle |
| 49 | + cx={cx} |
| 50 | + cy={cy} |
| 51 | + r={r * 2.4} |
| 52 | + fill="transparent" |
| 53 | + className="pointer-events-auto" |
| 54 | + style={{ cursor: grabbing ? "grabbing" : "grab" }} |
| 55 | + onPointerDown={props.onPointerDown} |
| 56 | + onPointerMove={props.onPointerMove} |
| 57 | + onPointerUp={props.onPointerUp} |
| 58 | + onContextMenu={props.onContextMenu} |
| 59 | + /> |
| 60 | + )} |
| 61 | + {removable && ( |
| 62 | + <g |
| 63 | + className="pointer-events-auto" |
| 64 | + style={{ cursor: "pointer" }} |
| 65 | + onPointerDown={props.onRemove} |
| 66 | + > |
| 67 | + <circle |
| 68 | + cx={bx} |
| 69 | + cy={by} |
| 70 | + r={r * 1.3} |
| 71 | + stroke="#0b0f1a" |
| 72 | + strokeWidth={1} |
| 73 | + vectorEffect="non-scaling-stroke" |
| 74 | + style={{ fill: ACCENT }} |
| 75 | + /> |
| 76 | + <line |
| 77 | + x1={bx - k} |
| 78 | + y1={by - k} |
| 79 | + x2={bx + k} |
| 80 | + y2={by + k} |
| 81 | + stroke="#0b0f1a" |
| 82 | + strokeWidth={1.5} |
| 83 | + vectorEffect="non-scaling-stroke" |
| 84 | + /> |
| 85 | + <line |
| 86 | + x1={bx + k} |
| 87 | + y1={by - k} |
| 88 | + x2={bx - k} |
| 89 | + y2={by + k} |
| 90 | + stroke="#0b0f1a" |
| 91 | + strokeWidth={1.5} |
| 92 | + vectorEffect="non-scaling-stroke" |
| 93 | + /> |
| 94 | + </g> |
| 95 | + )} |
| 96 | + </g> |
| 97 | + ); |
| 98 | +} |
0 commit comments