feat: Improve node cloning using @zumer/snapdom deepClone #792
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR should improve the cloning done by html2pdf.js as part of the "toContainer" stage, by using the core
deepClonelogic from@zumer/snapdomwith a few changes:inlineAllStyleslogic, because this was hard-coding things like width - I specifically want things to reflow with the chosen PDF document sizeprepareCloneprepareClonepieces I should be keeping, but scrolling was in my existing clone logic and I didn't want to lose itBig picture, I was hoping to eliminate my own cloning step entirely and rely only on snapdom's cloning as part of its image-creation process - unfortunately that won't be possible. html2pdf.js relies on reflowing the content to capture it in a specified PDF page size, and I don't want to resize the source element - that means there needs to be some clone that happens before styles are inlined. In snapdom, those inline styles are always calculated from the source elements, so there pretty much needs to be a preliminary clone step before it can do its work.
In local testing this new clone process still needs some time after the clone to allow things to properly reflow, so I'm leaving in the 10ms delay after cloning.