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

capture slotted elements #179

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/dom-to-image-more.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,16 @@

function getRenderedChildren(original) {
if (util.isShadowSlotElement(original)) {
return original.assignedNodes(); // shadow DOM <slot> has "assigned nodes" as rendered children
// default child elements inside the named slot
let childElement = original.childNodes;

if (original.assignedNodes().length > 0) {
// replace the default child elements when have assigned nodes
childElement = original.assignedNodes();
}
return childElement;
}

return original.childNodes;
}
}
Expand Down Expand Up @@ -658,9 +666,13 @@
}

function isInShadowRoot(value) {
// Object.prototype.hasOwnProperty.call(value, 'getRootNode') always is false
// MDN hasOwnProperty: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty
// hasOwnProperty returns a boolean indicating whether this object has the specified property as its own property
// getRootNode is inherited from the prototype chain, and defined on the Node prototype
return (
value !== null &&
Object.prototype.hasOwnProperty.call(value, 'getRootNode') &&
'getRootNode' in value &&
IDisposable marked this conversation as resolved.
Show resolved Hide resolved
isShadowRoot(value.getRootNode())
);
}
Expand Down