jsdom / cssstyle

A Node.js implementation of the CSS Object Model CSSStyleDeclaration interface
MIT License
107 stars 70 forks source link

Improve support of un-computed calc #128

Closed cdoublev closed 3 years ago

cdoublev commented 3 years ago

115 adds basic support for uncomputed calc () values, but only for those of type <dimension>, ie. a <length-percentage> like for the width property, but not for those of type <length>, like for the border-width property, or <percentage>.

This PR is only a draft, for several reasons.

  1. There is no support for types that can be used in calc but which are nested within another type, such as an <angle>or a <length-percentage> (<color-stop>) in a <gradient> for the background-image property.

  2. There is no support for <hsla?()> because its values are currently computed (see next point) to <rgba?()>.

  3. Ideally, calc should be computed when possible (see #101 ) to conform to the specification and browsers behavior.

  4. Some recent language features are used like array destructuring, and other features like var. So I'm not sure of the targeted environments that should be supported.

    The primary use case is for testing browser code in a Node environment.

    Latest and stable versions, I guess?

  5. <rgba?()> and <hsla?()> should be able to support a space as a separator for values ​​other than the alpha channel (note that it would complicate the task of their parser), and a /to separate the latter.

This draft provides support for properties directly receiving (ie. not nested in another type) a value of type <integer>, <number>, <color> (only <rgba? ()> ), <length>, <percentage> (font-stretch is an example but its values ​​are not parsed by cssstyle), <angle> (offset-rotate is an example but same as <percentage>).

This draft also fixes the two following issues:

codecov-commenter commented 3 years ago

Codecov Report

Merging #128 (dbf82a3) into master (b527ed7) will increase coverage by 0.38%. The diff coverage is 85.24%.

:exclamation: Current head dbf82a3 differs from pull request most recent head baf63bc. Consider uploading reports for the commit baf63bc to get more accurate results Impacted file tree graph

@@            Coverage Diff             @@
##           master     #128      +/-   ##
==========================================
+ Coverage   37.39%   37.78%   +0.38%     
==========================================
  Files          87       87              
  Lines        1182     1191       +9     
  Branches      227      234       +7     
==========================================
+ Hits          442      450       +8     
  Misses        633      633              
- Partials      107      108       +1     
Impacted Files Coverage Δ
lib/parsers.js 80.82% <85.24%> (+0.18%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update b527ed7...baf63bc. Read the comment docs.

cdoublev commented 3 years ago

Superseded by #140.