@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.
Files changed (57) hide show
  1. package/README.md +66 -2
  2. package/boardify/index.d.ts +280 -9
  3. package/camera/base.d.ts +364 -68
  4. package/camera/camera-edge-auto-input.d.ts +105 -0
  5. package/camera/camera-mux/animation-and-lock/animation-and-lock.d.ts +316 -14
  6. package/camera/camera-mux/animation-and-lock/index.d.ts +27 -0
  7. package/camera/camera-mux/animation-and-lock/pan-control-state-machine.d.ts +143 -60
  8. package/camera/camera-mux/animation-and-lock/rotation-control-state-machine.d.ts +143 -55
  9. package/camera/camera-mux/animation-and-lock/zoom-control-state-machine.d.ts +205 -58
  10. package/camera/camera-mux/index.d.ts +26 -0
  11. package/camera/camera-mux/interface.d.ts +161 -5
  12. package/camera/camera-mux/relay.d.ts +79 -16
  13. package/camera/camera-rig/camera-rig.d.ts +536 -94
  14. package/camera/camera-rig/index.d.ts +26 -1
  15. package/camera/camera-rig/pan-handler.d.ts +508 -48
  16. package/camera/camera-rig/rotation-handler.d.ts +353 -31
  17. package/camera/camera-rig/zoom-handler.d.ts +369 -32
  18. package/camera/default-camera.d.ts +173 -26
  19. package/camera/index.d.ts +20 -0
  20. package/camera/interface.d.ts +202 -2
  21. package/camera/update-publisher.d.ts +128 -38
  22. package/camera/utils/coordinate-conversion.d.ts +323 -26
  23. package/camera/utils/index.d.ts +22 -0
  24. package/camera/utils/matrix.d.ts +217 -14
  25. package/camera/utils/position.d.ts +249 -11
  26. package/camera/utils/rotation.d.ts +139 -9
  27. package/camera/utils/zoom.d.ts +72 -4
  28. package/index.d.ts +37 -0
  29. package/index.js +2 -4796
  30. package/index.js.map +39 -38
  31. package/input-interpretation/index.d.ts +29 -0
  32. package/input-interpretation/input-orchestrator.d.ts +197 -0
  33. package/input-interpretation/input-state-machine/index.d.ts +18 -0
  34. package/input-interpretation/input-state-machine/kmt-input-context.d.ts +191 -38
  35. package/input-interpretation/input-state-machine/kmt-input-state-machine.d.ts +201 -85
  36. package/input-interpretation/input-state-machine/touch-input-context.d.ts +76 -10
  37. package/input-interpretation/input-state-machine/touch-input-state-machine.d.ts +138 -17
  38. package/input-interpretation/raw-input-parser/index.d.ts +19 -0
  39. package/input-interpretation/raw-input-parser/vanilla-kmt-event-parser.d.ts +107 -21
  40. package/input-interpretation/raw-input-parser/vanilla-touch-event-parser.d.ts +71 -8
  41. package/input-interpretation/raw-input-publisher/index.d.ts +18 -0
  42. package/input-interpretation/raw-input-publisher/raw-input-publisher.d.ts +133 -37
  43. package/package.json +3 -3
  44. package/utils/canvas-position-dimension.d.ts +282 -1
  45. package/utils/coordinate-conversions/canvas-viewport.d.ts +79 -0
  46. package/utils/coordinate-conversions/viewport-world.d.ts +101 -0
  47. package/utils/coordinate-conversions/window-canvas.d.ts +90 -0
  48. package/utils/coorindate-conversion.d.ts +91 -0
  49. package/utils/drawing.d.ts +151 -3
  50. package/utils/index.d.ts +21 -0
  51. package/utils/observable.d.ts +179 -0
  52. package/utils/ruler.d.ts +36 -0
  53. package/utils/zoomlevel-adjustment.d.ts +144 -8
  54. package/camera/camera-rig/update-batcher/index.d.ts +0 -3
  55. package/camera/camera-rig/update-batcher/position-update-batcher.d.ts +0 -58
  56. package/camera/camera-rig/update-batcher/rotation-update-batcher.d.ts +0 -54
  57. package/camera/camera-rig/update-batcher/zoom-udpate-batcher.d.ts +0 -60
@@ -1,78 +1,400 @@
1
1
  import { BoardCamera } from "../interface";
2
2
  /**
3
- * @description This is the configuration for the rotation handler functions.
4
- * This is the configuration object that is passed to the rotation handler functions.
3
+ * Combined configuration for rotation handler behavior, merging restriction and clamping settings.
5
4
  *
6
- * @category Camera
5
+ * @remarks
6
+ * This type combines {@link RotationHandlerRestrictConfig} and {@link RotationHandlerClampConfig}
7
+ * to provide complete control over camera rotation behavior.
8
+ *
9
+ * Rotation handlers use this configuration to:
10
+ * - Completely disable rotation operations (restriction)
11
+ * - Clamp rotation angle to stay within defined angular limits
12
+ *
13
+ * @category Camera Rig
14
+ * @see {@link RotationHandlerRestrictConfig} for rotation locking options
15
+ * @see {@link RotationHandlerClampConfig} for angular boundary options
7
16
  */
8
17
  export type RotationHandlerConfig = RotationHandlerRestrictConfig & RotationHandlerClampConfig;
18
+ /**
19
+ * Configuration for completely disabling rotation operations.
20
+ *
21
+ * @remarks
22
+ * Provides a global "rotation lock" to prevent any rotation changes.
23
+ *
24
+ * When `restrictRotation` is true:
25
+ * - Rotate-to operations return current rotation (no change)
26
+ * - Rotate-by operations return zero delta (no change)
27
+ *
28
+ * This is useful for:
29
+ * - Locking rotation during specific application states
30
+ * - Fixed-orientation viewing modes (north-up maps, etc.)
31
+ * - Preventing user rotation in certain contexts
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * const config: RotationHandlerRestrictConfig = {
36
+ * restrictRotation: true // Lock rotation
37
+ * };
38
+ *
39
+ * // Any rotation attempt will be ignored
40
+ * ```
41
+ *
42
+ * @category Camera Rig
43
+ */
9
44
  export type RotationHandlerRestrictConfig = {
10
45
  /**
11
- * @description Whether to restrict the rotation. (if true, rotation input will be ignored)
46
+ * Whether to completely prevent rotation operations.
12
47
  */
13
48
  restrictRotation: boolean;
14
49
  };
50
+ /**
51
+ * Configuration for rotation angle boundary clamping.
52
+ *
53
+ * @remarks
54
+ * Controls whether rotation operations should be constrained to camera's rotation boundaries.
55
+ *
56
+ * When `clampRotation` is true, rotation handlers enforce {@link BoardCamera.rotationBoundaries}
57
+ * limits (min/max angles in radians). When false, rotation can exceed configured boundaries.
58
+ *
59
+ * Rotation boundaries allow limiting camera rotation to a specific angular range,
60
+ * useful for scenarios like:
61
+ * - Restricting rotation to ±45 degrees from north
62
+ * - Allowing only certain cardinal directions
63
+ * - Preventing full 360-degree rotation
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const config: RotationHandlerClampConfig = {
68
+ * clampRotation: true // Enforce rotation boundaries
69
+ * };
70
+ *
71
+ * camera.rotationBoundaries = { min: 0, max: Math.PI / 2 };
72
+ * // Rotation clamped to [0, 90 degrees] range
73
+ * ```
74
+ *
75
+ * @category Camera Rig
76
+ */
15
77
  export type RotationHandlerClampConfig = {
16
78
  /**
17
- * @description Whether to clamp the rotation if the rotation is out of the rotation boundaries.
79
+ * Whether to enforce rotation angle boundaries.
18
80
  */
19
81
  clampRotation: boolean;
20
82
  };
21
83
  /**
22
- * @description The function that is used to rotate the camera by a specific delta.
23
- * The delta is in radians.
24
- * This is structured as a handler pipeline.
84
+ * Handler function type for relative "rotate by" camera operations.
25
85
  *
26
- * @see {@link createHandlerChain}
27
- * @category Camera
86
+ * @param delta - Rotation angle change in radians (positive = counter-clockwise)
87
+ * @param camera - Current camera instance
88
+ * @param config - Rotation behavior configuration
89
+ * @returns Transformed rotation delta (after applying restrictions and clamping)
90
+ *
91
+ * @remarks
92
+ * Rotate-by handlers process relative rotation change requests. They form a pipeline
93
+ * that can apply restrictions, clamping, and other transformations to the delta.
94
+ *
95
+ * Handler pipeline pattern:
96
+ * - Each handler receives the rotation delta, camera state, and config
97
+ * - Returns a potentially modified delta
98
+ * - Handlers can be chained using {@link createHandlerChain}
99
+ *
100
+ * Common transformations:
101
+ * - Angular boundary clamping (prevent exceeding min/max angles)
102
+ * - Rotation locking (return zero delta)
103
+ * - Delta dampening or snapping
104
+ *
105
+ * Rotation angles are in radians where:
106
+ * - 0 = North (no rotation)
107
+ * - Positive values = Counter-clockwise rotation
108
+ * - Negative values = Clockwise rotation
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * const myRotateByHandler: RotateByHandlerFunction = (delta, camera, config) => {
113
+ * // Custom logic: snap to 45-degree increments
114
+ * const totalRotation = camera.rotation + delta;
115
+ * const snapped = Math.round(totalRotation / (Math.PI / 4)) * (Math.PI / 4);
116
+ * return snapped - camera.rotation;
117
+ * };
118
+ * ```
119
+ *
120
+ * @category Camera Rig
121
+ * @see {@link createHandlerChain} for composing handler pipelines
122
+ * @see {@link createDefaultRotateByHandler} for the default implementation
28
123
  */
29
124
  export type RotateByHandlerFunction = (delta: number, camera: BoardCamera, config: RotationHandlerConfig) => number;
30
125
  /**
31
- * @description The function that is used to rotate the camera to a specific target rotation.
32
- * The target rotation is in radians.
33
- * This is structured as a handler pipeline.
126
+ * Handler function type for absolute "rotate to" camera operations.
127
+ *
128
+ * @param targetRotation - Target rotation angle in radians
129
+ * @param camera - Current camera instance
130
+ * @param config - Rotation behavior configuration
131
+ * @returns Transformed rotation angle (after applying restrictions and clamping)
132
+ *
133
+ * @remarks
134
+ * Rotate-to handlers process absolute rotation angle requests. They form a pipeline
135
+ * that can apply restrictions, clamping, and other transformations.
136
+ *
137
+ * Handler pipeline pattern:
138
+ * - Each handler receives the target angle, camera state, and config
139
+ * - Returns a potentially modified angle
140
+ * - Handlers can be chained using {@link createHandlerChain}
34
141
  *
35
- * @see {@link createHandlerChain}
36
- * @category Camera
142
+ * Common transformations:
143
+ * - Angular boundary clamping (enforce min/max angles)
144
+ * - Rotation locking (return current angle)
145
+ * - Angle snapping or normalization
146
+ *
147
+ * Rotation angles are in radians where:
148
+ * - 0 = North (no rotation)
149
+ * - π/2 = West (90° counter-clockwise)
150
+ * - π = South (180°)
151
+ * - 3π/2 = East (270° counter-clockwise)
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const myRotateToHandler: RotateToHandlerFunction = (target, camera, config) => {
156
+ * // Custom logic: snap to cardinal directions
157
+ * const cardinals = [0, Math.PI/2, Math.PI, 3*Math.PI/2];
158
+ * return cardinals.reduce((prev, curr) =>
159
+ * Math.abs(curr - target) < Math.abs(prev - target) ? curr : prev
160
+ * );
161
+ * };
162
+ * ```
163
+ *
164
+ * @category Camera Rig
165
+ * @see {@link createHandlerChain} for composing handler pipelines
166
+ * @see {@link createDefaultRotateToHandler} for the default implementation
37
167
  */
38
168
  export type RotateToHandlerFunction = (targetRotation: number, camera: BoardCamera, config: RotationHandlerConfig) => number;
39
169
  /**
40
- * @description This is the clamp handler for the "rotate by" handler pipeline.
41
- * It clamps the delta to the range of the camera's rotation boundaries.
170
+ * Handler pipeline step that clamps "rotate by" deltas to prevent angular boundary violations.
171
+ *
172
+ * @param delta - Rotation angle change in radians
173
+ * @param camera - Current camera instance (provides current rotation and boundaries)
174
+ * @param config - Clamping configuration
175
+ * @returns Adjusted delta that respects rotation boundaries
176
+ *
177
+ * @remarks
178
+ * This handler ensures that applying the delta won't exceed rotation boundaries.
179
+ *
180
+ * Algorithm:
181
+ * 1. Calculate potential new rotation (current + delta)
182
+ * 2. Normalize angle to [0, 2π) range
183
+ * 3. Clamp to rotation boundaries
184
+ * 4. Calculate shortest angular distance from current to clamped angle
185
+ * 5. Return that distance as the new delta
186
+ *
187
+ * Behavior:
188
+ * - If `clampRotation` is false: Returns delta unchanged
189
+ * - If `clampRotation` is true: Adjusts delta to stay within boundaries
190
+ *
191
+ * The resulting delta may be zero if already at a boundary and trying to rotate further.
42
192
  *
43
- * @category Camera
193
+ * @example
194
+ * ```typescript
195
+ * camera.rotation = Math.PI * 0.4; // 72 degrees
196
+ * camera.rotationBoundaries = { max: Math.PI / 2 }; // Max 90 degrees
197
+ *
198
+ * const config: RotationHandlerClampConfig = {
199
+ * clampRotation: true
200
+ * };
201
+ *
202
+ * const delta = Math.PI * 0.2; // Try to rotate 36 degrees (would exceed max)
203
+ * const clamped = clampRotateByHandler(delta, camera, config);
204
+ * // clamped ≈ 0.314 radians (18 degrees - only rotate to boundary)
205
+ * ```
206
+ *
207
+ * @category Camera Rig
208
+ * @see {@link normalizeAngleZero2TwoPI} for angle normalization
209
+ * @see {@link clampRotation} for boundary clamping
210
+ * @see {@link angleSpan} for calculating angular distance
44
211
  */
45
212
  export declare function clampRotateByHandler(delta: number, camera: BoardCamera, config: RotationHandlerClampConfig): number;
46
213
  /**
47
- * @description This is the restrict handler for the "rotate by" handler pipeline.
48
- * It restricts the delta to the range of the camera's rotation boundaries.
214
+ * Handler pipeline step that prevents "rotate by" operations when rotation is locked.
215
+ *
216
+ * @param delta - Rotation angle change in radians
217
+ * @param camera - Current camera instance
218
+ * @param config - Restriction configuration
219
+ * @returns Zero (if locked) or delta (if unlocked)
220
+ *
221
+ * @remarks
222
+ * This handler implements a global rotation lock for relative rotation operations.
49
223
  *
50
- * @category Camera
224
+ * Behavior:
225
+ * - If `restrictRotation` is true: Returns 0 (prevents any change)
226
+ * - If `restrictRotation` is false: Returns delta unchanged
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * const config: RotationHandlerRestrictConfig = {
231
+ * restrictRotation: true // Lock rotation
232
+ * };
233
+ *
234
+ * const delta = Math.PI / 4; // Try to rotate 45 degrees
235
+ * const result = restrictRotateByHandler(delta, camera, config);
236
+ * // result = 0 (rotation locked, no change allowed)
237
+ * ```
238
+ *
239
+ * @category Camera Rig
240
+ * @see {@link createDefaultRotateByHandler} for default pipeline usage
51
241
  */
52
242
  export declare function restrictRotateByHandler(delta: number, camera: BoardCamera, config: RotationHandlerRestrictConfig): number;
53
243
  /**
54
- * @description This is the clamp handler for the "rotate to" handler pipeline.
55
- * It clamps the target rotation to the range of the camera's rotation boundaries.
244
+ * Handler pipeline step that clamps "rotate to" targets to camera rotation boundaries.
245
+ *
246
+ * @param targetRotation - Target rotation angle in radians
247
+ * @param camera - Current camera instance (provides rotationBoundaries)
248
+ * @param config - Clamping configuration
249
+ * @returns Clamped rotation angle
56
250
  *
57
- * @category Camera
251
+ * @remarks
252
+ * This handler enforces angular limits on absolute rotation requests.
253
+ *
254
+ * Behavior:
255
+ * - If `clampRotation` is false: Returns target unchanged
256
+ * - If `clampRotation` is true: Clamps target to {@link BoardCamera.rotationBoundaries}
257
+ *
258
+ * The clamping handles:
259
+ * - Missing boundaries (undefined min/max)
260
+ * - One-sided constraints (only min or only max)
261
+ * - Full range constraints
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * camera.rotationBoundaries = { min: 0, max: Math.PI }; // [0°, 180°]
266
+ *
267
+ * const config: RotationHandlerClampConfig = {
268
+ * clampRotation: true
269
+ * };
270
+ *
271
+ * const target = Math.PI * 1.5; // 270 degrees (exceeds max)
272
+ * const clamped = clampRotateToHandler(target, camera, config);
273
+ * // clamped = π (180 degrees - clamped to max boundary)
274
+ * ```
275
+ *
276
+ * @category Camera Rig
277
+ * @see {@link clampRotation} for clamping implementation
278
+ * @see {@link createDefaultRotateToHandler} for default pipeline usage
58
279
  */
59
280
  export declare function clampRotateToHandler(targetRotation: number, camera: BoardCamera, config: RotationHandlerClampConfig): number;
60
281
  /**
61
- * @description This is the restrict handler for the "rotate to" handler pipeline.
62
- * It restricts the target rotation to the range of the camera's rotation boundaries.
282
+ * Handler pipeline step that prevents "rotate to" operations when rotation is locked.
283
+ *
284
+ * @param targetRotation - Target rotation angle in radians
285
+ * @param camera - Current camera instance
286
+ * @param config - Restriction configuration
287
+ * @returns Current rotation (if locked) or target (if unlocked)
288
+ *
289
+ * @remarks
290
+ * This handler implements a global rotation lock for absolute rotation operations.
63
291
  *
64
- * @category Camera
292
+ * Behavior:
293
+ * - If `restrictRotation` is true: Returns current rotation (prevents any change)
294
+ * - If `restrictRotation` is false: Returns target unchanged
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * camera.rotation = Math.PI / 2; // Currently at 90 degrees
299
+ *
300
+ * const config: RotationHandlerRestrictConfig = {
301
+ * restrictRotation: true // Lock rotation
302
+ * };
303
+ *
304
+ * const target = Math.PI; // Try to rotate to 180 degrees
305
+ * const result = restrictRotateToHandler(target, camera, config);
306
+ * // result = π/2 (rotation locked, returns current angle)
307
+ * ```
308
+ *
309
+ * @category Camera Rig
310
+ * @see {@link createDefaultRotateToHandler} for default pipeline usage
65
311
  */
66
312
  export declare function restrictRotateToHandler(targetRotation: number, camera: BoardCamera, config: RotationHandlerRestrictConfig): number;
67
313
  /**
68
- * @description This is the create default handler chain function for the "rotate by" handler pipeline.
314
+ * Creates a default "rotate by" handler pipeline for relative rotation operations.
315
+ *
316
+ * @returns Rotate-by handler function with restriction and clamping
317
+ *
318
+ * @remarks
319
+ * The default handler pipeline applies transformations in this order:
320
+ * 1. **Restriction** ({@link restrictRotateByHandler}): Returns zero delta if locked
321
+ * 2. **Clamping** ({@link clampRotateByHandler}): Adjusts delta to respect boundaries
322
+ *
323
+ * This ensures that:
324
+ * - Rotation can be completely disabled via `restrictRotation` flag
325
+ * - Resulting rotation angle stays within configured angular boundaries
326
+ * - Delta is adjusted to prevent boundary violations
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * const rotateBy = createDefaultRotateByHandler();
331
+ *
332
+ * camera.rotation = Math.PI * 0.4; // 72 degrees
333
+ * camera.rotationBoundaries = { max: Math.PI / 2 }; // Max 90 degrees
69
334
  *
70
- * @category Camera
335
+ * const delta = Math.PI * 0.3; // Try to rotate 54 degrees (would exceed max)
336
+ * const constrained = rotateBy(delta, camera, {
337
+ * clampRotation: true,
338
+ * restrictRotation: false
339
+ * });
340
+ * // constrained adjusted to only rotate to boundary
341
+ * camera.setRotation(camera.rotation + constrained);
342
+ * ```
343
+ *
344
+ * @category Camera Rig
345
+ * @see {@link createHandlerChain} for creating custom handler pipelines
346
+ * @see {@link restrictRotateByHandler} for the restriction step
347
+ * @see {@link clampRotateByHandler} for the clamping step
71
348
  */
72
349
  export declare function createDefaultRotateByHandler(): RotateByHandlerFunction;
73
350
  /**
74
- * @description This is the create default handler chain function for the "rotate to" handler pipeline.
351
+ * Creates a default "rotate to" handler pipeline for absolute rotation operations.
352
+ *
353
+ * @returns Rotate-to handler function with restriction and clamping
354
+ *
355
+ * @remarks
356
+ * The default handler pipeline applies transformations in this order:
357
+ * 1. **Restriction** ({@link restrictRotateToHandler}): Returns current angle if locked
358
+ * 2. **Clamping** ({@link clampRotateToHandler}): Clamps angle to configured boundaries
359
+ *
360
+ * This ensures that:
361
+ * - Rotation can be completely disabled via `restrictRotation` flag
362
+ * - Rotation angle stays within configured angular boundaries
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * const rotateTo = createDefaultRotateToHandler();
367
+ *
368
+ * camera.rotationBoundaries = { min: 0, max: Math.PI }; // [0°, 180°]
369
+ *
370
+ * const target = Math.PI * 1.5; // 270 degrees (exceeds max)
371
+ * const constrained = rotateTo(target, camera, {
372
+ * clampRotation: true,
373
+ * restrictRotation: false
374
+ * });
375
+ * // constrained = π (clamped to max boundary of 180 degrees)
376
+ * camera.setRotation(constrained);
377
+ * ```
378
+ *
379
+ * @example
380
+ * ```typescript
381
+ * // Create custom pipeline with snapping
382
+ * const cardinalRotateTo = createHandlerChain<number, [BoardCamera, RotationHandlerConfig]>(
383
+ * restrictRotateToHandler,
384
+ * (angle) => {
385
+ * // Snap to cardinal directions (0°, 90°, 180°, 270°)
386
+ * const cardinals = [0, Math.PI/2, Math.PI, 3*Math.PI/2];
387
+ * return cardinals.reduce((prev, curr) =>
388
+ * Math.abs(curr - angle) < Math.abs(prev - angle) ? curr : prev
389
+ * );
390
+ * },
391
+ * clampRotateToHandler
392
+ * );
393
+ * ```
75
394
  *
76
- * @category Camera
395
+ * @category Camera Rig
396
+ * @see {@link createHandlerChain} for creating custom handler pipelines
397
+ * @see {@link restrictRotateToHandler} for the restriction step
398
+ * @see {@link clampRotateToHandler} for the clamping step
77
399
  */
78
400
  export declare function createDefaultRotateToHandler(): RotateToHandlerFunction;