@canvas-tile-engine/react 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -2
- package/dist/index.d.mts +157 -75
- package/dist/index.d.ts +157 -75
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Rect, Circle, ImageItem, Line, Text, Path, Coords, CanvasTileEngineConfig, CanvasTileEngine as CanvasTileEngine$1, EventHandlers, DrawHandle, IRenderer, onClickCallback, onRightClickCallback, onHoverCallback, onMouseDownCallback, onMouseUpCallback, onMouseLeaveCallback, onDrawCallback, onZoomCallback } from '@canvas-tile-engine/core';
|
|
3
3
|
export { CanvasTileEngineConfig, CanvasTileEngine as CanvasTileEngineCore, Circle, Coords, DrawObject, EventHandlers, ImageItem, Line, Path, Rect, Text, gridToSize, onClickCallback, onDrawCallback, onHoverCallback, onMouseDownCallback, onMouseLeaveCallback, onMouseUpCallback } from '@canvas-tile-engine/core';
|
|
4
4
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
interface RectProps {
|
|
7
|
-
items:
|
|
7
|
+
items: Rect | Rect[];
|
|
8
8
|
layer?: number;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
interface CircleProps {
|
|
12
|
-
items:
|
|
12
|
+
items: Circle | Circle[];
|
|
13
13
|
layer?: number;
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -26,13 +26,7 @@ interface GridLinesProps {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
interface LineProps {
|
|
29
|
-
items:
|
|
30
|
-
from: Coords;
|
|
31
|
-
to: Coords;
|
|
32
|
-
} | {
|
|
33
|
-
from: Coords;
|
|
34
|
-
to: Coords;
|
|
35
|
-
}[];
|
|
29
|
+
items: Line | Line[];
|
|
36
30
|
style?: {
|
|
37
31
|
strokeStyle?: string;
|
|
38
32
|
lineWidth?: number;
|
|
@@ -41,24 +35,12 @@ interface LineProps {
|
|
|
41
35
|
}
|
|
42
36
|
|
|
43
37
|
interface TextProps {
|
|
44
|
-
items:
|
|
45
|
-
coords: Coords;
|
|
46
|
-
text: string;
|
|
47
|
-
} | {
|
|
48
|
-
coords: Coords;
|
|
49
|
-
text: string;
|
|
50
|
-
}[];
|
|
51
|
-
style?: {
|
|
52
|
-
fillStyle?: string;
|
|
53
|
-
font?: string;
|
|
54
|
-
textAlign?: CanvasTextAlign;
|
|
55
|
-
textBaseline?: CanvasTextBaseline;
|
|
56
|
-
};
|
|
38
|
+
items: Text | Text[];
|
|
57
39
|
layer?: number;
|
|
58
40
|
}
|
|
59
41
|
|
|
60
42
|
interface PathProps {
|
|
61
|
-
items:
|
|
43
|
+
items: Path | Path[];
|
|
62
44
|
style?: {
|
|
63
45
|
strokeStyle?: string;
|
|
64
46
|
lineWidth?: number;
|
|
@@ -67,13 +49,13 @@ interface PathProps {
|
|
|
67
49
|
}
|
|
68
50
|
|
|
69
51
|
interface StaticRectProps {
|
|
70
|
-
items:
|
|
52
|
+
items: Rect[];
|
|
71
53
|
cacheKey: string;
|
|
72
54
|
layer?: number;
|
|
73
55
|
}
|
|
74
56
|
|
|
75
57
|
interface StaticCircleProps {
|
|
76
|
-
items:
|
|
58
|
+
items: Circle[];
|
|
77
59
|
cacheKey: string;
|
|
78
60
|
layer?: number;
|
|
79
61
|
}
|
|
@@ -86,7 +68,7 @@ interface StaticImageProps {
|
|
|
86
68
|
|
|
87
69
|
interface DrawFunctionProps {
|
|
88
70
|
/** The draw function to execute */
|
|
89
|
-
children: (ctx:
|
|
71
|
+
children: (ctx: unknown, coords: Coords, config: Required<CanvasTileEngineConfig>) => void;
|
|
90
72
|
layer?: number;
|
|
91
73
|
}
|
|
92
74
|
|
|
@@ -143,57 +125,34 @@ interface EngineHandle {
|
|
|
143
125
|
}): void;
|
|
144
126
|
/** Dynamically update event handlers at runtime */
|
|
145
127
|
setEventHandlers(handlers: Partial<EventHandlers>): void;
|
|
128
|
+
/** Register a custom draw function */
|
|
129
|
+
addDrawFunction(fn: (ctx: unknown, coords: Coords, config: Required<CanvasTileEngineConfig>) => void, layer?: number): DrawHandle;
|
|
146
130
|
/** Draw rectangles */
|
|
147
|
-
drawRect(items:
|
|
131
|
+
drawRect(items: Rect | Rect[], layer?: number): DrawHandle;
|
|
148
132
|
/** Draw static rectangles (cached) */
|
|
149
|
-
drawStaticRect(items:
|
|
133
|
+
drawStaticRect(items: Rect[], cacheKey: string, layer?: number): DrawHandle;
|
|
150
134
|
/** Draw circles */
|
|
151
|
-
drawCircle(items:
|
|
135
|
+
drawCircle(items: Circle | Circle[], layer?: number): DrawHandle;
|
|
152
136
|
/** Draw static circles (cached) */
|
|
153
|
-
drawStaticCircle(items:
|
|
137
|
+
drawStaticCircle(items: Circle[], cacheKey: string, layer?: number): DrawHandle;
|
|
154
138
|
/** Draw lines */
|
|
155
|
-
drawLine(items: {
|
|
156
|
-
from: Coords;
|
|
157
|
-
to: Coords;
|
|
158
|
-
} | {
|
|
159
|
-
from: Coords;
|
|
160
|
-
to: Coords;
|
|
161
|
-
}[], style?: {
|
|
139
|
+
drawLine(items: Line | Line[], style?: {
|
|
162
140
|
strokeStyle?: string;
|
|
163
141
|
lineWidth?: number;
|
|
164
|
-
}, layer?: number):
|
|
142
|
+
}, layer?: number): DrawHandle;
|
|
165
143
|
/** Draw text */
|
|
166
|
-
drawText(items:
|
|
167
|
-
coords: Coords;
|
|
168
|
-
text: string;
|
|
169
|
-
} | {
|
|
170
|
-
coords: Coords;
|
|
171
|
-
text: string;
|
|
172
|
-
}[], style?: {
|
|
173
|
-
fillStyle?: string;
|
|
174
|
-
font?: string;
|
|
175
|
-
textAlign?: CanvasTextAlign;
|
|
176
|
-
textBaseline?: CanvasTextBaseline;
|
|
177
|
-
}, layer?: number): LayerHandle;
|
|
144
|
+
drawText(items: Text | Text[], layer?: number): DrawHandle;
|
|
178
145
|
/** Draw paths/polylines */
|
|
179
146
|
drawPath(items: Coords[] | Coords[][], style?: {
|
|
180
147
|
strokeStyle?: string;
|
|
181
148
|
lineWidth?: number;
|
|
182
|
-
}, layer?: number):
|
|
149
|
+
}, layer?: number): DrawHandle;
|
|
183
150
|
/** Draw images */
|
|
184
|
-
drawImage(items:
|
|
185
|
-
img: HTMLImageElement;
|
|
186
|
-
}) | (Omit<DrawObject, "style"> & {
|
|
187
|
-
img: HTMLImageElement;
|
|
188
|
-
})[], layer?: number): LayerHandle;
|
|
151
|
+
drawImage(items: ImageItem | ImageItem[], layer?: number): DrawHandle;
|
|
189
152
|
/** Draw static images (cached) */
|
|
190
|
-
drawStaticImage(items:
|
|
191
|
-
img: HTMLImageElement;
|
|
192
|
-
})[], cacheKey: string, layer?: number): LayerHandle;
|
|
153
|
+
drawStaticImage(items: ImageItem[], cacheKey: string, layer?: number): DrawHandle;
|
|
193
154
|
/** Draw grid lines */
|
|
194
|
-
drawGridLines(cellSize: number, lineWidth?: number, strokeStyle?: string, layer?: number):
|
|
195
|
-
/** Add custom draw function */
|
|
196
|
-
addDrawFunction(fn: (ctx: CanvasRenderingContext2D, coords: Coords, config: Required<CanvasTileEngineConfig>) => void, layer?: number): LayerHandle;
|
|
155
|
+
drawGridLines(cellSize: number, lineWidth?: number, strokeStyle?: string, layer?: number): DrawHandle;
|
|
197
156
|
/** Clear a specific layer */
|
|
198
157
|
clearLayer(layer: number): void;
|
|
199
158
|
/** Clear all layers */
|
|
@@ -201,9 +160,20 @@ interface EngineHandle {
|
|
|
201
160
|
/** Clear static cache */
|
|
202
161
|
clearStaticCache(cacheKey?: string): void;
|
|
203
162
|
/** Remove a previously registered draw callback */
|
|
204
|
-
|
|
163
|
+
removeDrawHandle(handle: DrawHandle): void;
|
|
205
164
|
/** Image loader instance (undefined until engine mounts) */
|
|
206
165
|
readonly images: CanvasTileEngine$1["images"] | undefined;
|
|
166
|
+
/**
|
|
167
|
+
* Load an image using the engine's image loader.
|
|
168
|
+
* Returns a rejected promise if engine is not ready.
|
|
169
|
+
* @param src - Image URL to load
|
|
170
|
+
* @param retry - Number of retries on failure (default: 1)
|
|
171
|
+
* @example
|
|
172
|
+
* ```tsx
|
|
173
|
+
* const img = await engine.loadImage("/sprites/player.png");
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
loadImage(src: string, retry?: number): Promise<HTMLImageElement>;
|
|
207
177
|
}
|
|
208
178
|
/**
|
|
209
179
|
* React hook that creates an engine handle for use with CanvasTileEngine component.
|
|
@@ -241,6 +211,15 @@ declare function useCanvasTileEngine(): EngineHandle;
|
|
|
241
211
|
interface CanvasTileEngineProps {
|
|
242
212
|
/** Engine handle from useCanvasTileEngine hook (required) */
|
|
243
213
|
engine: EngineHandle;
|
|
214
|
+
/**
|
|
215
|
+
* Renderer instance to use.
|
|
216
|
+
* @example
|
|
217
|
+
* ```tsx
|
|
218
|
+
* import { RendererCanvas } from "@canvas-tile-engine/renderer-canvas";
|
|
219
|
+
* <CanvasTileEngine config={config} engine={engine} renderer={new RendererCanvas()} />
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
renderer: IRenderer;
|
|
244
223
|
/** Engine configuration */
|
|
245
224
|
config: CanvasTileEngineConfig;
|
|
246
225
|
/** Initial center coordinates */
|
|
@@ -251,25 +230,128 @@ interface CanvasTileEngineProps {
|
|
|
251
230
|
style?: React.CSSProperties;
|
|
252
231
|
/** Draw components (Rect, Circle, Image, GridLines, etc.) */
|
|
253
232
|
children?: React.ReactNode;
|
|
254
|
-
/**
|
|
233
|
+
/**
|
|
234
|
+
* Callback when center coordinates change (pan or zoom).
|
|
235
|
+
* @param coords - Center world coordinates: `{ x, y }`
|
|
236
|
+
* @example
|
|
237
|
+
* ```tsx
|
|
238
|
+
* onCoordsChange={(coords) => {
|
|
239
|
+
* console.log(`Center: ${coords.x}, ${coords.y}`);
|
|
240
|
+
* }}
|
|
241
|
+
* ```
|
|
242
|
+
*/
|
|
255
243
|
onCoordsChange?: (coords: Coords) => void;
|
|
256
|
-
/**
|
|
244
|
+
/**
|
|
245
|
+
* Callback when a tile is clicked (mouse or touch tap).
|
|
246
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
247
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
248
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
249
|
+
* @example
|
|
250
|
+
* ```tsx
|
|
251
|
+
* onClick={(coords) => {
|
|
252
|
+
* console.log(`Clicked tile: ${coords.snapped.x}, ${coords.snapped.y}`);
|
|
253
|
+
* }}
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
257
256
|
onClick?: onClickCallback;
|
|
258
|
-
/**
|
|
257
|
+
/**
|
|
258
|
+
* Callback when a tile is right-clicked.
|
|
259
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
260
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
261
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
262
|
+
* @example
|
|
263
|
+
* ```tsx
|
|
264
|
+
* onRightClick={(coords) => {
|
|
265
|
+
* showContextMenu(coords.snapped.x, coords.snapped.y);
|
|
266
|
+
* }}
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
259
269
|
onRightClick?: onRightClickCallback;
|
|
260
|
-
/**
|
|
270
|
+
/**
|
|
271
|
+
* Callback when hovering over tiles.
|
|
272
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
273
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
274
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
275
|
+
* @example
|
|
276
|
+
* ```tsx
|
|
277
|
+
* onHover={(coords) => {
|
|
278
|
+
* setHoveredTile({ x: coords.snapped.x, y: coords.snapped.y });
|
|
279
|
+
* }}
|
|
280
|
+
* ```
|
|
281
|
+
*/
|
|
261
282
|
onHover?: onHoverCallback;
|
|
262
|
-
/**
|
|
283
|
+
/**
|
|
284
|
+
* Callback on mouse/touch down.
|
|
285
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
286
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
287
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
288
|
+
* @example
|
|
289
|
+
* ```tsx
|
|
290
|
+
* onMouseDown={(coords) => {
|
|
291
|
+
* startPainting(coords.snapped.x, coords.snapped.y);
|
|
292
|
+
* }}
|
|
293
|
+
* ```
|
|
294
|
+
*/
|
|
263
295
|
onMouseDown?: onMouseDownCallback;
|
|
264
|
-
/**
|
|
296
|
+
/**
|
|
297
|
+
* Callback on mouse/touch up.
|
|
298
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
299
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
300
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
301
|
+
* @example
|
|
302
|
+
* ```tsx
|
|
303
|
+
* onMouseUp={() => {
|
|
304
|
+
* stopPainting();
|
|
305
|
+
* }}
|
|
306
|
+
* ```
|
|
307
|
+
*/
|
|
265
308
|
onMouseUp?: onMouseUpCallback;
|
|
266
|
-
/**
|
|
309
|
+
/**
|
|
310
|
+
* Callback when mouse/touch leaves the canvas.
|
|
311
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
312
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
313
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
314
|
+
* @example
|
|
315
|
+
* ```tsx
|
|
316
|
+
* onMouseLeave={() => {
|
|
317
|
+
* clearHoveredTile();
|
|
318
|
+
* }}
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
267
321
|
onMouseLeave?: onMouseLeaveCallback;
|
|
268
|
-
/**
|
|
322
|
+
/**
|
|
323
|
+
* Callback after each draw frame. Use for custom canvas drawing.
|
|
324
|
+
* @param ctx - The canvas 2D rendering context
|
|
325
|
+
* @param info - Frame info: `scale`, `width`, `height`, `coords` (center)
|
|
326
|
+
* @example
|
|
327
|
+
* ```tsx
|
|
328
|
+
* onDraw={(ctx, info) => {
|
|
329
|
+
* ctx.fillStyle = "red";
|
|
330
|
+
* ctx.fillText(`Scale: ${info.scale}`, 10, 20);
|
|
331
|
+
* }}
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
269
334
|
onDraw?: onDrawCallback;
|
|
270
|
-
/**
|
|
335
|
+
/**
|
|
336
|
+
* Callback on canvas resize.
|
|
337
|
+
* @example
|
|
338
|
+
* ```tsx
|
|
339
|
+
* onResize={() => {
|
|
340
|
+
* console.log("Canvas resized");
|
|
341
|
+
* }}
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
271
344
|
onResize?: () => void;
|
|
272
|
-
/**
|
|
345
|
+
/**
|
|
346
|
+
* Callback when zoom level changes (wheel or pinch).
|
|
347
|
+
* @param scale - The new scale value
|
|
348
|
+
* @example
|
|
349
|
+
* ```tsx
|
|
350
|
+
* onZoom={(scale) => {
|
|
351
|
+
* console.log(`Zoom level: ${scale}`);
|
|
352
|
+
* }}
|
|
353
|
+
* ```
|
|
354
|
+
*/
|
|
273
355
|
onZoom?: onZoomCallback;
|
|
274
356
|
}
|
|
275
357
|
|
|
@@ -308,7 +390,7 @@ interface CanvasTileEngineProps {
|
|
|
308
390
|
* }
|
|
309
391
|
* ```
|
|
310
392
|
*/
|
|
311
|
-
declare function CanvasTileEngineBase({ engine, config, center, className, style, children, onCoordsChange, onClick, onRightClick, onHover, onMouseDown, onMouseUp, onMouseLeave, onDraw, onResize, onZoom, }: CanvasTileEngineProps): react_jsx_runtime.JSX.Element;
|
|
393
|
+
declare function CanvasTileEngineBase({ engine, renderer, config, center, className, style, children, onCoordsChange, onClick, onRightClick, onHover, onMouseDown, onMouseUp, onMouseLeave, onDraw, onResize, onZoom, }: CanvasTileEngineProps): react_jsx_runtime.JSX.Element;
|
|
312
394
|
declare const CanvasTileEngine: typeof CanvasTileEngineBase & {
|
|
313
395
|
Rect: react.NamedExoticComponent<RectProps>;
|
|
314
396
|
Circle: react.NamedExoticComponent<CircleProps>;
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var z=Object.defineProperty;var oe=Object.getOwnPropertyDescriptor;var ie=Object.getOwnPropertyNames;var ae=Object.prototype.hasOwnProperty;var se=(r,o)=>{for(var t in o)z(r,t,{get:o[t],enumerable:!0})},ce=(r,o,t,i)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of ie(o))!ae.call(r,n)&&n!==t&&z(r,n,{get:()=>o[n],enumerable:!(i=oe(o,n))||i.enumerable});return r};var ue=r=>ce(z({},"__esModule",{value:!0}),r);var de={};se(de,{CanvasTileEngine:()=>q,CanvasTileEngineCore:()=>k.CanvasTileEngine,gridToSize:()=>k.gridToSize,useCanvasTileEngine:()=>F,useEngineContext:()=>c});module.exports=ue(de);var f=require("react"),ne=require("@canvas-tile-engine/core");var R=require("react"),T=(0,R.createContext)(null);function c(){let r=(0,R.useContext)(T);if(!r)throw new Error("useEngineContext must be used within a CanvasTileEngine component");return r}var P=require("react");var O=(0,P.memo)(function({items:o,layer:t=1}){let{engine:i,requestRender:n}=c();return(0,P.useEffect)(()=>{let s=i.drawRect(o,t);return n(),()=>{s&&i.removeDrawHandle(s)}},[i,o,t,n]),null});var h=require("react");var U=(0,h.memo)(function({items:o,layer:t=1}){let{engine:i,requestRender:n}=c();return(0,h.useEffect)(()=>{let s=i.drawCircle(o,t);return n(),()=>{s&&i.removeDrawHandle(s)}},[i,o,t,n]),null});var I=require("react");var j=(0,I.memo)(function({items:o,layer:t=1}){let{engine:i,requestRender:n}=c();return(0,I.useEffect)(()=>{let s=i.drawImage(o,t);return n(),()=>{s&&i.removeDrawHandle(s)}},[i,o,t,n]),null});var S=require("react");var N=(0,S.memo)(function({cellSize:o,lineWidth:t=1,strokeStyle:i="black",layer:n=0}){let{engine:s,requestRender:e}=c();return(0,S.useEffect)(()=>{let a=s.drawGridLines(o,t,i,n);return e(),()=>{a&&s.removeDrawHandle(a)}},[s,o,t,i,n,e]),null});var D=require("react");var Z=(0,D.memo)(function({items:o,style:t,layer:i=1}){let{engine:n,requestRender:s}=c();return(0,D.useEffect)(()=>{let e=n.drawLine(o,t,i);return s(),()=>{e&&n.removeDrawHandle(e)}},[n,o,t,i,s]),null});var H=require("react");var J=(0,H.memo)(function({items:o,layer:t=2}){let{engine:i,requestRender:n}=c();return(0,H.useEffect)(()=>{let s=i.drawText(o,t);return n(),()=>{s&&i.removeDrawHandle(s)}},[i,o,t,n]),null});var L=require("react");var Q=(0,L.memo)(function({items:o,style:t,layer:i=1}){let{engine:n,requestRender:s}=c();return(0,L.useEffect)(()=>{let e=n.drawPath(o,t,i);return s(),()=>{e&&n.removeDrawHandle(e)}},[n,o,t,i,s]),null});var x=require("react");var $=(0,x.memo)(function({items:o,cacheKey:t,layer:i=1}){let{engine:n,requestRender:s}=c(),e=(0,x.useRef)(t);return(0,x.useEffect)(()=>{if(o.length===0)return;e.current!==t&&(n.clearStaticCache(e.current),e.current=t);let a=n.drawStaticRect(o,t,i);return s(),()=>{a&&n.removeDrawHandle(a)}},[n,o,t,i,s]),(0,x.useEffect)(()=>()=>{n.clearStaticCache(t)},[n,t]),null});var v=require("react");var K=(0,v.memo)(function({items:o,cacheKey:t,layer:i=1}){let{engine:n,requestRender:s}=c(),e=(0,v.useRef)(t);return(0,v.useEffect)(()=>{if(o.length===0)return;e.current!==t&&(n.clearStaticCache(e.current),e.current=t);let a=n.drawStaticCircle(o,t,i);return s(),()=>{a&&n.removeDrawHandle(a)}},[n,o,t,i,s]),(0,v.useEffect)(()=>()=>{n.clearStaticCache(t)},[n,t]),null});var y=require("react");var ee=(0,y.memo)(function({items:o,cacheKey:t,layer:i=1}){let{engine:n,requestRender:s}=c(),e=(0,y.useRef)(t);return(0,y.useEffect)(()=>{if(o.length===0)return;e.current!==t&&(n.clearStaticCache(e.current),e.current=t);let a=n.drawStaticImage(o,t,i);return s(),()=>{a&&n.removeDrawHandle(a)}},[n,o,t,i,s]),(0,y.useEffect)(()=>()=>{n.clearStaticCache(t)},[n,t]),null});var w=require("react");var re=(0,w.memo)(function({children:o,layer:t=1}){let{engine:i,requestRender:n}=c(),s=(0,w.useRef)(o);return(0,w.useEffect)(()=>{s.current=o}),(0,w.useEffect)(()=>{let e=i.addDrawFunction((a,u,g)=>{s.current(a,u,g)},t);return n(),()=>{e&&i.removeDrawHandle(e)}},[i,t,n]),null});var E=require("react/jsx-runtime");function le({engine:r,renderer:o,config:t,center:i={x:0,y:0},className:n,style:s,children:e,onCoordsChange:a,onClick:u,onRightClick:g,onHover:M,onMouseDown:G,onMouseUp:V,onMouseLeave:_,onDraw:A,onResize:W,onZoom:Y}){let d=(0,f.useRef)({onCoordsChange:a,onClick:u,onRightClick:g,onHover:M,onMouseDown:G,onMouseUp:V,onMouseLeave:_,onDraw:A,onResize:W,onZoom:Y});(0,f.useEffect)(()=>{d.current={onCoordsChange:a,onClick:u,onRightClick:g,onHover:M,onMouseDown:G,onMouseUp:V,onMouseLeave:_,onDraw:A,onResize:W,onZoom:Y}});let b=(0,f.useRef)(null),X=(0,f.useCallback)(()=>{b.current===null&&(b.current=requestAnimationFrame(()=>{b.current=null,r.render()}))},[r]);(0,f.useEffect)(()=>()=>{b.current!==null&&cancelAnimationFrame(b.current)},[]);let te=(0,f.useMemo)(()=>({engine:r,requestRender:X}),[r,X]);return(0,f.useEffect)(()=>{let B=r._containerRef.current;if(!B)return;let m=new ne.CanvasTileEngine(B,t,o,i);return m.onCoordsChange=l=>d.current.onCoordsChange?.(l),m.onClick=(...l)=>d.current.onClick?.(...l),m.onRightClick=(...l)=>d.current.onRightClick?.(...l),m.onHover=(...l)=>d.current.onHover?.(...l),m.onMouseDown=(...l)=>d.current.onMouseDown?.(...l),m.onMouseUp=(...l)=>d.current.onMouseUp?.(...l),m.onMouseLeave=(...l)=>d.current.onMouseLeave?.(...l),m.onDraw=(...l)=>d.current.onDraw?.(...l),m.onResize=()=>d.current.onResize?.(),m.onZoom=l=>d.current.onZoom?.(l),r._setInstance(m),m.render(),()=>{m.destroy(),r._setInstance(null)}},[r]),(0,E.jsxs)(T.Provider,{value:te,children:[(0,E.jsx)("div",{ref:r._containerRef,className:n,style:{...s},children:(0,E.jsx)("canvas",{})}),r.isReady&&e]})}var q=Object.assign(le,{Rect:O,Circle:U,Image:j,GridLines:N,Line:Z,Text:J,Path:Q,StaticRect:$,StaticCircle:K,StaticImage:ee,DrawFunction:re});var C=require("react"),p={layer:-1,id:Symbol("dummy")},me={size:{width:0,height:0,minWidth:100,minHeight:100,maxWidth:1/0,maxHeight:1/0},responsive:!1,scale:1,minScale:.5,maxScale:2,backgroundColor:"#ffffff",gridAligned:!1,renderer:"canvas",eventHandlers:{drag:!0,zoom:!0,hover:!1,click:!1,rightClick:!1,resize:!1},bounds:{minX:-1/0,maxX:1/0,minY:-1/0,maxY:1/0},coordinates:{enabled:!1,shownScaleRange:{min:0,max:1/0}},cursor:{default:"default",move:"move"},debug:{enabled:!1,hud:{enabled:!1,topLeftCoordinates:!1,coordinates:!1,scale:!1,tilesInView:!1,fps:!1},eventHandlers:{click:!1,hover:!1,drag:!1,zoom:!1,resize:!1}}};function F(){let r=(0,C.useRef)(null),o=(0,C.useRef)(null),[,t]=(0,C.useState)(!1),i=(0,C.useRef)(!1),n=(0,C.useCallback)(e=>{r.current=e,i.current=e!==null,t(e!==null)},[]);return(0,C.useMemo)(()=>({_containerRef:o,_setInstance:n,get isReady(){return i.current},get instance(){return r.current},get images(){return r.current?.images},render(){r.current?.render()},getCenterCoords(){return r.current?.getCenterCoords()??{x:0,y:0}},getVisibleBounds(){return r.current?.getVisibleBounds()??{minX:0,maxX:0,minY:0,maxY:0}},updateCoords(e){r.current?.updateCoords(e)},goCoords(e,a,u,g){r.current?.goCoords(e,a,u,g)},resize(e,a,u,g){r.current?.resize(e,a,u,g)},getSize(){return r.current?.getSize()??{width:0,height:0}},getScale(){return r.current?.getScale()??1},setScale(e){r.current?.setScale(e)},zoomIn(e){r.current?.zoomIn(e)},zoomOut(e){r.current?.zoomOut(e)},getConfig(){return r.current?.getConfig()??me},setBounds(e){r.current?.setBounds(e)},setEventHandlers(e){r.current?.setEventHandlers(e)},addDrawFunction(e,a){return r.current?.addDrawFunction(e,a)??p},drawRect(e,a){return r.current?.drawRect(e,a)??p},drawStaticRect(e,a,u){return r.current?.drawStaticRect(e,a,u)??p},drawCircle(e,a){return r.current?.drawCircle(e,a)??p},drawStaticCircle(e,a,u){return r.current?.drawStaticCircle(e,a,u)??p},drawLine(e,a,u){return r.current?.drawLine(e,a,u)??p},drawText(e,a){return r.current?.drawText(e,a)??p},drawPath(e,a,u){return r.current?.drawPath(e,a,u)??p},drawImage(e,a){return r.current?.drawImage(e,a)??p},drawStaticImage(e,a,u){return r.current?.drawStaticImage(e,a,u)??p},drawGridLines(e,a,u,g){return r.current?.drawGridLines(e,a,u,g)??p},clearLayer(e){r.current?.clearLayer(e)},clearAll(){r.current?.clearAll()},clearStaticCache(e){r.current?.clearStaticCache(e)},removeDrawHandle(e){r.current?.removeDrawHandle(e)},loadImage(e,a){return r.current?r.current.images.load(e,a):Promise.reject(new Error("Engine not ready. Wait for isReady before loading images."))}}),[n])}var k=require("@canvas-tile-engine/core");0&&(module.exports={CanvasTileEngine,CanvasTileEngineCore,gridToSize,useCanvasTileEngine,useEngineContext});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/components/CanvasTileEngine.tsx","../src/context/EngineContext.tsx","../src/components/draw/Rect.tsx","../src/components/draw/Circle.tsx","../src/components/draw/Image.tsx","../src/components/draw/GridLines.tsx","../src/components/draw/Line.tsx","../src/components/draw/Text.tsx","../src/components/draw/Path.tsx","../src/components/draw/StaticRect.tsx","../src/components/draw/StaticCircle.tsx","../src/components/draw/StaticImage.tsx","../src/components/draw/DrawFunction.tsx","../src/hooks/useCanvasTileEngine.ts"],"sourcesContent":["// Main component\nexport { CanvasTileEngine } from \"./components\";\n\n// Draw components\nexport {\n type RectProps,\n type CircleProps,\n type ImageProps,\n type GridLinesProps,\n type LineProps,\n type TextProps,\n type PathProps,\n type StaticRectProps,\n type StaticCircleProps,\n type StaticImageProps,\n type DrawFunctionProps,\n} from \"./components\";\n\n// Hooks\nexport { useCanvasTileEngine } from \"./hooks\";\n\n// Context\nexport { useEngineContext, type EngineContextValue } from \"./context\";\n\n// Types\nexport type {\n CanvasTileEngineProps,\n CanvasTileEngineConfig,\n Coords,\n DrawObject,\n EventHandlers,\n onClickCallback,\n onHoverCallback,\n onMouseDownCallback,\n onMouseUpCallback,\n onMouseLeaveCallback,\n onDrawCallback,\n Rect,\n Line,\n Circle,\n Text,\n Path,\n ImageItem,\n} from \"./types\";\nexport type { EngineHandle } from \"./hooks/useCanvasTileEngine\";\n\n// Re-export core class and utilities\nexport { CanvasTileEngine as CanvasTileEngineCore, gridToSize } from \"@canvas-tile-engine/core\";\n","import { useEffect, useRef, useCallback, useMemo } from \"react\";\nimport { CanvasTileEngine as CanvasTileEngineCore } from \"@canvas-tile-engine/core\";\nimport { EngineContext, type EngineContextValue } from \"../context/EngineContext\";\nimport type { CanvasTileEngineProps } from \"../types\";\n\n// Import draw components for compound pattern\nimport { Rect } from \"./draw/Rect\";\nimport { Circle } from \"./draw/Circle\";\nimport { Image } from \"./draw/Image\";\nimport { GridLines } from \"./draw/GridLines\";\nimport { Line } from \"./draw/Line\";\nimport { Text } from \"./draw/Text\";\nimport { Path } from \"./draw/Path\";\nimport { StaticRect } from \"./draw/StaticRect\";\nimport { StaticCircle } from \"./draw/StaticCircle\";\nimport { StaticImage } from \"./draw/StaticImage\";\nimport { DrawFunction } from \"./draw/DrawFunction\";\n\n/**\n * React component that renders a CanvasTileEngine.\n * Supports both imperative API (via engine handle) and declarative API (via children).\n *\n * @example Declarative API with compound components\n * ```tsx\n * function App() {\n * const engine = useCanvasTileEngine();\n *\n * return (\n * <CanvasTileEngine engine={engine} config={config}>\n * <CanvasTileEngine.GridLines cellSize={50} layer={0} />\n * <CanvasTileEngine.Image items={imageItems} layer={1} />\n * <CanvasTileEngine.Circle items={markers} layer={2} />\n * </CanvasTileEngine>\n * );\n * }\n * ```\n *\n * @example Imperative API\n * ```tsx\n * function App() {\n * const engine = useCanvasTileEngine();\n *\n * useEffect(() => {\n * if (engine.isReady) {\n * engine.drawGridLines(50);\n * engine.render();\n * }\n * }, [engine.isReady]);\n *\n * return <CanvasTileEngine engine={engine} config={config} />;\n * }\n * ```\n */\nfunction CanvasTileEngineBase({\n engine,\n config,\n center = { x: 0, y: 0 },\n className,\n style,\n children,\n onCoordsChange,\n onClick,\n onRightClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n onZoom,\n}: CanvasTileEngineProps) {\n // Stable callback refs\n const callbacksRef = useRef({\n onCoordsChange,\n onClick,\n onRightClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n onZoom,\n });\n\n // Update callback refs\n useEffect(() => {\n callbacksRef.current = {\n onCoordsChange,\n onClick,\n onRightClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n onZoom,\n };\n });\n\n // Debounced render - multiple draw components calling requestRender\n // in the same frame will trigger only one render\n const rafIdRef = useRef<number | null>(null);\n const requestRender = useCallback(() => {\n if (rafIdRef.current !== null) return;\n rafIdRef.current = requestAnimationFrame(() => {\n rafIdRef.current = null;\n engine.render();\n });\n }, [engine]);\n\n // Cleanup RAF on unmount\n useEffect(() => {\n return () => {\n if (rafIdRef.current !== null) {\n cancelAnimationFrame(rafIdRef.current);\n }\n };\n }, []);\n\n // Context value\n const contextValue = useMemo<EngineContextValue>(\n () => ({\n engine,\n requestRender,\n }),\n [engine, requestRender]\n );\n\n // Initialize engine when component mounts\n // Note: config and center are intentionally not in deps - we only want to create the engine once\n // Callbacks are accessed via callbacksRef which is always up-to-date\n useEffect(() => {\n const container = engine._containerRef.current;\n\n if (!container) {\n return;\n }\n\n // Create engine instance\n const instance = new CanvasTileEngineCore(container, config, center);\n\n // Set up callbacks using stable refs\n instance.onCoordsChange = (coords) => callbacksRef.current.onCoordsChange?.(coords);\n instance.onClick = (...args) => callbacksRef.current.onClick?.(...args);\n instance.onRightClick = (...args) => callbacksRef.current.onRightClick?.(...args);\n instance.onHover = (...args) => callbacksRef.current.onHover?.(...args);\n instance.onMouseDown = (...args) => callbacksRef.current.onMouseDown?.(...args);\n instance.onMouseUp = (...args) => callbacksRef.current.onMouseUp?.(...args);\n instance.onMouseLeave = (...args) => callbacksRef.current.onMouseLeave?.(...args);\n instance.onDraw = (...args) => callbacksRef.current.onDraw?.(...args);\n instance.onResize = () => callbacksRef.current.onResize?.();\n instance.onZoom = (scale) => callbacksRef.current.onZoom?.(scale);\n\n // Attach to handle\n engine._setInstance(instance);\n\n // Initial render\n instance.render();\n\n // Cleanup on unmount\n return () => {\n instance.destroy();\n engine._setInstance(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [engine]);\n\n return (\n <EngineContext.Provider value={contextValue}>\n <div\n ref={engine._containerRef}\n className={className}\n style={{\n ...style,\n }}\n >\n <canvas />\n </div>\n {/* Render children only when engine is ready */}\n {engine.isReady && children}\n </EngineContext.Provider>\n );\n}\n\n// Compound component pattern - attach draw components as static properties\nexport const CanvasTileEngine = Object.assign(CanvasTileEngineBase, {\n Rect,\n Circle,\n Image,\n GridLines,\n Line,\n Text,\n Path,\n StaticRect,\n StaticCircle,\n StaticImage,\n DrawFunction,\n});\n","import { createContext, useContext } from \"react\";\nimport type { EngineHandle } from \"../hooks/useCanvasTileEngine\";\n\nexport interface EngineContextValue {\n engine: EngineHandle;\n /** Request a re-render of the canvas */\n requestRender: () => void;\n}\n\nexport const EngineContext = createContext<EngineContextValue | null>(null);\n\n/**\n * Hook to access the engine context from child components.\n * Must be used within a CanvasTileEngine component.\n */\nexport function useEngineContext(): EngineContextValue {\n const context = useContext(EngineContext);\n\n if (!context) {\n throw new Error(\"useEngineContext must be used within a CanvasTileEngine component\");\n }\n\n return context;\n}\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { DrawObject } from \"@canvas-tile-engine/core\";\n\nexport interface RectProps {\n items: DrawObject | DrawObject[];\n layer?: number;\n}\n\n/**\n * Draws rectangles on the canvas.\n */\nexport const Rect = memo(function Rect({ items, layer = 1 }: RectProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawRect(items, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, items, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { DrawObject } from \"@canvas-tile-engine/core\";\n\nexport interface CircleProps {\n items: DrawObject | DrawObject[];\n layer?: number;\n}\n\n/**\n * Draws circles on the canvas.\n */\nexport const Circle = memo(function Circle({ items, layer = 1 }: CircleProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawCircle(items, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, items, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport { ImageItem } from \"@canvas-tile-engine/core\";\n\nexport interface ImageProps {\n items: ImageItem | ImageItem[];\n layer?: number;\n}\n\n/**\n * Draws images on the canvas.\n */\nexport const Image = memo(function Image({ items, layer = 1 }: ImageProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawImage(items, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, items, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\n\nexport interface GridLinesProps {\n cellSize: number;\n lineWidth?: number;\n strokeStyle?: string;\n layer?: number;\n}\n\n/**\n * Draws grid lines on the canvas.\n * Multiple GridLines can share the same layer (additive drawing).\n */\nexport const GridLines = memo(function GridLines({ cellSize, lineWidth = 1, strokeStyle = \"black\", layer = 0 }: GridLinesProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawGridLines(cellSize, lineWidth, strokeStyle, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, cellSize, lineWidth, strokeStyle, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Coords } from \"@canvas-tile-engine/core\";\n\nexport interface LineProps {\n items: { from: Coords; to: Coords } | { from: Coords; to: Coords }[];\n style?: { strokeStyle?: string; lineWidth?: number };\n layer?: number;\n}\n\n/**\n * Draws lines on the canvas.\n */\nexport const Line = memo(function Line({ items, style, layer = 1 }: LineProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawLine(items, style, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, items, style, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Coords } from \"@canvas-tile-engine/core\";\n\nexport interface TextProps {\n items: { coords: Coords; text: string } | { coords: Coords; text: string }[];\n style?: {\n fillStyle?: string;\n font?: string;\n textAlign?: CanvasTextAlign;\n textBaseline?: CanvasTextBaseline;\n };\n layer?: number;\n}\n\n/**\n * Draws text on the canvas.\n */\nexport const Text = memo(function Text({ items, style, layer = 2 }: TextProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawText(items, style, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, items, style, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Coords } from \"@canvas-tile-engine/core\";\n\nexport interface PathProps {\n items: Coords[] | Coords[][];\n style?: { strokeStyle?: string; lineWidth?: number };\n layer?: number;\n}\n\n/**\n * Draws paths/polylines on the canvas.\n */\nexport const Path = memo(function Path({ items, style, layer = 1 }: PathProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawPath(items, style, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, items, style, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, useRef, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { DrawObject } from \"@canvas-tile-engine/core\";\n\nexport interface StaticRectProps {\n items: DrawObject[];\n cacheKey: string;\n layer?: number;\n}\n\n/**\n * Draws static rectangles with caching for performance.\n * Ideal for large datasets that don't change frequently.\n */\nexport const StaticRect = memo(function StaticRect({ items, cacheKey, layer = 1 }: StaticRectProps) {\n const { engine, requestRender } = useEngineContext();\n const prevCacheKeyRef = useRef<string>(cacheKey);\n\n useEffect(() => {\n if (items.length === 0) {\n return;\n }\n\n // Clear previous cache if cacheKey changed\n if (prevCacheKeyRef.current !== cacheKey) {\n engine.clearStaticCache(prevCacheKeyRef.current);\n prevCacheKeyRef.current = cacheKey;\n }\n\n const handle = engine.drawStaticRect(items, cacheKey, layer);\n requestRender();\n\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, items, cacheKey, layer, requestRender]);\n\n // Cleanup cache on unmount\n useEffect(() => {\n return () => {\n engine.clearStaticCache(cacheKey);\n };\n }, [engine, cacheKey]);\n\n return null;\n});\n","import { useEffect, useRef, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { DrawObject } from \"@canvas-tile-engine/core\";\n\nexport interface StaticCircleProps {\n items: DrawObject[];\n cacheKey: string;\n layer?: number;\n}\n\n/**\n * Draws static circles with caching for performance.\n */\nexport const StaticCircle = memo(function StaticCircle({ items, cacheKey, layer = 1 }: StaticCircleProps) {\n const { engine, requestRender } = useEngineContext();\n const prevCacheKeyRef = useRef<string>(cacheKey);\n\n useEffect(() => {\n if (items.length === 0) {\n return;\n }\n\n if (prevCacheKeyRef.current !== cacheKey) {\n engine.clearStaticCache(prevCacheKeyRef.current);\n prevCacheKeyRef.current = cacheKey;\n }\n\n const handle = engine.drawStaticCircle(items, cacheKey, layer);\n requestRender();\n\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, items, cacheKey, layer, requestRender]);\n\n useEffect(() => {\n return () => {\n engine.clearStaticCache(cacheKey);\n };\n }, [engine, cacheKey]);\n\n return null;\n});\n","import { useEffect, useRef, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport { ImageItem } from \"@canvas-tile-engine/core\";\n\nexport interface StaticImageProps {\n items: ImageItem[];\n cacheKey: string;\n layer?: number;\n}\n\n/**\n * Draws static images with caching for performance.\n * Ideal for terrain tiles or static decorations.\n */\nexport const StaticImage = memo(function StaticImage({ items, cacheKey, layer = 1 }: StaticImageProps) {\n const { engine, requestRender } = useEngineContext();\n const prevCacheKeyRef = useRef<string>(cacheKey);\n\n useEffect(() => {\n if (items.length === 0) {\n return;\n }\n\n if (prevCacheKeyRef.current !== cacheKey) {\n engine.clearStaticCache(prevCacheKeyRef.current);\n prevCacheKeyRef.current = cacheKey;\n }\n\n const handle = engine.drawStaticImage(items, cacheKey, layer);\n requestRender();\n\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, items, cacheKey, layer, requestRender]);\n\n useEffect(() => {\n return () => {\n engine.clearStaticCache(cacheKey);\n };\n }, [engine, cacheKey]);\n\n return null;\n});\n","import { useEffect, useRef, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { CanvasTileEngineConfig, Coords } from \"@canvas-tile-engine/core\";\n\nexport interface DrawFunctionProps {\n /** The draw function to execute */\n children: (ctx: CanvasRenderingContext2D, coords: Coords, config: Required<CanvasTileEngineConfig>) => void;\n layer?: number;\n}\n\n/**\n * Custom draw function component.\n * Allows arbitrary canvas drawing within the engine's render cycle.\n * Multiple DrawFunction components can share the same layer (additive drawing).\n *\n * @example\n * ```tsx\n * <DrawFunction layer={3}>\n * {(ctx, coords, config) => {\n * ctx.fillStyle = \"red\";\n * ctx.fillRect(config.size.width / 2 - 5, config.size.height / 2 - 5, 10, 10);\n * }}\n * </DrawFunction>\n * ```\n */\nexport const DrawFunction = memo(function DrawFunction({ children, layer = 1 }: DrawFunctionProps) {\n const { engine, requestRender } = useEngineContext();\n const fnRef = useRef(children);\n\n // Keep function ref updated\n useEffect(() => {\n fnRef.current = children;\n });\n\n useEffect(() => {\n const handle = engine.addDrawFunction((ctx, coords, config) => {\n fnRef.current(ctx, coords, config);\n }, layer);\n requestRender();\n\n return () => {\n if (handle) {\n engine.removeLayerHandle(handle);\n }\n };\n }, [engine, layer, requestRender]);\n\n return null;\n});\n","import { useRef, useCallback, useState, useMemo } from \"react\";\nimport type {\n CanvasTileEngine as CanvasTileEngineCore,\n CanvasTileEngineConfig,\n Coords,\n DrawObject,\n EventHandlers,\n LayerHandle,\n} from \"@canvas-tile-engine/core\";\n\n/** Dummy handle returned when engine is not ready */\nconst DUMMY_LAYER_HANDLE: LayerHandle = { layer: -1, id: Symbol(\"dummy\") };\n\n/** Default config when engine is not ready */\nconst DEFAULT_CONFIG: Required<CanvasTileEngineConfig> = {\n size: { width: 0, height: 0, minWidth: 100, minHeight: 100, maxWidth: Infinity, maxHeight: Infinity },\n responsive: false,\n scale: 1,\n minScale: 0.5,\n maxScale: 2,\n backgroundColor: \"#ffffff\",\n gridAligned: false,\n renderer: \"canvas\",\n eventHandlers: {\n drag: true,\n zoom: true,\n hover: false,\n click: false,\n rightClick: false,\n resize: false,\n },\n bounds: {\n minX: -Infinity,\n maxX: Infinity,\n minY: -Infinity,\n maxY: Infinity,\n },\n coordinates: {\n enabled: false,\n shownScaleRange: { min: 0, max: Infinity },\n },\n cursor: {\n default: \"default\",\n move: \"move\",\n },\n debug: {\n enabled: false,\n hud: {\n enabled: false,\n topLeftCoordinates: false,\n coordinates: false,\n scale: false,\n tilesInView: false,\n fps: false,\n },\n eventHandlers: {\n click: false,\n hover: false,\n drag: false,\n zoom: false,\n resize: false,\n },\n },\n};\n\n/**\n * Engine handle returned by useCanvasTileEngine hook.\n * Provides access to engine methods with proper typing.\n *\n * All methods return default/dummy values when engine is not ready,\n * allowing safe usage without null checks.\n */\nexport interface EngineHandle {\n /** @internal - Used by CanvasTileEngine component */\n readonly _containerRef: React.RefObject<HTMLDivElement>;\n /** @internal - Used by CanvasTileEngine component */\n _setInstance: (engine: CanvasTileEngineCore | null) => void;\n\n /** Whether the engine is ready (mounted and initialized) */\n readonly isReady: boolean;\n\n /** The underlying engine instance (null until component mounts) */\n readonly instance: CanvasTileEngineCore | null;\n\n /** Render a frame */\n render(): void;\n\n /** Get current center coordinates */\n getCenterCoords(): Coords;\n\n /** Get visible world coordinate bounds of the viewport */\n getVisibleBounds(): { minX: number; maxX: number; minY: number; maxY: number };\n\n /** Update center coordinates */\n updateCoords(center: Coords): void;\n\n /** Animate to target coordinates */\n goCoords(x: number, y: number, durationMs?: number, onComplete?: () => void): void;\n\n /** Resize the canvas */\n resize(width: number, height: number, durationMs?: number, onComplete?: () => void): void;\n\n /** Get current canvas size */\n getSize(): { width: number; height: number };\n\n /** Get current canvas scale */\n getScale(): number;\n\n /** Set the canvas scale directly, clamped to min/max bounds. */\n setScale(newScale: number): void;\n\n /** Zoom in by a factor (default: 1.5) */\n zoomIn(factor?: number): void;\n\n /** Zoom out by a factor (default: 1.5) */\n zoomOut(factor?: number): void;\n\n /** Get current config */\n getConfig(): Required<CanvasTileEngineConfig>;\n\n /** Set map boundaries */\n setBounds(bounds: { minX: number; maxX: number; minY: number; maxY: number }): void;\n\n /** Dynamically update event handlers at runtime */\n setEventHandlers(handlers: Partial<EventHandlers>): void;\n\n /** Draw rectangles */\n drawRect(items: DrawObject | DrawObject[], layer?: number): LayerHandle;\n\n /** Draw static rectangles (cached) */\n drawStaticRect(items: DrawObject[], cacheKey: string, layer?: number): LayerHandle;\n\n /** Draw circles */\n drawCircle(items: DrawObject | DrawObject[], layer?: number): LayerHandle;\n\n /** Draw static circles (cached) */\n drawStaticCircle(items: DrawObject[], cacheKey: string, layer?: number): LayerHandle;\n\n /** Draw lines */\n drawLine(\n items: { from: Coords; to: Coords } | { from: Coords; to: Coords }[],\n style?: { strokeStyle?: string; lineWidth?: number },\n layer?: number\n ): LayerHandle;\n\n /** Draw text */\n drawText(\n items: { coords: Coords; text: string } | { coords: Coords; text: string }[],\n style?: { fillStyle?: string; font?: string; textAlign?: CanvasTextAlign; textBaseline?: CanvasTextBaseline },\n layer?: number\n ): LayerHandle;\n\n /** Draw paths/polylines */\n drawPath(\n items: Coords[] | Coords[][],\n style?: { strokeStyle?: string; lineWidth?: number },\n layer?: number\n ): LayerHandle;\n\n /** Draw images */\n drawImage(\n items:\n | (Omit<DrawObject, \"style\"> & { img: HTMLImageElement })\n | (Omit<DrawObject, \"style\"> & { img: HTMLImageElement })[],\n layer?: number\n ): LayerHandle;\n\n /** Draw static images (cached) */\n drawStaticImage(\n items: (Omit<DrawObject, \"style\"> & { img: HTMLImageElement })[],\n cacheKey: string,\n layer?: number\n ): LayerHandle;\n\n /** Draw grid lines */\n drawGridLines(cellSize: number, lineWidth?: number, strokeStyle?: string, layer?: number): LayerHandle;\n\n /** Add custom draw function */\n addDrawFunction(\n fn: (ctx: CanvasRenderingContext2D, coords: Coords, config: Required<CanvasTileEngineConfig>) => void,\n layer?: number\n ): LayerHandle;\n\n /** Clear a specific layer */\n clearLayer(layer: number): void;\n\n /** Clear all layers */\n clearAll(): void;\n\n /** Clear static cache */\n clearStaticCache(cacheKey?: string): void;\n\n /** Remove a previously registered draw callback */\n removeLayerHandle(handle: LayerHandle): void;\n\n /** Image loader instance (undefined until engine mounts) */\n readonly images: CanvasTileEngineCore[\"images\"] | undefined;\n}\n\n/**\n * React hook that creates an engine handle for use with CanvasTileEngine component.\n *\n * @returns Engine handle to pass to CanvasTileEngine component\n *\n * @example\n * ```tsx\n * function App() {\n * const mainMap = useCanvasTileEngine();\n * const miniMap = useCanvasTileEngine();\n *\n * useEffect(() => {\n * if (mainMap.isReady && miniMap.isReady) {\n * // Both engines are ready, draw items\n * mainMap.drawGridLines(50);\n * mainMap.render();\n * }\n * }, [mainMap.isReady, miniMap.isReady]);\n *\n * return (\n * <>\n * <CanvasTileEngine engine={mainMap} config={...} />\n * <CanvasTileEngine engine={miniMap} config={...} />\n * </>\n * );\n * }\n * ```\n */\nexport function useCanvasTileEngine(): EngineHandle {\n const instanceRef = useRef<CanvasTileEngineCore | null>(null);\n const containerRef = useRef<HTMLDivElement>(null!);\n // _isReady state is only used to trigger re-renders, actual value is read from isReadyRef\n const [, setIsReady] = useState(false);\n // Keep isReady in a ref so the handle getter can read it without recreating handle\n const isReadyRef = useRef(false);\n\n const setInstance = useCallback((engine: CanvasTileEngineCore | null) => {\n instanceRef.current = engine;\n isReadyRef.current = engine !== null;\n setIsReady(engine !== null);\n }, []);\n\n // Create stable handle object using useMemo\n // Note: isReady is NOT in deps - we read from isReadyRef to keep handle stable\n const handle = useMemo<EngineHandle>(\n () => ({\n _containerRef: containerRef,\n _setInstance: setInstance,\n\n get isReady() {\n return isReadyRef.current;\n },\n\n get instance() {\n return instanceRef.current;\n },\n\n get images() {\n return instanceRef.current?.images;\n },\n\n render() {\n instanceRef.current?.render();\n },\n\n getCenterCoords() {\n return instanceRef.current?.getCenterCoords() ?? { x: 0, y: 0 };\n },\n\n getVisibleBounds() {\n return instanceRef.current?.getVisibleBounds() ?? { minX: 0, maxX: 0, minY: 0, maxY: 0 };\n },\n\n updateCoords(center: Coords) {\n instanceRef.current?.updateCoords(center);\n },\n\n goCoords(x: number, y: number, durationMs?: number, onComplete?: () => void) {\n instanceRef.current?.goCoords(x, y, durationMs, onComplete);\n },\n\n resize(width: number, height: number, durationMs?: number, onComplete?: () => void) {\n instanceRef.current?.resize(width, height, durationMs, onComplete);\n },\n\n getSize() {\n return instanceRef.current?.getSize() ?? { width: 0, height: 0 };\n },\n\n getScale() {\n return instanceRef.current?.getScale() ?? 1;\n },\n\n setScale(newScale: number) {\n instanceRef.current?.setScale(newScale);\n },\n\n zoomIn(factor?: number) {\n instanceRef.current?.zoomIn(factor);\n },\n\n zoomOut(factor?: number) {\n instanceRef.current?.zoomOut(factor);\n },\n\n getConfig() {\n return instanceRef.current?.getConfig() ?? DEFAULT_CONFIG;\n },\n\n setBounds(bounds) {\n instanceRef.current?.setBounds(bounds);\n },\n\n setEventHandlers(handlers) {\n instanceRef.current?.setEventHandlers(handlers);\n },\n\n drawRect(items, layer) {\n return instanceRef.current?.drawRect(items, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n drawStaticRect(items, cacheKey, layer) {\n return instanceRef.current?.drawStaticRect(items, cacheKey, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n drawCircle(items, layer) {\n return instanceRef.current?.drawCircle(items, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n drawStaticCircle(items, cacheKey, layer) {\n return instanceRef.current?.drawStaticCircle(items, cacheKey, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n drawLine(items, style, layer) {\n return instanceRef.current?.drawLine(items, style, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n drawText(items, style, layer) {\n return instanceRef.current?.drawText(items, style, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n drawPath(items, style, layer) {\n return instanceRef.current?.drawPath(items, style, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n drawImage(items, layer) {\n return instanceRef.current?.drawImage(items, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n drawStaticImage(items, cacheKey, layer) {\n return instanceRef.current?.drawStaticImage(items, cacheKey, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n drawGridLines(cellSize, lineWidth, strokeStyle, layer) {\n return (\n instanceRef.current?.drawGridLines(cellSize, lineWidth, strokeStyle, layer) ?? DUMMY_LAYER_HANDLE\n );\n },\n\n addDrawFunction(fn, layer) {\n return instanceRef.current?.addDrawFunction(fn, layer) ?? DUMMY_LAYER_HANDLE;\n },\n\n clearLayer(layer) {\n instanceRef.current?.clearLayer(layer);\n },\n\n clearAll() {\n instanceRef.current?.clearAll();\n },\n\n clearStaticCache(cacheKey) {\n instanceRef.current?.clearStaticCache(cacheKey);\n },\n\n removeLayerHandle(handle) {\n instanceRef.current?.removeLayerHandle(handle);\n },\n }),\n [setInstance]\n );\n\n return handle;\n}\n"],"mappings":"mbAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,sBAAAE,EAAA,gGAAAC,EAAA,qBAAAC,IAAA,eAAAC,GAAAL,ICAA,IAAAM,EAAwD,iBACxDC,GAAyD,oCCDzD,IAAAC,EAA0C,iBAS7BC,KAAgB,iBAAyC,IAAI,EAMnE,SAASC,GAAuC,CACnD,IAAMC,KAAU,cAAWF,CAAa,EAExC,GAAI,CAACE,EACD,MAAM,IAAI,MAAM,mEAAmE,EAGvF,OAAOA,CACX,CCvBA,IAAAC,EAAgC,iBAYzB,IAAMC,KAAO,QAAK,SAAc,CAAE,MAAAC,EAAO,MAAAC,EAAQ,CAAE,EAAc,CACpE,GAAM,CAAE,OAAAC,EAAQ,cAAAC,CAAc,EAAIC,EAAiB,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AUD,CAAK,GAAKrB,CAC5E,EAEA,SAASoB,EAAOG,EAAOF,EAAO,CAC1B,OAAOlB,EAAY,SAAS,SAASiB,EAAOG,EAAOF,CAAK,GAAKrB,CACjE,EAEA,SAASoB,EAAOG,EAAOF,EAAO,CAC1B,OAAOlB,EAAY,SAAS,SAASiB,EAAOG,EAAOF,CAAK,GAAKrB,CACjE,EAEA,SAASoB,EAAOG,EAAOF,EAAO,CAC1B,OAAOlB,EAAY,SAAS,SAASiB,EAAOG,EAAOF,CAAK,GAAKrB,CACjE,EAEA,UAAUoB,EAAOC,EAAO,CACpB,OAAOlB,EAAY,SAAS,UAAUiB,EAAOC,CAAK,GAAKrB,CAC3D,EAEA,gBAAgBoB,EAAOE,EAAUD,EAAO,CACpC,OAAOlB,EAAY,SAAS,gBAAgBiB,EAAOE,EAAUD,CAAK,GAAKrB,CAC3E,EAEA,cAAcwB,EAAUC,EAAWC,EAAaL,EAAO,CACnD,OACIlB,EAAY,SAAS,cAAcqB,EAAUC,EAAWC,EAAaL,CAAK,GAAKrB,CAEvF,EAEA,gBAAgB2B,EAAIN,EAAO,CACvB,OAAOlB,EAAY,SAAS,gBAAgBwB,EAAIN,CAAK,GAAKrB,CAC9D,EAEA,WAAWqB,EAAO,CACdlB,EAAY,SAAS,WAAWkB,CAAK,CACzC,EAEA,UAAW,CACPlB,EAAY,SAAS,SAAS,CAClC,EAEA,iBAAiBmB,EAAU,CACvBnB,EAAY,SAAS,iBAAiBmB,CAAQ,CAClD,EAEA,kBAAkBM,EAAQ,CACtBzB,EAAY,SAAS,kBAAkByB,CAAM,CACjD,CACJ,GACA,CAACrB,CAAW,CAChB,CAGJ,Cd/UA,IAAAsB,EAAqE","names":["index_exports","__export","CanvasTileEngine","useCanvasTileEngine","useEngineContext","__toCommonJS","import_react","import_core","import_react","EngineContext","useEngineContext","context","import_react","Rect","items","layer","engine","requestRender","useEngineContext","handle","import_react","Circle","items","layer","engine","requestRender","useEngineContext","handle","import_react","Image","items","layer","engine","requestRender","useEngineContext","handle","import_react","GridLines","cellSize","lineWidth","strokeStyle","layer","engine","requestRender","useEngineContext","handle","import_react","Line","items","style","layer","engine","requestRender","useEngineContext","handle","import_react","Text","items","style","layer","engine","requestRender","useEngineContext","handle","import_react","Path","items","style","layer","engine","requestRender","useEngineContext","handle","import_react","StaticRect","items","cacheKey","layer","engine","requestRender","useEngineContext","prevCacheKeyRef","handle","import_react","StaticCircle","items","cacheKey","layer","engine","requestRender","useEngineContext","prevCacheKeyRef","handle","import_react","StaticImage","items","cacheKey","layer","engine","requestRender","useEngineContext","prevCacheKeyRef","handle","import_react","DrawFunction","children","layer","engine","requestRender","useEngineContext","fnRef","handle","ctx","coords","config","import_jsx_runtime","CanvasTileEngineBase","engine","config","center","className","style","children","onCoordsChange","onClick","onRightClick","onHover","onMouseDown","onMouseUp","onMouseLeave","onDraw","onResize","onZoom","callbacksRef","rafIdRef","requestRender","contextValue","container","instance","CanvasTileEngineCore","coords","args","scale","EngineContext","CanvasTileEngine","Rect","Circle","Image","GridLines","Line","Text","Path","StaticRect","StaticCircle","StaticImage","DrawFunction","import_react","DUMMY_LAYER_HANDLE","DEFAULT_CONFIG","useCanvasTileEngine","instanceRef","containerRef","setIsReady","isReadyRef","setInstance","engine","center","x","y","durationMs","onComplete","width","height","newScale","factor","bounds","handlers","items","layer","cacheKey","style","cellSize","lineWidth","strokeStyle","fn","handle","import_core"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/components/CanvasTileEngine.tsx","../src/context/EngineContext.tsx","../src/components/draw/Rect.tsx","../src/components/draw/Circle.tsx","../src/components/draw/Image.tsx","../src/components/draw/GridLines.tsx","../src/components/draw/Line.tsx","../src/components/draw/Text.tsx","../src/components/draw/Path.tsx","../src/components/draw/StaticRect.tsx","../src/components/draw/StaticCircle.tsx","../src/components/draw/StaticImage.tsx","../src/components/draw/DrawFunction.tsx","../src/hooks/useCanvasTileEngine.ts"],"sourcesContent":["// Main component\nexport { CanvasTileEngine } from \"./components\";\n\n// Draw components\nexport {\n type RectProps,\n type CircleProps,\n type ImageProps,\n type GridLinesProps,\n type LineProps,\n type TextProps,\n type PathProps,\n type StaticRectProps,\n type StaticCircleProps,\n type StaticImageProps,\n type DrawFunctionProps,\n} from \"./components\";\n\n// Hooks\nexport { useCanvasTileEngine } from \"./hooks\";\n\n// Context\nexport { useEngineContext, type EngineContextValue } from \"./context\";\n\n// Types\nexport type {\n CanvasTileEngineProps,\n CanvasTileEngineConfig,\n Coords,\n DrawObject,\n EventHandlers,\n onClickCallback,\n onHoverCallback,\n onMouseDownCallback,\n onMouseUpCallback,\n onMouseLeaveCallback,\n onDrawCallback,\n Rect,\n Line,\n Circle,\n Text,\n Path,\n ImageItem,\n} from \"./types\";\nexport type { EngineHandle } from \"./hooks/useCanvasTileEngine\";\n\n// Re-export core class and utilities\nexport { CanvasTileEngine as CanvasTileEngineCore, gridToSize } from \"@canvas-tile-engine/core\";\n","import { useEffect, useRef, useCallback, useMemo } from \"react\";\nimport { CanvasTileEngine as CanvasTileEngineCore } from \"@canvas-tile-engine/core\";\nimport { EngineContext, type EngineContextValue } from \"../context/EngineContext\";\nimport type { CanvasTileEngineProps } from \"../types\";\n\n// Import draw components for compound pattern\nimport { Rect } from \"./draw/Rect\";\nimport { Circle } from \"./draw/Circle\";\nimport { Image } from \"./draw/Image\";\nimport { GridLines } from \"./draw/GridLines\";\nimport { Line } from \"./draw/Line\";\nimport { Text } from \"./draw/Text\";\nimport { Path } from \"./draw/Path\";\nimport { StaticRect } from \"./draw/StaticRect\";\nimport { StaticCircle } from \"./draw/StaticCircle\";\nimport { StaticImage } from \"./draw/StaticImage\";\nimport { DrawFunction } from \"./draw/DrawFunction\";\n\n/**\n * React component that renders a CanvasTileEngine.\n * Supports both imperative API (via engine handle) and declarative API (via children).\n *\n * @example Declarative API with compound components\n * ```tsx\n * function App() {\n * const engine = useCanvasTileEngine();\n *\n * return (\n * <CanvasTileEngine engine={engine} config={config}>\n * <CanvasTileEngine.GridLines cellSize={50} layer={0} />\n * <CanvasTileEngine.Image items={imageItems} layer={1} />\n * <CanvasTileEngine.Circle items={markers} layer={2} />\n * </CanvasTileEngine>\n * );\n * }\n * ```\n *\n * @example Imperative API\n * ```tsx\n * function App() {\n * const engine = useCanvasTileEngine();\n *\n * useEffect(() => {\n * if (engine.isReady) {\n * engine.drawGridLines(50);\n * engine.render();\n * }\n * }, [engine.isReady]);\n *\n * return <CanvasTileEngine engine={engine} config={config} />;\n * }\n * ```\n */\nfunction CanvasTileEngineBase({\n engine,\n renderer,\n config,\n center = { x: 0, y: 0 },\n className,\n style,\n children,\n onCoordsChange,\n onClick,\n onRightClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n onZoom,\n}: CanvasTileEngineProps) {\n // Stable callback refs\n const callbacksRef = useRef({\n onCoordsChange,\n onClick,\n onRightClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n onZoom,\n });\n\n // Update callback refs\n useEffect(() => {\n callbacksRef.current = {\n onCoordsChange,\n onClick,\n onRightClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n onZoom,\n };\n });\n\n // Debounced render - multiple draw components calling requestRender\n // in the same frame will trigger only one render\n const rafIdRef = useRef<number | null>(null);\n const requestRender = useCallback(() => {\n if (rafIdRef.current !== null) return;\n rafIdRef.current = requestAnimationFrame(() => {\n rafIdRef.current = null;\n engine.render();\n });\n }, [engine]);\n\n // Cleanup RAF on unmount\n useEffect(() => {\n return () => {\n if (rafIdRef.current !== null) {\n cancelAnimationFrame(rafIdRef.current);\n }\n };\n }, []);\n\n // Context value\n const contextValue = useMemo<EngineContextValue>(\n () => ({\n engine,\n requestRender,\n }),\n [engine, requestRender]\n );\n\n // Initialize engine when component mounts\n // Note: config and center are intentionally not in deps - we only want to create the engine once\n // Callbacks are accessed via callbacksRef which is always up-to-date\n useEffect(() => {\n const container = engine._containerRef.current;\n\n if (!container) {\n return;\n }\n\n // Create engine instance\n const instance = new CanvasTileEngineCore(container, config, renderer, center);\n\n // Set up callbacks using stable refs\n instance.onCoordsChange = (coords) => callbacksRef.current.onCoordsChange?.(coords);\n instance.onClick = (...args) => callbacksRef.current.onClick?.(...args);\n instance.onRightClick = (...args) => callbacksRef.current.onRightClick?.(...args);\n instance.onHover = (...args) => callbacksRef.current.onHover?.(...args);\n instance.onMouseDown = (...args) => callbacksRef.current.onMouseDown?.(...args);\n instance.onMouseUp = (...args) => callbacksRef.current.onMouseUp?.(...args);\n instance.onMouseLeave = (...args) => callbacksRef.current.onMouseLeave?.(...args);\n instance.onDraw = (...args) => callbacksRef.current.onDraw?.(...args);\n instance.onResize = () => callbacksRef.current.onResize?.();\n instance.onZoom = (scale) => callbacksRef.current.onZoom?.(scale);\n\n // Attach to handle\n engine._setInstance(instance);\n\n // Initial render\n instance.render();\n\n // Cleanup on unmount\n return () => {\n instance.destroy();\n engine._setInstance(null);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [engine]);\n\n return (\n <EngineContext.Provider value={contextValue}>\n <div\n ref={engine._containerRef}\n className={className}\n style={{\n ...style,\n }}\n >\n <canvas />\n </div>\n {/* Render children only when engine is ready */}\n {engine.isReady && children}\n </EngineContext.Provider>\n );\n}\n\n// Compound component pattern - attach draw components as static properties\nexport const CanvasTileEngine = Object.assign(CanvasTileEngineBase, {\n Rect,\n Circle,\n Image,\n GridLines,\n Line,\n Text,\n Path,\n StaticRect,\n StaticCircle,\n StaticImage,\n DrawFunction,\n});\n","import { createContext, useContext } from \"react\";\nimport type { EngineHandle } from \"../hooks/useCanvasTileEngine\";\n\nexport interface EngineContextValue {\n engine: EngineHandle;\n /** Request a re-render of the canvas */\n requestRender: () => void;\n}\n\nexport const EngineContext = createContext<EngineContextValue | null>(null);\n\n/**\n * Hook to access the engine context from child components.\n * Must be used within a CanvasTileEngine component.\n */\nexport function useEngineContext(): EngineContextValue {\n const context = useContext(EngineContext);\n\n if (!context) {\n throw new Error(\"useEngineContext must be used within a CanvasTileEngine component\");\n }\n\n return context;\n}\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Rect as RectType } from \"@canvas-tile-engine/core\";\n\nexport interface RectProps {\n items: RectType | RectType[];\n layer?: number;\n}\n\n/**\n * Draws rectangles on the canvas.\n */\nexport const Rect = memo(function Rect({ items, layer = 1 }: RectProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawRect(items, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, items, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Circle as CircleType } from \"@canvas-tile-engine/core\";\n\nexport interface CircleProps {\n items: CircleType | CircleType[];\n layer?: number;\n}\n\n/**\n * Draws circles on the canvas.\n */\nexport const Circle = memo(function Circle({ items, layer = 1 }: CircleProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawCircle(items, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, items, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport { ImageItem } from \"@canvas-tile-engine/core\";\n\nexport interface ImageProps {\n items: ImageItem | ImageItem[];\n layer?: number;\n}\n\n/**\n * Draws images on the canvas.\n */\nexport const Image = memo(function Image({ items, layer = 1 }: ImageProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawImage(items, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, items, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\n\nexport interface GridLinesProps {\n cellSize: number;\n lineWidth?: number;\n strokeStyle?: string;\n layer?: number;\n}\n\n/**\n * Draws grid lines on the canvas.\n * Multiple GridLines can share the same layer (additive drawing).\n */\nexport const GridLines = memo(function GridLines({ cellSize, lineWidth = 1, strokeStyle = \"black\", layer = 0 }: GridLinesProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawGridLines(cellSize, lineWidth, strokeStyle, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, cellSize, lineWidth, strokeStyle, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Line as LineType } from \"@canvas-tile-engine/core\";\n\nexport interface LineProps {\n items: LineType | LineType[];\n style?: { strokeStyle?: string; lineWidth?: number };\n layer?: number;\n}\n\n/**\n * Draws lines on the canvas.\n */\nexport const Line = memo(function Line({ items, style, layer = 1 }: LineProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawLine(items, style, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, items, style, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Text as TextType } from \"@canvas-tile-engine/core\";\n\nexport interface TextProps {\n items: TextType | TextType[];\n layer?: number;\n}\n\n/**\n * Draws text on the canvas.\n * @example\n * ```tsx\n * <Text\n * items={{\n * x: 0,\n * y: 0,\n * text: \"Hello\",\n * size: 1,\n * style: { fillStyle: \"black\", fontFamily: \"Arial\" }\n * }}\n * />\n * ```\n */\nexport const Text = memo(function Text({ items, layer = 2 }: TextProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawText(items, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, items, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Path as PathType } from \"@canvas-tile-engine/core\";\n\nexport interface PathProps {\n items: PathType | PathType[];\n style?: { strokeStyle?: string; lineWidth?: number };\n layer?: number;\n}\n\n/**\n * Draws paths/polylines on the canvas.\n */\nexport const Path = memo(function Path({ items, style, layer = 1 }: PathProps) {\n const { engine, requestRender } = useEngineContext();\n\n useEffect(() => {\n const handle = engine.drawPath(items, style, layer);\n requestRender();\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, items, style, layer, requestRender]);\n\n return null;\n});\n","import { useEffect, useRef, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Rect as RectType } from \"@canvas-tile-engine/core\";\n\nexport interface StaticRectProps {\n items: RectType[];\n cacheKey: string;\n layer?: number;\n}\n\n/**\n * Draws static rectangles with caching for performance.\n * Ideal for large datasets that don't change frequently.\n */\nexport const StaticRect = memo(function StaticRect({ items, cacheKey, layer = 1 }: StaticRectProps) {\n const { engine, requestRender } = useEngineContext();\n const prevCacheKeyRef = useRef<string>(cacheKey);\n\n useEffect(() => {\n if (items.length === 0) {\n return;\n }\n\n // Clear previous cache if cacheKey changed\n if (prevCacheKeyRef.current !== cacheKey) {\n engine.clearStaticCache(prevCacheKeyRef.current);\n prevCacheKeyRef.current = cacheKey;\n }\n\n const handle = engine.drawStaticRect(items, cacheKey, layer);\n requestRender();\n\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, items, cacheKey, layer, requestRender]);\n\n // Cleanup cache on unmount\n useEffect(() => {\n return () => {\n engine.clearStaticCache(cacheKey);\n };\n }, [engine, cacheKey]);\n\n return null;\n});\n","import { useEffect, useRef, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { Circle as CircleType } from \"@canvas-tile-engine/core\";\n\nexport interface StaticCircleProps {\n items: CircleType[];\n cacheKey: string;\n layer?: number;\n}\n\n/**\n * Draws static circles with caching for performance.\n */\nexport const StaticCircle = memo(function StaticCircle({ items, cacheKey, layer = 1 }: StaticCircleProps) {\n const { engine, requestRender } = useEngineContext();\n const prevCacheKeyRef = useRef<string>(cacheKey);\n\n useEffect(() => {\n if (items.length === 0) {\n return;\n }\n\n if (prevCacheKeyRef.current !== cacheKey) {\n engine.clearStaticCache(prevCacheKeyRef.current);\n prevCacheKeyRef.current = cacheKey;\n }\n\n const handle = engine.drawStaticCircle(items, cacheKey, layer);\n requestRender();\n\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, items, cacheKey, layer, requestRender]);\n\n useEffect(() => {\n return () => {\n engine.clearStaticCache(cacheKey);\n };\n }, [engine, cacheKey]);\n\n return null;\n});\n","import { useEffect, useRef, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport { ImageItem } from \"@canvas-tile-engine/core\";\n\nexport interface StaticImageProps {\n items: ImageItem[];\n cacheKey: string;\n layer?: number;\n}\n\n/**\n * Draws static images with caching for performance.\n * Ideal for terrain tiles or static decorations.\n */\nexport const StaticImage = memo(function StaticImage({ items, cacheKey, layer = 1 }: StaticImageProps) {\n const { engine, requestRender } = useEngineContext();\n const prevCacheKeyRef = useRef<string>(cacheKey);\n\n useEffect(() => {\n if (items.length === 0) {\n return;\n }\n\n if (prevCacheKeyRef.current !== cacheKey) {\n engine.clearStaticCache(prevCacheKeyRef.current);\n prevCacheKeyRef.current = cacheKey;\n }\n\n const handle = engine.drawStaticImage(items, cacheKey, layer);\n requestRender();\n\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, items, cacheKey, layer, requestRender]);\n\n useEffect(() => {\n return () => {\n engine.clearStaticCache(cacheKey);\n };\n }, [engine, cacheKey]);\n\n return null;\n});\n","import { useEffect, useRef, memo } from \"react\";\nimport { useEngineContext } from \"../../context/EngineContext\";\nimport type { CanvasTileEngineConfig, Coords } from \"@canvas-tile-engine/core\";\n\nexport interface DrawFunctionProps {\n /** The draw function to execute */\n children: (ctx: unknown, coords: Coords, config: Required<CanvasTileEngineConfig>) => void;\n layer?: number;\n}\n\n/**\n * Custom draw function component.\n * Allows arbitrary canvas drawing within the engine's render cycle.\n * Multiple DrawFunction components can share the same layer (additive drawing).\n *\n * @example\n * ```tsx\n * <DrawFunction layer={3}>\n * {(ctx, coords, config) => {\n * ctx.fillStyle = \"red\";\n * ctx.fillRect(config.size.width / 2 - 5, config.size.height / 2 - 5, 10, 10);\n * }}\n * </DrawFunction>\n * ```\n */\nexport const DrawFunction = memo(function DrawFunction({ children, layer = 1 }: DrawFunctionProps) {\n const { engine, requestRender } = useEngineContext();\n const fnRef = useRef(children);\n\n // Keep function ref updated\n useEffect(() => {\n fnRef.current = children;\n });\n\n useEffect(() => {\n const handle = engine.addDrawFunction((ctx, coords, config) => {\n fnRef.current(ctx, coords, config);\n }, layer);\n requestRender();\n\n return () => {\n if (handle) {\n engine.removeDrawHandle(handle);\n }\n };\n }, [engine, layer, requestRender]);\n\n return null;\n});\n","import { useRef, useCallback, useState, useMemo } from \"react\";\nimport type {\n CanvasTileEngine as CanvasTileEngineCore,\n CanvasTileEngineConfig,\n Coords,\n EventHandlers,\n DrawHandle,\n ImageItem,\n Text,\n Circle,\n Line,\n Rect,\n} from \"@canvas-tile-engine/core\";\n\n/** Dummy handle returned when engine is not ready */\nconst DUMMY_DRAW_HANDLE: DrawHandle = { layer: -1, id: Symbol(\"dummy\") };\n\n/** Default config when engine is not ready */\nconst DEFAULT_CONFIG: Required<CanvasTileEngineConfig> = {\n size: { width: 0, height: 0, minWidth: 100, minHeight: 100, maxWidth: Infinity, maxHeight: Infinity },\n responsive: false,\n scale: 1,\n minScale: 0.5,\n maxScale: 2,\n backgroundColor: \"#ffffff\",\n gridAligned: false,\n renderer: \"canvas\",\n eventHandlers: {\n drag: true,\n zoom: true,\n hover: false,\n click: false,\n rightClick: false,\n resize: false,\n },\n bounds: {\n minX: -Infinity,\n maxX: Infinity,\n minY: -Infinity,\n maxY: Infinity,\n },\n coordinates: {\n enabled: false,\n shownScaleRange: { min: 0, max: Infinity },\n },\n cursor: {\n default: \"default\",\n move: \"move\",\n },\n debug: {\n enabled: false,\n hud: {\n enabled: false,\n topLeftCoordinates: false,\n coordinates: false,\n scale: false,\n tilesInView: false,\n fps: false,\n },\n eventHandlers: {\n click: false,\n hover: false,\n drag: false,\n zoom: false,\n resize: false,\n },\n },\n};\n\n/**\n * Engine handle returned by useCanvasTileEngine hook.\n * Provides access to engine methods with proper typing.\n *\n * All methods return default/dummy values when engine is not ready,\n * allowing safe usage without null checks.\n */\nexport interface EngineHandle {\n /** @internal - Used by CanvasTileEngine component */\n readonly _containerRef: React.RefObject<HTMLDivElement>;\n /** @internal - Used by CanvasTileEngine component */\n _setInstance: (engine: CanvasTileEngineCore | null) => void;\n\n /** Whether the engine is ready (mounted and initialized) */\n readonly isReady: boolean;\n\n /** The underlying engine instance (null until component mounts) */\n readonly instance: CanvasTileEngineCore | null;\n\n /** Render a frame */\n render(): void;\n\n /** Get current center coordinates */\n getCenterCoords(): Coords;\n\n /** Get visible world coordinate bounds of the viewport */\n getVisibleBounds(): { minX: number; maxX: number; minY: number; maxY: number };\n\n /** Update center coordinates */\n updateCoords(center: Coords): void;\n\n /** Animate to target coordinates */\n goCoords(x: number, y: number, durationMs?: number, onComplete?: () => void): void;\n\n /** Resize the canvas */\n resize(width: number, height: number, durationMs?: number, onComplete?: () => void): void;\n\n /** Get current canvas size */\n getSize(): { width: number; height: number };\n\n /** Get current canvas scale */\n getScale(): number;\n\n /** Set the canvas scale directly, clamped to min/max bounds. */\n setScale(newScale: number): void;\n\n /** Zoom in by a factor (default: 1.5) */\n zoomIn(factor?: number): void;\n\n /** Zoom out by a factor (default: 1.5) */\n zoomOut(factor?: number): void;\n\n /** Get current config */\n getConfig(): Required<CanvasTileEngineConfig>;\n\n /** Set map boundaries */\n setBounds(bounds: { minX: number; maxX: number; minY: number; maxY: number }): void;\n\n /** Dynamically update event handlers at runtime */\n setEventHandlers(handlers: Partial<EventHandlers>): void;\n\n /** Register a custom draw function */\n addDrawFunction(\n fn: (ctx: unknown, coords: Coords, config: Required<CanvasTileEngineConfig>) => void,\n layer?: number\n ): DrawHandle;\n\n /** Draw rectangles */\n drawRect(items: Rect | Rect[], layer?: number): DrawHandle;\n\n /** Draw static rectangles (cached) */\n drawStaticRect(items: Rect[], cacheKey: string, layer?: number): DrawHandle;\n\n /** Draw circles */\n drawCircle(items: Circle | Circle[], layer?: number): DrawHandle;\n\n /** Draw static circles (cached) */\n drawStaticCircle(items: Circle[], cacheKey: string, layer?: number): DrawHandle;\n\n /** Draw lines */\n drawLine(items: Line | Line[], style?: { strokeStyle?: string; lineWidth?: number }, layer?: number): DrawHandle;\n\n /** Draw text */\n drawText(items: Text | Text[], layer?: number): DrawHandle;\n\n /** Draw paths/polylines */\n drawPath(\n items: Coords[] | Coords[][],\n style?: { strokeStyle?: string; lineWidth?: number },\n layer?: number\n ): DrawHandle;\n\n /** Draw images */\n drawImage(items: ImageItem | ImageItem[], layer?: number): DrawHandle;\n\n /** Draw static images (cached) */\n drawStaticImage(items: ImageItem[], cacheKey: string, layer?: number): DrawHandle;\n\n /** Draw grid lines */\n drawGridLines(cellSize: number, lineWidth?: number, strokeStyle?: string, layer?: number): DrawHandle;\n\n /** Clear a specific layer */\n clearLayer(layer: number): void;\n\n /** Clear all layers */\n clearAll(): void;\n\n /** Clear static cache */\n clearStaticCache(cacheKey?: string): void;\n\n /** Remove a previously registered draw callback */\n removeDrawHandle(handle: DrawHandle): void;\n\n /** Image loader instance (undefined until engine mounts) */\n readonly images: CanvasTileEngineCore[\"images\"] | undefined;\n\n /**\n * Load an image using the engine's image loader.\n * Returns a rejected promise if engine is not ready.\n * @param src - Image URL to load\n * @param retry - Number of retries on failure (default: 1)\n * @example\n * ```tsx\n * const img = await engine.loadImage(\"/sprites/player.png\");\n * ```\n */\n loadImage(src: string, retry?: number): Promise<HTMLImageElement>;\n}\n\n/**\n * React hook that creates an engine handle for use with CanvasTileEngine component.\n *\n * @returns Engine handle to pass to CanvasTileEngine component\n *\n * @example\n * ```tsx\n * function App() {\n * const mainMap = useCanvasTileEngine();\n * const miniMap = useCanvasTileEngine();\n *\n * useEffect(() => {\n * if (mainMap.isReady && miniMap.isReady) {\n * // Both engines are ready, draw items\n * mainMap.drawGridLines(50);\n * mainMap.render();\n * }\n * }, [mainMap.isReady, miniMap.isReady]);\n *\n * return (\n * <>\n * <CanvasTileEngine engine={mainMap} config={...} />\n * <CanvasTileEngine engine={miniMap} config={...} />\n * </>\n * );\n * }\n * ```\n */\nexport function useCanvasTileEngine(): EngineHandle {\n const instanceRef = useRef<CanvasTileEngineCore | null>(null);\n const containerRef = useRef<HTMLDivElement>(null!);\n // _isReady state is only used to trigger re-renders, actual value is read from isReadyRef\n const [, setIsReady] = useState(false);\n // Keep isReady in a ref so the handle getter can read it without recreating handle\n const isReadyRef = useRef(false);\n\n const setInstance = useCallback((engine: CanvasTileEngineCore | null) => {\n instanceRef.current = engine;\n isReadyRef.current = engine !== null;\n setIsReady(engine !== null);\n }, []);\n\n // Create stable handle object using useMemo\n // Note: isReady is NOT in deps - we read from isReadyRef to keep handle stable\n const handle = useMemo<EngineHandle>(\n () => ({\n _containerRef: containerRef,\n _setInstance: setInstance,\n\n get isReady() {\n return isReadyRef.current;\n },\n\n get instance() {\n return instanceRef.current;\n },\n\n get images() {\n return instanceRef.current?.images;\n },\n\n render() {\n instanceRef.current?.render();\n },\n\n getCenterCoords() {\n return instanceRef.current?.getCenterCoords() ?? { x: 0, y: 0 };\n },\n\n getVisibleBounds() {\n return instanceRef.current?.getVisibleBounds() ?? { minX: 0, maxX: 0, minY: 0, maxY: 0 };\n },\n\n updateCoords(center: Coords) {\n instanceRef.current?.updateCoords(center);\n },\n\n goCoords(x: number, y: number, durationMs?: number, onComplete?: () => void) {\n instanceRef.current?.goCoords(x, y, durationMs, onComplete);\n },\n\n resize(width: number, height: number, durationMs?: number, onComplete?: () => void) {\n instanceRef.current?.resize(width, height, durationMs, onComplete);\n },\n\n getSize() {\n return instanceRef.current?.getSize() ?? { width: 0, height: 0 };\n },\n\n getScale() {\n return instanceRef.current?.getScale() ?? 1;\n },\n\n setScale(newScale: number) {\n instanceRef.current?.setScale(newScale);\n },\n\n zoomIn(factor?: number) {\n instanceRef.current?.zoomIn(factor);\n },\n\n zoomOut(factor?: number) {\n instanceRef.current?.zoomOut(factor);\n },\n\n getConfig() {\n return instanceRef.current?.getConfig() ?? DEFAULT_CONFIG;\n },\n\n setBounds(bounds) {\n instanceRef.current?.setBounds(bounds);\n },\n\n setEventHandlers(handlers) {\n instanceRef.current?.setEventHandlers(handlers);\n },\n\n addDrawFunction(fn, layer) {\n return instanceRef.current?.addDrawFunction(fn, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawRect(items, layer) {\n return instanceRef.current?.drawRect(items, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawStaticRect(items, cacheKey, layer) {\n return instanceRef.current?.drawStaticRect(items, cacheKey, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawCircle(items, layer) {\n return instanceRef.current?.drawCircle(items, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawStaticCircle(items, cacheKey, layer) {\n return instanceRef.current?.drawStaticCircle(items, cacheKey, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawLine(items, style, layer) {\n return instanceRef.current?.drawLine(items, style, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawText(items, layer) {\n return instanceRef.current?.drawText(items, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawPath(items, style, layer) {\n return instanceRef.current?.drawPath(items, style, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawImage(items, layer) {\n return instanceRef.current?.drawImage(items, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawStaticImage(items, cacheKey, layer) {\n return instanceRef.current?.drawStaticImage(items, cacheKey, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n drawGridLines(cellSize, lineWidth, strokeStyle, layer) {\n return instanceRef.current?.drawGridLines(cellSize, lineWidth, strokeStyle, layer) ?? DUMMY_DRAW_HANDLE;\n },\n\n clearLayer(layer) {\n instanceRef.current?.clearLayer(layer);\n },\n\n clearAll() {\n instanceRef.current?.clearAll();\n },\n\n clearStaticCache(cacheKey) {\n instanceRef.current?.clearStaticCache(cacheKey);\n },\n\n removeDrawHandle(handle) {\n instanceRef.current?.removeDrawHandle(handle);\n },\n\n loadImage(src: string, retry?: number) {\n if (!instanceRef.current) {\n return Promise.reject(new Error(\"Engine not ready. Wait for isReady before loading images.\"));\n }\n return instanceRef.current.images.load(src, retry) as Promise<HTMLImageElement>;\n },\n }),\n [setInstance]\n );\n\n return handle;\n}\n"],"mappings":"mbAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,sBAAAE,EAAA,gGAAAC,EAAA,qBAAAC,IAAA,eAAAC,GAAAL,ICAA,IAAAM,EAAwD,iBACxDC,GAAyD,oCCDzD,IAAAC,EAA0C,iBAS7BC,KAAgB,iBAAyC,IAAI,EAMnE,SAASC,GAAuC,CACnD,IAAMC,KAAU,cAAWF,CAAa,EAExC,GAAI,CAACE,EACD,MAAM,IAAI,MAAM,mEAAmE,EAGvF,OAAOA,CACX,CCvBA,IAAAC,EAAgC,iBAYzB,IAAMC,KAAO,QAAK,SAAc,CAAE,MAAAC,EAAO,MAAAC,EAAQ,CAAE,EAAc,CACpE,GAAM,CAAE,OAAAC,EAAQ,cAAAC,CAAc,EAAIC,EAAiB,EAEnD,sBAAU,IAAM,CACZ,IAAMC,EAASH,EAAO,SAASF,EAAOC,CAAK,EAC3C,OAAAE,EAAc,EACP,IAAM,CACLE,GACAH,EAAO,iBAAiBG,CAAM,CAEtC,CACJ,EAAG,CAACH,EAAQF,EAAOC,EAAOE,CAAa,CAAC,EAEjC,IACX,CAAC,EC1BD,IAAAG,EAAgC,iBAYzB,IAAMC,KAAS,QAAK,SAAgB,CAAE,MAAA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,EAAOD,CAAK,GAAKrB,CAC1D,EAEA,SAASsB,EAAOE,EAAOH,EAAO,CAC1B,OAAOlB,EAAY,SAAS,SAASmB,EAAOE,EAAOH,CAAK,GAAKrB,CACjE,EAEA,UAAUsB,EAAOD,EAAO,CACpB,OAAOlB,EAAY,SAAS,UAAUmB,EAAOD,CAAK,GAAKrB,CAC3D,EAEA,gBAAgBsB,EAAOC,EAAUF,EAAO,CACpC,OAAOlB,EAAY,SAAS,gBAAgBmB,EAAOC,EAAUF,CAAK,GAAKrB,CAC3E,EAEA,cAAcyB,EAAUC,EAAWC,EAAaN,EAAO,CACnD,OAAOlB,EAAY,SAAS,cAAcsB,EAAUC,EAAWC,EAAaN,CAAK,GAAKrB,CAC1F,EAEA,WAAWqB,EAAO,CACdlB,EAAY,SAAS,WAAWkB,CAAK,CACzC,EAEA,UAAW,CACPlB,EAAY,SAAS,SAAS,CAClC,EAEA,iBAAiBoB,EAAU,CACvBpB,EAAY,SAAS,iBAAiBoB,CAAQ,CAClD,EAEA,iBAAiBK,EAAQ,CACrBzB,EAAY,SAAS,iBAAiByB,CAAM,CAChD,EAEA,UAAUC,EAAaC,EAAgB,CACnC,OAAK3B,EAAY,QAGVA,EAAY,QAAQ,OAAO,KAAK0B,EAAKC,CAAK,EAFtC,QAAQ,OAAO,IAAI,MAAM,2DAA2D,CAAC,CAGpG,CACJ,GACA,CAACvB,CAAW,CAChB,CAGJ,CdnVA,IAAAwB,EAAqE","names":["index_exports","__export","CanvasTileEngine","useCanvasTileEngine","useEngineContext","__toCommonJS","import_react","import_core","import_react","EngineContext","useEngineContext","context","import_react","Rect","items","layer","engine","requestRender","useEngineContext","handle","import_react","Circle","items","layer","engine","requestRender","useEngineContext","handle","import_react","Image","items","layer","engine","requestRender","useEngineContext","handle","import_react","GridLines","cellSize","lineWidth","strokeStyle","layer","engine","requestRender","useEngineContext","handle","import_react","Line","items","style","layer","engine","requestRender","useEngineContext","handle","import_react","Text","items","layer","engine","requestRender","useEngineContext","handle","import_react","Path","items","style","layer","engine","requestRender","useEngineContext","handle","import_react","StaticRect","items","cacheKey","layer","engine","requestRender","useEngineContext","prevCacheKeyRef","handle","import_react","StaticCircle","items","cacheKey","layer","engine","requestRender","useEngineContext","prevCacheKeyRef","handle","import_react","StaticImage","items","cacheKey","layer","engine","requestRender","useEngineContext","prevCacheKeyRef","handle","import_react","DrawFunction","children","layer","engine","requestRender","useEngineContext","fnRef","handle","ctx","coords","config","import_jsx_runtime","CanvasTileEngineBase","engine","renderer","config","center","className","style","children","onCoordsChange","onClick","onRightClick","onHover","onMouseDown","onMouseUp","onMouseLeave","onDraw","onResize","onZoom","callbacksRef","rafIdRef","requestRender","contextValue","container","instance","CanvasTileEngineCore","coords","args","scale","EngineContext","CanvasTileEngine","Rect","Circle","Image","GridLines","Line","Text","Path","StaticRect","StaticCircle","StaticImage","DrawFunction","import_react","DUMMY_DRAW_HANDLE","DEFAULT_CONFIG","useCanvasTileEngine","instanceRef","containerRef","setIsReady","isReadyRef","setInstance","engine","center","x","y","durationMs","onComplete","width","height","newScale","factor","bounds","handlers","fn","layer","items","cacheKey","style","cellSize","lineWidth","strokeStyle","handle","src","retry","import_core"]}
|