| 495 | * SVG nodes are used to render stretchy wide elements. |
| 496 | */ |
| 497 | export class SvgNode implements VirtualNode { |
| 498 | children: SvgChildNode[]; |
| 499 | attributes: Record<string, string>; |
| 500 | |
| 501 | constructor( |
| 502 | children?: SvgChildNode[], |
| 503 | attributes?: Record<string, string>, |
| 504 | ) { |
| 505 | this.children = children || []; |
| 506 | this.attributes = attributes || {}; |
| 507 | } |
| 508 | |
| 509 | toNode(): Node { |
| 510 | const svgNS = "http://www.w3.org/2000/svg"; |
| 511 | const node = document.createElementNS(svgNS, "svg"); |
| 512 | |
| 513 | // Apply attributes |
| 514 | for (const attr of Object.keys(this.attributes)) { |
| 515 | node.setAttribute(attr, this.attributes[attr]); |
| 516 | } |
| 517 | |
| 518 | for (let i = 0; i < this.children.length; i++) { |
| 519 | node.appendChild(this.children[i].toNode()); |
| 520 | } |
| 521 | return node; |
| 522 | } |
| 523 | |
| 524 | toMarkup(): string { |
| 525 | let markup = `<svg xmlns="http://www.w3.org/2000/svg"`; |
| 526 | |
| 527 | // Apply attributes |
| 528 | for (const attr of Object.keys(this.attributes)) { |
| 529 | markup += ` ${attr}="${escape(this.attributes[attr])}"`; |
| 530 | } |
| 531 | |
| 532 | markup += ">"; |
| 533 | |
| 534 | for (let i = 0; i < this.children.length; i++) { |
| 535 | markup += this.children[i].toMarkup(); |
| 536 | } |
| 537 | |
| 538 | markup += "</svg>"; |
| 539 | |
| 540 | return markup; |
| 541 | |
| 542 | } |
| 543 | } |
| 544 | |
| 545 | export class PathNode implements VirtualNode { |
| 546 | pathName: string; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…