Skip to content

Commit

Permalink
refactor: code prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
wssgcg1213 committed Dec 16, 2021
1 parent 2fe75c8 commit e6c3356
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
20 changes: 5 additions & 15 deletions kraken/lib/src/css/render_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -405,21 +405,11 @@ class CSSRenderStyle
@override
dynamic resolveValue(String propertyName, String propertyValue) {
RenderStyle renderStyle = this;
dynamic value;

// font-size: var(--x);
// font-size: var(--x, 28px);
if (CSSFunction.isFunction(propertyValue, functionName: 'var')) {
List<CSSFunctionalNotation> fns = CSSFunction.parseFunction(propertyValue);
if (fns.first.args.isNotEmpty) {
if (fns.first.args.length > 1) {
// Has default value for CSS Variable.
return CSSVariable(fns.first.args.first, renderStyle,
defaultValue: resolveValue(propertyName, fns.first.args.last));
} else {
return CSSVariable(fns.first.args.first, renderStyle);
}
}

// Process CSSVariable.
dynamic value = CSSVariable.tryParse(renderStyle, propertyName, propertyValue);
if (value != null) {
return value;
}

switch (propertyName) {
Expand Down
18 changes: 18 additions & 0 deletions kraken/lib/src/css/values/variable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ class CSSVariable {
return value.length > 2 && value.codeUnitAt(0) == _HYPHEN_CODE && value.codeUnitAt(1) == _HYPHEN_CODE;
}

// Try to parse CSSVariable.
static CSSVariable? tryParse(RenderStyle renderStyle, String propertyName, String propertyValue) {
// font-size: var(--x);
// font-size: var(--x, 28px);
if (CSSFunction.isFunction(propertyValue, functionName: VAR)) {
List<CSSFunctionalNotation> fns = CSSFunction.parseFunction(propertyValue);
if (fns.first.args.isNotEmpty) {
if (fns.first.args.length > 1) {
// Has default value for CSS Variable.
return CSSVariable(fns.first.args.first, renderStyle,
defaultValue: renderStyle.resolveValue(propertyName, fns.first.args.last));
} else {
return CSSVariable(fns.first.args.first, renderStyle);
}
}
}
}

final String identifier;
final dynamic defaultValue;
final RenderStyle _renderStyle;
Expand Down

0 comments on commit e6c3356

Please sign in to comment.