* @param {boolean=} deep whether to deep-clone children * @returns {FakeElement} cloned element
(deep = false)
| 424 | * @returns {FakeElement} cloned element |
| 425 | */ |
| 426 | cloneNode(deep = false) { |
| 427 | const cloned = new FakeElement( |
| 428 | this._document, |
| 429 | this._type, |
| 430 | this._document._basePath |
| 431 | ); |
| 432 | |
| 433 | // Copy attributes |
| 434 | cloned._attributes = { ...this._attributes }; |
| 435 | |
| 436 | // Copy src and href |
| 437 | cloned._src = this._src; |
| 438 | cloned._href = this._href; |
| 439 | |
| 440 | // For link elements, create a new sheet with the same href |
| 441 | if (this._type === "link" && this.sheet) { |
| 442 | cloned.sheet = new FakeSheet(cloned, this._document._basePath); |
| 443 | if (this._href) { |
| 444 | cloned.href = this._href; |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | // Copy event handlers if they exist |
| 449 | if (this.onload) { |
| 450 | cloned.onload = this.onload; |
| 451 | } |
| 452 | // Copy event listeners |
| 453 | if (this._eventListeners) { |
| 454 | cloned._eventListeners = new Map(); |
| 455 | for (const [event, handlers] of this._eventListeners.entries()) { |
| 456 | cloned._eventListeners.set(event, [...handlers]); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | // Deep clone children if requested |
| 461 | if (deep) { |
| 462 | for (const child of this._children) { |
| 463 | const clonedChild = child.cloneNode(true); |
| 464 | cloned.appendChild(clonedChild); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | return cloned; |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | class FakeSheet { |
nothing calls this directly
no test coverage detected