Skip to content
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

Expose ability to adjust the cloned node before generating image. #164

Merged
merged 3 commits into from
Feb 14, 2024

Conversation

IDisposable
Copy link
Member

@IDisposable IDisposable commented Feb 9, 2024

Added the ability to specify a call-back to be invoked on each node as we clone them so you can adjust the nodes in any way needed before the conversion. The handler is passed in the options as adjustClonedNode which is a function that gets the original node, the cloned node, and a boolean that says if we've cloned the children already (so you can handle either before or after)

Sample use (with this package source inlined) in the fiddle:

const adjustClone = (node, clone, after) => {
  if (!after && clone.id === 'element') {
    clone.style.transform = 'translateY(100px)';
  }
  return clone;                   
}

const wrapper = document.getElementById('wrapper');
const blob =  domtoimage.toBlob(wrapper, { adjustClonedNode: adjustClone});

Also bumps dev packages up to current and cleaned a bit of lint.

Fixes #163

@IDisposable IDisposable force-pushed the add-clone-eventing branch 2 times, most recently from ae8070f to 601f708 Compare February 9, 2024 22:30
@IDisposable IDisposable changed the title Add clone eventing Expose ability to adjust the cloned node before generating image. Feb 9, 2024
@IDisposable IDisposable merged commit d7086e6 into main Feb 14, 2024
3 checks passed
@IDisposable IDisposable deleted the add-clone-eventing branch February 14, 2024 17:38
@IDisposable
Copy link
Member Author

Released in https://github.com/1904labs/dom-to-image-more/releases/tag/v3.3.0

Thanks for your contribution @wyking1997!

@wyking1997
Copy link

Thank you for your quick support!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants