Giter Club home page Giter Club logo

Comments (7)

zm-cttae avatar zm-cttae commented on August 23, 2024 1

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.

zm-cttae avatar zm-cttae commented on August 23, 2024 1

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.

joswhite avatar joswhite commented on August 23, 2024 1

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.

zm-cttae avatar zm-cttae commented on August 23, 2024

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 of unset.
    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.

joswhite avatar joswhite commented on August 23, 2024

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.

IDisposable avatar IDisposable commented on August 23, 2024

Seems to work fine with current source inlined in this fiddle https://jsfiddle.net/L4bdynwr/

from dom-to-image-more.

IDisposable avatar IDisposable commented on August 23, 2024

Sorry, that leak has been corrected in v2.14.1 and v3.0.2-rc.0

from dom-to-image-more.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.