diff --git a/index.d.ts b/index.d.ts index 260af80..2a4fb53 100644 --- a/index.d.ts +++ b/index.d.ts @@ -2,7 +2,8 @@ declare namespace PIXI { export class SVG extends PIXI.Graphics { - constructor(svg:SVGSVGElement|SVGElement|string); + constructor(svg?:SVGSVGElement|SVGElement|string); + drawSVG(svg:SVGSVGElement|SVGElement|string): this; } } diff --git a/src/SVG.js b/src/SVG.js index 3024dc9..73b3bbc 100644 --- a/src/SVG.js +++ b/src/SVG.js @@ -7,7 +7,7 @@ import color from 'tinycolor2'; * @class SVG * @extends PIXI.Graphics * @memberof PIXI - * @param {SVGSVGElement|SVGElement|string} svg - Inline SVGElement `` or buffer. + * @param {SVGSVGElement|SVGElement|string} [svg] - Inline SVGElement `` or buffer. */ class SVG extends Graphics { @@ -15,6 +15,20 @@ class SVG extends Graphics { super(); + if (svg) + { + this.drawSVG(svg); + } + } + + /** + * Draw an SVG element. + * @method PIXI.SVG#drawSVG + * @param {SVGSVGElement|SVGElement|string} svg - Inline SVGElement `` or buffer. + * @return {PIXI.SVG} Element suitable for chaining. + */ + drawSVG(svg) + { if (typeof svg === 'string') { const div = document.createElement('div'); @@ -30,6 +44,8 @@ class SVG extends Graphics this._svgFill(svg); this._svgChildren(svg.children); + + return this; } /**