Skip to content

Commit

Permalink
fix(html): Fix parsing web colors
Browse files Browse the repository at this point in the history
* Fix parsing named colors.
* Fix parsing hex color values.
  • Loading branch information
realth000 committed Sep 14, 2024
1 parent 7f08319 commit 02bfa65
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 122 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- 消息:修复解析7天内的公共消息时失败的问题。
- 主页:修复部分网络不稳定的情况下将加载失败显示为未登录的问题。
- 网页:修复解析网页时,在折叠/展开按钮上的文字丢失颜色的问题。
- 网页:修复解析网页中的颜色时,部分颜色解析失败或错误的问题。

### Changed

Expand Down
6 changes: 3 additions & 3 deletions lib/utils/html/css_parser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ extension StringToColorExt on String? {
// Parse as color value.
if (this != null && _colorRe.hasMatch(this!)) {
if (this!.startsWith('#')) {
colorValue =
int.tryParse(this!.substring(1).padLeft(8, 'ff'), radix: 16);
colorValue = int.tryParse(this!.substring(1), radix: 16);
} else {
colorValue = int.tryParse(this!.padLeft(8, 'ff'), radix: 16);
colorValue = int.tryParse(this!, radix: 16);
}
}
if (colorValue != null) {
colorValue += 0xFF000000;
return Color(colorValue);
} else {
// If color not in format #aabcc, try parse as color name.
Expand Down
208 changes: 98 additions & 110 deletions lib/utils/html/web_colors.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import 'dart:ui';

import 'package:change_case/change_case.dart';

// ignore_for_file: public_member_api_docs

enum WebColors {
Expand Down Expand Up @@ -158,144 +156,144 @@ enum WebColors {
const WebColors(this.color);

factory WebColors.fromString(String? c) {
return switch (c?.toCamelCase()) {
'aliceBlue' => WebColors.aliceBlue,
'antiqueWhite' => WebColors.antiqueWhite,
return switch (c?.toLowerCase()) {
'aliceblue' => WebColors.aliceBlue,
'antiquewhite' => WebColors.antiqueWhite,
'aqua' => WebColors.aqua,
'aquamarine' => WebColors.aquamarine,
'azure' => WebColors.azure,
'beige' => WebColors.beige,
'bisque' => WebColors.bisque,
'black' => WebColors.black,
'blanchedAlmond' => WebColors.blanchedAlmond,
'blanchedalmond' => WebColors.blanchedAlmond,
'blue' => WebColors.blue,
'blueViolet' => WebColors.blueViolet,
'blueviolet' => WebColors.blueViolet,
'brown' => WebColors.brown,
'burlyWood' => WebColors.burlyWood,
'cadetBlue' => WebColors.cadetBlue,
'burlywood' => WebColors.burlyWood,
'cadetblue' => WebColors.cadetBlue,
'chartreuse' => WebColors.chartreuse,
'chocolate' => WebColors.chocolate,
'coral' => WebColors.coral,
'cornflowerBlue' => WebColors.cornflowerBlue,
'cornflowerblue' => WebColors.cornflowerBlue,
'cornsilk' => WebColors.cornsilk,
'crimson' => WebColors.crimson,
'cyan' => WebColors.cyan,
'darkBlue' => WebColors.darkBlue,
'darkCyan' => WebColors.darkCyan,
'darkGoldenRod' => WebColors.darkGoldenRod,
'darkGray' => WebColors.darkGray,
'darkGrey' => WebColors.darkGrey,
'darkGreen' => WebColors.darkGreen,
'darkKhaki' => WebColors.darkKhaki,
'darkMagenta' => WebColors.darkMagenta,
'darkOliveGreen' => WebColors.darkOliveGreen,
'darkOrange' => WebColors.darkOrange,
'darkOrchid' => WebColors.darkOrchid,
'darkRed' => WebColors.darkRed,
'darkSalmon' => WebColors.darkSalmon,
'darkSeaGreen' => WebColors.darkSeaGreen,
'darkSlateBlue' => WebColors.darkSlateBlue,
'darkSlateGray' => WebColors.darkSlateGray,
'darkSlateGrey' => WebColors.darkSlateGrey,
'darkTurquoise' => WebColors.darkTurquoise,
'darkViolet' => WebColors.darkViolet,
'deepPink' => WebColors.deepPink,
'deepSkyBlue' => WebColors.deepSkyBlue,
'dimGray' => WebColors.dimGray,
'dimGrey' => WebColors.dimGrey,
'dodgerBlue' => WebColors.dodgerBlue,
'fireBrick' => WebColors.fireBrick,
'floralWhite' => WebColors.floralWhite,
'forestGreen' => WebColors.forestGreen,
'darkblue' => WebColors.darkBlue,
'darkcyan' => WebColors.darkCyan,
'darkgoldenrod' => WebColors.darkGoldenRod,
'darkgray' => WebColors.darkGray,
'darkgrey' => WebColors.darkGrey,
'darkgreen' => WebColors.darkGreen,
'darkkhaki' => WebColors.darkKhaki,
'darkmagenta' => WebColors.darkMagenta,
'darkolivegreen' => WebColors.darkOliveGreen,
'darkorange' => WebColors.darkOrange,
'darkorchid' => WebColors.darkOrchid,
'darkred' => WebColors.darkRed,
'darksalmon' => WebColors.darkSalmon,
'darkseagreen' => WebColors.darkSeaGreen,
'darkslateblue' => WebColors.darkSlateBlue,
'darkslategray' => WebColors.darkSlateGray,
'darkslategrey' => WebColors.darkSlateGrey,
'darkturquoise' => WebColors.darkTurquoise,
'darkviolet' => WebColors.darkViolet,
'deeppink' => WebColors.deepPink,
'deepskyblue' => WebColors.deepSkyBlue,
'dimgray' => WebColors.dimGray,
'dimgrey' => WebColors.dimGrey,
'dodgerblue' => WebColors.dodgerBlue,
'firebrick' => WebColors.fireBrick,
'floralwhite' => WebColors.floralWhite,
'forestgreen' => WebColors.forestGreen,
'fuchsia' => WebColors.fuchsia,
'gainsboro' => WebColors.gainsboro,
'ghostWhite' => WebColors.ghostWhite,
'ghostwhite' => WebColors.ghostWhite,
'gold' => WebColors.gold,
'goldenRod' => WebColors.goldenRod,
'goldenrod' => WebColors.goldenRod,
'gray' => WebColors.gray,
'grey' => WebColors.grey,
'green' => WebColors.green,
'greenYellow' => WebColors.greenYellow,
'honeyDew' => WebColors.honeyDew,
'hotPink' => WebColors.hotPink,
'indianRed' => WebColors.indianRed,
'greenyellow' => WebColors.greenYellow,
'honeydew' => WebColors.honeyDew,
'hotpink' => WebColors.hotPink,
'indianred' => WebColors.indianRed,
'indigo' => WebColors.indigo,
'ivory' => WebColors.ivory,
'khaki' => WebColors.khaki,
'lavender' => WebColors.lavender,
'lavenderBlush' => WebColors.lavenderBlush,
'lawnGreen' => WebColors.lawnGreen,
'lemonChiffon' => WebColors.lemonChiffon,
'lightBlue' => WebColors.lightBlue,
'lightCoral' => WebColors.lightCoral,
'lightCyan' => WebColors.lightCyan,
'lightGoldenRodYellow' => WebColors.lightGoldenRodYellow,
'lightGray' => WebColors.lightGray,
'lightGrey' => WebColors.lightGrey,
'lightGreen' => WebColors.lightGreen,
'lightPink' => WebColors.lightPink,
'lightSalmon' => WebColors.lightSalmon,
'lightSeaGreen' => WebColors.lightSeaGreen,
'lightSkyBlue' => WebColors.lightSkyBlue,
'lightSlateGray' => WebColors.lightSlateGray,
'lightSlateGrey' => WebColors.lightSlateGrey,
'lightSteelBlue' => WebColors.lightSteelBlue,
'lightYellow' => WebColors.lightYellow,
'lavenderblush' => WebColors.lavenderBlush,
'lawngreen' => WebColors.lawnGreen,
'lemonchiffon' => WebColors.lemonChiffon,
'lightblue' => WebColors.lightBlue,
'lightcoral' => WebColors.lightCoral,
'lightcyan' => WebColors.lightCyan,
'lightgoldenrodyellow' => WebColors.lightGoldenRodYellow,
'lightgray' => WebColors.lightGray,
'lightgrey' => WebColors.lightGrey,
'lightgreen' => WebColors.lightGreen,
'lightpink' => WebColors.lightPink,
'lightsalmon' => WebColors.lightSalmon,
'lightseagreen' => WebColors.lightSeaGreen,
'lightskyblue' => WebColors.lightSkyBlue,
'lightslategray' => WebColors.lightSlateGray,
'lightslategrey' => WebColors.lightSlateGrey,
'lightsteelblue' => WebColors.lightSteelBlue,
'lightyellow' => WebColors.lightYellow,
'lime' => WebColors.lime,
'limeGreen' => WebColors.limeGreen,
'limegreen' => WebColors.limeGreen,
'linen' => WebColors.linen,
'magenta' => WebColors.magenta,
'maroon' => WebColors.maroon,
'mediumAquaMarine' => WebColors.mediumAquaMarine,
'mediumBlue' => WebColors.mediumBlue,
'mediumOrchid' => WebColors.mediumOrchid,
'mediumPurple' => WebColors.mediumPurple,
'mediumSeaGreen' => WebColors.mediumSeaGreen,
'mediumSlateBlue' => WebColors.mediumSlateBlue,
'mediumSpringGreen' => WebColors.mediumSpringGreen,
'mediumTurquoise' => WebColors.mediumTurquoise,
'mediumVioletRed' => WebColors.mediumVioletRed,
'midnightBlue' => WebColors.midnightBlue,
'mintCream' => WebColors.mintCream,
'mistyRose' => WebColors.mistyRose,
'mediumaquamarine' => WebColors.mediumAquaMarine,
'mediumblue' => WebColors.mediumBlue,
'mediumorchid' => WebColors.mediumOrchid,
'mediumpurple' => WebColors.mediumPurple,
'mediumseagreen' => WebColors.mediumSeaGreen,
'mediumslateblue' => WebColors.mediumSlateBlue,
'mediumspringgreen' => WebColors.mediumSpringGreen,
'mediumturquoise' => WebColors.mediumTurquoise,
'mediumvioletred' => WebColors.mediumVioletRed,
'midnightblue' => WebColors.midnightBlue,
'mintcream' => WebColors.mintCream,
'mistyrose' => WebColors.mistyRose,
'moccasin' => WebColors.moccasin,
'navajoWhite' => WebColors.navajoWhite,
'navajowhite' => WebColors.navajoWhite,
'navy' => WebColors.navy,
'oldLace' => WebColors.oldLace,
'oldlace' => WebColors.oldLace,
'olive' => WebColors.olive,
'oliveDrab' => WebColors.oliveDrab,
'olivedrab' => WebColors.oliveDrab,
'orange' => WebColors.orange,
'orangeRed' => WebColors.orangeRed,
'orangered' => WebColors.orangeRed,
'orchid' => WebColors.orchid,
'paleGoldenRod' => WebColors.paleGoldenRod,
'paleGreen' => WebColors.paleGreen,
'paleTurquoise' => WebColors.paleTurquoise,
'paleVioletRed' => WebColors.paleVioletRed,
'papayaWhip' => WebColors.papayaWhip,
'peachPuff' => WebColors.peachPuff,
'palegoldenrod' => WebColors.paleGoldenRod,
'palegreen' => WebColors.paleGreen,
'paleturquoise' => WebColors.paleTurquoise,
'palevioletred' => WebColors.paleVioletRed,
'papayawhip' => WebColors.papayaWhip,
'peachpuff' => WebColors.peachPuff,
'peru' => WebColors.peru,
'pink' => WebColors.pink,
'plum' => WebColors.plum,
'powderBlue' => WebColors.powderBlue,
'powderblue' => WebColors.powderBlue,
'purple' => WebColors.purple,
'rebeccaPurple' => WebColors.rebeccaPurple,
'rebeccapurple' => WebColors.rebeccaPurple,
'red' => WebColors.red,
'rosyBrown' => WebColors.rosyBrown,
'royalBlue' => WebColors.royalBlue,
'saddleBrown' => WebColors.saddleBrown,
'rosybrown' => WebColors.rosyBrown,
'royalblue' => WebColors.royalBlue,
'saddlebrown' => WebColors.saddleBrown,
'salmon' => WebColors.salmon,
'sandyBrown' => WebColors.sandyBrown,
'seaGreen' => WebColors.seaGreen,
'seaShell' => WebColors.seaShell,
'sandybrown' => WebColors.sandyBrown,
'seagreen' => WebColors.seaGreen,
'seashell' => WebColors.seaShell,
'sienna' => WebColors.sienna,
'silver' => WebColors.silver,
'skyBlue' => WebColors.skyBlue,
'slateBlue' => WebColors.slateBlue,
'slateGray' => WebColors.slateGray,
'slateGrey' => WebColors.slateGrey,
'skyblue' => WebColors.skyBlue,
'slateblue' => WebColors.slateBlue,
'slategray' => WebColors.slateGray,
'slategrey' => WebColors.slateGrey,
'snow' => WebColors.snow,
'springGreen' => WebColors.springGreen,
'steelBlue' => WebColors.steelBlue,
'springgreen' => WebColors.springGreen,
'steelblue' => WebColors.steelBlue,
'tan' => WebColors.tan,
'teal' => WebColors.teal,
'thistle' => WebColors.thistle,
Expand All @@ -304,9 +302,9 @@ enum WebColors {
'violet' => WebColors.violet,
'wheat' => WebColors.wheat,
'white' => WebColors.white,
'whiteSmoke' => WebColors.whiteSmoke,
'whitesmoke' => WebColors.whiteSmoke,
'yellow' => WebColors.yellow,
'yellowGreen' => WebColors.yellowGreen,
'yellowgreen' => WebColors.yellowGreen,
String() || null => WebColors.invalid,
};
}
Expand All @@ -317,13 +315,3 @@ enum WebColors {

final Color color;
}

enum OperatingSystem<T> {
macOS('Yes I can'),
windows<int>(0),
linux(false);

const OperatingSystem(this.canBuildForIos);

final T canBuildForIos;
}
8 changes: 0 additions & 8 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "8.9.2"
change_case:
dependency: "direct main"
description:
name: change_case
sha256: "99cfdf2018c627c8a3af5a23ea4c414eb69c75c31322d23b9660ebc3cf30b514"
url: "https://pub.dev"
source: hosted
version: "2.1.0"
characters:
dependency: transitive
description:
Expand Down
1 change: 0 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ dependencies:
ansicolor: any
bbob_dart: ^0.2.1
bloc: ^8.1.4
change_case: ^2.1.0
# Blocked by flutter
collection: any
cookie_jar: ^4.0.8
Expand Down

0 comments on commit 02bfa65

Please sign in to comment.