@codexo/exojs-tilemap 0.17.0 → 0.18.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.
Files changed (32) hide show
  1. package/README.md +28 -75
  2. package/dist/esm/ImageLayerNode.d.ts +5 -1
  3. package/dist/esm/ImageLayerNode.d.ts.map +1 -1
  4. package/dist/esm/ImageLayerNode.js +7 -2
  5. package/dist/esm/ImageLayerNode.js.map +1 -1
  6. package/dist/esm/TileLayerNode.d.ts +6 -1
  7. package/dist/esm/TileLayerNode.d.ts.map +1 -1
  8. package/dist/esm/TileLayerNode.js +8 -3
  9. package/dist/esm/TileLayerNode.js.map +1 -1
  10. package/dist/esm/TileMapNode.d.ts +6 -1
  11. package/dist/esm/TileMapNode.d.ts.map +1 -1
  12. package/dist/esm/TileMapNode.js +8 -3
  13. package/dist/esm/TileMapNode.js.map +1 -1
  14. package/dist/esm/TileMapView.d.ts +6 -1
  15. package/dist/esm/TileMapView.d.ts.map +1 -1
  16. package/dist/esm/TileMapView.js +9 -4
  17. package/dist/esm/TileMapView.js.map +1 -1
  18. package/dist/esm/WorkerSampledChunkSource.d.ts +4 -7
  19. package/dist/esm/WorkerSampledChunkSource.d.ts.map +1 -1
  20. package/dist/esm/WorkerSampledChunkSource.js +12 -18
  21. package/dist/esm/WorkerSampledChunkSource.js.map +1 -1
  22. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +4 -4
  23. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +1 -1
  24. package/dist/esm/webgl2/shaders/tile-chunk.frag.js +1 -1
  25. package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +1 -1
  26. package/dist/esm/webgl2/shaders/tile-chunk.vert.js +1 -1
  27. package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +1 -1
  28. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +4 -4
  29. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +1 -1
  30. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +1 -1
  31. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +1 -1
  32. package/package.json +3 -3
package/README.md CHANGED
@@ -1,9 +1,6 @@
1
1
  # @codexo/exojs-tilemap
2
2
 
3
- Generic, format-independent tilemap runtime **and** WebGL2/WebGPU chunk renderer for
4
- [ExoJS](https://exojs.dev). No Tiled (or any other on-disk format) vocabulary leaks into this
5
- package — adapters such as [`@codexo/exojs-tiled`](https://www.npmjs.com/package/@codexo/exojs-tiled)
6
- parse their format and hand this runtime fully-resolved tiles.
3
+ Generic, format-independent tilemap runtime **and** WebGL2/WebGPU chunk renderer for [ExoJS](https://exoridus.github.io/ExoJS/). No Tiled (or any other on-disk format) vocabulary leaks into this package - adapters such as [`@codexo/exojs-tiled`](https://www.npmjs.com/package/@codexo/exojs-tiled) parse their format and hand this runtime fully resolved tiles.
7
4
 
8
5
  ## Installation
9
6
 
@@ -11,46 +8,34 @@ parse their format and hand this runtime fully-resolved tiles.
11
8
  npm install @codexo/exojs @codexo/exojs-tilemap
12
9
  ```
13
10
 
14
- `@codexo/exojs` is a peer dependency, so install it explicitly. This package is itself a peer of
15
- the format adapters (`@codexo/exojs-tiled`, `@codexo/exojs-ldtk`) rather than something they pull
16
- in transitively — install it whether you use an adapter or build procedural / custom-format maps
17
- directly.
11
+ `@codexo/exojs` is a peer dependency, so install it explicitly. This package is itself a peer of the format adapters (`@codexo/exojs-tiled`, `@codexo/exojs-ldtk`) rather than something they pull in transitively — install it whether you use an adapter or build procedural / custom-format maps directly.
18
12
 
19
13
  ## What this package provides
20
14
 
21
15
  **Runtime (data model)** — pure data, no scene graph:
22
16
 
23
17
  - `TileMap` — a finite, chunk-first map: dimensions, tile size, `tilesets`, ordered `layers`.
24
- - `TileLayer` — one tile layer; packed `Uint32Array` chunk storage, `visible` / `opacity` /
25
- `offsetX/Y`, queries, and revision tracking.
18
+ - `TileLayer` — one tile layer; packed `Uint32Array` chunk storage, `visible` / `opacity` / `offsetX/Y`, queries, and revision tracking.
26
19
  - `TileSet` — a resolved tileset grid over a Core `TextureRegion` (Loader-owned texture).
27
- - `ResolvedTile` / `TileTransform` — value-typed tile references with `flipX` / `flipY` /
28
- `diagonal` orientation.
20
+ - `ResolvedTile` / `TileTransform` — value-typed tile references with `flipX` / `flipY` / `diagonal` orientation.
29
21
 
30
22
  **Worlds and level lifetime** — format-neutral, driven by whichever adapter loaded the data:
31
23
 
32
- - `MapWorld` / `MapLevel` — where levels sit: stable id, world bounds, neighbour graph,
33
- externality. Metadata only; no tiles, no textures.
34
- - `MapWorldRuntime` — explicit `loadLevel` / `unloadLevel`, one child `LoaderScope` per level,
35
- at most one live level per id. No camera policy: the game decides what to load.
36
- - `MapLevelRuntime` — one loaded level's map, scope and spawn session, with a single
37
- `destroy()` that tears all three down in a safe order.
24
+ - `MapWorld` / `MapLevel` — where levels sit: stable id, world bounds, neighbour graph, externality. Metadata only; no tiles, no textures.
25
+ - `MapWorldRuntime` — explicit `loadLevel` / `unloadLevel`, one child `LoaderScope` per level, at most one live level per id. No camera policy: the game decides what to load.
26
+ - `MapLevelRuntime` — one loaded level's map, scope and spawn session, with a single `destroy()` that tears all three down in a safe order.
38
27
 
39
28
  **Map object spawning**:
40
29
 
41
- - `MapObjectSpawner` — a local (never global) dispatch table from object class to a factory.
42
- Deterministic order, atomic rollback, `AbortSignal` cancellation.
30
+ - `MapObjectSpawner` — a local (never global) dispatch table from object class to a factory. Deterministic order, atomic rollback, `AbortSignal` cancellation.
43
31
  - `MapObjectDescriptor` — the format-neutral view of one authored object handed to a factory.
44
- - `MapSpawnSession` — owns what one spawn produced; constant-time lookup by stable source id,
45
- reverse-order teardown.
32
+ - `MapSpawnSession` — owns what one spawn produced; constant-time lookup by stable source id, reverse-order teardown.
46
33
 
47
34
  **Scene / rendering (`@advanced`)**:
48
35
 
49
36
  - `TileMapNode` — convenience root that renders a whole `TileMap`.
50
- - `TileLayerNode` — renders one `TileLayer`; generated per layer by `TileMapView` (or construct
51
- directly).
52
- - `TileMapView` — groups a map's layers into independently placeable layer nodes and named
53
- `TileMapBand`s for actor interleaving (a helper, not a scene node).
37
+ - `TileLayerNode` — renders one `TileLayer`; generated per layer by `TileMapView` (or construct directly).
38
+ - `TileMapView` — groups a map's layers into independently placeable layer nodes and named `TileMapBand`s for actor interleaving (a helper, not a scene node).
54
39
  - `TileMapBand` — a `Container` of tile-layer nodes produced by `TileMapView`.
55
40
  - `tilemapExtension` — extension descriptor carrying the WebGL2/WebGPU renderer bindings.
56
41
 
@@ -99,11 +84,7 @@ app.scenes.root.addChild(new TileMapNode(map));
99
84
 
100
85
  ### Interleaving actors between layers — `TileMapView`
101
86
 
102
- `TileMapNode` owns **only** the map's layer nodes and renders them back-to-front — use it when
103
- nothing renders between layers. To draw application actors _between_ tile layers, create a
104
- `TileMapView`: it generates one `TileLayerNode` per map layer (stable identity, map document
105
- order) and groups them into named `TileMapBand`s that you parent yourself, as siblings of your
106
- own actor containers:
87
+ `TileMapNode` owns **only** the map's layer nodes and renders them back-to-front — use it when nothing renders between layers. To draw application actors _between_ tile layers, create a `TileMapView`: it generates one `TileLayerNode` per map layer (stable identity, map document order) and groups them into named `TileMapBand`s that you parent yourself, as siblings of your own actor containers:
107
88
 
108
89
  ```ts
109
90
  const view = map.createView({
@@ -130,63 +111,35 @@ worldRoot.addChild(view.getLayerNodeById(groundId)!, actors, view.getLayerNodeBy
130
111
 
131
112
  Actors are application-owned siblings. `TileMapView` never adopts or destroys actors.
132
113
 
133
- - A band definition **selects** layers (by id, or by unique layer name); rendering order within
134
- a band always follows map document order — definitions never reorder layers.
135
- - Layers not listed in any band stay reachable via `view.getLayerNodeById(id)` /
136
- `view.getLayerNodesByName(name)`; they are not auto-added to any band.
137
- - Destroying a view or a band destroys only the tile nodes it generated — never actors, the
138
- `TileMap`, its `TileLayer`s, or tileset textures.
139
- - There is no map-replacement API: to swap maps, destroy the old view and create a new view from
140
- the new map — the actor tree is untouched.
141
- - After layers are structurally added to or removed from the map, call `view.refreshLayers()`:
142
- unchanged layer nodes keep their identity and bands keep their placement in your scene graph.
114
+ - A band definition **selects** layers (by id, or by unique layer name); rendering order within a band always follows map document order — definitions never reorder layers.
115
+ - Layers not listed in any band stay reachable via `view.getLayerNodeById(id)` / `view.getLayerNodesByName(name)`; they are not auto-added to any band.
116
+ - Destroying a view or a band destroys only the tile nodes it generated — never actors, the `TileMap`, its `TileLayer`s, or tileset textures.
117
+ - There is no map-replacement API: to swap maps, destroy the old view and create a new view from the new map — the actor tree is untouched.
118
+ - After layers are structurally added to or removed from the map, call `view.refreshLayers()`: unchanged layer nodes keep their identity and bands keep their placement in your scene graph.
143
119
 
144
120
  ## Renderer model
145
121
 
146
- - **Chunk-first.** A `TileLayerNode` is a container of per-chunk `TileChunkNode` drawables (one
147
- per non-empty loaded chunk). The renderer batches tiles by `(shader, tileset texture)` and
148
- issues one instanced draw per batch — draw calls scale with _visible chunks × layers_, not
149
- total tile count.
150
- - **Revision-cached geometry.** Each chunk's quad geometry is built once and cached against the
151
- source chunk's `revision`. Unchanged chunks never rebuild; a camera pan rebuilds nothing —
152
- off-screen chunks are culled by their local bounds before any geometry is touched.
153
- - **Orientation.** `flipX` / `flipY` / `diagonal` are baked into the chunk geometry / resolved in
154
- the shader (all 8 combinations), with no per-tile matrix or per-frame cost.
155
- - **Multiple tilesets** with differing tile sizes are first-class; tiles taller than the map grid
156
- are bottom-left aligned (Tiled orthogonal convention).
157
- - **WebGL2 and WebGPU** share one CPU geometry builder and produce identical output (golden
158
- parity tested on both backends).
159
- - **Sampling.** Tile UVs are exact (no half-texel inset), which assumes **nearest** atlas
160
- filtering — the typical pixel-art case. Under linear or mipmap filtering, author tilesets with
161
- extruded tile margins to avoid neighbour bleed at tile edges (extrusion-aware tilemap UV
162
- insetting is a planned follow-up; the `NineSlice` / `RepeatingSprite` geometry paths already
163
- inset).
122
+ - **Chunk-first.** A `TileLayerNode` is a container of per-chunk `TileChunkNode` drawables (one per non-empty loaded chunk). The renderer batches tiles by `(shader, tileset texture)` and issues one instanced draw per batch — draw calls scale with _visible chunks × layers_, not total tile count.
123
+ - **Revision-cached geometry.** Each chunk's quad geometry is built once and cached against the source chunk's `revision`. Unchanged chunks never rebuild; a camera pan rebuilds nothing — off-screen chunks are culled by their local bounds before any geometry is touched.
124
+ - **Orientation.** `flipX` / `flipY` / `diagonal` are baked into the chunk geometry / resolved in the shader (all 8 combinations), with no per-tile matrix or per-frame cost.
125
+ - **Multiple tilesets** with differing tile sizes are first-class; tiles taller than the map grid are bottom-left aligned (Tiled orthogonal convention).
126
+ - **WebGL2 and WebGPU** share one CPU geometry builder and produce identical output (golden parity tested on both backends).
127
+ - **Sampling.** Tile UVs are exact (no half-texel inset), which assumes **nearest** atlas filtering - the typical pixel-art case. Under linear or mipmap filtering, author tilesets with extruded tile margins to avoid neighbour bleed at tile edges; the tilemap renderer does not apply an extrusion-aware inset.
164
128
 
165
129
  ## Ownership & lifecycle
166
130
 
167
131
  - Tileset **textures are Loader-owned**. The runtime and renderer never destroy them.
168
- - A `MapWorldRuntime` owns the scope it creates under the one you give it, plus one child scope
169
- per loaded level - never the scope you passed in. A `MapLevelRuntime` owns the `TileMap` its
170
- provider returned, its spawn session, and its scope; `destroy()` releases them in that order.
171
- - `TileMapNode` / `TileMapView` / `TileMapBand` / `TileLayerNode` reference — but never own —
172
- the `TileMap`. Destroying a map node, view, or band frees only the tile nodes it generated
173
- (detaching them from their application parents) and their cached geometry; application actors,
174
- the `TileMap` data, its `TileLayer`s, and textures all survive. Free those via
175
- `TileMap.destroy()` and `Loader.destroy()` respectively.
176
- - A `TileMapNode` or `TileMapView` reflects the layer set at construction time. After layers are
177
- structurally added to or removed from the map call `node.refreshLayers()` /
178
- `view.refreshLayers()`; after tiles are written into previously-empty chunks call
179
- `layerNode.refresh()`. In-place edits to existing chunks are picked up automatically.
132
+ - A `MapWorldRuntime` owns the scope it creates under the one you give it, plus one child scope per loaded level - never the scope you passed in. A `MapLevelRuntime` owns the `TileMap` its provider returned, its spawn session, and its scope; `destroy()` releases them in that order.
133
+ - `TileMapNode` / `TileMapView` / `TileMapBand` / `TileLayerNode` reference — but never own — the `TileMap`. Destroying a map node, view, or band frees only the tile nodes it generated (detaching them from their application parents) and their cached geometry; application actors, the `TileMap` data, its `TileLayer`s, and textures all survive. Free those via `TileMap.destroy()` and `Loader.destroy()` respectively.
134
+ - A `TileMapNode` or `TileMapView` reflects the layer set at construction time. After layers are structurally added to or removed from the map call `node.refreshLayers()` / `view.refreshLayers()`; after tiles are written into previously-empty chunks call `layerNode.refresh()`. In-place edits to existing chunks are picked up automatically.
180
135
 
181
136
  ## Core compatibility
182
137
 
183
- | `@codexo/exojs-tilemap` | `@codexo/exojs` |
184
- | ----------------------- | --------------- |
185
- | 0.x | matching `0.x` |
138
+ This package follows the Core lockstep release line and declares the compatible `@codexo/exojs` minor as a peer dependency. Install matching package versions.
186
139
 
187
140
  ## Links
188
141
 
189
- - [API reference](https://exojs.dev/api/exojs-tilemap)
142
+ - [API reference](https://exoridus.github.io/ExoJS/en/api/)
190
143
  - [`@codexo/exojs-tiled`](https://www.npmjs.com/package/@codexo/exojs-tiled) — load Tiled `.tmj` maps into this runtime
191
144
 
192
145
  ## License
@@ -68,7 +68,11 @@ export declare class ImageLayerNode extends Container {
68
68
  * is simply stored. Setting the current value is a no-op; an invalid value
69
69
  * throws and leaves the prior mode unchanged.
70
70
  *
71
- * @default PixelSnapMode.None
71
+ * Defaults to `Geometry`, matching the tile layers it is composed with, so a
72
+ * repeated backdrop does not sample between two device pixels and shimmer as
73
+ * the view moves. Set `None` to opt out.
74
+ *
75
+ * @default PixelSnapMode.Geometry
72
76
  * @stable
73
77
  */
74
78
  get pixelSnapMode(): PixelSnapMode;
@@ -1 +1 @@
1
- {"version":3,"file":"ImageLayerNode.d.ts","sourceRoot":"","sources":["../../src/ImageLayerNode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,eAAe,CAAC;AAC3D,OAAO,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G;AACH,qBAAa,cAAe,SAAQ,SAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAa;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAS;IACtC,OAAO,CAAC,cAAc,CAAyC;IAI/D,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,SAAS,CAAc;IAC/B,OAAO,CAAC,aAAa,CAAc;IACnC,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,WAAW,CAAc;gBAEd,KAAK,EAAE,UAAU;IAmDpC,2CAA2C;IAC3C,IAAW,KAAK,IAAI,UAAU,CAE7B;IAED;;;;;;;;;;;;;;;;;OAiBG;IACH,IAAW,aAAa,IAAI,aAAa,CAExC;IAED,IAAW,aAAa,CAAC,IAAI,EAAE,aAAa,EAW3C;IAiDe,OAAO,IAAI,IAAI;IAQ/B;;;;;;;OAOG;IACH,OAAO,CAAC,qBAAqB;CA4D9B"}
@@ -49,7 +49,7 @@ var ImageLayerNode = class extends Container {
49
49
  _baseOffsetY;
50
50
  _imageWidth;
51
51
  _imageHeight;
52
- _pixelSnapMode = PixelSnapMode.None;
52
+ _pixelSnapMode = PixelSnapMode.Geometry;
53
53
  _covViewX = NaN;
54
54
  _covViewY = NaN;
55
55
  _covViewWidth = NaN;
@@ -84,6 +84,7 @@ var ImageLayerNode = class extends Container {
84
84
  const b = tintColor === null ? 255 : tintColor & 255;
85
85
  sprite.tint.set(r, g, b, layer.opacity);
86
86
  this._sprite = sprite;
87
+ sprite.pixelSnapMode = this._pixelSnapMode;
87
88
  this.addChild(sprite);
88
89
  if (layer.repeatX || layer.repeatY || layer.parallaxX !== 1 || layer.parallaxY !== 1 || layer.parallaxScale !== 1) this.cullable = false;
89
90
  }
@@ -102,7 +103,11 @@ var ImageLayerNode = class extends Container {
102
103
  * is simply stored. Setting the current value is a no-op; an invalid value
103
104
  * throws and leaves the prior mode unchanged.
104
105
  *
105
- * @default PixelSnapMode.None
106
+ * Defaults to `Geometry`, matching the tile layers it is composed with, so a
107
+ * repeated backdrop does not sample between two device pixels and shimmer as
108
+ * the view moves. Set `None` to opt out.
109
+ *
110
+ * @default PixelSnapMode.Geometry
106
111
  * @stable
107
112
  */
108
113
  get pixelSnapMode() {
@@ -1 +1 @@
1
- {"version":3,"file":"ImageLayerNode.js","names":[],"sources":["../../src/ImageLayerNode.ts"],"sourcesContent":["import { Container, RepeatingSprite } from '@codexo/exojs';\nimport { PixelSnapMode, type RenderPlanBuilder } from '@codexo/exojs/renderer-sdk';\n\nimport type { ImageLayer } from './ImageLayer';\nimport { assertPixelSnapMode } from './pixelSnap';\n\n/**\n * A scene node that renders one Tiled {@link ImageLayer} as a single\n * {@link RepeatingSprite} wrapped in a {@link Container}.\n *\n * The layer's pixel `offset` becomes this node's position; `parallax` is\n * resolved per frame in {@link _collectContent} by patching the node position\n * against the camera centre (exactly like {@link import('./TileLayerNode').TileLayerNode}),\n * then restoring it. When `repeatX`/`repeatY` is set the wrapped sprite is\n * grown each frame to cover the visible view with a period-aligned origin, so\n * the pattern tiles seamlessly and scrolls with parallax. A repeat axis or a\n * `parallax` factor other than `1` both make this node's rendered position\n * and/or size camera-dependent at collect time, so its static bounds cannot be\n * culled against - such a node opts out of view culling (`cullable = false`).\n *\n * `visible`, `opacity`, and `tintColor` are applied **once at construction**:\n * {@link ImageLayer} is immutable, so there is nothing to re-sync per frame.\n * A layer whose `texture` is `null` (image failed to load / not yet available)\n * produces an empty node with no children - it occupies its offset in the\n * scene graph but draws nothing.\n *\n * The node references - but never owns - the {@link ImageLayer} and its\n * Loader-owned texture: {@link destroy} frees the wrapped sprite but leaves the\n * layer and texture intact. Image-layer nodes are band-selectable exactly like\n * tile-layer nodes: list the image layer in a\n * {@link import('./TileMapView').TileMapViewOptions.bands} definition and the\n * band stacks it by the map's combined document order, or parent an unbanded\n * node into the scene directly wherever the image belongs in draw order.\n *\n * For a `repeatX`/`repeatY` node, bounds and hit-test queries reflect the\n * coverage geometry computed by the last {@link _collectContent} call (since\n * that geometry is recomputed per collect, not maintained incrementally),\n * which is also why such a node force-disables `cullable`. A repeating or\n * parallax node also re-sizes its wrapped sprite as the camera crosses period\n * boundaries, which content-dirties an enclosing retained group the same way\n * a streamed layer does - give it the same treatment (its own\n * `RetainedContainer`, or none).\n *\n * @advanced\n */\nexport class ImageLayerNode extends Container {\n private readonly _layer: ImageLayer;\n private readonly _sprite: RepeatingSprite | null;\n private readonly _baseOffsetX: number;\n private readonly _baseOffsetY: number;\n private readonly _imageWidth: number;\n private readonly _imageHeight: number;\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.None;\n\n // Repeat-coverage cache: the view span and patched origin that last drove a\n // resize. A static camera pays one comparison per frame and skips the rebuild.\n private _covViewX = Number.NaN;\n private _covViewY = Number.NaN;\n private _covViewWidth = Number.NaN;\n private _covViewHeight = Number.NaN;\n private _covOriginX = Number.NaN;\n private _covOriginY = Number.NaN;\n\n public constructor(layer: ImageLayer) {\n super();\n\n this._layer = layer;\n this._baseOffsetX = layer.offsetX;\n this._baseOffsetY = layer.offsetY;\n\n this.setPosition(layer.offsetX, layer.offsetY);\n this.visible = layer.visible;\n\n const texture = layer.texture;\n\n if (texture === null) {\n this._sprite = null;\n this._imageWidth = 0;\n this._imageHeight = 0;\n\n return;\n }\n\n this._imageWidth = texture.width;\n this._imageHeight = texture.height;\n\n // Non-repeating axes use `'stretch'` so the axis shows exactly one un-tiled\n // copy at its natural size; repeating axes use `'repeat'` and are grown to\n // cover the view in `_collectContent`.\n const sprite = new RepeatingSprite(texture, {\n modeX: layer.repeatX ? 'repeat' : 'stretch',\n modeY: layer.repeatY ? 'repeat' : 'stretch',\n width: texture.width,\n height: texture.height,\n });\n\n const tintColor = layer.tintColor;\n const r = tintColor === null ? 255 : (tintColor >> 16) & 0xff;\n const g = tintColor === null ? 255 : (tintColor >> 8) & 0xff;\n const b = tintColor === null ? 255 : tintColor & 0xff;\n\n sprite.tint.set(r, g, b, layer.opacity);\n\n this._sprite = sprite;\n this.addChild(sprite);\n\n if (layer.repeatX || layer.repeatY || layer.parallaxX !== 1 || layer.parallaxY !== 1 || layer.parallaxScale !== 1) {\n this.cullable = false;\n }\n }\n\n /** The runtime layer this node renders. */\n public get layer(): ImageLayer {\n return this._layer;\n }\n\n /**\n * Render-only pixel-snap mode forwarded to the wrapped {@link RepeatingSprite}\n * (which snaps its rendered origin, and - in `PixelSnapMode.Geometry` mode for\n * axis-aligned transforms - its repeat-segment boundaries, to the render\n * target's device-pixel grid). Purely visual: the layer offset, parallax, and\n * repeat coverage are never changed.\n *\n * For a `null`-texture layer there is no drawable to forward to, so the mode\n * is simply stored. Setting the current value is a no-op; an invalid value\n * throws and leaves the prior mode unchanged.\n *\n * @default PixelSnapMode.None\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n if (this._sprite !== null) {\n this._sprite.pixelSnapMode = mode;\n }\n }\n\n /** @internal */\n protected override _collectContent(builder: RenderPlanBuilder): void {\n if (this._sprite === null) {\n super._collectContent(builder);\n\n return;\n }\n\n const layer = this._layer;\n\n const patchesPosition = layer.parallaxX !== 1 || layer.parallaxY !== 1;\n const patchesScale = layer.parallaxScale !== 1;\n\n if (patchesPosition || patchesScale) {\n const camCenter = builder.view.center;\n const prevX = this.x;\n const prevY = this.y;\n const prevScaleX = this.scale.x;\n const prevScaleY = this.scale.y;\n\n if (patchesPosition) {\n this.x = this._baseOffsetX + camCenter.x * (1 - layer.parallaxX);\n this.y = this._baseOffsetY + camCenter.y * (1 - layer.parallaxY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX * layer.parallaxScale, prevScaleY * layer.parallaxScale);\n }\n\n try {\n this._updateRepeatCoverage(builder, layer.parallaxScale);\n super._collectContent(builder);\n } finally {\n if (patchesPosition) {\n this.setPosition(prevX, prevY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX, prevScaleY);\n }\n }\n } else {\n this._updateRepeatCoverage(builder);\n super._collectContent(builder);\n }\n }\n\n public override destroy(): void {\n const sprite = this._sprite;\n\n super.destroy();\n\n sprite?.destroy();\n }\n\n /**\n * Grow the wrapped sprite along each repeating axis so it covers the visible\n * view, with a period-aligned local origin so the pattern offset stays zero\n * (seamless tiling). Non-repeating axes keep the natural image size at local\n * `0`. Reads `this.x`/`this.y` after the parallax patch, so the pattern anchor\n * follows the parallax-shifted origin. Skips the rebuild when neither the view\n * span nor the patched origin changed since the last frame.\n */\n private _updateRepeatCoverage(builder: RenderPlanBuilder, parallaxScale = 1): void {\n const layer = this._layer;\n const sprite = this._sprite;\n\n if (sprite === null || (!layer.repeatX && !layer.repeatY)) {\n return;\n }\n\n const bounds = builder.view.getBounds();\n const originX = this.x;\n const originY = this.y;\n\n if (\n bounds.x === this._covViewX &&\n bounds.y === this._covViewY &&\n bounds.width === this._covViewWidth &&\n bounds.height === this._covViewHeight &&\n originX === this._covOriginX &&\n originY === this._covOriginY\n ) {\n return;\n }\n\n this._covViewX = bounds.x;\n this._covViewY = bounds.y;\n this._covViewWidth = bounds.width;\n this._covViewHeight = bounds.height;\n this._covOriginX = originX;\n this._covOriginY = originY;\n\n let childX = 0;\n let childY = 0;\n let childWidth = this._imageWidth;\n let childHeight = this._imageHeight;\n\n if (layer.repeatX) {\n const imgW = this._imageWidth;\n const localViewMin = (bounds.x - originX) / parallaxScale;\n const localViewWidth = bounds.width / parallaxScale;\n const startLocal = Math.floor(localViewMin / imgW) * imgW;\n const periods = Math.ceil((localViewMin + localViewWidth - startLocal) / imgW);\n\n childX = startLocal;\n childWidth = periods * imgW;\n }\n\n if (layer.repeatY) {\n const imgH = this._imageHeight;\n const localViewMin = (bounds.y - originY) / parallaxScale;\n const localViewHeight = bounds.height / parallaxScale;\n const startLocal = Math.floor(localViewMin / imgH) * imgH;\n const periods = Math.ceil((localViewMin + localViewHeight - startLocal) / imgH);\n\n childY = startLocal;\n childHeight = periods * imgH;\n }\n\n sprite.setPosition(childX, childY);\n sprite.setSize(childWidth, childHeight);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,iBAAb,cAAoC,UAAU;CAC5C,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ,iBAAgC,cAAc;CAItD,AAAQ,YAAY;CACpB,AAAQ,YAAY;CACpB,AAAQ,gBAAgB;CACxB,AAAQ,iBAAiB;CACzB,AAAQ,cAAc;CACtB,AAAQ,cAAc;CAEtB,AAAO,YAAY,OAAmB;EACpC,MAAM;EAEN,KAAK,SAAS;EACd,KAAK,eAAe,MAAM;EAC1B,KAAK,eAAe,MAAM;EAE1B,KAAK,YAAY,MAAM,SAAS,MAAM,OAAO;EAC7C,KAAK,UAAU,MAAM;EAErB,MAAM,UAAU,MAAM;EAEtB,IAAI,YAAY,MAAM;GACpB,KAAK,UAAU;GACf,KAAK,cAAc;GACnB,KAAK,eAAe;GAEpB;EACF;EAEA,KAAK,cAAc,QAAQ;EAC3B,KAAK,eAAe,QAAQ;EAK5B,MAAM,SAAS,IAAI,gBAAgB,SAAS;GAC1C,OAAO,MAAM,UAAU,WAAW;GAClC,OAAO,MAAM,UAAU,WAAW;GAClC,OAAO,QAAQ;GACf,QAAQ,QAAQ;EAClB,CAAC;EAED,MAAM,YAAY,MAAM;EACxB,MAAM,IAAI,cAAc,OAAO,MAAO,aAAa,KAAM;EACzD,MAAM,IAAI,cAAc,OAAO,MAAO,aAAa,IAA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aAAa,KAAK,MAAM,eAAe,IAAI,IAAI;GACrD,MAAM,UAAU,KAAK,MAAM,eAAe,kBAAkB,cAAc,IAAI;GAE9E,SAAS;GACT,cAAc,UAAU;EAC1B;EAEA,OAAO,YAAY,QAAQ,MAAM;EACjC,OAAO,QAAQ,YAAY,WAAW;CACxC;AACF"}
1
+ {"version":3,"file":"ImageLayerNode.js","names":[],"sources":["../../src/ImageLayerNode.ts"],"sourcesContent":["import { Container, RepeatingSprite } from '@codexo/exojs';\nimport { PixelSnapMode, type RenderPlanBuilder } from '@codexo/exojs/renderer-sdk';\n\nimport type { ImageLayer } from './ImageLayer';\nimport { assertPixelSnapMode } from './pixelSnap';\n\n/**\n * A scene node that renders one Tiled {@link ImageLayer} as a single\n * {@link RepeatingSprite} wrapped in a {@link Container}.\n *\n * The layer's pixel `offset` becomes this node's position; `parallax` is\n * resolved per frame in {@link _collectContent} by patching the node position\n * against the camera centre (exactly like {@link import('./TileLayerNode').TileLayerNode}),\n * then restoring it. When `repeatX`/`repeatY` is set the wrapped sprite is\n * grown each frame to cover the visible view with a period-aligned origin, so\n * the pattern tiles seamlessly and scrolls with parallax. A repeat axis or a\n * `parallax` factor other than `1` both make this node's rendered position\n * and/or size camera-dependent at collect time, so its static bounds cannot be\n * culled against - such a node opts out of view culling (`cullable = false`).\n *\n * `visible`, `opacity`, and `tintColor` are applied **once at construction**:\n * {@link ImageLayer} is immutable, so there is nothing to re-sync per frame.\n * A layer whose `texture` is `null` (image failed to load / not yet available)\n * produces an empty node with no children - it occupies its offset in the\n * scene graph but draws nothing.\n *\n * The node references - but never owns - the {@link ImageLayer} and its\n * Loader-owned texture: {@link destroy} frees the wrapped sprite but leaves the\n * layer and texture intact. Image-layer nodes are band-selectable exactly like\n * tile-layer nodes: list the image layer in a\n * {@link import('./TileMapView').TileMapViewOptions.bands} definition and the\n * band stacks it by the map's combined document order, or parent an unbanded\n * node into the scene directly wherever the image belongs in draw order.\n *\n * For a `repeatX`/`repeatY` node, bounds and hit-test queries reflect the\n * coverage geometry computed by the last {@link _collectContent} call (since\n * that geometry is recomputed per collect, not maintained incrementally),\n * which is also why such a node force-disables `cullable`. A repeating or\n * parallax node also re-sizes its wrapped sprite as the camera crosses period\n * boundaries, which content-dirties an enclosing retained group the same way\n * a streamed layer does - give it the same treatment (its own\n * `RetainedContainer`, or none).\n *\n * @advanced\n */\nexport class ImageLayerNode extends Container {\n private readonly _layer: ImageLayer;\n private readonly _sprite: RepeatingSprite | null;\n private readonly _baseOffsetX: number;\n private readonly _baseOffsetY: number;\n private readonly _imageWidth: number;\n private readonly _imageHeight: number;\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n // Repeat-coverage cache: the view span and patched origin that last drove a\n // resize. A static camera pays one comparison per frame and skips the rebuild.\n private _covViewX = Number.NaN;\n private _covViewY = Number.NaN;\n private _covViewWidth = Number.NaN;\n private _covViewHeight = Number.NaN;\n private _covOriginX = Number.NaN;\n private _covOriginY = Number.NaN;\n\n public constructor(layer: ImageLayer) {\n super();\n\n this._layer = layer;\n this._baseOffsetX = layer.offsetX;\n this._baseOffsetY = layer.offsetY;\n\n this.setPosition(layer.offsetX, layer.offsetY);\n this.visible = layer.visible;\n\n const texture = layer.texture;\n\n if (texture === null) {\n this._sprite = null;\n this._imageWidth = 0;\n this._imageHeight = 0;\n\n return;\n }\n\n this._imageWidth = texture.width;\n this._imageHeight = texture.height;\n\n // Non-repeating axes use `'stretch'` so the axis shows exactly one un-tiled\n // copy at its natural size; repeating axes use `'repeat'` and are grown to\n // cover the view in `_collectContent`.\n const sprite = new RepeatingSprite(texture, {\n modeX: layer.repeatX ? 'repeat' : 'stretch',\n modeY: layer.repeatY ? 'repeat' : 'stretch',\n width: texture.width,\n height: texture.height,\n });\n\n const tintColor = layer.tintColor;\n const r = tintColor === null ? 255 : (tintColor >> 16) & 0xff;\n const g = tintColor === null ? 255 : (tintColor >> 8) & 0xff;\n const b = tintColor === null ? 255 : tintColor & 0xff;\n\n sprite.tint.set(r, g, b, layer.opacity);\n\n this._sprite = sprite;\n // The sprite's own default is `None`; without this it would render\n // unsnapped while this node reports the mode it was constructed with.\n sprite.pixelSnapMode = this._pixelSnapMode;\n this.addChild(sprite);\n\n if (layer.repeatX || layer.repeatY || layer.parallaxX !== 1 || layer.parallaxY !== 1 || layer.parallaxScale !== 1) {\n this.cullable = false;\n }\n }\n\n /** The runtime layer this node renders. */\n public get layer(): ImageLayer {\n return this._layer;\n }\n\n /**\n * Render-only pixel-snap mode forwarded to the wrapped {@link RepeatingSprite}\n * (which snaps its rendered origin, and - in `PixelSnapMode.Geometry` mode for\n * axis-aligned transforms - its repeat-segment boundaries, to the render\n * target's device-pixel grid). Purely visual: the layer offset, parallax, and\n * repeat coverage are never changed.\n *\n * For a `null`-texture layer there is no drawable to forward to, so the mode\n * is simply stored. Setting the current value is a no-op; an invalid value\n * throws and leaves the prior mode unchanged.\n *\n * Defaults to `Geometry`, matching the tile layers it is composed with, so a\n * repeated backdrop does not sample between two device pixels and shimmer as\n * the view moves. Set `None` to opt out.\n *\n * @default PixelSnapMode.Geometry\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n if (this._sprite !== null) {\n this._sprite.pixelSnapMode = mode;\n }\n }\n\n /** @internal */\n protected override _collectContent(builder: RenderPlanBuilder): void {\n if (this._sprite === null) {\n super._collectContent(builder);\n\n return;\n }\n\n const layer = this._layer;\n\n const patchesPosition = layer.parallaxX !== 1 || layer.parallaxY !== 1;\n const patchesScale = layer.parallaxScale !== 1;\n\n if (patchesPosition || patchesScale) {\n const camCenter = builder.view.center;\n const prevX = this.x;\n const prevY = this.y;\n const prevScaleX = this.scale.x;\n const prevScaleY = this.scale.y;\n\n if (patchesPosition) {\n this.x = this._baseOffsetX + camCenter.x * (1 - layer.parallaxX);\n this.y = this._baseOffsetY + camCenter.y * (1 - layer.parallaxY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX * layer.parallaxScale, prevScaleY * layer.parallaxScale);\n }\n\n try {\n this._updateRepeatCoverage(builder, layer.parallaxScale);\n super._collectContent(builder);\n } finally {\n if (patchesPosition) {\n this.setPosition(prevX, prevY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX, prevScaleY);\n }\n }\n } else {\n this._updateRepeatCoverage(builder);\n super._collectContent(builder);\n }\n }\n\n public override destroy(): void {\n const sprite = this._sprite;\n\n super.destroy();\n\n sprite?.destroy();\n }\n\n /**\n * Grow the wrapped sprite along each repeating axis so it covers the visible\n * view, with a period-aligned local origin so the pattern offset stays zero\n * (seamless tiling). Non-repeating axes keep the natural image size at local\n * `0`. Reads `this.x`/`this.y` after the parallax patch, so the pattern anchor\n * follows the parallax-shifted origin. Skips the rebuild when neither the view\n * span nor the patched origin changed since the last frame.\n */\n private _updateRepeatCoverage(builder: RenderPlanBuilder, parallaxScale = 1): void {\n const layer = this._layer;\n const sprite = this._sprite;\n\n if (sprite === null || (!layer.repeatX && !layer.repeatY)) {\n return;\n }\n\n const bounds = builder.view.getBounds();\n const originX = this.x;\n const originY = this.y;\n\n if (\n bounds.x === this._covViewX &&\n bounds.y === this._covViewY &&\n bounds.width === this._covViewWidth &&\n bounds.height === this._covViewHeight &&\n originX === this._covOriginX &&\n originY === this._covOriginY\n ) {\n return;\n }\n\n this._covViewX = bounds.x;\n this._covViewY = bounds.y;\n this._covViewWidth = bounds.width;\n this._covViewHeight = bounds.height;\n this._covOriginX = originX;\n this._covOriginY = originY;\n\n let childX = 0;\n let childY = 0;\n let childWidth = this._imageWidth;\n let childHeight = this._imageHeight;\n\n if (layer.repeatX) {\n const imgW = this._imageWidth;\n const localViewMin = (bounds.x - originX) / parallaxScale;\n const localViewWidth = bounds.width / parallaxScale;\n const startLocal = Math.floor(localViewMin / imgW) * imgW;\n const periods = Math.ceil((localViewMin + localViewWidth - startLocal) / imgW);\n\n childX = startLocal;\n childWidth = periods * imgW;\n }\n\n if (layer.repeatY) {\n const imgH = this._imageHeight;\n const localViewMin = (bounds.y - originY) / parallaxScale;\n const localViewHeight = bounds.height / parallaxScale;\n const startLocal = Math.floor(localViewMin / imgH) * imgH;\n const periods = Math.ceil((localViewMin + localViewHeight - startLocal) / imgH);\n\n childY = startLocal;\n childHeight = periods * imgH;\n }\n\n sprite.setPosition(childX, childY);\n sprite.setSize(childWidth, childHeight);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,iBAAb,cAAoC,UAAU;CAC5C,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CACjB,AAAQ,iBAAgC,cAAc;CAItD,AAAQ,YAAY;CACpB,AAAQ,YAAY;CACpB,AAAQ,gBAAgB;CACxB,AAAQ,iBAAiB;CACzB,AAAQ,cAAc;CACtB,AAAQ,cAAc;CAEtB,AAAO,YAAY,OAAmB;EACpC,MAAM;EAEN,KAAK,SAAS;EACd,KAAK,eAAe,MAAM;EAC1B,KAAK,eAAe,MAAM;EAE1B,KAAK,YAAY,MAAM,SAAS,MAAM,OAAO;EAC7C,KAAK,UAAU,MAAM;EAErB,MAAM,UAAU,MAAM;EAEtB,IAAI,YAAY,MAAM;GACpB,KAAK,UAAU;GACf,KAAK,cAAc;GACnB,KAAK,eAAe;GAEpB;EACF;EAEA,KAAK,cAAc,QAAQ;EAC3B,KAAK,eAAe,QAAQ;EAK5B,MAAM,SAAS,IAAI,gBAAgB,SAAS;GAC1C,OAAO,MAAM,UAAU,WAAW;GAClC,OAAO,MAAM,UAAU,WAAW;GAClC,OAAO,QAAQ;GACf,QAAQ,QAAQ;EAClB,CAAC;EAED,MAAM,YAAY,MAAM;EACxB,MAAM,IAAI,cAAc,OAAO,MAAO,aAAa,KAAM;EACzD,MAAM,IAAI,cAAc,OA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,WAAW;GAC5C,MAAM,kBAAkB,OAAO,SAAS;GACxC,MAAM,aAAa,KAAK,MAAM,eAAe,IAAI,IAAI;GACrD,MAAM,UAAU,KAAK,MAAM,eAAe,kBAAkB,cAAc,IAAI;GAE9E,SAAS;GACT,cAAc,UAAU;EAC1B;EAEA,OAAO,YAAY,QAAQ,MAAM;EACjC,OAAO,QAAQ,YAAY,WAAW;CACxC;AACF"}
@@ -77,7 +77,12 @@ export declare class TileLayerNode extends Container {
77
77
  * integer pixel grid by construction). Setting the current value is a no-op;
78
78
  * an invalid value throws and leaves the prior mode unchanged.
79
79
  *
80
- * @default PixelSnapMode.None
80
+ * Defaults to `Geometry` because a tile grid is made of quads that share
81
+ * their edges: left unsnapped, a boundary landing between two device pixels
82
+ * is sampled across both, so the seams blur and shimmer as the view moves.
83
+ * Set `None` to opt out.
84
+ *
85
+ * @default PixelSnapMode.Geometry
81
86
  * @stable
82
87
  */
83
88
  get pixelSnapMode(): PixelSnapMode;
@@ -1 +1 @@
1
- {"version":3,"file":"TileLayerNode.d.ts","sourceRoot":"","sources":["../../src/TileLayerNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,aAAa,EAA0B,MAAM,4BAA4B,CAAC;AAMnF,OAAO,KAAK,EAAwB,SAAS,EAAE,MAAM,aAAa,CAAC;AAEnE;;;;GAIG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,aAAc,SAAQ,SAAS;IAC1C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAY;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW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W,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAuB;IACnD,OAAO,CAAC,cAAc,CAAM;IAC5B,OAAO,CAAC,WAAW,CAAwC;IAC3D,OAAO,CAAC,cAAc,CAAyC;IAE/D;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAoBlC;gBAEiB,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,oBAAoB;IAgBnE,2CAA2C;IAC3C,IAAW,KAAK,IAAI,SAAS,CAE5B;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,IAAW,aAAa,IAAI,aAAa,CAExC;IAED,IAAW,aAAa,CAAC,IAAI,EAAE,aAAa,EAW3C;IAED;;;;OAIG;IACI,OAAO,IAAI,IAAI;IAsBtB;;;;OAIG;IACa,cAAc,IAAI,iBAAiB;IAkEnC,OAAO,IAAI,IAAI;IAc/B,OAAO,CAAC,gBAAgB;IAiBxB;;;;;OAKG;IACH,OAAO,CAAC,gBAAgB;IAYxB;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU;IAQlB;;;;OAIG;IACH,OAAO,CAAC,SAAS;CAelB"}
@@ -42,7 +42,7 @@ var TileLayerNode = class extends Container {
42
42
  _chunkNodes = [];
43
43
  _syncedOpacity = -1;
44
44
  _syncedTint = void 0;
45
- _pixelSnapMode = PixelSnapMode.None;
45
+ _pixelSnapMode = PixelSnapMode.Geometry;
46
46
  /**
47
47
  * Bound once so `TileLayer._addStructuralListener`/`_removeStructuralListener`
48
48
  * add and remove the SAME function reference. Incrementally adds/removes
@@ -90,7 +90,12 @@ var TileLayerNode = class extends Container {
90
90
  * integer pixel grid by construction). Setting the current value is a no-op;
91
91
  * an invalid value throws and leaves the prior mode unchanged.
92
92
  *
93
- * @default PixelSnapMode.None
93
+ * Defaults to `Geometry` because a tile grid is made of quads that share
94
+ * their edges: left unsnapped, a boundary landing between two device pixels
95
+ * is sampled across both, so the seams blur and shimmer as the view moves.
96
+ * Set `None` to opt out.
97
+ *
98
+ * @default PixelSnapMode.Geometry
94
99
  * @stable
95
100
  */
96
101
  get pixelSnapMode() {
@@ -187,7 +192,7 @@ var TileLayerNode = class extends Container {
187
192
  const layer = this._layer;
188
193
  const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight);
189
194
  node.cullable = this._cullChunks;
190
- if (this._pixelSnapMode !== PixelSnapMode.None) node.pixelSnapMode = this._pixelSnapMode;
195
+ node.pixelSnapMode = this._pixelSnapMode;
191
196
  return node;
192
197
  }
193
198
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"TileLayerNode.js","names":[],"sources":["../../src/TileLayerNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode, type RenderPlanBuilder } from '@codexo/exojs/renderer-sdk';\n\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunkNode } from './TileChunkNode';\nimport type { ChunkStructuralEvent, TileLayer } from './TileLayer';\n\n/**\n * Options for a {@link TileLayerNode}. All optional; reserved for forward\n * compatibility.\n * @advanced\n */\nexport interface TileLayerNodeOptions {\n /**\n * Whether the layer's chunk nodes participate in per-chunk view culling.\n * Defaults to `true`. Disable only for tiny, always-on-screen layers where\n * the per-chunk bounds test is pure overhead.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A scene node that renders one generic {@link TileLayer} as a\n * {@link Container} of per-chunk {@link TileChunkNode} drawables.\n *\n * Each non-empty loaded chunk becomes one child positioned at its pixel\n * origin, so the engine's existing per-node culling drops individual chunks and\n * the render-plan optimiser batches them by tileset texture. The layer's pixel\n * `offset`, `visible` and `opacity` are all read live from the runtime layer on\n * every frame (no rebuild required).\n *\n * A `parallax` factor other than `1` makes this node's rendered position\n * camera-dependent, resolved per frame in {@link _collectContent} by patching\n * the node position against the camera centre, then restoring it - the cull\n * test runs before that patch, so a bounded layer with parallax would be\n * culled at its static base-offset bounds while actually rendering elsewhere.\n * Such a layer therefore opts out of view culling (`cullable = false`), same\n * as an unbounded layer (exactly like {@link import('./ImageLayerNode').ImageLayerNode}).\n *\n * The node references - but never owns - the {@link TileLayer}: destroying it\n * frees its chunk nodes and their cached geometry but leaves the layer, map,\n * and Loader-owned textures intact.\n *\n * Structural changes made via `_adoptChunk`/`_evictChunk` (chunk streaming)\n * are picked up incrementally as they happen, without a full rebuild.\n * {@link TileLayerNode.refresh} remains available for callers that mutate\n * chunk structure by other means (e.g. a bulk edit that bypasses\n * `_adoptChunk`/`_evictChunk`) and need a full resync. In-place tile edits to\n * existing chunks are picked up automatically via chunk revisions.\n *\n * @advanced\n */\nexport class TileLayerNode extends Container {\n private readonly _layer: TileLayer;\n private readonly _cullChunks: boolean;\n private readonly _chunkNodes: TileChunkNode[] = [];\n private _syncedOpacity = -1;\n private _syncedTint: number | null | undefined = undefined;\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.None;\n\n /**\n * Bound once so `TileLayer._addStructuralListener`/`_removeStructuralListener`\n * add and remove the SAME function reference. Incrementally adds/removes\n * the `TileChunkNode` child for exactly the chunk that changed - never\n * triggers a full {@link refresh}, so every other chunk node's\n * revision-cached geometry survives untouched.\n */\n private readonly _onStructuralChange = (event: ChunkStructuralEvent): void => {\n const existingIndex = this._chunkNodes.findIndex(n => n.chunkX === event.cx && n.chunkY === event.cy);\n\n const existing = this._chunkNodes[existingIndex];\n\n if (existing) {\n this._chunkNodes.splice(existingIndex, 1);\n this.removeChild(existing);\n existing.destroy();\n }\n\n if (event.chunk === null || event.chunk.empty) {\n return;\n }\n\n const node = this._createChunkNode(event.chunk);\n\n this._chunkNodes.push(node);\n this.addChild(node);\n this._applyTint(node);\n };\n\n public constructor(layer: TileLayer, options?: TileLayerNodeOptions) {\n super();\n\n this._layer = layer;\n this._cullChunks = options?.cullable ?? true;\n\n this.setPosition(layer.offsetX, layer.offsetY);\n this._buildChunkNodes();\n\n if (!this._layer.bounded || layer.parallaxX !== 1 || layer.parallaxY !== 1 || layer.parallaxScale !== 1) {\n this.cullable = false;\n }\n\n this._layer._addStructuralListener(this._onStructuralChange);\n }\n\n /** The runtime layer this node renders. */\n public get layer(): TileLayer {\n return this._layer;\n }\n\n /**\n * Render-only pixel-snap mode applied to every chunk node in this layer (and\n * to chunks rebuilt later by {@link refresh}). Each chunk's rendered origin is\n * snapped to the active render target's device-pixel grid; because chunk\n * origins are integer multiples of the integer tile pitch from the same layer\n * origin, the whole grid stays exact and adjacent chunks cannot drift apart.\n *\n * Purely visual: tile data, the layer offset, chunk content revisions, and\n * culling bounds are never changed. `PixelSnapMode.Geometry` and `PixelSnapMode.Position` both resolve\n * to coherent origin snapping for tile chunks (chunk quads are already on the\n * integer pixel grid by construction). Setting the current value is a no-op;\n * an invalid value throws and leaves the prior mode unchanged.\n *\n * @default PixelSnapMode.None\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const chunk of this._chunkNodes) {\n chunk.pixelSnapMode = mode;\n }\n }\n\n /**\n * Rebuild the chunk-node children from the layer's current loaded chunks.\n * Call after structural mutation that creates or empties chunks. In-place\n * tile edits to existing chunks do not need a refresh.\n */\n public refresh(): this {\n const previous = [...this._chunkNodes];\n\n this.removeChildren();\n this._chunkNodes.length = 0;\n\n for (const child of previous) {\n child.destroy();\n }\n\n this._syncedOpacity = -1;\n this._syncedTint = undefined;\n this._buildChunkNodes();\n\n return this;\n }\n\n /** The chunk render nodes owned by this layer node, in build order. @internal */\n public get chunkNodes(): readonly TileChunkNode[] {\n return this._chunkNodes;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._layer;\n\n if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(0, 0, pixelWidth, pixelHeight);\n } else if (this._chunkNodes.length > 0) {\n aggregateChildLocalBounds(this._chunkNodes, bounds);\n }\n\n return bounds;\n }\n\n /** @internal */\n protected override _collectContent(builder: RenderPlanBuilder): void {\n if (!this._layer.visible) {\n return;\n }\n\n this._syncTint();\n\n const layer = this._layer;\n\n const patchesPosition = layer.parallaxX !== 1 || layer.parallaxY !== 1;\n const patchesScale = layer.parallaxScale !== 1;\n\n // `offsetX`/`offsetY` are live, mutable fields (`TileColliderStreamer` and\n // `pixelToTile` already read them per call) - re-read here every frame so a\n // runtime-moved layer's rendering follows its collision rather than freezing\n // at the position it had when this node was constructed.\n if (patchesPosition || patchesScale) {\n const camCenter = builder.view.center;\n const prevScaleX = this.scale.x;\n const prevScaleY = this.scale.y;\n\n if (patchesPosition) {\n this.x = layer.offsetX + camCenter.x * (1 - layer.parallaxX);\n this.y = layer.offsetY + camCenter.y * (1 - layer.parallaxY);\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX * layer.parallaxScale, prevScaleY * layer.parallaxScale);\n }\n\n try {\n super._collectContent(builder);\n } finally {\n if (patchesPosition) {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX, prevScaleY);\n }\n }\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n super._collectContent(builder);\n }\n }\n\n public override destroy(): void {\n this._layer._removeStructuralListener(this._onStructuralChange);\n\n const children = [...this._chunkNodes];\n\n this._chunkNodes.length = 0;\n\n super.destroy();\n\n for (const child of children) {\n child.destroy();\n }\n }\n\n private _buildChunkNodes(): void {\n const layer = this._layer;\n\n for (const chunk of layer.loadedChunks()) {\n if (chunk.empty) {\n continue;\n }\n\n const node = this._createChunkNode(chunk);\n\n this._chunkNodes.push(node);\n this.addChild(node);\n }\n\n this._syncTint();\n }\n\n /**\n * Construct one configured {@link TileChunkNode} for `chunk` - shared by\n * the initial bulk build ({@link _buildChunkNodes}) and the incremental\n * structural-listener handler, so a future constructor argument or\n * per-node setting only needs to be added in one place.\n */\n private _createChunkNode(chunk: ReadonlyTileChunk): TileChunkNode {\n const layer = this._layer;\n const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight);\n\n node.cullable = this._cullChunks;\n\n if (this._pixelSnapMode !== PixelSnapMode.None) {\n node.pixelSnapMode = this._pixelSnapMode;\n }\n\n return node;\n }\n\n /**\n * Compute and apply this layer's live tint (opacity as alpha, `tintColor`\n * as RGB multiply) to a single chunk node. Used both by {@link _syncTint}'s\n * bulk pass and by the structural-listener handler for a freshly-added\n * node - a node added between two \"nothing changed\" full syncs must still\n * receive the current tint, which a change-detection-guarded bulk pass\n * alone would skip.\n */\n private _applyTint(node: TileChunkNode): void {\n const tintColor = this._layer.tintColor;\n const r = tintColor === null ? 255 : (tintColor >> 16) & 0xff;\n const g = tintColor === null ? 255 : (tintColor >> 8) & 0xff;\n const b = tintColor === null ? 255 : tintColor & 0xff;\n node.tint.set(r, g, b, this._layer.opacity);\n }\n\n /**\n * Propagate the layer's live opacity and tint colour onto every chunk\n * render tint if either changed since the last call. Opacity drives the\n * tint alpha; `tintColor` (`0xRRGGBB`) multiplies the RGB (white = no tint).\n */\n private _syncTint(): void {\n const opacity = this._layer.opacity;\n const tintColor = this._layer.tintColor;\n\n if (opacity === this._syncedOpacity && tintColor === this._syncedTint) {\n return;\n }\n\n for (const child of this._chunkNodes) {\n this._applyTint(child);\n }\n\n this._syncedOpacity = opacity;\n this._syncedTint = tintColor;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;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AK;EAGvB,KAAK,iBAAiB;EACtB,KAAK,cAAc;CACrB;AACF"}
1
+ {"version":3,"file":"TileLayerNode.js","names":[],"sources":["../../src/TileLayerNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode, type RenderPlanBuilder } from '@codexo/exojs/renderer-sdk';\n\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport { TileChunkNode } from './TileChunkNode';\nimport type { ChunkStructuralEvent, TileLayer } from './TileLayer';\n\n/**\n * Options for a {@link TileLayerNode}. All optional; reserved for forward\n * compatibility.\n * @advanced\n */\nexport interface TileLayerNodeOptions {\n /**\n * Whether the layer's chunk nodes participate in per-chunk view culling.\n * Defaults to `true`. Disable only for tiny, always-on-screen layers where\n * the per-chunk bounds test is pure overhead.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A scene node that renders one generic {@link TileLayer} as a\n * {@link Container} of per-chunk {@link TileChunkNode} drawables.\n *\n * Each non-empty loaded chunk becomes one child positioned at its pixel\n * origin, so the engine's existing per-node culling drops individual chunks and\n * the render-plan optimiser batches them by tileset texture. The layer's pixel\n * `offset`, `visible` and `opacity` are all read live from the runtime layer on\n * every frame (no rebuild required).\n *\n * A `parallax` factor other than `1` makes this node's rendered position\n * camera-dependent, resolved per frame in {@link _collectContent} by patching\n * the node position against the camera centre, then restoring it - the cull\n * test runs before that patch, so a bounded layer with parallax would be\n * culled at its static base-offset bounds while actually rendering elsewhere.\n * Such a layer therefore opts out of view culling (`cullable = false`), same\n * as an unbounded layer (exactly like {@link import('./ImageLayerNode').ImageLayerNode}).\n *\n * The node references - but never owns - the {@link TileLayer}: destroying it\n * frees its chunk nodes and their cached geometry but leaves the layer, map,\n * and Loader-owned textures intact.\n *\n * Structural changes made via `_adoptChunk`/`_evictChunk` (chunk streaming)\n * are picked up incrementally as they happen, without a full rebuild.\n * {@link TileLayerNode.refresh} remains available for callers that mutate\n * chunk structure by other means (e.g. a bulk edit that bypasses\n * `_adoptChunk`/`_evictChunk`) and need a full resync. In-place tile edits to\n * existing chunks are picked up automatically via chunk revisions.\n *\n * @advanced\n */\nexport class TileLayerNode extends Container {\n private readonly _layer: TileLayer;\n private readonly _cullChunks: boolean;\n private readonly _chunkNodes: TileChunkNode[] = [];\n private _syncedOpacity = -1;\n private _syncedTint: number | null | undefined = undefined;\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n /**\n * Bound once so `TileLayer._addStructuralListener`/`_removeStructuralListener`\n * add and remove the SAME function reference. Incrementally adds/removes\n * the `TileChunkNode` child for exactly the chunk that changed - never\n * triggers a full {@link refresh}, so every other chunk node's\n * revision-cached geometry survives untouched.\n */\n private readonly _onStructuralChange = (event: ChunkStructuralEvent): void => {\n const existingIndex = this._chunkNodes.findIndex(n => n.chunkX === event.cx && n.chunkY === event.cy);\n\n const existing = this._chunkNodes[existingIndex];\n\n if (existing) {\n this._chunkNodes.splice(existingIndex, 1);\n this.removeChild(existing);\n existing.destroy();\n }\n\n if (event.chunk === null || event.chunk.empty) {\n return;\n }\n\n const node = this._createChunkNode(event.chunk);\n\n this._chunkNodes.push(node);\n this.addChild(node);\n this._applyTint(node);\n };\n\n public constructor(layer: TileLayer, options?: TileLayerNodeOptions) {\n super();\n\n this._layer = layer;\n this._cullChunks = options?.cullable ?? true;\n\n this.setPosition(layer.offsetX, layer.offsetY);\n this._buildChunkNodes();\n\n if (!this._layer.bounded || layer.parallaxX !== 1 || layer.parallaxY !== 1 || layer.parallaxScale !== 1) {\n this.cullable = false;\n }\n\n this._layer._addStructuralListener(this._onStructuralChange);\n }\n\n /** The runtime layer this node renders. */\n public get layer(): TileLayer {\n return this._layer;\n }\n\n /**\n * Render-only pixel-snap mode applied to every chunk node in this layer (and\n * to chunks rebuilt later by {@link refresh}). Each chunk's rendered origin is\n * snapped to the active render target's device-pixel grid; because chunk\n * origins are integer multiples of the integer tile pitch from the same layer\n * origin, the whole grid stays exact and adjacent chunks cannot drift apart.\n *\n * Purely visual: tile data, the layer offset, chunk content revisions, and\n * culling bounds are never changed. `PixelSnapMode.Geometry` and `PixelSnapMode.Position` both resolve\n * to coherent origin snapping for tile chunks (chunk quads are already on the\n * integer pixel grid by construction). Setting the current value is a no-op;\n * an invalid value throws and leaves the prior mode unchanged.\n *\n * Defaults to `Geometry` because a tile grid is made of quads that share\n * their edges: left unsnapped, a boundary landing between two device pixels\n * is sampled across both, so the seams blur and shimmer as the view moves.\n * Set `None` to opt out.\n *\n * @default PixelSnapMode.Geometry\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const chunk of this._chunkNodes) {\n chunk.pixelSnapMode = mode;\n }\n }\n\n /**\n * Rebuild the chunk-node children from the layer's current loaded chunks.\n * Call after structural mutation that creates or empties chunks. In-place\n * tile edits to existing chunks do not need a refresh.\n */\n public refresh(): this {\n const previous = [...this._chunkNodes];\n\n this.removeChildren();\n this._chunkNodes.length = 0;\n\n for (const child of previous) {\n child.destroy();\n }\n\n this._syncedOpacity = -1;\n this._syncedTint = undefined;\n this._buildChunkNodes();\n\n return this;\n }\n\n /** The chunk render nodes owned by this layer node, in build order. @internal */\n public get chunkNodes(): readonly TileChunkNode[] {\n return this._chunkNodes;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._layer;\n\n if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(0, 0, pixelWidth, pixelHeight);\n } else if (this._chunkNodes.length > 0) {\n aggregateChildLocalBounds(this._chunkNodes, bounds);\n }\n\n return bounds;\n }\n\n /** @internal */\n protected override _collectContent(builder: RenderPlanBuilder): void {\n if (!this._layer.visible) {\n return;\n }\n\n this._syncTint();\n\n const layer = this._layer;\n\n const patchesPosition = layer.parallaxX !== 1 || layer.parallaxY !== 1;\n const patchesScale = layer.parallaxScale !== 1;\n\n // `offsetX`/`offsetY` are live, mutable fields (`TileColliderStreamer` and\n // `pixelToTile` already read them per call) - re-read here every frame so a\n // runtime-moved layer's rendering follows its collision rather than freezing\n // at the position it had when this node was constructed.\n if (patchesPosition || patchesScale) {\n const camCenter = builder.view.center;\n const prevScaleX = this.scale.x;\n const prevScaleY = this.scale.y;\n\n if (patchesPosition) {\n this.x = layer.offsetX + camCenter.x * (1 - layer.parallaxX);\n this.y = layer.offsetY + camCenter.y * (1 - layer.parallaxY);\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX * layer.parallaxScale, prevScaleY * layer.parallaxScale);\n }\n\n try {\n super._collectContent(builder);\n } finally {\n if (patchesPosition) {\n this.setPosition(layer.offsetX, layer.offsetY);\n }\n\n if (patchesScale) {\n this.setScale(prevScaleX, prevScaleY);\n }\n }\n } else {\n this.setPosition(layer.offsetX, layer.offsetY);\n super._collectContent(builder);\n }\n }\n\n public override destroy(): void {\n this._layer._removeStructuralListener(this._onStructuralChange);\n\n const children = [...this._chunkNodes];\n\n this._chunkNodes.length = 0;\n\n super.destroy();\n\n for (const child of children) {\n child.destroy();\n }\n }\n\n private _buildChunkNodes(): void {\n const layer = this._layer;\n\n for (const chunk of layer.loadedChunks()) {\n if (chunk.empty) {\n continue;\n }\n\n const node = this._createChunkNode(chunk);\n\n this._chunkNodes.push(node);\n this.addChild(node);\n }\n\n this._syncTint();\n }\n\n /**\n * Construct one configured {@link TileChunkNode} for `chunk` - shared by\n * the initial bulk build ({@link _buildChunkNodes}) and the incremental\n * structural-listener handler, so a future constructor argument or\n * per-node setting only needs to be added in one place.\n */\n private _createChunkNode(chunk: ReadonlyTileChunk): TileChunkNode {\n const layer = this._layer;\n const node = new TileChunkNode(chunk, layer.tilesets, layer.tileWidth, layer.tileHeight, layer.chunkWidth, layer.chunkHeight);\n\n node.cullable = this._cullChunks;\n // Unconditional: a chunk built after the layer was set to `None` has to\n // inherit that too, not just a non-default mode.\n node.pixelSnapMode = this._pixelSnapMode;\n\n return node;\n }\n\n /**\n * Compute and apply this layer's live tint (opacity as alpha, `tintColor`\n * as RGB multiply) to a single chunk node. Used both by {@link _syncTint}'s\n * bulk pass and by the structural-listener handler for a freshly-added\n * node - a node added between two \"nothing changed\" full syncs must still\n * receive the current tint, which a change-detection-guarded bulk pass\n * alone would skip.\n */\n private _applyTint(node: TileChunkNode): void {\n const tintColor = this._layer.tintColor;\n const r = tintColor === null ? 255 : (tintColor >> 16) & 0xff;\n const g = tintColor === null ? 255 : (tintColor >> 8) & 0xff;\n const b = tintColor === null ? 255 : tintColor & 0xff;\n node.tint.set(r, g, b, this._layer.opacity);\n }\n\n /**\n * Propagate the layer's live opacity and tint colour onto every chunk\n * render tint if either changed since the last call. Opacity drives the\n * tint alpha; `tintColor` (`0xRRGGBB`) multiplies the RGB (white = no tint).\n */\n private _syncTint(): void {\n const opacity = this._layer.opacity;\n const tintColor = this._layer.tintColor;\n\n if (opacity === this._syncedOpacity && tintColor === this._syncedTint) {\n return;\n }\n\n for (const child of this._chunkNodes) {\n this._applyTint(child);\n }\n\n this._syncedOpacity = opacity;\n this._syncedTint = tintColor;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuDA,IAAa,gBAAb,cAAmC,UAAU;CAC3C,AAAiB;CACjB,AAAiB;CACjB,AAAiB,cAA+B,CAAC;CACjD,AAAQ,iBAAiB;CACzB,AAAQ,cAAyC;CACjD,AAAQ,iBAAgC,cAA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ErC,KAAK,YAAY,SAAS;EAE1B,MAAM,QAAQ;EAEd,KAAK,MAAM,SAAS,UAClB,MAAM,QAAQ;CAElB;CAEA,AAAQ,mBAAyB;EAC/B,MAAM,QAAQ,KAAK;EAEnB,KAAK,MAAM,SAAS,MAAM,aAAa,GAAG;GACxC,IAAI,MAAM,OACR;GAGF,MAAM,OAAO,KAAK,iBAAiB,KAAK;GAExC,KAAK,YAAY,KAAK,IAAI;GAC1B,KAAK,SAAS,IAAI;EACpB;EAEA,KAAK,UAAU;CACjB;;;;;;;CAQA,AAAQ,iBAAiB,OAAyC;EAChE,MAAM,QAAQ,KAAK;EACnB,MAAM,OAAO,IAAI,cAAc,OAAO,MAAM,UAAU,MAAM,WAAW,MAAM,YAAY,MAAM,YAAY,MAAM,WAAW;EAE5H,KAAK,WAAW,KAAK;EAGrB,KAAK,gBAAgB,KAAK;EAE1B,OAAO;CACT;;;;;;;;;CAUA,AAAQ,WAAW,MAA2B;EAC5C,MAAM,YAAY,KAAK,OAAO;EAC9B,MAAM,IAAI,cAAc,OAAO,MAAO,aAAa,KAAM;EACzD,MAAM,IAAI,cAAc,OAAO,MAAO,aAAa,IAAK;EACxD,MAAM,IAAI,cAAc,OAAO,MAAM,YAAY;EACjD,KAAK,KAAK,IAAI,GAAG,GAAG,GAAG,KAAK,OAAO,OAAO;CAC5C;;;;;;CAOA,AAAQ,YAAkB;EACxB,MAAM,UAAU,KAAK,OAAO;EAC5B,MAAM,YAAY,KAAK,OAAO;EAE9B,IAAI,YAAY,KAAK,kBAAkB,cAAc,KAAK,aACxD;EAGF,KAAK,MAAM,SAAS,KAAK,aACvB,KAAK,WAAW,KAAK;EAGvB,KAAK,iBAAiB;EACtB,KAAK,cAAc;CACrB;AACF"}
@@ -54,7 +54,12 @@ export declare class TileMapNode extends Container {
54
54
  * unchanged. Setting the current value is a no-op; an invalid value throws and
55
55
  * leaves the prior mode unchanged.
56
56
  *
57
- * @default PixelSnapMode.None
57
+ * Defaults to `Geometry` because a tile grid is made of quads that share
58
+ * their edges: left unsnapped, a boundary landing between two device pixels
59
+ * is sampled across both, so the seams blur and shimmer as the view moves.
60
+ * Set `None` to opt out.
61
+ *
62
+ * @default PixelSnapMode.Geometry
58
63
  * @stable
59
64
  */
60
65
  get pixelSnapMode(): PixelSnapMode;
@@ -1 +1 @@
1
- {"version":3,"file":"TileMapNode.d.ts","sourceRoot":"","sources":["../../src/TileMapNode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,WAAY,SAAQ,SAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAU;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAU;IACtC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA6C;IACzE,OAAO,CAAC,cAAc,CAAqC;gBAExC,GAAG,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,kBAAkB;IAa7D,yCAAyC;IACzC,IAAW,GAAG,IAAI,OAAO,CAExB;IAED;;;;;;;;;;;OAWG;IACH,IAAW,aAAa,IAAI,aAAa,CAExC;IAED,IAAW,aAAa,CAAC,IAAI,EAAE,aAAa,EAW3C;IAED;;;OAGG;IACH,IAAW,UAAU,IAAI,aAAa,CAAC,aAAa,GAAG,cAAc,CAAC,CAErE;IA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C,aAAa,GAAG,cAAc,CAAC,CAErE;IAED;;;OAGG;IACI,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,cAAc,GAAG,SAAS;IAI7E;;;;OAIG;IACI,aAAa,IAAI,IAAI;IAe5B;;;;OAIG;IACa,cAAc,IAAI,iBAAiB;IAgBnC,OAAO,IAAI,IAAI;IAY/B,OAAO,CAAC,gBAAgB;CAYzB"}
@@ -33,7 +33,7 @@ var TileMapNode = class extends Container {
33
33
  _map;
34
34
  _cullChunks;
35
35
  _layerNodes = [];
36
- _pixelSnapMode = PixelSnapMode.None;
36
+ _pixelSnapMode = PixelSnapMode.Geometry;
37
37
  constructor(map, options) {
38
38
  super();
39
39
  this._map = map;
@@ -54,7 +54,12 @@ var TileMapNode = class extends Container {
54
54
  * unchanged. Setting the current value is a no-op; an invalid value throws and
55
55
  * leaves the prior mode unchanged.
56
56
  *
57
- * @default PixelSnapMode.None
57
+ * Defaults to `Geometry` because a tile grid is made of quads that share
58
+ * their edges: left unsnapped, a boundary landing between two device pixels
59
+ * is sampled across both, so the seams blur and shimmer as the view moves.
60
+ * Set `None` to opt out.
61
+ *
62
+ * @default PixelSnapMode.Geometry
58
63
  * @stable
59
64
  */
60
65
  get pixelSnapMode() {
@@ -114,7 +119,7 @@ var TileMapNode = class extends Container {
114
119
  _buildLayerNodes() {
115
120
  for (const layer of this._map.renderableLayers) {
116
121
  const node = layer instanceof ImageLayer ? new ImageLayerNode(layer) : new TileLayerNode(layer, { cullable: this._cullChunks });
117
- if (this._pixelSnapMode !== PixelSnapMode.None) node.pixelSnapMode = this._pixelSnapMode;
122
+ node.pixelSnapMode = this._pixelSnapMode;
118
123
  this._layerNodes.push(node);
119
124
  this.addChild(node);
120
125
  }
@@ -1 +1 @@
1
- {"version":3,"file":"TileMapNode.js","names":[],"sources":["../../src/TileMapNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode } from '@codexo/exojs/renderer-sdk';\n\nimport { ImageLayer } from './ImageLayer';\nimport { ImageLayerNode } from './ImageLayerNode';\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport { TileLayerNode } from './TileLayerNode';\nimport type { TileMap } from './TileMap';\n\n/**\n * Options for a {@link TileMapNode}.\n * @advanced\n */\nexport interface TileMapNodeOptions {\n /**\n * Whether the map's chunk nodes participate in per-chunk view culling.\n * Forwarded to every {@link TileLayerNode}. Defaults to `true`.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A convenience scene node that renders a whole {@link TileMap} as a\n * {@link Container} of one node per renderable layer - a {@link TileLayerNode}\n * per tile layer and an {@link ImageLayerNode} per image layer, interleaved\n * back-to-front by the map's combined document order\n * ({@link import('./TileMap').TileMap.renderableLayers}).\n *\n * `TileMapNode` owns **only** its layer nodes - never application actors. Use\n * it for the simple, non-interleaved case (no actors between layers); for\n * actor interleaving, place individual `TileLayerNode`s / `ImageLayerNode`s\n * into your own scene graph instead (see `TileMapView`).\n *\n * The node references - but never owns - the {@link TileMap}: destroying the\n * node frees its layer/chunk nodes and their cached GPU geometry, while the\n * `TileMap` data and Loader-owned textures survive (free them via\n * `TileMap.destroy()` / `Loader.destroy()` respectively).\n *\n * Layers added to or removed from the map after construction are reflected only\n * after {@link TileMapNode.refreshLayers}.\n *\n * @advanced\n */\nexport class TileMapNode extends Container {\n private readonly _map: TileMap;\n private readonly _cullChunks: boolean;\n private readonly _layerNodes: Array<TileLayerNode | ImageLayerNode> = [];\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.None;\n\n public constructor(map: TileMap, options?: TileMapNodeOptions) {\n super();\n\n this._map = map;\n this._cullChunks = options?.cullable ?? true;\n\n this._buildLayerNodes();\n\n if (!this._map.bounded) {\n this.cullable = false;\n }\n }\n\n /** The runtime map this node renders. */\n public get map(): TileMap {\n return this._map;\n }\n\n /**\n * Render-only pixel-snap mode applied to every layer (and forwarded to every\n * chunk node, current and rebuilt). Snaps tile chunk origins to the active\n * render target's device-pixel grid for crisp tiles; with integer tile pitch\n * the grid stays exact and adjacent chunks/layers cannot drift apart. Purely\n * visual - tile data, layer offsets, chunk revisions, and culling are\n * unchanged. Setting the current value is a no-op; an invalid value throws and\n * leaves the prior mode unchanged.\n *\n * @default PixelSnapMode.None\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const node of this._layerNodes) {\n node.pixelSnapMode = mode;\n }\n }\n\n /**\n * The layer render nodes - tile and image alike - in the map's combined\n * document order.\n */\n public get layerNodes(): ReadonlyArray<TileLayerNode | ImageLayerNode> {\n return this._layerNodes;\n }\n\n /**\n * Find the layer node rendering the named layer (tile or image; first match\n * in document order), or `undefined`.\n */\n public getLayerNode(name: string): TileLayerNode | ImageLayerNode | undefined {\n return this._layerNodes.find(node => node.layer.name === name);\n }\n\n /**\n * Rebuild the layer-node children from the map's current renderable layers.\n * Call after tile or image layers are structurally added to or removed from\n * the map.\n */\n public refreshLayers(): this {\n const previous = [...this._layerNodes];\n\n this.removeChildren();\n this._layerNodes.length = 0;\n\n for (const node of previous) {\n node.destroy();\n }\n\n this._buildLayerNodes();\n\n return this;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._map;\n\n if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(0, 0, pixelWidth, pixelHeight);\n } else if (this._layerNodes.length > 0) {\n aggregateChildLocalBounds(this._layerNodes, bounds);\n }\n\n return bounds;\n }\n\n public override destroy(): void {\n const layerNodes = [...this._layerNodes];\n\n this._layerNodes.length = 0;\n\n super.destroy();\n\n for (const node of layerNodes) {\n node.destroy();\n }\n }\n\n private _buildLayerNodes(): void {\n for (const layer of this._map.renderableLayers) {\n const node = layer instanceof ImageLayer ? new ImageLayerNode(layer) : new TileLayerNode(layer, { cullable: this._cullChunks });\n\n if (this._pixelSnapMode !== PixelSnapMode.None) {\n node.pixelSnapMode = this._pixelSnapMode;\n }\n\n this._layerNodes.push(node);\n this.addChild(node);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,cAAb,cAAiC,UAAU;CACzC,AAAiB;CACjB,AAAiB;CACjB,AAAiB,cAAqD,CAAC;CACvE,AAAQ,iBAAgC,cAAc;CAEtD,AAAO,YAAY,KAAc,SAA8B;EAC7D,MAAM;EAEN,KAAK,OAAO;EACZ,KAAK,cAAc,SAAS,YAAY;EAExC,KAAK,iBAAiB;EAEtB,IAAI,CAAC,KAAK,KAAK,SACb,KAAK,WAAW;CAEpB;;CAGA,IAAW,MAAe;EACxB,OAAO,KAAK;CACd;;;;;;;;;;;;;CAcA,IAAW,gBAA+B;EACxC,OAAO,KAAK;CACd;CAEA,IAAW,cAAc,MAAqB;EAC5C,IAAI,SAAS,KAAK,gBAChB;EAGF,oBAAoB,IAAI;EACxB,KAAK,iBAAiB;EAEtB,KAAK,MAAM,QAAQ,KAAK,aACtB,KAAK,gBAAgB;CAEzB;;;;;CAMA,IAAW,aAA4D;EACrE,OAAO,KAAK;CACd;;;;;CAMA,AAAO,aAAa,MAA0D;EAC5E,OAAO,KAAK,YAAY,MAAK,SAAQ,KAAK,MAAM,SAAS,IAAI;CAC/D;;;;;;CAOA,AAAO,gBAAsB;EAC3B,MAAM,WAAW,CAAC,GAAG,KAAK,WAAW;EAErC,KAAK,eAAe;EACpB,KAAK,YAAY,SAAS;EAE1B,KAAK,MAAM,QAAQ,UACjB,KAAK,QAAQ;EAGf,KAAK,iBAAiB;EAEtB,OAAO;CACT;;;;;;CAOA,AAAgB,iBAAoC;EAClD,MAAM,SAAS,KAAK;EAIpB,MAAM,EAAE,aAAa,eAAe,KAAK;EAEzC,IAAI,eAAe,UAAa,gBAAgB,QAC9C,OAAO,IAAI,GAAG,GAAG,YAAY,WAAW;OACnC,IAAI,KAAK,YAAY,SAAS,GACnC,0BAA0B,KAAK,aAAa,MAAM;EAGpD,OAAO;CACT;CAEA,AAAgB,UAAgB;EAC9B,MAAM,aAAa,CAAC,GAAG,KAAK,WAAW;EAEvC,KAAK,YAAY,SAAS;EAE1B,MAAM,QAAQ;EAEd,KAAK,MAAM,QAAQ,YACjB,KAAK,QAAQ;CAEjB;CAEA,AAAQ,mBAAyB;EAC/B,KAAK,MAAM,SAAS,KAAK,KAAK,kBAAkB;GAC9C,MAAM,OAAO,iBAAiB,aAAa,IAAI,eAAe,KAAK,IAAI,IAAI,cAAc,OAAO,EAAE,UAAU,KAAK,YAAY,CAAC;GAE9H,IAAI,KAAK,mBAAmB,cAAc,MACxC,KAAK,gBAAgB,KAAK;GAG5B,KAAK,YAAY,KAAK,IAAI;GAC1B,KAAK,SAAS,IAAI;EACpB;CACF;AACF"}
1
+ {"version":3,"file":"TileMapNode.js","names":[],"sources":["../../src/TileMapNode.ts"],"sourcesContent":["import type { ReadonlyRectangle } from '@codexo/exojs';\nimport { Container } from '@codexo/exojs';\nimport { PixelSnapMode } from '@codexo/exojs/renderer-sdk';\n\nimport { ImageLayer } from './ImageLayer';\nimport { ImageLayerNode } from './ImageLayerNode';\nimport { aggregateChildLocalBounds } from './nodeBounds';\nimport { assertPixelSnapMode } from './pixelSnap';\nimport { TileLayerNode } from './TileLayerNode';\nimport type { TileMap } from './TileMap';\n\n/**\n * Options for a {@link TileMapNode}.\n * @advanced\n */\nexport interface TileMapNodeOptions {\n /**\n * Whether the map's chunk nodes participate in per-chunk view culling.\n * Forwarded to every {@link TileLayerNode}. Defaults to `true`.\n */\n readonly cullable?: boolean;\n}\n\n/**\n * A convenience scene node that renders a whole {@link TileMap} as a\n * {@link Container} of one node per renderable layer - a {@link TileLayerNode}\n * per tile layer and an {@link ImageLayerNode} per image layer, interleaved\n * back-to-front by the map's combined document order\n * ({@link import('./TileMap').TileMap.renderableLayers}).\n *\n * `TileMapNode` owns **only** its layer nodes - never application actors. Use\n * it for the simple, non-interleaved case (no actors between layers); for\n * actor interleaving, place individual `TileLayerNode`s / `ImageLayerNode`s\n * into your own scene graph instead (see `TileMapView`).\n *\n * The node references - but never owns - the {@link TileMap}: destroying the\n * node frees its layer/chunk nodes and their cached GPU geometry, while the\n * `TileMap` data and Loader-owned textures survive (free them via\n * `TileMap.destroy()` / `Loader.destroy()` respectively).\n *\n * Layers added to or removed from the map after construction are reflected only\n * after {@link TileMapNode.refreshLayers}.\n *\n * @advanced\n */\nexport class TileMapNode extends Container {\n private readonly _map: TileMap;\n private readonly _cullChunks: boolean;\n private readonly _layerNodes: Array<TileLayerNode | ImageLayerNode> = [];\n private _pixelSnapMode: PixelSnapMode = PixelSnapMode.Geometry;\n\n public constructor(map: TileMap, options?: TileMapNodeOptions) {\n super();\n\n this._map = map;\n this._cullChunks = options?.cullable ?? true;\n\n this._buildLayerNodes();\n\n if (!this._map.bounded) {\n this.cullable = false;\n }\n }\n\n /** The runtime map this node renders. */\n public get map(): TileMap {\n return this._map;\n }\n\n /**\n * Render-only pixel-snap mode applied to every layer (and forwarded to every\n * chunk node, current and rebuilt). Snaps tile chunk origins to the active\n * render target's device-pixel grid for crisp tiles; with integer tile pitch\n * the grid stays exact and adjacent chunks/layers cannot drift apart. Purely\n * visual - tile data, layer offsets, chunk revisions, and culling are\n * unchanged. Setting the current value is a no-op; an invalid value throws and\n * leaves the prior mode unchanged.\n *\n * Defaults to `Geometry` because a tile grid is made of quads that share\n * their edges: left unsnapped, a boundary landing between two device pixels\n * is sampled across both, so the seams blur and shimmer as the view moves.\n * Set `None` to opt out.\n *\n * @default PixelSnapMode.Geometry\n * @stable\n */\n public get pixelSnapMode(): PixelSnapMode {\n return this._pixelSnapMode;\n }\n\n public set pixelSnapMode(mode: PixelSnapMode) {\n if (mode === this._pixelSnapMode) {\n return;\n }\n\n assertPixelSnapMode(mode);\n this._pixelSnapMode = mode;\n\n for (const node of this._layerNodes) {\n node.pixelSnapMode = mode;\n }\n }\n\n /**\n * The layer render nodes - tile and image alike - in the map's combined\n * document order.\n */\n public get layerNodes(): ReadonlyArray<TileLayerNode | ImageLayerNode> {\n return this._layerNodes;\n }\n\n /**\n * Find the layer node rendering the named layer (tile or image; first match\n * in document order), or `undefined`.\n */\n public getLayerNode(name: string): TileLayerNode | ImageLayerNode | undefined {\n return this._layerNodes.find(node => node.layer.name === name);\n }\n\n /**\n * Rebuild the layer-node children from the map's current renderable layers.\n * Call after tile or image layers are structurally added to or removed from\n * the map.\n */\n public refreshLayers(): this {\n const previous = [...this._layerNodes];\n\n this.removeChildren();\n this._layerNodes.length = 0;\n\n for (const node of previous) {\n node.destroy();\n }\n\n this._buildLayerNodes();\n\n return this;\n }\n\n /**\n * Recomputed lazily on read, so it writes `_localBounds` directly rather than\n * going through `setLocalBounds`: an invalidating write inside a getter\n * would re-dirty the node on every read.\n */\n public override getLocalBounds(): ReadonlyRectangle {\n const bounds = this._localBounds;\n\n // Reading the pixel extents directly (rather than gating on `bounded`)\n // is what narrows them to numbers - `bounded` is a plain boolean getter.\n const { pixelHeight, pixelWidth } = this._map;\n\n if (pixelWidth !== undefined && pixelHeight !== undefined) {\n bounds.set(0, 0, pixelWidth, pixelHeight);\n } else if (this._layerNodes.length > 0) {\n aggregateChildLocalBounds(this._layerNodes, bounds);\n }\n\n return bounds;\n }\n\n public override destroy(): void {\n const layerNodes = [...this._layerNodes];\n\n this._layerNodes.length = 0;\n\n super.destroy();\n\n for (const node of layerNodes) {\n node.destroy();\n }\n }\n\n private _buildLayerNodes(): void {\n for (const layer of this._map.renderableLayers) {\n const node = layer instanceof ImageLayer ? new ImageLayerNode(layer) : new TileLayerNode(layer, { cullable: this._cullChunks });\n\n // Unconditional: a node built after the map was set to `None` has to\n // inherit that too, not just a non-default mode.\n node.pixelSnapMode = this._pixelSnapMode;\n\n this._layerNodes.push(node);\n this.addChild(node);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,cAAb,cAAiC,UAAU;CACzC,AAAiB;CACjB,AAAiB;CACjB,AAAiB,cAAqD,CAAC;CACvE,AAAQ,iBAAgC,cAAc;CAEtD,AAAO,YAAY,KAAc,SAA8B;EAC7D,MAAM;EAEN,KAAK,OAAO;EACZ,KAAK,cAAc,SAAS,YAAY;EAExC,KAAK,iBAAiB;EAEtB,IAAI,CAAC,KAAK,KAAK,SACb,KAAK,WAAW;CAEpB;;CAGA,IAAW,MAAe;EACxB,OAAO,KAAK;CACd;;;;;;;;;;;;;;;;;;CAmBA,IAAW,gBAA+B;EACxC,OAAO,KAAK;CACd;CAEA,IAAW,cAAc,MAAqB;EAC5C,IAAI,SAAS,KAAK,gBAChB;EAGF,oBAAoB,IAAI;EACxB,KAAK,iBAAiB;EAEtB,KAAK,MAAM,QAAQ,KAAK,aACtB,KAAK,gBAAgB;CAEzB;;;;;CAMA,IAAW,aAA4D;EACrE,OAAO,KAAK;CACd;;;;;CAMA,AAAO,aAAa,MAA0D;EAC5E,OAAO,KAAK,YAAY,MAAK,SAAQ,KAAK,MAAM,SAAS,IAAI;CAC/D;;;;;;CAOA,AAAO,gBAAsB;EAC3B,MAAM,WAAW,CAAC,GAAG,KAAK,WAAW;EAErC,KAAK,eAAe;EACpB,KAAK,YAAY,SAAS;EAE1B,KAAK,MAAM,QAAQ,UACjB,KAAK,QAAQ;EAGf,KAAK,iBAAiB;EAEtB,OAAO;CACT;;;;;;CAOA,AAAgB,iBAAoC;EAClD,MAAM,SAAS,KAAK;EAIpB,MAAM,EAAE,aAAa,eAAe,KAAK;EAEzC,IAAI,eAAe,UAAa,gBAAgB,QAC9C,OAAO,IAAI,GAAG,GAAG,YAAY,WAAW;OACnC,IAAI,KAAK,YAAY,SAAS,GACnC,0BAA0B,KAAK,aAAa,MAAM;EAGpD,OAAO;CACT;CAEA,AAAgB,UAAgB;EAC9B,MAAM,aAAa,CAAC,GAAG,KAAK,WAAW;EAEvC,KAAK,YAAY,SAAS;EAE1B,MAAM,QAAQ;EAEd,KAAK,MAAM,QAAQ,YACjB,KAAK,QAAQ;CAEjB;CAEA,AAAQ,mBAAyB;EAC/B,KAAK,MAAM,SAAS,KAAK,KAAK,kBAAkB;GAC9C,MAAM,OAAO,iBAAiB,aAAa,IAAI,eAAe,KAAK,IAAI,IAAI,cAAc,OAAO,EAAE,UAAU,KAAK,YAAY,CAAC;GAI9H,KAAK,gBAAgB,KAAK;GAE1B,KAAK,YAAY,KAAK,IAAI;GAC1B,KAAK,SAAS,IAAI;EACpB;CACF;AACF"}
@@ -140,7 +140,12 @@ export declare class TileMapView {
140
140
  * current value is a no-op; an invalid value throws and leaves the prior mode
141
141
  * unchanged.
142
142
  *
143
- * @default PixelSnapMode.None
143
+ * Defaults to `Geometry` because a tile grid is made of quads that share
144
+ * their edges: left unsnapped, a boundary landing between two device pixels
145
+ * is sampled across both, so the seams blur and shimmer as the view moves.
146
+ * Set `None` to opt out.
147
+ *
148
+ * @default PixelSnapMode.Geometry
144
149
  * @stable
145
150
  */
146
151
  get pixelSnapMode(): PixelSnapMode;
@@ -1 +1 @@
1
- {"version":3,"file":"TileMapView.d.ts","sourceRoot":"","sources":["../../src/TileMapView.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAG3D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;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GAAG,WAAW;IAYtC,sDAAsD;IAC/C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIrC;;;;;;;;;;;;;;;;;;;OAmBG;IACI,aAAa,IAAI,IAAI;IA8F5B;;;;;;;OAOG;IACI,OAAO,IAAI,IAAI;IAsCtB,4EAA4E;IAC5E,OAAO,CAAC,WAAW;IAwCnB;;;;OAIG;IACH,OAAO,CAAC,gBAAgB;IAuCxB,4EAA4E;IAC5E,OAAO,CAAC,QAAQ;IAUhB,8EAA8E;IAC9E,OAAO,CAAC,cAAc;IAatB;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAmB1B,+EAA+E;IAC/E,OAAO,CAAC,cAAc;IAItB,2EAA2E;IAC3E,OAAO,CAAC,eAAe;IAevB,6EAA6E;IAC7E,OAAO,CAAC,gBAAgB;IAkBxB,8EAA8E;IAC9E,OAAO,CAAC,iBAAiB;CAc1B"}
@@ -71,7 +71,7 @@ var TileMapView = class {
71
71
  /** Image layer id → its canonical image layer node. */
72
72
  _imageLayerNodeById = /* @__PURE__ */ new Map();
73
73
  _destroyed = false;
74
- _pixelSnapMode = PixelSnapMode.None;
74
+ _pixelSnapMode = PixelSnapMode.Geometry;
75
75
  /**
76
76
  * @param map The runtime map to compose. Referenced, never owned.
77
77
  * @param options Band definitions and culling.
@@ -120,7 +120,12 @@ var TileMapView = class {
120
120
  * current value is a no-op; an invalid value throws and leaves the prior mode
121
121
  * unchanged.
122
122
  *
123
- * @default PixelSnapMode.None
123
+ * Defaults to `Geometry` because a tile grid is made of quads that share
124
+ * their edges: left unsnapped, a boundary landing between two device pixels
125
+ * is sampled across both, so the seams blur and shimmer as the view moves.
126
+ * Set `None` to opt out.
127
+ *
128
+ * @default PixelSnapMode.Geometry
124
129
  * @stable
125
130
  */
126
131
  get pixelSnapMode() {
@@ -223,7 +228,7 @@ var TileMapView = class {
223
228
  let node = this._layerNodeById.get(layer.id);
224
229
  if (!node) {
225
230
  node = new TileLayerNode(layer, { cullable: this._cullable });
226
- if (this._pixelSnapMode !== PixelSnapMode.None) node.pixelSnapMode = this._pixelSnapMode;
231
+ node.pixelSnapMode = this._pixelSnapMode;
227
232
  this._layerNodeById.set(layer.id, node);
228
233
  this._assignNewNode(node, layer);
229
234
  }
@@ -236,7 +241,7 @@ var TileMapView = class {
236
241
  let node = this._imageLayerNodes.find((candidate) => candidate.layer === imageLayer);
237
242
  if (!node) {
238
243
  node = new ImageLayerNode(imageLayer);
239
- if (this._pixelSnapMode !== PixelSnapMode.None) node.pixelSnapMode = this._pixelSnapMode;
244
+ node.pixelSnapMode = this._pixelSnapMode;
240
245
  this._imageLayerNodeById.set(imageLayer.id, node);
241
246
  this._assignNewNode(node, imageLayer);
242
247
  }