diff --git a/lib/src/input/figma/entities/style/fill/linear_gradient_fill_type.dart b/lib/src/input/figma/entities/style/fill/linear_gradient_fill_type.dart new file mode 100644 index 00000000..ea208935 --- /dev/null +++ b/lib/src/input/figma/entities/style/fill/linear_gradient_fill_type.dart @@ -0,0 +1,57 @@ +import 'package:pbdl/src/input/figma/entities/style/style_addition.dart'; +import 'package:pbdl/src/pbdl/pbdl_fill.dart'; + +import 'package:pbdl/src/input/figma/entities/style/figma_fill.dart'; + +import 'package:pbdl/src/input/figma/entities/style/figma_color.dart'; + +import 'dart:math'; + +import 'gradient_fill_type.dart'; + +class LinearGradientFillType implements GradientFillType { + @override + String blendMode; + + @override + FigmaColor color; + + @override + List> gradientHandlePositions; + + @override + List gradientStops; + + @override + num opacity; + + @override + String type; + + @override + bool visible; + + @override + FigmaFill createFigmaFill(Map json) { + // TODO: implement createFigmaFill + throw UnimplementedError(); + } + + @override + PBDLFill interpretFill() { + // TODO: implement interpretFill + throw UnimplementedError(); + } + + @override + Map toJson() { + // TODO: implement toJson + throw UnimplementedError(); + } + + @override + String addStyle(StyleAdditionNode style) { + // TODO: implement addStyle + throw UnimplementedError(); + } +} diff --git a/lib/src/input/figma/entities/style/global/effect_global.dart b/lib/src/input/figma/entities/style/global/effect_global.dart new file mode 100644 index 00000000..f582dc18 --- /dev/null +++ b/lib/src/input/figma/entities/style/global/effect_global.dart @@ -0,0 +1,59 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:pbdl/src/input/figma/entities/layers/figma_base_node.dart'; +import 'package:pbdl/src/input/figma/entities/layers/rectangle.dart'; +import 'package:pbdl/src/input/figma/entities/layers/text.dart'; +import 'package:pbdl/src/input/figma/entities/style/figma_effect.dart'; +import 'package:pbdl/src/input/figma/entities/style/figma_text_style.dart'; +import 'package:pbdl/src/input/figma/entities/style/global/global_style_property.dart'; +import 'package:pbdl/src/pbdl/global_styles/pbdl_global_effect.dart'; +import 'package:pbdl/src/pbdl/pbdl_node.dart'; + +part 'effect_global.g.dart'; + +@JsonSerializable(explicitToJson: true) +class EffectGlobal extends GlobalStyleProperty { + EffectGlobal( + String UUID, + String styleType, { + String name, + String description, + FigmaEffect styleNode, + }) : super( + UUID, + styleType, + name: name, + description: description, + styleNode: styleNode, + ); + + /// Contains the actual effect style value. + + @override + Future interpretNode() async { + if (styleNode == null) { + return null; + } + return PBDLGlobalEffect( + UUID, + name, + (styleNode as FigmaEffect).interpretEffect(), + description: description, + ); + } + + Map toJson() => _$EffectGlobalToJson(this); + + factory EffectGlobal.fromJson( + Map json, FigmaBaseNode styleNode) { + if (styleNode is! FigmaRectangle) { + return null; + } + + var firstEffect = + (styleNode as FigmaRectangle).figmaStyleProperty.effects.first; + + final figmaNode = _$EffectGlobalFromJson(json)..styleNode = firstEffect; + + return figmaNode; + } +} diff --git a/lib/src/input/figma/entities/style/global/effect_global.g.dart b/lib/src/input/figma/entities/style/global/effect_global.g.dart new file mode 100644 index 00000000..743e54f4 --- /dev/null +++ b/lib/src/input/figma/entities/style/global/effect_global.g.dart @@ -0,0 +1,28 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'effect_global.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +EffectGlobal _$EffectGlobalFromJson(Map json) { + return EffectGlobal( + json['UUID'] as String, + json['styleType'] as String, + name: json['name'] as String, + description: json['description'] as String, + styleNode: json['styleNode'] == null + ? null + : FigmaEffect.fromJson(json['styleNode'] as Map), + ); +} + +Map _$EffectGlobalToJson(EffectGlobal instance) => + { + 'UUID': instance.UUID, + 'name': instance.name, + 'description': instance.description, + 'styleType': instance.styleType, + 'styleNode': instance.styleNode, + }; diff --git a/lib/src/input/figma/entities/style/global/fill_style_global.dart b/lib/src/input/figma/entities/style/global/fill_style_global.dart index b788ff81..18d71f70 100644 --- a/lib/src/input/figma/entities/style/global/fill_style_global.dart +++ b/lib/src/input/figma/entities/style/global/fill_style_global.dart @@ -2,8 +2,12 @@ import 'package:json_annotation/json_annotation.dart'; import 'package:pbdl/src/input/figma/entities/layers/figma_base_node.dart'; import 'package:pbdl/src/input/figma/entities/layers/rectangle.dart'; import 'package:pbdl/src/input/figma/entities/style/figma_color.dart'; +import 'package:pbdl/src/input/figma/entities/style/fill/fill_type.dart'; +import 'package:pbdl/src/input/figma/entities/style/fill/gradient_fill_type.dart'; import 'package:pbdl/src/input/figma/entities/style/global/global_style_property.dart'; import 'package:pbdl/src/pbdl/global_styles/pbdl_global_color.dart'; +import 'package:pbdl/src/pbdl/global_styles/pbdl_global_gradient.dart'; +import 'package:pbdl/src/pbdl/global_styles/pbdl_global_image.dart'; import 'package:pbdl/src/pbdl/pbdl_node.dart'; part 'fill_style_global.g.dart'; @@ -15,7 +19,7 @@ class FillStyleGlobal extends GlobalStyleProperty { String styleType, { String name, String description, - FigmaColor styleNode, + var styleNode, }) : super( UUID, styleType, @@ -29,12 +33,30 @@ class FillStyleGlobal extends GlobalStyleProperty { if (styleNode == null) { return null; } - return PBDLGlobalColor( - UUID, - name, - (styleNode as FigmaColor).interpretColor(), - description: description, - ); + if (styleNode is FigmaColor) { + return PBDLGlobalColor( + UUID, + name, + (styleNode as FigmaColor).interpretColor(), + description: description, + ); + } else if (styleNode is ImageFillType) { + // TODO: figma Asset processor + return PBDLGlobalImage( + UUID, + name, + (styleNode as ImageFillType).interpretFill(), + description: description, + ); + } else if (styleNode is GradientFillType) { + return PBDLGlobalGradient( + UUID, + name, + (styleNode as GradientFillType).interpretFill(), + description: description, + ); + } + return null; } Map toJson() => _$FillStyleGlobalToJson(this); @@ -44,9 +66,20 @@ class FillStyleGlobal extends GlobalStyleProperty { if (styleNode is! FigmaRectangle) { return null; } - var color = - (styleNode as FigmaRectangle).figmaStyleProperty.fills.first.color; - var globalFill = _$FillStyleGlobalFromJson(json)..styleNode = color; + var firstFill = + (styleNode as FigmaRectangle).figmaStyleProperty.fills.first; + var color = firstFill.color; + + var globalFill; + if (color == null) { + if (firstFill is GradientFillType) { + globalFill = _$FillStyleGlobalFromJson(json)..styleNode = firstFill; + } else if (firstFill is ImageFillType) { + globalFill = _$FillStyleGlobalFromJson(json)..styleNode = firstFill; + } + } else { + globalFill = _$FillStyleGlobalFromJson(json)..styleNode = color; + } return globalFill; } diff --git a/lib/src/input/figma/entities/style/global/fill_style_global.g.dart b/lib/src/input/figma/entities/style/global/fill_style_global.g.dart index d6647d6a..c0f9a0a0 100644 --- a/lib/src/input/figma/entities/style/global/fill_style_global.g.dart +++ b/lib/src/input/figma/entities/style/global/fill_style_global.g.dart @@ -12,9 +12,7 @@ FillStyleGlobal _$FillStyleGlobalFromJson(Map json) { json['styleType'] as String, name: json['name'] as String, description: json['description'] as String, - styleNode: json['styleNode'] == null - ? null - : FigmaColor.fromJson(json['styleNode'] as Map), + styleNode: json['styleNode'], ); } @@ -24,5 +22,5 @@ Map _$FillStyleGlobalToJson(FillStyleGlobal instance) => 'name': instance.name, 'description': instance.description, 'styleType': instance.styleType, - 'styleNode': instance.styleNode?.toJson(), + 'styleNode': instance.styleNode, }; diff --git a/lib/src/input/figma/entities/style/global/global_style_holder.dart b/lib/src/input/figma/entities/style/global/global_style_holder.dart index 8c03a4d1..f17b4e4a 100644 --- a/lib/src/input/figma/entities/style/global/global_style_holder.dart +++ b/lib/src/input/figma/entities/style/global/global_style_holder.dart @@ -1,13 +1,11 @@ import 'package:json_annotation/json_annotation.dart'; +import 'package:pbdl/pbdl.dart'; import 'package:pbdl/src/input/figma/entities/layers/figma_base_node.dart'; +import 'package:pbdl/src/input/figma/entities/style/global/effect_global.dart'; import 'package:pbdl/src/input/figma/entities/style/global/fill_style_global.dart'; import 'package:pbdl/src/input/figma/entities/style/global/global_style_property.dart'; import 'package:pbdl/src/input/figma/entities/style/global/text_style_global.dart'; import 'package:pbdl/src/pbdl/global_styles/design_systems/design_system_theme_data.dart'; -import 'package:pbdl/src/pbdl/global_styles/pbdl_global_color.dart'; -import 'package:pbdl/src/pbdl/global_styles/pbdl_global_styles.dart'; -import 'package:pbdl/src/pbdl/global_styles/pbdl_global_text_style.dart'; -import 'package:pbdl/src/pbdl/pbdl_node.dart'; part 'global_style_holder.g.dart'; @@ -19,11 +17,6 @@ class GlobalStyleHolder extends FigmaBaseNode { /// Registered [GlobalStyleProperty]s. final _properties = {}; - final registeredPropertyNames = [ - 'fill', - 'text', - ]; - @JsonKey(ignore: true) final DesignSystemThemeData designSystemThemeData; @@ -42,6 +35,9 @@ class GlobalStyleHolder extends FigmaBaseNode { Iterable get textStyles => _properties.values.whereType(); + Iterable get effects => + _properties.values.whereType(); + /// Returns the [GlobalStyleProperty] with the given [UUID] and specified type [T]. /// /// If the [UUID] is not found, returns null. @@ -57,9 +53,10 @@ class GlobalStyleHolder extends FigmaBaseNode { Future interpretNode() async { /// Interpret fills to [PBDLGlobalFillProperty] var themeColors = []; - var globalColors = []; + var globalColors = []; var themeTextStyles = []; var globalTextStyles = []; + var globalEffects = []; for (var fill in fills) { final interpretedFill = await fill.interpretNode(); @@ -88,11 +85,17 @@ class GlobalStyleHolder extends FigmaBaseNode { } } + /// Interpret effects + for (var effect in effects) { + globalEffects.add(await effect.interpretNode()); + } + return PBDLGlobalStyles( colors: globalColors, textStyles: globalTextStyles, themeColors: themeColors, themeTextStyles: themeTextStyles, + effects: globalEffects, ); } diff --git a/lib/src/input/figma/entities/style/global/global_style_property.dart b/lib/src/input/figma/entities/style/global/global_style_property.dart index 623d281c..949549a2 100644 --- a/lib/src/input/figma/entities/style/global/global_style_property.dart +++ b/lib/src/input/figma/entities/style/global/global_style_property.dart @@ -1,4 +1,5 @@ import 'package:pbdl/src/input/figma/entities/layers/figma_base_node.dart'; +import 'package:pbdl/src/input/figma/entities/style/global/effect_global.dart'; import 'package:pbdl/src/input/figma/entities/style/global/fill_style_global.dart'; import 'package:pbdl/src/input/figma/entities/style/global/text_style_global.dart'; @@ -7,7 +8,7 @@ abstract class GlobalStyleProperty extends FigmaBaseNode { final String name; final String description; final String styleType; - FigmaBaseNode styleNode; + var styleNode; GlobalStyleProperty( this.UUID, @@ -26,6 +27,8 @@ abstract class GlobalStyleProperty extends FigmaBaseNode { return FillStyleGlobal.fromJson(json, styleNode); case 'TEXT': return TextStyleGlobal.fromJson(json, styleNode); + case 'EFFECT': + return EffectGlobal.fromJson(json, styleNode); default: return null; } diff --git a/lib/src/input/figma/entities/style/global/text_style_global.g.dart b/lib/src/input/figma/entities/style/global/text_style_global.g.dart index 1718d674..ae9fdff2 100644 --- a/lib/src/input/figma/entities/style/global/text_style_global.g.dart +++ b/lib/src/input/figma/entities/style/global/text_style_global.g.dart @@ -24,5 +24,5 @@ Map _$TextStyleGlobalToJson(TextStyleGlobal instance) => 'name': instance.name, 'description': instance.description, 'styleType': instance.styleType, - 'styleNode': instance.styleNode?.toJson(), + 'styleNode': instance.styleNode, }; diff --git a/lib/src/input/figma/helper/figma_asset_processor.dart b/lib/src/input/figma/helper/figma_asset_processor.dart index 6ee25b39..a3019ff0 100644 --- a/lib/src/input/figma/helper/figma_asset_processor.dart +++ b/lib/src/input/figma/helper/figma_asset_processor.dart @@ -32,6 +32,8 @@ class FigmaAssetProcessor extends AssetProcessingService { Logger log = Logger('Figma Image helper'); + Map globalImages = {}; + /// Adds [uuid] to queue to be processed as an image. /// Returns the formatted name of the image reference. @override @@ -53,9 +55,29 @@ class FigmaAssetProcessor extends AssetProcessingService { _uuidNoBoxQueue.add(uuid); } + var finalName = _getNameAndRegister(uuid, name); + return _imageFinalName(finalName, format); + } + + // To add images to get processed when they have their url + String processImageWithURL(String uuid, String url, + {String name, IMAGE_FORMAT format = IMAGE_FORMAT.PNG}) { + globalImages[uuid] = url; + + var finalName = _getNameAndRegister(uuid, name); + + return _imageFinalName(finalName, format); + } + + // Get image format correctly + String _imageFinalName(String name, IMAGE_FORMAT format) => + ('images/$name.${format.toShortLowerCaseString()}'); + + // Get name and register to uuid to name + String _getNameAndRegister(String uuid, String name) { var finalName = AssetProcessingService.getImageName(name); _uuidToName[uuid] = finalName; - return ('images/' + finalName + '.${format.toShortLowerCaseString()}'); + return finalName; } /// Adds [uuids] to queue to be processed as an image. @@ -146,30 +168,11 @@ class FigmaAssetProcessor extends AssetProcessingService { response['images'] != null && response['images'].values.isNotEmpty) { Map images = response['images']; + images.addAll(globalImages); // Download the images - for (var entry in images.entries) { - if (entry?.value != null && (entry?.value?.isNotEmpty ?? false)) { - response = - await http.get(Uri.parse(entry.value)).then((imageRes) async { - // Check if the request was successful - if (imageRes == null || imageRes.statusCode != 200) { - log.error('Image ${entry.key} was not processed correctly'); - } - var imageName = _uuidToName[entry.key]; - var pngPath = p.join(MainInfo().pngPath, - '${imageName}.${imageFormat.toShortLowerCaseString()}'); - var file = File(pngPath.replaceAll(':', '_')) - ..createSync(recursive: true); - file.writeAsBytesSync(imageRes.bodyBytes); - - // TODO: Only print out when verbose flag is active - // log.debug('File written to following path ${file.path}'); - }).catchError((e) { - //MainInfo().sentry.captureException(exception: e); - log.error(e.toString()); - }); - } - } + + response = downloadImages(images, imageFormat); + return response; } else { throw Exception('Image did not generate'); @@ -177,6 +180,35 @@ class FigmaAssetProcessor extends AssetProcessingService { }); } + Future downloadImages( + Map images, IMAGE_FORMAT imageFormat) async { + // Download the images + var response; + images.forEach((var key, var value) async { + if (value != null && (value?.isNotEmpty ?? false)) { + response = await http.get(Uri.parse(value)).then((imageRes) async { + // Check if the request was successful + if (imageRes == null || imageRes.statusCode != 200) { + log.error('Image $key was not processed correctly'); + } + var imageName = _uuidToName[key]; + var pngPath = p.join(MainInfo().pngPath, + '${imageName}.${imageFormat.toShortLowerCaseString()}'); + var file = File(pngPath.replaceAll(':', '_')) + ..createSync(recursive: true); + file.writeAsBytesSync(imageRes.bodyBytes); + + // TODO: Only print out when verbose flag is active + // log.debug('File written to following path ${file.path}'); + }).catchError((e) { + //MainInfo().sentry.captureException(exception: e); + log.error(e.toString()); + }); + } + }); + return response; + } + @override Future processRootElements(Map uuids) async { _addImagesToQueue(uuids.keys.toList()); diff --git a/lib/src/input/figma/helper/figma_project.dart b/lib/src/input/figma/helper/figma_project.dart index a3080e25..aa5d768b 100644 --- a/lib/src/input/figma/helper/figma_project.dart +++ b/lib/src/input/figma/helper/figma_project.dart @@ -2,9 +2,11 @@ import 'package:get_it/get_it.dart'; import 'package:pbdl/src/input/figma/entities/layers/canvas.dart'; import 'package:pbdl/src/input/figma/entities/layers/component_set.dart'; import 'package:pbdl/src/input/figma/entities/layers/figma_frame.dart'; +import 'package:pbdl/src/input/figma/entities/style/fill/fill_type.dart'; import 'package:pbdl/src/input/figma/entities/style/global/global_style_property.dart'; import 'package:pbdl/src/input/figma/entities/style/global/global_style_holder.dart'; import 'package:pbdl/src/input/figma/helper/api_call_service.dart'; +import 'package:pbdl/src/input/figma/helper/figma_asset_processor.dart'; import 'package:pbdl/src/input/figma/helper/figma_page.dart'; import 'package:pbdl/src/pbdl/pbdl_project.dart'; import 'package:pbdl/src/util/main_info.dart'; @@ -54,6 +56,13 @@ class FigmaProject { var stylingNodes = await APICallService.getFileNodes(id, ids, MainInfo().figmaKey); + /// Get all images meta data, using imageReference or imageRef as key + /// for their download url + var metaData = await APICallService.makeAPICall( + 'https://api.figma.com/v1/files/${MainInfo().figmaProjectID}/images', + MainInfo().figmaKey); + var imagesByReference = metaData['meta']['images']; + for (var entry in jsonStyles.entries) { // ?: [ApiCallService.getFileNodes] could return a [Map] to make this faster. var figmaNode = stylingNodes.firstWhere( @@ -70,6 +79,13 @@ class FigmaProject { var globalStyle = GlobalStyleProperty.fromJson(formattedJson, figmaNode); if (globalStyle != null) { + // If the styleNode is a image fill type, replace imageRef for their download url + if (globalStyle.styleNode is ImageFillType) { + globalStyle.styleNode.imageRef = FigmaAssetProcessor() + .processImageWithURL(globalStyle.UUID, + imagesByReference[globalStyle.styleNode.imageRef], + name: globalStyle.name); + } globalStyles.add(globalStyle); } } diff --git a/lib/src/pbdl/global_styles/global_styles.dart b/lib/src/pbdl/global_styles/global_styles.dart index 77754d65..526114eb 100644 --- a/lib/src/pbdl/global_styles/global_styles.dart +++ b/lib/src/pbdl/global_styles/global_styles.dart @@ -2,3 +2,6 @@ export 'pbdl_global_color.dart'; export 'pbdl_global_style.dart'; export 'pbdl_global_styles.dart'; export 'pbdl_global_text_style.dart'; +export 'pbdl_global_image.dart'; +export 'pbdl_global_gradient.dart'; +export 'pbdl_global_effect.dart'; diff --git a/lib/src/pbdl/global_styles/pbdl_global_effect.dart b/lib/src/pbdl/global_styles/pbdl_global_effect.dart new file mode 100644 index 00000000..b75bab0d --- /dev/null +++ b/lib/src/pbdl/global_styles/pbdl_global_effect.dart @@ -0,0 +1,33 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:pbdl/pbdl.dart'; +import 'package:pbdl/src/pbdl/pbdl_boundary_box.dart'; +import 'package:pbdl/src/pbdl/pbdl_constraints.dart'; +import 'package:pbdl/src/pbdl/pbdl_effect.dart'; + +part 'pbdl_global_effect.g.dart'; + +@JsonSerializable(explicitToJson: true) + +/// Class that represents a global effect for the entire project. +/// +/// Essentially, it is a wrapper for [PBDLEffect] that adds a name and a description +class PBDLGlobalEffect extends PBDLGlobalStyle { + PBDLGlobalEffect( + String UUID, + String name, + this.effect, { + String description = '', + }) : super(UUID, name, description: description); + + @override + final String pbdlType = 'global_effect'; + + /// Contains the actual effect object. + PBDLEffect effect; + + factory PBDLGlobalEffect.fromJson(Map json) => + _$PBDLGlobalEffectFromJson(json); + + @override + Map toJson() => _$PBDLGlobalEffectToJson(this); +} diff --git a/lib/src/pbdl/global_styles/pbdl_global_effect.g.dart b/lib/src/pbdl/global_styles/pbdl_global_effect.g.dart new file mode 100644 index 00000000..30949297 --- /dev/null +++ b/lib/src/pbdl/global_styles/pbdl_global_effect.g.dart @@ -0,0 +1,63 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pbdl_global_effect.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PBDLGlobalEffect _$PBDLGlobalEffectFromJson(Map json) { + return PBDLGlobalEffect( + json['UUID'] as String, + json['name'] as String, + json['effect'] == null + ? null + : PBDLEffect.fromJson(json['effect'] as Map), + description: json['description'] as String ?? '', + ) + ..layoutMainAxisSizing = + PBDLNode.parentLayoutFromString(json['layoutMainAxisSizing'] as String) + ..layoutCrossAxisSizing = + PBDLNode.parentLayoutFromString(json['layoutCrossAxisSizing'] as String) + ..isVisible = json['isVisible'] as bool + ..boundaryRectangle = json['boundaryRectangle'] == null + ? null + : PBDLBoundaryBox.fromJson( + json['boundaryRectangle'] as Map) + ..style = json['style'] == null + ? null + : PBDLStyle.fromJson(json['style'] as Map) + ..prototypeNodeUUID = json['prototypeNodeUUID'] as String + ..child = json['child'] == null + ? null + : PBDLNode.fromJson(json['child'] as Map) + ..constraints = json['constraints'] == null + ? null + : PBDLConstraints.fromJson(json['constraints'] as Map) + ..pbdlType = json['pbdlType'] as String; +} + +Map _$PBDLGlobalEffectToJson(PBDLGlobalEffect instance) => + { + 'UUID': instance.UUID, + 'layoutMainAxisSizing': + _$ParentLayoutSizingEnumMap[instance.layoutMainAxisSizing], + 'layoutCrossAxisSizing': + _$ParentLayoutSizingEnumMap[instance.layoutCrossAxisSizing], + 'name': instance.name, + 'isVisible': instance.isVisible, + 'boundaryRectangle': instance.boundaryRectangle?.toJson(), + 'style': instance.style?.toJson(), + 'prototypeNodeUUID': instance.prototypeNodeUUID, + 'child': instance.child?.toJson(), + 'constraints': instance.constraints?.toJson(), + 'description': instance.description, + 'pbdlType': instance.pbdlType, + 'effect': instance.effect?.toJson(), + }; + +const _$ParentLayoutSizingEnumMap = { + ParentLayoutSizing.INHERIT: 'INHERIT', + ParentLayoutSizing.STRETCH: 'STRETCH', + ParentLayoutSizing.NONE: 'NONE', +}; diff --git a/lib/src/pbdl/global_styles/pbdl_global_gradient.dart b/lib/src/pbdl/global_styles/pbdl_global_gradient.dart new file mode 100644 index 00000000..d735200d --- /dev/null +++ b/lib/src/pbdl/global_styles/pbdl_global_gradient.dart @@ -0,0 +1,40 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:pbdl/pbdl.dart'; +import 'package:pbdl/src/pbdl/pbdl_boundary_box.dart'; +import 'package:pbdl/src/pbdl/pbdl_constraints.dart'; + +part 'pbdl_global_gradient.g.dart'; + +@JsonSerializable(explicitToJson: true) + +/// Class that represents a global color for the entire project. +/// +/// Essentially, it is a wrapper for [PBDLColor] that adds a name and a description +class PBDLGlobalGradient extends PBDLGlobalStyle { + PBDLGlobalGradient( + String UUID, + String name, + this.gradient, { + String description = '', + }) : super(UUID, name, description: description); + + @override + final String pbdlType = 'global_gradient'; + + /// Contains the actual gradient value. + PBDLFill gradient; + + /// If [this] is part of a theme [ColorScheme], + /// the value will be contained within this [String]. + /// + /// For example, if [this] is part of [ColorScheme.light], the value + /// of [colorScheme] would be `light` + @JsonKey(includeIfNull: false) + String colorScheme; + + factory PBDLGlobalGradient.fromJson(Map json) => + _$PBDLGlobalGradientFromJson(json); + + @override + Map toJson() => _$PBDLGlobalGradientToJson(this); +} diff --git a/lib/src/pbdl/global_styles/pbdl_global_gradient.g.dart b/lib/src/pbdl/global_styles/pbdl_global_gradient.g.dart new file mode 100644 index 00000000..dc4f15ad --- /dev/null +++ b/lib/src/pbdl/global_styles/pbdl_global_gradient.g.dart @@ -0,0 +1,74 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pbdl_global_gradient.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PBDLGlobalGradient _$PBDLGlobalGradientFromJson(Map json) { + return PBDLGlobalGradient( + json['UUID'] as String, + json['name'] as String, + json['gradient'] == null + ? null + : PBDLFill.fromJson(json['gradient'] as Map), + description: json['description'] as String ?? '', + ) + ..layoutMainAxisSizing = + PBDLNode.parentLayoutFromString(json['layoutMainAxisSizing'] as String) + ..layoutCrossAxisSizing = + PBDLNode.parentLayoutFromString(json['layoutCrossAxisSizing'] as String) + ..isVisible = json['isVisible'] as bool + ..boundaryRectangle = json['boundaryRectangle'] == null + ? null + : PBDLBoundaryBox.fromJson( + json['boundaryRectangle'] as Map) + ..style = json['style'] == null + ? null + : PBDLStyle.fromJson(json['style'] as Map) + ..prototypeNodeUUID = json['prototypeNodeUUID'] as String + ..child = json['child'] == null + ? null + : PBDLNode.fromJson(json['child'] as Map) + ..constraints = json['constraints'] == null + ? null + : PBDLConstraints.fromJson(json['constraints'] as Map) + ..pbdlType = json['pbdlType'] as String + ..colorScheme = json['colorScheme'] as String; +} + +Map _$PBDLGlobalGradientToJson(PBDLGlobalGradient instance) { + final val = { + 'UUID': instance.UUID, + 'layoutMainAxisSizing': + _$ParentLayoutSizingEnumMap[instance.layoutMainAxisSizing], + 'layoutCrossAxisSizing': + _$ParentLayoutSizingEnumMap[instance.layoutCrossAxisSizing], + 'name': instance.name, + 'isVisible': instance.isVisible, + 'boundaryRectangle': instance.boundaryRectangle?.toJson(), + 'style': instance.style?.toJson(), + 'prototypeNodeUUID': instance.prototypeNodeUUID, + 'child': instance.child?.toJson(), + 'constraints': instance.constraints?.toJson(), + 'description': instance.description, + 'pbdlType': instance.pbdlType, + 'gradient': instance.gradient?.toJson(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('colorScheme', instance.colorScheme); + return val; +} + +const _$ParentLayoutSizingEnumMap = { + ParentLayoutSizing.INHERIT: 'INHERIT', + ParentLayoutSizing.STRETCH: 'STRETCH', + ParentLayoutSizing.NONE: 'NONE', +}; diff --git a/lib/src/pbdl/global_styles/pbdl_global_image.dart b/lib/src/pbdl/global_styles/pbdl_global_image.dart new file mode 100644 index 00000000..d499ae71 --- /dev/null +++ b/lib/src/pbdl/global_styles/pbdl_global_image.dart @@ -0,0 +1,40 @@ +import 'package:json_annotation/json_annotation.dart'; +import 'package:pbdl/pbdl.dart'; +import 'package:pbdl/src/pbdl/pbdl_boundary_box.dart'; +import 'package:pbdl/src/pbdl/pbdl_constraints.dart'; + +part 'pbdl_global_image.g.dart'; + +@JsonSerializable(explicitToJson: true) + +/// Class that represents a global color for the entire project. +/// +/// Essentially, it is a wrapper for [PBDLColor] that adds a name and a description +class PBDLGlobalImage extends PBDLGlobalStyle { + PBDLGlobalImage( + String UUID, + String name, + this.image, { + String description = '', + }) : super(UUID, name, description: description); + + @override + final String pbdlType = 'global_image'; + + /// Contains the actual image value. + PBDLFill image; + + /// If [this] is part of a theme [ColorScheme], + /// the value will be contained within this [String]. + /// + /// For example, if [this] is part of [ColorScheme.light], the value + /// of [colorScheme] would be `light` + @JsonKey(includeIfNull: false) + String colorScheme; + + factory PBDLGlobalImage.fromJson(Map json) => + _$PBDLGlobalImageFromJson(json); + + @override + Map toJson() => _$PBDLGlobalImageToJson(this); +} diff --git a/lib/src/pbdl/global_styles/pbdl_global_image.g.dart b/lib/src/pbdl/global_styles/pbdl_global_image.g.dart new file mode 100644 index 00000000..b6ac4c0a --- /dev/null +++ b/lib/src/pbdl/global_styles/pbdl_global_image.g.dart @@ -0,0 +1,74 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'pbdl_global_image.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +PBDLGlobalImage _$PBDLGlobalImageFromJson(Map json) { + return PBDLGlobalImage( + json['UUID'] as String, + json['name'] as String, + json['image'] == null + ? null + : PBDLFill.fromJson(json['image'] as Map), + description: json['description'] as String ?? '', + ) + ..layoutMainAxisSizing = + PBDLNode.parentLayoutFromString(json['layoutMainAxisSizing'] as String) + ..layoutCrossAxisSizing = + PBDLNode.parentLayoutFromString(json['layoutCrossAxisSizing'] as String) + ..isVisible = json['isVisible'] as bool + ..boundaryRectangle = json['boundaryRectangle'] == null + ? null + : PBDLBoundaryBox.fromJson( + json['boundaryRectangle'] as Map) + ..style = json['style'] == null + ? null + : PBDLStyle.fromJson(json['style'] as Map) + ..prototypeNodeUUID = json['prototypeNodeUUID'] as String + ..child = json['child'] == null + ? null + : PBDLNode.fromJson(json['child'] as Map) + ..constraints = json['constraints'] == null + ? null + : PBDLConstraints.fromJson(json['constraints'] as Map) + ..pbdlType = json['pbdlType'] as String + ..colorScheme = json['colorScheme'] as String; +} + +Map _$PBDLGlobalImageToJson(PBDLGlobalImage instance) { + final val = { + 'UUID': instance.UUID, + 'layoutMainAxisSizing': + _$ParentLayoutSizingEnumMap[instance.layoutMainAxisSizing], + 'layoutCrossAxisSizing': + _$ParentLayoutSizingEnumMap[instance.layoutCrossAxisSizing], + 'name': instance.name, + 'isVisible': instance.isVisible, + 'boundaryRectangle': instance.boundaryRectangle?.toJson(), + 'style': instance.style?.toJson(), + 'prototypeNodeUUID': instance.prototypeNodeUUID, + 'child': instance.child?.toJson(), + 'constraints': instance.constraints?.toJson(), + 'description': instance.description, + 'pbdlType': instance.pbdlType, + 'image': instance.image?.toJson(), + }; + + void writeNotNull(String key, dynamic value) { + if (value != null) { + val[key] = value; + } + } + + writeNotNull('colorScheme', instance.colorScheme); + return val; +} + +const _$ParentLayoutSizingEnumMap = { + ParentLayoutSizing.INHERIT: 'INHERIT', + ParentLayoutSizing.STRETCH: 'STRETCH', + ParentLayoutSizing.NONE: 'NONE', +}; diff --git a/lib/src/pbdl/global_styles/pbdl_global_styles.dart b/lib/src/pbdl/global_styles/pbdl_global_styles.dart index 6927c678..dd2a6f30 100644 --- a/lib/src/pbdl/global_styles/pbdl_global_styles.dart +++ b/lib/src/pbdl/global_styles/pbdl_global_styles.dart @@ -16,6 +16,7 @@ class PBDLGlobalStyles extends PBDLNode { this.themeColors, this.themeTextStyles, this.designSystem = 'material', + this.effects, }) : super('', '', false, null, null, null); @override @@ -26,7 +27,7 @@ class PBDLGlobalStyles extends PBDLNode { final String designSystem; @JsonKey(defaultValue: []) - final List colors; + final List colors; @JsonKey(defaultValue: []) final List textStyles; @@ -39,6 +40,10 @@ class PBDLGlobalStyles extends PBDLNode { @JsonKey(defaultValue: []) final List themeTextStyles; + /// List of [PBDLGlobalEffect] + @JsonKey(defaultValue: []) + final List effects; + factory PBDLGlobalStyles.fromJson(Map json) => _$PBDLGlobalStylesFromJson(json);