| 509 | } |
| 510 | |
| 511 | const measure = () => { |
| 512 | if (disposed) return |
| 513 | sync() |
| 514 | if (viewport === null) return |
| 515 | const { |
| 516 | clientHeight, |
| 517 | clientWidth, |
| 518 | scrollHeight, |
| 519 | scrollLeft, |
| 520 | scrollTop, |
| 521 | scrollWidth |
| 522 | } = viewport |
| 523 | if (scrollHeight === 0 || scrollWidth === 0) return report(noOverflow) |
| 524 | |
| 525 | const rtl = isRtl(viewport) |
| 526 | const both = clientWidth < scrollWidth && clientHeight < scrollHeight |
| 527 | const nextCornerWidth = both ? y.scrollbar?.offsetWidth || 0 : 0 |
| 528 | const nextCornerHeight = both ? x.scrollbar?.offsetHeight || 0 : 0 |
| 529 | const cornerUnsized = cornerWidth === 0 && cornerHeight === 0 |
| 530 | |
| 531 | const edges = (axis: Axis) => { |
| 532 | const vertical = axis.vertical |
| 533 | const client = vertical ? clientHeight : clientWidth |
| 534 | const size = vertical ? scrollHeight : scrollWidth |
| 535 | const overflow = client < size |
| 536 | const maxScroll = Math.max(0, size - client) |
| 537 | const fromStart = vertical |
| 538 | ? scrollTop |
| 539 | : rtl |
| 540 | ? -scrollLeft |
| 541 | : scrollLeft |
| 542 | const start = overflow |
| 543 | ? normalizeScrollOffset(fromStart, maxScroll) |
| 544 | : 0 |
| 545 | const { scrollbar, thumb } = axis |
| 546 | if (scrollbar !== null) { |
| 547 | const { inset, track } = insetsOf(axis, scrollbar) |
| 548 | const cornerOffset = cornerUnsized |
| 549 | ? (vertical ? nextCornerHeight : nextCornerWidth) |
| 550 | : 0 |
| 551 | const length = Math.min( |
| 552 | track - cornerOffset, |
| 553 | (overflow ? client : 0) - inset |
| 554 | ) |
| 555 | const thumbSize = Math.max( |
| 556 | MIN_THUMB_SIZE, |
| 557 | (length * client) / size |
| 558 | ) |
| 559 | const sizeVar = vertical ? thumbHeightVar : thumbWidthVar |
| 560 | scrollbar.style.setProperty(sizeVar, `${thumbSize}px`) |
| 561 | if (thumb !== null) { |
| 562 | const maxThumbOffset = track - thumbSize - inset |
| 563 | const offset = applyOverscrollThumb( |
| 564 | thumb, |
| 565 | sizeVar, |
| 566 | fromStart, |
| 567 | maxScroll, |
| 568 | size, |