vehicle-path2 1.0.11 → 1.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/core/algorithms/vehicleMovement.d.ts +20 -0
- package/dist/core/index.d.ts +2 -2
- package/dist/core/types/api.d.ts +0 -5
- package/dist/core/types/vehicle.d.ts +0 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +340 -358
- package/dist/react/hooks/useMovementQueue.d.ts +0 -1
- package/dist/react.cjs +1 -1
- package/dist/react.js +1 -1
- package/dist/useVehicleEvents-BZVmIugl.cjs +3 -0
- package/dist/{useVehicleEvents-t_p-Bwhj.js → useVehicleEvents-CabztfQ4.js} +185 -189
- package/dist/utils/dsl-parser.d.ts +4 -5
- package/dist/utils/type-converters.d.ts +0 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.js +1 -1
- package/dist/{vehicle-helpers-BYb2Ibex.js → vehicle-helpers-BgD4BTAJ.js} +15 -16
- package/dist/{vehicle-helpers-bgHGBdo9.cjs → vehicle-helpers-DrnYWjm3.cjs} +7 -7
- package/dist/vehicle-path.cjs +1 -1
- package/dist/vehicle-path.js +2 -2
- package/package.json +1 -1
- package/dist/useVehicleEvents-B7Z-9Hn2.cjs +0 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { useState as _, useCallback as p, useRef as A, useMemo as G, useEffect as K, createContext as
|
|
1
|
+
import { useState as _, useCallback as p, useRef as A, useMemo as G, useEffect as K, createContext as ae, useContext as le } from "react";
|
|
2
2
|
import { distance as fe, initializeAllVehicles as te, buildGraph as de, updateAxlePosition as re, handleArrival as me, prepareCommandPath as B, calculateFrontAxlePosition as se, initializeMovingVehicle as ge, createInitialMovementState as he } from "./core.js";
|
|
3
|
-
import { v as N, p as ve, a as W, f as pe, h as Pe, e as Ie, V as ne } from "./vehicle-helpers-
|
|
3
|
+
import { v as N, p as ve, a as W, f as pe, h as Pe, e as Ie, V as ne } from "./vehicle-helpers-BgD4BTAJ.js";
|
|
4
4
|
import { jsx as xe } from "react/jsx-runtime";
|
|
5
5
|
function J(t) {
|
|
6
6
|
return Array.isArray(t) ? { x: t[0], y: t[1] } : t;
|
|
@@ -42,7 +42,6 @@ function Z(t) {
|
|
|
42
42
|
// No conversion needed - internal format is now 0-1 (same as API)
|
|
43
43
|
targetOffset: V,
|
|
44
44
|
isPercentage: o,
|
|
45
|
-
awaitConfirmation: t.wait,
|
|
46
45
|
payload: t.payload
|
|
47
46
|
};
|
|
48
47
|
}
|
|
@@ -65,46 +64,46 @@ function oe() {
|
|
|
65
64
|
const v = Me(s);
|
|
66
65
|
if (!v.valid)
|
|
67
66
|
return e(v.errors.join("; ")), { success: !1, errors: v.errors };
|
|
68
|
-
const
|
|
69
|
-
return f(
|
|
67
|
+
const u = s.lines.map(H), h = s.connections?.map(U) || [];
|
|
68
|
+
return f(u, h), { success: !0 };
|
|
70
69
|
}, [f]), O = p((s) => {
|
|
71
|
-
if (t.some((
|
|
72
|
-
const
|
|
73
|
-
return e(
|
|
70
|
+
if (t.some((u) => u.id === s.id)) {
|
|
71
|
+
const u = `Line with ID '${s.id}' already exists`;
|
|
72
|
+
return e(u), { success: !1, error: u };
|
|
74
73
|
}
|
|
75
|
-
return o((
|
|
74
|
+
return o((u) => [...u, H(s)]), e(null), { success: !0 };
|
|
76
75
|
}, [t]), T = p((s, v) => {
|
|
77
76
|
if (t.findIndex((h) => h.id === s) === -1) {
|
|
78
77
|
const h = `Line with ID '${s}' not found`;
|
|
79
78
|
return e(h), { success: !1, error: h };
|
|
80
79
|
}
|
|
81
|
-
return o((h) => h.map((
|
|
82
|
-
...
|
|
83
|
-
start: v.start ? J(v.start) :
|
|
84
|
-
end: v.end ? J(v.end) :
|
|
80
|
+
return o((h) => h.map((L) => L.id !== s ? L : {
|
|
81
|
+
...L,
|
|
82
|
+
start: v.start ? J(v.start) : L.start,
|
|
83
|
+
end: v.end ? J(v.end) : L.end
|
|
85
84
|
})), e(null), { success: !0 };
|
|
86
85
|
}, [t]), y = p((s) => {
|
|
87
|
-
if (!t.some((
|
|
88
|
-
const
|
|
89
|
-
return e(
|
|
86
|
+
if (!t.some((u) => u.id === s)) {
|
|
87
|
+
const u = `Line with ID '${s}' not found`;
|
|
88
|
+
return e(u), { success: !1, error: u };
|
|
90
89
|
}
|
|
91
|
-
return o((
|
|
92
|
-
}, [t]),
|
|
93
|
-
const v = t.some((d) => d.id === s.from),
|
|
90
|
+
return o((u) => u.filter((h) => h.id !== s)), r((u) => u.filter((h) => h.fromLineId !== s && h.toLineId !== s)), e(null), { success: !0 };
|
|
91
|
+
}, [t]), C = p((s) => {
|
|
92
|
+
const v = t.some((d) => d.id === s.from), u = t.some((d) => d.id === s.to);
|
|
94
93
|
if (!v) {
|
|
95
94
|
const d = `Line '${s.from}' not found`;
|
|
96
95
|
return e(d), { success: !1, error: d };
|
|
97
96
|
}
|
|
98
|
-
if (!
|
|
97
|
+
if (!u) {
|
|
99
98
|
const d = `Line '${s.to}' not found`;
|
|
100
99
|
return e(d), { success: !1, error: d };
|
|
101
100
|
}
|
|
102
|
-
const h = s.fromIsPercentage !== !1,
|
|
101
|
+
const h = s.fromIsPercentage !== !1, L = s.toIsPercentage !== !1;
|
|
103
102
|
if (!h && s.fromPosition === void 0) {
|
|
104
103
|
const d = "fromPosition is required when fromIsPercentage is false";
|
|
105
104
|
return e(d), { success: !1, error: d };
|
|
106
105
|
}
|
|
107
|
-
if (!
|
|
106
|
+
if (!L && s.toPosition === void 0) {
|
|
108
107
|
const d = "toPosition is required when toIsPercentage is false";
|
|
109
108
|
return e(d), { success: !1, error: d };
|
|
110
109
|
}
|
|
@@ -113,17 +112,17 @@ function oe() {
|
|
|
113
112
|
return e(d), { success: !1, error: d };
|
|
114
113
|
}
|
|
115
114
|
return r((d) => [...d, U(s)]), e(null), { success: !0 };
|
|
116
|
-
}, [t, V]), P = p((s, v,
|
|
115
|
+
}, [t, V]), P = p((s, v, u) => {
|
|
117
116
|
const h = V.findIndex((l) => l.fromLineId === s && l.toLineId === v);
|
|
118
117
|
if (h === -1) {
|
|
119
118
|
const l = `Connection from '${s}' to '${v}' not found`;
|
|
120
119
|
return e(l), { success: !1, error: l };
|
|
121
120
|
}
|
|
122
|
-
const
|
|
121
|
+
const L = V[h], Q = u.fromIsPercentage ?? L.fromIsPercentage, d = u.toIsPercentage ?? L.toIsPercentage;
|
|
123
122
|
let D;
|
|
124
|
-
|
|
125
|
-
let
|
|
126
|
-
if (
|
|
123
|
+
u.fromOffset !== void 0 ? D = u.fromOffset : L.fromOffset !== void 0 && (D = L.fromOffset);
|
|
124
|
+
let w;
|
|
125
|
+
if (u.toOffset !== void 0 ? w = u.toOffset : L.toOffset !== void 0 && (w = L.toOffset), D !== void 0) {
|
|
127
126
|
if (Q !== !1 && (D < 0 || D > 1)) {
|
|
128
127
|
const l = `Invalid fromOffset: ${D} (must be 0-1 for percentage)`;
|
|
129
128
|
return e(l), { success: !1, error: l };
|
|
@@ -133,13 +132,13 @@ function oe() {
|
|
|
133
132
|
return e(l), { success: !1, error: l };
|
|
134
133
|
}
|
|
135
134
|
}
|
|
136
|
-
if (
|
|
137
|
-
if (d !== !1 && (
|
|
138
|
-
const l = `Invalid toOffset: ${
|
|
135
|
+
if (w !== void 0) {
|
|
136
|
+
if (d !== !1 && (w < 0 || w > 1)) {
|
|
137
|
+
const l = `Invalid toOffset: ${w} (must be 0-1 for percentage)`;
|
|
139
138
|
return e(l), { success: !1, error: l };
|
|
140
139
|
}
|
|
141
|
-
if (d === !1 &&
|
|
142
|
-
const l = `Invalid toOffset: ${
|
|
140
|
+
if (d === !1 && w < 0) {
|
|
141
|
+
const l = `Invalid toOffset: ${w} (must be >= 0 for absolute distance)`;
|
|
143
142
|
return e(l), { success: !1, error: l };
|
|
144
143
|
}
|
|
145
144
|
}
|
|
@@ -147,7 +146,7 @@ function oe() {
|
|
|
147
146
|
const l = "fromOffset is required when fromIsPercentage is false";
|
|
148
147
|
return e(l), { success: !1, error: l };
|
|
149
148
|
}
|
|
150
|
-
if (d === !1 &&
|
|
149
|
+
if (d === !1 && w === void 0) {
|
|
151
150
|
const l = "toOffset is required when toIsPercentage is false";
|
|
152
151
|
return e(l), { success: !1, error: l };
|
|
153
152
|
}
|
|
@@ -156,7 +155,7 @@ function oe() {
|
|
|
156
155
|
to: v,
|
|
157
156
|
fromPosition: D,
|
|
158
157
|
fromIsPercentage: Q,
|
|
159
|
-
toPosition:
|
|
158
|
+
toPosition: w,
|
|
160
159
|
toIsPercentage: d
|
|
161
160
|
};
|
|
162
161
|
return r((l) => l.map(
|
|
@@ -167,7 +166,7 @@ function oe() {
|
|
|
167
166
|
const h = `Connection from '${s}' to '${v}' not found`;
|
|
168
167
|
return e(h), { success: !1, error: h };
|
|
169
168
|
}
|
|
170
|
-
return r((h) => h.filter((
|
|
169
|
+
return r((h) => h.filter((L) => !(L.fromLineId === s && L.toLineId === v))), e(null), { success: !0 };
|
|
171
170
|
}, [V]), c = p(() => {
|
|
172
171
|
o([]), r([]), e(null);
|
|
173
172
|
}, []);
|
|
@@ -178,7 +177,7 @@ function oe() {
|
|
|
178
177
|
addLine: O,
|
|
179
178
|
updateLine: T,
|
|
180
179
|
removeLine: y,
|
|
181
|
-
addConnection:
|
|
180
|
+
addConnection: C,
|
|
182
181
|
updateConnection: P,
|
|
183
182
|
removeConnection: I,
|
|
184
183
|
clear: c,
|
|
@@ -195,42 +194,42 @@ function ce({ lines: t, wheelbase: o }) {
|
|
|
195
194
|
f.current.some((Q) => Q.id === h.id) && c.push(`Vehicle with ID '${h.id}' already exists`);
|
|
196
195
|
if (c.length > 0)
|
|
197
196
|
return e(c.join("; ")), { success: !1, errors: c };
|
|
198
|
-
const s = I.map(Y), { vehicles: v, errors:
|
|
197
|
+
const s = I.map(Y), { vehicles: v, errors: u } = N(
|
|
199
198
|
s,
|
|
200
199
|
t,
|
|
201
200
|
o
|
|
202
201
|
);
|
|
203
|
-
return
|
|
202
|
+
return u.length > 0 ? (e(u.join("; ")), { success: !1, errors: u }) : (f.current = [...f.current, ...v], r(f.current), e(null), { success: !0 });
|
|
204
203
|
}, [t, o]), T = p((P, I) => {
|
|
205
|
-
const c = f.current.findIndex((
|
|
204
|
+
const c = f.current.findIndex((w) => w.id === P);
|
|
206
205
|
if (c === -1) {
|
|
207
|
-
const
|
|
208
|
-
return e(
|
|
206
|
+
const w = `Vehicle with ID '${P}' not found`;
|
|
207
|
+
return e(w), { success: !1, error: w };
|
|
209
208
|
}
|
|
210
209
|
const s = f.current[c];
|
|
211
210
|
if (s.state !== "idle") {
|
|
212
|
-
const
|
|
213
|
-
return e(
|
|
211
|
+
const w = `Cannot update vehicle '${P}' while it is ${s.state}. Vehicle must be idle.`;
|
|
212
|
+
return e(w), { success: !1, error: w };
|
|
214
213
|
}
|
|
215
214
|
const v = I.lineId ?? s.lineId;
|
|
216
|
-
if (!t.find((
|
|
217
|
-
const
|
|
218
|
-
return e(
|
|
215
|
+
if (!t.find((w) => w.id === v)) {
|
|
216
|
+
const w = `Line '${v}' not found`;
|
|
217
|
+
return e(w), { success: !1, error: w };
|
|
219
218
|
}
|
|
220
|
-
let h,
|
|
221
|
-
I.lineId !== void 0 && I.position === void 0 ? (h = 0,
|
|
219
|
+
let h, L;
|
|
220
|
+
I.lineId !== void 0 && I.position === void 0 ? (h = 0, L = !0) : I.position !== void 0 ? (h = I.position, L = I.isPercentage ?? !0) : (h = s.offset, L = s.isPercentage);
|
|
222
221
|
const Q = {
|
|
223
222
|
vehicleId: P,
|
|
224
223
|
lineId: v,
|
|
225
224
|
offset: h,
|
|
226
|
-
isPercentage:
|
|
225
|
+
isPercentage: L
|
|
227
226
|
}, { vehicles: d, errors: D } = N(
|
|
228
227
|
[Q],
|
|
229
228
|
t,
|
|
230
229
|
o
|
|
231
230
|
);
|
|
232
231
|
return D.length > 0 ? (e(D.join("; ")), { success: !1, error: D.join("; ") }) : (f.current = f.current.map(
|
|
233
|
-
(
|
|
232
|
+
(w, k) => k === c ? d[0] : w
|
|
234
233
|
), r(f.current), e(null), { success: !0 });
|
|
235
234
|
}, [t, o]), y = p((P) => {
|
|
236
235
|
if (!f.current.some((c) => c.id === P)) {
|
|
@@ -238,7 +237,7 @@ function ce({ lines: t, wheelbase: o }) {
|
|
|
238
237
|
return e(c), { success: !1, error: c };
|
|
239
238
|
}
|
|
240
239
|
return f.current = f.current.filter((c) => c.id !== P), r(f.current), e(null), { success: !0 };
|
|
241
|
-
}, []),
|
|
240
|
+
}, []), C = p(() => {
|
|
242
241
|
f.current = [], r([]), e(null);
|
|
243
242
|
}, []);
|
|
244
243
|
return {
|
|
@@ -246,17 +245,17 @@ function ce({ lines: t, wheelbase: o }) {
|
|
|
246
245
|
addVehicles: O,
|
|
247
246
|
updateVehicle: T,
|
|
248
247
|
removeVehicle: y,
|
|
249
|
-
clear:
|
|
248
|
+
clear: C,
|
|
250
249
|
error: m,
|
|
251
250
|
_loadVehicles: M
|
|
252
251
|
};
|
|
253
252
|
}
|
|
254
253
|
function ie({ vehicles: t, lines: o }) {
|
|
255
|
-
const [V, r] = _(/* @__PURE__ */ new Map()), [m, e] = _(null), f = A(/* @__PURE__ */ new Map()), M = p(() => f.current, []), O = p((
|
|
256
|
-
f.current =
|
|
257
|
-
}, []), T = p((
|
|
258
|
-
if (!t.some((d) => d.id ===
|
|
259
|
-
const d = `Vehicle '${
|
|
254
|
+
const [V, r] = _(/* @__PURE__ */ new Map()), [m, e] = _(null), f = A(/* @__PURE__ */ new Map()), M = p(() => f.current, []), O = p((C) => {
|
|
255
|
+
f.current = C, r(C), e(null);
|
|
256
|
+
}, []), T = p((C, P) => {
|
|
257
|
+
if (!t.some((d) => d.id === C)) {
|
|
258
|
+
const d = `Vehicle '${C}' not found`;
|
|
260
259
|
return e(d), { success: !1, error: d };
|
|
261
260
|
}
|
|
262
261
|
const c = o.find((d) => d.id === P.targetLineId);
|
|
@@ -269,32 +268,32 @@ function ie({ vehicles: t, lines: o }) {
|
|
|
269
268
|
const d = "targetPosition is required when isPercentage is false";
|
|
270
269
|
return e(d), { success: !1, error: d };
|
|
271
270
|
}
|
|
272
|
-
const
|
|
271
|
+
const u = P.targetPosition ?? 1;
|
|
273
272
|
if (s) {
|
|
274
|
-
if (
|
|
275
|
-
const d = `Invalid targetPosition: ${
|
|
273
|
+
if (u < 0 || u > 1) {
|
|
274
|
+
const d = `Invalid targetPosition: ${u} (must be 0-1 for percentage)`;
|
|
276
275
|
return e(d), { success: !1, error: d };
|
|
277
276
|
}
|
|
278
277
|
} else {
|
|
279
|
-
if (
|
|
280
|
-
const d = `Invalid targetPosition: ${
|
|
278
|
+
if (u < 0) {
|
|
279
|
+
const d = `Invalid targetPosition: ${u} (must be >= 0 for absolute distance)`;
|
|
281
280
|
return e(d), { success: !1, error: d };
|
|
282
281
|
}
|
|
283
|
-
if (
|
|
284
|
-
const d = `Position ${
|
|
282
|
+
if (u > v) {
|
|
283
|
+
const d = `Position ${u} exceeds line length ${v}`;
|
|
285
284
|
return e(d), { success: !1, error: d };
|
|
286
285
|
}
|
|
287
286
|
}
|
|
288
|
-
const h = Z({ vehicleId:
|
|
289
|
-
return
|
|
290
|
-
}, [t, o]), y = p((
|
|
291
|
-
if (
|
|
292
|
-
if (!t.some((c) => c.id ===
|
|
293
|
-
const c = `Vehicle '${
|
|
287
|
+
const h = Z({ vehicleId: C, ...P }), L = new Map(f.current), Q = L.get(C) || [];
|
|
288
|
+
return L.set(C, [...Q, h]), f.current = L, r(L), e(null), { success: !0 };
|
|
289
|
+
}, [t, o]), y = p((C) => {
|
|
290
|
+
if (C !== void 0) {
|
|
291
|
+
if (!t.some((c) => c.id === C)) {
|
|
292
|
+
const c = `Vehicle '${C}' not found`;
|
|
294
293
|
return e(c), { success: !1, error: c };
|
|
295
294
|
}
|
|
296
295
|
const I = new Map(f.current);
|
|
297
|
-
I.delete(
|
|
296
|
+
I.delete(C), f.current = I, r(I);
|
|
298
297
|
} else
|
|
299
298
|
f.current = /* @__PURE__ */ new Map(), r(/* @__PURE__ */ new Map());
|
|
300
299
|
return e(null), { success: !0 };
|
|
@@ -318,7 +317,7 @@ function Ve({
|
|
|
318
317
|
curves: f,
|
|
319
318
|
eventEmitter: M
|
|
320
319
|
}) {
|
|
321
|
-
const [O, T] = _([]), y = A([]),
|
|
320
|
+
const [O, T] = _([]), y = A([]), C = p((l) => {
|
|
322
321
|
typeof l == "function" ? T((n) => {
|
|
323
322
|
const i = l(n);
|
|
324
323
|
return y.current = i, i;
|
|
@@ -334,7 +333,7 @@ function Ve({
|
|
|
334
333
|
const { movingVehicles: l, stateMap: n } = te(t, c);
|
|
335
334
|
s.current = n;
|
|
336
335
|
const i = setTimeout(() => {
|
|
337
|
-
|
|
336
|
+
C(l);
|
|
338
337
|
}, 0);
|
|
339
338
|
return () => clearTimeout(i);
|
|
340
339
|
}, [t, c]);
|
|
@@ -342,27 +341,27 @@ function Ve({
|
|
|
342
341
|
K(() => {
|
|
343
342
|
o.length > 0 && (v.current = de(o, f, I));
|
|
344
343
|
}, [o, f, I]);
|
|
345
|
-
const
|
|
344
|
+
const u = A(0), h = A(!1), L = p((l) => {
|
|
346
345
|
if (!h.current) return !1;
|
|
347
346
|
let n = !1;
|
|
348
|
-
for (const [,
|
|
349
|
-
if (
|
|
347
|
+
for (const [, a] of s.current)
|
|
348
|
+
if (a.vehicle.state === "moving") {
|
|
350
349
|
n = !0;
|
|
351
350
|
break;
|
|
352
351
|
}
|
|
353
352
|
if (!n)
|
|
354
353
|
return !1;
|
|
355
354
|
const i = [];
|
|
356
|
-
for (const [
|
|
355
|
+
for (const [a, g] of s.current) {
|
|
357
356
|
if (g.vehicle.state !== "moving" || !g.execution) continue;
|
|
358
357
|
const x = g.execution;
|
|
359
358
|
let S;
|
|
360
359
|
if (x.front.currentSegmentIndex < x.path.segments.length) {
|
|
361
360
|
const j = x.path.segments[x.front.currentSegmentIndex];
|
|
362
361
|
if (j.type === "line") {
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
Math.pow(
|
|
362
|
+
const $ = c.get(j.lineId);
|
|
363
|
+
$ && (S = Math.sqrt(
|
|
364
|
+
Math.pow($.end.x - $.start.x, 2) + Math.pow($.end.y - $.start.y, 2)
|
|
366
365
|
));
|
|
367
366
|
}
|
|
368
367
|
}
|
|
@@ -387,7 +386,7 @@ function Ve({
|
|
|
387
386
|
rear: b.axleState,
|
|
388
387
|
front: q.axleState
|
|
389
388
|
}, g.execution.rear = b.execution, g.execution.front = q.execution, b.completed) {
|
|
390
|
-
const
|
|
389
|
+
const $ = me(g, {
|
|
391
390
|
linesMap: c,
|
|
392
391
|
config: I,
|
|
393
392
|
vehicleQueues: V,
|
|
@@ -397,15 +396,15 @@ function Ve({
|
|
|
397
396
|
onCommandComplete: (F) => i.push({ type: "commandComplete", data: F }),
|
|
398
397
|
onCommandStart: (F) => i.push({ type: "commandStart", data: F })
|
|
399
398
|
});
|
|
400
|
-
g.vehicle =
|
|
399
|
+
g.vehicle = $.vehicle, $.newExecution !== void 0 && (g.execution = $.newExecution), $.vehicle.state !== "moving" && i.push({
|
|
401
400
|
type: "stateChange",
|
|
402
|
-
data: { vehicleId:
|
|
401
|
+
data: { vehicleId: a, from: "moving", to: $.vehicle.state }
|
|
403
402
|
});
|
|
404
|
-
const E =
|
|
403
|
+
const E = $.vehicle.rear.position, R = $.vehicle.front.position;
|
|
405
404
|
i.push({
|
|
406
405
|
type: "positionUpdate",
|
|
407
406
|
data: {
|
|
408
|
-
vehicleId:
|
|
407
|
+
vehicleId: a,
|
|
409
408
|
rear: E,
|
|
410
409
|
front: R,
|
|
411
410
|
center: { x: (E.x + R.x) / 2, y: (E.y + R.y) / 2 },
|
|
@@ -414,48 +413,48 @@ function Ve({
|
|
|
414
413
|
});
|
|
415
414
|
}
|
|
416
415
|
}
|
|
417
|
-
if (
|
|
416
|
+
if (C((a) => a.map((g) => {
|
|
418
417
|
const x = s.current.get(g.id);
|
|
419
418
|
return x ? x.vehicle : g;
|
|
420
419
|
})), M && i.length > 0) {
|
|
421
|
-
const
|
|
420
|
+
const a = u.current;
|
|
422
421
|
setTimeout(() => {
|
|
423
|
-
|
|
422
|
+
u.current === a && i.forEach(({ type: g, data: x }) => {
|
|
424
423
|
M.emit(g, x);
|
|
425
424
|
});
|
|
426
425
|
}, 0);
|
|
427
426
|
}
|
|
428
|
-
for (const [,
|
|
429
|
-
if (
|
|
427
|
+
for (const [, a] of s.current)
|
|
428
|
+
if (a.vehicle.state === "moving")
|
|
430
429
|
return !0;
|
|
431
430
|
return h.current = !1, !1;
|
|
432
431
|
}, [c, f, I, V, M]), Q = p(() => {
|
|
433
432
|
const l = v.current;
|
|
434
433
|
if (!l) return !1;
|
|
435
434
|
const n = r ? r() : V, i = [];
|
|
436
|
-
let
|
|
435
|
+
let a = !1;
|
|
437
436
|
for (const [g, x] of s.current) {
|
|
438
437
|
const S = x.vehicle;
|
|
439
438
|
if (S.state === "moving") continue;
|
|
440
439
|
const b = n.get(g);
|
|
441
440
|
if (!b || b.length === 0) continue;
|
|
442
|
-
const q = b[0],
|
|
443
|
-
if (
|
|
441
|
+
const q = b[0], $ = B(S, q, { graph: l, linesMap: c, curves: f, config: I });
|
|
442
|
+
if (!$) {
|
|
444
443
|
console.warn(`No path found for vehicle ${g}`);
|
|
445
444
|
continue;
|
|
446
445
|
}
|
|
447
|
-
const E = se(
|
|
446
|
+
const E = se($.path, 0, 0, m);
|
|
448
447
|
s.current.set(g, {
|
|
449
448
|
...x,
|
|
450
449
|
execution: {
|
|
451
|
-
path:
|
|
452
|
-
curveDataMap:
|
|
450
|
+
path: $.path,
|
|
451
|
+
curveDataMap: $.curveDataMap,
|
|
453
452
|
currentCommandIndex: 0,
|
|
454
453
|
rear: { currentSegmentIndex: 0, segmentDistance: 0 },
|
|
455
454
|
front: E ? { currentSegmentIndex: E.segmentIndex, segmentDistance: E.segmentDistance } : { currentSegmentIndex: 0, segmentDistance: 0 }
|
|
456
455
|
},
|
|
457
456
|
vehicle: { ...S, state: "moving" }
|
|
458
|
-
}),
|
|
457
|
+
}), a = !0, i.push({
|
|
459
458
|
id: g,
|
|
460
459
|
fromState: S.state,
|
|
461
460
|
command: q,
|
|
@@ -466,14 +465,14 @@ function Ve({
|
|
|
466
465
|
}
|
|
467
466
|
});
|
|
468
467
|
}
|
|
469
|
-
if (!
|
|
470
|
-
if (h.current = !0,
|
|
468
|
+
if (!a) return !1;
|
|
469
|
+
if (h.current = !0, C((g) => g.map((x) => {
|
|
471
470
|
const S = s.current.get(x.id);
|
|
472
471
|
return S ? S.vehicle : x;
|
|
473
472
|
})), M && i.length > 0) {
|
|
474
|
-
const g =
|
|
473
|
+
const g = u.current;
|
|
475
474
|
setTimeout(() => {
|
|
476
|
-
|
|
475
|
+
u.current === g && i.forEach(({ id: x, fromState: S, command: b, startPosition: q }) => {
|
|
477
476
|
M.emit("commandStart", {
|
|
478
477
|
vehicleId: x,
|
|
479
478
|
command: b,
|
|
@@ -489,23 +488,23 @@ function Ve({
|
|
|
489
488
|
}
|
|
490
489
|
return !0;
|
|
491
490
|
}, [c, f, V, r, I, m, M]), d = p(() => {
|
|
492
|
-
|
|
491
|
+
u.current++, h.current = !1;
|
|
493
492
|
const { movingVehicles: l, stateMap: n } = te(t, c);
|
|
494
|
-
s.current = n,
|
|
493
|
+
s.current = n, C(l);
|
|
495
494
|
}, [t, c]), D = p((l) => {
|
|
496
495
|
const n = t.find((x) => x.id === l);
|
|
497
496
|
if (!n || !c.get(n.lineId)) return;
|
|
498
|
-
const
|
|
499
|
-
s.current.set(l, g),
|
|
500
|
-
(S) => S.id === l ?
|
|
497
|
+
const a = ge(n), g = he(a);
|
|
498
|
+
s.current.set(l, g), C((x) => x.map(
|
|
499
|
+
(S) => S.id === l ? a : S
|
|
501
500
|
));
|
|
502
|
-
}, [t, c]),
|
|
501
|
+
}, [t, c]), w = p((l) => {
|
|
503
502
|
const n = s.current.get(l);
|
|
504
503
|
if (!n || n.vehicle.state !== "waiting")
|
|
505
504
|
return !1;
|
|
506
|
-
const i = V.get(l),
|
|
507
|
-
if (!
|
|
508
|
-
const g =
|
|
505
|
+
const i = V.get(l), a = n.execution;
|
|
506
|
+
if (!a) return !1;
|
|
507
|
+
const g = a.currentCommandIndex + 1;
|
|
509
508
|
if (i && g < i.length) {
|
|
510
509
|
const x = v.current;
|
|
511
510
|
if (x) {
|
|
@@ -518,10 +517,10 @@ function Ve({
|
|
|
518
517
|
currentCommandIndex: g,
|
|
519
518
|
rear: { currentSegmentIndex: 0, segmentDistance: 0 },
|
|
520
519
|
front: j ? { currentSegmentIndex: j.segmentIndex, segmentDistance: j.segmentDistance } : { currentSegmentIndex: 0, segmentDistance: 0 }
|
|
521
|
-
}, n.vehicle = { ...n.vehicle, state: "moving" },
|
|
522
|
-
const
|
|
520
|
+
}, n.vehicle = { ...n.vehicle, state: "moving" }, C(($) => $.map((E) => E.id === l ? n.vehicle : E)), M) {
|
|
521
|
+
const $ = u.current;
|
|
523
522
|
setTimeout(() => {
|
|
524
|
-
|
|
523
|
+
u.current === $ && M.emit("stateChange", {
|
|
525
524
|
vehicleId: l,
|
|
526
525
|
from: "waiting",
|
|
527
526
|
to: "moving"
|
|
@@ -532,10 +531,10 @@ function Ve({
|
|
|
532
531
|
}
|
|
533
532
|
}
|
|
534
533
|
}
|
|
535
|
-
if (n.vehicle = { ...n.vehicle, state: "idle" }, n.execution = null,
|
|
536
|
-
const x =
|
|
534
|
+
if (n.vehicle = { ...n.vehicle, state: "idle" }, n.execution = null, C((x) => x.map((S) => S.id === l ? n.vehicle : S)), M) {
|
|
535
|
+
const x = u.current;
|
|
537
536
|
setTimeout(() => {
|
|
538
|
-
|
|
537
|
+
u.current === x && M.emit("stateChange", {
|
|
539
538
|
vehicleId: l,
|
|
540
539
|
from: "waiting",
|
|
541
540
|
to: "idle"
|
|
@@ -553,10 +552,10 @@ function Ve({
|
|
|
553
552
|
movingVehicles: O,
|
|
554
553
|
getMovingVehicles: P,
|
|
555
554
|
prepare: Q,
|
|
556
|
-
tick:
|
|
555
|
+
tick: L,
|
|
557
556
|
reset: d,
|
|
558
557
|
resetVehicle: D,
|
|
559
|
-
continueVehicle:
|
|
558
|
+
continueVehicle: w,
|
|
560
559
|
isMoving: k,
|
|
561
560
|
isPrepared: h.current
|
|
562
561
|
};
|
|
@@ -583,18 +582,18 @@ function ye({
|
|
|
583
582
|
const i = r.addLine(n);
|
|
584
583
|
return i.success ? { success: !0 } : { success: !1, error: i.error };
|
|
585
584
|
}, [r]), y = p((n, i) => {
|
|
586
|
-
const
|
|
587
|
-
return
|
|
588
|
-
}, [r]),
|
|
589
|
-
const i = [],
|
|
590
|
-
|
|
585
|
+
const a = r.updateLine(n, i);
|
|
586
|
+
return a.success ? { success: !0 } : { success: !1, error: a.error };
|
|
587
|
+
}, [r]), C = p((n) => {
|
|
588
|
+
const i = [], a = M(n);
|
|
589
|
+
a.length > 0 && (i.push({
|
|
591
590
|
type: "vehicle_on_removed_line",
|
|
592
|
-
message: `${
|
|
591
|
+
message: `${a.length} vehicle(s) are on line '${n}'`,
|
|
593
592
|
details: {
|
|
594
593
|
lineId: n,
|
|
595
|
-
vehicleIds:
|
|
594
|
+
vehicleIds: a.map((S) => S.id)
|
|
596
595
|
}
|
|
597
|
-
}),
|
|
596
|
+
}), a.forEach((S) => {
|
|
598
597
|
m.removeVehicle(S.id), e.clearQueue(S.id);
|
|
599
598
|
}));
|
|
600
599
|
const g = r.curves.filter(
|
|
@@ -615,33 +614,33 @@ function ye({
|
|
|
615
614
|
} : { success: !1, error: x.error };
|
|
616
615
|
}, [r, M, m, e]), P = p(() => {
|
|
617
616
|
r.clear(), m.clear(), e.clearQueue();
|
|
618
|
-
}, [r, m, e]), I = p((n, i,
|
|
617
|
+
}, [r, m, e]), I = p((n, i, a) => {
|
|
619
618
|
const g = r.addConnection({
|
|
620
619
|
from: n,
|
|
621
620
|
to: i,
|
|
622
|
-
fromPosition:
|
|
623
|
-
fromIsPercentage:
|
|
624
|
-
toPosition:
|
|
625
|
-
toIsPercentage:
|
|
621
|
+
fromPosition: a?.fromOffset,
|
|
622
|
+
fromIsPercentage: a?.fromIsPercentage,
|
|
623
|
+
toPosition: a?.toOffset,
|
|
624
|
+
toIsPercentage: a?.toIsPercentage
|
|
626
625
|
});
|
|
627
626
|
return g.success ? { success: !0 } : { success: !1, error: g.error };
|
|
628
|
-
}, [r]), c = p((n, i,
|
|
629
|
-
const g = r.updateConnection(n, i,
|
|
627
|
+
}, [r]), c = p((n, i, a) => {
|
|
628
|
+
const g = r.updateConnection(n, i, a);
|
|
630
629
|
return g.success ? { success: !0 } : { success: !1, error: g.error };
|
|
631
630
|
}, [r]), s = p((n, i) => {
|
|
632
|
-
const
|
|
633
|
-
return
|
|
631
|
+
const a = r.removeConnection(n, i);
|
|
632
|
+
return a.success ? { success: !0 } : { success: !1, error: a.error };
|
|
634
633
|
}, [r]), v = p((n) => {
|
|
635
634
|
const i = m.addVehicles(n);
|
|
636
635
|
return i.success ? { success: !0 } : { success: !1, error: i.errors?.join("; ") };
|
|
637
|
-
}, [m]),
|
|
638
|
-
const
|
|
639
|
-
return
|
|
636
|
+
}, [m]), u = p((n, i) => {
|
|
637
|
+
const a = m.updateVehicle(n, i);
|
|
638
|
+
return a.success ? { success: !0 } : { success: !1, error: a.error };
|
|
640
639
|
}, [m]), h = p((n) => {
|
|
641
|
-
const i = [],
|
|
642
|
-
|
|
640
|
+
const i = [], a = e.vehicleQueues.get(n);
|
|
641
|
+
a && a.length > 0 && (i.push({
|
|
643
642
|
type: "movement_queue_cleared",
|
|
644
|
-
message: `${
|
|
643
|
+
message: `${a.length} queued movement(s) will be cleared for vehicle '${n}'`,
|
|
645
644
|
details: {
|
|
646
645
|
vehicleId: n
|
|
647
646
|
}
|
|
@@ -651,59 +650,57 @@ function ye({
|
|
|
651
650
|
success: !0,
|
|
652
651
|
warnings: i.length > 0 ? i : void 0
|
|
653
652
|
} : { success: !1, error: g.error };
|
|
654
|
-
}, [m, e]),
|
|
653
|
+
}, [m, e]), L = p(() => {
|
|
655
654
|
m.clear(), e.clearQueue();
|
|
656
655
|
}, [m, e]), Q = p((n) => {
|
|
657
656
|
const i = {
|
|
658
657
|
targetLineId: n.lineId,
|
|
659
658
|
targetPosition: n.position ?? 1,
|
|
660
659
|
isPercentage: n.isPercentage,
|
|
661
|
-
wait: n.wait,
|
|
662
660
|
payload: n.payload
|
|
663
|
-
},
|
|
664
|
-
return
|
|
661
|
+
}, a = e.queueMovement(n.id, i);
|
|
662
|
+
return a.success ? { success: !0 } : { success: !1, error: a.error };
|
|
665
663
|
}, [e]), d = p((n) => {
|
|
666
664
|
const i = e.clearQueue(n);
|
|
667
665
|
return i.success ? { success: !0 } : { success: !1, error: i.error };
|
|
668
666
|
}, [e]), D = p((n) => {
|
|
669
667
|
e.clearQueue(n), f.resetVehicle(n);
|
|
670
|
-
}, [e, f]),
|
|
671
|
-
const i = [],
|
|
672
|
-
g.errors.length > 0 &&
|
|
673
|
-
const b = g.data.lines.map(H), q = (g.data.connections || []).map(U), j = x.data.map(Y), { vehicles:
|
|
674
|
-
E.length > 0 &&
|
|
668
|
+
}, [e, f]), w = p((n) => {
|
|
669
|
+
const i = [], a = [], { scene: g, vehicles: x, movements: S } = ve(n);
|
|
670
|
+
g.errors.length > 0 && a.push(...g.errors), x.errors.length > 0 && a.push(...x.errors), S.errors.length > 0 && a.push(...S.errors);
|
|
671
|
+
const b = g.data.lines.map(H), q = (g.data.connections || []).map(U), j = x.data.map(Y), { vehicles: $, errors: E } = N(j, b, t);
|
|
672
|
+
E.length > 0 && a.push(...E);
|
|
675
673
|
const R = /* @__PURE__ */ new Map();
|
|
676
674
|
for (const F of S.data) {
|
|
677
675
|
const ee = R.get(F.vehicleId) || [];
|
|
678
676
|
ee.push(Z(F)), R.set(F.vehicleId, ee);
|
|
679
677
|
}
|
|
680
|
-
return r._loadScene(b, q), m._loadVehicles(
|
|
678
|
+
return r._loadScene(b, q), m._loadVehicles($), e._loadQueues(R), a.length > 0 && i.push({
|
|
681
679
|
type: "dsl_parse_error",
|
|
682
|
-
message: `DSL loading had ${
|
|
683
|
-
details: { errors:
|
|
680
|
+
message: `DSL loading had ${a.length} error(s)`,
|
|
681
|
+
details: { errors: a }
|
|
684
682
|
}), {
|
|
685
683
|
success: !0,
|
|
686
684
|
warnings: i.length > 0 ? i : void 0
|
|
687
685
|
};
|
|
688
686
|
}, [r, m, e, t]), k = p((n) => {
|
|
689
|
-
const i = [],
|
|
690
|
-
q.length > 0 &&
|
|
687
|
+
const i = [], a = [], g = n.lines.map(H), x = (n.connections || []).map(U), S = (n.vehicles || []).map(Y), { vehicles: b, errors: q } = N(S, g, t);
|
|
688
|
+
q.length > 0 && a.push(...q);
|
|
691
689
|
const j = /* @__PURE__ */ new Map();
|
|
692
|
-
for (const
|
|
693
|
-
const E = j.get(
|
|
690
|
+
for (const $ of n.movements || []) {
|
|
691
|
+
const E = j.get($.vehicleId) || [];
|
|
694
692
|
E.push(Z({
|
|
695
|
-
vehicleId:
|
|
696
|
-
targetLineId:
|
|
697
|
-
targetPosition:
|
|
698
|
-
isPercentage:
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
return r._loadScene(g, x), m._loadVehicles(b), e._loadQueues(j), u.length > 0 && i.push({
|
|
693
|
+
vehicleId: $.vehicleId,
|
|
694
|
+
targetLineId: $.targetLineId,
|
|
695
|
+
targetPosition: $.targetPosition,
|
|
696
|
+
isPercentage: $.isPercentage,
|
|
697
|
+
payload: $.payload
|
|
698
|
+
})), j.set($.vehicleId, E);
|
|
699
|
+
}
|
|
700
|
+
return r._loadScene(g, x), m._loadVehicles(b), e._loadQueues(j), a.length > 0 && i.push({
|
|
704
701
|
type: "dsl_parse_error",
|
|
705
|
-
message: `JSON loading had ${
|
|
706
|
-
details: { errors:
|
|
702
|
+
message: `JSON loading had ${a.length} error(s)`,
|
|
703
|
+
details: { errors: a }
|
|
707
704
|
}), {
|
|
708
705
|
success: !0,
|
|
709
706
|
warnings: i.length > 0 ? i : void 0
|
|
@@ -721,7 +718,7 @@ function ye({
|
|
|
721
718
|
// Scene operations
|
|
722
719
|
addLine: T,
|
|
723
720
|
updateLine: y,
|
|
724
|
-
removeLine:
|
|
721
|
+
removeLine: C,
|
|
725
722
|
clearScene: P,
|
|
726
723
|
// Connection operations
|
|
727
724
|
connect: I,
|
|
@@ -729,9 +726,9 @@ function ye({
|
|
|
729
726
|
disconnect: s,
|
|
730
727
|
// Vehicle operations
|
|
731
728
|
addVehicles: v,
|
|
732
|
-
updateVehicle:
|
|
729
|
+
updateVehicle: u,
|
|
733
730
|
removeVehicle: h,
|
|
734
|
-
clearVehicles:
|
|
731
|
+
clearVehicles: L,
|
|
735
732
|
// Movement operations
|
|
736
733
|
goto: Q,
|
|
737
734
|
clearQueue: d,
|
|
@@ -744,7 +741,7 @@ function ye({
|
|
|
744
741
|
continueVehicle: f.continueVehicle,
|
|
745
742
|
isMoving: f.isMoving,
|
|
746
743
|
// DSL Loading
|
|
747
|
-
loadFromDSL:
|
|
744
|
+
loadFromDSL: w,
|
|
748
745
|
// JSON Loading
|
|
749
746
|
loadFromJSON: k,
|
|
750
747
|
// Utility
|
|
@@ -811,7 +808,7 @@ function Ee() {
|
|
|
811
808
|
M.current = !0, o(v), setTimeout(() => {
|
|
812
809
|
M.current = !1;
|
|
813
810
|
}, 50);
|
|
814
|
-
}, [m, e, f]),
|
|
811
|
+
}, [m, e, f]), C = p((P) => {
|
|
815
812
|
const I = typeof P == "function" ? P(e) : P, c = X(I);
|
|
816
813
|
f({
|
|
817
814
|
lines: z(m),
|
|
@@ -835,19 +832,19 @@ function Ee() {
|
|
|
835
832
|
debounceKey: 0,
|
|
836
833
|
// Kept for API compatibility
|
|
837
834
|
setLines: y,
|
|
838
|
-
setCurves:
|
|
835
|
+
setCurves: C,
|
|
839
836
|
setSceneDefinitionText: T
|
|
840
837
|
};
|
|
841
838
|
}
|
|
842
839
|
function De({ lines: t, wheelbase: o }) {
|
|
843
|
-
const [V, r] = _(""), [m, e] = _(null), { vehicles: f, addVehicles: M, clear: O, error: T } = ce({ lines: t, wheelbase: o }), y = A(!1),
|
|
840
|
+
const [V, r] = _(""), [m, e] = _(null), { vehicles: f, addVehicles: M, clear: O, error: T } = ce({ lines: t, wheelbase: o }), y = A(!1), C = p((P) => {
|
|
844
841
|
y.current = !0, r(P);
|
|
845
842
|
try {
|
|
846
843
|
const { data: I, errors: c } = Pe(P), s = [...c];
|
|
847
844
|
O();
|
|
848
845
|
for (const v of I) {
|
|
849
|
-
const
|
|
850
|
-
!
|
|
846
|
+
const u = M(v);
|
|
847
|
+
!u.success && u.errors && s.push(...u.errors);
|
|
851
848
|
}
|
|
852
849
|
s.length > 0 ? e(s.join(`
|
|
853
850
|
`)) : e(null);
|
|
@@ -866,29 +863,28 @@ function De({ lines: t, wheelbase: o }) {
|
|
|
866
863
|
// No debouncing - parsing is immediate
|
|
867
864
|
debounceKey: 0,
|
|
868
865
|
// Kept for API compatibility
|
|
869
|
-
setInitialMovementText:
|
|
866
|
+
setInitialMovementText: C
|
|
870
867
|
};
|
|
871
868
|
}
|
|
872
869
|
function Oe({ lines: t, vehicles: o }) {
|
|
873
|
-
const [V, r] = _(""), [m, e] = _([]), [f, M] = _(null), { vehicleQueues: O, queueMovement: T, clearQueue: y, error:
|
|
870
|
+
const [V, r] = _(""), [m, e] = _([]), [f, M] = _(null), { vehicleQueues: O, queueMovement: T, clearQueue: y, error: C } = ie({
|
|
874
871
|
vehicles: o,
|
|
875
872
|
lines: t
|
|
876
873
|
}), P = A(!1), I = p((c) => {
|
|
877
874
|
P.current = !0, r(c);
|
|
878
875
|
try {
|
|
879
|
-
const { data: s, errors: v } = Ie(c),
|
|
876
|
+
const { data: s, errors: v } = Ie(c), u = [...v];
|
|
880
877
|
y();
|
|
881
878
|
for (const h of s) {
|
|
882
|
-
const
|
|
879
|
+
const L = T(h.vehicleId, {
|
|
883
880
|
targetLineId: h.targetLineId,
|
|
884
881
|
targetPosition: h.targetPosition,
|
|
885
882
|
isPercentage: h.isPercentage,
|
|
886
|
-
wait: h.wait,
|
|
887
883
|
payload: h.payload
|
|
888
884
|
});
|
|
889
|
-
!
|
|
885
|
+
!L.success && L.error && u.push(L.error);
|
|
890
886
|
}
|
|
891
|
-
e(s),
|
|
887
|
+
e(s), u.length > 0 ? M(u.join(`
|
|
892
888
|
`)) : M(null);
|
|
893
889
|
} catch (s) {
|
|
894
890
|
M(s instanceof Error ? s.message : "Invalid movement sequence"), e([]);
|
|
@@ -901,7 +897,7 @@ function Oe({ lines: t, vehicles: o }) {
|
|
|
901
897
|
movementSequenceText: V,
|
|
902
898
|
gotoCommands: m,
|
|
903
899
|
vehicleQueues: O,
|
|
904
|
-
sequenceError: f ||
|
|
900
|
+
sequenceError: f || C,
|
|
905
901
|
isDebouncing: !1,
|
|
906
902
|
// No debouncing - parsing is immediate
|
|
907
903
|
debounceKey: 0,
|
|
@@ -909,9 +905,9 @@ function Oe({ lines: t, vehicles: o }) {
|
|
|
909
905
|
setMovementSequenceText: I
|
|
910
906
|
};
|
|
911
907
|
}
|
|
912
|
-
const
|
|
908
|
+
const ue = ae(null);
|
|
913
909
|
function Se() {
|
|
914
|
-
const t = le(
|
|
910
|
+
const t = le(ue);
|
|
915
911
|
if (!t)
|
|
916
912
|
throw new Error("useVehicleEventEmitter must be used within a VehicleEventProvider");
|
|
917
913
|
return t;
|
|
@@ -925,10 +921,10 @@ function qe(t, o, V = []) {
|
|
|
925
921
|
}
|
|
926
922
|
function be({ children: t }) {
|
|
927
923
|
const o = G(() => new ne(), []);
|
|
928
|
-
return /* @__PURE__ */ xe(
|
|
924
|
+
return /* @__PURE__ */ xe(ue.Provider, { value: o, children: t });
|
|
929
925
|
}
|
|
930
926
|
export {
|
|
931
|
-
|
|
927
|
+
ue as V,
|
|
932
928
|
be as a,
|
|
933
929
|
Te as b,
|
|
934
930
|
De as c,
|