Skip to content

Commit

Permalink
Capture slotted elements child nodes
Browse files Browse the repository at this point in the history
When the element's  has no assignedNodes, fall-back to the node's childNodes for ShadowSlotElements.
Thanks @cWenyu
Fixes #178, Merges #179
  • Loading branch information
IDisposable committed Aug 21, 2024
1 parent 5b003ca commit 92efe42
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/dom-to-image-more.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,10 @@

function getRenderedChildren(original) {
if (util.isShadowSlotElement(original)) {
return original.assignedNodes(); // shadow DOM <slot> has "assigned nodes" as rendered children
const assignedNodes = original.assignedNodes();

if (assignedNodes && assignedNodes.length() > 0)
return assignedNodes; // shadow DOM <slot> has "assigned nodes" as rendered children
}
return original.childNodes;
}
Expand Down Expand Up @@ -663,7 +666,7 @@
function isInShadowRoot(value) {
return (
value !== null &&
Object.prototype.hasOwnProperty.call(value, 'getRootNode') &&
'getRootNode' in value &&
isShadowRoot(value.getRootNode())
);
}
Expand Down Expand Up @@ -1121,12 +1124,7 @@
function getCssRules(styleSheets) {
const cssRules = [];
styleSheets.forEach(function (sheet) {
if (
Object.prototype.hasOwnProperty.call(
Object.getPrototypeOf(sheet),
'cssRules'
)
) {
if ('cssRules' in Object.getPrototypeOf(sheet)) {
try {
util.asArray(sheet.cssRules || []).forEach(
cssRules.push.bind(cssRules)
Expand Down

0 comments on commit 92efe42

Please sign in to comment.