Skip to content
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
11 changes: 2 additions & 9 deletions pkgs/csslib/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,18 @@

- Correct `Font.hashCode` for partial/empty font styles and distribute hashes
across font families and other properties, avoiding hash-table collisions.
- Preserve fixed/relative line heights and independent font-family lists
when scaling fonts.
- `Font.scale` keeps the line height (scaling pixel heights and keeping
relative ratios), copies the font-family list, and no longer throws when
the font size is unspecified.
- Serialize partial font styles without bogus `ul` family names or trailing
spaces, and join font family lists directly.
- Serialize partial font styles without bogus family names or trailing
spaces; preserve explicit line heights without font weight.
- Serialize partial font styles without bogus family names, `nullpx` sizes or
trailing spaces; preserve explicit line heights without font weight and
keep the `px` unit on pixel line heights (a unitless value is a multiplier).
keep the `px` unit on pixel line heights (a unitless value is a multiplier);
include the font style and variant.
- Deep-clone selector groups, selector sequences, identifiers, functional
pseudo-selector arguments, and legacy pseudo-element flags instead of
sharing mutable AST nodes between the original and its clone.
- Preserve nested group terms, IE7-prefixed declaration flags, and variable
usage state when cloning CSS expression/declaration nodes.
- Preserve Dart style priorities when cloning and detach mutable font-family
lists from cloned font expressions.
- Deep-clone declaration style payloads and preserve Dart style priorities;
detach mutable font-family lists in cloned font expressions.
- Fix `Rgba.fromArgbValue`, `Rgba.argbValue` and `Hsla.color`, preserve alpha
Expand Down
2 changes: 2 additions & 0 deletions pkgs/csslib/lib/src/property.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,8 @@ class Font implements _StyleProperty {
? '${size}px'
: '${size}px/${height.height}${height.inPixels ? 'px' : ''}';
return [
if (style != null) style,
if (variant != null) variant,
if (weight != null) '$weight',
if (sizePart != null) sizePart,
if (families.isNotEmpty) families,
Expand Down
28 changes: 6 additions & 22 deletions pkgs/csslib/lib/src/tree.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1694,18 +1694,10 @@ class MarginExpression extends BoxExpression {
MarginExpression x, MarginExpression y, SourceSpan? span)
: super(x._styleType, span, BoxEdge.merge(x.box, y.box));

// BoxEdge is immutable, so the clone can share it (including a null box).
@override
MarginExpression clone() {
final edge = box!;
final result = MarginExpression(
span,
top: edge.top,
right: edge.right,
bottom: edge.bottom,
left: edge.left,
);
return result..priority = priority;
}
MarginExpression clone() =>
MarginExpression.boxEdge(span, box)..priority = priority;

@override
dynamic visit(VisitorBase visitor) => visitor.visitMarginExpression(this);
Expand Down Expand Up @@ -1836,18 +1828,10 @@ class PaddingExpression extends BoxExpression {
: super(DartStyleExpression.paddingStyle, span,
BoxEdge.merge(x.box, y.box));

// BoxEdge is immutable, so the clone can share it (including a null box).
@override
PaddingExpression clone() {
final edge = box!;
final result = PaddingExpression(
span,
top: edge.top,
right: edge.right,
bottom: edge.bottom,
left: edge.left,
);
return result..priority = priority;
}
PaddingExpression clone() =>
PaddingExpression.boxEdge(span, box)..priority = priority;

@override
dynamic visit(VisitorBase visitor) => visitor.visitPaddingExpression(this);
Expand Down
10 changes: 10 additions & 0 deletions pkgs/csslib/test/dart_style_clone_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,14 @@ void main() {
expect(style.priority, 42);
}
});

test('margin and padding clones keep a missing box edge', () {
final span = SourceFile.fromString('margin').span(0, 6);
final margin = MarginExpression.boxEdge(span, null)..priority = 3;
final padding = PaddingExpression.boxEdge(span, null)..priority = 4;
expect(margin.clone().box, isNull);
expect(margin.clone().priority, 3);
expect(padding.clone().box, isNull);
expect(padding.clone().priority, 4);
});
}
13 changes: 13 additions & 0 deletions pkgs/csslib/test/font_css_serialization_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,17 @@ void main() {
'',
);
});

test('font CSS includes style and variant in shorthand order', () {
expect(
const Font(
size: 16,
weight: FontWeight.bold,
style: FontStyle.italic,
variant: FontVariant.smallCaps,
family: ['Alef'],
).cssExpression,
'italic small-caps 700 16px Alef',
);
});
}
11 changes: 3 additions & 8 deletions pkgs/html/lib/dom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1200,19 +1200,14 @@ class FilteredElementList extends IterableBase<Element>
}

@override
bool get isEmpty => !_childNodes.any((node) => node is Element);
bool get isEmpty => _childNodes.whereType<Element>().isEmpty;

@override
int get length {
var count = 0;
for (final node in _childNodes) {
if (node is Element) count++;
}
return count;
}
int get length => _childNodes.whereType<Element>().length;

@override
Element operator [](int index) {
if (index < 0) throw RangeError.index(index, this);
var position = 0;
for (final node in _childNodes) {
if (node is Element) {
Expand Down
11 changes: 7 additions & 4 deletions pkgs/html/lib/src/html_input_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,13 @@ class HtmlInputStream {
c = Charcode.lineFeed;
}

if (c != rawChars[i] && identical(chars, rawChars)) {
chars = List<int>.of(rawChars, growable: true);
}
if (!identical(chars, rawChars)) {
if (c != rawChars[i]) {
if (identical(chars, rawChars)) {
chars = List<int>.of(rawChars, growable: true);
}
chars[i - deletedChars] = c;
} else if (deletedChars > 0) {
// The copy already holds unchanged code units at their own index.
chars[i - deletedChars] = c;
}
}
Expand Down
Loading