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
+9 -4
View File
@@ -187,10 +187,15 @@ class Board extends StatelessWidget {
children: [
if (value != 0)
Positioned.fill(
child: CustomPaint(
painter: PencilMark(
value: value,
variation: i,
child: RepaintBoundary(
child: CustomPaint(
painter:
PencilMark(
value:
value,
variation:
i,
),
),
),
),
+254
View File
@@ -0,0 +1,254 @@
import '../services/browser_assets.dart';
import 'package:flutter/material.dart';
import '../domain/book.dart';
import 'translation.dart';
const _shelfPaper = Color(0xfff6f1e7);
const _shelfInk = Color(0xff283e37);
const _shelfMuted = Color(0xff746f62);
TextStyle _type(double size, {Color color = _shelfInk, bool serif = false}) =>
TextStyle(
fontFamily: serif ? 'serif' : 'sans-serif',
fontSize: size,
height: serif ? 1.2 : 1.5,
color: color,
);
/// The collection has its own quiet surface, outside any one story's notebook.
class LibraryShelf extends StatelessWidget {
const LibraryShelf({
super.key,
required this.builder,
required this.onSettings,
});
final Widget Function(BuildContext context, double width) builder;
final VoidCallback onSettings;
@override
Widget build(BuildContext context) => ColoredBox(
color: _shelfPaper,
child: SafeArea(
child: LayoutBuilder(
builder: (context, constraints) {
final compact = constraints.maxWidth < 600;
final padding = compact ? 24.0 : 48.0;
return SingleChildScrollView(
key: const ValueKey('library-scroll'),
padding: EdgeInsets.fromLTRB(padding, 20, padding, 48),
child: Center(
child: ConstrainedBox(
constraints: const BoxConstraints(maxWidth: 1120),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Wrap(
alignment: WrapAlignment.spaceBetween,
crossAxisAlignment: WrapCrossAlignment.center,
spacing: 24,
children: [
Row(
mainAxisSize: MainAxisSize.min,
children: [
const Icon(
Icons.auto_stories_outlined,
color: _shelfInk,
size: 22,
),
const SizedBox(width: 10),
Text('L U M E N', style: _type(13)),
],
),
TextButton.icon(
onPressed: onSettings,
icon: const Icon(Icons.tune_rounded, size: 18),
label: CopyText('Settings', style: _type(13)),
style: TextButton.styleFrom(
foregroundColor: _shelfInk,
minimumSize: const Size(48, 48),
),
),
],
),
const SizedBox(height: 20),
Divider(color: _shelfInk.withValues(alpha: .18)),
SizedBox(height: compact ? 28 : 44),
CopyText(
'Choose a book',
style: _type(compact ? 36 : 48, serif: true),
),
const SizedBox(height: 12),
CopyText(
'Open a book to continue where you left off.',
style: _type(15, color: _shelfMuted),
),
SizedBox(height: compact ? 30 : 40),
LayoutBuilder(
builder: (context, c) => builder(context, c.maxWidth),
),
],
),
),
),
);
},
),
),
);
}
class LibraryBookCard extends StatelessWidget {
const LibraryBookCard({
super.key,
required this.story,
required this.restored,
required this.resuming,
required this.languages,
required this.onOpen,
});
final Book story;
final int restored;
final bool resuming;
final List<String> languages;
final VoidCallback onOpen;
@override
Widget build(BuildContext context) {
final (cloth, light) = switch (story.id) {
'mara-island' => (const Color(0xff355751), const Color(0xffe0e5d6)),
'paper-boat' => (const Color(0xff526c85), const Color(0xffe1e9e8)),
_ => (const Color(0xff51445e), const Color(0xffe8dfd8)),
};
return Semantics(
button: true,
child: Material(
color: Colors.transparent,
child: InkWell(
key: ValueKey('library-book-${story.id}'),
onTap: onOpen,
borderRadius: BorderRadius.circular(8),
child: Padding(
padding: const EdgeInsets.all(8),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
// A cloth-bound cover with a recessed illustrated panel. The
// artwork keeps its natural proportions inside each book.
Container(
height: 276,
padding: const EdgeInsets.fromLTRB(22, 20, 14, 20),
decoration: BoxDecoration(
gradient: LinearGradient(
colors: [cloth, Color.lerp(cloth, Colors.black, .2)!],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
),
boxShadow: [
BoxShadow(
color: cloth.withValues(alpha: .22),
offset: const Offset(0, 10),
blurRadius: 16,
spreadRadius: -5,
),
],
border: Border(
left: BorderSide(
color: Color.lerp(cloth, Colors.black, .35)!,
width: 7,
),
right: BorderSide(color: light, width: 3),
),
),
child: Container(
padding: const EdgeInsets.all(14),
decoration: BoxDecoration(
border: Border.all(color: light.withValues(alpha: .4)),
),
child: Column(
children: [
Icon(
Icons.auto_awesome_outlined,
size: 18,
color: light,
),
const SizedBox(height: 12),
Expanded(
child: story.coverAsset == null
? Icon(Icons.menu_book, size: 64, color: light)
: Image.asset(
artworkAsset(story.coverAsset!),
fit: BoxFit.contain,
excludeFromSemantics: true,
errorBuilder: (_, _, _) => Icon(
Icons.menu_book,
size: 64,
color: light,
),
),
),
const SizedBox(height: 12),
SizedBox(width: 38, child: Divider(color: light)),
],
),
),
),
const SizedBox(height: 24),
CopyText(story.title, style: _type(25, serif: true)),
const SizedBox(height: 10),
if (story.description.isNotEmpty)
CopyText(
story.description,
style: _type(14, color: _shelfMuted),
),
if (languages.length > 1) ...[
const SizedBox(height: 10),
Text(
languages.join(' · '),
style: _type(12, color: _shelfMuted),
),
],
const SizedBox(height: 20),
if (story.levels.isNotEmpty) ...[
ClipRRect(
borderRadius: BorderRadius.circular(2),
child: LinearProgressIndicator(
value: restored / story.levels.length,
minHeight: 3,
color: cloth,
backgroundColor: cloth.withValues(alpha: .13),
),
),
const SizedBox(height: 8),
CopyText(
'$restored / ${story.levels.length} memories restored',
style: _type(12, color: _shelfMuted),
),
],
const SizedBox(height: 16),
Row(
children: [
Expanded(
child: CopyText(
resuming ? 'Continue reading' : 'Open this book ›',
style: _type(
14,
color: cloth,
).copyWith(fontWeight: FontWeight.w600),
),
),
Icon(Icons.arrow_forward_rounded, size: 18, color: cloth),
],
),
const SizedBox(height: 8),
],
),
),
),
),
);
}
}
+1 -1
View File
@@ -24,7 +24,7 @@ extension _MaraStory on _NotebookState {
body.addAll([
if (p.illustrationAsset case final asset?)
Image.asset(
asset,
artworkAsset(asset),
height: 155,
fit: BoxFit.contain,
semanticLabel: 'Watercolour of Gran’s stone cottage, blue door and warm window.',
+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,
),