Skip to content

Ideal jsdom CSS implementation architecture #235

@domenic

Description

@domenic

Continuing discussion from #234 (comment).

I think the ideal architecture is maybe something like this?

  • At the foundation is a well-maintained third-party CSS library, maybe csstree or things under @csstools/, for core things like parsing.

  • All Web IDL-generated classes except CSSStyleDeclaration live in jsdom/jsdom, because that is where our webidl2js infrastructure is. They are all relatively simple and delegate hard CSS-specific stuff like parsing, serialization, etc. to another library.

    • This includes: StyleSheet, MediaList, CSSStyleSheet, CSSRule, lots of CSSRule-derived classes
    • For example, maybe the parsing library produces a "css import rule" AST structure, with properties like href, layerName, and supportsText. The jsdom code for CSSImportRule would wrap around that AST structure to implement the href getter (including URL resolution), layerName and supportsText getters (just passthrough), and media and styleSheet getters (via its reference to the containing CSSStyleSheet).
  • In the middle there are jsdom-specific libraries that takes care of any hard CSS logic (not CSSOM object implementation) that the core third-party library does not help with. For example, @asamuzakjp/css-color or cssstyle

  • I am not sure where the implementation of CSSStyleDeclaration and CSSStyleProperties should live. Maybe they can be in jsdom/jsdom and be wrappers around the jsdom-specific library. Or maybe they should be in the jsdom-specific library instead.

Part of the motivation to put more of the classes in jsdom/jsdom is that then the other libraries don't have to worry about the Web IDL wrapper/impl distinction and the accompanying build process. It's possible to have parts of jsdom outside of jsdom/jsdom use webidl2js. (For example, whatwg-url does this.) But the pattern of doing the wrapping in jsdom and the core logic in another library is, in my opinion, simpler. (See, e.g., w3c-xmlserializer + jsdom/jsdom wrapper.)

The above seems pretty different from what I understand of our current architecture. Our current architecture has the parser produce CSSOM objects like CSSImportRule directly.

It's possible the above suggestion is bad, or is failing to grasp the hard part of our CSS stack. Better ideas are welcome.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions