Comments (7)
I think by "post-processing op", you mean running styles through
copyUserComputedStyleFast
as a first pass, then the remainder through the block of code you linked to above, right? That would result in the best performance.
Correct!
from dom-to-image-more.
I noticed that for toSvg(node, options)
, the sandbox is not removed, and the default styles cache is not cleared after 20s.
Is persisting the default styles cache of benefit in your opinion?
(Polluting the DOM with 1 <iframe>
per SVG screenshot is a bug of course.)
from dom-to-image-more.
You are correct. removeSandbox
is called in draw()
, which calls toSvg()
. toSvg()
does not call removeSandbox
. We need to move the removeSandbox
call from draw()
into toSvg()
.
The other methods, like toPng()
, call draw()
, which is why this works: https://jsfiddle.net/L4bdynwr/.
from dom-to-image-more.
Could you update this SO comment to "maybe" recommend filterWinningInlineStyles
multi-pass compression as a post-processing op?copyUserComputedStyle
is an overeager data reduction.
If the library adopts filterWinningInlineStyles
it will be necessary to put the clone root in the sandbox iframe, then take the iframe width and height straight from the original document.
For posterity... there are two patches to the original implementation of copyUserComputedStyle
that would make it functional (even if it's far too slow for end users...) and minimize post-exit pollution:
- Remove inline style in target if we didn't have it in the first place..
- Rely on
revert
instead ofunset
.
function copyUserComputedStyle(sourceElement, sourceComputedStyles, targetElement) {
const targetStyles = targetElement.style;
const inlineStyles = sourceElement.style;
const inlineStyleText = inlineStyle.cssText;
for (let property of sourceComputedStyles) {
const value = sourceComputedStyles.getPropertyValue(property);
const inlineValue = inlineStyles.getPropertyValue(property);
inlineStyles.setProperty(style, 'revert');
const userAgentValue = sourceComputedStyles.getPropertyValue(property);
if (userAgentValue !== value) {
targetStyles.setProperty(property, value, undefined);
}
inlineStyles.setProperty(property, inlineValue);
}
if (!inlineStyleText.length) sourceElement.removeAttribute('style');
}
from dom-to-image-more.
I think by "post-processing op", you mean running styles through copyUserComputedStyleFast
as a first pass, then the remainder through the block of code you linked to above, right? That would result in the best performance.
Thanks for giving a shot at implementing this!
I did post an extra comment on StackOverflow. However, I cannot recommend this approach due to the complexity of the algorithm (see my comment in #92).
from dom-to-image-more.
Seems to work fine with current source inlined in this fiddle https://jsfiddle.net/L4bdynwr/
from dom-to-image-more.
Sorry, that leak has been corrected in v2.14.1 and v3.0.2-rc.0
from dom-to-image-more.
Related Issues (20)
- Icon to image display failed HOT 1
- TypeError: Cannot read properties of undefined (reading 'setProperty')
- Error using toPng with extra quote in HTML
- The internal picture is blank HOT 2
- border HOT 10
- Cannot convert webgl
- Need embed fonts to be optional HOT 5
- Browser crashes when using toPng
- Image is cropped in Firefox HOT 3
- cssRules from google CSS breaking HOT 1
- TypeError:Failed to execute 'readAsDataURL' on 'FileReader' : parameter 1 is not of type 'Blob' HOT 7
- Bug: get wrong pic from image jsp
- domtoimage doesn't work on vector layer
- Exporting blank image when element's parent has visibility hidden
- Dom-to-image conversion results misaligned content in Image for CSS flex styles
- domtoImage converts only first child element when cloneNode(true) is used HOT 1
- Unavaible to override existing CSS style within the adjustClone function HOT 4
- Date Inputs Not Captured in Firefox (v127.0) HOT 1
- When an image is rendered in the Dom of SVG, it is lost when exported HOT 2
- Proper @types/dom-to-image-more package
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dom-to-image-more.