@ue-too/board 0.9.5 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -2
- package/boardify/index.d.ts +280 -9
- package/camera/base.d.ts +364 -68
- package/camera/camera-edge-auto-input.d.ts +105 -0
- package/camera/camera-mux/animation-and-lock/animation-and-lock.d.ts +316 -14
- package/camera/camera-mux/animation-and-lock/index.d.ts +27 -0
- package/camera/camera-mux/animation-and-lock/pan-control-state-machine.d.ts +143 -60
- package/camera/camera-mux/animation-and-lock/rotation-control-state-machine.d.ts +143 -55
- package/camera/camera-mux/animation-and-lock/zoom-control-state-machine.d.ts +205 -58
- package/camera/camera-mux/index.d.ts +26 -0
- package/camera/camera-mux/interface.d.ts +161 -5
- package/camera/camera-mux/relay.d.ts +79 -16
- package/camera/camera-rig/camera-rig.d.ts +536 -94
- package/camera/camera-rig/index.d.ts +26 -1
- package/camera/camera-rig/pan-handler.d.ts +508 -48
- package/camera/camera-rig/rotation-handler.d.ts +353 -31
- package/camera/camera-rig/zoom-handler.d.ts +369 -32
- package/camera/default-camera.d.ts +173 -26
- package/camera/index.d.ts +20 -0
- package/camera/interface.d.ts +202 -2
- package/camera/update-publisher.d.ts +128 -38
- package/camera/utils/coordinate-conversion.d.ts +323 -26
- package/camera/utils/index.d.ts +22 -0
- package/camera/utils/matrix.d.ts +217 -14
- package/camera/utils/position.d.ts +249 -11
- package/camera/utils/rotation.d.ts +139 -9
- package/camera/utils/zoom.d.ts +72 -4
- package/index.d.ts +37 -0
- package/index.js +2 -4796
- package/index.js.map +39 -38
- package/input-interpretation/index.d.ts +29 -0
- package/input-interpretation/input-orchestrator.d.ts +197 -0
- package/input-interpretation/input-state-machine/index.d.ts +18 -0
- package/input-interpretation/input-state-machine/kmt-input-context.d.ts +191 -38
- package/input-interpretation/input-state-machine/kmt-input-state-machine.d.ts +201 -85
- package/input-interpretation/input-state-machine/touch-input-context.d.ts +76 -10
- package/input-interpretation/input-state-machine/touch-input-state-machine.d.ts +138 -17
- package/input-interpretation/raw-input-parser/index.d.ts +19 -0
- package/input-interpretation/raw-input-parser/vanilla-kmt-event-parser.d.ts +107 -21
- package/input-interpretation/raw-input-parser/vanilla-touch-event-parser.d.ts +71 -8
- package/input-interpretation/raw-input-publisher/index.d.ts +18 -0
- package/input-interpretation/raw-input-publisher/raw-input-publisher.d.ts +133 -37
- package/package.json +3 -3
- package/utils/canvas-position-dimension.d.ts +282 -1
- package/utils/coordinate-conversions/canvas-viewport.d.ts +79 -0
- package/utils/coordinate-conversions/viewport-world.d.ts +101 -0
- package/utils/coordinate-conversions/window-canvas.d.ts +90 -0
- package/utils/coorindate-conversion.d.ts +91 -0
- package/utils/drawing.d.ts +151 -3
- package/utils/index.d.ts +21 -0
- package/utils/observable.d.ts +179 -0
- package/utils/ruler.d.ts +36 -0
- package/utils/zoomlevel-adjustment.d.ts +144 -8
- package/camera/camera-rig/update-batcher/index.d.ts +0 -3
- package/camera/camera-rig/update-batcher/position-update-batcher.d.ts +0 -58
- package/camera/camera-rig/update-batcher/rotation-update-batcher.d.ts +0 -54
- package/camera/camera-rig/update-batcher/zoom-udpate-batcher.d.ts +0 -60
|
@@ -7,29 +7,88 @@ import { RotationLimits } from './utils/rotation';
|
|
|
7
7
|
import { CameraEventMap, CameraState } from './update-publisher';
|
|
8
8
|
import { ObservableBoardCamera } from './interface';
|
|
9
9
|
import { SubscriptionOptions } from '../utils/observable';
|
|
10
|
+
/** Default viewport width in CSS pixels */
|
|
10
11
|
export declare const DEFAULT_BOARD_CAMERA_VIEWPORT_WIDTH = 1000;
|
|
12
|
+
/** Default viewport height in CSS pixels */
|
|
11
13
|
export declare const DEFAULT_BOARD_CAMERA_VIEWPORT_HEIGHT = 1000;
|
|
14
|
+
/** Default zoom level constraints (0.1x to 10x) */
|
|
12
15
|
export declare const DEFAULT_BOARD_CAMERA_ZOOM_BOUNDARIES: ZoomLevelLimits;
|
|
16
|
+
/** Default position boundaries (±10000 on both axes) */
|
|
13
17
|
export declare const DEFAULT_BOARD_CAMERA_BOUNDARIES: Boundaries;
|
|
18
|
+
/** Default rotation boundaries (unrestricted) */
|
|
14
19
|
export declare const DEFAULT_BOARD_CAMERA_ROTATION_BOUNDARIES: RotationLimits | undefined;
|
|
15
20
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
21
|
+
* Observable camera implementation that extends {@link BaseCamera} with event notification.
|
|
22
|
+
* This is the recommended camera class for most applications.
|
|
23
|
+
*
|
|
24
|
+
* @remarks
|
|
25
|
+
* DefaultBoardCamera wraps {@link BaseCamera} and adds an event system via {@link CameraUpdatePublisher}.
|
|
26
|
+
* All camera state changes (pan, zoom, rotate) trigger corresponding events that observers can subscribe to.
|
|
27
|
+
*
|
|
28
|
+
* Use this class when you need to:
|
|
29
|
+
* - React to camera changes in your UI or game logic
|
|
30
|
+
* - Synchronize multiple systems with camera state
|
|
31
|
+
* - Implement camera-dependent features (minimap, LOD, culling)
|
|
32
|
+
*
|
|
33
|
+
* For a non-observable camera without event overhead, use {@link BaseCamera} directly.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* const camera = new DefaultBoardCamera(1920, 1080);
|
|
38
|
+
*
|
|
39
|
+
* // Subscribe to camera events
|
|
40
|
+
* camera.on('zoom', (event, state) => {
|
|
41
|
+
* console.log(`Zoomed by ${event.deltaZoomAmount}`);
|
|
42
|
+
* console.log(`New zoom level: ${state.zoomLevel}`);
|
|
43
|
+
* });
|
|
44
|
+
*
|
|
45
|
+
* camera.on('pan', (event, state) => {
|
|
46
|
+
* console.log(`Panned by (${event.diff.x}, ${event.diff.y})`);
|
|
47
|
+
* });
|
|
48
|
+
*
|
|
49
|
+
* // Camera updates trigger events
|
|
50
|
+
* camera.setZoomLevel(2.0);
|
|
51
|
+
* camera.setPosition({ x: 100, y: 200 });
|
|
52
|
+
* ```
|
|
18
53
|
*
|
|
19
54
|
* @category Camera
|
|
55
|
+
* @see {@link BaseCamera} for non-observable camera
|
|
56
|
+
* @see {@link ObservableBoardCamera} for the interface definition
|
|
20
57
|
*/
|
|
21
58
|
export default class DefaultBoardCamera implements ObservableBoardCamera {
|
|
22
59
|
private _baseCamera;
|
|
23
60
|
private _observer;
|
|
24
61
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* @param
|
|
28
|
-
* @param
|
|
29
|
-
* @param
|
|
30
|
-
* @param
|
|
31
|
-
* @param
|
|
32
|
-
* @param
|
|
62
|
+
* Creates a new observable camera with event notification capabilities.
|
|
63
|
+
*
|
|
64
|
+
* @param viewPortWidth - Width of the viewport in CSS pixels (default: 1000)
|
|
65
|
+
* @param viewPortHeight - Height of the viewport in CSS pixels (default: 1000)
|
|
66
|
+
* @param position - Initial camera position in world coordinates (default: {x: 0, y: 0})
|
|
67
|
+
* @param rotation - Initial rotation in radians (default: 0)
|
|
68
|
+
* @param zoomLevel - Initial zoom level (default: 1.0)
|
|
69
|
+
* @param boundaries - Position constraints (default: ±10000 on both axes)
|
|
70
|
+
* @param zoomLevelBoundaries - Zoom constraints (default: 0.1 to 10)
|
|
71
|
+
* @param rotationBoundaries - Optional rotation constraints (default: unrestricted)
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Camera with default settings
|
|
76
|
+
* const camera1 = new DefaultBoardCamera();
|
|
77
|
+
*
|
|
78
|
+
* // Camera with custom viewport
|
|
79
|
+
* const camera2 = new DefaultBoardCamera(1920, 1080);
|
|
80
|
+
*
|
|
81
|
+
* // Camera with all options
|
|
82
|
+
* const camera3 = new DefaultBoardCamera(
|
|
83
|
+
* 1920, 1080,
|
|
84
|
+
* { x: 0, y: 0 },
|
|
85
|
+
* 0,
|
|
86
|
+
* 1.0,
|
|
87
|
+
* { min: { x: -5000, y: -5000 }, max: { x: 5000, y: 5000 } },
|
|
88
|
+
* { min: 0.5, max: 4 },
|
|
89
|
+
* { start: 0, end: Math.PI * 2 }
|
|
90
|
+
* );
|
|
91
|
+
* ```
|
|
33
92
|
*/
|
|
34
93
|
constructor(viewPortWidth?: number, viewPortHeight?: number, position?: Point, rotation?: number, zoomLevel?: number, boundaries?: Boundaries, zoomLevelBoundaries?: ZoomLevelLimits, rotationBoundaries?: RotationLimits | undefined);
|
|
35
94
|
/**
|
|
@@ -60,13 +119,23 @@ export default class DefaultBoardCamera implements ObservableBoardCamera {
|
|
|
60
119
|
*/
|
|
61
120
|
get position(): Point;
|
|
62
121
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @
|
|
122
|
+
* Sets the camera position and notifies observers if successful.
|
|
123
|
+
*
|
|
124
|
+
* @param destination - Target position in world coordinates
|
|
125
|
+
* @returns True if position was updated, false if rejected by boundaries or negligible change
|
|
126
|
+
*
|
|
127
|
+
* @remarks
|
|
128
|
+
* If the position changes, a 'pan' event is triggered with the position delta and new camera state.
|
|
129
|
+
* All 'pan' and 'all' event subscribers will be notified.
|
|
66
130
|
*
|
|
67
|
-
* @
|
|
68
|
-
*
|
|
69
|
-
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* camera.on('pan', (event, state) => {
|
|
134
|
+
* console.log(`Camera moved by (${event.diff.x}, ${event.diff.y})`);
|
|
135
|
+
* });
|
|
136
|
+
*
|
|
137
|
+
* camera.setPosition({ x: 100, y: 200 }); // Triggers pan event
|
|
138
|
+
* ```
|
|
70
139
|
*/
|
|
71
140
|
setPosition(destination: Point): boolean;
|
|
72
141
|
/**
|
|
@@ -84,11 +153,31 @@ export default class DefaultBoardCamera implements ObservableBoardCamera {
|
|
|
84
153
|
set zoomBoundaries(zoomBoundaries: ZoomLevelLimits | undefined);
|
|
85
154
|
setMaxZoomLevel(maxZoomLevel: number): boolean;
|
|
86
155
|
setMinZoomLevel(minZoomLevel: number): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Sets the camera zoom level and notifies observers if successful.
|
|
158
|
+
*
|
|
159
|
+
* @param zoomLevel - Target zoom level (1.0 = 100%, 2.0 = 200%, etc.)
|
|
160
|
+
* @returns True if zoom was updated, false if outside boundaries or already at limit
|
|
161
|
+
*
|
|
162
|
+
* @remarks
|
|
163
|
+
* If the zoom changes, a 'zoom' event is triggered with the zoom delta and new camera state.
|
|
164
|
+
* All 'zoom' and 'all' event subscribers will be notified.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* camera.on('zoom', (event, state) => {
|
|
169
|
+
* console.log(`Zoom changed by ${event.deltaZoomAmount}`);
|
|
170
|
+
* console.log(`New zoom: ${state.zoomLevel}`);
|
|
171
|
+
* });
|
|
172
|
+
*
|
|
173
|
+
* camera.setZoomLevel(2.0); // Triggers zoom event
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
87
176
|
setZoomLevel(zoomLevel: number): boolean;
|
|
88
177
|
/**
|
|
89
|
-
*
|
|
178
|
+
* Gets the current camera rotation in radians.
|
|
90
179
|
*
|
|
91
|
-
* @
|
|
180
|
+
* @returns Current rotation angle (0 to 2π)
|
|
92
181
|
*/
|
|
93
182
|
get rotation(): number;
|
|
94
183
|
/**
|
|
@@ -112,9 +201,24 @@ export default class DefaultBoardCamera implements ObservableBoardCamera {
|
|
|
112
201
|
*/
|
|
113
202
|
getTransform(devicePixelRatio: number, alignCoorindate?: boolean): TransformationMatrix;
|
|
114
203
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
* @
|
|
204
|
+
* Sets the camera rotation and notifies observers if successful.
|
|
205
|
+
*
|
|
206
|
+
* @param rotation - Target rotation in radians
|
|
207
|
+
* @returns True if rotation was updated, false if outside boundaries or already at limit
|
|
208
|
+
*
|
|
209
|
+
* @remarks
|
|
210
|
+
* If the rotation changes, a 'rotate' event is triggered with the rotation delta and new camera state.
|
|
211
|
+
* All 'rotate' and 'all' event subscribers will be notified.
|
|
212
|
+
* Rotation is automatically normalized to 0-2π range.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
* ```typescript
|
|
216
|
+
* camera.on('rotate', (event, state) => {
|
|
217
|
+
* console.log(`Camera rotated by ${event.deltaRotation} radians`);
|
|
218
|
+
* });
|
|
219
|
+
*
|
|
220
|
+
* camera.setRotation(Math.PI / 4); // Triggers rotate event
|
|
221
|
+
* ```
|
|
118
222
|
*/
|
|
119
223
|
setRotation(rotation: number): boolean;
|
|
120
224
|
/**
|
|
@@ -149,11 +253,54 @@ export default class DefaultBoardCamera implements ObservableBoardCamera {
|
|
|
149
253
|
setHorizontalBoundaries(min: number, max: number): void;
|
|
150
254
|
setVerticalBoundaries(min: number, max: number): void;
|
|
151
255
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* @
|
|
155
|
-
* @param
|
|
156
|
-
* @
|
|
256
|
+
* Subscribes to camera events with optional AbortController for cancellation.
|
|
257
|
+
*
|
|
258
|
+
* @typeParam K - The event type key from CameraEventMap
|
|
259
|
+
* @param eventName - Event type to listen for: 'pan', 'zoom', 'rotate', or 'all'
|
|
260
|
+
* @param callback - Function called when event occurs, receives event data and camera state
|
|
261
|
+
* @param options - Optional subscription configuration including AbortController signal
|
|
262
|
+
* @returns Function to unsubscribe from this event
|
|
263
|
+
*
|
|
264
|
+
* @remarks
|
|
265
|
+
* Available events:
|
|
266
|
+
* - 'pan': Triggered when camera position changes
|
|
267
|
+
* - 'zoom': Triggered when zoom level changes
|
|
268
|
+
* - 'rotate': Triggered when rotation changes
|
|
269
|
+
* - 'all': Triggered for any camera change (pan, zoom, or rotate)
|
|
270
|
+
*
|
|
271
|
+
* Use the AbortController pattern to manage multiple subscriptions:
|
|
272
|
+
*
|
|
273
|
+
* @example
|
|
274
|
+
* ```typescript
|
|
275
|
+
* // Basic subscription
|
|
276
|
+
* const unsubscribe = camera.on('pan', (event, state) => {
|
|
277
|
+
* console.log(`Panned by (${event.diff.x}, ${event.diff.y})`);
|
|
278
|
+
* console.log(`New position: (${state.position.x}, ${state.position.y})`);
|
|
279
|
+
* });
|
|
280
|
+
*
|
|
281
|
+
* // Later: unsubscribe
|
|
282
|
+
* unsubscribe();
|
|
283
|
+
*
|
|
284
|
+
* // Subscribe to all events
|
|
285
|
+
* camera.on('all', (event, state) => {
|
|
286
|
+
* if (event.type === 'pan') {
|
|
287
|
+
* console.log('Pan event:', event.diff);
|
|
288
|
+
* } else if (event.type === 'zoom') {
|
|
289
|
+
* console.log('Zoom event:', event.deltaZoomAmount);
|
|
290
|
+
* } else if (event.type === 'rotate') {
|
|
291
|
+
* console.log('Rotate event:', event.deltaRotation);
|
|
292
|
+
* }
|
|
293
|
+
* });
|
|
294
|
+
*
|
|
295
|
+
* // Using AbortController for batch unsubscribe
|
|
296
|
+
* const controller = new AbortController();
|
|
297
|
+
* camera.on('pan', handlePan, { signal: controller.signal });
|
|
298
|
+
* camera.on('zoom', handleZoom, { signal: controller.signal });
|
|
299
|
+
* camera.on('rotate', handleRotate, { signal: controller.signal });
|
|
300
|
+
*
|
|
301
|
+
* // Unsubscribe all at once
|
|
302
|
+
* controller.abort();
|
|
303
|
+
* ```
|
|
157
304
|
*/
|
|
158
305
|
on<K extends keyof CameraEventMap>(eventName: K, callback: (event: CameraEventMap[K], cameraState: CameraState) => void, options?: SubscriptionOptions): UnSubscribe;
|
|
159
306
|
getTRS(devicePixelRatio: number, alignCoordinateSystem: boolean): {
|
package/camera/index.d.ts
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Camera system module exports.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This module provides the complete camera system for viewport management in the board package.
|
|
6
|
+
* It includes camera implementations, constraint systems (rigs), input multiplexing, and utilities.
|
|
7
|
+
*
|
|
8
|
+
* ## Key Components
|
|
9
|
+
*
|
|
10
|
+
* - **Camera Classes**: {@link DefaultBoardCamera} for viewport transformations (pan/zoom/rotate)
|
|
11
|
+
* - **Camera Rigs**: {@link CameraRig} for enforcing boundaries and movement constraints
|
|
12
|
+
* - **Camera Multiplexers**: {@link CameraMux} for coordinating user input, animations, and programmatic control
|
|
13
|
+
* - **Utilities**: Helper functions for coordinate conversion, position calculations, and more
|
|
14
|
+
*
|
|
15
|
+
* @see {@link DefaultBoardCamera} for the main camera implementation
|
|
16
|
+
* @see {@link CameraRig} for camera constraint configuration
|
|
17
|
+
* @see {@link CameraMux} for input coordination and animation support
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
1
21
|
export * from "./base";
|
|
2
22
|
export * from './utils';
|
|
3
23
|
export * from './default-camera';
|
package/camera/interface.d.ts
CHANGED
|
@@ -6,31 +6,114 @@ import { Boundaries } from "./utils/position";
|
|
|
6
6
|
import { CameraEventMap, CameraState } from "./update-publisher";
|
|
7
7
|
import { SubscriptionOptions } from "../utils/observable";
|
|
8
8
|
/**
|
|
9
|
-
*
|
|
9
|
+
* Observable camera interface that extends {@link BoardCamera} with event subscription capabilities.
|
|
10
|
+
* Allows observers to subscribe to camera state changes such as pan, zoom, and rotation events.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const camera: ObservableBoardCamera = new DefaultBoardCamera();
|
|
15
|
+
*
|
|
16
|
+
* // Subscribe to pan events
|
|
17
|
+
* const unsubscribe = camera.on('pan', (event, state) => {
|
|
18
|
+
* console.log('Camera panned by:', event.diff);
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Later, unsubscribe
|
|
22
|
+
* unsubscribe();
|
|
23
|
+
* ```
|
|
10
24
|
*
|
|
11
25
|
* @category Camera
|
|
12
26
|
*/
|
|
13
27
|
export interface ObservableBoardCamera extends BoardCamera {
|
|
28
|
+
/**
|
|
29
|
+
* Subscribes to camera events with an optional AbortController for cancellation.
|
|
30
|
+
*
|
|
31
|
+
* @typeParam K - The event type key from CameraEventMap
|
|
32
|
+
* @param eventName - The type of camera event to listen for ('pan', 'zoom', 'rotate', or 'all')
|
|
33
|
+
* @param callback - Function called when the event occurs, receives event data and current camera state
|
|
34
|
+
* @param options - Optional subscription configuration including AbortController signal
|
|
35
|
+
* @returns Function to unsubscribe from the event
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // Basic subscription
|
|
40
|
+
* camera.on('zoom', (event, state) => {
|
|
41
|
+
* console.log(`Zoom changed by ${event.deltaZoomAmount}`);
|
|
42
|
+
* });
|
|
43
|
+
*
|
|
44
|
+
* // With AbortController for batch unsubscribing
|
|
45
|
+
* const controller = new AbortController();
|
|
46
|
+
* camera.on('pan', handlePan, { signal: controller.signal });
|
|
47
|
+
* camera.on('zoom', handleZoom, { signal: controller.signal });
|
|
48
|
+
*
|
|
49
|
+
* // Unsubscribe all at once
|
|
50
|
+
* controller.abort();
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
14
53
|
on<K extends keyof CameraEventMap>(eventName: K, callback: (event: CameraEventMap[K], cameraState: CameraState) => void, options?: SubscriptionOptions): UnSubscribe;
|
|
15
54
|
}
|
|
16
55
|
/**
|
|
17
|
-
*
|
|
56
|
+
* Core camera interface for the infinite canvas board system.
|
|
57
|
+
* Manages camera position, rotation, zoom, and coordinate transformations between viewport and world space.
|
|
58
|
+
*
|
|
59
|
+
* The camera uses a center-anchored coordinate system where the camera position represents
|
|
60
|
+
* the center of the viewport in world coordinates.
|
|
61
|
+
*
|
|
62
|
+
* @remarks
|
|
63
|
+
* Transformation order: Scale (devicePixelRatio) → Translation (viewport center) → Rotation → Zoom → Translation (camera position)
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* const camera: BoardCamera = new BaseCamera(1920, 1080);
|
|
68
|
+
* camera.setPosition({ x: 100, y: 100 });
|
|
69
|
+
* camera.setZoomLevel(2.0);
|
|
70
|
+
* camera.setRotation(Math.PI / 4); // 45 degrees
|
|
71
|
+
*
|
|
72
|
+
* // Convert mouse position to world coordinates
|
|
73
|
+
* const worldPos = camera.convertFromViewPort2WorldSpace(mousePos);
|
|
74
|
+
* ```
|
|
18
75
|
*
|
|
19
76
|
* @category Camera
|
|
20
77
|
*/
|
|
21
78
|
export interface BoardCamera {
|
|
79
|
+
/** Current camera position in world coordinates (center of viewport) */
|
|
22
80
|
position: Point;
|
|
81
|
+
/** Current rotation in radians (0 to 2π), normalized */
|
|
23
82
|
rotation: number;
|
|
83
|
+
/** Current zoom level (1.0 = 100%, 2.0 = 200%, etc.) */
|
|
24
84
|
zoomLevel: number;
|
|
85
|
+
/** Width of the viewport in CSS pixels */
|
|
25
86
|
viewPortWidth: number;
|
|
87
|
+
/** Height of the viewport in CSS pixels */
|
|
26
88
|
viewPortHeight: number;
|
|
89
|
+
/** Optional position boundaries for the camera in world coordinates */
|
|
27
90
|
boundaries?: Boundaries;
|
|
91
|
+
/** Optional zoom level constraints (min and max zoom) */
|
|
28
92
|
zoomBoundaries?: ZoomLevelLimits;
|
|
93
|
+
/** Optional rotation constraints (start and end angles) */
|
|
29
94
|
rotationBoundaries?: RotationLimits;
|
|
95
|
+
/**
|
|
96
|
+
* Calculates the axis-aligned bounding box (AABB) of the viewport in world space.
|
|
97
|
+
*
|
|
98
|
+
* @param alignCoordinate - If true, uses standard coordinate system (y-up). If false, uses inverted y-axis
|
|
99
|
+
* @returns Object with min and max points defining the bounding box
|
|
100
|
+
*
|
|
101
|
+
* @remarks
|
|
102
|
+
* Useful for culling and determining which objects are visible in the current viewport.
|
|
103
|
+
*/
|
|
30
104
|
viewPortAABB(alignCoordinate?: boolean): {
|
|
31
105
|
min: Point;
|
|
32
106
|
max: Point;
|
|
33
107
|
};
|
|
108
|
+
/**
|
|
109
|
+
* Calculates the four corners of the viewport in world space, accounting for rotation.
|
|
110
|
+
*
|
|
111
|
+
* @param alignCoordinate - If true, uses standard coordinate system (y-up). If false, uses inverted y-axis
|
|
112
|
+
* @returns Object containing the four corner points (top-left, top-right, bottom-left, bottom-right)
|
|
113
|
+
*
|
|
114
|
+
* @remarks
|
|
115
|
+
* Returns the actual rotated viewport corners, not an AABB. Use this for precise viewport bounds.
|
|
116
|
+
*/
|
|
34
117
|
viewPortInWorldSpace(alignCoordinate?: boolean): {
|
|
35
118
|
top: {
|
|
36
119
|
left: Point;
|
|
@@ -41,16 +124,114 @@ export interface BoardCamera {
|
|
|
41
124
|
right: Point;
|
|
42
125
|
};
|
|
43
126
|
};
|
|
127
|
+
/**
|
|
128
|
+
* Sets the camera position in world coordinates.
|
|
129
|
+
*
|
|
130
|
+
* @param destination - Target position for the camera center
|
|
131
|
+
* @returns True if position was updated, false if rejected by boundaries or no significant change
|
|
132
|
+
*
|
|
133
|
+
* @remarks
|
|
134
|
+
* Position changes smaller than 10E-10 or 1/zoomLevel are ignored to prevent floating-point jitter.
|
|
135
|
+
* Position is clamped to boundaries if set.
|
|
136
|
+
*/
|
|
44
137
|
setPosition(destination: Point): boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Sets the camera zoom level.
|
|
140
|
+
*
|
|
141
|
+
* @param zoomLevel - Target zoom level (1.0 = 100%)
|
|
142
|
+
* @returns True if zoom was updated, false if outside boundaries or already at limit
|
|
143
|
+
*
|
|
144
|
+
* @remarks
|
|
145
|
+
* Zoom is clamped to zoomBoundaries if set. Values are clamped, not rejected.
|
|
146
|
+
*/
|
|
45
147
|
setZoomLevel(zoomLevel: number): boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Sets the camera rotation in radians.
|
|
150
|
+
*
|
|
151
|
+
* @param rotation - Target rotation angle in radians
|
|
152
|
+
* @returns True if rotation was updated, false if outside boundaries or already at limit
|
|
153
|
+
*
|
|
154
|
+
* @remarks
|
|
155
|
+
* Rotation is automatically normalized to 0-2π range. Clamped to rotationBoundaries if set.
|
|
156
|
+
*/
|
|
46
157
|
setRotation(rotation: number): boolean;
|
|
158
|
+
/**
|
|
159
|
+
* Updates the minimum allowed zoom level.
|
|
160
|
+
*
|
|
161
|
+
* @param minZoomLevel - Minimum zoom level constraint
|
|
162
|
+
*
|
|
163
|
+
* @remarks
|
|
164
|
+
* If current zoom is below the new minimum, camera will zoom in to match the minimum.
|
|
165
|
+
*/
|
|
47
166
|
setMinZoomLevel(minZoomLevel: number): void;
|
|
167
|
+
/**
|
|
168
|
+
* Updates the maximum allowed zoom level.
|
|
169
|
+
*
|
|
170
|
+
* @param maxZoomLevel - Maximum zoom level constraint
|
|
171
|
+
*/
|
|
48
172
|
setMaxZoomLevel(maxZoomLevel: number): void;
|
|
173
|
+
/**
|
|
174
|
+
* Sets horizontal (x-axis) movement boundaries for the camera.
|
|
175
|
+
*
|
|
176
|
+
* @param min - Minimum x coordinate in world space
|
|
177
|
+
* @param max - Maximum x coordinate in world space
|
|
178
|
+
*
|
|
179
|
+
* @remarks
|
|
180
|
+
* If min > max, values are automatically swapped.
|
|
181
|
+
*/
|
|
49
182
|
setHorizontalBoundaries(min: number, max: number): void;
|
|
183
|
+
/**
|
|
184
|
+
* Sets vertical (y-axis) movement boundaries for the camera.
|
|
185
|
+
*
|
|
186
|
+
* @param min - Minimum y coordinate in world space
|
|
187
|
+
* @param max - Maximum y coordinate in world space
|
|
188
|
+
*
|
|
189
|
+
* @remarks
|
|
190
|
+
* If min > max, values are automatically swapped.
|
|
191
|
+
*/
|
|
50
192
|
setVerticalBoundaries(min: number, max: number): void;
|
|
193
|
+
/**
|
|
194
|
+
* Gets the camera origin position in window coordinates.
|
|
195
|
+
*
|
|
196
|
+
* @deprecated This method is deprecated and will be removed in a future version
|
|
197
|
+
* @param centerInWindow - Center point in window coordinates
|
|
198
|
+
* @returns The camera origin point (currently just returns the input)
|
|
199
|
+
*/
|
|
51
200
|
getCameraOriginInWindow(centerInWindow: Point): Point;
|
|
201
|
+
/**
|
|
202
|
+
* Converts a point from viewport coordinates to world coordinates.
|
|
203
|
+
*
|
|
204
|
+
* @param point - Point in viewport space (pixels from viewport center)
|
|
205
|
+
* @returns Corresponding point in world coordinates
|
|
206
|
+
*
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* // Convert mouse position (relative to viewport center) to world position
|
|
210
|
+
* const mouseViewport = { x: mouseX - canvas.width/2, y: mouseY - canvas.height/2 };
|
|
211
|
+
* const worldPos = camera.convertFromViewPort2WorldSpace(mouseViewport);
|
|
212
|
+
* ```
|
|
213
|
+
*/
|
|
52
214
|
convertFromViewPort2WorldSpace(point: Point): Point;
|
|
215
|
+
/**
|
|
216
|
+
* Converts a point from world coordinates to viewport coordinates.
|
|
217
|
+
*
|
|
218
|
+
* @param point - Point in world coordinates
|
|
219
|
+
* @returns Corresponding point in viewport space (pixels from viewport center)
|
|
220
|
+
*
|
|
221
|
+
* @example
|
|
222
|
+
* ```typescript
|
|
223
|
+
* // Find viewport position of a world object
|
|
224
|
+
* const viewportPos = camera.convertFromWorld2ViewPort(objectWorldPos);
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
53
227
|
convertFromWorld2ViewPort(point: Point): Point;
|
|
228
|
+
/**
|
|
229
|
+
* Decomposes the camera transformation into Translation, Rotation, and Scale components.
|
|
230
|
+
*
|
|
231
|
+
* @param devicePixelRatio - Device pixel ratio for high-DPI displays
|
|
232
|
+
* @param alignCoordinateSystem - If true, uses standard coordinate system (y-up). If false, uses inverted y-axis
|
|
233
|
+
* @returns Object containing separate scale, rotation, and translation values
|
|
234
|
+
*/
|
|
54
235
|
getTRS(devicePixelRatio: number, alignCoordinateSystem: boolean): {
|
|
55
236
|
scale: {
|
|
56
237
|
x: number;
|
|
@@ -62,6 +243,25 @@ export interface BoardCamera {
|
|
|
62
243
|
y: number;
|
|
63
244
|
};
|
|
64
245
|
};
|
|
246
|
+
/**
|
|
247
|
+
* Calculates the complete transformation matrix for rendering.
|
|
248
|
+
* This matrix transforms from world space to canvas pixel space.
|
|
249
|
+
*
|
|
250
|
+
* @param devicePixelRatio - Device pixel ratio for high-DPI displays (typically window.devicePixelRatio)
|
|
251
|
+
* @param alignCoordinateSystem - If true, uses standard coordinate system (y-up). If false, uses inverted y-axis
|
|
252
|
+
* @returns 2D transformation matrix in standard form {a, b, c, d, e, f}
|
|
253
|
+
*
|
|
254
|
+
* @remarks
|
|
255
|
+
* Apply this matrix to canvas context: `ctx.setTransform(a, b, c, d, e, f)`
|
|
256
|
+
* The transformation includes devicePixelRatio scaling, viewport centering, rotation, zoom, and camera position.
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* ```typescript
|
|
260
|
+
* const transform = camera.getTransform(window.devicePixelRatio, true);
|
|
261
|
+
* ctx.setTransform(transform.a, transform.b, transform.c, transform.d, transform.e, transform.f);
|
|
262
|
+
* // Now draw in world coordinates
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
65
265
|
getTransform(devicePixelRatio: number, alignCoordinateSystem: boolean): {
|
|
66
266
|
a: number;
|
|
67
267
|
b: number;
|