( oldTree: HTMLElement, newTree: IRRElement, rrnodeMirror: Mirror, )
| 330 | } |
| 331 | |
| 332 | function diffProps( |
| 333 | oldTree: HTMLElement, |
| 334 | newTree: IRRElement, |
| 335 | rrnodeMirror: Mirror, |
| 336 | ) { |
| 337 | const oldAttributes = oldTree.attributes; |
| 338 | const newAttributes = newTree.attributes; |
| 339 | |
| 340 | for (const name in newAttributes) { |
| 341 | const newValue = newAttributes[name]; |
| 342 | const sn = rrnodeMirror.getMeta(newTree) as elementNode | null; |
| 343 | if (sn?.isSVG && NAMESPACES[name]) |
| 344 | oldTree.setAttributeNS(NAMESPACES[name], name, newValue); |
| 345 | else if (newTree.tagName === 'CANVAS' && name === 'rr_dataURL') { |
| 346 | const image = document.createElement('img'); |
| 347 | image.src = newValue; |
| 348 | image.onload = () => { |
| 349 | const ctx = (oldTree as HTMLCanvasElement).getContext('2d'); |
| 350 | if (ctx) { |
| 351 | ctx.drawImage(image, 0, 0, image.width, image.height); |
| 352 | } |
| 353 | }; |
| 354 | } else if (newTree.tagName === 'IFRAME' && name === 'srcdoc') continue; |
| 355 | else { |
| 356 | try { |
| 357 | oldTree.setAttribute(name, newValue); |
| 358 | } catch (err) { |
| 359 | // We want to continue diffing so we quietly catch |
| 360 | // this exception. Otherwise, this can throw and bubble up to |
| 361 | // the `ReplayerEvents.Flush` listener and break rendering |
| 362 | console.warn(err); |
| 363 | } |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | for (const { name } of Array.from(oldAttributes)) |
| 368 | if (!(name in newAttributes)) oldTree.removeAttribute(name); |
| 369 | newTree.scrollLeft && (oldTree.scrollLeft = newTree.scrollLeft); |
| 370 | newTree.scrollTop && (oldTree.scrollTop = newTree.scrollTop); |
| 371 | } |
| 372 | |
| 373 | function diffChildren( |
| 374 | oldTree: Node, |
no test coverage detected