Skip to content

Commit 0f612a3

Browse files
committed
Fix typo and get shadow dom node values rendering again.
Thanks for the review @cWenyu
1 parent 14945a5 commit 0f612a3

7 files changed

+58
-55
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ and render on the server._`
260260

261261
## Dependencies
262262

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

265266
### Source
266267

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

365366
## License
366367

dist/dom-to-image-more.min.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dom-to-image-more.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dom-to-image-more",
3-
"version": "3.4.2",
3+
"version": "3.4.3",
44
"description": "Generates an image from a DOM node using HTML5 canvas and SVG",
55
"main": "dist/dom-to-image-more.min.js",
66
"devDependencies": {

spec/dom-to-image-more.spec.js

+34-26
Original file line numberDiff line numberDiff line change
@@ -273,15 +273,23 @@
273273

274274
it('should render web fonts', function (done) {
275275
this.timeout(5000);
276-
loadTestPage('fonts/dom-node.html','fonts/style.css', 'fonts/control-image')
276+
loadTestPage(
277+
'fonts/dom-node.html',
278+
'fonts/style.css',
279+
'fonts/control-image'
280+
)
277281
.then(renderToPngAndCheck)
278282
.then(done)
279283
.catch(done);
280284
});
281285

282286
it('should not copy web font', function (done) {
283287
this.timeout(5000);
284-
loadTestPage('fonts/dom-node.html', 'fonts/style.css', 'fonts/control-image-no-font')
288+
loadTestPage(
289+
'fonts/dom-node.html',
290+
'fonts/style.css',
291+
'fonts/control-image-no-font'
292+
)
285293
.then(() => renderToPng(domNode(), { disableEmbedFonts: true }))
286294
.then(check)
287295
.then(done)
@@ -595,7 +603,7 @@
595603
);
596604

597605
function escapeImage(image) {
598-
if (image.indexOf('image/svg') >= 0){
606+
if (image.indexOf('image/svg') >= 0) {
599607
const svgStart = image.indexOf('<svg');
600608
const svgEnd = image.lastIndexOf('</svg>');
601609
const prefix = image.substring(0, svgStart);
@@ -613,45 +621,45 @@
613621
function escapeHtml(string) {
614622
var str = '' + string;
615623
var match = matchHtmlRegExp.exec(str);
616-
624+
617625
if (!match) {
618626
return str;
619627
}
620-
628+
621629
var escape;
622630
var html = '';
623631
var index = 0;
624632
var lastIndex = 0;
625-
633+
626634
for (index = match.index; index < str.length; index++) {
627635
switch (str.charCodeAt(index)) {
628-
case 34: // "
629-
escape = '&quot;';
630-
break;
631-
case 38: // &
632-
escape = '&amp;';
633-
break;
634-
case 39: // '
635-
escape = '&#39;';
636-
break;
637-
case 60: // <
638-
escape = '&lt;';
639-
break;
640-
case 62: // >
641-
escape = '&gt;';
642-
break;
643-
default:
644-
continue;
636+
case 34: // "
637+
escape = '&quot;';
638+
break;
639+
case 38: // &
640+
escape = '&amp;';
641+
break;
642+
case 39: // '
643+
escape = '&#39;';
644+
break;
645+
case 60: // <
646+
escape = '&lt;';
647+
break;
648+
case 62: // >
649+
escape = '&gt;';
650+
break;
651+
default:
652+
continue;
645653
}
646-
654+
647655
if (lastIndex !== index) {
648656
html += str.substring(lastIndex, index);
649657
}
650-
658+
651659
lastIndex = index + 1;
652660
html += escape;
653661
}
654-
662+
655663
return lastIndex !== index
656664
? html + str.substring(lastIndex, index)
657665
: html;

src/dom-to-image-more.js

+4-10
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,8 @@
442442
function getRenderedChildren(original) {
443443
if (util.isShadowSlotElement(original)) {
444444
const assignedNodes = original.assignedNodes();
445-
446-
if (assignedNodes && assignedNodes.length() > 0)
447-
return assignedNodes; // shadow DOM <slot> has "assigned nodes" as rendered children
445+
446+
if (assignedNodes && assignedNodes.length > 0) return assignedNodes; // shadow DOM <slot> has "assigned nodes" as rendered children
448447
}
449448
return original.childNodes;
450449
}
@@ -666,7 +665,7 @@
666665
function isInShadowRoot(value) {
667666
return (
668667
value !== null &&
669-
Object.hasOwn(value, 'getRootNode') &&
668+
'getRootNode' in value &&
670669
isShadowRoot(value.getRootNode())
671670
);
672671
}
@@ -1124,12 +1123,7 @@
11241123
function getCssRules(styleSheets) {
11251124
const cssRules = [];
11261125
styleSheets.forEach(function (sheet) {
1127-
if (
1128-
Object.hasOwn(
1129-
Object.getPrototypeOf(sheet),
1130-
'cssRules'
1131-
)
1132-
) {
1126+
if ('cssRules' in Object.getPrototypeOf(sheet)) {
11331127
try {
11341128
util.asArray(sheet.cssRules || []).forEach(
11351129
cssRules.push.bind(cssRules)

0 commit comments

Comments
 (0)