()
| 747 | } |
| 748 | |
| 749 | const sync = () => { |
| 750 | const nextViewport = find(viewportAttr) |
| 751 | if (nextViewport !== viewport) { |
| 752 | viewportListening?.abort() |
| 753 | viewport = observe(viewport, nextViewport) |
| 754 | if (viewport !== null) { |
| 755 | viewportListening = new AbortController() |
| 756 | const options = { |
| 757 | signal: viewportListening.signal, |
| 758 | passive: true |
| 759 | } |
| 760 | viewport.addEventListener("scroll", onViewportScroll, options) |
| 761 | for ( |
| 762 | const name of [ |
| 763 | "wheel", |
| 764 | "pointermove", |
| 765 | "pointerenter", |
| 766 | "keydown" |
| 767 | ] |
| 768 | ) { |
| 769 | viewport.addEventListener(name, onUserInteraction, options) |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | const nextContent = find(contentAttr) |
| 774 | if (nextContent !== content) content = observe(content, nextContent) |
| 775 | corner = find(cornerAttr) |
| 776 | for (const axis of [y, x]) { |
| 777 | const thumb = find(thumbAttr(axis.orientation)) |
| 778 | const scrollbar = find(scrollbarAttr(axis.orientation)) |
| 779 | if ( |
| 780 | drag !== null && drag.axis === axis && |
| 781 | (scrollbar !== axis.scrollbar || thumb !== axis.thumb) |
| 782 | ) { |
| 783 | clearDrag() |
| 784 | } |
| 785 | axis.thumb = thumb |
| 786 | if (scrollbar === axis.scrollbar) continue |
| 787 | axis.listening?.abort() |
| 788 | axis.scrollbar = scrollbar |
| 789 | if (scrollbar === null) continue |
| 790 | axis.listening = new AbortController() |
| 791 | const { signal } = axis.listening |
| 792 | scrollbar.addEventListener("wheel", onWheel(axis), { |
| 793 | signal, |
| 794 | passive: false |
| 795 | }) |
| 796 | scrollbar.addEventListener("pointerdown", onPointerDown(axis), { |
| 797 | signal |
| 798 | }) |
| 799 | scrollbar.addEventListener("pointermove", onPointerMove, { signal }) |
| 800 | scrollbar.addEventListener("pointerup", endDrag, { signal }) |
| 801 | scrollbar.addEventListener("pointercancel", endDrag, { signal }) |
| 802 | // A native scrollbar doesn't take focus when pressed. |
| 803 | scrollbar.addEventListener( |
| 804 | "mousedown", |
| 805 | (event) => event.preventDefault(), |
| 806 | { signal } |
no test coverage detected