vehicle-path2 1.0.5 → 1.0.7
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/dist/react/hooks/useAnimation.d.ts +1 -0
- package/dist/react/hooks/useVehicleSimulation.d.ts +1 -0
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/useVehicleEvents-CCCiLoAw.cjs +3 -0
- package/dist/useVehicleEvents-DcNmJGRn.js +941 -0
- package/dist/vehicle-path.cjs +1 -1
- package/dist/vehicle-path.js +1 -1
- package/package.json +1 -1
- package/dist/useVehicleEvents-B1_CZyWq.cjs +0 -3
- package/dist/useVehicleEvents-Cv-YgfXB.js +0 -931
|
@@ -0,0 +1,941 @@
|
|
|
1
|
+
import { useState as j, useCallback as P, useRef as A, useMemo as G, useEffect as K, createContext as ae, useContext as ue } from "react";
|
|
2
|
+
import { distance as le, initializeAllVehicles as ee, buildGraph as fe, updateAxlePosition as te, handleArrival as de, prepareCommandPath as B, calculateFrontAxlePosition as re, initializeMovingVehicle as me, createInitialMovementState as ge } from "./core.js";
|
|
3
|
+
import { v as N, p as he, a as W, f as ve, h as pe, e as Pe, V as se } from "./vehicle-helpers-BXX3GPzk.js";
|
|
4
|
+
import { jsx as Ie } from "react/jsx-runtime";
|
|
5
|
+
function J(r) {
|
|
6
|
+
return Array.isArray(r) ? { x: r[0], y: r[1] } : r;
|
|
7
|
+
}
|
|
8
|
+
function H(r) {
|
|
9
|
+
return {
|
|
10
|
+
id: r.id,
|
|
11
|
+
start: J(r.start),
|
|
12
|
+
end: J(r.end)
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function U(r) {
|
|
16
|
+
const c = r.fromIsPercentage !== !1, M = r.toIsPercentage !== !1;
|
|
17
|
+
return {
|
|
18
|
+
fromLineId: r.from,
|
|
19
|
+
toLineId: r.to,
|
|
20
|
+
// No conversion needed - internal format is now 0-1 (same as API)
|
|
21
|
+
fromOffset: r.fromPosition,
|
|
22
|
+
fromIsPercentage: r.fromPosition !== void 0 ? c : void 0,
|
|
23
|
+
toOffset: r.toPosition,
|
|
24
|
+
toIsPercentage: r.toPosition !== void 0 ? M : void 0
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function Y(r) {
|
|
28
|
+
const c = r.position ?? 0, M = r.isPercentage !== !1;
|
|
29
|
+
return {
|
|
30
|
+
vehicleId: r.id,
|
|
31
|
+
lineId: r.lineId,
|
|
32
|
+
// No conversion needed - internal format is now 0-1 (same as API)
|
|
33
|
+
offset: c,
|
|
34
|
+
isPercentage: M
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
function Z(r) {
|
|
38
|
+
const c = r.isPercentage !== !1, M = r.targetPosition ?? 1;
|
|
39
|
+
return {
|
|
40
|
+
vehicleId: r.vehicleId,
|
|
41
|
+
targetLineId: r.targetLineId,
|
|
42
|
+
// No conversion needed - internal format is now 0-1 (same as API)
|
|
43
|
+
targetOffset: M,
|
|
44
|
+
isPercentage: c,
|
|
45
|
+
awaitConfirmation: r.wait,
|
|
46
|
+
payload: r.payload
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function xe(r) {
|
|
50
|
+
const c = [], M = /* @__PURE__ */ new Set();
|
|
51
|
+
for (const s of r.lines)
|
|
52
|
+
M.has(s.id) && c.push(`Duplicate line ID: ${s.id}`), M.add(s.id);
|
|
53
|
+
if (r.connections)
|
|
54
|
+
for (const s of r.connections) {
|
|
55
|
+
M.has(s.from) || c.push(`Connection references non-existent line: ${s.from}`), M.has(s.to) || c.push(`Connection references non-existent line: ${s.to}`);
|
|
56
|
+
const d = s.fromIsPercentage !== !1, t = s.toIsPercentage !== !1;
|
|
57
|
+
!d && s.fromPosition === void 0 && c.push("fromPosition is required when fromIsPercentage is false"), !t && s.toPosition === void 0 && c.push("toPosition is required when toIsPercentage is false"), s.fromPosition !== void 0 && (d && (s.fromPosition < 0 || s.fromPosition > 1) ? c.push(`Invalid fromPosition: ${s.fromPosition} (must be 0-1 for percentage)`) : !d && s.fromPosition < 0 && c.push(`Invalid fromPosition: ${s.fromPosition} (must be >= 0 for absolute distance)`)), s.toPosition !== void 0 && (t && (s.toPosition < 0 || s.toPosition > 1) ? c.push(`Invalid toPosition: ${s.toPosition} (must be 0-1 for percentage)`) : !t && s.toPosition < 0 && c.push(`Invalid toPosition: ${s.toPosition} (must be >= 0 for absolute distance)`));
|
|
58
|
+
}
|
|
59
|
+
return { valid: c.length === 0, errors: c };
|
|
60
|
+
}
|
|
61
|
+
function ne() {
|
|
62
|
+
const [r, c] = j([]), [M, s] = j([]), [d, t] = j(null), l = P((n, g) => {
|
|
63
|
+
c(n), s(g), t(null);
|
|
64
|
+
}, []), I = P((n) => {
|
|
65
|
+
const g = xe(n);
|
|
66
|
+
if (!g.valid)
|
|
67
|
+
return t(g.errors.join("; ")), { success: !1, errors: g.errors };
|
|
68
|
+
const u = n.lines.map(H), m = n.connections?.map(U) || [];
|
|
69
|
+
return l(u, m), { success: !0 };
|
|
70
|
+
}, [l]), T = P((n) => {
|
|
71
|
+
if (r.some((u) => u.id === n.id)) {
|
|
72
|
+
const u = `Line with ID '${n.id}' already exists`;
|
|
73
|
+
return t(u), { success: !1, error: u };
|
|
74
|
+
}
|
|
75
|
+
return c((u) => [...u, H(n)]), t(null), { success: !0 };
|
|
76
|
+
}, [r]), q = P((n, g) => {
|
|
77
|
+
if (r.findIndex((m) => m.id === n) === -1) {
|
|
78
|
+
const m = `Line with ID '${n}' not found`;
|
|
79
|
+
return t(m), { success: !1, error: m };
|
|
80
|
+
}
|
|
81
|
+
return c((m) => m.map((S) => S.id !== n ? S : {
|
|
82
|
+
...S,
|
|
83
|
+
start: g.start ? J(g.start) : S.start,
|
|
84
|
+
end: g.end ? J(g.end) : S.end
|
|
85
|
+
})), t(null), { success: !0 };
|
|
86
|
+
}, [r]), y = P((n) => {
|
|
87
|
+
if (!r.some((u) => u.id === n)) {
|
|
88
|
+
const u = `Line with ID '${n}' not found`;
|
|
89
|
+
return t(u), { success: !1, error: u };
|
|
90
|
+
}
|
|
91
|
+
return c((u) => u.filter((m) => m.id !== n)), s((u) => u.filter((m) => m.fromLineId !== n && m.toLineId !== n)), t(null), { success: !0 };
|
|
92
|
+
}, [r]), C = P((n) => {
|
|
93
|
+
const g = r.some((f) => f.id === n.from), u = r.some((f) => f.id === n.to);
|
|
94
|
+
if (!g) {
|
|
95
|
+
const f = `Line '${n.from}' not found`;
|
|
96
|
+
return t(f), { success: !1, error: f };
|
|
97
|
+
}
|
|
98
|
+
if (!u) {
|
|
99
|
+
const f = `Line '${n.to}' not found`;
|
|
100
|
+
return t(f), { success: !1, error: f };
|
|
101
|
+
}
|
|
102
|
+
const m = n.fromIsPercentage !== !1, S = n.toIsPercentage !== !1;
|
|
103
|
+
if (!m && n.fromPosition === void 0) {
|
|
104
|
+
const f = "fromPosition is required when fromIsPercentage is false";
|
|
105
|
+
return t(f), { success: !1, error: f };
|
|
106
|
+
}
|
|
107
|
+
if (!S && n.toPosition === void 0) {
|
|
108
|
+
const f = "toPosition is required when toIsPercentage is false";
|
|
109
|
+
return t(f), { success: !1, error: f };
|
|
110
|
+
}
|
|
111
|
+
if (M.some((f) => f.fromLineId === n.from && f.toLineId === n.to)) {
|
|
112
|
+
const f = `Connection from '${n.from}' to '${n.to}' already exists`;
|
|
113
|
+
return t(f), { success: !1, error: f };
|
|
114
|
+
}
|
|
115
|
+
return s((f) => [...f, U(n)]), t(null), { success: !0 };
|
|
116
|
+
}, [r, M]), v = P((n, g, u) => {
|
|
117
|
+
const m = M.findIndex((e) => e.fromLineId === n && e.toLineId === g);
|
|
118
|
+
if (m === -1) {
|
|
119
|
+
const e = `Connection from '${n}' to '${g}' not found`;
|
|
120
|
+
return t(e), { success: !1, error: e };
|
|
121
|
+
}
|
|
122
|
+
const S = M[m], _ = u.fromIsPercentage ?? S.fromIsPercentage, f = u.toIsPercentage ?? S.toIsPercentage;
|
|
123
|
+
let D;
|
|
124
|
+
u.fromOffset !== void 0 ? D = u.fromOffset : S.fromOffset !== void 0 && (D = S.fromOffset);
|
|
125
|
+
let L;
|
|
126
|
+
if (u.toOffset !== void 0 ? L = u.toOffset : S.toOffset !== void 0 && (L = S.toOffset), D !== void 0) {
|
|
127
|
+
if (_ !== !1 && (D < 0 || D > 1)) {
|
|
128
|
+
const e = `Invalid fromOffset: ${D} (must be 0-1 for percentage)`;
|
|
129
|
+
return t(e), { success: !1, error: e };
|
|
130
|
+
}
|
|
131
|
+
if (_ === !1 && D < 0) {
|
|
132
|
+
const e = `Invalid fromOffset: ${D} (must be >= 0 for absolute distance)`;
|
|
133
|
+
return t(e), { success: !1, error: e };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
if (L !== void 0) {
|
|
137
|
+
if (f !== !1 && (L < 0 || L > 1)) {
|
|
138
|
+
const e = `Invalid toOffset: ${L} (must be 0-1 for percentage)`;
|
|
139
|
+
return t(e), { success: !1, error: e };
|
|
140
|
+
}
|
|
141
|
+
if (f === !1 && L < 0) {
|
|
142
|
+
const e = `Invalid toOffset: ${L} (must be >= 0 for absolute distance)`;
|
|
143
|
+
return t(e), { success: !1, error: e };
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (_ === !1 && D === void 0) {
|
|
147
|
+
const e = "fromOffset is required when fromIsPercentage is false";
|
|
148
|
+
return t(e), { success: !1, error: e };
|
|
149
|
+
}
|
|
150
|
+
if (f === !1 && L === void 0) {
|
|
151
|
+
const e = "toOffset is required when toIsPercentage is false";
|
|
152
|
+
return t(e), { success: !1, error: e };
|
|
153
|
+
}
|
|
154
|
+
const k = {
|
|
155
|
+
from: n,
|
|
156
|
+
to: g,
|
|
157
|
+
fromPosition: D,
|
|
158
|
+
fromIsPercentage: _,
|
|
159
|
+
toPosition: L,
|
|
160
|
+
toIsPercentage: f
|
|
161
|
+
};
|
|
162
|
+
return s((e) => e.map(
|
|
163
|
+
(o, a) => a === m ? U(k) : o
|
|
164
|
+
)), t(null), { success: !0 };
|
|
165
|
+
}, [M]), p = P((n, g) => {
|
|
166
|
+
if (!M.some((m) => m.fromLineId === n && m.toLineId === g)) {
|
|
167
|
+
const m = `Connection from '${n}' to '${g}' not found`;
|
|
168
|
+
return t(m), { success: !1, error: m };
|
|
169
|
+
}
|
|
170
|
+
return s((m) => m.filter((S) => !(S.fromLineId === n && S.toLineId === g))), t(null), { success: !0 };
|
|
171
|
+
}, [M]), i = P(() => {
|
|
172
|
+
c([]), s([]), t(null);
|
|
173
|
+
}, []);
|
|
174
|
+
return {
|
|
175
|
+
lines: r,
|
|
176
|
+
curves: M,
|
|
177
|
+
setScene: I,
|
|
178
|
+
addLine: T,
|
|
179
|
+
updateLine: q,
|
|
180
|
+
removeLine: y,
|
|
181
|
+
addConnection: C,
|
|
182
|
+
updateConnection: v,
|
|
183
|
+
removeConnection: p,
|
|
184
|
+
clear: i,
|
|
185
|
+
error: d,
|
|
186
|
+
_loadScene: l
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function oe({ lines: r, wheelbase: c }) {
|
|
190
|
+
const [M, s] = j([]), [d, t] = j(null), l = A([]), I = P((v) => {
|
|
191
|
+
l.current = v, s(v), t(null);
|
|
192
|
+
}, []), T = P((v) => {
|
|
193
|
+
const p = Array.isArray(v) ? v : [v], i = [];
|
|
194
|
+
for (const m of p)
|
|
195
|
+
l.current.some((_) => _.id === m.id) && i.push(`Vehicle with ID '${m.id}' already exists`);
|
|
196
|
+
if (i.length > 0)
|
|
197
|
+
return t(i.join("; ")), { success: !1, errors: i };
|
|
198
|
+
const n = p.map(Y), { vehicles: g, errors: u } = N(
|
|
199
|
+
n,
|
|
200
|
+
r,
|
|
201
|
+
c
|
|
202
|
+
);
|
|
203
|
+
return u.length > 0 ? (t(u.join("; ")), { success: !1, errors: u }) : (l.current = [...l.current, ...g], s(l.current), t(null), { success: !0 });
|
|
204
|
+
}, [r, c]), q = P((v, p) => {
|
|
205
|
+
const i = l.current.findIndex((L) => L.id === v);
|
|
206
|
+
if (i === -1) {
|
|
207
|
+
const L = `Vehicle with ID '${v}' not found`;
|
|
208
|
+
return t(L), { success: !1, error: L };
|
|
209
|
+
}
|
|
210
|
+
const n = l.current[i];
|
|
211
|
+
if (n.state !== "idle") {
|
|
212
|
+
const L = `Cannot update vehicle '${v}' while it is ${n.state}. Vehicle must be idle.`;
|
|
213
|
+
return t(L), { success: !1, error: L };
|
|
214
|
+
}
|
|
215
|
+
const g = p.lineId ?? n.lineId;
|
|
216
|
+
if (!r.find((L) => L.id === g)) {
|
|
217
|
+
const L = `Line '${g}' not found`;
|
|
218
|
+
return t(L), { success: !1, error: L };
|
|
219
|
+
}
|
|
220
|
+
let m, S;
|
|
221
|
+
p.lineId !== void 0 && p.position === void 0 ? (m = 0, S = !0) : p.position !== void 0 ? (m = p.position, S = p.isPercentage ?? !0) : (m = n.offset, S = n.isPercentage);
|
|
222
|
+
const _ = {
|
|
223
|
+
vehicleId: v,
|
|
224
|
+
lineId: g,
|
|
225
|
+
offset: m,
|
|
226
|
+
isPercentage: S
|
|
227
|
+
}, { vehicles: f, errors: D } = N(
|
|
228
|
+
[_],
|
|
229
|
+
r,
|
|
230
|
+
c
|
|
231
|
+
);
|
|
232
|
+
return D.length > 0 ? (t(D.join("; ")), { success: !1, error: D.join("; ") }) : (l.current = l.current.map(
|
|
233
|
+
(L, k) => k === i ? f[0] : L
|
|
234
|
+
), s(l.current), t(null), { success: !0 });
|
|
235
|
+
}, [r, c]), y = P((v) => {
|
|
236
|
+
if (!l.current.some((i) => i.id === v)) {
|
|
237
|
+
const i = `Vehicle with ID '${v}' not found`;
|
|
238
|
+
return t(i), { success: !1, error: i };
|
|
239
|
+
}
|
|
240
|
+
return l.current = l.current.filter((i) => i.id !== v), s(l.current), t(null), { success: !0 };
|
|
241
|
+
}, []), C = P(() => {
|
|
242
|
+
l.current = [], s([]), t(null);
|
|
243
|
+
}, []);
|
|
244
|
+
return {
|
|
245
|
+
vehicles: M,
|
|
246
|
+
addVehicles: T,
|
|
247
|
+
updateVehicle: q,
|
|
248
|
+
removeVehicle: y,
|
|
249
|
+
clear: C,
|
|
250
|
+
error: d,
|
|
251
|
+
_loadVehicles: I
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
function ce({ vehicles: r, lines: c }) {
|
|
255
|
+
const [M, s] = j(/* @__PURE__ */ new Map()), [d, t] = j(null), l = A(/* @__PURE__ */ new Map()), I = P(() => l.current, []), T = P((C) => {
|
|
256
|
+
l.current = C, s(C), t(null);
|
|
257
|
+
}, []), q = P((C, v) => {
|
|
258
|
+
if (!r.some((f) => f.id === C)) {
|
|
259
|
+
const f = `Vehicle '${C}' not found`;
|
|
260
|
+
return t(f), { success: !1, error: f };
|
|
261
|
+
}
|
|
262
|
+
const i = c.find((f) => f.id === v.targetLineId);
|
|
263
|
+
if (!i) {
|
|
264
|
+
const f = `Line '${v.targetLineId}' not found`;
|
|
265
|
+
return t(f), { success: !1, error: f };
|
|
266
|
+
}
|
|
267
|
+
const n = v.isPercentage !== !1, g = le(i.start, i.end);
|
|
268
|
+
if (!n && v.targetPosition === void 0) {
|
|
269
|
+
const f = "targetPosition is required when isPercentage is false";
|
|
270
|
+
return t(f), { success: !1, error: f };
|
|
271
|
+
}
|
|
272
|
+
const u = v.targetPosition ?? 1;
|
|
273
|
+
if (n) {
|
|
274
|
+
if (u < 0 || u > 1) {
|
|
275
|
+
const f = `Invalid targetPosition: ${u} (must be 0-1 for percentage)`;
|
|
276
|
+
return t(f), { success: !1, error: f };
|
|
277
|
+
}
|
|
278
|
+
} else {
|
|
279
|
+
if (u < 0) {
|
|
280
|
+
const f = `Invalid targetPosition: ${u} (must be >= 0 for absolute distance)`;
|
|
281
|
+
return t(f), { success: !1, error: f };
|
|
282
|
+
}
|
|
283
|
+
if (u > g) {
|
|
284
|
+
const f = `Position ${u} exceeds line length ${g}`;
|
|
285
|
+
return t(f), { success: !1, error: f };
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
const m = Z({ vehicleId: C, ...v }), S = new Map(l.current), _ = S.get(C) || [];
|
|
289
|
+
return S.set(C, [..._, m]), l.current = S, s(S), t(null), { success: !0 };
|
|
290
|
+
}, [r, c]), y = P((C) => {
|
|
291
|
+
if (C !== void 0) {
|
|
292
|
+
if (!r.some((i) => i.id === C)) {
|
|
293
|
+
const i = `Vehicle '${C}' not found`;
|
|
294
|
+
return t(i), { success: !1, error: i };
|
|
295
|
+
}
|
|
296
|
+
const p = new Map(l.current);
|
|
297
|
+
p.delete(C), l.current = p, s(p);
|
|
298
|
+
} else
|
|
299
|
+
l.current = /* @__PURE__ */ new Map(), s(/* @__PURE__ */ new Map());
|
|
300
|
+
return t(null), { success: !0 };
|
|
301
|
+
}, [r]);
|
|
302
|
+
return {
|
|
303
|
+
vehicleQueues: M,
|
|
304
|
+
getVehicleQueues: I,
|
|
305
|
+
queueMovement: q,
|
|
306
|
+
clearQueue: y,
|
|
307
|
+
error: d,
|
|
308
|
+
_loadQueues: T
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function Me({
|
|
312
|
+
vehicles: r,
|
|
313
|
+
lines: c,
|
|
314
|
+
vehicleQueues: M,
|
|
315
|
+
getVehicleQueues: s,
|
|
316
|
+
wheelbase: d,
|
|
317
|
+
tangentMode: t,
|
|
318
|
+
curves: l,
|
|
319
|
+
eventEmitter: I
|
|
320
|
+
}) {
|
|
321
|
+
const [T, q] = j([]), y = A([]), C = P((e) => {
|
|
322
|
+
typeof e == "function" ? q((o) => {
|
|
323
|
+
const a = e(o);
|
|
324
|
+
return y.current = a, a;
|
|
325
|
+
}) : (y.current = e, q(e));
|
|
326
|
+
}, []), v = P(() => y.current, []), p = G(() => ({
|
|
327
|
+
wheelbase: d,
|
|
328
|
+
tangentMode: t
|
|
329
|
+
}), [d, t]), i = G(
|
|
330
|
+
() => new Map(c.map((e) => [e.id, e])),
|
|
331
|
+
[c]
|
|
332
|
+
), n = A(/* @__PURE__ */ new Map());
|
|
333
|
+
K(() => {
|
|
334
|
+
const { movingVehicles: e, stateMap: o } = ee(r, i);
|
|
335
|
+
n.current = o;
|
|
336
|
+
const a = setTimeout(() => {
|
|
337
|
+
C(e);
|
|
338
|
+
}, 0);
|
|
339
|
+
return () => clearTimeout(a);
|
|
340
|
+
}, [r, i]);
|
|
341
|
+
const g = A(null);
|
|
342
|
+
K(() => {
|
|
343
|
+
c.length > 0 && (g.current = fe(c, l, p));
|
|
344
|
+
}, [c, l, p]);
|
|
345
|
+
const u = A(0), m = A(!1), S = P((e) => {
|
|
346
|
+
if (!m.current) return !1;
|
|
347
|
+
let o = !1;
|
|
348
|
+
for (const [, V] of n.current)
|
|
349
|
+
if (V.vehicle.state === "moving") {
|
|
350
|
+
o = !0;
|
|
351
|
+
break;
|
|
352
|
+
}
|
|
353
|
+
if (!o)
|
|
354
|
+
return !1;
|
|
355
|
+
const a = [];
|
|
356
|
+
for (const [V, x] of n.current) {
|
|
357
|
+
if (x.vehicle.state !== "moving" || !x.execution) continue;
|
|
358
|
+
const h = x.execution;
|
|
359
|
+
let w;
|
|
360
|
+
if (h.front.currentSegmentIndex < h.path.segments.length) {
|
|
361
|
+
const E = h.path.segments[h.front.currentSegmentIndex];
|
|
362
|
+
if (E.type === "line") {
|
|
363
|
+
const $ = i.get(E.lineId);
|
|
364
|
+
$ && (w = Math.sqrt(
|
|
365
|
+
Math.pow($.end.x - $.start.x, 2) + Math.pow($.end.y - $.start.y, 2)
|
|
366
|
+
));
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const Q = te(
|
|
370
|
+
x.vehicle.rear,
|
|
371
|
+
h.rear,
|
|
372
|
+
h.path,
|
|
373
|
+
e,
|
|
374
|
+
i,
|
|
375
|
+
h.curveDataMap
|
|
376
|
+
), O = te(
|
|
377
|
+
x.vehicle.front,
|
|
378
|
+
h.front,
|
|
379
|
+
h.path,
|
|
380
|
+
e,
|
|
381
|
+
i,
|
|
382
|
+
h.curveDataMap,
|
|
383
|
+
w
|
|
384
|
+
);
|
|
385
|
+
if (x.vehicle = {
|
|
386
|
+
...x.vehicle,
|
|
387
|
+
rear: Q.axleState,
|
|
388
|
+
front: O.axleState
|
|
389
|
+
}, x.execution.rear = Q.execution, x.execution.front = O.execution, Q.completed) {
|
|
390
|
+
const $ = de(x, {
|
|
391
|
+
linesMap: i,
|
|
392
|
+
config: p,
|
|
393
|
+
vehicleQueues: M,
|
|
394
|
+
curves: l,
|
|
395
|
+
graphRef: g,
|
|
396
|
+
prepareCommandPath: B,
|
|
397
|
+
onCommandComplete: (F) => a.push({ type: "commandComplete", data: F }),
|
|
398
|
+
onCommandStart: (F) => a.push({ type: "commandStart", data: F })
|
|
399
|
+
});
|
|
400
|
+
x.vehicle = $.vehicle, $.newExecution !== void 0 && (x.execution = $.newExecution), $.vehicle.state !== "moving" && a.push({
|
|
401
|
+
type: "stateChange",
|
|
402
|
+
data: { vehicleId: V, from: "moving", to: $.vehicle.state }
|
|
403
|
+
});
|
|
404
|
+
const b = $.vehicle.rear.position, R = $.vehicle.front.position;
|
|
405
|
+
a.push({
|
|
406
|
+
type: "positionUpdate",
|
|
407
|
+
data: {
|
|
408
|
+
vehicleId: V,
|
|
409
|
+
rear: b,
|
|
410
|
+
front: R,
|
|
411
|
+
center: { x: (b.x + R.x) / 2, y: (b.y + R.y) / 2 },
|
|
412
|
+
angle: Math.atan2(R.y - b.y, R.x - b.x)
|
|
413
|
+
}
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
if (C((V) => V.map((x) => {
|
|
418
|
+
const h = n.current.get(x.id);
|
|
419
|
+
return h ? h.vehicle : x;
|
|
420
|
+
})), I && a.length > 0) {
|
|
421
|
+
const V = u.current;
|
|
422
|
+
setTimeout(() => {
|
|
423
|
+
u.current === V && a.forEach(({ type: x, data: h }) => {
|
|
424
|
+
I.emit(x, h);
|
|
425
|
+
});
|
|
426
|
+
}, 0);
|
|
427
|
+
}
|
|
428
|
+
for (const [, V] of n.current)
|
|
429
|
+
if (V.vehicle.state === "moving")
|
|
430
|
+
return !0;
|
|
431
|
+
return m.current = !1, !1;
|
|
432
|
+
}, [i, l, p, M, I]), _ = P(() => {
|
|
433
|
+
const e = g.current;
|
|
434
|
+
if (!e) return !1;
|
|
435
|
+
const o = s ? s() : M, a = [];
|
|
436
|
+
let V = !1;
|
|
437
|
+
for (const [x, h] of n.current) {
|
|
438
|
+
const w = h.vehicle;
|
|
439
|
+
if (w.state === "moving") continue;
|
|
440
|
+
const Q = o.get(x);
|
|
441
|
+
if (!Q || Q.length === 0) continue;
|
|
442
|
+
const O = Q[0], $ = B(w, O, { graph: e, linesMap: i, curves: l, config: p });
|
|
443
|
+
if (!$) {
|
|
444
|
+
console.warn(`No path found for vehicle ${x}`);
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
const b = re($.path, 0, 0, d);
|
|
448
|
+
n.current.set(x, {
|
|
449
|
+
...h,
|
|
450
|
+
execution: {
|
|
451
|
+
path: $.path,
|
|
452
|
+
curveDataMap: $.curveDataMap,
|
|
453
|
+
currentCommandIndex: 0,
|
|
454
|
+
rear: { currentSegmentIndex: 0, segmentDistance: 0 },
|
|
455
|
+
front: b ? { currentSegmentIndex: b.segmentIndex, segmentDistance: b.segmentDistance } : { currentSegmentIndex: 0, segmentDistance: 0 }
|
|
456
|
+
},
|
|
457
|
+
vehicle: { ...w, state: "moving" }
|
|
458
|
+
}), V = !0, a.push({
|
|
459
|
+
id: x,
|
|
460
|
+
fromState: w.state,
|
|
461
|
+
command: O,
|
|
462
|
+
startPosition: {
|
|
463
|
+
lineId: w.rear.lineId,
|
|
464
|
+
absoluteOffset: w.rear.absoluteOffset,
|
|
465
|
+
position: w.rear.position
|
|
466
|
+
}
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
if (!V) return !1;
|
|
470
|
+
if (m.current = !0, C((x) => x.map((h) => {
|
|
471
|
+
const w = n.current.get(h.id);
|
|
472
|
+
return w ? w.vehicle : h;
|
|
473
|
+
})), I && a.length > 0) {
|
|
474
|
+
const x = u.current;
|
|
475
|
+
setTimeout(() => {
|
|
476
|
+
u.current === x && a.forEach(({ id: h, fromState: w, command: Q, startPosition: O }) => {
|
|
477
|
+
I.emit("commandStart", {
|
|
478
|
+
vehicleId: h,
|
|
479
|
+
command: Q,
|
|
480
|
+
commandIndex: 0,
|
|
481
|
+
startPosition: O
|
|
482
|
+
}), I.emit("stateChange", {
|
|
483
|
+
vehicleId: h,
|
|
484
|
+
from: w,
|
|
485
|
+
to: "moving"
|
|
486
|
+
});
|
|
487
|
+
});
|
|
488
|
+
}, 0);
|
|
489
|
+
}
|
|
490
|
+
return !0;
|
|
491
|
+
}, [i, l, M, s, p, d, I]), f = P(() => {
|
|
492
|
+
u.current++, m.current = !1;
|
|
493
|
+
const { movingVehicles: e, stateMap: o } = ee(r, i);
|
|
494
|
+
n.current = o, C(e);
|
|
495
|
+
}, [r, i]), D = P((e) => {
|
|
496
|
+
const o = r.find((h) => h.id === e);
|
|
497
|
+
if (!o || !i.get(o.lineId)) return;
|
|
498
|
+
const V = me(o), x = ge(V);
|
|
499
|
+
n.current.set(e, x), C((h) => h.map(
|
|
500
|
+
(w) => w.id === e ? V : w
|
|
501
|
+
));
|
|
502
|
+
}, [r, i]), L = P((e) => {
|
|
503
|
+
const o = n.current.get(e);
|
|
504
|
+
if (!o || o.vehicle.state !== "waiting")
|
|
505
|
+
return !1;
|
|
506
|
+
const a = M.get(e), V = o.execution;
|
|
507
|
+
if (!V) return !1;
|
|
508
|
+
const x = V.currentCommandIndex + 1;
|
|
509
|
+
if (a && x < a.length) {
|
|
510
|
+
const h = g.current;
|
|
511
|
+
if (h) {
|
|
512
|
+
const w = a[x], Q = { graph: h, linesMap: i, curves: l, config: p }, O = B(o.vehicle, w, Q);
|
|
513
|
+
if (O) {
|
|
514
|
+
const E = re(O.path, 0, 0, d);
|
|
515
|
+
if (o.execution = {
|
|
516
|
+
path: O.path,
|
|
517
|
+
curveDataMap: O.curveDataMap,
|
|
518
|
+
currentCommandIndex: x,
|
|
519
|
+
rear: { currentSegmentIndex: 0, segmentDistance: 0 },
|
|
520
|
+
front: E ? { currentSegmentIndex: E.segmentIndex, segmentDistance: E.segmentDistance } : { currentSegmentIndex: 0, segmentDistance: 0 }
|
|
521
|
+
}, o.vehicle = { ...o.vehicle, state: "moving" }, C(($) => $.map((b) => b.id === e ? o.vehicle : b)), I) {
|
|
522
|
+
const $ = u.current;
|
|
523
|
+
setTimeout(() => {
|
|
524
|
+
u.current === $ && I.emit("stateChange", {
|
|
525
|
+
vehicleId: e,
|
|
526
|
+
from: "waiting",
|
|
527
|
+
to: "moving"
|
|
528
|
+
});
|
|
529
|
+
}, 0);
|
|
530
|
+
}
|
|
531
|
+
return !0;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
if (o.vehicle = { ...o.vehicle, state: "idle" }, o.execution = null, C((h) => h.map((w) => w.id === e ? o.vehicle : w)), I) {
|
|
536
|
+
const h = u.current;
|
|
537
|
+
setTimeout(() => {
|
|
538
|
+
u.current === h && I.emit("stateChange", {
|
|
539
|
+
vehicleId: e,
|
|
540
|
+
from: "waiting",
|
|
541
|
+
to: "idle"
|
|
542
|
+
});
|
|
543
|
+
}, 0);
|
|
544
|
+
}
|
|
545
|
+
return !0;
|
|
546
|
+
}, [M, i, l, p, d, I]), k = P(() => {
|
|
547
|
+
for (const [, e] of n.current)
|
|
548
|
+
if (e.vehicle.state === "moving")
|
|
549
|
+
return !0;
|
|
550
|
+
return !1;
|
|
551
|
+
}, []);
|
|
552
|
+
return {
|
|
553
|
+
movingVehicles: T,
|
|
554
|
+
getMovingVehicles: v,
|
|
555
|
+
prepare: _,
|
|
556
|
+
tick: S,
|
|
557
|
+
reset: f,
|
|
558
|
+
resetVehicle: D,
|
|
559
|
+
continueVehicle: L,
|
|
560
|
+
isMoving: k,
|
|
561
|
+
isPrepared: m.current
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
function $e({
|
|
565
|
+
wheelbase: r,
|
|
566
|
+
tangentMode: c = "proportional-40",
|
|
567
|
+
eventEmitter: M
|
|
568
|
+
}) {
|
|
569
|
+
const s = ne(), d = oe({ lines: s.lines, wheelbase: r }), t = ce({
|
|
570
|
+
vehicles: d.vehicles,
|
|
571
|
+
lines: s.lines,
|
|
572
|
+
curves: s.curves
|
|
573
|
+
}), l = Me({
|
|
574
|
+
vehicles: d.vehicles,
|
|
575
|
+
lines: s.lines,
|
|
576
|
+
vehicleQueues: t.vehicleQueues,
|
|
577
|
+
getVehicleQueues: t.getVehicleQueues,
|
|
578
|
+
wheelbase: r,
|
|
579
|
+
tangentMode: c,
|
|
580
|
+
curves: s.curves,
|
|
581
|
+
eventEmitter: M
|
|
582
|
+
}), I = P((e) => d.vehicles.filter((o) => o.lineId === e || o.rear.lineId === e), [d.vehicles]), T = P((e) => I(e).length > 0, [I]), q = P((e) => {
|
|
583
|
+
const o = s.addLine(e);
|
|
584
|
+
return o.success ? { success: !0 } : { success: !1, error: o.error };
|
|
585
|
+
}, [s]), y = P((e, o) => {
|
|
586
|
+
const a = s.updateLine(e, o);
|
|
587
|
+
return a.success ? { success: !0 } : { success: !1, error: a.error };
|
|
588
|
+
}, [s]), C = P((e) => {
|
|
589
|
+
const o = [], a = I(e);
|
|
590
|
+
a.length > 0 && (o.push({
|
|
591
|
+
type: "vehicle_on_removed_line",
|
|
592
|
+
message: `${a.length} vehicle(s) are on line '${e}'`,
|
|
593
|
+
details: {
|
|
594
|
+
lineId: e,
|
|
595
|
+
vehicleIds: a.map((h) => h.id)
|
|
596
|
+
}
|
|
597
|
+
}), a.forEach((h) => {
|
|
598
|
+
d.removeVehicle(h.id), t.clearQueue(h.id);
|
|
599
|
+
}));
|
|
600
|
+
const V = s.curves.filter(
|
|
601
|
+
(h) => h.fromLineId === e || h.toLineId === e
|
|
602
|
+
);
|
|
603
|
+
V.length > 0 && o.push({
|
|
604
|
+
type: "orphaned_connection",
|
|
605
|
+
message: `${V.length} connection(s) will be removed`,
|
|
606
|
+
details: {
|
|
607
|
+
lineId: e,
|
|
608
|
+
connectionCount: V.length
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
const x = s.removeLine(e);
|
|
612
|
+
return x.success ? {
|
|
613
|
+
success: !0,
|
|
614
|
+
warnings: o.length > 0 ? o : void 0
|
|
615
|
+
} : { success: !1, error: x.error };
|
|
616
|
+
}, [s, I, d, t]), v = P(() => {
|
|
617
|
+
s.clear(), d.clear(), t.clearQueue();
|
|
618
|
+
}, [s, d, t]), p = P((e, o, a) => {
|
|
619
|
+
const V = s.addConnection({
|
|
620
|
+
from: e,
|
|
621
|
+
to: o,
|
|
622
|
+
fromPosition: a?.fromOffset,
|
|
623
|
+
fromIsPercentage: a?.fromIsPercentage,
|
|
624
|
+
toPosition: a?.toOffset,
|
|
625
|
+
toIsPercentage: a?.toIsPercentage
|
|
626
|
+
});
|
|
627
|
+
return V.success ? { success: !0 } : { success: !1, error: V.error };
|
|
628
|
+
}, [s]), i = P((e, o, a) => {
|
|
629
|
+
const V = s.updateConnection(e, o, a);
|
|
630
|
+
return V.success ? { success: !0 } : { success: !1, error: V.error };
|
|
631
|
+
}, [s]), n = P((e, o) => {
|
|
632
|
+
const a = s.removeConnection(e, o);
|
|
633
|
+
return a.success ? { success: !0 } : { success: !1, error: a.error };
|
|
634
|
+
}, [s]), g = P((e) => {
|
|
635
|
+
const o = d.addVehicles(e);
|
|
636
|
+
return o.success ? { success: !0 } : { success: !1, error: o.errors?.join("; ") };
|
|
637
|
+
}, [d]), u = P((e, o) => {
|
|
638
|
+
const a = d.updateVehicle(e, o);
|
|
639
|
+
return a.success ? { success: !0 } : { success: !1, error: a.error };
|
|
640
|
+
}, [d]), m = P((e) => {
|
|
641
|
+
const o = [], a = t.vehicleQueues.get(e);
|
|
642
|
+
a && a.length > 0 && (o.push({
|
|
643
|
+
type: "movement_queue_cleared",
|
|
644
|
+
message: `${a.length} queued movement(s) will be cleared for vehicle '${e}'`,
|
|
645
|
+
details: {
|
|
646
|
+
vehicleId: e
|
|
647
|
+
}
|
|
648
|
+
}), t.clearQueue(e));
|
|
649
|
+
const V = d.removeVehicle(e);
|
|
650
|
+
return V.success ? {
|
|
651
|
+
success: !0,
|
|
652
|
+
warnings: o.length > 0 ? o : void 0
|
|
653
|
+
} : { success: !1, error: V.error };
|
|
654
|
+
}, [d, t]), S = P(() => {
|
|
655
|
+
d.clear(), t.clearQueue();
|
|
656
|
+
}, [d, t]), _ = P((e) => {
|
|
657
|
+
const o = {
|
|
658
|
+
targetLineId: e.lineId,
|
|
659
|
+
targetPosition: e.position ?? 1,
|
|
660
|
+
isPercentage: e.isPercentage,
|
|
661
|
+
wait: e.wait,
|
|
662
|
+
payload: e.payload
|
|
663
|
+
}, a = t.queueMovement(e.id, o);
|
|
664
|
+
return a.success ? { success: !0 } : { success: !1, error: a.error };
|
|
665
|
+
}, [t]), f = P((e) => {
|
|
666
|
+
const o = t.clearQueue(e);
|
|
667
|
+
return o.success ? { success: !0 } : { success: !1, error: o.error };
|
|
668
|
+
}, [t]), D = P((e) => {
|
|
669
|
+
const o = [], a = [], { scene: V, vehicles: x, movements: h } = he(e);
|
|
670
|
+
V.errors.length > 0 && a.push(...V.errors), x.errors.length > 0 && a.push(...x.errors), h.errors.length > 0 && a.push(...h.errors);
|
|
671
|
+
const w = V.data.lines.map(H), Q = (V.data.connections || []).map(U), O = x.data.map(Y), { vehicles: E, errors: $ } = N(O, w, r);
|
|
672
|
+
$.length > 0 && a.push(...$);
|
|
673
|
+
const b = /* @__PURE__ */ new Map();
|
|
674
|
+
for (const R of h.data) {
|
|
675
|
+
const F = b.get(R.vehicleId) || [];
|
|
676
|
+
F.push(Z(R)), b.set(R.vehicleId, F);
|
|
677
|
+
}
|
|
678
|
+
return s._loadScene(w, Q), d._loadVehicles(E), t._loadQueues(b), a.length > 0 && o.push({
|
|
679
|
+
type: "dsl_parse_error",
|
|
680
|
+
message: `DSL loading had ${a.length} error(s)`,
|
|
681
|
+
details: { errors: a }
|
|
682
|
+
}), {
|
|
683
|
+
success: !0,
|
|
684
|
+
warnings: o.length > 0 ? o : void 0
|
|
685
|
+
};
|
|
686
|
+
}, [s, d, t, r]), L = P((e) => {
|
|
687
|
+
const o = [], a = [], V = e.lines.map(H), x = (e.connections || []).map(U), h = (e.vehicles || []).map(Y), { vehicles: w, errors: Q } = N(h, V, r);
|
|
688
|
+
Q.length > 0 && a.push(...Q);
|
|
689
|
+
const O = /* @__PURE__ */ new Map();
|
|
690
|
+
for (const E of e.movements || []) {
|
|
691
|
+
const $ = O.get(E.vehicleId) || [];
|
|
692
|
+
$.push(Z({
|
|
693
|
+
vehicleId: E.vehicleId,
|
|
694
|
+
targetLineId: E.targetLineId,
|
|
695
|
+
targetPosition: E.targetPosition,
|
|
696
|
+
isPercentage: E.isPercentage,
|
|
697
|
+
wait: E.wait,
|
|
698
|
+
payload: E.payload
|
|
699
|
+
})), O.set(E.vehicleId, $);
|
|
700
|
+
}
|
|
701
|
+
return s._loadScene(V, x), d._loadVehicles(w), t._loadQueues(O), a.length > 0 && o.push({
|
|
702
|
+
type: "dsl_parse_error",
|
|
703
|
+
message: `JSON loading had ${a.length} error(s)`,
|
|
704
|
+
details: { errors: a }
|
|
705
|
+
}), {
|
|
706
|
+
success: !0,
|
|
707
|
+
warnings: o.length > 0 ? o : void 0
|
|
708
|
+
};
|
|
709
|
+
}, [s, d, t, r]), k = G(() => s.error || d.error || t.error, [s.error, d.error, t.error]);
|
|
710
|
+
return {
|
|
711
|
+
// State
|
|
712
|
+
lines: s.lines,
|
|
713
|
+
curves: s.curves,
|
|
714
|
+
vehicles: d.vehicles,
|
|
715
|
+
movingVehicles: l.movingVehicles,
|
|
716
|
+
getMovingVehicles: l.getMovingVehicles,
|
|
717
|
+
vehicleQueues: t.vehicleQueues,
|
|
718
|
+
error: k,
|
|
719
|
+
// Scene operations
|
|
720
|
+
addLine: q,
|
|
721
|
+
updateLine: y,
|
|
722
|
+
removeLine: C,
|
|
723
|
+
clearScene: v,
|
|
724
|
+
// Connection operations
|
|
725
|
+
connect: p,
|
|
726
|
+
updateConnection: i,
|
|
727
|
+
disconnect: n,
|
|
728
|
+
// Vehicle operations
|
|
729
|
+
addVehicles: g,
|
|
730
|
+
updateVehicle: u,
|
|
731
|
+
removeVehicle: m,
|
|
732
|
+
clearVehicles: S,
|
|
733
|
+
// Movement operations
|
|
734
|
+
goto: _,
|
|
735
|
+
clearQueue: f,
|
|
736
|
+
// Animation (delegated to useVehicleMovement)
|
|
737
|
+
prepare: l.prepare,
|
|
738
|
+
tick: l.tick,
|
|
739
|
+
reset: l.reset,
|
|
740
|
+
resetVehicle: l.resetVehicle,
|
|
741
|
+
continueVehicle: l.continueVehicle,
|
|
742
|
+
isMoving: l.isMoving,
|
|
743
|
+
// DSL Loading
|
|
744
|
+
loadFromDSL: D,
|
|
745
|
+
// JSON Loading
|
|
746
|
+
loadFromJSON: L,
|
|
747
|
+
// Utility
|
|
748
|
+
getVehiclesOnLine: I,
|
|
749
|
+
hasVehiclesOnLine: T
|
|
750
|
+
};
|
|
751
|
+
}
|
|
752
|
+
function z(r) {
|
|
753
|
+
return r.map((c) => ({
|
|
754
|
+
id: c.id,
|
|
755
|
+
start: c.start,
|
|
756
|
+
end: c.end
|
|
757
|
+
}));
|
|
758
|
+
}
|
|
759
|
+
function X(r) {
|
|
760
|
+
return r.map((c) => ({
|
|
761
|
+
from: c.fromLineId,
|
|
762
|
+
to: c.toLineId,
|
|
763
|
+
// No conversion needed - internal format is now 0-1 (same as API)
|
|
764
|
+
fromPosition: c.fromOffset,
|
|
765
|
+
fromIsPercentage: c.fromIsPercentage,
|
|
766
|
+
toPosition: c.toOffset,
|
|
767
|
+
toIsPercentage: c.toIsPercentage
|
|
768
|
+
}));
|
|
769
|
+
}
|
|
770
|
+
function ye() {
|
|
771
|
+
const [r, c] = j(""), [M, s] = j(null), { lines: d, curves: t, setScene: l } = ne(), I = A(!1), T = A("");
|
|
772
|
+
K(() => {
|
|
773
|
+
T.current = r;
|
|
774
|
+
}, [r]), K(() => {
|
|
775
|
+
if (I.current)
|
|
776
|
+
return;
|
|
777
|
+
const v = {
|
|
778
|
+
lines: z(d),
|
|
779
|
+
connections: t.length > 0 ? X(t) : void 0
|
|
780
|
+
}, p = W(v);
|
|
781
|
+
p !== T.current && (I.current = !0, c(p), setTimeout(() => {
|
|
782
|
+
I.current = !1;
|
|
783
|
+
}, 50));
|
|
784
|
+
}, [d, t]);
|
|
785
|
+
const q = P((v) => {
|
|
786
|
+
I.current = !0, c(v);
|
|
787
|
+
try {
|
|
788
|
+
const { data: p, errors: i } = ve(v);
|
|
789
|
+
i.length > 0 && s(i.join("; "));
|
|
790
|
+
const n = l(p);
|
|
791
|
+
!n.success && n.errors ? s((g) => g ? `${g}; ${n.errors.join("; ")}` : n.errors.join("; ")) : i.length === 0 && s(null);
|
|
792
|
+
} catch (p) {
|
|
793
|
+
s(p instanceof Error ? p.message : "Invalid scene definition");
|
|
794
|
+
}
|
|
795
|
+
setTimeout(() => {
|
|
796
|
+
I.current = !1;
|
|
797
|
+
}, 50);
|
|
798
|
+
}, [l]), y = P((v) => {
|
|
799
|
+
const p = typeof v == "function" ? v(d) : v, i = X(t);
|
|
800
|
+
l({
|
|
801
|
+
lines: z(p),
|
|
802
|
+
connections: i.length > 0 ? i : void 0
|
|
803
|
+
});
|
|
804
|
+
const n = {
|
|
805
|
+
lines: z(p),
|
|
806
|
+
connections: i.length > 0 ? i : void 0
|
|
807
|
+
}, g = W(n);
|
|
808
|
+
I.current = !0, c(g), setTimeout(() => {
|
|
809
|
+
I.current = !1;
|
|
810
|
+
}, 50);
|
|
811
|
+
}, [d, t, l]), C = P((v) => {
|
|
812
|
+
const p = typeof v == "function" ? v(t) : v, i = X(p);
|
|
813
|
+
l({
|
|
814
|
+
lines: z(d),
|
|
815
|
+
connections: i.length > 0 ? i : void 0
|
|
816
|
+
});
|
|
817
|
+
const n = {
|
|
818
|
+
lines: z(d),
|
|
819
|
+
connections: i.length > 0 ? i : void 0
|
|
820
|
+
}, g = W(n);
|
|
821
|
+
I.current = !0, c(g), setTimeout(() => {
|
|
822
|
+
I.current = !1;
|
|
823
|
+
}, 50);
|
|
824
|
+
}, [d, t, l]);
|
|
825
|
+
return {
|
|
826
|
+
lines: d,
|
|
827
|
+
curves: t,
|
|
828
|
+
sceneDefinitionText: r,
|
|
829
|
+
sceneError: M,
|
|
830
|
+
isDebouncing: !1,
|
|
831
|
+
// No debouncing - parsing is immediate
|
|
832
|
+
debounceKey: 0,
|
|
833
|
+
// Kept for API compatibility
|
|
834
|
+
setLines: y,
|
|
835
|
+
setCurves: C,
|
|
836
|
+
setSceneDefinitionText: q
|
|
837
|
+
};
|
|
838
|
+
}
|
|
839
|
+
function Ee({ lines: r, wheelbase: c }) {
|
|
840
|
+
const [M, s] = j(""), [d, t] = j(null), { vehicles: l, addVehicles: I, clear: T, error: q } = oe({ lines: r, wheelbase: c }), y = A(!1), C = P((v) => {
|
|
841
|
+
y.current = !0, s(v);
|
|
842
|
+
try {
|
|
843
|
+
const { data: p, errors: i } = pe(v), n = [...i];
|
|
844
|
+
T();
|
|
845
|
+
for (const g of p) {
|
|
846
|
+
const u = I(g);
|
|
847
|
+
!u.success && u.errors && n.push(...u.errors);
|
|
848
|
+
}
|
|
849
|
+
n.length > 0 ? t(n.join(`
|
|
850
|
+
`)) : t(null);
|
|
851
|
+
} catch (p) {
|
|
852
|
+
t(p instanceof Error ? p.message : "Invalid initial movement");
|
|
853
|
+
}
|
|
854
|
+
setTimeout(() => {
|
|
855
|
+
y.current = !1;
|
|
856
|
+
}, 50);
|
|
857
|
+
}, [I, T]);
|
|
858
|
+
return {
|
|
859
|
+
vehicles: l,
|
|
860
|
+
initialMovementText: M,
|
|
861
|
+
movementError: d || q,
|
|
862
|
+
isDebouncing: !1,
|
|
863
|
+
// No debouncing - parsing is immediate
|
|
864
|
+
debounceKey: 0,
|
|
865
|
+
// Kept for API compatibility
|
|
866
|
+
setInitialMovementText: C
|
|
867
|
+
};
|
|
868
|
+
}
|
|
869
|
+
function De({ lines: r, vehicles: c }) {
|
|
870
|
+
const [M, s] = j(""), [d, t] = j([]), [l, I] = j(null), { vehicleQueues: T, queueMovement: q, clearQueue: y, error: C } = ce({
|
|
871
|
+
vehicles: c,
|
|
872
|
+
lines: r
|
|
873
|
+
}), v = A(!1), p = P((i) => {
|
|
874
|
+
v.current = !0, s(i);
|
|
875
|
+
try {
|
|
876
|
+
const { data: n, errors: g } = Pe(i), u = [...g];
|
|
877
|
+
y();
|
|
878
|
+
for (const m of n) {
|
|
879
|
+
const S = q(m.vehicleId, {
|
|
880
|
+
targetLineId: m.targetLineId,
|
|
881
|
+
targetPosition: m.targetPosition,
|
|
882
|
+
isPercentage: m.isPercentage,
|
|
883
|
+
wait: m.wait,
|
|
884
|
+
payload: m.payload
|
|
885
|
+
});
|
|
886
|
+
!S.success && S.error && u.push(S.error);
|
|
887
|
+
}
|
|
888
|
+
t(n), u.length > 0 ? I(u.join(`
|
|
889
|
+
`)) : I(null);
|
|
890
|
+
} catch (n) {
|
|
891
|
+
I(n instanceof Error ? n.message : "Invalid movement sequence"), t([]);
|
|
892
|
+
}
|
|
893
|
+
setTimeout(() => {
|
|
894
|
+
v.current = !1;
|
|
895
|
+
}, 50);
|
|
896
|
+
}, [q, y]);
|
|
897
|
+
return {
|
|
898
|
+
movementSequenceText: M,
|
|
899
|
+
gotoCommands: d,
|
|
900
|
+
vehicleQueues: T,
|
|
901
|
+
sequenceError: l || C,
|
|
902
|
+
isDebouncing: !1,
|
|
903
|
+
// No debouncing - parsing is immediate
|
|
904
|
+
debounceKey: 0,
|
|
905
|
+
// Kept for API compatibility
|
|
906
|
+
setMovementSequenceText: p
|
|
907
|
+
};
|
|
908
|
+
}
|
|
909
|
+
const ie = ae(null);
|
|
910
|
+
function Ve() {
|
|
911
|
+
const r = ue(ie);
|
|
912
|
+
if (!r)
|
|
913
|
+
throw new Error("useVehicleEventEmitter must be used within a VehicleEventProvider");
|
|
914
|
+
return r;
|
|
915
|
+
}
|
|
916
|
+
function Oe() {
|
|
917
|
+
return G(() => new se(), []);
|
|
918
|
+
}
|
|
919
|
+
function Te(r, c, M = []) {
|
|
920
|
+
const s = Ve();
|
|
921
|
+
K(() => s.on(r, c), [s, r, ...M]);
|
|
922
|
+
}
|
|
923
|
+
function qe({ children: r }) {
|
|
924
|
+
const c = G(() => new se(), []);
|
|
925
|
+
return /* @__PURE__ */ Ie(ie.Provider, { value: c, children: r });
|
|
926
|
+
}
|
|
927
|
+
export {
|
|
928
|
+
ie as V,
|
|
929
|
+
qe as a,
|
|
930
|
+
Oe as b,
|
|
931
|
+
Ee as c,
|
|
932
|
+
ce as d,
|
|
933
|
+
De as e,
|
|
934
|
+
ne as f,
|
|
935
|
+
ye as g,
|
|
936
|
+
Te as h,
|
|
937
|
+
Ve as i,
|
|
938
|
+
$e as j,
|
|
939
|
+
oe as k,
|
|
940
|
+
Me as u
|
|
941
|
+
};
|