-
Notifications
You must be signed in to change notification settings - Fork 79
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
Export CSSOM classes #201
Comments
PS: as a linkedom user in deno, I don't know how to use CSSStyleRule, etc... appart from importing a fresh new module that will conflict with the one used bt linkedom: import { CSSStyleRule } from 'npm:cssom'
document.querySelector('style').sheet.cssRules[0].contructor === CSSStyleRule
// false I would need: import { CSSStyleRule } from 'linkedom'
// or
import { cssom } from 'linkedom'
const { CSSStyleRule } = cssom
document.querySelector('style').sheet.cssRules[0].contructor === CSSStyleRule
// true |
this seems a reasonable question, I just need to be sure that module doesn't export conflicting names for the module. If you fancy a PR, please go ahead! (source of truth being the |
After investing code, there is a conflict with Your's is used to be synced with the Your's also is Both are not fully compliant with W3C (like concerning constructed StyleSheet's So the thing is that you get 2 really different classes that should both be the same, depending on where you get it: // el is a <style> with some css
assert( el.style.constructor == el.sheet.cssRules[0].style.contructor )
// false ! |
I tried that to extract the classes from instances : import { DOMParser } from 'https://esm.sh/[email protected]'
const temp = ( new DOMParser ).parseFromString(`<style>
@import url("style.css") screen;
@media (min-width: 500px) {}
div {
foo: bar;
}
</style>`, 'text/html' ).documentElement
const CSSStyleSheet = temp.sheet.constructor
const linkedomCSSStyleDeclaration = temp.style.constructor // only Element.style , is part of linkedom
const CSSImportRule = temp.sheet.cssRules[0].constructor
const CSSMediaRule = temp.sheet.cssRules[1].constructor
const CSSStyleRule = temp.sheet.cssRules[2].constructor // or CSSRule
const CSSStyleDeclaration = temp.sheet.cssRules[2].style.constructor
const CSSRule = CSSStyleRule.prototype.constructor
export {
CSSStyleSheet,
CSSStyleDeclaration, linkedomCSSStyleDeclaration,
CSSImportRule,
CSSMediaRule,
CSSStyleRule,
CSSRule,
} |
My conclusion is that it's weird to have 2 different implementations of CSS parsing depending on using This means rewrite the way ( level of skill that I don't have! ^^; ) |
It’s not a goal of this project to be 100% standard compliant, there’s JSDOM for that goal … I think I remember why indeed I didn’t use cssom internally, neither I’ve exposed that class externally. as performance here matters more than standard compliance, what is your use case for having cssom available? If the answer is test then I’m afraid I’m not keen to accommodate that use case with changes that might both break and will slow down this project. |
I'm trying to re-implement a (compliant like)
|
it's fast because I've pushed back on many similar requests (it misses just this, it misses just that, this should be more standard, ... and so on) but you gave me an idea around I'll think about it, but not immediately. |
Well, I'm not sure if you took it hard (I'm not english native)... If it's the case please apologize! I did not asked you to add this or that nor to be more W3C compiant ! :) The idea behind my request was to be able to code a custom getComputedStyle for my project... not to be integrated in linkedom not make you work on it ! ;) And finaly... I may still work on this on my side (the same it's not my priority), if you want I may share future stuff / investigation here... PS: The issue was more a way to communicate than a real issue though ! |
I did'nt get why passing through the proxy is "a decent guard" ? |
Apologies I’m not native English neither, let’s try to assume best intents from both side 😉 a guard meaning I can intercept the usage/need of getComputedStyle via the proxy and enable only when accessed a better cssom integration/story for style attributes and CSS parsing/behavior. I’m short on time these days but I’ll have a look |
AFAIK I'm afraid t say that implementing a getComputedStyle may be a real chalenge because of the CSS cascade. There are a lot of concern (not even covered by cssom) to take in account, especialy selector precedence and DOM layout, pseudos element etc... The only real no go right now is the use of cssom "somewhere" but not "elsewhere" in linkedom, what's confusing when using a user-land own copy of cssom (or any other implementation).
Your choice BTW! I'll be happy to help if you want me to start something (with your directives and good directions ;)) |
OK, I took the time to give cssom a shot and here's what's problematic:
I am skeptic about exporting cssom because of the Last, but not least, bundled files like the worker.js can't benefit from tree-shaking if I export all cssom when I need, in fact, only its parser, so that's another no-go from my side. Accordingly with these findings and blockers, the only escape hatch I can think about is to offer an export |
I can to almost the same conclusions:
So I came to the question: Why parsing |
it's one nice-to-have thing I've previously used and if it's a no-brainer and it doesn't affect performance, as it's a lazy getter, the answer is more likely why not? this is some pragmatism I've used when creating this project: if something is trivial, already solved elsewhere, and not perf critical, it's OK to have it in ... if any of these points doesn't match, it's either very needed, super useful, or both, otherwise it's a meh from my side. |
It can be usefull to be able to get and work with CSS classes, as it's already used in the library, why not make it accessible in root module and
window
like the rest of classes?linkedom/esm/html/style-element.js
Line 1 in 5527ee4
The text was updated successfully, but these errors were encountered: