sourcePosition property

PortPosition get sourcePosition

Get source port position.

When a source port is available, returns its position. When no source port (e.g., temporary connection dragging FROM an input port), returns the opposite of the target port's position for smooth line flow.

Implementation

PortPosition get sourcePosition {
  // If we have a source port, use its position
  if (sourcePort != null) {
    return sourcePort!.position;
  }

  // For temporary connections dragging from an INPUT port:
  // - The input port becomes the TARGET (targetPort is set)
  // - The mouse position becomes the SOURCE (sourcePort is null)
  // - Use opposite of target position so line flows naturally toward the input
  if (targetPort != null) {
    return _oppositePosition(targetPort!.position);
  }

  // Fallback (shouldn't happen in practice)
  return PortPosition.right;
}