forked from odrick/free-tex-packer-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
318 lines (306 loc) · 6.52 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
declare module 'free-tex-packer-core' {
export default function pack(
files: Array<{ path: string; contents: Buffer }>,
config?: TexturePackerOptions,
callback?: (files: Array<{ name: string, buffer: Buffer }>, error?: Error) => void,
): void;
export function packAsync(
files: Array<{ path: string; contents: Buffer }>,
config?: TexturePackerOptions,
): Promise<Array<{ name: string, buffer: Buffer }>>;
}
/**
* Trim mode for sprites
*
* @see TexturePackerOptions.trimMode
* @see TexturePackerOptions.allowTrim
*/
export enum TrimMode {
/**
* Remove transparent pixels from sides, but left original frame size
*
* For example:
* Original sprite has size 64x64, after removing transparent pixels its real size will be reduced to 32x28,
* which will be written as frame size, but original frame size will stay the same: 64x64
*/
TRIM = 'trim',
/**
* Remove transparent pixels from sides, and update frame size
*
* For example:
* Original sprite has size 64x64, after removing transparent pixels its real size will be reduced to 32x28,
* which will be written as frame size, and original frame size will be reduced to the same dimensions
*/
CROP = 'crop',
}
/**
* Output atlas texture format
*
* @see TexturePackerOptions.textureFormat
*/
export enum TextureFormat {
PNG = 'png',
JPG = 'jpg',
}
/**
* Atlas packer type.
* There are two implementations which could be used
*
* @see TexturePackerOptions.packer
* @see TexturePackerOptions.packerMethod
* @see MaxRectsBinMethod
* @see MaxRectsPackerMethod
*/
export enum PackerType {
MAX_RECTS_BIN = 'MaxRectsBin',
MAX_RECTS_PACKER = 'MaxRectsPacker',
OPTIMAL_PACKER = 'OptimalPacker'
}
/**
* MaxRectsBin packer method
*
* @see TexturePackerOptions.packerMethod
*/
export enum MaxRectsBinMethod {
BEST_SHORT_SIDE_FIT = 'BestShortSideFit',
BEST_LONG_SIDE_FIT = 'BestLongSideFit',
BEST_AREA_FIT = 'BestAreaFit',
BOTTOM_LEFT_RULE = 'BottomLeftRule',
CONTACT_POINT_RULE = 'ContactPointRule',
}
/**
* MaxRectsPacker packer method
*
* @see TexturePackerOptions.packerMethod
*/
export enum MaxRectsPackerMethod {
SMART = 'Smart',
SQUARE = 'Square',
SMART_SQUARE = 'SmartSquare',
SMART_AREA = 'SmartArea',
SQUARE_AREA = 'SquareArea',
SMART_SQUARE_AREA = 'SmartSquareArea'
}
/**
* Packer exporter type
* Predefined exporter types (supported popular formats)
* Instead of predefined type you could use custom exporter
*
* @see TexturePackerOptions.exporter
* @see PackerExporter
*/
export enum PackerExporterType {
JSON_HASH = 'JsonHash',
JSON_ARRAY = 'JsonArray',
CSS = 'Css',
OLD_CSS = 'OldCss',
PIXI = 'Pixi',
PHASER_HASH = 'PhaserHash',
PHASER_ARRAY = 'PhaserArray',
PHASER3 = 'Phaser3',
XML = 'XML',
STARLING = 'Starling',
COCOS2D = 'Cocos2d',
SPINE = 'Spine',
UNREAL = 'Unreal',
UIKIT = 'UIKit',
UNITY3D = 'Unity3D',
}
/**
* Bitmap filter, applicable to output atlas texture
*
* @see TexturePackerOptions.filter
*/
export enum BitmapFilterType {
GRAYSCALE = 'grayscale',
MASK = 'mask',
NONE = 'none',
}
/**
* Texture packer options
*/
export interface TexturePackerOptions {
/**
* Name of output files.
*
* @default pack-result
*/
textureName?: string;
/**
* Max single texture width in pixels
*
* @default 2048
*/
width?: number;
/**
* Max single texture height in pixels
*
* @default 2048
*/
height?: number;
/**
* Fixed texture size
*
* @default false
*/
fixedSize?: boolean;
/**
* Force power of two textures sizes
*
* @default false
*/
powerOfTwo?: boolean;
/**
* Spaces in pixels around images
*
* @default 0
*/
padding?: number;
/**
* Extrude border pixels size around images
*
* @default 0
*/
extrude?: number;
/**
* Allow image rotation
* @default true
*/
allowRotation?: boolean;
/**
* Allow detect identical images
*
* @default true
*/
detectIdentical?: boolean;
/**
* Allow trim images
*
* @default true
*/
allowTrim?: boolean;
/**
* Trim mode
*
* @default {@link TrimMode.TRIM}
* @see {@link TrimMode}
* @see {@link allowTrim}
*/
trimMode?: TrimMode;
/**
* Threshold alpha value
*
* @default 0
*/
alphaThreshold?: number;
/**
* Remove file extensions from frame names
*
* @default false
*/
removeFileExtension?: boolean;
/**
* Prepend folder name to frame names
*
* @default true
*/
prependFolderName?: boolean;
/**
* Output file format
*
* @default {@link TextureFormat.PNG}
* @see {@link TextureFormat}
*/
textureFormat?: TextureFormat;
/**
* Export texture as base64 string to atlas meta tag
*
* @default false
*/
base64Export?: boolean;
/**
* Scale size and positions in atlas
*
* @default 1
*/
scale?: number;
/**
* Texture scaling method
*
* @default ScaleMethod.BILINEAR
*/
scaleMethod?: ScaleMethod;
/**
* "Tinify" texture using TinyPNG
*
* @default false
*/
tinify?: boolean;
/**
* TinyPNG key
*
* @default empty string
*/
tinifyKey?: string;
/**
* Type of packer
* @see PackerType
* @default {@link PackerType.MAX_RECTS_BIN}
*/
packer?: PackerType;
/**
* Pack method
*
* @default {@link MaxRectsBinMethod.BEST_SHORT_SIDE_FIT}
* @see MaxRectsBinMethod
* @see MaxRectsPackerMethod
*/
packerMethod?: MaxRectsBinMethod | MaxRectsPackerMethod;
/**
* Name of predefined exporter (), or custom exporter (see below)
*
* @default JsonHash
*/
exporter?: PackerExporterType | PackerExporter;
/**
* Bitmap filter type
*
* @see BitmapFilterType
* @default {@link BitmapFilterType.NONE}
*/
filter?: BitmapFilterType;
/**
* External application info.
* Required fields: url and version
*
* @default null
*/
appInfo?: any;
}
export enum ScaleMethod {
BILINEAR = 'BILINEAR',
NEAREST_NEIGHBOR = 'NEAREST_NEIGHBOR',
HERMITE = 'HERMITE',
BEZIER = 'BEZIER',
}
/**
* Texture packer uses {@link http://mustache.github.io/ | mustache} template engine.
* Look at documentation how to create custom exporter:
* {@link https://www.npmjs.com/package/free-tex-packer-core#custom-exporter}
*/
export interface PackerExporter {
/**
* File extension
*/
fileExt: string;
/**
* Path to template file (content could be used instead)
* @see {@link content}
*/
template?: string;
/**
* Template content (template path could be used instead)
* @see {@link template}
*/
content?: string;
}