Spaces:
Running
Running
Download src/features/canvas/components/StickerEdge.jsx from DanilDrotik/FlowWeb: direct link, hf CLI and curl.
- Browser
- Download file 2.21 kB
-
https://huggingface.co/spaces/DanilDrotik/FlowWeb/resolve/main/src/features/canvas/components/StickerEdge.jsx
- Command line
-
hf download hf://spaces/DanilDrotik/FlowWeb/src/features/canvas/components/StickerEdge.jsx
-
curl -L -o StickerEdge.jsx https://huggingface.co/spaces/DanilDrotik/FlowWeb/resolve/main/src/features/canvas/components/StickerEdge.jsx
2.21 kB
| import React from 'react'; | |
| import { getBezierPath, BaseEdge, useInternalNode } from '@xyflow/react'; | |
| import { floatingPoints } from './floatingEdge'; | |
| export default function StickerEdge({ | |
| id, | |
| source, | |
| target, | |
| sourceX, | |
| sourceY, | |
| targetX, | |
| targetY, | |
| sourcePosition, | |
| targetPosition, | |
| style = {}, | |
| selected, | |
| interactionWidth, | |
| }) { | |
| const sourceNode = useInternalNode(source); | |
| const targetNode = useInternalNode(target); | |
| // Threads float between the facing sides of the sticker and its card | |
| const p = sourceNode && targetNode | |
| ? floatingPoints(sourceNode, targetNode, {}) | |
| : { sx: sourceX, sy: sourceY, tx: targetX, ty: targetY, sourcePos: sourcePosition, targetPos: targetPosition }; | |
| const [edgePath] = getBezierPath({ | |
| sourceX: p.sx, | |
| sourceY: p.sy, | |
| sourcePosition: p.sourcePos, | |
| targetX: p.tx, | |
| targetY: p.ty, | |
| targetPosition: p.targetPos, | |
| curvature: 0.6, // More curved for a "hanging thread" feel | |
| }); | |
| return ( | |
| <> | |
| {/* Interaction area for easier clicking */} | |
| <path | |
| id={id} | |
| style={{ fill: 'none', strokeWidth: 20, stroke: 'transparent' }} | |
| className="react-flow__edge-interaction" | |
| d={edgePath} | |
| /> | |
| {/* Shadow path */} | |
| <BaseEdge | |
| path={edgePath} | |
| style={{ | |
| ...style, | |
| strokeWidth: 3, | |
| stroke: 'rgba(0,0,0,0.1)', | |
| fill: 'none', | |
| transform: 'translate(1px, 2px)', | |
| }} | |
| /> | |
| {/* Main Thread */} | |
| <BaseEdge | |
| path={edgePath} | |
| style={{ | |
| ...style, | |
| strokeWidth: selected ? 3 : 2, | |
| stroke: selected ? '#f59e0b' : '#94a3b8', // Amber when selected, slate otherwise | |
| strokeDasharray: '5 3', // Slightly longer dashes | |
| fill: 'none', | |
| strokeLinecap: 'round', | |
| transition: 'stroke 0.2s, stroke-width 0.2s', | |
| }} | |
| /> | |
| {/* Optional: Small highlight on the thread */} | |
| <BaseEdge | |
| path={edgePath} | |
| style={{ | |
| ...style, | |
| strokeWidth: 0.5, | |
| stroke: 'rgba(255,255,255,0.4)', | |
| fill: 'none', | |
| strokeDasharray: '2 10', | |
| }} | |
| /> | |
| </> | |
| ); | |
| } | |