import 'package:flutter/widgets.dart'; import 'package:hgdj/tools_base/debug_log.dart'; class HtmlProParser { static Color? spanBg(String? value) { if (value == null || value.isEmpty) return null; try { final splitArr = value.toLowerCase().split(":"); if (splitArr.length != 2 || !splitArr.last.contains("rgb")) return null; final rgbStr = splitArr.last.replaceAll("rgb(", "").replaceAll(");", ""); final rgbArr = rgbStr.split(","); if (rgbArr.length != 3) return null; final r = int.tryParse(rgbArr[0]); final g = int.tryParse(rgbArr[1]); final b = int.tryParse(rgbArr[2]); if (r == null || g == null || b == null) return null; return Color.fromRGBO(r, g, b, 1); } catch (e) { debugLog(e); } return null; } static AlignmentGeometry alignment(String? value) { if (value == "text-align:center;") { return Alignment.topCenter; } else if (value == "text-align:right;") { return Alignment.topRight; } else { return Alignment.topLeft; } } static WrapAlignment wrapAlignment(String? value) { if (value == "text-align:right;") { return WrapAlignment.end; } else if (value == "text-align:center;") { return WrapAlignment.center; } else { return WrapAlignment.start; } } static double? lineHeight(String? value) { try { if (value?.contains("line-height:") == true) { final sizeStr = value!.replaceAll("line-height:", "").replaceAll(";", ""); return double.tryParse(sizeStr); } } catch (e) { debugLog(e); } return null; } } class HexColor extends Color { static int _getColorFromHex(String hexColor) { try { hexColor = hexColor.toUpperCase().replaceAll("#", ""); if (hexColor.length == 6) { hexColor = "FF$hexColor"; } return int.parse(hexColor, radix: 16); } catch (e) { return 0xffffffff; } } HexColor(final String hexColor) : super(_getColorFromHex(hexColor)); }