diff --git a/app/fonts/README.md b/app/fonts/README.md index ec95efe4..a21d4d31 100644 --- a/app/fonts/README.md +++ b/app/fonts/README.md @@ -51,3 +51,17 @@ which is also registered with `LicenseRegistry`. The files are unmodified (no subsetting), so the Reserved Font Names stay usable. + +## Paper reading serif + +`source-serif-4/` holds Source Serif 4.005 (github.com/adobe-fonts/source-serif +release 4.005R, `source-serif-4.005_Desktop.zip`, `TTF/`): the unmodified +Regular, Italic, Semibold and Semibold Italic files of the default (Text) +optical size, and `LICENSE.md` from the same archive as `OFL.txt` (SIL Open +Font License 1.1, (c) Adobe, Reserved Font Name "Source"). The Paper design +sets chat and document text in it (`lib/ui/theme/paper_fonts.dart`). Like the +interface fonts it is a plain asset registered with a `FontLoader` when Paper +is first chosen, so neither the web build nor the other designs download it. +It draws the transcript's `•`, `→` and `✓` itself (no fallback fetch). Its +italic has no small-caps feature, so Paper's small-caps labels are set as +spaced capitals at a smaller size. diff --git a/app/fonts/source-serif-4/OFL.txt b/app/fonts/source-serif-4/OFL.txt new file mode 100644 index 00000000..ebe298c6 --- /dev/null +++ b/app/fonts/source-serif-4/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2014 - 2023 Adobe (http://www.adobe.com/), with Reserved Font Name ‘Source’. All Rights Reserved. Source is a trademark of Adobe in the United States and/or other countries. + +This Font Software is licensed under the SIL Open Font License, Version 1.1. + +This license is copied below, and is also available with a FAQ at: http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/app/fonts/source-serif-4/SourceSerif4-It.ttf b/app/fonts/source-serif-4/SourceSerif4-It.ttf new file mode 100644 index 00000000..e818087d Binary files /dev/null and b/app/fonts/source-serif-4/SourceSerif4-It.ttf differ diff --git a/app/fonts/source-serif-4/SourceSerif4-Regular.ttf b/app/fonts/source-serif-4/SourceSerif4-Regular.ttf new file mode 100644 index 00000000..964a2bf8 Binary files /dev/null and b/app/fonts/source-serif-4/SourceSerif4-Regular.ttf differ diff --git a/app/fonts/source-serif-4/SourceSerif4-Semibold.ttf b/app/fonts/source-serif-4/SourceSerif4-Semibold.ttf new file mode 100644 index 00000000..151e9a9d Binary files /dev/null and b/app/fonts/source-serif-4/SourceSerif4-Semibold.ttf differ diff --git a/app/fonts/source-serif-4/SourceSerif4-SemiboldIt.ttf b/app/fonts/source-serif-4/SourceSerif4-SemiboldIt.ttf new file mode 100644 index 00000000..7c54fcfe Binary files /dev/null and b/app/fonts/source-serif-4/SourceSerif4-SemiboldIt.ttf differ diff --git a/app/lib/features/artifacts/ui/artifact_controls_overlay.dart b/app/lib/features/artifacts/ui/artifact_controls_overlay.dart index f0c8bf5d..f615273b 100644 --- a/app/lib/features/artifacts/ui/artifact_controls_overlay.dart +++ b/app/lib/features/artifacts/ui/artifact_controls_overlay.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; +import '../../../ui/theme/app_design_tokens.dart'; /// Open, Copy and the file actions float over the top of the content: shown /// when the page opens and whenever the content is touched, hidden again after @@ -81,10 +82,19 @@ class _ArtifactControlsOverlayState extends State { child: DecoratedBox( decoration: BoxDecoration( color: surface, - borderRadius: BorderRadius.circular(12), - boxShadow: const [ - BoxShadow(color: Color(0x22000000), blurRadius: 6), - ], + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(12)), + // A flat design frames the bar instead of shadowing it. + border: switch (AppDesignTokens.of(context).frameSide) { + final side? => Border.fromBorderSide(side), + null => null, + }, + boxShadow: AppDesignTokens.of(context).flat + ? null + : const [ + BoxShadow(color: Color(0x22000000), blurRadius: 6), + ], ), child: Padding( padding: const EdgeInsets.symmetric( diff --git a/app/lib/features/artifacts/ui/artifact_tile.dart b/app/lib/features/artifacts/ui/artifact_tile.dart index f4b26f70..4b5999df 100644 --- a/app/lib/features/artifacts/ui/artifact_tile.dart +++ b/app/lib/features/artifacts/ui/artifact_tile.dart @@ -7,6 +7,7 @@ import '../domain/artifact_url.dart'; import 'artifact_row_labels.dart'; import 'artifact_thumbnail_image.dart'; import 'artifact_viewer_fetch.dart'; +import '../../../ui/theme/app_design_tokens.dart'; /// One artifact in the gallery grid: a thumbnail for an image, otherwise an /// icon for its kind of file, with its name and facts underneath. @@ -55,7 +56,12 @@ class _ArtifactTileState extends State { AspectRatio( aspectRatio: 4 / 3, child: ClipRRect( - borderRadius: const BorderRadius.vertical(top: Radius.circular(11)), + // Just inside the tile's frame: its corners less the line. + borderRadius: BorderRadius.vertical( + top: Radius.circular( + (AppDesignTokens.of(context).radius ?? 12) - 1, + ), + ), child: ColoredBox(color: surface, child: preview), ), ), @@ -81,7 +87,9 @@ class _ArtifactTileState extends State { final decorated = DecoratedBox( decoration: BoxDecoration( border: Border.all(color: border, width: widget.selected ? 2 : 1), - borderRadius: BorderRadius.circular(12), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(12)), ), child: body, ); @@ -94,7 +102,9 @@ class _ArtifactTileState extends State { child: Material( type: MaterialType.transparency, child: InkWell( - borderRadius: BorderRadius.circular(12), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(12)), onTap: onSelected == null ? null : tap, child: decorated, ), diff --git a/app/lib/features/chat/conversation/chat_background_task_card.dart b/app/lib/features/chat/conversation/chat_background_task_card.dart index 87c75ca3..4517828b 100644 --- a/app/lib/features/chat/conversation/chat_background_task_card.dart +++ b/app/lib/features/chat/conversation/chat_background_task_card.dart @@ -5,6 +5,7 @@ import '../domain/chat_shells.dart'; import '../domain/chat_task_metadata.dart'; import 'chat_task_metadata_view.dart'; import 'chat_task_presentation.dart'; +import '../../../ui/theme/app_design_tokens.dart'; /// One scan-friendly task card; only the explicit Details control loads output. class ChatBackgroundTaskCard extends StatelessWidget { @@ -32,7 +33,9 @@ class ChatBackgroundTaskCard extends StatelessWidget { final status = DecoratedBox( decoration: BoxDecoration( color: Theme.of(context).colorScheme.secondaryContainer, - borderRadius: BorderRadius.circular(8), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(8)), ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 5), @@ -128,7 +131,9 @@ class ChatBackgroundTaskCard extends StatelessWidget { DecoratedBox( decoration: BoxDecoration( color: Theme.of(context).colorScheme.surfaceContainerLowest, - borderRadius: BorderRadius.circular(8), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(8)), ), child: Padding( padding: const EdgeInsets.all(12), diff --git a/app/lib/features/chat/conversation/chat_background_task_output.dart b/app/lib/features/chat/conversation/chat_background_task_output.dart index 627a186b..c531967e 100644 --- a/app/lib/features/chat/conversation/chat_background_task_output.dart +++ b/app/lib/features/chat/conversation/chat_background_task_output.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import '../../../ui/text/monospace.dart'; import '../domain/chat_shells.dart'; import 'chat_task_presentation.dart'; +import '../../../ui/theme/app_design_tokens.dart'; const _outputVisibleLines = 12; const _outputLineHeight = 1.5; @@ -54,7 +55,9 @@ class ChatBackgroundTaskOutput extends StatelessWidget { DecoratedBox( decoration: BoxDecoration( color: Theme.of(context).colorScheme.surfaceContainerLowest, - borderRadius: BorderRadius.circular(8), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(8)), ), child: Padding( padding: const EdgeInsets.all(12), diff --git a/app/lib/features/chat/conversation/chat_bar_tint.dart b/app/lib/features/chat/conversation/chat_bar_tint.dart index 2fad08c4..082bd715 100644 --- a/app/lib/features/chat/conversation/chat_bar_tint.dart +++ b/app/lib/features/chat/conversation/chat_bar_tint.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import '../../../ui/adaptive/glass_pill.dart'; +import '../../../ui/theme/app_design_tokens.dart'; import '../ui/sessions/chat_color_palette.dart'; /// How strongly the chat's shade colours the bar's glass pieces over the @@ -70,7 +71,10 @@ ChatBarTint? chatBarTintOf(BuildContext context, String? name) { if (shade == null) return null; return ChatBarTint.from( shade: shade, - raised: Theme.of(context).colorScheme.surfaceContainerHigh, + // A design with its own panel fill (Paper's page) tints that instead. + raised: + AppDesignTokens.of(context).panel ?? + Theme.of(context).colorScheme.surfaceContainerHigh, dark: chatColorDarkSurface(context), inactive: ChatPaneActivity.inactiveOf(context), solid: MediaQuery.maybeHighContrastOf(context) ?? false, diff --git a/app/lib/features/chat/conversation/chat_composer_bar.dart b/app/lib/features/chat/conversation/chat_composer_bar.dart index acca0ace..863ea02d 100644 --- a/app/lib/features/chat/conversation/chat_composer_bar.dart +++ b/app/lib/features/chat/conversation/chat_composer_bar.dart @@ -34,6 +34,7 @@ import 'composer_focus_request.dart'; import 'composer_focus_restore.dart'; import 'chat_bar_tint.dart'; import 'composer_focus_ring.dart'; +import 'composer_underline.dart'; import '../../../ui/theme/app_design_tokens.dart'; import 'composer_running_border.dart'; import '../shell/chat_shell_command.dart'; @@ -1003,7 +1004,9 @@ class _ChatComposerBarState extends State { child: Align( heightFactor: 1, child: ConstrainedBox( - constraints: const BoxConstraints(maxWidth: kChatReadingWidth), + constraints: BoxConstraints( + maxWidth: chatReadingWidthOf(context), + ), child: Padding( key: const Key('chat-composer'), padding: EdgeInsetsDirectional.fromSTEB( @@ -1108,7 +1111,16 @@ class _ChatComposerBarState extends State { /// ([ComposerRunningBorder]); it is mounted only for that time. Widget _pill(BuildContext context, Widget child) { final accent = chatFocusRingColor(context, widget.chatColor); - final shape = AppDesignTokens.of(context).shape(_pillShape); + final tokens = AppDesignTokens.of(context); + if (tokens.composer == ComposerStyle.underline) { + return ComposerUnderline( + focus: _focus, + accent: accent, + running: widget.running, + child: child, + ); + } + final shape = tokens.shape(_pillShape); return Stack( children: [ ComposerFocusRing( diff --git a/app/lib/features/chat/conversation/chat_permission_card.dart b/app/lib/features/chat/conversation/chat_permission_card.dart index e853e85a..d25335f9 100644 --- a/app/lib/features/chat/conversation/chat_permission_card.dart +++ b/app/lib/features/chat/conversation/chat_permission_card.dart @@ -3,6 +3,7 @@ import 'package:flutter/material.dart'; import '../ui/transcript/native_disclosure.dart'; import 'chat_card_styles.dart'; import 'chat_permission_card_model.dart'; +import '../../../ui/theme/app_design_tokens.dart'; /// One recorded permission request as a native card. /// @@ -61,7 +62,9 @@ class ChatPermissionCard extends StatelessWidget { DecoratedBox( decoration: BoxDecoration( color: chatCardFillColor(context), - borderRadius: BorderRadius.circular(8), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(8)), ), child: Padding( padding: const EdgeInsets.all(8), @@ -104,7 +107,9 @@ class ChatPermissionCard extends StatelessWidget { return DecoratedBox( decoration: BoxDecoration( color: chatCardWarningFillColor(context), - borderRadius: BorderRadius.circular(8), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(8)), ), child: Padding( padding: const EdgeInsets.all(12), diff --git a/app/lib/features/chat/conversation/chat_reading_width.dart b/app/lib/features/chat/conversation/chat_reading_width.dart index de38d045..1c28ff33 100644 --- a/app/lib/features/chat/conversation/chat_reading_width.dart +++ b/app/lib/features/chat/conversation/chat_reading_width.dart @@ -1,13 +1,38 @@ import 'dart:math' as math; +import 'package:flutter/widgets.dart'; + +import '../../../ui/theme/app_design_tokens.dart'; +import '../ui/transcript/chat_message_bubble.dart'; +import '../ui/transcript/chat_turn_activity_view.dart'; + /// The widest the conversation's reading column grows: transcript rows and /// the floating composer share it, centred, so a wide window keeps a /// comfortable line length instead of stretching messages edge to edge. const double kChatReadingWidth = 760; -/// The space on each side of the centred reading column in [width]. -double chatReadingInset(double width) => - math.max(0, (width - kChatReadingWidth) / 2); +/// The reading column's width under the design at [context]: +/// [kChatReadingWidth], or, for a design that sets a reading measure +/// ([ReadingType.measure], Paper's ~70ch), that many reading characters plus +/// the rows' own side padding (16 each side, then the answer's inset), so +/// the text itself is that wide. It follows the operator's text scaling. +double chatReadingWidthOf(BuildContext context) { + final reading = AppDesignTokens.of(context).reading; + final measure = reading.measure; + if (measure == null) return kChatReadingWidth; + final size = MediaQuery.textScalerOf( + context, + ).scale(chatMessageTextStyle(context)?.fontSize ?? 16); + return measure * size * reading.figureWidth + + 2 * (16 + chatAgentContentInset); +} + +/// The space on each side of the centred reading column in [width], for a +/// column [readingWidth] wide. +double chatReadingInset( + double width, [ + double readingWidth = kChatReadingWidth, +]) => math.max(0, (width - readingWidth) / 2); /// The strip left of the reading column that holds an answer's Copy button, /// outside the answer itself. @@ -17,5 +42,9 @@ const double kChatCopyGutterWidth = 48; /// [kChatCopyGutterWidth] when the margin left of the centred reading column /// fits it, else 0, and Copy stays in the answer's footer (phones, narrow /// panes). -double chatCopyGutter(double width) => - chatReadingInset(width) >= kChatCopyGutterWidth ? kChatCopyGutterWidth : 0; +double chatCopyGutter( + double width, [ + double readingWidth = kChatReadingWidth, +]) => chatReadingInset(width, readingWidth) >= kChatCopyGutterWidth + ? kChatCopyGutterWidth + : 0; diff --git a/app/lib/features/chat/conversation/chat_task_presentation.dart b/app/lib/features/chat/conversation/chat_task_presentation.dart index 1a31a194..9560b912 100644 --- a/app/lib/features/chat/conversation/chat_task_presentation.dart +++ b/app/lib/features/chat/conversation/chat_task_presentation.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../domain/chat_task_metadata.dart'; import '../../../ui/text/monospace.dart'; +import '../../../ui/theme/app_design_tokens.dart'; Color taskSecondary(BuildContext context) => Theme.of(context).colorScheme.onSurfaceVariant; @@ -72,6 +73,9 @@ class ChatTaskSurface extends StatelessWidget { @override Widget build(BuildContext context) => Card.filled( + // A design with its own panel fill (Paper's page under a hairline) + // draws the card in it rather than a filled tone. + color: AppDesignTokens.of(context).panel, margin: EdgeInsets.zero, child: Padding(padding: padding, child: child), ); diff --git a/app/lib/features/chat/conversation/chat_thread_view.dart b/app/lib/features/chat/conversation/chat_thread_view.dart index 248eac05..0500deb3 100644 --- a/app/lib/features/chat/conversation/chat_thread_view.dart +++ b/app/lib/features/chat/conversation/chat_thread_view.dart @@ -1356,10 +1356,17 @@ class _ChatThreadViewState extends State with ChatFindHost { builder: (context, constraints) { // Rows keep to the centred reading column on a wide // window; the margins beside it still scroll the list. - final side = chatReadingInset(constraints.maxWidth); + final reading = chatReadingWidthOf(context); + final side = chatReadingInset( + constraints.maxWidth, + reading, + ); // Answers draw Copy in a strip left of the column; every // other row keeps to the column by insetting past it. - final gutter = chatCopyGutter(constraints.maxWidth); + final gutter = chatCopyGutter( + constraints.maxWidth, + reading, + ); final media = MediaQuery.paddingOf(context); // The date shows once per calendar day, above that day's // first row; each row itself shows only its time. diff --git a/app/lib/features/chat/conversation/chat_usage_limit_banner.dart b/app/lib/features/chat/conversation/chat_usage_limit_banner.dart index efce45db..2251b43f 100644 --- a/app/lib/features/chat/conversation/chat_usage_limit_banner.dart +++ b/app/lib/features/chat/conversation/chat_usage_limit_banner.dart @@ -11,6 +11,7 @@ import 'chat_claude_accounts_controller.dart'; import 'chat_composer_controller.dart'; import 'chat_schedule_time.dart'; import 'chat_thread_controller.dart'; +import '../../../ui/theme/app_design_tokens.dart'; /// Above the composer while the chat's account is out of quota, as Claude /// Code's own app shows it: "Out of usage credits" (or the refusal's own @@ -265,8 +266,16 @@ class _ChatUsageLimitBannerState extends State { padding: const EdgeInsetsDirectional.only(bottom: 8), child: Material( key: const Key('chat-usage-limit'), - color: scheme.surfaceContainerHigh, - borderRadius: BorderRadius.circular(16), + // A flat design's panel: its own fill and corners, framed. + color: AppDesignTokens.of( + context, + ).panelFill(scheme, scheme.surfaceContainerHigh), + shape: RoundedRectangleBorder( + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(16)), + side: AppDesignTokens.of(context).frameSide ?? BorderSide.none, + ), child: Padding( padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 12, 8), child: Column( @@ -356,7 +365,9 @@ class _ChatUsageLimitBannerState extends State { return MergeSemantics( child: InkWell( key: const Key('chat-usage-limit-auto-continue'), - borderRadius: BorderRadius.circular(8), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(8)), onTap: () => toggle(!enabled), child: Row( mainAxisSize: MainAxisSize.min, diff --git a/app/lib/features/chat/conversation/composer_underline.dart b/app/lib/features/chat/conversation/composer_underline.dart new file mode 100644 index 00000000..b037c4e5 --- /dev/null +++ b/app/lib/features/chat/conversation/composer_underline.dart @@ -0,0 +1,76 @@ +import 'package:flutter/material.dart'; + +import '../../../ui/adaptive/glass_bar.dart'; +import '../../../ui/theme/app_design_tokens.dart'; +import 'composer_focus_ring.dart'; + +/// The composer's writing area under a design whose composer is an +/// underline ([ComposerStyle.underline], Paper): the field and its controls +/// on the page's own colour (it floats over the transcript, so it is +/// opaque) above a hairline rule. While the field has focus the rule +/// thickens in [accent]; while a turn runs a thin moving line runs along it +/// instead, in place of the pill's travelling highlight. +class ComposerUnderline extends StatelessWidget { + const ComposerUnderline({ + super.key, + required this.focus, + required this.accent, + required this.running, + required this.child, + }); + + final FocusNode focus; + + /// The chat's focus colour (the host's primary for a chat with none). + final Color accent; + + /// Whether a turn is running. + final bool running; + final Widget child; + + @override + Widget build(BuildContext context) { + final scheme = Theme.of(context).colorScheme; + final tokens = AppDesignTokens.of(context); + return Material( + key: const Key('chat-composer-underline'), + color: tokens.panelFill(scheme, scheme.surface), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Padding( + padding: const EdgeInsets.all(GlassBarMetrics.fieldEdgeGap), + child: child, + ), + SizedBox( + height: ComposerFocusRing.ringWidth, + child: running + ? LinearProgressIndicator( + key: const Key('chat-composer-running-rule'), + minHeight: ComposerFocusRing.ringWidth, + color: accent, + backgroundColor: scheme.outlineVariant, + ) + : ListenableBuilder( + listenable: focus, + builder: (context, _) { + final focused = focus.hasFocus; + return Align( + alignment: Alignment.bottomCenter, + child: AnimatedContainer( + key: const Key('chat-composer-rule'), + duration: ComposerFocusRing.duration, + curve: Curves.easeOutCubic, + height: focused ? ComposerFocusRing.ringWidth : 1, + color: focused ? accent : scheme.outline, + ), + ); + }, + ), + ), + ], + ), + ); + } +} diff --git a/app/lib/features/chat/ui/sessions/chat_color_palette.dart b/app/lib/features/chat/ui/sessions/chat_color_palette.dart index 0afa93e1..e81b3c1d 100644 --- a/app/lib/features/chat/ui/sessions/chat_color_palette.dart +++ b/app/lib/features/chat/ui/sessions/chat_color_palette.dart @@ -1,12 +1,23 @@ import 'package:flutter/material.dart'; +import '../../../../ui/theme/app_design_tokens.dart'; import '../../domain/chat_colors.dart'; /// The host's own shade for a chat colour name, tuned for the current /// brightness: Material's standard swatches (a deeper tone on light surfaces, -/// a lighter one on dark), so the mark keeps its contrast in both. Null for no -/// (or an unknown) colour. +/// a lighter one on dark), so the mark keeps its contrast in both, quietened +/// to the design's [AppDesignTokens.chatColorSaturation] (Paper's ink tones). +/// Null for no (or an unknown) colour. Color? chatColorShade(BuildContext context, String? name) { + final shade = _materialShade(context, name); + if (shade == null) return null; + final saturation = AppDesignTokens.of(context).chatColorSaturation; + if (saturation >= 1) return shade; + final hsl = HSLColor.fromColor(shade); + return hsl.withSaturation(hsl.saturation * saturation).toColor(); +} + +Color? _materialShade(BuildContext context, String? name) { if (name == null || !chatColorNames.contains(name)) return null; final dark = Theme.of(context).brightness == Brightness.dark; final MaterialColor swatch = switch (name) { diff --git a/app/lib/features/chat/ui/transcript/chat_attachment_frame.dart b/app/lib/features/chat/ui/transcript/chat_attachment_frame.dart index f321cefa..96026b07 100644 --- a/app/lib/features/chat/ui/transcript/chat_attachment_frame.dart +++ b/app/lib/features/chat/ui/transcript/chat_attachment_frame.dart @@ -1,9 +1,12 @@ import 'package:flutter/material.dart'; +import '../../../../ui/theme/app_design_tokens.dart'; + /// Rounds an attachment thumbnail and draws a subtle hairline around it, so a /// dark screenshot on a dark page (or a light one on a light page) still reads /// as a separate object. The line sits over the image's edge, in the host's -/// own outline role. +/// own outline role. A design with its own corners ([AppDesignTokens.radius]) +/// rounds it with those. class ChatAttachmentFrame extends StatelessWidget { const ChatAttachmentFrame({ super.key, @@ -17,6 +20,7 @@ class ChatAttachmentFrame extends StatelessWidget { @override Widget build(BuildContext context) { final line = Theme.of(context).colorScheme.outlineVariant; + final radius = AppDesignTokens.of(context).corners(this.radius); return Container( key: const Key('chat-attachment-frame'), foregroundDecoration: BoxDecoration( diff --git a/app/lib/features/chat/ui/transcript/chat_attachment_gallery.dart b/app/lib/features/chat/ui/transcript/chat_attachment_gallery.dart index d3c38419..78582ab8 100644 --- a/app/lib/features/chat/ui/transcript/chat_attachment_gallery.dart +++ b/app/lib/features/chat/ui/transcript/chat_attachment_gallery.dart @@ -1,6 +1,7 @@ import 'package:flutter/widgets.dart'; import '../../../../core/api_gateway.dart'; +import '../../../../ui/theme/app_design_tokens.dart'; import '../../data/chat_attachment_images.dart'; import '../../domain/chat_attachment_image.dart'; import 'chat_attachment_thumbnail.dart'; @@ -12,7 +13,8 @@ bool chatPartIsThumbnail(JsonMap part) => chatImageSourceOf('${part['uri'] ?? ''}'.trim()) != null; /// The operator's attached images above their message, end-aligned like the -/// turn itself, wrapping onto further lines on a narrow pane. +/// turn itself (start-aligned under a manuscript's block quote), wrapping +/// onto further lines on a narrow pane. class ChatAttachmentGallery extends StatelessWidget { const ChatAttachmentGallery({ super.key, @@ -27,7 +29,10 @@ class ChatAttachmentGallery extends StatelessWidget { @override Widget build(BuildContext context) => Wrap( key: const Key('chat-attachment-gallery'), - alignment: WrapAlignment.end, + alignment: + AppDesignTokens.of(context).transcript == TranscriptStyle.manuscript + ? WrapAlignment.start + : WrapAlignment.end, spacing: 8, runSpacing: 8, children: [ diff --git a/app/lib/features/chat/ui/transcript/chat_attachment_thumbnail.dart b/app/lib/features/chat/ui/transcript/chat_attachment_thumbnail.dart index e38bc2bf..b60f3c4e 100644 --- a/app/lib/features/chat/ui/transcript/chat_attachment_thumbnail.dart +++ b/app/lib/features/chat/ui/transcript/chat_attachment_thumbnail.dart @@ -2,6 +2,7 @@ import 'dart:typed_data'; import 'package:flutter/material.dart'; import '../../../../ui/status/app_spinner.dart'; +import '../../../../ui/theme/app_design_tokens.dart'; import '../../data/chat_attachment_images.dart'; import 'chat_attachment_frame.dart'; @@ -139,7 +140,7 @@ class _ChatAttachmentThumbnailState extends State { type: MaterialType.transparency, child: InkWell( key: const Key('chat-attachment-thumbnail'), - borderRadius: _radius, + borderRadius: AppDesignTokens.of(context).corners(_radius), onTap: open, child: constrained, ), diff --git a/app/lib/features/chat/ui/transcript/chat_automated_prompt.dart b/app/lib/features/chat/ui/transcript/chat_automated_prompt.dart index 270ab826..23b89ad3 100644 --- a/app/lib/features/chat/ui/transcript/chat_automated_prompt.dart +++ b/app/lib/features/chat/ui/transcript/chat_automated_prompt.dart @@ -6,6 +6,8 @@ import '../../conversation/chat_schedule_time.dart'; import '../../domain/chat_prompt_origin.dart'; import 'chat_copy_button.dart'; import 'chat_hover_actions.dart'; +import 'paper/paper_editorial_note.dart'; +import 'paper/paper_quote.dart'; import 'terminal/terminal_glyphs.dart'; /// The header words of an automated prompt. @@ -67,7 +69,15 @@ class ChatAutomatedPromptCard extends StatelessWidget { ], ), ); - final card = AppDesignTokens.of(context).terminal + final transcript = AppDesignTokens.of(context).transcript; + final card = transcript == TranscriptStyle.manuscript + ? PaperEditorialNote( + label: label, + detail: detail, + body: body, + hasBody: prompt.body.trim().isNotEmpty, + ) + : transcript == TranscriptStyle.prompt ? _terminalLine(context, label, detail) : Material( key: const Key('chat-automated-prompt'), @@ -98,9 +108,11 @@ class ChatAutomatedPromptCard extends StatelessWidget { final copy = prompt.body.trim().isEmpty ? null : ChatHoverReveal(child: ChatCopyButton(text: prompt.body.trim())); - final footerInset = AppDesignTokens.of(context).terminal - ? 8 + terminalGlyphColumn(context) - : 14.0; + final footerInset = switch (transcript) { + TranscriptStyle.prompt => 8 + terminalGlyphColumn(context), + TranscriptStyle.manuscript => paperQuoteTextInset, + TranscriptStyle.bubbles => 14.0, + }; return ChatHoverRegion( child: Column( mainAxisSize: MainAxisSize.min, diff --git a/app/lib/features/chat/ui/transcript/chat_code_hover.dart b/app/lib/features/chat/ui/transcript/chat_code_hover.dart index 90c4e16f..b3c7ecfc 100644 --- a/app/lib/features/chat/ui/transcript/chat_code_hover.dart +++ b/app/lib/features/chat/ui/transcript/chat_code_hover.dart @@ -57,8 +57,15 @@ class ChatCodeHover { onEnter: (_) => _exit?.cancel(), onExit: (_) => scheduleHide(token), child: Material( - elevation: 3, - borderRadius: BorderRadius.circular(8), + // A floating piece, shaped as the design's menus are. + elevation: Theme.of(context).popupMenuTheme.elevation ?? 3, + shadowColor: Theme.of(context).popupMenuTheme.shadowColor, + color: Theme.of(context).popupMenuTheme.color, + shape: + Theme.of(context).popupMenuTheme.shape ?? + const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(8)), + ), child: ChatCopyButton(text: text, showLabel: true), ), ), diff --git a/app/lib/features/chat/ui/transcript/chat_markdown_view.dart b/app/lib/features/chat/ui/transcript/chat_markdown_view.dart index 4df4ea3d..da8f254b 100644 --- a/app/lib/features/chat/ui/transcript/chat_markdown_view.dart +++ b/app/lib/features/chat/ui/transcript/chat_markdown_view.dart @@ -284,7 +284,7 @@ class _ChatMarkdownViewState extends State { (part) => TextSpan(text: part), ), ), - style: const TextStyle(fontFamily: appMonospaceFamily), + style: _codeStyle(context), ), ), ), @@ -429,9 +429,14 @@ class _ChatMarkdownViewState extends State { ); } + // Beside a reading face (Paper's serif) the monospace runs large: it + // drops to about the serif's x-height. + final ambient = DefaultTextStyle.of(context).style.fontSize; + final reading = AppDesignTokens.of(context).reading.family != null; return TextSpan( style: TextStyle( fontFamily: appMonospaceFamily, + fontSize: reading && ambient != null ? ambient * 0.86 : null, // A span's background is painted over the selection highlight, so an // opaque fill hid a selected code span; a partial fill keeps code // distinct and lets the selection show through. @@ -525,7 +530,25 @@ class _ChatMarkdownViewState extends State { final text = Theme.of(context).textTheme; // A terminal prints headings at the text's own size, in bold; the top // level takes the accent colour. - if (AppDesignTokens.of(context).terminal) { + final transcript = AppDesignTokens.of(context).transcript; + // A manuscript sets headings like a book's: the reading face itself, + // semibold, a step or two larger, with a tighter line. + if (transcript == TranscriptStyle.manuscript) { + final ambient = DefaultTextStyle.of(context).style; + final size = ambient.fontSize ?? 16; + return ambient.copyWith( + fontSize: + size * + switch (level) { + 1 => 1.4, + 2 => 1.2, + _ => 1.0, + }, + fontWeight: FontWeight.w600, + height: 1.3, + ); + } + if (transcript == TranscriptStyle.prompt) { return _roleStyle( context, text.bodyLarge?.copyWith( @@ -542,6 +565,21 @@ class _ChatMarkdownViewState extends State { return _roleStyle(context, role); } + /// A code block's text: the bundled monospace face. A design with its + /// own reading type (Paper) sets code a step smaller than its prose and on + /// a tighter line, as a technical book does. + TextStyle _codeStyle(BuildContext context) { + const mono = TextStyle(fontFamily: appMonospaceFamily); + final reading = AppDesignTokens.of(context).reading; + if (reading.family == null) return mono; + final size = DefaultTextStyle.of(context).style.fontSize ?? 16; + return mono.copyWith( + fontSize: size * 0.82, + height: 1.45, + fontStyle: FontStyle.normal, + ); + } + /// Merges a host theme role into the ambient text style. TextStyle? _roleStyle(BuildContext context, TextStyle? role) => role == null ? null diff --git a/app/lib/features/chat/ui/transcript/chat_message_bubble.dart b/app/lib/features/chat/ui/transcript/chat_message_bubble.dart index ef7db957..464fba1f 100644 --- a/app/lib/features/chat/ui/transcript/chat_message_bubble.dart +++ b/app/lib/features/chat/ui/transcript/chat_message_bubble.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../../../../ui/theme/app_design_tokens.dart'; import '../sessions/chat_color_palette.dart'; +import 'paper/paper_quote.dart'; import 'terminal/terminal_prompt_line.dart'; /// How strongly a coloured chat's shade washes the operator's bubbles over @@ -45,8 +46,13 @@ class ChatUserBubble extends StatelessWidget { @override Widget build(BuildContext context) { - if (AppDesignTokens.of(context).terminal) { - return TerminalPromptLine(child: child); + switch (AppDesignTokens.of(context).transcript) { + case TranscriptStyle.prompt: + return TerminalPromptLine(child: child); + case TranscriptStyle.manuscript: + return PaperQuote(child: child); + case TranscriptStyle.bubbles: + break; } // A Material surface (not a bare DecoratedBox) so a disclosure ListTile // inside the bubble keeps its ink and background. @@ -75,9 +81,11 @@ class ChatAgentSurface extends StatelessWidget { } /// The transcript's reading text: the host's large body role, so answers read -/// at a comfortable size and still follow the operator's text scaling. -TextStyle? chatMessageTextStyle(BuildContext context) => - Theme.of(context).textTheme.bodyLarge; +/// at a comfortable size and still follow the operator's text scaling, in +/// the design's reading face and line height (Paper's serif). +TextStyle? chatMessageTextStyle(BuildContext context) => AppDesignTokens.of( + context, +).reading.apply(Theme.of(context).textTheme.bodyLarge); /// The empty-line gap between two paragraphs of a reply: about one line of /// body text at [fontSize] (else the ambient text size), scaled by the diff --git a/app/lib/features/chat/ui/transcript/chat_message_view.dart b/app/lib/features/chat/ui/transcript/chat_message_view.dart index c76216e2..e14c7062 100644 --- a/app/lib/features/chat/ui/transcript/chat_message_view.dart +++ b/app/lib/features/chat/ui/transcript/chat_message_view.dart @@ -18,6 +18,7 @@ import 'chat_link_text.dart'; import 'chat_message_bubble.dart'; import 'chat_turn_activity_view.dart'; import 'native_disclosure.dart'; +import 'paper/paper_quote.dart'; import 'terminal/terminal_glyphs.dart'; import 'chat_message_timestamp.dart'; import 'chat_read_aloud_button.dart'; @@ -79,11 +80,12 @@ class ChatMessageView extends StatelessWidget { // A wide window draws an answer's Copy in the gutter left of the reading // column; without room it trails the time in the answer's footer. final gutter = user ? 0.0 : ChatCopyGutter.of(context); - // A terminal design reads top to bottom like a CLI: the operator's - // prompt line starts at the same edge as the answer and spans its - // column. - final terminal = AppDesignTokens.of(context).terminal; - final trailingUser = user && !automated && !terminal; + // A terminal or manuscript transcript reads top to bottom: the + // operator's prompt line or block quote starts at the same edge as the + // answer and spans its column. + final transcript = AppDesignTokens.of(context).transcript; + final trailingUser = + user && !automated && transcript == TranscriptStyle.bubbles; // No visible role label: side and surface say who spoke and the row's // semantics label names the role. The operator's turn is a neutral bubble // that shrinks to its content; the agent's answer sits on the page with no @@ -101,7 +103,11 @@ class ChatMessageView extends StatelessWidget { explicitChildNodes: true, label: '$role message', child: Padding( - padding: const EdgeInsets.symmetric(vertical: 6), + // A manuscript leaves a little more air between turns, as a page + // spaces its paragraphs, since no bubble sets them apart. + padding: EdgeInsets.symmetric( + vertical: transcript == TranscriptStyle.manuscript ? 12 : 6, + ), child: LayoutBuilder( builder: (context, constraints) => Align( alignment: trailingUser @@ -119,7 +125,7 @@ class ChatMessageView extends StatelessWidget { child: automated ? _automatedTurn(origin, content) : user - ? _userTurn(content, body, origin, terminal: terminal) + ? _userTurn(content, body, origin, transcript: transcript) : _agentRow( context, content, @@ -147,8 +153,9 @@ class ChatMessageView extends StatelessWidget { List content, Widget body, ChatPromptOrigin origin, { - required bool terminal, + required TranscriptStyle transcript, }) { + final stacked = transcript != TranscriptStyle.bubbles; final thumbnails = [ for (final part in _partsOf(_userMessage)) if (_isFile(part) && chatPartIsThumbnail(part)) part, @@ -163,14 +170,21 @@ class ChatMessageView extends StatelessWidget { } return Column( mainAxisSize: MainAxisSize.min, - crossAxisAlignment: terminal + crossAxisAlignment: stacked ? CrossAxisAlignment.stretch : CrossAxisAlignment.end, children: [ if (thumbnails.isNotEmpty) - ChatAttachmentGallery( - parts: thumbnails, - images: images ?? _inlineImages, + Padding( + padding: EdgeInsetsDirectional.only( + start: transcript == TranscriptStyle.manuscript + ? paperQuoteTextInset + : 0, + ), + child: ChatAttachmentGallery( + parts: thumbnails, + images: images ?? _inlineImages, + ), ), if (thumbnails.isNotEmpty && content.isNotEmpty) const SizedBox(height: 6), @@ -179,16 +193,24 @@ class ChatMessageView extends StatelessWidget { // The delivery line and the time share one line under the bubble. if (footer.isNotEmpty || hasTimestamp || marked) ...[ const SizedBox(height: 2), - Wrap( - key: const Key('chat-message-footer'), - spacing: 8, - alignment: terminal ? WrapAlignment.start : WrapAlignment.end, - crossAxisAlignment: WrapCrossAlignment.center, - children: [ - ...footer, - if (marked) const ChatScheduledMark(), - if (hasTimestamp) timestamp, - ], + Padding( + // Under a manuscript the line starts at the quoted text. + padding: EdgeInsetsDirectional.only( + start: transcript == TranscriptStyle.manuscript + ? paperQuoteTextInset + : 0, + ), + child: Wrap( + key: const Key('chat-message-footer'), + spacing: 8, + alignment: stacked ? WrapAlignment.start : WrapAlignment.end, + crossAxisAlignment: WrapCrossAlignment.center, + children: [ + ...footer, + if (marked) const ChatScheduledMark(), + if (hasTimestamp) timestamp, + ], + ), ), ], ], diff --git a/app/lib/features/chat/ui/transcript/chat_turn_activity_view.dart b/app/lib/features/chat/ui/transcript/chat_turn_activity_view.dart index fdc5c9a8..0f0ff06f 100644 --- a/app/lib/features/chat/ui/transcript/chat_turn_activity_view.dart +++ b/app/lib/features/chat/ui/transcript/chat_turn_activity_view.dart @@ -9,6 +9,7 @@ import '../../../../ui/theme/app_design_tokens.dart'; import 'chat_response_pending.dart'; import 'chat_turn_activity_details.dart'; import 'chat_turn_chip.dart'; +import 'paper/paper_activity_note.dart'; import 'terminal/terminal_activity_rows.dart'; /// The activity control's content inset is shared with the rest of the reply. @@ -122,14 +123,25 @@ class _ChatTurnActivityViewState extends State { : DateTime.now().difference(started); final seconds = duration.inSeconds.clamp(0, 2147483647); final label = '${data.label}${widget.streaming ? ' ${seconds}s' : ''}'; - if (AppDesignTokens.of(context).terminal) { - return TerminalActivityRows( - data: data, - status: label, - streaming: widget.streaming, - seconds: seconds, - onOpen: _open, - ); + switch (AppDesignTokens.of(context).transcript) { + case TranscriptStyle.prompt: + return TerminalActivityRows( + data: data, + status: label, + streaming: widget.streaming, + seconds: seconds, + onOpen: _open, + ); + case TranscriptStyle.manuscript: + return PaperActivityNote( + data: data, + status: label, + streaming: widget.streaming, + failed: data.failed, + onOpen: _open, + ); + case TranscriptStyle.bubbles: + break; } // Desktop hover hugs the label; phones keep the full-width touch row. final compact = prefersCompactHitTargets(context); diff --git a/app/lib/features/chat/ui/transcript/chat_turn_chip.dart b/app/lib/features/chat/ui/transcript/chat_turn_chip.dart index 8a5b1859..98e5b244 100644 --- a/app/lib/features/chat/ui/transcript/chat_turn_chip.dart +++ b/app/lib/features/chat/ui/transcript/chat_turn_chip.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../../../../ui/adaptive/app_popups.dart'; import 'chat_turn_activity_view.dart'; +import '../../../../ui/theme/app_design_tokens.dart'; /// The quiet chip under an agent turn (its tools, its permissions) and the /// native sheet it opens. @@ -103,7 +104,9 @@ class _ChatTurnChipState extends State { padding: const EdgeInsets.only(top: 2), child: InkWell( key: widget.chipKey, - borderRadius: BorderRadius.circular(8), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(8)), onTap: _show, child: Padding( padding: const EdgeInsets.symmetric( diff --git a/app/lib/features/chat/ui/transcript/paper/paper_activity_note.dart b/app/lib/features/chat/ui/transcript/paper/paper_activity_note.dart new file mode 100644 index 00000000..229f0963 --- /dev/null +++ b/app/lib/features/chat/ui/transcript/paper/paper_activity_note.dart @@ -0,0 +1,108 @@ +import 'package:flutter/material.dart'; + +import '../../../../../ui/adaptive/platform.dart'; +import '../../../domain/chat_tool_calls.dart'; +import '../../../domain/chat_turn_activity.dart'; +import '../chat_message_bubble.dart'; +import '../chat_response_pending.dart'; + +/// How many distinct tool names a marginal note lists before "and more". +const int paperActivityNamedTools = 3; + +/// A turn's activity under a manuscript transcript: a small muted note in +/// the margin of the answer, as a book prints a side note. A short rule, +/// then the turn's status in small italic reading type and, once settled, +/// the tools it used ("Used 6 tools — Bash, Read, Edit"). The note is one +/// button that opens the activity details, like the Default design's line. +class PaperActivityNote extends StatelessWidget { + const PaperActivityNote({ + super.key, + required this.data, + required this.status, + required this.streaming, + required this.failed, + required this.onOpen, + }); + + final ChatTurnActivityData data; + + /// The turn's one-line status (with its running seconds while streaming). + final String status; + final bool streaming; + final bool failed; + final VoidCallback onOpen; + + /// The note's words: the status, then the distinct tools it used. + static String noteText(ChatTurnActivityData data, String status) { + final names = []; + for (final call in data.tools) { + final name = chatToolLabel(call); + if (!names.contains(name)) names.add(name); + } + if (names.isEmpty) return status; + final shown = names.take(paperActivityNamedTools).join(', '); + final more = names.length > paperActivityNamedTools ? ', …' : ''; + return '$status — $shown$more'; + } + + @override + Widget build(BuildContext context) { + final scheme = Theme.of(context).colorScheme; + final color = failed && !streaming ? scheme.error : scheme.onSurfaceVariant; + final reading = chatMessageTextStyle(context); + final style = reading?.copyWith( + fontSize: (reading.fontSize ?? 16) * 0.82, + fontStyle: FontStyle.italic, + height: 1.3, + color: color, + ); + final compact = prefersCompactHitTargets(context); + final text = streaming ? status : noteText(data, status); + return Semantics( + button: true, + label: '$status, expand for details', + excludeSemantics: true, + onTap: onOpen, + child: Align( + alignment: AlignmentDirectional.centerStart, + widthFactor: 1, + child: InkWell( + key: const Key('chat-turn-activity'), + onTap: onOpen, + borderRadius: const BorderRadius.all(Radius.circular(4)), + child: ConstrainedBox( + constraints: BoxConstraints(minHeight: compact ? 32 : 40), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + child: Row( + key: const Key('chat-paper-activity-note'), + mainAxisSize: compact ? MainAxisSize.min : MainAxisSize.max, + children: [ + if (streaming) + ExcludeSemantics( + child: DefaultTextStyle.merge( + style: TextStyle(color: scheme.primary), + child: const ChatResponsePending(), + ), + ) + else + // The margin rule a side note hangs from. + Container(width: 16, height: 1, color: scheme.outline), + const SizedBox(width: 8), + Flexible( + child: Text( + text, + maxLines: 1, + overflow: TextOverflow.ellipsis, + style: style, + ), + ), + ], + ), + ), + ), + ), + ), + ); + } +} diff --git a/app/lib/features/chat/ui/transcript/paper/paper_editorial_note.dart b/app/lib/features/chat/ui/transcript/paper/paper_editorial_note.dart new file mode 100644 index 00000000..63d19300 --- /dev/null +++ b/app/lib/features/chat/ui/transcript/paper/paper_editorial_note.dart @@ -0,0 +1,78 @@ +import 'package:flutter/material.dart'; + +import '../chat_message_bubble.dart'; +import 'paper_quote.dart'; + +/// A prompt the agent or the server sent (a follow-up, an auto-continue) +/// under a manuscript transcript: not a card but a small italic editorial +/// note, as an editor's aside is set in a book. A spaced small-caps header +/// names what sent it, then the prompt in the muted italic reading face, set +/// in from the page like the operator's quoted words. +class PaperEditorialNote extends StatelessWidget { + const PaperEditorialNote({ + super.key, + required this.label, + required this.detail, + required this.body, + required this.hasBody, + }); + + /// What sent the prompt ("Follow-up from agent"). + final String label; + + /// When or why it was sent, or null. + final String? detail; + final Widget body; + final bool hasBody; + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final muted = theme.colorScheme.onSurfaceVariant; + final caps = paperSmallCapsStyle(context); + final reading = chatMessageTextStyle(context); + final note = reading?.copyWith( + fontSize: (reading.fontSize ?? 16) * 0.92, + fontStyle: FontStyle.italic, + height: 1.45, + color: muted, + ); + final header = SelectionContainer.disabled( + child: Text.rich( + key: const Key('chat-automated-prompt-header'), + TextSpan( + children: [ + TextSpan(text: label.toUpperCase(), style: caps), + if (detail != null) + TextSpan( + text: ' · $detail', + style: caps?.copyWith(letterSpacing: 0.2), + ), + ], + ), + ), + ); + return Material( + key: const Key('chat-automated-prompt'), + type: MaterialType.transparency, + child: Padding( + padding: const EdgeInsetsDirectional.only( + start: paperQuoteTextInset, + top: 2, + bottom: 2, + ), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + header, + if (hasBody) ...[ + const SizedBox(height: 4), + DefaultTextStyle.merge(style: note, child: body), + ], + ], + ), + ), + ); + } +} diff --git a/app/lib/features/chat/ui/transcript/paper/paper_quote.dart b/app/lib/features/chat/ui/transcript/paper/paper_quote.dart new file mode 100644 index 00000000..daa69410 --- /dev/null +++ b/app/lib/features/chat/ui/transcript/paper/paper_quote.dart @@ -0,0 +1,100 @@ +import 'package:flutter/material.dart'; + +import '../../sessions/chat_color_palette.dart'; +import '../chat_message_bubble.dart'; + +/// How far a manuscript's block quote (the operator's turn) sits in from the +/// answer's text edge, so the reader sees whose words they are by indent. +const double paperQuoteIndent = 16; + +/// The width of the quote's rule. +const double paperQuoteRule = 2; + +/// The gap between the rule and the quoted text. +const double paperQuoteGap = 12; + +/// Where the quoted text starts, from the row's edge: the footer under the +/// quote (its delivery line and time) starts here too. +const double paperQuoteTextInset = + paperQuoteIndent + paperQuoteRule + paperQuoteGap; + +/// The words of the small-caps label above the operator's turn. +const String paperQuoteLabel = 'You'; + +/// The style of a manuscript's small editorial labels: italic capitals set +/// small and spaced, the way a book sets small caps (the serif's italic has +/// no small-caps feature, so they are spaced capitals), in the muted ink. +TextStyle? paperSmallCapsStyle(BuildContext context) { + final theme = Theme.of(context); + final reading = chatMessageTextStyle(context); + final size = (reading?.fontSize ?? 16) * 0.72; + return reading?.copyWith( + fontSize: size, + fontStyle: FontStyle.italic, + letterSpacing: size * 0.12, + height: 1.2, + color: theme.colorScheme.onSurfaceVariant, + ); +} + +/// The operator's turn under a manuscript transcript: an indented block +/// quote with a thin rule in the chat's colour (the outline for a chat with +/// none) and a small-caps "You" above it, instead of a bubble. It spans the +/// reading column, like the answer below it. +class PaperQuote extends StatelessWidget { + const PaperQuote({super.key, required this.child}); + + final Widget child; + + @override + Widget build(BuildContext context) { + final scheme = Theme.of(context).colorScheme; + final shade = chatColorShade(context, ChatBubbleColor.of(context)); + return Material( + key: const Key('chat-paper-quote'), + type: MaterialType.transparency, + child: Padding( + padding: const EdgeInsetsDirectional.only(start: paperQuoteIndent), + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + ExcludeSemantics( + child: SelectionContainer.disabled( + child: Padding( + padding: const EdgeInsetsDirectional.only( + start: paperQuoteRule + paperQuoteGap, + bottom: 4, + ), + child: Text( + paperQuoteLabel.toUpperCase(), + key: const Key('chat-paper-quote-label'), + style: paperSmallCapsStyle(context), + ), + ), + ), + ), + DecoratedBox( + decoration: BoxDecoration( + border: BorderDirectional( + start: BorderSide( + color: shade ?? scheme.outline, + width: paperQuoteRule, + ), + ), + ), + child: Padding( + padding: const EdgeInsetsDirectional.only( + start: paperQuoteGap, + top: 2, + bottom: 2, + ), + child: child, + ), + ), + ], + ), + ), + ); + } +} diff --git a/app/lib/features/graph/painting/edge_highlight_layer.dart b/app/lib/features/graph/painting/edge_highlight_layer.dart index c00e5bcb..1cda2ae9 100644 --- a/app/lib/features/graph/painting/edge_highlight_layer.dart +++ b/app/lib/features/graph/painting/edge_highlight_layer.dart @@ -15,6 +15,7 @@ class EdgeHighlightPainter extends CustomPainter { required this.endpoints, required this.color, required this.strokeWidth, + this.glowRadius = 14, }); final EdgeRoute route; @@ -26,13 +27,17 @@ class EdgeHighlightPainter extends CustomPainter { /// The highlighted stroke; the halo is wider. final double strokeWidth; + /// The corner radius of the glow around each endpoint stage: the stage + /// card's own corners plus the glow's spread. + final double glowRadius; + @override void paint(Canvas canvas, Size size) { final glow = Paint()..color = color.withValues(alpha: 0.18); for (final box in endpoints) { final rect = Rect.fromLTWH(box.x, box.y, box.width, box.height); canvas.drawRRect( - RRect.fromRectAndRadius(rect.inflate(5), const Radius.circular(14)), + RRect.fromRectAndRadius(rect.inflate(5), Radius.circular(glowRadius)), glow, ); } @@ -79,6 +84,7 @@ class EdgeHighlightPainter extends CustomPainter { oldDelegate.route != route || oldDelegate.color != color || oldDelegate.strokeWidth != strokeWidth || + oldDelegate.glowRadius != glowRadius || oldDelegate.endpoints.length != endpoints.length || !_sameBoxes(oldDelegate.endpoints, endpoints); diff --git a/app/lib/features/graph/widgets/graph_edge_hover.dart b/app/lib/features/graph/widgets/graph_edge_hover.dart index 85db53d7..db5c239d 100644 --- a/app/lib/features/graph/widgets/graph_edge_hover.dart +++ b/app/lib/features/graph/widgets/graph_edge_hover.dart @@ -1,6 +1,7 @@ import 'package:flutter/gestures.dart' show PointerDeviceKind; import 'package:flutter/material.dart'; +import '../../../ui/theme/app_design_tokens.dart'; import '../domain/graph_protocol.dart'; import '../layout/layout_models.dart'; import '../painting/edge_highlight_layer.dart'; @@ -160,6 +161,7 @@ class _GraphEdgeHoverState extends State { final size = overlay.size; final theme = Theme.of(context); final colors = theme.colorScheme; + final tokens = AppDesignTokens.of(context); const gap = 14.0; final flipX = local.dx > size.width * 0.6; final flipY = local.dy > size.height * 0.75; @@ -174,8 +176,10 @@ class _GraphEdgeHoverState extends State { child: Material( key: const Key('graph-edge-tooltip'), color: colors.inverseSurface, - elevation: 2, - borderRadius: BorderRadius.circular(6), + // A floating piece: the design's menu elevation and corners. + elevation: theme.popupMenuTheme.elevation ?? 2, + shadowColor: theme.popupMenuTheme.shadowColor, + borderRadius: tokens.corners(BorderRadius.circular(6)), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 6), child: Text( @@ -216,6 +220,12 @@ Widget graphEdgeHighlight({ endpoints: endpoints, color: Theme.of(context).colorScheme.primary, strokeWidth: edgeWidth * 2.5, + // A design's own corners (the stage cards take them) plus the + // glow's 5px spread; the Default keeps its rounder glow. + glowRadius: switch (AppDesignTokens.of(context).radius) { + final radius? => radius + 5, + null => 14, + }, ), ), ); @@ -270,7 +280,9 @@ Widget graphEdgeLabel({ : DecoratedBox( decoration: BoxDecoration( color: colors.primaryContainer, - borderRadius: BorderRadius.circular(4), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(4)), boxShadow: [ BoxShadow(color: colors.primaryContainer, spreadRadius: 2), ], diff --git a/app/lib/features/runs/ui/run_failure_banner.dart b/app/lib/features/runs/ui/run_failure_banner.dart index 034d14e8..863fffeb 100644 --- a/app/lib/features/runs/ui/run_failure_banner.dart +++ b/app/lib/features/runs/ui/run_failure_banner.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../../../core/api_gateway.dart'; import '../domain/run_outcome_line.dart'; +import '../../../ui/theme/app_design_tokens.dart'; /// The run Summary's prominent "Why it failed" note: a failed run's recorded /// failure reason (else its diagnostic), selectable, at the top of the @@ -29,7 +30,9 @@ class RunFailureBanner extends StatelessWidget { decoration: ShapeDecoration( color: scheme.errorContainer, shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(12), + borderRadius: AppDesignTokens.of( + context, + ).corners(BorderRadius.circular(12)), ), ), child: Padding( diff --git a/app/lib/features/settings/settings_design_section.dart b/app/lib/features/settings/settings_design_section.dart index 641cb258..4e8c5c6e 100644 --- a/app/lib/features/settings/settings_design_section.dart +++ b/app/lib/features/settings/settings_design_section.dart @@ -10,8 +10,9 @@ import 'settings_theme.dart'; const designSectionTitle = 'Design'; const designSectionFooter = 'Saved on this device only and applied at once. Light and dark follow ' - 'the system under every design; Terminal uses its monospace font ' - 'instead of the Font choice below.'; + 'the system under every design. Terminal uses its monospace font ' + 'instead of the Font choice below; Paper keeps that font for the ' + 'interface and sets reading text in its own serif.'; const designSaveFailedText = 'Not saved on this device; it applies until reload.'; @@ -53,9 +54,60 @@ class SettingsDesignSection extends StatelessWidget { value: design, title: Text(design.label), subtitle: Text(design.description), + secondary: DesignSwatchPreview( + swatch: design.swatch(Theme.of(context).brightness), + ), ), ], ), ), ); } + +/// A design's small preview in the picker: its page with a line of its ink +/// and a dot of its accent, framed by a hairline. +class DesignSwatchPreview extends StatelessWidget { + const DesignSwatchPreview({super.key, required this.swatch}); + + final DesignSwatch swatch; + + @override + Widget build(BuildContext context) => ExcludeSemantics( + child: Container( + width: 48, + height: 32, + decoration: BoxDecoration( + color: swatch.page, + borderRadius: const BorderRadius.all(Radius.circular(6)), + border: Border.all(color: Theme.of(context).colorScheme.outlineVariant), + ), + padding: const EdgeInsets.all(8), + child: Row( + children: [ + Expanded( + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container(height: 2, color: swatch.ink), + FractionallySizedBox( + widthFactor: 0.6, + child: Container(height: 2, color: swatch.ink), + ), + ], + ), + ), + const SizedBox(width: 4), + Container( + width: 6, + height: 6, + decoration: BoxDecoration( + color: swatch.accent, + shape: BoxShape.circle, + ), + ), + ], + ), + ), + ); +} diff --git a/app/lib/features/settings/settings_group.dart b/app/lib/features/settings/settings_group.dart index 1649d19f..1923aa04 100644 --- a/app/lib/features/settings/settings_group.dart +++ b/app/lib/features/settings/settings_group.dart @@ -52,9 +52,10 @@ class SettingsGroup extends StatelessWidget { if (children.isNotEmpty) Material( type: MaterialType.card, - color: tokens.flat - ? theme.colorScheme.surfaceContainerLow - : theme.colorScheme.surfaceContainer, + color: tokens.panelFill( + theme.colorScheme, + theme.colorScheme.surfaceContainer, + ), elevation: 0, shape: RoundedRectangleBorder( borderRadius: tokens.corners( diff --git a/app/lib/features/settings/settings_page_chrome.dart b/app/lib/features/settings/settings_page_chrome.dart index cd4adef8..1173a0fd 100644 --- a/app/lib/features/settings/settings_page_chrome.dart +++ b/app/lib/features/settings/settings_page_chrome.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; +import '../../ui/theme/app_design_tokens.dart'; import 'settings_section.dart'; /// The Settings search field: filters the sections as the operator types. @@ -35,7 +36,11 @@ class SettingsSearchField extends StatelessWidget { onChanged(''); }, ), - border: const OutlineInputBorder(), + border: OutlineInputBorder( + borderRadius: AppDesignTokens.of( + context, + ).corners(const BorderRadius.all(Radius.circular(4))), + ), ), ), ); diff --git a/app/lib/shell/attention_badge.dart b/app/lib/shell/attention_badge.dart index 3de5d619..94870e70 100644 --- a/app/lib/shell/attention_badge.dart +++ b/app/lib/shell/attention_badge.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import '../features/attention/domain/attention_models.dart'; import '../ui/motion/motion.dart'; +import '../ui/theme/app_design_tokens.dart'; /// A generic attention count, separate from the Runs tab's status counts. /// @@ -116,7 +117,9 @@ class ActivityBadge extends StatelessWidget { child: DecoratedBox( decoration: ShapeDecoration( color: color, - shape: const StadiumBorder(), + // A design's own corners (Terminal's square badge); the + // Default keeps the round count. + shape: AppDesignTokens.of(context).shape(const StadiumBorder()), ), child: Padding( padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 1), diff --git a/app/lib/ui/adaptive/app_popups.dart b/app/lib/ui/adaptive/app_popups.dart index e46c0e26..95822bab 100644 --- a/app/lib/ui/adaptive/app_popups.dart +++ b/app/lib/ui/adaptive/app_popups.dart @@ -169,12 +169,21 @@ class _AnchoredMenuRoute extends PopupRoute { label: label, child: Material( key: const ValueKey('app-choice-menu'), - elevation: 3, + // A design's menus (Terminal's flat frame, Paper's whisper + // of shadow) shape this panel too. + elevation: Theme.of(context).popupMenuTheme.elevation ?? 3, + shadowColor: Theme.of(context).popupMenuTheme.shadowColor, // A step above a window's own surface, so the panel reads // as raised when it opens over one. - color: colors.surfaceContainerHigh, + color: + Theme.of(context).popupMenuTheme.color ?? + colors.surfaceContainerHigh, surfaceTintColor: Colors.transparent, - borderRadius: BorderRadius.circular(12), + shape: + Theme.of(context).popupMenuTheme.shape ?? + const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(12)), + ), clipBehavior: Clip.antiAlias, child: Padding( padding: const EdgeInsets.symmetric(vertical: 8), diff --git a/app/lib/ui/adaptive/glass_pill.dart b/app/lib/ui/adaptive/glass_pill.dart index 334a62cc..a9000ae1 100644 --- a/app/lib/ui/adaptive/glass_pill.dart +++ b/app/lib/ui/adaptive/glass_pill.dart @@ -71,7 +71,7 @@ class GlassPill extends StatelessWidget { final Color base; final Color edge; final scheme = Theme.of(context).colorScheme; - base = flat ? scheme.surfaceContainerLow : scheme.surfaceContainerHigh; + base = tokens.panelFill(scheme, scheme.surfaceContainerHigh); edge = flat ? tokens.frame ?? scheme.outline : scheme.outlineVariant; final opaque = fill ?? (solid ? base : base.withValues(alpha: fillOpacity)); final color = opaque.withValues(alpha: opaque.a * reveal); diff --git a/app/lib/ui/layout/app_list_row.dart b/app/lib/ui/layout/app_list_row.dart index b1199cfa..3dfadb1a 100644 --- a/app/lib/ui/layout/app_list_row.dart +++ b/app/lib/ui/layout/app_list_row.dart @@ -136,6 +136,15 @@ class AppListRow extends StatelessWidget { alpha: Theme.of(context).brightness == Brightness.dark ? 0.12 : 0.07, ); + /// How strongly a flat design's open row washes its bar colour over the + /// page: Terminal's framed row strongly, Paper's unframed wash a little + /// lighter (its frameless row still stands well apart from tinted rows). + static double _washAlpha(SelectedRowStyle style, bool dark) => + switch (style) { + SelectedRowStyle.washed => dark ? .22 : .15, + _ => dark ? .26 : .2, + }; + /// The open row's fill is Material `secondaryContainer`. static Color selectedColor(BuildContext context) => Theme.of(context).colorScheme.secondaryContainer; @@ -188,22 +197,26 @@ class AppListRow extends StatelessWidget { ), ); final tint = tintFor(context, accent); - // A terminal design's flat surfaces make a tonal fill too faint - // beside tinted rows: the open row takes its bar colour, stronger, - // and a hairline frame (below). - final framed = selected && AppDesignTokens.of(context).terminal; + // How the design marks the open row: Material's tonal fill, or + // (on a flat design, where a tonal fill is too faint beside tinted + // rows) its bar colour washed over the page, stronger, with a + // hairline frame in it when the design frames it (below). + final rowStyle = AppDesignTokens.of(context).selectedRow; + final washed = selected && rowStyle != SelectedRowStyle.tonal; + final framed = selected && rowStyle == SelectedRowStyle.framed; final frameColor = selectionAccent ?? accent ?? Theme.of(context).colorScheme.primary; final surface = Material( key: appListRowSurfaceKey, - color: framed + color: washed ? Color.alphaBlend( frameColor.withValues( - alpha: Theme.of(context).brightness == Brightness.dark - ? .26 - : .2, + alpha: _washAlpha( + rowStyle, + Theme.of(context).brightness == Brightness.dark, + ), ), Theme.of(context).scaffoldBackgroundColor, ) diff --git a/app/lib/ui/theme/app_design.dart b/app/lib/ui/theme/app_design.dart index e6e1c2b8..df538afe 100644 --- a/app/lib/ui/theme/app_design.dart +++ b/app/lib/ui/theme/app_design.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'app_design_tokens.dart'; import 'app_theme.dart'; +import 'paper_theme.dart'; import 'terminal_theme.dart'; /// An app-wide design: how every surface is shaped, typed and coloured, not @@ -9,8 +10,18 @@ import 'terminal_theme.dart'; /// its [AppDesignTokens], so widgets that draw design-specific shapes read the /// tokens instead of hard-coding one look. /// -/// Adding a design means one more value here and its theme builder; the -/// Settings picker lists [AppDesign.values]. +/// Adding a design: +/// 1. add a value here with a stable [id], a [label] and a one-line +/// [description] (the Settings picker lists [AppDesign.values]); +/// 2. write its theme builder (`_theme.dart` beside this file, with a +/// palette and, when it needs one, its own typography) and return it from +/// [light] and [dark]; +/// 3. give the theme an [AppDesignTokens] extension: set only the tokens it +/// changes (corners, flat surfaces, frame, panel fill, transcript, +/// composer and selected-row styles, reading type); every token defaults +/// to the Default look; +/// 4. give it a [swatch] for the picker and say whether it [usesInterfaceFont]. +/// Widgets read the tokens, so most surfaces follow without per-widget code. enum AppDesign { /// The app's own Material look. standard('default', 'Default', 'The app’s Material look.'), @@ -21,6 +32,14 @@ enum AppDesign { 'terminal', 'Terminal', 'Monospace, flat frames and prompt-style chat, like a CLI agent.', + ), + + /// A calm reading look: a warm paper page, a serif for reading, ink + /// colours, hairline rules and the chat set as a typeset page. + paper( + 'paper', + 'Paper', + 'Warm paper, serif reading text and ink colours; calm for long reads.', ); const AppDesign(this.id, this.label, this.description); @@ -47,14 +66,76 @@ enum AppDesign { ThemeData light({String? fontFamily}) => switch (this) { standard => appLightTheme(fontFamily: fontFamily), terminal => terminalTheme(Brightness.light), + paper => paperTheme(Brightness.light, fontFamily: fontFamily), }; /// The design's dark theme; see [light]. ThemeData dark({String? fontFamily}) => switch (this) { standard => appDarkTheme(fontFamily: fontFamily), terminal => terminalTheme(Brightness.dark), + paper => paperTheme(Brightness.dark, fontFamily: fontFamily), }; - /// Whether the device's interface font applies under this design. - bool get usesInterfaceFont => this == standard; + /// Whether the device's interface font applies under this design (Paper + /// keeps it for its interface text and sets reading text in its serif). + bool get usesInterfaceFont => this != terminal; + + /// The picker's preview: the design's page, ink and accent in [brightness], + /// without building its theme. + DesignSwatch swatch(Brightness brightness) { + final dark = brightness == Brightness.dark; + return switch (this) { + standard => + dark + ? const DesignSwatch( + Color(0xFF141416), + Color(0xFFE6E0E9), + Color(0xFFCFBDFE), + ) + : const DesignSwatch( + Color(0xFFFDF7FF), + Color(0xFF1D1B20), + Color(0xFF65558F), + ), + terminal => + dark + ? const DesignSwatch( + Color(0xFF0B0B0B), + Color(0xFFD7D7D2), + Color(0xFF8CC38F), + ) + : const DesignSwatch( + Color(0xFFF7F6F1), + Color(0xFF1E1E1C), + Color(0xFF2F7434), + ), + paper => + dark + ? const DesignSwatch( + Color(0xFF1E1B17), + Color(0xFFE9E1D3), + Color(0xFF9DB4DC), + ) + : const DesignSwatch( + Color(0xFFF8F4EB), + Color(0xFF221E19), + Color(0xFF2C4F86), + ), + }; + } +} + +/// A design's three defining colours, for the picker's small preview. +@immutable +class DesignSwatch { + const DesignSwatch(this.page, this.ink, this.accent); + + /// The page (scaffold) colour. + final Color page; + + /// The main text colour. + final Color ink; + + /// The accent (primary) colour. + final Color accent; } diff --git a/app/lib/ui/theme/app_design_styles.dart b/app/lib/ui/theme/app_design_styles.dart new file mode 100644 index 00000000..0e757293 --- /dev/null +++ b/app/lib/ui/theme/app_design_styles.dart @@ -0,0 +1,93 @@ +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; + +/// How the chat transcript draws a conversation. Each design picks one; the +/// transcript widgets branch on it, never on the design itself. +enum TranscriptStyle { + /// The operator's turns as bubbles on the trailing side, the agent's + /// answers on the page and its activity as a one-line button (Default). + bubbles, + + /// A CLI's prompt line, glyph-led tool lines and bracketed injected + /// prompts, every turn starting at the same edge (Terminal). + prompt, + + /// A typeset page: the operator's turns as indented block quotes under a + /// small-caps label, answers as prose, activity as a muted marginal note + /// and injected prompts as italic editorial notes (Paper). + manuscript, +} + +/// How the chat composer frames its writing area. +enum ComposerStyle { + /// A floating pill (frosted, or flat and framed under a flat design) in + /// the design's corners, with a focus ring along its edge. + pill, + + /// An open writing area on the page with a rule beneath it that takes + /// the accent while the field has focus. + underline, +} + +/// How a list (AppListRow) marks the row that is open. Every style keeps +/// the leading bar in the row's accent; they differ in the fill and frame. +enum SelectedRowStyle { + /// Material's tonal `secondaryContainer` fill (Default). + tonal, + + /// The accent washed over the page, stronger than a tinted row, inside a + /// hairline frame in the accent (Terminal). + framed, + + /// The accent washed over the page, without a frame (Paper). + washed, +} + +/// The typography of reading text: chat messages, markdown answers and +/// documents. Interface text (navigation, buttons, chips, labels, metadata) +/// keeps the theme's own text roles. +@immutable +class ReadingType { + const ReadingType({ + this.family, + this.height, + this.measure, + this.scale = 1, + this.figureWidth = 0.5, + }); + + /// The reading face; null keeps the theme's body face. + final String? family; + + /// The line height as a multiple of the font size; null keeps the role's. + final double? height; + + /// The widest reading column in `ch` (widths of the digit zero in the + /// reading face); null keeps the app's fixed reading width. + final double? measure; + + /// The reading size relative to the theme's `bodyLarge`. + final double scale; + + /// The width of the reading face's digit zero, in ems: what one `ch` of + /// [measure] is worth (half an em for Source Serif's figures). + final double figureWidth; + + /// [base] in the reading face, size and line height. + TextStyle? apply(TextStyle? base) { + if (base == null) return null; + if (family == null && height == null && scale == 1) return base; + final size = base.fontSize; + return base.copyWith( + fontFamily: family, + // The interface face stays as the fallback, so a glyph the reading + // face lacks still draws from a bundled family. + fontFamilyFallback: family == null || base.fontFamily == null + ? null + : [base.fontFamily!, ...?base.fontFamilyFallback], + fontSize: size == null ? null : size * scale, + height: height, + letterSpacing: family == null ? null : 0, + ); + } +} diff --git a/app/lib/ui/theme/app_design_tokens.dart b/app/lib/ui/theme/app_design_tokens.dart index 92d21816..42598535 100644 --- a/app/lib/ui/theme/app_design_tokens.dart +++ b/app/lib/ui/theme/app_design_tokens.dart @@ -1,9 +1,13 @@ import 'package:flutter/material.dart'; import 'app_design.dart'; +import 'app_design_styles.dart'; + +export 'app_design_styles.dart'; /// The muted ANSI-style accents a design names for status and roles. The -/// Default design leaves them to its colour scheme; Terminal sets them. +/// Default design leaves them to its colour scheme; Terminal sets them, and +/// Paper sets ink-toned ones. @immutable class AnsiAccents { const AnsiAccents({ @@ -24,9 +28,15 @@ class AnsiAccents { } /// The design-specific facts widgets read instead of hard-coding one look: -/// corner shapes, whether surfaces are flat, frame colour and how the chat -/// transcript is drawn. Every theme an [AppDesign] builds carries one; a -/// theme without one (a test's bare `ThemeData`) reads as [standard]. +/// corner shapes, whether surfaces are flat, frame colour, how the chat +/// transcript, the composer and the open list row are drawn, and the reading +/// typography. Every theme an [AppDesign] builds carries one; a theme without +/// one (a test's bare `ThemeData`) reads as [standard]. +/// +/// Adding a design: every field has a default that keeps the Default look, +/// so a new design sets only what it changes. Widgets branch on the named +/// styles ([transcript], [composer], [selectedRow]) rather than on [design], +/// so two designs can share a behaviour. @immutable class AppDesignTokens extends ThemeExtension { const AppDesignTokens({ @@ -34,8 +44,14 @@ class AppDesignTokens extends ThemeExtension { this.radius, this.flat = false, this.frame, + this.panel, this.ansi, this.promptGlyph = '>', + this.transcript = TranscriptStyle.bubbles, + this.composer = ComposerStyle.pill, + this.selectedRow = SelectedRowStyle.tonal, + this.reading = const ReadingType(), + this.chatColorSaturation = 1, }); /// The Default design: every widget keeps its own shapes. @@ -46,7 +62,7 @@ class AppDesignTokens extends ThemeExtension { final AppDesign design; /// The corner radius of framed surfaces (cards, pills, the composer, - /// bubbles); null keeps each widget's own shape. + /// bubbles, thumbnails, badges); null keeps each widget's own shape. final double? radius; /// Whether surfaces are flat: no frosted glass, blur, highlight or shadow. @@ -55,6 +71,10 @@ class AppDesignTokens extends ThemeExtension { /// The 1px frame colour around flat surfaces; null keeps each widget's own. final Color? frame; + /// The fill of a flat design's own panels (settings groups, floating bars, + /// cards a widget draws itself); null keeps `surfaceContainerLow`. + final Color? panel; + /// The design's ANSI-style accents; null for a design that uses its colour /// scheme's roles. final AnsiAccents? ansi; @@ -62,8 +82,24 @@ class AppDesignTokens extends ThemeExtension { /// The glyph before the operator's prompt line and the composer's field. final String promptGlyph; + /// How the chat transcript draws the operator's and the agent's turns. + final TranscriptStyle transcript; + + /// How the chat composer frames its writing area. + final ComposerStyle composer; + + /// How a list marks its open row. + final SelectedRowStyle selectedRow; + + /// The face, line height and measure of reading text (chat, documents). + final ReadingType reading; + + /// How much of a chat colour's saturation the transcript keeps: 1 for the + /// palette as is, lower to quieten it towards ink. + final double chatColorSaturation; + /// Whether the transcript draws prompt and tool lines rather than bubbles. - bool get terminal => design == AppDesign.terminal; + bool get terminal => transcript == TranscriptStyle.prompt; /// The tokens of the theme at [context]; [standard] when it has none. static AppDesignTokens of(BuildContext context) => @@ -83,21 +119,43 @@ class AppDesignTokens extends ThemeExtension { return r == null ? designed : BorderRadius.circular(r); } + /// [designed] (a widget's own fill) or, under a flat design, its [panel]. + Color panelFill(ColorScheme scheme, Color designed) => + flat ? panel ?? scheme.surfaceContainerLow : designed; + + /// The hairline a flat design frames its panels with; null keeps none. + BorderSide? get frameSide { + final color = frame; + return color == null ? null : BorderSide(color: color); + } + @override AppDesignTokens copyWith({ AppDesign? design, double? radius, bool? flat, Color? frame, + Color? panel, AnsiAccents? ansi, String? promptGlyph, + TranscriptStyle? transcript, + ComposerStyle? composer, + SelectedRowStyle? selectedRow, + ReadingType? reading, + double? chatColorSaturation, }) => AppDesignTokens( design: design ?? this.design, radius: radius ?? this.radius, flat: flat ?? this.flat, frame: frame ?? this.frame, + panel: panel ?? this.panel, ansi: ansi ?? this.ansi, promptGlyph: promptGlyph ?? this.promptGlyph, + transcript: transcript ?? this.transcript, + composer: composer ?? this.composer, + selectedRow: selectedRow ?? this.selectedRow, + reading: reading ?? this.reading, + chatColorSaturation: chatColorSaturation ?? this.chatColorSaturation, ); /// Designs switch whole: a theme animation snaps halfway rather than diff --git a/app/lib/ui/theme/app_font_licenses.dart b/app/lib/ui/theme/app_font_licenses.dart index 96f4a168..d92d5c63 100644 --- a/app/lib/ui/theme/app_font_licenses.dart +++ b/app/lib/ui/theme/app_font_licenses.dart @@ -3,10 +3,12 @@ import 'package:flutter/services.dart'; import '../text/terminal_symbols_font.dart'; import 'app_font.dart'; +import 'paper_fonts.dart'; bool _registered = false; -/// Adds each bundled interface font's SIL Open Font License, and the +/// Adds each bundled interface font's SIL Open Font License, Paper's reading +/// serif's, and the /// terminal symbols font's MIT licence, to the /// [LicenseRegistry]. The texts are read from the bundle only when a licence /// page asks for them. @@ -21,6 +23,9 @@ void registerAppFontLicenses() { font.label, ], await rootBundle.loadString(asset)); } + yield LicenseEntryWithLineBreaks([ + paperSerifFamily, + ], await rootBundle.loadString(paperSerifLicenseAsset)); yield LicenseEntryWithLineBreaks([ 'Symbols Nerd Font Mono', ], await rootBundle.loadString(terminalSymbolsLicenseAsset)); diff --git a/app/lib/ui/theme/paper_controls.dart b/app/lib/ui/theme/paper_controls.dart new file mode 100644 index 00000000..354b7e07 --- /dev/null +++ b/app/lib/ui/theme/paper_controls.dart @@ -0,0 +1,166 @@ +import 'package:flutter/material.dart'; + +import 'paper_theme.dart'; + +const Color _clear = Color(0x00000000); + +/// [base] with Paper's controls: buttons, menus, chips, fields, search bars, +/// tabs, segmented buttons, switches, checkboxes, sliders, badges and +/// progress, all in [paperRadius] corners with hairline outlines, no +/// elevation and the ink-blue accent. +ThemeData paperControls(ThemeData base, PaperSurfaces surfaces) { + final scheme = base.colorScheme; + const rounded = PaperSurfaces.rounded; + ButtonStyle buttons(ButtonStyle? style) => + (style ?? const ButtonStyle()).copyWith( + shape: const WidgetStatePropertyAll(rounded), + elevation: const WidgetStatePropertyAll(0), + shadowColor: const WidgetStatePropertyAll(_clear), + ); + final outline = WidgetStatePropertyAll(BorderSide(color: scheme.outline)); + final menu = MenuStyle( + backgroundColor: WidgetStatePropertyAll(surfaces.floating), + elevation: const WidgetStatePropertyAll(PaperSurfaces.floatElevation), + shadowColor: WidgetStatePropertyAll(surfaces.shadow), + surfaceTintColor: const WidgetStatePropertyAll(_clear), + shape: WidgetStatePropertyAll(surfaces.framed), + padding: const WidgetStatePropertyAll(EdgeInsets.symmetric(vertical: 4)), + ); + return base.copyWith( + menuTheme: MenuThemeData(style: menu), + dropdownMenuTheme: DropdownMenuThemeData(menuStyle: menu), + menuButtonTheme: MenuButtonThemeData( + style: MenuItemButton.styleFrom(shape: rounded), + ), + filledButtonTheme: FilledButtonThemeData( + style: buttons(base.filledButtonTheme.style), + ), + elevatedButtonTheme: ElevatedButtonThemeData( + style: buttons(base.elevatedButtonTheme.style).copyWith( + backgroundColor: WidgetStatePropertyAll(scheme.surface), + side: outline, + ), + ), + outlinedButtonTheme: OutlinedButtonThemeData( + style: buttons(base.outlinedButtonTheme.style).copyWith(side: outline), + ), + textButtonTheme: TextButtonThemeData( + style: buttons(base.textButtonTheme.style), + ), + iconButtonTheme: IconButtonThemeData( + style: buttons(base.iconButtonTheme.style), + ), + segmentedButtonTheme: SegmentedButtonThemeData( + style: buttons(base.segmentedButtonTheme.style).copyWith( + side: WidgetStatePropertyAll(BorderSide(color: scheme.outline)), + ), + ), + floatingActionButtonTheme: FloatingActionButtonThemeData( + elevation: 0, + focusElevation: 0, + hoverElevation: 0, + highlightElevation: 0, + backgroundColor: scheme.surface, + foregroundColor: scheme.primary, + shape: RoundedRectangleBorder( + borderRadius: PaperSurfaces.corners, + side: BorderSide(color: scheme.outline), + ), + ), + chipTheme: ChipThemeData( + backgroundColor: _clear, + selectedColor: scheme.secondaryContainer, + shape: surfaces.framed, + side: surfaces.hairline, + elevation: 0, + pressElevation: 0, + padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 4), + ), + // Only the base border: a field that sets `InputBorder.none` (the + // composer, whose rule it draws itself) keeps none in every state. + // An underline is a writing line on the page, not a box. + inputDecorationTheme: InputDecorationTheme( + border: UnderlineInputBorder( + borderSide: BorderSide(color: scheme.outline), + ), + ), + searchBarTheme: SearchBarThemeData( + elevation: const WidgetStatePropertyAll(0), + shape: const WidgetStatePropertyAll(rounded), + side: WidgetStatePropertyAll(surfaces.hairline), + backgroundColor: WidgetStatePropertyAll(scheme.surfaceContainerLowest), + surfaceTintColor: const WidgetStatePropertyAll(_clear), + padding: const WidgetStatePropertyAll( + EdgeInsets.symmetric(horizontal: 12), + ), + ), + listTileTheme: const ListTileThemeData(shape: rounded), + expansionTileTheme: const ExpansionTileThemeData( + shape: Border(), + collapsedShape: Border(), + ), + tabBarTheme: TabBarThemeData( + dividerColor: scheme.outlineVariant, + labelColor: scheme.onSurface, + unselectedLabelColor: scheme.onSurfaceVariant, + indicatorSize: TabBarIndicatorSize.label, + indicator: UnderlineTabIndicator( + borderSide: BorderSide(color: scheme.primary, width: 2), + ), + ), + switchTheme: SwitchThemeData( + trackOutlineColor: WidgetStateProperty.resolveWith( + (states) => states.contains(WidgetState.selected) + ? scheme.primary + : scheme.outline, + ), + trackOutlineWidth: const WidgetStatePropertyAll(1), + ), + checkboxTheme: CheckboxThemeData( + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(3)), + ), + side: WidgetStateBorderSide.resolveWith( + (states) => states.contains(WidgetState.selected) + ? BorderSide(color: scheme.primary, width: 1.5) + : BorderSide(color: scheme.outline, width: 1.5), + ), + ), + // A thin rule with a small round thumb, like a reading-app slider. + sliderTheme: SliderThemeData( + trackHeight: 2, + activeTrackColor: scheme.primary, + inactiveTrackColor: scheme.outlineVariant, + thumbColor: scheme.primary, + overlayColor: scheme.primary.withValues(alpha: 0.1), + thumbShape: const RoundSliderThumbShape( + enabledThumbRadius: 7, + elevation: 0, + pressedElevation: 0, + ), + overlayShape: const RoundSliderOverlayShape(overlayRadius: 16), + trackShape: const RoundedRectSliderTrackShape(), + tickMarkShape: const RoundSliderTickMarkShape(tickMarkRadius: 1.5), + activeTickMarkColor: scheme.onPrimary, + inactiveTickMarkColor: scheme.outline, + valueIndicatorColor: scheme.inverseSurface, + valueIndicatorTextStyle: TextStyle(color: scheme.onInverseSurface), + ), + // Counts in the accent's ink rather than an alarm red. + badgeTheme: BadgeThemeData( + backgroundColor: scheme.primary, + textColor: scheme.onPrimary, + padding: const EdgeInsets.symmetric(horizontal: 4), + ), + progressIndicatorTheme: ProgressIndicatorThemeData( + color: scheme.primary, + linearTrackColor: scheme.outlineVariant, + circularTrackColor: _clear, + linearMinHeight: 2, + ), + scrollbarTheme: const ScrollbarThemeData( + radius: Radius.circular(4), + thickness: WidgetStatePropertyAll(6), + ), + ); +} diff --git a/app/lib/ui/theme/paper_fonts.dart b/app/lib/ui/theme/paper_fonts.dart new file mode 100644 index 00000000..23d98c33 --- /dev/null +++ b/app/lib/ui/theme/paper_fonts.dart @@ -0,0 +1,44 @@ +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/services.dart'; + +/// Paper's reading serif (fonts/README.md): Source Serif 4. +const String paperSerifFamily = 'Source Serif 4'; + +const String _directory = 'fonts/source-serif-4'; + +/// The licence shipped beside the files, registered with the app's other +/// font licences. +const String paperSerifLicenseAsset = '$_directory/OFL.txt'; + +/// Every face of [paperSerifFamily]: regular, italic, semibold and semibold +/// italic. The loader reads each file's own weight and style. +const List paperSerifAssets = [ + '$_directory/SourceSerif4-Regular.ttf', + '$_directory/SourceSerif4-It.ttf', + '$_directory/SourceSerif4-Semibold.ttf', + '$_directory/SourceSerif4-SemiboldIt.ttf', +]; + +Future? _loading; + +/// Registers [paperSerifFamily] the first time Paper's theme is built. The +/// files are plain assets, not a `fonts:` family, so the web build fetches +/// them only for a device that chooses Paper. Once registered the engine +/// reports a font change and text lays out again in the serif; until then +/// it reads in the interface face (the reading style's fallback). A failed +/// load is logged and the interface face stays. +Future ensurePaperFonts() => _loading ??= _load(); + +Future _load() async { + try { + final loader = FontLoader(paperSerifFamily); + for (final asset in paperSerifAssets) { + loader.addFont(rootBundle.load(asset)); + } + await loader.load(); + } catch (error) { + debugPrint('Paper serif font did not load: $error'); + } +} diff --git a/app/lib/ui/theme/paper_palette.dart b/app/lib/ui/theme/paper_palette.dart new file mode 100644 index 00000000..4158ed7b --- /dev/null +++ b/app/lib/ui/theme/paper_palette.dart @@ -0,0 +1,108 @@ +import 'package:flutter/material.dart'; + +import 'app_design_tokens.dart'; + +/// Paper's status accents on its warm page: the usual hues pulled towards +/// ink, so a status still reads by colour without shouting. +const AnsiAccents paperLightAccents = AnsiAccents( + green: Color(0xFF3D6B3F), + cyan: Color(0xFF2E6670), + yellow: Color(0xFF8A6A1F), + red: Color(0xFF9B3B32), + magenta: Color(0xFF7A4570), + blue: Color(0xFF2C4F86), +); + +/// Paper's status accents on its night page. +const AnsiAccents paperDarkAccents = AnsiAccents( + green: Color(0xFF9DBE95), + cyan: Color(0xFF8DB8BE), + yellow: Color(0xFFD5B977), + red: Color(0xFFDE9A8E), + magenta: Color(0xFFC6A0C0), + blue: Color(0xFF9DB4DC), +); + +/// Paper's colour scheme: a warm off-white page (or a sepia-tinted charcoal +/// "night paper"), near-black ink with a muted secondary ink, surfaces that +/// step only slightly from the page, hairline rules, and one restrained +/// accent, a deep ink blue. Secondary and tertiary roles are quiet sepia +/// tones, so nothing but the accent carries colour. +ColorScheme paperColorScheme(Brightness brightness) { + if (brightness == Brightness.dark) { + return const ColorScheme( + brightness: Brightness.dark, + primary: Color(0xFF9DB4DC), + onPrimary: Color(0xFF13213A), + primaryContainer: Color(0xFF2B3447), + onPrimaryContainer: Color(0xFFD7E1F2), + secondary: Color(0xFFC2B6A2), + onSecondary: Color(0xFF2A241C), + secondaryContainer: Color(0xFF3A342B), + onSecondaryContainer: Color(0xFFEAE1D1), + tertiary: Color(0xFFD5B977), + onTertiary: Color(0xFF2E2410), + tertiaryContainer: Color(0xFF433824), + onTertiaryContainer: Color(0xFFF0E1BC), + error: Color(0xFFE39C90), + onError: Color(0xFF3A120D), + errorContainer: Color(0xFF4D2620), + onErrorContainer: Color(0xFFF6D3CC), + surface: Color(0xFF1E1B17), + onSurface: Color(0xFFE9E1D3), + onSurfaceVariant: Color(0xFFADA393), + surfaceDim: Color(0xFF1A1814), + surfaceBright: Color(0xFF3B362F), + surfaceContainerLowest: Color(0xFF181612), + surfaceContainerLow: Color(0xFF221F1A), + surfaceContainer: Color(0xFF27231E), + surfaceContainerHigh: Color(0xFF2D2923), + surfaceContainerHighest: Color(0xFF35302A), + outline: Color(0xFF746B5E), + outlineVariant: Color(0xFF3D3830), + shadow: Color(0xFF000000), + scrim: Color(0xFF000000), + inverseSurface: Color(0xFFE9E1D3), + onInverseSurface: Color(0xFF26221D), + inversePrimary: Color(0xFF2C4F86), + surfaceTint: Color(0x00000000), + ); + } + return const ColorScheme( + brightness: Brightness.light, + primary: Color(0xFF2C4F86), + onPrimary: Color(0xFFFFFFFF), + primaryContainer: Color(0xFFDDE4EF), + onPrimaryContainer: Color(0xFF132A4D), + secondary: Color(0xFF6B5E4B), + onSecondary: Color(0xFFFFFFFF), + secondaryContainer: Color(0xFFEAE2D2), + onSecondaryContainer: Color(0xFF2E271C), + tertiary: Color(0xFF8A6A1F), + onTertiary: Color(0xFFFFFFFF), + tertiaryContainer: Color(0xFFF1E6C9), + onTertiaryContainer: Color(0xFF3A2C08), + error: Color(0xFF9B3B32), + onError: Color(0xFFFFFFFF), + errorContainer: Color(0xFFF4DCD6), + onErrorContainer: Color(0xFF451410), + surface: Color(0xFFF8F4EB), + onSurface: Color(0xFF221E19), + onSurfaceVariant: Color(0xFF655D51), + surfaceDim: Color(0xFFE7E0D3), + surfaceBright: Color(0xFFFCFAF5), + surfaceContainerLowest: Color(0xFFFCFAF5), + surfaceContainerLow: Color(0xFFF3EEE3), + surfaceContainer: Color(0xFFEEE8DC), + surfaceContainerHigh: Color(0xFFE9E2D5), + surfaceContainerHighest: Color(0xFFE3DBCC), + outline: Color(0xFFA09686), + outlineVariant: Color(0xFFDDD5C6), + shadow: Color(0xFF3B2F1E), + scrim: Color(0xFF000000), + inverseSurface: Color(0xFF2E2A24), + onInverseSurface: Color(0xFFF3EEE3), + inversePrimary: Color(0xFF9DB4DC), + surfaceTint: Color(0x00000000), + ); +} diff --git a/app/lib/ui/theme/paper_theme.dart b/app/lib/ui/theme/paper_theme.dart new file mode 100644 index 00000000..8bf25ee3 --- /dev/null +++ b/app/lib/ui/theme/paper_theme.dart @@ -0,0 +1,193 @@ +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +import 'app_design.dart'; +import 'app_design_tokens.dart'; +import 'app_theme.dart'; +import 'paper_controls.dart'; +import 'paper_fonts.dart'; +import 'paper_palette.dart'; +import 'paper_typography.dart'; + +/// Paper's corner radius: every card, field, menu, dialog, chip, button and +/// thumbnail takes it, so the page has one soft corner throughout. +const double paperRadius = 8; + +/// Paper's surfaces: hairline rules on the page rather than filled panels, +/// and no elevation except a whisper of shadow under the pieces that float +/// over the page (menus, dialogs, sheets, snack bars). +class PaperSurfaces { + PaperSurfaces(this.scheme); + + final ColorScheme scheme; + + static const BorderRadius corners = BorderRadius.all( + Radius.circular(paperRadius), + ); + + /// The whisper: a low elevation in the page's warm shadow at low alpha. + static const double floatElevation = 3; + + Color get shadow => scheme.shadow.withValues( + alpha: scheme.brightness == Brightness.dark ? 0.5 : 0.22, + ); + + BorderSide get hairline => BorderSide(color: scheme.outlineVariant); + + /// A floating piece's fill: the brightest paper, so it lifts off the page + /// by tone and hairline rather than by shadow. + Color get floating => scheme.brightness == Brightness.dark + ? scheme.surfaceContainerHigh + : scheme.surfaceContainerLowest; + + RoundedRectangleBorder get framed => + RoundedRectangleBorder(borderRadius: corners, side: hairline); + + static const RoundedRectangleBorder rounded = RoundedRectangleBorder( + borderRadius: corners, + ); +} + +/// The Paper design's theme: a warm paper page (or night paper in dark), ink +/// text with a muted secondary ink and one deep-blue accent, titles and +/// reading text in a bundled serif with the interface font for chrome, soft +/// [paperRadius] corners, hairline rules and almost no elevation. Building it +/// starts loading the serif ([ensurePaperFonts]). +ThemeData paperTheme(Brightness brightness, {String? fontFamily}) { + unawaited(ensurePaperFonts()); + final scheme = paperColorScheme(brightness); + final surfaces = PaperSurfaces(scheme); + final base = ThemeData( + platform: kIsWeb ? TargetPlatform.android : null, + colorScheme: scheme, + fontFamily: fontFamily, + scaffoldBackgroundColor: scheme.surface, + canvasColor: scheme.surface, + pageTransitionsTheme: appPageTransitions, + dividerColor: scheme.outlineVariant, + shadowColor: surfaces.shadow, + extensions: [ + AppDesignTokens( + design: AppDesign.paper, + radius: paperRadius, + flat: true, + frame: scheme.outlineVariant, + panel: scheme.surface, + ansi: brightness == Brightness.dark + ? paperDarkAccents + : paperLightAccents, + transcript: TranscriptStyle.manuscript, + composer: ComposerStyle.underline, + selectedRow: SelectedRowStyle.washed, + reading: paperReading, + chatColorSaturation: 0.45, + ), + ], + ); + final floating = surfaces.floating; + final floatingShape = RoundedRectangleBorder( + borderRadius: PaperSurfaces.corners, + side: surfaces.hairline, + ); + return paperControls( + base.copyWith( + textTheme: paperTextTheme(base.textTheme), + primaryTextTheme: paperTextTheme(base.primaryTextTheme), + appBarTheme: AppBarTheme( + backgroundColor: scheme.surface, + foregroundColor: scheme.onSurface, + surfaceTintColor: const Color(0x00000000), + elevation: 0, + scrolledUnderElevation: 0, + shape: Border(bottom: surfaces.hairline), + ), + // Only the hairline and the corners: each card variant keeps its own + // fill, so a selected graph node still reads apart. + cardTheme: CardThemeData( + elevation: 0, + shadowColor: const Color(0x00000000), + surfaceTintColor: const Color(0x00000000), + shape: surfaces.framed, + ), + dialogTheme: DialogThemeData( + backgroundColor: floating, + surfaceTintColor: const Color(0x00000000), + elevation: PaperSurfaces.floatElevation, + shadowColor: surfaces.shadow, + shape: floatingShape, + ), + bottomSheetTheme: BottomSheetThemeData( + backgroundColor: floating, + modalBackgroundColor: floating, + surfaceTintColor: const Color(0x00000000), + elevation: PaperSurfaces.floatElevation, + modalElevation: PaperSurfaces.floatElevation, + shadowColor: surfaces.shadow, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.vertical( + top: Radius.circular(paperRadius), + ), + ), + dragHandleColor: scheme.outline, + ), + popupMenuTheme: PopupMenuThemeData( + color: floating, + surfaceTintColor: const Color(0x00000000), + elevation: PaperSurfaces.floatElevation, + shadowColor: surfaces.shadow, + shape: floatingShape, + ), + snackBarTheme: SnackBarThemeData( + backgroundColor: scheme.inverseSurface, + contentTextStyle: base.textTheme.bodyMedium?.copyWith( + color: scheme.onInverseSurface, + ), + actionTextColor: scheme.inversePrimary, + elevation: PaperSurfaces.floatElevation, + shape: PaperSurfaces.rounded, + ), + tooltipTheme: TooltipThemeData( + decoration: BoxDecoration( + color: scheme.inverseSurface.withValues(alpha: 0.94), + borderRadius: const BorderRadius.all(Radius.circular(4)), + ), + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + textStyle: base.textTheme.bodySmall?.copyWith( + color: scheme.onInverseSurface, + ), + ), + dividerTheme: DividerThemeData( + color: scheme.outlineVariant, + thickness: 1, + space: 1, + ), + navigationRailTheme: NavigationRailThemeData( + backgroundColor: scheme.surface, + elevation: 0, + indicatorColor: scheme.secondaryContainer, + indicatorShape: PaperSurfaces.rounded, + ), + navigationBarTheme: NavigationBarThemeData( + backgroundColor: scheme.surface, + elevation: 0, + indicatorColor: scheme.secondaryContainer, + indicatorShape: PaperSurfaces.rounded, + surfaceTintColor: const Color(0x00000000), + ), + drawerTheme: DrawerThemeData( + backgroundColor: scheme.surface, + surfaceTintColor: const Color(0x00000000), + elevation: PaperSurfaces.floatElevation, + shadowColor: surfaces.shadow, + ), + textSelectionTheme: TextSelectionThemeData( + cursorColor: scheme.primary, + selectionColor: scheme.primary.withValues(alpha: 0.22), + selectionHandleColor: scheme.primary, + ), + ), + surfaces, + ); +} diff --git a/app/lib/ui/theme/paper_typography.dart b/app/lib/ui/theme/paper_typography.dart new file mode 100644 index 00000000..02b7ab5f --- /dev/null +++ b/app/lib/ui/theme/paper_typography.dart @@ -0,0 +1,38 @@ +import 'package:flutter/material.dart'; + +import 'app_design_styles.dart'; +import 'paper_fonts.dart'; + +/// Paper's reading type: the serif at a little over the body size, with a +/// book's line height and a measure of about seventy characters. +const ReadingType paperReading = ReadingType( + family: paperSerifFamily, + height: 1.55, + measure: 70, + scale: 17 / 16, +); + +/// [base] for Paper: the page's titles (display, headline and the large +/// title role a page or dialog heads with) in the reading serif, semibold +/// and without added tracking; every interface role (list titles, labels, +/// buttons, chips, metadata and body text in controls) keeps the interface +/// face, so chrome stays a clean sans. +TextTheme paperTextTheme(TextTheme base) { + TextStyle? serif(TextStyle? style) => style?.copyWith( + fontFamily: paperSerifFamily, + fontFamilyFallback: style.fontFamily == null + ? null + : [style.fontFamily!], + fontWeight: FontWeight.w600, + letterSpacing: 0, + ); + return base.copyWith( + displayLarge: serif(base.displayLarge), + displayMedium: serif(base.displayMedium), + displaySmall: serif(base.displaySmall), + headlineLarge: serif(base.headlineLarge), + headlineMedium: serif(base.headlineMedium), + headlineSmall: serif(base.headlineSmall), + titleLarge: serif(base.titleLarge), + ); +} diff --git a/app/lib/ui/theme/terminal_theme.dart b/app/lib/ui/theme/terminal_theme.dart index 23124f46..ab1c0e9e 100644 --- a/app/lib/ui/theme/terminal_theme.dart +++ b/app/lib/ui/theme/terminal_theme.dart @@ -45,6 +45,8 @@ ThemeData terminalTheme(Brightness brightness) { flat: true, frame: scheme.outlineVariant, ansi: ansi, + transcript: TranscriptStyle.prompt, + selectedRow: SelectedRowStyle.framed, ), ], ); diff --git a/app/notes/design-paper.md b/app/notes/design-paper.md new file mode 100644 index 00000000..9252a746 --- /dev/null +++ b/app/notes/design-paper.md @@ -0,0 +1,38 @@ +# Paper design + +A calm reading design (Settings > Design > Paper): warm paper page (sepia +charcoal "night paper" in dark), Source Serif 4 for reading text and titles, +the interface font for chrome, ink colours with one deep-blue accent, 8px +corners, hairline rules and a whisper of shadow only on menus, dialogs, sheets +and snack bars. + +## Tokens added to `AppDesignTokens` (all default to the Default look) + +- `transcript` (`TranscriptStyle.bubbles | prompt | manuscript`): how the chat + draws turns. Terminal = `prompt`; Paper = `manuscript` (block-quote operator + turns with a small-caps "YOU", serif prose, marginal activity note, italic + editorial notes for follow-ups/auto-continue). `tokens.terminal` now means + `transcript == prompt`. +- `composer` (`pill | underline`): Paper's composer is an underlined writing + area (`composer_underline.dart`). +- `selectedRow` (`tonal | framed | washed`): AppListRow's open row; replaces + the hard-coded Terminal frame. Terminal = `framed` (unchanged look). +- `reading` (`ReadingType`: family, height, measure in ch, scale, + figureWidth): reading text style (`chatMessageTextStyle`) and the chat + reading column width (`chatReadingWidthOf`). +- `panel`: fill of a flat design's own panels (settings groups, floating bar + pieces, task cards, the usage banner); `panelFill()` and `frameSide` helpers. +- `chatColorSaturation`: quietens chat colours (`chatColorShade`). + +## Adding a design + +See the `AppDesign` doc comment: add the enum value (id, label, one line), +a `_theme.dart` builder, its tokens and a `swatch`. Floating pieces +(app choice menu, code Copy hover, graph edge tooltip) follow the theme's +`popupMenuTheme`; custom radii go through `tokens.corners()` / `shape()`. + +## Font + +`fonts/source-serif-4/` (OFL, see fonts/README.md), plain assets loaded on +demand by `ensurePaperFonts()` when Paper's theme is first built; no network +font fetch. Its italic has no `smcp`, so small caps are spaced capitals. diff --git a/app/pubspec.yaml b/app/pubspec.yaml index 0ed37808..711d59c7 100644 --- a/app/pubspec.yaml +++ b/app/pubspec.yaml @@ -86,6 +86,9 @@ flutter: - fonts/ibm-plex-sans/ - fonts/source-sans-3/ - fonts/atkinson-hyperlegible-next/ + # Paper design's reading serif, registered when Paper is first chosen + # (lib/ui/theme/paper_fonts.dart). + - fonts/source-serif-4/ # Terminal icon fallback, registered when a terminal is first drawn # (lib/ui/text/terminal_symbols_font.dart). - fonts/symbols-nerd-font/ diff --git a/app/test/features/chat/conversation/chat_composer_underline_test.dart b/app/test/features/chat/conversation/chat_composer_underline_test.dart new file mode 100644 index 00000000..58f2864d --- /dev/null +++ b/app/test/features/chat/conversation/chat_composer_underline_test.dart @@ -0,0 +1,68 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_draft_store.dart'; +import 'package:pipelines_app/features/chat/conversation/chat_thread_view.dart'; +import 'package:pipelines_app/ui/theme/app_design.dart'; + +import 'chat_composer_bar_fixtures.dart'; + +Widget _thread(ComposerBarGateway gateway, AppDesign design) => MaterialApp( + theme: design.light(), + home: Scaffold( + body: ChatThreadView( + gateway: gateway, + sessionId: 's', + session: const {'id': 's', 'directory': '/Users/ada/repos/tank'}, + syncToken: 0, + onBack: () {}, + drafts: MemoryChatDraftStore(), + ), + ), +); + +void main() { + testWidgets('Paper: the composer is an underlined writing area, not a ' + 'pill, and its rule takes the accent on focus', (tester) async { + final gateway = ComposerBarGateway(); + addTearDown(gateway.close); + await tester.pumpWidget(_thread(gateway, AppDesign.paper)); + await tester.pumpAndSettle(); + + expect(find.byKey(const Key('chat-composer-pill')), findsNothing); + final area = find.byKey(const Key('chat-composer-underline')); + expect(area, findsOneWidget); + for (final key in [ + 'chat-composer-attach', + 'chat-composer-field', + 'chat-composer-primary', + ]) { + expect( + find.descendant(of: area, matching: find.byKey(Key(key))), + findsOneWidget, + ); + } + final scheme = Theme.of(tester.element(area)).colorScheme; + Color? rule() => + (tester + .widget( + find.byKey(const Key('chat-composer-rule')), + ) + .decoration + as BoxDecoration?) + ?.color; + expect(rule(), scheme.outline); + + await tester.tap(find.byKey(const Key('chat-composer-field'))); + await tester.pumpAndSettle(); + expect(rule(), scheme.primary); + }); + + testWidgets('Default keeps the pill', (tester) async { + final gateway = ComposerBarGateway(); + addTearDown(gateway.close); + await tester.pumpWidget(_thread(gateway, AppDesign.standard)); + await tester.pumpAndSettle(); + expect(find.byKey(const Key('chat-composer-pill')), findsOneWidget); + expect(find.byKey(const Key('chat-composer-underline')), findsNothing); + }); +} diff --git a/app/test/features/chat/ui/transcript/paper_transcript_test.dart b/app/test/features/chat/ui/transcript/paper_transcript_test.dart new file mode 100644 index 00000000..d07bf52e --- /dev/null +++ b/app/test/features/chat/ui/transcript/paper_transcript_test.dart @@ -0,0 +1,203 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/core/api_gateway.dart'; +import 'package:pipelines_app/features/chat/domain/chat_transcript.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/chat_markdown_view.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/chat_message_bubble.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/chat_message_view.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_activity_note.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_editorial_note.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/paper/paper_quote.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_activity_rows.dart'; +import 'package:pipelines_app/features/chat/ui/transcript/terminal/terminal_prompt_line.dart'; +import 'package:pipelines_app/ui/text/monospace.dart'; +import 'package:pipelines_app/ui/theme/app_design.dart'; +import 'package:pipelines_app/ui/theme/paper_fonts.dart'; + +JsonMap _row(JsonMap message) => transcriptRows([message]).single; + +final JsonMap _operator = _row({ + 'id': 'u1', + 'role': 'user', + 'parts': [ + {'type': 'text', 'text': 'Fix the Windows paths.'}, + ], +}); + +JsonMap _tool(String id, String name, String status) => { + 'type': 'tool', + 'id': id, + 'name': name, + 'state': { + 'status': status, + 'input': {'command': 'go test ./...'}, + if (status == 'error') 'error': {'message': 'exit status 1'}, + }, +}; + +final JsonMap _agent = _row({ + 'id': 'a1', + 'role': 'assistant', + 'parts': [ + _tool('t1', 'Bash', 'completed'), + _tool('t2', 'Read', 'completed'), + _tool('t3', 'Bash', 'completed'), + { + 'type': 'text', + 'text': + '## Cause\n\nFixed the separators.\n\n' + '- one\n- two\n\n```go\nreturn filepath.Join(a, b)\n```', + }, + ], +}); + +final JsonMap _followup = _row({ + 'id': 'f1', + 'role': 'user', + 'origin': 'followup', + 'client': 'Agent follow-up', + 'parts': [ + {'type': 'text', 'text': 'Check whether run 42 finished.'}, + ], +}); + +Widget _host(AppDesign design, List rows) => MaterialApp( + theme: design.light(), + home: Scaffold( + body: ListView( + children: [ + for (final row in rows) + ChatMessageView(row: row, textBuilder: chatMarkdownText), + ], + ), + ), +); + +double _left(WidgetTester tester, Finder finder) => + tester.getTopLeft(finder).dx; + +/// The style the text containing [text] is laid out in: the root of the +/// first [RichText] that draws it. +TextStyle _style(WidgetTester tester, String text) { + final rich = tester + .widgetList(find.byType(RichText)) + .firstWhere((rich) => rich.text.toPlainText().contains(text)); + return rich.text.style ?? const TextStyle(); +} + +void main() { + testWidgets('Paper: the operator turn is an indented block quote with a ' + 'small-caps label and a rule, not a bubble', (tester) async { + await tester.pumpWidget(_host(AppDesign.paper, [_operator, _agent])); + final quote = find.byType(PaperQuote); + expect(quote, findsOneWidget); + expect(find.byType(TerminalPromptLine), findsNothing); + final label = find.byKey(const Key('chat-paper-quote-label')); + expect(tester.widget(label).data, 'YOU'); + expect(tester.widget(label).style?.fontStyle, FontStyle.italic); + // Indented past the answer's text edge, not on the trailing side. + final words = find.text('Fix the Windows paths.'); + final answer = find.text('Fixed the separators.'); + expect(_left(tester, words), greaterThan(_left(tester, answer))); + expect(_left(tester, words) - _left(tester, answer), lessThan(40)); + // The rule runs down the quote's leading edge. + final rule = tester.widget( + find.descendant(of: quote, matching: find.byType(DecoratedBox)).first, + ); + final side = + ((rule.decoration as BoxDecoration).border! as BorderDirectional).start; + expect(side.width, paperQuoteRule); + }); + + testWidgets('Paper: answers are serif prose, code keeps the monospace', ( + tester, + ) async { + await tester.pumpWidget(_host(AppDesign.paper, [_agent])); + final prose = _style(tester, 'Fixed the separators.'); + expect(prose.fontFamily, paperSerifFamily); + expect(prose.height, closeTo(1.55, 0.01)); + final heading = _style(tester, 'Cause'); + expect(heading.fontFamily, paperSerifFamily); + expect(heading.fontWeight, FontWeight.w600); + expect(heading.fontSize, greaterThan(prose.fontSize!)); + final code = _style(tester, 'return filepath.Join(a, b)'); + expect(code.fontFamily, appMonospaceFamily); + expect(code.fontSize, lessThan(prose.fontSize!)); + expect(find.text('•'), findsNWidgets(2)); + }); + + testWidgets('Paper: tool activity is a muted marginal note naming the ' + 'tools, and it still opens the details', (tester) async { + await tester.pumpWidget(_host(AppDesign.paper, [_agent])); + expect(find.byType(TerminalActivityRows), findsNothing); + final note = find.byType(PaperActivityNote); + expect(note, findsOneWidget); + expect( + find.descendant( + of: note, + matching: find.textContaining('Used 3 tools — Bash, Read'), + ), + findsOneWidget, + ); + final text = tester.widget( + find.descendant(of: note, matching: find.byType(Text)), + ); + expect(text.style?.fontStyle, FontStyle.italic); + await tester.tap(note); + await tester.pumpAndSettle(); + expect(find.text('Activity details'), findsOneWidget); + }); + + testWidgets('Paper: a follow-up is a small italic editorial note', ( + tester, + ) async { + await tester.pumpWidget(_host(AppDesign.paper, [_followup])); + expect(find.byType(PaperEditorialNote), findsOneWidget); + final header = find.byKey(const Key('chat-automated-prompt-header')); + final text = tester.widget(header).textSpan!.toPlainText(); + expect(text, startsWith('FOLLOW-UP FROM AGENT')); + // The body is selectable text in the note's ambient style. + final body = DefaultTextStyle.of( + tester.element(find.text('Check whether run 42 finished.')), + ).style; + expect(body.fontStyle, FontStyle.italic); + // No card: the note has no Material fill. + final note = tester.widget( + find.byKey(const Key('chat-automated-prompt')), + ); + expect(note.type, MaterialType.transparency); + }); + + testWidgets('Default is unchanged: a trailing bubble, no Paper pieces', ( + tester, + ) async { + await tester.pumpWidget( + _host(AppDesign.standard, [_operator, _agent, _followup]), + ); + expect(find.byType(PaperQuote), findsNothing); + expect(find.byType(PaperActivityNote), findsNothing); + expect(find.byType(PaperEditorialNote), findsNothing); + expect(find.byType(ChatUserBubble), findsOneWidget); + final bubble = find.byType(ChatUserBubble); + final answer = find.text('Fixed the separators.'); + expect(_left(tester, bubble), greaterThan(_left(tester, answer))); + expect( + _style(tester, 'Fixed the separators.').fontFamily, + isNot(paperSerifFamily), + ); + }); + + testWidgets('Terminal is unchanged: prompt line and tool rows', ( + tester, + ) async { + await tester.pumpWidget(_host(AppDesign.terminal, [_operator, _agent])); + expect(find.byType(TerminalPromptLine), findsOneWidget); + expect(find.byType(TerminalActivityRows), findsOneWidget); + expect(find.byType(PaperQuote), findsNothing); + expect(find.byType(PaperActivityNote), findsNothing); + expect( + _style(tester, 'Fixed the separators.').fontFamily, + appMonospaceFamily, + ); + }); +} diff --git a/app/test/features/settings/settings_design_section_test.dart b/app/test/features/settings/settings_design_section_test.dart index e76a43a8..6b2185ae 100644 --- a/app/test/features/settings/settings_design_section_test.dart +++ b/app/test/features/settings/settings_design_section_test.dart @@ -91,4 +91,27 @@ void main() { expect(find.text(designSaveFailedText), findsOneWidget); expect(designs.design, AppDesign.terminal); }); + + testWidgets('choosing Paper stores it, restyles the page live and is ' + 'restored on the next launch', (tester) async { + final store = MemoryAppDesignStore(); + final designs = AppDesignController(store: store); + await _pump(tester, designs); + + // Every row shows its design's swatch. + expect( + find.byType(DesignSwatchPreview), + findsNWidgets(AppDesign.values.length), + ); + expect(find.text(AppDesign.paper.description), findsOneWidget); + await tester.tap(find.text(AppDesign.paper.label)); + await tester.pumpAndSettle(); + expect(store.id, 'paper'); + expect(designs.design, AppDesign.paper); + expect(_tokens(tester).transcript, TranscriptStyle.manuscript); + + final next = AppDesignController(store: MemoryAppDesignStore(store.id)); + await next.restore(); + expect(next.design, AppDesign.paper); + }); } diff --git a/app/test/ui/layout/app_list_row_test.dart b/app/test/ui/layout/app_list_row_test.dart index 40a923f0..57447ee3 100644 --- a/app/test/ui/layout/app_list_row_test.dart +++ b/app/test/ui/layout/app_list_row_test.dart @@ -6,6 +6,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/ui/layout/app_list_avatar.dart'; import 'package:pipelines_app/ui/layout/app_list_row.dart'; import 'package:pipelines_app/ui/layout/app_overflow_menu.dart'; +import 'package:pipelines_app/ui/theme/app_design.dart'; const _longTitle = 'A row title long enough that it must ellipsise somewhere'; const _longLine = 'a muted line of facts that is far too long for one line'; @@ -257,4 +258,63 @@ void main() { expect(_paint(tester, 'B').fontSize, 18); expect(_paint(tester, 'B').fontWeight, FontWeight.w700); }); + + // Each design marks the open row its own way (AppDesignTokens.selectedRow); + // every way keeps the leading bar in the accent. + for (final (design, framed, tonal) in [ + (AppDesign.standard, false, true), + (AppDesign.terminal, true, false), + (AppDesign.paper, false, false), + ]) { + testWidgets('${design.label}: the open row is clearly marked', ( + tester, + ) async { + _size(tester, 560); + await tester.pumpWidget( + MaterialApp( + theme: design.light(), + home: Scaffold(body: ListView(children: [_row(selected: true)])), + ), + ); + final row = find.byKey(const Key('row')); + final context = tester.element(row); + final scheme = Theme.of(context).colorScheme; + final fill = tester + .widget( + find.descendant( + of: row, + matching: find.byKey(appListRowSurfaceKey), + ), + ) + .color!; + if (tonal) { + expect(fill, AppListRow.selectedColor(context)); + } else { + // The accent washed over the page, visibly apart from it. + expect(fill, isNot(Theme.of(context).scaffoldBackgroundColor)); + expect(fill.a, 1); + final page = Theme.of(context).scaffoldBackgroundColor; + expect( + (fill.computeLuminance() - page.computeLuminance()).abs(), + greaterThan(0.04), + ); + } + final border = + (tester + .widget( + find.descendant( + of: row, + matching: find.byKey(appListRowSelectionKey), + ), + ) + .decoration + as BoxDecoration) + .border! + as BorderDirectional; + expect(border.start.color, scheme.primary); + expect(border.start.width, kAppListRowBarWidth); + expect(border.top == BorderSide.none, !framed); + expect(border.end == BorderSide.none, !framed); + }); + } } diff --git a/app/test/ui/theme/paper_design_test.dart b/app/test/ui/theme/paper_design_test.dart new file mode 100644 index 00000000..14f9401c --- /dev/null +++ b/app/test/ui/theme/paper_design_test.dart @@ -0,0 +1,177 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pipelines_app/ui/text/monospace.dart'; +import 'package:pipelines_app/ui/theme/app_design.dart'; +import 'package:pipelines_app/ui/theme/app_design_tokens.dart'; +import 'package:pipelines_app/ui/theme/app_theme.dart'; +import 'package:pipelines_app/ui/theme/paper_fonts.dart'; + +ThemeData _theme(AppDesign design, Brightness brightness, {String? font}) => + brightness == Brightness.dark + ? design.dark(fontFamily: font) + : design.light(fontFamily: font); + +void main() { + test('Paper is listed with a stable id, a label and one line', () { + expect(AppDesign.values, contains(AppDesign.paper)); + expect(AppDesign.fromId('paper'), AppDesign.paper); + expect(AppDesign.paper.label, 'Paper'); + expect(AppDesign.paper.description, isNot(contains('\n'))); + expect(AppDesign.paper.usesInterfaceFont, isTrue); + expect(AppDesign.terminal.usesInterfaceFont, isFalse); + }); + + test('Paper tokens: manuscript transcript, underline composer, washed ' + 'row, serif reading at ~70ch, soft corners, hairlines', () { + for (final brightness in Brightness.values) { + final theme = _theme(AppDesign.paper, brightness); + final tokens = theme.extension()!; + expect(tokens.design, AppDesign.paper); + expect(tokens.transcript, TranscriptStyle.manuscript); + expect(tokens.terminal, isFalse); + expect(tokens.composer, ComposerStyle.underline); + expect(tokens.selectedRow, SelectedRowStyle.washed); + expect(tokens.reading.family, paperSerifFamily); + expect(tokens.reading.height, closeTo(1.5, 0.1)); + expect(tokens.reading.measure, 70); + expect(tokens.radius, inInclusiveRange(8, 10)); + expect(tokens.flat, isTrue); + expect(tokens.frame, theme.colorScheme.outlineVariant); + expect(tokens.panel, theme.colorScheme.surface); + expect(tokens.chatColorSaturation, lessThan(1)); + expect(tokens.ansi, isNotNull); + } + }); + + test('Paper pages: warm off-white by day, sepia charcoal by night', () { + final light = _theme(AppDesign.paper, Brightness.light); + final page = light.scaffoldBackgroundColor; + expect(page.computeLuminance(), greaterThan(0.8)); + expect(page, isNot(const Color(0xFFFFFFFF))); + expect(page.r, greaterThan(page.b), reason: 'a warm page'); + final dark = _theme(AppDesign.paper, Brightness.dark); + final night = dark.scaffoldBackgroundColor; + expect(night.computeLuminance(), inExclusiveRange(0.008, 0.05)); + expect(night.r, greaterThan(night.b), reason: 'sepia, not neutral'); + for (final theme in [light, dark]) { + // Ink, a muted secondary ink and one accent. + final scheme = theme.colorScheme; + expect(scheme.onSurface, isNot(scheme.onSurfaceVariant)); + expect(scheme.primary.b, greaterThan(scheme.primary.r)); + } + }); + + test('Paper sets titles in the serif and keeps chrome in the interface ' + 'font', () { + for (final brightness in Brightness.values) { + final text = _theme(AppDesign.paper, brightness, font: 'Inter').textTheme; + for (final title in [ + text.headlineSmall, + text.titleLarge, + text.displaySmall, + ]) { + expect(title?.fontFamily, paperSerifFamily); + } + for (final chrome in [ + text.labelLarge, + text.labelSmall, + text.titleMedium, + text.bodyMedium, + text.bodySmall, + ]) { + expect(chrome?.fontFamily, 'Inter'); + } + } + // The reading style sets the serif over the body role and keeps the + // interface face as its fallback. + final paper = _theme(AppDesign.paper, Brightness.light, font: 'Inter'); + final tokens = paper.extension()!; + const body = TextStyle(fontFamily: 'Inter', fontSize: 16); + final reading = tokens.reading.apply(body)!; + expect(reading.fontFamily, paperSerifFamily); + expect(reading.fontFamilyFallback, contains('Inter')); + expect(reading.height, tokens.reading.height); + expect(reading.fontSize, greaterThan(16)); + }); + + test('Paper floats only menus and dialogs, by a whisper, in its corners', () { + final theme = _theme(AppDesign.paper, Brightness.light); + final radius = theme.extension()!.radius!; + expect(theme.cardTheme.elevation, 0); + expect(theme.appBarTheme.scrolledUnderElevation, 0); + expect(theme.floatingActionButtonTheme.elevation, 0); + expect(theme.dialogTheme.elevation, inInclusiveRange(1, 4)); + expect(theme.popupMenuTheme.elevation, inInclusiveRange(1, 4)); + expect(theme.dialogTheme.shadowColor!.a, lessThan(0.5)); + for (final shape in [ + theme.cardTheme.shape, + theme.dialogTheme.shape, + theme.popupMenuTheme.shape, + theme.chipTheme.shape, + theme.snackBarTheme.shape, + ]) { + expect( + (shape! as RoundedRectangleBorder).borderRadius, + BorderRadius.circular(radius), + ); + } + // Controls the Default leaves to Material are Paper's own. + expect(theme.sliderTheme.trackHeight, 2); + expect(theme.sliderTheme.thumbShape, isA()); + expect(theme.badgeTheme.backgroundColor, theme.colorScheme.primary); + expect(theme.checkboxTheme.shape, isA()); + expect(theme.switchTheme.trackOutlineWidth, isNotNull); + expect(theme.tabBarTheme.indicator, isA()); + expect(theme.inputDecorationTheme.border, isA()); + expect(theme.searchBarTheme.elevation?.resolve({}), 0); + }); + + test('the Default design is unchanged: no tokens, every style defaulted', () { + expect(AppDesign.standard.light(), appLightTheme()); + expect(AppDesign.standard.dark(), appDarkTheme()); + const tokens = AppDesignTokens.standard; + expect(tokens.transcript, TranscriptStyle.bubbles); + expect(tokens.composer, ComposerStyle.pill); + expect(tokens.selectedRow, SelectedRowStyle.tonal); + expect(tokens.reading.family, isNull); + expect(tokens.reading.measure, isNull); + expect(tokens.chatColorSaturation, 1); + expect(tokens.panel, isNull); + final style = const TextStyle(fontSize: 16, fontFamily: 'Inter'); + expect(tokens.reading.apply(style), same(style)); + }); + + test('Terminal is unchanged: prompt transcript, framed row, pill, its own ' + 'monospace and no reading type', () { + for (final brightness in Brightness.values) { + final theme = _theme(AppDesign.terminal, brightness, font: 'Inter'); + final tokens = theme.extension()!; + expect(tokens.transcript, TranscriptStyle.prompt); + expect(tokens.terminal, isTrue); + expect(tokens.selectedRow, SelectedRowStyle.framed); + expect(tokens.composer, ComposerStyle.pill); + expect(tokens.reading.family, isNull); + expect(tokens.panel, isNull); + expect(tokens.chatColorSaturation, 1); + expect(tokens.radius, 3); + expect(theme.textTheme.bodyLarge?.fontFamily, appMonospaceFamily); + // A flat panel keeps Terminal's own low surface. + expect( + tokens.panelFill(theme.colorScheme, Colors.red), + theme.colorScheme.surfaceContainerLow, + ); + } + }); + + test('each design swatch matches its theme', () { + for (final design in AppDesign.values) { + for (final brightness in Brightness.values) { + final theme = _theme(design, brightness); + final swatch = design.swatch(brightness); + expect(swatch.page, theme.scaffoldBackgroundColor, reason: '$design'); + expect(swatch.ink, theme.colorScheme.onSurface, reason: '$design'); + expect(swatch.accent, theme.colorScheme.primary, reason: '$design'); + } + } + }); +}