import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:google_fonts/google_fonts.dart'; class EditorStyleCustomizer { EditorStyleCustomizer({ required this.context, }); static double get horizontalPadding => PlatformExtension.isDesktop ? 50.0 : 10.0; final BuildContext context; EditorStyle style() { if (PlatformExtension.isDesktopOrWeb) { return desktop(); } else if (PlatformExtension.isMobile) { return mobile(); } throw UnimplementedError(); } EditorStyle desktop() { final theme = Theme.of(context); final fontSize = context.read().state.fontSize; return EditorStyle.desktop( padding: EdgeInsets.symmetric(horizontal: horizontalPadding), backgroundColor: theme.colorScheme.surface, cursorColor: theme.colorScheme.primary, textStyleConfiguration: TextStyleConfiguration( text: TextStyle( fontFamily: 'Poppins', fontSize: fontSize, color: theme.colorScheme.onBackground, height: 1.5, ), bold: const TextStyle( fontFamily: 'Poppins-Bold', fontWeight: FontWeight.w600, ), italic: const TextStyle(fontStyle: FontStyle.italic), underline: const TextStyle(decoration: TextDecoration.underline), strikethrough: const TextStyle(decoration: TextDecoration.lineThrough), href: TextStyle( color: theme.colorScheme.primary, decoration: TextDecoration.underline, ), code: GoogleFonts.robotoMono( textStyle: TextStyle( fontSize: fontSize, fontWeight: FontWeight.normal, color: Colors.red, backgroundColor: theme.colorScheme.inverseSurface, ), ), ), ); } EditorStyle mobile() { final theme = Theme.of(context); final fontSize = context.read().state.fontSize; return EditorStyle.desktop( padding: EdgeInsets.symmetric(horizontal: horizontalPadding), backgroundColor: theme.colorScheme.surface, cursorColor: theme.colorScheme.primary, textStyleConfiguration: TextStyleConfiguration( text: TextStyle( fontFamily: 'poppins', fontSize: fontSize, color: theme.colorScheme.onBackground, height: 1.5, ), bold: const TextStyle( fontFamily: 'poppins-Bold', fontWeight: FontWeight.w600, ), italic: const TextStyle(fontStyle: FontStyle.italic), underline: const TextStyle(decoration: TextDecoration.underline), strikethrough: const TextStyle(decoration: TextDecoration.lineThrough), href: TextStyle( color: theme.colorScheme.primary, decoration: TextDecoration.underline, ), code: GoogleFonts.robotoMono( textStyle: TextStyle( fontSize: fontSize, fontWeight: FontWeight.normal, color: Colors.red, backgroundColor: theme.colorScheme.inverseSurface, ), ), ), ); } TextStyle headingStyleBuilder(int level) { final fontSize = context.read().state.fontSize; final fontSizes = [ fontSize + 16, fontSize + 12, fontSize + 8, fontSize + 4, fontSize + 2, fontSize ]; return TextStyle( fontSize: fontSizes.elementAtOrNull(level - 1) ?? fontSize, fontWeight: FontWeight.bold, ); } TextStyle codeBlockStyleBuilder() { final theme = Theme.of(context); final fontSize = context.read().state.fontSize; return TextStyle( fontFamily: 'poppins', fontSize: fontSize, height: 1.5, color: theme.colorScheme.onBackground, ); } }