-
-
Notifications
You must be signed in to change notification settings - Fork 75
Description
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 ofCSSRule
-derived classes - For example, maybe the parsing library produces a "css import rule" AST structure, with properties like
href
,layerName
, andsupportsText
. The jsdom code forCSSImportRule
would wrap around that AST structure to implement thehref
getter (including URL resolution),layerName
andsupportsText
getters (just passthrough), andmedia
andstyleSheet
getters (via its reference to the containingCSSStyleSheet
).
- This includes:
-
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
orcssstyle
-
I am not sure where the implementation of
CSSStyleDeclaration
andCSSStyleProperties
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.