Skip to content

Commit

Permalink
Fix typo and get shadow dom node values rendering again.
Browse files Browse the repository at this point in the history
Thanks for the review @cWenyu
  • Loading branch information
IDisposable committed Aug 29, 2024
1 parent 14945a5 commit 0f612a3
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 55 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ and render on the server._`

## Dependencies

Uses Object.hasOwn() so needs at least Chrome/Edge 93, Firefox 92, Opera 79. Safari 15.4 or Node 16.9.0
Uses Object.hasOwn() so needs at least Chrome/Edge 93, Firefox 92, Opera 79. Safari 15.4
or Node 16.9.0

### Source

Expand Down Expand Up @@ -358,9 +359,9 @@ SNDST00M (optimize), Joseph White (performance CSS), Phani Rithvij (test), David
DOLCIMASCOLO (packaging), Zee (ZM) @zm-cttae (many major updates), Joshua Walsh
@JoshuaWalsh (Firefox issues), Emre Coban @emrecoban (documentation), Nate Stuyvesant
@nstuyvesant (fixes), King Wang @eachmawzw (CORS image proxy), TMM Schmit @tmmschmit
(useCredentialsFilters), Aravind @codesculpture (fix overridden props),
Shi Wenyu @cWenyu (shadow slot fix), David Burns @davidburns573
and Yujia Cheng @YujiaCheng1996 (font copy optional)
(useCredentialsFilters), Aravind @codesculpture (fix overridden props), Shi Wenyu @cWenyu
(shadow slot fix), David Burns @davidburns573 and Yujia Cheng @YujiaCheng1996 (font copy
optional)

## License

Expand Down
4 changes: 2 additions & 2 deletions dist/dom-to-image-more.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/dom-to-image-more.min.js.map

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dom-to-image-more",
"version": "3.4.2",
"version": "3.4.3",
"description": "Generates an image from a DOM node using HTML5 canvas and SVG",
"main": "dist/dom-to-image-more.min.js",
"devDependencies": {
Expand Down
60 changes: 34 additions & 26 deletions spec/dom-to-image-more.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,23 @@

it('should render web fonts', function (done) {
this.timeout(5000);
loadTestPage('fonts/dom-node.html','fonts/style.css', 'fonts/control-image')
loadTestPage(
'fonts/dom-node.html',
'fonts/style.css',
'fonts/control-image'
)
.then(renderToPngAndCheck)
.then(done)
.catch(done);
});

it('should not copy web font', function (done) {
this.timeout(5000);
loadTestPage('fonts/dom-node.html', 'fonts/style.css', 'fonts/control-image-no-font')
loadTestPage(
'fonts/dom-node.html',
'fonts/style.css',
'fonts/control-image-no-font'
)
.then(() => renderToPng(domNode(), { disableEmbedFonts: true }))
.then(check)
.then(done)
Expand Down Expand Up @@ -595,7 +603,7 @@
);

function escapeImage(image) {
if (image.indexOf('image/svg') >= 0){
if (image.indexOf('image/svg') >= 0) {
const svgStart = image.indexOf('<svg');
const svgEnd = image.lastIndexOf('</svg>');
const prefix = image.substring(0, svgStart);
Expand All @@ -613,45 +621,45 @@
function escapeHtml(string) {
var str = '' + string;
var match = matchHtmlRegExp.exec(str);

if (!match) {
return str;
}

var escape;
var html = '';
var index = 0;
var lastIndex = 0;

for (index = match.index; index < str.length; index++) {
switch (str.charCodeAt(index)) {
case 34: // "
escape = '&quot;';
break;
case 38: // &
escape = '&amp;';
break;
case 39: // '
escape = '&#39;';
break;
case 60: // <
escape = '&lt;';
break;
case 62: // >
escape = '&gt;';
break;
default:
continue;
case 34: // "
escape = '&quot;';
break;
case 38: // &
escape = '&amp;';
break;
case 39: // '
escape = '&#39;';
break;
case 60: // <
escape = '&lt;';
break;
case 62: // >
escape = '&gt;';
break;
default:
continue;
}

if (lastIndex !== index) {
html += str.substring(lastIndex, index);
}

lastIndex = index + 1;
html += escape;
}

return lastIndex !== index
? html + str.substring(lastIndex, index)
: html;
Expand Down
14 changes: 4 additions & 10 deletions src/dom-to-image-more.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,8 @@
function getRenderedChildren(original) {
if (util.isShadowSlotElement(original)) {
const assignedNodes = original.assignedNodes();

if (assignedNodes && assignedNodes.length() > 0)
return assignedNodes; // shadow DOM <slot> has "assigned nodes" as rendered children

if (assignedNodes && assignedNodes.length > 0) return assignedNodes; // shadow DOM <slot> has "assigned nodes" as rendered children
}
return original.childNodes;
}
Expand Down Expand Up @@ -666,7 +665,7 @@
function isInShadowRoot(value) {
return (
value !== null &&
Object.hasOwn(value, 'getRootNode') &&
'getRootNode' in value &&
isShadowRoot(value.getRootNode())
);
}
Expand Down Expand Up @@ -1124,12 +1123,7 @@
function getCssRules(styleSheets) {
const cssRules = [];
styleSheets.forEach(function (sheet) {
if (
Object.hasOwn(
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 0f612a3

Please sign in to comment.