svg-engine
Version:
Create SVG files in Node.js
80 lines • 3.17 kB
JavaScript
import { SVGInstance } from "../../../node/instance/SVGInstance.js";
import { SVGRectInstance } from "../../instances/SVGRectInstance.js";
import { SVGCircleInstance } from "../../instances/SVGCircleInstance.js";
import { SVGLineInstance } from "../../instances/SVGLineInstance.js";
import { SVGPathInstance } from "../../instances/SVGPathInstance.js";
import { SVGTextInstance } from "../../instances/SVGTextInstance.js";
export class ShapeInstances extends SVGInstance {
addRect(xOrUndefined, yOrUndefined, widthOrUndefined, heightOrUndefined) {
const rect = new SVGRectInstance(this);
if (xOrUndefined !== undefined) {
rect.attr("x", xOrUndefined + "");
}
if (yOrUndefined !== undefined) {
rect.attr("y", yOrUndefined + "");
}
if (widthOrUndefined !== undefined) {
rect.attr("width", widthOrUndefined + "");
}
if (heightOrUndefined !== undefined) {
rect.attr("height", heightOrUndefined + "");
}
this.appendInstance(rect);
return rect;
}
addCircle(cxOrUndefined, cyOrUndefined, radiusOrUndefined) {
const circle = new SVGCircleInstance(this);
if (cxOrUndefined !== undefined) {
circle.attr("cx", cxOrUndefined + "");
}
if (cyOrUndefined !== undefined) {
circle.attr("cy", cyOrUndefined + "");
}
if (radiusOrUndefined !== undefined) {
circle.attr("r", radiusOrUndefined + "");
}
this.appendInstance(circle);
return circle;
}
addLine(x1OrUndefined, y1OrUndefined, x2OrUndefined, y2OrUndefined) {
const line = new SVGLineInstance(this);
if (x1OrUndefined !== undefined) {
line.attr("x1", x1OrUndefined + "");
}
if (y1OrUndefined !== undefined) {
line.attr("y1", y1OrUndefined + "");
}
if (x2OrUndefined !== undefined) {
line.attr("x2", x2OrUndefined + "");
}
if (y2OrUndefined !== undefined) {
line.attr("y2", y2OrUndefined + "");
}
this.appendInstance(line);
return line;
}
addPath(dOrUndefined) {
const path = new SVGPathInstance(this);
if (dOrUndefined !== undefined) {
path.attr("d", dOrUndefined + "");
}
this.appendInstance(path);
return path;
}
addText(xOrTextOrUndefined, yOrUndefined, textOrUndefined) {
const text = new SVGTextInstance(this);
if (typeof xOrTextOrUndefined === "string" && typeof yOrUndefined === "undefined") {
text.text(xOrTextOrUndefined);
}
else if ((typeof xOrTextOrUndefined === "string" || typeof xOrTextOrUndefined === "number") && (typeof yOrUndefined === "string" || typeof yOrUndefined === "number")) {
text.attr("x", xOrTextOrUndefined);
text.attr("y", yOrUndefined);
if (typeof textOrUndefined === "string") {
text.text(textOrUndefined);
}
}
this.appendInstance(text);
return text;
}
}
//# sourceMappingURL=shapeInstances.js.map