Files
cutdex/packages/cutdex_ui/lib/src/theme/app_theme.dart
T
lingjhf 2e0033ce2d
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
feat(workspace): refresh desktop editing experience and prepare 0.1.2
2026-10-09 01:56:01 +08:00

1821 lines
65 KiB
Dart

import 'package:flutter/foundation.dart';
import 'menu_metrics.dart';
import 'app_palette.dart';
import 'package:flutter/material.dart';
import '../icons/app_icons.dart';
/// Workspace semantic colors and Codex desktop typography.
abstract final class AppTheme {
/// Applied by the desktop shell only; touch surfaces retain their own scale.
static ThemeData desktopWorkspaceTheme(ThemeData theme) {
if (theme.extension<DesktopControlDensity>() != null) return theme;
final text = theme.textTheme;
final body = text.bodyMedium!.copyWith(fontSize: 13, height: 20 / 13);
final label = body.copyWith(
fontWeight: FontWeight.w500,
fontVariations: const [FontVariation('wght', 500)],
);
ButtonStyle? button(ButtonStyle? style) => style?.copyWith(
minimumSize: const WidgetStatePropertyAll(
Size(0, AppDesktopMetrics.button),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: 12, vertical: 6),
),
textStyle: WidgetStatePropertyAll(label),
);
return theme.copyWith(
extensions: [...theme.extensions.values, const DesktopControlDensity()],
textTheme: text.copyWith(
bodyLarge: body.copyWith(fontSize: 14, height: 20 / 14),
bodyMedium: body,
bodySmall: text.bodySmall?.copyWith(fontSize: 12, height: 16 / 12),
labelLarge: label,
titleSmall: label.copyWith(fontSize: 14, height: 20 / 14),
),
textButtonTheme: TextButtonThemeData(
style: button(theme.textButtonTheme.style),
),
filledButtonTheme: FilledButtonThemeData(
style: button(theme.filledButtonTheme.style),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: button(theme.outlinedButtonTheme.style),
),
iconButtonTheme: IconButtonThemeData(
style: theme.iconButtonTheme.style?.copyWith(
minimumSize: const WidgetStatePropertyAll(
Size.square(AppDesktopMetrics.iconButton),
),
padding: const WidgetStatePropertyAll(EdgeInsets.all(4)),
iconSize: const WidgetStatePropertyAll(16),
),
),
inputDecorationTheme: theme.inputDecorationTheme.copyWith(
constraints: const BoxConstraints(minHeight: AppDesktopMetrics.input),
contentPadding: const EdgeInsets.symmetric(horizontal: 10, vertical: 8),
hintStyle: body.copyWith(
color: theme.inputDecorationTheme.hintStyle?.color,
leadingDistribution: TextLeadingDistribution.even,
),
),
);
}
static bool isDesktop(BuildContext context) =>
Theme.of(context).extension<DesktopControlDensity>() != null;
/// Window project navigation uses quiet neutral surfaces in every palette.
static ButtonStyle projectTabStyle(
BuildContext context, {
required bool selected,
}) {
final theme = Theme.of(context);
final colors = theme.colorScheme;
return ButtonStyle(
minimumSize: const WidgetStatePropertyAll(
Size(0, AppProjectTabMetrics.height),
),
maximumSize: const WidgetStatePropertyAll(
Size(double.infinity, AppProjectTabMetrics.height),
),
visualDensity: VisualDensity.standard,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: const WidgetStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(AppProjectTabMetrics.radius),
),
),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: 8),
),
textStyle: WidgetStatePropertyAll(
theme.textTheme.labelLarge?.copyWith(
fontSize: 13,
height: 1.3,
fontWeight: selected ? FontWeight.w500 : FontWeight.w400,
fontVariations: [FontVariation('wght', selected ? 500 : 400)],
),
),
foregroundColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.disabled)
? colors.onSurface.withValues(alpha: .38)
: selected
? colors.onSurface
: colors.onSurfaceVariant,
),
backgroundColor: WidgetStateProperty.resolveWith(
(states) => colors.onSurface.withValues(
alpha: states.contains(WidgetState.pressed)
? .12
: selected
? .08
: states.contains(WidgetState.hovered) ||
states.contains(WidgetState.focused)
? .05
: 0,
),
),
overlayColor: const WidgetStatePropertyAll(Colors.transparent),
);
}
static ButtonStyle projectTabActionStyle(
BuildContext context, {
double size = AppProjectTabMetrics.height,
}) => IconButton.styleFrom(
fixedSize: Size.square(size),
minimumSize: Size.square(size),
maximumSize: Size.square(size),
visualDensity: VisualDensity.standard,
padding: EdgeInsets.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
foregroundColor: Theme.of(context).colorScheme.onSurfaceVariant,
backgroundColor: Colors.transparent,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(AppProjectTabMetrics.radius),
),
),
);
/// Tab navigation sits one surface level above the timeline commands.
static Color timelineTabsBackground(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return isDesktop(context) ? colors.surfaceContainerLow : colors.surface;
}
/// Rounded document tabs keep selection distinct from editing commands.
static ButtonStyle timelineTabStyle(
BuildContext context, {
required bool selected,
}) {
final theme = Theme.of(context);
final desktop = isDesktop(context);
final colors = theme.colorScheme;
final height = desktop ? AppDesktopMetrics.timelineTabControl : 20.0;
return ButtonStyle(
minimumSize: WidgetStatePropertyAll(Size(0, height)),
maximumSize: WidgetStatePropertyAll(Size(double.infinity, height)),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: desktop
? const WidgetStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(AppDesktopMetrics.timelineTabRadius),
),
),
)
: null,
textStyle: WidgetStatePropertyAll(
theme.textTheme.labelLarge?.copyWith(
fontSize: desktop ? 13 : 12,
height: 1.3,
fontWeight: desktop && selected ? FontWeight.w500 : FontWeight.w400,
fontVariations: desktop
? [FontVariation('wght', selected ? 500 : 400)]
: null,
),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: AppSpacing.small),
),
foregroundColor: WidgetStatePropertyAll(
selected
? desktop
? colors.primary
: colors.onSurface
: colors.onSurfaceVariant,
),
backgroundColor: WidgetStatePropertyAll(
selected
? desktop
? colors.primary.withValues(alpha: .12)
: colors.onSurface.withValues(alpha: .05)
: Colors.transparent,
),
overlayColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.hovered) ||
states.contains(WidgetState.focused) ||
states.contains(WidgetState.pressed)) {
return colors.onSurface.withValues(alpha: .078);
}
return Colors.transparent;
}),
);
}
static ButtonStyle get timelineTabActionStyle => IconButton.styleFrom(
fixedSize: const Size.square(AppDesktopMetrics.timelineTabControl),
minimumSize: const Size.square(AppDesktopMetrics.timelineTabControl),
maximumSize: const Size.square(AppDesktopMetrics.timelineTabControl),
padding: EdgeInsets.zero,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(AppDesktopMetrics.timelineTabRadius),
),
),
);
static ThemeData get penLight => _build(AppColors.penLight);
static ThemeData get penDark => _build(AppColors.penDark);
static ThemeData forPalette(AppPalette palette, Brightness brightness) =>
_build(AppColors.forPalette(palette, brightness));
/// Media canvas controls keep a dark palette in either workspace appearance.
static ThemeData get previewCanvasTheme => penDark;
/// Fullscreen also places Material children on the black preview surface.
static ThemeData get previewFullscreenTheme {
final theme = previewCanvasTheme;
return theme.copyWith(
colorScheme: theme.colorScheme.copyWith(
surface: theme.extension<AppSurfaces>()!.previewBackground,
),
);
}
static Color itemHoverColor(BuildContext context, {required bool selected}) {
final theme = Theme.of(context);
return theme.colorScheme.onSurface.withValues(
alpha: selected
? .05
: theme.brightness == Brightness.dark
? .078
: .058,
);
}
static Color comboboxBackground(BuildContext context) {
final theme = Theme.of(context);
return theme.brightness == Brightness.dark
? theme.colorScheme.surfaceContainerHighest.withValues(alpha: .3)
: Colors.transparent;
}
static Color tabBorderColor(
BuildContext context, {
required bool selected,
required bool headerStyle,
}) {
final theme = Theme.of(context);
return selected && (headerStyle || theme.brightness == Brightness.dark)
? theme.colorScheme.outlineVariant
: Colors.transparent;
}
static Color dropOverlayBackground(BuildContext context) {
final theme = Theme.of(context);
return theme.colorScheme.scrim.withValues(
alpha: theme.brightness == Brightness.dark ? .62 : .38,
);
}
static TextStyle resourceProgressTextStyle(BuildContext context) {
final theme = Theme.of(context);
return theme.textTheme.bodyMedium!.copyWith(
color: theme.brightness == Brightness.dark
? theme.colorScheme.onSurface.withValues(alpha: .55)
: theme.colorScheme.onSurfaceVariant,
);
}
static Color settingsSidebarBackground(BuildContext context) {
final theme = Theme.of(context);
return theme.brightness == Brightness.dark
? AppColors.of(theme).settingsSidebar
: theme.colorScheme.surfaceContainer;
}
static Color switchTrackColor(BuildContext context, Set<WidgetState> states) {
final theme = Theme.of(context);
final configured = theme.switchTheme.trackColor?.resolve(states);
if (configured != null) return configured;
if (states.contains(WidgetState.selected)) return theme.colorScheme.primary;
final input = theme.inputDecorationTheme.enabledBorder!.borderSide.color;
return input.withValues(
alpha: input.a * (theme.brightness == Brightness.dark ? .8 : 1),
);
}
static Color switchThumbColor(BuildContext context, Set<WidgetState> states) {
final theme = Theme.of(context);
final configured = theme.switchTheme.thumbColor?.resolve(states);
if (configured != null) return configured;
if (theme.brightness == Brightness.dark) {
return states.contains(WidgetState.selected)
? theme.colorScheme.onPrimary
: theme.colorScheme.onSurface;
}
return theme.colorScheme.surface;
}
static String systemFontFamily(TargetPlatform platform) => switch (platform) {
TargetPlatform.macOS || TargetPlatform.iOS => '.AppleSystemUIFont',
TargetPlatform.windows => 'Segoe UI',
_ => 'sans-serif',
};
static List<String> systemFontFamilyFallback(TargetPlatform platform) =>
switch (platform) {
TargetPlatform.windows => const [
'Microsoft YaHei UI',
'Microsoft YaHei',
'Noto Sans CJK SC',
'sans-serif',
],
_ => const ['PingFang SC', 'Noto Sans CJK SC', 'sans-serif'],
};
static Color popoverBackground(BuildContext context) {
final theme = Theme.of(context);
return theme.extension<AppSurfaces>()?.popoverBackground ??
theme.colorScheme.surfaceContainerHigh;
}
/// The visible sidebar/content boundary in the opaque Codex window.
static Color sidebarDividerColor(BuildContext context) =>
Theme.of(context).dividerColor;
/// Keeps boundaries visible on the brighter floating composer surface.
static Color floatingDialogDividerColor(BuildContext context) {
final theme = Theme.of(context);
if (theme.brightness != Brightness.dark) return theme.dividerColor;
return Color.alphaBlend(
theme.colorScheme.onSurface.withValues(alpha: .16),
AppSurfaces.of(context).composerBackground,
);
}
/// Side panels keep their Material children on the same surface.
static ThemeData panelTheme(ThemeData theme) {
final background = theme.colorScheme.surfaceContainerLow;
return theme.copyWith(
canvasColor: background,
colorScheme: theme.colorScheme.copyWith(surface: background),
);
}
static ThemeData timelinePanelTheme(ThemeData theme) {
final divider = theme.dividerColor;
return theme.copyWith(
dividerColor: divider,
dividerTheme: theme.dividerTheme.copyWith(color: divider, space: 1),
);
}
/// Desktop inspectors use a denser scale than dialogs and settings.
static ThemeData propertiesPanelTheme(ThemeData theme) {
final desktop = theme.extension<DesktopControlDensity>() != null;
final colors = theme.colorScheme;
final panelText = desktop
? theme.textTheme.copyWith(
bodyMedium: theme.textTheme.bodyMedium?.copyWith(
fontSize: 13,
height: 20 / 13,
leadingDistribution: TextLeadingDistribution.even,
),
bodySmall: theme.textTheme.bodySmall?.copyWith(
fontSize: 12,
height: 16 / 12,
leadingDistribution: TextLeadingDistribution.even,
),
)
: theme.textTheme;
final actionSize = desktop
? AppInspectorMetrics.action
: AppControlSize.propertyControl;
ButtonStyle? buttonStyle(ButtonStyle? style) => style?.copyWith(
textStyle: WidgetStatePropertyAll(panelText.labelLarge),
minimumSize: desktop
? const WidgetStatePropertyAll(Size(0, AppInspectorMetrics.input))
: style.minimumSize,
padding: desktop
? const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: 8, vertical: 4),
)
: style.padding,
);
final panelColors = colors.copyWith(surface: colors.surfaceContainerLow);
final composerBackground = theme
.extension<AppSurfaces>()!
.composerBackground;
final hintColor = theme.brightness == Brightness.dark
? colors.onSurface.withValues(alpha: .249)
: colors.onSurfaceVariant.withValues(alpha: .5);
const inputShape = OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(AppRadius.large)),
borderSide: BorderSide.none,
);
return theme.copyWith(
extensions: [
...theme.extensions.values,
if (desktop) const InspectorControlDensity(),
],
canvasColor: colors.surfaceContainerLow,
colorScheme: panelColors,
textTheme: panelText,
primaryTextTheme: panelText,
inputDecorationTheme: theme.inputDecorationTheme.copyWith(
constraints: BoxConstraints(
minHeight: desktop
? AppInspectorMetrics.input
: AppControlSize.propertyControl,
),
contentPadding: EdgeInsets.symmetric(
horizontal: AppSpacing.controlHorizontal,
vertical: AppSpacing.tiny,
),
fillColor: composerBackground,
hintStyle: panelText.bodyMedium?.copyWith(
color: hintColor,
leadingDistribution: TextLeadingDistribution.even,
),
border: inputShape,
enabledBorder: inputShape,
disabledBorder: inputShape,
focusedBorder: AppColors.of(theme)._legacy
? inputShape
: inputShape.copyWith(
borderSide: BorderSide(color: colors.primary),
),
errorBorder: inputShape,
focusedErrorBorder: inputShape,
),
iconButtonTheme: IconButtonThemeData(
style: theme.iconButtonTheme.style?.copyWith(
minimumSize: WidgetStatePropertyAll(Size.square(actionSize)),
maximumSize: WidgetStatePropertyAll(Size.square(actionSize)),
fixedSize: WidgetStatePropertyAll(Size.square(actionSize)),
),
),
textButtonTheme: TextButtonThemeData(
style: buttonStyle(theme.textButtonTheme.style),
),
filledButtonTheme: FilledButtonThemeData(
style: buttonStyle(theme.filledButtonTheme.style),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: buttonStyle(theme.outlinedButtonTheme.style),
),
);
}
static bool isCompactInspector(BuildContext context) =>
Theme.of(context).extension<InspectorControlDensity>() != null;
static EdgeInsets propertySectionPadding(BuildContext context) =>
isDesktop(context)
? const EdgeInsets.symmetric(
horizontal: AppInspectorMetrics.padding,
vertical: AppInspectorMetrics.groupGap / 2,
)
: AppSpacing.panelSection;
static double propertyRowGap(BuildContext context) =>
isDesktop(context) ? AppInspectorMetrics.rowGap : AppSpacing.small;
static double propertyInputHeight(BuildContext context) => isDesktop(context)
? AppInspectorMetrics.input
: AppControlSize.propertyControl;
static TextStyle propertyLabelStyle(BuildContext context) {
final theme = Theme.of(context);
return theme.textTheme.bodyMedium!.copyWith(
fontSize: isCompactInspector(context) ? 12 : null,
height: isCompactInspector(context) ? 16 / 12 : null,
leadingDistribution: TextLeadingDistribution.even,
color: theme.colorScheme.onSurfaceVariant,
);
}
static TextStyle toolbarTextStyle(BuildContext context) =>
Theme.of(context).textTheme.bodyMedium!
.copyWith(fontSize: 13, height: 18 / 13);
/// Codex desktop's compact heading-sm: 13px, 1.4 line height, medium ink.
static TextStyle propertySectionTitleStyle(BuildContext context) =>
Theme.of(context).textTheme.labelLarge!.copyWith(
height: 1.4,
color: Theme.of(context).colorScheme.onSurface,
);
static ButtonStyle toolbarButtonStyle(BuildContext context) => ButtonStyle(
textStyle: WidgetStatePropertyAll(toolbarTextStyle(context)),
minimumSize: const WidgetStatePropertyAll(
Size(0, AppControlSize.headerButton),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: AppSpacing.small),
),
);
static ThemeData dialogContentTheme(ThemeData theme) {
final inputText = theme.textTheme.bodyMedium!.copyWith(
fontSize: 14,
height: 20 / 14,
leadingDistribution: TextLeadingDistribution.even,
);
const buttonSize = WidgetStatePropertyAll(Size(0, 32));
const buttonPadding = WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: 16, vertical: AppSpacing.gap),
);
final buttonText = WidgetStatePropertyAll(
theme.textTheme.labelLarge?.copyWith(fontSize: 14, height: 20 / 14),
);
final dark = theme.brightness == Brightness.dark;
final inputBorder = OutlineInputBorder(
borderRadius: BorderRadius.circular(AppRadius.large),
borderSide: BorderSide(
color: dark
? AppColors.of(theme).dialogBorder
: theme.colorScheme.outlineVariant,
),
);
return theme.copyWith(
extensions: theme.extensions.values.where(
(value) => value is! InspectorControlDensity,
),
textTheme: theme.textTheme.copyWith(bodyMedium: inputText),
inputDecorationTheme: theme.inputDecorationTheme.copyWith(
constraints: const BoxConstraints(minHeight: 36),
fillColor: dark || !AppColors.of(theme)._legacy
? AppColors.of(theme).dialogInputBackground
: theme.colorScheme.surface,
contentPadding: const EdgeInsets.symmetric(
horizontal: 10,
vertical: AppSpacing.small,
),
hintStyle: inputText.copyWith(
color:
theme.inputDecorationTheme.hintStyle?.color ??
theme.colorScheme.onSurfaceVariant,
),
border: inputBorder,
enabledBorder: inputBorder,
focusedBorder: inputBorder.copyWith(
borderSide: BorderSide(
color: dark
? AppColors.of(theme).dialogFocusBorder
: theme.colorScheme.outline,
),
),
),
textButtonTheme: TextButtonThemeData(
style: theme.textButtonTheme.style?.copyWith(
minimumSize: buttonSize,
padding: buttonPadding,
textStyle: buttonText,
),
),
filledButtonTheme: FilledButtonThemeData(
style: theme.filledButtonTheme.style?.copyWith(
minimumSize: buttonSize,
padding: buttonPadding,
textStyle: buttonText,
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: theme.outlinedButtonTheme.style?.copyWith(
minimumSize: buttonSize,
padding: buttonPadding,
textStyle: buttonText,
),
),
);
}
static ThemeData settingsContentTheme(ThemeData theme) {
final base = dialogContentTheme(theme);
final dark = base.brightness == Brightness.dark;
final colors = base.colorScheme;
final text = base.textTheme;
final border = dark
? AppColors.of(theme).settingsBorder
: colors.outlineVariant;
final body = text.bodyMedium!.copyWith(
fontSize: 13,
height: 18 / 13,
letterSpacing: 0,
fontWeight: FontWeight.w400,
fontVariations: const [FontVariation('wght', 400)],
);
ButtonStyle? control(ButtonStyle? style) => style?.copyWith(
minimumSize: WidgetStatePropertyAll(
Size(
0,
theme.extension<DesktopControlDensity>() != null
? AppDesktopMetrics.button
: AppSettingsMetrics.controlHeight,
),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: 10, vertical: 5),
),
textStyle: WidgetStatePropertyAll(body),
iconSize: const WidgetStatePropertyAll(16),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(
theme.extension<DesktopControlDensity>() != null ? 6 : 10,
),
),
),
),
);
return base.copyWith(
colorScheme: colors.copyWith(
surface: dark ? AppColors.of(theme).background : colors.surface,
surfaceContainer: dark
? AppColors.of(theme).settingsContainer
: colors.surfaceContainer,
outlineVariant: border,
),
dividerTheme: base.dividerTheme.copyWith(color: base.dividerColor),
textTheme: text.copyWith(
bodyMedium: body,
labelLarge: body,
labelMedium: body,
bodySmall: text.bodySmall?.copyWith(fontSize: 12, height: 16 / 12),
titleLarge: text.headlineSmall?.copyWith(
fontSize: 28,
height: 36 / 28,
fontWeight: FontWeight.w600,
fontVariations: const [FontVariation('wght', 600)],
),
),
textButtonTheme: TextButtonThemeData(
style: control(base.textButtonTheme.style),
),
filledButtonTheme: FilledButtonThemeData(
style: control(base.filledButtonTheme.style)?.copyWith(
backgroundColor: WidgetStateProperty.resolveWith(
(states) =>
(AppColors.of(theme)._legacy
? colors.onSurface
: colors.primary)
.withValues(
alpha: states.contains(WidgetState.disabled) ? .3 : 1,
),
),
foregroundColor: WidgetStatePropertyAll(
AppColors.of(theme)._legacy ? colors.surface : colors.onPrimary,
),
side: const WidgetStatePropertyAll(BorderSide.none),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: control(base.outlinedButtonTheme.style)?.copyWith(
backgroundColor: WidgetStatePropertyAll(
dark
? AppColors.of(theme).settingsControlBackground
: colors.surface,
),
side: WidgetStatePropertyAll(BorderSide(color: border)),
),
),
switchTheme: base.switchTheme.copyWith(
trackColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected)
? AppColors.of(theme).settingsSwitchColor
: AppColors.of(theme).settingsSwitchTrack,
),
thumbColor: WidgetStateProperty.resolveWith(
(states) => AppColors.of(theme).settingsSwitchThumb(states),
),
),
);
}
static ThemeData dialogActionTheme(ThemeData theme) {
final colors = theme.colorScheme;
final dark = theme.brightness == Brightness.dark;
return theme.copyWith(
textButtonTheme: TextButtonThemeData(
style: theme.textButtonTheme.style?.copyWith(
backgroundColor: WidgetStatePropertyAll(
AppColors.of(theme).dialogActionBackground,
),
side: WidgetStatePropertyAll(
BorderSide(
color: dark
? AppColors.of(theme).dialogBorder
: colors.outlineVariant,
),
),
foregroundColor: WidgetStatePropertyAll(colors.onSurface),
),
),
filledButtonTheme: FilledButtonThemeData(
style: theme.filledButtonTheme.style?.copyWith(
backgroundColor: WidgetStatePropertyAll(
AppColors.of(theme)._legacy ? colors.onSurface : colors.primary,
),
foregroundColor: WidgetStatePropertyAll(
AppColors.of(theme)._legacy ? colors.surface : colors.onPrimary,
),
side: const WidgetStatePropertyAll(BorderSide.none),
),
),
);
}
static ButtonStyle panelTabStyle(
BuildContext context, {
required bool selected,
}) {
final colors = Theme.of(context).colorScheme;
final ink = colors.onSurface;
return ButtonStyle(
minimumSize: const WidgetStatePropertyAll(
Size(0, AppControlSize.headerButton),
),
maximumSize: const WidgetStatePropertyAll(
Size(double.infinity, AppControlSize.headerButton),
),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
textStyle: WidgetStatePropertyAll(toolbarTextStyle(context)),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(horizontal: AppSpacing.small),
),
shape: WidgetStatePropertyAll(
RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
),
foregroundColor: WidgetStatePropertyAll(
selected
? ink
: Theme.of(context).brightness == Brightness.dark
? ink.withValues(alpha: .498)
: colors.onSurfaceVariant,
),
backgroundColor: WidgetStatePropertyAll(
selected ? ink.withValues(alpha: .05) : Colors.transparent,
),
overlayColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.hovered) ||
states.contains(WidgetState.focused) ||
states.contains(WidgetState.pressed)) {
return selected
? ink.withValues(alpha: .05)
: ink.withValues(alpha: .078);
}
return Colors.transparent;
}),
);
}
static ButtonStyle iconButtonStyle(BuildContext context) {
final theme = Theme.of(context);
return _iconButtonStyle(theme.colorScheme.onSurface, theme.brightness);
}
static ButtonStyle _iconButtonStyle(Color ink, Brightness brightness) {
final dark = brightness == Brightness.dark;
final inactive = ink.withValues(alpha: dark ? .498 : .51);
final hover = ink.withValues(alpha: dark ? .078 : .058);
return ButtonStyle(
foregroundColor: WidgetStateProperty.resolveWith((states) {
final color = states.contains(WidgetState.selected) ? ink : inactive;
return states.contains(WidgetState.disabled)
? color.withValues(alpha: color.a * .5)
: color;
}),
backgroundColor: WidgetStateProperty.resolveWith((states) {
if (!states.contains(WidgetState.selected)) return Colors.transparent;
final interacting =
!states.contains(WidgetState.disabled) &&
(states.contains(WidgetState.hovered) ||
states.contains(WidgetState.focused) ||
states.contains(WidgetState.pressed));
return ink.withValues(alpha: interacting ? .10 : .05);
}),
overlayColor: WidgetStateProperty.resolveWith((states) {
// Selected buttons resolve their entire background above, without an
// extra overlay: Codex secondary uses bg-text/5 and hover:bg-text/10.
if (states.contains(WidgetState.disabled) ||
states.contains(WidgetState.selected)) {
return Colors.transparent;
}
if (states.contains(WidgetState.hovered) ||
states.contains(WidgetState.focused) ||
states.contains(WidgetState.pressed)) {
return hover;
}
return Colors.transparent;
}),
);
}
static ButtonStyle primaryIconButtonStyle(BuildContext context) {
final colors = Theme.of(context).colorScheme;
return ButtonStyle(
backgroundColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.disabled)
? colors.onSurface.withValues(alpha: 0.12)
: colors.primary,
),
foregroundColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.disabled)
? colors.onSurface.withValues(alpha: 0.38)
: colors.onPrimary,
),
);
}
static ButtonStyle accentIconButtonStyle(BuildContext context) {
final theme = Theme.of(context);
final colors = theme.colorScheme;
return primaryIconButtonStyle(context).copyWith(
shape: const WidgetStatePropertyAll(CircleBorder()),
backgroundColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.disabled)
? colors.onSurface.withValues(alpha: .12)
: colors.outline,
),
foregroundColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.disabled)
? colors.onSurface.withValues(alpha: .38)
: AppColors.of(theme)._legacy
? Colors.white
: colors.onPrimary,
),
);
}
static BoxDecoration userMessageDecoration(BuildContext context) =>
BoxDecoration(
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: .08),
borderRadius: const BorderRadius.all(Radius.circular(20)),
);
static TextStyle chatMessageTextStyle(BuildContext context) =>
Theme.of(context).textTheme.bodyMedium!.copyWith(
fontSize: 14,
height: 1.5,
color: Theme.of(context).colorScheme.onSurface,
);
static TextStyle chatMetaTextStyle(BuildContext context) =>
Theme.of(context).textTheme.bodySmall!.copyWith(
fontSize: 13,
height: 18 / 13,
color: Theme.of(context).colorScheme.onSurface.withValues(alpha: .5),
);
/// Splits extra line height evenly above and below editable text.
static TextStyle inputTextStyle(BuildContext context, {TextStyle? style}) =>
(style ?? Theme.of(context).textTheme.bodyMedium!).copyWith(
leadingDistribution: TextLeadingDistribution.even,
);
/// Hints share the input's metrics and retain the theme's secondary color.
static TextStyle inputHintStyle(BuildContext context, {TextStyle? style}) =>
inputTextStyle(context, style: style).copyWith(
color:
Theme.of(context).inputDecorationTheme.hintStyle?.color ??
Theme.of(context).colorScheme.onSurfaceVariant,
);
static TextStyle composerTextStyle(BuildContext context) =>
AppSidebarTypography.style(
context,
fontSize: 13,
height: 20 / 13,
color: Theme.of(context).colorScheme.onSurface,
).copyWith(leadingDistribution: TextLeadingDistribution.even);
static Color composerReferenceColor(BuildContext context) {
final theme = Theme.of(context);
return Color.lerp(
theme.colorScheme.outline,
theme.colorScheme.onSurface,
theme.brightness == Brightness.dark ? .35 : .15,
)!;
}
/// Composer action bar composites the dark elevated-secondary alpha surface.
static Color composerUtilityBackground(BuildContext context) {
final theme = Theme.of(context);
return theme.brightness == Brightness.dark
? Color.alphaBlend(
AppColors.of(theme).composerUtilityOverlay,
theme.colorScheme.surface,
)
: theme.colorScheme.surfaceContainerLow;
}
static TextStyle composerHintStyle(BuildContext context) {
final tertiary = AppSidebarColors.of(context).tertiary;
return composerTextStyle(context)
.copyWith(color: tertiary.withValues(alpha: tertiary.a * 0.5));
}
/// Match the glyph size, rather than the editable line's leading.
static double inputCursorHeight(BuildContext context, {TextStyle? style}) =>
MediaQuery.textScalerOf(context)
.scale(inputTextStyle(context, style: style).fontSize!);
static double composerCursorHeight(BuildContext context) =>
MediaQuery.textScalerOf(context)
.scale(composerTextStyle(context).fontSize!);
static const composerInputDecoration = InputDecoration(
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
disabledBorder: InputBorder.none,
filled: false,
contentPadding: EdgeInsets.only(left: 12, top: 12, right: 8),
);
static ThemeData _build(AppColors palette) {
final brightness = palette.brightness;
final colors = ColorScheme(
brightness: brightness,
primary: palette.primary,
onPrimary: palette.primaryForeground,
primaryContainer: palette.accent,
onPrimaryContainer: palette.foreground,
primaryFixed: palette.primary,
primaryFixedDim: palette.mutedForeground,
onPrimaryFixed: palette.card,
onPrimaryFixedVariant: palette.accent,
secondary: palette.foreground,
onSecondary: palette.primaryForeground,
secondaryContainer: palette.accent,
onSecondaryContainer: palette.foreground,
secondaryFixed: palette.primary,
secondaryFixedDim: palette.mutedForeground,
onSecondaryFixed: palette.card,
onSecondaryFixedVariant: palette.accent,
tertiary: palette.foreground,
onTertiary: palette.primaryForeground,
tertiaryContainer: palette.accent,
onTertiaryContainer: palette.foreground,
tertiaryFixed: palette.primary,
tertiaryFixedDim: palette.mutedForeground,
onTertiaryFixed: palette.card,
onTertiaryFixedVariant: palette.accent,
surface: palette.background,
onSurface: palette.foreground,
onSurfaceVariant: palette.mutedForeground,
surfaceDim: palette.background,
surfaceBright: palette.accent,
surfaceContainerLowest: palette.background,
surfaceContainerLow: palette.sidebar,
surfaceContainer: palette.card,
surfaceContainerHigh: palette._legacy ? palette.accent : palette.card,
surfaceContainerHighest: palette._legacy ? palette.accent : palette.card,
surfaceTint: Colors.transparent,
outline: palette.ring,
outlineVariant: palette.border,
inverseSurface: palette.foreground,
onInverseSurface: palette.card,
inversePrimary: palette.accent,
error: palette.destructive,
onError: palette.background,
errorContainer: palette.destructiveBackground,
onErrorContainer: palette.destructive,
shadow: Colors.black,
scrim: Colors.black,
);
final text = _typography(palette);
final controlShape = const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(AppRadius.menuItem)),
);
final cardShape = RoundedRectangleBorder(
borderRadius: const BorderRadius.all(Radius.circular(20)),
side: BorderSide(color: palette.border),
);
const dialogShape = RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(AppRadius.dialog)),
);
final inputBorder = OutlineInputBorder(
borderRadius: const BorderRadius.all(Radius.circular(AppRadius.large)),
borderSide: BorderSide(color: palette.input),
);
final buttonStyle = ButtonStyle(
shape: WidgetStatePropertyAll(controlShape),
minimumSize: const WidgetStatePropertyAll(
Size(0, AppControlSize.standard),
),
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
textStyle: WidgetStatePropertyAll(text.labelLarge),
iconSize: const WidgetStatePropertyAll(AppIconSize.standard),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(
horizontal: AppSpacing.controlHorizontal,
vertical: AppSpacing.tiny,
),
),
overlayColor: WidgetStateProperty.resolveWith((states) {
if (states.contains(WidgetState.focused)) {
return palette.ring.withValues(alpha: 0.3);
}
if (states.contains(WidgetState.hovered) ||
states.contains(WidgetState.pressed)) {
return palette.foreground.withValues(alpha: 0.05);
}
return null;
}),
);
final foreground = WidgetStateProperty.resolveWith<Color>(
(states) => states.contains(WidgetState.disabled)
? palette.foreground.withValues(alpha: 0.5)
: palette.foreground,
);
return ThemeData(
brightness: brightness,
useMaterial3: true,
colorScheme: colors,
fontFamily: systemFontFamily(defaultTargetPlatform),
fontFamilyFallback: systemFontFamilyFallback(defaultTargetPlatform),
textTheme: text,
primaryTextTheme: text,
scaffoldBackgroundColor: palette.background,
canvasColor: palette.background,
disabledColor: palette.foreground.withValues(alpha: 0.5),
hoverColor: palette.accent,
focusColor: palette.ring.withValues(alpha: 0.3),
splashFactory: NoSplash.splashFactory,
dividerColor: palette.divider,
visualDensity: VisualDensity.standard,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
appBarTheme: AppBarThemeData(
backgroundColor: palette.background,
foregroundColor: palette.foreground,
surfaceTintColor: Colors.transparent,
elevation: 0,
titleTextStyle: text.titleLarge,
toolbarHeight: AppControlSize.panelHeader,
),
dividerTheme: DividerThemeData(
color: palette.divider,
thickness: brightness == Brightness.dark ? 0.5 : 1,
space: 1,
),
iconTheme: IconThemeData(
color: palette.mutedForeground,
size: AppIconSize.standard,
),
actionIconTheme: ActionIconThemeData(
backButtonIconBuilder: (_) => const Icon(AppIcons.arrowBack),
closeButtonIconBuilder: (_) => const Icon(AppIcons.close),
drawerButtonIconBuilder: (_) => const Icon(AppIcons.menu),
endDrawerButtonIconBuilder: (_) => const Icon(AppIcons.menu),
),
iconButtonTheme: IconButtonThemeData(
style: _iconButtonStyle(palette.foreground, brightness)
.merge(buttonStyle)
.copyWith(
minimumSize: const WidgetStatePropertyAll(
Size.square(AppControlSize.compact),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.all(AppSpacing.tiny),
),
),
),
cardTheme: CardThemeData(
color: palette.card,
surfaceTintColor: Colors.transparent,
elevation: 0,
margin: EdgeInsets.zero,
shape: cardShape,
clipBehavior: Clip.antiAlias,
),
dialogTheme: DialogThemeData(
backgroundColor: palette.popover,
surfaceTintColor: Colors.transparent,
shape: dialogShape,
titleTextStyle: text.headlineSmall?.copyWith(
fontWeight: FontWeight.w600,
fontVariations: const [FontVariation('wght', 600)],
),
contentTextStyle: text.bodyMedium?.copyWith(
fontSize: 14,
height: 20 / 14,
),
actionsPadding: const EdgeInsets.all(AppSpacing.large),
barrierColor: Colors.black.withValues(alpha: 0.5),
),
inputDecorationTheme: InputDecorationThemeData(
constraints: const BoxConstraints(minHeight: AppControlSize.input),
isDense: true,
filled: true,
fillColor: palette.inputFill,
border: inputBorder,
enabledBorder: inputBorder,
disabledBorder: inputBorder,
focusedBorder: inputBorder.copyWith(
borderSide: BorderSide(color: palette.ring, width: 2),
),
errorBorder: inputBorder.copyWith(
borderSide: BorderSide(color: palette.destructive),
),
focusedErrorBorder: inputBorder.copyWith(
borderSide: BorderSide(color: palette.destructive, width: 2),
),
contentPadding: const EdgeInsets.symmetric(
horizontal: AppSpacing.controlHorizontal,
vertical: AppSpacing.inputVertical,
),
hintStyle: text.bodyMedium?.copyWith(
color: palette.mutedForeground,
leadingDistribution: TextLeadingDistribution.even,
),
labelStyle: text.bodyMedium?.copyWith(color: palette.mutedForeground),
errorStyle: text.bodySmall?.copyWith(color: palette.destructive),
),
textSelectionTheme: TextSelectionThemeData(
cursorColor: palette.foreground,
selectionColor: palette.ring.withValues(alpha: 0.5),
selectionHandleColor: palette.foreground,
),
filledButtonTheme: FilledButtonThemeData(
style: buttonStyle.copyWith(
backgroundColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.disabled)
? palette.filledButtonBackground.withValues(alpha: 0.5)
: palette.filledButtonBackground,
),
foregroundColor: WidgetStatePropertyAll(
palette.filledButtonForeground,
),
side: WidgetStatePropertyAll(
BorderSide(
color: palette._legacy ? palette.buttonBorder : palette.primary,
),
),
),
),
outlinedButtonTheme: OutlinedButtonThemeData(
style: buttonStyle.copyWith(
side: WidgetStatePropertyAll(BorderSide(color: palette.buttonBorder)),
foregroundColor: foreground,
),
),
textButtonTheme: TextButtonThemeData(
style: buttonStyle.copyWith(foregroundColor: foreground),
),
popupMenuTheme: PopupMenuThemeData(
textStyle: text.bodyMedium,
color: palette.popover,
surfaceTintColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppMenuMetrics.radius),
side: BorderSide(
color: palette.border,
width: AppMenuMetrics.borderWidth,
),
),
menuPadding: const EdgeInsets.all(AppMenuMetrics.gutter),
),
menuTheme: MenuThemeData(
style: MenuStyle(
backgroundColor: WidgetStatePropertyAll(palette.popover),
surfaceTintColor: const WidgetStatePropertyAll(Colors.transparent),
side: WidgetStatePropertyAll(
BorderSide(
color: palette.border,
width: AppMenuMetrics.borderWidth,
),
),
padding: const WidgetStatePropertyAll(
EdgeInsets.all(AppMenuMetrics.gutter),
),
shape: const WidgetStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(AppMenuMetrics.radius),
),
),
),
),
),
menuButtonTheme: MenuButtonThemeData(
style: buttonStyle.copyWith(
textStyle: WidgetStatePropertyAll(
text.bodyMedium?.copyWith(
height: AppMenuMetrics.lineHeight / AppMenuMetrics.fontSize,
),
),
minimumSize: const WidgetStatePropertyAll(
Size(0, AppMenuMetrics.rowHeight),
),
iconSize: const WidgetStatePropertyAll(AppMenuMetrics.iconSize),
padding: const WidgetStatePropertyAll(
EdgeInsets.symmetric(
horizontal: AppMenuMetrics.iconGap,
vertical: 5,
),
),
shape: const WidgetStatePropertyAll(
RoundedRectangleBorder(
borderRadius: BorderRadius.all(
Radius.circular(AppMenuMetrics.itemRadius),
),
),
),
),
),
listTileTheme: ListTileThemeData(
minTileHeight: AppControlSize.standard,
minVerticalPadding: AppSpacing.tiny,
horizontalTitleGap: AppSpacing.small,
minLeadingWidth: AppIconSize.standard,
iconColor: palette.mutedForeground,
textColor: palette.foreground,
selectedColor: palette.foreground,
selectedTileColor: palette.accent,
titleTextStyle: text.bodyMedium,
subtitleTextStyle: text.bodySmall,
contentPadding: const EdgeInsets.symmetric(
horizontal: AppSpacing.compact,
),
),
snackBarTheme: SnackBarThemeData(
backgroundColor: palette.card,
contentTextStyle: text.bodyMedium,
behavior: SnackBarBehavior.floating,
shape: cardShape,
),
tooltipTheme: TooltipThemeData(
textStyle: text.bodySmall?.copyWith(color: palette.card),
decoration: ShapeDecoration(
color: palette.foreground,
shape: controlShape,
),
padding: const EdgeInsets.symmetric(
horizontal: AppSpacing.small,
vertical: AppSpacing.tiny,
),
),
progressIndicatorTheme: ProgressIndicatorThemeData(
color: palette.primary,
linearMinHeight: 2,
),
checkboxTheme: CheckboxThemeData(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(AppRadius.small),
),
side: BorderSide(color: palette.input),
fillColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected)
? palette.primary
: palette.inputFill,
),
checkColor: WidgetStatePropertyAll(palette.primaryForeground),
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
switchTheme: SwitchThemeData(
trackOutlineColor: const WidgetStatePropertyAll(Colors.transparent),
trackColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected)
? palette.primary
: palette.input,
),
thumbColor: WidgetStateProperty.resolveWith(
(states) => states.contains(WidgetState.selected)
? palette.primaryForeground
: palette.foreground,
),
),
scrollbarTheme: ScrollbarThemeData(
thickness: const WidgetStatePropertyAll(6),
radius: const Radius.circular(3),
thumbColor: WidgetStateProperty.resolveWith((states) {
final interacting =
states.contains(WidgetState.hovered) ||
states.contains(WidgetState.dragged) ||
states.contains(WidgetState.pressed);
return palette.foreground.withValues(
alpha: brightness == Brightness.dark
? (interacting ? .156 : .084)
: (interacting ? .126 : .084),
);
}),
trackColor: const WidgetStatePropertyAll(Colors.transparent),
trackBorderColor: const WidgetStatePropertyAll(Colors.transparent),
),
extensions: [
_AppPaletteData(palette),
AppSurfaces(
previewBackground: Colors.black,
composerBackground: palette.composer,
popoverBackground: palette.popover,
errorText: text.bodyMedium!.copyWith(color: palette.destructive),
),
],
);
}
static TextTheme _typography(AppColors palette) {
TextStyle style(
double size,
double lineHeight, {
FontWeight weight = FontWeight.w400,
Color? color,
}) => TextStyle(
inherit: false,
fontFamily: systemFontFamily(defaultTargetPlatform),
fontFamilyFallback: systemFontFamilyFallback(defaultTargetPlatform),
textBaseline: TextBaseline.alphabetic,
fontSize: size,
height: lineHeight / size,
fontWeight: weight,
letterSpacing: 0,
color: color ?? palette.foreground,
);
return TextTheme(
displayLarge: style(48, 56, weight: FontWeight.w600),
displayMedium: style(36, 44, weight: FontWeight.w600),
displaySmall: style(30, 38, weight: FontWeight.w600),
headlineLarge: style(28, 36, weight: FontWeight.w600),
headlineMedium: style(24, 32, weight: FontWeight.w600),
headlineSmall: style(20, 28, weight: FontWeight.w600),
titleLarge: style(18, 24, weight: FontWeight.w600),
titleMedium: style(14, 21, weight: FontWeight.w500),
titleSmall: style(14, 20, weight: FontWeight.w500),
bodyLarge: style(16, 24),
bodyMedium: style(13, 20),
bodySmall: style(12, 18, color: palette.mutedForeground),
labelLarge: style(13, 20, weight: FontWeight.w500),
labelMedium: style(12, 18, weight: FontWeight.w500),
labelSmall: style(12, 18, color: palette.mutedForeground),
);
}
}
/// Workspace surfaces and semantic colors. Pen presets remain compatible with
/// existing integrations; selectable palettes share one surface hierarchy.
enum AppColors {
penLight,
penDark,
graphiteLight,
graphiteDark,
violetLight,
violetDark,
tealLight,
tealDark;
bool get _legacy => index < 2;
bool get _dark => index.isOdd;
Brightness get brightness => _dark ? Brightness.dark : Brightness.light;
static AppColors forPalette(AppPalette palette, Brightness brightness) {
final dark = brightness == Brightness.dark;
return switch (palette) {
AppPalette.graphite => dark ? graphiteDark : graphiteLight,
AppPalette.violet => dark ? violetDark : violetLight,
AppPalette.teal => dark ? tealDark : tealLight,
};
}
static AppColors of(ThemeData theme) =>
theme.extension<_AppPaletteData>()?.colors ??
(theme.brightness == Brightness.dark ? penDark : penLight);
AppPalette get family => switch (this) {
violetLight || violetDark => AppPalette.violet,
tealLight || tealDark => AppPalette.teal,
_ => AppPalette.graphite,
};
(Color, Color, Color, Color) get _surfaces => switch ((family, _dark)) {
(AppPalette.graphite, false) => (
const Color(0xFFF3F3F3),
const Color(0xFFFAFAFA),
const Color(0xFFFFFFFF),
const Color(0xFFDDDDDD),
),
(AppPalette.graphite, true) => (
const Color(0xFF181818),
const Color(0xFF202020),
const Color(0xFF282828),
const Color(0xFF363636),
),
(AppPalette.violet, false) => (
const Color(0xFFF3F3F5),
const Color(0xFFFAFAFA),
const Color(0xFFFFFFFF),
const Color(0xFFDEDEE3),
),
(AppPalette.violet, true) => (
const Color(0xFF19191C),
const Color(0xFF222226),
const Color(0xFF2B2B30),
const Color(0xFF393940),
),
(AppPalette.teal, false) => (
const Color(0xFFF4F3F0),
const Color(0xFFFAF9F6),
const Color(0xFFFFFFFF),
const Color(0xFFDEDBD5),
),
(AppPalette.teal, true) => (
const Color(0xFF1C1B19),
const Color(0xFF252420),
const Color(0xFF2E2D29),
const Color(0xFF3D3B35),
),
};
Color get background => _legacy
? (_dark ? const Color(0xFF111111) : const Color(0xFFF6F6F6))
: _surfaces.$1;
Color get foreground => _legacy
? (_dark ? const Color(0xFFFCFCFC) : const Color(0xFF020202))
: (_dark ? const Color(0xFFEEEEEE) : const Color(0xFF242424));
Color get card => _legacy
? (_dark ? const Color(0xFF27272A) : const Color(0xFFFAFAFA))
: _surfaces.$3;
Color get popover => _legacy && _dark ? const Color(0xFF242424) : card;
Color get sidebar => _legacy
? (_dark ? const Color(0xFF151515) : const Color(0xFFFAFAFA))
: _surfaces.$2;
Color get primary => _legacy
? (_dark ? const Color(0xFFF4F4F5) : const Color(0xFF18181B))
: ring;
Color get primaryForeground => _legacy
? (_dark ? const Color(0xFF18181B) : const Color(0xFFFAFAFA))
: (_dark ? const Color(0xFF111111) : Colors.white);
Color get accent => _legacy
? (_dark ? const Color(0xFF3F3F46) : const Color(0xFFECECEE))
: Color.alphaBlend(foreground.withValues(alpha: .06), sidebar);
Color get mutedForeground => _legacy
? (_dark
? const Color(0xFFFCFCFC).withValues(alpha: .71)
: const Color(0xFF71717A))
: (_dark ? const Color(0xFFAAAAAA) : const Color(0xFF666666));
Color get ring => _legacy
? const Color(0xFF3B82F6)
: switch ((family, _dark)) {
(AppPalette.graphite, false) => const Color(0xFF2563EB),
(AppPalette.graphite, true) => const Color(0xFF6B9FFF),
(AppPalette.violet, false) => const Color(0xFF6D4BD1),
(AppPalette.violet, true) => const Color(0xFFAD9AF2),
(AppPalette.teal, false) => const Color(0xFF147566),
(AppPalette.teal, true) => const Color(0xFF76C5B0),
};
Color get border => _legacy
? (_dark
? const Color(0xFFFCFCFC).withValues(alpha: .084)
: const Color(0xFFE4E4E7))
: _surfaces.$4;
Color get divider => _legacy && _dark ? const Color(0xFF303030) : border;
Color get input => _legacy
? (_dark ? const Color(0x1AC8C8C8) : const Color(0x0A020202))
: border;
Color get inputFill => _legacy ? input : card;
Color get buttonBackground => _legacy
? (_dark ? const Color(0xFF18181B) : const Color(0xFFFAFAFA))
: sidebar;
Color get filledButtonBackground => _legacy ? buttonBackground : primary;
Color get filledButtonForeground => _legacy ? foreground : primaryForeground;
Color get buttonBorder => _legacy && _dark ? const Color(0xFF38383C) : border;
Color get destructive =>
_dark ? const Color(0xFFFF6467) : const Color(0xFFE7000B);
Color get destructiveBackground =>
destructive.withValues(alpha: _dark ? .2 : .1);
Color get visualClip => _legacy
? (_dark ? const Color(0xFF2F2F2F) : accent)
: (_dark ? const Color(0xFF304053) : const Color(0xFFD8E3F0));
Color get audioClip => _legacy
? popover
: (_dark ? const Color(0xFF2D4740) : const Color(0xFFD5E8E2));
Color get audioWaveform => _legacy
? mutedForeground
: (_dark ? const Color(0xFF9AD3BE) : const Color(0xFF28624D));
Color get selection => _legacy ? foreground : ring;
Color get composer =>
_legacy ? (_dark ? const Color(0xFF2F2F2F) : background) : card;
Color get composerUtilityOverlay =>
_dark ? foreground.withValues(alpha: .032) : Colors.transparent;
Color get dialogBorder => _legacy && _dark ? const Color(0xFF3C3C3C) : border;
Color get dialogInputBackground =>
_legacy ? (_dark ? const Color(0xFF262626) : background) : card;
Color get dialogFocusBorder =>
_legacy && _dark ? const Color(0xFF6084AF) : ring;
Color get dialogActionBackground => _legacy
? (_dark ? const Color(0xFF2B2B2B) : const Color(0xFFF0F0F0))
: sidebar;
Color get settingsSidebar =>
_legacy && _dark ? const Color(0xFF141414) : sidebar;
Color get settingsContainer =>
_legacy && _dark ? const Color(0xFF1C1C1C) : card;
Color get settingsBorder =>
_legacy && _dark ? const Color(0xFF2E2E2E) : border;
Color get settingsControlBackground =>
_legacy ? (_dark ? const Color(0xFF262626) : background) : card;
Color get settingsSwitchTrack => _legacy
? (_dark ? const Color(0xFF333333) : const Color(0xFFD0D0D0))
: border;
static const settingsSwitchAccent = Color(0xFF007AFF);
Color get settingsSwitchColor => _legacy ? settingsSwitchAccent : primary;
Color settingsSwitchThumb(Set<WidgetState> states) => _legacy
? Colors.white
: states.contains(WidgetState.selected)
? primaryForeground
: foreground;
AppSidebarColors resolveSidebarColors(
ColorScheme colors, {
required Color disabledColor,
}) {
if (_dark) {
final ink = foreground;
return AppSidebarColors(
primary: ink.withValues(alpha: .85),
secondary: ink.withValues(alpha: .71),
tertiary: ink.withValues(alpha: .498),
disabled: ink.withValues(alpha: .85 * .6),
hover: ink.withValues(alpha: .078),
section: ink.withValues(alpha: .498 * .75),
);
}
return AppSidebarColors(
primary: colors.onSurface,
secondary: colors.onSurfaceVariant,
tertiary: colors.onSurfaceVariant,
disabled: disabledColor,
hover: colors.onSurface.withValues(alpha: .0535),
section: colors.onSurfaceVariant.withValues(alpha: .75),
);
}
}
class _AppPaletteData extends ThemeExtension<_AppPaletteData> {
const _AppPaletteData(this.colors);
final AppColors colors;
@override
_AppPaletteData copyWith({AppColors? colors}) =>
_AppPaletteData(colors ?? this.colors);
@override
_AppPaletteData lerp(covariant _AppPaletteData? other, double t) =>
other == null || t < .5 ? this : other;
}
/// Styles with product semantics that Material's built-in themes do not expose.
@immutable
class AppSurfaces extends ThemeExtension<AppSurfaces> {
const AppSurfaces({
required this.previewBackground,
required this.composerBackground,
required this.popoverBackground,
required this.errorText,
});
final Color previewBackground;
final Color composerBackground;
final Color popoverBackground;
final TextStyle errorText;
static AppSurfaces of(BuildContext context) =>
Theme.of(context).extension<AppSurfaces>()!;
@override
AppSurfaces copyWith({
Color? previewBackground,
Color? composerBackground,
Color? popoverBackground,
TextStyle? errorText,
}) => AppSurfaces(
previewBackground: previewBackground ?? this.previewBackground,
composerBackground: composerBackground ?? this.composerBackground,
popoverBackground: popoverBackground ?? this.popoverBackground,
errorText: errorText ?? this.errorText,
);
@override
AppSurfaces lerp(covariant AppSurfaces? other, double t) {
if (other == null) return this;
return AppSurfaces(
previewBackground: Color.lerp(
previewBackground,
other.previewBackground,
t,
)!,
composerBackground: Color.lerp(
composerBackground,
other.composerBackground,
t,
)!,
popoverBackground: Color.lerp(
popoverBackground,
other.popoverBackground,
t,
)!,
errorText: TextStyle.lerp(errorText, other.errorText, t)!,
);
}
}
abstract final class AppSidebarMetrics {
static const rowHeight = 30.0;
static const modeHeight = 32.0;
static const outerPadding = 8.0;
static const cellPadding = 8.0;
static const iconSize = 16.0;
static const iconGap = 0.0;
// hZ: row-sized icon slot, -3px margins, and 4px padding on each side.
static const iconSlotWidth = rowHeight + 2;
static const actionSize = 24.0;
static const radius = 10.0;
static const fontSize = 14.0;
static const conversationFontSize = 14.0;
static const conversationLineHeight = 20 / conversationFontSize;
static const lineHeight = 1.5;
static const sectionFontSize = 14.0;
static const sectionHeight = 25.0;
static const sectionGap = 4.0;
static const rowGap = 1.0;
static const projectGap = 1.0;
static const hintFontSize = 12.0;
static const titleFontSize = 18.0;
static const titleLineHeight = 24 / titleFontSize;
static const textInset = iconSlotWidth;
static const rowPadding = EdgeInsets.symmetric(horizontal: outerPadding);
}
/// Sidebar typography retains its own size and foreground hierarchy.
abstract final class AppSidebarTypography {
static TextStyle style(
BuildContext context, {
double fontSize = AppSidebarMetrics.fontSize,
double height = AppSidebarMetrics.lineHeight,
FontWeight weight = FontWeight.w400,
Color? color,
}) => TextStyle(
fontFamily: AppTheme.systemFontFamily(Theme.of(context).platform),
fontFamilyFallback: AppTheme.systemFontFamilyFallback(
Theme.of(context).platform,
),
fontSize: fontSize,
height: height,
fontWeight: weight,
color: color ?? AppSidebarColors.of(context).primary,
);
}
/// Text hierarchy for project navigation, independent of editor text colors.
@immutable
class AppSidebarColors {
const AppSidebarColors({
required this.primary,
required this.secondary,
required this.tertiary,
required this.disabled,
required this.hover,
required this.section,
});
final Color primary;
final Color secondary;
final Color tertiary;
final Color disabled;
final Color hover;
final Color section;
static AppSidebarColors of(BuildContext context) {
final theme = Theme.of(context);
final palette = AppColors.of(theme);
return palette.resolveSidebarColors(
theme.colorScheme,
disabledColor: theme.disabledColor,
);
}
}
/// Shared spacing for compact controls and unframed editor panels.
abstract final class AppSpacing {
static const hairline = 2.0;
static const tiny = 4.0;
static const gap = 6.0;
static const small = 8.0;
static const itemVertical = 10.0;
static const controlHorizontal = 8.0;
static const panelContentHorizontal = gap + controlHorizontal;
static const inputVertical = 3.0;
static const compact = 12.0;
static const medium = 16.0;
static const large = 20.0;
static const extraLarge = 24.0;
static const dialogHorizontal = 32.0;
static const page = 16.0;
static const emptyState = 64.0;
static const panelSection = EdgeInsets.symmetric(
horizontal: panelContentHorizontal,
vertical: small,
);
}
/// Compact desktop controls with slightly softer dialog and card corners.
abstract final class AppRadius {
static const extraSmall = 3.0;
static const large = 6.0;
static const small = 4.0;
static const medium = 5.0;
static const menuItem = 8.0;
static const extraLarge = 10.0;
static const dialog = 20.0;
static const pill = 999.0;
}
abstract final class AppSettingsMetrics {
static const contentPadding = EdgeInsets.all(AppSpacing.large);
static const rowVerticalPadding = AppSpacing.compact;
static const controlHeight = 28.0;
static const inputHeight = 36.0;
static const controlWidth = 144.0;
static const contentWidth = 728.0;
static const cardRadius = 16.0;
}
/// Desktop geometry is separate from touch component defaults.
abstract final class AppDesktopMetrics {
static const windowHeader = 44.0;
static const panelHeader = 36.0;
static const timelineTabs = 32.0;
static const timelineTabControl = 26.0;
static const timelineTabRadius = 7.0;
static const timelineToolbar = 36.0;
static const timelineRuler = 28.0;
static const playbackBar = 36.0;
static const iconButton = 28.0;
static const button = 32.0;
static const input = 36.0;
static const sidebarRow = 32.0;
static const panelPadding = 12.0;
}
/// Window project tabs have their own geometry, separate from timeline tabs.
abstract final class AppProjectTabMetrics {
static const height = 28.0;
static const close = 24.0;
static const radius = 6.0;
static const gap = 4.0;
static const minWidth = 112.0;
static const maxWidth = 180.0;
}
/// Geometry for desktop parameter editing, independent of general inputs.
abstract final class AppInspectorMetrics {
static const input = 28.0;
static const action = 24.0;
static const rowGap = 4.0;
static const groupGap = 12.0;
static const padding = 12.0;
}
class InspectorControlDensity extends ThemeExtension<InspectorControlDensity> {
const InspectorControlDensity();
@override
InspectorControlDensity copyWith() => this;
@override
InspectorControlDensity lerp(
covariant InspectorControlDensity? other,
double t,
) => this;
}
class DesktopControlDensity extends ThemeExtension<DesktopControlDensity> {
const DesktopControlDensity();
@override
DesktopControlDensity copyWith() => this;
@override
DesktopControlDensity lerp(
covariant DesktopControlDensity? other,
double t,
) => this;
}
abstract final class AppControlSize {
static const compact = 24.0;
static const small = 24.0;
static const standard = 24.0;
static const input = 24.0;
static const propertyControl = 28.0;
static const propertyItem = 32.0;
static const headerButton = 28.0;
static const panelHeader = 46.0;
static const panelToolbar = 40.0;
}
abstract final class AppIconSize {
static const header = 16.0;
static const small = 16.0;
static const standard = 16.0;
static const emptyState = 24.0;
static const project = 40.0;
}