Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/pb 304 support fo global effects #95

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -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<Point<num>> gradientHandlePositions;

@override
List<GradientStop> gradientStops;

@override
num opacity;

@override
String type;

@override
bool visible;

@override
FigmaFill createFigmaFill(Map<String, dynamic> json) {
// TODO: implement createFigmaFill
throw UnimplementedError();
}

@override
PBDLFill interpretFill() {
// TODO: implement interpretFill
throw UnimplementedError();
}

@override
Map<String, dynamic> toJson() {
// TODO: implement toJson
throw UnimplementedError();
}

@override
String addStyle(StyleAdditionNode style) {
// TODO: implement addStyle
throw UnimplementedError();
}
}
59 changes: 59 additions & 0 deletions lib/src/input/figma/entities/style/global/effect_global.dart
Original file line number Diff line number Diff line change
@@ -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<PBDLNode> interpretNode() async {
if (styleNode == null) {
return null;
}
return PBDLGlobalEffect(
UUID,
name,
(styleNode as FigmaEffect).interpretEffect(),
description: description,
);
}

Map<String, dynamic> toJson() => _$EffectGlobalToJson(this);

factory EffectGlobal.fromJson(
Map<String, dynamic> 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;
}
}
28 changes: 28 additions & 0 deletions lib/src/input/figma/entities/style/global/effect_global.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 43 additions & 10 deletions lib/src/input/figma/entities/style/global/fill_style_global.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -15,7 +19,7 @@ class FillStyleGlobal extends GlobalStyleProperty {
String styleType, {
String name,
String description,
FigmaColor styleNode,
var styleNode,
}) : super(
UUID,
styleType,
Expand All @@ -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<String, dynamic> toJson() => _$FillStyleGlobalToJson(this);
Expand All @@ -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;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 13 additions & 10 deletions lib/src/input/figma/entities/style/global/global_style_holder.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -19,11 +17,6 @@ class GlobalStyleHolder extends FigmaBaseNode {
/// Registered [GlobalStyleProperty]s.
final _properties = <String, GlobalStyleProperty>{};

final registeredPropertyNames = <String>[
'fill',
'text',
];

@JsonKey(ignore: true)
final DesignSystemThemeData designSystemThemeData;

Expand All @@ -42,6 +35,9 @@ class GlobalStyleHolder extends FigmaBaseNode {
Iterable<TextStyleGlobal> get textStyles =>
_properties.values.whereType<TextStyleGlobal>();

Iterable<EffectGlobal> get effects =>
_properties.values.whereType<EffectGlobal>();

/// Returns the [GlobalStyleProperty] with the given [UUID] and specified type [T].
///
/// If the [UUID] is not found, returns null.
Expand All @@ -57,9 +53,10 @@ class GlobalStyleHolder extends FigmaBaseNode {
Future<PBDLNode> interpretNode() async {
/// Interpret fills to [PBDLGlobalFillProperty]
var themeColors = <PBDLGlobalColor>[];
var globalColors = <PBDLGlobalColor>[];
var globalColors = <PBDLGlobalStyle>[];
var themeTextStyles = <PBDLGlobalTextStyle>[];
var globalTextStyles = <PBDLGlobalTextStyle>[];
var globalEffects = <PBDLGlobalEffect>[];

for (var fill in fills) {
final interpretedFill = await fill.interpretNode();
Expand Down Expand Up @@ -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,
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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,
Expand All @@ -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;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading