From 9c9540ea46757f0b02d6bd89fe8b4e37996be650 Mon Sep 17 00:00:00 2001 From: Matt Karl Date: Wed, 27 May 2020 07:05:34 -0700 Subject: [PATCH] Adds new public method to make it easier to reuse Graphics objects --- index.d.ts | 3 ++- src/SVG.js | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) 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; } /**