-
Notifications
You must be signed in to change notification settings - Fork 108
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
Add onclone
size optimization for inline styles
#92
Comments
I'm really steering away from this change right now. Really do NOT want to delve into the very fragile territory that it brings trying to white-list things. I will add a override path for the SVG path to the |
Sounds all right. Happy hols! I imagine the Wrote
|
Thanks for giving a shot at trying to implement this! I agree with @IDisposable. I think this algorithm is getting too complex for it to be feasible to maintain as part of the library. Users who desire better SVG size optimizations should override the behavior on their own. We don't want to maintain code that will have to be frequently updated to keep up with the spec. A comment on the robust-ness on this algorithm: The algorithm looks good so far. As I understand it, it tries removing the property on an SVG clone of the DOM tree, to see if the computed value changes. If the computed value stays the same, the property can be removed. We process children elements before their parents. I would like to know if you have tested if removing the property with the given |
Since my last comment there was a gotcha (removing explicit Closing this as we can now package up this filter and users can insert it in the module using the
I don't have data to present, but as I understand it, the filter isn't aggressive or behaviour-dependent enough to produce this footgun. The user agent stylesheets also avoid One day later: realised that CSS properties are qualified like |
Reopening as I don't want to be the one to maintain an NPM package. I've updated #92 (comment) for Here is a possible README for a
|
toSvg
onclone
size optimization for inline styles
I will be working on this next. |
This algorithm has $O(log(N)$ or $O(c*N)$ growth - 1904labs#135 Refs: 1904labs#36, 1904labs#91, 1904labs#92
onclone
size optimization for inline stylesonclone
size optimization for inline styles
I have extracted the solution design here into a standalone package that's usable as we speak :)
|
Thanks for doing that... I've been hacking in .Net land of late and haven't been able to address much here... might be able to sweep this into a build soonish, but I love that you've made a package to allow others to benefit from it now! |
That |
Use case: description, code
In an ideal world we want to optimize SVG output by removing styles that can be inherited.
This mainly has an impact at >>1K nodes where the output is in the 1MB scale of magnitude.
There's not much of a story here at the moment, but the library did previously lean on
unset
until the #90 regression:dom-to-image-more/src/dom-to-image-more.js
Lines 915 to 934 in 2c54d7f
There's two strategies I tried to research:
document.styleSheets
while
loop on.parentNode
, and a hardcoded list of inheritable CSS propstoSvg
TreeWalker
to iterate over the nodesSome starter code, but this code snippet:
The text was updated successfully, but these errors were encountered: