Skip to content

Commit e542fb5

Browse files
remmelmrdoob
authored andcommitted
HtmlMesh doesn't handle html comment (mrdoob#23657)
* HTMLMesh fix html comment, constants and basic html example HTMLMesh was not working when the html has a comment (see err below). And use Node constants https://developer.mozilla.org/fr/docs/Web/API/Node/nodeType. Add basic example of html with list in webxr_vr_sandbox ``` HTMLMesh.js:258 Uncaught TypeError: Cannot read properties of undefined (reading 'display') at drawElement (HTMLMesh.js:258) at drawElement (HTMLMesh.js:307) at html2canvas (HTMLMesh.js:337) at new HTMLTexture (HTMLMesh.js:54) at new HTMLMesh (HTMLMesh.js:14) at init (webxr_vr_sandbox.html:224) at webxr_vr_sandbox.html:62 ``` * Update webxr_vr_sandbox.html * Update webxr_vr_sandbox.html Co-authored-by: mrdoob <[email protected]>
1 parent c89e54f commit e542fb5

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

examples/js/interactive/HTMLMesh.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@
210210
width = 0,
211211
height = 0;
212212

213-
if ( element.nodeType === 3 ) {
213+
if ( element.nodeType === Node.TEXT_NODE ) {
214214

215215
// text
216216
range.selectNode( element );
@@ -221,6 +221,10 @@
221221
height = rect.height;
222222
drawText( style, x, y, element.nodeValue.trim() );
223223

224+
} else if ( element.nodeType === Node.COMMENT_NODE ) {
225+
226+
return;
227+
224228
} else if ( element instanceof HTMLCanvasElement ) {
225229

226230
// Canvas element
@@ -333,7 +337,7 @@
333337

334338
function traverse( element ) {
335339

336-
if ( element.nodeType !== 3 ) {
340+
if ( element.nodeType !== Node.TEXT_NODE && element.nodeType !== Node.COMMENT_NODE ) {
337341

338342
const rect = element.getBoundingClientRect();
339343

examples/jsm/interactive/HTMLMesh.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function html2canvas( element ) {
223223

224224
let x = 0, y = 0, width = 0, height = 0;
225225

226-
if ( element.nodeType === 3 ) {
226+
if ( element.nodeType === Node.TEXT_NODE ) {
227227

228228
// text
229229

@@ -238,6 +238,10 @@ function html2canvas( element ) {
238238

239239
drawText( style, x, y, element.nodeValue.trim() );
240240

241+
} else if ( element.nodeType === Node.COMMENT_NODE ) {
242+
243+
return;
244+
241245
} else if ( element instanceof HTMLCanvasElement ) {
242246

243247
// Canvas element
@@ -355,7 +359,7 @@ function htmlevent( element, event, x, y ) {
355359

356360
function traverse( element ) {
357361

358-
if ( element.nodeType !== 3 ) {
362+
if ( element.nodeType !== Node.TEXT_NODE && element.nodeType !== Node.COMMENT_NODE ) {
359363

360364
const rect = element.getBoundingClientRect();
361365

0 commit comments

Comments
 (0)