11import  *  as  React  from  'react' ; 
22import  *  as  PropTypes  from  'prop-types' ; 
3- import  SigPad ,  {  type  Options ,  type  PointGroup ,  type  ToSVGOptions  }  from  'signature_pad' ; 
3+ import  SigPad ,  {  type  FromDataUrlOptions ,   type   Options ,  type  PointGroup ,  type  ToSVGOptions  }  from  'signature_pad' ; 
44import  {  debounce  }  from  'throttle-debounce' ; 
55
66type  Props  =  { 
@@ -251,7 +251,7 @@ class SignaturePad extends React.PureComponent<Props, State> {
251251     * 
252252     * @return  {boolean } 
253253     */ 
254-     isEmpty ( ) : boolean  { 
254+     public   isEmpty ( ) : boolean  { 
255255        return  this . signaturePad . isEmpty ( ) ; 
256256    } 
257257
@@ -260,21 +260,27 @@ class SignaturePad extends React.PureComponent<Props, State> {
260260     * 
261261     * @return  {void } 
262262     */ 
263-     clear ( ) : void   { 
263+     public   clear ( ) : void   { 
264264        this . signaturePad . clear ( ) ; 
265265    } 
266266
267+     /** 
268+      * Redraw the signature. 
269+      *  
270+      * @return  {void } 
271+      */ 
272+     public  redraw ( ) : void   { 
273+         this . signaturePad . redraw ( ) ; 
274+     } 
275+ 
267276    /** 
268277     * Draw a signature from a data URL. 
269278     * 
270279     * @param  {string } dataUrl 
271280     * @param  {object } options 
272281     * @return  {void } 
273282     */ 
274-     fromDataURL ( 
275-         dataUrl : string , 
276-         options : Partial < {  ratio : number ;  width : number ;  height : number ;  xOffset : number ;  yOffset : number  } >  =  { } , 
277-     ) : void   { 
283+     public  fromDataURL ( dataUrl : string ,  options : FromDataUrlOptions  =  { } ) : void   { 
278284        this . signaturePad . fromDataURL ( dataUrl ,  options ) ; 
279285    } 
280286
@@ -285,10 +291,21 @@ class SignaturePad extends React.PureComponent<Props, State> {
285291     * @param  {?number } encoderOptions 
286292     * @return  {string } 
287293     */ 
288-     toDataURL ( type ?: string ,  encoderOptions ?: number ) : string  { 
294+     public   toDataURL ( type ?: string ,  encoderOptions ?: number ) : string  { 
289295        return  this . signaturePad . toDataURL ( type ,  encoderOptions ) ; 
290296    } 
291297
298+     /** 
299+      * Get the signature data as an SVG data URL. 
300+      * 
301+      * @param  {string } mime 
302+      * @param  {?ToSVGOptions } encoderOptions 
303+      * @return  {string } 
304+      */ 
305+     public  toSvgDataUrl ( encoderOptions ?: ToSVGOptions ) : string  { 
306+         return  this . signaturePad . toDataURL ( 'image/svg+xml' ,  encoderOptions ) ; 
307+     } 
308+ 
292309    /** 
293310     * Get the signature data as an SVG string without converting to base64. 
294311     * 
@@ -365,12 +382,6 @@ class SignaturePad extends React.PureComponent<Props, State> {
365382
366383        if  ( width  ===  canvasWidth  &&  height  ===  canvasHeight )  return ; 
367384
368-         let  data ; 
369- 
370-         if  ( this . props . redrawOnResize  &&  this . signaturePad  &&  ! this . signaturePad . isEmpty ( ) )  { 
371-             data  =  this . signaturePad . toDataURL ( ) ; 
372-         } 
373- 
374385        canvas . width  =  width ; 
375386        canvas . height  =  height ; 
376387
@@ -382,10 +393,8 @@ class SignaturePad extends React.PureComponent<Props, State> {
382393            ctx . scale ( ratio ,  ratio ) ; 
383394        } 
384395
385-         if  ( data )  { 
386-             this . signaturePad . fromDataURL ( data ) ; 
387-         }  else  if  ( this . signaturePad )  { 
388-             this . signaturePad . clear ( ) ; 
396+         if  ( this . props . redrawOnResize  &&  this . signaturePad )  { 
397+             this . redraw ( ) ; 
389398        } 
390399    } 
391400
0 commit comments