Add browser playtest and improve library, media and input

Bundle web bootstrap, icons, local font fallbacks and hosting instructions.
Add optimized WebP/MP3 packaging, asset checks and a browser narration
regression tool. Support browser audio handoff and ad-free explained hints.

Refresh the responsive bookshelf and reduce unnecessary app, narration and
paper repaint work. Preserve deliberate page swipes while tolerating small
mouse movements during cell and navigation clicks.

Validation: all 77 Flutter tests pass; shell, JavaScript and Python scripts
parse; locale and web manifests are valid JSON; git diff --check passes.
This commit is contained in:
Hadrian Burkhardt
2026-11-06 03:33:26 +01:00
parent 7855aafade
commit 7e6b203a02
34 changed files with 1370 additions and 269 deletions
+83 -14
View File
@@ -1,6 +1,9 @@
import '../services/browser_assets.dart';
import 'dart:math' as math;
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'translation.dart';
@@ -13,6 +16,9 @@ const ink = Color(0xff36413c),
amber = Color(0xffe0b568);
TextStyle hand(double size, {Color color = ink}) => TextStyle(
fontFamily: 'MaraHand',
fontFamilyFallback: kIsWeb
? const ['LumenText', 'LumenSymbols', 'LumenSymbols2', 'LumenMath']
: null,
fontSize: size,
height: 1.30,
color: color,
@@ -78,6 +84,65 @@ class PaperSkin extends InheritedWidget {
bool updateShouldNotify(PaperSkin oldWidget) => asset != oldWidget.asset;
}
/// Flutter's default mouse drag threshold is one pixel. That turns ordinary
/// click jitter into a swipe and cancels a child button's/cell's tap recognizer.
/// Use the normal tap tolerance for mouse drags too, retaining deliberate swipes.
class _PageHorizontalDrag extends HorizontalDragGestureRecognizer {
_PageHorizontalDrag({super.debugOwner});
@override
bool hasSufficientGlobalDistanceToAccept(
PointerDeviceKind pointerDeviceKind,
double? deviceTouchSlop,
) => pointerDeviceKind == PointerDeviceKind.mouse
? globalDistanceMoved.abs() > kTouchSlop
: super.hasSufficientGlobalDistanceToAccept(
pointerDeviceKind,
deviceTouchSlop,
);
}
class _PageDragDetector extends StatelessWidget {
const _PageDragDetector({
required this.child,
this.onHorizontalDragStart,
this.onHorizontalDragUpdate,
this.onHorizontalDragEnd,
this.onHorizontalDragCancel,
this.dragStartBehavior = DragStartBehavior.start,
});
final Widget child;
final GestureDragStartCallback? onHorizontalDragStart;
final GestureDragUpdateCallback? onHorizontalDragUpdate;
final GestureDragEndCallback? onHorizontalDragEnd;
final GestureDragCancelCallback? onHorizontalDragCancel;
final DragStartBehavior dragStartBehavior;
@override
Widget build(BuildContext context) => RawGestureDetector(
behavior: HitTestBehavior.opaque,
gestures: {
if (onHorizontalDragStart != null ||
onHorizontalDragUpdate != null ||
onHorizontalDragEnd != null ||
onHorizontalDragCancel != null)
_PageHorizontalDrag:
GestureRecognizerFactoryWithHandlers<_PageHorizontalDrag>(
() => _PageHorizontalDrag(debugOwner: this),
(recognizer) => recognizer
..gestureSettings = MediaQuery.maybeGestureSettingsOf(context)
..dragStartBehavior = dragStartBehavior
..onStart = onHorizontalDragStart
..onUpdate = onHorizontalDragUpdate
..onEnd = onHorizontalDragEnd
..onCancel = onHorizontalDragCancel,
),
},
child: child,
);
}
class _PaperState extends State<Paper> {
Offset _drag = Offset.zero;
Offset _origin = Offset.zero;
@@ -115,8 +180,7 @@ class _PaperState extends State<Paper> {
onPointerCancel: (_) {
_drag = Offset.zero;
},
child: GestureDetector(
behavior: HitTestBehavior.opaque,
child: _PageDragDetector(
dragStartBehavior: DragStartBehavior.down,
onHorizontalDragStart: widget.onTurn == null
? null
@@ -148,15 +212,21 @@ class _PaperState extends State<Paper> {
clipBehavior: Clip.hardEdge,
children: [
Positioned(
left: left,
top: top,
width: w,
height: h,
child: Image.asset(
PaperSkin.assetOf(context) ??
'assets/artwork/mara-single-page-v2.png',
fit: BoxFit.fill,
excludeFromSemantics: true,
// Crop the source image while painting, rather than
// caching a tall off-screen paper layer on wide displays.
left: landscape ? 0 : left,
top: landscape ? 0 : top,
width: landscape ? c.maxWidth : w,
height: landscape ? c.maxHeight : h,
child: RepaintBoundary(
child: Image.asset(
artworkAsset(
PaperSkin.assetOf(context) ??
'assets/artwork/mara-single-page-v2.png',
),
fit: landscape ? BoxFit.cover : BoxFit.fill,
excludeFromSemantics: true,
),
),
),
Positioned.fromRect(rect: content, child: widget.child),
@@ -176,8 +246,7 @@ class PageSwipeBlocker extends StatelessWidget {
const PageSwipeBlocker({super.key, required this.child});
final Widget child;
@override
Widget build(BuildContext context) => GestureDetector(
behavior: HitTestBehavior.opaque,
Widget build(BuildContext context) => _PageDragDetector(
onHorizontalDragStart: (_) {},
onHorizontalDragUpdate: (_) {},
onHorizontalDragEnd: (_) {},
@@ -251,7 +320,7 @@ class Cover extends StatelessWidget {
children: [
Positioned.fill(
child: Image.asset(
'assets/artwork/home-notebook-cover-v2.png',
artworkAsset('assets/artwork/home-notebook-cover-v2.png'),
fit: BoxFit.fill,
excludeFromSemantics: true,
),