From 1efa53d0d2f6a9281d4c5fbe0d069cdc453fb53a Mon Sep 17 00:00:00 2001 From: Cherry Ng Date: Sat, 10 Oct 2015 23:29:12 +0800 Subject: [PATCH 1/3] Add defs + tests for Bounce.js --- bounce.js/bounce-tests.ts | 77 +++++++++++++++++++++++++++++++++++++++ bounce.js/bounce.d.ts | 66 +++++++++++++++++++++++++++++++++ 2 files changed, 143 insertions(+) create mode 100644 bounce.js/bounce-tests.ts create mode 100644 bounce.js/bounce.d.ts diff --git a/bounce.js/bounce-tests.ts b/bounce.js/bounce-tests.ts new file mode 100644 index 000000000..bd90bfe4c --- /dev/null +++ b/bounce.js/bounce-tests.ts @@ -0,0 +1,77 @@ +/// +/// + +import Bounce from 'bounce.js'; +import * as $ from 'jquery'; + +function test_chaining_transformations() { + var bounce = new Bounce(); + bounce + .scale({ + from: { x: 0, y: 0 }, + to: { x: 2, y: 2 }, + duration: 1000 + }) + .rotate({ + from: 0, + to: 360, + delay: 500 + }) + .translate({ + from: { x: 0, y: -100 }, + to: { x: 0, y: 0 }, + stiffness: 1, + bounces: 4 + }) + .skew({ + from: { x: 1, y: 0.8 }, + to: { x: 0.8, y: 1 }, + easing: 'bounce' + }); +} + +function test_serialization() { + var b1 = new Bounce(); + var serialized = b1.serialize(); + var b2 = new Bounce(); + b2.deserialize(serialized); +} + +function test_apply () { + var bounce = new Bounce(); + var element = document.createElement('div'); + bounce.applyTo(element); + bounce.applyTo([element]); + bounce.applyTo($('div')); + + var options = { + loop: true, + remove: true, + onComplete: () => {} + }; + bounce.applyTo(element, options); + bounce.applyTo([element], options); + bounce.applyTo($('div'), options); +} + +function test_apply_promise () { + var bounce = new Bounce(); + var element = document.createElement('div'); + bounce.applyTo($('div')).then(() => {}); + + var options = { + loop: true, + remove: true + }; + bounce.applyTo($('div')).then(() => {}); +} + +function test_define() { + var bounce = new Bounce(); + bounce.define('named-animation'); +} + +function test_remove() { + var bounce = new Bounce(); + bounce.remove(); +} diff --git a/bounce.js/bounce.d.ts b/bounce.js/bounce.d.ts new file mode 100644 index 000000000..9ff7c3a08 --- /dev/null +++ b/bounce.js/bounce.d.ts @@ -0,0 +1,66 @@ +// Type definitions for Bounce.js v0.8.2 +// Project: http://github.com/tictail/bounce.js +// Definitions by: Cherry +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module 'bounce.js' { + export default Bounce + + interface Point2D { + x: number + y: number + } + + interface BounceOptions { + from: T + to: T + duration?: number + delay?: number + easing?: string + bounces?: number + stiffness?: number + } + + interface AnimationOptions { + loop?: boolean + remove?: boolean + onComplete?: () => void + } + + interface SerailizedComponent { + type: string + from: T + to: T + duration: number + delay: number + easing: string + bounces: number + stiffness: number + } + + class Bounce { + static FPS: number + static counter: number + + static isSupported(): boolean + + constructor(); + + scale(options: BounceOptions): Bounce + rotate(options: BounceOptions): Bounce + translate(options: BounceOptions): Bounce + skew(options: BounceOptions): Bounce + + serialize(): SerailizedComponent[] + deserialize(serailized: SerailizedComponent[]): Bounce + + applyTo(element: Element, options?: AnimationOptions): void + applyTo(elements: Element[], options?: AnimationOptions): void + applyTo(elements: JQuery, options?: AnimationOptions): JQueryPromise + + define(name: string): Bounce + remove(): void + } +} From 5fc7b22967d562c19a7155ac7d3f744a714eb8d5 Mon Sep 17 00:00:00 2001 From: Cherry Ng Date: Tue, 13 Oct 2015 07:39:21 +0800 Subject: [PATCH 2/3] Rename bounce.js to bounce --- {bounce.js => bounce}/bounce-tests.ts | 2 +- {bounce.js => bounce}/bounce.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename {bounce.js => bounce}/bounce-tests.ts (98%) rename {bounce.js => bounce}/bounce.d.ts (98%) diff --git a/bounce.js/bounce-tests.ts b/bounce/bounce-tests.ts similarity index 98% rename from bounce.js/bounce-tests.ts rename to bounce/bounce-tests.ts index bd90bfe4c..e8dd64d2b 100644 --- a/bounce.js/bounce-tests.ts +++ b/bounce/bounce-tests.ts @@ -1,7 +1,7 @@ /// /// -import Bounce from 'bounce.js'; +import Bounce from 'bounce'; import * as $ from 'jquery'; function test_chaining_transformations() { diff --git a/bounce.js/bounce.d.ts b/bounce/bounce.d.ts similarity index 98% rename from bounce.js/bounce.d.ts rename to bounce/bounce.d.ts index 9ff7c3a08..562fa210f 100644 --- a/bounce.js/bounce.d.ts +++ b/bounce/bounce.d.ts @@ -5,7 +5,7 @@ /// -declare module 'bounce.js' { +declare module 'bounce' { export default Bounce interface Point2D { From 7053dee09501ac08e2ba1c82dfdc60eacb8e7806 Mon Sep 17 00:00:00 2001 From: Cherry Ng Date: Tue, 13 Oct 2015 07:48:19 +0800 Subject: [PATCH 3/3] Fix module naming --- bounce/bounce-tests.ts | 2 +- bounce/bounce.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bounce/bounce-tests.ts b/bounce/bounce-tests.ts index e8dd64d2b..bd90bfe4c 100644 --- a/bounce/bounce-tests.ts +++ b/bounce/bounce-tests.ts @@ -1,7 +1,7 @@ /// /// -import Bounce from 'bounce'; +import Bounce from 'bounce.js'; import * as $ from 'jquery'; function test_chaining_transformations() { diff --git a/bounce/bounce.d.ts b/bounce/bounce.d.ts index 562fa210f..9ff7c3a08 100644 --- a/bounce/bounce.d.ts +++ b/bounce/bounce.d.ts @@ -5,7 +5,7 @@ /// -declare module 'bounce' { +declare module 'bounce.js' { export default Bounce interface Point2D {