buildAnnotationFromDrag

fun buildAnnotationFromDrag(pageIndex: Int, startX: Float, startY: Float, endX: Float, endY: Float, pageWidth: Float, pageHeight: Float, color: Color = PdfViewerAnnotation.DefaultHighlightColor): PdfViewerAnnotation?

Builds a normalised PdfViewerAnnotation from a drag in page-point space, given the two opposite corners (startX/startYendX/endY). The corners are normalised so a drag in any direction (up-left, down-right, …) yields a box with non-negative width/height, and the result is clamped to the page bounds (pageWidth × pageHeight) so a highlight can never spill outside the page.

Returns null when the resulting box is degenerate (zero-area after clamping) — e.g. a tap with no drag — so the caller can treat that as "not a highlight" and fall through to hit-testing instead.

Pure logic (no Compose dependency) so it is unit-testable on the JVM.