From 511c202dce506ae593082c8295005df075180d26 Mon Sep 17 00:00:00 2001 From: Terry Mun Date: Fri, 4 Jan 2019 20:59:58 +0100 Subject: [PATCH 1/8] Exporting the Snap.set() function, added new tests --- types/snapsvg/index.d.ts | 6 ++- types/snapsvg/test/4.ts | 92 +++++++++++++++++++++++++++++++++++++ types/snapsvg/tsconfig.json | 3 +- 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 types/snapsvg/test/4.ts diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index 85f1eda7b8..8c2e22ce73 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -1,6 +1,9 @@ // Type definitions for Snap-SVG 0.4.1 // Project: https://github.com/adobe-webplatform/Snap.svg -// Definitions by: Lars Klein , Mattanja Kern , Andrey Kurdyumov +// Definitions by: Lars Klein , +// Mattanja Kern , +// Andrey Kurdyumov , +// Terry Mun // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -31,6 +34,7 @@ declare namespace Snap { export function plugin(f:Function):void; export function select(query:string):Snap.Element; export function selectAll(query:string):any; + export function set(...args:Snap.Element[]): Snap.Set; export function snapTo(values:Array|number,value:number,tolerance?:number):number; export function animate(from:number|number[],to:number|number[],updater:(n:number)=>void,duration:number,easing?:(num:number)=>number,callback?:()=>void):mina.MinaAnimation; diff --git a/types/snapsvg/test/4.ts b/types/snapsvg/test/4.ts new file mode 100644 index 0000000000..fe15e6110f --- /dev/null +++ b/types/snapsvg/test/4.ts @@ -0,0 +1,92 @@ +// Tests by Terry Mun +// Checks that Snap.set() is properly typed + +const s = Snap(200, 500); +s.attr({ + viewBox: '0 0 200 500' +}); + +// Create multiple elements to be added to set +const rect1 = s.rect(0,0,50,50); +const rect2 = s.rect(0,100,50,50); +const rect3 = s.rect(0,200,50,50); +const rect4 = s.rect(0,300,50,50); +let rect5 = null; + +// Create new set +const rectSet = Snap.set(rect1, rect2); + +// Add missing rectangles to set +rectSet.push(rect3, rect4); + +// Set all attributes +rectSet.attr({ fill: 'steelblue' }); + +// Animate all elements in set +function animateTest() { + return new Promise(resolve => { + rectSet.animate({ x: 50 }, 500, mina.bounce, resolve); + }); +} + +// Animate elements individually +function forEachTest() { + const colors = ['red', 'green', 'blue']; + return new Promise(resolve => { + rectSet.forEach((element, idx) => element.attr({ fill: colors[idx] || '#aaa' })); + resolve(); + }); +} + +// Exclude rect4 from set +function excludeTest() { + return new Promise(resolve => { + rectSet.exclude(rect4); + rectSet.animate({ x: 100 }, 500, mina.bounce, resolve); + }); +} + +// Remove rect2 from set (it has index of 1) +// Add new rect5 to set +async function spliceTest() { + rectSet.splice(1, 1); + rectSet.attr({ fill: '#000' }); + + rect5 = s.rect(100, 400, 50, 50); + rectSet.splice(1, 0, rect5); + return; +} + +// Clear set. Rectangles should not go back to x=0 +function clearTest() { + return new Promise(resolve => { + rectSet.clear(); + + // SHOULD NOT WORK + rectSet.animate({ x: 0 }, 500, mina.bounce, resolve); + + // Re-add rects to set + rectSet.push(rect1, rect2, rect3, rect4, rect5); + resolve(); + }); +} + +// Remove all elements from DOM that are present in set +async function removeTest() { + rectSet.remove(); + return; +} + +// Start test +async function startTest() { + await animateTest(); + await forEachTest(); + await excludeTest(); + await spliceTest(); + await clearTest(); + await removeTest(); + + return; +} + +startTest(); \ No newline at end of file diff --git a/types/snapsvg/tsconfig.json b/types/snapsvg/tsconfig.json index 7ee69cd259..23101593c7 100644 --- a/types/snapsvg/tsconfig.json +++ b/types/snapsvg/tsconfig.json @@ -21,6 +21,7 @@ "index.d.ts", "test/1.ts", "test/2.ts", - "test/3.ts" + "test/3.ts", + "test/4.ts" ] } \ No newline at end of file From e7f993ee3e429253b381d1a51c849ce6e4bc3cdc Mon Sep 17 00:00:00 2001 From: Terry Mun Date: Fri, 4 Jan 2019 21:08:00 +0100 Subject: [PATCH 2/8] Updated SnapSVG version to 0.5.1 --- types/snapsvg/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index 8c2e22ce73..7a05c8d0bc 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for Snap-SVG 0.4.1 +// Type definitions for Snap-SVG 0.5.1 // Project: https://github.com/adobe-webplatform/Snap.svg // Definitions by: Lars Klein , // Mattanja Kern , From b40e204bbf8ef4bb74e6fd482e835f85315ec19c Mon Sep 17 00:00:00 2001 From: Terry Mun Date: Fri, 4 Jan 2019 21:31:10 +0100 Subject: [PATCH 3/8] Further updated `Snap.set()` typings, fixed issues with scoping in test file --- types/snapsvg/index.d.ts | 12 +-- types/snapsvg/test/4.ts | 160 ++++++++++++++++++++------------------- 2 files changed, 87 insertions(+), 85 deletions(-) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index 7a05c8d0bc..0931ceda65 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -303,9 +303,9 @@ 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|BBox|any}): Snap.Element; + animate(attrs:{[attr:string]:string|number|boolean|any},duration:number,easing?:(num:number)=>number,callback?:()=>void):Snap.Set; + animate(...params:Array<{attrs:any,duration:number,easing:(num:number)=>number,callback?:()=>void}>):Snap.Set; + attr(params: {[attr:string]:string|number|boolean|BBox|any}): Snap.Set; attr(param: "viewBox"): BBox; attr(param: string): string; bind(attr: string, callback: Function): Snap.Set; @@ -315,10 +315,10 @@ declare namespace Snap { exclude(element:Snap.Element):boolean; forEach(callback:Function,thisArg?:Object):Snap.Set; pop():Snap.Element; - push(el:Snap.Element):Snap.Element; - push(els:Snap.Element[]):Snap.Element; + push(el:Snap.Element):Snap.Set; + push(...els:Snap.element[]):Snap.Set; remove(): Snap.Set; - splice(index:number,count:number,insertion?:Object[]):Snap.Element[]; + splice(index:number,count:number,...insertion:Snap.Element[]):Snap.Set; } interface Filter { diff --git a/types/snapsvg/test/4.ts b/types/snapsvg/test/4.ts index fe15e6110f..6e7e0728f2 100644 --- a/types/snapsvg/test/4.ts +++ b/types/snapsvg/test/4.ts @@ -1,92 +1,94 @@ -// Tests by Terry Mun -// Checks that Snap.set() is properly typed +(() => { + // Tests by Terry Mun + // Checks that Snap.set() is properly typed -const s = Snap(200, 500); -s.attr({ - viewBox: '0 0 200 500' -}); + const s = Snap(200, 500); + s.attr({ + viewBox: '0 0 200 500' + }); -// Create multiple elements to be added to set -const rect1 = s.rect(0,0,50,50); -const rect2 = s.rect(0,100,50,50); -const rect3 = s.rect(0,200,50,50); -const rect4 = s.rect(0,300,50,50); -let rect5 = null; + // Create multiple elements to be added to set + const rect1 = s.rect(0,0,50,50); + const rect2 = s.rect(0,100,50,50); + const rect3 = s.rect(0,200,50,50); + const rect4 = s.rect(0,300,50,50); + let rect5: Snap.Element; -// Create new set -const rectSet = Snap.set(rect1, rect2); + // Create new set + const rectSet = Snap.set(rect1, rect2); -// Add missing rectangles to set -rectSet.push(rect3, rect4); + // Add missing rectangles to set + rectSet.push(rect3, rect4); -// Set all attributes -rectSet.attr({ fill: 'steelblue' }); + // Set all attributes + rectSet.attr({ fill: 'steelblue' }); -// Animate all elements in set -function animateTest() { - return new Promise(resolve => { - rectSet.animate({ x: 50 }, 500, mina.bounce, resolve); - }); -} + // Animate all elements in set + function animateTest() { + return new Promise(resolve => { + rectSet.animate({ x: 50 }, 500, mina.bounce, resolve); + }); + } -// Animate elements individually -function forEachTest() { - const colors = ['red', 'green', 'blue']; - return new Promise(resolve => { - rectSet.forEach((element, idx) => element.attr({ fill: colors[idx] || '#aaa' })); - resolve(); - }); -} + // Animate elements individually + function forEachTest() { + const colors = ['red', 'green', 'blue']; + return new Promise(resolve => { + rectSet.forEach((element, idx) => element.attr({ fill: colors[idx] || '#aaa' })); + resolve(); + }); + } -// Exclude rect4 from set -function excludeTest() { - return new Promise(resolve => { - rectSet.exclude(rect4); - rectSet.animate({ x: 100 }, 500, mina.bounce, resolve); - }); -} + // Exclude rect4 from set + function excludeTest() { + return new Promise(resolve => { + rectSet.exclude(rect4); + rectSet.animate({ x: 100 }, 500, mina.bounce, resolve); + }); + } -// Remove rect2 from set (it has index of 1) -// Add new rect5 to set -async function spliceTest() { - rectSet.splice(1, 1); - rectSet.attr({ fill: '#000' }); - - rect5 = s.rect(100, 400, 50, 50); - rectSet.splice(1, 0, rect5); - return; -} + // Remove rect2 from set (it has index of 1) + // Add new rect5 to set + async function spliceTest() { + rectSet.splice(1, 1); + rectSet.attr({ fill: '#000' }); + + rect5 = s.rect(100, 400, 50, 50); + rectSet.splice(1, 0, rect5); + return; + } -// Clear set. Rectangles should not go back to x=0 -function clearTest() { - return new Promise(resolve => { - rectSet.clear(); - - // SHOULD NOT WORK - rectSet.animate({ x: 0 }, 500, mina.bounce, resolve); - - // Re-add rects to set - rectSet.push(rect1, rect2, rect3, rect4, rect5); - resolve(); - }); -} + // Clear set. Rectangles should not go back to x=0 + function clearTest() { + return new Promise(resolve => { + rectSet.clear(); + + // SHOULD NOT WORK + rectSet.animate({ x: 0 }, 500, mina.bounce, resolve); + + // Re-add rects to set + rectSet.push(rect1, rect2, rect3, rect4, rect5); + resolve(); + }); + } -// Remove all elements from DOM that are present in set -async function removeTest() { - rectSet.remove(); - return; -} + // Remove all elements from DOM that are present in set + async function removeTest() { + rectSet.remove(); + return; + } -// Start test -async function startTest() { - await animateTest(); - await forEachTest(); - await excludeTest(); - await spliceTest(); - await clearTest(); - await removeTest(); - - return; -} + // Start test + async function startTest() { + await animateTest(); + await forEachTest(); + await excludeTest(); + await spliceTest(); + await clearTest(); + await removeTest(); + + return; + } -startTest(); \ No newline at end of file + startTest(); +})(); \ No newline at end of file From 2ff95235fb829970a733dde7ed516e96ebdd7c4a Mon Sep 17 00:00:00 2001 From: Terry Mun Date: Fri, 4 Jan 2019 21:40:24 +0100 Subject: [PATCH 4/8] Updated typing for callback in `Set.forEach()` --- types/snapsvg/index.d.ts | 4 ++-- types/snapsvg/test/4.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index 0931ceda65..05d69b3d57 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -313,10 +313,10 @@ declare namespace Snap { bind(attr:string,element:Snap.Element,eattr:string):Snap.Set; clear():Snap.Set; exclude(element:Snap.Element):boolean; - forEach(callback:Function,thisArg?:Object):Snap.Set; + forEach(callback:(el:Snap.Element,index?:number)=>void|boolean),thisArg?:Object):Snap.Set; pop():Snap.Element; push(el:Snap.Element):Snap.Set; - push(...els:Snap.element[]):Snap.Set; + push(...els:Snap.Element[]):Snap.Set; remove(): Snap.Set; splice(index:number,count:number,...insertion:Snap.Element[]):Snap.Set; } diff --git a/types/snapsvg/test/4.ts b/types/snapsvg/test/4.ts index 6e7e0728f2..01f3747c5e 100644 --- a/types/snapsvg/test/4.ts +++ b/types/snapsvg/test/4.ts @@ -34,7 +34,7 @@ function forEachTest() { const colors = ['red', 'green', 'blue']; return new Promise(resolve => { - rectSet.forEach((element, idx) => element.attr({ fill: colors[idx] || '#aaa' })); + rectSet.forEach((element,idx) => element.attr({ fill: colors[idx] || '#aaa' })); resolve(); }); } From 66cc864a9a8016ddcf3a84b0d040976981362433 Mon Sep 17 00:00:00 2001 From: Terry Mun Date: Fri, 4 Jan 2019 21:45:37 +0100 Subject: [PATCH 5/8] Removed extraenous closing parenthesis --- types/snapsvg/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index 05d69b3d57..9080b358df 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -313,7 +313,7 @@ declare namespace Snap { bind(attr:string,element:Snap.Element,eattr:string):Snap.Set; clear():Snap.Set; exclude(element:Snap.Element):boolean; - forEach(callback:(el:Snap.Element,index?:number)=>void|boolean),thisArg?:Object):Snap.Set; + forEach(callback:(el:Snap.Element,index?:number)=>void|boolean,thisArg?:Object):Snap.Set; pop():Snap.Element; push(el:Snap.Element):Snap.Set; push(...els:Snap.Element[]):Snap.Set; From 98c484fd96d6b6e05058d77798775be339ac3cd5 Mon Sep 17 00:00:00 2001 From: Terry Mun Date: Fri, 4 Jan 2019 21:56:12 +0100 Subject: [PATCH 6/8] Added minimum requirement for TS2.1, fixed test --- types/snapsvg/index.d.ts | 1 + types/snapsvg/test/4.ts | 180 +++++++++++++++++++++------------------ 2 files changed, 98 insertions(+), 83 deletions(-) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index 9080b358df..0bd6c573ff 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -5,6 +5,7 @@ // Andrey Kurdyumov , // Terry Mun // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 /// export = Snap; diff --git a/types/snapsvg/test/4.ts b/types/snapsvg/test/4.ts index 01f3747c5e..6fcf8a2a95 100644 --- a/types/snapsvg/test/4.ts +++ b/types/snapsvg/test/4.ts @@ -1,94 +1,108 @@ (() => { - // Tests by Terry Mun - // Checks that Snap.set() is properly typed + // Tests by Terry Mun + // Checks that Snap.set() is properly typed - const s = Snap(200, 500); - s.attr({ - viewBox: '0 0 200 500' + const s = Snap(200, 500); + s.attr({ + viewBox: '0 0 200 500' + }); + + // Create multiple elements to be added to set + const rect1 = s.rect(0, 0, 50, 50); + const rect2 = s.rect(0, 100, 50, 50); + const rect3 = s.rect(0, 200, 50, 50); + const rect4 = s.rect(0, 300, 50, 50); + let rect5: Snap.Element; + + // Create new set + const rectSet = Snap.set(rect1, rect2); + + // Add missing rectangles to set + rectSet.push(rect3, rect4); + + // Set all attributes + rectSet.attr({ + fill: 'steelblue' + }); + + // Animate all elements in set + function animateTest() { + return new Promise(resolve => { + rectSet.animate({ + x: 50 + }, 500, mina.bounce, resolve); + }); + } + + // Animate elements individually + function forEachTest() { + const colors = ['red', 'green', 'blue']; + return new Promise(resolve => { + rectSet.forEach((element, idx) => { + element.attr({ + fill: colors[idx] || '#aaa' + }); + }); + resolve(); + }); + } + + // Exclude rect4 from set + function excludeTest() { + return new Promise(resolve => { + rectSet.exclude(rect4); + rectSet.animate({ + x: 100 + }, 500, mina.bounce, resolve); + }); + } + + // Remove rect2 from set (it has index of 1) + // Add new rect5 to set + async function spliceTest() { + rectSet.splice(1, 1); + rectSet.attr({ + fill: '#000' }); - // Create multiple elements to be added to set - const rect1 = s.rect(0,0,50,50); - const rect2 = s.rect(0,100,50,50); - const rect3 = s.rect(0,200,50,50); - const rect4 = s.rect(0,300,50,50); - let rect5: Snap.Element; + rect5 = s.rect(100, 400, 50, 50); + rectSet.splice(1, 0, rect5); + return; + } - // Create new set - const rectSet = Snap.set(rect1, rect2); + // Clear set. Rectangles should not go back to x=0 + function clearTest() { + return new Promise(resolve => { + rectSet.clear(); - // Add missing rectangles to set - rectSet.push(rect3, rect4); + // SHOULD NOT WORK + rectSet.animate({ + x: 0 + }, 500, mina.bounce, resolve); - // Set all attributes - rectSet.attr({ fill: 'steelblue' }); + // Re-add rects to set + rectSet.push(rect1, rect2, rect3, rect4, rect5); + resolve(); + }); + } - // Animate all elements in set - function animateTest() { - return new Promise(resolve => { - rectSet.animate({ x: 50 }, 500, mina.bounce, resolve); - }); - } + // Remove all elements from DOM that are present in set + async function removeTest() { + rectSet.remove(); + return; + } - // Animate elements individually - function forEachTest() { - const colors = ['red', 'green', 'blue']; - return new Promise(resolve => { - rectSet.forEach((element,idx) => element.attr({ fill: colors[idx] || '#aaa' })); - resolve(); - }); - } + // Start test + async function startTest() { + await animateTest(); + await forEachTest(); + await excludeTest(); + await spliceTest(); + await clearTest(); + await removeTest(); - // Exclude rect4 from set - function excludeTest() { - return new Promise(resolve => { - rectSet.exclude(rect4); - rectSet.animate({ x: 100 }, 500, mina.bounce, resolve); - }); - } + return; + } - // Remove rect2 from set (it has index of 1) - // Add new rect5 to set - async function spliceTest() { - rectSet.splice(1, 1); - rectSet.attr({ fill: '#000' }); - - rect5 = s.rect(100, 400, 50, 50); - rectSet.splice(1, 0, rect5); - return; - } - - // Clear set. Rectangles should not go back to x=0 - function clearTest() { - return new Promise(resolve => { - rectSet.clear(); - - // SHOULD NOT WORK - rectSet.animate({ x: 0 }, 500, mina.bounce, resolve); - - // Re-add rects to set - rectSet.push(rect1, rect2, rect3, rect4, rect5); - resolve(); - }); - } - - // Remove all elements from DOM that are present in set - async function removeTest() { - rectSet.remove(); - return; - } - - // Start test - async function startTest() { - await animateTest(); - await forEachTest(); - await excludeTest(); - await spliceTest(); - await clearTest(); - await removeTest(); - - return; - } - - startTest(); -})(); \ No newline at end of file + startTest(); +})(); From c38f3d2767f154dc0f425541e004ce5ada484f7e Mon Sep 17 00:00:00 2001 From: Terry Mun Date: Sat, 5 Jan 2019 12:53:07 +0100 Subject: [PATCH 7/8] Minor spelling changes, whitespace removal, and improvement to Snap.set() API This commit includes ensuring methods exposed by the Set API is typed in a consistent manner as per documentation: * `.attr()` always returns `Snap.set` * `.getBBox()`, `.insertAfter()` is added --- types/snapsvg/index.d.ts | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index 0bd6c573ff..ca08eb1eff 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -35,7 +35,7 @@ declare namespace Snap { export function plugin(f:Function):void; export function select(query:string):Snap.Element; export function selectAll(query:string):any; - export function set(...args:Snap.Element[]): Snap.Set; + export function set(...els:Snap.Element[]):Snap.Set; export function snapTo(values:Array|number,value:number,tolerance?:number):number; export function animate(from:number|number[],to:number|number[],updater:(n:number)=>void,duration:number,easing?:(num:number)=>number,callback?:()=>void):mina.MinaAnimation; @@ -306,19 +306,21 @@ declare namespace Snap { export interface Set { animate(attrs:{[attr:string]:string|number|boolean|any},duration:number,easing?:(num:number)=>number,callback?:()=>void):Snap.Set; animate(...params:Array<{attrs:any,duration:number,easing:(num:number)=>number,callback?:()=>void}>):Snap.Set; - attr(params: {[attr:string]:string|number|boolean|BBox|any}): Snap.Set; - attr(param: "viewBox"): BBox; - attr(param: string): string; - bind(attr: string, callback: Function): Snap.Set; + attr(params:{[attr:string]:string|number|boolean|BBox|any}):Snap.Set; + attr(param:"viewBox"):Snap.Set; + attr(param:string):Snap.Set; + bind(attr:string,callback:Function):Snap.Set; bind(attr:string,element:Snap.Element):Snap.Set; bind(attr:string,element:Snap.Element,eattr:string):Snap.Set; - clear():Snap.Set; - exclude(element:Snap.Element):boolean; + clear():void; + exclude(el:Snap.Element):boolean; forEach(callback:(el:Snap.Element,index?:number)=>void|boolean,thisArg?:Object):Snap.Set; + getBBox():BBox; + insertAfter():Snap.Set; pop():Snap.Element; push(el:Snap.Element):Snap.Set; push(...els:Snap.Element[]):Snap.Set; - remove(): Snap.Set; + remove():Snap.Set; splice(index:number,count:number,...insertion:Snap.Element[]):Snap.Set; } From 034e6e8e62595317c33ef3a4227be3bc81401c08 Mon Sep 17 00:00:00 2001 From: Terry Mun Date: Mon, 7 Jan 2019 09:40:23 +0100 Subject: [PATCH 8/8] The Set.Animate requires support for optional tuples, TS3.0 required --- types/snapsvg/index.d.ts | 4 ++-- types/snapsvg/test/4.ts | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/types/snapsvg/index.d.ts b/types/snapsvg/index.d.ts index ca08eb1eff..cc9c4f3627 100644 --- a/types/snapsvg/index.d.ts +++ b/types/snapsvg/index.d.ts @@ -5,7 +5,7 @@ // Andrey Kurdyumov , // Terry Mun // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -// TypeScript Version: 2.1 +// TypeScript Version: 3.0 /// export = Snap; @@ -305,7 +305,7 @@ declare namespace Snap { export interface Set { animate(attrs:{[attr:string]:string|number|boolean|any},duration:number,easing?:(num:number)=>number,callback?:()=>void):Snap.Set; - animate(...params:Array<{attrs:any,duration:number,easing:(num:number)=>number,callback?:()=>void}>):Snap.Set; + animate(...attrs:[{[attr:string]:string|number|boolean|any},number?,((num:number)=>number)?,(()=>void)?][]):Snap.Element; attr(params:{[attr:string]:string|number|boolean|BBox|any}):Snap.Set; attr(param:"viewBox"):Snap.Set; attr(param:string):Snap.Set; diff --git a/types/snapsvg/test/4.ts b/types/snapsvg/test/4.ts index 6fcf8a2a95..cfe9b40b14 100644 --- a/types/snapsvg/test/4.ts +++ b/types/snapsvg/test/4.ts @@ -2,7 +2,7 @@ // Tests by Terry Mun // Checks that Snap.set() is properly typed - const s = Snap(200, 500); + const s = Snap(300, 500); s.attr({ viewBox: '0 0 200 500' }); @@ -34,6 +34,18 @@ }); } + // Animate elements individually + function animateMultipleTest() { + return new Promise(resolve => { + rectSet.animate( + [{ x: 100 }, 500, mina.linear], + [{ x: 100 }, 1000, mina.linear], + [{ x: 100 }, 1500, mina.linear], + [{ x: 100 }, 2000, mina.linear, resolve] + ); + }); + } + // Animate elements individually function forEachTest() { const colors = ['red', 'green', 'blue']; @@ -52,7 +64,7 @@ return new Promise(resolve => { rectSet.exclude(rect4); rectSet.animate({ - x: 100 + x: 150 }, 500, mina.bounce, resolve); }); } @@ -95,6 +107,7 @@ // Start test async function startTest() { await animateTest(); + await animateMultipleTest(); await forEachTest(); await excludeTest(); await spliceTest();