Merge pull request #17520 from Perlmint/new/mapbox__shelf-pack

add types for @mapbox/shelf-pack
This commit is contained in:
Paul van Brenk
2017-06-27 13:55:48 -07:00
committed by GitHub
4 changed files with 112 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
// Type definitions for @mapbox/shelf-pack 3.0
// Project: https://github.com/mapbox/shelf-pack
// Definitions by: Gyusun Yeom <https://github.com/Perlmint>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// tslint:disable-next-line no-single-declare-module
declare module "@mapbox/shelf-pack" {
export = ShelfPack;
class ShelfPack {
constructor(width?: number, height?: number, options?: ShelfPack.CreateOption);
pack(bins: Array<ShelfPack.RequestShort | ShelfPack.RequestLong>, options?: ShelfPack.PackOption): ShelfPack.Bin[];
packOne(w: number, h: number, id?: ShelfPack.ID): ShelfPack.Bin;
getBin(id: ShelfPack.ID): ShelfPack.Bin;
ref(bin: ShelfPack.Bin): number;
unref(bin: ShelfPack.Bin): number;
clear(): void;
resize(w: number, h: number): boolean;
w: number;
h: number;
}
namespace ShelfPack {
class Bin {
constructor(id: ID, x: number, y: number, w: number, h: number, maxw?: number, maxh?: number);
id: ID;
x: number;
y: number;
w: number;
h: number;
}
type ID = number | string;
interface Request {
id?: ID;
}
interface RequestShort extends Request {
w: number;
h: number;
}
interface RequestLong extends Request {
width: number;
height: number;
}
interface PackOption {
/// If true , the supplied bin objects will be updated inplace with x and y properties
inPlace?: boolean;
}
interface CreateOption {
/// If true , the sprite will automatically grow
autoResize?: boolean;
}
}
}
@@ -0,0 +1,30 @@
import * as ShelfPack from '@mapbox/shelf-pack';
let sprite = new ShelfPack(64, 64);
for (let i = 0; i < 5; i++) {
const bin = sprite.packOne(32, 32);
}
sprite.clear();
sprite.resize(128, 128);
sprite = new ShelfPack(64, 64);
[100, 101, 102].forEach(id => {
const bin = sprite.packOne(16, 16, id);
});
const bin102 = sprite.packOne(16, 16, 102);
const bin101 = sprite.getBin(101);
sprite.ref(bin101);
const bin100 = sprite.getBin(100);
sprite.unref(bin100);
const bin103 = sprite.packOne(16, 15, 103);
sprite.unref(bin103);
const bin104 = sprite.packOne(16, 16, 104);
+22
View File
@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"mapbox__shelf-pack-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }