@canvas-tile-engine/react 0.0.1

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 ADDED
@@ -0,0 +1,46 @@
1
+ # @canvas-tile-engine/react
2
+
3
+ React bindings for Canvas Tile Engine — build interactive 2D grid-based maps with declarative components.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install @canvas-tile-engine/react
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```tsx
14
+ import { CanvasTileEngine, useCanvasTileEngine } from "@canvas-tile-engine/react";
15
+
16
+ const config = {
17
+ scale: 50,
18
+ size: { width: 800, height: 600 },
19
+ backgroundColor: "#337426",
20
+ eventHandlers: { drag: true, zoom: true, click: true },
21
+ };
22
+
23
+ function App() {
24
+ const engine = useCanvasTileEngine();
25
+
26
+ return (
27
+ <CanvasTileEngine
28
+ engine={engine}
29
+ config={config}
30
+ center={{ x: 0, y: 0 }}
31
+ onClick={(coords) => console.log("Clicked:", coords.snapped)}
32
+ >
33
+ <CanvasTileEngine.Rect items={[{ x: 0, y: 0, size: 1, style: { fillStyle: "#f9c74f" } }]} layer={0} />
34
+ <CanvasTileEngine.GridLines cellSize={10} layer={1} />
35
+ </CanvasTileEngine>
36
+ );
37
+ }
38
+ ```
39
+
40
+ ## Documentation
41
+
42
+ Full API reference and examples: [https://www.canvastileengine.dev/docs/react/installation](https://www.canvastileengine.dev/docs/react/installation)
43
+
44
+ ## License
45
+
46
+ MIT
@@ -0,0 +1,324 @@
1
+ import * as react from 'react';
2
+ import { DrawObject, ImageItem, Coords, CanvasTileEngineConfig, CanvasTileEngine as CanvasTileEngine$1, EventHandlers, LayerHandle, onClickCallback, onHoverCallback, onDrawCallback } from '@canvas-tile-engine/core';
3
+ export { CanvasTileEngineConfig, CanvasTileEngine as CanvasTileEngineCore, Circle, Coords, DrawObject, EventHandlers, ImageItem, Line, Path, Rect, Text, onClickCallback, onDrawCallback, onHoverCallback } from '@canvas-tile-engine/core';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+
6
+ interface RectProps {
7
+ items: DrawObject | DrawObject[];
8
+ layer?: number;
9
+ }
10
+
11
+ interface CircleProps {
12
+ items: DrawObject | DrawObject[];
13
+ layer?: number;
14
+ }
15
+
16
+ interface ImageProps {
17
+ items: ImageItem | ImageItem[];
18
+ layer?: number;
19
+ }
20
+
21
+ interface GridLinesProps {
22
+ cellSize: number;
23
+ lineWidth?: number;
24
+ strokeStyle?: string;
25
+ layer?: number;
26
+ }
27
+
28
+ interface LineProps {
29
+ items: {
30
+ from: Coords;
31
+ to: Coords;
32
+ } | {
33
+ from: Coords;
34
+ to: Coords;
35
+ }[];
36
+ style?: {
37
+ strokeStyle?: string;
38
+ lineWidth?: number;
39
+ };
40
+ layer?: number;
41
+ }
42
+
43
+ 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
+ };
57
+ layer?: number;
58
+ }
59
+
60
+ interface PathProps {
61
+ items: Coords[] | Coords[][];
62
+ style?: {
63
+ strokeStyle?: string;
64
+ lineWidth?: number;
65
+ };
66
+ layer?: number;
67
+ }
68
+
69
+ interface StaticRectProps {
70
+ items: DrawObject[];
71
+ cacheKey: string;
72
+ layer?: number;
73
+ }
74
+
75
+ interface StaticCircleProps {
76
+ items: DrawObject[];
77
+ cacheKey: string;
78
+ layer?: number;
79
+ }
80
+
81
+ interface StaticImageProps {
82
+ items: ImageItem[];
83
+ cacheKey: string;
84
+ layer?: number;
85
+ }
86
+
87
+ interface DrawFunctionProps {
88
+ /** The draw function to execute */
89
+ children: (ctx: CanvasRenderingContext2D, coords: Coords, config: Required<CanvasTileEngineConfig>) => void;
90
+ layer?: number;
91
+ }
92
+
93
+ /**
94
+ * Engine handle returned by useCanvasTileEngine hook.
95
+ * Provides access to engine methods with proper typing.
96
+ *
97
+ * All methods return default/dummy values when engine is not ready,
98
+ * allowing safe usage without null checks.
99
+ */
100
+ interface EngineHandle {
101
+ /** Whether the engine is ready (mounted and initialized) */
102
+ readonly isReady: boolean;
103
+ /** The underlying engine instance (null until component mounts) */
104
+ readonly instance: CanvasTileEngine$1 | null;
105
+ /** Render a frame */
106
+ render(): void;
107
+ /** Get current center coordinates */
108
+ getCenterCoords(): Coords;
109
+ /** Update center coordinates */
110
+ updateCoords(center: Coords): void;
111
+ /** Animate to target coordinates */
112
+ goCoords(x: number, y: number, durationMs?: number, onComplete?: () => void): void;
113
+ /** Resize the canvas */
114
+ resize(width: number, height: number, durationMs?: number, onComplete?: () => void): void;
115
+ /** Get current canvas size */
116
+ getSize(): {
117
+ width: number;
118
+ height: number;
119
+ };
120
+ /** Get current canvas scale */
121
+ getScale(): number;
122
+ /** Zoom in by a factor (default: 1.5) */
123
+ zoomIn(factor?: number): void;
124
+ /** Zoom out by a factor (default: 1.5) */
125
+ zoomOut(factor?: number): void;
126
+ /** Get current config */
127
+ getConfig(): Required<CanvasTileEngineConfig>;
128
+ /** Set map boundaries */
129
+ setBounds(bounds: {
130
+ minX: number;
131
+ maxX: number;
132
+ minY: number;
133
+ maxY: number;
134
+ }): void;
135
+ /** Dynamically update event handlers at runtime */
136
+ setEventHandlers(handlers: Partial<EventHandlers>): void;
137
+ /** Draw rectangles */
138
+ drawRect(items: DrawObject | DrawObject[], layer?: number): LayerHandle;
139
+ /** Draw static rectangles (cached) */
140
+ drawStaticRect(items: DrawObject[], cacheKey: string, layer?: number): LayerHandle;
141
+ /** Draw circles */
142
+ drawCircle(items: DrawObject | DrawObject[], layer?: number): LayerHandle;
143
+ /** Draw static circles (cached) */
144
+ drawStaticCircle(items: DrawObject[], cacheKey: string, layer?: number): LayerHandle;
145
+ /** Draw lines */
146
+ drawLine(items: {
147
+ from: Coords;
148
+ to: Coords;
149
+ } | {
150
+ from: Coords;
151
+ to: Coords;
152
+ }[], style?: {
153
+ strokeStyle?: string;
154
+ lineWidth?: number;
155
+ }, layer?: number): LayerHandle;
156
+ /** Draw text */
157
+ drawText(items: {
158
+ coords: Coords;
159
+ text: string;
160
+ } | {
161
+ coords: Coords;
162
+ text: string;
163
+ }[], style?: {
164
+ fillStyle?: string;
165
+ font?: string;
166
+ textAlign?: CanvasTextAlign;
167
+ textBaseline?: CanvasTextBaseline;
168
+ }, layer?: number): LayerHandle;
169
+ /** Draw paths/polylines */
170
+ drawPath(items: Coords[] | Coords[][], style?: {
171
+ strokeStyle?: string;
172
+ lineWidth?: number;
173
+ }, layer?: number): LayerHandle;
174
+ /** Draw images */
175
+ drawImage(items: (Omit<DrawObject, "style"> & {
176
+ img: HTMLImageElement;
177
+ }) | (Omit<DrawObject, "style"> & {
178
+ img: HTMLImageElement;
179
+ })[], layer?: number): LayerHandle;
180
+ /** Draw static images (cached) */
181
+ drawStaticImage(items: (Omit<DrawObject, "style"> & {
182
+ img: HTMLImageElement;
183
+ })[], cacheKey: string, layer?: number): LayerHandle;
184
+ /** Draw grid lines */
185
+ drawGridLines(cellSize: number, lineWidth?: number, strokeStyle?: string, layer?: number): LayerHandle;
186
+ /** Add custom draw function */
187
+ addDrawFunction(fn: (ctx: CanvasRenderingContext2D, coords: Coords, config: Required<CanvasTileEngineConfig>) => void, layer?: number): LayerHandle;
188
+ /** Clear a specific layer */
189
+ clearLayer(layer: number): void;
190
+ /** Clear all layers */
191
+ clearAll(): void;
192
+ /** Clear static cache */
193
+ clearStaticCache(cacheKey?: string): void;
194
+ /** Remove a previously registered draw callback */
195
+ removeLayerHandle(handle: LayerHandle): void;
196
+ /** Image loader instance (undefined until engine mounts) */
197
+ readonly images: CanvasTileEngine$1["images"] | undefined;
198
+ }
199
+ /**
200
+ * React hook that creates an engine handle for use with CanvasTileEngine component.
201
+ *
202
+ * @returns Engine handle to pass to CanvasTileEngine component
203
+ *
204
+ * @example
205
+ * ```tsx
206
+ * function App() {
207
+ * const mainMap = useCanvasTileEngine();
208
+ * const miniMap = useCanvasTileEngine();
209
+ *
210
+ * useEffect(() => {
211
+ * if (mainMap.isReady && miniMap.isReady) {
212
+ * // Both engines are ready, draw items
213
+ * mainMap.drawGridLines(50);
214
+ * mainMap.render();
215
+ * }
216
+ * }, [mainMap.isReady, miniMap.isReady]);
217
+ *
218
+ * return (
219
+ * <>
220
+ * <CanvasTileEngine engine={mainMap} config={...} />
221
+ * <CanvasTileEngine engine={miniMap} config={...} />
222
+ * </>
223
+ * );
224
+ * }
225
+ * ```
226
+ */
227
+ declare function useCanvasTileEngine(): EngineHandle;
228
+
229
+ /**
230
+ * Props for CanvasTileEngine component
231
+ */
232
+ interface CanvasTileEngineProps {
233
+ /** Engine handle from useCanvasTileEngine hook (required) */
234
+ engine: EngineHandle;
235
+ /** Engine configuration */
236
+ config: CanvasTileEngineConfig;
237
+ /** Initial center coordinates */
238
+ center?: Coords;
239
+ /** Additional class name for the wrapper div */
240
+ className?: string;
241
+ /** Additional styles for the wrapper div */
242
+ style?: React.CSSProperties;
243
+ /** Draw components (Rect, Circle, Image, GridLines, etc.) */
244
+ children?: React.ReactNode;
245
+ /** Callback when center coordinates change */
246
+ onCoordsChange?: (coords: Coords) => void;
247
+ /** Callback when a tile is clicked */
248
+ onClick?: onClickCallback;
249
+ /** Callback when hovering over tiles */
250
+ onHover?: onHoverCallback;
251
+ /** Callback on mouse down */
252
+ onMouseDown?: () => void;
253
+ /** Callback on mouse up */
254
+ onMouseUp?: () => void;
255
+ /** Callback on mouse leave */
256
+ onMouseLeave?: () => void;
257
+ /** Callback after each draw frame */
258
+ onDraw?: onDrawCallback;
259
+ /** Callback on canvas resize */
260
+ onResize?: () => void;
261
+ }
262
+
263
+ /**
264
+ * React component that renders a CanvasTileEngine.
265
+ * Supports both imperative API (via engine handle) and declarative API (via children).
266
+ *
267
+ * @example Declarative API with compound components
268
+ * ```tsx
269
+ * function App() {
270
+ * const engine = useCanvasTileEngine();
271
+ *
272
+ * return (
273
+ * <CanvasTileEngine engine={engine} config={config}>
274
+ * <CanvasTileEngine.GridLines cellSize={50} layer={0} />
275
+ * <CanvasTileEngine.Image items={imageItems} layer={1} />
276
+ * <CanvasTileEngine.Circle items={markers} layer={2} />
277
+ * </CanvasTileEngine>
278
+ * );
279
+ * }
280
+ * ```
281
+ *
282
+ * @example Imperative API
283
+ * ```tsx
284
+ * function App() {
285
+ * const engine = useCanvasTileEngine();
286
+ *
287
+ * useEffect(() => {
288
+ * if (engine.isReady) {
289
+ * engine.drawGridLines(50);
290
+ * engine.render();
291
+ * }
292
+ * }, [engine.isReady]);
293
+ *
294
+ * return <CanvasTileEngine engine={engine} config={config} />;
295
+ * }
296
+ * ```
297
+ */
298
+ declare function CanvasTileEngineBase({ engine, config, center, className, style, children, onCoordsChange, onClick, onHover, onMouseDown, onMouseUp, onMouseLeave, onDraw, onResize, }: CanvasTileEngineProps): react_jsx_runtime.JSX.Element;
299
+ declare const CanvasTileEngine: typeof CanvasTileEngineBase & {
300
+ Rect: react.NamedExoticComponent<RectProps>;
301
+ Circle: react.NamedExoticComponent<CircleProps>;
302
+ Image: react.NamedExoticComponent<ImageProps>;
303
+ GridLines: react.NamedExoticComponent<GridLinesProps>;
304
+ Line: react.NamedExoticComponent<LineProps>;
305
+ Text: react.NamedExoticComponent<TextProps>;
306
+ Path: react.NamedExoticComponent<PathProps>;
307
+ StaticRect: react.NamedExoticComponent<StaticRectProps>;
308
+ StaticCircle: react.NamedExoticComponent<StaticCircleProps>;
309
+ StaticImage: react.NamedExoticComponent<StaticImageProps>;
310
+ DrawFunction: react.NamedExoticComponent<DrawFunctionProps>;
311
+ };
312
+
313
+ interface EngineContextValue {
314
+ engine: EngineHandle;
315
+ /** Request a re-render of the canvas */
316
+ requestRender: () => void;
317
+ }
318
+ /**
319
+ * Hook to access the engine context from child components.
320
+ * Must be used within a CanvasTileEngine component.
321
+ */
322
+ declare function useEngineContext(): EngineContextValue;
323
+
324
+ export { CanvasTileEngine, type CanvasTileEngineProps, type CircleProps, type DrawFunctionProps, type EngineContextValue, type EngineHandle, type GridLinesProps, type ImageProps, type LineProps, type PathProps, type RectProps, type StaticCircleProps, type StaticImageProps, type StaticRectProps, type TextProps, useCanvasTileEngine, useEngineContext };
@@ -0,0 +1,324 @@
1
+ import * as react from 'react';
2
+ import { DrawObject, ImageItem, Coords, CanvasTileEngineConfig, CanvasTileEngine as CanvasTileEngine$1, EventHandlers, LayerHandle, onClickCallback, onHoverCallback, onDrawCallback } from '@canvas-tile-engine/core';
3
+ export { CanvasTileEngineConfig, CanvasTileEngine as CanvasTileEngineCore, Circle, Coords, DrawObject, EventHandlers, ImageItem, Line, Path, Rect, Text, onClickCallback, onDrawCallback, onHoverCallback } from '@canvas-tile-engine/core';
4
+ import * as react_jsx_runtime from 'react/jsx-runtime';
5
+
6
+ interface RectProps {
7
+ items: DrawObject | DrawObject[];
8
+ layer?: number;
9
+ }
10
+
11
+ interface CircleProps {
12
+ items: DrawObject | DrawObject[];
13
+ layer?: number;
14
+ }
15
+
16
+ interface ImageProps {
17
+ items: ImageItem | ImageItem[];
18
+ layer?: number;
19
+ }
20
+
21
+ interface GridLinesProps {
22
+ cellSize: number;
23
+ lineWidth?: number;
24
+ strokeStyle?: string;
25
+ layer?: number;
26
+ }
27
+
28
+ interface LineProps {
29
+ items: {
30
+ from: Coords;
31
+ to: Coords;
32
+ } | {
33
+ from: Coords;
34
+ to: Coords;
35
+ }[];
36
+ style?: {
37
+ strokeStyle?: string;
38
+ lineWidth?: number;
39
+ };
40
+ layer?: number;
41
+ }
42
+
43
+ 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
+ };
57
+ layer?: number;
58
+ }
59
+
60
+ interface PathProps {
61
+ items: Coords[] | Coords[][];
62
+ style?: {
63
+ strokeStyle?: string;
64
+ lineWidth?: number;
65
+ };
66
+ layer?: number;
67
+ }
68
+
69
+ interface StaticRectProps {
70
+ items: DrawObject[];
71
+ cacheKey: string;
72
+ layer?: number;
73
+ }
74
+
75
+ interface StaticCircleProps {
76
+ items: DrawObject[];
77
+ cacheKey: string;
78
+ layer?: number;
79
+ }
80
+
81
+ interface StaticImageProps {
82
+ items: ImageItem[];
83
+ cacheKey: string;
84
+ layer?: number;
85
+ }
86
+
87
+ interface DrawFunctionProps {
88
+ /** The draw function to execute */
89
+ children: (ctx: CanvasRenderingContext2D, coords: Coords, config: Required<CanvasTileEngineConfig>) => void;
90
+ layer?: number;
91
+ }
92
+
93
+ /**
94
+ * Engine handle returned by useCanvasTileEngine hook.
95
+ * Provides access to engine methods with proper typing.
96
+ *
97
+ * All methods return default/dummy values when engine is not ready,
98
+ * allowing safe usage without null checks.
99
+ */
100
+ interface EngineHandle {
101
+ /** Whether the engine is ready (mounted and initialized) */
102
+ readonly isReady: boolean;
103
+ /** The underlying engine instance (null until component mounts) */
104
+ readonly instance: CanvasTileEngine$1 | null;
105
+ /** Render a frame */
106
+ render(): void;
107
+ /** Get current center coordinates */
108
+ getCenterCoords(): Coords;
109
+ /** Update center coordinates */
110
+ updateCoords(center: Coords): void;
111
+ /** Animate to target coordinates */
112
+ goCoords(x: number, y: number, durationMs?: number, onComplete?: () => void): void;
113
+ /** Resize the canvas */
114
+ resize(width: number, height: number, durationMs?: number, onComplete?: () => void): void;
115
+ /** Get current canvas size */
116
+ getSize(): {
117
+ width: number;
118
+ height: number;
119
+ };
120
+ /** Get current canvas scale */
121
+ getScale(): number;
122
+ /** Zoom in by a factor (default: 1.5) */
123
+ zoomIn(factor?: number): void;
124
+ /** Zoom out by a factor (default: 1.5) */
125
+ zoomOut(factor?: number): void;
126
+ /** Get current config */
127
+ getConfig(): Required<CanvasTileEngineConfig>;
128
+ /** Set map boundaries */
129
+ setBounds(bounds: {
130
+ minX: number;
131
+ maxX: number;
132
+ minY: number;
133
+ maxY: number;
134
+ }): void;
135
+ /** Dynamically update event handlers at runtime */
136
+ setEventHandlers(handlers: Partial<EventHandlers>): void;
137
+ /** Draw rectangles */
138
+ drawRect(items: DrawObject | DrawObject[], layer?: number): LayerHandle;
139
+ /** Draw static rectangles (cached) */
140
+ drawStaticRect(items: DrawObject[], cacheKey: string, layer?: number): LayerHandle;
141
+ /** Draw circles */
142
+ drawCircle(items: DrawObject | DrawObject[], layer?: number): LayerHandle;
143
+ /** Draw static circles (cached) */
144
+ drawStaticCircle(items: DrawObject[], cacheKey: string, layer?: number): LayerHandle;
145
+ /** Draw lines */
146
+ drawLine(items: {
147
+ from: Coords;
148
+ to: Coords;
149
+ } | {
150
+ from: Coords;
151
+ to: Coords;
152
+ }[], style?: {
153
+ strokeStyle?: string;
154
+ lineWidth?: number;
155
+ }, layer?: number): LayerHandle;
156
+ /** Draw text */
157
+ drawText(items: {
158
+ coords: Coords;
159
+ text: string;
160
+ } | {
161
+ coords: Coords;
162
+ text: string;
163
+ }[], style?: {
164
+ fillStyle?: string;
165
+ font?: string;
166
+ textAlign?: CanvasTextAlign;
167
+ textBaseline?: CanvasTextBaseline;
168
+ }, layer?: number): LayerHandle;
169
+ /** Draw paths/polylines */
170
+ drawPath(items: Coords[] | Coords[][], style?: {
171
+ strokeStyle?: string;
172
+ lineWidth?: number;
173
+ }, layer?: number): LayerHandle;
174
+ /** Draw images */
175
+ drawImage(items: (Omit<DrawObject, "style"> & {
176
+ img: HTMLImageElement;
177
+ }) | (Omit<DrawObject, "style"> & {
178
+ img: HTMLImageElement;
179
+ })[], layer?: number): LayerHandle;
180
+ /** Draw static images (cached) */
181
+ drawStaticImage(items: (Omit<DrawObject, "style"> & {
182
+ img: HTMLImageElement;
183
+ })[], cacheKey: string, layer?: number): LayerHandle;
184
+ /** Draw grid lines */
185
+ drawGridLines(cellSize: number, lineWidth?: number, strokeStyle?: string, layer?: number): LayerHandle;
186
+ /** Add custom draw function */
187
+ addDrawFunction(fn: (ctx: CanvasRenderingContext2D, coords: Coords, config: Required<CanvasTileEngineConfig>) => void, layer?: number): LayerHandle;
188
+ /** Clear a specific layer */
189
+ clearLayer(layer: number): void;
190
+ /** Clear all layers */
191
+ clearAll(): void;
192
+ /** Clear static cache */
193
+ clearStaticCache(cacheKey?: string): void;
194
+ /** Remove a previously registered draw callback */
195
+ removeLayerHandle(handle: LayerHandle): void;
196
+ /** Image loader instance (undefined until engine mounts) */
197
+ readonly images: CanvasTileEngine$1["images"] | undefined;
198
+ }
199
+ /**
200
+ * React hook that creates an engine handle for use with CanvasTileEngine component.
201
+ *
202
+ * @returns Engine handle to pass to CanvasTileEngine component
203
+ *
204
+ * @example
205
+ * ```tsx
206
+ * function App() {
207
+ * const mainMap = useCanvasTileEngine();
208
+ * const miniMap = useCanvasTileEngine();
209
+ *
210
+ * useEffect(() => {
211
+ * if (mainMap.isReady && miniMap.isReady) {
212
+ * // Both engines are ready, draw items
213
+ * mainMap.drawGridLines(50);
214
+ * mainMap.render();
215
+ * }
216
+ * }, [mainMap.isReady, miniMap.isReady]);
217
+ *
218
+ * return (
219
+ * <>
220
+ * <CanvasTileEngine engine={mainMap} config={...} />
221
+ * <CanvasTileEngine engine={miniMap} config={...} />
222
+ * </>
223
+ * );
224
+ * }
225
+ * ```
226
+ */
227
+ declare function useCanvasTileEngine(): EngineHandle;
228
+
229
+ /**
230
+ * Props for CanvasTileEngine component
231
+ */
232
+ interface CanvasTileEngineProps {
233
+ /** Engine handle from useCanvasTileEngine hook (required) */
234
+ engine: EngineHandle;
235
+ /** Engine configuration */
236
+ config: CanvasTileEngineConfig;
237
+ /** Initial center coordinates */
238
+ center?: Coords;
239
+ /** Additional class name for the wrapper div */
240
+ className?: string;
241
+ /** Additional styles for the wrapper div */
242
+ style?: React.CSSProperties;
243
+ /** Draw components (Rect, Circle, Image, GridLines, etc.) */
244
+ children?: React.ReactNode;
245
+ /** Callback when center coordinates change */
246
+ onCoordsChange?: (coords: Coords) => void;
247
+ /** Callback when a tile is clicked */
248
+ onClick?: onClickCallback;
249
+ /** Callback when hovering over tiles */
250
+ onHover?: onHoverCallback;
251
+ /** Callback on mouse down */
252
+ onMouseDown?: () => void;
253
+ /** Callback on mouse up */
254
+ onMouseUp?: () => void;
255
+ /** Callback on mouse leave */
256
+ onMouseLeave?: () => void;
257
+ /** Callback after each draw frame */
258
+ onDraw?: onDrawCallback;
259
+ /** Callback on canvas resize */
260
+ onResize?: () => void;
261
+ }
262
+
263
+ /**
264
+ * React component that renders a CanvasTileEngine.
265
+ * Supports both imperative API (via engine handle) and declarative API (via children).
266
+ *
267
+ * @example Declarative API with compound components
268
+ * ```tsx
269
+ * function App() {
270
+ * const engine = useCanvasTileEngine();
271
+ *
272
+ * return (
273
+ * <CanvasTileEngine engine={engine} config={config}>
274
+ * <CanvasTileEngine.GridLines cellSize={50} layer={0} />
275
+ * <CanvasTileEngine.Image items={imageItems} layer={1} />
276
+ * <CanvasTileEngine.Circle items={markers} layer={2} />
277
+ * </CanvasTileEngine>
278
+ * );
279
+ * }
280
+ * ```
281
+ *
282
+ * @example Imperative API
283
+ * ```tsx
284
+ * function App() {
285
+ * const engine = useCanvasTileEngine();
286
+ *
287
+ * useEffect(() => {
288
+ * if (engine.isReady) {
289
+ * engine.drawGridLines(50);
290
+ * engine.render();
291
+ * }
292
+ * }, [engine.isReady]);
293
+ *
294
+ * return <CanvasTileEngine engine={engine} config={config} />;
295
+ * }
296
+ * ```
297
+ */
298
+ declare function CanvasTileEngineBase({ engine, config, center, className, style, children, onCoordsChange, onClick, onHover, onMouseDown, onMouseUp, onMouseLeave, onDraw, onResize, }: CanvasTileEngineProps): react_jsx_runtime.JSX.Element;
299
+ declare const CanvasTileEngine: typeof CanvasTileEngineBase & {
300
+ Rect: react.NamedExoticComponent<RectProps>;
301
+ Circle: react.NamedExoticComponent<CircleProps>;
302
+ Image: react.NamedExoticComponent<ImageProps>;
303
+ GridLines: react.NamedExoticComponent<GridLinesProps>;
304
+ Line: react.NamedExoticComponent<LineProps>;
305
+ Text: react.NamedExoticComponent<TextProps>;
306
+ Path: react.NamedExoticComponent<PathProps>;
307
+ StaticRect: react.NamedExoticComponent<StaticRectProps>;
308
+ StaticCircle: react.NamedExoticComponent<StaticCircleProps>;
309
+ StaticImage: react.NamedExoticComponent<StaticImageProps>;
310
+ DrawFunction: react.NamedExoticComponent<DrawFunctionProps>;
311
+ };
312
+
313
+ interface EngineContextValue {
314
+ engine: EngineHandle;
315
+ /** Request a re-render of the canvas */
316
+ requestRender: () => void;
317
+ }
318
+ /**
319
+ * Hook to access the engine context from child components.
320
+ * Must be used within a CanvasTileEngine component.
321
+ */
322
+ declare function useEngineContext(): EngineContextValue;
323
+
324
+ export { CanvasTileEngine, type CanvasTileEngineProps, type CircleProps, type DrawFunctionProps, type EngineContextValue, type EngineHandle, type GridLinesProps, type ImageProps, type LineProps, type PathProps, type RectProps, type StaticCircleProps, type StaticImageProps, type StaticRectProps, type TextProps, useCanvasTileEngine, useEngineContext };
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";var O=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ne=Object.getOwnPropertyNames;var te=Object.prototype.hasOwnProperty;var oe=(r,o)=>{for(var t in o)O(r,t,{get:o[t],enumerable:!0})},ae=(r,o,t,a)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of ne(o))!te.call(r,n)&&n!==t&&O(r,n,{get:()=>o[n],enumerable:!(a=re(o,n))||a.enumerable});return r};var ie=r=>ae(O({},"__esModule",{value:!0}),r);var le={};oe(le,{CanvasTileEngine:()=>j,CanvasTileEngineCore:()=>K.CanvasTileEngine,useCanvasTileEngine:()=>k,useEngineContext:()=>c});module.exports=ie(le);var m=require("react"),$=require("@canvas-tile-engine/core");var R=require("react"),L=(0,R.createContext)(null);function c(){let r=(0,R.useContext)(L);if(!r)throw new Error("useEngineContext must be used within a CanvasTileEngine component");return r}var S=require("react");var _=(0,S.memo)(function({items:o,layer:t=1}){let{engine:a,requestRender:n}=c();return(0,S.useEffect)(()=>{let s=a.drawRect(o,t);return n(),()=>{s&&a.removeLayerHandle(s)}},[a,o,t,n]),null});var P=require("react");var V=(0,P.memo)(function({items:o,layer:t=1}){let{engine:a,requestRender:n}=c();return(0,P.useEffect)(()=>{let s=a.drawCircle(o,t);return n(),()=>{s&&a.removeLayerHandle(s)}},[a,o,t,n]),null});var h=require("react");var B=(0,h.memo)(function({items:o,layer:t=1}){let{engine:a,requestRender:n}=c();return(0,h.useEffect)(()=>{let s=a.drawImage(o,t);return n(),()=>{s&&a.removeLayerHandle(s)}},[a,o,t,n]),null});var I=require("react");var W=(0,I.memo)(function({cellSize:o,lineWidth:t=1,strokeStyle:a="black",layer:n=0}){let{engine:s,requestRender:e}=c();return(0,I.useEffect)(()=>{let i=s.drawGridLines(o,t,a,n);return e(),()=>{i&&s.removeLayerHandle(i)}},[s,o,t,a,n,e]),null});var T=require("react");var Y=(0,T.memo)(function({items:o,style:t,layer:a=1}){let{engine:n,requestRender:s}=c();return(0,T.useEffect)(()=>{let e=n.drawLine(o,t,a);return s(),()=>{e&&n.removeLayerHandle(e)}},[n,o,t,a,s]),null});var H=require("react");var X=(0,H.memo)(function({items:o,style:t,layer:a=2}){let{engine:n,requestRender:s}=c();return(0,H.useEffect)(()=>{let e=n.drawText(o,t,a);return s(),()=>{e&&n.removeLayerHandle(e)}},[n,o,t,a,s]),null});var D=require("react");var N=(0,D.memo)(function({items:o,style:t,layer:a=1}){let{engine:n,requestRender:s}=c();return(0,D.useEffect)(()=>{let e=n.drawPath(o,t,a);return s(),()=>{e&&n.removeLayerHandle(e)}},[n,o,t,a,s]),null});var y=require("react");var U=(0,y.memo)(function({items:o,cacheKey:t,layer:a=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 i=n.drawStaticRect(o,t,a);return s(),()=>{i&&n.removeLayerHandle(i)}},[n,o,t,a,s]),(0,y.useEffect)(()=>()=>{n.clearStaticCache(t)},[n,t]),null});var x=require("react");var J=(0,x.memo)(function({items:o,cacheKey:t,layer:a=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 i=n.drawStaticCircle(o,t,a);return s(),()=>{i&&n.removeLayerHandle(i)}},[n,o,t,a,s]),(0,x.useEffect)(()=>()=>{n.clearStaticCache(t)},[n,t]),null});var v=require("react");var Q=(0,v.memo)(function({items:o,cacheKey:t,layer:a=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 i=n.drawStaticImage(o,t,a);return s(),()=>{i&&n.removeLayerHandle(i)}},[n,o,t,a,s]),(0,v.useEffect)(()=>()=>{n.clearStaticCache(t)},[n,t]),null});var b=require("react");var Z=(0,b.memo)(function({children:o,layer:t=1}){let{engine:a,requestRender:n}=c(),s=(0,b.useRef)(o);return(0,b.useEffect)(()=>{s.current=o}),(0,b.useEffect)(()=>{let e=a.addDrawFunction((i,l,f)=>{s.current(i,l,f)},t);return n(),()=>{e&&a.removeLayerHandle(e)}},[a,t,n]),null});var w=require("react/jsx-runtime");function se({engine:r,config:o,center:t={x:0,y:0},className:a,style:n,children:s,onCoordsChange:e,onClick:i,onHover:l,onMouseDown:f,onMouseUp:z,onMouseLeave:q,onDraw:F,onResize:M}){let g=(0,m.useRef)({onCoordsChange:e,onClick:i,onHover:l,onMouseDown:f,onMouseUp:z,onMouseLeave:q,onDraw:F,onResize:M});(0,m.useEffect)(()=>{g.current={onCoordsChange:e,onClick:i,onHover:l,onMouseDown:f,onMouseUp:z,onMouseLeave:q,onDraw:F,onResize:M}});let E=(0,m.useRef)(null),G=(0,m.useCallback)(()=>{E.current===null&&(E.current=requestAnimationFrame(()=>{E.current=null,r.render()}))},[r]);(0,m.useEffect)(()=>()=>{E.current!==null&&cancelAnimationFrame(E.current)},[]);let ee=(0,m.useMemo)(()=>({engine:r,requestRender:G}),[r,G]);return(0,m.useEffect)(()=>{let A=r._containerRef.current;if(!A)return;let u=new $.CanvasTileEngine(A,o,t);return u.onCoordsChange=C=>g.current.onCoordsChange?.(C),u.onClick=(...C)=>g.current.onClick?.(...C),u.onHover=(...C)=>g.current.onHover?.(...C),u.onMouseDown=()=>g.current.onMouseDown?.(),u.onMouseUp=()=>g.current.onMouseUp?.(),u.onMouseLeave=()=>g.current.onMouseLeave?.(),u.onDraw=(...C)=>g.current.onDraw?.(...C),u.onResize=()=>g.current.onResize?.(),r._setInstance(u),u.render(),()=>{u.destroy(),r._setInstance(null)}},[r]),(0,w.jsxs)(L.Provider,{value:ee,children:[(0,w.jsx)("div",{ref:r._containerRef,className:a,style:{...n},children:(0,w.jsx)("canvas",{})}),r.isReady&&s]})}var j=Object.assign(se,{Rect:_,Circle:V,Image:B,GridLines:W,Line:Y,Text:X,Path:N,StaticRect:U,StaticCircle:J,StaticImage:Q,DrawFunction:Z});var p=require("react"),d={layer:-1,id:Symbol("dummy")},ce={size:{width:0,height:0,minWidth:100,minHeight:100,maxWidth:1/0,maxHeight:1/0},scale:1,minScale:.5,maxScale:2,backgroundColor:"#ffffff",renderer:"canvas",eventHandlers:{drag:!0,zoom:!0,hover:!1,click:!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 k(){let r=(0,p.useRef)(null),o=(0,p.useRef)(null),[t,a]=(0,p.useState)(!1),n=(0,p.useCallback)(e=>{r.current=e,a(e!==null)},[]);return(0,p.useMemo)(()=>({_containerRef:o,_setInstance:n,get isReady(){return t},get instance(){return r.current},get images(){return r.current?.images},render(){r.current?.render()},getCenterCoords(){return r.current?.getCenterCoords()??{x:0,y:0}},updateCoords(e){r.current?.updateCoords(e)},goCoords(e,i,l,f){r.current?.goCoords(e,i,l,f)},resize(e,i,l,f){r.current?.resize(e,i,l,f)},getSize(){return r.current?.getSize()??{width:0,height:0}},getScale(){return r.current?.getScale()??1},zoomIn(e){r.current?.zoomIn(e)},zoomOut(e){r.current?.zoomOut(e)},getConfig(){return r.current?.getConfig()??ce},setBounds(e){r.current?.setBounds(e)},setEventHandlers(e){r.current?.setEventHandlers(e)},drawRect(e,i){return r.current?.drawRect(e,i)??d},drawStaticRect(e,i,l){return r.current?.drawStaticRect(e,i,l)??d},drawCircle(e,i){return r.current?.drawCircle(e,i)??d},drawStaticCircle(e,i,l){return r.current?.drawStaticCircle(e,i,l)??d},drawLine(e,i,l){return r.current?.drawLine(e,i,l)??d},drawText(e,i,l){return r.current?.drawText(e,i,l)??d},drawPath(e,i,l){return r.current?.drawPath(e,i,l)??d},drawImage(e,i){return r.current?.drawImage(e,i)??d},drawStaticImage(e,i,l){return r.current?.drawStaticImage(e,i,l)??d},drawGridLines(e,i,l,f){return r.current?.drawGridLines(e,i,l,f)??d},addDrawFunction(e,i){return r.current?.addDrawFunction(e,i)??d},clearLayer(e){r.current?.clearLayer(e)},clearAll(){r.current?.clearAll()},clearStaticCache(e){r.current?.clearStaticCache(e)},removeLayerHandle(e){r.current?.removeLayerHandle(e)}}),[n,t])}var K=require("@canvas-tile-engine/core");0&&(module.exports={CanvasTileEngine,CanvasTileEngineCore,useCanvasTileEngine,useEngineContext});
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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 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 with different name\nexport { CanvasTileEngine as CanvasTileEngineCore } 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 onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n}: CanvasTileEngineProps) {\n // Stable callback refs\n const callbacksRef = useRef({\n onCoordsChange,\n onClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n });\n\n // Update callback refs\n useEffect(() => {\n callbacksRef.current = {\n onCoordsChange,\n onClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\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.onHover = (...args) => callbacksRef.current.onHover?.(...args);\n instance.onMouseDown = () => callbacksRef.current.onMouseDown?.();\n instance.onMouseUp = () => callbacksRef.current.onMouseUp?.();\n instance.onMouseLeave = () => callbacksRef.current.onMouseLeave?.();\n instance.onDraw = (...args) => callbacksRef.current.onDraw?.(...args);\n instance.onResize = () => callbacksRef.current.onResize?.();\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 scale: 1,\n minScale: 0.5,\n maxScale: 2,\n backgroundColor: \"#ffffff\",\n renderer: \"canvas\",\n eventHandlers: {\n drag: true,\n zoom: true,\n hover: false,\n click: 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 /** 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 /** 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 const [isReady, setIsReady] = useState(false);\n\n const setInstance = useCallback((engine: CanvasTileEngineCore | null) => {\n instanceRef.current = engine;\n setIsReady(engine !== null);\n }, []);\n\n // Create stable handle object using useMemo\n const handle = useMemo<EngineHandle>(\n () => ({\n _containerRef: containerRef,\n _setInstance: setInstance,\n\n get isReady() {\n return isReady;\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 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 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 instanceRef.current?.drawGridLines(cellSize, lineWidth, strokeStyle, layer) ?? DUMMY_LAYER_HANDLE;\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, isReady]\n );\n\n return handle;\n}\n"],"mappings":"mbAAA,IAAAA,GAAA,GAAAC,GAAAD,GAAA,sBAAAE,EA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AKpB,CACjE,EAEA,SAASmB,EAAOG,EAAOF,EAAO,CAC1B,OAAOjB,EAAY,SAAS,SAASgB,EAAOG,EAAOF,CAAK,GAAKpB,CACjE,EAEA,SAASmB,EAAOG,EAAOF,EAAO,CAC1B,OAAOjB,EAAY,SAAS,SAASgB,EAAOG,EAAOF,CAAK,GAAKpB,CACjE,EAEA,UAAUmB,EAAOC,EAAO,CACpB,OAAOjB,EAAY,SAAS,UAAUgB,EAAOC,CAAK,GAAKpB,CAC3D,EAEA,gBAAgBmB,EAAOE,EAAUD,EAAO,CACpC,OAAOjB,EAAY,SAAS,gBAAgBgB,EAAOE,EAAUD,CAAK,GAAKpB,CAC3E,EAEA,cAAcuB,EAAUC,EAAWC,EAAaL,EAAO,CACnD,OAAOjB,EAAY,SAAS,cAAcoB,EAAUC,EAAWC,EAAaL,CAAK,GAAKpB,CAC1F,EAEA,gBAAgB0B,EAAIN,EAAO,CACvB,OAAOjB,EAAY,SAAS,gBAAgBuB,EAAIN,CAAK,GAAKpB,CAC9D,EAEA,WAAWoB,EAAO,CACdjB,EAAY,SAAS,WAAWiB,CAAK,CACzC,EAEA,UAAW,CACPjB,EAAY,SAAS,SAAS,CAClC,EAEA,iBAAiBkB,EAAU,CACvBlB,EAAY,SAAS,iBAAiBkB,CAAQ,CAClD,EAEA,kBAAkBM,EAAQ,CACtBxB,EAAY,SAAS,kBAAkBwB,CAAM,CACjD,CACJ,GACA,CAACpB,EAAaF,CAAO,CACzB,CAGJ,Cd1TA,IAAAuB,EAAyD","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","onHover","onMouseDown","onMouseUp","onMouseLeave","onDraw","onResize","callbacksRef","rafIdRef","requestRender","contextValue","container","instance","CanvasTileEngineCore","coords","args","EngineContext","CanvasTileEngine","Rect","Circle","Image","GridLines","Line","Text","Path","StaticRect","StaticCircle","StaticImage","DrawFunction","import_react","DUMMY_LAYER_HANDLE","DEFAULT_CONFIG","useCanvasTileEngine","instanceRef","containerRef","isReady","setIsReady","setInstance","engine","center","x","y","durationMs","onComplete","width","height","factor","bounds","handlers","items","layer","cacheKey","style","cellSize","lineWidth","strokeStyle","fn","handle","import_core"]}
package/dist/index.mjs ADDED
@@ -0,0 +1,2 @@
1
+ import{useEffect as y,useRef as G,useCallback as pe,useMemo as Ce}from"react";import{CanvasTileEngine as ye}from"@canvas-tile-engine/core";import{createContext as Y,useContext as X}from"react";var C=Y(null);function c(){let r=X(C);if(!r)throw new Error("useEngineContext must be used within a CanvasTileEngine component");return r}import{useEffect as N,memo as U}from"react";var L=U(function({items:i,layer:n=1}){let{engine:a,requestRender:t}=c();return N(()=>{let s=a.drawRect(i,n);return t(),()=>{s&&a.removeLayerHandle(s)}},[a,i,n,t]),null});import{useEffect as J,memo as Q}from"react";var S=Q(function({items:i,layer:n=1}){let{engine:a,requestRender:t}=c();return J(()=>{let s=a.drawCircle(i,n);return t(),()=>{s&&a.removeLayerHandle(s)}},[a,i,n,t]),null});import{useEffect as Z,memo as $}from"react";var P=$(function({items:i,layer:n=1}){let{engine:a,requestRender:t}=c();return Z(()=>{let s=a.drawImage(i,n);return t(),()=>{s&&a.removeLayerHandle(s)}},[a,i,n,t]),null});import{useEffect as K,memo as ee}from"react";var h=ee(function({cellSize:i,lineWidth:n=1,strokeStyle:a="black",layer:t=0}){let{engine:s,requestRender:e}=c();return K(()=>{let o=s.drawGridLines(i,n,a,t);return e(),()=>{o&&s.removeLayerHandle(o)}},[s,i,n,a,t,e]),null});import{useEffect as re,memo as ne}from"react";var I=ne(function({items:i,style:n,layer:a=1}){let{engine:t,requestRender:s}=c();return re(()=>{let e=t.drawLine(i,n,a);return s(),()=>{e&&t.removeLayerHandle(e)}},[t,i,n,a,s]),null});import{useEffect as te,memo as oe}from"react";var T=oe(function({items:i,style:n,layer:a=2}){let{engine:t,requestRender:s}=c();return te(()=>{let e=t.drawText(i,n,a);return s(),()=>{e&&t.removeLayerHandle(e)}},[t,i,n,a,s]),null});import{useEffect as ae,memo as ie}from"react";var H=ie(function({items:i,style:n,layer:a=1}){let{engine:t,requestRender:s}=c();return ae(()=>{let e=t.drawPath(i,n,a);return s(),()=>{e&&t.removeLayerHandle(e)}},[t,i,n,a,s]),null});import{useEffect as D,useRef as se,memo as ce}from"react";var O=ce(function({items:i,cacheKey:n,layer:a=1}){let{engine:t,requestRender:s}=c(),e=se(n);return D(()=>{if(i.length===0)return;e.current!==n&&(t.clearStaticCache(e.current),e.current=n);let o=t.drawStaticRect(i,n,a);return s(),()=>{o&&t.removeLayerHandle(o)}},[t,i,n,a,s]),D(()=>()=>{t.clearStaticCache(n)},[t,n]),null});import{useEffect as j,useRef as le,memo as ue}from"react";var k=ue(function({items:i,cacheKey:n,layer:a=1}){let{engine:t,requestRender:s}=c(),e=le(n);return j(()=>{if(i.length===0)return;e.current!==n&&(t.clearStaticCache(e.current),e.current=n);let o=t.drawStaticCircle(i,n,a);return s(),()=>{o&&t.removeLayerHandle(o)}},[t,i,n,a,s]),j(()=>()=>{t.clearStaticCache(n)},[t,n]),null});import{useEffect as z,useRef as me,memo as de}from"react";var q=de(function({items:i,cacheKey:n,layer:a=1}){let{engine:t,requestRender:s}=c(),e=me(n);return z(()=>{if(i.length===0)return;e.current!==n&&(t.clearStaticCache(e.current),e.current=n);let o=t.drawStaticImage(i,n,a);return s(),()=>{o&&t.removeLayerHandle(o)}},[t,i,n,a,s]),z(()=>()=>{t.clearStaticCache(n)},[t,n]),null});import{useEffect as F,useRef as fe,memo as ge}from"react";var M=ge(function({children:i,layer:n=1}){let{engine:a,requestRender:t}=c(),s=fe(i);return F(()=>{s.current=i}),F(()=>{let e=a.addDrawFunction((o,l,d)=>{s.current(o,l,d)},n);return t(),()=>{e&&a.removeLayerHandle(e)}},[a,n,t]),null});import{jsx as A,jsxs as ve}from"react/jsx-runtime";function xe({engine:r,config:i,center:n={x:0,y:0},className:a,style:t,children:s,onCoordsChange:e,onClick:o,onHover:l,onMouseDown:d,onMouseUp:x,onMouseLeave:v,onDraw:b,onResize:E}){let f=G({onCoordsChange:e,onClick:o,onHover:l,onMouseDown:d,onMouseUp:x,onMouseLeave:v,onDraw:b,onResize:E});y(()=>{f.current={onCoordsChange:e,onClick:o,onHover:l,onMouseDown:d,onMouseUp:x,onMouseLeave:v,onDraw:b,onResize:E}});let p=G(null),w=pe(()=>{p.current===null&&(p.current=requestAnimationFrame(()=>{p.current=null,r.render()}))},[r]);y(()=>()=>{p.current!==null&&cancelAnimationFrame(p.current)},[]);let W=Ce(()=>({engine:r,requestRender:w}),[r,w]);return y(()=>{let R=r._containerRef.current;if(!R)return;let u=new ye(R,i,n);return u.onCoordsChange=g=>f.current.onCoordsChange?.(g),u.onClick=(...g)=>f.current.onClick?.(...g),u.onHover=(...g)=>f.current.onHover?.(...g),u.onMouseDown=()=>f.current.onMouseDown?.(),u.onMouseUp=()=>f.current.onMouseUp?.(),u.onMouseLeave=()=>f.current.onMouseLeave?.(),u.onDraw=(...g)=>f.current.onDraw?.(...g),u.onResize=()=>f.current.onResize?.(),r._setInstance(u),u.render(),()=>{u.destroy(),r._setInstance(null)}},[r]),ve(C.Provider,{value:W,children:[A("div",{ref:r._containerRef,className:a,style:{...t},children:A("canvas",{})}),r.isReady&&s]})}var _=Object.assign(xe,{Rect:L,Circle:S,Image:P,GridLines:h,Line:I,Text:T,Path:H,StaticRect:O,StaticCircle:k,StaticImage:q,DrawFunction:M});import{useRef as V,useCallback as be,useState as Ee,useMemo as we}from"react";var m={layer:-1,id:Symbol("dummy")},Re={size:{width:0,height:0,minWidth:100,minHeight:100,maxWidth:1/0,maxHeight:1/0},scale:1,minScale:.5,maxScale:2,backgroundColor:"#ffffff",renderer:"canvas",eventHandlers:{drag:!0,zoom:!0,hover:!1,click:!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 B(){let r=V(null),i=V(null),[n,a]=Ee(!1),t=be(e=>{r.current=e,a(e!==null)},[]);return we(()=>({_containerRef:i,_setInstance:t,get isReady(){return n},get instance(){return r.current},get images(){return r.current?.images},render(){r.current?.render()},getCenterCoords(){return r.current?.getCenterCoords()??{x:0,y:0}},updateCoords(e){r.current?.updateCoords(e)},goCoords(e,o,l,d){r.current?.goCoords(e,o,l,d)},resize(e,o,l,d){r.current?.resize(e,o,l,d)},getSize(){return r.current?.getSize()??{width:0,height:0}},getScale(){return r.current?.getScale()??1},zoomIn(e){r.current?.zoomIn(e)},zoomOut(e){r.current?.zoomOut(e)},getConfig(){return r.current?.getConfig()??Re},setBounds(e){r.current?.setBounds(e)},setEventHandlers(e){r.current?.setEventHandlers(e)},drawRect(e,o){return r.current?.drawRect(e,o)??m},drawStaticRect(e,o,l){return r.current?.drawStaticRect(e,o,l)??m},drawCircle(e,o){return r.current?.drawCircle(e,o)??m},drawStaticCircle(e,o,l){return r.current?.drawStaticCircle(e,o,l)??m},drawLine(e,o,l){return r.current?.drawLine(e,o,l)??m},drawText(e,o,l){return r.current?.drawText(e,o,l)??m},drawPath(e,o,l){return r.current?.drawPath(e,o,l)??m},drawImage(e,o){return r.current?.drawImage(e,o)??m},drawStaticImage(e,o,l){return r.current?.drawStaticImage(e,o,l)??m},drawGridLines(e,o,l,d){return r.current?.drawGridLines(e,o,l,d)??m},addDrawFunction(e,o){return r.current?.addDrawFunction(e,o)??m},clearLayer(e){r.current?.clearLayer(e)},clearAll(){r.current?.clearAll()},clearStaticCache(e){r.current?.clearStaticCache(e)},removeLayerHandle(e){r.current?.removeLayerHandle(e)}}),[t,n])}import{CanvasTileEngine as kr}from"@canvas-tile-engine/core";export{_ as CanvasTileEngine,kr as CanvasTileEngineCore,B as useCanvasTileEngine,c as useEngineContext};
2
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../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","../src/index.ts"],"sourcesContent":["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 onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n}: CanvasTileEngineProps) {\n // Stable callback refs\n const callbacksRef = useRef({\n onCoordsChange,\n onClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\n });\n\n // Update callback refs\n useEffect(() => {\n callbacksRef.current = {\n onCoordsChange,\n onClick,\n onHover,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDraw,\n onResize,\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.onHover = (...args) => callbacksRef.current.onHover?.(...args);\n instance.onMouseDown = () => callbacksRef.current.onMouseDown?.();\n instance.onMouseUp = () => callbacksRef.current.onMouseUp?.();\n instance.onMouseLeave = () => callbacksRef.current.onMouseLeave?.();\n instance.onDraw = (...args) => callbacksRef.current.onDraw?.(...args);\n instance.onResize = () => callbacksRef.current.onResize?.();\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 scale: 1,\n minScale: 0.5,\n maxScale: 2,\n backgroundColor: \"#ffffff\",\n renderer: \"canvas\",\n eventHandlers: {\n drag: true,\n zoom: true,\n hover: false,\n click: 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 /** 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 /** 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 const [isReady, setIsReady] = useState(false);\n\n const setInstance = useCallback((engine: CanvasTileEngineCore | null) => {\n instanceRef.current = engine;\n setIsReady(engine !== null);\n }, []);\n\n // Create stable handle object using useMemo\n const handle = useMemo<EngineHandle>(\n () => ({\n _containerRef: containerRef,\n _setInstance: setInstance,\n\n get isReady() {\n return isReady;\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 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 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 instanceRef.current?.drawGridLines(cellSize, lineWidth, strokeStyle, layer) ?? DUMMY_LAYER_HANDLE;\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, isReady]\n );\n\n return handle;\n}\n","// 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 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 with different name\nexport { CanvasTileEngine as CanvasTileEngineCore } from \"@canvas-tile-engine/core\";\n"],"mappings":"AAAA,OAAS,aAAAA,EAAW,UAAAC,EAAQ,eAAAC,GAAa,WAAAC,OAAe,QACxD,OAAS,oBAAoBC,OAA4B,2BCDzD,OAAS,iBAAAC,EAAe,cAAAC,MAAkB,QASnC,IAAMC,EAAgBF,EAAyC,IAAI,EAMnE,SAASG,GAAuC,CACnD,IAAMC,EAAUH,EAAWC,CAAa,EAExC,GAAI,CAACE,EACD,MAAM,IAAI,MAAM,mEAAmE,EAGvF,OAAOA,CACX,CCvBA,OAAS,aAAAC,EAAW,QAAAC,MAAY,QAYzB,IAAMC,EAAOC,EAAK,SAAc,CAAE,MAAAC,EAAO,MAAAC,EAAQ,CAAE,EAAc,CACpE,GAAM,CAAE,OAAAC,EAAQ,cAAAC,CAAc,EAAIC,EAAiB,EAEnD,OAAAC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pB,CACjE,EAEA,SAASmB,EAAOG,EAAOF,EAAO,CAC1B,OAAOjB,EAAY,SAAS,SAASgB,EAAOG,EAAOF,CAAK,GAAKpB,CACjE,EAEA,SAASmB,EAAOG,EAAOF,EAAO,CAC1B,OAAOjB,EAAY,SAAS,SAASgB,EAAOG,EAAOF,CAAK,GAAKpB,CACjE,EAEA,UAAUmB,EAAOC,EAAO,CACpB,OAAOjB,EAAY,SAAS,UAAUgB,EAAOC,CAAK,GAAKpB,CAC3D,EAEA,gBAAgBmB,EAAOE,EAAUD,EAAO,CACpC,OAAOjB,EAAY,SAAS,gBAAgBgB,EAAOE,EAAUD,CAAK,GAAKpB,CAC3E,EAEA,cAAcuB,EAAUC,EAAWC,EAAaL,EAAO,CACnD,OAAOjB,EAAY,SAAS,cAAcoB,EAAUC,EAAWC,EAAaL,CAAK,GAAKpB,CAC1F,EAEA,gBAAgB0B,EAAIN,EAAO,CACvB,OAAOjB,EAAY,SAAS,gBAAgBuB,EAAIN,CAAK,GAAKpB,CAC9D,EAEA,WAAWoB,EAAO,CACdjB,EAAY,SAAS,WAAWiB,CAAK,CACzC,EAEA,UAAW,CACPjB,EAAY,SAAS,SAAS,CAClC,EAEA,iBAAiBkB,EAAU,CACvBlB,EAAY,SAAS,iBAAiBkB,CAAQ,CAClD,EAEA,kBAAkBM,EAAQ,CACtBxB,EAAY,SAAS,kBAAkBwB,CAAM,CACjD,CACJ,GACA,CAACpB,EAAaF,CAAO,CACzB,CAGJ,CC1TA,OAA6B,oBAApBuB,OAAgD","names":["useEffect","useRef","useCallback","useMemo","CanvasTileEngineCore","createContext","useContext","EngineContext","useEngineContext","context","useEffect","memo","Rect","memo","items","layer","engine","requestRender","useEngineContext","useEffect","handle","useEffect","memo","Circle","memo","items","layer","engine","requestRender","useEngineContext","useEffect","handle","useEffect","memo","Image","memo","items","layer","engine","requestRender","useEngineContext","useEffect","handle","useEffect","memo","GridLines","memo","cellSize","lineWidth","strokeStyle","layer","engine","requestRender","useEngineContext","useEffect","handle","useEffect","memo","Line","memo","items","style","layer","engine","requestRender","useEngineContext","useEffect","handle","useEffect","memo","Text","memo","items","style","layer","engine","requestRender","useEngineContext","useEffect","handle","useEffect","memo","Path","memo","items","style","layer","engine","requestRender","useEngineContext","useEffect","handle","useEffect","useRef","memo","StaticRect","memo","items","cacheKey","layer","engine","requestRender","useEngineContext","prevCacheKeyRef","useRef","useEffect","handle","useEffect","useRef","memo","StaticCircle","memo","items","cacheKey","layer","engine","requestRender","useEngineContext","prevCacheKeyRef","useRef","useEffect","handle","useEffect","useRef","memo","StaticImage","memo","items","cacheKey","layer","engine","requestRender","useEngineContext","prevCacheKeyRef","useRef","useEffect","handle","useEffect","useRef","memo","DrawFunction","memo","children","layer","engine","requestRender","useEngineContext","fnRef","useRef","useEffect","handle","ctx","coords","config","jsx","jsxs","CanvasTileEngineBase","engine","config","center","className","style","children","onCoordsChange","onClick","onHover","onMouseDown","onMouseUp","onMouseLeave","onDraw","onResize","callbacksRef","useRef","useEffect","rafIdRef","requestRender","useCallback","contextValue","useMemo","container","instance","CanvasTileEngineCore","coords","args","EngineContext","CanvasTileEngine","Rect","Circle","Image","GridLines","Line","Text","Path","StaticRect","StaticCircle","StaticImage","DrawFunction","useRef","useCallback","useState","useMemo","DUMMY_LAYER_HANDLE","DEFAULT_CONFIG","useCanvasTileEngine","instanceRef","containerRef","isReady","setIsReady","setInstance","engine","center","x","y","durationMs","onComplete","width","height","factor","bounds","handlers","items","layer","cacheKey","style","cellSize","lineWidth","strokeStyle","fn","handle","CanvasTileEngine"]}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@canvas-tile-engine/react",
3
+ "version": "0.0.1",
4
+ "description": "React bindings for Canvas Tile Engine - build interactive 2D grid-based maps with declarative components",
5
+ "author": "Enes Yüksel",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/enesyukselx/canvas-tile-engine.git",
10
+ "directory": "packages/react"
11
+ },
12
+ "homepage": "https://canvastileengine.dev",
13
+ "bugs": {
14
+ "url": "https://github.com/enesyukselx/canvas-tile-engine/issues"
15
+ },
16
+ "keywords": [
17
+ "canvas",
18
+ "tile",
19
+ "engine",
20
+ "react",
21
+ "2d",
22
+ "map",
23
+ "game",
24
+ "grid",
25
+ "visualization",
26
+ "component"
27
+ ],
28
+ "sideEffects": false,
29
+ "main": "dist/index.cjs",
30
+ "module": "dist/index.mjs",
31
+ "types": "dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "types": "./dist/index.d.ts",
35
+ "import": "./dist/index.mjs",
36
+ "require": "./dist/index.cjs"
37
+ }
38
+ },
39
+ "files": [
40
+ "dist"
41
+ ],
42
+ "scripts": {
43
+ "build": "tsup",
44
+ "dev": "tsup --watch",
45
+ "typecheck": "tsc --noEmit"
46
+ },
47
+ "peerDependencies": {
48
+ "react": ">=18.0.0",
49
+ "react-dom": ">=18.0.0",
50
+ "@canvas-tile-engine/core": ">=0.0.1"
51
+ },
52
+ "dependencies": {
53
+ "@canvas-tile-engine/core": "workspace:*"
54
+ },
55
+ "devDependencies": {
56
+ "@types/react": "^18.3.0",
57
+ "@types/react-dom": "^18.3.0"
58
+ }
59
+ }