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

[WIP]: feat: support initial CSS value. #421

Merged
merged 3 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions webf/lib/src/css/computed_style_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ class ComputedCSSStyleDeclaration extends CSSStyleDeclaration {
final afterValue = afterSlashSeparator.map((e) => _valueForPropertyInStyle(e)).join(' ');
return backgroundColor + ' ' + beforeValue + ' / ' + afterValue;
}

@override
String toString() {
return 'ComputedCSSStyleDeclaration($_element)';
}
}

List<T>? _compressSlidesValue<T>(List<T> values) {
Expand Down
4 changes: 4 additions & 0 deletions webf/lib/src/css/render_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ class CSSRenderStyle extends RenderStyle
dynamic resolveValue(String propertyName, String propertyValue, { String? baseHref }) {
RenderStyle renderStyle = this;

if (propertyValue == INITIAL) {
propertyValue = CSSInitialValues[propertyName] ?? propertyValue;
}

// Process CSSVariable.
dynamic value = CSSVariable.tryParse(renderStyle, propertyValue);
if (value != null) {
Expand Down
2 changes: 2 additions & 0 deletions webf/lib/src/css/style_declaration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@ class CSSStyleDeclaration extends BindingObject {
// Eg. var(--x), calc(1 + 1)
if (CSSFunction.isFunction(normalizedValue)) return true;

if (CSSLength.isInitial(normalizedValue)) return true;

// Validate value.
switch (propertyName) {
case WIDTH:
Expand Down
4 changes: 4 additions & 0 deletions webf/lib/src/css/values/length.dart
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,10 @@ class CSSLength {
return value == AUTO;
}

static bool isInitial(String? value) {
return value == INITIAL;
}

static bool isLength(String? value) {
return value != null && (value == ZERO || _lengthRegExp.hasMatch(value));
}
Expand Down
6 changes: 5 additions & 1 deletion webf/lib/src/css/values/variable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ class CSSVariable {

// Get the lazy calculated CSS resolved value.
dynamic computedValue(String propertyName) {
dynamic value = _renderStyle.getCSSVariable(identifier, propertyName) ?? defaultValue;
dynamic value = _renderStyle.getCSSVariable(identifier, propertyName);
if (value == null || value == INITIAL) {
value = defaultValue;
}

if (value == null) {
return null;
}
Expand Down
4 changes: 3 additions & 1 deletion webf/lib/src/devtools/modules/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ class InspectorNode extends JSONEncodable {
'childNodeCount': childNodeCount,
'attributes': attributes,
if (childNodeCount > 0)
'children': referencedNode.childNodes.map((Node node) => InspectorNode(node).toJson()).toList(),
'children': referencedNode.childNodes.where((node) {
return node is Element || (node is TextNode && node.data.isNotEmpty);
}).map((Node node) => InspectorNode(node).toJson()).toList(),
};
}
}
Expand Down
Loading