-
Notifications
You must be signed in to change notification settings - Fork 143
/
index.d.ts
198 lines (171 loc) · 4.21 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* main declaration file
*
* @author zakaria harti
*/
/**
* configuration object of the MagicGrid constructor
*/
export interface MagicGridProps {
container: string | HTMLElement;
static?: boolean;
items?: number;
gutter?: number;
maxColumns?: number;
useMin?: boolean;
useTransform?: boolean;
animate?: boolean;
center?: boolean;
}
/**
* Listener class
*/
declare class Listener {
id: number;
event: string;
handler: (payload?: any) => void;
constructor(id: number, event: string, handler: (payload?: any) => void);
}
/**
* EventEmitter class
*/
declare class EventEmitter {
listeners: Array<Listener>;
private idCounter: number;
constructor();
removeListener(id: number): boolean;
addListener(event: string, handler: (payload?: any) => void): number;
emit(event: string, payload?: any): void;
}
/**
* MagicGrid class
*/
declare class MagicGrid extends EventEmitter {
container: HTMLElement;
containerClass: string;
static: boolean;
size: number;
gutter: number;
maxColumns: number | false;
useMin: boolean;
useTransform: boolean;
animate: boolean;
center: boolean;
styledItems: Set<HTMLElement>;
resizeObserver: ResizeObserver | null;
isPositioning: boolean;
/**
* class constructor
*
* @param {MagicGridProps} config
*/
constructor(config: MagicGridProps);
/**
* Set a new container. Useful in cases where
* the container reference changes for any reason.
*
* @param container
*/
setContainer(container: HTMLElement);
/**
* Positions all the items and
* repositions them whenever the
* window size changes.
*
* @returns {void}
*/
listen(): void;
/**
* Position each item in the container
* based on their corresponding columns
* values.
*
* @returns {void}
*/
positionItems(): void;
/**
* Checks if every item has been loaded
* in the dom.
*
* @return {boolean} true if every item is present
*/
ready(): boolean;
/**
* Initializes styles
*
* @private
*/
private initStyles(): void;
/**
* Gets a collection of all items in a grid.
*
* @return {HTMLCollection}
* @private
*/
private items(): HTMLCollection;
/**
* Calculates the width of a column.
*
* @return {number} width of a column in the grid
* @private
*/
private colWidth(): number;
/**
* Initializes an array of empty columns
* and calculates the leftover whitespace.
*
* @return {{cols: Array<object>, wSpace: number}}
* @private
*/
private setup(): { cols: Array<{ height: number; index: number }>; wSpace: number };
/**
* Gets the next available column.
*
* @param cols list of columns
* @param i index of dom element
*
* @return {object} next available column
* @private
*/
private nextCol(cols: Array<{ height: number; index: number }>, i: number): { height: number; index: number };
/**
* Periodically checks that all items
* have been loaded in the dom. Calls
* this.listen() once all the items are
* present.
*
* @private
*/
private getReady(): void;
/**
* Observes changes in the container size and repositions items
* @private
*/
private observeContainerResize(): void;
/**
* Adds a callback for when the grid is ready
* @param callback - function to be called on grid ready
*/
onReady(callback: () => void): number;
/**
* Adds a callback for when positioning is complete
* @param callback - function to be called on positioning complete
*/
onPositionComplete(callback: () => void): number;
}
/**
* Validates the configuration object.
*
* @param config - configuration object
*/
declare function checkParams(config: MagicGridProps): void;
/**
* Finds the shortest column in
* a column list
*
* @param cols - list of columns
*
* @return {object} shortest column
*/
declare function getMin(cols: Array<{ height: number; index: number }>): { height: number; index: number };
export default MagicGrid;