diff --git a/types/mapbox__shelf-pack/index.d.ts b/types/mapbox__shelf-pack/index.d.ts new file mode 100644 index 0000000000..3ef3ec3507 --- /dev/null +++ b/types/mapbox__shelf-pack/index.d.ts @@ -0,0 +1,59 @@ +// Type definitions for @mapbox/shelf-pack 3.0 +// Project: https://github.com/mapbox/shelf-pack +// Definitions by: Gyusun Yeom +// 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, 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; + } + } +} diff --git a/types/mapbox__shelf-pack/mapbox__shelf-pack-tests.ts b/types/mapbox__shelf-pack/mapbox__shelf-pack-tests.ts new file mode 100644 index 0000000000..3baff984cb --- /dev/null +++ b/types/mapbox__shelf-pack/mapbox__shelf-pack-tests.ts @@ -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); diff --git a/types/mapbox__shelf-pack/tsconfig.json b/types/mapbox__shelf-pack/tsconfig.json new file mode 100644 index 0000000000..540d660492 --- /dev/null +++ b/types/mapbox__shelf-pack/tsconfig.json @@ -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" + ] +} diff --git a/types/mapbox__shelf-pack/tslint.json b/types/mapbox__shelf-pack/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/mapbox__shelf-pack/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }