From d2299c54c2837660ab39bfa9a505bba62734015f Mon Sep 17 00:00:00 2001 From: FlashSystems Date: Mon, 12 Mar 2018 21:25:55 +0100 Subject: [PATCH 1/4] The attr method returns a BBox based on the viewBox of the element if "viewBox" is passed as a param value. This update adds a string literal type to handle this use case. --- types/snapsvg/index.d.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index a3397cedaa..f9719af863 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -144,8 +144,9 @@ declare namespace Snap { append(el:Snap.Element):Snap.Element; appendTo(el:Snap.Element):Snap.Element; asPX(attr:string,value?:string):number; //TODO: check what is really returned - attr(param:string):string; - attr(params:{[attr:string]:string|number|boolean|any}):Snap.Element; + attr(param: "viewBox"): BBox; + attr(param: string): string; + attr(params:{[attr:string]:string|number|boolean|BBox|any}):Snap.Element; before(el:Snap.Element):Snap.Element; children(): Snap.Element[]; clone():Snap.Element; @@ -289,7 +290,8 @@ declare namespace Snap { export interface Set { animate(attrs:{[attr:string]:string|number|boolean|any},duration:number,easing?:(num:number)=>number,callback?:()=>void):Snap.Element; animate(...params:Array<{attrs:any,duration:number,easing:(num:number)=>number,callback?:()=>void}>):Snap.Element; - attr(params: {[attr:string]:string|number|boolean|any}): Snap.Element; + attr(params: {[attr:string]:string|number|boolean|BBox|any}): Snap.Element; + attr(param: "viewBox"): BBox; attr(param: string): string; bind(attr: string, callback: Function): Snap.Set; bind(attr:string,element:Snap.Element):Snap.Set; From 059f0bc252923b8d547cd907b8ffd9bb0628f210 Mon Sep 17 00:00:00 2001 From: FlashSystems Date: Mon, 12 Mar 2018 21:27:23 +0100 Subject: [PATCH 2/4] The add and append method accept a set as an input type. --- types/snapsvg/index.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index f9719af863..d937f1dff3 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -136,12 +136,14 @@ declare namespace Snap { export interface Element { add(el:Snap.Element):Snap.Element; + add(el:Snap.Set):Snap.Element; addClass(value:string):Snap.Element; after(el:Snap.Element):Snap.Element; align(el: Snap.Element, way: string):Snap.Element; animate(animation:any):Snap.Element; animate(attrs:{[attr:string]:string|number|boolean|any},duration:number,easing?:(num: number)=> number,callback?:()=>void):Snap.Element; append(el:Snap.Element):Snap.Element; + append(el:Snap.Set):Snap.Element; appendTo(el:Snap.Element):Snap.Element; asPX(attr:string,value?:string):number; //TODO: check what is really returned attr(param: "viewBox"): BBox; From 2c70be4600960b5c3fac15271b5d92068c6036d9 Mon Sep 17 00:00:00 2001 From: FlashSystems Date: Mon, 12 Mar 2018 21:27:55 +0100 Subject: [PATCH 3/4] Added the symbol element to the Paper class. --- types/snapsvg/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index d937f1dff3..489b771752 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -287,6 +287,7 @@ declare namespace Snap { rect(x:number,y:number,width:number,height:number,rx?:number,ry?:number):Snap.Element; text(x:number,y:number,text:string|number):Snap.Element; text(x:number,y:number,text:Array):Snap.Element; + symbol(vbx:number,vby:number,vbw:number,vbh:number):Snap.Element; } export interface Set { From 2d5f11b72c6b0be3b9c3c20aa85d899db2455cc4 Mon Sep 17 00:00:00 2001 From: FlashSystems Date: Wed, 14 Mar 2018 20:03:28 +0100 Subject: [PATCH 4/4] Added test for commit d2299c54, 059f0bc2, 2c70be46. --- types/snapsvg/test/2.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/types/snapsvg/test/2.ts b/types/snapsvg/test/2.ts index 0ab83291bd..5afcf36460 100644 --- a/types/snapsvg/test/2.ts +++ b/types/snapsvg/test/2.ts @@ -125,6 +125,19 @@ function tester6() { console.log(!path.isPointInsideBBox(b3, 50, 50)); } +function tester7() { + var paper = Snap(600, 800); + + Snap.load("http://snapsvg.io/assets/images/logo.svg", (fragment: Snap.Fragment) => { + // viewBox retrieveal + let fragmentViewBox = fragment.select("svg").attr("viewBox"); + let symbol = paper.symbol(fragmentViewBox.x, fragmentViewBox.y, fragmentViewBox.width, fragmentViewBox.height); + + symbol.add(fragment.selectAll("svg *")); + symbol.toDefs(); + }); +} + //$(function () { // tester1(); //}); @@ -134,3 +147,4 @@ function tester6() { //tester4(); //tester5(); //tester6(); +//tester7();