Code Monkey home page Code Monkey logo

Comments (2)

Jym77 avatar Jym77 commented on September 25, 2024

So, it seems that CSSStyleDeclaration.style[i] only exposes longhands, but not the shorthands that are defined.
Upon looking at the declaration corresponding to that block, we get:

…
0: "background-image"
1: "background-position-x"
2: "background-position-y"
3: "background-size"
4: "background-repeat"
5: "background-attachment"
6: "background-origin"
7: "background-clip"
8: "background-color"
…
background: "var(--blue)"
backgroundAttachment: ""
backgroundBlendMode: ""
backgroundClip: ""
backgroundColor: ""
backgroundImage: ""
backgroundOrigin: ""
backgroundPosition: ""
backgroundPositionX: ""
backgroundPositionY: ""
backgroundRepeat: ""
backgroundSize: ""
…

So, only the longhands are indexed, but the shorthand is still correctly recorded. Since Alfa looks at the indexed properties, it does not see that the shorthand has been defined and should be grabbed instead.

When the variable is not used, and background: blue is used instead, we get:

…
0: "background-image"
1: "background-position-x"
2: "background-position-y"
3: "background-size"
4: "background-repeat"
5: "background-attachment"
6: "background-origin"
7: "background-clip"
8: "background-color"
…
background: "blue"
backgroundAttachment: "initial"
backgroundBlendMode: ""
backgroundClip: "initial"
backgroundColor: "blue"
backgroundImage: "initial"
backgroundOrigin: "initial"
backgroundPosition: "initial"
backgroundPositionX: "initial"
backgroundPositionY: "initial"
backgroundRepeat: "initial"
backgroundSize: "initial"
…

So, the shorthand is correctly expanded (which is possible since it's not a variable that needs cascading to be resolved first), and we grab the correct value.


We might need some special handling of shorthand when grabbing style rules…

from alfa.

Jym77 avatar Jym77 commented on September 25, 2024

We will likely need to have Native.toBlock send a JSON object with unparsed CSS text, so we can use CSSDeclaration.cssText instead, and then Block.fromJSON (or a new version) use alfa-css/syntax/Declaration.parse to get the correct values.

from alfa.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.