@flare-engine/assets 0.4.6 → 0.4.7

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/dist/index.d.mts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Signal } from "@flare-engine/events";
2
- //#region src/sprite-sheet.d.ts
3
2
  /** A single frame rectangle in a sprite sheet. */
4
3
  interface SpriteFrame {
5
4
  /** Name/key of the frame. */
@@ -34,21 +33,19 @@ interface SpriteSheet {
34
33
  animations: Map<string, AnimationSequence>;
35
34
  }
36
35
  /** Create an empty sprite sheet. */
37
- declare function createSpriteSheet(): SpriteSheet;
36
+ export declare function createSpriteSheet(): SpriteSheet;
38
37
  /** Parse TexturePacker JSON hash format. */
39
- declare function parseTexturePackerHash(json: unknown): SpriteSheet;
38
+ export declare function parseTexturePackerHash(json: unknown): SpriteSheet;
40
39
  /** Parse TexturePacker JSON array format. */
41
- declare function parseTexturePackerArray(json: unknown): SpriteSheet;
40
+ export declare function parseTexturePackerArray(json: unknown): SpriteSheet;
42
41
  /** Parse Aseprite JSON export. */
43
- declare function parseAseprite(json: unknown): SpriteSheet;
42
+ export declare function parseAseprite(json: unknown): SpriteSheet;
44
43
  /**
45
44
  * Add a custom animation sequence to a sprite sheet.
46
45
  */
47
- declare function addAnimation(sheet: SpriteSheet, name: string, frameIndices: number[], frameDuration: number, loop?: boolean): void;
46
+ export declare function addAnimation(sheet: SpriteSheet, name: string, frameIndices: number[], frameDuration: number, loop?: boolean): void;
48
47
  /** Get a frame by name. Returns undefined if not found. */
49
- declare function getFrame(sheet: SpriteSheet, name: string): SpriteFrame | undefined;
50
- //#endregion
51
- //#region src/texture.d.ts
48
+ export declare function getFrame(sheet: SpriteSheet, name: string): SpriteFrame | undefined;
52
49
  /** Minimal interface for the Skia SkImage we wrap. */
53
50
  interface SkImageLike {
54
51
  width(): number;
@@ -74,9 +71,7 @@ interface Texture {
74
71
  readonly height: number;
75
72
  }
76
73
  /** Create a Texture from a Skia SkImage. */
77
- declare function createTexture(key: string, image: SkImageLike): Texture;
78
- //#endregion
79
- //#region src/asset-manager.d.ts
74
+ export declare function createTexture(key: string, image: SkImageLike): Texture;
80
75
  /** Types of assets the manager can store. */
81
76
  type AssetType = 'texture' | 'spritesheet' | 'json' | 'binary';
82
77
  /** A single entry in an asset manifest. */
@@ -111,7 +106,7 @@ interface ManifestLoadResult {
111
106
  * function injected at construction. This allows Skia-dependent texture
112
107
  * loading to live in the React layer while keeping this module testable.
113
108
  */
114
- declare class AssetManager {
109
+ export declare class AssetManager {
115
110
  /** Fires on each asset loaded with current progress (0-1). */
116
111
  readonly onProgress: Signal<number>;
117
112
  /** Current loading progress 0-1. */
@@ -140,8 +135,6 @@ declare class AssetManager {
140
135
  /** Clear all cached assets. */
141
136
  clear(): void;
142
137
  }
143
- //#endregion
144
- //#region src/decode-image.d.ts
145
138
  /** Opaque handle for a Skia SkData object. */
146
139
  interface SkDataLike {
147
140
  readonly __skData: unique symbol;
@@ -164,9 +157,7 @@ interface SkiaImageDecodeModuleLike {
164
157
  * Returns null on failure — never throws. Callers are responsible for
165
158
  * handling null (e.g. falling back to a placeholder texture).
166
159
  */
167
- declare function decodeImage(Skia: SkiaImageDecodeModuleLike, bytes: Uint8Array): SkImageLike | null;
168
- //#endregion
169
- //#region src/loaders.d.ts
160
+ export declare function decodeImage(Skia: SkiaImageDecodeModuleLike, bytes: Uint8Array): SkImageLike | null;
170
161
  /**
171
162
  * Decodes raw image bytes into an SkImage. Returns `null` on failure.
172
163
  * Wire it to `decodeImage(Skia, bytes)` (native) or `kit.MakeImageFromEncoded`
@@ -210,7 +201,7 @@ interface FileAssetLoaderOptions {
210
201
  * Fail-fast: a non-OK response or a null decode throws, so `AssetManager.load`
211
202
  * rejects. Use `AssetManager.loadManifestSettled` for partial-failure tolerance.
212
203
  */
213
- declare function createFetchAssetLoader(options: FetchAssetLoaderOptions): AssetLoader;
204
+ export declare function createFetchAssetLoader(options: FetchAssetLoaderOptions): AssetLoader;
214
205
  /**
215
206
  * A native `AssetLoader` backed by an injected `readFile`. `texture` entries are
216
207
  * decoded into a `Texture`; `binary` yields the raw `Uint8Array`;
@@ -218,9 +209,7 @@ declare function createFetchAssetLoader(options: FetchAssetLoaderOptions): Asset
218
209
  *
219
210
  * Fail-fast: a null decode (or a rejecting `readFile`) throws.
220
211
  */
221
- declare function createFileAssetLoader(options: FileAssetLoaderOptions): AssetLoader;
222
- //#endregion
223
- //#region src/procedural-atlas.d.ts
212
+ export declare function createFileAssetLoader(options: FileAssetLoaderOptions): AssetLoader;
224
213
  /** One entry in a procedural atlas — a named colored rectangle. */
225
214
  interface ProceduralFrameSpec {
226
215
  /** Frame name (used as the SpriteFrame name for lookup). */
@@ -308,7 +297,6 @@ interface SkiaAtlasModuleLike {
308
297
  * shape draw-calls for `parseTexturePackerHash(jsonText)` with no other
309
298
  * code changes.
310
299
  */
311
- declare function createProceduralAtlas(Skia: SkiaAtlasModuleLike, frames: readonly ProceduralFrameSpec[], options?: ProceduralAtlasOptions): ProceduralAtlas;
312
- //#endregion
313
- export { type AnimationSequence, type AssetLoader, AssetManager, type AssetType, type DecodeImage, type FetchAssetLoaderOptions, type FetchLike, type FetchResponseLike, type FileAssetLoaderOptions, type ManifestEntry, type ManifestLoadFailure, type ManifestLoadResult, type ProceduralAtlas, type ProceduralAtlasOptions, type ProceduralFrameSpec, type SkCanvasLike, type SkDataLike, type SkImageLike, type SkPaintLike, type SkRectLike, type SkSurfaceLike, type SkiaAtlasModuleLike, type SkiaImageDecodeModuleLike, type SpriteFrame, type SpriteSheet, type Texture, addAnimation, createFetchAssetLoader, createFileAssetLoader, createProceduralAtlas, createSpriteSheet, createTexture, decodeImage, getFrame, parseAseprite, parseTexturePackerArray, parseTexturePackerHash };
300
+ export declare function createProceduralAtlas(Skia: SkiaAtlasModuleLike, frames: readonly ProceduralFrameSpec[], options?: ProceduralAtlasOptions): ProceduralAtlas;
301
+ export type { AnimationSequence, AssetLoader, AssetType, DecodeImage, FetchAssetLoaderOptions, FetchLike, FetchResponseLike, FileAssetLoaderOptions, ManifestEntry, ManifestLoadFailure, ManifestLoadResult, ProceduralAtlas, ProceduralAtlasOptions, ProceduralFrameSpec, SkCanvasLike, SkDataLike, SkImageLike, SkPaintLike, SkRectLike, SkSurfaceLike, SkiaAtlasModuleLike, SkiaImageDecodeModuleLike, SpriteFrame, SpriteSheet, Texture };
314
302
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/sprite-sheet.ts","../src/texture.ts","../src/asset-manager.ts","../src/decode-image.ts","../src/loaders.ts","../src/procedural-atlas.ts"],"mappings":";;;UACiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf,QAAQ;;EAER,UAAU;;EAEV,YAAY,YAAY;;;iBAIV,qBAAqB;;iBAqCrB,uBAAuB,gBAAgB;;iBA6BvC,wBAAwB,gBAAgB;;iBA2CxC,cAAc,gBAAgB;;;;iBAiE9B,aACd,OAAO,aACP,cACA,wBACA,uBACA;;iBAMc,SAAS,OAAO,aAAa,eAAe;;;;UC7N3C;EACf;EACA;EACA,cAAc,eAAe;;;;;;;EAO7B,wBAAwB;;;UAIT;;WAEN;;WAEA,OAAO;;WAEP;;WAEA;;;iBAIK,cAAc,aAAa,OAAO,cAAc;;;;KCtBpD;;UAGK;;EAEf;;EAEA,MAAM;;EAEN;;;KAIU,eAAe,OAAO,kBAAkB,QAAQ,UAAU;;UAGrD;;EAEf;;EAEA;;;UAIe;;EAEf;;EAEA,QAAQ;;;;;;;;;cAUG;;WAEF,YAAU;;EAGnB;UAEQ;UACA;cAEI,QAAQ;;;;;EAQd,KAAK,UAAU,kBAAkB;;;;;;;EA2BjC,oBAAoB,UAAU,kBAAkB,QAAQ;;EAgC9D,IAAI,aAAa,cAAc;;EAK/B,IAAI;;EAKJ,OAAO;;EAKP;;;;;UCpIe;WACN;;;;;;UAOM;EACf;IACE,UAAU,OAAO,aAAa;;EAEhC;IACE,qBAAqB,MAAM,aAAa;;;;;;;;;iBAU5B,YACd,MAAM,2BACN,OAAO,aACN;;;;;;;;KCpBS,eAAe,OAAO,eAAe;;UAGhC;WACN;WACA;EACT,eAAe,QAAQ;EACvB,QAAQ;;;;;;KAOE,aAAa,iBAAiB,QAAQ;;UAGjC;;EAEf,aAAa;;EAEb,QAAQ;;;UAIO;;;;;EAKf,WAAW,iBAAiB,QAAQ;;EAEpC,aAAa;;;;;;;;;;iBAWC,uBAAuB,SAAS,0BAA0B;;;;;;;;iBAoC1D,sBAAsB,SAAS,yBAAyB;;;;UCpFvD;;EAEf;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;;;UAIe;;EAEf,OAAO;;EAEP,OAAO;;EAEP;;EAEA;;;KAIG,cAAc;;UAGF;EACf,SAAS,OAAO;;;UAID;WACN;WACA;WACA;WACA;;;UAIM;EACf,SAAS,MAAM,YAAY,OAAO;;;UAInB;EACf,aAAa;EACb,qBAAqB;;;;;;;UAQN;EACf;IAAW,KAAK,eAAe,iBAAiB;;EAChD,SAAS;EACT,SAAS,WAAW,WAAW,WAAW,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BxC,sBACd,MAAM,qBACN,iBAAiB,uBACjB,UAAS,yBACR"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/sprite-sheet.ts","../src/texture.ts","../src/asset-manager.ts","../src/decode-image.ts","../src/loaders.ts","../src/procedural-atlas.ts"],"mappings":";;UACiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf,QAAQ;;EAER,UAAU;;EAEV,YAAY,YAAY;;;wBAIV,qBAAqB;;wBAqCrB,uBAAuB,gBAAgB;;wBA6BvC,wBAAwB,gBAAgB;;wBA2CxC,cAAc,gBAAgB;;;;wBAiE9B,aACd,OAAO,aACP,cACA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e,iBAAiB;;EAChD,SAAS;EACT,SAAS,WAAW,WAAW,WAAW,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2BxC,sBACd,MAAM,qBACN,iBAAiB,uBACjB,UAAS,yBACR"}
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { Signal } from "@flare-engine/events";
2
- //#region src/sprite-sheet.d.ts
3
2
  /** A single frame rectangle in a sprite sheet. */
4
3
  interface SpriteFrame {
5
4
  /** Name/key of the frame. */
@@ -34,21 +33,19 @@ interface SpriteSheet {
34
33
  animations: Map<string, AnimationSequence>;
35
34
  }
36
35
  /** Create an empty sprite sheet. */
37
- declare function createSpriteSheet(): SpriteSheet;
36
+ export declare function createSpriteSheet(): SpriteSheet;
38
37
  /** Parse TexturePacker JSON hash format. */
39
- declare function parseTexturePackerHash(json: unknown): SpriteSheet;
38
+ export declare function parseTexturePackerHash(json: unknown): SpriteSheet;
40
39
  /** Parse TexturePacker JSON array format. */
41
- declare function parseTexturePackerArray(json: unknown): SpriteSheet;
40
+ export declare function parseTexturePackerArray(json: unknown): SpriteSheet;
42
41
  /** Parse Aseprite JSON export. */
43
- declare function parseAseprite(json: unknown): SpriteSheet;
42
+ export declare function parseAseprite(json: unknown): SpriteSheet;
44
43
  /**
45
44
  * Add a custom animation sequence to a sprite sheet.
46
45
  */
47
- declare function addAnimation(sheet: SpriteSheet, name: string, frameIndices: number[], frameDuration: number, loop?: boolean): void;
46
+ export declare function addAnimation(sheet: SpriteSheet, name: string, frameIndices: number[], frameDuration: number, loop?: boolean): void;
48
47
  /** Get a frame by name. Returns undefined if not found. */
49
- declare function getFrame(sheet: SpriteSheet, name: string): SpriteFrame | undefined;
50
- //#endregion
51
- //#region src/texture.d.ts
48
+ export declare function getFrame(sheet: SpriteSheet, name: string): SpriteFrame | undefined;
52
49
  /** Minimal interface for the Skia SkImage we wrap. */
53
50
  interface SkImageLike {
54
51
  width(): number;
@@ -74,9 +71,7 @@ interface Texture {
74
71
  readonly height: number;
75
72
  }
76
73
  /** Create a Texture from a Skia SkImage. */
77
- declare function createTexture(key: string, image: SkImageLike): Texture;
78
- //#endregion
79
- //#region src/asset-manager.d.ts
74
+ export declare function createTexture(key: string, image: SkImageLike): Texture;
80
75
  /** Types of assets the manager can store. */
81
76
  type AssetType = 'texture' | 'spritesheet' | 'json' | 'binary';
82
77
  /** A single entry in an asset manifest. */
@@ -111,7 +106,7 @@ interface ManifestLoadResult {
111
106
  * function injected at construction. This allows Skia-dependent texture
112
107
  * loading to live in the React layer while keeping this module testable.
113
108
  */
114
- declare class AssetManager {
109
+ export declare class AssetManager {
115
110
  /** Fires on each asset loaded with current progress (0-1). */
116
111
  readonly onProgress: Signal<number>;
117
112
  /** Current loading progress 0-1. */
@@ -140,8 +135,6 @@ declare class AssetManager {
140
135
  /** Clear all cached assets. */
141
136
  clear(): void;
142
137
  }
143
- //#endregion
144
- //#region src/decode-image.d.ts
145
138
  /** Opaque handle for a Skia SkData object. */
146
139
  interface SkDataLike {
147
140
  readonly __skData: unique symbol;
@@ -164,9 +157,7 @@ interface SkiaImageDecodeModuleLike {
164
157
  * Returns null on failure — never throws. Callers are responsible for
165
158
  * handling null (e.g. falling back to a placeholder texture).
166
159
  */
167
- declare function decodeImage(Skia: SkiaImageDecodeModuleLike, bytes: Uint8Array): SkImageLike | null;
168
- //#endregion
169
- //#region src/loaders.d.ts
160
+ export declare function decodeImage(Skia: SkiaImageDecodeModuleLike, bytes: Uint8Array): SkImageLike | null;
170
161
  /**
171
162
  * Decodes raw image bytes into an SkImage. Returns `null` on failure.
172
163
  * Wire it to `decodeImage(Skia, bytes)` (native) or `kit.MakeImageFromEncoded`
@@ -210,7 +201,7 @@ interface FileAssetLoaderOptions {
210
201
  * Fail-fast: a non-OK response or a null decode throws, so `AssetManager.load`
211
202
  * rejects. Use `AssetManager.loadManifestSettled` for partial-failure tolerance.
212
203
  */
213
- declare function createFetchAssetLoader(options: FetchAssetLoaderOptions): AssetLoader;
204
+ export declare function createFetchAssetLoader(options: FetchAssetLoaderOptions): AssetLoader;
214
205
  /**
215
206
  * A native `AssetLoader` backed by an injected `readFile`. `texture` entries are
216
207
  * decoded into a `Texture`; `binary` yields the raw `Uint8Array`;
@@ -218,9 +209,7 @@ declare function createFetchAssetLoader(options: FetchAssetLoaderOptions): Asset
218
209
  *
219
210
  * Fail-fast: a null decode (or a rejecting `readFile`) throws.
220
211
  */
221
- declare function createFileAssetLoader(options: FileAssetLoaderOptions): AssetLoader;
222
- //#endregion
223
- //#region src/procedural-atlas.d.ts
212
+ export declare function createFileAssetLoader(options: FileAssetLoaderOptions): AssetLoader;
224
213
  /** One entry in a procedural atlas — a named colored rectangle. */
225
214
  interface ProceduralFrameSpec {
226
215
  /** Frame name (used as the SpriteFrame name for lookup). */
@@ -308,7 +297,6 @@ interface SkiaAtlasModuleLike {
308
297
  * shape draw-calls for `parseTexturePackerHash(jsonText)` with no other
309
298
  * code changes.
310
299
  */
311
- declare function createProceduralAtlas(Skia: SkiaAtlasModuleLike, frames: readonly ProceduralFrameSpec[], options?: ProceduralAtlasOptions): ProceduralAtlas;
312
- //#endregion
313
- export { type AnimationSequence, type AssetLoader, AssetManager, type AssetType, type DecodeImage, type FetchAssetLoaderOptions, type FetchLike, type FetchResponseLike, type FileAssetLoaderOptions, type ManifestEntry, type ManifestLoadFailure, type ManifestLoadResult, type ProceduralAtlas, type ProceduralAtlasOptions, type ProceduralFrameSpec, type SkCanvasLike, type SkDataLike, type SkImageLike, type SkPaintLike, type SkRectLike, type SkSurfaceLike, type SkiaAtlasModuleLike, type SkiaImageDecodeModuleLike, type SpriteFrame, type SpriteSheet, type Texture, addAnimation, createFetchAssetLoader, createFileAssetLoader, createProceduralAtlas, createSpriteSheet, createTexture, decodeImage, getFrame, parseAseprite, parseTexturePackerArray, parseTexturePackerHash };
300
+ export declare function createProceduralAtlas(Skia: SkiaAtlasModuleLike, frames: readonly ProceduralFrameSpec[], options?: ProceduralAtlasOptions): ProceduralAtlas;
301
+ export type { AnimationSequence, AssetLoader, AssetType, DecodeImage, FetchAssetLoaderOptions, FetchLike, FetchResponseLike, FileAssetLoaderOptions, ManifestEntry, ManifestLoadFailure, ManifestLoadResult, ProceduralAtlas, ProceduralAtlasOptions, ProceduralFrameSpec, SkCanvasLike, SkDataLike, SkImageLike, SkPaintLike, SkRectLike, SkSurfaceLike, SkiaAtlasModuleLike, SkiaImageDecodeModuleLike, SpriteFrame, SpriteSheet, Texture };
314
302
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/sprite-sheet.ts","../src/texture.ts","../src/asset-manager.ts","../src/decode-image.ts","../src/loaders.ts","../src/procedural-atlas.ts"],"mappings":";;;UACiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf,QAAQ;;EAER,UAAU;;EAEV,YAAY,YAAY;;;iBAIV,qBAAqB;;iBAqCrB,uBAAuB,gBAAgB;;iBA6BvC,wBAAwB,gBAAgB;;iBA2CxC,cAAc,gBAAgB;;;;iBAiE9B,aACd,OAAO,aACP,cACA,wBACA,uBACA;;iBAMc,SAAS,OAAO,aAAa,eAAe;;;;UC7N3C;EACf;EACA;EACA,cAAc,eAAe;;;;;;;EAO7B,wBAAwB;;;UAIT;;WAEN;;WAEA,OAAO;;WAEP;;WAEA;;;iBAIK,cAAc,aAAa,OAAO,cAAc;;;;KCtBpD;;UAGK;;EAEf;;EAEA,MAAM;;EAEN;;;KAIU,eAAe,OAAO,kBAAkB,QAAQ,UAAU;;UAGrD;;EAEf;;EAEA;;;UAIe;;EAEf;;EAEA,QAAQ;;;;;;;;;cAUG;;WAEF,YAAU;;EAGnB;UAEQ;UACA;cAEI,QAAQ;;;;;EAQd,KAAK,UAAU,kBAAkB;;;;;;;EA2BjC,oBAAoB,UAAU,kBAAkB,QAAQ;;EAgC9D,IAAI,aAAa,cAAc;;EAK/B,IAAI;;EAKJ,OAAO;;EAKP;;;;;UCpIe;WACN;;;;;;UAOM;EACf;IACE,UAAU,OAAO,aAAa;;EAEhC;IACE,qBAAqB,MAAM,aAAa;;;;;;;;;iBAU5B,YACd,MAAM,2BACN,OAAO,aACN;;;;;;;;KCpBS,eAAe,OAAO,eAAe;;UAGhC;WACN;WACA;EACT,eAAe,QAAQ;EACvB,QAAQ;;;;;;KAOE,aAAa,iBAAiB,QAAQ;;UAGjC;;EAEf,aAAa;;EAEb,QAAQ;;;UAIO;;;;;EAKf,WAAW,iBAAiB,QAAQ;;EAEpC,aAAa;;;;;;;;;;iBAWC,uBAAuB,SAAS,0BAA0B;;;;;;;;iBAoC1D,sBAAsB,SAAS,yBAAyB;;;;UCpFvD;;EAEf;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;;;UAIe;;EAEf,OAAO;;EAEP,OAAO;;EAEP;;EAEA;;;KAIG,cAAc;;UAGF;EACf,SAAS,OAAO;;;UAID;WACN;WACA;WACA;WACA;;;UAIM;EACf,SAAS,MAAM,YAAY,OAAO;;;UAInB;EACf,aAAa;EACb,qBAAqB;;;;;;;UAQN;EACf;IAAW,KAAK,eAAe,iBAAiB;;EAChD,SAAS;EACT,SAAS,WAAW,WAAW,WAAW,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;iBA2BxC,sBACd,MAAM,qBACN,iBAAiB,uBACjB,UAAS,yBACR"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/sprite-sheet.ts","../src/texture.ts","../src/asset-manager.ts","../src/decode-image.ts","../src/loaders.ts","../src/procedural-atlas.ts"],"mappings":";;UACiB;;EAEf;;EAEA;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf;;EAEA;;EAEA;;EAEA;;;UAIe;;EAEf,QAAQ;;EAER,UAAU;;EAEV,YAAY,YAAY;;;wBAIV,qBAAqB;;wBAqCrB,uBAAuB,gBAAgB;;wBA6BvC,wBAAwB,gBAAgB;;wBA2CxC,cAAc,gBAAg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;;;;;;;UAQN;EACf;IAAW,KAAK,eAAe,iBAAiB;;EAChD,SAAS;EACT,SAAS,WAAW,WAAW,WAAW,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;wBA2BxC,sBACd,MAAM,qBACN,iBAAiB,uBACjB,UAAS,yBACR"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let _flare_engine_events = require("@flare-engine/events");
3
- //#region src/asset-manager.ts
3
+ // src/asset-manager.ts
4
4
  /**
5
5
  * AssetManager — loads, caches, and provides access to game assets.
6
6
  *
@@ -98,8 +98,7 @@ var AssetManager = class {
98
98
  this.progress = 0;
99
99
  }
100
100
  };
101
- //#endregion
102
- //#region src/decode-image.ts
101
+ // src/decode-image.ts
103
102
  /**
104
103
  * Decode raw image bytes into a Skia SkImage.
105
104
  *
@@ -110,8 +109,7 @@ function decodeImage(Skia, bytes) {
110
109
  const data = Skia.Data.fromBytes(bytes);
111
110
  return Skia.Image.MakeImageFromEncoded(data);
112
111
  }
113
- //#endregion
114
- //#region src/texture.ts
112
+ // src/texture.ts
115
113
  /** Create a Texture from a Skia SkImage. */
116
114
  function createTexture(key, image) {
117
115
  return {
@@ -121,8 +119,7 @@ function createTexture(key, image) {
121
119
  height: image.height()
122
120
  };
123
121
  }
124
- //#endregion
125
- //#region src/loaders.ts
122
+ // src/loaders.ts
126
123
  /**
127
124
  * A web `AssetLoader` backed by `fetch`. `texture` entries are decoded into a
128
125
  * `Texture`; `binary` yields a `Uint8Array`; `json`/`spritesheet` yield the
@@ -171,8 +168,7 @@ function createFileAssetLoader(options) {
171
168
  }
172
169
  };
173
170
  }
174
- //#endregion
175
- //#region src/sprite-sheet.ts
171
+ // src/sprite-sheet.ts
176
172
  /** Create an empty sprite sheet. */
177
173
  function createSpriteSheet() {
178
174
  return {
@@ -284,8 +280,7 @@ function getFrame(sheet, name) {
284
280
  if (idx === void 0) return void 0;
285
281
  return sheet.frames[idx];
286
282
  }
287
- //#endregion
288
- //#region src/procedural-atlas.ts
283
+ // src/procedural-atlas.ts
289
284
  /**
290
285
  * Build a flat atlas `SkImage` from a list of colored rectangles.
291
286
  *
@@ -375,7 +370,6 @@ function writeArgb(out, argb) {
375
370
  out[2] = (argb & 255) / 255;
376
371
  out[3] = (argb >>> 24 & 255) / 255;
377
372
  }
378
- //#endregion
379
373
  exports.AssetManager = AssetManager;
380
374
  exports.addAnimation = addAnimation;
381
375
  exports.createFetchAssetLoader = createFetchAssetLoader;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["Signal"],"sources":["../src/asset-manager.ts","../src/decode-image.ts","../src/texture.ts","../src/loaders.ts","../src/sprite-sheet.ts","../src/procedural-atlas.ts"],"sourcesContent":["import { Signal } from '@flare-engine/events';\nimport type { SpriteSheet } from './sprite-sheet.js';\nimport type { Texture } from './texture.js';\n\n/** Types of assets the manager can store. */\nexport type AssetType = 'texture' | 'spritesheet' | 'json' | 'binary';\n\n/** A single entry in an asset manifest. */\nexport interface ManifestEntry {\n /** Unique key to retrieve this asset. */\n key: string;\n /** Asset type. */\n type: AssetType;\n /** Path or URI to the asset. */\n path: string;\n}\n\n/** A load function provided by the platform to actually fetch+decode assets. */\nexport type AssetLoader = (entry: ManifestEntry) => Promise<Texture | SpriteSheet | unknown>;\n\n/** A single entry that failed during {@link AssetManager.loadManifestSettled}. */\nexport interface ManifestLoadFailure {\n /** Key of the manifest entry that failed. */\n key: string;\n /** The value thrown by the loader (an `Error` or otherwise). */\n error: unknown;\n}\n\n/** Partial-failure summary returned by {@link AssetManager.loadManifestSettled}. */\nexport interface ManifestLoadResult {\n /** Keys of entries that loaded and were cached. */\n loaded: string[];\n /** Entries that threw, with the captured error. */\n failed: ManifestLoadFailure[];\n}\n\n/**\n * AssetManager — loads, caches, and provides access to game assets.\n *\n * Platform-agnostic: the actual loading is delegated to an `AssetLoader`\n * function injected at construction. This allows Skia-dependent texture\n * loading to live in the React layer while keeping this module testable.\n */\nexport class AssetManager {\n /** Fires on each asset loaded with current progress (0-1). */\n readonly onProgress = new Signal<number>();\n\n /** Current loading progress 0-1. */\n progress = 0;\n\n private _assets = new Map<string, unknown>();\n private _loader: AssetLoader;\n\n constructor(loader: AssetLoader) {\n this._loader = loader;\n }\n\n /**\n * Load all assets in the manifest.\n * Resolves when all assets are loaded and cached.\n */\n async load(manifest: ManifestEntry[]): Promise<void> {\n if (manifest.length === 0) {\n this.progress = 1;\n this.onProgress.emit(1);\n return;\n }\n\n let loaded = 0;\n const total = manifest.length;\n\n const promises = manifest.map(async (entry) => {\n const asset = await this._loader(entry);\n this._assets.set(entry.key, asset);\n loaded++;\n this.progress = loaded / total;\n this.onProgress.emit(this.progress);\n });\n\n await Promise.all(promises);\n }\n\n /**\n * Load all assets without rejecting on the first failure. Successful assets\n * are cached; failures are collected and returned. Progress still advances to\n * 1 once every entry has settled. Prefer this over {@link load} when a partial\n * asset set is acceptable (e.g. optional/decorative assets).\n */\n async loadManifestSettled(manifest: ManifestEntry[]): Promise<ManifestLoadResult> {\n const loaded: string[] = [];\n const failed: ManifestLoadFailure[] = [];\n\n if (manifest.length === 0) {\n this.progress = 1;\n this.onProgress.emit(1);\n return { loaded, failed };\n }\n\n let settled = 0;\n const total = manifest.length;\n\n const promises = manifest.map(async (entry) => {\n try {\n const asset = await this._loader(entry);\n this._assets.set(entry.key, asset);\n loaded.push(entry.key);\n } catch (error) {\n failed.push({ key: entry.key, error });\n } finally {\n settled++;\n this.progress = settled / total;\n this.onProgress.emit(this.progress);\n }\n });\n\n await Promise.all(promises);\n return { loaded, failed };\n }\n\n /** Get a loaded asset by key. Returns undefined if not found. */\n get<T = unknown>(key: string): T | undefined {\n return this._assets.get(key) as T | undefined;\n }\n\n /** Check if an asset is loaded. */\n has(key: string): boolean {\n return this._assets.has(key);\n }\n\n /** Remove an asset from the cache. */\n unload(key: string): boolean {\n return this._assets.delete(key);\n }\n\n /** Clear all cached assets. */\n clear(): void {\n this._assets.clear();\n this.progress = 0;\n }\n}\n","import type { SkImageLike } from './texture.js';\n\n/** Opaque handle for a Skia SkData object. */\nexport interface SkDataLike {\n readonly __skData: unique symbol;\n}\n\n/**\n * Narrow view of the Skia module — only the factories this helper needs.\n * Injected by the caller so @flare-engine/assets stays runtime-agnostic.\n */\nexport interface SkiaImageDecodeModuleLike {\n Data: {\n fromBytes(bytes: Uint8Array): SkDataLike;\n };\n Image: {\n MakeImageFromEncoded(data: SkDataLike): SkImageLike | null;\n };\n}\n\n/**\n * Decode raw image bytes into a Skia SkImage.\n *\n * Returns null on failure — never throws. Callers are responsible for\n * handling null (e.g. falling back to a placeholder texture).\n */\nexport function decodeImage(\n Skia: SkiaImageDecodeModuleLike,\n bytes: Uint8Array,\n): SkImageLike | null {\n const data = Skia.Data.fromBytes(bytes);\n return Skia.Image.MakeImageFromEncoded(data);\n}\n","/** Minimal interface for the Skia SkImage we wrap. */\nexport interface SkImageLike {\n width(): number;\n height(): number;\n readPixels(): Float32Array | Uint8Array | null;\n /**\n * Optional — present on GPU-backed SkImages returned by RN-Skia's\n * MakeOffscreen surfaces. Copies the texture into a CPU-raster image so it\n * can be safely sampled from a different GrDirectContext (e.g. the on-screen\n * Canvas). Must be called before the image crosses a context boundary.\n */\n makeNonTextureImage?(): SkImageLike;\n}\n\n/** A loaded texture wrapping a Skia SkImage. */\nexport interface Texture {\n /** Unique key for this texture in the asset manager. */\n readonly key: string;\n /** The underlying Skia SkImage. */\n readonly image: SkImageLike;\n /** Width in pixels. */\n readonly width: number;\n /** Height in pixels. */\n readonly height: number;\n}\n\n/** Create a Texture from a Skia SkImage. */\nexport function createTexture(key: string, image: SkImageLike): Texture {\n return {\n key,\n image,\n width: image.width(),\n height: image.height(),\n };\n}\n","import type { AssetLoader, ManifestEntry } from './asset-manager.js';\nimport type { SkImageLike } from './texture.js';\nimport { createTexture } from './texture.js';\n\n/**\n * Decodes raw image bytes into an SkImage. Returns `null` on failure.\n * Wire it to `decodeImage(Skia, bytes)` (native) or `kit.MakeImageFromEncoded`\n * (CanvasKit / web) — see the package README for both.\n */\nexport type DecodeImage = (bytes: Uint8Array) => SkImageLike | null;\n\n/** Minimal structural view of a fetch `Response` — only what the loader reads. */\nexport interface FetchResponseLike {\n readonly ok: boolean;\n readonly status: number;\n arrayBuffer(): Promise<ArrayBuffer>;\n json(): Promise<unknown>;\n}\n\n/**\n * Minimal structural `fetch`. The global `fetch` (web / RN / Bun) satisfies it,\n * so the package needs no DOM/Bun fetch typing of its own.\n */\nexport type FetchLike = (path: string) => Promise<FetchResponseLike>;\n\n/** Options for {@link createFetchAssetLoader}. */\nexport interface FetchAssetLoaderOptions {\n /** Decodes fetched image bytes into an SkImage. */\n decodeImage: DecodeImage;\n /** `fetch` implementation; defaults to the global `fetch`. */\n fetch?: FetchLike;\n}\n\n/** Options for {@link createFileAssetLoader}. */\nexport interface FileAssetLoaderOptions {\n /**\n * Reads a file path into raw bytes — structural, so any native filesystem\n * (e.g. expo-file-system) satisfies it without a hard dependency here.\n */\n readFile: (path: string) => Promise<Uint8Array>;\n /** Decodes read image bytes into an SkImage. */\n decodeImage: DecodeImage;\n}\n\n/**\n * A web `AssetLoader` backed by `fetch`. `texture` entries are decoded into a\n * `Texture`; `binary` yields a `Uint8Array`; `json`/`spritesheet` yield the\n * parsed JSON (feed a spritesheet result to `parseTexturePackerHash` etc.).\n *\n * Fail-fast: a non-OK response or a null decode throws, so `AssetManager.load`\n * rejects. Use `AssetManager.loadManifestSettled` for partial-failure tolerance.\n */\nexport function createFetchAssetLoader(options: FetchAssetLoaderOptions): AssetLoader {\n const { decodeImage } = options;\n const fetchFn: FetchLike = options.fetch ?? globalThis.fetch;\n return async (entry: ManifestEntry) => {\n const response = await fetchFn(entry.path);\n if (!response.ok) {\n throw new Error(\n `[flare-engine/assets] fetch failed for \"${entry.key}\" (${entry.path}): ${response.status}`,\n );\n }\n switch (entry.type) {\n case 'texture': {\n const bytes = new Uint8Array(await response.arrayBuffer());\n const image = decodeImage(bytes);\n if (!image) {\n throw new Error(\n `[flare-engine/assets] image decode failed for \"${entry.key}\" (${entry.path})`,\n );\n }\n return createTexture(entry.key, image);\n }\n case 'binary':\n return new Uint8Array(await response.arrayBuffer());\n default:\n return response.json();\n }\n };\n}\n\n/**\n * A native `AssetLoader` backed by an injected `readFile`. `texture` entries are\n * decoded into a `Texture`; `binary` yields the raw `Uint8Array`;\n * `json`/`spritesheet` yield the JSON parsed from UTF-8 bytes.\n *\n * Fail-fast: a null decode (or a rejecting `readFile`) throws.\n */\nexport function createFileAssetLoader(options: FileAssetLoaderOptions): AssetLoader {\n const { readFile, decodeImage } = options;\n return async (entry: ManifestEntry) => {\n const bytes = await readFile(entry.path);\n switch (entry.type) {\n case 'texture': {\n const image = decodeImage(bytes);\n if (!image) {\n throw new Error(\n `[flare-engine/assets] image decode failed for \"${entry.key}\" (${entry.path})`,\n );\n }\n return createTexture(entry.key, image);\n }\n case 'binary':\n return bytes;\n default:\n return JSON.parse(new TextDecoder().decode(bytes));\n }\n };\n}\n","/** A single frame rectangle in a sprite sheet. */\nexport interface SpriteFrame {\n /** Name/key of the frame. */\n name: string;\n /** X offset in the source texture (pixels). */\n x: number;\n /** Y offset in the source texture (pixels). */\n y: number;\n /** Width of the frame (pixels). */\n w: number;\n /** Height of the frame (pixels). */\n h: number;\n}\n\n/** A named animation sequence within a sprite sheet. */\nexport interface AnimationSequence {\n /** Sequence name (e.g. \"walk\", \"idle\"). */\n name: string;\n /** Indices into the SpriteSheet.frames array. */\n frameIndices: number[];\n /** Duration per frame in seconds. */\n frameDuration: number;\n /** Whether to loop the sequence. */\n loop: boolean;\n}\n\n/** Parsed sprite sheet data — pure data, no Skia dependency. */\nexport interface SpriteSheet {\n /** Ordered array of all frames. */\n frames: SpriteFrame[];\n /** Map from frame name to index in frames[]. */\n frameMap: Map<string, number>;\n /** Named animation sequences. */\n animations: Map<string, AnimationSequence>;\n}\n\n/** Create an empty sprite sheet. */\nexport function createSpriteSheet(): SpriteSheet {\n return {\n frames: [],\n frameMap: new Map(),\n animations: new Map(),\n };\n}\n\n// ----- Rotated-frame dev warning -----\n\ndeclare const __DEV__: boolean | undefined;\n\n/**\n * Warn (dev builds only) when a TexturePacker frame is exported rotated.\n * Rotated frames are not yet remapped, so they render sideways — the frame is\n * named so the artist can re-export it. Full rotation support is post-launch.\n */\nfunction warnRotatedFrame(name: string): void {\n if (typeof __DEV__ !== 'undefined' && __DEV__) {\n console.warn(\n `[flare-engine/assets] sprite frame \"${name}\": rotation unsupported — re-export without rotation`,\n );\n }\n}\n\n// ----- TexturePacker JSON (hash format) -----\n\ninterface TPHashFrame {\n frame: { x: number; y: number; w: number; h: number };\n rotated?: boolean;\n}\n\ninterface TPHashJSON {\n frames: Record<string, TPHashFrame>;\n}\n\n/** Parse TexturePacker JSON hash format. */\nexport function parseTexturePackerHash(json: unknown): SpriteSheet {\n const data = json as TPHashJSON;\n const sheet = createSpriteSheet();\n const entries = Object.entries(data.frames);\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (!entry) continue;\n const [name, value] = entry;\n if (value.rotated) warnRotatedFrame(name);\n const f = value.frame;\n sheet.frames.push({ name, x: f.x, y: f.y, w: f.w, h: f.h });\n sheet.frameMap.set(name, i);\n }\n return sheet;\n}\n\n// ----- TexturePacker JSON (array format) -----\n\ninterface TPArrayFrame {\n filename: string;\n frame: { x: number; y: number; w: number; h: number };\n rotated?: boolean;\n}\n\ninterface TPArrayJSON {\n frames: TPArrayFrame[];\n}\n\n/** Parse TexturePacker JSON array format. */\nexport function parseTexturePackerArray(json: unknown): SpriteSheet {\n const data = json as TPArrayJSON;\n const sheet = createSpriteSheet();\n for (let i = 0; i < data.frames.length; i++) {\n const entry = data.frames[i];\n if (!entry) continue;\n if (entry.rotated) warnRotatedFrame(entry.filename);\n const f = entry.frame;\n sheet.frames.push({\n name: entry.filename,\n x: f.x,\n y: f.y,\n w: f.w,\n h: f.h,\n });\n sheet.frameMap.set(entry.filename, i);\n }\n return sheet;\n}\n\n// ----- Aseprite JSON -----\n\ninterface AsepriteFrame {\n filename: string;\n frame: { x: number; y: number; w: number; h: number };\n duration: number; // ms\n}\n\ninterface AsepriteTag {\n name: string;\n from: number;\n to: number;\n direction: string;\n}\n\ninterface AsepriteJSON {\n frames: AsepriteFrame[] | Record<string, AsepriteFrame>;\n meta?: {\n frameTags?: AsepriteTag[];\n };\n}\n\n/** Parse Aseprite JSON export. */\nexport function parseAseprite(json: unknown): SpriteSheet {\n const data = json as AsepriteJSON;\n const sheet = createSpriteSheet();\n\n // Aseprite can export frames as array or object\n const frameEntries: AsepriteFrame[] = Array.isArray(data.frames)\n ? data.frames\n : Object.values(data.frames);\n\n for (let i = 0; i < frameEntries.length; i++) {\n const entry = frameEntries[i];\n if (!entry) continue;\n const f = entry.frame;\n sheet.frames.push({\n name: entry.filename,\n x: f.x,\n y: f.y,\n w: f.w,\n h: f.h,\n });\n sheet.frameMap.set(entry.filename, i);\n }\n\n // Parse frame tags as animation sequences\n const tags = data.meta?.frameTags;\n if (tags) {\n for (const tag of tags) {\n const indices: number[] = [];\n if (tag.direction === 'reverse') {\n for (let i = tag.to; i >= tag.from; i--) {\n indices.push(i);\n }\n } else if (tag.direction === 'pingpong') {\n for (let i = tag.from; i <= tag.to; i++) {\n indices.push(i);\n }\n for (let i = tag.to - 1; i > tag.from; i--) {\n indices.push(i);\n }\n } else {\n // \"forward\" or default\n for (let i = tag.from; i <= tag.to; i++) {\n indices.push(i);\n }\n }\n\n // Use the first frame's duration as the uniform frame duration\n const firstFrame = frameEntries[tag.from];\n const durationMs = firstFrame?.duration ?? 100;\n\n sheet.animations.set(tag.name, {\n name: tag.name,\n frameIndices: indices,\n frameDuration: durationMs / 1000,\n loop: true,\n });\n }\n }\n\n return sheet;\n}\n\n/**\n * Add a custom animation sequence to a sprite sheet.\n */\nexport function addAnimation(\n sheet: SpriteSheet,\n name: string,\n frameIndices: number[],\n frameDuration: number,\n loop = true,\n): void {\n sheet.animations.set(name, { name, frameIndices, frameDuration, loop });\n}\n\n/** Get a frame by name. Returns undefined if not found. */\nexport function getFrame(sheet: SpriteSheet, name: string): SpriteFrame | undefined {\n const idx = sheet.frameMap.get(name);\n if (idx === undefined) return undefined;\n return sheet.frames[idx];\n}\n","import { createSpriteSheet, type SpriteFrame, type SpriteSheet } from './sprite-sheet.js';\nimport type { SkImageLike } from './texture.js';\n\n/** One entry in a procedural atlas — a named colored rectangle. */\nexport interface ProceduralFrameSpec {\n /** Frame name (used as the SpriteFrame name for lookup). */\n name: string;\n /** Width in pixels. */\n w: number;\n /** Height in pixels. */\n h: number;\n /** Color as ARGB int (0xAARRGGBB). */\n color: number;\n}\n\n/** Options controlling atlas layout. */\nexport interface ProceduralAtlasOptions {\n /** Max atlas width before wrapping to a new row. Default 1024. */\n maxWidth?: number;\n /** Gap between frames in pixels. Default 0. */\n padding?: number;\n}\n\n/** Result of a procedural atlas build. */\nexport interface ProceduralAtlas {\n /** Backing Skia image with all rects drawn. */\n image: SkImageLike;\n /** SpriteSheet whose frames describe the rect positions. */\n sheet: SpriteSheet;\n /** Total atlas width in pixels. */\n width: number;\n /** Total atlas height in pixels. */\n height: number;\n}\n\n/** Opaque Skia color value — a Float32Array of length 4 (r, g, b, a in [0,1]). */\ntype SkColorLike = Float32Array;\n\n/** Narrow paint interface — only the setter we use. */\nexport interface SkPaintLike {\n setColor(color: SkColorLike): void;\n}\n\n/** Narrow rect interface — a rect value object passed to drawRect. */\nexport interface SkRectLike {\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n}\n\n/** Narrow canvas interface — only the method we use. */\nexport interface SkCanvasLike {\n drawRect(rect: SkRectLike, paint: SkPaintLike): void;\n}\n\n/** Narrow surface interface — getCanvas + snapshot. */\nexport interface SkSurfaceLike {\n getCanvas(): SkCanvasLike;\n makeImageSnapshot(): SkImageLike;\n}\n\n/**\n * Narrow view of the Skia module — only the factories this helper needs.\n * Declared locally so unit tests can supply a plain mock without pulling\n * in the full `@shopify/react-native-skia` surface.\n */\nexport interface SkiaAtlasModuleLike {\n Surface: { Make(width: number, height: number): SkSurfaceLike | null };\n Paint(): SkPaintLike;\n XYWHRect(x: number, y: number, w: number, h: number): SkRectLike;\n}\n\n/**\n * Build a flat atlas `SkImage` from a list of colored rectangles.\n *\n * Row-packs frames left-to-right until `maxWidth` is exceeded, then wraps\n * to a new row. Returns both the backing image and a `SpriteSheet` whose\n * frames match the packed positions, so consumers can look up frames by\n * name exactly as with a real `parseTexturePacker*` sheet.\n *\n * Useful for:\n * - bootstrapping gameplay before final art lands (replace with one\n * `parseTexturePackerHash` call once the real atlas arrives),\n * - engine tests / benchmarks that need a valid `SkImage` without\n * shipping any binary asset.\n *\n * **Canonical placeholder-atlas pattern:** a game can ship a full \"shape\n * atlas\" that draws every entity (enemies, bosses, ships, pickups) as\n * composed primitives onto an offscreen Skia surface, then wraps the result\n * in a `SpriteSheet`.\n * That pattern (declarative shape spec → Skia draw calls → `SpriteSheet`\n * with one named frame per shape) is the recommended way to build a\n * manifest-swappable placeholder atlas: when final art lands, swap the\n * shape draw-calls for `parseTexturePackerHash(jsonText)` with no other\n * code changes.\n */\nexport function createProceduralAtlas(\n Skia: SkiaAtlasModuleLike,\n frames: readonly ProceduralFrameSpec[],\n options: ProceduralAtlasOptions = {},\n): ProceduralAtlas {\n const maxWidth = options.maxWidth ?? 1024;\n const padding = options.padding ?? 0;\n\n const positions = layoutRows(frames, maxWidth, padding);\n const surface = Skia.Surface.Make(positions.width, positions.height);\n if (surface === null) {\n throw new Error(`Skia.Surface.Make returned null for ${positions.width}x${positions.height}`);\n }\n\n const canvas = surface.getCanvas();\n const paint = Skia.Paint();\n const color: SkColorLike = new Float32Array(4);\n\n const sheet = createSpriteSheet();\n\n for (let i = 0; i < frames.length; i++) {\n const spec = frames[i];\n const pos = positions.rects[i];\n if (spec === undefined || pos === undefined) continue;\n\n writeArgb(color, spec.color);\n paint.setColor(color);\n canvas.drawRect(Skia.XYWHRect(pos.x, pos.y, spec.w, spec.h), paint);\n\n const frame: SpriteFrame = {\n name: spec.name,\n x: pos.x,\n y: pos.y,\n w: spec.w,\n h: spec.h,\n };\n sheet.frames.push(frame);\n sheet.frameMap.set(spec.name, i);\n }\n\n return {\n image: surface.makeImageSnapshot(),\n sheet,\n width: positions.width,\n height: positions.height,\n };\n}\n\ninterface PackedPosition {\n x: number;\n y: number;\n}\n\ninterface PackedLayout {\n rects: PackedPosition[];\n width: number;\n height: number;\n}\n\nfunction layoutRows(\n frames: readonly ProceduralFrameSpec[],\n maxWidth: number,\n padding: number,\n): PackedLayout {\n const rects: PackedPosition[] = [];\n let x = 0;\n let y = 0;\n let rowHeight = 0;\n let atlasWidth = 0;\n\n for (const spec of frames) {\n if (x > 0 && x + spec.w > maxWidth) {\n y += rowHeight + padding;\n x = 0;\n rowHeight = 0;\n }\n rects.push({ x, y });\n x += spec.w + padding;\n if (spec.h > rowHeight) rowHeight = spec.h;\n if (x - padding > atlasWidth) atlasWidth = x - padding;\n }\n\n const atlasHeight = y + rowHeight;\n return {\n rects,\n width: atlasWidth > 0 ? atlasWidth : 1,\n height: atlasHeight > 0 ? atlasHeight : 1,\n };\n}\n\nfunction writeArgb(out: SkColorLike, argb: number): void {\n out[0] = ((argb >>> 16) & 0xff) / 255;\n out[1] = ((argb >>> 8) & 0xff) / 255;\n out[2] = (argb & 0xff) / 255;\n out[3] = ((argb >>> 24) & 0xff) / 255;\n}\n"],"mappings":";;;;;;;;;;AA2CA,IAAa,eAAb,MAA0B;;CAExB,aAAsB,IAAIA,qBAAAA,OAAe;;CAGzC,WAAW;CAEX,0BAAkB,IAAI,IAAqB;CAC3C;CAEA,YAAY,QAAqB;EAC/B,KAAK,UAAU;CACjB;;;;;CAMA,MAAM,KAAK,UAA0C;EACnD,IAAI,SAAS,WAAW,GAAG;GACzB,KAAK,WAAW;GAChB,KAAK,WAAW,KAAK,CAAC;GACtB;EACF;EAEA,IAAI,SAAS;EACb,MAAM,QAAQ,SAAS;EAEvB,MAAM,W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AI,YAAY;CAChB,IAAI,aAAa;CAEjB,KAAK,MAAM,QAAQ,QAAQ;EACzB,IAAI,IAAI,KAAK,IAAI,KAAK,IAAI,UAAU;GAClC,KAAK,YAAY;GACjB,IAAI;GACJ,YAAY;EACd;EACA,MAAM,KAAK;GAAE;GAAG;EAAE,CAAC;EACnB,KAAK,KAAK,IAAI;EACd,IAAI,KAAK,IAAI,WAAW,YAAY,KAAK;EACzC,IAAI,IAAI,UAAU,YAAY,aAAa,IAAI;CACjD;CAEA,MAAM,cAAc,IAAI;CACxB,OAAO;EACL;EACA,OAAO,aAAa,IAAI,aAAa;EACrC,QAAQ,cAAc,IAAI,cAAc;CAC1C;AACF;AAEA,SAAS,UAAU,KAAkB,MAAoB;CACvD,IAAI,MAAO,SAAS,KAAM,OAAQ;CAClC,IAAI,MAAO,SAAS,IAAK,OAAQ;CACjC,IAAI,MAAM,OAAO,OAAQ;CACzB,IAAI,MAAO,SAAS,KAAM,OAAQ;AACpC"}
1
+ {"version":3,"file":"index.js","names":["Signal"],"sources":["../src/asset-manager.ts","../src/decode-image.ts","../src/texture.ts","../src/loaders.ts","../src/sprite-sheet.ts","../src/procedural-atlas.ts"],"sourcesContent":["import { Signal } from '@flare-engine/events';\nimport type { SpriteSheet } from './sprite-sheet.js';\nimport type { Texture } from './texture.js';\n\n/** Types of assets the manager can store. */\nexport type AssetType = 'texture' | 'spritesheet' | 'json' | 'binary';\n\n/** A single entry in an asset manifest. */\nexport interface ManifestEntry {\n /** Unique key to retrieve this asset. */\n key: string;\n /** Asset type. */\n type: AssetType;\n /** Path or URI to the asset. */\n path: string;\n}\n\n/** A load function provided by the platform to actually fetch+decode assets. */\nexport type AssetLoader = (entry: ManifestEntry) => Promise<Texture | SpriteSheet | unknown>;\n\n/** A single entry that failed during {@link AssetManager.loadManifestSettled}. */\nexport interface ManifestLoadFailure {\n /** Key of the manifest entry that failed. */\n key: string;\n /** The value thrown by the loader (an `Error` or otherwise). */\n error: unknown;\n}\n\n/** Partial-failure summary returned by {@link AssetManager.loadManifestSettled}. */\nexport interface ManifestLoadResult {\n /** Keys of entries that loaded and were cached. */\n loaded: string[];\n /** Entries that threw, with the captured error. */\n failed: ManifestLoadFailure[];\n}\n\n/**\n * AssetManager — loads, caches, and provides access to game assets.\n *\n * Platform-agnostic: the actual loading is delegated to an `AssetLoader`\n * function injected at construction. This allows Skia-dependent texture\n * loading to live in the React layer while keeping this module testable.\n */\nexport class AssetManager {\n /** Fires on each asset loaded with current progress (0-1). */\n readonly onProgress = new Signal<number>();\n\n /** Current loading progress 0-1. */\n progress = 0;\n\n private _assets = new Map<string, unknown>();\n private _loader: AssetLoader;\n\n constructor(loader: AssetLoader) {\n this._loader = loader;\n }\n\n /**\n * Load all assets in the manifest.\n * Resolves when all assets are loaded and cached.\n */\n async load(manifest: ManifestEntry[]): Promise<void> {\n if (manifest.length === 0) {\n this.progress = 1;\n this.onProgress.emit(1);\n return;\n }\n\n let loaded = 0;\n const total = manifest.length;\n\n const promises = manifest.map(async (entry) => {\n const asset = await this._loader(entry);\n this._assets.set(entry.key, asset);\n loaded++;\n this.progress = loaded / total;\n this.onProgress.emit(this.progress);\n });\n\n await Promise.all(promises);\n }\n\n /**\n * Load all assets without rejecting on the first failure. Successful assets\n * are cached; failures are collected and returned. Progress still advances to\n * 1 once every entry has settled. Prefer this over {@link load} when a partial\n * asset set is acceptable (e.g. optional/decorative assets).\n */\n async loadManifestSettled(manifest: ManifestEntry[]): Promise<ManifestLoadResult> {\n const loaded: string[] = [];\n const failed: ManifestLoadFailure[] = [];\n\n if (manifest.length === 0) {\n this.progress = 1;\n this.onProgress.emit(1);\n return { loaded, failed };\n }\n\n let settled = 0;\n const total = manifest.length;\n\n const promises = manifest.map(async (entry) => {\n try {\n const asset = await this._loader(entry);\n this._assets.set(entry.key, asset);\n loaded.push(entry.key);\n } catch (error) {\n failed.push({ key: entry.key, error });\n } finally {\n settled++;\n this.progress = settled / total;\n this.onProgress.emit(this.progress);\n }\n });\n\n await Promise.all(promises);\n return { loaded, failed };\n }\n\n /** Get a loaded asset by key. Returns undefined if not found. */\n get<T = unknown>(key: string): T | undefined {\n return this._assets.get(key) as T | undefined;\n }\n\n /** Check if an asset is loaded. */\n has(key: string): boolean {\n return this._assets.has(key);\n }\n\n /** Remove an asset from the cache. */\n unload(key: string): boolean {\n return this._assets.delete(key);\n }\n\n /** Clear all cached assets. */\n clear(): void {\n this._assets.clear();\n this.progress = 0;\n }\n}\n","import type { SkImageLike } from './texture.js';\n\n/** Opaque handle for a Skia SkData object. */\nexport interface SkDataLike {\n readonly __skData: unique symbol;\n}\n\n/**\n * Narrow view of the Skia module — only the factories this helper needs.\n * Injected by the caller so @flare-engine/assets stays runtime-agnostic.\n */\nexport interface SkiaImageDecodeModuleLike {\n Data: {\n fromBytes(bytes: Uint8Array): SkDataLike;\n };\n Image: {\n MakeImageFromEncoded(data: SkDataLike): SkImageLike | null;\n };\n}\n\n/**\n * Decode raw image bytes into a Skia SkImage.\n *\n * Returns null on failure — never throws. Callers are responsible for\n * handling null (e.g. falling back to a placeholder texture).\n */\nexport function decodeImage(\n Skia: SkiaImageDecodeModuleLike,\n bytes: Uint8Array,\n): SkImageLike | null {\n const data = Skia.Data.fromBytes(bytes);\n return Skia.Image.MakeImageFromEncoded(data);\n}\n","/** Minimal interface for the Skia SkImage we wrap. */\nexport interface SkImageLike {\n width(): number;\n height(): number;\n readPixels(): Float32Array | Uint8Array | null;\n /**\n * Optional — present on GPU-backed SkImages returned by RN-Skia's\n * MakeOffscreen surfaces. Copies the texture into a CPU-raster image so it\n * can be safely sampled from a different GrDirectContext (e.g. the on-screen\n * Canvas). Must be called before the image crosses a context boundary.\n */\n makeNonTextureImage?(): SkImageLike;\n}\n\n/** A loaded texture wrapping a Skia SkImage. */\nexport interface Texture {\n /** Unique key for this texture in the asset manager. */\n readonly key: string;\n /** The underlying Skia SkImage. */\n readonly image: SkImageLike;\n /** Width in pixels. */\n readonly width: number;\n /** Height in pixels. */\n readonly height: number;\n}\n\n/** Create a Texture from a Skia SkImage. */\nexport function createTexture(key: string, image: SkImageLike): Texture {\n return {\n key,\n image,\n width: image.width(),\n height: image.height(),\n };\n}\n","import type { AssetLoader, ManifestEntry } from './asset-manager.js';\nimport type { SkImageLike } from './texture.js';\nimport { createTexture } from './texture.js';\n\n/**\n * Decodes raw image bytes into an SkImage. Returns `null` on failure.\n * Wire it to `decodeImage(Skia, bytes)` (native) or `kit.MakeImageFromEncoded`\n * (CanvasKit / web) — see the package README for both.\n */\nexport type DecodeImage = (bytes: Uint8Array) => SkImageLike | null;\n\n/** Minimal structural view of a fetch `Response` — only what the loader reads. */\nexport interface FetchResponseLike {\n readonly ok: boolean;\n readonly status: number;\n arrayBuffer(): Promise<ArrayBuffer>;\n json(): Promise<unknown>;\n}\n\n/**\n * Minimal structural `fetch`. The global `fetch` (web / RN / Bun) satisfies it,\n * so the package needs no DOM/Bun fetch typing of its own.\n */\nexport type FetchLike = (path: string) => Promise<FetchResponseLike>;\n\n/** Options for {@link createFetchAssetLoader}. */\nexport interface FetchAssetLoaderOptions {\n /** Decodes fetched image bytes into an SkImage. */\n decodeImage: DecodeImage;\n /** `fetch` implementation; defaults to the global `fetch`. */\n fetch?: FetchLike;\n}\n\n/** Options for {@link createFileAssetLoader}. */\nexport interface FileAssetLoaderOptions {\n /**\n * Reads a file path into raw bytes — structural, so any native filesystem\n * (e.g. expo-file-system) satisfies it without a hard dependency here.\n */\n readFile: (path: string) => Promise<Uint8Array>;\n /** Decodes read image bytes into an SkImage. */\n decodeImage: DecodeImage;\n}\n\n/**\n * A web `AssetLoader` backed by `fetch`. `texture` entries are decoded into a\n * `Texture`; `binary` yields a `Uint8Array`; `json`/`spritesheet` yield the\n * parsed JSON (feed a spritesheet result to `parseTexturePackerHash` etc.).\n *\n * Fail-fast: a non-OK response or a null decode throws, so `AssetManager.load`\n * rejects. Use `AssetManager.loadManifestSettled` for partial-failure tolerance.\n */\nexport function createFetchAssetLoader(options: FetchAssetLoaderOptions): AssetLoader {\n const { decodeImage } = options;\n const fetchFn: FetchLike = options.fetch ?? globalThis.fetch;\n return async (entry: ManifestEntry) => {\n const response = await fetchFn(entry.path);\n if (!response.ok) {\n throw new Error(\n `[flare-engine/assets] fetch failed for \"${entry.key}\" (${entry.path}): ${response.status}`,\n );\n }\n switch (entry.type) {\n case 'texture': {\n const bytes = new Uint8Array(await response.arrayBuffer());\n const image = decodeImage(bytes);\n if (!image) {\n throw new Error(\n `[flare-engine/assets] image decode failed for \"${entry.key}\" (${entry.path})`,\n );\n }\n return createTexture(entry.key, image);\n }\n case 'binary':\n return new Uint8Array(await response.arrayBuffer());\n default:\n return response.json();\n }\n };\n}\n\n/**\n * A native `AssetLoader` backed by an injected `readFile`. `texture` entries are\n * decoded into a `Texture`; `binary` yields the raw `Uint8Array`;\n * `json`/`spritesheet` yield the JSON parsed from UTF-8 bytes.\n *\n * Fail-fast: a null decode (or a rejecting `readFile`) throws.\n */\nexport function createFileAssetLoader(options: FileAssetLoaderOptions): AssetLoader {\n const { readFile, decodeImage } = options;\n return async (entry: ManifestEntry) => {\n const bytes = await readFile(entry.path);\n switch (entry.type) {\n case 'texture': {\n const image = decodeImage(bytes);\n if (!image) {\n throw new Error(\n `[flare-engine/assets] image decode failed for \"${entry.key}\" (${entry.path})`,\n );\n }\n return createTexture(entry.key, image);\n }\n case 'binary':\n return bytes;\n default:\n return JSON.parse(new TextDecoder().decode(bytes));\n }\n };\n}\n","/** A single frame rectangle in a sprite sheet. */\nexport interface SpriteFrame {\n /** Name/key of the frame. */\n name: string;\n /** X offset in the source texture (pixels). */\n x: number;\n /** Y offset in the source texture (pixels). */\n y: number;\n /** Width of the frame (pixels). */\n w: number;\n /** Height of the frame (pixels). */\n h: number;\n}\n\n/** A named animation sequence within a sprite sheet. */\nexport interface AnimationSequence {\n /** Sequence name (e.g. \"walk\", \"idle\"). */\n name: string;\n /** Indices into the SpriteSheet.frames array. */\n frameIndices: number[];\n /** Duration per frame in seconds. */\n frameDuration: number;\n /** Whether to loop the sequence. */\n loop: boolean;\n}\n\n/** Parsed sprite sheet data — pure data, no Skia dependency. */\nexport interface SpriteSheet {\n /** Ordered array of all frames. */\n frames: SpriteFrame[];\n /** Map from frame name to index in frames[]. */\n frameMap: Map<string, number>;\n /** Named animation sequences. */\n animations: Map<string, AnimationSequence>;\n}\n\n/** Create an empty sprite sheet. */\nexport function createSpriteSheet(): SpriteSheet {\n return {\n frames: [],\n frameMap: new Map(),\n animations: new Map(),\n };\n}\n\n// ----- Rotated-frame dev warning -----\n\ndeclare const __DEV__: boolean | undefined;\n\n/**\n * Warn (dev builds only) when a TexturePacker frame is exported rotated.\n * Rotated frames are not yet remapped, so they render sideways — the frame is\n * named so the artist can re-export it. Full rotation support is post-launch.\n */\nfunction warnRotatedFrame(name: string): void {\n if (typeof __DEV__ !== 'undefined' && __DEV__) {\n console.warn(\n `[flare-engine/assets] sprite frame \"${name}\": rotation unsupported — re-export without rotation`,\n );\n }\n}\n\n// ----- TexturePacker JSON (hash format) -----\n\ninterface TPHashFrame {\n frame: { x: number; y: number; w: number; h: number };\n rotated?: boolean;\n}\n\ninterface TPHashJSON {\n frames: Record<string, TPHashFrame>;\n}\n\n/** Parse TexturePacker JSON hash format. */\nexport function parseTexturePackerHash(json: unknown): SpriteSheet {\n const data = json as TPHashJSON;\n const sheet = createSpriteSheet();\n const entries = Object.entries(data.frames);\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (!entry) continue;\n const [name, value] = entry;\n if (value.rotated) warnRotatedFrame(name);\n const f = value.frame;\n sheet.frames.push({ name, x: f.x, y: f.y, w: f.w, h: f.h });\n sheet.frameMap.set(name, i);\n }\n return sheet;\n}\n\n// ----- TexturePacker JSON (array format) -----\n\ninterface TPArrayFrame {\n filename: string;\n frame: { x: number; y: number; w: number; h: number };\n rotated?: boolean;\n}\n\ninterface TPArrayJSON {\n frames: TPArrayFrame[];\n}\n\n/** Parse TexturePacker JSON array format. */\nexport function parseTexturePackerArray(json: unknown): SpriteSheet {\n const data = json as TPArrayJSON;\n const sheet = createSpriteSheet();\n for (let i = 0; i < data.frames.length; i++) {\n const entry = data.frames[i];\n if (!entry) continue;\n if (entry.rotated) warnRotatedFrame(entry.filename);\n const f = entry.frame;\n sheet.frames.push({\n name: entry.filename,\n x: f.x,\n y: f.y,\n w: f.w,\n h: f.h,\n });\n sheet.frameMap.set(entry.filename, i);\n }\n return sheet;\n}\n\n// ----- Aseprite JSON -----\n\ninterface AsepriteFrame {\n filename: string;\n frame: { x: number; y: number; w: number; h: number };\n duration: number; // ms\n}\n\ninterface AsepriteTag {\n name: string;\n from: number;\n to: number;\n direction: string;\n}\n\ninterface AsepriteJSON {\n frames: AsepriteFrame[] | Record<string, AsepriteFrame>;\n meta?: {\n frameTags?: AsepriteTag[];\n };\n}\n\n/** Parse Aseprite JSON export. */\nexport function parseAseprite(json: unknown): SpriteSheet {\n const data = json as AsepriteJSON;\n const sheet = createSpriteSheet();\n\n // Aseprite can export frames as array or object\n const frameEntries: AsepriteFrame[] = Array.isArray(data.frames)\n ? data.frames\n : Object.values(data.frames);\n\n for (let i = 0; i < frameEntries.length; i++) {\n const entry = frameEntries[i];\n if (!entry) continue;\n const f = entry.frame;\n sheet.frames.push({\n name: entry.filename,\n x: f.x,\n y: f.y,\n w: f.w,\n h: f.h,\n });\n sheet.frameMap.set(entry.filename, i);\n }\n\n // Parse frame tags as animation sequences\n const tags = data.meta?.frameTags;\n if (tags) {\n for (const tag of tags) {\n const indices: number[] = [];\n if (tag.direction === 'reverse') {\n for (let i = tag.to; i >= tag.from; i--) {\n indices.push(i);\n }\n } else if (tag.direction === 'pingpong') {\n for (let i = tag.from; i <= tag.to; i++) {\n indices.push(i);\n }\n for (let i = tag.to - 1; i > tag.from; i--) {\n indices.push(i);\n }\n } else {\n // \"forward\" or default\n for (let i = tag.from; i <= tag.to; i++) {\n indices.push(i);\n }\n }\n\n // Use the first frame's duration as the uniform frame duration\n const firstFrame = frameEntries[tag.from];\n const durationMs = firstFrame?.duration ?? 100;\n\n sheet.animations.set(tag.name, {\n name: tag.name,\n frameIndices: indices,\n frameDuration: durationMs / 1000,\n loop: true,\n });\n }\n }\n\n return sheet;\n}\n\n/**\n * Add a custom animation sequence to a sprite sheet.\n */\nexport function addAnimation(\n sheet: SpriteSheet,\n name: string,\n frameIndices: number[],\n frameDuration: number,\n loop = true,\n): void {\n sheet.animations.set(name, { name, frameIndices, frameDuration, loop });\n}\n\n/** Get a frame by name. Returns undefined if not found. */\nexport function getFrame(sheet: SpriteSheet, name: string): SpriteFrame | undefined {\n const idx = sheet.frameMap.get(name);\n if (idx === undefined) return undefined;\n return sheet.frames[idx];\n}\n","import { createSpriteSheet, type SpriteFrame, type SpriteSheet } from './sprite-sheet.js';\nimport type { SkImageLike } from './texture.js';\n\n/** One entry in a procedural atlas — a named colored rectangle. */\nexport interface ProceduralFrameSpec {\n /** Frame name (used as the SpriteFrame name for lookup). */\n name: string;\n /** Width in pixels. */\n w: number;\n /** Height in pixels. */\n h: number;\n /** Color as ARGB int (0xAARRGGBB). */\n color: number;\n}\n\n/** Options controlling atlas layout. */\nexport interface ProceduralAtlasOptions {\n /** Max atlas width before wrapping to a new row. Default 1024. */\n maxWidth?: number;\n /** Gap between frames in pixels. Default 0. */\n padding?: number;\n}\n\n/** Result of a procedural atlas build. */\nexport interface ProceduralAtlas {\n /** Backing Skia image with all rects drawn. */\n image: SkImageLike;\n /** SpriteSheet whose frames describe the rect positions. */\n sheet: SpriteSheet;\n /** Total atlas width in pixels. */\n width: number;\n /** Total atlas height in pixels. */\n height: number;\n}\n\n/** Opaque Skia color value — a Float32Array of length 4 (r, g, b, a in [0,1]). */\ntype SkColorLike = Float32Array;\n\n/** Narrow paint interface — only the setter we use. */\nexport interface SkPaintLike {\n setColor(color: SkColorLike): void;\n}\n\n/** Narrow rect interface — a rect value object passed to drawRect. */\nexport interface SkRectLike {\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n}\n\n/** Narrow canvas interface — only the method we use. */\nexport interface SkCanvasLike {\n drawRect(rect: SkRectLike, paint: SkPaintLike): void;\n}\n\n/** Narrow surface interface — getCanvas + snapshot. */\nexport interface SkSurfaceLike {\n getCanvas(): SkCanvasLike;\n makeImageSnapshot(): SkImageLike;\n}\n\n/**\n * Narrow view of the Skia module — only the factories this helper needs.\n * Declared locally so unit tests can supply a plain mock without pulling\n * in the full `@shopify/react-native-skia` surface.\n */\nexport interface SkiaAtlasModuleLike {\n Surface: { Make(width: number, height: number): SkSurfaceLike | null };\n Paint(): SkPaintLike;\n XYWHRect(x: number, y: number, w: number, h: number): SkRectLike;\n}\n\n/**\n * Build a flat atlas `SkImage` from a list of colored rectangles.\n *\n * Row-packs frames left-to-right until `maxWidth` is exceeded, then wraps\n * to a new row. Returns both the backing image and a `SpriteSheet` whose\n * frames match the packed positions, so consumers can look up frames by\n * name exactly as with a real `parseTexturePacker*` sheet.\n *\n * Useful for:\n * - bootstrapping gameplay before final art lands (replace with one\n * `parseTexturePackerHash` call once the real atlas arrives),\n * - engine tests / benchmarks that need a valid `SkImage` without\n * shipping any binary asset.\n *\n * **Canonical placeholder-atlas pattern:** a game can ship a full \"shape\n * atlas\" that draws every entity (enemies, bosses, ships, pickups) as\n * composed primitives onto an offscreen Skia surface, then wraps the result\n * in a `SpriteSheet`.\n * That pattern (declarative shape spec → Skia draw calls → `SpriteSheet`\n * with one named frame per shape) is the recommended way to build a\n * manifest-swappable placeholder atlas: when final art lands, swap the\n * shape draw-calls for `parseTexturePackerHash(jsonText)` with no other\n * code changes.\n */\nexport function createProceduralAtlas(\n Skia: SkiaAtlasModuleLike,\n frames: readonly ProceduralFrameSpec[],\n options: ProceduralAtlasOptions = {},\n): ProceduralAtlas {\n const maxWidth = options.maxWidth ?? 1024;\n const padding = options.padding ?? 0;\n\n const positions = layoutRows(frames, maxWidth, padding);\n const surface = Skia.Surface.Make(positions.width, positions.height);\n if (surface === null) {\n throw new Error(`Skia.Surface.Make returned null for ${positions.width}x${positions.height}`);\n }\n\n const canvas = surface.getCanvas();\n const paint = Skia.Paint();\n const color: SkColorLike = new Float32Array(4);\n\n const sheet = createSpriteSheet();\n\n for (let i = 0; i < frames.length; i++) {\n const spec = frames[i];\n const pos = positions.rects[i];\n if (spec === undefined || pos === undefined) continue;\n\n writeArgb(color, spec.color);\n paint.setColor(color);\n canvas.drawRect(Skia.XYWHRect(pos.x, pos.y, spec.w, spec.h), paint);\n\n const frame: SpriteFrame = {\n name: spec.name,\n x: pos.x,\n y: pos.y,\n w: spec.w,\n h: spec.h,\n };\n sheet.frames.push(frame);\n sheet.frameMap.set(spec.name, i);\n }\n\n return {\n image: surface.makeImageSnapshot(),\n sheet,\n width: positions.width,\n height: positions.height,\n };\n}\n\ninterface PackedPosition {\n x: number;\n y: number;\n}\n\ninterface PackedLayout {\n rects: PackedPosition[];\n width: number;\n height: number;\n}\n\nfunction layoutRows(\n frames: readonly ProceduralFrameSpec[],\n maxWidth: number,\n padding: number,\n): PackedLayout {\n const rects: PackedPosition[] = [];\n let x = 0;\n let y = 0;\n let rowHeight = 0;\n let atlasWidth = 0;\n\n for (const spec of frames) {\n if (x > 0 && x + spec.w > maxWidth) {\n y += rowHeight + padding;\n x = 0;\n rowHeight = 0;\n }\n rects.push({ x, y });\n x += spec.w + padding;\n if (spec.h > rowHeight) rowHeight = spec.h;\n if (x - padding > atlasWidth) atlasWidth = x - padding;\n }\n\n const atlasHeight = y + rowHeight;\n return {\n rects,\n width: atlasWidth > 0 ? atlasWidth : 1,\n height: atlasHeight > 0 ? atlasHeight : 1,\n };\n}\n\nfunction writeArgb(out: SkColorLike, argb: number): void {\n out[0] = ((argb >>> 16) & 0xff) / 255;\n out[1] = ((argb >>> 8) & 0xff) / 255;\n out[2] = (argb & 0xff) / 255;\n out[3] = ((argb >>> 24) & 0xff) / 255;\n}\n"],"mappings":";;;;;;;;;;AA2CA,IAAa,eAAb,MAA0B;;CAExB,aAAsB,IAAIA,qBAAAA,OAAe;;CAGzC,WAAW;CAEX,0B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AK;EACvB,MAAM,SAAS,IAAI,KAAK,MAAM,CAAC;CACjC;CAEA,OAAO;EACL,OAAO,QAAQ,kBAAkB;EACjC;EACA,OAAO,UAAU;EACjB,QAAQ,UAAU;CACpB;AACF;AAaA,SAAS,WACP,QACA,UACA,SACc;CACd,MAAM,QAA0B,CAAC;CACjC,IAAI,IAAI;CACR,IAAI,IAAI;CACR,IAAI,YAAY;CAChB,IAAI,aAAa;CAEjB,KAAK,MAAM,QAAQ,QAAQ;EACzB,IAAI,IAAI,KAAK,IAAI,KAAK,IAAI,UAAU;GAClC,KAAK,YAAY;GACjB,IAAI;GACJ,YAAY;EACd;EACA,MAAM,KAAK;GAAE;GAAG;EAAE,CAAC;EACnB,KAAK,KAAK,IAAI;EACd,IAAI,KAAK,IAAI,WAAW,YAAY,KAAK;EACzC,IAAI,IAAI,UAAU,YAAY,aAAa,IAAI;CACjD;CAEA,MAAM,cAAc,IAAI;CACxB,OAAO;EACL;EACA,OAAO,aAAa,IAAI,aAAa;EACrC,QAAQ,cAAc,IAAI,cAAc;CAC1C;AACF;AAEA,SAAS,UAAU,KAAkB,MAAoB;CACvD,IAAI,MAAO,SAAS,KAAM,OAAQ;CAClC,IAAI,MAAO,SAAS,IAAK,OAAQ;CACjC,IAAI,MAAM,OAAO,OAAQ;CACzB,IAAI,MAAO,SAAS,KAAM,OAAQ;AACpC"}
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Signal } from "@flare-engine/events";
2
- //#region src/asset-manager.ts
2
+ // src/asset-manager.ts
3
3
  /**
4
4
  * AssetManager — loads, caches, and provides access to game assets.
5
5
  *
@@ -97,8 +97,7 @@ var AssetManager = class {
97
97
  this.progress = 0;
98
98
  }
99
99
  };
100
- //#endregion
101
- //#region src/decode-image.ts
100
+ // src/decode-image.ts
102
101
  /**
103
102
  * Decode raw image bytes into a Skia SkImage.
104
103
  *
@@ -109,8 +108,7 @@ function decodeImage(Skia, bytes) {
109
108
  const data = Skia.Data.fromBytes(bytes);
110
109
  return Skia.Image.MakeImageFromEncoded(data);
111
110
  }
112
- //#endregion
113
- //#region src/texture.ts
111
+ // src/texture.ts
114
112
  /** Create a Texture from a Skia SkImage. */
115
113
  function createTexture(key, image) {
116
114
  return {
@@ -120,8 +118,7 @@ function createTexture(key, image) {
120
118
  height: image.height()
121
119
  };
122
120
  }
123
- //#endregion
124
- //#region src/loaders.ts
121
+ // src/loaders.ts
125
122
  /**
126
123
  * A web `AssetLoader` backed by `fetch`. `texture` entries are decoded into a
127
124
  * `Texture`; `binary` yields a `Uint8Array`; `json`/`spritesheet` yield the
@@ -170,8 +167,7 @@ function createFileAssetLoader(options) {
170
167
  }
171
168
  };
172
169
  }
173
- //#endregion
174
- //#region src/sprite-sheet.ts
170
+ // src/sprite-sheet.ts
175
171
  /** Create an empty sprite sheet. */
176
172
  function createSpriteSheet() {
177
173
  return {
@@ -283,8 +279,7 @@ function getFrame(sheet, name) {
283
279
  if (idx === void 0) return void 0;
284
280
  return sheet.frames[idx];
285
281
  }
286
- //#endregion
287
- //#region src/procedural-atlas.ts
282
+ // src/procedural-atlas.ts
288
283
  /**
289
284
  * Build a flat atlas `SkImage` from a list of colored rectangles.
290
285
  *
@@ -374,7 +369,6 @@ function writeArgb(out, argb) {
374
369
  out[2] = (argb & 255) / 255;
375
370
  out[3] = (argb >>> 24 & 255) / 255;
376
371
  }
377
- //#endregion
378
372
  export { AssetManager, addAnimation, createFetchAssetLoader, createFileAssetLoader, createProceduralAtlas, createSpriteSheet, createTexture, decodeImage, getFrame, parseAseprite, parseTexturePackerArray, parseTexturePackerHash };
379
373
 
380
374
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/asset-manager.ts","../src/decode-image.ts","../src/texture.ts","../src/loaders.ts","../src/sprite-sheet.ts","../src/procedural-atlas.ts"],"sourcesContent":["import { Signal } from '@flare-engine/events';\nimport type { SpriteSheet } from './sprite-sheet.js';\nimport type { Texture } from './texture.js';\n\n/** Types of assets the manager can store. */\nexport type AssetType = 'texture' | 'spritesheet' | 'json' | 'binary';\n\n/** A single entry in an asset manifest. */\nexport interface ManifestEntry {\n /** Unique key to retrieve this asset. */\n key: string;\n /** Asset type. */\n type: AssetType;\n /** Path or URI to the asset. */\n path: string;\n}\n\n/** A load function provided by the platform to actually fetch+decode assets. */\nexport type AssetLoader = (entry: ManifestEntry) => Promise<Texture | SpriteSheet | unknown>;\n\n/** A single entry that failed during {@link AssetManager.loadManifestSettled}. */\nexport interface ManifestLoadFailure {\n /** Key of the manifest entry that failed. */\n key: string;\n /** The value thrown by the loader (an `Error` or otherwise). */\n error: unknown;\n}\n\n/** Partial-failure summary returned by {@link AssetManager.loadManifestSettled}. */\nexport interface ManifestLoadResult {\n /** Keys of entries that loaded and were cached. */\n loaded: string[];\n /** Entries that threw, with the captured error. */\n failed: ManifestLoadFailure[];\n}\n\n/**\n * AssetManager — loads, caches, and provides access to game assets.\n *\n * Platform-agnostic: the actual loading is delegated to an `AssetLoader`\n * function injected at construction. This allows Skia-dependent texture\n * loading to live in the React layer while keeping this module testable.\n */\nexport class AssetManager {\n /** Fires on each asset loaded with current progress (0-1). */\n readonly onProgress = new Signal<number>();\n\n /** Current loading progress 0-1. */\n progress = 0;\n\n private _assets = new Map<string, unknown>();\n private _loader: AssetLoader;\n\n constructor(loader: AssetLoader) {\n this._loader = loader;\n }\n\n /**\n * Load all assets in the manifest.\n * Resolves when all assets are loaded and cached.\n */\n async load(manifest: ManifestEntry[]): Promise<void> {\n if (manifest.length === 0) {\n this.progress = 1;\n this.onProgress.emit(1);\n return;\n }\n\n let loaded = 0;\n const total = manifest.length;\n\n const promises = manifest.map(async (entry) => {\n const asset = await this._loader(entry);\n this._assets.set(entry.key, asset);\n loaded++;\n this.progress = loaded / total;\n this.onProgress.emit(this.progress);\n });\n\n await Promise.all(promises);\n }\n\n /**\n * Load all assets without rejecting on the first failure. Successful assets\n * are cached; failures are collected and returned. Progress still advances to\n * 1 once every entry has settled. Prefer this over {@link load} when a partial\n * asset set is acceptable (e.g. optional/decorative assets).\n */\n async loadManifestSettled(manifest: ManifestEntry[]): Promise<ManifestLoadResult> {\n const loaded: string[] = [];\n const failed: ManifestLoadFailure[] = [];\n\n if (manifest.length === 0) {\n this.progress = 1;\n this.onProgress.emit(1);\n return { loaded, failed };\n }\n\n let settled = 0;\n const total = manifest.length;\n\n const promises = manifest.map(async (entry) => {\n try {\n const asset = await this._loader(entry);\n this._assets.set(entry.key, asset);\n loaded.push(entry.key);\n } catch (error) {\n failed.push({ key: entry.key, error });\n } finally {\n settled++;\n this.progress = settled / total;\n this.onProgress.emit(this.progress);\n }\n });\n\n await Promise.all(promises);\n return { loaded, failed };\n }\n\n /** Get a loaded asset by key. Returns undefined if not found. */\n get<T = unknown>(key: string): T | undefined {\n return this._assets.get(key) as T | undefined;\n }\n\n /** Check if an asset is loaded. */\n has(key: string): boolean {\n return this._assets.has(key);\n }\n\n /** Remove an asset from the cache. */\n unload(key: string): boolean {\n return this._assets.delete(key);\n }\n\n /** Clear all cached assets. */\n clear(): void {\n this._assets.clear();\n this.progress = 0;\n }\n}\n","import type { SkImageLike } from './texture.js';\n\n/** Opaque handle for a Skia SkData object. */\nexport interface SkDataLike {\n readonly __skData: unique symbol;\n}\n\n/**\n * Narrow view of the Skia module — only the factories this helper needs.\n * Injected by the caller so @flare-engine/assets stays runtime-agnostic.\n */\nexport interface SkiaImageDecodeModuleLike {\n Data: {\n fromBytes(bytes: Uint8Array): SkDataLike;\n };\n Image: {\n MakeImageFromEncoded(data: SkDataLike): SkImageLike | null;\n };\n}\n\n/**\n * Decode raw image bytes into a Skia SkImage.\n *\n * Returns null on failure — never throws. Callers are responsible for\n * handling null (e.g. falling back to a placeholder texture).\n */\nexport function decodeImage(\n Skia: SkiaImageDecodeModuleLike,\n bytes: Uint8Array,\n): SkImageLike | null {\n const data = Skia.Data.fromBytes(bytes);\n return Skia.Image.MakeImageFromEncoded(data);\n}\n","/** Minimal interface for the Skia SkImage we wrap. */\nexport interface SkImageLike {\n width(): number;\n height(): number;\n readPixels(): Float32Array | Uint8Array | null;\n /**\n * Optional — present on GPU-backed SkImages returned by RN-Skia's\n * MakeOffscreen surfaces. Copies the texture into a CPU-raster image so it\n * can be safely sampled from a different GrDirectContext (e.g. the on-screen\n * Canvas). Must be called before the image crosses a context boundary.\n */\n makeNonTextureImage?(): SkImageLike;\n}\n\n/** A loaded texture wrapping a Skia SkImage. */\nexport interface Texture {\n /** Unique key for this texture in the asset manager. */\n readonly key: string;\n /** The underlying Skia SkImage. */\n readonly image: SkImageLike;\n /** Width in pixels. */\n readonly width: number;\n /** Height in pixels. */\n readonly height: number;\n}\n\n/** Create a Texture from a Skia SkImage. */\nexport function createTexture(key: string, image: SkImageLike): Texture {\n return {\n key,\n image,\n width: image.width(),\n height: image.height(),\n };\n}\n","import type { AssetLoader, ManifestEntry } from './asset-manager.js';\nimport type { SkImageLike } from './texture.js';\nimport { createTexture } from './texture.js';\n\n/**\n * Decodes raw image bytes into an SkImage. Returns `null` on failure.\n * Wire it to `decodeImage(Skia, bytes)` (native) or `kit.MakeImageFromEncoded`\n * (CanvasKit / web) — see the package README for both.\n */\nexport type DecodeImage = (bytes: Uint8Array) => SkImageLike | null;\n\n/** Minimal structural view of a fetch `Response` — only what the loader reads. */\nexport interface FetchResponseLike {\n readonly ok: boolean;\n readonly status: number;\n arrayBuffer(): Promise<ArrayBuffer>;\n json(): Promise<unknown>;\n}\n\n/**\n * Minimal structural `fetch`. The global `fetch` (web / RN / Bun) satisfies it,\n * so the package needs no DOM/Bun fetch typing of its own.\n */\nexport type FetchLike = (path: string) => Promise<FetchResponseLike>;\n\n/** Options for {@link createFetchAssetLoader}. */\nexport interface FetchAssetLoaderOptions {\n /** Decodes fetched image bytes into an SkImage. */\n decodeImage: DecodeImage;\n /** `fetch` implementation; defaults to the global `fetch`. */\n fetch?: FetchLike;\n}\n\n/** Options for {@link createFileAssetLoader}. */\nexport interface FileAssetLoaderOptions {\n /**\n * Reads a file path into raw bytes — structural, so any native filesystem\n * (e.g. expo-file-system) satisfies it without a hard dependency here.\n */\n readFile: (path: string) => Promise<Uint8Array>;\n /** Decodes read image bytes into an SkImage. */\n decodeImage: DecodeImage;\n}\n\n/**\n * A web `AssetLoader` backed by `fetch`. `texture` entries are decoded into a\n * `Texture`; `binary` yields a `Uint8Array`; `json`/`spritesheet` yield the\n * parsed JSON (feed a spritesheet result to `parseTexturePackerHash` etc.).\n *\n * Fail-fast: a non-OK response or a null decode throws, so `AssetManager.load`\n * rejects. Use `AssetManager.loadManifestSettled` for partial-failure tolerance.\n */\nexport function createFetchAssetLoader(options: FetchAssetLoaderOptions): AssetLoader {\n const { decodeImage } = options;\n const fetchFn: FetchLike = options.fetch ?? globalThis.fetch;\n return async (entry: ManifestEntry) => {\n const response = await fetchFn(entry.path);\n if (!response.ok) {\n throw new Error(\n `[flare-engine/assets] fetch failed for \"${entry.key}\" (${entry.path}): ${response.status}`,\n );\n }\n switch (entry.type) {\n case 'texture': {\n const bytes = new Uint8Array(await response.arrayBuffer());\n const image = decodeImage(bytes);\n if (!image) {\n throw new Error(\n `[flare-engine/assets] image decode failed for \"${entry.key}\" (${entry.path})`,\n );\n }\n return createTexture(entry.key, image);\n }\n case 'binary':\n return new Uint8Array(await response.arrayBuffer());\n default:\n return response.json();\n }\n };\n}\n\n/**\n * A native `AssetLoader` backed by an injected `readFile`. `texture` entries are\n * decoded into a `Texture`; `binary` yields the raw `Uint8Array`;\n * `json`/`spritesheet` yield the JSON parsed from UTF-8 bytes.\n *\n * Fail-fast: a null decode (or a rejecting `readFile`) throws.\n */\nexport function createFileAssetLoader(options: FileAssetLoaderOptions): AssetLoader {\n const { readFile, decodeImage } = options;\n return async (entry: ManifestEntry) => {\n const bytes = await readFile(entry.path);\n switch (entry.type) {\n case 'texture': {\n const image = decodeImage(bytes);\n if (!image) {\n throw new Error(\n `[flare-engine/assets] image decode failed for \"${entry.key}\" (${entry.path})`,\n );\n }\n return createTexture(entry.key, image);\n }\n case 'binary':\n return bytes;\n default:\n return JSON.parse(new TextDecoder().decode(bytes));\n }\n };\n}\n","/** A single frame rectangle in a sprite sheet. */\nexport interface SpriteFrame {\n /** Name/key of the frame. */\n name: string;\n /** X offset in the source texture (pixels). */\n x: number;\n /** Y offset in the source texture (pixels). */\n y: number;\n /** Width of the frame (pixels). */\n w: number;\n /** Height of the frame (pixels). */\n h: number;\n}\n\n/** A named animation sequence within a sprite sheet. */\nexport interface AnimationSequence {\n /** Sequence name (e.g. \"walk\", \"idle\"). */\n name: string;\n /** Indices into the SpriteSheet.frames array. */\n frameIndices: number[];\n /** Duration per frame in seconds. */\n frameDuration: number;\n /** Whether to loop the sequence. */\n loop: boolean;\n}\n\n/** Parsed sprite sheet data — pure data, no Skia dependency. */\nexport interface SpriteSheet {\n /** Ordered array of all frames. */\n frames: SpriteFrame[];\n /** Map from frame name to index in frames[]. */\n frameMap: Map<string, number>;\n /** Named animation sequences. */\n animations: Map<string, AnimationSequence>;\n}\n\n/** Create an empty sprite sheet. */\nexport function createSpriteSheet(): SpriteSheet {\n return {\n frames: [],\n frameMap: new Map(),\n animations: new Map(),\n };\n}\n\n// ----- Rotated-frame dev warning -----\n\ndeclare const __DEV__: boolean | undefined;\n\n/**\n * Warn (dev builds only) when a TexturePacker frame is exported rotated.\n * Rotated frames are not yet remapped, so they render sideways — the frame is\n * named so the artist can re-export it. Full rotation support is post-launch.\n */\nfunction warnRotatedFrame(name: string): void {\n if (typeof __DEV__ !== 'undefined' && __DEV__) {\n console.warn(\n `[flare-engine/assets] sprite frame \"${name}\": rotation unsupported — re-export without rotation`,\n );\n }\n}\n\n// ----- TexturePacker JSON (hash format) -----\n\ninterface TPHashFrame {\n frame: { x: number; y: number; w: number; h: number };\n rotated?: boolean;\n}\n\ninterface TPHashJSON {\n frames: Record<string, TPHashFrame>;\n}\n\n/** Parse TexturePacker JSON hash format. */\nexport function parseTexturePackerHash(json: unknown): SpriteSheet {\n const data = json as TPHashJSON;\n const sheet = createSpriteSheet();\n const entries = Object.entries(data.frames);\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (!entry) continue;\n const [name, value] = entry;\n if (value.rotated) warnRotatedFrame(name);\n const f = value.frame;\n sheet.frames.push({ name, x: f.x, y: f.y, w: f.w, h: f.h });\n sheet.frameMap.set(name, i);\n }\n return sheet;\n}\n\n// ----- TexturePacker JSON (array format) -----\n\ninterface TPArrayFrame {\n filename: string;\n frame: { x: number; y: number; w: number; h: number };\n rotated?: boolean;\n}\n\ninterface TPArrayJSON {\n frames: TPArrayFrame[];\n}\n\n/** Parse TexturePacker JSON array format. */\nexport function parseTexturePackerArray(json: unknown): SpriteSheet {\n const data = json as TPArrayJSON;\n const sheet = createSpriteSheet();\n for (let i = 0; i < data.frames.length; i++) {\n const entry = data.frames[i];\n if (!entry) continue;\n if (entry.rotated) warnRotatedFrame(entry.filename);\n const f = entry.frame;\n sheet.frames.push({\n name: entry.filename,\n x: f.x,\n y: f.y,\n w: f.w,\n h: f.h,\n });\n sheet.frameMap.set(entry.filename, i);\n }\n return sheet;\n}\n\n// ----- Aseprite JSON -----\n\ninterface AsepriteFrame {\n filename: string;\n frame: { x: number; y: number; w: number; h: number };\n duration: number; // ms\n}\n\ninterface AsepriteTag {\n name: string;\n from: number;\n to: number;\n direction: string;\n}\n\ninterface AsepriteJSON {\n frames: AsepriteFrame[] | Record<string, AsepriteFrame>;\n meta?: {\n frameTags?: AsepriteTag[];\n };\n}\n\n/** Parse Aseprite JSON export. */\nexport function parseAseprite(json: unknown): SpriteSheet {\n const data = json as AsepriteJSON;\n const sheet = createSpriteSheet();\n\n // Aseprite can export frames as array or object\n const frameEntries: AsepriteFrame[] = Array.isArray(data.frames)\n ? data.frames\n : Object.values(data.frames);\n\n for (let i = 0; i < frameEntries.length; i++) {\n const entry = frameEntries[i];\n if (!entry) continue;\n const f = entry.frame;\n sheet.frames.push({\n name: entry.filename,\n x: f.x,\n y: f.y,\n w: f.w,\n h: f.h,\n });\n sheet.frameMap.set(entry.filename, i);\n }\n\n // Parse frame tags as animation sequences\n const tags = data.meta?.frameTags;\n if (tags) {\n for (const tag of tags) {\n const indices: number[] = [];\n if (tag.direction === 'reverse') {\n for (let i = tag.to; i >= tag.from; i--) {\n indices.push(i);\n }\n } else if (tag.direction === 'pingpong') {\n for (let i = tag.from; i <= tag.to; i++) {\n indices.push(i);\n }\n for (let i = tag.to - 1; i > tag.from; i--) {\n indices.push(i);\n }\n } else {\n // \"forward\" or default\n for (let i = tag.from; i <= tag.to; i++) {\n indices.push(i);\n }\n }\n\n // Use the first frame's duration as the uniform frame duration\n const firstFrame = frameEntries[tag.from];\n const durationMs = firstFrame?.duration ?? 100;\n\n sheet.animations.set(tag.name, {\n name: tag.name,\n frameIndices: indices,\n frameDuration: durationMs / 1000,\n loop: true,\n });\n }\n }\n\n return sheet;\n}\n\n/**\n * Add a custom animation sequence to a sprite sheet.\n */\nexport function addAnimation(\n sheet: SpriteSheet,\n name: string,\n frameIndices: number[],\n frameDuration: number,\n loop = true,\n): void {\n sheet.animations.set(name, { name, frameIndices, frameDuration, loop });\n}\n\n/** Get a frame by name. Returns undefined if not found. */\nexport function getFrame(sheet: SpriteSheet, name: string): SpriteFrame | undefined {\n const idx = sheet.frameMap.get(name);\n if (idx === undefined) return undefined;\n return sheet.frames[idx];\n}\n","import { createSpriteSheet, type SpriteFrame, type SpriteSheet } from './sprite-sheet.js';\nimport type { SkImageLike } from './texture.js';\n\n/** One entry in a procedural atlas — a named colored rectangle. */\nexport interface ProceduralFrameSpec {\n /** Frame name (used as the SpriteFrame name for lookup). */\n name: string;\n /** Width in pixels. */\n w: number;\n /** Height in pixels. */\n h: number;\n /** Color as ARGB int (0xAARRGGBB). */\n color: number;\n}\n\n/** Options controlling atlas layout. */\nexport interface ProceduralAtlasOptions {\n /** Max atlas width before wrapping to a new row. Default 1024. */\n maxWidth?: number;\n /** Gap between frames in pixels. Default 0. */\n padding?: number;\n}\n\n/** Result of a procedural atlas build. */\nexport interface ProceduralAtlas {\n /** Backing Skia image with all rects drawn. */\n image: SkImageLike;\n /** SpriteSheet whose frames describe the rect positions. */\n sheet: SpriteSheet;\n /** Total atlas width in pixels. */\n width: number;\n /** Total atlas height in pixels. */\n height: number;\n}\n\n/** Opaque Skia color value — a Float32Array of length 4 (r, g, b, a in [0,1]). */\ntype SkColorLike = Float32Array;\n\n/** Narrow paint interface — only the setter we use. */\nexport interface SkPaintLike {\n setColor(color: SkColorLike): void;\n}\n\n/** Narrow rect interface — a rect value object passed to drawRect. */\nexport interface SkRectLike {\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n}\n\n/** Narrow canvas interface — only the method we use. */\nexport interface SkCanvasLike {\n drawRect(rect: SkRectLike, paint: SkPaintLike): void;\n}\n\n/** Narrow surface interface — getCanvas + snapshot. */\nexport interface SkSurfaceLike {\n getCanvas(): SkCanvasLike;\n makeImageSnapshot(): SkImageLike;\n}\n\n/**\n * Narrow view of the Skia module — only the factories this helper needs.\n * Declared locally so unit tests can supply a plain mock without pulling\n * in the full `@shopify/react-native-skia` surface.\n */\nexport interface SkiaAtlasModuleLike {\n Surface: { Make(width: number, height: number): SkSurfaceLike | null };\n Paint(): SkPaintLike;\n XYWHRect(x: number, y: number, w: number, h: number): SkRectLike;\n}\n\n/**\n * Build a flat atlas `SkImage` from a list of colored rectangles.\n *\n * Row-packs frames left-to-right until `maxWidth` is exceeded, then wraps\n * to a new row. Returns both the backing image and a `SpriteSheet` whose\n * frames match the packed positions, so consumers can look up frames by\n * name exactly as with a real `parseTexturePacker*` sheet.\n *\n * Useful for:\n * - bootstrapping gameplay before final art lands (replace with one\n * `parseTexturePackerHash` call once the real atlas arrives),\n * - engine tests / benchmarks that need a valid `SkImage` without\n * shipping any binary asset.\n *\n * **Canonical placeholder-atlas pattern:** a game can ship a full \"shape\n * atlas\" that draws every entity (enemies, bosses, ships, pickups) as\n * composed primitives onto an offscreen Skia surface, then wraps the result\n * in a `SpriteSheet`.\n * That pattern (declarative shape spec → Skia draw calls → `SpriteSheet`\n * with one named frame per shape) is the recommended way to build a\n * manifest-swappable placeholder atlas: when final art lands, swap the\n * shape draw-calls for `parseTexturePackerHash(jsonText)` with no other\n * code changes.\n */\nexport function createProceduralAtlas(\n Skia: SkiaAtlasModuleLike,\n frames: readonly ProceduralFrameSpec[],\n options: ProceduralAtlasOptions = {},\n): ProceduralAtlas {\n const maxWidth = options.maxWidth ?? 1024;\n const padding = options.padding ?? 0;\n\n const positions = layoutRows(frames, maxWidth, padding);\n const surface = Skia.Surface.Make(positions.width, positions.height);\n if (surface === null) {\n throw new Error(`Skia.Surface.Make returned null for ${positions.width}x${positions.height}`);\n }\n\n const canvas = surface.getCanvas();\n const paint = Skia.Paint();\n const color: SkColorLike = new Float32Array(4);\n\n const sheet = createSpriteSheet();\n\n for (let i = 0; i < frames.length; i++) {\n const spec = frames[i];\n const pos = positions.rects[i];\n if (spec === undefined || pos === undefined) continue;\n\n writeArgb(color, spec.color);\n paint.setColor(color);\n canvas.drawRect(Skia.XYWHRect(pos.x, pos.y, spec.w, spec.h), paint);\n\n const frame: SpriteFrame = {\n name: spec.name,\n x: pos.x,\n y: pos.y,\n w: spec.w,\n h: spec.h,\n };\n sheet.frames.push(frame);\n sheet.frameMap.set(spec.name, i);\n }\n\n return {\n image: surface.makeImageSnapshot(),\n sheet,\n width: positions.width,\n height: positions.height,\n };\n}\n\ninterface PackedPosition {\n x: number;\n y: number;\n}\n\ninterface PackedLayout {\n rects: PackedPosition[];\n width: number;\n height: number;\n}\n\nfunction layoutRows(\n frames: readonly ProceduralFrameSpec[],\n maxWidth: number,\n padding: number,\n): PackedLayout {\n const rects: PackedPosition[] = [];\n let x = 0;\n let y = 0;\n let rowHeight = 0;\n let atlasWidth = 0;\n\n for (const spec of frames) {\n if (x > 0 && x + spec.w > maxWidth) {\n y += rowHeight + padding;\n x = 0;\n rowHeight = 0;\n }\n rects.push({ x, y });\n x += spec.w + padding;\n if (spec.h > rowHeight) rowHeight = spec.h;\n if (x - padding > atlasWidth) atlasWidth = x - padding;\n }\n\n const atlasHeight = y + rowHeight;\n return {\n rects,\n width: atlasWidth > 0 ? atlasWidth : 1,\n height: atlasHeight > 0 ? atlasHeight : 1,\n };\n}\n\nfunction writeArgb(out: SkColorLike, argb: number): void {\n out[0] = ((argb >>> 16) & 0xff) / 255;\n out[1] = ((argb >>> 8) & 0xff) / 255;\n out[2] = (argb & 0xff) / 255;\n out[3] = ((argb >>> 24) & 0xff) / 255;\n}\n"],"mappings":";;;;;;;;;AA2CA,IAAa,eAAb,MAA0B;;CAExB,aAAsB,IAAI,OAAe;;CAGzC,WAAW;CAEX,0BAAkB,IAAI,IAAqB;CAC3C;CAEA,YAAY,QAAqB;EAC/B,KAAK,UAAU;CACjB;;;;;CAMA,MAAM,KAAK,UAA0C;EACnD,IAAI,SAAS,WAAW,GAAG;GACzB,KAAK,WAAW;GAChB,KAAK,WAAW,KAAK,CAAC;GACtB;EACF;EAEA,IAAI,SAAS;EACb,MAAM,QAAQ,SAAS;EAEvB,MAAM,WAAW,SAAS,IAAI,OAAO,UAAU;GAC7C,MAAM,QAAQ,MAAM,KAAK,QAAQ,KAAK;GACtC,KAAK,QAAQ,IAAI,MAAM,KAAK,KAAK;GACjC;GACA,KAAK,WAAW,SAAS;GACzB,KAAK,WAAW,KAAK,KAAK,QAAQ;EACpC,CAAC;EAED,MAAM,QAAQ,IAAI,QAAQ;CAC5B;;;;;;;CAQA,MAAM,oBAAoB,UAAwD;EAChF,MAAM,SAAmB,CAAC;EAC1B,MAAM,SAAgC,CAAC;EAEvC,IAAI,SAAS,WAAW,GAAG;GACzB,KAAK,WAAW;GAChB,KAAK,WAAW,KAAK,CAAC;GACtB,OAAO;IAAE;IAAQ;GAAO;EAC1B;EAEA,IAAI,UAAU;EACd,MAAM,QAAQ,SAAS;EAEvB,MAAM,WAAW,SAAS,IAAI,OAAO,UAAU;GAC7C,IAAI;IACF,MAAM,QAAQ,MAAM,KAAK,QA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AI,MAAO,SAAS,KAAM,OAAQ;AACpC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/asset-manager.ts","../src/decode-image.ts","../src/texture.ts","../src/loaders.ts","../src/sprite-sheet.ts","../src/procedural-atlas.ts"],"sourcesContent":["import { Signal } from '@flare-engine/events';\nimport type { SpriteSheet } from './sprite-sheet.js';\nimport type { Texture } from './texture.js';\n\n/** Types of assets the manager can store. */\nexport type AssetType = 'texture' | 'spritesheet' | 'json' | 'binary';\n\n/** A single entry in an asset manifest. */\nexport interface ManifestEntry {\n /** Unique key to retrieve this asset. */\n key: string;\n /** Asset type. */\n type: AssetType;\n /** Path or URI to the asset. */\n path: string;\n}\n\n/** A load function provided by the platform to actually fetch+decode assets. */\nexport type AssetLoader = (entry: ManifestEntry) => Promise<Texture | SpriteSheet | unknown>;\n\n/** A single entry that failed during {@link AssetManager.loadManifestSettled}. */\nexport interface ManifestLoadFailure {\n /** Key of the manifest entry that failed. */\n key: string;\n /** The value thrown by the loader (an `Error` or otherwise). */\n error: unknown;\n}\n\n/** Partial-failure summary returned by {@link AssetManager.loadManifestSettled}. */\nexport interface ManifestLoadResult {\n /** Keys of entries that loaded and were cached. */\n loaded: string[];\n /** Entries that threw, with the captured error. */\n failed: ManifestLoadFailure[];\n}\n\n/**\n * AssetManager — loads, caches, and provides access to game assets.\n *\n * Platform-agnostic: the actual loading is delegated to an `AssetLoader`\n * function injected at construction. This allows Skia-dependent texture\n * loading to live in the React layer while keeping this module testable.\n */\nexport class AssetManager {\n /** Fires on each asset loaded with current progress (0-1). */\n readonly onProgress = new Signal<number>();\n\n /** Current loading progress 0-1. */\n progress = 0;\n\n private _assets = new Map<string, unknown>();\n private _loader: AssetLoader;\n\n constructor(loader: AssetLoader) {\n this._loader = loader;\n }\n\n /**\n * Load all assets in the manifest.\n * Resolves when all assets are loaded and cached.\n */\n async load(manifest: ManifestEntry[]): Promise<void> {\n if (manifest.length === 0) {\n this.progress = 1;\n this.onProgress.emit(1);\n return;\n }\n\n let loaded = 0;\n const total = manifest.length;\n\n const promises = manifest.map(async (entry) => {\n const asset = await this._loader(entry);\n this._assets.set(entry.key, asset);\n loaded++;\n this.progress = loaded / total;\n this.onProgress.emit(this.progress);\n });\n\n await Promise.all(promises);\n }\n\n /**\n * Load all assets without rejecting on the first failure. Successful assets\n * are cached; failures are collected and returned. Progress still advances to\n * 1 once every entry has settled. Prefer this over {@link load} when a partial\n * asset set is acceptable (e.g. optional/decorative assets).\n */\n async loadManifestSettled(manifest: ManifestEntry[]): Promise<ManifestLoadResult> {\n const loaded: string[] = [];\n const failed: ManifestLoadFailure[] = [];\n\n if (manifest.length === 0) {\n this.progress = 1;\n this.onProgress.emit(1);\n return { loaded, failed };\n }\n\n let settled = 0;\n const total = manifest.length;\n\n const promises = manifest.map(async (entry) => {\n try {\n const asset = await this._loader(entry);\n this._assets.set(entry.key, asset);\n loaded.push(entry.key);\n } catch (error) {\n failed.push({ key: entry.key, error });\n } finally {\n settled++;\n this.progress = settled / total;\n this.onProgress.emit(this.progress);\n }\n });\n\n await Promise.all(promises);\n return { loaded, failed };\n }\n\n /** Get a loaded asset by key. Returns undefined if not found. */\n get<T = unknown>(key: string): T | undefined {\n return this._assets.get(key) as T | undefined;\n }\n\n /** Check if an asset is loaded. */\n has(key: string): boolean {\n return this._assets.has(key);\n }\n\n /** Remove an asset from the cache. */\n unload(key: string): boolean {\n return this._assets.delete(key);\n }\n\n /** Clear all cached assets. */\n clear(): void {\n this._assets.clear();\n this.progress = 0;\n }\n}\n","import type { SkImageLike } from './texture.js';\n\n/** Opaque handle for a Skia SkData object. */\nexport interface SkDataLike {\n readonly __skData: unique symbol;\n}\n\n/**\n * Narrow view of the Skia module — only the factories this helper needs.\n * Injected by the caller so @flare-engine/assets stays runtime-agnostic.\n */\nexport interface SkiaImageDecodeModuleLike {\n Data: {\n fromBytes(bytes: Uint8Array): SkDataLike;\n };\n Image: {\n MakeImageFromEncoded(data: SkDataLike): SkImageLike | null;\n };\n}\n\n/**\n * Decode raw image bytes into a Skia SkImage.\n *\n * Returns null on failure — never throws. Callers are responsible for\n * handling null (e.g. falling back to a placeholder texture).\n */\nexport function decodeImage(\n Skia: SkiaImageDecodeModuleLike,\n bytes: Uint8Array,\n): SkImageLike | null {\n const data = Skia.Data.fromBytes(bytes);\n return Skia.Image.MakeImageFromEncoded(data);\n}\n","/** Minimal interface for the Skia SkImage we wrap. */\nexport interface SkImageLike {\n width(): number;\n height(): number;\n readPixels(): Float32Array | Uint8Array | null;\n /**\n * Optional — present on GPU-backed SkImages returned by RN-Skia's\n * MakeOffscreen surfaces. Copies the texture into a CPU-raster image so it\n * can be safely sampled from a different GrDirectContext (e.g. the on-screen\n * Canvas). Must be called before the image crosses a context boundary.\n */\n makeNonTextureImage?(): SkImageLike;\n}\n\n/** A loaded texture wrapping a Skia SkImage. */\nexport interface Texture {\n /** Unique key for this texture in the asset manager. */\n readonly key: string;\n /** The underlying Skia SkImage. */\n readonly image: SkImageLike;\n /** Width in pixels. */\n readonly width: number;\n /** Height in pixels. */\n readonly height: number;\n}\n\n/** Create a Texture from a Skia SkImage. */\nexport function createTexture(key: string, image: SkImageLike): Texture {\n return {\n key,\n image,\n width: image.width(),\n height: image.height(),\n };\n}\n","import type { AssetLoader, ManifestEntry } from './asset-manager.js';\nimport type { SkImageLike } from './texture.js';\nimport { createTexture } from './texture.js';\n\n/**\n * Decodes raw image bytes into an SkImage. Returns `null` on failure.\n * Wire it to `decodeImage(Skia, bytes)` (native) or `kit.MakeImageFromEncoded`\n * (CanvasKit / web) — see the package README for both.\n */\nexport type DecodeImage = (bytes: Uint8Array) => SkImageLike | null;\n\n/** Minimal structural view of a fetch `Response` — only what the loader reads. */\nexport interface FetchResponseLike {\n readonly ok: boolean;\n readonly status: number;\n arrayBuffer(): Promise<ArrayBuffer>;\n json(): Promise<unknown>;\n}\n\n/**\n * Minimal structural `fetch`. The global `fetch` (web / RN / Bun) satisfies it,\n * so the package needs no DOM/Bun fetch typing of its own.\n */\nexport type FetchLike = (path: string) => Promise<FetchResponseLike>;\n\n/** Options for {@link createFetchAssetLoader}. */\nexport interface FetchAssetLoaderOptions {\n /** Decodes fetched image bytes into an SkImage. */\n decodeImage: DecodeImage;\n /** `fetch` implementation; defaults to the global `fetch`. */\n fetch?: FetchLike;\n}\n\n/** Options for {@link createFileAssetLoader}. */\nexport interface FileAssetLoaderOptions {\n /**\n * Reads a file path into raw bytes — structural, so any native filesystem\n * (e.g. expo-file-system) satisfies it without a hard dependency here.\n */\n readFile: (path: string) => Promise<Uint8Array>;\n /** Decodes read image bytes into an SkImage. */\n decodeImage: DecodeImage;\n}\n\n/**\n * A web `AssetLoader` backed by `fetch`. `texture` entries are decoded into a\n * `Texture`; `binary` yields a `Uint8Array`; `json`/`spritesheet` yield the\n * parsed JSON (feed a spritesheet result to `parseTexturePackerHash` etc.).\n *\n * Fail-fast: a non-OK response or a null decode throws, so `AssetManager.load`\n * rejects. Use `AssetManager.loadManifestSettled` for partial-failure tolerance.\n */\nexport function createFetchAssetLoader(options: FetchAssetLoaderOptions): AssetLoader {\n const { decodeImage } = options;\n const fetchFn: FetchLike = options.fetch ?? globalThis.fetch;\n return async (entry: ManifestEntry) => {\n const response = await fetchFn(entry.path);\n if (!response.ok) {\n throw new Error(\n `[flare-engine/assets] fetch failed for \"${entry.key}\" (${entry.path}): ${response.status}`,\n );\n }\n switch (entry.type) {\n case 'texture': {\n const bytes = new Uint8Array(await response.arrayBuffer());\n const image = decodeImage(bytes);\n if (!image) {\n throw new Error(\n `[flare-engine/assets] image decode failed for \"${entry.key}\" (${entry.path})`,\n );\n }\n return createTexture(entry.key, image);\n }\n case 'binary':\n return new Uint8Array(await response.arrayBuffer());\n default:\n return response.json();\n }\n };\n}\n\n/**\n * A native `AssetLoader` backed by an injected `readFile`. `texture` entries are\n * decoded into a `Texture`; `binary` yields the raw `Uint8Array`;\n * `json`/`spritesheet` yield the JSON parsed from UTF-8 bytes.\n *\n * Fail-fast: a null decode (or a rejecting `readFile`) throws.\n */\nexport function createFileAssetLoader(options: FileAssetLoaderOptions): AssetLoader {\n const { readFile, decodeImage } = options;\n return async (entry: ManifestEntry) => {\n const bytes = await readFile(entry.path);\n switch (entry.type) {\n case 'texture': {\n const image = decodeImage(bytes);\n if (!image) {\n throw new Error(\n `[flare-engine/assets] image decode failed for \"${entry.key}\" (${entry.path})`,\n );\n }\n return createTexture(entry.key, image);\n }\n case 'binary':\n return bytes;\n default:\n return JSON.parse(new TextDecoder().decode(bytes));\n }\n };\n}\n","/** A single frame rectangle in a sprite sheet. */\nexport interface SpriteFrame {\n /** Name/key of the frame. */\n name: string;\n /** X offset in the source texture (pixels). */\n x: number;\n /** Y offset in the source texture (pixels). */\n y: number;\n /** Width of the frame (pixels). */\n w: number;\n /** Height of the frame (pixels). */\n h: number;\n}\n\n/** A named animation sequence within a sprite sheet. */\nexport interface AnimationSequence {\n /** Sequence name (e.g. \"walk\", \"idle\"). */\n name: string;\n /** Indices into the SpriteSheet.frames array. */\n frameIndices: number[];\n /** Duration per frame in seconds. */\n frameDuration: number;\n /** Whether to loop the sequence. */\n loop: boolean;\n}\n\n/** Parsed sprite sheet data — pure data, no Skia dependency. */\nexport interface SpriteSheet {\n /** Ordered array of all frames. */\n frames: SpriteFrame[];\n /** Map from frame name to index in frames[]. */\n frameMap: Map<string, number>;\n /** Named animation sequences. */\n animations: Map<string, AnimationSequence>;\n}\n\n/** Create an empty sprite sheet. */\nexport function createSpriteSheet(): SpriteSheet {\n return {\n frames: [],\n frameMap: new Map(),\n animations: new Map(),\n };\n}\n\n// ----- Rotated-frame dev warning -----\n\ndeclare const __DEV__: boolean | undefined;\n\n/**\n * Warn (dev builds only) when a TexturePacker frame is exported rotated.\n * Rotated frames are not yet remapped, so they render sideways — the frame is\n * named so the artist can re-export it. Full rotation support is post-launch.\n */\nfunction warnRotatedFrame(name: string): void {\n if (typeof __DEV__ !== 'undefined' && __DEV__) {\n console.warn(\n `[flare-engine/assets] sprite frame \"${name}\": rotation unsupported — re-export without rotation`,\n );\n }\n}\n\n// ----- TexturePacker JSON (hash format) -----\n\ninterface TPHashFrame {\n frame: { x: number; y: number; w: number; h: number };\n rotated?: boolean;\n}\n\ninterface TPHashJSON {\n frames: Record<string, TPHashFrame>;\n}\n\n/** Parse TexturePacker JSON hash format. */\nexport function parseTexturePackerHash(json: unknown): SpriteSheet {\n const data = json as TPHashJSON;\n const sheet = createSpriteSheet();\n const entries = Object.entries(data.frames);\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n if (!entry) continue;\n const [name, value] = entry;\n if (value.rotated) warnRotatedFrame(name);\n const f = value.frame;\n sheet.frames.push({ name, x: f.x, y: f.y, w: f.w, h: f.h });\n sheet.frameMap.set(name, i);\n }\n return sheet;\n}\n\n// ----- TexturePacker JSON (array format) -----\n\ninterface TPArrayFrame {\n filename: string;\n frame: { x: number; y: number; w: number; h: number };\n rotated?: boolean;\n}\n\ninterface TPArrayJSON {\n frames: TPArrayFrame[];\n}\n\n/** Parse TexturePacker JSON array format. */\nexport function parseTexturePackerArray(json: unknown): SpriteSheet {\n const data = json as TPArrayJSON;\n const sheet = createSpriteSheet();\n for (let i = 0; i < data.frames.length; i++) {\n const entry = data.frames[i];\n if (!entry) continue;\n if (entry.rotated) warnRotatedFrame(entry.filename);\n const f = entry.frame;\n sheet.frames.push({\n name: entry.filename,\n x: f.x,\n y: f.y,\n w: f.w,\n h: f.h,\n });\n sheet.frameMap.set(entry.filename, i);\n }\n return sheet;\n}\n\n// ----- Aseprite JSON -----\n\ninterface AsepriteFrame {\n filename: string;\n frame: { x: number; y: number; w: number; h: number };\n duration: number; // ms\n}\n\ninterface AsepriteTag {\n name: string;\n from: number;\n to: number;\n direction: string;\n}\n\ninterface AsepriteJSON {\n frames: AsepriteFrame[] | Record<string, AsepriteFrame>;\n meta?: {\n frameTags?: AsepriteTag[];\n };\n}\n\n/** Parse Aseprite JSON export. */\nexport function parseAseprite(json: unknown): SpriteSheet {\n const data = json as AsepriteJSON;\n const sheet = createSpriteSheet();\n\n // Aseprite can export frames as array or object\n const frameEntries: AsepriteFrame[] = Array.isArray(data.frames)\n ? data.frames\n : Object.values(data.frames);\n\n for (let i = 0; i < frameEntries.length; i++) {\n const entry = frameEntries[i];\n if (!entry) continue;\n const f = entry.frame;\n sheet.frames.push({\n name: entry.filename,\n x: f.x,\n y: f.y,\n w: f.w,\n h: f.h,\n });\n sheet.frameMap.set(entry.filename, i);\n }\n\n // Parse frame tags as animation sequences\n const tags = data.meta?.frameTags;\n if (tags) {\n for (const tag of tags) {\n const indices: number[] = [];\n if (tag.direction === 'reverse') {\n for (let i = tag.to; i >= tag.from; i--) {\n indices.push(i);\n }\n } else if (tag.direction === 'pingpong') {\n for (let i = tag.from; i <= tag.to; i++) {\n indices.push(i);\n }\n for (let i = tag.to - 1; i > tag.from; i--) {\n indices.push(i);\n }\n } else {\n // \"forward\" or default\n for (let i = tag.from; i <= tag.to; i++) {\n indices.push(i);\n }\n }\n\n // Use the first frame's duration as the uniform frame duration\n const firstFrame = frameEntries[tag.from];\n const durationMs = firstFrame?.duration ?? 100;\n\n sheet.animations.set(tag.name, {\n name: tag.name,\n frameIndices: indices,\n frameDuration: durationMs / 1000,\n loop: true,\n });\n }\n }\n\n return sheet;\n}\n\n/**\n * Add a custom animation sequence to a sprite sheet.\n */\nexport function addAnimation(\n sheet: SpriteSheet,\n name: string,\n frameIndices: number[],\n frameDuration: number,\n loop = true,\n): void {\n sheet.animations.set(name, { name, frameIndices, frameDuration, loop });\n}\n\n/** Get a frame by name. Returns undefined if not found. */\nexport function getFrame(sheet: SpriteSheet, name: string): SpriteFrame | undefined {\n const idx = sheet.frameMap.get(name);\n if (idx === undefined) return undefined;\n return sheet.frames[idx];\n}\n","import { createSpriteSheet, type SpriteFrame, type SpriteSheet } from './sprite-sheet.js';\nimport type { SkImageLike } from './texture.js';\n\n/** One entry in a procedural atlas — a named colored rectangle. */\nexport interface ProceduralFrameSpec {\n /** Frame name (used as the SpriteFrame name for lookup). */\n name: string;\n /** Width in pixels. */\n w: number;\n /** Height in pixels. */\n h: number;\n /** Color as ARGB int (0xAARRGGBB). */\n color: number;\n}\n\n/** Options controlling atlas layout. */\nexport interface ProceduralAtlasOptions {\n /** Max atlas width before wrapping to a new row. Default 1024. */\n maxWidth?: number;\n /** Gap between frames in pixels. Default 0. */\n padding?: number;\n}\n\n/** Result of a procedural atlas build. */\nexport interface ProceduralAtlas {\n /** Backing Skia image with all rects drawn. */\n image: SkImageLike;\n /** SpriteSheet whose frames describe the rect positions. */\n sheet: SpriteSheet;\n /** Total atlas width in pixels. */\n width: number;\n /** Total atlas height in pixels. */\n height: number;\n}\n\n/** Opaque Skia color value — a Float32Array of length 4 (r, g, b, a in [0,1]). */\ntype SkColorLike = Float32Array;\n\n/** Narrow paint interface — only the setter we use. */\nexport interface SkPaintLike {\n setColor(color: SkColorLike): void;\n}\n\n/** Narrow rect interface — a rect value object passed to drawRect. */\nexport interface SkRectLike {\n readonly x: number;\n readonly y: number;\n readonly width: number;\n readonly height: number;\n}\n\n/** Narrow canvas interface — only the method we use. */\nexport interface SkCanvasLike {\n drawRect(rect: SkRectLike, paint: SkPaintLike): void;\n}\n\n/** Narrow surface interface — getCanvas + snapshot. */\nexport interface SkSurfaceLike {\n getCanvas(): SkCanvasLike;\n makeImageSnapshot(): SkImageLike;\n}\n\n/**\n * Narrow view of the Skia module — only the factories this helper needs.\n * Declared locally so unit tests can supply a plain mock without pulling\n * in the full `@shopify/react-native-skia` surface.\n */\nexport interface SkiaAtlasModuleLike {\n Surface: { Make(width: number, height: number): SkSurfaceLike | null };\n Paint(): SkPaintLike;\n XYWHRect(x: number, y: number, w: number, h: number): SkRectLike;\n}\n\n/**\n * Build a flat atlas `SkImage` from a list of colored rectangles.\n *\n * Row-packs frames left-to-right until `maxWidth` is exceeded, then wraps\n * to a new row. Returns both the backing image and a `SpriteSheet` whose\n * frames match the packed positions, so consumers can look up frames by\n * name exactly as with a real `parseTexturePacker*` sheet.\n *\n * Useful for:\n * - bootstrapping gameplay before final art lands (replace with one\n * `parseTexturePackerHash` call once the real atlas arrives),\n * - engine tests / benchmarks that need a valid `SkImage` without\n * shipping any binary asset.\n *\n * **Canonical placeholder-atlas pattern:** a game can ship a full \"shape\n * atlas\" that draws every entity (enemies, bosses, ships, pickups) as\n * composed primitives onto an offscreen Skia surface, then wraps the result\n * in a `SpriteSheet`.\n * That pattern (declarative shape spec → Skia draw calls → `SpriteSheet`\n * with one named frame per shape) is the recommended way to build a\n * manifest-swappable placeholder atlas: when final art lands, swap the\n * shape draw-calls for `parseTexturePackerHash(jsonText)` with no other\n * code changes.\n */\nexport function createProceduralAtlas(\n Skia: SkiaAtlasModuleLike,\n frames: readonly ProceduralFrameSpec[],\n options: ProceduralAtlasOptions = {},\n): ProceduralAtlas {\n const maxWidth = options.maxWidth ?? 1024;\n const padding = options.padding ?? 0;\n\n const positions = layoutRows(frames, maxWidth, padding);\n const surface = Skia.Surface.Make(positions.width, positions.height);\n if (surface === null) {\n throw new Error(`Skia.Surface.Make returned null for ${positions.width}x${positions.height}`);\n }\n\n const canvas = surface.getCanvas();\n const paint = Skia.Paint();\n const color: SkColorLike = new Float32Array(4);\n\n const sheet = createSpriteSheet();\n\n for (let i = 0; i < frames.length; i++) {\n const spec = frames[i];\n const pos = positions.rects[i];\n if (spec === undefined || pos === undefined) continue;\n\n writeArgb(color, spec.color);\n paint.setColor(color);\n canvas.drawRect(Skia.XYWHRect(pos.x, pos.y, spec.w, spec.h), paint);\n\n const frame: SpriteFrame = {\n name: spec.name,\n x: pos.x,\n y: pos.y,\n w: spec.w,\n h: spec.h,\n };\n sheet.frames.push(frame);\n sheet.frameMap.set(spec.name, i);\n }\n\n return {\n image: surface.makeImageSnapshot(),\n sheet,\n width: positions.width,\n height: positions.height,\n };\n}\n\ninterface PackedPosition {\n x: number;\n y: number;\n}\n\ninterface PackedLayout {\n rects: PackedPosition[];\n width: number;\n height: number;\n}\n\nfunction layoutRows(\n frames: readonly ProceduralFrameSpec[],\n maxWidth: number,\n padding: number,\n): PackedLayout {\n const rects: PackedPosition[] = [];\n let x = 0;\n let y = 0;\n let rowHeight = 0;\n let atlasWidth = 0;\n\n for (const spec of frames) {\n if (x > 0 && x + spec.w > maxWidth) {\n y += rowHeight + padding;\n x = 0;\n rowHeight = 0;\n }\n rects.push({ x, y });\n x += spec.w + padding;\n if (spec.h > rowHeight) rowHeight = spec.h;\n if (x - padding > atlasWidth) atlasWidth = x - padding;\n }\n\n const atlasHeight = y + rowHeight;\n return {\n rects,\n width: atlasWidth > 0 ? atlasWidth : 1,\n height: atlasHeight > 0 ? atlasHeight : 1,\n };\n}\n\nfunction writeArgb(out: SkColorLike, argb: number): void {\n out[0] = ((argb >>> 16) & 0xff) / 255;\n out[1] = ((argb >>> 8) & 0xff) / 255;\n out[2] = (argb & 0xff) / 255;\n out[3] = ((argb >>> 24) & 0xff) / 255;\n}\n"],"mappings":";;;;;;;;;AA2CA,IAAa,eAAb,MAA0B;;CAExB,aAAsB,IAAI,OAAe;;CAGzC,WAAW;CAEX,0BAAkB,IAAI,IAAqB;CAC3C;CAEA,YAAY,QAAqB;EAC/B,KAAK,UAAU;CACjB;;;;;CAMA,MAAM,KAAK,UAA0C;EACnD,IAAI,SAAS,WAAW,GAAG;GACzB,KAAK,WAAW;GAChB,KAAK,WAAW,KAAK,CAAC;GACtB;EACF;EAEA,IAAI,SAAS;EACb,MAAM,QAAQ,SAAS;EAEvB,MAAM,WAAW,SAAS,IAAI,OAAO,UAAU;GAC7C,MAAM,QAAQ,MAAM,KAAK,QAAQ,KAAK;GACtC,KAAK,QAAQ,IAAI,MAAM,KAAK,KAAK;GACjC;GACA,KAAK,WAAW,SAAS;GACzB,KAAK,WAAW,KAAK,KAAK,QAAQ;EACpC,CAAC;EAED,MAAM,QAAQ,IAAI,QAAQ;CAC5B;;;;;;;CAQA,MAAM,oBAAoB,UAAwD;EAChF,MAAM,SAAmB,CAAC;EAC1B,MAAM,SAAgC,CAAC;EAEvC,IAAI,SA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AO;EACL;EACA,OAAO,aAAa,IAAI,aAAa;EACrC,QAAQ,cAAc,IAAI,cAAc;CAC1C;AACF;AAEA,SAAS,UAAU,KAAkB,MAAoB;CACvD,IAAI,MAAO,SAAS,KAAM,OAAQ;CAClC,IAAI,MAAO,SAAS,IAAK,OAAQ;CACjC,IAAI,MAAM,OAAO,OAAQ;CACzB,IAAI,MAAO,SAAS,KAAM,OAAQ;AACpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flare-engine/assets",
3
- "version": "0.4.6",
3
+ "version": "0.4.7",
4
4
  "description": "Asset loading, sprite sheet parsing",
5
5
  "keywords": ["flare-engine", "assets", "sprite-sheet", "loader"],
6
6
  "license": "Apache-2.0",
@@ -37,7 +37,7 @@
37
37
  "typecheck": "tsc --noEmit"
38
38
  },
39
39
  "dependencies": {
40
- "@flare-engine/events": "^0.4.6"
40
+ "@flare-engine/events": "^0.4.7"
41
41
  },
42
42
  "engines": {
43
43
  "node": ">=20"