@canvas-tile-engine/core 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +162 -49
- package/dist/index.d.ts +162 -49
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -147,23 +147,27 @@ type DrawObject = {
|
|
|
147
147
|
radius?: number | number[];
|
|
148
148
|
};
|
|
149
149
|
type Rect = DrawObject;
|
|
150
|
+
type Circle = Omit<DrawObject, "rotate" | "radius">;
|
|
151
|
+
type ImageItem = Omit<DrawObject, "style"> & {
|
|
152
|
+
img: HTMLImageElement;
|
|
153
|
+
};
|
|
154
|
+
type Text = Omit<DrawObject, "radius" | "size"> & {
|
|
155
|
+
text: string;
|
|
156
|
+
/** Font size in world units (scales with zoom). Default: 1 */
|
|
157
|
+
size?: number;
|
|
158
|
+
style?: {
|
|
159
|
+
fillStyle?: string;
|
|
160
|
+
/** Font family (default: "sans-serif") */
|
|
161
|
+
fontFamily?: string;
|
|
162
|
+
textAlign?: CanvasTextAlign;
|
|
163
|
+
textBaseline?: CanvasTextBaseline;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
150
166
|
type Line = {
|
|
151
167
|
from: Coords;
|
|
152
168
|
to: Coords;
|
|
153
|
-
style: {
|
|
154
|
-
strokeStyle?: string;
|
|
155
|
-
lineWidth?: number;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
type Circle = Omit<DrawObject, "rotate" | "radius">;
|
|
159
|
-
type Text = {
|
|
160
|
-
coords: Coords;
|
|
161
|
-
text: string;
|
|
162
169
|
};
|
|
163
170
|
type Path = Coords[];
|
|
164
|
-
type ImageItem = Omit<DrawObject, "style"> & {
|
|
165
|
-
img: HTMLImageElement;
|
|
166
|
-
};
|
|
167
171
|
|
|
168
172
|
/**
|
|
169
173
|
* Core engine wiring camera, config, renderer, events, and draw helpers.
|
|
@@ -183,34 +187,145 @@ declare class CanvasTileEngine {
|
|
|
183
187
|
private responsiveWatcher?;
|
|
184
188
|
canvasWrapper: HTMLDivElement;
|
|
185
189
|
canvas: HTMLCanvasElement;
|
|
186
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* Callback when center coordinates change (pan or zoom).
|
|
192
|
+
* @param coords - Center world coordinates: `{ x, y }`
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* engine.onCoordsChange = (coords) => {
|
|
196
|
+
* console.log(`Center: ${coords.x}, ${coords.y}`);
|
|
197
|
+
* };
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
187
200
|
onCoordsChange?: (coords: Coords) => void;
|
|
188
201
|
private _onClick?;
|
|
202
|
+
/**
|
|
203
|
+
* Callback when a tile is clicked (mouse or touch tap).
|
|
204
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
205
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
206
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* engine.onClick = (coords, mouse, client) => {
|
|
210
|
+
* console.log(`Clicked tile: ${coords.snapped.x}, ${coords.snapped.y}`);
|
|
211
|
+
* };
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
189
214
|
get onClick(): onClickCallback | undefined;
|
|
190
215
|
set onClick(cb: onClickCallback | undefined);
|
|
191
216
|
private _onRightClick?;
|
|
217
|
+
/**
|
|
218
|
+
* Callback when a tile is right-clicked.
|
|
219
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
220
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
221
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* engine.onRightClick = (coords) => {
|
|
225
|
+
* showContextMenu(coords.snapped.x, coords.snapped.y);
|
|
226
|
+
* };
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
192
229
|
get onRightClick(): onRightClickCallback | undefined;
|
|
193
230
|
set onRightClick(cb: onRightClickCallback | undefined);
|
|
194
231
|
private _onHover?;
|
|
232
|
+
/**
|
|
233
|
+
* Callback when hovering over tiles.
|
|
234
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
235
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
236
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* engine.onHover = (coords) => {
|
|
240
|
+
* setHoveredTile({ x: coords.snapped.x, y: coords.snapped.y });
|
|
241
|
+
* };
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
195
244
|
get onHover(): onHoverCallback | undefined;
|
|
196
245
|
set onHover(cb: onHoverCallback | undefined);
|
|
197
246
|
private _onMouseDown?;
|
|
247
|
+
/**
|
|
248
|
+
* Callback on mouse/touch down.
|
|
249
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
250
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
251
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* engine.onMouseDown = (coords) => {
|
|
255
|
+
* startPainting(coords.snapped.x, coords.snapped.y);
|
|
256
|
+
* };
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
198
259
|
get onMouseDown(): onMouseDownCallback | undefined;
|
|
199
260
|
set onMouseDown(cb: onMouseDownCallback | undefined);
|
|
200
261
|
private _onMouseUp?;
|
|
262
|
+
/**
|
|
263
|
+
* Callback on mouse/touch up.
|
|
264
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
265
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
266
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* engine.onMouseUp = (coords) => {
|
|
270
|
+
* stopPainting();
|
|
271
|
+
* };
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
201
274
|
get onMouseUp(): onMouseUpCallback | undefined;
|
|
202
275
|
set onMouseUp(cb: onMouseUpCallback | undefined);
|
|
203
276
|
private _onMouseLeave?;
|
|
277
|
+
/**
|
|
278
|
+
* Callback when mouse/touch leaves the canvas.
|
|
279
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
280
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
281
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* engine.onMouseLeave = () => {
|
|
285
|
+
* clearHoveredTile();
|
|
286
|
+
* };
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
204
289
|
get onMouseLeave(): onMouseLeaveCallback | undefined;
|
|
205
290
|
set onMouseLeave(cb: onMouseLeaveCallback | undefined);
|
|
206
291
|
private _onDraw?;
|
|
292
|
+
/**
|
|
293
|
+
* Callback after each draw frame. Use for custom canvas drawing.
|
|
294
|
+
* @param ctx - The canvas 2D rendering context
|
|
295
|
+
* @param info - Frame info: `scale`, `width`, `height`, `coords` (center)
|
|
296
|
+
* @example
|
|
297
|
+
* ```ts
|
|
298
|
+
* engine.onDraw = (ctx, info) => {
|
|
299
|
+
* ctx.fillStyle = "red";
|
|
300
|
+
* ctx.fillText(`Scale: ${info.scale}`, 10, 20);
|
|
301
|
+
* };
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
207
304
|
get onDraw(): onDrawCallback | undefined;
|
|
208
305
|
set onDraw(cb: onDrawCallback | undefined);
|
|
209
306
|
private _onResize?;
|
|
307
|
+
/**
|
|
308
|
+
* Callback on canvas resize.
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* engine.onResize = () => {
|
|
312
|
+
* console.log("Canvas resized:", engine.getSize());
|
|
313
|
+
* };
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
210
316
|
get onResize(): (() => void) | undefined;
|
|
211
317
|
set onResize(cb: (() => void) | undefined);
|
|
212
318
|
private _onZoom?;
|
|
213
|
-
/**
|
|
319
|
+
/**
|
|
320
|
+
* Callback when zoom level changes (wheel or pinch).
|
|
321
|
+
* @param scale - The new scale value
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* engine.onZoom = (scale) => {
|
|
325
|
+
* console.log(`Zoom level: ${scale}`);
|
|
326
|
+
* };
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
214
329
|
get onZoom(): ((scale: number) => void) | undefined;
|
|
215
330
|
set onZoom(cb: ((scale: number) => void) | undefined);
|
|
216
331
|
/**
|
|
@@ -247,6 +362,7 @@ declare class CanvasTileEngine {
|
|
|
247
362
|
/**
|
|
248
363
|
* Set the canvas scale directly, clamped to min/max bounds.
|
|
249
364
|
* @param newScale The desired scale value.
|
|
365
|
+
* @throws {ConfigValidationError} If scale is not a positive finite number.
|
|
250
366
|
*/
|
|
251
367
|
setScale(newScale: number): void;
|
|
252
368
|
/**
|
|
@@ -282,7 +398,11 @@ declare class CanvasTileEngine {
|
|
|
282
398
|
minY: number;
|
|
283
399
|
maxY: number;
|
|
284
400
|
};
|
|
285
|
-
/**
|
|
401
|
+
/**
|
|
402
|
+
* Set center coordinates from outside (adjusts the camera accordingly).
|
|
403
|
+
* @param newCenter The new center coordinates.
|
|
404
|
+
* @throws {ConfigValidationError} If coordinates are not finite numbers.
|
|
405
|
+
*/
|
|
286
406
|
updateCoords(newCenter: Coords): void;
|
|
287
407
|
/**
|
|
288
408
|
* Smoothly move the camera center to target coordinates over the given duration.
|
|
@@ -290,6 +410,7 @@ declare class CanvasTileEngine {
|
|
|
290
410
|
* @param y Target world y.
|
|
291
411
|
* @param durationMs Animation duration in milliseconds (default: 500ms). Set to 0 for instant move.
|
|
292
412
|
* @param onComplete Optional callback fired when animation completes.
|
|
413
|
+
* @throws {ConfigValidationError} If coordinates are not finite numbers.
|
|
293
414
|
*/
|
|
294
415
|
goCoords(x: number, y: number, durationMs?: number, onComplete?: () => void): void;
|
|
295
416
|
/**
|
|
@@ -342,7 +463,7 @@ declare class CanvasTileEngine {
|
|
|
342
463
|
* @param items Rectangle definitions.
|
|
343
464
|
* @param layer Layer order (lower draws first).
|
|
344
465
|
*/
|
|
345
|
-
drawRect(items:
|
|
466
|
+
drawRect(items: Rect | Array<Rect>, layer?: number): LayerHandle;
|
|
346
467
|
/**
|
|
347
468
|
* Draw rectangles with pre-rendering cache (canvas renderer only).
|
|
348
469
|
* Renders all items once to an offscreen canvas, then blits the visible portion each frame.
|
|
@@ -352,7 +473,7 @@ declare class CanvasTileEngine {
|
|
|
352
473
|
* @param cacheKey Unique key for this cache (e.g., "minimap-items").
|
|
353
474
|
* @param layer Layer order (lower draws first).
|
|
354
475
|
*/
|
|
355
|
-
drawStaticRect(items: Array<
|
|
476
|
+
drawStaticRect(items: Array<Rect>, cacheKey: string, layer?: number): LayerHandle;
|
|
356
477
|
/**
|
|
357
478
|
* Draw circles with pre-rendering cache (canvas renderer only).
|
|
358
479
|
* Renders all items once to an offscreen canvas, then blits the visible portion each frame.
|
|
@@ -361,7 +482,7 @@ declare class CanvasTileEngine {
|
|
|
361
482
|
* @param cacheKey Unique key for this cache (e.g., "minimap-circles").
|
|
362
483
|
* @param layer Layer order (lower draws first).
|
|
363
484
|
*/
|
|
364
|
-
drawStaticCircle(items: Array<
|
|
485
|
+
drawStaticCircle(items: Array<Circle>, cacheKey: string, layer?: number): LayerHandle;
|
|
365
486
|
/**
|
|
366
487
|
* Draw images with pre-rendering cache (canvas renderer only).
|
|
367
488
|
* Renders all items once to an offscreen canvas, then blits the visible portion each frame.
|
|
@@ -371,9 +492,7 @@ declare class CanvasTileEngine {
|
|
|
371
492
|
* @param cacheKey Unique key for this cache (e.g., "terrain-cache").
|
|
372
493
|
* @param layer Layer order (lower draws first).
|
|
373
494
|
*/
|
|
374
|
-
drawStaticImage(items: Array<
|
|
375
|
-
img: HTMLImageElement;
|
|
376
|
-
}>, cacheKey: string, layer?: number): LayerHandle;
|
|
495
|
+
drawStaticImage(items: Array<ImageItem>, cacheKey: string, layer?: number): LayerHandle;
|
|
377
496
|
/**
|
|
378
497
|
* Clear a static rendering cache.
|
|
379
498
|
* @param cacheKey The cache key to clear, or undefined to clear all caches.
|
|
@@ -385,13 +504,7 @@ declare class CanvasTileEngine {
|
|
|
385
504
|
* @param style Line style overrides.
|
|
386
505
|
* @param layer Layer order.
|
|
387
506
|
*/
|
|
388
|
-
drawLine(items: Array<{
|
|
389
|
-
from: Coords;
|
|
390
|
-
to: Coords;
|
|
391
|
-
}> | {
|
|
392
|
-
from: Coords;
|
|
393
|
-
to: Coords;
|
|
394
|
-
}, style?: {
|
|
507
|
+
drawLine(items: Array<Line> | Line, style?: {
|
|
395
508
|
strokeStyle?: string;
|
|
396
509
|
lineWidth?: number;
|
|
397
510
|
}, layer?: number): LayerHandle;
|
|
@@ -400,32 +513,36 @@ declare class CanvasTileEngine {
|
|
|
400
513
|
* @param items Circle definitions.
|
|
401
514
|
* @param layer Layer order.
|
|
402
515
|
*/
|
|
403
|
-
drawCircle(items:
|
|
516
|
+
drawCircle(items: Circle | Array<Circle>, layer?: number): LayerHandle;
|
|
404
517
|
/**
|
|
405
518
|
* Draw one or many texts at world positions (canvas renderer only).
|
|
406
|
-
* @param items Text definitions.
|
|
407
|
-
* @param style Text style overrides.
|
|
519
|
+
* @param items Text definitions with position, text, size, and style.
|
|
408
520
|
* @param layer Layer order.
|
|
521
|
+
* @example
|
|
522
|
+
* ```ts
|
|
523
|
+
* engine.drawText({
|
|
524
|
+
* x: 0,
|
|
525
|
+
* y: 0,
|
|
526
|
+
* text: "Hello",
|
|
527
|
+
* size: 1, // 1 tile height
|
|
528
|
+
* style: { fillStyle: "black", fontFamily: "Arial" }
|
|
529
|
+
* });
|
|
530
|
+
*
|
|
531
|
+
* // Multiple texts
|
|
532
|
+
* engine.drawText([
|
|
533
|
+
* { x: 0, y: 0, text: "A", size: 2 },
|
|
534
|
+
* { x: 1, y: 0, text: "B", size: 2 }
|
|
535
|
+
* ]);
|
|
536
|
+
* ```
|
|
409
537
|
*/
|
|
410
|
-
drawText(items: Array<
|
|
411
|
-
coords: Coords;
|
|
412
|
-
text: string;
|
|
413
|
-
}> | {
|
|
414
|
-
coords: Coords;
|
|
415
|
-
text: string;
|
|
416
|
-
}, style?: {
|
|
417
|
-
fillStyle?: string;
|
|
418
|
-
font?: string;
|
|
419
|
-
textAlign?: CanvasTextAlign;
|
|
420
|
-
textBaseline?: CanvasTextBaseline;
|
|
421
|
-
}, layer?: number): LayerHandle;
|
|
538
|
+
drawText(items: Array<Text> | Text, layer?: number): LayerHandle;
|
|
422
539
|
/**
|
|
423
540
|
* Draw one or many polylines through world points (canvas renderer only).
|
|
424
541
|
* @param items Polyline point collections.
|
|
425
542
|
* @param style Stroke style overrides.
|
|
426
543
|
* @param layer Layer order.
|
|
427
544
|
*/
|
|
428
|
-
drawPath(items: Array<
|
|
545
|
+
drawPath(items: Array<Path> | Path, style?: {
|
|
429
546
|
strokeStyle?: string;
|
|
430
547
|
lineWidth?: number;
|
|
431
548
|
}, layer?: number): LayerHandle;
|
|
@@ -435,11 +552,7 @@ declare class CanvasTileEngine {
|
|
|
435
552
|
* @param items Image definitions.
|
|
436
553
|
* @param layer Layer order.
|
|
437
554
|
*/
|
|
438
|
-
drawImage(items: Array<
|
|
439
|
-
img: HTMLImageElement;
|
|
440
|
-
}> | (Omit<DrawObject, "style"> & {
|
|
441
|
-
img: HTMLImageElement;
|
|
442
|
-
}), layer?: number): LayerHandle;
|
|
555
|
+
drawImage(items: Array<ImageItem> | ImageItem, layer?: number): LayerHandle;
|
|
443
556
|
/**
|
|
444
557
|
* Draw grid lines at specified cell size (canvas renderer only).
|
|
445
558
|
* @param cellSize Size of each grid cell in world units.
|
package/dist/index.d.ts
CHANGED
|
@@ -147,23 +147,27 @@ type DrawObject = {
|
|
|
147
147
|
radius?: number | number[];
|
|
148
148
|
};
|
|
149
149
|
type Rect = DrawObject;
|
|
150
|
+
type Circle = Omit<DrawObject, "rotate" | "radius">;
|
|
151
|
+
type ImageItem = Omit<DrawObject, "style"> & {
|
|
152
|
+
img: HTMLImageElement;
|
|
153
|
+
};
|
|
154
|
+
type Text = Omit<DrawObject, "radius" | "size"> & {
|
|
155
|
+
text: string;
|
|
156
|
+
/** Font size in world units (scales with zoom). Default: 1 */
|
|
157
|
+
size?: number;
|
|
158
|
+
style?: {
|
|
159
|
+
fillStyle?: string;
|
|
160
|
+
/** Font family (default: "sans-serif") */
|
|
161
|
+
fontFamily?: string;
|
|
162
|
+
textAlign?: CanvasTextAlign;
|
|
163
|
+
textBaseline?: CanvasTextBaseline;
|
|
164
|
+
};
|
|
165
|
+
};
|
|
150
166
|
type Line = {
|
|
151
167
|
from: Coords;
|
|
152
168
|
to: Coords;
|
|
153
|
-
style: {
|
|
154
|
-
strokeStyle?: string;
|
|
155
|
-
lineWidth?: number;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
type Circle = Omit<DrawObject, "rotate" | "radius">;
|
|
159
|
-
type Text = {
|
|
160
|
-
coords: Coords;
|
|
161
|
-
text: string;
|
|
162
169
|
};
|
|
163
170
|
type Path = Coords[];
|
|
164
|
-
type ImageItem = Omit<DrawObject, "style"> & {
|
|
165
|
-
img: HTMLImageElement;
|
|
166
|
-
};
|
|
167
171
|
|
|
168
172
|
/**
|
|
169
173
|
* Core engine wiring camera, config, renderer, events, and draw helpers.
|
|
@@ -183,34 +187,145 @@ declare class CanvasTileEngine {
|
|
|
183
187
|
private responsiveWatcher?;
|
|
184
188
|
canvasWrapper: HTMLDivElement;
|
|
185
189
|
canvas: HTMLCanvasElement;
|
|
186
|
-
/**
|
|
190
|
+
/**
|
|
191
|
+
* Callback when center coordinates change (pan or zoom).
|
|
192
|
+
* @param coords - Center world coordinates: `{ x, y }`
|
|
193
|
+
* @example
|
|
194
|
+
* ```ts
|
|
195
|
+
* engine.onCoordsChange = (coords) => {
|
|
196
|
+
* console.log(`Center: ${coords.x}, ${coords.y}`);
|
|
197
|
+
* };
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
187
200
|
onCoordsChange?: (coords: Coords) => void;
|
|
188
201
|
private _onClick?;
|
|
202
|
+
/**
|
|
203
|
+
* Callback when a tile is clicked (mouse or touch tap).
|
|
204
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
205
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
206
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
207
|
+
* @example
|
|
208
|
+
* ```ts
|
|
209
|
+
* engine.onClick = (coords, mouse, client) => {
|
|
210
|
+
* console.log(`Clicked tile: ${coords.snapped.x}, ${coords.snapped.y}`);
|
|
211
|
+
* };
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
189
214
|
get onClick(): onClickCallback | undefined;
|
|
190
215
|
set onClick(cb: onClickCallback | undefined);
|
|
191
216
|
private _onRightClick?;
|
|
217
|
+
/**
|
|
218
|
+
* Callback when a tile is right-clicked.
|
|
219
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
220
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
221
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
222
|
+
* @example
|
|
223
|
+
* ```ts
|
|
224
|
+
* engine.onRightClick = (coords) => {
|
|
225
|
+
* showContextMenu(coords.snapped.x, coords.snapped.y);
|
|
226
|
+
* };
|
|
227
|
+
* ```
|
|
228
|
+
*/
|
|
192
229
|
get onRightClick(): onRightClickCallback | undefined;
|
|
193
230
|
set onRightClick(cb: onRightClickCallback | undefined);
|
|
194
231
|
private _onHover?;
|
|
232
|
+
/**
|
|
233
|
+
* Callback when hovering over tiles.
|
|
234
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
235
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
236
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
237
|
+
* @example
|
|
238
|
+
* ```ts
|
|
239
|
+
* engine.onHover = (coords) => {
|
|
240
|
+
* setHoveredTile({ x: coords.snapped.x, y: coords.snapped.y });
|
|
241
|
+
* };
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
195
244
|
get onHover(): onHoverCallback | undefined;
|
|
196
245
|
set onHover(cb: onHoverCallback | undefined);
|
|
197
246
|
private _onMouseDown?;
|
|
247
|
+
/**
|
|
248
|
+
* Callback on mouse/touch down.
|
|
249
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
250
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
251
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
252
|
+
* @example
|
|
253
|
+
* ```ts
|
|
254
|
+
* engine.onMouseDown = (coords) => {
|
|
255
|
+
* startPainting(coords.snapped.x, coords.snapped.y);
|
|
256
|
+
* };
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
198
259
|
get onMouseDown(): onMouseDownCallback | undefined;
|
|
199
260
|
set onMouseDown(cb: onMouseDownCallback | undefined);
|
|
200
261
|
private _onMouseUp?;
|
|
262
|
+
/**
|
|
263
|
+
* Callback on mouse/touch up.
|
|
264
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
265
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
266
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
267
|
+
* @example
|
|
268
|
+
* ```ts
|
|
269
|
+
* engine.onMouseUp = (coords) => {
|
|
270
|
+
* stopPainting();
|
|
271
|
+
* };
|
|
272
|
+
* ```
|
|
273
|
+
*/
|
|
201
274
|
get onMouseUp(): onMouseUpCallback | undefined;
|
|
202
275
|
set onMouseUp(cb: onMouseUpCallback | undefined);
|
|
203
276
|
private _onMouseLeave?;
|
|
277
|
+
/**
|
|
278
|
+
* Callback when mouse/touch leaves the canvas.
|
|
279
|
+
* @param coords - World coordinates: `raw` (exact), `snapped` (floored to tile)
|
|
280
|
+
* @param mouse - Canvas-relative position: `raw` (exact), `snapped` (tile-aligned)
|
|
281
|
+
* @param client - Viewport position: `raw` (exact), `snapped` (tile-aligned)
|
|
282
|
+
* @example
|
|
283
|
+
* ```ts
|
|
284
|
+
* engine.onMouseLeave = () => {
|
|
285
|
+
* clearHoveredTile();
|
|
286
|
+
* };
|
|
287
|
+
* ```
|
|
288
|
+
*/
|
|
204
289
|
get onMouseLeave(): onMouseLeaveCallback | undefined;
|
|
205
290
|
set onMouseLeave(cb: onMouseLeaveCallback | undefined);
|
|
206
291
|
private _onDraw?;
|
|
292
|
+
/**
|
|
293
|
+
* Callback after each draw frame. Use for custom canvas drawing.
|
|
294
|
+
* @param ctx - The canvas 2D rendering context
|
|
295
|
+
* @param info - Frame info: `scale`, `width`, `height`, `coords` (center)
|
|
296
|
+
* @example
|
|
297
|
+
* ```ts
|
|
298
|
+
* engine.onDraw = (ctx, info) => {
|
|
299
|
+
* ctx.fillStyle = "red";
|
|
300
|
+
* ctx.fillText(`Scale: ${info.scale}`, 10, 20);
|
|
301
|
+
* };
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
207
304
|
get onDraw(): onDrawCallback | undefined;
|
|
208
305
|
set onDraw(cb: onDrawCallback | undefined);
|
|
209
306
|
private _onResize?;
|
|
307
|
+
/**
|
|
308
|
+
* Callback on canvas resize.
|
|
309
|
+
* @example
|
|
310
|
+
* ```ts
|
|
311
|
+
* engine.onResize = () => {
|
|
312
|
+
* console.log("Canvas resized:", engine.getSize());
|
|
313
|
+
* };
|
|
314
|
+
* ```
|
|
315
|
+
*/
|
|
210
316
|
get onResize(): (() => void) | undefined;
|
|
211
317
|
set onResize(cb: (() => void) | undefined);
|
|
212
318
|
private _onZoom?;
|
|
213
|
-
/**
|
|
319
|
+
/**
|
|
320
|
+
* Callback when zoom level changes (wheel or pinch).
|
|
321
|
+
* @param scale - The new scale value
|
|
322
|
+
* @example
|
|
323
|
+
* ```ts
|
|
324
|
+
* engine.onZoom = (scale) => {
|
|
325
|
+
* console.log(`Zoom level: ${scale}`);
|
|
326
|
+
* };
|
|
327
|
+
* ```
|
|
328
|
+
*/
|
|
214
329
|
get onZoom(): ((scale: number) => void) | undefined;
|
|
215
330
|
set onZoom(cb: ((scale: number) => void) | undefined);
|
|
216
331
|
/**
|
|
@@ -247,6 +362,7 @@ declare class CanvasTileEngine {
|
|
|
247
362
|
/**
|
|
248
363
|
* Set the canvas scale directly, clamped to min/max bounds.
|
|
249
364
|
* @param newScale The desired scale value.
|
|
365
|
+
* @throws {ConfigValidationError} If scale is not a positive finite number.
|
|
250
366
|
*/
|
|
251
367
|
setScale(newScale: number): void;
|
|
252
368
|
/**
|
|
@@ -282,7 +398,11 @@ declare class CanvasTileEngine {
|
|
|
282
398
|
minY: number;
|
|
283
399
|
maxY: number;
|
|
284
400
|
};
|
|
285
|
-
/**
|
|
401
|
+
/**
|
|
402
|
+
* Set center coordinates from outside (adjusts the camera accordingly).
|
|
403
|
+
* @param newCenter The new center coordinates.
|
|
404
|
+
* @throws {ConfigValidationError} If coordinates are not finite numbers.
|
|
405
|
+
*/
|
|
286
406
|
updateCoords(newCenter: Coords): void;
|
|
287
407
|
/**
|
|
288
408
|
* Smoothly move the camera center to target coordinates over the given duration.
|
|
@@ -290,6 +410,7 @@ declare class CanvasTileEngine {
|
|
|
290
410
|
* @param y Target world y.
|
|
291
411
|
* @param durationMs Animation duration in milliseconds (default: 500ms). Set to 0 for instant move.
|
|
292
412
|
* @param onComplete Optional callback fired when animation completes.
|
|
413
|
+
* @throws {ConfigValidationError} If coordinates are not finite numbers.
|
|
293
414
|
*/
|
|
294
415
|
goCoords(x: number, y: number, durationMs?: number, onComplete?: () => void): void;
|
|
295
416
|
/**
|
|
@@ -342,7 +463,7 @@ declare class CanvasTileEngine {
|
|
|
342
463
|
* @param items Rectangle definitions.
|
|
343
464
|
* @param layer Layer order (lower draws first).
|
|
344
465
|
*/
|
|
345
|
-
drawRect(items:
|
|
466
|
+
drawRect(items: Rect | Array<Rect>, layer?: number): LayerHandle;
|
|
346
467
|
/**
|
|
347
468
|
* Draw rectangles with pre-rendering cache (canvas renderer only).
|
|
348
469
|
* Renders all items once to an offscreen canvas, then blits the visible portion each frame.
|
|
@@ -352,7 +473,7 @@ declare class CanvasTileEngine {
|
|
|
352
473
|
* @param cacheKey Unique key for this cache (e.g., "minimap-items").
|
|
353
474
|
* @param layer Layer order (lower draws first).
|
|
354
475
|
*/
|
|
355
|
-
drawStaticRect(items: Array<
|
|
476
|
+
drawStaticRect(items: Array<Rect>, cacheKey: string, layer?: number): LayerHandle;
|
|
356
477
|
/**
|
|
357
478
|
* Draw circles with pre-rendering cache (canvas renderer only).
|
|
358
479
|
* Renders all items once to an offscreen canvas, then blits the visible portion each frame.
|
|
@@ -361,7 +482,7 @@ declare class CanvasTileEngine {
|
|
|
361
482
|
* @param cacheKey Unique key for this cache (e.g., "minimap-circles").
|
|
362
483
|
* @param layer Layer order (lower draws first).
|
|
363
484
|
*/
|
|
364
|
-
drawStaticCircle(items: Array<
|
|
485
|
+
drawStaticCircle(items: Array<Circle>, cacheKey: string, layer?: number): LayerHandle;
|
|
365
486
|
/**
|
|
366
487
|
* Draw images with pre-rendering cache (canvas renderer only).
|
|
367
488
|
* Renders all items once to an offscreen canvas, then blits the visible portion each frame.
|
|
@@ -371,9 +492,7 @@ declare class CanvasTileEngine {
|
|
|
371
492
|
* @param cacheKey Unique key for this cache (e.g., "terrain-cache").
|
|
372
493
|
* @param layer Layer order (lower draws first).
|
|
373
494
|
*/
|
|
374
|
-
drawStaticImage(items: Array<
|
|
375
|
-
img: HTMLImageElement;
|
|
376
|
-
}>, cacheKey: string, layer?: number): LayerHandle;
|
|
495
|
+
drawStaticImage(items: Array<ImageItem>, cacheKey: string, layer?: number): LayerHandle;
|
|
377
496
|
/**
|
|
378
497
|
* Clear a static rendering cache.
|
|
379
498
|
* @param cacheKey The cache key to clear, or undefined to clear all caches.
|
|
@@ -385,13 +504,7 @@ declare class CanvasTileEngine {
|
|
|
385
504
|
* @param style Line style overrides.
|
|
386
505
|
* @param layer Layer order.
|
|
387
506
|
*/
|
|
388
|
-
drawLine(items: Array<{
|
|
389
|
-
from: Coords;
|
|
390
|
-
to: Coords;
|
|
391
|
-
}> | {
|
|
392
|
-
from: Coords;
|
|
393
|
-
to: Coords;
|
|
394
|
-
}, style?: {
|
|
507
|
+
drawLine(items: Array<Line> | Line, style?: {
|
|
395
508
|
strokeStyle?: string;
|
|
396
509
|
lineWidth?: number;
|
|
397
510
|
}, layer?: number): LayerHandle;
|
|
@@ -400,32 +513,36 @@ declare class CanvasTileEngine {
|
|
|
400
513
|
* @param items Circle definitions.
|
|
401
514
|
* @param layer Layer order.
|
|
402
515
|
*/
|
|
403
|
-
drawCircle(items:
|
|
516
|
+
drawCircle(items: Circle | Array<Circle>, layer?: number): LayerHandle;
|
|
404
517
|
/**
|
|
405
518
|
* Draw one or many texts at world positions (canvas renderer only).
|
|
406
|
-
* @param items Text definitions.
|
|
407
|
-
* @param style Text style overrides.
|
|
519
|
+
* @param items Text definitions with position, text, size, and style.
|
|
408
520
|
* @param layer Layer order.
|
|
521
|
+
* @example
|
|
522
|
+
* ```ts
|
|
523
|
+
* engine.drawText({
|
|
524
|
+
* x: 0,
|
|
525
|
+
* y: 0,
|
|
526
|
+
* text: "Hello",
|
|
527
|
+
* size: 1, // 1 tile height
|
|
528
|
+
* style: { fillStyle: "black", fontFamily: "Arial" }
|
|
529
|
+
* });
|
|
530
|
+
*
|
|
531
|
+
* // Multiple texts
|
|
532
|
+
* engine.drawText([
|
|
533
|
+
* { x: 0, y: 0, text: "A", size: 2 },
|
|
534
|
+
* { x: 1, y: 0, text: "B", size: 2 }
|
|
535
|
+
* ]);
|
|
536
|
+
* ```
|
|
409
537
|
*/
|
|
410
|
-
drawText(items: Array<
|
|
411
|
-
coords: Coords;
|
|
412
|
-
text: string;
|
|
413
|
-
}> | {
|
|
414
|
-
coords: Coords;
|
|
415
|
-
text: string;
|
|
416
|
-
}, style?: {
|
|
417
|
-
fillStyle?: string;
|
|
418
|
-
font?: string;
|
|
419
|
-
textAlign?: CanvasTextAlign;
|
|
420
|
-
textBaseline?: CanvasTextBaseline;
|
|
421
|
-
}, layer?: number): LayerHandle;
|
|
538
|
+
drawText(items: Array<Text> | Text, layer?: number): LayerHandle;
|
|
422
539
|
/**
|
|
423
540
|
* Draw one or many polylines through world points (canvas renderer only).
|
|
424
541
|
* @param items Polyline point collections.
|
|
425
542
|
* @param style Stroke style overrides.
|
|
426
543
|
* @param layer Layer order.
|
|
427
544
|
*/
|
|
428
|
-
drawPath(items: Array<
|
|
545
|
+
drawPath(items: Array<Path> | Path, style?: {
|
|
429
546
|
strokeStyle?: string;
|
|
430
547
|
lineWidth?: number;
|
|
431
548
|
}, layer?: number): LayerHandle;
|
|
@@ -435,11 +552,7 @@ declare class CanvasTileEngine {
|
|
|
435
552
|
* @param items Image definitions.
|
|
436
553
|
* @param layer Layer order.
|
|
437
554
|
*/
|
|
438
|
-
drawImage(items: Array<
|
|
439
|
-
img: HTMLImageElement;
|
|
440
|
-
}> | (Omit<DrawObject, "style"> & {
|
|
441
|
-
img: HTMLImageElement;
|
|
442
|
-
}), layer?: number): LayerHandle;
|
|
555
|
+
drawImage(items: Array<ImageItem> | ImageItem, layer?: number): LayerHandle;
|
|
443
556
|
/**
|
|
444
557
|
* Draw grid lines at specified cell size (canvas renderer only).
|
|
445
558
|
* @param cellSize Size of each grid cell in world units.
|