Skip to content

Commit

Permalink
capture slotted elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Wenyu Shi committed Aug 2, 2024
1 parent e0cc616 commit b7d7ba9
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/dom-to-image-more.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@
let restorations = [];
return Promise.resolve(node)
.then(ensureElement)
.then(function (clonee) {
return cloneNode(clonee, options, null, ownerWindow);
.then(function (clone) {
return cloneNode(clone, options, null, ownerWindow);
})
.then(embedFonts)
.then(inlineImages)
Expand Down Expand Up @@ -439,8 +439,14 @@

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

return childElement;
}

return original.childNodes;
}
}
Expand Down Expand Up @@ -658,9 +664,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 &&
isShadowRoot(value.getRootNode())
);
}
Expand Down

0 comments on commit b7d7ba9

Please sign in to comment.