From 20ee33878e9a80d0576163022c2c3e91a98a2f1c Mon Sep 17 00:00:00 2001 From: Karolis Strazdas Date: Mon, 23 Nov 2026 01:01:25 +0200 Subject: [PATCH 1/2] fix: add resistance to PDF wheel page turns --- docs/ARCHITECTURE.md | 20 +- lib/src/engine/pdf/pdf_facade.dart | 4 + lib/src/presentation/papyrus_reader.dart | 192 ++++--- .../presentation/reader_chrome_insets.dart | 23 + lib/src/presentation/reader_page_wheel.dart | 354 ++++++++++-- test/presentation/papyrus_reader_test.dart | 94 ++++ test/presentation/pdf_tools_test.dart | 67 ++- test/presentation/reader_page_wheel_test.dart | 514 ++++++++++++++++++ tool/browser/formats.mjs | 20 +- tool/browser/pdf_swipes.mjs | 24 +- tool/browser/smoke.mjs | 14 +- 11 files changed, 1198 insertions(+), 128 deletions(-) create mode 100644 lib/src/presentation/reader_chrome_insets.dart diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index e9787c8..f596e05 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -106,13 +106,21 @@ In paginated text formats, mouse drags starting in blank space, including the outer window margins, turn pages; drags starting on rendered text remain selection gestures. Mouse turns use the same page controller as touch and can interrupt an unfinished turn. -Wheel input turns paginated pages immediately without changing the animation -preference. Small nonzero deltas count as a turn; same-direction bursts are -limited to one turn per 120 ms, while reversing direction responds immediately. +Wheel input turns paginated text pages immediately: small nonzero deltas count +as a turn, same-direction bursts are limited to one turn per 120 ms, and reversing +direction responds immediately. Paginated PDFs, including converted comic archives, +accumulate scroll distance before turning, with an axis lock to tolerate diagonal +touchpad drift. Resistance feedback +persists between samples, uses theme colors, and clears the measured top and bottom +controls without resizing the viewport. It is hidden when page-turn animation or +system motion is disabled. Continued deliberate input can build one subsequent +turn while navigation completes. After a turn, a decaying wheel tail is consumed; +a fresh impulse, direction change, or quiet gap releases the momentum filter. +This is a heuristic because browser wheel events do not identify momentum phases. Zoomed PDFs pan within the current spread; scrolling outward at its top or bottom -turns the page without animation. Forward turns open at the top, backward turns -at the bottom, preserving zoom. Horizontal zoomed panning, continuous readers, -and modifier-key zoom retain native wheel input. +builds resistance before turning without animation. Forward turns open at the top, +backward turns at the bottom, preserving zoom. Horizontal zoomed panning, +continuous readers, and modifier-key zoom retain native wheel input. Continuous EPUB uses a full-width scroll surface with centered text and a viewport-edge scrollbar. Its chunk extents use the rendered fragment heights, including text reshaping at paragraph cuts. Outward wheel input at a chapter edge opens the adjacent chapter; diff --git a/lib/src/engine/pdf/pdf_facade.dart b/lib/src/engine/pdf/pdf_facade.dart index cc0810c..3bf3a73 100644 --- a/lib/src/engine/pdf/pdf_facade.dart +++ b/lib/src/engine/pdf/pdf_facade.dart @@ -1054,6 +1054,10 @@ final class _PdfrxFacade extends PdfReaderTools final pages = _pagesController; return ReaderPageWheel( + resistance: configuration.layoutMode == ReaderLayoutMode.paginated, + showResistance: + configuration.pageTurnAnimation && + !MediaQuery.disableAnimationsOf(context), canTurn: _canTurnWithWheel, onTurn: (direction) => _turnSpread(direction, fromWheel: true), child: applyPdfBrightness( diff --git a/lib/src/presentation/papyrus_reader.dart b/lib/src/presentation/papyrus_reader.dart index d2292f1..37e1563 100644 --- a/lib/src/presentation/papyrus_reader.dart +++ b/lib/src/presentation/papyrus_reader.dart @@ -18,6 +18,7 @@ import '../domain/reader_types.dart'; import '../engine/reader_engine_registry.dart'; import 'reader_material_theme.dart'; import 'reader_controls.dart'; +import 'reader_chrome_insets.dart'; import 'reader_pdf_search_panel.dart'; import 'reader_surface.dart'; import 'reader_contents_panel.dart'; @@ -82,6 +83,10 @@ final class _PapyrusReaderState extends State { bool _hasReadableContent = false; _ReaderPanel _panel = _ReaderPanel.none; bool _controlsVisible = false; + final GlobalKey _toolbarBounds = GlobalKey(); + final GlobalKey _progressBounds = GlobalKey(); + EdgeInsets _chromeInsets = EdgeInsets.zero; + bool _chromeMeasurementScheduled = false; double? _dragProgress; bool _draggingProgress = false; int _seekRevision = 0; @@ -645,6 +650,7 @@ final class _PapyrusReaderState extends State { ) { return LayoutBuilder( builder: (context, constraints) { + _scheduleChromeMeasurement(); final isWide = constraints.maxWidth >= theme.compactBreakpoint; final compactPdf = _controller.pdfTools != null && @@ -684,45 +690,53 @@ final class _PapyrusReaderState extends State { key: const ValueKey('reader-content'), child: FocusTraversalOrder( order: const NumericFocusOrder(3), - child: _readingSurface(context, snapshot, isWide), + child: ReaderChromeInsets( + insets: _controlsVisible + ? _chromeInsets + : EdgeInsets.zero, + child: _readingSurface(context, snapshot, isWide), + ), ), ), PositionedDirectional( bottom: 0, start: 0, end: 0, - child: _chromeVisibility( - child: _overlayBar( - theme, - Center( - child: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: 1000), - child: FocusTraversalOrder( - key: const ValueKey('reader-progress-controls'), - order: const NumericFocusOrder(4), - child: ReaderProgressControls( - progress: - _dragProgress ?? - _progressOf(snapshot.locator), - locationLabel: _controller.pdfTools == null - ? snapshot.locationLabel - : null, - onProgressChangeStart: _startProgressDrag, - onProgressChanged: (value) => setState(() { - _draggingProgress = true; - _dragProgress = value; - }), - onProgressChangeEnd: _goToProgress, - onPrevious: _goPrevious, - onNext: _goNext, - enabled: true, - theme: theme, + child: _measuredChrome( + _progressBounds, + _chromeVisibility( + child: _overlayBar( + theme, + Center( + child: ConstrainedBox( + constraints: const BoxConstraints(maxWidth: 1000), + child: FocusTraversalOrder( + key: const ValueKey('reader-progress-controls'), + order: const NumericFocusOrder(4), + child: ReaderProgressControls( + progress: + _dragProgress ?? + _progressOf(snapshot.locator), + locationLabel: _controller.pdfTools == null + ? snapshot.locationLabel + : null, + onProgressChangeStart: _startProgressDrag, + onProgressChanged: (value) => setState(() { + _draggingProgress = true; + _dragProgress = value; + }), + onProgressChangeEnd: _goToProgress, + onPrevious: _goPrevious, + onNext: _goNext, + enabled: true, + theme: theme, + ), ), ), ), - ), - border: Border( - top: BorderSide(color: theme.dividerColor), + border: Border( + top: BorderSide(color: theme.dividerColor), + ), ), ), ), @@ -730,50 +744,55 @@ final class _PapyrusReaderState extends State { Positioned.fill( child: Column( children: [ - _chromeVisibility( - child: FocusTraversalOrder( - key: const ValueKey('reader-toolbar'), - order: const NumericFocusOrder(1), - child: _overlayBar( - theme, - Column( - mainAxisSize: MainAxisSize.min, - children: [ - toolbar ?? - ReaderToolbar( - document: widget.document, - actions: actions, - pdfTools: _controller.pdfTools, - compactPdf: compactPdf, - onSearch: _openPdfSearch, - onBack: widget.onBack, - onTableOfContents: () => _openPanel( - context, - _ReaderPanel.tableOfContents, - isWide, - theme, + _measuredChrome( + _toolbarBounds, + _chromeVisibility( + child: FocusTraversalOrder( + key: const ValueKey('reader-toolbar'), + order: const NumericFocusOrder(1), + child: _overlayBar( + theme, + Column( + mainAxisSize: MainAxisSize.min, + children: [ + toolbar ?? + ReaderToolbar( + document: widget.document, + actions: actions, + pdfTools: _controller.pdfTools, + compactPdf: compactPdf, + onSearch: _openPdfSearch, + onBack: widget.onBack, + onTableOfContents: () => _openPanel( + context, + _ReaderPanel.tableOfContents, + isWide, + theme, + ), + onSettings: () => _openPanel( + context, + _ReaderPanel.settings, + isWide, + theme, + ), + tocFocusNode: _tocButtonFocusNode, + settingsFocusNode: + _settingsButtonFocusNode, + theme: theme, + isWide: isWide, ), - onSettings: () => _openPanel( - context, - _ReaderPanel.settings, - isWide, - theme, + if (_showBusy) + const LinearProgressIndicator( + key: ValueKey( + 'reader-command-progress', ), - tocFocusNode: _tocButtonFocusNode, - settingsFocusNode: - _settingsButtonFocusNode, - theme: theme, - isWide: isWide, + minHeight: 2, ), - if (_showBusy) - const LinearProgressIndicator( - key: ValueKey('reader-command-progress'), - minHeight: 2, - ), - ], - ), - border: Border( - bottom: BorderSide(color: theme.dividerColor), + ], + ), + border: Border( + bottom: BorderSide(color: theme.dividerColor), + ), ), ), ), @@ -860,6 +879,37 @@ final class _PapyrusReaderState extends State { ); } + void _scheduleChromeMeasurement() { + if (_chromeMeasurementScheduled) return; + + _chromeMeasurementScheduled = true; + WidgetsBinding.instance.addPostFrameCallback((_) { + _chromeMeasurementScheduled = false; + + if (!mounted) return; + + final insets = _controlsVisible + ? EdgeInsets.only( + top: _toolbarBounds.currentContext?.size?.height ?? 0, + bottom: _progressBounds.currentContext?.size?.height ?? 0, + ) + : EdgeInsets.zero; + + if (insets != _chromeInsets) { + setState(() => _chromeInsets = insets); + } + }); + } + + Widget _measuredChrome(GlobalKey key, Widget child) => + NotificationListener( + onNotification: (_) { + _scheduleChromeMeasurement(); + return false; + }, + child: SizeChangedLayoutNotifier(key: key, child: child), + ); + Widget _chromeVisibility({required Widget child}) => Visibility( visible: _controlsVisible, maintainState: true, diff --git a/lib/src/presentation/reader_chrome_insets.dart b/lib/src/presentation/reader_chrome_insets.dart new file mode 100644 index 0000000..c88559d --- /dev/null +++ b/lib/src/presentation/reader_chrome_insets.dart @@ -0,0 +1,23 @@ +import 'package:flutter/widgets.dart'; + +/// Space obscured by reader controls, for feedback that overlays the viewport. +/// Reading content keeps its full size when the controls appear. +final class ReaderChromeInsets extends InheritedWidget { + const ReaderChromeInsets({ + required this.insets, + required super.child, + super.key, + }); + + final EdgeInsets insets; + + static EdgeInsets of(BuildContext context) => + context + .dependOnInheritedWidgetOfExactType() + ?.insets ?? + EdgeInsets.zero; + + @override + bool updateShouldNotify(ReaderChromeInsets oldWidget) => + insets != oldWidget.insets; +} diff --git a/lib/src/presentation/reader_page_wheel.dart b/lib/src/presentation/reader_page_wheel.dart index 56f34bd..449be50 100644 --- a/lib/src/presentation/reader_page_wheel.dart +++ b/lib/src/presentation/reader_page_wheel.dart @@ -1,10 +1,12 @@ import 'dart:async'; +import 'dart:math' as math; import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; -import 'package:flutter/widgets.dart'; import '../domain/reader_exception.dart'; +import 'reader_chrome_insets.dart'; /// Claims page-turn wheel signals before nested scrolling or PDF panning. final class ReaderPageWheel extends StatefulWidget { @@ -12,12 +14,16 @@ final class ReaderPageWheel extends StatefulWidget { required this.canTurn, required this.onTurn, required this.child, + this.resistance = false, + this.showResistance = true, super.key, }); final bool Function(Offset delta) canTurn; final Future Function(int direction) onTurn; final Widget child; + final bool resistance; + final bool showResistance; @override State createState() => _ReaderPageWheelState(); @@ -27,68 +33,336 @@ final class _ReaderPageWheelState extends State { Timer? _cooldown; int? _direction; Future _pending = Future.value(); + static const _threshold = 640.0; + static const _axisLockDistance = 8.0; + static const _feedbackHold = Duration(milliseconds: 900); + static const _feedbackFade = Duration(milliseconds: 220); + static const _tailGap = Duration(milliseconds: 180); + Timer? _gestureEnd; + Timer? _tailEnd; + int? _tailDirection; + bool _tailHorizontal = false; + bool _suppressTail = false; + double _tailMagnitude = 0; + double _tailFloor = 0; + int _tailDeclines = 0; + double _distance = 0; + double _displayProgress = 0; + bool _feedbackVisible = false; + bool _turning = false; + bool _horizontal = false; + Offset? _lastDelta; + Offset _axisIntent = Offset.zero; + + void _clearTail() { + _tailEnd?.cancel(); + _tailDirection = null; + _suppressTail = false; + } + + void _armTail(int direction, Offset delta) { + _tailDirection = direction; + _tailHorizontal = delta.dx.abs() > delta.dy.abs(); + _tailMagnitude = _tailHorizontal ? delta.dx.abs() : delta.dy.abs(); + _tailFloor = _tailMagnitude; + _tailDeclines = 0; + _suppressTail = false; + _tailEnd?.cancel(); + _tailEnd = Timer(_tailGap, _clearTail); + } + + bool _consumeTail(Offset delta) { + final direction = _tailDirection; + + if (!widget.resistance || direction == null) return false; + + final movement = _tailHorizontal ? delta.dx : delta.dy; + final crossMovement = _tailHorizontal ? delta.dy : delta.dx; + final magnitude = movement.abs(); + final reversed = movement != 0 && (movement > 0 ? 1 : -1) != direction; + final changedAxis = crossMovement.abs() > math.max(8, magnitude * 2); + final reference = _suppressTail ? _tailFloor : _tailMagnitude; + final accelerated = magnitude > reference + math.max(4, reference * .5); + + // Browsers do not label momentum events. A renewed impulse or direction + // change releases the tail immediately; a quiet gap also starts fresh input. + if (reversed || changedAxis || accelerated) { + _clearTail(); + + if (changedAxis) { + _resetResistance(); + } + + return false; + } + + final axisDelta = _tailHorizontal + ? Offset(movement, 0) + : Offset(0, movement); + _tailDeclines = magnitude < _tailMagnitude - .01 ? _tailDeclines + 1 : 0; + _suppressTail = + _suppressTail || + _tailDeclines >= 2 || + (!_turning && !widget.canTurn(axisDelta)); + _tailFloor = _suppressTail ? math.min(_tailFloor, magnitude) : magnitude; + _tailMagnitude = magnitude; + _tailEnd?.cancel(); + _tailEnd = Timer(_tailGap, _clearTail); + + if (_suppressTail) { + _distance = 0; + } + + return _suppressTail; + } + + void _resetResistance() { + _gestureEnd?.cancel(); + _distance = 0; + _lastDelta = null; + _axisIntent = Offset.zero; + + if (_feedbackVisible) { + setState(() => _feedbackVisible = false); + } + } + + void _accumulate(Offset offset, double delta) { + _gestureEnd?.cancel(); + _gestureEnd = Timer(_feedbackHold, _resetResistance); + final direction = delta > 0 ? 1 : -1; + final horizontal = offset.dx.abs() > offset.dy.abs(); + final distance = delta.abs(); + + if (_distance == 0 || horizontal != _horizontal) { + _direction = direction; + _horizontal = horizontal; + _distance = 0; + } + + // Small reverse samples unwind pressure rather than flickering between edges. + if (direction != _direction) { + _distance -= distance; + + if (_distance < 0) { + _direction = direction; + _distance = (-_distance).clamp(0, _threshold); + } + } else { + _distance = (_distance + distance).clamp(0, _threshold); + } + + _lastDelta = offset; + setState(() { + _feedbackVisible = true; + _displayProgress = _distance / _threshold; + }); + _turnIfReady(); + } + + void _turnIfReady() { + final delta = _lastDelta; + + if (!mounted || + !widget.resistance || + _turning || + _distance < _threshold || + delta == null || + !widget.canTurn(delta)) { + return; + } + + _distance = 0; + _armTail(_direction!, delta); + _queueTurn(_direction!, delta); + } + + void _queueTurn(int direction, Offset delta) { + _turning = true; + _pending = _pending + .then((_) async { + if (mounted && widget.canTurn(delta)) { + await widget.onTurn(direction); + } + }) + .catchError((Object error, StackTrace stack) { + if (error is ReaderException && + error.code == ReaderErrorCode.navigationBoundary) { + return; + } + + FlutterError.reportError( + FlutterErrorDetails( + exception: error, + stack: stack, + library: 'papyrus_reader', + context: ErrorDescription( + 'while turning a page with the scroll wheel', + ), + ), + ); + }) + .whenComplete(() { + _turning = false; + _turnIfReady(); + }); + } void _signal(PointerSignalEvent event) { - if (event is! PointerScrollEvent || - !widget.canTurn(event.scrollDelta) || - HardwareKeyboard.instance.isControlPressed || + if (event is! PointerScrollEvent) return; + + if (HardwareKeyboard.instance.isControlPressed || HardwareKeyboard.instance.isMetaPressed) { + _clearTail(); + _resetResistance(); return; } - final delta = event.scrollDelta.dy.abs() >= event.scrollDelta.dx.abs() - ? event.scrollDelta.dy - : event.scrollDelta.dx; + if (_consumeTail(event.scrollDelta)) { + GestureBinding.instance.pointerSignalResolver.register(event, (_) {}); + return; + } + + final offset = _scrollAxis(event.scrollDelta); + final delta = offset.dy.abs() >= offset.dx.abs() ? offset.dy : offset.dx; if (delta == 0) return; + if (!widget.canTurn(offset) && !(widget.resistance && _turning)) { + _resetResistance(); + return; + } + GestureBinding.instance.pointerSignalResolver.register(event, (_) { final direction = delta > 0 ? 1 : -1; + + if (widget.resistance) { + _accumulate(offset, delta); + return; + } + if (_cooldown?.isActive == true && direction == _direction) return; + _direction = direction; _cooldown?.cancel(); _cooldown = Timer(const Duration(milliseconds: 120), () {}); - _pending = _pending - .then((_) async { - if (mounted && widget.canTurn(event.scrollDelta)) { - await widget.onTurn(direction); - } - }) - .catchError((Object error, StackTrace stack) { - if (error is ReaderException && - error.code == ReaderErrorCode.navigationBoundary) { - return; - } - FlutterError.reportError( - FlutterErrorDetails( - exception: error, - stack: stack, - library: 'papyrus_reader', - context: ErrorDescription( - 'while turning a page with the scroll wheel', - ), - ), - ); - }); + _queueTurn(direction, event.scrollDelta); }); } + Offset _scrollAxis(Offset delta) { + if (!widget.resistance) return delta; + + // Keep diagonal finger drift on the axis chosen for this scroll sequence. + // Reconsider it only after the sequence ends or ordinary panning resumes. + var horizontal = _horizontal; + + if (_axisIntent.distanceSquared < _axisLockDistance * _axisLockDistance) { + _axisIntent += delta; + horizontal = _axisIntent.dx.abs() > _axisIntent.dy.abs(); + } + + return horizontal ? Offset(delta.dx, 0) : Offset(0, delta.dy); + } + + @override + void didUpdateWidget(ReaderPageWheel oldWidget) { + super.didUpdateWidget(oldWidget); + + if (oldWidget.resistance != widget.resistance) { + _clearTail(); + _resetResistance(); + } + } + @override void dispose() { _cooldown?.cancel(); + _gestureEnd?.cancel(); + _tailEnd?.cancel(); super.dispose(); } @override - Widget build(BuildContext context) => Stack( - fit: StackFit.expand, - children: [ - widget.child, - Positioned.fill( - child: Listener( - behavior: HitTestBehavior.translucent, - onPointerSignal: _signal, + Widget build(BuildContext context) { + final colors = Theme.of(context).colorScheme; + final dark = colors.brightness == Brightness.dark; + final background = dark ? colors.inverseSurface : colors.surface; + final foreground = dark ? colors.onInverseSurface : colors.onSurface; + + return Stack( + fit: StackFit.expand, + children: [ + widget.child, + Positioned.fill( + child: Listener( + behavior: HitTestBehavior.translucent, + onPointerSignal: _signal, + ), ), - ), - ], - ); + if (widget.resistance && widget.showResistance) + Positioned.fill( + child: IgnorePointer( + child: AnimatedOpacity( + opacity: _feedbackVisible ? 1 : 0, + duration: _feedbackVisible ? Duration.zero : _feedbackFade, + child: ExcludeSemantics( + child: SafeArea( + minimum: const EdgeInsets.all(12), + child: Padding( + padding: ReaderChromeInsets.of(context), + child: Align( + alignment: _horizontal + ? (_direction == 1 + ? Alignment.centerRight + : Alignment.centerLeft) + : (_direction == 1 + ? Alignment.bottomCenter + : Alignment.topCenter), + child: RotatedBox( + quarterTurns: _horizontal + ? (_direction == 1 ? 3 : 1) + : 0, + child: DecoratedBox( + decoration: BoxDecoration( + color: background, + borderRadius: BorderRadius.circular(8), + ), + child: Padding( + padding: const EdgeInsets.all(6), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + !_horizontal && _direction == -1 + ? Icons.keyboard_arrow_up + : Icons.keyboard_arrow_down, + size: 18, + color: foreground, + ), + SizedBox( + width: 56, + child: LinearProgressIndicator( + value: _displayProgress, + minHeight: 3, + color: foreground, + backgroundColor: dark + ? foreground.withValues(alpha: .24) + : colors.surfaceContainerHighest, + ), + ), + ], + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ), + ], + ); + } } diff --git a/test/presentation/papyrus_reader_test.dart b/test/presentation/papyrus_reader_test.dart index 84c4c81..0e2a75d 100644 --- a/test/presentation/papyrus_reader_test.dart +++ b/test/presentation/papyrus_reader_test.dart @@ -2,9 +2,11 @@ import 'dart:async'; import 'dart:math' as math; import 'package:flutter/material.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:papyrus_reader/papyrus_reader.dart'; +import 'package:papyrus_reader/src/presentation/reader_page_wheel.dart'; void main() { TestWidgetsFlutterBinding.ensureInitialized(); @@ -163,6 +165,98 @@ void main() { }, ); + for (final width in [400.0, 1200.0]) { + testWidgets('wheel feedback clears measured controls at width $width', ( + tester, + ) async { + final toolbarHeight = ValueNotifier(96); + addTearDown(toolbarHeight.dispose); + final engine = _UiReaderEngine( + viewportBuilder: (_, _) => ReaderPageWheel( + resistance: true, + canTurn: (_) => true, + onTurn: (_) async {}, + child: const SizedBox.expand(key: ValueKey('wheel-page')), + ), + ); + final controller = controllerFor([engine]); + addTearDown(controller.dispose); + await pumpReader( + tester, + document: document('Resistance'), + controller: controller, + size: Size(width, 800), + textScale: 2, + showControls: false, + builders: ReaderUiBuilders( + toolbar: (_, _) => ValueListenableBuilder( + valueListenable: toolbarHeight, + builder: (_, height, _) => SizedBox(height: height), + ), + ), + ); + await tester.pumpAndSettle(); + final page = find.byKey(const ValueKey('wheel-page')); + final pageBounds = tester.getRect(page); + final wheelState = tester.state(find.byType(ReaderPageWheel)); + final locator = controller.snapshot.locator; + final indicator = find.descendant( + of: find.byType(ReaderPageWheel), + matching: find.byType(RotatedBox), + ); + + Future scroll(double delta) async { + await tester.sendEventToBinding( + PointerScrollEvent( + position: pageBounds.center, + scrollDelta: Offset(0, delta), + ), + ); + await tester.pump(); + } + + await scroll(-80); + final hiddenTop = tester.getRect(indicator).top; + await toggleReaderControls(tester); + await tester.pump(); + final toolbar = find.byKey(const ValueKey('reader-toolbar')); + expect( + tester.getRect(indicator).top, + greaterThan(tester.getRect(toolbar).bottom), + ); + toolbarHeight.value = 160; + await tester.pump(); + await tester.pump(); + expect( + tester.getRect(indicator).top, + greaterThan(tester.getRect(toolbar).bottom), + reason: + 'Internal toolbar resizing must update feedback without resizing the page', + ); + expect(tester.getRect(page), pageBounds); + expect(tester.state(find.byType(ReaderPageWheel)), same(wheelState)); + + await scroll(160); + final footer = find.byKey(const ValueKey('reader-progress-controls')); + expect( + tester.getRect(indicator).bottom, + lessThan(tester.getRect(footer).top), + ); + await toggleReaderControls(tester); + await tester.pump(); + expect( + tester.getRect(indicator).bottom, + closeTo(pageBounds.bottom - 12, .01), + ); + await scroll(-160); + expect(tester.getRect(indicator).top, hiddenTop); + expect(tester.getRect(page), pageBounds); + expect(controller.snapshot.locator, locator); + expect(tester.takeException(), isNull); + await tester.pumpWidget(const SizedBox.shrink()); + }); + } + testWidgets('custom snapshot viewports refresh without losing state', ( tester, ) async { diff --git a/test/presentation/pdf_tools_test.dart b/test/presentation/pdf_tools_test.dart index 50f56b5..7c673cc 100644 --- a/test/presentation/pdf_tools_test.dart +++ b/test/presentation/pdf_tools_test.dart @@ -95,7 +95,7 @@ Future _navigate(WidgetTester tester, Future operation) async { void main() { testWidgets( - 'PDF wheel turns respond to a one-pixel delta and preserve zoomed panning', + 'PDF wheel turns require deliberate scrolling and preserve zoomed panning', (tester) async { final bytes = await tester.runAsync(() => _document()); await tester.runAsync(initializePdfiumForTest); @@ -137,12 +137,26 @@ void main() { await tester.pump(); expect(original.textSelectionDelegate.hasSelectedText, isTrue); for (final direction in [1, -1]) { + final previousPage = tools.pageNumber; await tester.sendEventToBinding( PointerScrollEvent( position: const Offset(400, 300), scrollDelta: Offset(0, direction.toDouble()), ), ); + await tester.pump(); + expect(tools.pageNumber, previousPage); + await tester.pump(const Duration(milliseconds: 80)); + + for (var tick = 0; tick < 8; tick++) { + await tester.sendEventToBinding( + PointerScrollEvent( + position: const Offset(400, 300), + scrollDelta: Offset(0, direction * 80.0), + ), + ); + await tester.pump(const Duration(milliseconds: 80)); + } await tester.pumpAndSettle(); await _ready(tester, tools); expect(tools.pageNumber, direction > 0 ? 2 : 1); @@ -228,6 +242,49 @@ void main() { await tester.pump(const Duration(milliseconds: 120)); } + Future turn(int direction, {bool withTail = false}) async { + await tester.pump(const Duration(milliseconds: 300)); + + for (var tick = 0; tick < 8; tick++) { + await tester.sendEventToBinding( + PointerScrollEvent( + position: const Offset(720, 450), + scrollDelta: Offset(0, direction * 80.0), + ), + ); + await tester.pump(const Duration(milliseconds: 80)); + } + + if (withTail) { + for (final distance in [ + 72.0, + 64.0, + 48.0, + 32.0, + 20.0, + 12.0, + 6.0, + 3.0, + 1.0, + ]) { + await tester.sendEventToBinding( + PointerScrollEvent( + position: const Offset(720, 450), + scrollDelta: Offset(0, direction * distance), + ), + ); + await tester.runAsync( + () => Future.delayed(const Duration(milliseconds: 20)), + ); + await tester.pump(const Duration(milliseconds: 16)); + } + } + + await tester.pumpAndSettle(); + await _ready(tester, tools); + await tester.pump(const Duration(milliseconds: 300)); + } + Future pan(double distance) async { await tools.scrollVertically(distance); await tester.pumpAndSettle(); @@ -266,7 +323,7 @@ void main() { expect(tools.pageNumber, 1); expect(controller().visibleRect.top, greaterThan(before)); await pan(-100000); - await wheel(const Offset(0, -1)); + await turn(-1); expect(tools.pageNumber, 1, reason: 'The first page is a boundary'); await pan(100000); await wheel(const Offset(40, 0)); @@ -275,12 +332,12 @@ void main() { 1, reason: 'Horizontal zoomed input still pans', ); - await wheel(const Offset(0, 1)); + await turn(1, withTail: true); expect(tools.pageNumber, facingPages ? 3 : 2); expect(tools.zoom, closeTo(zoom, .001)); expect(controller().visibleRect.top, closeTo(spread().top, .01)); expect(reportedOffset, closeTo(0, .001)); - await wheel(const Offset(0, -1)); + await turn(-1, withTail: true); expect(tools.pageNumber, 1); expect(tools.zoom, closeTo(zoom, .001)); expect(controller().visibleRect.bottom, closeTo(spread().bottom, .01)); @@ -295,7 +352,7 @@ void main() { expect(controller().visibleRect.top, lessThan(bottom)); await _navigate(tester, facade.showPage(4, 0)); await pan(100000); - await wheel(const Offset(0, 1)); + await turn(1); expect(tools.pageNumber, 5, reason: 'The last page is a boundary'); expect(tester.takeException(), isNull); await tester.pumpWidget(const SizedBox.shrink()); diff --git a/test/presentation/reader_page_wheel_test.dart b/test/presentation/reader_page_wheel_test.dart index bf338a5..14fbd00 100644 --- a/test/presentation/reader_page_wheel_test.dart +++ b/test/presentation/reader_page_wheel_test.dart @@ -1,5 +1,8 @@ +import 'dart:async'; + import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:papyrus_reader/src/presentation/reader_page_wheel.dart'; @@ -61,4 +64,515 @@ void main() { await tester.pumpWidget(const SizedBox.shrink()); }, ); + testWidgets( + 'resistance stays visible and continued scrolling keeps turning', + (tester) async { + final turns = []; + var nativeSignals = 0; + var canTurn = true; + await tester.pumpWidget( + MaterialApp( + home: ReaderPageWheel( + resistance: true, + canTurn: (_) => canTurn, + onTurn: (direction) async => turns.add(direction), + child: Listener( + behavior: HitTestBehavior.opaque, + onPointerSignal: (event) => GestureBinding + .instance + .pointerSignalResolver + .register(event, (_) => nativeSignals++), + child: const SizedBox.expand(), + ), + ), + ), + ); + + Future wheel(double delta, {int milliseconds = 80}) async { + await tester.sendEventToBinding( + PointerScrollEvent( + position: const Offset(400, 300), + scrollDelta: Offset(0, delta), + ), + ); + await tester.pump(Duration(milliseconds: milliseconds)); + } + + double progress() => tester + .widget(find.byType(LinearProgressIndicator)) + .value!; + double opacity() => + tester.widget(find.byType(AnimatedOpacity)).opacity; + + await wheel(80); + final partial = progress(); + await tester.pump(const Duration(milliseconds: 400)); + expect( + opacity(), + 1, + reason: 'Feedback persists between touchpad strokes', + ); + expect(progress(), partial); + await wheel(-1); + expect( + find.byIcon(Icons.keyboard_arrow_down), + findsOneWidget, + reason: 'Reverse jitter unwinds pressure without jumping edges', + ); + await wheel(1); + + for (var tick = 0; tick < 6; tick++) { + await wheel(80); + } + + expect(turns, isEmpty, reason: 'Two wheel notches no longer turn a page'); + await wheel(80); + expect(turns, [1]); + expect(opacity(), 1, reason: 'Feedback stays visible across page turns'); + + for (var tick = 0; tick < 8; tick++) { + await wheel(80); + } + + expect(turns, [ + 1, + 1, + ], reason: 'Continued input turns without an idle pause'); + expect(nativeSignals, 0); + await tester.pump(const Duration(milliseconds: 700)); + expect(opacity(), 1); + await tester.pump(const Duration(milliseconds: 200)); + expect(opacity(), 0); + final fade = tester.renderObject( + find.descendant( + of: find.byType(AnimatedOpacity), + matching: find.byType(FadeTransition), + ), + ); + expect( + fade.opacity.value, + greaterThan(0), + reason: 'Hide fades instead of popping', + ); + await tester.pump(const Duration(milliseconds: 250)); + expect(fade.opacity.value, 0); + + await wheel(80); + expect( + progress(), + partial, + reason: 'Idle input starts with fresh resistance', + ); + canTurn = false; + await wheel(40); + expect(opacity(), 0); + canTurn = true; + await wheel(80); + expect(progress(), partial, reason: 'Panning clears partial pressure'); + + for (final key in [ + LogicalKeyboardKey.controlLeft, + LogicalKeyboardKey.metaLeft, + ]) { + await tester.sendKeyDownEvent(key); + await wheel(80); + await tester.sendKeyUpEvent(key); + expect(opacity(), 0); + } + + expect(nativeSignals, 3); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); + + for (final interval in [8, 80]) { + for (final sampleDistance in [40.0, 160.0]) { + testWidgets( + 'swipes count distance at $interval ms intervals with $sampleDistance samples', + (tester) async { + final turns = []; + await tester.pumpWidget( + MaterialApp( + home: ReaderPageWheel( + resistance: true, + canTurn: (_) => true, + onTurn: (direction) async => turns.add(direction), + child: const SizedBox.expand(), + ), + ), + ); + final samplesPerPage = (640 / sampleDistance).round(); + + for (var page = 0; page < 2; page++) { + for (var sample = 0; sample < samplesPerPage; sample++) { + await tester.sendEventToBinding( + PointerScrollEvent( + position: const Offset(400, 300), + scrollDelta: Offset(0, sampleDistance), + ), + ); + await tester.pump(Duration(milliseconds: interval)); + final completed = sample == samplesPerPage - 1; + expect(turns.length, page + (completed ? 1 : 0)); + expect( + tester + .widget( + find.byType(LinearProgressIndicator), + ) + .value, + closeTo((sample + 1) / samplesPerPage, .0001), + reason: + 'Active motion must count regardless of speed or event batching', + ); + } + } + + expect(turns, [ + 1, + 1, + ], reason: 'Both turns complete without an inertia tail'); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); + } + } + + for (final horizontal in [false, true]) { + testWidgets('diagonal drift does not reset $horizontal scrolling', ( + tester, + ) async { + final turns = []; + final claimed = []; + await tester.pumpWidget( + MaterialApp( + home: ReaderPageWheel( + resistance: true, + canTurn: (delta) { + claimed.add(delta); + return true; + }, + onTurn: (direction) async => turns.add(direction), + child: const SizedBox.expand(), + ), + ), + ); + + Future wheel(Offset delta) async { + await tester.sendEventToBinding( + PointerScrollEvent( + position: const Offset(400, 300), + scrollDelta: delta, + ), + ); + await tester.pump(const Duration(milliseconds: 8)); + } + + for (var sample = 0; sample < 8; sample++) { + final drift = sample == 0 ? 0.0 : (sample.isEven ? -100.0 : 100.0); + await wheel(horizontal ? Offset(80, drift) : Offset(drift, 80)); + expect( + tester + .widget( + find.byType(LinearProgressIndicator), + ) + .value, + closeTo((sample + 1) / 8, .0001), + ); + } + + expect(turns, [1]); + expect( + claimed.every((delta) => horizontal ? delta.dy == 0 : delta.dx == 0), + isTrue, + ); + await tester.pump(const Duration(milliseconds: 1200)); + await wheel(horizontal ? const Offset(0, -80) : const Offset(-80, 0)); + expect( + claimed.last, + horizontal ? const Offset(0, -80) : const Offset(-80, 0), + reason: 'A fresh sequence can choose a different axis', + ); + expect( + tester + .widget( + find.byType(LinearProgressIndicator), + ) + .value, + .125, + ); + await tester.pumpWidget(const SizedBox.shrink()); + }); + } + + testWidgets( + 'tiny initial sideways movement does not lock out a vertical swipe', + (tester) async { + final turns = []; + await tester.pumpWidget( + MaterialApp( + home: ReaderPageWheel( + resistance: true, + canTurn: (_) => true, + onTurn: (direction) async => turns.add(direction), + child: const SizedBox.expand(), + ), + ), + ); + + for (final delta in [ + const Offset(1, 0), + ...List.filled(8, const Offset(0, 80)), + ]) { + await tester.sendEventToBinding( + PointerScrollEvent( + position: const Offset(400, 300), + scrollDelta: delta, + ), + ); + await tester.pump(const Duration(milliseconds: 8)); + } + + expect(turns, [1]); + expect(find.byIcon(Icons.keyboard_arrow_down), findsOneWidget); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); + + for (final fitted in [false, true]) { + testWidgets( + 'a page turn absorbs its decaying scroll tail, fitted $fitted', + (tester) async { + final turns = []; + final nativeSignals = []; + var canTurn = true; + await tester.pumpWidget( + MaterialApp( + home: ReaderPageWheel( + resistance: true, + canTurn: (_) => canTurn, + onTurn: (direction) async { + turns.add(direction); + canTurn = fitted; + }, + child: Listener( + behavior: HitTestBehavior.opaque, + onPointerSignal: (event) { + if (event is PointerScrollEvent) { + GestureBinding.instance.pointerSignalResolver.register( + event, + (_) => nativeSignals.add(event.scrollDelta), + ); + } + }, + child: const SizedBox.expand(), + ), + ), + ), + ); + + Future wheel(double delta) async { + await tester.sendEventToBinding( + PointerScrollEvent( + position: const Offset(400, 300), + scrollDelta: Offset(0, delta), + ), + ); + await tester.pump(const Duration(milliseconds: 16)); + } + + for (var sample = 0; sample < 8; sample++) { + await wheel(80); + } + + expect(turns, [1]); + + for (var tail = 79.0; tail >= 1; tail--) { + await wheel(tail); + } + + expect(turns, [ + 1, + ], reason: 'Even a long momentum tail must not turn again'); + expect( + nativeSignals, + isEmpty, + reason: 'The tail must not pan the new page', + ); + await wheel(12); + + if (fitted) { + expect( + tester + .widget( + find.byType(LinearProgressIndicator), + ) + .value, + closeTo(12 / 640, .0001), + ); + } else { + expect(nativeSignals, [ + const Offset(0, 12), + ], reason: 'A fresh impulse pans immediately without waiting'); + } + + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); + } + + for (final release in ['reverse', 'axis', 'pause', 'zoom']) { + testWidgets('post-turn inertia releases on $release', (tester) async { + var canTurn = true; + var nativeSignals = 0; + await tester.pumpWidget( + MaterialApp( + home: ReaderPageWheel( + resistance: true, + canTurn: (_) => canTurn, + onTurn: (_) async => canTurn = false, + child: Listener( + behavior: HitTestBehavior.opaque, + onPointerSignal: (event) => GestureBinding + .instance + .pointerSignalResolver + .register(event, (_) => nativeSignals++), + child: const SizedBox.expand(), + ), + ), + ), + ); + + Future wheel(Offset delta) async { + await tester.sendEventToBinding( + PointerScrollEvent( + position: const Offset(400, 300), + scrollDelta: delta, + ), + ); + await tester.pump(const Duration(milliseconds: 16)); + } + + for (var sample = 0; sample < 8; sample++) { + await wheel(const Offset(0, 80)); + } + + await wheel(const Offset(0, 40)); + expect(nativeSignals, 0); + + if (release == 'pause') { + await tester.pump(const Duration(milliseconds: 200)); + } else if (release == 'zoom') { + await tester.sendKeyDownEvent(LogicalKeyboardKey.controlLeft); + } + + await wheel(switch (release) { + 'reverse' => const Offset(0, -20), + 'axis' => const Offset(40, 0), + _ => const Offset(0, 20), + }); + expect(nativeSignals, 1); + + if (release == 'zoom') { + await tester.sendKeyUpEvent(LogicalKeyboardKey.controlLeft); + } + + await tester.pumpWidget(const SizedBox.shrink()); + }); + } + + testWidgets( + 'input during navigation builds the next turn without queuing a burst', + (tester) async { + final turns = []; + final navigation = Completer(); + var canTurn = true; + await tester.pumpWidget( + MaterialApp( + home: ReaderPageWheel( + resistance: true, + canTurn: (_) => canTurn, + onTurn: (direction) async { + turns.add(direction); + + if (turns.length == 1) { + canTurn = false; + await navigation.future; + canTurn = true; + } + }, + child: const SizedBox.expand(), + ), + ), + ); + + Future stroke(int count) async { + for (var tick = 0; tick < count; tick++) { + await tester.sendEventToBinding( + const PointerScrollEvent( + position: Offset(400, 300), + scrollDelta: Offset(0, 80), + ), + ); + await tester.pump(const Duration(milliseconds: 80)); + } + } + + await stroke(8); + expect(turns, [1]); + await stroke(12); + expect(turns, [1]); + navigation.complete(); + await tester.pump(); + expect(turns, [1, 1]); + await tester.pump(const Duration(seconds: 2)); + expect(turns, [ + 1, + 1, + ], reason: 'Excess input must not queue multiple pages'); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); + + testWidgets( + 'resistance works without feedback and clears on layout changes', + (tester) async { + final turns = []; + Future mount({required bool resistance}) => tester.pumpWidget( + MaterialApp( + home: ReaderPageWheel( + resistance: resistance, + showResistance: false, + canTurn: (_) => true, + onTurn: (direction) async => turns.add(direction), + child: const SizedBox.expand(), + ), + ), + ); + Future wheel() async { + await tester.sendEventToBinding( + const PointerScrollEvent( + position: Offset(400, 300), + scrollDelta: Offset(0, 80), + ), + ); + await tester.pump(const Duration(milliseconds: 80)); + } + + await mount(resistance: true); + await wheel(); + expect(turns, isEmpty); + expect(find.byType(LinearProgressIndicator), findsNothing); + await mount(resistance: false); + await mount(resistance: true); + + for (var tick = 0; tick < 7; tick++) { + await wheel(); + } + + expect(turns, isEmpty); + await wheel(); + expect(turns, [1]); + await tester.pumpWidget(const SizedBox.shrink()); + }, + ); } diff --git a/tool/browser/formats.mjs b/tool/browser/formats.mjs index 2593b8b..1c265ed 100644 --- a/tool/browser/formats.mjs +++ b/tool/browser/formats.mjs @@ -141,8 +141,24 @@ export async function checkFormats(browser, origin, reader) { await page.mouse.move(550, 400); await page.mouse.wheel(0, 1); await page.waitForTimeout(500); - assert.notEqual(await location(), initial, `${format} a small wheel movement must turn the page`); - await page.mouse.wheel(0, -1); + const fixedPages = ['pdf', 'cbz', 'cbr'].includes(format); + if (fixedPages) { + assert.equal(await location(), initial, `${format} small wheel movements must not turn the page`); + for (let sample = 0; sample < 8; sample++) { + await page.mouse.wheel(0, 80); + await page.waitForTimeout(16); + } + await page.waitForTimeout(100); + } + assert.notEqual(await location(), initial, `${format} wheel input must turn the page`); + if (fixedPages) { + for (let sample = 0; sample < 8; sample++) { + await page.mouse.wheel(0, -80); + await page.waitForTimeout(16); + } + } else { + await page.mouse.wheel(0, -1); + } await page.waitForTimeout(500); assert.equal(await location(), initial, `${format} reverse wheel input must restore the initial page`); await next.click({ force: true }); diff --git a/tool/browser/pdf_swipes.mjs b/tool/browser/pdf_swipes.mjs index 50f08ae..67672a1 100644 --- a/tool/browser/pdf_swipes.mjs +++ b/tool/browser/pdf_swipes.mjs @@ -192,23 +192,45 @@ try { await page.mouse.wheel(0, delta); await page.waitForTimeout(400); }; + const wheelTurn = async direction => { + for (let sample = 0; sample < 8; sample++) { + await page.mouse.wheel(0, direction * 80); + await page.waitForTimeout(16); + } + }; await wheel(40); await assertPage(5); await wheel(100000); await assertPage(5); await wheel(1); + await assertPage(5); + await wheelTurn(1); + const newPageText = page.getByText('Swipe page 6.', { exact: true }); + await newPageText.waitFor(); + const beforeTail = await newPageText.boundingBox(); + for (const delta of [72, 64, 48, 32, 20, 12, 6, 3, 1]) { + await page.mouse.wheel(0, delta); + await page.waitForTimeout(16); + } + const afterTail = await newPageText.boundingBox(); + assert.ok(beforeTail && afterTail && Math.abs(afterTail.y - beforeTail.y) < 1, + 'Post-turn inertia must not move the new zoomed PDF page'); await assertPage(6); await wheel(-1); + await assertPage(6); + await wheelTurn(-1); await assertPage(5); await wheel(-40); await assertPage(5); await wheel(-100000); await assertPage(5); await wheel(-1); + await assertPage(5); + await wheelTurn(-1); await assertPage(4); await assertZoom(true); assert.deepEqual(errors, []); - console.log(`PASS: ${width}px zoomed PDF wheel pans within pages and turns at both edges`); + console.log(`PASS: ${width}px zoomed PDF wheel resistance, boundary turns, and inertia suppression`); if (input === 'mouse') { await setControlsVisible(false); // Each interrupted drag must cover enough distance to pass the next diff --git a/tool/browser/smoke.mjs b/tool/browser/smoke.mjs index 9727790..b2b5d0a 100644 --- a/tool/browser/smoke.mjs +++ b/tool/browser/smoke.mjs @@ -391,11 +391,19 @@ try { await closeSettings(); await page.mouse.move(450, 350); await page.mouse.wheel(0, 180); + await settle(); + assert.ok(await page.getByText('Page 2 of 3.', { exact: true }).isVisible(), + 'A small PDF wheel movement must not turn the page'); + for (let sample = 0; sample < 6; sample++) { + await page.mouse.wheel(0, 80); + await page.waitForTimeout(16); + } await page.getByText('Page 3 of 3.', { exact: true }).waitFor(); await settle(); - // Discrete PDF wheel turns intentionally debounce input for 250 ms. - await page.waitForTimeout(260); - await page.mouse.wheel(0, -180); + for (let sample = 0; sample < 8; sample++) { + await page.mouse.wheel(0, -80); + await page.waitForTimeout(16); + } await page.getByText('Page 2 of 3.', { exact: true }).waitFor(); await settle(); await openSettings(); From 9fd30de24f88da746131bc8fcf5cb75d72a5d5af Mon Sep 17 00:00:00 2001 From: Karolis Strazdas Date: Wed, 25 Nov 2026 00:07:07 +0200 Subject: [PATCH 2/2] test: keep PDF inertia input continuous during browser checks --- tool/browser/pdf_swipes.mjs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/tool/browser/pdf_swipes.mjs b/tool/browser/pdf_swipes.mjs index 67672a1..6887209 100644 --- a/tool/browser/pdf_swipes.mjs +++ b/tool/browser/pdf_swipes.mjs @@ -204,17 +204,35 @@ try { await assertPage(5); await wheel(1); await assertPage(5); + await page.evaluate(() => { + window.inertiaProbe = { beforeTail: null, samples: [] }; + const observe = event => { + window.inertiaProbe.samples.push({ time: performance.now(), delta: event.deltaY }); + if (event.deltaY === 72) { + const text = [...document.querySelectorAll('flt-semantics')] + .findLast(element => element.textContent === 'Swipe page 6.'); + window.inertiaProbe.beforeTail = text?.getBoundingClientRect().toJSON() ?? null; + } + if (event.deltaY === 1) window.removeEventListener('wheel', observe, true); + }; + window.addEventListener('wheel', observe, { capture: true }); + }); await wheelTurn(1); - const newPageText = page.getByText('Swipe page 6.', { exact: true }); - await newPageText.waitFor(); - const beforeTail = await newPageText.boundingBox(); + // Keep the stroke and its tail continuous. Locator polling here can exceed + // the reader's idle cutoff on CI, turning the tail into fresh panning input. + // Capture the starting geometry in the browser before the first tail event. for (const delta of [72, 64, 48, 32, 20, 12, 6, 3, 1]) { await page.mouse.wheel(0, delta); await page.waitForTimeout(16); } + const newPageText = page.getByText('Swipe page 6.', { exact: true }); + await newPageText.waitFor(); + const { beforeTail, samples } = await page.evaluate(() => window.inertiaProbe); const afterTail = await newPageText.boundingBox(); assert.ok(beforeTail && afterTail && Math.abs(afterTail.y - beforeTail.y) < 1, - 'Post-turn inertia must not move the new zoomed PDF page'); + `Post-turn inertia must not move the new zoomed PDF page: ${JSON.stringify({ + beforeTail, afterTail, samples, + })}`); await assertPage(6); await wheel(-1); await assertPage(6);