diff --git a/pkgs/csslib/CHANGELOG.md b/pkgs/csslib/CHANGELOG.md index e8ae2bf557..49998e90f8 100644 --- a/pkgs/csslib/CHANGELOG.md +++ b/pkgs/csslib/CHANGELOG.md @@ -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 diff --git a/pkgs/csslib/lib/src/property.dart b/pkgs/csslib/lib/src/property.dart index 421046c87b..bd8371ab9d 100644 --- a/pkgs/csslib/lib/src/property.dart +++ b/pkgs/csslib/lib/src/property.dart @@ -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, diff --git a/pkgs/csslib/lib/src/tree.dart b/pkgs/csslib/lib/src/tree.dart index 3c143f7c68..104de22ce1 100644 --- a/pkgs/csslib/lib/src/tree.dart +++ b/pkgs/csslib/lib/src/tree.dart @@ -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); @@ -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); diff --git a/pkgs/csslib/test/dart_style_clone_test.dart b/pkgs/csslib/test/dart_style_clone_test.dart index f6c50816ef..5abaa7ea46 100644 --- a/pkgs/csslib/test/dart_style_clone_test.dart +++ b/pkgs/csslib/test/dart_style_clone_test.dart @@ -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); + }); } diff --git a/pkgs/csslib/test/font_css_serialization_test.dart b/pkgs/csslib/test/font_css_serialization_test.dart index c5667c6ab6..516b2f66d2 100644 --- a/pkgs/csslib/test/font_css_serialization_test.dart +++ b/pkgs/csslib/test/font_css_serialization_test.dart @@ -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', + ); + }); } diff --git a/pkgs/html/lib/dom.dart b/pkgs/html/lib/dom.dart index a600600ac2..38d3468151 100644 --- a/pkgs/html/lib/dom.dart +++ b/pkgs/html/lib/dom.dart @@ -1200,19 +1200,14 @@ class FilteredElementList extends IterableBase } @override - bool get isEmpty => !_childNodes.any((node) => node is Element); + bool get isEmpty => _childNodes.whereType().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().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) { diff --git a/pkgs/html/lib/src/html_input_stream.dart b/pkgs/html/lib/src/html_input_stream.dart index 6cb34b1de8..b452ab263f 100644 --- a/pkgs/html/lib/src/html_input_stream.dart +++ b/pkgs/html/lib/src/html_input_stream.dart @@ -134,10 +134,13 @@ class HtmlInputStream { c = Charcode.lineFeed; } - if (c != rawChars[i] && identical(chars, rawChars)) { - chars = List.of(rawChars, growable: true); - } - if (!identical(chars, rawChars)) { + if (c != rawChars[i]) { + if (identical(chars, rawChars)) { + chars = List.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; } }