vehicle-path2 1.0.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 +160 -0
- package/dist/animation-loop-bZEm2pMN.js +37 -0
- package/dist/animation-loop-fC2LjxCd.cjs +1 -0
- package/dist/core/algorithms/math.d.ts +35 -0
- package/dist/core/algorithms/pathFinding.d.ts +62 -0
- package/dist/core/algorithms/vehicleMovement.d.ts +174 -0
- package/dist/core/index.d.ts +20 -0
- package/dist/core/types/api.d.ts +185 -0
- package/dist/core/types/config.d.ts +9 -0
- package/dist/core/types/geometry.d.ts +26 -0
- package/dist/core/types/movement.d.ts +56 -0
- package/dist/core/types/vehicle.d.ts +65 -0
- package/dist/core.cjs +1 -0
- package/dist/core.js +551 -0
- package/dist/index.d.ts +45 -0
- package/dist/react/dsl-hooks/useInitialMovement.d.ts +24 -0
- package/dist/react/dsl-hooks/useMovementSequence.d.ts +27 -0
- package/dist/react/dsl-hooks/useSceneDefinition.d.ts +22 -0
- package/dist/react/hooks/useAnimation.d.ts +43 -0
- package/dist/react/hooks/useMovementQueue.d.ts +52 -0
- package/dist/react/hooks/useScene.d.ts +78 -0
- package/dist/react/hooks/useVehicleSimulation.d.ts +126 -0
- package/dist/react/hooks/useVehicles.d.ts +55 -0
- package/dist/react/index.d.ts +48 -0
- package/dist/react/providers/useVehicleEvents.d.ts +78 -0
- package/dist/react.cjs +1 -0
- package/dist/react.js +18 -0
- package/dist/useVehicleEvents-B2JQFNjc.js +923 -0
- package/dist/useVehicleEvents-CBymulau.cjs +3 -0
- package/dist/utils/animation-loop.d.ts +105 -0
- package/dist/utils/dsl-parser.d.ts +152 -0
- package/dist/utils/event-emitter.d.ts +94 -0
- package/dist/utils/index.d.ts +15 -0
- package/dist/utils/type-converters.d.ts +38 -0
- package/dist/utils/vehicle-helpers.d.ts +8 -0
- package/dist/utils.cjs +1 -0
- package/dist/utils.js +17 -0
- package/dist/vehicle-helpers-DIcksrtO.cjs +7 -0
- package/dist/vehicle-helpers-_72KxCqO.js +276 -0
- package/dist/vehicle-path.cjs +1 -0
- package/dist/vehicle-path.js +62 -0
- package/package.json +103 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { Line } from '../../core/types/geometry';
|
|
2
|
+
import type { Vehicle, GotoCommand } from '../../core/types/vehicle';
|
|
3
|
+
import type { TangentMode } from '../../core/types/config';
|
|
4
|
+
import type { VehicleEventEmitter } from '../../utils/event-emitter';
|
|
5
|
+
export interface UseAnimationProps {
|
|
6
|
+
vehicles: Vehicle[];
|
|
7
|
+
lines: Line[];
|
|
8
|
+
vehicleQueues: Map<string, GotoCommand[]>;
|
|
9
|
+
wheelbase: number;
|
|
10
|
+
tangentMode: TangentMode;
|
|
11
|
+
curves: import('../../core/types/geometry').Curve[];
|
|
12
|
+
eventEmitter?: VehicleEventEmitter;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Hook for running vehicle animation/simulation.
|
|
16
|
+
*
|
|
17
|
+
* This hook handles the actual movement of vehicles along paths.
|
|
18
|
+
* Call prepare() before starting, then tick() in your animation loop.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* const { movingVehicles, prepare, tick, reset, isMoving } = useAnimation({
|
|
23
|
+
* vehicles, lines, vehicleQueues, wheelbase: 30, tangentMode: 'proportional-40', curves
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* // Start animation
|
|
27
|
+
* prepare()
|
|
28
|
+
*
|
|
29
|
+
* // In animation loop
|
|
30
|
+
* const animate = () => {
|
|
31
|
+
* if (tick(5)) requestAnimationFrame(animate)
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function useAnimation({ vehicles, lines, vehicleQueues, wheelbase, tangentMode, curves, eventEmitter }: UseAnimationProps): {
|
|
36
|
+
movingVehicles: Vehicle[];
|
|
37
|
+
prepare: () => boolean;
|
|
38
|
+
tick: (distance: number) => boolean;
|
|
39
|
+
reset: () => void;
|
|
40
|
+
continueVehicle: (vehicleId: string) => boolean;
|
|
41
|
+
isMoving: () => boolean;
|
|
42
|
+
isPrepared: boolean;
|
|
43
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Line, Curve } from '../../core/types/geometry';
|
|
2
|
+
import type { Vehicle, GotoCommand } from '../../core/types/vehicle';
|
|
3
|
+
import type { GotoCommandInput } from '../../core/types/api';
|
|
4
|
+
export interface UseMovementQueueProps {
|
|
5
|
+
vehicles: Vehicle[];
|
|
6
|
+
lines: Line[];
|
|
7
|
+
curves: Curve[];
|
|
8
|
+
}
|
|
9
|
+
export interface UseMovementQueueResult {
|
|
10
|
+
/** Queue of commands per vehicle */
|
|
11
|
+
vehicleQueues: Map<string, GotoCommand[]>;
|
|
12
|
+
/** Queue a movement command for a vehicle */
|
|
13
|
+
queueMovement: (vehicleId: string, input: GotoCommandInput) => {
|
|
14
|
+
success: boolean;
|
|
15
|
+
error?: string;
|
|
16
|
+
};
|
|
17
|
+
/** Clear the queue for a specific vehicle or all vehicles */
|
|
18
|
+
clearQueue: (vehicleId?: string) => {
|
|
19
|
+
success: boolean;
|
|
20
|
+
error?: string;
|
|
21
|
+
};
|
|
22
|
+
/** Any error from the last operation */
|
|
23
|
+
error: string | null;
|
|
24
|
+
/** @internal Load pre-computed queues directly (for bulk loading) */
|
|
25
|
+
_loadQueues: (queues: Map<string, GotoCommand[]>) => void;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Hook for managing the queue of movement commands.
|
|
29
|
+
*
|
|
30
|
+
* This hook provides a simple API for queuing goto commands at runtime.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* const { vehicleQueues, queueMovement, clearQueue } = useMovementQueue({ vehicles, lines, curves })
|
|
35
|
+
*
|
|
36
|
+
* // Queue movements
|
|
37
|
+
* queueMovement('v1', { targetLineId: 'line002', targetPosition: 0.5 })
|
|
38
|
+
* queueMovement('v1', {
|
|
39
|
+
* targetLineId: 'line003',
|
|
40
|
+
* targetPosition: 1.0,
|
|
41
|
+
* wait: true,
|
|
42
|
+
* payload: { orderId: '123' }
|
|
43
|
+
* })
|
|
44
|
+
*
|
|
45
|
+
* // Clear queue for a specific vehicle
|
|
46
|
+
* clearQueue('v1')
|
|
47
|
+
*
|
|
48
|
+
* // Clear all queues
|
|
49
|
+
* clearQueue()
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function useMovementQueue({ vehicles, lines }: UseMovementQueueProps): UseMovementQueueResult;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { Line, Curve } from '../../core/types/geometry';
|
|
2
|
+
import type { SceneConfig, SceneLineInput, SceneConnectionInput, CoordinateInput, ConnectionUpdateInput } from '../../core/types/api';
|
|
3
|
+
export interface UseSceneResult {
|
|
4
|
+
/** Current lines in the scene */
|
|
5
|
+
lines: Line[];
|
|
6
|
+
/** Current curves (connections) in the scene */
|
|
7
|
+
curves: Curve[];
|
|
8
|
+
/** Set the entire scene configuration */
|
|
9
|
+
setScene: (config: SceneConfig) => {
|
|
10
|
+
success: boolean;
|
|
11
|
+
errors?: string[];
|
|
12
|
+
};
|
|
13
|
+
/** Add a single line to the scene */
|
|
14
|
+
addLine: (line: SceneLineInput) => {
|
|
15
|
+
success: boolean;
|
|
16
|
+
error?: string;
|
|
17
|
+
};
|
|
18
|
+
/** Update a line's start and/or end coordinates */
|
|
19
|
+
updateLine: (lineId: string, updates: {
|
|
20
|
+
start?: CoordinateInput;
|
|
21
|
+
end?: CoordinateInput;
|
|
22
|
+
}) => {
|
|
23
|
+
success: boolean;
|
|
24
|
+
error?: string;
|
|
25
|
+
};
|
|
26
|
+
/** Remove a line from the scene */
|
|
27
|
+
removeLine: (lineId: string) => {
|
|
28
|
+
success: boolean;
|
|
29
|
+
error?: string;
|
|
30
|
+
};
|
|
31
|
+
/** Add a connection between two lines */
|
|
32
|
+
addConnection: (connection: SceneConnectionInput) => {
|
|
33
|
+
success: boolean;
|
|
34
|
+
error?: string;
|
|
35
|
+
};
|
|
36
|
+
/** Update a connection's offset values */
|
|
37
|
+
updateConnection: (fromLineId: string, toLineId: string, updates: ConnectionUpdateInput) => {
|
|
38
|
+
success: boolean;
|
|
39
|
+
error?: string;
|
|
40
|
+
};
|
|
41
|
+
/** Remove a connection */
|
|
42
|
+
removeConnection: (fromLineId: string, toLineId: string) => {
|
|
43
|
+
success: boolean;
|
|
44
|
+
error?: string;
|
|
45
|
+
};
|
|
46
|
+
/** Clear all lines and curves */
|
|
47
|
+
clear: () => void;
|
|
48
|
+
/** Any validation errors from the last operation */
|
|
49
|
+
error: string | null;
|
|
50
|
+
/** @internal Load pre-computed scene data directly (for bulk loading) */
|
|
51
|
+
_loadScene: (lines: Line[], curves: Curve[]) => void;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Hook for managing scene configuration programmatically.
|
|
55
|
+
*
|
|
56
|
+
* This hook provides a simple API for creating and managing scenes without DSL.
|
|
57
|
+
* It's designed to be the backbone of the vehicle-path library.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* const { lines, curves, setScene, addLine } = useScene()
|
|
62
|
+
*
|
|
63
|
+
* // Set entire scene at once
|
|
64
|
+
* setScene({
|
|
65
|
+
* lines: [
|
|
66
|
+
* { id: 'line001', start: [100, 100], end: [500, 100] },
|
|
67
|
+
* { id: 'line002', start: [500, 100], end: [500, 400] }
|
|
68
|
+
* ],
|
|
69
|
+
* connections: [
|
|
70
|
+
* { from: 'line001', to: 'line002' }
|
|
71
|
+
* ]
|
|
72
|
+
* })
|
|
73
|
+
*
|
|
74
|
+
* // Or add lines incrementally
|
|
75
|
+
* addLine({ id: 'line003', start: [500, 400], end: [100, 400] })
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function useScene(): UseSceneResult;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { SceneLineInput, CoordinateInput, VehicleInput, VehicleUpdateInput, GotoInput, SimulationConfig, ConnectionUpdateInput } from '../../core/types/api';
|
|
2
|
+
import type { Line, Curve } from '../../core/types/geometry';
|
|
3
|
+
import type { Vehicle, GotoCommand } from '../../core/types/vehicle';
|
|
4
|
+
import type { TangentMode } from '../../core/types/config';
|
|
5
|
+
import type { VehicleEventEmitter } from '../../utils/event-emitter';
|
|
6
|
+
/**
|
|
7
|
+
* Warning types for edge case detection
|
|
8
|
+
*/
|
|
9
|
+
export interface SimulationWarning {
|
|
10
|
+
type: 'vehicle_on_removed_line' | 'movement_queue_cleared' | 'orphaned_connection' | 'dsl_parse_error';
|
|
11
|
+
message: string;
|
|
12
|
+
details?: {
|
|
13
|
+
lineId?: string;
|
|
14
|
+
vehicleId?: string;
|
|
15
|
+
vehicleIds?: string[];
|
|
16
|
+
connectionCount?: number;
|
|
17
|
+
errors?: string[];
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Result type with warnings for operations that may have side effects
|
|
22
|
+
*/
|
|
23
|
+
export interface SimulationResult {
|
|
24
|
+
success: boolean;
|
|
25
|
+
error?: string;
|
|
26
|
+
warnings?: SimulationWarning[];
|
|
27
|
+
}
|
|
28
|
+
export interface UseVehicleSimulationProps {
|
|
29
|
+
wheelbase: number;
|
|
30
|
+
tangentMode?: TangentMode;
|
|
31
|
+
eventEmitter?: VehicleEventEmitter;
|
|
32
|
+
}
|
|
33
|
+
export interface UseVehicleSimulationResult {
|
|
34
|
+
lines: Line[];
|
|
35
|
+
curves: Curve[];
|
|
36
|
+
vehicles: Vehicle[];
|
|
37
|
+
movingVehicles: Vehicle[];
|
|
38
|
+
vehicleQueues: Map<string, GotoCommand[]>;
|
|
39
|
+
error: string | null;
|
|
40
|
+
addLine: (line: SceneLineInput) => SimulationResult;
|
|
41
|
+
updateLine: (lineId: string, updates: {
|
|
42
|
+
start?: CoordinateInput;
|
|
43
|
+
end?: CoordinateInput;
|
|
44
|
+
}) => SimulationResult;
|
|
45
|
+
removeLine: (lineId: string) => SimulationResult;
|
|
46
|
+
clearScene: () => void;
|
|
47
|
+
connect: (fromLineId: string, toLineId: string, options?: {
|
|
48
|
+
fromOffset?: number;
|
|
49
|
+
fromIsPercentage?: boolean;
|
|
50
|
+
toOffset?: number;
|
|
51
|
+
toIsPercentage?: boolean;
|
|
52
|
+
}) => SimulationResult;
|
|
53
|
+
updateConnection: (fromLineId: string, toLineId: string, updates: ConnectionUpdateInput) => SimulationResult;
|
|
54
|
+
disconnect: (fromLineId: string, toLineId: string) => SimulationResult;
|
|
55
|
+
addVehicles: (input: VehicleInput | VehicleInput[]) => SimulationResult;
|
|
56
|
+
updateVehicle: (vehicleId: string, updates: VehicleUpdateInput) => SimulationResult;
|
|
57
|
+
removeVehicle: (vehicleId: string) => SimulationResult;
|
|
58
|
+
clearVehicles: () => void;
|
|
59
|
+
goto: (input: GotoInput) => SimulationResult;
|
|
60
|
+
clearQueue: (vehicleId?: string) => SimulationResult;
|
|
61
|
+
prepare: () => boolean;
|
|
62
|
+
tick: (distance: number) => boolean;
|
|
63
|
+
reset: () => void;
|
|
64
|
+
continueVehicle: (vehicleId: string) => boolean;
|
|
65
|
+
isMoving: () => boolean;
|
|
66
|
+
loadFromDSL: (dsl: string) => SimulationResult;
|
|
67
|
+
loadFromJSON: (config: SimulationConfig) => SimulationResult;
|
|
68
|
+
getVehiclesOnLine: (lineId: string) => Vehicle[];
|
|
69
|
+
hasVehiclesOnLine: (lineId: string) => boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Single entrypoint hook for vehicle path simulation.
|
|
73
|
+
*
|
|
74
|
+
* This hook provides a clean, DSL-like API that combines all functionality:
|
|
75
|
+
* scene management, vehicles, movement commands, and animation.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const sim = useVehicleSimulation({ wheelbase: 30, tangentMode: 'proportional-40' })
|
|
80
|
+
*
|
|
81
|
+
* // Scene (mirrors DSL: "line001 : (141, 513) -> (362, 121)")
|
|
82
|
+
* sim.addLine({ id: 'line001', start: [141, 513], end: [362, 121] })
|
|
83
|
+
* sim.updateLine('line001', { end: [400, 150] }) // for drag
|
|
84
|
+
* sim.removeLine('line001')
|
|
85
|
+
*
|
|
86
|
+
* // Connection (mirrors DSL: "line001 80% -> line002 20%")
|
|
87
|
+
* sim.connect('line001', 'line002', { fromOffset: 0.8, toOffset: 0.2 })
|
|
88
|
+
* sim.connect('line001', 'line002', { fromOffset: 150, fromIsPercentage: false, toOffset: 50, toIsPercentage: false })
|
|
89
|
+
* sim.disconnect('line001', 'line002')
|
|
90
|
+
*
|
|
91
|
+
* // Vehicle (mirrors DSL: "v1 start line001 0")
|
|
92
|
+
* sim.addVehicles({ id: 'v1', lineId: 'line001', position: 0 })
|
|
93
|
+
* sim.removeVehicle('v1')
|
|
94
|
+
*
|
|
95
|
+
* // Movement (mirrors DSL: "v1 goto line001 100%")
|
|
96
|
+
* sim.goto({ id: 'v1', lineId: 'line001', position: 1.0 })
|
|
97
|
+
* sim.goto({ id: 'v1', lineId: 'line001', position: 150, isPercentage: false })
|
|
98
|
+
*
|
|
99
|
+
* // Animation
|
|
100
|
+
* sim.prepare()
|
|
101
|
+
* sim.tick(5)
|
|
102
|
+
* sim.reset()
|
|
103
|
+
*
|
|
104
|
+
* // DSL Loading
|
|
105
|
+
* sim.loadFromDSL(\`
|
|
106
|
+
* line001 : (0, 0) -> (400, 0)
|
|
107
|
+
* v1 start line001 0%
|
|
108
|
+
* v1 goto line001 100%
|
|
109
|
+
* \`)
|
|
110
|
+
*
|
|
111
|
+
* // JSON Loading
|
|
112
|
+
* sim.loadFromJSON({
|
|
113
|
+
* lines: [
|
|
114
|
+
* { id: 'line001', start: [0, 0], end: [400, 0] },
|
|
115
|
+
* { id: 'line002', start: [400, 0], end: [400, 300] }
|
|
116
|
+
* ],
|
|
117
|
+
* connections: [{ from: 'line001', to: 'line002' }],
|
|
118
|
+
* vehicles: [{ id: 'v1', lineId: 'line001', position: 0 }],
|
|
119
|
+
* movements: [
|
|
120
|
+
* { vehicleId: 'v1', targetLineId: 'line001', targetPosition: 1.0 },
|
|
121
|
+
* { vehicleId: 'v1', targetLineId: 'line002', targetPosition: 1.0 }
|
|
122
|
+
* ]
|
|
123
|
+
* })
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
export declare function useVehicleSimulation({ wheelbase, tangentMode, eventEmitter }: UseVehicleSimulationProps): UseVehicleSimulationResult;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Line } from '../../core/types/geometry';
|
|
2
|
+
import type { Vehicle } from '../../core/types/vehicle';
|
|
3
|
+
import type { VehicleInput, VehicleUpdateInput } from '../../core/types/api';
|
|
4
|
+
export interface UseVehiclesProps {
|
|
5
|
+
lines: Line[];
|
|
6
|
+
wheelbase: number;
|
|
7
|
+
}
|
|
8
|
+
export interface UseVehiclesResult {
|
|
9
|
+
/** Current vehicles in the scene */
|
|
10
|
+
vehicles: Vehicle[];
|
|
11
|
+
/** Add one or more vehicles to the scene */
|
|
12
|
+
addVehicles: (input: VehicleInput | VehicleInput[]) => {
|
|
13
|
+
success: boolean;
|
|
14
|
+
errors?: string[];
|
|
15
|
+
};
|
|
16
|
+
/** Update a vehicle's position or line (only when idle) */
|
|
17
|
+
updateVehicle: (vehicleId: string, updates: VehicleUpdateInput) => {
|
|
18
|
+
success: boolean;
|
|
19
|
+
error?: string;
|
|
20
|
+
};
|
|
21
|
+
/** Remove a vehicle from the scene */
|
|
22
|
+
removeVehicle: (vehicleId: string) => {
|
|
23
|
+
success: boolean;
|
|
24
|
+
error?: string;
|
|
25
|
+
};
|
|
26
|
+
/** Clear all vehicles */
|
|
27
|
+
clear: () => void;
|
|
28
|
+
/** Any error from the last operation */
|
|
29
|
+
error: string | null;
|
|
30
|
+
/** @internal Load pre-computed vehicles directly (for bulk loading) */
|
|
31
|
+
_loadVehicles: (vehicles: Vehicle[]) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Hook for managing vehicles programmatically.
|
|
35
|
+
*
|
|
36
|
+
* This hook provides a simple API for adding and removing vehicles at runtime.
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const { vehicles, addVehicles, removeVehicle } = useVehicles({ lines, wheelbase: 30 })
|
|
41
|
+
*
|
|
42
|
+
* // Add single vehicle
|
|
43
|
+
* addVehicles({ id: 'v1', lineId: 'line001', position: 0.5 })
|
|
44
|
+
*
|
|
45
|
+
* // Add multiple vehicles
|
|
46
|
+
* addVehicles([
|
|
47
|
+
* { id: 'v1', lineId: 'line001', position: 0 },
|
|
48
|
+
* { id: 'v2', lineId: 'line002', position: 0.5 }
|
|
49
|
+
* ])
|
|
50
|
+
*
|
|
51
|
+
* // Remove a vehicle
|
|
52
|
+
* removeVehicle('v1')
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export declare function useVehicles({ lines, wheelbase }: UseVehiclesProps): UseVehiclesResult;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Layer - React hooks and providers
|
|
3
|
+
*
|
|
4
|
+
* This layer provides React-specific integrations for the vehicle-path library.
|
|
5
|
+
* Use this if you want the complete React experience.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import {
|
|
10
|
+
* useVehicleSimulation,
|
|
11
|
+
* useScene,
|
|
12
|
+
* useVehicles,
|
|
13
|
+
* VehicleEventProvider
|
|
14
|
+
* } from 'vehicle-path/react'
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export { useVehicleSimulation, type UseVehicleSimulationProps, type UseVehicleSimulationResult, type SimulationWarning, type SimulationResult } from './hooks/useVehicleSimulation';
|
|
18
|
+
/** Hook for managing scene (lines & curves) */
|
|
19
|
+
export { useScene, type UseSceneResult } from './hooks/useScene';
|
|
20
|
+
/** Hook for managing vehicles */
|
|
21
|
+
export { useVehicles, type UseVehiclesResult, type UseVehiclesProps } from './hooks/useVehicles';
|
|
22
|
+
/** Hook for managing the queue of movement commands */
|
|
23
|
+
export { useMovementQueue, type UseMovementQueueResult, type UseMovementQueueProps } from './hooks/useMovementQueue';
|
|
24
|
+
/** Hook for running animation (prepare, tick, reset) */
|
|
25
|
+
export { useAnimation, type UseAnimationProps } from './hooks/useAnimation';
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use `useMovementQueue` instead. This alias will be removed in a future version.
|
|
28
|
+
*/
|
|
29
|
+
export { useMovementQueue as useMovement } from './hooks/useMovementQueue';
|
|
30
|
+
export type { UseMovementQueueResult as UseMovementResult } from './hooks/useMovementQueue';
|
|
31
|
+
export type { UseMovementQueueProps as UseMovementProps } from './hooks/useMovementQueue';
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated Use `useAnimation` instead. This alias will be removed in a future version.
|
|
34
|
+
*/
|
|
35
|
+
export { useAnimation as useVehicleMovement } from './hooks/useAnimation';
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated Use `useVehicleSimulation.loadFromDSL()` instead. This hook will be removed in a future version.
|
|
38
|
+
*/
|
|
39
|
+
export { useSceneDefinition } from './dsl-hooks/useSceneDefinition';
|
|
40
|
+
/**
|
|
41
|
+
* @deprecated Use `useVehicleSimulation.loadFromDSL()` instead. This hook will be removed in a future version.
|
|
42
|
+
*/
|
|
43
|
+
export { useInitialMovement } from './dsl-hooks/useInitialMovement';
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated Use `useVehicleSimulation.loadFromDSL()` instead. This hook will be removed in a future version.
|
|
46
|
+
*/
|
|
47
|
+
export { useMovementSequence } from './dsl-hooks/useMovementSequence';
|
|
48
|
+
export { useVehicleEventEmitter, useCreateVehicleEventEmitter, useVehicleEvent, VehicleEventContext, VehicleEventProvider, type VehicleEventProviderProps } from './providers/useVehicleEvents';
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React, { type ReactNode } from 'react';
|
|
2
|
+
import { VehicleEventEmitter, type VehicleEventType, type VehicleEventCallback, type VehicleEventMap, type VehiclePositionUpdate } from '../../utils/event-emitter';
|
|
3
|
+
/**
|
|
4
|
+
* React context for VehicleEventEmitter
|
|
5
|
+
*/
|
|
6
|
+
export declare const VehicleEventContext: React.Context<VehicleEventEmitter | null>;
|
|
7
|
+
/**
|
|
8
|
+
* Hook to access the VehicleEventEmitter instance from context
|
|
9
|
+
* @returns VehicleEventEmitter instance
|
|
10
|
+
* @throws Error if used outside of VehicleEventProvider
|
|
11
|
+
*/
|
|
12
|
+
export declare function useVehicleEventEmitter(): VehicleEventEmitter;
|
|
13
|
+
/**
|
|
14
|
+
* Hook to create a new VehicleEventEmitter instance (for provider)
|
|
15
|
+
* @returns VehicleEventEmitter instance (stable reference)
|
|
16
|
+
*/
|
|
17
|
+
export declare function useCreateVehicleEventEmitter(): VehicleEventEmitter;
|
|
18
|
+
/**
|
|
19
|
+
* Hook to subscribe to a vehicle event with automatic cleanup
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* useVehicleEvent('commandComplete', (info) => {
|
|
24
|
+
* console.log(`Vehicle ${info.vehicleId} arrived!`)
|
|
25
|
+
* if (info.payload) {
|
|
26
|
+
* // Handle payload
|
|
27
|
+
* }
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function useVehicleEvent<K extends VehicleEventType>(event: K, callback: VehicleEventCallback<K>, deps?: React.DependencyList): void;
|
|
32
|
+
/**
|
|
33
|
+
* Props for VehicleEventProvider
|
|
34
|
+
*/
|
|
35
|
+
export interface VehicleEventProviderProps {
|
|
36
|
+
children: ReactNode;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Provider component for VehicleEventEmitter
|
|
40
|
+
*
|
|
41
|
+
* This simplifies the setup from:
|
|
42
|
+
* ```typescript
|
|
43
|
+
* const emitter = useCreateVehicleEventEmitter()
|
|
44
|
+
* <VehicleEventContext.Provider value={emitter}>
|
|
45
|
+
* <App />
|
|
46
|
+
* </VehicleEventContext.Provider>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* To just:
|
|
50
|
+
* ```typescript
|
|
51
|
+
* <VehicleEventProvider>
|
|
52
|
+
* <App />
|
|
53
|
+
* </VehicleEventProvider>
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { VehicleEventProvider, useVehicleEvent } from 'vehicle-path'
|
|
59
|
+
*
|
|
60
|
+
* function App() {
|
|
61
|
+
* return (
|
|
62
|
+
* <VehicleEventProvider>
|
|
63
|
+
* <MyComponent />
|
|
64
|
+
* </VehicleEventProvider>
|
|
65
|
+
* )
|
|
66
|
+
* }
|
|
67
|
+
*
|
|
68
|
+
* function MyComponent() {
|
|
69
|
+
* useVehicleEvent('commandComplete', (info) => {
|
|
70
|
+
* console.log(`Vehicle ${info.vehicleId} arrived!`)
|
|
71
|
+
* })
|
|
72
|
+
*
|
|
73
|
+
* return <div>...</div>
|
|
74
|
+
* }
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function VehicleEventProvider({ children }: VehicleEventProviderProps): React.ReactElement;
|
|
78
|
+
export type { VehicleEventEmitter, VehicleEventType, VehicleEventCallback, VehicleEventMap, VehiclePositionUpdate };
|
package/dist/react.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./useVehicleEvents-CBymulau.cjs");exports.VehicleEventContext=e.VehicleEventContext;exports.VehicleEventProvider=e.VehicleEventProvider;exports.useAnimation=e.useAnimation;exports.useCreateVehicleEventEmitter=e.useCreateVehicleEventEmitter;exports.useInitialMovement=e.useInitialMovement;exports.useMovement=e.useMovementQueue;exports.useMovementQueue=e.useMovementQueue;exports.useMovementSequence=e.useMovementSequence;exports.useScene=e.useScene;exports.useSceneDefinition=e.useSceneDefinition;exports.useVehicleEvent=e.useVehicleEvent;exports.useVehicleEventEmitter=e.useVehicleEventEmitter;exports.useVehicleMovement=e.useAnimation;exports.useVehicleSimulation=e.useVehicleSimulation;exports.useVehicles=e.useVehicles;
|
package/dist/react.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { V as t, a as i, u as a, b as n, c as u, d as c, d as o, e as v, f as l, g as m, h, i as V, u as r, j as E, k as M } from "./useVehicleEvents-B2JQFNjc.js";
|
|
2
|
+
export {
|
|
3
|
+
t as VehicleEventContext,
|
|
4
|
+
i as VehicleEventProvider,
|
|
5
|
+
a as useAnimation,
|
|
6
|
+
n as useCreateVehicleEventEmitter,
|
|
7
|
+
u as useInitialMovement,
|
|
8
|
+
c as useMovement,
|
|
9
|
+
o as useMovementQueue,
|
|
10
|
+
v as useMovementSequence,
|
|
11
|
+
l as useScene,
|
|
12
|
+
m as useSceneDefinition,
|
|
13
|
+
h as useVehicleEvent,
|
|
14
|
+
V as useVehicleEventEmitter,
|
|
15
|
+
r as useVehicleMovement,
|
|
16
|
+
E as useVehicleSimulation,
|
|
17
|
+
M as useVehicles
|
|
18
|
+
};
|