editor_style.dart 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart';
  2. import 'package:appflowy_editor/appflowy_editor.dart';
  3. import 'package:collection/collection.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_bloc/flutter_bloc.dart';
  6. import 'package:google_fonts/google_fonts.dart';
  7. class EditorStyleCustomizer {
  8. EditorStyleCustomizer({
  9. required this.context,
  10. });
  11. static double get horizontalPadding =>
  12. PlatformExtension.isDesktop ? 100.0 : 10.0;
  13. final BuildContext context;
  14. EditorStyle style() {
  15. if (PlatformExtension.isDesktopOrWeb) {
  16. return desktop();
  17. } else if (PlatformExtension.isMobile) {
  18. return mobile();
  19. }
  20. throw UnimplementedError();
  21. }
  22. EditorStyle desktop() {
  23. final theme = Theme.of(context);
  24. final fontSize = context.read<DocumentAppearanceCubit>().state.fontSize;
  25. return EditorStyle.desktop(
  26. padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
  27. backgroundColor: theme.colorScheme.surface,
  28. cursorColor: theme.colorScheme.primary,
  29. textStyleConfiguration: TextStyleConfiguration(
  30. text: TextStyle(
  31. fontFamily: 'poppins',
  32. fontSize: fontSize,
  33. color: theme.colorScheme.onBackground,
  34. height: 1.5,
  35. ),
  36. bold: const TextStyle(
  37. fontFamily: 'poppins-Bold',
  38. fontWeight: FontWeight.w600,
  39. ),
  40. italic: const TextStyle(fontStyle: FontStyle.italic),
  41. underline: const TextStyle(decoration: TextDecoration.underline),
  42. strikethrough: const TextStyle(decoration: TextDecoration.lineThrough),
  43. href: TextStyle(
  44. color: theme.colorScheme.primary,
  45. decoration: TextDecoration.underline,
  46. ),
  47. code: GoogleFonts.robotoMono(
  48. textStyle: TextStyle(
  49. fontSize: fontSize,
  50. fontWeight: FontWeight.normal,
  51. color: Colors.red,
  52. backgroundColor: theme.colorScheme.inverseSurface,
  53. ),
  54. ),
  55. ),
  56. );
  57. }
  58. EditorStyle mobile() {
  59. final theme = Theme.of(context);
  60. final fontSize = context.read<DocumentAppearanceCubit>().state.fontSize;
  61. return EditorStyle.desktop(
  62. padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
  63. backgroundColor: theme.colorScheme.surface,
  64. cursorColor: theme.colorScheme.primary,
  65. textStyleConfiguration: TextStyleConfiguration(
  66. text: TextStyle(
  67. fontFamily: 'poppins',
  68. fontSize: fontSize,
  69. color: theme.colorScheme.onBackground,
  70. height: 1.5,
  71. ),
  72. bold: const TextStyle(
  73. fontFamily: 'poppins-Bold',
  74. fontWeight: FontWeight.w600,
  75. ),
  76. italic: const TextStyle(fontStyle: FontStyle.italic),
  77. underline: const TextStyle(decoration: TextDecoration.underline),
  78. strikethrough: const TextStyle(decoration: TextDecoration.lineThrough),
  79. href: TextStyle(
  80. color: theme.colorScheme.primary,
  81. decoration: TextDecoration.underline,
  82. ),
  83. code: GoogleFonts.robotoMono(
  84. textStyle: TextStyle(
  85. fontSize: fontSize,
  86. fontWeight: FontWeight.normal,
  87. color: Colors.red,
  88. backgroundColor: theme.colorScheme.inverseSurface,
  89. ),
  90. ),
  91. ),
  92. );
  93. }
  94. TextStyle headingStyleBuilder(int level) {
  95. final fontSize = context.read<DocumentAppearanceCubit>().state.fontSize;
  96. final fontSizes = [
  97. fontSize + 16,
  98. fontSize + 12,
  99. fontSize + 8,
  100. fontSize + 4,
  101. fontSize + 2,
  102. fontSize
  103. ];
  104. return TextStyle(
  105. fontSize: fontSizes.elementAtOrNull(level - 1) ?? fontSize,
  106. fontWeight: FontWeight.bold,
  107. );
  108. }
  109. TextStyle codeBlockStyleBuilder() {
  110. final fontSize = context.read<DocumentAppearanceCubit>().state.fontSize;
  111. return TextStyle(
  112. fontFamily: 'poppins',
  113. fontSize: fontSize,
  114. height: 1.5,
  115. );
  116. }
  117. }