| 91 | If you're not interested in animating SVG, you can use {@link Img} instead. |
| 92 | */ |
| 93 | export class SVG extends Shape { |
| 94 | @lazy(() => { |
| 95 | const element = document.createElement('div'); |
| 96 | View2D.shadowRoot.appendChild(element); |
| 97 | return element; |
| 98 | }) |
| 99 | protected static containerElement: HTMLDivElement; |
| 100 | private static svgNodesPool: Record<string, SVGDocumentData> = {}; |
| 101 | |
| 102 | /** |
| 103 | * SVG string to be rendered |
| 104 | */ |
| 105 | @signal() |
| 106 | public declare readonly svg: SimpleSignal<string, this>; |
| 107 | |
| 108 | /** |
| 109 | * Child to wrap all SVG node |
| 110 | */ |
| 111 | public wrapper: Node; |
| 112 | |
| 113 | private lastTweenTargetSrc: string | null = null; |
| 114 | private lastTweenTargetDocument: SVGDocument | null = null; |
| 115 | |
| 116 | public constructor(props: SVGProps) { |
| 117 | super(props); |
| 118 | this.wrapper = new Node({}); |
| 119 | this.wrapper.children(this.documentNodes); |
| 120 | this.wrapper.scale(this.wrapperScale); |
| 121 | this.add(this.wrapper); |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Get all SVG nodes with the given id. |
| 126 | * @param id - An id to query. |
| 127 | */ |
| 128 | public getChildrenById(id: string) { |
| 129 | return this.document() |
| 130 | .nodes.filter(node => node.id === id) |
| 131 | .map(({shape}) => shape); |
| 132 | } |
| 133 | |
| 134 | protected override desiredSize(): SerializedVector2<DesiredLength> { |
| 135 | const docSize = this.document().size; |
| 136 | const scale = this.calculateWrapperScale( |
| 137 | docSize, |
| 138 | super.desiredSize() as SerializedVector2<number | null>, |
| 139 | ); |
| 140 | return docSize.mul(scale); |
| 141 | } |
| 142 | |
| 143 | protected getCurrentSize() { |
| 144 | return { |
| 145 | x: this.width.isInitial() ? null : this.width(), |
| 146 | y: this.height.isInitial() ? null : this.height(), |
| 147 | }; |
| 148 | } |
| 149 | |
| 150 | protected calculateWrapperScale( |
nothing calls this directly
no test coverage detected