From db93b8de44ba80214b2690cc6c13f7797860b827 Mon Sep 17 00:00:00 2001 From: Ketan Choyal Date: Thu, 18 May 2023 10:38:42 -0400 Subject: [PATCH] feat: Added color dependency so that I don't have to manage it's code --- CHANGELOG.md | 5 + example/pubspec.lock | 10 +- lib/colors/cielab_color.dart | 49 ------- lib/colors/color.dart | 75 ---------- lib/colors/color_filter.dart | 79 ---------- lib/colors/color_parser.dart | 87 ----------- lib/colors/css_color_space.dart | 5 - lib/colors/hex_color.dart | 37 ----- lib/colors/hsl_color.dart | 89 ------------ lib/colors/hsv_color.dart | 53 ------- lib/colors/rgb_color.dart | 250 -------------------------------- lib/colors/xyz_color.dart | 66 --------- lib/mapbox_search.dart | 4 +- pubspec.lock | 8 + pubspec.yaml | 3 +- test/static_image_test.dart | 2 - 16 files changed, 27 insertions(+), 795 deletions(-) delete mode 100644 lib/colors/cielab_color.dart delete mode 100644 lib/colors/color.dart delete mode 100644 lib/colors/color_filter.dart delete mode 100644 lib/colors/color_parser.dart delete mode 100644 lib/colors/css_color_space.dart delete mode 100644 lib/colors/hex_color.dart delete mode 100644 lib/colors/hsl_color.dart delete mode 100644 lib/colors/hsv_color.dart delete mode 100644 lib/colors/rgb_color.dart delete mode 100644 lib/colors/xyz_color.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index 8832731..04368bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ +# [4.1.0-beta.2] - 18 May 2023 +- Added color dependency to the package so that I don't have to manage code related to it. + # [4.1.0-beta.1] - 17 May 2023 - Updated Readme with examples on how to use new added dart 3.0 features - Introduced MapBoxSearch.init() method to initialize the API Key for the package (This is not a breaking change since the API Key can be passed to every class that uses the package) +- Require Dart 3.0 to use the package - Breaking Change: - Instead of throwing exceptions, the package now returns `ApiResponse` Record which can be either `Success` or `Failure` and can be handled using `fold` method. - Location class is now converted to a record. @@ -10,6 +14,7 @@ - Fixed Parsing issue for Search Results - Added maki_icons to enum_generating script to keepup with new icons - This will be last version to support dart < 3.0 +- Require Dart 2.19 to use the package # [4.0.0-beta.1] - 25 April 2023 ## Breaking Changes diff --git a/example/pubspec.lock b/example/pubspec.lock index bf45767..d9ab0cb 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -17,6 +17,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.17.1" + color: + dependency: transitive + description: + name: color + sha256: ddcdf1b3badd7008233f5acffaf20ca9f5dc2cd0172b75f68f24526a5f5725cb + url: "https://pub.dev" + source: hosted + version: "3.0.0" crypto: dependency: transitive description: @@ -47,7 +55,7 @@ packages: path: ".." relative: true source: path - version: "4.1.0-beta.1" + version: "4.1.0-beta.2" meta: dependency: transitive description: diff --git a/lib/colors/cielab_color.dart b/lib/colors/cielab_color.dart deleted file mode 100644 index 8ddfe9c..0000000 --- a/lib/colors/cielab_color.dart +++ /dev/null @@ -1,49 +0,0 @@ -part of color; - -/// A color in the CIELAB color space. -class CielabColor extends Color { - final num l; - final num a; - final num b; - - const CielabColor(this.l, this.a, this.b); - - RgbColor toRgbColor() { - XyzColor xyz = toXyzColor(); - return xyz.toRgbColor(); - } - - /// Converts the color to HSL color space. - HslColor toHslColor() => this.toRgbColor().toHslColor(); - - /// Converts the color to HSV color space. - HsvColor toHsvColor() => this.toRgbColor().toHsvColor(); - - /// Converts the color to XYZ color space. - XyzColor toXyzColor() { - Map xyz = { - 'x': a / 500 + (l + 16) / 116, - 'y': (l + 16) / 116, - 'z': (l + 16) / 116 - b / 200 - }; - - xyz.forEach((key, value) { - num cube = pow(value, 3); - if (cube > 0.008856) { - xyz[key] = cube; - } else { - xyz[key] = (value - 16 / 116) / 7.787; - } - xyz[key] = xyz[key]! * XyzColor.referenceWhite[key]; - }); - - return XyzColor(xyz['x']!, xyz['y']!, xyz['z']!); - } - - // Returns a CielabColor with the same color values as this Color. - CielabColor toCielabColor() => this; - - String toString() => "l: $l, a: $a, b: $b"; - - Map toMap() => {'l': l, 'a': a, 'b': b}; -} diff --git a/lib/colors/color.dart b/lib/colors/color.dart deleted file mode 100644 index 4e1c6f5..0000000 --- a/lib/colors/color.dart +++ /dev/null @@ -1,75 +0,0 @@ -/** -* Copyright (c) 2014 Michael Fenwick -* -* The use of this source code is governed by the MIT license as specified -* in the LICENSE file. -*/ - -library color; - -import 'dart:math'; - -part 'rgb_color.dart'; -part 'hex_color.dart'; -part 'hsl_color.dart'; -part 'hsv_color.dart'; -part 'xyz_color.dart'; -part 'cielab_color.dart'; -part 'color_filter.dart'; -part 'css_color_space.dart'; -part 'color_parser.dart'; - -/** - * An object representing a color. - * - * A [Color] can be constructed be specifying its value as either an RGB vector, a 6 digit hex string, an HSL vector, an XYZ vector, or a LAB vector using the appropriate named constructor. Alternatively, the appropriate subclass can be instantiated directly. - * - * [Color]s can be directly compared using the `==` operator, which will return true if the two [Color] objects represent the same RGB color. - */ -abstract class Color { - const Color(); - const factory Color.rgb(num r, num g, num b) = RgbColor; - factory Color.hex(String hexCode) = HexColor; - const factory Color.hsl(num h, num s, num l) = HslColor; - const factory Color.hsv(num h, num s, num v) = HsvColor; - const factory Color.xyz(num x, num y, num z) = XyzColor; - const factory Color.cielab(num l, num a, num b) = CielabColor; - - RgbColor toRgbColor(); - HexColor toHexColor() => toRgbColor().toHexColor(); - HslColor toHslColor(); - HsvColor toHsvColor(); - XyzColor toXyzColor(); - CielabColor toCielabColor(); - - String toString(); - Map toMap(); - - get hashCode { - RgbColor rgb = this.toRgbColor(); - return 256 * 256 * rgb.r.toInt() + 256 * rgb.g.toInt() + rgb.b.toInt(); - } - - operator ==(Object other) => - other is Color && this.hashCode == other.hashCode; - - operator [](String key) => this.toMap()[key]; - - Color _convert(Type colorType) { - if (colorType is RgbColor) { - return this.toRgbColor(); - } else if (colorType is HexColor) { - return this.toHexColor(); - } else if (colorType is HslColor) { - return this.toHslColor(); - } else if (colorType is HsvColor) { - return this.toHsvColor(); - } else if (colorType is XyzColor) { - return this.toXyzColor(); - } else if (colorType is CielabColor) { - return this.toCielabColor(); - } else { - return this; - } - } -} diff --git a/lib/colors/color_filter.dart b/lib/colors/color_filter.dart deleted file mode 100644 index f82de11..0000000 --- a/lib/colors/color_filter.dart +++ /dev/null @@ -1,79 +0,0 @@ -part of color; - -typedef Color FilterFunction(Color color, [List? args]); - -class ColorFilter { - final FilterFunction filterFunction; - final Type baseType; - - ColorFilter(FilterFunction this.filterFunction, Type this.baseType); - - /** - * Makes the color lighter by the percentage specified in the first argument, or by 10% if no percentage is specified. Percentages should be specified as a float, e.g. an argument of 0.25 will result in a color 25% lighter than the original. The lightening conversion is performed by adjusting the y component of the color in XYZ color space. - */ - static ColorFilter lighten = - new ColorFilter((Color inputColor, [List? args]) { - CielabColor color = inputColor.toCielabColor(); - num percent = 0.1; - if (args is List && args.isNotEmpty && args[0] is num) { - percent = args[0]; - } - return new CielabColor(color.l * (1 + percent), color.a, color.b); - }, CielabColor); - - /** - * Makes the color darker by the percentage specified in the first argument, or by 10% if no percentage is specified. Percentages should be specified as a float, e.g. an argument of 0.25 will result in a color 25% darker than the original. The darkening conversion is performed by adjusting the y component of the color in XYZ color space. - */ - static ColorFilter darken = new ColorFilter((Color inputColor, [List? args]) { - CielabColor color = inputColor.toCielabColor(); - num percent = 0.1; - if (args is List && args.length > 0 && args[0] is num) { - percent = args[0]; - } - return new CielabColor(color.l * (1 - percent), color.a, color.b); - }, CielabColor); - - /** - * Converts the color into its sepia tone equivalent. - */ - static ColorFilter sepia = new ColorFilter((Color baseColor, [List? args]) { - RgbColor color = baseColor.toRgbColor(); - return new RgbColor( - min(RgbColor.rMax, - (color.r * 0.393 + color.g * 0.769 + color.b * 0.189)), - min(RgbColor.gMax, - (color.r * 0.349 + color.g * 0.686 + color.b * 0.168)), - min(RgbColor.bMax, - (color.r * 0.272 + color.g * 0.534 + color.b * 0.131))) - .toCielabColor(); - }, RgbColor); - - /** - * Creates a greyscale color with the same perceived luminance as the source color (as given by the L* value of the color in the CieLAB color space). - */ - static ColorFilter greyscale = - new ColorFilter((Color inputColor, [List? args]) { - CielabColor color = inputColor.toCielabColor(); - num rgbLevel = color.l * 255 / 100; - return new RgbColor(rgbLevel, rgbLevel, rgbLevel).toCielabColor(); - }, CielabColor); - - /** - * Inverts the color by flipping it along the red/green, blue/yellow, and light/dark axes. - */ - static ColorFilter invert = new ColorFilter((Color inputColor, [List? args]) { - CielabColor color = inputColor.toCielabColor(); - return new CielabColor(100 - color.l, -1 * color.a, -1 * color.b); - }, CielabColor); - - /** - * Magic method that allows instances of ColorFilter to be called as functions. The filter itself should be called as a function, rather than calling this method directly. - */ - Color call(Color color, List args) { - Type startingColorSpace = color.runtimeType; - color = color._convert(this.baseType); - color = this.filterFunction(color, args); - color = color._convert(startingColorSpace); - return color; - } -} diff --git a/lib/colors/color_parser.dart b/lib/colors/color_parser.dart deleted file mode 100644 index ab02b5e..0000000 --- a/lib/colors/color_parser.dart +++ /dev/null @@ -1,87 +0,0 @@ -part of color; - -class ColorParser { - static final RegExp _beginsHash = new RegExp("^#"); - static final RegExp _hexColorRegExp = new RegExp("^#?([\\da-fA-F]{6})\$"); - static final RegExp _hexColorAbbreviatedRegExp = - new RegExp("^#?([\\da-fA-F]{3})\$"); - static final RegExp _rgbColorImplicitRegExp = - new RegExp("^(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\$"); - static final RegExp _rgbColorExplicitRegExp = new RegExp( - "^rgb\\(\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*,\\s*(\\d{1,3})\\s*\\)\$"); - static final RegExp _hslColorRegExp = new RegExp( - "^hsl\\(\\s*(\\d{1,3})\\s*,\\s*(\\d+(\\.\\d*)?|\\.\\d+)%\\s*,\\s*(\\d+(\\.\\d*)?|\\.\\d+)%\\s*\\)\$"); - - ///* The code above does the following: - ///1. Trim the string to parse - ///2. If it starts with #, it is a hex color - ///3. If it matches the hex color regexp, it is a hex color - ///4. If it matches the abbreviated hex color regexp, it is a hex color - ///5. If it matches the rgb regexp, it is an rgb color - ///6. If it matches the rgb regexp, it is an rgb color - ///7. If it matches the hsl regexp, it is an hsl color - ///8. If it matches the named regexp, it is a named color - ///9. If none of the above are true, return null or the fallback color */ - Color? parse(String toParse, {Color orElse()?}) { - toParse = toParse.trim(); - return _parseRgb(toParse) ?? - _parseHex(toParse) ?? - _parseHsl(toParse) ?? - _parseNamed(toParse) ?? - orElse?.call() ?? - null; - } - - Color? _parseHex(String toParse) { - if (_hexColorRegExp.hasMatch(toParse)) { - return new HexColor(toParse); - } - - if (_hexColorAbbreviatedRegExp.hasMatch(toParse)) { - String _unAbbreviated = new String.fromCharCodes(toParse - .replaceFirst(_beginsHash, "") - .codeUnits - .map((c) => [c, c]) - .expand((c) => c)); - return new HexColor(_unAbbreviated); - } - - return null; - } - - Color? _parseHsl(String toParse) { - if (_hslColorRegExp.hasMatch(toParse)) { - Match match = _hslColorRegExp.allMatches(toParse).first; - return new HslColor( - int.parse(match.group(1)!), - double.parse(match.group(2) ?? match.group(3)!), - double.parse(match.group(4) ?? match.group(5)!)); - } - - return null; - } - - Color? _parseRgb(String toParse) { - if (_rgbColorImplicitRegExp.hasMatch(toParse)) { - Match match = _rgbColorImplicitRegExp.allMatches(toParse).first; - return new RgbColor(int.parse(match.group(1)!), - int.parse(match.group(2)!), int.parse(match.group(3)!)); - } - - if (_rgbColorExplicitRegExp.hasMatch(toParse)) { - Match match = _rgbColorExplicitRegExp.allMatches(toParse).first; - return new RgbColor(int.parse(match.group(1)!), - int.parse(match.group(2)!), int.parse(match.group(3)!)); - } - - return null; - } - - Color? _parseNamed(String toParse) { - try { - return new RgbColor.name(toParse.toLowerCase()); - } catch (argumentError) { - return null; - } - } -} diff --git a/lib/colors/css_color_space.dart b/lib/colors/css_color_space.dart deleted file mode 100644 index d2f1cde..0000000 --- a/lib/colors/css_color_space.dart +++ /dev/null @@ -1,5 +0,0 @@ -part of color; - -abstract class CssColorSpace { - String toCssString(); -} diff --git a/lib/colors/hex_color.dart b/lib/colors/hex_color.dart deleted file mode 100644 index fe5b4ba..0000000 --- a/lib/colors/hex_color.dart +++ /dev/null @@ -1,37 +0,0 @@ -part of color; - -class HexColor extends RgbColor implements CssColorSpace { - /** - * Creates a [HexColor] using a [String] describing its RGB value in hex. - * - * The [hexCode] should be a string of 6 characters, each of which is a - * valid hex character (0 through 9 and A through F). Capital and lowercase - * letters will work equally well. Characters after the first 6 characters - * will be ignored. If non-valid hex characters are encountered, a - * [FormatException] will be thrown. - * - * The [hexCode] should not be preceeded with a pound sign (#). - */ - factory HexColor(String hexCode) { - if (hexCode.startsWith('#')) { - hexCode = hexCode.substring(1); - } - List hexDigits = hexCode.split(''); - int r = int.parse(hexDigits.sublist(0, 2).join(), radix: 16); - int g = int.parse(hexDigits.sublist(2, 4).join(), radix: 16); - int b = int.parse(hexDigits.sublist(4).join(), radix: 16); - return new HexColor.fromRgb(r, g, b); - } - - const HexColor.fromRgb(num r, num g, num b) : super(r, g, b); - - get rHex => r.toInt().toRadixString(16).padLeft(2, '0'); - get gHex => g.toInt().toRadixString(16).padLeft(2, '0'); - get bHex => b.toInt().toRadixString(16).padLeft(2, '0'); - - HexColor toHexColor() => this; - - String toString() => '$rHex$gHex$bHex'; - - String toCssString() => '#$rHex$gHex$bHex'; -} diff --git a/lib/colors/hsl_color.dart b/lib/colors/hsl_color.dart deleted file mode 100644 index 96bb795..0000000 --- a/lib/colors/hsl_color.dart +++ /dev/null @@ -1,89 +0,0 @@ -part of color; - -class HslColor extends Color implements CssColorSpace { - final num h; - final num s; - final num l; - static const num hMin = 0; - static const num sMin = 0; - static const num lMin = 0; - static const num hMax = 360; - static const num sMax = 100; - static const num lMax = 100; - - /** - * Creates a [HslColor] using a vector describing its hue, saturation, and - * luminance. - * - * The [hue] is given as a number in degrees, typically ranging in value - * between 0 and 360. Values outside of this converted as `hue % 360` to - * be fit into the standard angle range. - * - * The [saturation] is given as a percentage between 0 and 100 (inclusive). - * - * The [luminance] is given as a percentage between 0 and 100 (inclusive). - */ - const HslColor(num this.h, num this.s, num this.l); - - RgbColor toRgbColor() { - List rgb = [0, 0, 0]; - - num hue = h / 360 % 1; - num saturation = s / 100; - num luminance = l / 100; - - if (hue < 1 / 6) { - rgb[0] = 1; - rgb[1] = hue * 6; - } else if (hue < 2 / 6) { - rgb[0] = 2 - hue * 6; - rgb[1] = 1; - } else if (hue < 3 / 6) { - rgb[1] = 1; - rgb[2] = hue * 6 - 2; - } else if (hue < 4 / 6) { - rgb[1] = 4 - hue * 6; - rgb[2] = 1; - } else if (hue < 5 / 6) { - rgb[0] = hue * 6 - 4; - rgb[2] = 1; - } else { - rgb[0] = 1; - rgb[2] = 6 - hue * 6; - } - - rgb = rgb.map((val) => val + (1 - saturation) * (0.5 - val)).toList(); - - if (luminance < 0.5) { - rgb = rgb.map((val) => luminance * 2 * val).toList(); - } else { - rgb = rgb.map((val) => luminance * 2 * (1 - val) + 2 * val - 1).toList(); - } - - rgb = rgb.map((val) => (val * 255).round()).toList(); - - return new RgbColor(rgb[0], rgb[1], rgb[2]); - } - - HslColor toHslColor() => this; - - HsvColor toHsvColor() { - num hslSaturation = s / 100; - num lightness = l / 100; - - num value = lightness + hslSaturation * min(lightness, 1 - lightness); - num saturation = value == 0 ? 0 : 2 * (1 - lightness / value); - - return HsvColor(h, saturation * 100, value * 100); - } - - XyzColor toXyzColor() => this.toRgbColor().toXyzColor(); - - CielabColor toCielabColor() => this.toRgbColor().toXyzColor().toCielabColor(); - - String toString() => "h: $h, s: $s%, l: $l%"; - - String toCssString() => 'hsl($h, $s%, $l%)'; - - Map toMap() => {'h': h, 's': s, 'l': l}; -} diff --git a/lib/colors/hsv_color.dart b/lib/colors/hsv_color.dart deleted file mode 100644 index c5332cb..0000000 --- a/lib/colors/hsv_color.dart +++ /dev/null @@ -1,53 +0,0 @@ -part of color; - -class HsvColor extends Color { - final num h; - final num s; - final num v; - static const num hMin = 0; - static const num sMin = 0; - static const num vMin = 0; - static const num hMax = 360; - static const num sMax = 100; - static const num vMax = 100; - - /** - * Creates a [HsvColor] using a vector describing its hue, saturation, and - * value. - * - * The [hue] is given as a number in degrees, typically ranging in value - * between 0 and 360. Values outside of this converted as `hue % 360` to - * be fit into the standard angle range. - * - * The [saturation] is given as a percentage between 0 and 100 (inclusive). - * - * The [value] is given as a percentage between 0 and 100 (inclusive). - */ - const HsvColor(num this.h, num this.s, num this.v); - - num abs(num value) => value >= 0 ? value : -value; - - RgbColor toRgbColor() => this.toHslColor().toRgbColor(); - - HslColor toHslColor() { - num hsvSaturation = s / 100; - num value = v / 100; - - num lightness = value * (1 - hsvSaturation / 2); - num saturation = lightness == 0 || lightness == 1 - ? 0 - : (value - lightness) / min(lightness, 1 - lightness); - - return HslColor(h, saturation * 100, lightness * 100); - } - - HsvColor toHsvColor() => this; - - XyzColor toXyzColor() => this.toRgbColor().toXyzColor(); - - CielabColor toCielabColor() => this.toRgbColor().toXyzColor().toCielabColor(); - - String toString() => "h: $h, s: $s%, v: $v%"; - - Map toMap() => {'h': h, 's': s, 'v': v}; -} diff --git a/lib/colors/rgb_color.dart b/lib/colors/rgb_color.dart deleted file mode 100644 index b9678ec..0000000 --- a/lib/colors/rgb_color.dart +++ /dev/null @@ -1,250 +0,0 @@ -part of color; - -class RgbColor extends Color implements CssColorSpace { - final num r; - final num g; - final num b; - static const int rMin = 0; - static const int gMin = 0; - static const int bMin = 0; - static const int rMax = 255; - static const int gMax = 255; - static const int bMax = 255; - - /** - * Creates a [Color] using a vector describing its red, green, and blue - * values. - * - * The value for [r], [g], and [b] should be in the range between 0 and - * 255 (inclusive). Values above this range will be assumed to be a value - * of 255, and values below this range will be assumed to be a value of 0. - */ - const RgbColor(this.r, this.g, this.b); - - factory RgbColor.name(String name) { - if (RgbColor.namedColors.containsKey(name)) { - return RgbColor.namedColors[name]!; - } else { - throw new ArgumentError( - "Only the color names defined by the CSS3 spec are supported. See http://www.w3.org/TR/css3-color/#svg-color for a list of valid color names."); - } - } - - RgbColor toRgbColor() => this; - - HslColor toHslColor() { - num rf = r / 255; - num gf = g / 255; - num bf = b / 255; - num cMax = [rf, gf, bf].reduce(max); - num cMin = [rf, gf, bf].reduce(min); - num delta = cMax - cMin; - num hue; - num saturation; - num luminance; - - if (cMax == rf) { - hue = 60 * ((gf - bf) / delta % 6); - } else if (cMax == gf) { - hue = 60 * ((bf - rf) / delta + 2); - } else { - hue = 60 * ((rf - gf) / delta + 4); - } - - if (hue.isNaN || hue.isInfinite) { - hue = 0; - } - - luminance = (cMax + cMin) / 2; - - if (delta == 0) { - saturation = 0; - } else { - saturation = delta / (1 - (luminance * 2 - 1).abs()); - } - - return new HslColor(hue, saturation * 100, luminance * 100); - } - - HsvColor toHsvColor() => toHslColor().toHsvColor(); - - XyzColor toXyzColor() { - Map rgb = {'r': r / 255, 'g': g / 255, 'b': b / 255}; - - rgb.forEach((key, value) { - if (value > 0.04045) { - rgb[key] = pow((value + 0.055) / 1.055, 2.4); - } else { - rgb[key] = value / 12.92; - } - rgb[key] = rgb[key]! * 100; - }); - - num x = rgb['r']! * 0.4124 + rgb['g']! * 0.3576 + rgb['b']! * 0.1805; - num y = rgb['r']! * 0.2126 + rgb['g']! * 0.7152 + rgb['b']! * 0.0722; - num z = rgb['r']! * 0.0193 + rgb['g']! * 0.1192 + rgb['b']! * 0.9505; - - return XyzColor(x, y, z); - } - - CielabColor toCielabColor() => this.toXyzColor().toCielabColor(); - - HexColor toHexColor() => new HexColor.fromRgb(r, g, b); - - String toString() => "r: $r, g: $g, b: $b"; - - String toCssString() => 'rgb(${r.toInt()}, ${g.toInt()}, ${b.toInt()})'; - - Map toMap() => {'r': r, 'g': g, 'b': b}; - - static const Map namedColors = const { - 'aliceblue': const Color.rgb(240, 248, 255) as RgbColor, - 'antiquewhite': const Color.rgb(250, 235, 215) as RgbColor, - 'aqua': const Color.rgb(0, 255, 255) as RgbColor, - 'aquamarine': const Color.rgb(127, 255, 212) as RgbColor, - 'azure': const Color.rgb(240, 255, 255) as RgbColor, - 'beige': const Color.rgb(245, 245, 220) as RgbColor, - 'bisque': const Color.rgb(255, 228, 196) as RgbColor, - 'black': const Color.rgb(0, 0, 0) as RgbColor, - 'blanchedalmond': const Color.rgb(255, 235, 205) as RgbColor, - 'blue': const Color.rgb(0, 0, 255) as RgbColor, - 'blueviolet': const Color.rgb(138, 43, 226) as RgbColor, - 'brown': const Color.rgb(165, 42, 42) as RgbColor, - 'burlywood': const Color.rgb(222, 184, 135) as RgbColor, - 'cadetblue': const Color.rgb(95, 158, 160) as RgbColor, - 'chartreuse': const Color.rgb(127, 255, 0) as RgbColor, - 'chocolate': const Color.rgb(210, 105, 30) as RgbColor, - 'coral': const Color.rgb(255, 127, 80) as RgbColor, - 'cornflowerblue': const Color.rgb(100, 149, 237) as RgbColor, - 'cornsilk': const Color.rgb(255, 248, 220) as RgbColor, - 'crimson': const Color.rgb(220, 20, 60) as RgbColor, - 'cyan': const Color.rgb(0, 255, 255) as RgbColor, - 'darkblue': const Color.rgb(0, 0, 139) as RgbColor, - 'darkcyan': const Color.rgb(0, 139, 139) as RgbColor, - 'darkgoldenrod': const Color.rgb(184, 134, 11) as RgbColor, - 'darkgray': const Color.rgb(169, 169, 169) as RgbColor, - 'darkgreen': const Color.rgb(0, 100, 0) as RgbColor, - 'darkgrey': const Color.rgb(169, 169, 169) as RgbColor, - 'darkkhaki': const Color.rgb(189, 183, 107) as RgbColor, - 'darkmagenta': const Color.rgb(139, 0, 139) as RgbColor, - 'darkolivegreen': const Color.rgb(85, 107, 47) as RgbColor, - 'darkorange': const Color.rgb(255, 140, 0) as RgbColor, - 'darkorchid': const Color.rgb(153, 50, 204) as RgbColor, - 'darkred': const Color.rgb(139, 0, 0) as RgbColor, - 'darksalmon': const Color.rgb(233, 150, 122) as RgbColor, - 'darkseagreen': const Color.rgb(143, 188, 143) as RgbColor, - 'darkslateblue': const Color.rgb(72, 61, 139) as RgbColor, - 'darkslategray': const Color.rgb(47, 79, 79) as RgbColor, - 'darkslategrey': const Color.rgb(47, 79, 79) as RgbColor, - 'darkturquoise': const Color.rgb(0, 206, 209) as RgbColor, - 'darkviolet': const Color.rgb(148, 0, 211) as RgbColor, - 'deeppink': const Color.rgb(255, 20, 147) as RgbColor, - 'deepskyblue': const Color.rgb(0, 191, 255) as RgbColor, - 'dimgray': const Color.rgb(105, 105, 105) as RgbColor, - 'dimgrey': const Color.rgb(105, 105, 105) as RgbColor, - 'dodgerblue': const Color.rgb(30, 144, 255) as RgbColor, - 'firebrick': const Color.rgb(178, 34, 34) as RgbColor, - 'floralwhite': const Color.rgb(255, 250, 240) as RgbColor, - 'forestgreen': const Color.rgb(34, 139, 34) as RgbColor, - 'fuchsia': const Color.rgb(255, 0, 255) as RgbColor, - 'gainsboro': const Color.rgb(220, 220, 220) as RgbColor, - 'ghostwhite': const Color.rgb(248, 248, 255) as RgbColor, - 'gold': const Color.rgb(255, 215, 0) as RgbColor, - 'goldenrod': const Color.rgb(218, 165, 32) as RgbColor, - 'gray': const Color.rgb(128, 128, 128) as RgbColor, - 'green': const Color.rgb(0, 128, 0) as RgbColor, - 'greenyellow': const Color.rgb(173, 255, 47) as RgbColor, - 'grey': const Color.rgb(128, 128, 128) as RgbColor, - 'honeydew': const Color.rgb(240, 255, 240) as RgbColor, - 'hotpink': const Color.rgb(255, 105, 180) as RgbColor, - 'indianred': const Color.rgb(205, 92, 92) as RgbColor, - 'indigo': const Color.rgb(75, 0, 130) as RgbColor, - 'ivory': const Color.rgb(255, 255, 240) as RgbColor, - 'khaki': const Color.rgb(240, 230, 140) as RgbColor, - 'lavender': const Color.rgb(230, 230, 250) as RgbColor, - 'lavenderblush': const Color.rgb(255, 240, 245) as RgbColor, - 'lawngreen': const Color.rgb(124, 252, 0) as RgbColor, - 'lemonchiffon': const Color.rgb(255, 250, 205) as RgbColor, - 'lightblue': const Color.rgb(173, 216, 230) as RgbColor, - 'lightcoral': const Color.rgb(240, 128, 128) as RgbColor, - 'lightcyan': const Color.rgb(224, 255, 255) as RgbColor, - 'lightgoldenrodyellow': const Color.rgb(250, 250, 210) as RgbColor, - 'lightgray': const Color.rgb(211, 211, 211) as RgbColor, - 'lightgreen': const Color.rgb(144, 238, 144) as RgbColor, - 'lightgrey': const Color.rgb(211, 211, 211) as RgbColor, - 'lightpink': const Color.rgb(255, 182, 193) as RgbColor, - 'lightsalmon': const Color.rgb(255, 160, 122) as RgbColor, - 'lightseagreen': const Color.rgb(32, 178, 170) as RgbColor, - 'lightskyblue': const Color.rgb(135, 206, 250) as RgbColor, - 'lightslategray': const Color.rgb(119, 136, 153) as RgbColor, - 'lightslategrey': const Color.rgb(119, 136, 153) as RgbColor, - 'lightsteelblue': const Color.rgb(176, 196, 222) as RgbColor, - 'lightyellow': const Color.rgb(255, 255, 224) as RgbColor, - 'lime': const Color.rgb(0, 255, 0) as RgbColor, - 'limegreen': const Color.rgb(50, 205, 50) as RgbColor, - 'linen': const Color.rgb(250, 240, 230) as RgbColor, - 'magenta': const Color.rgb(255, 0, 255) as RgbColor, - 'maroon': const Color.rgb(128, 0, 0) as RgbColor, - 'mediumaquamarine': const Color.rgb(102, 205, 170) as RgbColor, - 'mediumblue': const Color.rgb(0, 0, 205) as RgbColor, - 'mediumorchid': const Color.rgb(186, 85, 211) as RgbColor, - 'mediumpurple': const Color.rgb(147, 112, 219) as RgbColor, - 'mediumseagreen': const Color.rgb(60, 179, 113) as RgbColor, - 'mediumslateblue': const Color.rgb(123, 104, 238) as RgbColor, - 'mediumspringgreen': const Color.rgb(0, 250, 154) as RgbColor, - 'mediumturquoise': const Color.rgb(72, 209, 204) as RgbColor, - 'mediumvioletred': const Color.rgb(199, 21, 133) as RgbColor, - 'midnightblue': const Color.rgb(25, 25, 112) as RgbColor, - 'mintcream': const Color.rgb(245, 255, 250) as RgbColor, - 'mistyrose': const Color.rgb(255, 228, 225) as RgbColor, - 'moccasin': const Color.rgb(255, 228, 181) as RgbColor, - 'navajowhite': const Color.rgb(255, 222, 173) as RgbColor, - 'navy': const Color.rgb(0, 0, 128) as RgbColor, - 'oldlace': const Color.rgb(253, 245, 230) as RgbColor, - 'olive': const Color.rgb(128, 128, 0) as RgbColor, - 'olivedrab': const Color.rgb(107, 142, 35) as RgbColor, - 'orange': const Color.rgb(255, 165, 0) as RgbColor, - 'orangered': const Color.rgb(255, 69, 0) as RgbColor, - 'orchid': const Color.rgb(218, 112, 214) as RgbColor, - 'palegoldenrod': const Color.rgb(238, 232, 170) as RgbColor, - 'palegreen': const Color.rgb(152, 251, 152) as RgbColor, - 'paleturquoise': const Color.rgb(175, 238, 238) as RgbColor, - 'palevioletred': const Color.rgb(219, 112, 147) as RgbColor, - 'papayawhip': const Color.rgb(255, 239, 213) as RgbColor, - 'peachpuff': const Color.rgb(255, 218, 185) as RgbColor, - 'peru': const Color.rgb(205, 133, 63) as RgbColor, - 'pink': const Color.rgb(255, 192, 203) as RgbColor, - 'plum': const Color.rgb(221, 160, 221) as RgbColor, - 'powderblue': const Color.rgb(176, 224, 230) as RgbColor, - 'purple': const Color.rgb(128, 0, 128) as RgbColor, - 'rebeccapurple': const Color.rgb(102, 51, 153) as RgbColor, - 'red': const Color.rgb(255, 0, 0) as RgbColor, - 'rosybrown': const Color.rgb(188, 143, 143) as RgbColor, - 'royalblue': const Color.rgb(65, 105, 225) as RgbColor, - 'saddlebrown': const Color.rgb(139, 69, 19) as RgbColor, - 'salmon': const Color.rgb(250, 128, 114) as RgbColor, - 'sandybrown': const Color.rgb(244, 164, 96) as RgbColor, - 'seagreen': const Color.rgb(46, 139, 87) as RgbColor, - 'seashell': const Color.rgb(255, 245, 238) as RgbColor, - 'sienna': const Color.rgb(160, 82, 45) as RgbColor, - 'silver': const Color.rgb(192, 192, 192) as RgbColor, - 'skyblue': const Color.rgb(135, 206, 235) as RgbColor, - 'slateblue': const Color.rgb(106, 90, 205) as RgbColor, - 'slategray': const Color.rgb(112, 128, 144) as RgbColor, - 'slategrey': const Color.rgb(112, 128, 144) as RgbColor, - 'snow': const Color.rgb(255, 250, 250) as RgbColor, - 'springgreen': const Color.rgb(0, 255, 127) as RgbColor, - 'steelblue': const Color.rgb(70, 130, 180) as RgbColor, - 'tan': const Color.rgb(210, 180, 140) as RgbColor, - 'teal': const Color.rgb(0, 128, 128) as RgbColor, - 'thistle': const Color.rgb(216, 191, 216) as RgbColor, - 'tomato': const Color.rgb(255, 99, 71) as RgbColor, - 'turquoise': const Color.rgb(64, 224, 208) as RgbColor, - 'violet': const Color.rgb(238, 130, 238) as RgbColor, - 'wheat': const Color.rgb(245, 222, 179) as RgbColor, - 'white': const Color.rgb(255, 255, 255) as RgbColor, - 'whitesmoke': const Color.rgb(245, 245, 245) as RgbColor, - 'yellow': const Color.rgb(255, 255, 0) as RgbColor, - 'yellowgreen': const Color.rgb(154, 205, 50) as RgbColor - }; -} diff --git a/lib/colors/xyz_color.dart b/lib/colors/xyz_color.dart deleted file mode 100644 index 4a8faeb..0000000 --- a/lib/colors/xyz_color.dart +++ /dev/null @@ -1,66 +0,0 @@ -part of color; - -class XyzColor extends Color { - final num x; - final num y; - final num z; - - static const referenceWhite = const XyzColor(95.047, 100, 108.883); - - const XyzColor(this.x, this.y, this.z); - - RgbColor toRgbColor() { - num x = this.x / 100; - num y = this.y / 100; - num z = this.z / 100; - - Map rgb = { - 'r': x * 3.2406 + y * -1.5372 + z * -0.4986, - 'g': x * -0.9689 + y * 1.8758 + z * 0.0415, - 'b': x * 0.0557 + y * -0.2040 + z * 1.0570 - }; - - rgb.forEach((key, value) { - if (value > 0.0031308) { - rgb[key] = 1.055 * pow(value, 1 / 2.4) - 0.055; - } else { - rgb[key] = value * 12.92; - } - rgb[key] = rgb[key]! * 255; - }); - - return new RgbColor(rgb['r']!, rgb['g']!, rgb['b']!); - } - - HslColor toHslColor() => this.toRgbColor().toHslColor(); - - HsvColor toHsvColor() => this.toRgbColor().toHsvColor(); - - XyzColor toXyzColor() => this; - - CielabColor toCielabColor() { - Map lab = {}; - Map xyz = {}; - - this.toMap().forEach((String key, num? value) { - value = value! / referenceWhite[key]; - - if (value > 0.008856) { - value = pow(value, 1 / 3); - } else { - value = (7.787 * value) + 16 / 116; - } - xyz[key] = value; - }); - - lab['l'] = (116 * xyz['y']!) - 16; - lab['a'] = 500 * (xyz['x']! - xyz['y']!); - lab['b'] = 200 * (xyz['y']! - xyz['z']!); - - return new CielabColor(lab['l']!, lab['a']!, lab['b']!); - } - - String toString() => "x: $x, y: $y, z: $z"; - - Map toMap() => {'x': x, 'y': y, 'z': z}; -} diff --git a/lib/mapbox_search.dart b/lib/mapbox_search.dart index 9e90560..c50e83e 100644 --- a/lib/mapbox_search.dart +++ b/lib/mapbox_search.dart @@ -2,9 +2,11 @@ library mapbox_search; import 'dart:convert'; import 'package:http/http.dart' as http; -import 'package:mapbox_search/colors/color.dart'; +import 'package:color/color.dart'; import 'package:uuid/uuid.dart'; +export 'package:color/color.dart'; + part 'models/predictions.dart'; part 'models/location_context.dart'; part 'models/geometry.dart'; diff --git a/pubspec.lock b/pubspec.lock index fd5b34b..d1484b6 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -57,6 +57,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.15.0" + color: + dependency: "direct main" + description: + name: color + sha256: ddcdf1b3badd7008233f5acffaf20ca9f5dc2cd0172b75f68f24526a5f5725cb + url: "https://pub.dev" + source: hosted + version: "3.0.0" convert: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 2ca5990..f506318 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: mapbox_search description: A Flutter package for place search using MapBox Api and for Static map image -version: 4.1.0-beta.1 +version: 4.1.0-beta.2 homepage: https://github.com/ketanchoyal/mapbox_search @@ -10,6 +10,7 @@ environment: dependencies: http: ^0.13.6 uuid: ^3.0.7 + color: ^3.0.0 dev_dependencies: pedantic: ^1.11.1 diff --git a/test/static_image_test.dart b/test/static_image_test.dart index a11f261..ffbb107 100644 --- a/test/static_image_test.dart +++ b/test/static_image_test.dart @@ -1,6 +1,4 @@ import 'dart:io'; - -import 'package:mapbox_search/colors/color.dart'; import 'package:mapbox_search/mapbox_search.dart'; import 'package:test/test.dart'; import 'credentials.dart' as c;