Skip to content

Commit c8416d2

Browse files
committed
feat: use external web colors and more bbcode parsing
This commit moved pre-defined web colors and related color utilities to external package `dart_bbcode_web_colors` because multiple packages in this project rely on the same functionality. Besides, update upstream code to get more bbcode parsing support, till now most frequently used bbcode tags can be recognized and parsed into quill delta.
1 parent a77a57f commit c8416d2

File tree

9 files changed

+25
-364
lines changed

9 files changed

+25
-364
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@
77
[submodule "packages/dart_bbcode_parser"]
88
path = packages/dart_bbcode_parser
99
url = https://github.com/realth000/dart_bbcode_parser.git
10+
[submodule "packages/dart_bbcode_web_colors"]
11+
path = packages/dart_bbcode_web_colors
12+
url = git@github.com:realth000/dart_bbcode_web_colors.git

lib/utils/html/css_parser.dart

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import 'dart:ui';
22

3+
import 'package:dart_bbcode_web_colors/dart_bbcode_web_colors.dart';
34
import 'package:tsdm_client/shared/models/models.dart';
4-
import 'package:tsdm_client/utils/html/web_colors.dart';
5-
6-
final _colorRe = RegExp(r'^(#)?[0-9a-fA-F]{1,6}$');
75

86
/// Parse a [String] of css to [CssTypes].
97
///
@@ -60,44 +58,3 @@ FontWeight? _parseFontWeight(String data) {
6058

6159
return (cssPart.substring(0, separateIndex), cssPart.substring(separateIndex + 1));
6260
}
63-
64-
/// Extension to convert nullable string to [Color].
65-
extension StringToColorExt on String? {
66-
/// Parse nullable color string to [Color].
67-
///
68-
/// * If `this` is null, return null.
69-
/// * Parse `this` in style `#COLOR_VALUE` or `COLOR_NAME` where COLOR_NAME is
70-
/// hit in [WebColors].
71-
Color? toColor() {
72-
int? colorValue;
73-
// Parse as color value.
74-
if (this != null && _colorRe.hasMatch(this!)) {
75-
if (this!.startsWith('#')) {
76-
if (this!.length == 4) {
77-
// #abc format short hand for #aabbcc.
78-
colorValue = int.tryParse(
79-
'${this![1]}${this![1]}${this![2]}'
80-
'${this![2]}${this![3]}${this![3]}',
81-
radix: 16,
82-
);
83-
} else {
84-
// Normal #aabbcc format.
85-
colorValue = int.tryParse(this!.substring(1), radix: 16);
86-
}
87-
} else {
88-
colorValue = int.tryParse(this!, radix: 16);
89-
}
90-
}
91-
if (colorValue != null) {
92-
colorValue += 0xFF000000;
93-
return Color(colorValue);
94-
} else {
95-
// If color not in format #aabcc, try parse as color name.
96-
final webColor = WebColors.fromString(this);
97-
if (webColor.isValid) {
98-
return webColor.color;
99-
}
100-
}
101-
return null;
102-
}
103-
}

lib/utils/html/html_muncher.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:collection/collection.dart';
2+
import 'package:dart_bbcode_web_colors/dart_bbcode_web_colors.dart';
23
import 'package:flutter/gestures.dart';
34
import 'package:flutter/material.dart';
45
import 'package:tsdm_client/constants/layout.dart';

lib/utils/html/web_colors.dart

Lines changed: 0 additions & 318 deletions
This file was deleted.

packages/dart_bbcode_web_colors

Submodule dart_bbcode_web_colors added at a678d7a

0 commit comments

Comments
 (0)