Add defs + tests for Bounce.js

This commit is contained in:
Cherry Ng
2015-10-13 07:43:23 +08:00
parent 3fc1377ce2
commit 1efa53d0d2
2 changed files with 143 additions and 0 deletions
+77
View File
@@ -0,0 +1,77 @@
/// <reference path="./bounce.d.ts" />
/// <reference path="./../jquery/jquery.d.ts" />
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();
}
+66
View File
@@ -0,0 +1,66 @@
// Type definitions for Bounce.js v0.8.2
// Project: http://github.com/tictail/bounce.js
// Definitions by: Cherry <http://github.com/cherrry>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts"/>
declare module 'bounce.js' {
export default Bounce
interface Point2D {
x: number
y: number
}
interface BounceOptions<T> {
from: T
to: T
duration?: number
delay?: number
easing?: string
bounces?: number
stiffness?: number
}
interface AnimationOptions {
loop?: boolean
remove?: boolean
onComplete?: () => void
}
interface SerailizedComponent<T> {
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<Point2D>): Bounce
rotate(options: BounceOptions<number>): Bounce
translate(options: BounceOptions<Point2D>): Bounce
skew(options: BounceOptions<Point2D>): Bounce
serialize(): SerailizedComponent<number|Point2D>[]
deserialize(serailized: SerailizedComponent<number|Point2D>[]): Bounce
applyTo(element: Element, options?: AnimationOptions): void
applyTo(elements: Element[], options?: AnimationOptions): void
applyTo(elements: JQuery, options?: AnimationOptions): JQueryPromise<void>
define(name: string): Bounce
remove(): void
}
}