@codexo/exojs-tilemap 0.17.0 → 0.19.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 (87) hide show
  1. package/README.md +84 -109
  2. package/dist/esm/ChunkStreamer.d.ts.map +1 -1
  3. package/dist/esm/ChunkStreamer.js +28 -6
  4. package/dist/esm/ChunkStreamer.js.map +1 -1
  5. package/dist/esm/ImageLayer.d.ts +1 -1
  6. package/dist/esm/ImageLayer.d.ts.map +1 -1
  7. package/dist/esm/ImageLayerNode.d.ts +5 -1
  8. package/dist/esm/ImageLayerNode.d.ts.map +1 -1
  9. package/dist/esm/ImageLayerNode.js +7 -2
  10. package/dist/esm/ImageLayerNode.js.map +1 -1
  11. package/dist/esm/MapObject.d.ts +2 -2
  12. package/dist/esm/MapObject.d.ts.map +1 -1
  13. package/dist/esm/MapObject.js.map +1 -1
  14. package/dist/esm/MapObjectSpawner.d.ts.map +1 -1
  15. package/dist/esm/MapSpawnSession.d.ts.map +1 -1
  16. package/dist/esm/MapWorld.d.ts +8 -8
  17. package/dist/esm/MapWorld.d.ts.map +1 -1
  18. package/dist/esm/MapWorldRuntime.d.ts.map +1 -1
  19. package/dist/esm/ObjectLayer.d.ts +26 -10
  20. package/dist/esm/ObjectLayer.d.ts.map +1 -1
  21. package/dist/esm/ObjectLayer.js +28 -0
  22. package/dist/esm/ObjectLayer.js.map +1 -1
  23. package/dist/esm/SampledChunkSource.d.ts.map +1 -1
  24. package/dist/esm/TileAnimator.d.ts.map +1 -1
  25. package/dist/esm/TileChunk.d.ts.map +1 -1
  26. package/dist/esm/TileChunkNode.js +47 -10
  27. package/dist/esm/TileChunkNode.js.map +1 -1
  28. package/dist/esm/TileLayer.d.ts +11 -2
  29. package/dist/esm/TileLayer.d.ts.map +1 -1
  30. package/dist/esm/TileLayer.js +20 -10
  31. package/dist/esm/TileLayer.js.map +1 -1
  32. package/dist/esm/TileLayerNode.d.ts +12 -5
  33. package/dist/esm/TileLayerNode.d.ts.map +1 -1
  34. package/dist/esm/TileLayerNode.js +44 -24
  35. package/dist/esm/TileLayerNode.js.map +1 -1
  36. package/dist/esm/TileMap.d.ts +6 -2
  37. package/dist/esm/TileMap.d.ts.map +1 -1
  38. package/dist/esm/TileMap.js +13 -12
  39. package/dist/esm/TileMap.js.map +1 -1
  40. package/dist/esm/TileMapBand.d.ts.map +1 -1
  41. package/dist/esm/TileMapNode.d.ts +6 -1
  42. package/dist/esm/TileMapNode.d.ts.map +1 -1
  43. package/dist/esm/TileMapNode.js +12 -4
  44. package/dist/esm/TileMapNode.js.map +1 -1
  45. package/dist/esm/TileMapView.d.ts +6 -1
  46. package/dist/esm/TileMapView.d.ts.map +1 -1
  47. package/dist/esm/TileMapView.js +9 -4
  48. package/dist/esm/TileMapView.js.map +1 -1
  49. package/dist/esm/TileProjection.d.ts +59 -0
  50. package/dist/esm/TileProjection.d.ts.map +1 -0
  51. package/dist/esm/TileProjection.js +106 -0
  52. package/dist/esm/TileProjection.js.map +1 -0
  53. package/dist/esm/TileSet.d.ts.map +1 -1
  54. package/dist/esm/WangSet.d.ts.map +1 -1
  55. package/dist/esm/WorkerSampledChunkSource.d.ts +4 -7
  56. package/dist/esm/WorkerSampledChunkSource.d.ts.map +1 -1
  57. package/dist/esm/WorkerSampledChunkSource.js +12 -18
  58. package/dist/esm/WorkerSampledChunkSource.js.map +1 -1
  59. package/dist/esm/autoTile.d.ts.map +1 -1
  60. package/dist/esm/chunkGeometry.js +78 -50
  61. package/dist/esm/chunkGeometry.js.map +1 -1
  62. package/dist/esm/index.js +2 -1
  63. package/dist/esm/projectObject.d.ts +4 -0
  64. package/dist/esm/projectObject.d.ts.map +1 -0
  65. package/dist/esm/projectObject.js +87 -0
  66. package/dist/esm/projectObject.js.map +1 -0
  67. package/dist/esm/public.d.ts +1 -0
  68. package/dist/esm/public.d.ts.map +1 -1
  69. package/dist/esm/tileCollision.d.ts +2 -2
  70. package/dist/esm/tileCollision.d.ts.map +1 -1
  71. package/dist/esm/tileCollision.js +48 -16
  72. package/dist/esm/tileCollision.js.map +1 -1
  73. package/dist/esm/tilemapSerializers.js +1 -1
  74. package/dist/esm/tilemapSerializers.js.map +1 -1
  75. package/dist/esm/types.d.ts +3 -3
  76. package/dist/esm/types.d.ts.map +1 -1
  77. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js +8 -7
  78. package/dist/esm/webgl2/WebGl2TileChunkRenderer.js.map +1 -1
  79. package/dist/esm/webgl2/shaders/tile-chunk.frag.js +1 -1
  80. package/dist/esm/webgl2/shaders/tile-chunk.frag.js.map +1 -1
  81. package/dist/esm/webgl2/shaders/tile-chunk.vert.js +1 -1
  82. package/dist/esm/webgl2/shaders/tile-chunk.vert.js.map +1 -1
  83. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js +67 -31
  84. package/dist/esm/webgpu/WebGpuTileChunkRenderer.js.map +1 -1
  85. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js +1 -1
  86. package/dist/esm/webgpu/shaders/tile-chunk.wgsl.js.map +1 -1
  87. package/package.json +4 -4
@@ -0,0 +1,59 @@
1
+ import type { TileMapObject } from './ObjectLayer';
2
+ /** Immutable grid geometry shared by a map and its independently usable layers. */
3
+ export interface TileProjectionOptions {
4
+ /** Orthogonal is the default. Isometric cells are diamonds with the given pixel dimensions. */
5
+ readonly orientation?: 'orthogonal' | 'isometric';
6
+ readonly tileWidth: number;
7
+ readonly tileHeight: number;
8
+ /** Display position of grid vertex (0, 0). Defaults to zero. */
9
+ readonly originX?: number;
10
+ readonly originY?: number;
11
+ }
12
+ /**
13
+ * Converts between grid vertices, display pixels and unprojected logical pixels.
14
+ * Isometric logical cells are squares of side `tileHeight`; orthogonal logical
15
+ * coordinates are display coordinates before the origin translation.
16
+ */
17
+ export declare class TileProjection {
18
+ readonly orientation: 'orthogonal' | 'isometric';
19
+ readonly tileWidth: number;
20
+ readonly tileHeight: number;
21
+ readonly originX: number;
22
+ readonly originY: number;
23
+ constructor(options: TileProjectionOptions);
24
+ /** Width of a cell in the unprojected simulation space. */
25
+ get logicalTileWidth(): number;
26
+ get logicalTileHeight(): number;
27
+ /** Maps a grid vertex, including fractional coordinates, to display pixels. */
28
+ tileToPixel(tx: number, ty: number): {
29
+ x: number;
30
+ y: number;
31
+ };
32
+ /** Picks the half-open cell containing a display point; negative cells are valid. */
33
+ pixelToTile(x: number, y: number): {
34
+ tx: number;
35
+ ty: number;
36
+ };
37
+ /** Projects a logical position; layer offsets and scene transforms are separate. */
38
+ logicalToPixel(x: number, y: number): {
39
+ x: number;
40
+ y: number;
41
+ };
42
+ /** Inverts display projection without quantizing to a cell. */
43
+ pixelToLogical(x: number, y: number): {
44
+ x: number;
45
+ y: number;
46
+ };
47
+ /** Display AABB of a cell region, excluding artwork overhang and layer offsets. */
48
+ getBounds(tx: number, ty: number, width: number, height: number): {
49
+ x: number;
50
+ y: number;
51
+ width: number;
52
+ height: number;
53
+ };
54
+ /** Projects logical object geometry; image and text dimensions stay in display pixels. */
55
+ projectObject(object: TileMapObject): TileMapObject;
56
+ /** Inverts object geometry into logical space; affine ellipses remain exact. */
57
+ unprojectObject(object: TileMapObject): TileMapObject;
58
+ }
59
+ //# sourceMappingURL=TileProjection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TileProjection.d.ts","sourceRoot":"","sources":["../../src/TileProjection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAInD,mFAAmF;AACnF,MAAM,WAAW,qBAAqB;IACpC,+FAA+F;IAC/F,QAAQ,CAAC,WAAW,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;IAClD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,gEAAgE;IAChE,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAA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AA;KAAE,CAW/H;IAED,0FAA0F;IACnF,aAAa,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAQzD;IAED,gFAAgF;IACzE,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,CAQ3D;CACF"}
@@ -0,0 +1,106 @@
1
+ import { validatePositiveInteger } from "./types.js";
2
+ import { projectObject } from "./projectObject.js";
3
+
4
+ //#region src/TileProjection.ts
5
+ /**
6
+ * Converts between grid vertices, display pixels and unprojected logical pixels.
7
+ * Isometric logical cells are squares of side `tileHeight`; orthogonal logical
8
+ * coordinates are display coordinates before the origin translation.
9
+ */
10
+ var TileProjection = class {
11
+ orientation;
12
+ tileWidth;
13
+ tileHeight;
14
+ originX;
15
+ originY;
16
+ constructor(options) {
17
+ validatePositiveInteger(options.tileWidth, "projection.tileWidth");
18
+ validatePositiveInteger(options.tileHeight, "projection.tileHeight");
19
+ this.orientation = options.orientation ?? "orthogonal";
20
+ this.tileWidth = options.tileWidth;
21
+ this.tileHeight = options.tileHeight;
22
+ this.originX = options.originX ?? 0;
23
+ this.originY = options.originY ?? 0;
24
+ if (!Number.isFinite(this.originX) || !Number.isFinite(this.originY)) throw new Error("TileProjection origin must be finite.");
25
+ }
26
+ /** Width of a cell in the unprojected simulation space. */
27
+ get logicalTileWidth() {
28
+ return this.orientation === "isometric" ? this.tileHeight : this.tileWidth;
29
+ }
30
+ get logicalTileHeight() {
31
+ return this.tileHeight;
32
+ }
33
+ /** Maps a grid vertex, including fractional coordinates, to display pixels. */
34
+ tileToPixel(tx, ty) {
35
+ return this.orientation === "isometric" ? {
36
+ x: this.originX + (tx - ty) * this.tileWidth / 2,
37
+ y: this.originY + (tx + ty) * this.tileHeight / 2
38
+ } : {
39
+ x: this.originX + tx * this.tileWidth,
40
+ y: this.originY + ty * this.tileHeight
41
+ };
42
+ }
43
+ /** Picks the half-open cell containing a display point; negative cells are valid. */
44
+ pixelToTile(x, y) {
45
+ const logical = this.pixelToLogical(x, y);
46
+ return {
47
+ tx: Math.floor(logical.x / this.logicalTileWidth),
48
+ ty: Math.floor(logical.y / this.logicalTileHeight)
49
+ };
50
+ }
51
+ /** Projects a logical position; layer offsets and scene transforms are separate. */
52
+ logicalToPixel(x, y) {
53
+ return this.tileToPixel(x / this.logicalTileWidth, y / this.logicalTileHeight);
54
+ }
55
+ /** Inverts display projection without quantizing to a cell. */
56
+ pixelToLogical(x, y) {
57
+ const dx = x - this.originX;
58
+ const dy = y - this.originY;
59
+ return this.orientation === "isometric" ? {
60
+ x: dy + dx * this.tileHeight / this.tileWidth,
61
+ y: dy - dx * this.tileHeight / this.tileWidth
62
+ } : {
63
+ x: dx,
64
+ y: dy
65
+ };
66
+ }
67
+ /** Display AABB of a cell region, excluding artwork overhang and layer offsets. */
68
+ getBounds(tx, ty, width, height) {
69
+ const top = this.tileToPixel(tx, ty);
70
+ if (this.orientation === "orthogonal") return {
71
+ ...top,
72
+ width: width * this.tileWidth,
73
+ height: height * this.tileHeight
74
+ };
75
+ return {
76
+ x: top.x - height * this.tileWidth / 2,
77
+ y: top.y,
78
+ width: (width + height) * this.tileWidth / 2,
79
+ height: (width + height) * this.tileHeight / 2
80
+ };
81
+ }
82
+ /** Projects logical object geometry; image and text dimensions stay in display pixels. */
83
+ projectObject(object) {
84
+ if (this.orientation === "orthogonal") return object.kind === "tile" ? projectObject(object, 1, 0, 0, 1, this.originX, this.originY) : {
85
+ ...object,
86
+ x: object.x + this.originX,
87
+ y: object.y + this.originY
88
+ };
89
+ const ratio = this.tileWidth / (2 * this.tileHeight);
90
+ return projectObject(object, ratio, .5, -ratio, .5, this.originX, this.originY);
91
+ }
92
+ /** Inverts object geometry into logical space; affine ellipses remain exact. */
93
+ unprojectObject(object) {
94
+ if (this.orientation === "orthogonal") return object.kind === "tile" ? projectObject(object, 1, 0, 0, 1, -this.originX, -this.originY) : {
95
+ ...object,
96
+ x: object.x - this.originX,
97
+ y: object.y - this.originY
98
+ };
99
+ const ratio = this.tileHeight / this.tileWidth;
100
+ return projectObject(object, ratio, -ratio, 1, 1, -this.originY - this.originX * ratio, -this.originY + this.originX * ratio);
101
+ }
102
+ };
103
+
104
+ //#endregion
105
+ export { TileProjection };
106
+ //# sourceMappingURL=TileProjection.js.map
@@ -0,0 +1 @@
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,gBAAgB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AG,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"}
@@ -82,13 +82,10 @@ export interface WorkerSampledChunkSourceOptions {
82
82
  * lifecycle hook, so nothing ties the two together automatically. Call it
83
83
  * yourself alongside your own `ChunkStreamer.destroy()` call.
84
84
  *
85
- * Implementation note: `workerSource` is Blob-URL'd into a real `Worker`
86
- * (`new Blob([workerSource])` → `URL.createObjectURL` → `new Worker(url)`) -
87
- * the same technique {@link import('@codexo/exojs').WorkletEffect} already
88
- * uses for AudioWorklet processors. This is bundler-agnostic (no special
89
- * config needed in Vite/webpack/etc.) but requires a Content-Security-Policy
90
- * that permits `blob:` in `worker-src` (or `script-src` as a fallback) if
91
- * your deployment sets one.
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.
92
89
  * @advanced
93
90
  */
94
91
  export declare const createWorkerSampledChunkSource: (layer: TileLayer, options: WorkerSampledChunkSourceOptions) => ChunkSource & {
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerSampledChunkSource.d.ts","sourceRoot":"","sources":["../../src/WorkerSampledChunkSource.ts"],"names":[],"mappings":"AAAA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,8BAA8B,GAAI,OAAO,SAAS,EAAE,SAAS,+BAA+B,KAAG,WAAW,GAAG;IAAE,OAAO,IAAI,IAAI,CAAA;CA8F1I,CAAC"}
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"}
@@ -1,4 +1,5 @@
1
1
  import { packTile } from "./types.js";
2
+ import { InlineWorker } from "@codexo/exojs";
2
3
 
3
4
  //#region src/WorkerSampledChunkSource.ts
4
5
  const isWorkerErrorMessage = (message) => "error" in message;
@@ -21,25 +22,19 @@ const isWorkerErrorMessage = (message) => "error" in message;
21
22
  * lifecycle hook, so nothing ties the two together automatically. Call it
22
23
  * yourself alongside your own `ChunkStreamer.destroy()` call.
23
24
  *
24
- * Implementation note: `workerSource` is Blob-URL'd into a real `Worker`
25
- * (`new Blob([workerSource])` → `URL.createObjectURL` → `new Worker(url)`) -
26
- * the same technique {@link import('@codexo/exojs').WorkletEffect} already
27
- * uses for AudioWorklet processors. This is bundler-agnostic (no special
28
- * config needed in Vite/webpack/etc.) but requires a Content-Security-Policy
29
- * that permits `blob:` in `worker-src` (or `script-src` as a fallback) if
30
- * your deployment sets one.
25
+ * `workerSource` runs through {@link import('@codexo/exojs').InlineWorker},
26
+ * so it needs no bundler support of its own but does need a
27
+ * Content-Security-Policy that permits `blob:` in `worker-src` if your
28
+ * deployment sets one; the constructor names that cause when it is refused.
31
29
  * @advanced
32
30
  */
33
31
  const createWorkerSampledChunkSource = (layer, options) => {
34
32
  const mapValueToTile = options.mapValueToTile.bind(options);
35
- const blob = new Blob([options.workerSource], { type: "application/javascript" });
36
- const url = URL.createObjectURL(blob);
37
- const worker = new Worker(url);
38
- URL.revokeObjectURL(url);
39
- if (options.initMessage !== void 0) worker.postMessage(options.initMessage);
33
+ const inline = new InlineWorker(options.workerSource, { name: "exojs-tilemap-chunk-sampler" });
34
+ const worker = inline.worker;
35
+ if (options.initMessage !== void 0) inline.postMessage(options.initMessage);
40
36
  let requestCounter = 0;
41
37
  const pending = /* @__PURE__ */ new Map();
42
- let destroyed = false;
43
38
  const composePayload = (values, request) => {
44
39
  const { cx, cy, chunkWidth, chunkHeight } = request;
45
40
  const startTx = cx * chunkWidth;
@@ -80,7 +75,7 @@ const createWorkerSampledChunkSource = (layer, options) => {
80
75
  };
81
76
  return {
82
77
  getChunk(cx, cy) {
83
- if (destroyed) return Promise.reject(/* @__PURE__ */ new Error("WorkerSampledChunkSource: getChunk() called after destroy()."));
78
+ if (inline.destroyed) return Promise.reject(/* @__PURE__ */ new Error("WorkerSampledChunkSource: getChunk() called after destroy()."));
84
79
  const chunkWidth = layer.chunkWidth;
85
80
  const chunkHeight = layer.chunkHeight;
86
81
  const requestId = ++requestCounter;
@@ -100,16 +95,15 @@ const createWorkerSampledChunkSource = (layer, options) => {
100
95
  chunkWidth,
101
96
  chunkHeight
102
97
  };
103
- worker.postMessage(request);
98
+ inline.postMessage(request);
104
99
  });
105
100
  },
106
101
  destroy() {
107
- if (destroyed) return;
108
- destroyed = true;
102
+ if (inline.destroyed) return;
109
103
  const error = /* @__PURE__ */ new Error("WorkerSampledChunkSource destroyed.");
110
104
  for (const entry of pending.values()) entry.reject(error);
111
105
  pending.clear();
112
- worker.terminate();
106
+ inline.destroy();
113
107
  }
114
108
  };
115
109
  };
@@ -1 +1 @@
1
- {"version":3,"file":"WorkerSampledChunkSource.js","names":[],"sources":["../../src/WorkerSampledChunkSource.ts"],"sourcesContent":["import type { ChunkPayload, ChunkSource } from './ChunkSource';\nimport type { TileLayer } from './TileLayer';\nimport type { ResolvedTile } from './types';\nimport { packTile } from './types';\n\n/**\n * Options for {@link createWorkerSampledChunkSource}.\n * @advanced\n */\nexport interface WorkerSampledChunkSourceOptions {\n /**\n * Complete worker script source as a single self-contained string, Blob-URL'd\n * into a real `Worker` at construction time - the same technique\n * {@link import('@codexo/exojs').WorkletEffect} uses for AudioWorklet\n * processors. No separate worker asset is fetched and no bundler-specific\n * worker-import syntax is involved.\n *\n * Producing that string by hand-writing JavaScript into a template literal\n * works but gives up type checking, linting and shared code. Prefer a build\n * step that bundles a real module into a string: this repository's own\n * examples are authored as `*.worker.ts` and imported through a `?worker`\n * query, which is why they can `import` the sampling functions the main\n * thread uses instead of restating them.\n *\n * Must implement this request/response protocol:\n * - Request (received via `self.onmessage`):\n * `{ requestId: number; cx: number; cy: number; chunkWidth: number; chunkHeight: number }`.\n * - Response, success (send via `self.postMessage`, transferring the\n * buffer for a zero-copy handoff - `postMessage(response, [response.values.buffer])`):\n * `{ requestId: number; values: Float64Array }`, `values.length ===\n * chunkWidth * chunkHeight`, row-major (`localTy * chunkWidth + localTx`),\n * one sampled value per tile in the requested chunk. Compute each tile's\n * absolute coordinate as `cx * chunkWidth + localTx` /\n * `cy * chunkHeight + localTy`.\n * - Response, error (one request failed without crashing the worker):\n * `{ requestId: number; error: string }`.\n *\n * Your worker must reply to every request with exactly one success or\n * error message bearing the same `requestId`. A request left unanswered\n * leaves that chunk permanently unfetched - there is no timeout - since\n * `ChunkStreamer` tracks it as still in flight and never retries it.\n */\n workerSource: string;\n /**\n * Posted to the worker once, before any chunk request, when present.\n *\n * The transport for whatever the sampler needs to know that is not per-chunk\n * - a seed, a feature size, a cost knob. Without it those values would have\n * to be interpolated into {@link WorkerSampledChunkSourceOptions.workerSource}\n * as literals, which turns every parameter change into a source rebuild and a\n * new `Worker`.\n *\n * `postMessage` delivery is ordered, so the worker is guaranteed to see this\n * before the first request. Distinguish it from a chunk request by its own\n * shape; requests carry a `requestId`.\n */\n initMessage?: unknown;\n /**\n * Convert a sampled value (and its absolute tile coordinate) into a\n * resolved tile, or `null` for an empty cell. Always runs on the main\n * thread - a `ResolvedTile` references a `TileSet`/`Texture`, neither of\n * which can cross a `postMessage` boundary. Must be pure and\n * deterministic, same requirement as\n * {@link import('./SampledChunkSource').SampledChunkSourceOptions.mapValueToTile}.\n */\n mapValueToTile(value: number, tx: number, ty: number): ResolvedTile | null;\n}\n\ninterface WorkerRequestMessage {\n readonly requestId: number;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\ninterface WorkerSuccessMessage {\n readonly requestId: number;\n readonly values: Float64Array;\n}\n\ninterface WorkerErrorMessage {\n readonly requestId: number;\n readonly error: string;\n}\n\ntype WorkerResponseMessage = WorkerSuccessMessage | WorkerErrorMessage;\n\nconst isWorkerErrorMessage = (message: WorkerResponseMessage): message is WorkerErrorMessage => 'error' in message;\n\ninterface PendingRequest {\n readonly resolve: (payload: ChunkPayload | null) => void;\n readonly reject: (error: Error) => void;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\n/**\n * Build a {@link import('./ChunkStreamer').ChunkStreamer}-ready\n * {@link ChunkSource} that samples off the main thread via a Web Worker -\n * the async counterpart to\n * {@link import('./SampledChunkSource').createSampledChunkSource}, for\n * sampling functions expensive enough to want off-thread execution.\n *\n * Unlike the synchronous provider, sampling logic cannot be passed as a\n * live function - functions cannot cross a `postMessage` boundary. Instead\n * {@link WorkerSampledChunkSourceOptions.workerSource} is a self-contained\n * worker script string; see its documentation for the protocol.\n *\n * The returned value's `destroy()` MUST be called when done with it - the\n * underlying `Worker` is a real resource that leaks otherwise.\n * {@link import('./ChunkStreamer').ChunkStreamer} does not own the source it\n * is given and never calls this for you: `ChunkSource` itself has no\n * lifecycle hook, so nothing ties the two together automatically. Call it\n * yourself alongside your own `ChunkStreamer.destroy()` call.\n *\n * Implementation note: `workerSource` is Blob-URL'd into a real `Worker`\n * (`new Blob([workerSource])` → `URL.createObjectURL` → `new Worker(url)`) -\n * the same technique {@link import('@codexo/exojs').WorkletEffect} already\n * uses for AudioWorklet processors. This is bundler-agnostic (no special\n * config needed in Vite/webpack/etc.) but requires a Content-Security-Policy\n * that permits `blob:` in `worker-src` (or `script-src` as a fallback) if\n * your deployment sets one.\n * @advanced\n */\nexport const createWorkerSampledChunkSource = (layer: TileLayer, options: WorkerSampledChunkSourceOptions): ChunkSource & { destroy(): void } => {\n const mapValueToTile = options.mapValueToTile.bind(options);\n\n const blob = new Blob([options.workerSource], { type: 'application/javascript' });\n const url = URL.createObjectURL(blob);\n const worker = new Worker(url);\n URL.revokeObjectURL(url);\n\n if (options.initMessage !== undefined) {\n worker.postMessage(options.initMessage);\n }\n\n let requestCounter = 0;\n const pending = new Map<number, PendingRequest>();\n let destroyed = false;\n\n const composePayload = (values: Float64Array, request: PendingRequest): ChunkPayload | null => {\n const { cx, cy, chunkWidth, chunkHeight } = request;\n const startTx = cx * chunkWidth;\n const startTy = cy * chunkHeight;\n\n let out: Uint32Array | null = null;\n for (let ty = startTy; ty < startTy + chunkHeight; ty++) {\n for (let tx = startTx; tx < startTx + chunkWidth; tx++) {\n // Bounded-layer edge chunks may be smaller than a full chunk - same\n // clamp createSampledChunkSource applies, computed here (not asked\n // of the worker) since only this side knows the layer's bounds.\n if (layer.width !== undefined && layer.height !== undefined && (tx >= layer.width || ty >= layer.height)) continue;\n\n const localIndex = (ty - startTy) * chunkWidth + (tx - startTx);\n const value = values[localIndex];\n if (value === undefined) continue; // defensive: malformed/short values array\n const resolved = mapValueToTile(value, tx, ty);\n if (!resolved) continue;\n\n out ??= new Uint32Array(chunkWidth * chunkHeight);\n const tilesetIndex = layer.tilesets.indexOf(resolved.tileset);\n out[localIndex] = packTile(tilesetIndex, resolved.localTileId, resolved.transform);\n }\n }\n\n return out === null ? null : { width: chunkWidth, height: chunkHeight, tiles: out };\n };\n\n worker.onmessage = (event: MessageEvent<WorkerResponseMessage>): void => {\n const message = event.data;\n const entry = pending.get(message.requestId);\n if (!entry) return; // stale/unknown requestId (e.g. arrived after destroy())\n pending.delete(message.requestId);\n\n if (isWorkerErrorMessage(message)) {\n entry.reject(new Error(message.error));\n return;\n }\n\n entry.resolve(composePayload(message.values, entry));\n };\n\n worker.onerror = (event: ErrorEvent): void => {\n const error = new Error(`WorkerSampledChunkSource worker error: ${event.message}`);\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n };\n\n return {\n getChunk(cx: number, cy: number): Promise<ChunkPayload | null> {\n if (destroyed) {\n return Promise.reject(new Error('WorkerSampledChunkSource: getChunk() called after destroy().'));\n }\n\n const chunkWidth = layer.chunkWidth;\n const chunkHeight = layer.chunkHeight;\n const requestId = ++requestCounter;\n\n return new Promise<ChunkPayload | null>((resolve, reject) => {\n pending.set(requestId, { resolve, reject, cx, cy, chunkWidth, chunkHeight });\n const request: WorkerRequestMessage = { requestId, cx, cy, chunkWidth, chunkHeight };\n worker.postMessage(request);\n });\n },\n\n destroy(): void {\n if (destroyed) return;\n destroyed = true;\n const error = new Error('WorkerSampledChunkSource destroyed.');\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n worker.terminate();\n },\n };\n};\n"],"mappings":";;;AAwFA,MAAM,wBAAwB,YAAkE,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuC3G,MAAa,kCAAkC,OAAkB,YAAgF;CAC/I,MAAM,iBAAiB,QAAQ,eAAe,KAAK,OAAO;CAE1D,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ,YAAY,GAAG,EAAE,MAAM,yBAAyB,CAAC;CAChF,MAAM,MAAM,IAAI,gBAAgB,IAAI;CACpC,MAAM,SAAS,IAAI,OAAO,GAAG;CAC7B,IAAI,gBAAgB,GAAG;CAEvB,IAAI,QAAQ,gBAAgB,QAC1B,OAAO,YAAY,QAAQ,WAAW;CAGxC,IAAI,iBAAiB;CACrB,MAAM,0BAAU,IAAI,IAA4B;CAChD,IAAI,YAAY;CAEhB,MAAM,kBAAkB,QAAsB,YAAiD;EAC7F,MAAM,EAAE,IAAI,IAAI,YAAY,gBAAgB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aAAa,MAAM;GACzB,MAAM,cAAc,MAAM;GAC1B,MAAM,YAAY,EAAE;GAEpB,OAAO,IAAI,SAA8B,SAAS,WAAW;IAC3D,QAAQ,IAAI,WAAW;KAAE;KAAS;KAAQ;KAAI;KAAI;KAAY;IAAY,CAAC;IAC3E,MAAM,UAAgC;KAAE;KAAW;KAAI;KAAI;KAAY;IAAY;IACnF,OAAO,YAAY,OAAO;GAC5B,CAAC;EACH;EAEA,UAAgB;GACd,IAAI,WAAW;GACf,YAAY;GACZ,MAAM,wBAAQ,IAAI,MAAM,qCAAqC;GAC7D,KAAK,MAAM,SAAS,QAAQ,OAAO,GACjC,MAAM,OAAO,KAAK;GAEpB,QAAQ,MAAM;GACd,OAAO,UAAU;EACnB;CACF;AACF"}
1
+ {"version":3,"file":"WorkerSampledChunkSource.js","names":[],"sources":["../../src/WorkerSampledChunkSource.ts"],"sourcesContent":["import { InlineWorker } from '@codexo/exojs';\n\nimport type { ChunkPayload, ChunkSource } from './ChunkSource';\nimport type { TileLayer } from './TileLayer';\nimport type { ResolvedTile } from './types';\nimport { packTile } from './types';\n\n/**\n * Options for {@link createWorkerSampledChunkSource}.\n * @advanced\n */\nexport interface WorkerSampledChunkSourceOptions {\n /**\n * Complete worker script source as a single self-contained string, Blob-URL'd\n * into a real `Worker` at construction time - the same technique\n * {@link import('@codexo/exojs').WorkletEffect} uses for AudioWorklet\n * processors. No separate worker asset is fetched and no bundler-specific\n * worker-import syntax is involved.\n *\n * Producing that string by hand-writing JavaScript into a template literal\n * works but gives up type checking, linting and shared code. Prefer a build\n * step that bundles a real module into a string: this repository's own\n * examples are authored as `*.worker.ts` and imported through a `?worker`\n * query, which is why they can `import` the sampling functions the main\n * thread uses instead of restating them.\n *\n * Must implement this request/response protocol:\n * - Request (received via `self.onmessage`):\n * `{ requestId: number; cx: number; cy: number; chunkWidth: number; chunkHeight: number }`.\n * - Response, success (send via `self.postMessage`, transferring the\n * buffer for a zero-copy handoff - `postMessage(response, [response.values.buffer])`):\n * `{ requestId: number; values: Float64Array }`, `values.length ===\n * chunkWidth * chunkHeight`, row-major (`localTy * chunkWidth + localTx`),\n * one sampled value per tile in the requested chunk. Compute each tile's\n * absolute coordinate as `cx * chunkWidth + localTx` /\n * `cy * chunkHeight + localTy`.\n * - Response, error (one request failed without crashing the worker):\n * `{ requestId: number; error: string }`.\n *\n * Your worker must reply to every request with exactly one success or\n * error message bearing the same `requestId`. A request left unanswered\n * leaves that chunk permanently unfetched - there is no timeout - since\n * `ChunkStreamer` tracks it as still in flight and never retries it.\n */\n workerSource: string;\n /**\n * Posted to the worker once, before any chunk request, when present.\n *\n * The transport for whatever the sampler needs to know that is not per-chunk\n * - a seed, a feature size, a cost knob. Without it those values would have\n * to be interpolated into {@link WorkerSampledChunkSourceOptions.workerSource}\n * as literals, which turns every parameter change into a source rebuild and a\n * new `Worker`.\n *\n * `postMessage` delivery is ordered, so the worker is guaranteed to see this\n * before the first request. Distinguish it from a chunk request by its own\n * shape; requests carry a `requestId`.\n */\n initMessage?: unknown;\n /**\n * Convert a sampled value (and its absolute tile coordinate) into a\n * resolved tile, or `null` for an empty cell. Always runs on the main\n * thread - a `ResolvedTile` references a `TileSet`/`Texture`, neither of\n * which can cross a `postMessage` boundary. Must be pure and\n * deterministic, same requirement as\n * {@link import('./SampledChunkSource').SampledChunkSourceOptions.mapValueToTile}.\n */\n mapValueToTile(value: number, tx: number, ty: number): ResolvedTile | null;\n}\n\ninterface WorkerRequestMessage {\n readonly requestId: number;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\ninterface WorkerSuccessMessage {\n readonly requestId: number;\n readonly values: Float64Array;\n}\n\ninterface WorkerErrorMessage {\n readonly requestId: number;\n readonly error: string;\n}\n\ntype WorkerResponseMessage = WorkerSuccessMessage | WorkerErrorMessage;\n\nconst isWorkerErrorMessage = (message: WorkerResponseMessage): message is WorkerErrorMessage => 'error' in message;\n\ninterface PendingRequest {\n readonly resolve: (payload: ChunkPayload | null) => void;\n readonly reject: (error: Error) => void;\n readonly cx: number;\n readonly cy: number;\n readonly chunkWidth: number;\n readonly chunkHeight: number;\n}\n\n/**\n * Build a {@link import('./ChunkStreamer').ChunkStreamer}-ready\n * {@link ChunkSource} that samples off the main thread via a Web Worker -\n * the async counterpart to\n * {@link import('./SampledChunkSource').createSampledChunkSource}, for\n * sampling functions expensive enough to want off-thread execution.\n *\n * Unlike the synchronous provider, sampling logic cannot be passed as a\n * live function - functions cannot cross a `postMessage` boundary. Instead\n * {@link WorkerSampledChunkSourceOptions.workerSource} is a self-contained\n * worker script string; see its documentation for the protocol.\n *\n * The returned value's `destroy()` MUST be called when done with it - the\n * underlying `Worker` is a real resource that leaks otherwise.\n * {@link import('./ChunkStreamer').ChunkStreamer} does not own the source it\n * is given and never calls this for you: `ChunkSource` itself has no\n * lifecycle hook, so nothing ties the two together automatically. Call it\n * yourself alongside your own `ChunkStreamer.destroy()` call.\n *\n * `workerSource` runs through {@link import('@codexo/exojs').InlineWorker},\n * so it needs no bundler support of its own but does need a\n * Content-Security-Policy that permits `blob:` in `worker-src` if your\n * deployment sets one; the constructor names that cause when it is refused.\n * @advanced\n */\nexport const createWorkerSampledChunkSource = (layer: TileLayer, options: WorkerSampledChunkSourceOptions): ChunkSource & { destroy(): void } => {\n const mapValueToTile = options.mapValueToTile.bind(options);\n\n const inline = new InlineWorker(options.workerSource, { name: 'exojs-tilemap-chunk-sampler' });\n const worker = inline.worker;\n\n if (options.initMessage !== undefined) {\n inline.postMessage(options.initMessage);\n }\n\n let requestCounter = 0;\n const pending = new Map<number, PendingRequest>();\n\n const composePayload = (values: Float64Array, request: PendingRequest): ChunkPayload | null => {\n const { cx, cy, chunkWidth, chunkHeight } = request;\n const startTx = cx * chunkWidth;\n const startTy = cy * chunkHeight;\n\n let out: Uint32Array | null = null;\n for (let ty = startTy; ty < startTy + chunkHeight; ty++) {\n for (let tx = startTx; tx < startTx + chunkWidth; tx++) {\n // Bounded-layer edge chunks may be smaller than a full chunk - same\n // clamp createSampledChunkSource applies, computed here (not asked\n // of the worker) since only this side knows the layer's bounds.\n if (layer.width !== undefined && layer.height !== undefined && (tx >= layer.width || ty >= layer.height)) continue;\n\n const localIndex = (ty - startTy) * chunkWidth + (tx - startTx);\n const value = values[localIndex];\n if (value === undefined) continue; // defensive: malformed/short values array\n const resolved = mapValueToTile(value, tx, ty);\n if (!resolved) continue;\n\n out ??= new Uint32Array(chunkWidth * chunkHeight);\n const tilesetIndex = layer.tilesets.indexOf(resolved.tileset);\n out[localIndex] = packTile(tilesetIndex, resolved.localTileId, resolved.transform);\n }\n }\n\n return out === null ? null : { width: chunkWidth, height: chunkHeight, tiles: out };\n };\n\n worker.onmessage = (event: MessageEvent<WorkerResponseMessage>): void => {\n const message = event.data;\n const entry = pending.get(message.requestId);\n if (!entry) return; // stale/unknown requestId (e.g. arrived after destroy())\n pending.delete(message.requestId);\n\n if (isWorkerErrorMessage(message)) {\n entry.reject(new Error(message.error));\n return;\n }\n\n entry.resolve(composePayload(message.values, entry));\n };\n\n worker.onerror = (event: ErrorEvent): void => {\n const error = new Error(`WorkerSampledChunkSource worker error: ${event.message}`);\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n };\n\n return {\n getChunk(cx: number, cy: number): Promise<ChunkPayload | null> {\n if (inline.destroyed) {\n return Promise.reject(new Error('WorkerSampledChunkSource: getChunk() called after destroy().'));\n }\n\n const chunkWidth = layer.chunkWidth;\n const chunkHeight = layer.chunkHeight;\n const requestId = ++requestCounter;\n\n return new Promise<ChunkPayload | null>((resolve, reject) => {\n pending.set(requestId, { resolve, reject, cx, cy, chunkWidth, chunkHeight });\n const request: WorkerRequestMessage = { requestId, cx, cy, chunkWidth, chunkHeight };\n inline.postMessage(request);\n });\n },\n\n destroy(): void {\n if (inline.destroyed) return;\n const error = new Error('WorkerSampledChunkSource destroyed.');\n for (const entry of pending.values()) {\n entry.reject(error);\n }\n pending.clear();\n inline.destroy();\n },\n };\n};\n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types.js";
4
4
  /** Pack a {@link TileTransform} into a 3-bit orientation code. @internal */
5
5
  const orientCode = (transform) => (transform.flipX ? 1 : 0) | (transform.flipY ? 2 : 0) | (transform.diagonal ? 4 : 0);
6
6
  let tileGeometryRebuildCount = 0;
7
+ const drawableTileset = (tilesets, tilesetIndex, localTileId) => {
8
+ const tileset = tilesets[tilesetIndex];
9
+ if (tileset === void 0 || localTileId >= tileset.tileCount) return void 0;
10
+ const texture = tileset.texture.texture;
11
+ if (texture.width <= 0 || texture.height <= 0) return void 0;
12
+ return tileset;
13
+ };
14
+ const pageQuads = (tileset, isometric, buckets, ordered) => {
15
+ let bucket;
16
+ if (isometric) {
17
+ const previous = ordered[ordered.length - 1];
18
+ if (previous?.tileset === tileset) bucket = previous.quads;
19
+ } else bucket = buckets.get(tileset);
20
+ if (bucket === void 0) {
21
+ bucket = [];
22
+ buckets.set(tileset, bucket);
23
+ if (isometric) ordered.push({
24
+ tileset,
25
+ texture: tileset.texture.texture,
26
+ quads: bucket
27
+ });
28
+ }
29
+ return bucket;
30
+ };
31
+ const tilesetPages = (tilesets, buckets) => {
32
+ const pages = [];
33
+ for (const tileset of tilesets) {
34
+ const quads = buckets.get(tileset);
35
+ if (quads !== void 0 && quads.length > 0) pages.push({
36
+ tileset,
37
+ texture: tileset.texture.texture,
38
+ quads
39
+ });
40
+ }
41
+ return pages;
42
+ };
7
43
  /**
8
44
  * Build per-tileset page geometry for a single chunk.
9
45
  *
10
- * Iterates the chunk's packed cells in deterministic row-major order, skipping
46
+ * Iterates packed cells in row-major or isometric diagonal order, skipping
11
47
  * empties, out-of-range tilesets, and out-of-range local tile ids (all treated
12
48
  * as empty - this is the renderer's half of the G-GID contract). Each surviving
13
49
  * cell is resolved to its source UV rect (from `tileset.getTileRect` + the
@@ -25,62 +61,54 @@ let tileGeometryRebuildCount = 0;
25
61
  * @param tileHeight Map/layer tile cell height in pixels.
26
62
  * @internal
27
63
  */
28
- const buildChunkPages = (chunk, tilesets, tileWidth, tileHeight) => {
64
+ const buildChunkPages = (chunk, tilesets, tileWidth, tileHeight, projection, diagonal, geometryX = 0, geometryY = 0) => {
29
65
  tileGeometryRebuildCount++;
30
66
  if (chunk.empty) return [];
31
67
  const buckets = /* @__PURE__ */ new Map();
68
+ const ordered = [];
69
+ const isometric = projection?.orientation === "isometric";
32
70
  const width = chunk.width;
33
71
  const height = chunk.height;
34
- for (let ly = 0; ly < height; ly++) for (let lx = 0; lx < width; lx++) {
35
- const packed = chunk.getRawAt(lx, ly);
36
- if (packed === 0) continue;
37
- const decoded = unpackTile(packed);
38
- if (decoded === null) continue;
39
- const tileset = tilesets[decoded.tilesetIndex];
40
- if (tileset === void 0 || decoded.localTileId >= tileset.tileCount) continue;
41
- const region = tileset.texture;
42
- const texture = region.texture;
43
- const textureWidth = texture.width;
44
- const textureHeight = texture.height;
45
- if (textureWidth <= 0 || textureHeight <= 0) continue;
46
- const rect = tileset.getTileRect(decoded.localTileId);
47
- const sx = region.x + rect.x;
48
- const sy = region.y + rect.y;
49
- const u0 = sx / textureWidth;
50
- const v0 = sy / textureHeight;
51
- const u1 = (sx + rect.width) / textureWidth;
52
- const v1 = (sy + rect.height) / textureHeight;
53
- const x0 = lx * tileWidth + tileset.offsetX;
54
- const y0 = ly * tileHeight + tileHeight - rect.height + tileset.offsetY;
55
- const x1 = x0 + rect.width;
56
- const y1 = y0 + rect.height;
57
- let bucket = buckets.get(tileset);
58
- if (bucket === void 0) {
59
- bucket = [];
60
- buckets.set(tileset, bucket);
72
+ for (let row = 0; row < (isometric ? width + height - 1 : height); row++) {
73
+ if (diagonal !== void 0 && row !== diagonal) continue;
74
+ for (let lx = 0; lx < width; lx++) {
75
+ const ly = isometric ? row - lx : row;
76
+ if (ly < 0 || ly >= height) continue;
77
+ const packed = chunk.getRawAt(lx, ly);
78
+ if (packed === 0) continue;
79
+ const decoded = unpackTile(packed);
80
+ if (decoded === null) continue;
81
+ const tileset = drawableTileset(tilesets, decoded.tilesetIndex, decoded.localTileId);
82
+ if (tileset === void 0) continue;
83
+ const region = tileset.texture;
84
+ const texture = region.texture;
85
+ const textureWidth = texture.width;
86
+ const textureHeight = texture.height;
87
+ const rect = tileset.getTileRect(decoded.localTileId);
88
+ const sx = region.x + rect.x;
89
+ const sy = region.y + rect.y;
90
+ const u0 = sx / textureWidth;
91
+ const v0 = sy / textureHeight;
92
+ const u1 = (sx + rect.width) / textureWidth;
93
+ const v1 = (sy + rect.height) / textureHeight;
94
+ const x0 = geometryX + (isometric ? (lx - ly) * tileWidth / 2 - tileWidth / 2 : lx * tileWidth) + tileset.offsetX;
95
+ const y0 = geometryY + (isometric ? (lx + ly) * tileHeight / 2 : ly * tileHeight) + tileHeight - rect.height + tileset.offsetY;
96
+ const x1 = x0 + rect.width;
97
+ const y1 = y0 + rect.height;
98
+ pageQuads(tileset, isometric, buckets, ordered).push({
99
+ x0,
100
+ y0,
101
+ x1,
102
+ y1,
103
+ u0,
104
+ v0,
105
+ u1,
106
+ v1,
107
+ orient: orientCode(decoded.transform)
108
+ });
61
109
  }
62
- bucket.push({
63
- x0,
64
- y0,
65
- x1,
66
- y1,
67
- u0,
68
- v0,
69
- u1,
70
- v1,
71
- orient: orientCode(decoded.transform)
72
- });
73
- }
74
- const pages = [];
75
- for (const tileset of tilesets) {
76
- const quads = buckets.get(tileset);
77
- if (quads !== void 0 && quads.length > 0) pages.push({
78
- tileset,
79
- texture: tileset.texture.texture,
80
- quads
81
- });
82
110
  }
83
- return pages;
111
+ return isometric ? ordered : tilesetPages(tilesets, buckets);
84
112
  };
85
113
 
86
114
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"chunkGeometry.js","names":[],"sources":["../../src/chunkGeometry.ts"],"sourcesContent":["import type { Texture } from '@codexo/exojs';\n\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport type { TileSet } from './TileSet';\nimport type { TileTransform } from './types';\nimport { unpackTile } from './types';\n\n/**\n * One textured tile quad in chunk-local pixel space.\n *\n * `u0/v0/u1/v1` are the raw (min/max) source UV bounds of the tile within its\n * tileset texture - flip/orientation is **not** baked here; it travels in\n * {@link TileQuad.orient} and is applied by the per-backend renderer (flipX/Y\n * via UV-corner swap, diagonal via an axis swap in the shader). Keeping the\n * geometry orientation-neutral lets both backends share one CPU builder.\n * @internal\n */\nexport interface TileQuad {\n /** Local destination rect, left/top (chunk-local pixels). */\n readonly x0: number;\n readonly y0: number;\n /** Local destination rect, right/bottom (chunk-local pixels). */\n readonly x1: number;\n readonly y1: number;\n /** Normalised source UV bounds (always min ≤ max). */\n readonly u0: number;\n readonly v0: number;\n readonly u1: number;\n readonly v1: number;\n /** Orientation code: bit0 = flipX, bit1 = flipY, bit2 = diagonal. */\n readonly orient: number;\n}\n\n/**\n * Geometry for one tileset \"page\" within a chunk: every tile in the chunk that\n * draws from a single tileset texture, grouped so the renderer can batch by\n * `(shader, texture)`.\n * @internal\n */\nexport interface ChunkPage {\n /** The tileset all quads in this page draw from. */\n readonly tileset: TileSet;\n /** The underlying GPU texture (the tileset's atlas), bound once per page. */\n readonly texture: Texture;\n /** The tile quads for this page, in deterministic row-major order. */\n readonly quads: readonly TileQuad[];\n}\n\n/** Pack a {@link TileTransform} into a 3-bit orientation code. @internal */\nexport const orientCode = (transform: TileTransform): number => (transform.flipX ? 1 : 0) | (transform.flipY ? 2 : 0) | (transform.diagonal ? 4 : 0);\n\n// Test/perf-only instrumentation: counts CPU chunk-geometry rebuilds. A rebuild\n// happens once per {@link buildChunkPages} call - i.e. when a chunk node sees a\n// changed `chunk.revision`. Lets benchmarks/regression tests assert that a camera\n// pan rebuilds nothing and a single tile mutation rebuilds exactly one chunk.\n// Near-zero cost (one integer increment on the already-expensive rebuild path).\nlet tileGeometryRebuildCount = 0;\n\n/** Read the cumulative chunk-geometry rebuild count. @internal */\nexport const getTileGeometryRebuildCount = (): number => tileGeometryRebuildCount;\n\n/** Reset the chunk-geometry rebuild counter (call before a measured frame). @internal */\nexport const resetTileGeometryRebuildCount = (): void => {\n tileGeometryRebuildCount = 0;\n};\n\n/**\n * Build per-tileset page geometry for a single chunk.\n *\n * Iterates the chunk's packed cells in deterministic row-major order, skipping\n * empties, out-of-range tilesets, and out-of-range local tile ids (all treated\n * as empty - this is the renderer's half of the G-GID contract). Each surviving\n * cell is resolved to its source UV rect (from `tileset.getTileRect` + the\n * tileset `TextureRegion`) and a chunk-local destination rect (bottom-left\n * aligned per Tiled orthogonal semantics, so tilesets whose tiles are taller\n * than the map grid extend upward).\n *\n * Allocation happens here only - the result is cached on the owning\n * {@link import('./TileChunkNode').TileChunkNode} keyed by `chunk.revision`, so\n * unchanged chunks never rebuild and the per-frame path stays allocation-free.\n *\n * @param chunk The readonly chunk view to build from.\n * @param tilesets The layer's tileset array (packed `tilesetIndex` selects one).\n * @param tileWidth Map/layer tile cell width in pixels.\n * @param tileHeight Map/layer tile cell height in pixels.\n * @internal\n */\nexport const buildChunkPages = (chunk: ReadonlyTileChunk, tilesets: readonly TileSet[], tileWidth: number, tileHeight: number): ChunkPage[] => {\n tileGeometryRebuildCount++;\n\n if (chunk.empty) {\n return [];\n }\n\n const buckets = new Map<TileSet, TileQuad[]>();\n const width = chunk.width;\n const height = chunk.height;\n\n for (let ly = 0; ly < height; ly++) {\n for (let lx = 0; lx < width; lx++) {\n const packed = chunk.getRawAt(lx, ly);\n\n if (packed === 0) {\n continue;\n }\n\n const decoded = unpackTile(packed);\n\n if (decoded === null) {\n continue;\n }\n\n const tileset = tilesets[decoded.tilesetIndex];\n\n // Out-of-range tileset or local id → treat as empty (G-GID). getTileRect\n // throws on an out-of-range id, so the bounds check must precede it.\n if (tileset === undefined || decoded.localTileId >= tileset.tileCount) {\n continue;\n }\n\n const region = tileset.texture;\n const texture = region.texture;\n const textureWidth = texture.width;\n const textureHeight = texture.height;\n\n if (textureWidth <= 0 || textureHeight <= 0) {\n continue;\n }\n\n const rect = tileset.getTileRect(decoded.localTileId);\n\n // Absolute source pixel rect = tileset-region offset + in-atlas tile rect.\n const sx = region.x + rect.x;\n const sy = region.y + rect.y;\n // Exact tile UVs, no half-texel inset. This assumes NEAREST filtering on\n // the tileset atlas (the typical pixel-art case). Under LINEAR/mipmap\n // filtering an atlas WITHOUT extrusion padding can bleed neighbouring\n // tiles at the edges; author tilesets with extruded margins for linear\n // sampling. (Extrusion-aware tilemap UV insetting - already done on the\n // NineSlice/RepeatingSprite geometry paths - is a v0.14 follow-up.)\n const u0 = sx / textureWidth;\n const v0 = sy / textureHeight;\n const u1 = (sx + rect.width) / textureWidth;\n const v1 = (sy + rect.height) / textureHeight;\n\n // Bottom-left aligned destination (Tiled orthogonal). Uniform tiles\n // (rect.height === tileHeight) collapse to a plain cell rect. The\n // tileset's visual draw offset (Tiled `tileoffset`) shifts every tile.\n const x0 = lx * tileWidth + tileset.offsetX;\n const y0 = ly * tileHeight + tileHeight - rect.height + tileset.offsetY;\n const x1 = x0 + rect.width;\n const y1 = y0 + rect.height;\n\n let bucket = buckets.get(tileset);\n\n if (bucket === undefined) {\n bucket = [];\n buckets.set(tileset, bucket);\n }\n\n bucket.push({ x0, y0, x1, y1, u0, v0, u1, v1, orient: orientCode(decoded.transform) });\n }\n }\n\n // Emit pages in tileset-array order for deterministic, reproducible builds.\n const pages: ChunkPage[] = [];\n\n for (const tileset of tilesets) {\n const quads = buckets.get(tileset);\n\n if (quads !== undefined && quads.length > 0) {\n pages.push({ tileset, texture: tileset.texture.texture, quads });\n }\n }\n\n return pages;\n};\n"],"mappings":";;;;AAiDA,MAAa,cAAc,eAAsC,UAAU,QAAQ,IAAI,MAAM,UAAU,QAAQ,IAAI,MAAM,UAAU,WAAW,IAAI;AAOlJ,IAAI,2BAA2B;;;;;;;;;;;;;;;;;;;;;;AA+B/B,MAAa,mBAAmB,OAA0B,UAA8B,WAAmB,eAAoC;CAC7I;CAEA,IAAI,MAAM,OACR,OAAO,CAAC;CAGV,MAAM,0BAAU,IAAI,IAAyB;CAC7C,MAAM,QAAQ,MAAM;CACpB,MAAM,SAAS,MAAM;CAErB,KAAK,IAAI,KAA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Q;GAAS;EAAM,CAAC;CAEnE;CAEA,OAAO;AACT"}
1
+ {"version":3,"file":"chunkGeometry.js","names":[],"sources":["../../src/chunkGeometry.ts"],"sourcesContent":["import type { Texture } from '@codexo/exojs';\n\nimport type { ReadonlyTileChunk } from './TileChunk';\nimport type { TileProjection } from './TileProjection';\nimport type { TileSet } from './TileSet';\nimport type { TileTransform } from './types';\nimport { unpackTile } from './types';\n\n/**\n * One textured tile quad in chunk-local pixel space.\n *\n * `u0/v0/u1/v1` are the raw (min/max) source UV bounds of the tile within its\n * tileset texture - flip/orientation is **not** baked here; it travels in\n * {@link TileQuad.orient} and is applied by the per-backend renderer (flipX/Y\n * via UV-corner swap, diagonal via an axis swap in the shader). Keeping the\n * geometry orientation-neutral lets both backends share one CPU builder.\n * @internal\n */\nexport interface TileQuad {\n /** Local destination rect, left/top (chunk-local pixels). */\n readonly x0: number;\n readonly y0: number;\n /** Local destination rect, right/bottom (chunk-local pixels). */\n readonly x1: number;\n readonly y1: number;\n /** Normalised source UV bounds (always min ≤ max). */\n readonly u0: number;\n readonly v0: number;\n readonly u1: number;\n readonly v1: number;\n /** Orientation code: bit0 = flipX, bit1 = flipY, bit2 = diagonal. */\n readonly orient: number;\n}\n\n/**\n * Geometry sharing one tileset texture. Orthogonal chunks group tiles by\n * tileset; isometric chunks keep consecutive runs to preserve painter order.\n * @internal\n */\nexport interface ChunkPage {\n /** The tileset all quads in this page draw from. */\n readonly tileset: TileSet;\n /** The underlying GPU texture (the tileset's atlas), bound once per page. */\n readonly texture: Texture;\n /** The tile quads in deterministic projection-specific draw order. */\n readonly quads: readonly TileQuad[];\n}\n\n/** Pack a {@link TileTransform} into a 3-bit orientation code. @internal */\nexport const orientCode = (transform: TileTransform): number => (transform.flipX ? 1 : 0) | (transform.flipY ? 2 : 0) | (transform.diagonal ? 4 : 0);\n\n// Test/perf-only instrumentation: counts CPU chunk-geometry rebuilds. A rebuild\n// happens once per {@link buildChunkPages} call - i.e. when a chunk node sees a\n// changed `chunk.revision`. Lets benchmarks/regression tests assert that a camera\n// pan rebuilds nothing and a single tile mutation rebuilds exactly one chunk.\n// Near-zero cost (one integer increment on the already-expensive rebuild path).\nlet tileGeometryRebuildCount = 0;\n\n/** Read the cumulative chunk-geometry rebuild count. @internal */\nexport const getTileGeometryRebuildCount = (): number => tileGeometryRebuildCount;\n\n/** Reset the chunk-geometry rebuild counter (call before a measured frame). @internal */\nexport const resetTileGeometryRebuildCount = (): void => {\n tileGeometryRebuildCount = 0;\n};\n\nconst drawableTileset = (tilesets: readonly TileSet[], tilesetIndex: number, localTileId: number): TileSet | undefined => {\n const tileset = tilesets[tilesetIndex];\n\n // getTileRect throws for an invalid id; malformed cells must remain empty.\n if (tileset === undefined || localTileId >= tileset.tileCount) return undefined;\n const texture = tileset.texture.texture;\n if (texture.width <= 0 || texture.height <= 0) return undefined;\n return tileset;\n};\n\nconst pageQuads = (tileset: TileSet, isometric: boolean, buckets: Map<TileSet, TileQuad[]>, ordered: ChunkPage[]): TileQuad[] => {\n let bucket: TileQuad[] | undefined;\n if (isometric) {\n const previous = ordered[ordered.length - 1];\n if (previous?.tileset === tileset) bucket = previous.quads as TileQuad[];\n } else {\n bucket = buckets.get(tileset);\n }\n\n if (bucket === undefined) {\n bucket = [];\n buckets.set(tileset, bucket);\n if (isometric) ordered.push({ tileset, texture: tileset.texture.texture, quads: bucket });\n }\n return bucket;\n};\n\nconst tilesetPages = (tilesets: readonly TileSet[], buckets: ReadonlyMap<TileSet, TileQuad[]>): ChunkPage[] => {\n const pages: ChunkPage[] = [];\n for (const tileset of tilesets) {\n const quads = buckets.get(tileset);\n if (quads !== undefined && quads.length > 0) {\n pages.push({ tileset, texture: tileset.texture.texture, quads });\n }\n }\n return pages;\n};\n\n/**\n * Build per-tileset page geometry for a single chunk.\n *\n * Iterates packed cells in row-major or isometric diagonal order, skipping\n * empties, out-of-range tilesets, and out-of-range local tile ids (all treated\n * as empty - this is the renderer's half of the G-GID contract). Each surviving\n * cell is resolved to its source UV rect (from `tileset.getTileRect` + the\n * tileset `TextureRegion`) and a chunk-local destination rect (bottom-left\n * aligned per Tiled orthogonal semantics, so tilesets whose tiles are taller\n * than the map grid extend upward).\n *\n * Allocation happens here only - the result is cached on the owning\n * {@link import('./TileChunkNode').TileChunkNode} keyed by `chunk.revision`, so\n * unchanged chunks never rebuild and the per-frame path stays allocation-free.\n *\n * @param chunk The readonly chunk view to build from.\n * @param tilesets The layer's tileset array (packed `tilesetIndex` selects one).\n * @param tileWidth Map/layer tile cell width in pixels.\n * @param tileHeight Map/layer tile cell height in pixels.\n * @internal\n */\nexport const buildChunkPages = (\n chunk: ReadonlyTileChunk,\n tilesets: readonly TileSet[],\n tileWidth: number,\n tileHeight: number,\n projection?: TileProjection,\n diagonal?: number,\n geometryX = 0,\n geometryY = 0,\n): ChunkPage[] => {\n tileGeometryRebuildCount++;\n\n if (chunk.empty) {\n return [];\n }\n\n const buckets = new Map<TileSet, TileQuad[]>();\n const ordered: ChunkPage[] = [];\n const isometric = projection?.orientation === 'isometric';\n const width = chunk.width;\n const height = chunk.height;\n\n for (let row = 0; row < (isometric ? width + height - 1 : height); row++) {\n if (diagonal !== undefined && row !== diagonal) continue;\n for (let lx = 0; lx < width; lx++) {\n const ly = isometric ? row - lx : row;\n if (ly < 0 || ly >= height) continue;\n const packed = chunk.getRawAt(lx, ly);\n\n if (packed === 0) {\n continue;\n }\n\n const decoded = unpackTile(packed);\n\n if (decoded === null) {\n continue;\n }\n\n const tileset = drawableTileset(tilesets, decoded.tilesetIndex, decoded.localTileId);\n if (tileset === undefined) {\n continue;\n }\n\n const region = tileset.texture;\n const texture = region.texture;\n const textureWidth = texture.width;\n const textureHeight = texture.height;\n\n const rect = tileset.getTileRect(decoded.localTileId);\n\n // Absolute source pixel rect = tileset-region offset + in-atlas tile rect.\n const sx = region.x + rect.x;\n const sy = region.y + rect.y;\n // Exact tile UVs, no half-texel inset. This assumes NEAREST filtering on\n // the tileset atlas (the typical pixel-art case). Under LINEAR/mipmap\n // filtering an atlas WITHOUT extrusion padding can bleed neighbouring\n // tiles at the edges; author tilesets with extruded margins for linear\n // sampling. (Extrusion-aware tilemap UV insetting - already done on the\n // NineSlice/RepeatingSprite geometry paths - is a v0.14 follow-up.)\n const u0 = sx / textureWidth;\n const v0 = sy / textureHeight;\n const u1 = (sx + rect.width) / textureWidth;\n const v1 = (sy + rect.height) / textureHeight;\n\n // Isometric cells start at their top vertex; artwork is bottom-aligned\n // with the cell base before applying the tileset's display offset.\n const x0 = geometryX + (isometric ? ((lx - ly) * tileWidth) / 2 - tileWidth / 2 : lx * tileWidth) + tileset.offsetX;\n const y0 = geometryY + (isometric ? ((lx + ly) * tileHeight) / 2 : ly * tileHeight) + tileHeight - rect.height + tileset.offsetY;\n const x1 = x0 + rect.width;\n const y1 = y0 + rect.height;\n\n const bucket = pageQuads(tileset, isometric, buckets, ordered);\n bucket.push({ x0, y0, x1, y1, u0, v0, u1, v1, orient: orientCode(decoded.transform) });\n }\n }\n\n return isometric ? ordered : tilesetPages(tilesets, buckets);\n};\n"],"mappings":";;;;AAiDA,MAAa,cAAc,eAAsC,UAAU,QAAQ,IAAI,MAAM,UAAU,QAAQ,IAAI,MAAM,UAAU,WAAW,IAAI;AAOlJ,IAAI,2BAA2B;AAU/B,MAAM,mBAAmB,UAA8B,cAAsB,gBAA6C;CACxH,MAAM,UAAU,SAAS;CAGzB,IAAI,YAAY,UAAa,eAAe,QAAQ,WAAW,OAAO;CACtE,MAAM,UAAU,QAAQ,QAAQ;CAChC,IAAI,QAAQ,SAAS,KAAK,QAAQ,UAAU,GAAG,OAAO;CACtD,OAAO;AACT;AAEA,MAAM,aAAa,SAAkB,WAAoB,SAAmC,YAAqC;CAC/H,IAAI;CACJ,IAAI,WAAW;EACb,MAAM,WAAW,QAAQ,QAAQ,SAAS;EAC1C,IAAI,UAAU,YAAY,SAAS,SAAS,SAAS;CACvD,OACE,SAAS,QAAQ,IAAI,OAAO;CAG9B,IAAI,WAAW,QAAW;EACx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Q;GAE9B,MAAM,OAAO,QAAQ,YAAY,QAAQ,WAAW;GAGpD,MAAM,KAAK,OAAO,IAAI,KAAK;GAC3B,MAAM,KAAK,OAAO,IAAI,KAAK;GAO3B,MAAM,KAAK,KAAK;GAChB,MAAM,KAAK,KAAK;GAChB,MAAM,MAAM,KAAK,KAAK,SAAS;GAC/B,MAAM,MAAM,KAAK,KAAK,UAAU;GAIhC,MAAM,KAAK,aAAa,aAAc,KAAK,MAAM,YAAa,IAAI,YAAY,IAAI,KAAK,aAAa,QAAQ;GAC5G,MAAM,KAAK,aAAa,aAAc,KAAK,MAAM,aAAc,IAAI,KAAK,cAAc,aAAa,KAAK,SAAS,QAAQ;GACzH,MAAM,KAAK,KAAK,KAAK;GACrB,MAAM,KAAK,KAAK,KAAK;GAGrB,AADe,UAAU,SAAS,WAAW,SAAS,OACjD,CAAC,CAAC,KAAK;IAAE;IAAI;IAAI;IAAI;IAAI;IAAI;IAAI;IAAI;IAAI,QAAQ,WAAW,QAAQ,SAAS;GAAE,CAAC;EACvF;CACF;CAEA,OAAO,YAAY,UAAU,aAAa,UAAU,OAAO;AAC7D"}
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { TILE_TRANSFORM_IDENTITY, TilePropertyKind, packTile, tileToChunkCoord, tileToLocalInChunk, unpackTile } from "./types.js";
2
+ import { TileProjection } from "./TileProjection.js";
2
3
  import { ImageLayer } from "./ImageLayer.js";
3
4
  import { ImageLayerNode } from "./ImageLayerNode.js";
4
5
  import { TileLayerNode } from "./TileLayerNode.js";
@@ -23,4 +24,4 @@ import { createWorkerSampledChunkSource } from "./WorkerSampledChunkSource.js";
23
24
  import { autoTile, refreshCell } from "./autoTile.js";
24
25
  import { WangSet } from "./WangSet.js";
25
26
 
26
- export { ChunkStreamer, ImageLayer, ImageLayerNode, MapLevelRuntime, MapLevelSide, MapObjectSpawner, MapSpawnError, MapSpawnSession, MapWorld, MapWorldRuntime, ObjectKind, ObjectLayer, TILE_TRANSFORM_IDENTITY, TileAnimator, TileLayer, TileLayerNode, TileMap, TileMapBand, TileMapNode, TileMapView, TilePropertyKind, TileSet, WangSet, autoTile, buildTileCollisionGeometry, createSampledChunkSource, createWorkerSampledChunkSource, mapObjectDescriptor, mapObjectDescriptors, packTile, refreshCell, tileToChunkCoord, tileToLocalInChunk, tilemapExtension, unpackTile };
27
+ export { ChunkStreamer, ImageLayer, ImageLayerNode, MapLevelRuntime, MapLevelSide, MapObjectSpawner, MapSpawnError, MapSpawnSession, MapWorld, MapWorldRuntime, ObjectKind, ObjectLayer, TILE_TRANSFORM_IDENTITY, TileAnimator, TileLayer, TileLayerNode, TileMap, TileMapBand, TileMapNode, TileMapView, TileProjection, TilePropertyKind, TileSet, WangSet, autoTile, buildTileCollisionGeometry, createSampledChunkSource, createWorkerSampledChunkSource, mapObjectDescriptor, mapObjectDescriptors, packTile, refreshCell, tileToChunkCoord, tileToLocalInChunk, tilemapExtension, unpackTile };
@@ -0,0 +1,4 @@
1
+ import type { TileMapObject } from './ObjectLayer';
2
+ /** Affine object geometry mapping; tile images and text keep their display dimensions. */
3
+ export declare const projectObject: (object: TileMapObject, a: number, b: number, c: number, d: number, offsetX: number, offsetY: number) => TileMapObject;
4
+ //# sourceMappingURL=projectObject.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"projectObject.d.ts","sourceRoot":"","sources":["../../src/projectObject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,0FAA0F;AAC1F,eAAO,MAAM,aAAa,WAAY,aAAa,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM,WAAW,MAAM,WAAW,MAAM,KAAG,aAmDnI,CAAC"}