From 1efa53d0d2f6a9281d4c5fbe0d069cdc453fb53a Mon Sep 17 00:00:00 2001 From: Cherry Ng Date: Sat, 10 Oct 2015 23:29:12 +0800 Subject: [PATCH] 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 0000000000..bd90bfe4c1 --- /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 0000000000..9ff7c3a088 --- /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 + } +}