({
clampEnabled,
rangeStart,
rangeEnd,
itemCount,
viewportHeight,
mountedStartTop,
mountedEndBottom,
}: VirtualScrollClampBoundsInput)
| 388 | } |
| 389 | |
| 390 | export function computeVirtualScrollClampBounds({ |
| 391 | clampEnabled, |
| 392 | rangeStart, |
| 393 | rangeEnd, |
| 394 | itemCount, |
| 395 | viewportHeight, |
| 396 | mountedStartTop, |
| 397 | mountedEndBottom, |
| 398 | }: VirtualScrollClampBoundsInput): VirtualScrollClampBounds { |
| 399 | if (!clampEnabled || rangeEnd <= rangeStart || itemCount === 0) { |
| 400 | return { |
| 401 | clampMin: undefined, |
| 402 | clampMax: undefined, |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | if (rangeStart > 0 && mountedStartTop === undefined) { |
| 407 | return { |
| 408 | clampMin: undefined, |
| 409 | clampMax: undefined, |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | if (rangeEnd < itemCount && mountedEndBottom === undefined) { |
| 414 | return { |
| 415 | clampMin: undefined, |
| 416 | clampMax: undefined, |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | const clampMin = rangeStart === 0 ? 0 : mountedStartTop! |
| 421 | const clampMax = |
| 422 | rangeEnd === itemCount |
| 423 | ? Infinity |
| 424 | : Math.max(clampMin, mountedEndBottom! - viewportHeight) |
| 425 | |
| 426 | return { |
| 427 | clampMin, |
| 428 | clampMax, |
| 429 | } |
| 430 | } |
| 431 | |
| 432 | export type VirtualScrollResult = { |
| 433 | /** [startIndex, endIndex) half-open slice of items to render. */ |
no test coverage detected