diff --git a/README.md b/README.md index e26b49d..09c8b78 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,8 @@ An unofficial add-on for the Next.js App Router. It draws slide transitions betw - Slide transition between routes; vertical slide for routes in `modalRoutes`. - Edge-swipe Back (`swipeBack`) with a preview of the previous screen. - Scroll offset restored per history entry (`preserveScroll`). -- Document scrolling by default (`window.scrollTo`, `window.scrollY` keep working), with a custom vertical scrollbar; an independent scroll container also works (`scrollTarget`). +- Document scrolling by default (`window.scrollTo`, `window.scrollY` keep working); an independent scroll container also works (`scrollTarget`). +- A vertical scrollbar drawn with [OverlayScrollbars](https://github.com/KingSora/OverlayScrollbars): its track stays between fixed headers, footers and tab bars, follows whichever scroller is moving, and can be dragged or clicked. - `edgeBounce`: optional touch bounce at scroll boundaries on non-Apple touch devices. - `skipSlideQueryKeys`: skip the page slide when only a popup query parameter changes. - `fixedTargets` keeps chosen elements still during the slide. @@ -52,22 +53,27 @@ An unofficial add-on for the Next.js App Router. It draws slide transitions betw - Next.js below 16.4.6 and React below 19.3.1 are untested. - No benchmarks against other libraries. - No physics or spring animation. Motion is CSS and the Web Animations API. +- No horizontal custom scrollbar. Horizontal overflow keeps native scrolling without a drawn bar. +- The drawn scrollbar no longer shrinks during elastic overscroll; `edgeBounce` still compresses it. ## Where it stands -| | `@uiwwsw/stackflow-next` | `@stackflow/react` | -| --- | --- | --- | -| npm downloads, week of 2026-11-18 | 271 | 38,535 | -| Maintainers | one | Daangn team | -| Status | unofficial | official | - -- Usage is close to zero. No known production users. -- It is a visual layer over Next.js. Stackflow is a full navigation stack with its own router and activity model; this package does not replace it. -- Versions 3.0.0 to 3.1.0 were published to npm from a branch before they reached `main`; `main` now matches 3.1.0. Eight releases in one day (3.0.0 to 3.1.0 on 2026-11-17) mean the API is still moving. -- Next.js documents its own View Transitions support ([guide](https://nextjs.org/docs/app/guides/view-transitions)). If a plain page transition is enough, use that and skip this package. -- For animation work, Motion is the common choice (about 40 million weekly downloads). -- For a native-style navigation stack with an official maintainer, use Stackflow. -- Use this package only if you need the swipe-back gesture and per-entry scroll restoration on the Next.js App Router, and accept an unproven, single-maintainer dependency. +One maintainer, no known production users, not tested on real devices. Compared with the libraries people use for the same job on the Next.js App Router (checked against each project's docs or source, November 2026): + +| | stackflow-next | [SSGOI](https://github.com/meursyphus/ssgoi) | [next-view-transitions](https://github.com/shuding/next-view-transitions) | [Stackflow](https://github.com/daangn/stackflow) | +| --- | --- | --- | --- | --- | +| Keeps App Router routes and server components | yes | yes | yes | no; its README marks the Next.js example "Not Recommended" | +| Back/Forward plays the reverse direction | yes, from history position | yes, per saved entry | same animation both ways | yes, with its own router | +| Swipe Back with a preview of the previous screen | yes | browser's own gesture only | no | yes (cupertino theme) | +| Scroll position per history entry | yes | yes | no | not applicable | +| Draggable scrollbar kept clear of fixed bars | yes | no | no | no | +| Animation engine | View Transitions API | Web Animations API | View Transitions API | CSS transitions | +| Framework range | Next.js 16.4.6+ | React, Vue, Svelte, Solid, Angular, Qwik; Next.js 13.4–16 | Next.js App Router | React, single page | + +- If you need effects beyond slides, older Next.js versions or browsers without View Transitions, SSGOI covers more and is more widely used. +- If a crossfade on link clicks is enough, Next.js's own `` or next-view-transitions is smaller. +- This package fits an app-like Next.js site that wants swipe Back, per-entry scroll and a scrollbar that respects its fixed header and tab bar together. +- iOS Safari uses the same left edge for its own Back gesture; how the two interact has not been checked on a device. ## Install diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 78ccc3b..4cc246e 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -62,6 +62,7 @@ library. | Package | Kind | Used for | | --- | --- | --- | | `@stackflow/core` | dependency | `aggregate` and `makeEvent` in `src/next/engine.ts`, to build the `Stack` returned by `useStack()`. | +| `overlayscrollbars` | dependency | Draws the vertical scrollbar in `src/next/scroll.ts` (drag, click, auto-hide; handle moved by a `ScrollTimeline` where supported). Its base CSS is bundled into `dist/style.css` by `scripts/build-css.mjs`. | | `next` | peer | `next/link`, `next/navigation` (`useRouter`, `usePathname`, `useSearchParams`) and the `NextConfig` type. | | `react`, `react-dom` | peer | Components and hooks (`useSyncExternalStore`, `useLayoutEffect`, `Suspense`). | @@ -107,8 +108,9 @@ The `./dom` entry has no dependencies. ready. - **`scroll.ts`** Scroll handling for the two modes. Window mode keeps document scrolling and measures the visible area; container mode scrolls an element. - Both draw the custom vertical scrollbar thumb and help the engine save and - restore offsets. + Both place the scrollbar track (between fixed bars, fitted to the target's + content box) and hand the active scroller to an OverlayScrollbars instance + that draws the handle. They also help the engine save and restore offsets. - **`swipe.ts`** `attachSwipeBack`. Pointer-event gesture starting in the left 24 px. Moves the live content, reveals a cloned preview of the previous screen, and on release either calls `router.back()` or settles back. diff --git a/docs/REFERENCE.md b/docs/REFERENCE.md index 1e9ebaf..a2d9ec2 100644 --- a/docs/REFERENCE.md +++ b/docs/REFERENCE.md @@ -245,11 +245,12 @@ hash, or another query key also changes, the usual transition rules apply. The document scrolls by default. Existing calls to `window.scrollTo()` and `window.scrollBy()`, reads of `window.scrollY`, and window `scroll` listeners work with this package. It hides the browser's document scrollbar and -draws a vertical thumb beside the content box of `scrollTarget`, excluding +draws a vertical scrollbar with [OverlayScrollbars](https://github.com/KingSora/OverlayScrollbars) +beside the content box of `scrollTarget`, excluding its margins, borders and padding. The track starts at the content's top edge as seen at the start of scrolling and ends at its bottom edge as seen at the end of scrolling, within the visible viewport. Its length stays steady -as the content moves and the thumb follows the full native scroll range. +as the content moves and the handle follows the full native scroll range. No header or footer settings are needed. When a sticky provider slot or a fixed bar covers the track, the track stops @@ -262,8 +263,9 @@ height between any recognized bars. If existing CSS makes the selected area an independent native scroller, the scrollbar follows that element while it scrolls and switches to the -document when document scrolling takes over. The thumb fades shortly after -vertical scrolling stops. +document when document scrolling takes over. The scrollbar appears while the +pointer moves or the page scrolls and hides 0.8 seconds later. Drag the handle +or click the track to scroll; keyboard, wheel and touch scrolling stay native. ```tsx @@ -274,9 +276,11 @@ vertical scrolling stops. Let the provider and content grow with the page. The header sticks to the top, and `persistent` and `footer` stick together at the bottom. The browser handles wheel and touch input, momentum, and elastic overscroll where -supported. The thumb compresses at the edge when the browser reports an -elastic offset. Set `--stackflow-scrollbar-color` on the provider to set its -color. +supported. Set `--stackflow-scrollbar-color` and +`--stackflow-scrollbar-active-color` (hover and drag) on the provider to set its +colors. The scrollbar uses the `os-theme-stackflow` OverlayScrollbars theme, so +its CSS variables (`--os-size`, `--os-handle-min-size` and others) can be +overridden too. If the app positions its own bars with CSS `position: fixed`, reserve their heights in the layout so the first and last content remain reachable. diff --git a/examples/next-app/next.config.mjs b/examples/next-app/next.config.mjs index f28edfb..6c72ac6 100644 --- a/examples/next-app/next.config.mjs +++ b/examples/next-app/next.config.mjs @@ -2,4 +2,4 @@ import path from 'node:path'; import {fileURLToPath} from 'node:url'; import { withStackflow } from '../../dist/config.js'; const root=path.resolve(path.dirname(fileURLToPath(import.meta.url)),'../..'); -export default withStackflow({ distDir:process.env.STACKFLOW_NEXT_BUILD_DIR||'.next', webpack(config){config.resolve.alias['@uiwwsw/stackflow-next/style.css']=path.join(root,'src/next/style.css');config.resolve.alias['@uiwwsw/stackflow-next$']=path.join(root,'dist/index.js');return config;} }); +export default withStackflow({ distDir:process.env.STACKFLOW_NEXT_BUILD_DIR||'.next', webpack(config){config.resolve.alias['@uiwwsw/stackflow-next/style.css']=path.join(root,'dist/style.css');config.resolve.alias['@uiwwsw/stackflow-next$']=path.join(root,'dist/index.js');return config;} }); diff --git a/package-lock.json b/package-lock.json index 9aca684..f48a664 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,16 @@ { "name": "@uiwwsw/stackflow-next", - "version": "3.1.1", + "version": "3.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@uiwwsw/stackflow-next", - "version": "3.1.1", + "version": "3.2.0", "license": "MIT", "dependencies": { - "@stackflow/core": "^3.1.0" + "@stackflow/core": "^3.1.0", + "overlayscrollbars": "^2.17.1" }, "devDependencies": { "@types/node": "^26.6.6", @@ -1855,6 +1856,12 @@ } } }, + "node_modules/overlayscrollbars": { + "version": "2.17.1", + "resolved": "https://registry.npmjs.org/overlayscrollbars/-/overlayscrollbars-2.17.1.tgz", + "integrity": "sha512-EVBOsCB/BhvdP4WMLvIej8jHikJtGCxrWRBC8qX8xj3QmvSuY+PJgOr02du9Y2ad9dn9T8c7vp4MiMDQNWT9RQ==", + "license": "MIT" + }, "node_modules/picocolors": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.1.1.tgz", diff --git a/package.json b/package.json index 6a80910..280e9cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@uiwwsw/stackflow-next", - "version": "3.1.1", + "version": "3.2.0", "type": "module", "description": "Unofficial slide transitions, swipe-back and scroll restoration for the Next.js App Router, built on Next.js Cache Components, @stackflow/core and the View Transitions API", "keywords": [ @@ -22,7 +22,7 @@ }, "./style.css": { "types": "./src/style.d.ts", - "default": "./src/next/style.css" + "default": "./dist/style.css" }, "./dom": { "types": "./src/index.d.ts", @@ -50,7 +50,7 @@ "scripts": { "test": "node --import tsx --test test/*.test.js test/next/*.test.ts", "check": "tsc --noEmit", - "build": "tsc", + "build": "tsc && node scripts/build-css.mjs", "prepack": "npm run build" }, "devDependencies": { @@ -66,7 +66,8 @@ }, "license": "MIT", "dependencies": { - "@stackflow/core": "^3.1.0" + "@stackflow/core": "^3.1.0", + "overlayscrollbars": "^2.17.1" }, "peerDependencies": { "next": "^16.4.6", diff --git a/scripts/build-css.mjs b/scripts/build-css.mjs new file mode 100644 index 0000000..de63906 --- /dev/null +++ b/scripts/build-css.mjs @@ -0,0 +1,13 @@ +// Bundle OverlayScrollbars' base styles (MIT, license header kept) with the +// package styles so applications import a single `style.css`. +import { readFile, writeFile, mkdir } from 'node:fs/promises'; +import { createRequire } from 'node:module'; +import { dirname, resolve } from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const root = resolve(dirname(fileURLToPath(import.meta.url)), '..'); +const require = createRequire(import.meta.url); +const overlay = await readFile(require.resolve('overlayscrollbars/overlayscrollbars.css'), 'utf8'); +const own = await readFile(resolve(root, 'src/next/style.css'), 'utf8'); +await mkdir(resolve(root, 'dist'), { recursive: true }); +await writeFile(resolve(root, 'dist/style.css'), `${overlay.trim()}\n\n${own.trim()}\n`); diff --git a/src/next/edge-bounce.ts b/src/next/edge-bounce.ts index 359bc39..f768dc4 100644 --- a/src/next/edge-bounce.ts +++ b/src/next/edge-bounce.ts @@ -21,7 +21,8 @@ export function attachEdgeBounce(content: HTMLElement, thumb: HTMLElement | unde || !content.animate) return; const reducedMotion = win.matchMedia('(prefers-reduced-motion: reduce)'); - const indicator = thumb?.firstElementChild; + // The handle of the visible drawn scrollbar inside the slot, if any. + const indicator = () => thumb?.querySelector('.os-scrollbar-vertical.os-scrollbar-visible .os-scrollbar-handle') ?? undefined; let gesture: Gesture | undefined; let frame = 0; let latest: Touch | undefined; @@ -119,9 +120,10 @@ export function attachEdgeBounce(content: HTMLElement, thumb: HTMLElement | unde bodyAnimation = surface.animate([{translate: '0 0px'}, {translate: `0 ${edge * maxPull}px`}], { ...added, duration: maxPull }); bodyAnimation.pause(); - if (indicator && thumb && !thumb.hidden) { + const handle = indicator(); + if (handle && thumb && !thumb.hidden) { const transformOrigin = edge > 0 ? 'center top' : 'center bottom'; - thumbAnimation = indicator.animate([{scale: '1 1', transformOrigin}, {scale: '1 .55', transformOrigin}], + thumbAnimation = handle.animate([{scale: '1 1', transformOrigin}, {scale: '1 .55', transformOrigin}], { duration: maxPull, fill: 'both' }); thumbAnimation.pause(); } @@ -146,8 +148,9 @@ export function attachEdgeBounce(content: HTMLElement, thumb: HTMLElement | unde stop(); const settling = surface.animate([{translate: `0 ${pull}px`}, {translate: '0 0px'}], { ...returnTiming, composite: 'add' }); bodyAnimation = settling; - if (indicator && thumb && !thumb.hidden) { - thumbAnimation = indicator.animate([{scale: `1 ${scale}`, transformOrigin}, {scale: '1 1', transformOrigin}], returnTiming); + const handle = indicator(); + if (handle && thumb && !thumb.hidden) { + thumbAnimation = handle.animate([{scale: `1 ${scale}`, transformOrigin}, {scale: '1 1', transformOrigin}], returnTiming); thumb.setAttribute('data-stackflow-bouncing', ''); } settling.onfinish = () => { diff --git a/src/next/index.tsx b/src/next/index.tsx index 3f9bcf0..bbf0bed 100644 --- a/src/next/index.tsx +++ b/src/next/index.tsx @@ -144,9 +144,7 @@ export function StackflowProvider({children,header,footer,persistent,animation=' {header &&
{header}
}
{children}
- diff --git a/src/next/scroll.ts b/src/next/scroll.ts index 80ebcf1..33f7759 100644 --- a/src/next/scroll.ts +++ b/src/next/scroll.ts @@ -1,11 +1,87 @@ +import { ClickScrollPlugin, OverlayScrollbars } from 'overlayscrollbars'; import { attachEdgeBounce, bounceScrollAttribute } from './edge-bounce.js'; const targetAttribute = 'data-stackflow-scroll-target'; const delegatedAttribute = 'data-stackflow-scroll-delegated'; const nativeScrollbarAttribute = 'data-stackflow-native-scrollbar-hidden'; +const sourceAttribute = 'data-stackflow-scroll-source'; type ScrollBounds = { top: number; right: number; bottom: number; left: number }; -type ScrollbarOrigin = { top: number; right: number } | { viewportRight: number; rootTimeline?: boolean }; +type ScrollbarOrigin = { top: number; right: number } | { viewportRight: number }; + +/** One drawn scrollbar for one native scroller. */ +export type OverlayScrollbar = { setActive(active: boolean): void; dispose(): void }; +/** + * Creates the drawn scrollbar for a scroller inside `slot`. `root` means the + * document scroller. Returns `undefined` when no scrollbar can be drawn. + */ +export type OverlayScrollbarFactory = (scroller: HTMLElement, root: boolean, slot: HTMLElement) => OverlayScrollbar | undefined; + +// Shown while the pointer moves or the page scrolls, so a mouse can grab it. +// Nothing shows before the first scroll (OverlayScrollbars' accessible default). +const overlayOptions = { + scrollbars: { + theme: 'os-theme-stackflow', autoHide: 'move', autoHideDelay: 800, autoHideSuspend: true, + dragScroll: true, clickScroll: true, + }, +} as const; +let clickScrollRegistered = false; + +/** + * OverlayScrollbars keeps native scrolling (window.scrollTo, keyboard, touch + * momentum) and draws a draggable, clickable scrollbar whose handle follows a + * ScrollTimeline where supported. The scroller's DOM is not wrapped: the + * document uses as its viewport, and an element is its own viewport. + */ +export const createOverlayScrollbar: OverlayScrollbarFactory = (scroller, root, slot) => { + try { + if (!clickScrollRegistered) { + OverlayScrollbars.plugin(ClickScrollPlugin); + clickScrollRegistered = true; + } + const instance = OverlayScrollbars(root + ? { target: scroller.ownerDocument.body, scrollbars: { slot }, cancel: { body: null } } + : { target: scroller, elements: { viewport: scroller }, scrollbars: { slot } }, overlayOptions); + if (!OverlayScrollbars.valid(instance)) return; + return { + setActive(active) { instance.options({ scrollbars: { visibility: active ? 'auto' : 'hidden' } }); }, + dispose() { instance.destroy(); }, + }; + } catch { + return; + } +}; + +function overlays(slot: HTMLElement, factory: OverlayScrollbarFactory) { + const created = new Map(); + let active: HTMLElement | undefined; + return { + show(scroller: HTMLElement, root: boolean) { + if (!created.has(scroller)) created.set(scroller, factory(scroller, root, slot)); + slot.setAttribute(sourceAttribute, root ? 'document' : 'element'); + if (active === scroller) return; + active = scroller; + for (const [element, overlay] of created) overlay?.setActive(element === scroller); + }, + release(scroller: HTMLElement) { + created.get(scroller)?.dispose(); + created.delete(scroller); + if (active === scroller) active = undefined; + }, + dispose() { + for (const overlay of created.values()) overlay?.dispose(); + created.clear(); + active = undefined; + slot.removeAttribute(sourceAttribute); + }, + }; +} + +/** Mutations made by the scrollbar itself must not schedule another layout pass. */ +function ownMutation(record: MutationRecord, slot: HTMLElement | undefined) { + return !!slot && (record.target === slot || slot.contains(record.target)) + || !!record.attributeName?.startsWith('data-overlayscrollbars'); +} function resolveTarget(content: HTMLElement, selector?: string) { if (selector === undefined) return { element: content }; @@ -42,13 +118,19 @@ export function previewScrollElement(content: HTMLElement) { return content.querySelector(`[${targetAttribute}]`) ?? content; } -function paintThumb(thumb: HTMLElement, track: ScrollBounds, scrollRange: number, offset: number, origin: ScrollbarOrigin) { +/** + * Positions the slot over the track. The drawn scrollbar fills the slot and + * moves its own handle, so the track only changes when the layout does. + * Returns true when the slot's containing block moves with the document, + * which means the track must be placed again after each document scroll. + */ +function placeTrack(slot: HTMLElement, track: ScrollBounds, scrollRange: number, origin: ScrollbarOrigin) { const trackHeight = track.bottom - track.top; - thumb.hidden = trackHeight <= 0 || track.right <= track.left || scrollRange <= 0; - if (thumb.hidden) return; + slot.hidden = trackHeight <= 0 || track.right <= track.left || scrollRange <= 0; + if (slot.hidden) return false; const fixed = 'viewportRight' in origin; - const parent = fixed ? thumb.offsetParent as HTMLElement | null : null; + const parent = fixed ? slot.offsetParent as HTMLElement | null : null; let originTop = fixed ? 0 : origin.top; let originRight = fixed ? origin.viewportRight : origin.right; if (parent) { @@ -57,40 +139,13 @@ function paintThumb(thumb: HTMLElement, track: ScrollBounds, scrollRange: number originTop = rect.top + (parent.clientTop - parent.scrollTop) * zoom; originRight = rect.left + (parent.clientLeft + parent.clientWidth - parent.scrollLeft) * zoom; } - // A fixed containing block can itself move with the document. In that - // case update its origin and the thumb's scroll progress in the same frame. - const rootTimeline = fixed && origin.rootTimeline === true && !parent; - thumb.toggleAttribute('data-stackflow-scrollbar-root', rootTimeline); - const clamped = Math.min(scrollRange, Math.max(0, offset)); - const normalHeight = Math.min(trackHeight, Math.max(12, trackHeight ** 2 / (trackHeight + scrollRange))); - const height = Math.max(Math.min(8, normalHeight), normalHeight - Math.abs(offset - clamped) / 2); - const travel = trackHeight - height; - const top = track.top - originTop; // Track geometry is in viewport pixels. CSS lengths are scaled again by - // the thumb's effective zoom, including when inherited from an ancestor. - const zoom = thumb.currentCSSZoom || 1; - thumb.style.height = `${height / zoom}px`; - thumb.style.right = `${(originRight - track.right) / zoom + 3}px`; - thumb.style.transform = `translateY(${(top + clamped / scrollRange * travel) / zoom}px)`; - if (rootTimeline) { - thumb.style.setProperty('--stackflow-scrollbar-start', `${top / zoom}px`); - thumb.style.setProperty('--stackflow-scrollbar-end', `${(top + travel) / zoom}px`); - } -} - -function scrollbarActivity(win: Window, thumb: HTMLElement) { - let timer: number | undefined; - return { - show() { - thumb.setAttribute('data-stackflow-scrolling', ''); - win.clearTimeout(timer); - timer = win.setTimeout(() => thumb.removeAttribute('data-stackflow-scrolling'), 450); - }, - reset() { - win.clearTimeout(timer); - thumb.removeAttribute('data-stackflow-scrolling'); - }, - }; + // the slot's effective zoom, including when inherited from an ancestor. + const zoom = slot.currentCSSZoom || 1; + slot.style.height = `${trackHeight / zoom}px`; + slot.style.right = `${(originRight - track.right) / zoom}px`; + slot.style.transform = `translateY(${(track.top - originTop) / zoom}px)`; + return !!parent; } function contentBox(element: HTMLElement, bounds: ScrollBounds, borderBox: boolean): ScrollBounds { @@ -118,7 +173,7 @@ function fitTrack(track: ScrollBounds, region: ScrollBounds, offset: number, ran } } -function paintElementScrollbar(thumb: HTMLElement, element: HTMLElement, +function placeElementTrack(slot: HTMLElement, element: HTMLElement, bounds: ScrollBounds, origin: ScrollbarOrigin = bounds, excludeChrome?: (track: ScrollBounds) => void, target?: HTMLElement) { const rect = element.getBoundingClientRect(); @@ -143,7 +198,7 @@ function paintElementScrollbar(thumb: HTMLElement, element: HTMLElement, if (target === element) fitTrack(track, contentBox(element, scrollport, false), 0, 0); else if (target) fitTrack(track, contentBox(target, target.getBoundingClientRect(), true), offset, range); excludeChrome?.(track); - paintThumb(thumb, track, range, offset, origin); + return placeTrack(slot, track, range, origin); } function visualBounds(content: HTMLElement): ScrollBounds { @@ -248,7 +303,8 @@ export function sizeWindowScrollSnapshot(snapshot: HTMLElement, bounds: DOMRect) } export function attachWindowScroll(content: HTMLElement, selector: string | undefined, - onScroll: (element: HTMLElement) => void, thumb: HTMLElement, fixedSelectors: readonly string[] = [], edgeBounce = false) { + onScroll: (element: HTMLElement) => void, slot: HTMLElement, fixedSelectors: readonly string[] = [], edgeBounce = false, + createScrollbar: OverlayScrollbarFactory = createOverlayScrollbar) { const doc = content.ownerDocument; const win = doc.defaultView!; const viewport = win.visualViewport; @@ -262,9 +318,11 @@ export function attachWindowScroll(content: HTMLElement, selector: string | unde let target = content; let dirty = true; let frame = 0; - const activity = scrollbarActivity(win, thumb); + // True while the slot's containing block moves with the document. + let followsDocument = false; + const scrollbars = overlays(slot, createScrollbar); const chrome = observeFixedChrome(content, fixedSelectors, schedule); - const bounce = edgeBounce ? attachEdgeBounce(content, thumb, hit => { + const bounce = edgeBounce ? attachEdgeBounce(content, slot, hit => { const scroller = nestedScroller?.contains(hit) ? nestedScroller : root; if (scroller !== root && root.scrollHeight > root.clientHeight && /^(auto|chain)$/.test(win.getComputedStyle(scroller).overscrollBehaviorY)) return; @@ -294,12 +352,10 @@ export function attachWindowScroll(content: HTMLElement, selector: string | unde if (nextScroller !== nestedScroller) { if (nestedScroller) { if (nestedScroller !== target) resize.unobserve(nestedScroller); + scrollbars.release(nestedScroller); nestedScroller.removeAttribute(nativeScrollbarAttribute); } - if (activeScroller === nestedScroller) { - activeScroller = root; - activity.reset(); - } + if (activeScroller === nestedScroller) activeScroller = root; nestedScroller = nextScroller; if (nestedScroller) { nestedScroller.setAttribute(nativeScrollbarAttribute, ''); @@ -314,8 +370,9 @@ export function attachWindowScroll(content: HTMLElement, selector: string | unde // scroller reaches its edge. Use the source that actually moved. const scroller = range > 0 ? activeScroller : nestedScroller ?? root; const viewportRight = doc.documentElement.clientWidth; + scrollbars.show(scroller, scroller === root); if (scroller !== root) { - paintElementScrollbar(thumb, scroller, viewportBounds, { viewportRight }, chrome.exclude, target); + followsDocument = placeElementTrack(slot, scroller, viewportBounds, { viewportRight }, chrome.exclude, target); return; } const rect = target.getBoundingClientRect(); @@ -326,33 +383,34 @@ export function attachWindowScroll(content: HTMLElement, selector: string | unde viewportBounds.right = Math.min(viewportBounds.right, region.right); } chrome.exclude(viewportBounds); - paintThumb(thumb, viewportBounds, range, win.scrollY, { viewportRight, rootTimeline: true }); + followsDocument = placeTrack(slot, viewportBounds, range, { viewportRight }); } function schedule() { if (!frame) frame = win.requestAnimationFrame(paint); } function scrolled(event: Event) { const documentEvent = event.target === doc || event.target === win; + const previous = activeScroller; if (documentEvent) { onScroll(root); if (win.scrollY !== rootOffset) { bounce?.clearEffect(); rootOffset = win.scrollY; activeScroller = root; - activity.show(); } } else if (nestedScroller && event.target === nestedScroller && nestedScroller.scrollTop !== nestedOffset) { bounce?.clearEffect(); nestedOffset = nestedScroller.scrollTop; activeScroller = nestedScroller; - activity.show(); } - if (documentEvent || event.target === nestedScroller) schedule(); + // The track is fixed to the layout. It only moves when the scroll source + // changes or the slot's containing block scrolls with the document. + if (activeScroller !== previous || (documentEvent && followsDocument)) schedule(); } function invalidate() { bounce?.clearEffect(); dirty = true; schedule(); } const unwatchVisibility = watchTargetVisibility(content, selector, invalidate); const resize = new win.ResizeObserver(invalidate); const mutation = new win.MutationObserver(records => { - if (records.some(record => record.target !== thumb && record.attributeName !== nativeScrollbarAttribute && + if (records.some(record => !ownMutation(record, slot) && record.attributeName !== nativeScrollbarAttribute && record.attributeName !== bounceScrollAttribute)) invalidate(); }); resize.observe(content); @@ -377,10 +435,9 @@ export function attachWindowScroll(content: HTMLElement, selector: string | unde viewport?.removeEventListener('resize', schedule); viewport?.removeEventListener('scroll', schedule); win.cancelAnimationFrame(frame); + scrollbars.dispose(); nestedScroller?.removeAttribute(nativeScrollbarAttribute); - activity.reset(); - thumb.removeAttribute('data-stackflow-scrollbar-root'); - thumb.hidden = true; + slot.hidden = true; }, }; } @@ -390,16 +447,17 @@ export function attachScrollViewport( selector: string | undefined, onScroll: (element: HTMLElement) => void, onTargetReady: (element: HTMLElement) => void, - thumb?: HTMLElement, + slot?: HTMLElement, fixedSelectors: readonly string[] = [], edgeBounce = false, + createScrollbar: OverlayScrollbarFactory = createOverlayScrollbar, ) { let element = content; element.addEventListener('scroll', scrolled, { passive: true }); const win = content.ownerDocument.defaultView!; - const activity = thumb && scrollbarActivity(win, thumb); - const chrome = thumb && observeFixedChrome(content, fixedSelectors, schedule); - const bounce = edgeBounce ? attachEdgeBounce(content, thumb, hit => { + const scrollbars = slot && overlays(slot, createScrollbar); + const chrome = slot && observeFixedChrome(content, fixedSelectors, schedule); + const bounce = edgeBounce ? attachEdgeBounce(content, slot, hit => { const scroller = getElement(); if (scroller.contains(hit) && !chrome?.isInside(scroller)) return { scroller, surface: scroller }; }) : undefined; @@ -418,9 +476,10 @@ export function attachScrollViewport( const previous = element; const current = getElement(); if (current !== previous && current !== content) onTargetReady(current); - if (thumb?.parentElement) { - const bounds = thumb.parentElement.getBoundingClientRect(); - paintElementScrollbar(thumb, current, bounds, bounds, chrome?.exclude, current === content ? undefined : current); + if (slot?.parentElement) { + scrollbars?.show(current, false); + const bounds = slot.parentElement.getBoundingClientRect(); + placeElementTrack(slot, current, bounds, bounds, chrome?.exclude, current === content ? undefined : current); } } @@ -428,14 +487,14 @@ export function attachScrollViewport( if (!frame) frame = win.requestAnimationFrame(refreshTarget); } + // The drawn scrollbar follows the scroller itself; the track only changes + // with the layout, which the observers below report. function scrolled() { onScroll(element); if (element.scrollTop !== previousOffset) { bounce?.clearEffect(); previousOffset = element.scrollTop; - activity?.show(); } - if (thumb) schedule(); } function invalidate() { @@ -448,7 +507,7 @@ export function attachScrollViewport( const unwatchVisibility = watchTargetVisibility(content, selector, invalidate); const resize = new win.ResizeObserver(invalidate); const mutation = new win.MutationObserver(records => { - if (records.some(record => record.target !== thumb && + if (records.some(record => !ownMutation(record, slot) && record.attributeName !== targetAttribute && record.attributeName !== delegatedAttribute && record.attributeName !== bounceScrollAttribute)) invalidate(); }); @@ -463,20 +522,20 @@ export function attachScrollViewport( } if (next !== element) { element.removeEventListener('scroll', scrolled); + scrollbars?.release(element); if (element !== content) { resize.unobserve(element); element.removeAttribute(targetAttribute); } element = next; previousOffset = element.scrollTop; - activity?.reset(); content.toggleAttribute(delegatedAttribute, element !== content); if (element !== content) { element.setAttribute(targetAttribute, ''); resize.observe(element); } element.addEventListener('scroll', scrolled, { passive: true }); - if (thumb) schedule(); + if (slot) schedule(); } return element; } @@ -486,7 +545,7 @@ export function attachScrollViewport( content.addEventListener('load', invalidate, true); win.addEventListener('resize', invalidate); getElement(); - if (thumb) schedule(); + if (slot) schedule(); return { getElement, dispose() { @@ -495,14 +554,14 @@ export function attachScrollViewport( mutation.disconnect(); resize.disconnect(); chrome?.dispose(); + scrollbars?.dispose(); element.removeEventListener('scroll', scrolled); if (element !== content) element.removeAttribute(targetAttribute); content.removeAttribute(delegatedAttribute); content.removeEventListener('load', invalidate, true); win.removeEventListener('resize', invalidate); win.cancelAnimationFrame(frame); - activity?.reset(); - if (thumb) thumb.hidden = true; + if (slot) slot.hidden = true; }, }; } diff --git a/src/next/style.css b/src/next/style.css index d4c1c2a..3ff17f2 100644 --- a/src/next/style.css +++ b/src/next/style.css @@ -12,25 +12,21 @@ html[data-stackflow-animating] .stackflow-next-content:not([data-stackflow-slide .stackflow-next-content,[data-stackflow-scroll-target],[data-stackflow-native-scrollbar-hidden]{scrollbar-width:none} .stackflow-next-content::-webkit-scrollbar,[data-stackflow-scroll-target]::-webkit-scrollbar,[data-stackflow-native-scrollbar-hidden]::-webkit-scrollbar{display:none} .stackflow-next-content[data-stackflow-scroll-delegated]{overflow:clip} -.stackflow-next-scrollbar{ - position:absolute;top:0;right:3px;width:3px;z-index:3;border-radius:3px; - pointer-events:none;opacity:0;transition:opacity 180ms ease-out -} -.stackflow-next-scrollbar-thumb{ - width:100%;height:100%;border-radius:inherit; - background:var(--stackflow-scrollbar-color,color-mix(in srgb, CanvasText 36%, transparent)) -} -.stackflow-next-scrollbar:is([data-stackflow-scrolling],[data-stackflow-bouncing]){opacity:1;transition:none} -@media(prefers-reduced-motion:reduce){.stackflow-next-scrollbar{transition:none}} -@supports (animation-timeline:scroll(root y)) { - .stackflow-next-scrollbar[data-stackflow-scrollbar-root]{ - animation:stackflow-scrollbar-position linear both;animation-duration:auto;animation-timeline:scroll(root y) - } - @keyframes stackflow-scrollbar-position{ - from{transform:translateY(var(--stackflow-scrollbar-start))} - to{transform:translateY(var(--stackflow-scrollbar-end))} - } +/* The slot is the track box. OverlayScrollbars draws the handle inside it. */ +.stackflow-next-scrollbar{position:absolute;top:0;right:0;width:10px;z-index:3;pointer-events:none} +.stackflow-next-scrollbar > .os-scrollbar-vertical{top:0;right:0;bottom:0;height:auto} +.stackflow-next-scrollbar > .os-scrollbar-horizontal{display:none} +.os-theme-stackflow{ + box-sizing:border-box; + --os-size:10px;--os-padding-perpendicular:3px;--os-padding-axis:0px; + --os-track-border-radius:3px;--os-handle-border-radius:3px;--os-handle-min-size:24px; + --os-handle-interactive-area-offset:4px; + --os-handle-bg:var(--stackflow-scrollbar-color,color-mix(in srgb, CanvasText 36%, transparent)); + --os-handle-bg-hover:var(--stackflow-scrollbar-active-color,color-mix(in srgb, CanvasText 50%, transparent)); + --os-handle-bg-active:var(--stackflow-scrollbar-active-color,color-mix(in srgb, CanvasText 58%, transparent)) } +.stackflow-next-scrollbar[data-stackflow-bouncing] > .os-scrollbar{opacity:1;visibility:visible;transition:none} +@media(prefers-reduced-motion:reduce){.stackflow-next-scrollbar > .os-scrollbar{transition:none}} .stackflow-next-scrollbar[hidden], html[data-stackflow-animating] .stackflow-next-scrollbar, .stackflow-next-content:is([data-stackflow-slide-staged],[data-stackflow-slide-incoming]) ~ .stackflow-next-scrollbar{display:none} diff --git a/test/next/scroll.test.ts b/test/next/scroll.test.ts index 4c37549..b909da8 100644 --- a/test/next/scroll.test.ts +++ b/test/next/scroll.test.ts @@ -1,7 +1,25 @@ import { test } from 'node:test'; import assert from 'node:assert/strict'; import { Window } from 'happy-dom'; -import { attachScrollViewport, attachWindowScroll } from '../../src/next/scroll.ts'; +import { attachScrollViewport, attachWindowScroll, type OverlayScrollbarFactory } from '../../src/next/scroll.ts'; + +// Records how the provider drives the drawn scrollbars without loading OverlayScrollbars. +function recordScrollbars() { + const log: string[] = []; + const created: { scroller: HTMLElement; root: boolean; active: boolean; disposed: boolean }[] = []; + const factory: OverlayScrollbarFactory = (scroller, root, slot) => { + const entry = { scroller, root, active: false, disposed: false }; + created.push(entry); + log.push(`create:${root ? 'document' : scroller.tagName.toLowerCase()}:${slot.className || 'slot'}`); + return { + setActive(active) { entry.active = active; }, + dispose() { entry.disposed = true; }, + }; + }; + return { factory, created, log }; +} + +const translateY = (element: HTMLElement) => parseFloat(element.style.transform.slice('translateY('.length)); test('only the visible target scrolls and a second visible match restores the default', t => { const win = new Window(); @@ -42,7 +60,7 @@ test('only the visible target scrolls and a second visible match restores the de assert.equal(target.hasAttribute('data-stackflow-scroll-target'), false); }); -test('the window scrollbar uses the target content box up to both native scroll endpoints', t => { +test('the window track spans the target content box between both native scroll endpoints', t => { const win = new Window(); const root = win.document.documentElement; Object.defineProperties(root, { @@ -52,13 +70,14 @@ test('the window scrollbar uses the target content box up to both native scroll let offset = 0; Object.defineProperty(win, 'scrollY', { get: () => offset }); let paint: FrameRequestCallback; - t.mock.method(win, 'requestAnimationFrame', (callback: FrameRequestCallback) => { paint = callback; return 1; }); + let scheduled = 0; + t.mock.method(win, 'requestAnimationFrame', (callback: FrameRequestCallback) => { paint = callback; scheduled++; return 1; }); win.document.body.innerHTML = `
`; const content = win.document.querySelector('.stackflow-next-content')! as unknown as HTMLElement; - const thumb = content.nextElementSibling as HTMLElement; + const slot = content.nextElementSibling as HTMLElement; const main = content.querySelector('main')!; t.mock.method(main, 'getClientRects', () => ({ length: 1 })); // The target's rect already leaves out its margins. @@ -66,74 +85,64 @@ test('the window scrollbar uses the target content box up to both native scroll const start = 90 + 16 + 2; const end = 90 + 1540 - 1200 - 24 - 2; const railHeight = end - start; + const { factory, created } = recordScrollbars(); const scrolled: HTMLElement[] = []; - const controller = attachWindowScroll(content, 'main', element => scrolled.push(element), thumb); + const controller = attachWindowScroll(content, 'main', element => scrolled.push(element), slot, [], false, factory); try { - const thumbTop = () => parseFloat(thumb.style.transform.slice('translateY('.length)); - const updateOffset = (next: number) => { + const scroll = (next: number) => { offset = next; win.dispatchEvent(new win.Event('scroll')); - paint!(0); }; paint!(0); - const size = parseFloat(thumb.style.height); assert.equal(controller.getElement(), root); - assert.equal(thumb.hidden, false); - assert.equal(thumb.style.right, '33px'); - assert.equal(thumbTop(), start); - assert.equal(thumb.hasAttribute('data-stackflow-scrolling'), false); - assert.ok(Math.abs(size - railHeight ** 2 / (railHeight + 1200)) < 0.001); - - updateOffset(0.5); - assert.ok(thumbTop() > start); - assert.equal(thumb.hasAttribute('data-stackflow-scrolling'), true); + assert.equal(slot.hidden, false); + assert.equal(slot.getAttribute('data-stackflow-scroll-source'), 'document'); + assert.equal(created.length, 1); + assert.equal(created[0].root, true); + assert.equal(created[0].active, true); + assert.equal(slot.style.right, '30px'); + assert.equal(translateY(slot), start); + assert.equal(parseFloat(slot.style.height), railHeight); - updateOffset(600); - assert.equal(parseFloat(thumb.style.height), size); - assert.ok(Math.abs(thumbTop() - (start + (railHeight - size) / 2)) < 0.001); - - updateOffset(1199.5); - assert.equal(parseFloat(thumb.style.height), size); - assert.ok(thumbTop() + size < end); - - updateOffset(1200); - assert.ok(Math.abs(thumbTop() + size - end) < 0.001); - - for (const edge of [-60, 1260]) { - updateOffset(edge); - const height = parseFloat(thumb.style.height); - assert.ok(height < size); - assert.ok(Math.abs(thumbTop() - (edge < 0 ? start : end - height)) < 0.001); - } - assert.deepEqual(scrolled, [root, root, root, root, root, root]); + // The drawn scrollbar moves its own handle. Document scrolling does not + // schedule another layout pass while the track stays where it is. + const before = scheduled; + for (const next of [0.5, 600, 1200, -60, 1260]) scroll(next); + assert.equal(scheduled, before); + paint!(0); + assert.equal(translateY(slot), start); + assert.equal(parseFloat(slot.style.height), railHeight); + assert.deepEqual(scrolled, [root, root, root, root, root]); const zoom = 1.17; - Object.defineProperty(thumb, 'currentCSSZoom', { value: zoom }); - updateOffset(1199.5); - assert.ok((thumbTop() + parseFloat(thumb.style.height)) * zoom < end); - updateOffset(1200); - const cssEnd = parseFloat(thumb.style.getPropertyValue('--stackflow-scrollbar-end')); - const zoomedHeight = parseFloat(thumb.style.height); - assert.ok(Math.abs((thumbTop() + zoomedHeight) * zoom - end) < 0.001); - assert.ok(Math.abs((cssEnd + zoomedHeight) * zoom - end) < 0.001); + Object.defineProperty(slot, 'currentCSSZoom', { value: zoom }); + paint!(0); + assert.ok(Math.abs(parseFloat(slot.style.height) * zoom - railHeight) < 0.001); + assert.ok(Math.abs(translateY(slot) * zoom - start) < 0.001); + // A fixed containing block that scrolls with the document moves the + // track, so document scrolling schedules a new placement. const shell = content.parentElement!; Object.defineProperties(shell, { clientWidth: { value: 376 }, clientLeft: { value: 0 }, clientTop: { value: 0 } }); - Object.defineProperty(thumb, 'offsetParent', { value: shell }); + Object.defineProperty(slot, 'offsetParent', { value: shell }); t.mock.method(shell, 'getBoundingClientRect', () => new win.DOMRect(12, 21 - offset, 376, 1900)); - updateOffset(600); - assert.equal(thumb.hasAttribute('data-stackflow-scrollbar-root'), false); - assert.ok(Math.abs(thumbTop() * zoom + 21 - offset - (start + (railHeight - size) / 2)) < 0.001); - assert.ok(Math.abs(388 - parseFloat(thumb.style.right) * zoom - (370 - 3 * zoom)) < 0.001); + paint!(0); + const placed = scheduled; + scroll(600); + assert.equal(scheduled, placed + 1); + paint!(0); + assert.ok(Math.abs(translateY(slot) * zoom + 21 - offset - start) < 0.001); + assert.ok(Math.abs(parseFloat(slot.style.right) * zoom - (388 - 370)) < 0.001); } finally { controller.dispose(); } - assert.equal(thumb.hidden, true); - assert.equal(thumb.hasAttribute('data-stackflow-scrolling'), false); + assert.equal(slot.hidden, true); + assert.equal(slot.hasAttribute('data-stackflow-scroll-source'), false); + assert.equal(created[0].disposed, true); }); -test('the scrollbar follows the document after the inner scroller reaches its edge', t => { +test('the active scrollbar follows the document after the inner scroller reaches its edge', t => { const win = new Window(); const root = win.document.documentElement; Object.defineProperties(root, { @@ -149,7 +158,7 @@ test('the scrollbar follows the document after the inner scroller reaches its ed
`; const content = win.document.querySelector('.stackflow-next-content')! as unknown as HTMLElement; - const thumb = content.nextElementSibling as HTMLElement; + const slot = content.nextElementSibling as HTMLElement; const inner = win.document.querySelector('main')!; Object.defineProperties(inner, { clientHeight: { value: 400 }, clientWidth: { value: 400 }, scrollHeight: { value: 1600 }, @@ -158,52 +167,48 @@ test('the scrollbar follows the document after the inner scroller reaches its ed t.mock.method(inner, 'getBoundingClientRect', () => new win.DOMRect(0, 270 - offset, 400, 400)); t.mock.method(win.document.querySelector('header')!, 'getBoundingClientRect', () => new win.DOMRect(0, 0, 400, 50)); t.mock.method(win.document.querySelector('footer')!, 'getBoundingClientRect', () => new win.DOMRect(0, 550, 400, 50)); + const { factory, created } = recordScrollbars(); + const source = () => slot.getAttribute('data-stackflow-scroll-source'); + const active = () => created.filter(entry => entry.active).map(entry => entry.root ? 'document' : 'main'); - const controller = attachWindowScroll(content, 'main', () => {}, thumb); + const controller = attachWindowScroll(content, 'main', () => {}, slot, [], false, factory); try { paint!(0); - const usesDocument = () => thumb.hasAttribute('data-stackflow-scrollbar-root'); - const thumbTop = () => parseFloat(thumb.style.transform.slice('translateY('.length)); - const thumbHeight = () => parseFloat(thumb.style.height); - assert.equal(usesDocument(), true); - assert.equal(thumb.hasAttribute('data-stackflow-scrolling'), false); + assert.equal(source(), 'document'); + assert.deepEqual(active(), ['document']); + assert.equal(inner.hasAttribute('data-stackflow-native-scrollbar-hidden'), true); + assert.equal(translateY(slot), 50); + assert.equal(parseFloat(slot.style.height), 500); inner.scrollTop = 1200; inner.dispatchEvent(new win.Event('scroll')); paint!(0); - assert.equal(usesDocument(), false); - assert.ok(Math.abs(thumbHeight() - 280 ** 2 / 1480) < 0.001); - assert.ok(Math.abs(thumbTop() + thumbHeight() - 550) < 0.001); + assert.equal(source(), 'element'); + assert.deepEqual(active(), ['main']); + assert.equal(translateY(slot), 270); + assert.equal(parseFloat(slot.style.height), 280); offset = 1200; win.dispatchEvent(new win.Event('scroll')); paint!(0); - assert.equal(usesDocument(), true); - assert.ok(Math.abs(thumbTop() + thumbHeight() - 550) < 0.001); - - offset = 1199; - win.dispatchEvent(new win.Event('scroll')); - paint!(0); - assert.ok(thumbTop() + thumbHeight() < 550); - - offset = 100; - win.dispatchEvent(new win.Event('scroll')); - inner.dispatchEvent(new win.Event('scroll')); - paint!(0); - assert.equal(usesDocument(), true); + assert.equal(source(), 'document'); + assert.deepEqual(active(), ['document']); + assert.equal(translateY(slot), 50); inner.scrollTop = 1199; inner.dispatchEvent(new win.Event('scroll')); paint!(0); - assert.equal(usesDocument(), false); - assert.ok(thumbTop() + thumbHeight() < 550); + assert.equal(source(), 'element'); + assert.equal(created.length, 2); } finally { controller.dispose(); } + assert.ok(created.every(entry => entry.disposed)); + assert.equal(inner.hasAttribute('data-stackflow-native-scrollbar-hidden'), false); }); for (const mode of ['window', 'container']) { - test(`the ${mode} scrollbar stays between fixed bars for its entire travel`, t => { + test(`the ${mode} track stays between fixed bars`, t => { const win = new Window(); const root = win.document.documentElement; Object.defineProperties(root, { @@ -223,7 +228,7 @@ for (const mode of ['window', 'container']) { `; const content = win.document.querySelector('.stackflow-next-content')! as unknown as HTMLElement; - const thumb = content.nextElementSibling as HTMLElement; + const slot = content.nextElementSibling as HTMLElement; const target = content.querySelector('main')!; Object.defineProperties(target, { clientHeight: { value: 664 }, clientWidth: { value: 346 }, scrollHeight: { value: 3203 }, @@ -235,10 +240,11 @@ for (const mode of ['window', 'container']) { t.mock.method(win.document.querySelector('#top')!, 'getBoundingClientRect', () => new win.DOMRect(0, 0, 390, 79)); t.mock.method(win.document.querySelector('#bottom')!, 'getBoundingClientRect', () => new win.DOMRect(0, 561, 390, 103)); t.mock.method(content.parentElement!, 'getBoundingClientRect', () => new win.DOMRect(0, 0, 390, 664)); + const { factory, created } = recordScrollbars(); const controller = mode === 'window' - ? attachWindowScroll(content, 'main', () => {}, thumb, ['#bottom']) - : attachScrollViewport(content, 'main', () => {}, () => {}, thumb, ['#bottom']); + ? attachWindowScroll(content, 'main', () => {}, slot, ['#bottom'], false, factory) + : attachScrollViewport(content, 'main', () => {}, () => {}, slot, ['#bottom'], false, factory); try { for (const next of [0, 1, 2499, 2539, 2499, 0]) { offset = next; @@ -246,16 +252,17 @@ for (const mode of ['window', 'container']) { if (mode === 'window') win.dispatchEvent(new win.Event('scroll')); else target.dispatchEvent(new win.Event('scroll') as unknown as Event); paint!(0); - const expectedHeight = 482 ** 2 / (482 + 2539); - const height = parseFloat(thumb.style.height); - const top = parseFloat(thumb.style.transform.slice('translateY('.length)); - assert.equal(thumb.hidden, false); - assert.equal(thumb.style.right, '25px'); - assert.ok(Math.abs(height - expectedHeight) < 0.001); - assert.ok(Math.abs(top - (79 + (482 - height) * next / 2539)) < 0.001); + assert.equal(slot.hidden, false); + assert.equal(slot.style.right, '22px'); + assert.equal(translateY(slot), 79); + assert.equal(parseFloat(slot.style.height), 482); } + assert.equal(created.length, 1); + assert.equal(created[0].root, mode === 'window'); + assert.equal(created[0].active, true); } finally { controller.dispose(); } + assert.equal(created[0].disposed, true); }); }