@hydroperx/tiles
Version:
Metro tile layout
157 lines (156 loc) • 3.46 kB
TypeScript
import type { Tiles } from "./Tiles";
import { BaseLayout } from "./BaseLayout";
/**
* Layout.
*/
export declare abstract class Layout {
/**
* Tiles back-reference.
*/
readonly $: Tiles;
/**
* Ordered groups.
*/
readonly groups: LayoutGroup[];
/**
* Constructor.
*/
constructor($: Tiles);
/**
* Rearranges group tiles.
*/
abstract rearrange(): void;
/**
* Snaps location to grid.
*/
abstract snapToGrid(tile: HTMLButtonElement): null | GridSnapResult;
}
/**
* Grid snap result.
*/
export type GridSnapResult = {
/**
* Group ID.
*
* If none, requests an anonymous group.
*/
group?: string;
/**
* X coordinate in small tiles.
*/
x: number;
/**
* Y coordinate in small tiles.
*/
y: number;
};
/**
* Group.
*/
export declare class LayoutGroup {
$: Layout;
id: string;
div: null | HTMLDivElement;
/**
* Unordered tiles.
* @hidden
*/
readonly _tiles: Map<string, LayoutTile>;
/**
* A structure with fine-grained control over tiles.
* @hidden
*/
_layout: BaseLayout;
/**
* Constructor.
*/
constructor($: Layout, id: string, div: null | HTMLDivElement, width: undefined | number, height: undefined | number);
/**
* Returns an immutable unordered list of the contained tiles.
*/
getTiles(): LayoutTile[];
/**
* Returns a specific tile.
*/
getTile(id: string): null | LayoutTile;
/**
* Returns whether a tile exists in this group.
*/
hasTile(id: string): boolean;
/**
* Returns whether the group is empty or not.
*/
isEmpty(): boolean;
/**
* Layout size in small tiles unit (1x1).
*/
getLayoutSize(): {
width: number;
height: number;
};
/**
* Rearranges group tiles and resizes the group's tiles div.
*/
rearrange(): void;
}
/**
* Tile.
*/
export declare class LayoutTile {
readonly id: string;
button: null | HTMLButtonElement;
/**
* Cached tween.
*/
tween: null | gsap.core.Tween;
/**
* Cached indicator for initial position.
*/
positioned: boolean;
/**
* Parent layout group.
*/
$: null | LayoutGroup;
/**
* Cosntructor.
* @param button If `null` indicates this is a placeholder tile.
*/
constructor(id: string, button: null | HTMLButtonElement);
/**
* Attempts to contributes the tile to the layout.
* If `x` and `y` are both given as `null`, then the
* method is guaranteed to always succeed, contributing
* the tile to the best last position.
*/
addTo($: LayoutGroup, x: null | number, y: null | number, width: number, height: number): boolean;
/**
* Removes the tile from the parent `LayoutGroup`.
* This method does not, however, remove the tile
* from the overall state.
*/
remove(): void;
/**
* X coordinate in small tiles.
*/
get x(): number;
/**
* Y coordinate in small tiles.
*/
get y(): number;
/**
* Width in small tiles.
*/
get width(): number;
/**
* Height in small tiles.
*/
get height(): number;
/**
* Moves position.
*/
move(x: number, y: number): boolean;
/**
* Resizes tile.
*/
resize(width: number, height: number): boolean;
}