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