From 8c302ef477b56747252b2c876ca6c7ad9d8b841b Mon Sep 17 00:00:00 2001 From: Leonardo da Silva Date: Sat, 2 Jan 2021 11:58:11 -0300 Subject: [PATCH 01/26] upgrade to null safety --- lib/color_from_string.dart | 226 +++++++++++++++++++++++++++++++++++++ lib/conversion.dart | 6 +- lib/hsl_color.dart | 2 +- lib/tinycolor.dart | 17 ++- pubspec.lock | 45 ++++---- pubspec.yaml | 4 +- 6 files changed, 256 insertions(+), 44 deletions(-) create mode 100644 lib/color_from_string.dart diff --git a/lib/color_from_string.dart b/lib/color_from_string.dart new file mode 100644 index 0000000..7510abd --- /dev/null +++ b/lib/color_from_string.dart @@ -0,0 +1,226 @@ +// inlined from package Pigment, since it is not being supported anymore +import 'dart:ui'; + +const _cssColors = { + 'lightsalmon': '#FFA07A', + 'salmon': '#FA8072', + 'darksalmon': '#E9967A', + 'lightcoral': '#F08080', + 'indianred': '#CD5C5C', + 'crimson': '#DC143C', + 'firebrick': '#B22222', + 'red': '#FF0000', + 'darkred': '#8B0000', + 'coral': '#FF7F50', + 'tomato': '#FF6347', + 'orangered': '#FF4500', + 'gold': '#FFD700', + 'orange': '#FFA500', + 'darkorange': '#FF8C00', + 'lightyellow': '#FFFFE0', + 'lemonchiffon': '#FFFACD', + 'lightgoldenrodyellow': '#FAFAD2', + 'papayawhip': '#FFEFD5', + 'moccasin': '#FFE4B5', + 'peachpuff': '#FFDAB9', + 'palegoldenrod': '#EEE8AA', + 'khaki': '#F0E68C', + 'darkkhaki': '#BDB76B', + 'yellow': '#FFFF00', + 'awngreen': '#7CFC00', + 'chartreuse': '#7FFF00', + 'limegreen': '#32CD32', + 'lime': '#00FF00', + 'forestgreen': '#228B22', + 'green': '#008000', + 'darkgreen': '#006400', + 'greenyellow': '#ADFF2F', + 'yellowgreen': '#9ACD32', + 'springgreen': '#00FF7F', + 'mediumspringgreen': '#00FA9A', + 'lightgreen': '#90EE90', + 'palegreen': '#98FB98', + 'darkseagreen': '#8FBC8F', + 'mediumseagreen': '#3CB371', + 'seagreen': '#2E8B57', + 'olive': '#808000', + 'darkolivegreen': '#556B2F', + 'olivedrab': '#6B8E23', + 'lightcyan': '#E0FFFF', + 'cyan': '#00FFFF', + 'aqua': '#00FFFF', + 'aquamarine': '#7FFFD4', + 'mediumaquamarine': '#66CDAA', + 'paleturquoise': '#AFEEEE', + 'turquoise': '#40E0D0', + 'mediumturquoise': '#48D1CC', + 'darkturquoise': '#00CED1', + 'lightseagreen': '#20B2AA', + 'cadetblue': '#5F9EA0', + 'darkcyan': '#008B8B', + 'teal': '#008080', + 'powderblue': '#B0E0E6', + 'lightblue': '#ADD8E6', + 'lightskyblue': '#87CEFA', + 'skyblue': '#87CEEB', + 'deepskyblue': '#00BFFF', + 'lightsteelblue': '#B0C4DE', + 'dodgerblue': '#1E90FF', + 'cornflowerblue': '#6495ED', + 'steelblue': '#4682B4', + 'royalblue': '#4169E1', + 'blue': '#0000FF', + 'mediumblue': '#0000CD', + 'darkblue': '#00008B', + 'navy': '#000080', + 'midnightblue': '#191970', + 'mediumslateblue': '#7B68EE', + 'slateblue': '#6A5ACD', + 'darkslateblue': '#483D8B', + 'lavender': '#E6E6FA', + 'thistle': '#D8BFD8', + 'plum': '#DDA0DD', + 'violet': '#EE82EE', + 'orchid': '#DA70D6', + 'fuchsia': '#FF00FF', + 'magenta': '#FF00FF', + 'mediumorchid': '#BA55D3', + 'mediumpurple': '#9370DB', + 'blueviolet': '#8A2BE2', + 'darkviolet': '#9400D3', + 'darkorchid': '#9932CC', + 'darkmagenta': '#8B008B', + 'purple': '#800080', + 'indigo': '#4B0082', + 'pink': '#FFC0CB', + 'lightpink': '#FFB6C1', + 'hotpink': '#FF69B4', + 'deeppink': '#FF1493', + 'palevioletred': '#DB7093', + 'mediumvioletred': '#C71585', + 'white': '#FFFFFF', + 'snow': '#FFFAFA', + 'honeydew': '#F0FFF0', + 'mintcream': '#F5FFFA', + 'azure': '#F0FFFF', + 'aliceblue': '#F0F8FF', + 'ghostwhite': '#F8F8FF', + 'whitesmoke': '#F5F5F5', + 'seashell': '#FFF5EE', + 'beige': '#F5F5DC', + 'oldlace': '#FDF5E6', + 'floralwhite': '#FFFAF0', + 'ivory': '#FFFFF0', + 'antiquewhite': '#FAEBD7', + 'linen': '#FAF0E6', + 'lavenderblush': '#FFF0F5', + 'mistyrose': '#FFE4E1', + 'gainsboro': '#DCDCDC', + 'lightgray': '#D3D3D3', + 'silver': '#C0C0C0', + 'darkgray': '#A9A9A9', + 'gray': '#808080', + 'dimgray': '#696969', + 'lightslategray': '#778899', + 'slategray': '#708090', + 'darkslategray': '#2F4F4F', + 'black': '#000000', + 'cornsilk': '#FFF8DC', + 'blanchedalmond': '#FFEBCD', + 'bisque': '#FFE4C4', + 'navajowhite': '#FFDEAD', + 'wheat': '#F5DEB3', + 'burlywood': '#DEB887', + 'tan': '#D2B48C', + 'rosybrown': '#BC8F8F', + 'sandybrown': '#F4A460', + 'goldenrod': '#DAA520', + 'peru': '#CD853F', + 'chocolate': '#D2691E', + 'saddlebrown': '#8B4513', + 'sienna': '#A0522D', + 'brown': '#A52A2A', + 'maroon': '#800000', +}; + +Color colorFromString(String color) { + color = color.trim(); + + final rgbColor = _getRGBColorFromString(color); + if (rgbColor != null) { + return rgbColor; + } + + Color? finalColor; + if (_hasCorrectHexPattern(color)) { + color = color.replaceAll("#", ""); + int size = color.length; + if (size == 6 || size == 3) { + if (size == 3) { + color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2]; + } + + int value = int.parse(color, radix: 16); + value = value + 0xFF000000; + finalColor = new Color(value); + } else if (size == 8 || size == 4) { + if (size == 4) { + color = color[0] + + color[0] + + color[1] + + color[1] + + color[2] + + color[2] + + color[3] + + color[3]; + } + String alpha = color.substring(6); + color = alpha + color.substring(0, 6); + int value = int.parse(color, radix: 16); + finalColor = new Color(value); + } + } + + if (finalColor != null) { + return finalColor; + } + + var namedColor = _cssColors[color]; + if (namedColor != null && namedColor != "") { + namedColor = namedColor.replaceAll("#", ""); + int value = int.parse(namedColor, radix: 16); + value = value + 0xFF000000; + return new Color(value); + } + + throw 'color pattern [$color] not found! D:'; +} + +Color? _getRGBColorFromString(String string) { + string = string.replaceAll(" ", ""); // pseudo-trimming + if (string.startsWith("rgb(") && string.endsWith(")")) { + // Correct + string = string.replaceAll("rgb(", ""); + string = string.replaceAll(")", ""); + List rgb = string.split(","); + if (rgb.length == 3) { + int r = int.parse(rgb[0]); + int g = int.parse(rgb[1]); + int b = int.parse(rgb[2]); + return new Color.fromARGB(255, r, g, b); + } + return null; + } + return null; +} + +bool _hasCorrectHexPattern(String string) { + string = string.replaceAll("#", ""); + String validChars = "0123456789AaBbCcDdEeFf"; + for (int i = 0; i < string.length; i++) { + if (!validChars.contains(string[i])) { + return false; + } + } + return true; +} diff --git a/lib/conversion.dart b/lib/conversion.dart index 12f8a81..760ab0d 100644 --- a/lib/conversion.dart +++ b/lib/conversion.dart @@ -2,13 +2,11 @@ import 'dart:math' as Math; import 'dart:ui'; import 'package:flutter/painting.dart'; -import 'package:meta/meta.dart'; import 'hsl_color.dart'; import 'util.dart'; -HslColor rgbToHsl( - {@required double r, @required double g, @required double b}) { +HslColor rgbToHsl({required double r, required double g, required double b}) { r = bound01(r, 255.0); g = bound01(g, 255.0); b = bound01(b, 255.0); @@ -67,7 +65,7 @@ HSVColor colorToHsv(Color color) { } HSVColor rgbToHsv( - {@required int r, @required int g, @required int b, @required int a}) { + {required int r, required int g, required int b, required int a}) { return colorToHsv(Color.fromARGB(a, r, g, b)); } diff --git a/lib/hsl_color.dart b/lib/hsl_color.dart index 2a83f5d..0abf1d5 100644 --- a/lib/hsl_color.dart +++ b/lib/hsl_color.dart @@ -4,7 +4,7 @@ class HslColor { double l; double a; - HslColor({this.h, this.s, this.l, this.a = 0.0}); + HslColor({required this.h, required this.s, required this.l, this.a = 0.0}); String toString() { return "HSL(h: $h, s: $s, l: $l, a: $a)"; diff --git a/lib/tinycolor.dart b/lib/tinycolor.dart index 06e429d..1fcef24 100644 --- a/lib/tinycolor.dart +++ b/lib/tinycolor.dart @@ -2,9 +2,8 @@ import 'dart:math' as Math; import 'dart:ui'; import 'package:flutter/painting.dart'; -import 'package:meta/meta.dart'; -import 'package:pigment/pigment.dart'; +import 'color_from_string.dart'; import 'conversion.dart'; import 'hsl_color.dart'; import 'util.dart'; @@ -13,18 +12,16 @@ export 'hsl_color.dart'; export 'color_extension.dart'; class TinyColor { - Color originalColor; - Color _color; + final Color originalColor; + late Color _color; - TinyColor(Color color) { - this.originalColor = - Color.fromARGB(color.alpha, color.red, color.green, color.blue); + TinyColor(Color color) : this.originalColor = color { this._color = Color.fromARGB(color.alpha, color.red, color.green, color.blue); } factory TinyColor.fromRGB( - {@required int r, @required int g, @required int b, int a = 100}) { + {required int r, required int g, required int b, int a = 100}) { return TinyColor(Color.fromARGB(a, r, g, b)); } @@ -37,7 +34,7 @@ class TinyColor { } factory TinyColor.fromString(String string) { - return TinyColor(Pigment.fromString(string)); + return TinyColor(colorFromString(string)); } bool isDark() { @@ -142,7 +139,7 @@ class TinyColor { return TinyColor.fromHSL(hsl); } - TinyColor mix({@required Color input, int amount = 50}) { + TinyColor mix({required Color input, int amount = 50}) { final int p = (amount / 100).round(); final color = Color.fromARGB( (input.alpha - _color.alpha) * p + _color.alpha, diff --git a/pubspec.lock b/pubspec.lock index 544bf47..1d1928d 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.4.2" + version: "2.5.0-nullsafety.3" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.3" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.0.0" + version: "1.1.0-nullsafety.5" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.1.3" + version: "1.2.0-nullsafety.3" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.0.1" + version: "1.1.0-nullsafety.3" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.14.13" + version: "1.15.0-nullsafety.5" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety.3" flutter: dependency: "direct main" description: flutter @@ -66,28 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.8" + version: "0.12.10-nullsafety.3" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.1.8" + version: "1.3.0-nullsafety.6" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" - pigment: - dependency: "direct main" - description: - name: pigment - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.3" + version: "1.8.0-nullsafety.3" sky_engine: dependency: transitive description: flutter @@ -99,56 +92,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.7.0" + version: "1.8.0-nullsafety.4" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.9.5" + version: "1.10.0-nullsafety.6" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.0.0" + version: "2.1.0-nullsafety.3" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.0.5" + version: "1.1.0-nullsafety.3" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.2.0-nullsafety.3" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.17" + version: "0.2.19-nullsafety.6" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.2.0" + version: "1.3.0-nullsafety.5" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.0.8" + version: "2.1.0-nullsafety.5" sdks: - dart: ">=2.9.0-14.0.dev <3.0.0" + dart: ">=2.12.0-0.0 <3.0.0" flutter: ">=1.12.0 <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index 1bb06c5..1c140d7 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,12 +4,10 @@ version: 1.0.3 homepage: https://github.com/FooStudio/tinycolor environment: - sdk: ">=2.6.0 <3.0.0" + sdk: ">=2.12.0-0 <3.0.0" flutter: ">=1.12.0 <3.0.0" dependencies: - pigment: ^1.0.3 - meta: ^1.2.2 flutter: sdk: flutter From 467de0737179574b59aa6c38b34ed4e786aca5b8 Mon Sep 17 00:00:00 2001 From: Leonardo da Silva Date: Tue, 4 May 2021 08:17:21 -0300 Subject: [PATCH 02/26] updated dependencies --- pubspec.lock | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/pubspec.lock b/pubspec.lock index 1d1928d..52ed0ad 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -7,49 +7,49 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.5.0-nullsafety.3" + version: "2.5.0" boolean_selector: dependency: transitive description: name: boolean_selector url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" characters: dependency: transitive description: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.5" + version: "1.1.0" charcode: dependency: transitive description: name: charcode url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" clock: dependency: transitive description: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" collection: dependency: transitive description: name: collection url: "https://pub.dartlang.org" source: hosted - version: "1.15.0-nullsafety.5" + version: "1.15.0" fake_async: dependency: transitive description: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" flutter: dependency: "direct main" description: flutter @@ -66,21 +66,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.10-nullsafety.3" + version: "0.12.10" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.6" + version: "1.3.0" path: dependency: transitive description: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.3" + version: "1.8.0" sky_engine: dependency: transitive description: flutter @@ -92,56 +92,56 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.8.0-nullsafety.4" + version: "1.8.0" stack_trace: dependency: transitive description: name: stack_trace url: "https://pub.dartlang.org" source: hosted - version: "1.10.0-nullsafety.6" + version: "1.10.0" stream_channel: dependency: transitive description: name: stream_channel url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.3" + version: "2.1.0" string_scanner: dependency: transitive description: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-nullsafety.3" + version: "1.1.0" term_glyph: dependency: transitive description: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-nullsafety.3" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.2.19-nullsafety.6" + version: "0.2.19" typed_data: dependency: transitive description: name: typed_data url: "https://pub.dartlang.org" source: hosted - version: "1.3.0-nullsafety.5" + version: "1.3.0" vector_math: dependency: transitive description: name: vector_math url: "https://pub.dartlang.org" source: hosted - version: "2.1.0-nullsafety.5" + version: "2.1.0" sdks: dart: ">=2.12.0-0.0 <3.0.0" - flutter: ">=1.12.0 <3.0.0" + flutter: ">=1.12.0" From eb3efbdc4e514e5fba66709601c0a5037ddca046 Mon Sep 17 00:00:00 2001 From: Leonardo da Silva Date: Tue, 4 May 2021 08:17:46 -0300 Subject: [PATCH 03/26] remove unnecessary late --- lib/tinycolor.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/tinycolor.dart b/lib/tinycolor.dart index 1fcef24..e784ce0 100644 --- a/lib/tinycolor.dart +++ b/lib/tinycolor.dart @@ -13,12 +13,11 @@ export 'color_extension.dart'; class TinyColor { final Color originalColor; - late Color _color; + Color _color; - TinyColor(Color color) : this.originalColor = color { - this._color = - Color.fromARGB(color.alpha, color.red, color.green, color.blue); - } + TinyColor(Color color) + : this.originalColor = color, + _color = color.copy(); factory TinyColor.fromRGB( {required int r, required int g, required int b, int a = 100}) { @@ -159,3 +158,9 @@ class TinyColor { return _color; } } + +extension on Color { + Color copy() { + return Color.fromARGB(alpha, red, green, blue); + } +} From 87f654ce7b79daddfbe7cdf7b7d9bb27574a8b89 Mon Sep 17 00:00:00 2001 From: Leonardo da Silva Date: Tue, 4 May 2021 08:20:16 -0300 Subject: [PATCH 04/26] using Pigment lib instead of reimplementing colorFromString --- lib/color_from_string.dart | 226 ------------------------------------- lib/tinycolor.dart | 4 +- pubspec.lock | 9 +- pubspec.yaml | 1 + 4 files changed, 11 insertions(+), 229 deletions(-) delete mode 100644 lib/color_from_string.dart diff --git a/lib/color_from_string.dart b/lib/color_from_string.dart deleted file mode 100644 index 7510abd..0000000 --- a/lib/color_from_string.dart +++ /dev/null @@ -1,226 +0,0 @@ -// inlined from package Pigment, since it is not being supported anymore -import 'dart:ui'; - -const _cssColors = { - 'lightsalmon': '#FFA07A', - 'salmon': '#FA8072', - 'darksalmon': '#E9967A', - 'lightcoral': '#F08080', - 'indianred': '#CD5C5C', - 'crimson': '#DC143C', - 'firebrick': '#B22222', - 'red': '#FF0000', - 'darkred': '#8B0000', - 'coral': '#FF7F50', - 'tomato': '#FF6347', - 'orangered': '#FF4500', - 'gold': '#FFD700', - 'orange': '#FFA500', - 'darkorange': '#FF8C00', - 'lightyellow': '#FFFFE0', - 'lemonchiffon': '#FFFACD', - 'lightgoldenrodyellow': '#FAFAD2', - 'papayawhip': '#FFEFD5', - 'moccasin': '#FFE4B5', - 'peachpuff': '#FFDAB9', - 'palegoldenrod': '#EEE8AA', - 'khaki': '#F0E68C', - 'darkkhaki': '#BDB76B', - 'yellow': '#FFFF00', - 'awngreen': '#7CFC00', - 'chartreuse': '#7FFF00', - 'limegreen': '#32CD32', - 'lime': '#00FF00', - 'forestgreen': '#228B22', - 'green': '#008000', - 'darkgreen': '#006400', - 'greenyellow': '#ADFF2F', - 'yellowgreen': '#9ACD32', - 'springgreen': '#00FF7F', - 'mediumspringgreen': '#00FA9A', - 'lightgreen': '#90EE90', - 'palegreen': '#98FB98', - 'darkseagreen': '#8FBC8F', - 'mediumseagreen': '#3CB371', - 'seagreen': '#2E8B57', - 'olive': '#808000', - 'darkolivegreen': '#556B2F', - 'olivedrab': '#6B8E23', - 'lightcyan': '#E0FFFF', - 'cyan': '#00FFFF', - 'aqua': '#00FFFF', - 'aquamarine': '#7FFFD4', - 'mediumaquamarine': '#66CDAA', - 'paleturquoise': '#AFEEEE', - 'turquoise': '#40E0D0', - 'mediumturquoise': '#48D1CC', - 'darkturquoise': '#00CED1', - 'lightseagreen': '#20B2AA', - 'cadetblue': '#5F9EA0', - 'darkcyan': '#008B8B', - 'teal': '#008080', - 'powderblue': '#B0E0E6', - 'lightblue': '#ADD8E6', - 'lightskyblue': '#87CEFA', - 'skyblue': '#87CEEB', - 'deepskyblue': '#00BFFF', - 'lightsteelblue': '#B0C4DE', - 'dodgerblue': '#1E90FF', - 'cornflowerblue': '#6495ED', - 'steelblue': '#4682B4', - 'royalblue': '#4169E1', - 'blue': '#0000FF', - 'mediumblue': '#0000CD', - 'darkblue': '#00008B', - 'navy': '#000080', - 'midnightblue': '#191970', - 'mediumslateblue': '#7B68EE', - 'slateblue': '#6A5ACD', - 'darkslateblue': '#483D8B', - 'lavender': '#E6E6FA', - 'thistle': '#D8BFD8', - 'plum': '#DDA0DD', - 'violet': '#EE82EE', - 'orchid': '#DA70D6', - 'fuchsia': '#FF00FF', - 'magenta': '#FF00FF', - 'mediumorchid': '#BA55D3', - 'mediumpurple': '#9370DB', - 'blueviolet': '#8A2BE2', - 'darkviolet': '#9400D3', - 'darkorchid': '#9932CC', - 'darkmagenta': '#8B008B', - 'purple': '#800080', - 'indigo': '#4B0082', - 'pink': '#FFC0CB', - 'lightpink': '#FFB6C1', - 'hotpink': '#FF69B4', - 'deeppink': '#FF1493', - 'palevioletred': '#DB7093', - 'mediumvioletred': '#C71585', - 'white': '#FFFFFF', - 'snow': '#FFFAFA', - 'honeydew': '#F0FFF0', - 'mintcream': '#F5FFFA', - 'azure': '#F0FFFF', - 'aliceblue': '#F0F8FF', - 'ghostwhite': '#F8F8FF', - 'whitesmoke': '#F5F5F5', - 'seashell': '#FFF5EE', - 'beige': '#F5F5DC', - 'oldlace': '#FDF5E6', - 'floralwhite': '#FFFAF0', - 'ivory': '#FFFFF0', - 'antiquewhite': '#FAEBD7', - 'linen': '#FAF0E6', - 'lavenderblush': '#FFF0F5', - 'mistyrose': '#FFE4E1', - 'gainsboro': '#DCDCDC', - 'lightgray': '#D3D3D3', - 'silver': '#C0C0C0', - 'darkgray': '#A9A9A9', - 'gray': '#808080', - 'dimgray': '#696969', - 'lightslategray': '#778899', - 'slategray': '#708090', - 'darkslategray': '#2F4F4F', - 'black': '#000000', - 'cornsilk': '#FFF8DC', - 'blanchedalmond': '#FFEBCD', - 'bisque': '#FFE4C4', - 'navajowhite': '#FFDEAD', - 'wheat': '#F5DEB3', - 'burlywood': '#DEB887', - 'tan': '#D2B48C', - 'rosybrown': '#BC8F8F', - 'sandybrown': '#F4A460', - 'goldenrod': '#DAA520', - 'peru': '#CD853F', - 'chocolate': '#D2691E', - 'saddlebrown': '#8B4513', - 'sienna': '#A0522D', - 'brown': '#A52A2A', - 'maroon': '#800000', -}; - -Color colorFromString(String color) { - color = color.trim(); - - final rgbColor = _getRGBColorFromString(color); - if (rgbColor != null) { - return rgbColor; - } - - Color? finalColor; - if (_hasCorrectHexPattern(color)) { - color = color.replaceAll("#", ""); - int size = color.length; - if (size == 6 || size == 3) { - if (size == 3) { - color = color[0] + color[0] + color[1] + color[1] + color[2] + color[2]; - } - - int value = int.parse(color, radix: 16); - value = value + 0xFF000000; - finalColor = new Color(value); - } else if (size == 8 || size == 4) { - if (size == 4) { - color = color[0] + - color[0] + - color[1] + - color[1] + - color[2] + - color[2] + - color[3] + - color[3]; - } - String alpha = color.substring(6); - color = alpha + color.substring(0, 6); - int value = int.parse(color, radix: 16); - finalColor = new Color(value); - } - } - - if (finalColor != null) { - return finalColor; - } - - var namedColor = _cssColors[color]; - if (namedColor != null && namedColor != "") { - namedColor = namedColor.replaceAll("#", ""); - int value = int.parse(namedColor, radix: 16); - value = value + 0xFF000000; - return new Color(value); - } - - throw 'color pattern [$color] not found! D:'; -} - -Color? _getRGBColorFromString(String string) { - string = string.replaceAll(" ", ""); // pseudo-trimming - if (string.startsWith("rgb(") && string.endsWith(")")) { - // Correct - string = string.replaceAll("rgb(", ""); - string = string.replaceAll(")", ""); - List rgb = string.split(","); - if (rgb.length == 3) { - int r = int.parse(rgb[0]); - int g = int.parse(rgb[1]); - int b = int.parse(rgb[2]); - return new Color.fromARGB(255, r, g, b); - } - return null; - } - return null; -} - -bool _hasCorrectHexPattern(String string) { - string = string.replaceAll("#", ""); - String validChars = "0123456789AaBbCcDdEeFf"; - for (int i = 0; i < string.length; i++) { - if (!validChars.contains(string[i])) { - return false; - } - } - return true; -} diff --git a/lib/tinycolor.dart b/lib/tinycolor.dart index e784ce0..eda3763 100644 --- a/lib/tinycolor.dart +++ b/lib/tinycolor.dart @@ -2,8 +2,8 @@ import 'dart:math' as Math; import 'dart:ui'; import 'package:flutter/painting.dart'; +import 'package:pigment/pigment.dart'; -import 'color_from_string.dart'; import 'conversion.dart'; import 'hsl_color.dart'; import 'util.dart'; @@ -33,7 +33,7 @@ class TinyColor { } factory TinyColor.fromString(String string) { - return TinyColor(colorFromString(string)); + return TinyColor(Pigment.fromString(string)); } bool isDark() { diff --git a/pubspec.lock b/pubspec.lock index 52ed0ad..7ffb8e0 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -81,6 +81,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.8.0" + pigment: + dependency: "direct main" + description: + name: pigment + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.4" sky_engine: dependency: transitive description: flutter @@ -143,5 +150,5 @@ packages: source: hosted version: "2.1.0" sdks: - dart: ">=2.12.0-0.0 <3.0.0" + dart: ">=2.12.0 <3.0.0" flutter: ">=1.12.0" diff --git a/pubspec.yaml b/pubspec.yaml index 1c140d7..510a382 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,6 +10,7 @@ environment: dependencies: flutter: sdk: flutter + pigment: ^1.0.4 dev_dependencies: flutter_test: From 56d7d945b3dd86c00fe36559028c280ec905fe70 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 24 Jun 2021 13:17:26 -0700 Subject: [PATCH 05/26] Update issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 33 ++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..3b38583 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,33 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: bug +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environment (please complete the following information)** + - Package version [e.g. 22] + - Dart version [e.g. 2.12.0] + - Flutter version [e.g. 2.2.0] + - Target platform for Flutter [e.g. Android, iOS, web, etc.] + +**Additional context** +Add any other context about the problem here (including error message, logs). From f61116c84a7255a4bc6ca7e8a2e5264d0e4c6e50 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 24 Jun 2021 13:27:06 -0700 Subject: [PATCH 06/26] Update pubspec for this fork --- pubspec.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pubspec.yaml b/pubspec.yaml index 1bb06c5..3493701 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ -name: tinycolor +name: tinycolor2 description: Flutter Color manipulation and conversion, ported from JS tinycolor2 -version: 1.0.3 -homepage: https://github.com/FooStudio/tinycolor +version: 2.0.0 +homepage: https://github.com/TinyCommunity/tinycolor2 environment: sdk: ">=2.6.0 <3.0.0" From f431be7252103f81c9a9191c7a05ebd68f49ca4f Mon Sep 17 00:00:00 2001 From: Tyler Norbury Date: Thu, 24 Jun 2021 14:19:42 -0700 Subject: [PATCH 07/26] Update underlying color with setting alpha and opacity. --- lib/tinycolor.dart | 4 ++-- test/tinycolor_test.dart | 27 +++++++++++++++++++++++++++ test/util_test.dart | 3 +-- 3 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 test/tinycolor_test.dart diff --git a/lib/tinycolor.dart b/lib/tinycolor.dart index 06e429d..c104482 100644 --- a/lib/tinycolor.dart +++ b/lib/tinycolor.dart @@ -57,12 +57,12 @@ class TinyColor { } TinyColor setAlpha(int alpha) { - _color.withAlpha(alpha); + _color = _color.withAlpha(alpha); return this; } TinyColor setOpacity(double opacity) { - _color.withOpacity(opacity); + _color = _color.withOpacity(opacity); return this; } diff --git a/test/tinycolor_test.dart b/test/tinycolor_test.dart new file mode 100644 index 0000000..3d7f1d8 --- /dev/null +++ b/test/tinycolor_test.dart @@ -0,0 +1,27 @@ +import 'dart:ui'; + +import 'package:flutter_test/flutter_test.dart'; +import 'package:tinycolor2/tinycolor.dart'; + +void main() { + test( + "setAlpha updates alpha value of color", + () { + TinyColor color = TinyColor(Color(0xFFFFFFFF)); + color.setAlpha(0x00); + expect(color.color.alpha, 0x00); + }, + ); + + test( + "setOpacity updates opacity value of color", + () { + TinyColor color = TinyColor(Color(0xFFFFFFFF).withOpacity(1.0)); + color.setOpacity(0.5); + + // underlying dart implementation converts the opacity value to an + // int, then back into a double. Thus some precision is loss. + expect(color.color.opacity, moreOrLessEquals(0.5, epsilon: 1e-2)); + }, + ); +} diff --git a/test/util_test.dart b/test/util_test.dart index eb7120a..a5c8a63 100644 --- a/test/util_test.dart +++ b/test/util_test.dart @@ -1,6 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; -//import 'package:test/test.dart'; -import 'package:tinycolor/util.dart'; +import 'package:tinycolor2/util.dart'; void main() { test("bound01 values", () { From 2f13899de0d65738176e2fca17a37a549815622e Mon Sep 17 00:00:00 2001 From: Tyler Norbury Date: Thu, 24 Jun 2021 14:52:22 -0700 Subject: [PATCH 08/26] restructure as a library --- lib/{ => src}/color_extension.dart | 0 lib/{ => src}/conversion.dart | 0 lib/{ => src}/hsl_color.dart | 0 lib/{ => src}/tinycolor.dart | 0 lib/{ => src}/util.dart | 0 lib/tinycolor2.dart | 7 +++++++ test/tinycolor_test.dart | 2 +- test/util_test.dart | 2 +- 8 files changed, 9 insertions(+), 2 deletions(-) rename lib/{ => src}/color_extension.dart (100%) rename lib/{ => src}/conversion.dart (100%) rename lib/{ => src}/hsl_color.dart (100%) rename lib/{ => src}/tinycolor.dart (100%) rename lib/{ => src}/util.dart (100%) create mode 100644 lib/tinycolor2.dart diff --git a/lib/color_extension.dart b/lib/src/color_extension.dart similarity index 100% rename from lib/color_extension.dart rename to lib/src/color_extension.dart diff --git a/lib/conversion.dart b/lib/src/conversion.dart similarity index 100% rename from lib/conversion.dart rename to lib/src/conversion.dart diff --git a/lib/hsl_color.dart b/lib/src/hsl_color.dart similarity index 100% rename from lib/hsl_color.dart rename to lib/src/hsl_color.dart diff --git a/lib/tinycolor.dart b/lib/src/tinycolor.dart similarity index 100% rename from lib/tinycolor.dart rename to lib/src/tinycolor.dart diff --git a/lib/util.dart b/lib/src/util.dart similarity index 100% rename from lib/util.dart rename to lib/src/util.dart diff --git a/lib/tinycolor2.dart b/lib/tinycolor2.dart new file mode 100644 index 0000000..9104354 --- /dev/null +++ b/lib/tinycolor2.dart @@ -0,0 +1,7 @@ +library tinycolor2; + +export 'src/color_extension.dart'; +export 'src/conversion.dart'; +export 'src/hsl_color.dart'; +export 'src/tinycolor.dart'; +export 'src/util.dart'; diff --git a/test/tinycolor_test.dart b/test/tinycolor_test.dart index 3d7f1d8..093cebe 100644 --- a/test/tinycolor_test.dart +++ b/test/tinycolor_test.dart @@ -1,7 +1,7 @@ import 'dart:ui'; import 'package:flutter_test/flutter_test.dart'; -import 'package:tinycolor2/tinycolor.dart'; +import 'package:tinycolor2/tinycolor2.dart'; void main() { test( diff --git a/test/util_test.dart b/test/util_test.dart index a5c8a63..e050c33 100644 --- a/test/util_test.dart +++ b/test/util_test.dart @@ -1,5 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:tinycolor2/util.dart'; +import 'package:tinycolor2/tinycolor2.dart'; void main() { test("bound01 values", () { From 1997311f47defea00f375d55f4c4cc0bb82861a9 Mon Sep 17 00:00:00 2001 From: Tyler Norbury Date: Thu, 24 Jun 2021 15:00:23 -0700 Subject: [PATCH 09/26] format code for pub points --- lib/src/color_extension.dart | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/src/color_extension.dart b/lib/src/color_extension.dart index af86a7b..64d2a1d 100644 --- a/lib/src/color_extension.dart +++ b/lib/src/color_extension.dart @@ -7,7 +7,7 @@ extension TinyColorExtension on Color { TinyColor toTinyColor() => TinyColor(this); HSVColor toHsv() => TinyColor(this).toHsv(); - + HslColor toHsl() => TinyColor(this).toHsl(); /// Lighten the color a given amount, from 0 to 100. Providing 100 will always return white. @@ -26,7 +26,8 @@ extension TinyColorExtension on Color { Color shade([int amount = 10]) => TinyColor(this).shade(amount).color; /// Desaturate the color a given amount, from 0 to 100. Providing 100 will is the same as calling greyscale. - Color desaturate([int amount = 10]) => TinyColor(this).desaturate(amount).color; + Color desaturate([int amount = 10]) => + TinyColor(this).desaturate(amount).color; /// Saturate the color a given amount, from 0 to 100. Color saturate([int amount = 10]) => TinyColor(this).saturate(amount).color; @@ -53,5 +54,6 @@ extension TinyColorExtension on Color { Color get compliment => TinyColor(this).complement().color; /// Blends the color with another color a given amount, from 0 - 100, default 50. - Color mix(Color toColor, [int amount = 50]) => TinyColor(this).mix(input: toColor, amount: amount).color; + Color mix(Color toColor, [int amount = 50]) => + TinyColor(this).mix(input: toColor, amount: amount).color; } From 797606a0acb79e001d6c029a3c481506e4c86dce Mon Sep 17 00:00:00 2001 From: dsyrstad Date: Thu, 24 Jun 2021 17:13:27 -0500 Subject: [PATCH 10/26] Fixes issues #2 and #10 in FooStudio/tinycolor --- lib/tinycolor.dart | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/tinycolor.dart b/lib/tinycolor.dart index 06e429d..28cac85 100644 --- a/lib/tinycolor.dart +++ b/lib/tinycolor.dart @@ -110,11 +110,11 @@ class TinyColor { } TinyColor tint([int amount = 10]) { - return this.mix(input: Color.fromRGBO(255, 255, 255, 1.0)); + return this.mix(input: Color.fromRGBO(255, 255, 255, 1.0), amount: amount); } TinyColor shade([int amount = 10]) { - return this.mix(input: Color.fromRGBO(0, 0, 0, 1.0)); + return this.mix(input: Color.fromRGBO(0, 0, 0, 1.0), amount: amount); } TinyColor desaturate([int amount = 10]) { @@ -143,12 +143,12 @@ class TinyColor { } TinyColor mix({@required Color input, int amount = 50}) { - final int p = (amount / 100).round(); + final p = amount / 100.0; final color = Color.fromARGB( - (input.alpha - _color.alpha) * p + _color.alpha, - (input.red - _color.red) * p + _color.red, - (input.green - _color.green) * p + _color.green, - (input.blue - _color.blue) * p + _color.blue); + ((input.alpha - _color.alpha) * p + _color.alpha).round(), + ((input.red - _color.red) * p + _color.red).round(), + ((input.green - _color.green) * p + _color.green).round(), + ((input.blue - _color.blue) * p + _color.blue).round()); return TinyColor(color); } From 68d18fda199bdd95b992e88faa5ea03679991f7a Mon Sep 17 00:00:00 2001 From: Tyler Norbury Date: Fri, 25 Jun 2021 13:11:19 -0700 Subject: [PATCH 11/26] spelling --- lib/src/color_extension.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/color_extension.dart b/lib/src/color_extension.dart index 64d2a1d..235d4b2 100644 --- a/lib/src/color_extension.dart +++ b/lib/src/color_extension.dart @@ -1,7 +1,7 @@ import 'package:flutter/painting.dart'; import 'tinycolor.dart'; -/// Extends the Color class to allow direct TinyColor manipulation nativly +/// Extends the Color class to allow direct TinyColor manipulation natively extension TinyColorExtension on Color { /// Converts standard Color to TinyColor object TinyColor toTinyColor() => TinyColor(this); From 1fc89ce09408c88ebfda15211587fe01af4e3c76 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Sat, 26 Jun 2021 01:30:08 -0700 Subject: [PATCH 12/26] Create SECURITY.md --- SECURITY.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..3e83b0b --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,14 @@ +# Security Policy + +## Supported Versions + +The following versions are currently being supported with security updates. + +| Version | Supported | +| ------- | ------------------ | +| 2.0.x | :white_check_mark: | +| < 2.0 | :x: | + +## Reporting a Vulnerability + +To report any security issues, please open an issue [here](https://github.com/TinyCommunity/tinycolor2/issues/new/choose). From 7ab3574549973c5e98b2519051243daa93bbfc3c Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Sat, 26 Jun 2021 01:33:31 -0700 Subject: [PATCH 13/26] Update issue templates --- .../ISSUE_TEMPLATE/vulnerability-report.md | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/vulnerability-report.md diff --git a/.github/ISSUE_TEMPLATE/vulnerability-report.md b/.github/ISSUE_TEMPLATE/vulnerability-report.md new file mode 100644 index 0000000..515f089 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/vulnerability-report.md @@ -0,0 +1,33 @@ +--- +name: Vulnerability report +about: Report any vulnerability you have found. +title: '' +labels: vulnerability +assignees: '' + +--- + +**Describe the vulnerability** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environment (please complete the following information)** + - Package version [e.g. 22] + - Dart version [e.g. 2.12.0] + - Flutter version [e.g. 2.2.0] + - Target platform for Flutter [e.g. Android, iOS, web, etc.] + +**Additional context** +Add any other context about the problem here (including error message, logs). From 3cf70782fbd8719d47b507b22f3fefcb179e4602 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Tue, 29 Jun 2021 13:56:05 -0700 Subject: [PATCH 14/26] Update changelog template --- CHANGELOG.md | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b854253..a7256f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,32 @@ -## [1.0.3] -* Added Color class extension method for direct usage -## [1.0.2] -* Fixed compatibility issues with dart 2.1 and pigment 1.0.3 -## [1.0.1] -* Fixed HSLColor class name duplicate definition. -* Updated package description -## [1.0.0] -* Initial port of tinycolor2 +# Changelog + +## [2.0.0] - TBD + +### Changed +* Forked as a community version `tinycolor2` + +### Fixed +* #2, #6, #10 from upstream at [PR #5](https://github.com/TinyCommunity/tinycolor2/pull/5) + +## [1.0.3] - 2020-08-27 + +### Added +* Color class extension method for direct usage + +## [1.0.2] - 2018-08-17 + +### Fixed +* Compatibility issues with dart 2.1 and pigment 1.0.3 + +## [1.0.1] - 2018-08-04 + +### Fixed +* HSLColor class name duplicate definition + +### Changed +* Package description + +## [1.0.0] - 2018-08-04 + +### Added +* Initial port of tinycolor2 From eebc84c35ffaa9ee849bb7d2565a268bce744447 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Sun, 4 Jul 2021 06:40:51 -0700 Subject: [PATCH 15/26] Replace .gitignore from flutter/packages --- .gitignore | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 9172bce..f3c2053 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,44 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp .DS_Store -.dart_tool/ -.idea +.atom/ +.buildlog/ +.history +.svn/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +**/doc/api/ +**/ios/Flutter/.last_build_id +.dart_tool/ +.flutter-plugins +.flutter-plugins-dependencies .packages +.pub-cache/ .pub/ +/build/ + +# Web related +lib/generated_plugin_registrant.dart + +# Symbolication related +app.*.symbols + +# Obfuscation related +app.*.map.json -build/ -ios/.generated/ -ios/Flutter/Generated.xcconfig -ios/Runner/GeneratedPluginRegistrant.* +# Exceptions to above rules. +!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages From a3314648016407bafe7476a9ef9b139f457d2161 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Sun, 4 Jul 2021 06:43:26 -0700 Subject: [PATCH 16/26] Reimport .gitignore from dart template --- .gitignore | 55 ++++++++++++++++-------------------------------------- 1 file changed, 16 insertions(+), 39 deletions(-) diff --git a/.gitignore b/.gitignore index f3c2053..dbef116 100644 --- a/.gitignore +++ b/.gitignore @@ -1,44 +1,21 @@ -# Miscellaneous -*.class -*.log -*.pyc -*.swp -.DS_Store -.atom/ -.buildlog/ -.history -.svn/ +# See https://www.dartlang.org/guides/libraries/private-files -# IntelliJ related -*.iml -*.ipr -*.iws -.idea/ - -# The .vscode folder contains launch configuration and tasks you configure in -# VS Code which you may wish to be included in version control, so this line -# is commented out by default. -#.vscode/ - -# Flutter/Dart/Pub related -**/doc/api/ -**/ios/Flutter/.last_build_id +# Files and directories created by pub .dart_tool/ -.flutter-plugins -.flutter-plugins-dependencies .packages -.pub-cache/ -.pub/ -/build/ - -# Web related -lib/generated_plugin_registrant.dart - -# Symbolication related -app.*.symbols +build/ +# If you're building an application, you may want to check-in your pubspec.lock +pubspec.lock -# Obfuscation related -app.*.map.json +# Directory created by dartdoc +# If you don't generate documentation locally you can remove this line. +doc/api/ -# Exceptions to above rules. -!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages +# Avoid committing generated Javascript files: +*.dart.js +*.info.json # Produced by the --dump-info flag. +*.js # When generated by dart2js. Don't specify *.js if your + # project includes source files written in JavaScript. +*.js_ +*.js.deps +*.js.map From d9737dc0f3342af927795776e66ecfc89ace3126 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Sun, 4 Jul 2021 06:43:53 -0700 Subject: [PATCH 17/26] Remove pubspec.lock --- pubspec.lock | 154 --------------------------------------------------- 1 file changed, 154 deletions(-) delete mode 100644 pubspec.lock diff --git a/pubspec.lock b/pubspec.lock deleted file mode 100644 index 544bf47..0000000 --- a/pubspec.lock +++ /dev/null @@ -1,154 +0,0 @@ -# Generated by pub -# See https://dart.dev/tools/pub/glossary#lockfile -packages: - async: - dependency: transitive - description: - name: async - url: "https://pub.dartlang.org" - source: hosted - version: "2.4.2" - boolean_selector: - dependency: transitive - description: - name: boolean_selector - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" - characters: - dependency: transitive - description: - name: characters - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.0" - charcode: - dependency: transitive - description: - name: charcode - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.3" - clock: - dependency: transitive - description: - name: clock - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.1" - collection: - dependency: transitive - description: - name: collection - url: "https://pub.dartlang.org" - source: hosted - version: "1.14.13" - fake_async: - dependency: transitive - description: - name: fake_async - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - flutter: - dependency: "direct main" - description: flutter - source: sdk - version: "0.0.0" - flutter_test: - dependency: "direct dev" - description: flutter - source: sdk - version: "0.0.0" - matcher: - dependency: transitive - description: - name: matcher - url: "https://pub.dartlang.org" - source: hosted - version: "0.12.8" - meta: - dependency: transitive - description: - name: meta - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.8" - path: - dependency: transitive - description: - name: path - url: "https://pub.dartlang.org" - source: hosted - version: "1.7.0" - pigment: - dependency: "direct main" - description: - name: pigment - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.3" - sky_engine: - dependency: transitive - description: flutter - source: sdk - version: "0.0.99" - source_span: - dependency: transitive - description: - name: source_span - url: "https://pub.dartlang.org" - source: hosted - version: "1.7.0" - stack_trace: - dependency: transitive - description: - name: stack_trace - url: "https://pub.dartlang.org" - source: hosted - version: "1.9.5" - stream_channel: - dependency: transitive - description: - name: stream_channel - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.0" - string_scanner: - dependency: transitive - description: - name: string_scanner - url: "https://pub.dartlang.org" - source: hosted - version: "1.0.5" - term_glyph: - dependency: transitive - description: - name: term_glyph - url: "https://pub.dartlang.org" - source: hosted - version: "1.1.0" - test_api: - dependency: transitive - description: - name: test_api - url: "https://pub.dartlang.org" - source: hosted - version: "0.2.17" - typed_data: - dependency: transitive - description: - name: typed_data - url: "https://pub.dartlang.org" - source: hosted - version: "1.2.0" - vector_math: - dependency: transitive - description: - name: vector_math - url: "https://pub.dartlang.org" - source: hosted - version: "2.0.8" -sdks: - dart: ">=2.9.0-14.0.dev <3.0.0" - flutter: ">=1.12.0 <3.0.0" From 4b92abec70885c487a280eb8243056b5c2871dc7 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Tue, 6 Jul 2021 23:28:55 -0700 Subject: [PATCH 18/26] Add .equals() (#16) * Add .equals() * Fix value to be checked * Add @Deprecated for .equals() --- lib/src/tinycolor.dart | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/src/tinycolor.dart b/lib/src/tinycolor.dart index 0b9ae3c..209f829 100644 --- a/lib/src/tinycolor.dart +++ b/lib/src/tinycolor.dart @@ -161,4 +161,17 @@ class TinyColor { Color get color { return _color; } + + @override + bool operator ==(Object other) => + identical(this, other) || + other is TinyColor && + runtimeType == other.runtimeType && + color == other.color; + + @override + int get hashCode => name.hashCode; + + @Deprecated('Use == instead.') + bool equals(Object other) => this == other; } From c7b9db754a2f59c48be5b40fc67cf427a2a12f66 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 8 Jul 2021 11:48:20 -0700 Subject: [PATCH 19/26] Fix #19 --- lib/src/tinycolor.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/tinycolor.dart b/lib/src/tinycolor.dart index 209f829..ad9012d 100644 --- a/lib/src/tinycolor.dart +++ b/lib/src/tinycolor.dart @@ -170,7 +170,7 @@ class TinyColor { color == other.color; @override - int get hashCode => name.hashCode; + int get hashCode => color.hashCode; @Deprecated('Use == instead.') bool equals(Object other) => this == other; From 983245c1eab01aabd6426b66fce63d3408f70409 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 8 Jul 2021 12:09:11 -0700 Subject: [PATCH 20/26] Update with template gitignore --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.gitignore b/.gitignore index dbef116..3a83c2f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,9 @@ pubspec.lock # If you don't generate documentation locally you can remove this line. doc/api/ +# dotenv environment variables file +.env* + # Avoid committing generated Javascript files: *.dart.js *.info.json # Produced by the --dump-info flag. @@ -19,3 +22,6 @@ doc/api/ *.js_ *.js.deps *.js.map + +.flutter-plugins +.flutter-plugins-dependencies From 4806874c992f2cf606a670c100734bd0d576758a Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 8 Jul 2021 12:10:39 -0700 Subject: [PATCH 21/26] Ignore OS related files --- .gitignore | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/.gitignore b/.gitignore index 3a83c2f..4092daa 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,69 @@ doc/api/ .flutter-plugins .flutter-plugins-dependencies + +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* From 825a1b4ae4da7a653476114ed0c6a471f5c02d0f Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 8 Jul 2021 12:14:27 -0700 Subject: [PATCH 22/26] Ignore IDE related files Xcode, JetBrains, VSCode --- .gitignore | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/.gitignore b/.gitignore index 4092daa..b76b3d1 100644 --- a/.gitignore +++ b/.gitignore @@ -91,3 +91,115 @@ $RECYCLE.BIN/ # .nfs files are created when an open file is removed but is still being accessed .nfs* + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser + +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Gcc Patch +/*.gcno From a6e7c4a4a9ed9f732ed9d3c024c3d6891439b4c2 Mon Sep 17 00:00:00 2001 From: Calvin Tam Date: Thu, 8 Jul 2021 12:17:14 -0700 Subject: [PATCH 23/26] Add .toHex8() (#17) --- lib/src/tinycolor.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/src/tinycolor.dart b/lib/src/tinycolor.dart index ad9012d..7daf1ff 100644 --- a/lib/src/tinycolor.dart +++ b/lib/src/tinycolor.dart @@ -80,6 +80,8 @@ class TinyColor { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: _color.alpha.toDouble()); } + String toHex8() => _color.value.toRadixString(16).padLeft(8, '0'); + TinyColor clone() { return TinyColor(_color); } From 5a58244cbff40ff4799134a2b4faf9538e930523 Mon Sep 17 00:00:00 2001 From: Felix Date: Sun, 11 Jul 2021 09:42:08 +0200 Subject: [PATCH 24/26] Add autogenerated files in .idea/ folder (#22) --- .idea/misc.xml | 6 ++++++ .idea/modules.xml | 8 ++++++++ .idea/runConfigurations.xml | 10 ++++++++++ .idea/tinycolor2.iml | 15 +++++++++++++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 45 insertions(+) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/runConfigurations.xml create mode 100644 .idea/tinycolor2.iml create mode 100644 .idea/vcs.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..f8c5fc9 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..a84f1b5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..797acea --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/tinycolor2.iml b/.idea/tinycolor2.iml new file mode 100644 index 0000000..ae9af97 --- /dev/null +++ b/.idea/tinycolor2.iml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file From e52805a7ed7114c0bd9c6cd196908b0490261f0a Mon Sep 17 00:00:00 2001 From: Felix Date: Sun, 11 Jul 2021 09:58:25 +0200 Subject: [PATCH 25/26] Add component ProjectRootManager line in misc.xml (#23) --- .idea/misc.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/.idea/misc.xml b/.idea/misc.xml index f8c5fc9..7b6e330 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,4 +3,5 @@ + \ No newline at end of file From d3710c17dd9cce39ec4da046c2a4888c522436c2 Mon Sep 17 00:00:00 2001 From: Leonardo da Silva Date: Tue, 13 Jul 2021 15:42:20 -0300 Subject: [PATCH 26/26] rename method copy -> clone make extension private access more explicit --- lib/tinycolor.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/tinycolor.dart b/lib/tinycolor.dart index eda3763..ffc3858 100644 --- a/lib/tinycolor.dart +++ b/lib/tinycolor.dart @@ -17,7 +17,7 @@ class TinyColor { TinyColor(Color color) : this.originalColor = color, - _color = color.copy(); + _color = color.clone(); factory TinyColor.fromRGB( {required int r, required int g, required int b, int a = 100}) { @@ -159,8 +159,8 @@ class TinyColor { } } -extension on Color { - Color copy() { +extension _ on Color { + Color clone() { return Color.fromARGB(alpha, red, green, blue); } }