MCPcopy
hub / github.com/midrender/revideo / SVG

Class SVG

packages/2d/src/lib/components/SVG.ts:93–797  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91If you're not interested in animating SVG, you can use {@link Img} instead.
92 */
93export 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(

Callers

nothing calls this directly

Calls 4

lazyFunction · 0.90
signalFunction · 0.90
threadableFunction · 0.90
computedFunction · 0.90

Tested by

no test coverage detected