vehicle-path2 1.0.14 → 2.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.
Files changed (40) hide show
  1. package/README.md +168 -168
  2. package/dist/core/algorithms/pathFinding.d.ts +2 -2
  3. package/dist/core/algorithms/vehicleMovement.d.ts +29 -20
  4. package/dist/core/engine.d.ts +160 -0
  5. package/dist/core/index.d.ts +3 -2
  6. package/dist/core/types/api.d.ts +9 -0
  7. package/dist/core/types/movement.d.ts +2 -3
  8. package/dist/core/types/vehicle.d.ts +4 -2
  9. package/dist/core.cjs +1 -1
  10. package/dist/core.js +33 -541
  11. package/dist/index.d.ts +4 -34
  12. package/dist/utils/event-emitter.d.ts +4 -6
  13. package/dist/vehicle-path.cjs +1 -1
  14. package/dist/vehicle-path.js +729 -59
  15. package/package.json +83 -103
  16. package/dist/animation-loop-bZEm2pMN.js +0 -37
  17. package/dist/animation-loop-fC2LjxCd.cjs +0 -1
  18. package/dist/react/dsl-hooks/useInitialMovement.d.ts +0 -24
  19. package/dist/react/dsl-hooks/useMovementSequence.d.ts +0 -27
  20. package/dist/react/dsl-hooks/useSceneDefinition.d.ts +0 -22
  21. package/dist/react/hooks/useAnimation.d.ts +0 -47
  22. package/dist/react/hooks/useMovementQueue.d.ts +0 -53
  23. package/dist/react/hooks/useScene.d.ts +0 -78
  24. package/dist/react/hooks/useVehicleSimulation.d.ts +0 -128
  25. package/dist/react/hooks/useVehicles.d.ts +0 -55
  26. package/dist/react/index.d.ts +0 -48
  27. package/dist/react/providers/useVehicleEvents.d.ts +0 -78
  28. package/dist/react.cjs +0 -1
  29. package/dist/react.js +0 -18
  30. package/dist/useVehicleEvents-BZVmIugl.cjs +0 -3
  31. package/dist/useVehicleEvents-CabztfQ4.js +0 -940
  32. package/dist/utils/animation-loop.d.ts +0 -105
  33. package/dist/utils/dsl-parser.d.ts +0 -151
  34. package/dist/utils/index.d.ts +0 -15
  35. package/dist/utils/type-converters.d.ts +0 -40
  36. package/dist/utils/vehicle-helpers.d.ts +0 -8
  37. package/dist/utils.cjs +0 -1
  38. package/dist/utils.js +0 -17
  39. package/dist/vehicle-helpers-BgD4BTAJ.js +0 -275
  40. package/dist/vehicle-helpers-DrnYWjm3.cjs +0 -7
package/package.json CHANGED
@@ -1,103 +1,83 @@
1
- {
2
- "name": "vehicle-path2",
3
- "version": "1.0.14",
4
- "description": "Vehicle motion simulator library for dual-axle vehicle movement along paths composed of lines and Bezier curves",
5
- "type": "module",
6
- "main": "./dist/vehicle-path.cjs",
7
- "module": "./dist/vehicle-path.js",
8
- "types": "./dist/index.d.ts",
9
- "exports": {
10
- ".": {
11
- "import": {
12
- "types": "./dist/index.d.ts",
13
- "default": "./dist/vehicle-path.js"
14
- },
15
- "require": {
16
- "types": "./dist/index.d.cts",
17
- "default": "./dist/vehicle-path.cjs"
18
- }
19
- },
20
- "./core": {
21
- "import": {
22
- "types": "./dist/core/index.d.ts",
23
- "default": "./dist/core.js"
24
- },
25
- "require": {
26
- "types": "./dist/core/index.d.cts",
27
- "default": "./dist/core.cjs"
28
- }
29
- },
30
- "./utils": {
31
- "import": {
32
- "types": "./dist/utils/index.d.ts",
33
- "default": "./dist/utils.js"
34
- },
35
- "require": {
36
- "types": "./dist/utils/index.d.cts",
37
- "default": "./dist/utils.cjs"
38
- }
39
- },
40
- "./react": {
41
- "import": {
42
- "types": "./dist/react/index.d.ts",
43
- "default": "./dist/react.js"
44
- },
45
- "require": {
46
- "types": "./dist/react/index.d.cts",
47
- "default": "./dist/react.cjs"
48
- }
49
- }
50
- },
51
- "files": [
52
- "dist"
53
- ],
54
- "scripts": {
55
- "dev": "vite build --watch",
56
- "build": "vite build && tsc -p tsconfig.build.json",
57
- "prepublishOnly": "npm run build",
58
- "lint": "eslint .",
59
- "test": "vitest",
60
- "test:ui": "vitest --ui",
61
- "test:coverage": "vitest --coverage"
62
- },
63
- "peerDependencies": {
64
- "react": "^18.0.0 || ^19.0.0",
65
- "react-dom": "^18.0.0 || ^19.0.0"
66
- },
67
- "devDependencies": {
68
- "@eslint/js": "^9.39.1",
69
- "@testing-library/react": "^16.3.1",
70
- "@types/node": "^24.10.1",
71
- "@types/react": "^19.2.5",
72
- "@types/react-dom": "^19.2.3",
73
- "@vitejs/plugin-react": "^5.1.1",
74
- "@vitest/coverage-v8": "^4.0.16",
75
- "@vitest/ui": "^4.0.16",
76
- "eslint": "^9.39.1",
77
- "eslint-plugin-react-hooks": "^7.0.1",
78
- "eslint-plugin-react-refresh": "^0.4.24",
79
- "globals": "^16.5.0",
80
- "happy-dom": "^20.0.11",
81
- "react": "^19.2.0",
82
- "react-dom": "^19.2.0",
83
- "typescript": "~5.9.3",
84
- "typescript-eslint": "^8.46.4",
85
- "vite": "^7.2.4",
86
- "vitest": "^4.0.16"
87
- },
88
- "keywords": [
89
- "vehicle",
90
- "path",
91
- "bezier",
92
- "simulation",
93
- "animation",
94
- "dual-axle",
95
- "react"
96
- ],
97
- "author": "",
98
- "license": "MIT",
99
- "repository": {
100
- "type": "git",
101
- "url": ""
102
- }
103
- }
1
+ {
2
+ "name": "vehicle-path2",
3
+ "version": "2.0.0",
4
+ "description": "Vehicle motion simulator library for dual-axle vehicle movement along paths composed of lines and Bezier curves",
5
+ "type": "module",
6
+ "main": "./dist/vehicle-path.cjs",
7
+ "module": "./dist/vehicle-path.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/vehicle-path.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/vehicle-path.cjs"
18
+ }
19
+ },
20
+ "./core": {
21
+ "import": {
22
+ "types": "./dist/core/index.d.ts",
23
+ "default": "./dist/core.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/core/index.d.cts",
27
+ "default": "./dist/core.cjs"
28
+ }
29
+ }
30
+ },
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "scripts": {
35
+ "dev": "vite build --watch",
36
+ "build": "vite build && tsc -p tsconfig.build.json",
37
+ "prepublishOnly": "npm run build",
38
+ "lint": "eslint .",
39
+ "test": "vitest",
40
+ "test:ui": "vitest --ui",
41
+ "test:coverage": "vitest --coverage"
42
+ },
43
+ "peerDependencies": {
44
+ "react": "^18.0.0 || ^19.0.0",
45
+ "react-dom": "^18.0.0 || ^19.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "@eslint/js": "^9.39.1",
49
+ "@testing-library/react": "^16.3.1",
50
+ "@types/node": "^24.10.1",
51
+ "@types/react": "^19.2.5",
52
+ "@types/react-dom": "^19.2.3",
53
+ "@vitejs/plugin-react": "^5.1.1",
54
+ "@vitest/coverage-v8": "^4.0.16",
55
+ "@vitest/ui": "^4.0.16",
56
+ "eslint": "^9.39.1",
57
+ "eslint-plugin-react-hooks": "^7.0.1",
58
+ "eslint-plugin-react-refresh": "^0.4.24",
59
+ "globals": "^16.5.0",
60
+ "happy-dom": "^20.0.11",
61
+ "react": "^19.2.0",
62
+ "react-dom": "^19.2.0",
63
+ "typescript": "~5.9.3",
64
+ "typescript-eslint": "^8.46.4",
65
+ "vite": "^7.2.4",
66
+ "vitest": "^4.0.16"
67
+ },
68
+ "keywords": [
69
+ "vehicle",
70
+ "path",
71
+ "bezier",
72
+ "simulation",
73
+ "animation",
74
+ "dual-axle",
75
+ "react"
76
+ ],
77
+ "author": "",
78
+ "license": "MIT",
79
+ "repository": {
80
+ "type": "git",
81
+ "url": ""
82
+ }
83
+ }
@@ -1,37 +0,0 @@
1
- import { useRef as p, useEffect as d } from "react";
2
- function A(o) {
3
- const { onTick: t, onComplete: a, onStart: i, onPause: c, onStop: f } = o;
4
- let n = null, u = null, e = !1, l = !1;
5
- const s = (r) => {
6
- if (!e) return;
7
- const m = u !== null ? r - u : 0;
8
- if (u = r, t(m) === !1) {
9
- e = !1, n = null, u = null, a?.();
10
- return;
11
- }
12
- n = requestAnimationFrame(s);
13
- };
14
- return {
15
- start: () => {
16
- e || (e = !0, l = !1, u = null, i?.(), n = requestAnimationFrame(s));
17
- },
18
- pause: () => {
19
- !e || l || (e = !1, l = !0, n !== null && (cancelAnimationFrame(n), n = null), c?.());
20
- },
21
- stop: () => {
22
- e = !1, l = !1, u = null, n !== null && (cancelAnimationFrame(n), n = null), f?.();
23
- },
24
- isRunning: () => e,
25
- isPaused: () => l
26
- };
27
- }
28
- function q(o) {
29
- const t = p(null);
30
- return t.current || (t.current = A(o)), d(() => () => {
31
- t.current?.stop();
32
- }, []), t.current;
33
- }
34
- export {
35
- A as c,
36
- q as u
37
- };
@@ -1 +0,0 @@
1
- "use strict";const i=require("react");function a(s){const{onTick:t,onComplete:c,onStart:f,onPause:m,onStop:p}=s;let n=null,o=null,e=!1,u=!1;const l=r=>{if(!e)return;const A=o!==null?r-o:0;if(o=r,t(A)===!1){e=!1,n=null,o=null,c?.();return}n=requestAnimationFrame(l)};return{start:()=>{e||(e=!0,u=!1,o=null,f?.(),n=requestAnimationFrame(l))},pause:()=>{!e||u||(e=!1,u=!0,n!==null&&(cancelAnimationFrame(n),n=null),m?.())},stop:()=>{e=!1,u=!1,o=null,n!==null&&(cancelAnimationFrame(n),n=null),p?.()},isRunning:()=>e,isPaused:()=>u}}function d(s){const t=i.useRef(null);return t.current||(t.current=a(s)),i.useEffect(()=>()=>{t.current?.stop()},[]),t.current}exports.createAnimationLoop=a;exports.useAnimationLoop=d;
@@ -1,24 +0,0 @@
1
- import type { Line } from '../../core/types/geometry';
2
- interface UseInitialMovementProps {
3
- lines: Line[];
4
- wheelbase: number;
5
- }
6
- /**
7
- * DSL wrapper for useVehicles hook.
8
- *
9
- * This hook provides text-based vehicle initialization that internally uses
10
- * the programmatic useVehicles API as the single source of truth.
11
- *
12
- * @deprecated Use `useVehicleSimulation.loadFromDSL()` instead. This hook will be removed in a future version.
13
- * The new unified hook provides a simpler API for loading DSL definitions that includes
14
- * scene, vehicles, and movements in a single call.
15
- */
16
- export declare function useInitialMovement({ lines, wheelbase }: UseInitialMovementProps): {
17
- vehicles: import("../..").Vehicle[];
18
- initialMovementText: string;
19
- movementError: string | null;
20
- isDebouncing: boolean;
21
- debounceKey: number;
22
- setInitialMovementText: (text: string) => void;
23
- };
24
- export {};
@@ -1,27 +0,0 @@
1
- import type { Line } from '../../core/types/geometry';
2
- import type { Vehicle } from '../../core/types/vehicle';
3
- import { type MovementCommand } from '../../utils/dsl-parser';
4
- interface UseMovementSequenceProps {
5
- lines: Line[];
6
- vehicles: Vehicle[];
7
- }
8
- /**
9
- * DSL wrapper for useMovementQueue hook.
10
- *
11
- * This hook provides text-based movement commands that internally uses
12
- * the programmatic useMovementQueue API as the single source of truth.
13
- *
14
- * @deprecated Use `useVehicleSimulation.loadFromDSL()` instead. This hook will be removed in a future version.
15
- * The new unified hook provides a simpler API for loading DSL definitions that includes
16
- * scene, vehicles, and movements in a single call.
17
- */
18
- export declare function useMovementSequence({ lines, vehicles }: UseMovementSequenceProps): {
19
- movementSequenceText: string;
20
- gotoCommands: MovementCommand[];
21
- vehicleQueues: Map<string, import("../..").GotoCommand[]>;
22
- sequenceError: string | null;
23
- isDebouncing: boolean;
24
- debounceKey: number;
25
- setMovementSequenceText: (text: string) => void;
26
- };
27
- export {};
@@ -1,22 +0,0 @@
1
- import type { Line, Curve } from '../../core/types/geometry';
2
- /**
3
- * DSL wrapper for useScene hook.
4
- *
5
- * This hook provides text-based scene definition that internally uses
6
- * the programmatic useScene API as the single source of truth.
7
- *
8
- * @deprecated Use `useVehicleSimulation.loadFromDSL()` instead. This hook will be removed in a future version.
9
- * The new unified hook provides a simpler API for loading DSL definitions that includes
10
- * scene, vehicles, and movements in a single call.
11
- */
12
- export declare function useSceneDefinition(): {
13
- lines: Line[];
14
- curves: Curve[];
15
- sceneDefinitionText: string;
16
- sceneError: string | null;
17
- isDebouncing: boolean;
18
- debounceKey: number;
19
- setLines: (newLines: Line[] | ((prev: Line[]) => Line[])) => void;
20
- setCurves: (newCurves: Curve[] | ((prev: Curve[]) => Curve[])) => void;
21
- setSceneDefinitionText: (text: string) => void;
22
- };
@@ -1,47 +0,0 @@
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
- /** Get current queues immediately (bypasses React state timing) */
10
- getVehicleQueues?: () => Map<string, GotoCommand[]>;
11
- wheelbase: number;
12
- tangentMode: TangentMode;
13
- curves: import('../../core/types/geometry').Curve[];
14
- eventEmitter?: VehicleEventEmitter;
15
- }
16
- /**
17
- * Hook for running vehicle animation/simulation.
18
- *
19
- * This hook handles the actual movement of vehicles along paths.
20
- * Call prepare() before starting, then tick() in your animation loop.
21
- *
22
- * @example
23
- * ```typescript
24
- * const { movingVehicles, prepare, tick, reset, isMoving } = useAnimation({
25
- * vehicles, lines, vehicleQueues, wheelbase: 30, tangentMode: 'proportional-40', curves
26
- * })
27
- *
28
- * // Start animation
29
- * prepare()
30
- *
31
- * // In animation loop
32
- * const animate = () => {
33
- * if (tick(5)) requestAnimationFrame(animate)
34
- * }
35
- * ```
36
- */
37
- export declare function useAnimation({ vehicles, lines, vehicleQueues, getVehicleQueues, wheelbase, tangentMode, curves, eventEmitter }: UseAnimationProps): {
38
- movingVehicles: Vehicle[];
39
- getMovingVehicles: () => Vehicle[];
40
- prepare: () => boolean;
41
- tick: (distance: number) => boolean;
42
- reset: () => void;
43
- resetVehicle: (vehicleId: string) => void;
44
- continueVehicle: (vehicleId: string) => boolean;
45
- isMoving: () => boolean;
46
- isPrepared: boolean;
47
- };
@@ -1,53 +0,0 @@
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
- /** Get current queues immediately (bypasses React state timing) */
13
- getVehicleQueues: () => Map<string, GotoCommand[]>;
14
- /** Queue a movement command for a vehicle */
15
- queueMovement: (vehicleId: string, input: GotoCommandInput) => {
16
- success: boolean;
17
- error?: string;
18
- };
19
- /** Clear the queue for a specific vehicle or all vehicles */
20
- clearQueue: (vehicleId?: string) => {
21
- success: boolean;
22
- error?: string;
23
- };
24
- /** Any error from the last operation */
25
- error: string | null;
26
- /** @internal Load pre-computed queues directly (for bulk loading) */
27
- _loadQueues: (queues: Map<string, GotoCommand[]>) => void;
28
- }
29
- /**
30
- * Hook for managing the queue of movement commands.
31
- *
32
- * This hook provides a simple API for queuing goto commands at runtime.
33
- *
34
- * @example
35
- * ```typescript
36
- * const { vehicleQueues, queueMovement, clearQueue } = useMovementQueue({ vehicles, lines, curves })
37
- *
38
- * // Queue movements
39
- * queueMovement('v1', { targetLineId: 'line002', targetPosition: 0.5 })
40
- * queueMovement('v1', {
41
- * targetLineId: 'line003',
42
- * targetPosition: 1.0,
43
- * payload: { orderId: '123' }
44
- * })
45
- *
46
- * // Clear queue for a specific vehicle
47
- * clearQueue('v1')
48
- *
49
- * // Clear all queues
50
- * clearQueue()
51
- * ```
52
- */
53
- export declare function useMovementQueue({ vehicles, lines }: UseMovementQueueProps): UseMovementQueueResult;
@@ -1,78 +0,0 @@
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;
@@ -1,128 +0,0 @@
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
- getMovingVehicles: () => Vehicle[];
39
- vehicleQueues: Map<string, GotoCommand[]>;
40
- error: string | null;
41
- addLine: (line: SceneLineInput) => SimulationResult;
42
- updateLine: (lineId: string, updates: {
43
- start?: CoordinateInput;
44
- end?: CoordinateInput;
45
- }) => SimulationResult;
46
- removeLine: (lineId: string) => SimulationResult;
47
- clearScene: () => void;
48
- connect: (fromLineId: string, toLineId: string, options?: {
49
- fromOffset?: number;
50
- fromIsPercentage?: boolean;
51
- toOffset?: number;
52
- toIsPercentage?: boolean;
53
- }) => SimulationResult;
54
- updateConnection: (fromLineId: string, toLineId: string, updates: ConnectionUpdateInput) => SimulationResult;
55
- disconnect: (fromLineId: string, toLineId: string) => SimulationResult;
56
- addVehicles: (input: VehicleInput | VehicleInput[]) => SimulationResult;
57
- updateVehicle: (vehicleId: string, updates: VehicleUpdateInput) => SimulationResult;
58
- removeVehicle: (vehicleId: string) => SimulationResult;
59
- clearVehicles: () => void;
60
- goto: (input: GotoInput) => SimulationResult;
61
- clearQueue: (vehicleId?: string) => SimulationResult;
62
- prepare: () => boolean;
63
- tick: (distance: number) => boolean;
64
- reset: () => void;
65
- resetVehicle: (vehicleId: string) => void;
66
- continueVehicle: (vehicleId: string) => boolean;
67
- isMoving: () => boolean;
68
- loadFromDSL: (dsl: string) => SimulationResult;
69
- loadFromJSON: (config: SimulationConfig) => SimulationResult;
70
- getVehiclesOnLine: (lineId: string) => Vehicle[];
71
- hasVehiclesOnLine: (lineId: string) => boolean;
72
- }
73
- /**
74
- * Single entrypoint hook for vehicle path simulation.
75
- *
76
- * This hook provides a clean, DSL-like API that combines all functionality:
77
- * scene management, vehicles, movement commands, and animation.
78
- *
79
- * @example
80
- * ```typescript
81
- * const sim = useVehicleSimulation({ wheelbase: 30, tangentMode: 'proportional-40' })
82
- *
83
- * // Scene (mirrors DSL: "line001 : (141, 513) -> (362, 121)")
84
- * sim.addLine({ id: 'line001', start: [141, 513], end: [362, 121] })
85
- * sim.updateLine('line001', { end: [400, 150] }) // for drag
86
- * sim.removeLine('line001')
87
- *
88
- * // Connection (mirrors DSL: "line001 80% -> line002 20%")
89
- * sim.connect('line001', 'line002', { fromOffset: 0.8, toOffset: 0.2 })
90
- * sim.connect('line001', 'line002', { fromOffset: 150, fromIsPercentage: false, toOffset: 50, toIsPercentage: false })
91
- * sim.disconnect('line001', 'line002')
92
- *
93
- * // Vehicle (mirrors DSL: "v1 start line001 0")
94
- * sim.addVehicles({ id: 'v1', lineId: 'line001', position: 0 })
95
- * sim.removeVehicle('v1')
96
- *
97
- * // Movement (mirrors DSL: "v1 goto line001 100%")
98
- * sim.goto({ id: 'v1', lineId: 'line001', position: 1.0 })
99
- * sim.goto({ id: 'v1', lineId: 'line001', position: 150, isPercentage: false })
100
- *
101
- * // Animation
102
- * sim.prepare()
103
- * sim.tick(5)
104
- * sim.reset()
105
- *
106
- * // DSL Loading
107
- * sim.loadFromDSL(\`
108
- * line001 : (0, 0) -> (400, 0)
109
- * v1 start line001 0%
110
- * v1 goto line001 100%
111
- * \`)
112
- *
113
- * // JSON Loading
114
- * sim.loadFromJSON({
115
- * lines: [
116
- * { id: 'line001', start: [0, 0], end: [400, 0] },
117
- * { id: 'line002', start: [400, 0], end: [400, 300] }
118
- * ],
119
- * connections: [{ from: 'line001', to: 'line002' }],
120
- * vehicles: [{ id: 'v1', lineId: 'line001', position: 0 }],
121
- * movements: [
122
- * { vehicleId: 'v1', targetLineId: 'line001', targetPosition: 1.0 },
123
- * { vehicleId: 'v1', targetLineId: 'line002', targetPosition: 1.0 }
124
- * ]
125
- * })
126
- * ```
127
- */
128
- export declare function useVehicleSimulation({ wheelbase, tangentMode, eventEmitter }: UseVehicleSimulationProps): UseVehicleSimulationResult;
@@ -1,55 +0,0 @@
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;