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

Release 1.0.0 #157

Open
wants to merge 59 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
2a2f5da
Empty string behaves like null
FlorianRappl Feb 16, 2023
8ecae08
Update ColorParser.cs
jogibear9988 Apr 20, 2023
49b4877
Merge pull request #141 from jogibear9988/patch-1
FlorianRappl Apr 20, 2023
6ab7166
WIP
FlorianRappl Jun 6, 2023
c8321b8
Working on new media list parser
FlorianRappl Jun 10, 2023
3b89d01
Fixed serialization due to broken longhands #129
FlorianRappl Jun 14, 2023
b9aef4c
Fixed appending eof character #123
FlorianRappl Jun 14, 2023
6905fa5
Fixed missing semicolon separator #135
FlorianRappl Jun 14, 2023
1f3d718
Fixed keyframe stop truncation #128
FlorianRappl Jun 14, 2023
12f61a1
Fixed grid and grid-gap ordering #137
FlorianRappl Jun 14, 2023
ad7aff4
Improved CSS minification of grid #89
FlorianRappl Jun 14, 2023
78740fe
Added more tests for background-size
FlorianRappl Jun 14, 2023
6d52e79
Updated media parsing #133
FlorianRappl Jun 15, 2023
10845f2
Added test to verify fix for #133
FlorianRappl Jun 15, 2023
314805d
Added test to validate #140
FlorianRappl Jun 15, 2023
9fe8a86
Added 8-digit hex color #132
FlorianRappl Jun 15, 2023
50d8e9d
WIP #136
FlorianRappl Jun 15, 2023
15cb522
Validate that #126 can be done
FlorianRappl Jun 16, 2023
c9bc34e
Added rgb function syntax L4 #131
FlorianRappl Jun 18, 2023
4ceb46c
Prepare for more color functions
FlorianRappl Jun 18, 2023
649beb7
Added implementation of new color functions #131
FlorianRappl Jun 18, 2023
240cee3
Update Directory.Build.props
FlorianRappl Dec 15, 2023
7a96a55
Added support for recent list-type
FlorianRappl Jan 16, 2024
dba9069
Fixed text align behavior
FlorianRappl Jan 16, 2024
6ab4a63
Improved rule prios
FlorianRappl Jan 16, 2024
0c3aa78
Fix for GetInnerText #155
FlorianRappl Jan 16, 2024
c39af8a
Working on CSS nesting
FlorianRappl Jan 17, 2024
bf4db74
Allow disabling of nesting
FlorianRappl Jan 17, 2024
06b15e3
Updated nested implementation #148
FlorianRappl Jan 17, 2024
e97935a
Added margin and padding decls
FlorianRappl Jan 17, 2024
a5bcabf
Improved render tree
FlorianRappl Jan 17, 2024
baca67a
Improved computation #136
FlorianRappl Jan 17, 2024
1c9efd4
Prepared computation model
FlorianRappl Jan 18, 2024
8295892
Implemented CSS variable resolution #62
FlorianRappl Jan 18, 2024
9abdd1b
Added new metric values
FlorianRappl Jan 18, 2024
ed2b542
Activated disabled test
FlorianRappl Jan 18, 2024
64df5cf
Refactored naming to be consistent
FlorianRappl Jan 18, 2024
e8dab26
Refactored value model names
FlorianRappl Jan 18, 2024
2a44071
Extended model for css integer
FlorianRappl Jan 19, 2024
d856b31
Integrate percentage
FlorianRappl Jan 19, 2024
8205cf8
Added extra API method for computing style
FlorianRappl Jan 19, 2024
caab82a
Added test for new API
FlorianRappl Jan 19, 2024
c51cd43
Use latest version of AngleSharp
FlorianRappl Jan 19, 2024
973d83c
Prepare docs update
FlorianRappl Jan 19, 2024
b755de0
Updated CI/CD
FlorianRappl Jan 19, 2024
adba277
Updated CI/CD
FlorianRappl Feb 25, 2024
0652a66
Re-added dropped character
FlorianRappl Feb 25, 2024
333885b
Fix NullReferenceException in ChangeDeclarations
meziantou Feb 26, 2024
b36924d
review
meziantou Feb 26, 2024
46635ab
Fix nullable reference exception in CssOriginValue
meziantou Feb 26, 2024
c1c83ee
Merge pull request #160 from meziantou/fix-nre
FlorianRappl Feb 26, 2024
e68db8f
Update CssOriginValue.cs
meziantou Feb 26, 2024
102cc32
Merge pull request #162 from meziantou/nre-CssOriginValue
FlorianRappl Feb 26, 2024
dbf8aca
Uniformize CssValue.Equals implementation
meziantou Feb 26, 2024
151244d
Fix NullReferenceException in CssShadowValue
meziantou Feb 26, 2024
1d40f1c
Merge pull request #163 from meziantou/uniformize-cssvalue-comparison
FlorianRappl Feb 26, 2024
ff33ad7
Merge pull request #164 from meziantou/fix-nre-CssShadowValue
FlorianRappl Feb 26, 2024
4c9f16a
Get declarations
SebastianStehle Sep 19, 2024
459b48c
Merge pull request #176 from SebastianStehle/devel
FlorianRappl Sep 20, 2024
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
Prev Previous commit
Next Next commit
Improved computation #136
FlorianRappl committed Jan 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit baca67ae9fa2cd37bb41440f6a71186210fc91dd
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ Released on tbd.
- Fixed style empty if `text-align` is `start` (#151)
- Fixed computation of priority in CSS rules using multi selector
- Fixed `GetInnerText` multi-line / text node behavior (#155) @Seyden
- Fixed computation of relative (`em`) values to absolute (`px`) for `Length` (#136)
- Added further compactification of CSS tuples (#89, #93)
- Added support for CSS nesting in style rules (#148)
- Added support for 8-digit hex color codes (#132)
10 changes: 10 additions & 0 deletions src/AngleSharp.Css.Tests/Extensions/AnalysisWindow.cs
Original file line number Diff line number Diff line change
@@ -298,5 +298,15 @@ public async Task PriorityInMultiSelectorIsEvaluatedPerMatch()
var style = sc.ComputeCascadedStyle(document.QuerySelector("h3"));
Assert.AreEqual("rgba(0, 0, 255, 1)", style.GetColor());
}

[Test]
public async Task ComputesAbsoluteValuesFromRelative_Issue136()
{
var sheet = ParseStyleSheet(@"p { font-size: 1.5em }");
var document = await sheet.Context.OpenAsync(res => res.Content(@"<p>This is <span>only</span> a test.</p>"));
var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
var style = sc.ComputeDeclarations(document.QuerySelector("span"));
Assert.AreEqual("24px", style.GetFontSize());
}
}
}
7 changes: 7 additions & 0 deletions src/AngleSharp.Css/Dom/ICssProperty.cs
Original file line number Diff line number Diff line change
@@ -57,5 +57,12 @@ public interface ICssProperty : IStyleFormattable
/// Gets if the property is a shorthand.
/// </summary>
Boolean IsShorthand { get; }

/// <summary>
/// Creates a computed version of the property.
/// </summary>
/// <param name="device">The device to compute for.</param>
/// <returns>The computed version of the property if uncomputed, otherwise the same.</returns>
ICssProperty Compute(IRenderDevice device);
}
}
17 changes: 17 additions & 0 deletions src/AngleSharp.Css/Dom/Internal/CssProperty.cs
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@ namespace AngleSharp.Css.Dom
{
using AngleSharp.Css;
using AngleSharp.Css.Converters;
using AngleSharp.Css.Values;
using AngleSharp.Text;
using System;
using System.IO;
@@ -86,6 +87,22 @@ public Boolean IsImportant

#endregion

#region Methods

public ICssProperty Compute(IRenderDevice device)
{
if (_value is Length length && length.Type != Length.Unit.Px)
{
var px = length.ToPixel(device);
var value = new Length(px, Length.Unit.Px);
return new CssProperty(_name, _converter, _flags, value, _important);
}

return this;
}

#endregion

#region String Representation

public void ToCss(TextWriter writer, IStyleFormatter formatter) => writer.Write(formatter.Declaration(CssUtilities.Escape(Name), Value, IsImportant));
15 changes: 15 additions & 0 deletions src/AngleSharp.Css/Dom/Internal/CssStyleDeclaration.cs
Original file line number Diff line number Diff line change
@@ -32,6 +32,11 @@ sealed class CssStyleDeclaration : ICssStyleDeclaration

#region ctor

public CssStyleDeclaration()
: this(default(IBrowsingContext))
{
}

public CssStyleDeclaration(IBrowsingContext context)
{
_declarations = new List<ICssProperty>();
@@ -301,6 +306,16 @@ public void SetProperty(String propertyName, String propertyValue, String priori
}
}

public void AddProperty(ICssProperty declaration)
{
_declarations.Add(declaration);
}

public void RemoveProperty(ICssProperty declaration)
{
_declarations.Remove(declaration);
}

#endregion

#region Internal Methods
15 changes: 6 additions & 9 deletions src/AngleSharp.Css/Extensions/CssOmExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
namespace AngleSharp.Css.Dom
{
using AngleSharp.Css.Parser;
using AngleSharp.Css.Values;
using AngleSharp.Text;
using System;
using System.Linq;
@@ -74,16 +73,14 @@ public static ICssValue GetValueOf(this ICssStyleRule rule, String propertyName)
/// <returns>A new style declaration with the existing or computed values.</returns>
public static ICssStyleDeclaration Compute(this ICssStyleDeclaration style, IRenderDevice device)
{
//var prop = style.GetProperty("font-size");
var computedStyle = new CssStyleDeclaration();

//if (prop is not null && prop.RawValue is Length length)
//{
// var px = length.ToPixel(device, RenderMode.Horizontal);
// var prio = prop.IsImportant ? CssKeywords.Important : null;
// style.SetProperty(prop.Name, $"{px}px", prio);
//}
foreach (var property in style)
{
computedStyle.AddProperty(property.Compute(device));
}

return style;
return computedStyle;
}
}
}
16 changes: 8 additions & 8 deletions src/AngleSharp.Css/Extensions/StyleCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -36,14 +36,14 @@ public static IStyleCollection GetStyleCollection(this IWindow window)
/// Computes the declarations for the given element in the context of
/// the specified styling rules.
/// </summary>
/// <param name="rules">The styles to use.</param>
/// <param name="styles">The styles to use.</param>
/// <param name="element">The element that is questioned.</param>
/// <param name="pseudoSelector">The optional pseudo selector to use.</param>
/// <returns>The style declaration containing all the declarations.</returns>
public static ICssStyleDeclaration ComputeDeclarations(this IEnumerable<ICssStyleRule> rules, IElement element, String pseudoSelector = null)
public static ICssStyleDeclaration ComputeDeclarations(this IStyleCollection styles, IElement element, String pseudoSelector = null)
{
var ctx = element.Owner?.Context;
var device = ctx?.GetService<IRenderDevice>();
var device = styles.Device;
var computedStyle = new CssStyleDeclaration(ctx);
var nodes = element.GetAncestors().OfType<IElement>();

@@ -57,11 +57,11 @@ public static ICssStyleDeclaration ComputeDeclarations(this IEnumerable<ICssStyl
}
}

computedStyle.SetDeclarations(rules.ComputeCascadedStyle(element));
computedStyle.SetDeclarations(styles.ComputeCascadedStyle(element));

foreach (var node in nodes)
{
computedStyle.UpdateDeclarations(rules.ComputeCascadedStyle(node));
computedStyle.UpdateDeclarations(styles.ComputeCascadedStyle(node));
}

if (device is not null)
@@ -77,14 +77,14 @@ public static ICssStyleDeclaration ComputeDeclarations(this IEnumerable<ICssStyl
/// Two rules with the same specificity are ordered according to their appearance. The more
/// recent declaration wins. Inheritance is not taken into account.
/// </summary>
/// <param name="styleCollection">The style rules to apply.</param>
/// <param name="rules">The style rules to apply.</param>
/// <param name="element">The element to compute the cascade for.</param>
/// <param name="parent">The potential parent for the cascade.</param>
/// <returns>Returns the cascaded read-only style declaration.</returns>
public static ICssStyleDeclaration ComputeCascadedStyle(this IEnumerable<ICssStyleRule> styleCollection, IElement element, ICssStyleDeclaration parent = null)
public static ICssStyleDeclaration ComputeCascadedStyle(this IStyleCollection styles, IElement element, ICssStyleDeclaration parent = null)
{
var computedStyle = new CssStyleDeclaration(element.Owner?.Context);
var rules = styleCollection.SortBySpecificity(element);
var rules = styles.SortBySpecificity(element);

foreach (var rule in rules)
{
2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Angle.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
/// Represents an angle object.
/// https://developer.mozilla.org/en-US/docs/Web/CSS/angle
/// </summary>
public struct Angle : IEquatable<Angle>, IComparable<Angle>, ICssPrimitiveValue
public readonly struct Angle : IEquatable<Angle>, IComparable<Angle>, ICssPrimitiveValue
{
#region Basic angles

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Constant.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a selected CSS enum value.
/// </summary>
public struct Constant<T> : ICssPrimitiveValue, IEquatable<Constant<T>>
public readonly struct Constant<T> : ICssPrimitiveValue, IEquatable<Constant<T>>
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/CounterDefinition.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a CSS counter.
/// </summary>
public struct CounterDefinition : ICssPrimitiveValue, IEquatable<CounterDefinition>
public readonly struct CounterDefinition : ICssPrimitiveValue, IEquatable<CounterDefinition>
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/CounterValue.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Sets a CSS counter.
/// </summary>
public struct CounterValue : ICssPrimitiveValue, IEquatable<CounterValue>
public readonly struct CounterValue : ICssPrimitiveValue, IEquatable<CounterValue>
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Fraction.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a fractional value.
/// </summary>
public struct Fraction : IEquatable<Fraction>, IComparable<Fraction>, ICssPrimitiveValue
public readonly struct Fraction : IEquatable<Fraction>, IComparable<Fraction>, ICssPrimitiveValue
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Frequency.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a time value.
/// </summary>
public struct Frequency : IEquatable<Frequency>, IComparable<Frequency>, ICssPrimitiveValue
public readonly struct Frequency : IEquatable<Frequency>, IComparable<Frequency>, ICssPrimitiveValue
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Identifier.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a CSS identifier value.
/// </summary>
public struct Identifier : ICssPrimitiveValue, IEquatable<Identifier>
public readonly struct Identifier : ICssPrimitiveValue, IEquatable<Identifier>
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Label.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a CSS label ("string") value.
/// </summary>
public struct Label : ICssPrimitiveValue, IEquatable<Label>
public readonly struct Label : ICssPrimitiveValue, IEquatable<Label>
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Length.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents an absolute length value.
/// </summary>
public struct Length : IEquatable<Length>, IComparable<Length>, ICssPrimitiveValue
public readonly struct Length : IEquatable<Length>, IComparable<Length>, ICssPrimitiveValue
{
#region Basic lengths

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/LineNames.cs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a CSS line names definition.
/// </summary>
public struct LineNames : ICssPrimitiveValue, IEquatable<LineNames>
public readonly struct LineNames : ICssPrimitiveValue, IEquatable<LineNames>
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Point.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a point value consisting of two distances.
/// </summary>
public struct Point : IEquatable<Point>, ICssPrimitiveValue
public readonly struct Point : IEquatable<Point>, ICssPrimitiveValue
{
#region Basic values

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Quote.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a CSS quote.
/// </summary>
public struct Quote : ICssPrimitiveValue, IEquatable<Quote>
public readonly struct Quote : ICssPrimitiveValue, IEquatable<Quote>
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Ratio.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a ratio (top to bottom) value.
/// </summary>
public struct Ratio : IEquatable<Ratio>, IComparable<Ratio>, ICssPrimitiveValue
public readonly struct Ratio : IEquatable<Ratio>, IComparable<Ratio>, ICssPrimitiveValue
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Resolution.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a resolution value.
/// </summary>
public struct Resolution : IEquatable<Resolution>, IComparable<Resolution>, ICssPrimitiveValue
public readonly struct Resolution : IEquatable<Resolution>, IComparable<Resolution>, ICssPrimitiveValue
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Primitives/Time.cs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a time value.
/// </summary>
public struct Time : IEquatable<Time>, IComparable<Time>, ICssPrimitiveValue
public readonly struct Time : IEquatable<Time>, IComparable<Time>, ICssPrimitiveValue
{
#region Basic times

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Raws/CssInitialValue.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents the CSS initial value.
/// </summary>
struct CssInitialValue : ICssSpecialValue
readonly struct CssInitialValue : ICssSpecialValue
{
#region Fields

2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Values/Raws/CssUnsetValue.cs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
/// <summary>
/// Represents a CSS unset value.
/// </summary>
struct CssUnsetValue : ICssSpecialValue
readonly struct CssUnsetValue : ICssSpecialValue
{
#region Fields