@codexo/exojs-tilemap 0.19.1 → 0.20.0
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/README.md +7 -163
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +12 -20
- package/dist/esm/ChunkSource.d.ts +0 -33
- package/dist/esm/ChunkSource.d.ts.map +0 -1
- package/dist/esm/ChunkStreamer.d.ts +0 -104
- package/dist/esm/ChunkStreamer.d.ts.map +0 -1
- package/dist/esm/ChunkStreamer.js +0 -229
- package/dist/esm/ChunkStreamer.js.map +0 -1
- package/dist/esm/ImageLayer.d.ts +0 -89
- package/dist/esm/ImageLayer.d.ts.map +0 -1
- package/dist/esm/ImageLayer.js +0 -74
- package/dist/esm/ImageLayer.js.map +0 -1
- package/dist/esm/ImageLayerNode.d.ts +0 -91
- package/dist/esm/ImageLayerNode.d.ts.map +0 -1
- package/dist/esm/ImageLayerNode.js +0 -210
- package/dist/esm/ImageLayerNode.js.map +0 -1
- package/dist/esm/MapObject.d.ts +0 -70
- package/dist/esm/MapObject.d.ts.map +0 -1
- package/dist/esm/MapObject.js +0 -34
- package/dist/esm/MapObject.js.map +0 -1
- package/dist/esm/MapObjectSpawner.d.ts +0 -133
- package/dist/esm/MapObjectSpawner.d.ts.map +0 -1
- package/dist/esm/MapObjectSpawner.js +0 -147
- package/dist/esm/MapObjectSpawner.js.map +0 -1
- package/dist/esm/MapSpawnSession.d.ts +0 -46
- package/dist/esm/MapSpawnSession.d.ts.map +0 -1
- package/dist/esm/MapSpawnSession.js +0 -88
- package/dist/esm/MapSpawnSession.js.map +0 -1
- package/dist/esm/MapWorld.d.ts +0 -134
- package/dist/esm/MapWorld.d.ts.map +0 -1
- package/dist/esm/MapWorld.js +0 -150
- package/dist/esm/MapWorld.js.map +0 -1
- package/dist/esm/MapWorldRuntime.d.ts +0 -180
- package/dist/esm/MapWorldRuntime.d.ts.map +0 -1
- package/dist/esm/MapWorldRuntime.js +0 -261
- package/dist/esm/MapWorldRuntime.js.map +0 -1
- package/dist/esm/ObjectLayer.d.ts +0 -379
- package/dist/esm/ObjectLayer.d.ts.map +0 -1
- package/dist/esm/ObjectLayer.js +0 -221
- package/dist/esm/ObjectLayer.js.map +0 -1
- package/dist/esm/SampledChunkSource.d.ts +0 -43
- package/dist/esm/SampledChunkSource.d.ts.map +0 -1
- package/dist/esm/SampledChunkSource.js +0 -48
- package/dist/esm/SampledChunkSource.js.map +0 -1
- package/dist/esm/TileAnimator.d.ts +0 -72
- package/dist/esm/TileAnimator.d.ts.map +0 -1
- package/dist/esm/TileAnimator.js +0 -158
- package/dist/esm/TileAnimator.js.map +0 -1
- package/dist/esm/TileChunk.d.ts +0 -103
- package/dist/esm/TileChunk.d.ts.map +0 -1
- package/dist/esm/TileChunk.js +0 -194
- package/dist/esm/TileChunk.js.map +0 -1
- package/dist/esm/TileChunkNode.d.ts +0 -2
- package/dist/esm/TileChunkNode.d.ts.map +0 -1
- package/dist/esm/TileChunkNode.js +0 -145
- package/dist/esm/TileChunkNode.js.map +0 -1
- package/dist/esm/TileLayer.d.ts +0 -286
- package/dist/esm/TileLayer.d.ts.map +0 -1
- package/dist/esm/TileLayer.js +0 -526
- package/dist/esm/TileLayer.js.map +0 -1
- package/dist/esm/TileLayerNode.d.ts +0 -129
- package/dist/esm/TileLayerNode.d.ts.map +0 -1
- package/dist/esm/TileLayerNode.js +0 -245
- package/dist/esm/TileLayerNode.js.map +0 -1
- package/dist/esm/TileMap.d.ts +0 -317
- package/dist/esm/TileMap.d.ts.map +0 -1
- package/dist/esm/TileMap.js +0 -406
- package/dist/esm/TileMap.js.map +0 -1
- package/dist/esm/TileMapBand.d.ts +0 -80
- package/dist/esm/TileMapBand.d.ts.map +0 -1
- package/dist/esm/TileMapBand.js +0 -155
- package/dist/esm/TileMapBand.js.map +0 -1
- package/dist/esm/TileMapNode.d.ts +0 -92
- package/dist/esm/TileMapNode.d.ts.map +0 -1
- package/dist/esm/TileMapNode.js +0 -134
- package/dist/esm/TileMapNode.js.map +0 -1
- package/dist/esm/TileMapView.d.ts +0 -248
- package/dist/esm/TileMapView.d.ts.map +0 -1
- package/dist/esm/TileMapView.js +0 -394
- package/dist/esm/TileMapView.js.map +0 -1
- package/dist/esm/TileProjection.d.ts +0 -59
- package/dist/esm/TileProjection.d.ts.map +0 -1
- package/dist/esm/TileProjection.js +0 -106
- package/dist/esm/TileProjection.js.map +0 -1
- package/dist/esm/TileSet.d.ts +0 -116
- package/dist/esm/TileSet.d.ts.map +0 -1
- package/dist/esm/TileSet.js +0 -168
- package/dist/esm/TileSet.js.map +0 -1
- package/dist/esm/WangSet.d.ts +0 -80
- package/dist/esm/WangSet.d.ts.map +0 -1
- package/dist/esm/WangSet.js +0 -73
- package/dist/esm/WangSet.js.map +0 -1
- package/dist/esm/WorkerSampledChunkSource.d.ts +0 -94
- package/dist/esm/WorkerSampledChunkSource.d.ts.map +0 -1
- package/dist/esm/WorkerSampledChunkSource.js +0 -113
- package/dist/esm/WorkerSampledChunkSource.js.map +0 -1
- package/dist/esm/autoTile.d.ts +0 -88
- package/dist/esm/autoTile.d.ts.map +0 -1
- package/dist/esm/autoTile.js +0 -173
- package/dist/esm/autoTile.js.map +0 -1
- package/dist/esm/chunkGeometry.d.ts +0 -2
- package/dist/esm/chunkGeometry.d.ts.map +0 -1
- package/dist/esm/chunkGeometry.js +0 -116
- package/dist/esm/chunkGeometry.js.map +0 -1
- package/dist/esm/index.d.ts +0 -2
- package/dist/esm/index.d.ts.map +0 -1
- package/dist/esm/index.js +0 -27
- package/dist/esm/nodeBounds.d.ts +0 -2
- package/dist/esm/nodeBounds.d.ts.map +0 -1
- package/dist/esm/nodeBounds.js +0 -40
- package/dist/esm/nodeBounds.js.map +0 -1
- package/dist/esm/pixelSnap.d.ts +0 -2
- package/dist/esm/pixelSnap.d.ts.map +0 -1
- package/dist/esm/pixelSnap.js +0 -21
- package/dist/esm/pixelSnap.js.map +0 -1
- package/dist/esm/projectObject.d.ts +0 -4
- package/dist/esm/projectObject.d.ts.map +0 -1
- package/dist/esm/projectObject.js +0 -87
- package/dist/esm/projectObject.js.map +0 -1
- package/dist/esm/public.d.ts +0 -48
- package/dist/esm/public.d.ts.map +0 -1
- package/dist/esm/tileCollision.d.ts +0 -190
- package/dist/esm/tileCollision.d.ts.map +0 -1
- package/dist/esm/tileCollision.js +0 -399
- package/dist/esm/tileCollision.js.map +0 -1
- package/dist/esm/tileWord.d.ts +0 -2
- package/dist/esm/tileWord.d.ts.map +0 -1
- package/dist/esm/tileWord.js +0 -16
- package/dist/esm/tileWord.js.map +0 -1
- package/dist/esm/tilemapExtension.d.ts +0 -20
- package/dist/esm/tilemapExtension.d.ts.map +0 -1
- package/dist/esm/tilemapExtension.js +0 -53
- package/dist/esm/tilemapExtension.js.map +0 -1
- package/dist/esm/tilemapSerializers.d.ts +0 -2
- package/dist/esm/tilemapSerializers.d.ts.map +0 -1
- package/dist/esm/tilemapSerializers.js +0 -54
- package/dist/esm/tilemapSerializers.js.map +0 -1
- package/dist/esm/types.d.ts +0 -231
- package/dist/esm/types.d.ts.map +0 -1
- package/dist/esm/types.js +0 -129
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts +0 -2
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.d.ts.map +0 -1
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +0 -376
- package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +0 -1
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js +0 -6
- package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +0 -1
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js +0 -6
- package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +0 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts +0 -2
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.d.ts.map +0 -1
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +0 -539
- package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +0 -1
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +0 -6
- package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TileProjection.js","names":[],"sources":["../../src/TileProjection.ts"],"sourcesContent":["import type { TileMapObject } from './ObjectLayer';\nimport { projectObject } from './projectObject';\nimport { validatePositiveInteger } from './types';\n\n/** Immutable grid geometry shared by a map and its independently usable layers. */\nexport interface TileProjectionOptions {\n /** Orthogonal is the default. Isometric cells are diamonds with the given pixel dimensions. */\n readonly orientation?: 'orthogonal' | 'isometric';\n readonly tileWidth: number;\n readonly tileHeight: number;\n /** Display position of grid vertex (0, 0). Defaults to zero. */\n readonly originX?: number;\n readonly originY?: number;\n}\n\n/**\n * Converts between grid vertices, display pixels and unprojected logical pixels.\n * Isometric logical cells are squares of side `tileHeight`; orthogonal logical\n * coordinates are display coordinates before the origin translation.\n */\nexport class TileProjection {\n public readonly orientation: 'orthogonal' | 'isometric';\n public readonly tileWidth: number;\n public readonly tileHeight: number;\n public readonly originX: number;\n public readonly originY: number;\n\n public constructor(options: TileProjectionOptions) {\n validatePositiveInteger(options.tileWidth, 'projection.tileWidth');\n validatePositiveInteger(options.tileHeight, 'projection.tileHeight');\n this.orientation = options.orientation ?? 'orthogonal';\n this.tileWidth = options.tileWidth;\n this.tileHeight = options.tileHeight;\n this.originX = options.originX ?? 0;\n this.originY = options.originY ?? 0;\n if (!Number.isFinite(this.originX) || !Number.isFinite(this.originY)) {\n throw new Error('TileProjection origin must be finite.');\n }\n }\n\n /** Width of a cell in the unprojected simulation space. */\n public get logicalTileWidth(): number {\n return this.orientation === 'isometric' ? this.tileHeight : this.tileWidth;\n }\n\n public get logicalTileHeight(): number {\n return this.tileHeight;\n }\n\n /** Maps a grid vertex, including fractional coordinates, to display pixels. */\n public tileToPixel(tx: number, ty: number): { x: number; y: number } {\n return this.orientation === 'isometric'\n ? { x: this.originX + ((tx - ty) * this.tileWidth) / 2, y: this.originY + ((tx + ty) * this.tileHeight) / 2 }\n : { x: this.originX + tx * this.tileWidth, y: this.originY + ty * this.tileHeight };\n }\n\n /** Picks the half-open cell containing a display point; negative cells are valid. */\n public pixelToTile(x: number, y: number): { tx: number; ty: number } {\n const logical = this.pixelToLogical(x, y);\n return { tx: Math.floor(logical.x / this.logicalTileWidth), ty: Math.floor(logical.y / this.logicalTileHeight) };\n }\n\n /** Projects a logical position; layer offsets and scene transforms are separate. */\n public logicalToPixel(x: number, y: number): { x: number; y: number } {\n return this.tileToPixel(x / this.logicalTileWidth, y / this.logicalTileHeight);\n }\n\n /** Inverts display projection without quantizing to a cell. */\n public pixelToLogical(x: number, y: number): { x: number; y: number } {\n const dx = x - this.originX;\n const dy = y - this.originY;\n return this.orientation === 'isometric'\n ? { x: dy + (dx * this.tileHeight) / this.tileWidth, y: dy - (dx * this.tileHeight) / this.tileWidth }\n : { x: dx, y: dy };\n }\n\n /** Display AABB of a cell region, excluding artwork overhang and layer offsets. */\n public getBounds(tx: number, ty: number, width: number, height: number): { x: number; y: number; width: number; height: number } {\n const top = this.tileToPixel(tx, ty);\n if (this.orientation === 'orthogonal') {\n return { ...top, width: width * this.tileWidth, height: height * this.tileHeight };\n }\n return {\n x: top.x - (height * this.tileWidth) / 2,\n y: top.y,\n width: ((width + height) * this.tileWidth) / 2,\n height: ((width + height) * this.tileHeight) / 2,\n };\n }\n\n /** Projects logical object geometry; image and text dimensions stay in display pixels. */\n public projectObject(object: TileMapObject): TileMapObject {\n if (this.orientation === 'orthogonal') {\n return object.kind === 'tile'\n ? projectObject(object, 1, 0, 0, 1, this.originX, this.originY)\n : { ...object, x: object.x + this.originX, y: object.y + this.originY };\n }\n const ratio = this.tileWidth / (2 * this.tileHeight);\n return projectObject(object, ratio, 0.5, -ratio, 0.5, this.originX, this.originY);\n }\n\n /** Inverts object geometry into logical space; affine ellipses remain exact. */\n public unprojectObject(object: TileMapObject): TileMapObject {\n if (this.orientation === 'orthogonal') {\n return object.kind === 'tile'\n ? projectObject(object, 1, 0, 0, 1, -this.originX, -this.originY)\n : { ...object, x: object.x - this.originX, y: object.y - this.originY };\n }\n const ratio = this.tileHeight / this.tileWidth;\n return projectObject(object, ratio, -ratio, 1, 1, -this.originY - this.originX * ratio, -this.originY + this.originX * ratio);\n }\n}\n"],"mappings":";;;;;;;;;AAoBA,IAAa,iBAAb,MAA4B;CAC1B,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAChB,AAAgB;CAEhB,AAAO,YAAY,SAAgC;EACjD,wBAAwB,QAAQ,WAAW,sBAAsB;EACjE,wBAAwB,QAAQ,YAAY,uBAAuB;EACnE,KAAK,cAAc,QAAQ,eAAe;EAC1C,KAAK,YAAY,QAAQ;EACzB,KAAK,aAAa,QAAQ;EAC1B,KAAK,UAAU,QAAQ,WAAW;EAClC,KAAK,UAAU,QAAQ,WAAW;EAClC,IAAI,CAAC,OAAO,SAAS,KAAK,OAAO,KAAK,CAAC,OAAO,SAAS,KAAK,OAAO,GACjE,MAAM,IAAI,MAAM,uCAAuC;CAE3D;;CAGA,IAAW,mBAA2B;EACpC,OAAO,KAAK,gBAAgB,cAAc,KAAK,aAAa,KAAK;CACnE;CAEA,IAAW,oBAA4B;EACrC,OAAO,KAAK;CACd;;CAGA,AAAO,YAAY,IAAY,IAAsC;EACnE,OAAO,KAAK,gBAAgB,cACxB;GAAE,GAAG,KAAK,WAAY,KAAK,MAAM,KAAK,YAAa;GAAG,GAAG,KAAK,WAAY,KAAK,MAAM,KAAK,aAAc;EAAE,IAC1G;GAAE,GAAG,KAAK,UAAU,KAAK,KAAK;GAAW,GAAG,KAAK,UAAU,KAAK,KAAK;EAAW;CACtF;;CAGA,AAAO,YAAY,GAAW,GAAuC;EACnE,MAAM,UAAU,KAAK,eAAe,GAAG,CAAC;EACxC,OAAO;GAAE,IAAI,KAAK,MAAM,QAAQ,IAAI,KAAK,g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B,cAAc,QAAQ,GAAG,GAAG,GAAG,GAAG,CAAC,KAAK,SAAS,CAAC,KAAK,OAAO,IAC9D;GAAE,GAAG;GAAQ,GAAG,OAAO,IAAI,KAAK;GAAS,GAAG,OAAO,IAAI,KAAK;EAAQ;EAE1E,MAAM,QAAQ,KAAK,aAAa,KAAK;EACrC,OAAO,cAAc,QAAQ,OAAO,CAAC,OAAO,GAAG,GAAG,CAAC,KAAK,UAAU,KAAK,UAAU,OAAO,CAAC,KAAK,UAAU,KAAK,UAAU,KAAK;CAC9H;AACF"}
|
package/dist/esm/TileSet.d.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import type { TextureRegion } from '@codexo/exojs';
|
|
2
|
-
import type { TileDefinition, TileProperties } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Options for constructing a {@link TileSet}.
|
|
5
|
-
* @advanced
|
|
6
|
-
*/
|
|
7
|
-
export interface TileSetOptions {
|
|
8
|
-
/** Stable runtime name (unique within a {@link TileMap}). */
|
|
9
|
-
readonly name: string;
|
|
10
|
-
/** Texture atlas for this tileset. Textures are Loader-owned. */
|
|
11
|
-
readonly texture: TextureRegion;
|
|
12
|
-
/** Width of each tile in pixels. */
|
|
13
|
-
readonly tileWidth: number;
|
|
14
|
-
/** Height of each tile in pixels. */
|
|
15
|
-
readonly tileHeight: number;
|
|
16
|
-
/** Total number of tiles in this tileset. */
|
|
17
|
-
readonly tileCount: number;
|
|
18
|
-
/** Number of tile columns in the atlas grid. Computed from texture width / tileWidth if omitted. */
|
|
19
|
-
readonly columns?: number;
|
|
20
|
-
/** Pixel spacing between tiles in the atlas. Defaults to 0. */
|
|
21
|
-
readonly spacing?: number;
|
|
22
|
-
/** Pixel margin around the atlas. Defaults to 0. */
|
|
23
|
-
readonly margin?: number;
|
|
24
|
-
/** Tileset class/type string (Tiled `class`). Defaults to `''`. */
|
|
25
|
-
readonly class?: string;
|
|
26
|
-
/** Visual drawing offset in pixels applied to every tile of this set drawn by a tile layer. Defaults to 0. */
|
|
27
|
-
readonly offsetX?: number;
|
|
28
|
-
/** Visual drawing offset in pixels applied to every tile of this set drawn by a tile layer. Defaults to 0. */
|
|
29
|
-
readonly offsetY?: number;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* A resolved tileset: a uniform grid of tiles within a texture atlas.
|
|
33
|
-
*
|
|
34
|
-
* Does **not** own its texture - the Loader or application code retains
|
|
35
|
-
* texture ownership. Tileset dimensions are validated at construction and
|
|
36
|
-
* frozen thereafter.
|
|
37
|
-
*
|
|
38
|
-
* Multiple tilesets are supported per {@link TileMap}; each carries its own
|
|
39
|
-
* tile dimensions, spacing, and optional per-tile metadata.
|
|
40
|
-
* @advanced
|
|
41
|
-
*/
|
|
42
|
-
export declare class TileSet {
|
|
43
|
-
/** Stable runtime name. */
|
|
44
|
-
readonly name: string;
|
|
45
|
-
/** Atlas texture region - Loader-owned, never destroyed by the tileset. */
|
|
46
|
-
readonly texture: TextureRegion;
|
|
47
|
-
/** Tile width in pixels. */
|
|
48
|
-
readonly tileWidth: number;
|
|
49
|
-
/** Tile height in pixels. */
|
|
50
|
-
readonly tileHeight: number;
|
|
51
|
-
/** Total number of tiles in the tileset. */
|
|
52
|
-
readonly tileCount: number;
|
|
53
|
-
/** Number of columns in the atlas grid. */
|
|
54
|
-
readonly columns: number;
|
|
55
|
-
/** Number of rows implied by tileCount and columns. */
|
|
56
|
-
readonly rows: number;
|
|
57
|
-
/** Pixel spacing between tiles in the atlas. */
|
|
58
|
-
readonly spacing: number;
|
|
59
|
-
/** Pixel margin around the atlas. */
|
|
60
|
-
readonly margin: number;
|
|
61
|
-
/** Tileset class/type string (Tiled `class`; may be empty). */
|
|
62
|
-
readonly class: string;
|
|
63
|
-
/**
|
|
64
|
-
* Visual drawing offset X in pixels (Tiled `tileoffset`).
|
|
65
|
-
*
|
|
66
|
-
* Applied by the tile-layer geometry builder and by the tile-collision
|
|
67
|
-
* helpers - i.e. wherever this package places a tile on a grid. It is **not**
|
|
68
|
-
* folded into a {@link TileObject}'s `x`/`y`: object layers are data-only, so
|
|
69
|
-
* code that draws a tile object itself has to add this offset the way a tile
|
|
70
|
-
* layer would.
|
|
71
|
-
*/
|
|
72
|
-
readonly offsetX: number;
|
|
73
|
-
/** Visual drawing offset Y in pixels (Tiled `tileoffset`) - see {@link offsetX} for where it applies. */
|
|
74
|
-
readonly offsetY: number;
|
|
75
|
-
private readonly _definitions;
|
|
76
|
-
/**
|
|
77
|
-
* @throws When dimensions, counts, or spacing values are invalid.
|
|
78
|
-
*/
|
|
79
|
-
constructor(options: TileSetOptions);
|
|
80
|
-
/**
|
|
81
|
-
* Replace all tile definitions with the given array. Each entry's
|
|
82
|
-
* properties are copied and frozen.
|
|
83
|
-
*
|
|
84
|
-
* Part of the tilemap SDK contract for extension packages that build
|
|
85
|
-
* tilesets programmatically.
|
|
86
|
-
*/
|
|
87
|
-
setDefinitions(definitions: readonly TileDefinition[]): void;
|
|
88
|
-
/**
|
|
89
|
-
* Retrieve per-tile metadata, or undefined if none defined.
|
|
90
|
-
* @advanced
|
|
91
|
-
*/
|
|
92
|
-
getTileDefinition(localTileId: number): TileDefinition | undefined;
|
|
93
|
-
/**
|
|
94
|
-
* Compute the pixel-space source rectangle for a local tile ID
|
|
95
|
-
* within the atlas, accounting for columns, spacing, and margin.
|
|
96
|
-
* @advanced
|
|
97
|
-
*/
|
|
98
|
-
getTileRect(localTileId: number): {
|
|
99
|
-
x: number;
|
|
100
|
-
y: number;
|
|
101
|
-
width: number;
|
|
102
|
-
height: number;
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Iterate over all defined tiles (sparse).
|
|
106
|
-
* @advanced
|
|
107
|
-
*/
|
|
108
|
-
definedTiles(): IterableIterator<TileDefinition>;
|
|
109
|
-
/**
|
|
110
|
-
* Read-only snapshot of all per-tile definitions.
|
|
111
|
-
* The returned record is a caller-owned copy.
|
|
112
|
-
* @advanced
|
|
113
|
-
*/
|
|
114
|
-
get allDefinitions(): Readonly<Record<number, TileProperties | undefined>>;
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=TileSet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TileSet.d.ts","sourceRoot":"","sources":["../../src/TileSet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG9D;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,6DAA6D;IAC7D,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,iEAAiE;IACjE,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC;IAChC,oCAAoC;IACpC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,qCAAqC;IACrC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,6CAA6C;IAC7C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,oGAAoG;IACpG,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,+DAA+D;IAC/D,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,oDAAoD;IACpD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,mEAAmE;IACnE,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,8GAA8G;IAC9G,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,8GAA8G;IAC9G,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,OAAO;IAClB,2BAA2B;IAC3B,SAAgB,IAAI,EAAE,MAAM,CAAC;IAE7B,2EAA2E;IAC3E,SAAgB,OAAO,EAAE,aAAa,CAAC;IAEvC,4BAA4B;IAC5B,SAAgB,SAAS,EAAE,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
2
|
-
|
|
3
|
-
//#region src/TileSet.ts
|
|
4
|
-
/**
|
|
5
|
-
* A resolved tileset: a uniform grid of tiles within a texture atlas.
|
|
6
|
-
*
|
|
7
|
-
* Does **not** own its texture - the Loader or application code retains
|
|
8
|
-
* texture ownership. Tileset dimensions are validated at construction and
|
|
9
|
-
* frozen thereafter.
|
|
10
|
-
*
|
|
11
|
-
* Multiple tilesets are supported per {@link TileMap}; each carries its own
|
|
12
|
-
* tile dimensions, spacing, and optional per-tile metadata.
|
|
13
|
-
* @advanced
|
|
14
|
-
*/
|
|
15
|
-
var TileSet = class {
|
|
16
|
-
/** Stable runtime name. */
|
|
17
|
-
name;
|
|
18
|
-
/** Atlas texture region - Loader-owned, never destroyed by the tileset. */
|
|
19
|
-
texture;
|
|
20
|
-
/** Tile width in pixels. */
|
|
21
|
-
tileWidth;
|
|
22
|
-
/** Tile height in pixels. */
|
|
23
|
-
tileHeight;
|
|
24
|
-
/** Total number of tiles in the tileset. */
|
|
25
|
-
tileCount;
|
|
26
|
-
/** Number of columns in the atlas grid. */
|
|
27
|
-
columns;
|
|
28
|
-
/** Number of rows implied by tileCount and columns. */
|
|
29
|
-
rows;
|
|
30
|
-
/** Pixel spacing between tiles in the atlas. */
|
|
31
|
-
spacing;
|
|
32
|
-
/** Pixel margin around the atlas. */
|
|
33
|
-
margin;
|
|
34
|
-
/** Tileset class/type string (Tiled `class`; may be empty). */
|
|
35
|
-
class;
|
|
36
|
-
/**
|
|
37
|
-
* Visual drawing offset X in pixels (Tiled `tileoffset`).
|
|
38
|
-
*
|
|
39
|
-
* Applied by the tile-layer geometry builder and by the tile-collision
|
|
40
|
-
* helpers - i.e. wherever this package places a tile on a grid. It is **not**
|
|
41
|
-
* folded into a {@link TileObject}'s `x`/`y`: object layers are data-only, so
|
|
42
|
-
* code that draws a tile object itself has to add this offset the way a tile
|
|
43
|
-
* layer would.
|
|
44
|
-
*/
|
|
45
|
-
offsetX;
|
|
46
|
-
/** Visual drawing offset Y in pixels (Tiled `tileoffset`) - see {@link offsetX} for where it applies. */
|
|
47
|
-
offsetY;
|
|
48
|
-
_definitions;
|
|
49
|
-
/**
|
|
50
|
-
* @throws When dimensions, counts, or spacing values are invalid.
|
|
51
|
-
*/
|
|
52
|
-
constructor(options) {
|
|
53
|
-
if (!options.name || typeof options.name !== "string") throw new Error("TileSet name must be a non-empty string.");
|
|
54
|
-
if (!options.texture) throw new Error("TileSet requires a valid TextureRegion.");
|
|
55
|
-
validatePositiveInteger(options.tileWidth, "tileWidth");
|
|
56
|
-
validatePositiveInteger(options.tileHeight, "tileHeight");
|
|
57
|
-
validatePositiveInteger(options.tileCount, "tileCount");
|
|
58
|
-
const spacing = options.spacing ?? 0;
|
|
59
|
-
const margin = options.margin ?? 0;
|
|
60
|
-
validateNonNegativeInteger(spacing, "spacing");
|
|
61
|
-
validateNonNegativeInteger(margin, "margin");
|
|
62
|
-
if (options.texture.width <= 0 || options.texture.height <= 0) throw new Error(`TileSet needs a loaded texture to derive its grid, but "${options.name}" was given one measuring ${options.texture.width}x${options.texture.height}. Await it (loader.load(...) or texture.loaded) before constructing the tile set.`);
|
|
63
|
-
const atlasWidth = options.texture.width - margin * 2;
|
|
64
|
-
const atlasHeight = options.texture.height - margin * 2;
|
|
65
|
-
const columns = options.columns ?? Math.floor(atlasWidth / options.tileWidth);
|
|
66
|
-
validatePositiveInteger(columns, "columns");
|
|
67
|
-
if (columns <= 0) throw new Error(`TileSet columns must be positive (got ${columns}).`);
|
|
68
|
-
if (options.tileWidth * columns + spacing * (columns - 1) > atlasWidth) throw new Error(`TileSet grid width exceeds atlas: ${options.tileWidth}*${columns} + ${spacing}*${columns - 1} > ${atlasWidth}.`);
|
|
69
|
-
const rows = Math.ceil(options.tileCount / columns);
|
|
70
|
-
if (rows > 0 && options.tileHeight * rows + spacing * (rows - 1) > atlasHeight) throw new Error(`TileSet grid height exceeds atlas: ${options.tileHeight}*${rows} + ${spacing}*${rows - 1} > ${atlasHeight}.`);
|
|
71
|
-
this.name = options.name;
|
|
72
|
-
this.texture = options.texture;
|
|
73
|
-
this.tileWidth = options.tileWidth;
|
|
74
|
-
this.tileHeight = options.tileHeight;
|
|
75
|
-
this.tileCount = options.tileCount;
|
|
76
|
-
this.columns = columns;
|
|
77
|
-
this.rows = rows;
|
|
78
|
-
this.spacing = spacing;
|
|
79
|
-
this.margin = margin;
|
|
80
|
-
this.class = options.class ?? "";
|
|
81
|
-
this.offsetX = options.offsetX ?? 0;
|
|
82
|
-
this.offsetY = options.offsetY ?? 0;
|
|
83
|
-
this._definitions = /* @__PURE__ */ new Map();
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Set per-tile metadata for a local tile ID.
|
|
87
|
-
* Copies input to prevent caller-owned mutation leaking into the tileset.
|
|
88
|
-
* @internal
|
|
89
|
-
*/
|
|
90
|
-
_setDefinition(localTileId, definition) {
|
|
91
|
-
if (localTileId < 0 || localTileId >= this.tileCount) throw new Error(`Tile definition localTileId ${localTileId} out of range [0, ${this.tileCount - 1}].`);
|
|
92
|
-
const props = definition.properties ? Object.freeze({ ...definition.properties }) : void 0;
|
|
93
|
-
const animation = definition.animation ? Object.freeze(definition.animation.map((frame) => Object.freeze({ ...frame }))) : void 0;
|
|
94
|
-
const collision = definition.collision ? Object.freeze([...definition.collision]) : void 0;
|
|
95
|
-
this._definitions.set(localTileId, {
|
|
96
|
-
localTileId,
|
|
97
|
-
...props !== void 0 && { properties: props },
|
|
98
|
-
...animation !== void 0 && { animation },
|
|
99
|
-
...collision !== void 0 && { collision }
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Replace all tile definitions with the given array. Each entry's
|
|
104
|
-
* properties are copied and frozen.
|
|
105
|
-
*
|
|
106
|
-
* Part of the tilemap SDK contract for extension packages that build
|
|
107
|
-
* tilesets programmatically.
|
|
108
|
-
*/
|
|
109
|
-
setDefinitions(definitions) {
|
|
110
|
-
const map = this._definitions;
|
|
111
|
-
map.clear();
|
|
112
|
-
for (const def of definitions) {
|
|
113
|
-
const props = def.properties ? Object.freeze({ ...def.properties }) : void 0;
|
|
114
|
-
const animation = def.animation ? Object.freeze(def.animation.map((frame) => Object.freeze({ ...frame }))) : void 0;
|
|
115
|
-
const collision = def.collision ? Object.freeze([...def.collision]) : void 0;
|
|
116
|
-
map.set(def.localTileId, {
|
|
117
|
-
localTileId: def.localTileId,
|
|
118
|
-
...props !== void 0 && { properties: props },
|
|
119
|
-
...animation !== void 0 && { animation },
|
|
120
|
-
...collision !== void 0 && { collision }
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Retrieve per-tile metadata, or undefined if none defined.
|
|
126
|
-
* @advanced
|
|
127
|
-
*/
|
|
128
|
-
getTileDefinition(localTileId) {
|
|
129
|
-
return this._definitions.get(localTileId);
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* Compute the pixel-space source rectangle for a local tile ID
|
|
133
|
-
* within the atlas, accounting for columns, spacing, and margin.
|
|
134
|
-
* @advanced
|
|
135
|
-
*/
|
|
136
|
-
getTileRect(localTileId) {
|
|
137
|
-
if (localTileId < 0 || localTileId >= this.tileCount) throw new Error(`getTileRect: localTileId ${localTileId} out of range [0, ${this.tileCount - 1}].`);
|
|
138
|
-
const col = localTileId % this.columns;
|
|
139
|
-
const row = Math.floor(localTileId / this.columns);
|
|
140
|
-
return {
|
|
141
|
-
x: this.margin + col * (this.tileWidth + this.spacing),
|
|
142
|
-
y: this.margin + row * (this.tileHeight + this.spacing),
|
|
143
|
-
width: this.tileWidth,
|
|
144
|
-
height: this.tileHeight
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Iterate over all defined tiles (sparse).
|
|
149
|
-
* @advanced
|
|
150
|
-
*/
|
|
151
|
-
definedTiles() {
|
|
152
|
-
return this._definitions.values();
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* Read-only snapshot of all per-tile definitions.
|
|
156
|
-
* The returned record is a caller-owned copy.
|
|
157
|
-
* @advanced
|
|
158
|
-
*/
|
|
159
|
-
get allDefinitions() {
|
|
160
|
-
const result = {};
|
|
161
|
-
for (const [id, def] of this._definitions) result[id] = def.properties;
|
|
162
|
-
return Object.freeze(result);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
//#endregion
|
|
167
|
-
export { TileSet };
|
|
168
|
-
//# sourceMappingURL=TileSet.js.map
|
package/dist/esm/TileSet.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"TileSet.js","names":[],"sources":["../../src/TileSet.ts"],"sourcesContent":["import type { TextureRegion } from '@codexo/exojs';\n\nimport type { TileDefinition, TileProperties } from './types';\nimport { validateNonNegativeInteger, validatePositiveInteger } from './types';\n\n/**\n * Options for constructing a {@link TileSet}.\n * @advanced\n */\nexport interface TileSetOptions {\n /** Stable runtime name (unique within a {@link TileMap}). */\n readonly name: string;\n /** Texture atlas for this tileset. Textures are Loader-owned. */\n readonly texture: TextureRegion;\n /** Width of each tile in pixels. */\n readonly tileWidth: number;\n /** Height of each tile in pixels. */\n readonly tileHeight: number;\n /** Total number of tiles in this tileset. */\n readonly tileCount: number;\n /** Number of tile columns in the atlas grid. Computed from texture width / tileWidth if omitted. */\n readonly columns?: number;\n /** Pixel spacing between tiles in the atlas. Defaults to 0. */\n readonly spacing?: number;\n /** Pixel margin around the atlas. Defaults to 0. */\n readonly margin?: number;\n /** Tileset class/type string (Tiled `class`). Defaults to `''`. */\n readonly class?: string;\n /** Visual drawing offset in pixels applied to every tile of this set drawn by a tile layer. Defaults to 0. */\n readonly offsetX?: number;\n /** Visual drawing offset in pixels applied to every tile of this set drawn by a tile layer. Defaults to 0. */\n readonly offsetY?: number;\n}\n\n/**\n * A resolved tileset: a uniform grid of tiles within a texture atlas.\n *\n * Does **not** own its texture - the Loader or application code retains\n * texture ownership. Tileset dimensions are validated at construction and\n * frozen thereafter.\n *\n * Multiple tilesets are supported per {@link TileMap}; each carries its own\n * tile dimensions, spacing, and optional per-tile metadata.\n * @advanced\n */\nexport class TileSet {\n /** Stable runtime name. */\n public readonly name: string;\n\n /** Atlas texture region - Loader-owned, never destroyed by the tileset. */\n public readonly texture: TextureRegion;\n\n /** Tile width in pixels. */\n public readonly tileWidth: number;\n /** Tile height in pixels. */\n public readonly tileHeight: number;\n\n /** Total number of tiles in the tileset. */\n public readonly tileCount: number;\n\n /** Number of columns in the atlas grid. */\n public readonly columns: number;\n /** Number of rows implied by tileCount and columns. */\n public readonly rows: number;\n\n /** Pixel spacing between tiles in the atlas. */\n public readonly spacing: number;\n /** Pixel margin around the atlas. */\n public readonly margin: number;\n\n /** Tileset class/type string (Tiled `class`; may be empty). */\n public readonly class: string;\n /**\n * Visual drawing offset X in pixels (Tiled `tileoffset`).\n *\n * Applied by the tile-layer geometry builder and by the tile-collision\n * helpers - i.e. wherever this package places a tile on a grid. It is **not**\n * folded into a {@link TileObject}'s `x`/`y`: object layers are data-only, so\n * code that draws a tile object itself has to add this offset the way a tile\n * layer would.\n */\n public readonly offsetX: number;\n /** Visual drawing offset Y in pixels (Tiled `tileoffset`) - see {@link offsetX} for where it applies. */\n public readonly offsetY: number;\n\n private readonly _definitions: ReadonlyMap<number, TileDefinition>;\n\n /**\n * @throws When dimensions, counts, or spacing values are invalid.\n */\n public constructor(options: TileSetOptions) {\n if (!options.name || typeof options.name !== 'string') {\n throw new Error('TileSet name must be a non-empty string.');\n }\n\n if (!options.texture) {\n throw new Error('TileSet requires a valid TextureRegion.');\n }\n\n validatePositiveInteger(options.tileWidth, 'tileWidth');\n validatePositiveInteger(options.tileHeight, 'tileHeight');\n validatePositiveInteger(options.tileCount, 'tileCount');\n\n const spacing = options.spacing ?? 0;\n const margin = options.margin ?? 0;\n validateNonNegativeInteger(spacing, 'spacing');\n validateNonNegativeInteger(margin, 'margin');\n\n // A tile grid is derived from the atlas dimensions and then fixed, so it\n // cannot be built against a texture that has not loaded yet - and the\n // dimension checks below would otherwise report the resulting zeros as a\n // bad tile size rather than as the real cause.\n if (options.texture.width <= 0 || options.texture.height <= 0) {\n throw new Error(\n `TileSet needs a loaded texture to derive its grid, but \"${options.name}\" was given one measuring ` +\n `${options.texture.width}x${options.texture.height}. Await it (loader.load(...) or texture.loaded) before constructing the tile set.`,\n );\n }\n\n const atlasWidth = options.texture.width - margin * 2;\n const atlasHeight = options.texture.height - margin * 2;\n\n const columns = options.columns ?? Math.floor(atlasWidth / options.tileWidth);\n\n validatePositiveInteger(columns, 'columns');\n if (columns <= 0) {\n throw new Error(`TileSet columns must be positive (got ${columns}).`);\n }\n\n if (options.tileWidth * columns + spacing * (columns - 1) > atlasWidth) {\n throw new Error(`TileSet grid width exceeds atlas: ${options.tileWidth}*${columns}` + ` + ${spacing}*${columns - 1} > ${atlasWidth}.`);\n }\n\n const rows = Math.ceil(options.tileCount / columns);\n if (rows > 0 && options.tileHeight * rows + spacing * (rows - 1) > atlasHeight) {\n throw new Error(`TileSet grid height exceeds atlas: ${options.tileHeight}*${rows}` + ` + ${spacing}*${rows - 1} > ${atlasHeight}.`);\n }\n\n this.name = options.name;\n this.texture = options.texture;\n this.tileWidth = options.tileWidth;\n this.tileHeight = options.tileHeight;\n this.tileCount = options.tileCount;\n this.columns = columns;\n this.rows = rows;\n this.spacing = spacing;\n this.margin = margin;\n this.class = options.class ?? '';\n this.offsetX = options.offsetX ?? 0;\n this.offsetY = options.offsetY ?? 0;\n\n this._definitions = new Map();\n\n if (__DEV__) {\n Object.freeze(this);\n }\n }\n\n /**\n * Set per-tile metadata for a local tile ID.\n * Copies input to prevent caller-owned mutation leaking into the tileset.\n * @internal\n */\n public _setDefinition(localTileId: number, definition: Partial<TileDefinition>): void {\n if (localTileId < 0 || localTileId >= this.tileCount) {\n throw new Error(`Tile definition localTileId ${localTileId} out of range [0, ${this.tileCount - 1}].`);\n }\n const props = definition.properties ? Object.freeze({ ...definition.properties }) : undefined;\n const animation = definition.animation ? Object.freeze(definition.animation.map(frame => Object.freeze({ ...frame }))) : undefined;\n const collision = definition.collision ? Object.freeze([...definition.collision]) : undefined;\n (this._definitions as Map<number, TileDefinition>).set(localTileId, {\n localTileId,\n ...(props !== undefined && { properties: props }),\n ...(animation !== undefined && { animation }),\n ...(collision !== undefined && { collision }),\n });\n }\n\n /**\n * Replace all tile definitions with the given array. Each entry's\n * properties are copied and frozen.\n *\n * Part of the tilemap SDK contract for extension packages that build\n * tilesets programmatically.\n */\n public setDefinitions(definitions: readonly TileDefinition[]): void {\n const map = this._definitions as Map<number, TileDefinition>;\n map.clear();\n for (const def of definitions) {\n const props = def.properties ? Object.freeze({ ...def.properties }) : undefined;\n const animation = def.animation ? Object.freeze(def.animation.map(frame => Object.freeze({ ...frame }))) : undefined;\n const collision = def.collision ? Object.freeze([...def.collision]) : undefined;\n map.set(def.localTileId, {\n localTileId: def.localTileId,\n ...(props !== undefined && { properties: props }),\n ...(animation !== undefined && { animation }),\n ...(collision !== undefined && { collision }),\n });\n }\n }\n\n /**\n * Retrieve per-tile metadata, or undefined if none defined.\n * @advanced\n */\n public getTileDefinition(localTileId: number): TileDefinition | undefined {\n return this._definitions.get(localTileId);\n }\n\n /**\n * Compute the pixel-space source rectangle for a local tile ID\n * within the atlas, accounting for columns, spacing, and margin.\n * @advanced\n */\n public getTileRect(localTileId: number): { x: number; y: number; width: number; height: number } {\n if (localTileId < 0 || localTileId >= this.tileCount) {\n throw new Error(`getTileRect: localTileId ${localTileId} out of range [0, ${this.tileCount - 1}].`);\n }\n const col = localTileId % this.columns;\n const row = Math.floor(localTileId / this.columns);\n return {\n x: this.margin + col * (this.tileWidth + this.spacing),\n y: this.margin + row * (this.tileHeight + this.spacing),\n width: this.tileWidth,\n height: this.tileHeight,\n };\n }\n\n /**\n * Iterate over all defined tiles (sparse).\n * @advanced\n */\n public definedTiles(): IterableIterator<TileDefinition> {\n return this._definitions.values();\n }\n\n /**\n * Read-only snapshot of all per-tile definitions.\n * The returned record is a caller-owned copy.\n * @advanced\n */\n public get allDefinitions(): Readonly<Record<number, TileProperties | undefined>> {\n const result: Record<number, TileProperties | undefined> = {};\n for (const [id, def] of this._definitions) {\n result[id] = def.properties;\n }\n return Object.freeze(result);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;AA6CA,IAAa,UAAb,MAAqB;;CAEnB,AAAgB;;CAGhB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,AAAgB;;CAEhB,AAAgB;;CAGhB,AAAgB;;;;;;;;;;CAUhB,AAAgB;;CAEhB,AAAgB;CAEhB,AAAiB;;;;CAKjB,AAAO,YAAY,SAAyB;EAC1C,IAAI,CAAC,QAAQ,QAAQ,OAAO,QAAQ,SAAS,UAC3C,MAAM,IAAI,MAAM,0CAA0C;EAG5D,IAAI,CAAC,QAAQ,SACX,MAAM,IAAI,MAAM,yCAAyC;EAG3D,wBAAwB,QAAQ,WAAW,WAAW;EACtD,wBAAwB,QAAQ,YAAY,YAAY;EACxD,wBAAwB,QAAQ,WAAW,WAAW;EAEtD,MAAM,UAAU,QAAQ,WAAW;EACnC,MAAM,SAAS,QAAQ,UAAU;EACjC,2BAA2B,SAAS,SAAS;EAC7C,2BAA2B,QAAQ,QAAQ;EAM3C,IAAI,QAAQ,QAAQ,SAAS,KAAK,QAAQ,QAAQ,UAAU,GAC1D,MAAM,IAAI,MACR,2DAA2D,QAAQ,KAAK,4BACnE,QAAQ,QAAQ,MAAM,GAAG,QAAQ,QAAQ,OAAO,kFACvD;EAGF,MAAM,aAAa,QAAQ,QAAQ,QAAQ,SAAS;EACpD,MAAM,cAAc,QAAQ,QAAQ,SAAS,SAAS;EAEtD,MAAM,UAAU,QAAQ,WAAW,KAAK,MAAM,aAAa,QAAQ,SAAS;EAE5E,wBAAwB,SAAS,SAAS;EAC1C,IAAI,WAAW,GACb,MAAM,IAAI,MAAM,yCAAyC,QAAQ,GAAG;EAGtE,IAA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KAAK,cAC3B,OAAO,MAAM,IAAI;EAEnB,OAAO,OAAO,OAAO,MAAM;CAC7B;AACF"}
|
package/dist/esm/WangSet.d.ts
DELETED
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Options for constructing a {@link WangSet}.
|
|
3
|
-
*/
|
|
4
|
-
export interface WangSetOptions {
|
|
5
|
-
/** Which TileSet contains the Wang tiles (index into the layer's tilesets array). */
|
|
6
|
-
tilesetIndex: number;
|
|
7
|
-
/**
|
|
8
|
-
* Map from Wang bitmask to local tile ID within the tileset.
|
|
9
|
-
*
|
|
10
|
-
* For blob mode (8-neighbor), keys are 0-255; the 47 valid combinations
|
|
11
|
-
* of the blob encoding must be covered at minimum.
|
|
12
|
-
* For edge mode (4-neighbor), keys are 0-15.
|
|
13
|
-
*
|
|
14
|
-
* Accepts either a {@link ReadonlyMap} or a plain `Record<number, number>`.
|
|
15
|
-
*/
|
|
16
|
-
blobMap: ReadonlyMap<number, number> | Record<number, number>;
|
|
17
|
-
/** Whether this is a blob (8-neighbor, default) or edge (4-neighbor) Wang set. */
|
|
18
|
-
type?: 'blob' | 'edge';
|
|
19
|
-
/**
|
|
20
|
-
* Extra local tile IDs that count as belonging to this Wang group, beyond
|
|
21
|
-
* the variant IDs already present as {@link blobMap} *values*.
|
|
22
|
-
*
|
|
23
|
-
* Membership is what {@link autoTile} / `refreshCell` use to decide whether a
|
|
24
|
-
* neighbouring cell is "part of the terrain". Because every value in
|
|
25
|
-
* `blobMap` is itself a member, group membership stays stable no matter which
|
|
26
|
-
* variant a cell currently shows - that is what makes incremental
|
|
27
|
-
* `refreshCell` correct. Add the *base* tile ID you paint with here if it is
|
|
28
|
-
* not already one of the blobMap variants.
|
|
29
|
-
*/
|
|
30
|
-
members?: Iterable<number>;
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Describes a Wang autotile set: a mapping from a neighbor bitmask to a
|
|
34
|
-
* local tile ID within a specific tileset.
|
|
35
|
-
*
|
|
36
|
-
* Blob bitmask bit layout (powers of 2):
|
|
37
|
-
* - Bit 0 (1): Top-left
|
|
38
|
-
* - Bit 1 (2): Top
|
|
39
|
-
* - Bit 2 (4): Top-right
|
|
40
|
-
* - Bit 3 (8): Left
|
|
41
|
-
* - Bit 4 (16): Right
|
|
42
|
-
* - Bit 5 (32): Bottom-left
|
|
43
|
-
* - Bit 6 (64): Bottom
|
|
44
|
-
* - Bit 7 (128): Bottom-right
|
|
45
|
-
*
|
|
46
|
-
* Diagonal (corner) bits are only set when both adjacent cardinal directions
|
|
47
|
-
* are also set - reducing 256 raw combinations to 47 meaningful blob states.
|
|
48
|
-
*
|
|
49
|
-
* Edge bitmask bit layout:
|
|
50
|
-
* - Bit 0 (1): Top
|
|
51
|
-
* - Bit 1 (2): Right
|
|
52
|
-
* - Bit 2 (4): Bottom
|
|
53
|
-
* - Bit 3 (8): Left
|
|
54
|
-
*/
|
|
55
|
-
export declare class WangSet {
|
|
56
|
-
/** Index of the tileset that contains the Wang tiles. */
|
|
57
|
-
readonly tilesetIndex: number;
|
|
58
|
-
/** The Wang mode: `'blob'` (8-neighbor) or `'edge'` (4-neighbor). */
|
|
59
|
-
readonly type: 'blob' | 'edge';
|
|
60
|
-
private readonly _map;
|
|
61
|
-
private readonly _members;
|
|
62
|
-
constructor(options: WangSetOptions);
|
|
63
|
-
/**
|
|
64
|
-
* Look up the local tile ID for a given neighbor bitmask.
|
|
65
|
-
* Returns `undefined` if the mask has no mapping in this set.
|
|
66
|
-
*/
|
|
67
|
-
getTileId(mask: number): number | undefined;
|
|
68
|
-
/**
|
|
69
|
-
* Whether a local tile ID belongs to this Wang group. True for every variant
|
|
70
|
-
* the set produces plus any explicit {@link WangSetOptions.members}. Used as
|
|
71
|
-
* the default, variant-stable neighbour-membership test by {@link autoTile}
|
|
72
|
-
* and `refreshCell`.
|
|
73
|
-
*/
|
|
74
|
-
isMember(localTileId: number): boolean;
|
|
75
|
-
/** Read-only view of the full bitmask → tile-ID mapping. */
|
|
76
|
-
get blobMap(): ReadonlyMap<number, number>;
|
|
77
|
-
/** Read-only view of the local tile IDs that count as group members. */
|
|
78
|
-
get members(): ReadonlySet<number>;
|
|
79
|
-
}
|
|
80
|
-
//# sourceMappingURL=WangSet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WangSet.d.ts","sourceRoot":"","sources":["../../src/WangSet.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qFAAqF;IACrF,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;;;OAQG;IACH,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9D,kFAAkF;IAClF,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvB;;;;;;;;;;OAUG;IACH,OAAO,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CAC5B;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,qBAAa,OAAO;IAClB,yDAAyD;IACzD,SAAgB,YAAY,EAAE,MAAM,CAAC;IAErC,qEAAqE;IACrE,SAAgB,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAEtC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAA8B;IACnD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAsB;IAE/C,YAAmB,OAAO,EAAE,cAAc,EAsBzC;IAED;;;OAGG;IACI,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAEjD;IAED;;;;;OAKG;IACI,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAE5C;IAED,4DAA4D;IAC5D,IAAW,OAAO,IAAI,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAEhD;IAED,wEAAwE;IACxE,IAAW,OAAO,IAAI,WAAW,CAAC,MAAM,CAAC,CAExC;CACF"}
|
package/dist/esm/WangSet.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
//#region src/WangSet.ts
|
|
2
|
-
/**
|
|
3
|
-
* Describes a Wang autotile set: a mapping from a neighbor bitmask to a
|
|
4
|
-
* local tile ID within a specific tileset.
|
|
5
|
-
*
|
|
6
|
-
* Blob bitmask bit layout (powers of 2):
|
|
7
|
-
* - Bit 0 (1): Top-left
|
|
8
|
-
* - Bit 1 (2): Top
|
|
9
|
-
* - Bit 2 (4): Top-right
|
|
10
|
-
* - Bit 3 (8): Left
|
|
11
|
-
* - Bit 4 (16): Right
|
|
12
|
-
* - Bit 5 (32): Bottom-left
|
|
13
|
-
* - Bit 6 (64): Bottom
|
|
14
|
-
* - Bit 7 (128): Bottom-right
|
|
15
|
-
*
|
|
16
|
-
* Diagonal (corner) bits are only set when both adjacent cardinal directions
|
|
17
|
-
* are also set - reducing 256 raw combinations to 47 meaningful blob states.
|
|
18
|
-
*
|
|
19
|
-
* Edge bitmask bit layout:
|
|
20
|
-
* - Bit 0 (1): Top
|
|
21
|
-
* - Bit 1 (2): Right
|
|
22
|
-
* - Bit 2 (4): Bottom
|
|
23
|
-
* - Bit 3 (8): Left
|
|
24
|
-
*/
|
|
25
|
-
var WangSet = class {
|
|
26
|
-
/** Index of the tileset that contains the Wang tiles. */
|
|
27
|
-
tilesetIndex;
|
|
28
|
-
/** The Wang mode: `'blob'` (8-neighbor) or `'edge'` (4-neighbor). */
|
|
29
|
-
type;
|
|
30
|
-
_map;
|
|
31
|
-
_members;
|
|
32
|
-
constructor(options) {
|
|
33
|
-
this.tilesetIndex = options.tilesetIndex;
|
|
34
|
-
this.type = options.type ?? "blob";
|
|
35
|
-
if (options.blobMap instanceof Map) this._map = options.blobMap;
|
|
36
|
-
else {
|
|
37
|
-
const map = /* @__PURE__ */ new Map();
|
|
38
|
-
for (const [k, v] of Object.entries(options.blobMap)) map.set(Number(k), v);
|
|
39
|
-
this._map = map;
|
|
40
|
-
}
|
|
41
|
-
const members = new Set(this._map.values());
|
|
42
|
-
if (options.members) for (const id of options.members) members.add(id);
|
|
43
|
-
this._members = members;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Look up the local tile ID for a given neighbor bitmask.
|
|
47
|
-
* Returns `undefined` if the mask has no mapping in this set.
|
|
48
|
-
*/
|
|
49
|
-
getTileId(mask) {
|
|
50
|
-
return this._map.get(mask);
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Whether a local tile ID belongs to this Wang group. True for every variant
|
|
54
|
-
* the set produces plus any explicit {@link WangSetOptions.members}. Used as
|
|
55
|
-
* the default, variant-stable neighbour-membership test by {@link autoTile}
|
|
56
|
-
* and `refreshCell`.
|
|
57
|
-
*/
|
|
58
|
-
isMember(localTileId) {
|
|
59
|
-
return this._members.has(localTileId);
|
|
60
|
-
}
|
|
61
|
-
/** Read-only view of the full bitmask → tile-ID mapping. */
|
|
62
|
-
get blobMap() {
|
|
63
|
-
return this._map;
|
|
64
|
-
}
|
|
65
|
-
/** Read-only view of the local tile IDs that count as group members. */
|
|
66
|
-
get members() {
|
|
67
|
-
return this._members;
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
//#endregion
|
|
72
|
-
export { WangSet };
|
|
73
|
-
//# sourceMappingURL=WangSet.js.map
|
package/dist/esm/WangSet.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WangSet.js","names":[],"sources":["../../src/WangSet.ts"],"sourcesContent":["/**\n * Options for constructing a {@link WangSet}.\n */\nexport interface WangSetOptions {\n /** Which TileSet contains the Wang tiles (index into the layer's tilesets array). */\n tilesetIndex: number;\n /**\n * Map from Wang bitmask to local tile ID within the tileset.\n *\n * For blob mode (8-neighbor), keys are 0-255; the 47 valid combinations\n * of the blob encoding must be covered at minimum.\n * For edge mode (4-neighbor), keys are 0-15.\n *\n * Accepts either a {@link ReadonlyMap} or a plain `Record<number, number>`.\n */\n blobMap: ReadonlyMap<number, number> | Record<number, number>;\n /** Whether this is a blob (8-neighbor, default) or edge (4-neighbor) Wang set. */\n type?: 'blob' | 'edge';\n /**\n * Extra local tile IDs that count as belonging to this Wang group, beyond\n * the variant IDs already present as {@link blobMap} *values*.\n *\n * Membership is what {@link autoTile} / `refreshCell` use to decide whether a\n * neighbouring cell is \"part of the terrain\". Because every value in\n * `blobMap` is itself a member, group membership stays stable no matter which\n * variant a cell currently shows - that is what makes incremental\n * `refreshCell` correct. Add the *base* tile ID you paint with here if it is\n * not already one of the blobMap variants.\n */\n members?: Iterable<number>;\n}\n\n/**\n * Describes a Wang autotile set: a mapping from a neighbor bitmask to a\n * local tile ID within a specific tileset.\n *\n * Blob bitmask bit layout (powers of 2):\n * - Bit 0 (1): Top-left\n * - Bit 1 (2): Top\n * - Bit 2 (4): Top-right\n * - Bit 3 (8): Left\n * - Bit 4 (16): Right\n * - Bit 5 (32): Bottom-left\n * - Bit 6 (64): Bottom\n * - Bit 7 (128): Bottom-right\n *\n * Diagonal (corner) bits are only set when both adjacent cardinal directions\n * are also set - reducing 256 raw combinations to 47 meaningful blob states.\n *\n * Edge bitmask bit layout:\n * - Bit 0 (1): Top\n * - Bit 1 (2): Right\n * - Bit 2 (4): Bottom\n * - Bit 3 (8): Left\n */\nexport class WangSet {\n /** Index of the tileset that contains the Wang tiles. */\n public readonly tilesetIndex: number;\n\n /** The Wang mode: `'blob'` (8-neighbor) or `'edge'` (4-neighbor). */\n public readonly type: 'blob' | 'edge';\n\n private readonly _map: ReadonlyMap<number, number>;\n private readonly _members: ReadonlySet<number>;\n\n public constructor(options: WangSetOptions) {\n this.tilesetIndex = options.tilesetIndex;\n this.type = options.type ?? 'blob';\n\n if (options.blobMap instanceof Map) {\n this._map = options.blobMap;\n } else {\n const map = new Map<number, number>();\n for (const [k, v] of Object.entries(options.blobMap as Record<string, number>)) {\n map.set(Number(k), v);\n }\n this._map = map;\n }\n\n // Members default to every variant tile ID the set can produce, so that any\n // autotiled variant is recognised as part of the group (variant-stable\n // membership). Explicit `members` (e.g. the base paint ID) are added on top.\n const members = new Set<number>(this._map.values());\n if (options.members) {\n for (const id of options.members) members.add(id);\n }\n this._members = members;\n }\n\n /**\n * Look up the local tile ID for a given neighbor bitmask.\n * Returns `undefined` if the mask has no mapping in this set.\n */\n public getTileId(mask: number): number | undefined {\n return this._map.get(mask);\n }\n\n /**\n * Whether a local tile ID belongs to this Wang group. True for every variant\n * the set produces plus any explicit {@link WangSetOptions.members}. Used as\n * the default, variant-stable neighbour-membership test by {@link autoTile}\n * and `refreshCell`.\n */\n public isMember(localTileId: number): boolean {\n return this._members.has(localTileId);\n }\n\n /** Read-only view of the full bitmask → tile-ID mapping. */\n public get blobMap(): ReadonlyMap<number, number> {\n return this._map;\n }\n\n /** Read-only view of the local tile IDs that count as group members. */\n public get members(): ReadonlySet<number> {\n return this._members;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,UAAb,MAAqB;;CAEnB,AAAgB;;CAGhB,AAAgB;CAEhB,AAAiB;CACjB,AAAiB;CAEjB,AAAO,YAAY,SAAyB;EAC1C,KAAK,eAAe,QAAQ;EAC5B,KAAK,OAAO,QAAQ,QAAQ;EAE5B,IAAI,QAAQ,mBAAmB,KAC7B,KAAK,OAAO,QAAQ;OACf;GACL,MAAM,sBAAM,IAAI,IAAoB;GACpC,KAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,QAAQ,OAAiC,GAC3E,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC;GAEtB,KAAK,OAAO;EACd;EAKA,MAAM,UAAU,IAAI,IAAY,KAAK,KAAK,OAAO,CAAC;EAClD,IAAI,QAAQ,SACV,KAAK,MAAM,MAAM,QAAQ,SAAS,QAAQ,IAAI,EAAE;EAElD,KAAK,WAAW;CAClB;;;;;CAMA,AAAO,UAAU,MAAkC;EACjD,OAAO,KAAK,KAAK,IAAI,IAAI;CAC3B;;;;;;;CAQA,AAAO,SAAS,aAA8B;EAC5C,OAAO,KAAK,SAAS,IAAI,WAAW;CACtC;;CAGA,IAAW,UAAuC;EAChD,OAAO,KAAK;CACd;;CAGA,IAAW,UAA+B;EACxC,OAAO,KAAK;CACd;AACF"}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import type { ChunkSource } from './ChunkSource';
|
|
2
|
-
import type { TileLayer } from './TileLayer';
|
|
3
|
-
import type { ResolvedTile } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Options for {@link createWorkerSampledChunkSource}.
|
|
6
|
-
* @advanced
|
|
7
|
-
*/
|
|
8
|
-
export interface WorkerSampledChunkSourceOptions {
|
|
9
|
-
/**
|
|
10
|
-
* Complete worker script source as a single self-contained string, Blob-URL'd
|
|
11
|
-
* into a real `Worker` at construction time - the same technique
|
|
12
|
-
* {@link import('@codexo/exojs').WorkletEffect} uses for AudioWorklet
|
|
13
|
-
* processors. No separate worker asset is fetched and no bundler-specific
|
|
14
|
-
* worker-import syntax is involved.
|
|
15
|
-
*
|
|
16
|
-
* Producing that string by hand-writing JavaScript into a template literal
|
|
17
|
-
* works but gives up type checking, linting and shared code. Prefer a build
|
|
18
|
-
* step that bundles a real module into a string: this repository's own
|
|
19
|
-
* examples are authored as `*.worker.ts` and imported through a `?worker`
|
|
20
|
-
* query, which is why they can `import` the sampling functions the main
|
|
21
|
-
* thread uses instead of restating them.
|
|
22
|
-
*
|
|
23
|
-
* Must implement this request/response protocol:
|
|
24
|
-
* - Request (received via `self.onmessage`):
|
|
25
|
-
* `{ requestId: number; cx: number; cy: number; chunkWidth: number; chunkHeight: number }`.
|
|
26
|
-
* - Response, success (send via `self.postMessage`, transferring the
|
|
27
|
-
* buffer for a zero-copy handoff - `postMessage(response, [response.values.buffer])`):
|
|
28
|
-
* `{ requestId: number; values: Float64Array }`, `values.length ===
|
|
29
|
-
* chunkWidth * chunkHeight`, row-major (`localTy * chunkWidth + localTx`),
|
|
30
|
-
* one sampled value per tile in the requested chunk. Compute each tile's
|
|
31
|
-
* absolute coordinate as `cx * chunkWidth + localTx` /
|
|
32
|
-
* `cy * chunkHeight + localTy`.
|
|
33
|
-
* - Response, error (one request failed without crashing the worker):
|
|
34
|
-
* `{ requestId: number; error: string }`.
|
|
35
|
-
*
|
|
36
|
-
* Your worker must reply to every request with exactly one success or
|
|
37
|
-
* error message bearing the same `requestId`. A request left unanswered
|
|
38
|
-
* leaves that chunk permanently unfetched - there is no timeout - since
|
|
39
|
-
* `ChunkStreamer` tracks it as still in flight and never retries it.
|
|
40
|
-
*/
|
|
41
|
-
workerSource: string;
|
|
42
|
-
/**
|
|
43
|
-
* Posted to the worker once, before any chunk request, when present.
|
|
44
|
-
*
|
|
45
|
-
* The transport for whatever the sampler needs to know that is not per-chunk
|
|
46
|
-
* - a seed, a feature size, a cost knob. Without it those values would have
|
|
47
|
-
* to be interpolated into {@link WorkerSampledChunkSourceOptions.workerSource}
|
|
48
|
-
* as literals, which turns every parameter change into a source rebuild and a
|
|
49
|
-
* new `Worker`.
|
|
50
|
-
*
|
|
51
|
-
* `postMessage` delivery is ordered, so the worker is guaranteed to see this
|
|
52
|
-
* before the first request. Distinguish it from a chunk request by its own
|
|
53
|
-
* shape; requests carry a `requestId`.
|
|
54
|
-
*/
|
|
55
|
-
initMessage?: unknown;
|
|
56
|
-
/**
|
|
57
|
-
* Convert a sampled value (and its absolute tile coordinate) into a
|
|
58
|
-
* resolved tile, or `null` for an empty cell. Always runs on the main
|
|
59
|
-
* thread - a `ResolvedTile` references a `TileSet`/`Texture`, neither of
|
|
60
|
-
* which can cross a `postMessage` boundary. Must be pure and
|
|
61
|
-
* deterministic, same requirement as
|
|
62
|
-
* {@link import('./SampledChunkSource').SampledChunkSourceOptions.mapValueToTile}.
|
|
63
|
-
*/
|
|
64
|
-
mapValueToTile(value: number, tx: number, ty: number): ResolvedTile | null;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Build a {@link import('./ChunkStreamer').ChunkStreamer}-ready
|
|
68
|
-
* {@link ChunkSource} that samples off the main thread via a Web Worker -
|
|
69
|
-
* the async counterpart to
|
|
70
|
-
* {@link import('./SampledChunkSource').createSampledChunkSource}, for
|
|
71
|
-
* sampling functions expensive enough to want off-thread execution.
|
|
72
|
-
*
|
|
73
|
-
* Unlike the synchronous provider, sampling logic cannot be passed as a
|
|
74
|
-
* live function - functions cannot cross a `postMessage` boundary. Instead
|
|
75
|
-
* {@link WorkerSampledChunkSourceOptions.workerSource} is a self-contained
|
|
76
|
-
* worker script string; see its documentation for the protocol.
|
|
77
|
-
*
|
|
78
|
-
* The returned value's `destroy()` MUST be called when done with it - the
|
|
79
|
-
* underlying `Worker` is a real resource that leaks otherwise.
|
|
80
|
-
* {@link import('./ChunkStreamer').ChunkStreamer} does not own the source it
|
|
81
|
-
* is given and never calls this for you: `ChunkSource` itself has no
|
|
82
|
-
* lifecycle hook, so nothing ties the two together automatically. Call it
|
|
83
|
-
* yourself alongside your own `ChunkStreamer.destroy()` call.
|
|
84
|
-
*
|
|
85
|
-
* `workerSource` runs through {@link import('@codexo/exojs').InlineWorker},
|
|
86
|
-
* so it needs no bundler support of its own but does need a
|
|
87
|
-
* Content-Security-Policy that permits `blob:` in `worker-src` if your
|
|
88
|
-
* deployment sets one; the constructor names that cause when it is refused.
|
|
89
|
-
* @advanced
|
|
90
|
-
*/
|
|
91
|
-
export declare const createWorkerSampledChunkSource: (layer: TileLayer, options: WorkerSampledChunkSourceOptions) => ChunkSource & {
|
|
92
|
-
destroy(): void;
|
|
93
|
-
};
|
|
94
|
-
//# sourceMappingURL=WorkerSampledChunkSource.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerSampledChunkSource.d.ts","sourceRoot":"","sources":["../../src/WorkerSampledChunkSource.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAgB,WAAW,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAG5C;;;GAGG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,YAAY,EAAE,MAAM,CAAC;IACrB;;;;;;;;;;;;OAYG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;;;;OAOG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI,CAAC;CAC5E;AAiCD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,8BAA8B,UAAW,SAAS,WAAW,+BAA+B,KAAG,WAAW,GAAG;IAAE,OAAO,IAAI,IAAI,CAAA;CA0F1I,CAAC"}
|