@spritecrate/core 0.0.0-stage → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SpriteCrate contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Alexander Norinchak
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,34 @@
1
- # Temporary Holding Version
1
+ # @spritecrate/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Platform-independent RGBA processing, MaxRects packing, compositing, and atlas metadata export. No Node.js, DOM, or image codec dependencies.
4
+
5
+ ```bash
6
+ npm install @spritecrate/core
7
+ ```
8
+
9
+ ```ts
10
+ import { pack, exportAtlas } from '@spritecrate/core';
11
+
12
+ const result = pack({
13
+ sprites: [{ id: 'pixel', width: 1, height: 1, pixels: new Uint8Array([255, 0, 0, 255]) }],
14
+ });
15
+ const descriptions = exportAtlas(result.pages, 'phaser4');
16
+ ```
17
+
18
+ Pages contain raw RGBA bytes. Use @spritecrate/node for PNG codecs and file input.
19
+
20
+ ## Documentation
21
+
22
+ - [Project README](https://github.com/iulo/spritecrate#readme)
23
+ - [简体中文](https://github.com/iulo/spritecrate/blob/main/README_CN.md)
24
+ - [Configuration](https://github.com/iulo/spritecrate/blob/main/docs/configuration.md)
25
+
26
+ Based in part on [odrick/free-tex-packer-core](https://github.com/odrick/free-tex-packer-core). Adapted portions retain the original attribution; see THIRD_PARTY_NOTICES.md and LICENSES.
27
+
28
+ ## License
29
+
30
+ MIT © SpriteCrate contributors.
31
+
32
+ ## Export targets
33
+
34
+ Built-in formats: `phaser4` (primary), `phaser3`, `pixijs`, `cocos2d`, `json-hash`, and `json-array`. Phaser and PixiJS have WebGL rendering checks; Cocos plist has metadata/pixel reconstruction tests, with editor/runtime validation pending. See the [framework guide](https://github.com/iulo/spritecrate/blob/main/docs/frameworks.md).
@@ -0,0 +1,8 @@
1
+ # Third-party notices
2
+
3
+ Contains or depends on a TypeScript adaptation of MaxRectsBin from free-tex-packer-core,
4
+ commit f918f61569e669df61825ec1040540f1d8470acb.
5
+ Copyright (c) 2018 Alexander Norinchak, MIT.
6
+ See LICENSES/free-tex-packer-MIT.txt.
7
+
8
+ Upstream: https://github.com/odrick/free-tex-packer-core
@@ -0,0 +1,88 @@
1
+ interface Sprite {
2
+ id: string;
3
+ width: number;
4
+ height: number;
5
+ /** Straight-alpha, row-major sRGB RGBA, four bytes per pixel. */
6
+ pixels: Uint8Array;
7
+ }
8
+ interface Rect {
9
+ x: number;
10
+ y: number;
11
+ w: number;
12
+ h: number;
13
+ }
14
+ interface Size {
15
+ w: number;
16
+ h: number;
17
+ }
18
+ interface AtlasOptions {
19
+ name?: string;
20
+ maxWidth?: number;
21
+ maxHeight?: number;
22
+ /** best searches sizes and heuristics; fast preserves the single-pass BSSF layout. */
23
+ packMode?: "fast" | "best";
24
+ fixedSize?: boolean;
25
+ powerOfTwo?: boolean;
26
+ square?: boolean;
27
+ trim?: boolean;
28
+ alphaThreshold?: number;
29
+ deduplicate?: boolean;
30
+ rotate?: boolean;
31
+ padding?: number;
32
+ border?: number;
33
+ extrude?: number;
34
+ }
35
+ type ResolvedOptions = Required<AtlasOptions>;
36
+ interface Frame {
37
+ id: string;
38
+ /** Physical rectangle on the atlas; excludes extrusion. */
39
+ frame: Rect;
40
+ /** Clockwise 90 degrees, if true. */
41
+ rotated: boolean;
42
+ trimmed: boolean;
43
+ sourceSize: Size;
44
+ spriteSourceSize: Rect;
45
+ }
46
+ interface AtlasPage {
47
+ image: string;
48
+ width: number;
49
+ height: number;
50
+ pixels: Uint8Array;
51
+ frames: Frame[];
52
+ }
53
+ interface Report {
54
+ inputCount: number;
55
+ uniqueCount: number;
56
+ pageCount: number;
57
+ /** Unique content area divided by total output area. */
58
+ occupancy: number;
59
+ }
60
+ interface PackResult {
61
+ pages: AtlasPage[];
62
+ report: Report;
63
+ warnings: string[];
64
+ }
65
+ interface OutputFile {
66
+ name: string;
67
+ data: Uint8Array;
68
+ }
69
+ export declare const EXPORT_FORMATS: readonly ["json-hash", "json-array", "phaser4", "phaser3", "pixijs", "cocos2d"];
70
+ type ExportFormat = (typeof EXPORT_FORMATS)[number];
71
+ type Exporter = (pages: readonly AtlasPage[], name: string) => OutputFile[];
72
+ type ErrorCode = "INVALID_OPTIONS" | "INVALID_INPUT" | "DUPLICATE_ID" | "NO_INPUT" | "IMAGE_TOO_LARGE" | "LIMIT_EXCEEDED" | "INPUT_IO" | "DECODE_FAILED" | "OUTPUT_IO";
73
+ export declare class AtlasError extends Error {
74
+ readonly code: ErrorCode;
75
+ readonly details: Readonly<Record<string, unknown>>;
76
+ constructor(code: ErrorCode, message: string, details?: Record<string, unknown>);
77
+ }
78
+ export declare const MAX_IMAGE_PIXELS: number;
79
+ export declare const MAX_TOTAL_PIXELS: number;
80
+ export declare const MAX_SPRITES: number;
81
+ export declare function pack(request: {
82
+ sprites: readonly Sprite[];
83
+ options?: AtlasOptions;
84
+ }): PackResult;
85
+ export declare function exportAtlas(pages: readonly AtlasPage[], format: ExportFormat, name?: string): OutputFile[];
86
+ export declare function resolveOptions(options?: AtlasOptions): ResolvedOptions;
87
+ export declare const VERSION: string;
88
+ export type { AtlasOptions, AtlasPage, ErrorCode, ExportFormat, Exporter, Frame, OutputFile, PackResult, Rect, Report, ResolvedOptions, Size, Sprite };
package/dist/index.js ADDED
@@ -0,0 +1,609 @@
1
+ // src/model.ts
2
+ const EXPORT_FORMATS = [
3
+ "json-hash",
4
+ "json-array",
5
+ "phaser4",
6
+ "phaser3",
7
+ "pixijs",
8
+ "cocos2d"
9
+ ];
10
+ var AtlasError = class extends Error {
11
+ code;
12
+ details;
13
+ constructor(code, message, details = {}) {
14
+ super(message);
15
+ this.name = "AtlasError";
16
+ this.code = code;
17
+ this.details = details;
18
+ }
19
+ };
20
+ const MAX_IMAGE_PIXELS = 16777216;
21
+ const MAX_TOTAL_PIXELS = 67108864;
22
+ const MAX_SPRITES = 1e4;
23
+ function compareIds(a, b) {
24
+ return a < b ? -1 : a > b ? 1 : 0;
25
+ }
26
+ // src/options.ts
27
+ const defaults = {
28
+ name: "atlas",
29
+ maxWidth: 2048,
30
+ maxHeight: 2048,
31
+ packMode: "best",
32
+ fixedSize: false,
33
+ powerOfTwo: false,
34
+ square: false,
35
+ trim: true,
36
+ alphaThreshold: 0,
37
+ deduplicate: true,
38
+ rotate: false,
39
+ padding: 2,
40
+ border: 0,
41
+ extrude: 1
42
+ };
43
+ function resolveOptions(options = {}) {
44
+ if (options === null || typeof options !== "object" || Array.isArray(options)) throw new AtlasError("INVALID_OPTIONS", "atlas must be an object");
45
+ for (const key of Object.keys(options)) if (!Object.hasOwn(defaults, key)) throw new AtlasError("INVALID_OPTIONS", `Unknown atlas option: ${key}`);
46
+ const resolved = {
47
+ ...defaults,
48
+ ...options
49
+ };
50
+ if (resolved.packMode !== "fast" && resolved.packMode !== "best") throw new AtlasError("INVALID_OPTIONS", "packMode must be fast or best");
51
+ for (const key of [
52
+ "maxWidth",
53
+ "maxHeight",
54
+ "padding",
55
+ "border",
56
+ "extrude",
57
+ "alphaThreshold"
58
+ ]) {
59
+ const value = resolved[key];
60
+ const min = key === "maxWidth" || key === "maxHeight" ? 1 : 0;
61
+ const max = key === "alphaThreshold" ? 255 : 8192;
62
+ if (!Number.isSafeInteger(value) || value < min || value > max) throw new AtlasError("INVALID_OPTIONS", `${key} must be an integer in [${min}, ${max}]`);
63
+ }
64
+ for (const key of [
65
+ "fixedSize",
66
+ "powerOfTwo",
67
+ "square",
68
+ "trim",
69
+ "deduplicate",
70
+ "rotate"
71
+ ]) if (typeof resolved[key] !== "boolean") throw new AtlasError("INVALID_OPTIONS", `${key} must be boolean`);
72
+ if (typeof resolved.name !== "string" || !/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(resolved.name)) throw new AtlasError("INVALID_OPTIONS", "name must be a safe filename stem");
73
+ if (/[. ]$/.test(resolved.name) || /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(resolved.name)) throw new AtlasError("INVALID_OPTIONS", "name must be portable across supported operating systems");
74
+ if (resolved.fixedSize && resolved.square && resolved.maxWidth !== resolved.maxHeight) throw new AtlasError("INVALID_OPTIONS", "A fixed square atlas needs equal dimensions");
75
+ if (resolved.fixedSize && resolved.powerOfTwo && (!isPowerOfTwo(resolved.maxWidth) || !isPowerOfTwo(resolved.maxHeight))) throw new AtlasError("INVALID_OPTIONS", "Fixed dimensions must be powers of two");
76
+ return resolved;
77
+ }
78
+ function isPowerOfTwo(value) {
79
+ return (value & value - 1) === 0;
80
+ }
81
+ function ceilPowerOfTwo(value) {
82
+ return 2 ** Math.ceil(Math.log2(Math.max(1, value)));
83
+ }
84
+ function floorPowerOfTwo(value) {
85
+ return 2 ** Math.floor(Math.log2(value));
86
+ }
87
+ // src/maxrects.ts
88
+ const HEURISTICS = [
89
+ "short-side-fit",
90
+ "long-side-fit",
91
+ "area-fit",
92
+ "bottom-left",
93
+ "contact-point"
94
+ ];
95
+ var MaxRects = class {
96
+ width;
97
+ height;
98
+ heuristic;
99
+ free;
100
+ used = [];
101
+ constructor(width, height, heuristic = "short-side-fit") {
102
+ this.width = width;
103
+ this.height = height;
104
+ this.heuristic = heuristic;
105
+ this.free = [{
106
+ x: 0,
107
+ y: 0,
108
+ w: width,
109
+ h: height
110
+ }];
111
+ }
112
+ score(w, h, rotate, budget) {
113
+ if (budget) {
114
+ const cost = this.free.length * (rotate && w !== h ? 2 : 1) * (this.heuristic === "contact-point" ? this.used.length + 1 : 1);
115
+ if (cost > budget.remaining) {
116
+ budget.remaining = 0;
117
+ return;
118
+ }
119
+ budget.remaining -= cost;
120
+ }
121
+ let best;
122
+ for (const rect of this.free) for (const rotated of rotate && w !== h ? [false, true] : [false]) {
123
+ const width = rotated ? h : w, height = rotated ? w : h;
124
+ if (width > rect.w || height > rect.h) continue;
125
+ const short = Math.min(rect.w - width, rect.h - height);
126
+ const long = Math.max(rect.w - width, rect.h - height);
127
+ let primary = short, secondary = long;
128
+ switch (this.heuristic) {
129
+ case "long-side-fit":
130
+ primary = long;
131
+ secondary = short;
132
+ break;
133
+ case "area-fit":
134
+ primary = rect.w * rect.h - width * height;
135
+ secondary = short;
136
+ break;
137
+ case "bottom-left":
138
+ primary = rect.y + height;
139
+ secondary = rect.x;
140
+ break;
141
+ case "contact-point":
142
+ primary = -this.contact(rect.x, rect.y, width, height);
143
+ secondary = 0;
144
+ }
145
+ const candidate = {
146
+ x: rect.x,
147
+ y: rect.y,
148
+ w: width,
149
+ h: height,
150
+ rotated,
151
+ primary,
152
+ secondary
153
+ };
154
+ if (!best || comparePlacement(candidate, best) < 0) best = candidate;
155
+ }
156
+ return best;
157
+ }
158
+ contact(x, y, w, h) {
159
+ let score = (x === 0 || x + w === this.width ? h : 0) + (y === 0 || y + h === this.height ? w : 0);
160
+ for (const used of this.used) {
161
+ if (used.x + used.w === x || x + w === used.x) score += Math.max(0, Math.min(y + h, used.y + used.h) - Math.max(y, used.y));
162
+ if (used.y + used.h === y || y + h === used.y) score += Math.max(0, Math.min(x + w, used.x + used.w) - Math.max(x, used.x));
163
+ }
164
+ return score;
165
+ }
166
+ place(used) {
167
+ if (this.heuristic === "contact-point") this.used.push(used);
168
+ const next = [];
169
+ for (const free of this.free) {
170
+ if (used.x >= free.x + free.w || used.x + used.w <= free.x || used.y >= free.y + free.h || used.y + used.h <= free.y) {
171
+ next.push(free);
172
+ continue;
173
+ }
174
+ if (used.x > free.x) next.push({
175
+ ...free,
176
+ w: used.x - free.x
177
+ });
178
+ if (used.x + used.w < free.x + free.w) next.push({
179
+ ...free,
180
+ x: used.x + used.w,
181
+ w: free.x + free.w - used.x - used.w
182
+ });
183
+ if (used.y > free.y) next.push({
184
+ ...free,
185
+ h: used.y - free.y
186
+ });
187
+ if (used.y + used.h < free.y + free.h) next.push({
188
+ ...free,
189
+ y: used.y + used.h,
190
+ h: free.y + free.h - used.y - used.h
191
+ });
192
+ }
193
+ this.free = next.filter((a, i) => !next.some((b, j) => i !== j && a.x >= b.x && a.y >= b.y && a.x + a.w <= b.x + b.w && a.y + a.h <= b.y + b.h && (a.x !== b.x || a.y !== b.y || a.w !== b.w || a.h !== b.h || j < i)));
194
+ }
195
+ };
196
+ function comparePlacement(a, b) {
197
+ return a.primary - b.primary || a.secondary - b.secondary || a.y - b.y || a.x - b.x || Number(a.rotated) - Number(b.rotated);
198
+ }
199
+ // src/layout.ts
200
+ const GRID_STEPS = 48;
201
+ const STRATEGY_WORK = [
202
+ 8e6,
203
+ 2e6,
204
+ 2e6,
205
+ 2e6,
206
+ 2e6
207
+ ];
208
+ function fits(item, w, h, options) {
209
+ const iw = item.width + 2 * options.extrude, ih = item.height + 2 * options.extrude;
210
+ w -= 2 * options.border;
211
+ h -= 2 * options.border;
212
+ return iw <= w && ih <= h || options.rotate && ih <= w && iw <= h;
213
+ }
214
+ function dimensions(placed, capW, capH, options) {
215
+ let width = options.fixedSize ? capW : Math.max(...placed.map(({ placement: p }) => p.x + p.w - options.padding)) + 2 * options.border;
216
+ let height = options.fixedSize ? capH : Math.max(...placed.map(({ placement: p }) => p.y + p.h - options.padding)) + 2 * options.border;
217
+ if (options.powerOfTwo) {
218
+ width = ceilPowerOfTwo(width);
219
+ height = ceilPowerOfTwo(height);
220
+ }
221
+ if (options.square) width = height = Math.max(width, height);
222
+ return [width, height];
223
+ }
224
+ function attempt(items, options, capW, capH, heuristic, maxPages = 1e400, budget) {
225
+ if (items.some((item) => !fits(item, capW, capH, options))) return void 0;
226
+ const remaining = [...items], pages = [];
227
+ let area = 0;
228
+ while (remaining.length) {
229
+ if (pages.length === maxPages || budget?.remaining === 0) return void 0;
230
+ const bin = new MaxRects(capW - 2 * options.border + options.padding, capH - 2 * options.border + options.padding, heuristic);
231
+ const placed = [];
232
+ while (remaining.length) {
233
+ let best;
234
+ for (const [index, item] of remaining.entries()) {
235
+ const placement = bin.score(item.width + 2 * options.extrude + options.padding, item.height + 2 * options.extrude + options.padding, options.rotate, budget);
236
+ if (!placement && budget?.remaining === 0) return void 0;
237
+ if (placement && (!best || comparePlacement(placement, best.placement) < 0)) best = {
238
+ item,
239
+ placement,
240
+ index
241
+ };
242
+ }
243
+ if (!best) break;
244
+ bin.place(best.placement);
245
+ placed.push(best);
246
+ remaining.splice(best.index, 1);
247
+ }
248
+ if (!placed.length) return void 0;
249
+ const [width, height] = dimensions(placed, capW, capH, options);
250
+ pages.push({
251
+ width,
252
+ height,
253
+ placed
254
+ });
255
+ area += width * height;
256
+ }
257
+ return {
258
+ pages,
259
+ area,
260
+ capW,
261
+ capH,
262
+ valid: area <= 67108864 && pages.every((page) => page.width * page.height <= 16777216)
263
+ };
264
+ }
265
+ function axis(min, max, powerOfTwo) {
266
+ if (powerOfTwo) {
267
+ const sizes = [];
268
+ for (let value = ceilPowerOfTwo(min); value <= max; value *= 2) sizes.push(value);
269
+ return sizes;
270
+ }
271
+ const values = /* @__PURE__ */ new Set([min, max]);
272
+ const step = Math.max(1, Math.ceil(max / GRID_STEPS));
273
+ for (let value = Math.ceil(min / step) * step; value <= max; value += step) values.add(value);
274
+ return [...values].sort((a, b) => a - b);
275
+ }
276
+ function planLayout(items, options) {
277
+ let capW = options.powerOfTwo ? floorPowerOfTwo(options.maxWidth) : options.maxWidth;
278
+ let capH = options.powerOfTwo ? floorPowerOfTwo(options.maxHeight) : options.maxHeight;
279
+ if (options.square) capW = capH = Math.min(capW, capH);
280
+ const oversized = items.find((item) => !fits(item, capW, capH, options));
281
+ if (oversized) throw new AtlasError("IMAGE_TOO_LARGE", `Sprite cannot fit atlas: ${oversized.aliases[0].id}`, {
282
+ id: oversized.aliases[0].id,
283
+ width: oversized.width,
284
+ height: oversized.height,
285
+ maxWidth: capW,
286
+ maxHeight: capH
287
+ });
288
+ const baseline = attempt(items, options, capW, capH, "short-side-fit");
289
+ if (options.packMode === "fast" || items.length === 1) return baseline.pages;
290
+ let best = baseline;
291
+ const improve = (candidate) => {
292
+ if (!candidate || !candidate.valid) return;
293
+ if (baseline.valid && (candidate.pages.length > baseline.pages.length || candidate.area > baseline.area)) return;
294
+ if (!best.valid || candidate.pages.length < best.pages.length || candidate.pages.length === best.pages.length && candidate.area < best.area) best = candidate;
295
+ };
296
+ const budgets = STRATEGY_WORK.map((remaining) => ({ remaining }));
297
+ for (const [index, heuristic] of HEURISTICS.entries()) if (index) improve(attempt(items, options, capW, capH, heuristic, best.pages.length, budgets[index]));
298
+ if (options.fixedSize) return best.pages;
299
+ const minW = Math.max(...items.map((item) => (options.rotate ? Math.min(item.width, item.height) : item.width) + 2 * options.extrude)) + 2 * options.border;
300
+ const minH = Math.max(...items.map((item) => (options.rotate ? Math.min(item.width, item.height) : item.height) + 2 * options.extrude)) + 2 * options.border;
301
+ const requiredArea = items.reduce((sum, item) => sum + (item.width + 2 * options.extrude) * (item.height + 2 * options.extrude), 0);
302
+ const viable = (w, h) => (w - 2 * options.border) * (h - 2 * options.border) * best.pages.length >= requiredArea && (best.pages.length > 1 || w * h <= best.area * 1.2);
303
+ const widths = axis(options.square ? Math.max(minW, minH) : minW, capW, options.powerOfTwo);
304
+ const heights = axis(minH, capH, options.powerOfTwo);
305
+ const candidates = widths.flatMap((w) => (options.square ? [w] : heights).filter((h) => viable(w, h)).map((h) => [w, h]));
306
+ candidates.sort((a, b) => a[0] * a[1] - b[0] * b[1] || b[0] - a[0]);
307
+ for (const [index, heuristic] of HEURISTICS.entries()) {
308
+ const budget = budgets[index];
309
+ const visited = /* @__PURE__ */ new Set([`${capW},${capH}`]);
310
+ const consider = (w, h) => {
311
+ const key = `${w},${h}`;
312
+ if (visited.has(key) || !viable(w, h)) return;
313
+ visited.add(key);
314
+ improve(attempt(items, options, w, h, heuristic, best.pages.length, budget));
315
+ };
316
+ const reserve = budget.remaining / 4;
317
+ for (const [w, h] of candidates) {
318
+ if (budget.remaining <= reserve) break;
319
+ consider(w, h);
320
+ }
321
+ if (options.powerOfTwo) continue;
322
+ let radiusW = Math.max(1, Math.ceil(capW / GRID_STEPS)), radiusH = Math.max(1, Math.ceil(capH / GRID_STEPS));
323
+ for (let pass = 0; pass < 3 && budget.remaining > 0; pass++) {
324
+ const centerW = best.capW, centerH = best.capH;
325
+ const stepW = Math.max(1, Math.ceil(radiusW / 4)), stepH = Math.max(1, Math.ceil(radiusH / 4));
326
+ for (let w = Math.max(minW, centerW - radiusW); w <= Math.min(capW, centerW + radiusW) && budget.remaining > 0; w += stepW) if (options.square) consider(w, w);
327
+ else for (let h = Math.max(minH, centerH - radiusH); h <= Math.min(capH, centerH + radiusH) && budget.remaining > 0; h += stepH) consider(w, h);
328
+ radiusW = stepW;
329
+ radiusH = stepH;
330
+ }
331
+ }
332
+ return best.pages;
333
+ }
334
+ // src/preprocess.ts
335
+ function prepare(sprites, options) {
336
+ if (!Array.isArray(sprites) || sprites.length === 0) throw new AtlasError("NO_INPUT", "No sprites supplied");
337
+ if (sprites.length > 1e4) throw new AtlasError("LIMIT_EXCEEDED", "Sprite count limit exceeded");
338
+ const ids = /* @__PURE__ */ new Set();
339
+ let total = 0;
340
+ for (const sprite of sprites) {
341
+ if (!sprite || typeof sprite.id !== "string" || !sprite.id || sprite.id.includes("\\") || sprite.id.startsWith("/") || sprite.id.includes("\0") || /^[a-z]:/i.test(sprite.id) || sprite.id.split("/").some((part) => part === ".." || part === "." || !part)) throw new AtlasError("INVALID_INPUT", "Sprite id must be a nonempty relative slash path");
342
+ if (ids.has(sprite.id)) throw new AtlasError("DUPLICATE_ID", `Duplicate sprite id: ${sprite.id}`, { id: sprite.id });
343
+ ids.add(sprite.id);
344
+ if (!Number.isSafeInteger(sprite.width) || !Number.isSafeInteger(sprite.height) || sprite.width < 1 || sprite.height < 1 || sprite.width * sprite.height > 16777216) throw new AtlasError("LIMIT_EXCEEDED", `Invalid or excessive dimensions: ${sprite.id}`, {
345
+ id: sprite.id,
346
+ width: sprite.width,
347
+ height: sprite.height
348
+ });
349
+ if (!(sprite.pixels instanceof Uint8Array) || sprite.pixels.length !== sprite.width * sprite.height * 4) throw new AtlasError("INVALID_INPUT", `Expected width × height × 4 RGBA bytes: ${sprite.id}`, { id: sprite.id });
350
+ total += sprite.width * sprite.height;
351
+ if (total > 67108864) throw new AtlasError("LIMIT_EXCEEDED", "Total input pixel limit exceeded");
352
+ }
353
+ const unique = [];
354
+ const buckets = /* @__PURE__ */ new Map();
355
+ for (const sprite of [...sprites].sort((a, b) => compareIds(a.id, b.id))) {
356
+ const item = crop(sprite, options);
357
+ const hash = hashPixels(item);
358
+ const bucket = buckets.get(hash) ?? [];
359
+ const same = options.deduplicate ? bucket.find((other) => equalPixels(other, item)) : void 0;
360
+ if (same) same.aliases.push(...item.aliases);
361
+ else {
362
+ unique.push(item);
363
+ bucket.push(item);
364
+ buckets.set(hash, bucket);
365
+ }
366
+ }
367
+ return unique;
368
+ }
369
+ function crop(sprite, options) {
370
+ let left = sprite.width, top = sprite.height, right = -1, bottom = -1;
371
+ if (options.trim) {
372
+ for (let y = 0; y < sprite.height; y++) for (let x = 0; x < sprite.width; x++) if (sprite.pixels[(y * sprite.width + x) * 4 + 3] > options.alphaThreshold) {
373
+ left = Math.min(left, x);
374
+ top = Math.min(top, y);
375
+ right = Math.max(right, x);
376
+ bottom = Math.max(bottom, y);
377
+ }
378
+ } else {
379
+ left = 0;
380
+ top = 0;
381
+ right = sprite.width - 1;
382
+ bottom = sprite.height - 1;
383
+ }
384
+ const empty = right < left;
385
+ if (empty) {
386
+ left = 0;
387
+ top = 0;
388
+ right = 0;
389
+ bottom = 0;
390
+ }
391
+ const width = right - left + 1, height = bottom - top + 1;
392
+ const pixels = new Uint8Array(width * height * 4);
393
+ if (!empty) for (let y = 0; y < height; y++) {
394
+ const start = ((top + y) * sprite.width + left) * 4;
395
+ pixels.set(sprite.pixels.subarray(start, start + width * 4), y * width * 4);
396
+ }
397
+ return {
398
+ width,
399
+ height,
400
+ pixels,
401
+ aliases: [{
402
+ id: sprite.id,
403
+ trimmed: left !== 0 || top !== 0 || width !== sprite.width || height !== sprite.height,
404
+ sourceSize: {
405
+ w: sprite.width,
406
+ h: sprite.height
407
+ },
408
+ spriteSourceSize: {
409
+ x: left,
410
+ y: top,
411
+ w: width,
412
+ h: height
413
+ }
414
+ }]
415
+ };
416
+ }
417
+ function hashPixels(item) {
418
+ let hash = Math.imul(item.width ^ 2166136261, 16777619) ^ item.height;
419
+ for (const byte of item.pixels) hash = Math.imul(hash ^ byte, 16777619);
420
+ return hash >>> 0;
421
+ }
422
+ function equalPixels(a, b) {
423
+ return a.width === b.width && a.height === b.height && a.pixels.every((value, i) => value === b.pixels[i]);
424
+ }
425
+ // src/pack.ts
426
+ function pack(request) {
427
+ const options = resolveOptions(request.options);
428
+ const items = prepare(request.sprites, options);
429
+ const pages = [];
430
+ const { border, extrude } = options;
431
+ let outputPixels = 0;
432
+ let contentArea = 0;
433
+ for (const { width, height, placed } of planLayout(items, options)) {
434
+ outputPixels += width * height;
435
+ if (width * height > 16777216 || outputPixels > 67108864) throw new AtlasError("LIMIT_EXCEEDED", "Output pixel limit exceeded", {
436
+ width,
437
+ height
438
+ });
439
+ const page = {
440
+ image: "",
441
+ width,
442
+ height,
443
+ pixels: new Uint8Array(width * height * 4),
444
+ frames: []
445
+ };
446
+ for (const { item, placement: p } of placed) {
447
+ const physicalW = p.rotated ? item.height : item.width;
448
+ const physicalH = p.rotated ? item.width : item.height;
449
+ const x = p.x + border + extrude, y = p.y + border + extrude;
450
+ render(page, item, x, y, physicalW, physicalH, p.rotated, extrude);
451
+ for (const alias of item.aliases) page.frames.push({
452
+ ...alias,
453
+ rotated: p.rotated,
454
+ frame: {
455
+ x,
456
+ y,
457
+ w: physicalW,
458
+ h: physicalH
459
+ }
460
+ });
461
+ contentArea += item.width * item.height;
462
+ }
463
+ page.frames.sort((a, b) => compareIds(a.id, b.id));
464
+ pages.push(page);
465
+ }
466
+ pages.forEach((page, index) => {
467
+ page.image = `${options.name}${pages.length > 1 ? `-${index}` : ""}.png`;
468
+ });
469
+ return {
470
+ pages,
471
+ report: {
472
+ inputCount: request.sprites.length,
473
+ uniqueCount: items.length,
474
+ pageCount: pages.length,
475
+ occupancy: contentArea / outputPixels
476
+ },
477
+ warnings: []
478
+ };
479
+ }
480
+ function render(page, item, x, y, w, h, rotated, extrude) {
481
+ for (let py = -extrude; py < h + extrude; py++) for (let px = -extrude; px < w + extrude; px++) {
482
+ const dx = Math.max(0, Math.min(w - 1, px)), dy = Math.max(0, Math.min(h - 1, py));
483
+ const sx = rotated ? dy : dx;
484
+ const source = ((rotated ? item.height - 1 - dx : dy) * item.width + sx) * 4;
485
+ const target = ((y + py) * page.width + x + px) * 4;
486
+ page.pixels.set(item.pixels.subarray(source, source + 4), target);
487
+ }
488
+ }
489
+ // src/export-cocos.ts
490
+ function xmlText(value) {
491
+ return Array.from(value, (char) => {
492
+ const code = char.codePointAt(0);
493
+ if (code < 32 && code !== 9 && code !== 10 && code !== 13 || code >= 55296 && code <= 57343 || code === 65534 || code === 65535) throw new AtlasError("INVALID_INPUT", "Cocos plist contains a name unsupported by XML 1.0");
494
+ if (char === "&") return "&amp;";
495
+ if (char === "<") return "&lt;";
496
+ if (char === ">") return "&gt;";
497
+ return code >= 127 || code === 9 || code === 10 || code === 13 ? `&#${code};` : char;
498
+ }).join("");
499
+ }
500
+ function plist(value) {
501
+ if (typeof value === "string") return `<string>${xmlText(value)}</string>`;
502
+ if (typeof value === "number") return `<integer>${value}</integer>`;
503
+ if (typeof value === "boolean") return value ? "<true/>" : "<false/>";
504
+ if (Array.isArray(value)) return `<array>${value.map(plist).join("")}</array>`;
505
+ return `<dict>${Object.entries(value).map(([key, item]) => `<key>${xmlText(key)}</key>${plist(item)}`).join("")}</dict>`;
506
+ }
507
+ function exportCocos(pages) {
508
+ return pages.map((page) => {
509
+ const document = `<?xml version="1.0" encoding="UTF-8"?>
510
+ <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
511
+ <plist version="1.0">${plist({
512
+ frames: Object.fromEntries(page.frames.map((frame) => {
513
+ const crop = frame.spriteSourceSize;
514
+ const source = frame.sourceSize;
515
+ const offsetX = crop.x + crop.w / 2 - source.w / 2;
516
+ const offsetY = source.h / 2 - crop.y - crop.h / 2;
517
+ return [frame.id, {
518
+ aliases: [],
519
+ spriteOffset: `{${offsetX},${offsetY}}`,
520
+ spriteSize: `{${crop.w},${crop.h}}`,
521
+ spriteSourceSize: `{${source.w},${source.h}}`,
522
+ textureRect: `{{${frame.frame.x},${frame.frame.y}},{${crop.w},${crop.h}}}`,
523
+ textureRotated: frame.rotated
524
+ }];
525
+ })),
526
+ metadata: {
527
+ format: 3,
528
+ pixelFormat: "RGBA8888",
529
+ premultiplyAlpha: false,
530
+ realTextureFileName: page.image,
531
+ textureFileName: page.image,
532
+ size: `{${page.width},${page.height}}`
533
+ }
534
+ })}</plist>
535
+ `;
536
+ return {
537
+ name: page.image.replace(/\.png$/, ".plist"),
538
+ data: Uint8Array.from(document, (char) => char.charCodeAt(0))
539
+ };
540
+ });
541
+ }
542
+ // src/version.ts
543
+ const VERSION = "0.1.3";
544
+ // src/export.ts
545
+ function frameData(frame) {
546
+ const { id: _id, ...data } = frame;
547
+ return {
548
+ ...data,
549
+ frame: {
550
+ ...frame.frame,
551
+ w: frame.spriteSourceSize.w,
552
+ h: frame.spriteSourceSize.h
553
+ }
554
+ };
555
+ }
556
+ function jsonFile(name, value) {
557
+ const json = `${JSON.stringify(value, null, 2)}\n`.replace(/[\u007f-\uffff]/g, (char) => `\\u${char.charCodeAt(0).toString(16).padStart(4, "0")}`);
558
+ return {
559
+ name,
560
+ data: Uint8Array.from(json, (char) => char.charCodeAt(0))
561
+ };
562
+ }
563
+ function exportAtlas(pages, format, name = "atlas") {
564
+ if (!EXPORT_FORMATS.includes(format)) throw new AtlasError("INVALID_OPTIONS", `Unknown format: ${format}`);
565
+ if (format === "cocos2d") return exportCocos(pages);
566
+ if (format === "phaser4" || format === "phaser3") {
567
+ if (pages.some((page) => page.frames.some((frame) => frame.rotated))) throw new AtlasError("INVALID_OPTIONS", "Phaser export requires unrotated frames");
568
+ return [jsonFile(`${name}.json`, {
569
+ textures: pages.map((page) => ({
570
+ image: page.image,
571
+ format: "RGBA8888",
572
+ size: {
573
+ w: page.width,
574
+ h: page.height
575
+ },
576
+ scale: 1,
577
+ frames: page.frames.map((frame) => ({
578
+ filename: frame.id,
579
+ ...frameData(frame)
580
+ }))
581
+ })),
582
+ meta: {
583
+ app: "SpriteCrate",
584
+ version: VERSION
585
+ }
586
+ })];
587
+ }
588
+ return pages.map((page) => jsonFile(page.image.replace(/\.png$/, ".json"), {
589
+ frames: format === "json-hash" || format === "pixijs" ? Object.fromEntries(page.frames.map((frame) => [frame.id, frameData(frame)])) : page.frames.map((frame) => ({
590
+ filename: frame.id,
591
+ ...frameData(frame)
592
+ })),
593
+ meta: {
594
+ app: "SpriteCrate",
595
+ version: VERSION,
596
+ image: page.image,
597
+ format: "RGBA8888",
598
+ size: {
599
+ w: page.width,
600
+ h: page.height
601
+ },
602
+ scale: 1,
603
+ ...format === "pixijs" && pages.length > 1 ? { related_multi_packs: pages.filter((other) => other !== page).map((other) => other.image.replace(/\.png$/, ".json")) } : {}
604
+ }
605
+ }));
606
+ }
607
+ export { AtlasError, EXPORT_FORMATS, MAX_IMAGE_PIXELS, MAX_SPRITES, MAX_TOTAL_PIXELS, VERSION, exportAtlas, pack, resolveOptions };
608
+
609
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/model.ts","../src/options.ts","../src/maxrects.ts","../src/layout.ts","../src/preprocess.ts","../src/pack.ts","../src/export-cocos.ts","../src/version.ts","../src/export.ts"],"sourcesContent":["export interface Sprite {\n id: string;\n width: number;\n height: number;\n /** Straight-alpha, row-major sRGB RGBA, four bytes per pixel. */\n pixels: Uint8Array;\n}\n\nexport interface Rect {\n x: number;\n y: number;\n w: number;\n h: number;\n}\n\nexport interface Size {\n w: number;\n h: number;\n}\n\nexport interface AtlasOptions {\n name?: string;\n maxWidth?: number;\n maxHeight?: number;\n /** best searches sizes and heuristics; fast preserves the single-pass BSSF layout. */\n packMode?: 'fast' | 'best';\n fixedSize?: boolean;\n powerOfTwo?: boolean;\n square?: boolean;\n trim?: boolean;\n alphaThreshold?: number;\n deduplicate?: boolean;\n rotate?: boolean;\n padding?: number;\n border?: number;\n extrude?: number;\n}\n\nexport type ResolvedOptions = Required<AtlasOptions>;\n\nexport interface Frame {\n id: string;\n /** Physical rectangle on the atlas; excludes extrusion. */\n frame: Rect;\n /** Clockwise 90 degrees, if true. */\n rotated: boolean;\n trimmed: boolean;\n sourceSize: Size;\n spriteSourceSize: Rect;\n}\n\nexport interface AtlasPage {\n image: string;\n width: number;\n height: number;\n pixels: Uint8Array;\n frames: Frame[];\n}\n\nexport interface Report {\n inputCount: number;\n uniqueCount: number;\n pageCount: number;\n /** Unique content area divided by total output area. */\n occupancy: number;\n}\n\nexport interface PackResult {\n pages: AtlasPage[];\n report: Report;\n warnings: string[];\n}\n\nexport interface OutputFile {\n name: string;\n data: Uint8Array;\n}\n\nexport const EXPORT_FORMATS = [\n 'json-hash',\n 'json-array',\n 'phaser4',\n 'phaser3',\n 'pixijs',\n 'cocos2d',\n] as const;\nexport type ExportFormat = (typeof EXPORT_FORMATS)[number];\nexport type Exporter = (pages: readonly AtlasPage[], name: string) => OutputFile[];\n\nexport type ErrorCode =\n | 'INVALID_OPTIONS'\n | 'INVALID_INPUT'\n | 'DUPLICATE_ID'\n | 'NO_INPUT'\n | 'IMAGE_TOO_LARGE'\n | 'LIMIT_EXCEEDED'\n | 'INPUT_IO'\n | 'DECODE_FAILED'\n | 'OUTPUT_IO';\n\nexport class AtlasError extends Error {\n readonly code: ErrorCode;\n readonly details: Readonly<Record<string, unknown>>;\n\n constructor(code: ErrorCode, message: string, details: Record<string, unknown> = {}) {\n super(message);\n this.name = 'AtlasError';\n this.code = code;\n this.details = details;\n }\n}\n\nexport const MAX_IMAGE_PIXELS: number = 16_777_216;\nexport const MAX_TOTAL_PIXELS: number = 67_108_864;\nexport const MAX_SPRITES: number = 10_000;\n\nexport function compareIds(a: string, b: string): number {\n return a < b ? -1 : a > b ? 1 : 0;\n}\n","import { AtlasError } from './model.js';\nimport type { AtlasOptions, ResolvedOptions } from './model.js';\n\nconst defaults: ResolvedOptions = {\n name: 'atlas',\n maxWidth: 2048,\n maxHeight: 2048,\n packMode: 'best',\n fixedSize: false,\n powerOfTwo: false,\n square: false,\n trim: true,\n alphaThreshold: 0,\n deduplicate: true,\n rotate: false,\n padding: 2,\n border: 0,\n extrude: 1,\n};\n\nexport function resolveOptions(options: AtlasOptions = {}): ResolvedOptions {\n if (options === null || typeof options !== 'object' || Array.isArray(options)) {\n throw new AtlasError('INVALID_OPTIONS', 'atlas must be an object');\n }\n for (const key of Object.keys(options)) {\n if (!Object.hasOwn(defaults, key))\n throw new AtlasError('INVALID_OPTIONS', `Unknown atlas option: ${key}`);\n }\n const resolved = { ...defaults, ...options };\n if (resolved.packMode !== 'fast' && resolved.packMode !== 'best')\n throw new AtlasError('INVALID_OPTIONS', 'packMode must be fast or best');\n for (const key of [\n 'maxWidth',\n 'maxHeight',\n 'padding',\n 'border',\n 'extrude',\n 'alphaThreshold',\n ] as const) {\n const value = resolved[key];\n const min = key === 'maxWidth' || key === 'maxHeight' ? 1 : 0;\n const max = key === 'alphaThreshold' ? 255 : 8192;\n if (!Number.isSafeInteger(value) || value < min || value > max) {\n throw new AtlasError('INVALID_OPTIONS', `${key} must be an integer in [${min}, ${max}]`);\n }\n }\n for (const key of [\n 'fixedSize',\n 'powerOfTwo',\n 'square',\n 'trim',\n 'deduplicate',\n 'rotate',\n ] as const) {\n if (typeof resolved[key] !== 'boolean')\n throw new AtlasError('INVALID_OPTIONS', `${key} must be boolean`);\n }\n if (typeof resolved.name !== 'string' || !/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(resolved.name)) {\n throw new AtlasError('INVALID_OPTIONS', 'name must be a safe filename stem');\n }\n if (\n /[. ]$/.test(resolved.name) ||\n /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\\.|$)/i.test(resolved.name)\n ) {\n throw new AtlasError(\n 'INVALID_OPTIONS',\n 'name must be portable across supported operating systems',\n );\n }\n if (resolved.fixedSize && resolved.square && resolved.maxWidth !== resolved.maxHeight) {\n throw new AtlasError('INVALID_OPTIONS', 'A fixed square atlas needs equal dimensions');\n }\n if (\n resolved.fixedSize &&\n resolved.powerOfTwo &&\n (!isPowerOfTwo(resolved.maxWidth) || !isPowerOfTwo(resolved.maxHeight))\n ) {\n throw new AtlasError('INVALID_OPTIONS', 'Fixed dimensions must be powers of two');\n }\n return resolved;\n}\n\nfunction isPowerOfTwo(value: number): boolean {\n return (value & (value - 1)) === 0;\n}\n\nexport function ceilPowerOfTwo(value: number): number {\n return 2 ** Math.ceil(Math.log2(Math.max(1, value)));\n}\n\nexport function floorPowerOfTwo(value: number): number {\n return 2 ** Math.floor(Math.log2(value));\n}\n","/**\n * Adapted from free-tex-packer-core/packers/MaxRectsBin.js\n * f918f61569e669df61825ec1040540f1d8470acb\n * Copyright (c) 2018 Alexander Norinchak. MIT, see ../LICENSES.\n * Stable scoring, explicit physical dimensions and five placement heuristics.\n */\nimport type { Rect } from './model.js';\n\nexport const HEURISTICS = [\n 'short-side-fit',\n 'long-side-fit',\n 'area-fit',\n 'bottom-left',\n 'contact-point',\n] as const;\nexport type Heuristic = (typeof HEURISTICS)[number];\nexport interface SearchBudget {\n remaining: number;\n}\nexport interface Placement extends Rect {\n rotated: boolean;\n primary: number;\n secondary: number;\n}\n\nexport class MaxRects {\n private free: Rect[];\n private used: Rect[] = [];\n\n constructor(\n private width: number,\n private height: number,\n private heuristic: Heuristic = 'short-side-fit',\n ) {\n this.free = [{ x: 0, y: 0, w: width, h: height }];\n }\n\n score(w: number, h: number, rotate: boolean, budget?: SearchBudget): Placement | undefined {\n if (budget) {\n const cost =\n this.free.length *\n (rotate && w !== h ? 2 : 1) *\n (this.heuristic === 'contact-point' ? this.used.length + 1 : 1);\n if (cost > budget.remaining) {\n budget.remaining = 0;\n return undefined;\n }\n budget.remaining -= cost;\n }\n let best: Placement | undefined;\n for (const rect of this.free) {\n for (const rotated of rotate && w !== h ? [false, true] : [false]) {\n const width = rotated ? h : w,\n height = rotated ? w : h;\n if (width > rect.w || height > rect.h) continue;\n const short = Math.min(rect.w - width, rect.h - height);\n const long = Math.max(rect.w - width, rect.h - height);\n let primary = short,\n secondary = long;\n switch (this.heuristic) {\n case 'long-side-fit':\n primary = long;\n secondary = short;\n break;\n case 'area-fit':\n primary = rect.w * rect.h - width * height;\n secondary = short;\n break;\n case 'bottom-left':\n primary = rect.y + height;\n secondary = rect.x;\n break;\n case 'contact-point':\n primary = -this.contact(rect.x, rect.y, width, height);\n secondary = 0;\n break;\n }\n const candidate = {\n x: rect.x,\n y: rect.y,\n w: width,\n h: height,\n rotated,\n primary,\n secondary,\n };\n if (!best || comparePlacement(candidate, best) < 0) best = candidate;\n }\n }\n return best;\n }\n\n private contact(x: number, y: number, w: number, h: number): number {\n let score =\n (x === 0 || x + w === this.width ? h : 0) + (y === 0 || y + h === this.height ? w : 0);\n for (const used of this.used) {\n if (used.x + used.w === x || x + w === used.x)\n score += Math.max(0, Math.min(y + h, used.y + used.h) - Math.max(y, used.y));\n if (used.y + used.h === y || y + h === used.y)\n score += Math.max(0, Math.min(x + w, used.x + used.w) - Math.max(x, used.x));\n }\n return score;\n }\n\n place(used: Rect): void {\n if (this.heuristic === 'contact-point') this.used.push(used);\n const next: Rect[] = [];\n for (const free of this.free) {\n if (\n used.x >= free.x + free.w ||\n used.x + used.w <= free.x ||\n used.y >= free.y + free.h ||\n used.y + used.h <= free.y\n ) {\n next.push(free);\n continue;\n }\n if (used.x > free.x) next.push({ ...free, w: used.x - free.x });\n if (used.x + used.w < free.x + free.w)\n next.push({ ...free, x: used.x + used.w, w: free.x + free.w - used.x - used.w });\n if (used.y > free.y) next.push({ ...free, h: used.y - free.y });\n if (used.y + used.h < free.y + free.h)\n next.push({ ...free, y: used.y + used.h, h: free.y + free.h - used.y - used.h });\n }\n this.free = next.filter(\n (a, i) =>\n !next.some(\n (b, j) =>\n i !== j &&\n a.x >= b.x &&\n a.y >= b.y &&\n a.x + a.w <= b.x + b.w &&\n a.y + a.h <= b.y + b.h &&\n (a.x !== b.x || a.y !== b.y || a.w !== b.w || a.h !== b.h || j < i),\n ),\n );\n }\n}\n\nexport function comparePlacement(a: Placement, b: Placement): number {\n return (\n a.primary - b.primary ||\n a.secondary - b.secondary ||\n a.y - b.y ||\n a.x - b.x ||\n Number(a.rotated) - Number(b.rotated)\n );\n}\n","import { AtlasError, MAX_IMAGE_PIXELS, MAX_TOTAL_PIXELS } from './model.js';\nimport type { ResolvedOptions } from './model.js';\nimport { ceilPowerOfTwo, floorPowerOfTwo } from './options.js';\nimport { MaxRects, HEURISTICS, comparePlacement } from './maxrects.js';\nimport type { Heuristic, Placement, SearchBudget } from './maxrects.js';\nimport type { Prepared } from './preprocess.js';\n\nexport interface Placed {\n item: Prepared;\n placement: Placement;\n}\nexport interface LayoutPage {\n width: number;\n height: number;\n placed: Placed[];\n}\ninterface Plan {\n pages: LayoutPage[];\n area: number;\n valid: boolean;\n capW: number;\n capH: number;\n}\nconst GRID_STEPS = 48;\n// Deterministic scoring-work limits, not wall-clock deadlines. Baseline is never interrupted.\nconst STRATEGY_WORK = [8_000_000, 2_000_000, 2_000_000, 2_000_000, 2_000_000] as const;\n\nfunction fits(item: Prepared, w: number, h: number, options: ResolvedOptions): boolean {\n const iw = item.width + 2 * options.extrude,\n ih = item.height + 2 * options.extrude;\n w -= 2 * options.border;\n h -= 2 * options.border;\n return (iw <= w && ih <= h) || (options.rotate && ih <= w && iw <= h);\n}\n\nfunction dimensions(\n placed: readonly Placed[],\n capW: number,\n capH: number,\n options: ResolvedOptions,\n): [number, number] {\n let width = options.fixedSize\n ? capW\n : Math.max(...placed.map(({ placement: p }) => p.x + p.w - options.padding)) +\n 2 * options.border;\n let height = options.fixedSize\n ? capH\n : Math.max(...placed.map(({ placement: p }) => p.y + p.h - options.padding)) +\n 2 * options.border;\n if (options.powerOfTwo) {\n width = ceilPowerOfTwo(width);\n height = ceilPowerOfTwo(height);\n }\n if (options.square) width = height = Math.max(width, height);\n return [width, height];\n}\n\nfunction attempt(\n items: readonly Prepared[],\n options: ResolvedOptions,\n capW: number,\n capH: number,\n heuristic: Heuristic,\n maxPages = Infinity,\n budget?: SearchBudget,\n): Plan | undefined {\n if (items.some((item) => !fits(item, capW, capH, options))) return undefined;\n const remaining = [...items],\n pages: LayoutPage[] = [];\n let area = 0;\n while (remaining.length) {\n if (pages.length === maxPages || budget?.remaining === 0) return undefined;\n const bin = new MaxRects(\n capW - 2 * options.border + options.padding,\n capH - 2 * options.border + options.padding,\n heuristic,\n );\n const placed: Placed[] = [];\n while (remaining.length) {\n let best: { item: Prepared; placement: Placement; index: number } | undefined;\n for (const [index, item] of remaining.entries()) {\n const placement = bin.score(\n item.width + 2 * options.extrude + options.padding,\n item.height + 2 * options.extrude + options.padding,\n options.rotate,\n budget,\n );\n if (!placement && budget?.remaining === 0) return undefined;\n if (placement && (!best || comparePlacement(placement, best.placement) < 0))\n best = { item, placement, index };\n }\n if (!best) break;\n bin.place(best.placement);\n placed.push(best);\n remaining.splice(best.index, 1);\n }\n if (!placed.length) return undefined;\n const [width, height] = dimensions(placed, capW, capH, options);\n pages.push({ width, height, placed });\n area += width * height;\n }\n return {\n pages,\n area,\n capW,\n capH,\n valid:\n area <= MAX_TOTAL_PIXELS &&\n pages.every((page) => page.width * page.height <= MAX_IMAGE_PIXELS),\n };\n}\n\nfunction axis(min: number, max: number, powerOfTwo: boolean): number[] {\n if (powerOfTwo) {\n const sizes: number[] = [];\n for (let value = ceilPowerOfTwo(min); value <= max; value *= 2) sizes.push(value);\n return sizes;\n }\n const values = new Set([min, max]);\n const step = Math.max(1, Math.ceil(max / GRID_STEPS));\n for (let value = Math.ceil(min / step) * step; value <= max; value += step) values.add(value);\n return [...values].sort((a, b) => a - b);\n}\n\nexport function planLayout(items: readonly Prepared[], options: ResolvedOptions): LayoutPage[] {\n let capW = options.powerOfTwo ? floorPowerOfTwo(options.maxWidth) : options.maxWidth;\n let capH = options.powerOfTwo ? floorPowerOfTwo(options.maxHeight) : options.maxHeight;\n if (options.square) capW = capH = Math.min(capW, capH);\n const oversized = items.find((item) => !fits(item, capW, capH, options));\n if (oversized)\n throw new AtlasError(\n 'IMAGE_TOO_LARGE',\n `Sprite cannot fit atlas: ${oversized.aliases[0]!.id}`,\n {\n id: oversized.aliases[0]!.id,\n width: oversized.width,\n height: oversized.height,\n maxWidth: capW,\n maxHeight: capH,\n },\n );\n const baseline = attempt(items, options, capW, capH, 'short-side-fit')!;\n if (options.packMode === 'fast' || items.length === 1) return baseline.pages;\n let best = baseline;\n const improve = (candidate: Plan | undefined): void => {\n if (!candidate || !candidate.valid) return;\n // Never regress page count or total area against the valid fast baseline.\n if (\n baseline.valid &&\n (candidate.pages.length > baseline.pages.length || candidate.area > baseline.area)\n )\n return;\n if (\n !best.valid ||\n candidate.pages.length < best.pages.length ||\n (candidate.pages.length === best.pages.length && candidate.area < best.area)\n )\n best = candidate;\n };\n const budgets = STRATEGY_WORK.map((remaining) => ({ remaining }));\n for (const [index, heuristic] of HEURISTICS.entries()) {\n if (index)\n improve(attempt(items, options, capW, capH, heuristic, best.pages.length, budgets[index]));\n }\n if (options.fixedSize) return best.pages;\n const minW =\n Math.max(\n ...items.map(\n (item) =>\n (options.rotate ? Math.min(item.width, item.height) : item.width) + 2 * options.extrude,\n ),\n ) +\n 2 * options.border;\n const minH =\n Math.max(\n ...items.map(\n (item) =>\n (options.rotate ? Math.min(item.width, item.height) : item.height) + 2 * options.extrude,\n ),\n ) +\n 2 * options.border;\n const requiredArea = items.reduce(\n (sum, item) => sum + (item.width + 2 * options.extrude) * (item.height + 2 * options.extrude),\n 0,\n );\n const viable = (w: number, h: number): boolean =>\n (w - 2 * options.border) * (h - 2 * options.border) * best.pages.length >= requiredArea &&\n (best.pages.length > 1 || w * h <= best.area * 1.2);\n const widths = axis(options.square ? Math.max(minW, minH) : minW, capW, options.powerOfTwo);\n const heights = axis(minH, capH, options.powerOfTwo);\n const candidates = widths.flatMap((w) =>\n (options.square ? [w] : heights).filter((h) => viable(w, h)).map((h) => [w, h] as const),\n );\n candidates.sort((a, b) => a[0] * a[1] - b[0] * b[1] || b[0] - a[0]);\n for (const [index, heuristic] of HEURISTICS.entries()) {\n const budget = budgets[index]!;\n const visited = new Set<string>([`${capW},${capH}`]);\n const consider = (w: number, h: number): void => {\n const key = `${w},${h}`;\n if (visited.has(key) || !viable(w, h)) return;\n visited.add(key);\n improve(attempt(items, options, w, h, heuristic, best.pages.length, budget));\n };\n const reserve = budget.remaining / 4;\n for (const [w, h] of candidates) {\n if (budget.remaining <= reserve) break;\n consider(w, h);\n }\n if (options.powerOfTwo) continue;\n // Refine around the best cap with successively smaller deterministic steps.\n let radiusW = Math.max(1, Math.ceil(capW / GRID_STEPS)),\n radiusH = Math.max(1, Math.ceil(capH / GRID_STEPS));\n for (let pass = 0; pass < 3 && budget.remaining > 0; pass++) {\n const centerW = best.capW,\n centerH = best.capH;\n const stepW = Math.max(1, Math.ceil(radiusW / 4)),\n stepH = Math.max(1, Math.ceil(radiusH / 4));\n for (\n let w = Math.max(minW, centerW - radiusW);\n w <= Math.min(capW, centerW + radiusW) && budget.remaining > 0;\n w += stepW\n ) {\n if (options.square) consider(w, w);\n else\n for (\n let h = Math.max(minH, centerH - radiusH);\n h <= Math.min(capH, centerH + radiusH) && budget.remaining > 0;\n h += stepH\n )\n consider(w, h);\n }\n radiusW = stepW;\n radiusH = stepH;\n }\n }\n return best.pages;\n}\n","import {\n AtlasError,\n compareIds,\n MAX_IMAGE_PIXELS,\n MAX_TOTAL_PIXELS,\n MAX_SPRITES,\n} from './model.js';\nimport type { Frame, ResolvedOptions, Sprite } from './model.js';\n\nexport interface Prepared {\n width: number;\n height: number;\n pixels: Uint8Array;\n aliases: Omit<Frame, 'frame' | 'rotated'>[];\n}\n\nexport function prepare(sprites: readonly Sprite[], options: ResolvedOptions): Prepared[] {\n if (!Array.isArray(sprites) || sprites.length === 0)\n throw new AtlasError('NO_INPUT', 'No sprites supplied');\n if (sprites.length > MAX_SPRITES)\n throw new AtlasError('LIMIT_EXCEEDED', 'Sprite count limit exceeded');\n const ids = new Set<string>();\n let total = 0;\n for (const sprite of sprites) {\n if (\n !sprite ||\n typeof sprite.id !== 'string' ||\n !sprite.id ||\n sprite.id.includes('\\\\') ||\n sprite.id.startsWith('/') ||\n sprite.id.includes('\\0') ||\n /^[a-z]:/i.test(sprite.id) ||\n sprite.id.split('/').some((part: string) => part === '..' || part === '.' || !part)\n ) {\n throw new AtlasError('INVALID_INPUT', 'Sprite id must be a nonempty relative slash path');\n }\n if (ids.has(sprite.id))\n throw new AtlasError('DUPLICATE_ID', `Duplicate sprite id: ${sprite.id}`, { id: sprite.id });\n ids.add(sprite.id);\n if (\n !Number.isSafeInteger(sprite.width) ||\n !Number.isSafeInteger(sprite.height) ||\n sprite.width < 1 ||\n sprite.height < 1 ||\n sprite.width * sprite.height > MAX_IMAGE_PIXELS\n ) {\n throw new AtlasError('LIMIT_EXCEEDED', `Invalid or excessive dimensions: ${sprite.id}`, {\n id: sprite.id,\n width: sprite.width,\n height: sprite.height,\n });\n }\n if (\n !(sprite.pixels instanceof Uint8Array) ||\n sprite.pixels.length !== sprite.width * sprite.height * 4\n ) {\n throw new AtlasError(\n 'INVALID_INPUT',\n `Expected width × height × 4 RGBA bytes: ${sprite.id}`,\n { id: sprite.id },\n );\n }\n total += sprite.width * sprite.height;\n if (total > MAX_TOTAL_PIXELS)\n throw new AtlasError('LIMIT_EXCEEDED', 'Total input pixel limit exceeded');\n }\n const unique: Prepared[] = [];\n const buckets = new Map<number, Prepared[]>();\n for (const sprite of [...sprites].sort((a, b) => compareIds(a.id, b.id))) {\n const item = crop(sprite, options);\n const hash = hashPixels(item);\n const bucket = buckets.get(hash) ?? [];\n const same = options.deduplicate ? bucket.find((other) => equalPixels(other, item)) : undefined;\n if (same) same.aliases.push(...item.aliases);\n else {\n unique.push(item);\n bucket.push(item);\n buckets.set(hash, bucket);\n }\n }\n return unique;\n}\n\nfunction crop(sprite: Sprite, options: ResolvedOptions): Prepared {\n let left = sprite.width,\n top = sprite.height,\n right = -1,\n bottom = -1;\n if (options.trim) {\n for (let y = 0; y < sprite.height; y++) {\n for (let x = 0; x < sprite.width; x++) {\n if (sprite.pixels[(y * sprite.width + x) * 4 + 3]! > options.alphaThreshold) {\n left = Math.min(left, x);\n top = Math.min(top, y);\n right = Math.max(right, x);\n bottom = Math.max(bottom, y);\n }\n }\n }\n } else {\n left = 0;\n top = 0;\n right = sprite.width - 1;\n bottom = sprite.height - 1;\n }\n const empty = right < left;\n if (empty) {\n left = 0;\n top = 0;\n right = 0;\n bottom = 0;\n }\n const width = right - left + 1,\n height = bottom - top + 1;\n const pixels = new Uint8Array(width * height * 4);\n if (!empty) {\n for (let y = 0; y < height; y++) {\n const start = ((top + y) * sprite.width + left) * 4;\n pixels.set(sprite.pixels.subarray(start, start + width * 4), y * width * 4);\n }\n }\n return {\n width,\n height,\n pixels,\n aliases: [\n {\n id: sprite.id,\n trimmed: left !== 0 || top !== 0 || width !== sprite.width || height !== sprite.height,\n sourceSize: { w: sprite.width, h: sprite.height },\n spriteSourceSize: { x: left, y: top, w: width, h: height },\n },\n ],\n };\n}\n\nfunction hashPixels(item: Prepared): number {\n let hash = Math.imul(item.width ^ 2166136261, 16777619) ^ item.height;\n for (const byte of item.pixels) hash = Math.imul(hash ^ byte, 16777619);\n return hash >>> 0;\n}\n\nfunction equalPixels(a: Prepared, b: Prepared): boolean {\n return (\n a.width === b.width &&\n a.height === b.height &&\n a.pixels.every((value, i) => value === b.pixels[i])\n );\n}\n","import { AtlasError, compareIds, MAX_IMAGE_PIXELS, MAX_TOTAL_PIXELS } from './model.js';\nimport type { AtlasOptions, AtlasPage, PackResult, Sprite } from './model.js';\nimport { resolveOptions } from './options.js';\nimport { planLayout } from './layout.js';\nimport { prepare } from './preprocess.js';\nimport type { Prepared } from './preprocess.js';\n\nexport function pack(request: { sprites: readonly Sprite[]; options?: AtlasOptions }): PackResult {\n const options = resolveOptions(request.options);\n const items = prepare(request.sprites, options);\n const pages: AtlasPage[] = [];\n const { border, extrude } = options;\n let outputPixels = 0;\n let contentArea = 0;\n for (const { width, height, placed } of planLayout(items, options)) {\n outputPixels += width * height;\n if (width * height > MAX_IMAGE_PIXELS || outputPixels > MAX_TOTAL_PIXELS)\n throw new AtlasError('LIMIT_EXCEEDED', 'Output pixel limit exceeded', { width, height });\n const page: AtlasPage = {\n image: '',\n width,\n height,\n pixels: new Uint8Array(width * height * 4),\n frames: [],\n };\n for (const { item, placement: p } of placed) {\n const physicalW = p.rotated ? item.height : item.width;\n const physicalH = p.rotated ? item.width : item.height;\n const x = p.x + border + extrude,\n y = p.y + border + extrude;\n render(page, item, x, y, physicalW, physicalH, p.rotated, extrude);\n for (const alias of item.aliases)\n page.frames.push({\n ...alias,\n rotated: p.rotated,\n frame: { x, y, w: physicalW, h: physicalH },\n });\n contentArea += item.width * item.height;\n }\n page.frames.sort((a, b) => compareIds(a.id, b.id));\n pages.push(page);\n }\n pages.forEach((page, index) => {\n page.image = `${options.name}${pages.length > 1 ? `-${index}` : ''}.png`;\n });\n return {\n pages,\n report: {\n inputCount: request.sprites.length,\n uniqueCount: items.length,\n pageCount: pages.length,\n occupancy: contentArea / outputPixels,\n },\n warnings: [],\n };\n}\n\nfunction render(\n page: AtlasPage,\n item: Prepared,\n x: number,\n y: number,\n w: number,\n h: number,\n rotated: boolean,\n extrude: number,\n): void {\n for (let py = -extrude; py < h + extrude; py++) {\n for (let px = -extrude; px < w + extrude; px++) {\n const dx = Math.max(0, Math.min(w - 1, px)),\n dy = Math.max(0, Math.min(h - 1, py));\n const sx = rotated ? dy : dx,\n sy = rotated ? item.height - 1 - dx : dy;\n const source = (sy * item.width + sx) * 4;\n const target = ((y + py) * page.width + x + px) * 4;\n page.pixels.set(item.pixels.subarray(source, source + 4), target);\n }\n }\n}\n","import { AtlasError } from './model.js';\nimport type { AtlasPage, OutputFile } from './model.js';\n\ntype PlistValue = string | number | boolean | PlistValue[] | { [key: string]: PlistValue };\n\nfunction xmlText(value: string): string {\n return Array.from(value, (char) => {\n const code = char.codePointAt(0)!;\n if (\n (code < 32 && code !== 9 && code !== 10 && code !== 13) ||\n (code >= 0xd800 && code <= 0xdfff) ||\n code === 0xfffe ||\n code === 0xffff\n )\n throw new AtlasError('INVALID_INPUT', 'Cocos plist contains a name unsupported by XML 1.0');\n if (char === '&') return '&amp;';\n if (char === '<') return '&lt;';\n if (char === '>') return '&gt;';\n // ASCII output keeps core independent of TextEncoder and preserves CR in XML.\n return code >= 127 || code === 9 || code === 10 || code === 13 ? `&#${code};` : char;\n }).join('');\n}\n\nfunction plist(value: PlistValue): string {\n if (typeof value === 'string') return `<string>${xmlText(value)}</string>`;\n if (typeof value === 'number') return `<integer>${value}</integer>`;\n if (typeof value === 'boolean') return value ? '<true/>' : '<false/>';\n if (Array.isArray(value)) return `<array>${value.map(plist).join('')}</array>`;\n return `<dict>${Object.entries(value)\n .map(([key, item]) => `<key>${xmlText(key)}</key>${plist(item)}`)\n .join('')}</dict>`;\n}\n\nexport function exportCocos(pages: readonly AtlasPage[]): OutputFile[] {\n return pages.map((page) => {\n const frames = Object.fromEntries(\n page.frames.map((frame) => {\n const crop = frame.spriteSourceSize;\n const source = frame.sourceSize;\n // Cocos offsets are measured from the source center, with positive Y up.\n const offsetX = crop.x + crop.w / 2 - source.w / 2;\n const offsetY = source.h / 2 - crop.y - crop.h / 2;\n return [\n frame.id,\n {\n aliases: [],\n spriteOffset: `{${offsetX},${offsetY}}`,\n spriteSize: `{${crop.w},${crop.h}}`,\n spriteSourceSize: `{${source.w},${source.h}}`,\n // Match TexturePacker: rectangle dimensions stay logical when rotated.\n textureRect: `{{${frame.frame.x},${frame.frame.y}},{${crop.w},${crop.h}}}`,\n textureRotated: frame.rotated,\n },\n ];\n }),\n );\n const document = `<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n<plist version=\"1.0\">${plist({\n frames,\n metadata: {\n format: 3,\n pixelFormat: 'RGBA8888',\n premultiplyAlpha: false,\n realTextureFileName: page.image,\n textureFileName: page.image,\n size: `{${page.width},${page.height}}`,\n },\n })}</plist>\n`;\n return {\n name: page.image.replace(/\\.png$/, '.plist'),\n data: Uint8Array.from(document, (char) => char.charCodeAt(0)),\n };\n });\n}\n","declare const __SPRITECRATE_VERSION__: string;\nexport const VERSION: string = __SPRITECRATE_VERSION__;\n","import { exportCocos } from './export-cocos.js';\nimport { AtlasError, EXPORT_FORMATS } from './model.js';\nimport { VERSION } from './version.js';\nimport type { AtlasPage, ExportFormat, Frame, OutputFile } from './model.js';\n\nfunction frameData(frame: Frame): Omit<Frame, 'id'> {\n const { id: _id, ...data } = frame;\n // TexturePacker/Phaser describe logical, unrotated dimensions, even though\n // the physical atlas rectangle has swapped dimensions when rotated.\n return {\n ...data,\n frame: { ...frame.frame, w: frame.spriteSourceSize.w, h: frame.spriteSourceSize.h },\n };\n}\n\nfunction jsonFile(name: string, value: unknown): OutputFile {\n // All generated JSON contains Unicode as escapes so core needs no DOM TextEncoder.\n const json = `${JSON.stringify(value, null, 2)}\\n`.replace(\n /[\\u007f-\\uffff]/g,\n (char) => `\\\\u${char.charCodeAt(0).toString(16).padStart(4, '0')}`,\n );\n return { name, data: Uint8Array.from(json, (char) => char.charCodeAt(0)) };\n}\n\nexport function exportAtlas(\n pages: readonly AtlasPage[],\n format: ExportFormat,\n name = 'atlas',\n): OutputFile[] {\n if (!EXPORT_FORMATS.includes(format))\n throw new AtlasError('INVALID_OPTIONS', `Unknown format: ${format}`);\n if (format === 'cocos2d') return exportCocos(pages);\n if (format === 'phaser4' || format === 'phaser3') {\n if (pages.some((page) => page.frames.some((frame) => frame.rotated))) {\n throw new AtlasError('INVALID_OPTIONS', 'Phaser export requires unrotated frames');\n }\n return [\n jsonFile(`${name}.json`, {\n textures: pages.map((page) => ({\n image: page.image,\n format: 'RGBA8888',\n size: { w: page.width, h: page.height },\n scale: 1,\n frames: page.frames.map((frame) => ({ filename: frame.id, ...frameData(frame) })),\n })),\n meta: { app: 'SpriteCrate', version: VERSION },\n }),\n ];\n }\n return pages.map((page) =>\n jsonFile(page.image.replace(/\\.png$/, '.json'), {\n frames:\n format === 'json-hash' || format === 'pixijs'\n ? Object.fromEntries(page.frames.map((frame) => [frame.id, frameData(frame)]))\n : page.frames.map((frame) => ({ filename: frame.id, ...frameData(frame) })),\n meta: {\n app: 'SpriteCrate',\n version: VERSION,\n image: page.image,\n format: 'RGBA8888',\n size: { w: page.width, h: page.height },\n scale: 1,\n ...(format === 'pixijs' && pages.length > 1\n ? {\n related_multi_packs: pages\n .filter((other) => other !== page)\n .map((other) => other.image.replace(/\\.png$/, '.json')),\n }\n : {}),\n },\n }),\n );\n}\n"],"mappings":";AA8EA,MAAa,iBAAiB;CAC5B;CACA;CACA;CACA;CACA;CACA;AACF;AAeA,IAAa,aAAb,cAAgC,MAAM;CAC3B;CACA;CAET,YAAY,MAAiB,SAAiB,UAAmC,CAAC,GAAG;EACnF,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,UAAU;CACjB;AACF;AAEA,MAAa,mBAA2B;AACxC,MAAa,mBAA2B;AACxC,MAAa,cAAsB;AAEnC,SAAgB,WAAW,GAAW,GAAmB;CACvD,OAAO,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI;AAClC;;ACnHA,MAAM,WAA4B;CAChC,MAAM;CACN,UAAU;CACV,WAAW;CACX,UAAU;CACV,WAAW;CAC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K;GACL,SAAS;GACT,OAAO,KAAK;GACZ,QAAQ;GACR,MAAM;IAAE,GAAG,KAAK;IAAO,GAAG,KAAK;GAAO;GACtC,OAAO;GACP,GAAI,WAAW,YAAY,MAAM,SAAS,IACtC,EACE,qBAAqB,MAClB,QAAQ,UAAU,UAAU,IAAI,CAAC,CACjC,KAAK,UAAU,MAAM,MAAM,QAAQ,UAAU,OAAO,CAAC,EAC1D,IACA,CAAC;EACP;CACF,CAAC,CACH;AACF"}
package/package.json CHANGED
@@ -1,6 +1,51 @@
1
1
  {
2
2
  "name": "@spritecrate/core",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.3",
4
+ "description": "SpriteCrate core: deterministic texture atlas tooling",
5
+ "keywords": [
6
+ "cocos-creator",
7
+ "cocos2d",
8
+ "phaser",
9
+ "phaser4",
10
+ "pixijs",
11
+ "spritecrate",
12
+ "spritesheet",
13
+ "texture-atlas",
14
+ "texture-packer"
15
+ ],
16
+ "homepage": "https://github.com/iulo/spritecrate#readme",
17
+ "bugs": {
18
+ "url": "https://github.com/iulo/spritecrate/issues"
19
+ },
20
+ "license": "MIT",
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/iulo/spritecrate.git",
24
+ "directory": "packages/core"
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "LICENSE",
29
+ "LICENSES",
30
+ "THIRD_PARTY_NOTICES.md"
31
+ ],
32
+ "type": "module",
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js"
38
+ }
39
+ },
40
+ "publishConfig": {
41
+ "access": "public"
42
+ },
43
+ "engines": {
44
+ "node": ">=22.18.0"
45
+ },
46
+ "scripts": {
47
+ "build": "tsdown",
48
+ "typecheck": "tsc -p tsconfig.json",
49
+ "check:package": "node ../../scripts/check-package.mjs"
50
+ }
6
51
  }