@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
package/utils/ruler.d.ts CHANGED
@@ -1 +1,37 @@
1
+ /**
2
+ * Calculates the order of magnitude (power of 10) of a number.
3
+ *
4
+ * @param value - The number to analyze
5
+ * @returns The power of 10 that best represents this value's magnitude
6
+ *
7
+ * @remarks
8
+ * The order of magnitude helps determine appropriate tick spacing for rulers
9
+ * and grids. For example:
10
+ * - Value 1234 has order 3 (10^3 = 1000)
11
+ * - Value 0.056 has order -2 (10^-2 = 0.01)
12
+ *
13
+ * The calculation finds the largest power of 10 that is less than or equal
14
+ * to the absolute value.
15
+ *
16
+ * Edge cases:
17
+ * - Returns 0 for values <= 0
18
+ * - For values >= 1: Counts powers of 10 until reaching the value
19
+ * - For values < 1: Counts negative powers of 10 until reaching the value
20
+ *
21
+ * This is used by drawing utilities to automatically scale tick marks and
22
+ * grid lines appropriately for different zoom levels.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * calculateOrderOfMagnitude(1500); // 3 (between 10^3=1000 and 10^4=10000)
27
+ * calculateOrderOfMagnitude(85); // 1 (between 10^1=10 and 10^2=100)
28
+ * calculateOrderOfMagnitude(7); // 0 (between 10^0=1 and 10^1=10)
29
+ * calculateOrderOfMagnitude(0.05); // -2 (between 10^-2=0.01 and 10^-1=0.1)
30
+ * calculateOrderOfMagnitude(0); // 0 (edge case)
31
+ * calculateOrderOfMagnitude(-100); // 0 (negative edge case)
32
+ * ```
33
+ *
34
+ * @category Drawing Utilities
35
+ * @see {@link drawRuler} for usage in ruler drawing
36
+ */
1
37
  export declare function calculateOrderOfMagnitude(value: number): number;
@@ -1,28 +1,164 @@
1
1
  import { Boundaries } from "../camera/utils/position";
2
2
  import { ZoomLevelLimits } from "../camera/utils/zoom";
3
3
  /**
4
- * @description Calculates the minimum zoom level based on the dimensions of the boundaries.
5
- * Used when the canvas on the html is resized.
4
+ * Calculates minimum zoom level to fit boundaries within canvas at any rotation.
5
+ *
6
+ * @param boundaries - The world-space boundaries to fit
7
+ * @param canvasWidth - Canvas width in pixels
8
+ * @param canvasHeight - Canvas height in pixels
9
+ * @param cameraRotation - Camera rotation angle in radians
10
+ * @returns Minimum zoom level, or undefined if boundaries are incomplete
11
+ *
12
+ * @remarks
13
+ * This function ensures the entire boundary region remains visible regardless
14
+ * of camera rotation. It considers both width and height projections of the
15
+ * rotated boundaries.
16
+ *
17
+ * When boundaries are rotated, they occupy a larger axis-aligned bounding box.
18
+ * This function calculates the minimum zoom needed to fit that box:
19
+ *
20
+ * For each dimension (width/height):
21
+ * 1. Project boundary width onto canvas width axis: `width * cos(rotation)`
22
+ * 2. Project boundary height onto canvas width axis: `height * cos(rotation)`
23
+ * 3. Calculate zoom needed for each projection
24
+ * 4. Take the maximum of all zoom levels
25
+ *
26
+ * Returns undefined if boundaries don't have both width and height defined.
27
+ *
28
+ * Used when canvas is resized to automatically adjust zoom to keep content visible.
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * const boundaries = {
33
+ * min: { x: 0, y: 0 },
34
+ * max: { x: 1000, y: 500 }
35
+ * };
36
+ *
37
+ * // No rotation, 800x600 canvas
38
+ * const zoom1 = minZoomLevelBaseOnDimensions(boundaries, 800, 600, 0);
39
+ * // Result: 1.2 (600/500, height is limiting)
40
+ *
41
+ * // 45 degree rotation
42
+ * const zoom2 = minZoomLevelBaseOnDimensions(
43
+ * boundaries, 800, 600, Math.PI / 4
44
+ * );
45
+ * // Result: higher zoom (rotated bounds need more space)
46
+ * ```
6
47
  *
7
48
  * @category Camera
49
+ * @see {@link minZoomLevelBaseOnWidth} for width-only calculation
50
+ * @see {@link minZoomLevelBaseOnHeight} for height-only calculation
8
51
  */
9
52
  export declare function minZoomLevelBaseOnDimensions(boundaries: Boundaries | undefined, canvasWidth: number, canvasHeight: number, cameraRotation: number): number | undefined;
10
53
  /**
11
- * @description Determines if the zoom level boundaries should be updated when the canvas is resized.
12
- * Zoom level boundaries adjustment only tightens the zoom level boundaries; it does not relax them.
54
+ * Determines if zoom level boundaries should be updated.
55
+ *
56
+ * @param zoomLevelBoundaries - Current zoom level limits
57
+ * @param targetMinZoomLevel - Proposed new minimum zoom level
58
+ * @returns True if boundaries should be updated (type guard for targetMinZoomLevel)
59
+ *
60
+ * @remarks
61
+ * Zoom level boundary updates only tighten (increase minimum zoom), never relax.
62
+ * This prevents the camera from zooming out too far when boundaries shrink.
63
+ *
64
+ * Returns true (update needed) when:
65
+ * - No current boundaries exist (first-time setup)
66
+ * - Target minimum is higher than current minimum (tightening)
67
+ *
68
+ * Returns false (no update) when:
69
+ * - Target is undefined (invalid/incomplete)
70
+ * - Target is Infinity (invalid state)
71
+ * - Target is lower than current minimum (would relax, not allowed)
72
+ *
73
+ * This function is a type guard: when it returns true, TypeScript knows
74
+ * targetMinZoomLevel is a number (not undefined).
75
+ *
76
+ * @example
77
+ * ```typescript
78
+ * const currentLimits = { min: 0.5, max: 10 };
79
+ * const newMin = 0.8;
80
+ *
81
+ * if (zoomLevelBoundariesShouldUpdate(currentLimits, newMin)) {
82
+ * // Safe to use newMin as number here
83
+ * currentLimits.min = newMin; // Tighten the limit
84
+ * }
85
+ *
86
+ * // No update for lower values
87
+ * zoomLevelBoundariesShouldUpdate(currentLimits, 0.3); // false
88
+ * ```
13
89
  *
14
90
  * @category Camera
15
91
  */
16
92
  export declare function zoomLevelBoundariesShouldUpdate(zoomLevelBoundaries: ZoomLevelLimits | undefined, targetMinZoomLevel: number | undefined): targetMinZoomLevel is number;
17
93
  /**
18
- * @description Calculates the minimum zoom level based on the width of the boundaries.
19
- * Used when the canvas on the html is resized.
94
+ * Calculates minimum zoom level based only on boundary width.
95
+ *
96
+ * @param boundaries - The world-space boundaries
97
+ * @param canvasWidth - Canvas width in pixels
98
+ * @param canvasHeight - Canvas height in pixels
99
+ * @param cameraRotation - Camera rotation angle in radians
100
+ * @returns Minimum zoom level, or undefined if width is not defined
101
+ *
102
+ * @remarks
103
+ * Similar to {@link minZoomLevelBaseOnDimensions} but only considers the
104
+ * width constraint. Useful when height is unbounded or not relevant.
105
+ *
106
+ * Calculates zoom needed to fit the boundary width within the canvas,
107
+ * accounting for rotation:
108
+ * - Width projection on canvas X-axis: `width * cos(rotation)`
109
+ * - Width projection on canvas Y-axis: `width * sin(rotation)`
110
+ *
111
+ * Takes the maximum of these to ensure the width fits regardless of
112
+ * how rotation distributes it across canvas axes.
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * const boundaries = {
117
+ * min: { x: 0 },
118
+ * max: { x: 1000 }
119
+ * };
120
+ *
121
+ * const zoom = minZoomLevelBaseOnWidth(boundaries, 800, 600, 0);
122
+ * // Result: 0.8 (800/1000)
123
+ * ```
124
+ *
20
125
  * @category Camera
126
+ * @see {@link minZoomLevelBaseOnDimensions} for full calculation
21
127
  */
22
128
  export declare function minZoomLevelBaseOnWidth(boundaries: Boundaries | undefined, canvasWidth: number, canvasHeight: number, cameraRotation: number): number | undefined;
23
129
  /**
24
- * @description Calculates the minimum zoom level based on the height of the boundaries.
25
- * Used when the canvas on the html is resized.
130
+ * Calculates minimum zoom level based only on boundary height.
131
+ *
132
+ * @param boundaries - The world-space boundaries
133
+ * @param canvasWidth - Canvas width in pixels
134
+ * @param canvasHeight - Canvas height in pixels
135
+ * @param cameraRotation - Camera rotation angle in radians
136
+ * @returns Minimum zoom level, or undefined if height is not defined
137
+ *
138
+ * @remarks
139
+ * Similar to {@link minZoomLevelBaseOnDimensions} but only considers the
140
+ * height constraint. Useful when width is unbounded or not relevant.
141
+ *
142
+ * Calculates zoom needed to fit the boundary height within the canvas,
143
+ * accounting for rotation:
144
+ * - Height projection on canvas X-axis: `height * cos(rotation)`
145
+ * - Height projection on canvas Y-axis: `height * sin(rotation)`
146
+ *
147
+ * Takes the maximum of these to ensure the height fits regardless of
148
+ * how rotation distributes it across canvas axes.
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * const boundaries = {
153
+ * min: { y: 0 },
154
+ * max: { y: 500 }
155
+ * };
156
+ *
157
+ * const zoom = minZoomLevelBaseOnHeight(boundaries, 800, 600, 0);
158
+ * // Result: 1.2 (600/500)
159
+ * ```
160
+ *
26
161
  * @category Camera
162
+ * @see {@link minZoomLevelBaseOnDimensions} for full calculation
27
163
  */
28
164
  export declare function minZoomLevelBaseOnHeight(boundaries: Boundaries | undefined, canvasWidth: number, canvasHeight: number, cameraRotation: number): number | undefined;
@@ -1,3 +0,0 @@
1
- export * from "./position-update-batcher";
2
- export * from "./rotation-update-batcher";
3
- export * from "./zoom-udpate-batcher";
@@ -1,58 +0,0 @@
1
- import { Observer, SubscriptionOptions } from "../../../utils/observable";
2
- export type Position = {
3
- x: number;
4
- y: number;
5
- };
6
- export type Velocity = {
7
- vx: number;
8
- vy: number;
9
- };
10
- export type DestinationUpdate = Position & {
11
- type: 'destination';
12
- };
13
- export type DeltaUpdate = Position & {
14
- type: 'delta';
15
- };
16
- export type PositionUpdate = DestinationUpdate | DeltaUpdate;
17
- export declare class CameraPositionUpdateBatcher {
18
- private nextPosition;
19
- private delta;
20
- private observable;
21
- private queuePositionUpdateCount;
22
- private queuePositionUpdateToCount;
23
- private queuePositionUpdateByCount;
24
- private lastUpdateCount;
25
- constructor();
26
- /**
27
- * Queue an absolute position update to be processed in the next animation frame
28
- */
29
- queuePositionUpdate(x: number, y: number): void;
30
- /**
31
- * Queue a position update to a specific destination to be processed in the next animation frame
32
- * This will override any pending delta updates
33
- */
34
- queuePositionUpdateTo(destination: Position): void;
35
- /**
36
- * Queue a position update by delta to be processed in the next animation frame
37
- * This will be ignored if there's a pending destination update
38
- */
39
- queuePositionUpdateBy(delta: Position): void;
40
- /**
41
- * Process and clear all queued position updates
42
- * @returns the update to apply to the position, with type information
43
- */
44
- processQueuedUpdates(): PositionUpdate | null;
45
- /**
46
- * Subscribe to position updates
47
- */
48
- subscribe(observer: Observer<[PositionUpdate]>, options?: SubscriptionOptions): () => void;
49
- /**
50
- * Get debug information about queue method calls since last update
51
- */
52
- getDebugInfo(): {
53
- lastUpdateTotalCalls: number;
54
- queuePositionUpdateCalls: number;
55
- queuePositionUpdateToCalls: number;
56
- queuePositionUpdateByCalls: number;
57
- };
58
- }
@@ -1,54 +0,0 @@
1
- import { Observer, SubscriptionOptions } from "../../../utils/observable";
2
- export type Rotation = number;
3
- export type RotationVelocity = number;
4
- export type RotationDestinationUpdate = {
5
- type: 'destination';
6
- destination: Rotation;
7
- };
8
- export type RotationDeltaUpdate = {
9
- type: 'delta';
10
- delta: Rotation;
11
- };
12
- export type RotationUpdate = RotationDestinationUpdate | RotationDeltaUpdate;
13
- export declare class CameraRotationUpdateBatcher {
14
- private nextRotation;
15
- private delta;
16
- private observable;
17
- private queueRotationUpdateCount;
18
- private queueRotationUpdateToCount;
19
- private queueRotationUpdateByCount;
20
- private lastUpdateCount;
21
- constructor();
22
- /**
23
- * Queue an absolute rotation update to be processed in the next animation frame
24
- */
25
- queueRotationUpdate(rotation: Rotation): void;
26
- /**
27
- * Queue a rotation update to a specific destination to be processed in the next animation frame
28
- * This will override any pending delta updates
29
- */
30
- queueRotationUpdateTo(destination: Rotation): void;
31
- /**
32
- * Queue a rotation update by delta to be processed in the next animation frame
33
- * This will be ignored if there's a pending destination update
34
- */
35
- queueRotationUpdateBy(delta: Rotation): void;
36
- /**
37
- * Process and clear all queued rotation updates
38
- * @returns the update to apply to the rotation, with type information
39
- */
40
- processQueuedUpdates(): RotationUpdate | null;
41
- /**
42
- * Subscribe to rotation updates
43
- */
44
- subscribe(observer: Observer<[RotationUpdate]>, options?: SubscriptionOptions): () => void;
45
- /**
46
- * Get debug information about queue method calls since last update
47
- */
48
- getDebugInfo(): {
49
- lastUpdateTotalCalls: number;
50
- queueRotationUpdateCalls: number;
51
- queueRotationUpdateToCalls: number;
52
- queueRotationUpdateByCalls: number;
53
- };
54
- }
@@ -1,60 +0,0 @@
1
- import { Observer, SubscriptionOptions } from "../../../utils/observable";
2
- import { Point } from "@ue-too/math";
3
- export type DestinationZoomUpdate = {
4
- type: 'destination';
5
- destination: number;
6
- anchor?: Point;
7
- };
8
- export type DeltaZoomUpdate = {
9
- type: 'delta';
10
- delta: number;
11
- anchor?: Point;
12
- };
13
- export type ZoomUpdate = {
14
- anchorCoordinateSystem: 'world' | 'viewport';
15
- update: DestinationZoomUpdate | DeltaZoomUpdate;
16
- };
17
- export declare class CameraZoomUpdateBatcher {
18
- private nextZoom;
19
- private observable;
20
- private anchor;
21
- private delta;
22
- private anchorCoordinateSystem;
23
- private queueZoomUpdateCount;
24
- private queueZoomUpdateToCount;
25
- private lastUpdateCount;
26
- constructor();
27
- /**
28
- * Queue a zoom update to a specific destination to be processed in the next animation frame
29
- */
30
- queueZoomUpdateTo(destination: number, anchor?: Point): void;
31
- /**
32
- * Queue a zoom update by delta to be processed in the next animation frame
33
- */
34
- queueZoomUpdateBy(delta: number, anchor?: Point): void;
35
- /**
36
- * Queue a zoom update by delta at a world anchor to be processed in the next animation frame
37
- */
38
- queueZoomByAtWorld(delta: number, worldAnchor: Point): void;
39
- /**
40
- * Queue a zoom update to a specific destination at a world anchor to be processed in the next animation frame
41
- */
42
- queueZoomToAtWorld(destination: number, worldAnchor: Point): void;
43
- /**
44
- * Process and clear all queued zoom updates
45
- * @returns the update to apply to the zoom level, with type information
46
- */
47
- processQueuedUpdates(): ZoomUpdate | null;
48
- /**
49
- * Subscribe to zoom updates
50
- */
51
- subscribe(observer: Observer<[ZoomUpdate]>, options?: SubscriptionOptions): () => void;
52
- /**
53
- * Get debug information about queue method calls since last update
54
- */
55
- getDebugInfo(): {
56
- lastUpdateTotalCalls: number;
57
- queueZoomUpdateCalls: number;
58
- queueZoomUpdateToCalls: number;
59
- };
60
- }