astar-visualizer 1.0.7 → 1.0.8
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/astar-visualizer.js +649 -426
- package/dist/astar-visualizer.umd.cjs +5 -5
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/astar-visualizer.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
const
|
|
1
|
+
import { jsx as v, jsxs as N } from "react/jsx-runtime";
|
|
2
|
+
import z, { useState as ee, useEffect as te, useRef as ne } from "react";
|
|
3
|
+
const U = (e) => {
|
|
4
4
|
let t;
|
|
5
|
-
const r = /* @__PURE__ */ new Set(),
|
|
6
|
-
const
|
|
7
|
-
if (!Object.is(
|
|
8
|
-
const
|
|
9
|
-
t =
|
|
5
|
+
const r = /* @__PURE__ */ new Set(), s = (d, c) => {
|
|
6
|
+
const u = typeof d == "function" ? d(t) : d;
|
|
7
|
+
if (!Object.is(u, t)) {
|
|
8
|
+
const f = t;
|
|
9
|
+
t = c ?? (typeof u != "object" || u === null) ? u : Object.assign({}, t, u), r.forEach((h) => h(t, f));
|
|
10
10
|
}
|
|
11
|
-
},
|
|
11
|
+
}, n = () => t, w = { setState: s, getState: n, getInitialState: () => i, subscribe: (d) => (r.add(d), () => r.delete(d)), destroy: () => {
|
|
12
12
|
r.clear();
|
|
13
|
-
} },
|
|
14
|
-
return
|
|
15
|
-
},
|
|
16
|
-
function
|
|
13
|
+
} }, i = t = e(s, n, w);
|
|
14
|
+
return w;
|
|
15
|
+
}, se = (e) => e ? U(e) : U;
|
|
16
|
+
function ae(e) {
|
|
17
17
|
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
18
18
|
}
|
|
19
|
-
var
|
|
19
|
+
var B = { exports: {} }, k = {}, V = { exports: {} }, W = {};
|
|
20
20
|
/**
|
|
21
21
|
* @license React
|
|
22
22
|
* use-sync-external-store-shim.production.js
|
|
@@ -26,49 +26,49 @@ var M = { exports: {} }, A = {}, L = { exports: {} }, D = {};
|
|
|
26
26
|
* This source code is licensed under the MIT license found in the
|
|
27
27
|
* LICENSE file in the root directory of this source tree.
|
|
28
28
|
*/
|
|
29
|
-
var
|
|
30
|
-
function
|
|
31
|
-
if (
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
var e =
|
|
35
|
-
function t(
|
|
36
|
-
return
|
|
29
|
+
var q;
|
|
30
|
+
function le() {
|
|
31
|
+
if (q)
|
|
32
|
+
return W;
|
|
33
|
+
q = 1;
|
|
34
|
+
var e = z;
|
|
35
|
+
function t(c, u) {
|
|
36
|
+
return c === u && (c !== 0 || 1 / c === 1 / u) || c !== c && u !== u;
|
|
37
37
|
}
|
|
38
|
-
var r = typeof Object.is == "function" ? Object.is : t,
|
|
39
|
-
function
|
|
40
|
-
var
|
|
41
|
-
return
|
|
38
|
+
var r = typeof Object.is == "function" ? Object.is : t, s = e.useState, n = e.useEffect, o = e.useLayoutEffect, l = e.useDebugValue;
|
|
39
|
+
function p(c, u) {
|
|
40
|
+
var f = u(), h = s({ inst: { value: f, getSnapshot: u } }), m = h[0].inst, S = h[1];
|
|
41
|
+
return o(
|
|
42
42
|
function() {
|
|
43
|
-
|
|
43
|
+
m.value = f, m.getSnapshot = u, w(m) && S({ inst: m });
|
|
44
44
|
},
|
|
45
|
-
[
|
|
46
|
-
),
|
|
45
|
+
[c, f, u]
|
|
46
|
+
), n(
|
|
47
47
|
function() {
|
|
48
|
-
return
|
|
49
|
-
|
|
48
|
+
return w(m) && S({ inst: m }), c(function() {
|
|
49
|
+
w(m) && S({ inst: m });
|
|
50
50
|
});
|
|
51
51
|
},
|
|
52
|
-
[
|
|
53
|
-
),
|
|
52
|
+
[c]
|
|
53
|
+
), l(f), f;
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
var
|
|
57
|
-
|
|
55
|
+
function w(c) {
|
|
56
|
+
var u = c.getSnapshot;
|
|
57
|
+
c = c.value;
|
|
58
58
|
try {
|
|
59
|
-
var
|
|
60
|
-
return !r(
|
|
59
|
+
var f = u();
|
|
60
|
+
return !r(c, f);
|
|
61
61
|
} catch {
|
|
62
62
|
return !0;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
function
|
|
66
|
-
return
|
|
65
|
+
function i(c, u) {
|
|
66
|
+
return u();
|
|
67
67
|
}
|
|
68
|
-
var
|
|
69
|
-
return
|
|
68
|
+
var d = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? i : p;
|
|
69
|
+
return W.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : d, W;
|
|
70
70
|
}
|
|
71
|
-
var
|
|
71
|
+
var P = {};
|
|
72
72
|
/**
|
|
73
73
|
* @license React
|
|
74
74
|
* use-sync-external-store-shim.development.js
|
|
@@ -78,62 +78,62 @@ var z = {};
|
|
|
78
78
|
* This source code is licensed under the MIT license found in the
|
|
79
79
|
* LICENSE file in the root directory of this source tree.
|
|
80
80
|
*/
|
|
81
|
-
var
|
|
82
|
-
function
|
|
83
|
-
return
|
|
84
|
-
function e(
|
|
85
|
-
return
|
|
81
|
+
var J;
|
|
82
|
+
function ie() {
|
|
83
|
+
return J || (J = 1, process.env.NODE_ENV !== "production" && function() {
|
|
84
|
+
function e(f, h) {
|
|
85
|
+
return f === h && (f !== 0 || 1 / f === 1 / h) || f !== f && h !== h;
|
|
86
86
|
}
|
|
87
|
-
function t(
|
|
88
|
-
|
|
87
|
+
function t(f, h) {
|
|
88
|
+
d || n.startTransition === void 0 || (d = !0, console.error(
|
|
89
89
|
"You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."
|
|
90
90
|
));
|
|
91
|
-
var
|
|
92
|
-
if (!
|
|
93
|
-
var
|
|
94
|
-
|
|
91
|
+
var m = h();
|
|
92
|
+
if (!c) {
|
|
93
|
+
var S = h();
|
|
94
|
+
o(m, S) || (console.error(
|
|
95
95
|
"The result of getSnapshot should be cached to avoid an infinite loop"
|
|
96
|
-
),
|
|
96
|
+
), c = !0);
|
|
97
97
|
}
|
|
98
|
-
|
|
99
|
-
inst: { value:
|
|
98
|
+
S = l({
|
|
99
|
+
inst: { value: m, getSnapshot: h }
|
|
100
100
|
});
|
|
101
|
-
var E =
|
|
102
|
-
return
|
|
101
|
+
var E = S[0].inst, O = S[1];
|
|
102
|
+
return w(
|
|
103
103
|
function() {
|
|
104
|
-
E.value =
|
|
104
|
+
E.value = m, E.getSnapshot = h, r(E) && O({ inst: E });
|
|
105
105
|
},
|
|
106
|
-
[
|
|
107
|
-
),
|
|
106
|
+
[f, m, h]
|
|
107
|
+
), p(
|
|
108
108
|
function() {
|
|
109
|
-
return r(E) && O({ inst: E }),
|
|
109
|
+
return r(E) && O({ inst: E }), f(function() {
|
|
110
110
|
r(E) && O({ inst: E });
|
|
111
111
|
});
|
|
112
112
|
},
|
|
113
|
-
[
|
|
114
|
-
),
|
|
113
|
+
[f]
|
|
114
|
+
), i(m), m;
|
|
115
115
|
}
|
|
116
|
-
function r(
|
|
117
|
-
var
|
|
118
|
-
|
|
116
|
+
function r(f) {
|
|
117
|
+
var h = f.getSnapshot;
|
|
118
|
+
f = f.value;
|
|
119
119
|
try {
|
|
120
|
-
var
|
|
121
|
-
return !
|
|
120
|
+
var m = h();
|
|
121
|
+
return !o(f, m);
|
|
122
122
|
} catch {
|
|
123
123
|
return !0;
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
|
-
function
|
|
127
|
-
return
|
|
126
|
+
function s(f, h) {
|
|
127
|
+
return h();
|
|
128
128
|
}
|
|
129
129
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
130
|
-
var
|
|
131
|
-
|
|
132
|
-
}()),
|
|
130
|
+
var n = z, o = typeof Object.is == "function" ? Object.is : e, l = n.useState, p = n.useEffect, w = n.useLayoutEffect, i = n.useDebugValue, d = !1, c = !1, u = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? s : t;
|
|
131
|
+
P.useSyncExternalStore = n.useSyncExternalStore !== void 0 ? n.useSyncExternalStore : u, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
132
|
+
}()), P;
|
|
133
133
|
}
|
|
134
|
-
var
|
|
135
|
-
function
|
|
136
|
-
return
|
|
134
|
+
var Y;
|
|
135
|
+
function re() {
|
|
136
|
+
return Y || (Y = 1, process.env.NODE_ENV === "production" ? V.exports = le() : V.exports = ie()), V.exports;
|
|
137
137
|
}
|
|
138
138
|
/**
|
|
139
139
|
* @license React
|
|
@@ -144,61 +144,61 @@ function K() {
|
|
|
144
144
|
* This source code is licensed under the MIT license found in the
|
|
145
145
|
* LICENSE file in the root directory of this source tree.
|
|
146
146
|
*/
|
|
147
|
-
var
|
|
148
|
-
function
|
|
149
|
-
if (
|
|
150
|
-
return
|
|
151
|
-
|
|
152
|
-
var e =
|
|
153
|
-
function r(
|
|
154
|
-
return
|
|
147
|
+
var Q;
|
|
148
|
+
function ce() {
|
|
149
|
+
if (Q)
|
|
150
|
+
return k;
|
|
151
|
+
Q = 1;
|
|
152
|
+
var e = z, t = re();
|
|
153
|
+
function r(i, d) {
|
|
154
|
+
return i === d && (i !== 0 || 1 / i === 1 / d) || i !== i && d !== d;
|
|
155
155
|
}
|
|
156
|
-
var
|
|
157
|
-
return
|
|
158
|
-
var
|
|
159
|
-
if (
|
|
160
|
-
var
|
|
161
|
-
|
|
156
|
+
var s = typeof Object.is == "function" ? Object.is : r, n = t.useSyncExternalStore, o = e.useRef, l = e.useEffect, p = e.useMemo, w = e.useDebugValue;
|
|
157
|
+
return k.useSyncExternalStoreWithSelector = function(i, d, c, u, f) {
|
|
158
|
+
var h = o(null);
|
|
159
|
+
if (h.current === null) {
|
|
160
|
+
var m = { hasValue: !1, value: null };
|
|
161
|
+
h.current = m;
|
|
162
162
|
} else
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
m = h.current;
|
|
164
|
+
h = p(
|
|
165
165
|
function() {
|
|
166
|
-
function E(
|
|
166
|
+
function E(_) {
|
|
167
167
|
if (!O) {
|
|
168
|
-
if (O = !0,
|
|
169
|
-
var
|
|
170
|
-
if (
|
|
171
|
-
return
|
|
168
|
+
if (O = !0, b = _, _ = u(_), f !== void 0 && m.hasValue) {
|
|
169
|
+
var C = m.value;
|
|
170
|
+
if (f(C, _))
|
|
171
|
+
return M = C;
|
|
172
172
|
}
|
|
173
|
-
return
|
|
173
|
+
return M = _;
|
|
174
174
|
}
|
|
175
|
-
if (
|
|
176
|
-
return
|
|
177
|
-
var
|
|
178
|
-
return
|
|
175
|
+
if (C = M, s(b, _))
|
|
176
|
+
return C;
|
|
177
|
+
var L = u(_);
|
|
178
|
+
return f !== void 0 && f(C, L) ? (b = _, C) : (b = _, M = L);
|
|
179
179
|
}
|
|
180
|
-
var O = !1,
|
|
180
|
+
var O = !1, b, M, R = c === void 0 ? null : c;
|
|
181
181
|
return [
|
|
182
182
|
function() {
|
|
183
|
-
return E(
|
|
183
|
+
return E(d());
|
|
184
184
|
},
|
|
185
|
-
|
|
186
|
-
return E(
|
|
185
|
+
R === null ? void 0 : function() {
|
|
186
|
+
return E(R());
|
|
187
187
|
}
|
|
188
188
|
];
|
|
189
189
|
},
|
|
190
|
-
[
|
|
190
|
+
[d, c, u, f]
|
|
191
191
|
);
|
|
192
|
-
var
|
|
193
|
-
return
|
|
192
|
+
var S = n(i, h[0], h[1]);
|
|
193
|
+
return l(
|
|
194
194
|
function() {
|
|
195
|
-
|
|
195
|
+
m.hasValue = !0, m.value = S;
|
|
196
196
|
},
|
|
197
|
-
[
|
|
198
|
-
), S
|
|
199
|
-
},
|
|
197
|
+
[S]
|
|
198
|
+
), w(S), S;
|
|
199
|
+
}, k;
|
|
200
200
|
}
|
|
201
|
-
var
|
|
201
|
+
var I = {};
|
|
202
202
|
/**
|
|
203
203
|
* @license React
|
|
204
204
|
* use-sync-external-store-shim/with-selector.development.js
|
|
@@ -208,150 +208,152 @@ var V = {};
|
|
|
208
208
|
* This source code is licensed under the MIT license found in the
|
|
209
209
|
* LICENSE file in the root directory of this source tree.
|
|
210
210
|
*/
|
|
211
|
-
var
|
|
212
|
-
function
|
|
213
|
-
return
|
|
214
|
-
function e(
|
|
215
|
-
return
|
|
211
|
+
var X;
|
|
212
|
+
function ue() {
|
|
213
|
+
return X || (X = 1, process.env.NODE_ENV !== "production" && function() {
|
|
214
|
+
function e(i, d) {
|
|
215
|
+
return i === d && (i !== 0 || 1 / i === 1 / d) || i !== i && d !== d;
|
|
216
216
|
}
|
|
217
217
|
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
|
|
218
|
-
var t =
|
|
219
|
-
|
|
220
|
-
var
|
|
221
|
-
if (
|
|
222
|
-
var
|
|
223
|
-
|
|
218
|
+
var t = z, r = re(), s = typeof Object.is == "function" ? Object.is : e, n = r.useSyncExternalStore, o = t.useRef, l = t.useEffect, p = t.useMemo, w = t.useDebugValue;
|
|
219
|
+
I.useSyncExternalStoreWithSelector = function(i, d, c, u, f) {
|
|
220
|
+
var h = o(null);
|
|
221
|
+
if (h.current === null) {
|
|
222
|
+
var m = { hasValue: !1, value: null };
|
|
223
|
+
h.current = m;
|
|
224
224
|
} else
|
|
225
|
-
|
|
226
|
-
|
|
225
|
+
m = h.current;
|
|
226
|
+
h = p(
|
|
227
227
|
function() {
|
|
228
|
-
function E(
|
|
228
|
+
function E(_) {
|
|
229
229
|
if (!O) {
|
|
230
|
-
if (O = !0,
|
|
231
|
-
var
|
|
232
|
-
if (
|
|
233
|
-
return
|
|
230
|
+
if (O = !0, b = _, _ = u(_), f !== void 0 && m.hasValue) {
|
|
231
|
+
var C = m.value;
|
|
232
|
+
if (f(C, _))
|
|
233
|
+
return M = C;
|
|
234
234
|
}
|
|
235
|
-
return
|
|
235
|
+
return M = _;
|
|
236
236
|
}
|
|
237
|
-
if (
|
|
238
|
-
return
|
|
239
|
-
var
|
|
240
|
-
return
|
|
237
|
+
if (C = M, s(b, _))
|
|
238
|
+
return C;
|
|
239
|
+
var L = u(_);
|
|
240
|
+
return f !== void 0 && f(C, L) ? (b = _, C) : (b = _, M = L);
|
|
241
241
|
}
|
|
242
|
-
var O = !1,
|
|
242
|
+
var O = !1, b, M, R = c === void 0 ? null : c;
|
|
243
243
|
return [
|
|
244
244
|
function() {
|
|
245
|
-
return E(
|
|
245
|
+
return E(d());
|
|
246
246
|
},
|
|
247
|
-
|
|
248
|
-
return E(
|
|
247
|
+
R === null ? void 0 : function() {
|
|
248
|
+
return E(R());
|
|
249
249
|
}
|
|
250
250
|
];
|
|
251
251
|
},
|
|
252
|
-
[
|
|
252
|
+
[d, c, u, f]
|
|
253
253
|
);
|
|
254
|
-
var
|
|
255
|
-
return
|
|
254
|
+
var S = n(i, h[0], h[1]);
|
|
255
|
+
return l(
|
|
256
256
|
function() {
|
|
257
|
-
|
|
257
|
+
m.hasValue = !0, m.value = S;
|
|
258
258
|
},
|
|
259
|
-
[
|
|
260
|
-
), S
|
|
259
|
+
[S]
|
|
260
|
+
), w(S), S;
|
|
261
261
|
}, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(Error());
|
|
262
|
-
}()),
|
|
262
|
+
}()), I;
|
|
263
263
|
}
|
|
264
|
-
process.env.NODE_ENV === "production" ?
|
|
265
|
-
var
|
|
266
|
-
const
|
|
267
|
-
const
|
|
268
|
-
function
|
|
269
|
-
const
|
|
264
|
+
process.env.NODE_ENV === "production" ? B.exports = ce() : B.exports = ue();
|
|
265
|
+
var de = B.exports;
|
|
266
|
+
const fe = /* @__PURE__ */ ae(de), { useDebugValue: he } = z, { useSyncExternalStoreWithSelector: me } = fe;
|
|
267
|
+
const pe = (e) => e;
|
|
268
|
+
function ve(e, t = pe, r) {
|
|
269
|
+
const s = me(
|
|
270
270
|
e.subscribe,
|
|
271
271
|
e.getState,
|
|
272
272
|
e.getServerState || e.getInitialState,
|
|
273
273
|
t,
|
|
274
274
|
r
|
|
275
275
|
);
|
|
276
|
-
return
|
|
276
|
+
return he(s), s;
|
|
277
277
|
}
|
|
278
|
-
const
|
|
279
|
-
const t = typeof e == "function" ?
|
|
278
|
+
const Z = (e) => {
|
|
279
|
+
const t = typeof e == "function" ? se(e) : e, r = (s, n) => ve(t, s, n);
|
|
280
280
|
return Object.assign(r, t), r;
|
|
281
|
-
},
|
|
282
|
-
var
|
|
283
|
-
const
|
|
284
|
-
const r = Math.abs(e.row - t.row),
|
|
285
|
-
return Math.floor(10 * Math.sqrt(r * r +
|
|
286
|
-
},
|
|
281
|
+
}, we = (e) => e ? Z(e) : Z;
|
|
282
|
+
var a = /* @__PURE__ */ ((e) => (e[e.Empty = 0] = "Empty", e[e.Start = 1] = "Start", e[e.End = 2] = "End", e[e.Obstacle = 3] = "Obstacle", e[e.Visited = 4] = "Visited", e[e.Path = 5] = "Path", e[e.Water = 6] = "Water", e[e.Forest = 7] = "Forest", e[e.Mountain = 8] = "Mountain", e))(a || {}), A = /* @__PURE__ */ ((e) => (e.Classic = "classic", e.Medieval = "medieval", e))(A || {});
|
|
283
|
+
const x = (e, t) => {
|
|
284
|
+
const r = Math.abs(e.row - t.row), s = Math.abs(e.col - t.col);
|
|
285
|
+
return Math.floor(10 * Math.sqrt(r * r + s * s));
|
|
286
|
+
}, be = (e, t) => ({
|
|
287
287
|
row: e.row,
|
|
288
288
|
col: e.col,
|
|
289
289
|
g: 0,
|
|
290
|
-
h:
|
|
291
|
-
f:
|
|
290
|
+
h: x(e, t),
|
|
291
|
+
f: x(e, t),
|
|
292
292
|
parent: null
|
|
293
|
-
}),
|
|
294
|
-
const
|
|
293
|
+
}), ge = (e, t, r) => {
|
|
294
|
+
const s = [
|
|
295
295
|
{ row: e.row - 1, col: e.col },
|
|
296
296
|
{ row: e.row + 1, col: e.col },
|
|
297
297
|
{ row: e.row, col: e.col - 1 },
|
|
298
298
|
{ row: e.row, col: e.col + 1 }
|
|
299
299
|
];
|
|
300
|
-
|
|
300
|
+
r && s.push(
|
|
301
301
|
{ row: e.row - 1, col: e.col - 1 },
|
|
302
302
|
{ row: e.row - 1, col: e.col + 1 },
|
|
303
303
|
{ row: e.row + 1, col: e.col - 1 },
|
|
304
304
|
{ row: e.row + 1, col: e.col + 1 }
|
|
305
|
-
)
|
|
305
|
+
);
|
|
306
|
+
const n = [a.Obstacle, a.Water, a.Mountain];
|
|
307
|
+
return s.filter((o) => o.row >= 0 && o.row < t.length && o.col >= 0 && o.col < t[0].length && !n.includes(t[o.row][o.col].state)).map((o) => ({
|
|
306
308
|
row: o.row,
|
|
307
309
|
col: o.col,
|
|
308
310
|
state: t[o.row][o.col].state
|
|
309
311
|
}));
|
|
310
|
-
},
|
|
311
|
-
const
|
|
312
|
-
return { g:
|
|
313
|
-
},
|
|
312
|
+
}, Ee = (e, t, r) => {
|
|
313
|
+
const s = Math.abs(e.row - t.row), n = Math.abs(e.col - t.col), o = e.g + (s === 0 || n === 0 ? 10 : 14), l = x(t, r), p = o + l;
|
|
314
|
+
return { g: o, h: l, f: p };
|
|
315
|
+
}, Se = (e) => {
|
|
314
316
|
const t = [];
|
|
315
317
|
let r = e;
|
|
316
318
|
for (; r; )
|
|
317
319
|
t.push(r), r = r.parent;
|
|
318
320
|
return t.reverse();
|
|
319
|
-
},
|
|
320
|
-
const
|
|
321
|
-
for (
|
|
322
|
-
|
|
323
|
-
const
|
|
324
|
-
if (
|
|
325
|
-
return
|
|
326
|
-
|
|
327
|
-
const
|
|
328
|
-
for (const
|
|
329
|
-
if (
|
|
321
|
+
}, _e = (e, t, r, s) => {
|
|
322
|
+
const n = [], o = [], l = be(t, r);
|
|
323
|
+
for (n.push(l); n.length > 0; ) {
|
|
324
|
+
n.sort((i, d) => i.f - d.f);
|
|
325
|
+
const p = n.shift();
|
|
326
|
+
if (p.row === r.row && p.col === r.col)
|
|
327
|
+
return o.push(p), { path: Se(p), visitedNodes: o };
|
|
328
|
+
o.push(p);
|
|
329
|
+
const w = ge(p, e, s);
|
|
330
|
+
for (const i of w) {
|
|
331
|
+
if (o.some((h) => h.row === i.row && h.col === i.col))
|
|
330
332
|
continue;
|
|
331
|
-
const { g:
|
|
332
|
-
(
|
|
333
|
+
const { g: d, h: c, f: u } = Ee(p, i, r), f = n.find(
|
|
334
|
+
(h) => h.row === i.row && h.col === i.col
|
|
333
335
|
);
|
|
334
|
-
if (!
|
|
335
|
-
const
|
|
336
|
-
row:
|
|
337
|
-
col:
|
|
338
|
-
g:
|
|
339
|
-
h:
|
|
340
|
-
f:
|
|
341
|
-
parent:
|
|
336
|
+
if (!f || d < f.g) {
|
|
337
|
+
const h = {
|
|
338
|
+
row: i.row,
|
|
339
|
+
col: i.col,
|
|
340
|
+
g: d,
|
|
341
|
+
h: c,
|
|
342
|
+
f: u,
|
|
343
|
+
parent: p
|
|
342
344
|
};
|
|
343
|
-
|
|
345
|
+
f ? (f.g = d, f.f = u, f.parent = p) : n.push(h);
|
|
344
346
|
}
|
|
345
347
|
}
|
|
346
348
|
}
|
|
347
|
-
return { path: [], visitedNodes:
|
|
348
|
-
},
|
|
349
|
+
return { path: [], visitedNodes: o };
|
|
350
|
+
}, Oe = (e) => ({
|
|
349
351
|
cells: Array.from(
|
|
350
352
|
{ length: 8 },
|
|
351
|
-
(t, r) => Array.from({ length: 12 }, (
|
|
353
|
+
(t, r) => Array.from({ length: 12 }, (s, n) => ({
|
|
352
354
|
row: r,
|
|
353
|
-
col:
|
|
354
|
-
state:
|
|
355
|
+
col: n,
|
|
356
|
+
state: a.Empty
|
|
355
357
|
}))
|
|
356
358
|
),
|
|
357
359
|
rows: 8,
|
|
@@ -363,72 +365,72 @@ const k = (e, t) => {
|
|
|
363
365
|
visitedNodes: [],
|
|
364
366
|
setNumberOfColumns: (t) => {
|
|
365
367
|
e((r) => {
|
|
366
|
-
const
|
|
367
|
-
...
|
|
368
|
+
const s = r.cells.map((n) => t > r.columns ? [
|
|
369
|
+
...n,
|
|
368
370
|
...Array.from(
|
|
369
371
|
{ length: t - r.columns },
|
|
370
|
-
(
|
|
371
|
-
row:
|
|
372
|
-
col: r.columns +
|
|
373
|
-
state:
|
|
372
|
+
(o, l) => ({
|
|
373
|
+
row: n[0].row,
|
|
374
|
+
col: r.columns + l,
|
|
375
|
+
state: a.Empty
|
|
374
376
|
})
|
|
375
377
|
)
|
|
376
|
-
] :
|
|
378
|
+
] : n.slice(0, t));
|
|
377
379
|
return {
|
|
378
380
|
...r,
|
|
379
381
|
columns: t,
|
|
380
|
-
cells:
|
|
382
|
+
cells: s
|
|
381
383
|
};
|
|
382
384
|
});
|
|
383
385
|
},
|
|
384
386
|
setNumberOfRows: (t) => {
|
|
385
387
|
e((r) => {
|
|
386
|
-
let
|
|
387
|
-
return t > r.rows ?
|
|
388
|
-
...
|
|
388
|
+
let s = [...r.cells];
|
|
389
|
+
return t > r.rows ? s = [
|
|
390
|
+
...s,
|
|
389
391
|
...Array.from(
|
|
390
392
|
{ length: t - r.rows },
|
|
391
|
-
(
|
|
392
|
-
row: r.rows +
|
|
393
|
-
col:
|
|
394
|
-
state:
|
|
393
|
+
(n, o) => Array.from({ length: r.columns }, (l, p) => ({
|
|
394
|
+
row: r.rows + o,
|
|
395
|
+
col: p,
|
|
396
|
+
state: a.Empty
|
|
395
397
|
}))
|
|
396
398
|
)
|
|
397
|
-
] :
|
|
399
|
+
] : s = s.slice(0, t), {
|
|
398
400
|
...r,
|
|
399
401
|
rows: t,
|
|
400
|
-
cells:
|
|
402
|
+
cells: s
|
|
401
403
|
};
|
|
402
404
|
});
|
|
403
405
|
},
|
|
404
|
-
setCellState: (t, r,
|
|
405
|
-
e((
|
|
406
|
-
const
|
|
407
|
-
(
|
|
406
|
+
setCellState: (t, r, s) => {
|
|
407
|
+
e((n) => {
|
|
408
|
+
const o = n.cells.map(
|
|
409
|
+
(i) => i.map((d) => ({ ...d }))
|
|
408
410
|
);
|
|
409
|
-
let
|
|
410
|
-
switch (
|
|
411
|
-
case
|
|
412
|
-
|
|
411
|
+
let l = n.startTile, p = n.endTile, w = [...n.obstacleTiles];
|
|
412
|
+
switch (s === a.Start && n.startTile && (o[n.startTile.row][n.startTile.col].state = a.Empty, l = null), s === a.End && n.endTile && (o[n.endTile.row][n.endTile.col].state = a.Empty, p = null), o[t][r].state = s, s) {
|
|
413
|
+
case a.Start:
|
|
414
|
+
l = { row: t, col: r };
|
|
413
415
|
break;
|
|
414
|
-
case
|
|
415
|
-
|
|
416
|
+
case a.End:
|
|
417
|
+
p = { row: t, col: r };
|
|
416
418
|
break;
|
|
417
|
-
case
|
|
418
|
-
|
|
419
|
+
case a.Obstacle:
|
|
420
|
+
w.some((i) => i.row === t && i.col === r) || w.push({ row: t, col: r });
|
|
419
421
|
break;
|
|
420
|
-
case
|
|
421
|
-
|
|
422
|
-
(
|
|
422
|
+
case a.Empty:
|
|
423
|
+
w = w.filter(
|
|
424
|
+
(i) => !(i.row === t && i.col === r)
|
|
423
425
|
);
|
|
424
426
|
break;
|
|
425
427
|
}
|
|
426
428
|
return {
|
|
427
|
-
...
|
|
428
|
-
cells:
|
|
429
|
-
startTile:
|
|
430
|
-
endTile:
|
|
431
|
-
obstacleTiles:
|
|
429
|
+
...n,
|
|
430
|
+
cells: o,
|
|
431
|
+
startTile: l,
|
|
432
|
+
endTile: p,
|
|
433
|
+
obstacleTiles: w
|
|
432
434
|
};
|
|
433
435
|
});
|
|
434
436
|
},
|
|
@@ -436,9 +438,9 @@ const k = (e, t) => {
|
|
|
436
438
|
e((t) => ({
|
|
437
439
|
...t,
|
|
438
440
|
cells: t.cells.map(
|
|
439
|
-
(r) => r.map((
|
|
440
|
-
...
|
|
441
|
-
state:
|
|
441
|
+
(r) => r.map((s) => ({
|
|
442
|
+
...s,
|
|
443
|
+
state: a.Empty
|
|
442
444
|
}))
|
|
443
445
|
),
|
|
444
446
|
startTile: null,
|
|
@@ -450,125 +452,169 @@ const k = (e, t) => {
|
|
|
450
452
|
},
|
|
451
453
|
handleFindPath: (t) => {
|
|
452
454
|
e((r) => {
|
|
453
|
-
const
|
|
454
|
-
if (
|
|
455
|
-
const
|
|
456
|
-
(
|
|
457
|
-
row:
|
|
458
|
-
col:
|
|
459
|
-
state:
|
|
455
|
+
const s = r.cells.flat().find((o) => o.state === a.Start), n = r.cells.flat().find((o) => o.state === a.End);
|
|
456
|
+
if (s && n) {
|
|
457
|
+
const o = r.cells.map(
|
|
458
|
+
(i) => i.map((d) => ({
|
|
459
|
+
row: d.row,
|
|
460
|
+
col: d.col,
|
|
461
|
+
state: d.state
|
|
460
462
|
}))
|
|
461
|
-
), { path:
|
|
462
|
-
return (async (
|
|
463
|
-
for (let
|
|
464
|
-
await new Promise((
|
|
465
|
-
const
|
|
466
|
-
(
|
|
467
|
-
...
|
|
468
|
-
state:
|
|
463
|
+
), { path: l, visitedNodes: p } = _e(o, s, n, t);
|
|
464
|
+
return (async (i, d) => {
|
|
465
|
+
for (let c of d)
|
|
466
|
+
await new Promise((u) => setTimeout(u, 100)), e((u) => {
|
|
467
|
+
const f = u.cells.map(
|
|
468
|
+
(h) => h.map((m) => ({
|
|
469
|
+
...m,
|
|
470
|
+
state: c.row === m.row && c.col === m.col && m.state === a.Empty ? a.Visited : m.state
|
|
469
471
|
}))
|
|
470
472
|
);
|
|
471
473
|
return {
|
|
472
|
-
...
|
|
473
|
-
cells:
|
|
474
|
-
visitedNodes: [...
|
|
474
|
+
...u,
|
|
475
|
+
cells: f,
|
|
476
|
+
visitedNodes: [...u.visitedNodes, c]
|
|
475
477
|
};
|
|
476
478
|
});
|
|
477
|
-
for (let
|
|
478
|
-
await new Promise((
|
|
479
|
-
const
|
|
480
|
-
(
|
|
481
|
-
...
|
|
482
|
-
state:
|
|
479
|
+
for (let c of i)
|
|
480
|
+
await new Promise((u) => setTimeout(u, 250)), e((u) => {
|
|
481
|
+
const f = u.cells.map(
|
|
482
|
+
(h) => h.map((m) => ({
|
|
483
|
+
...m,
|
|
484
|
+
state: c.row === m.row && c.col === m.col ? a.Path : m.state
|
|
483
485
|
}))
|
|
484
486
|
);
|
|
485
487
|
return {
|
|
486
|
-
...
|
|
487
|
-
cells:
|
|
488
|
-
path: [...
|
|
488
|
+
...u,
|
|
489
|
+
cells: f,
|
|
490
|
+
path: [...u.path, c]
|
|
489
491
|
};
|
|
490
492
|
});
|
|
491
|
-
})(
|
|
493
|
+
})(l, p), { ...r, path: [], visitedNodes: [] };
|
|
492
494
|
}
|
|
493
495
|
return r;
|
|
494
496
|
});
|
|
495
497
|
},
|
|
496
498
|
setPath: (t) => {
|
|
497
499
|
e((r) => {
|
|
498
|
-
const
|
|
499
|
-
(
|
|
500
|
-
...
|
|
501
|
-
state: t.some((
|
|
500
|
+
const s = r.cells.map(
|
|
501
|
+
(n) => n.map((o) => ({
|
|
502
|
+
...o,
|
|
503
|
+
state: t.some((l) => l.row === o.row && l.col === o.col) ? a.Path : o.state
|
|
502
504
|
}))
|
|
503
505
|
);
|
|
504
506
|
return {
|
|
505
507
|
...r,
|
|
506
|
-
cells:
|
|
508
|
+
cells: s
|
|
507
509
|
};
|
|
508
510
|
});
|
|
509
511
|
},
|
|
510
512
|
setVisitedNodes: (t) => {
|
|
511
513
|
e((r) => {
|
|
512
|
-
const
|
|
513
|
-
(
|
|
514
|
-
...
|
|
515
|
-
state: t.some((
|
|
514
|
+
const s = r.cells.map(
|
|
515
|
+
(n) => n.map((o) => ({
|
|
516
|
+
...o,
|
|
517
|
+
state: t.some((l) => l.row === o.row && l.col === o.col) && o.state === a.Empty ? a.Visited : o.state
|
|
516
518
|
}))
|
|
517
519
|
);
|
|
518
520
|
return {
|
|
519
521
|
...r,
|
|
520
|
-
cells:
|
|
522
|
+
cells: s
|
|
521
523
|
};
|
|
522
524
|
});
|
|
523
525
|
}
|
|
524
|
-
}),
|
|
525
|
-
activeButton:
|
|
526
|
+
}), ye = (e) => ({
|
|
527
|
+
activeButton: a.Start,
|
|
526
528
|
setSelectedButtonState: (t) => e({ activeButton: t }),
|
|
527
529
|
canTravelDiagonally: !0,
|
|
528
530
|
setCanTravelDiagonally: (t) => e({ canTravelDiagonally: t })
|
|
529
|
-
}),
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
})
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
531
|
+
}), Ne = (e) => ({
|
|
532
|
+
visualTheme: A.Medieval,
|
|
533
|
+
showCosts: !1,
|
|
534
|
+
setVisualTheme: (t) => e({ visualTheme: t }),
|
|
535
|
+
setShowCosts: (t) => e({ showCosts: t })
|
|
536
|
+
}), j = we((e, t, r) => ({
|
|
537
|
+
...Oe(e),
|
|
538
|
+
...ye(e),
|
|
539
|
+
...Ne(e)
|
|
540
|
+
})), Me = {
|
|
541
|
+
id: A.Classic,
|
|
542
|
+
name: "Classic",
|
|
543
|
+
startIcon: "●",
|
|
544
|
+
endIcon: "●",
|
|
545
|
+
terrains: {
|
|
546
|
+
[a.Obstacle]: { name: "Wall", icon: "■", passable: !1 }
|
|
547
|
+
},
|
|
548
|
+
presets: [
|
|
549
|
+
{ id: "random", name: "Random", icon: "🎲" },
|
|
550
|
+
{ id: "maze", name: "Maze", icon: "🔲" }
|
|
551
|
+
]
|
|
552
|
+
}, Ce = {
|
|
553
|
+
id: A.Medieval,
|
|
554
|
+
name: "Medieval",
|
|
555
|
+
startIcon: "⚔️",
|
|
556
|
+
endIcon: "🏰",
|
|
557
|
+
terrains: {
|
|
558
|
+
[a.Obstacle]: { name: "Wall", icon: "🧱", passable: !1 },
|
|
559
|
+
[a.Water]: { name: "Water", icon: "🌊", passable: !1 },
|
|
560
|
+
[a.Forest]: { name: "Forest", icon: "🌲", passable: !0 },
|
|
561
|
+
[a.Mountain]: { name: "Mountain", icon: "⛰️", passable: !1 }
|
|
562
|
+
},
|
|
563
|
+
presets: [
|
|
564
|
+
{ id: "river", name: "River Crossing", icon: "🌊" },
|
|
565
|
+
{ id: "mountains", name: "Mountain Range", icon: "⛰️" },
|
|
566
|
+
{ id: "maze", name: "Castle Maze", icon: "🏰" },
|
|
567
|
+
{ id: "random", name: "Random Forest", icon: "🎲" }
|
|
568
|
+
]
|
|
569
|
+
}, oe = {
|
|
570
|
+
[A.Classic]: Me,
|
|
571
|
+
[A.Medieval]: Ce
|
|
572
|
+
}, F = (e) => oe[e], Te = (e) => {
|
|
573
|
+
const t = F(e);
|
|
574
|
+
return Object.entries(t.terrains).map(([r, s]) => ({
|
|
575
|
+
state: Number(r),
|
|
576
|
+
config: s
|
|
577
|
+
}));
|
|
578
|
+
};
|
|
579
|
+
const Re = () => {
|
|
580
|
+
var S;
|
|
581
|
+
const { cells: e, activeButton: t, setCellState: r, setSelectedButtonState: s, visitedNodes: n, path: o, visualTheme: l, showCosts: p } = j(), w = F(l), [i, d] = ee({ width: 0, height: 0 }), c = z.useRef(null);
|
|
582
|
+
te(() => {
|
|
583
|
+
const E = () => {
|
|
584
|
+
if (c.current) {
|
|
585
|
+
const O = c.current.getBoundingClientRect();
|
|
586
|
+
d({ width: O.width, height: O.height });
|
|
541
587
|
}
|
|
542
588
|
};
|
|
543
|
-
return
|
|
589
|
+
return E(), window.addEventListener("resize", E), () => window.removeEventListener("resize", E);
|
|
544
590
|
}, []);
|
|
545
|
-
const
|
|
546
|
-
switch (r(
|
|
547
|
-
case
|
|
548
|
-
a
|
|
591
|
+
const u = (E, O) => {
|
|
592
|
+
switch (r(E, O, t), t) {
|
|
593
|
+
case a.Start:
|
|
594
|
+
s(a.End);
|
|
549
595
|
break;
|
|
550
|
-
case
|
|
551
|
-
a
|
|
596
|
+
case a.End:
|
|
597
|
+
s(a.Obstacle);
|
|
552
598
|
break;
|
|
553
599
|
}
|
|
554
|
-
},
|
|
555
|
-
const
|
|
556
|
-
return
|
|
557
|
-
},
|
|
558
|
-
var
|
|
559
|
-
if (!
|
|
600
|
+
}, f = (E, O) => {
|
|
601
|
+
const b = n.find((M) => M.row === E && M.col === O);
|
|
602
|
+
return b ? { g: b.g, h: b.h, f: b.f } : { g: null, h: null, f: null };
|
|
603
|
+
}, m = (() => {
|
|
604
|
+
var y;
|
|
605
|
+
if (!i.width || !i.height)
|
|
560
606
|
return 20;
|
|
561
|
-
const
|
|
607
|
+
const E = ((y = e[0]) == null ? void 0 : y.length) || 1, O = e.length || 1, b = 20, M = E + O, R = i.width - b - M, _ = i.height - b - M, C = R / E, L = _ / O, g = Math.min(C, L);
|
|
562
608
|
return Math.max(15, Math.min(g, 60));
|
|
563
609
|
})();
|
|
564
|
-
return /* @__PURE__ */
|
|
610
|
+
return /* @__PURE__ */ v("div", { className: "grid-wrapper", ref: c, children: /* @__PURE__ */ v(
|
|
565
611
|
"div",
|
|
566
612
|
{
|
|
567
613
|
className: "grid-container",
|
|
568
614
|
style: {
|
|
569
615
|
display: "grid",
|
|
570
|
-
gridTemplateColumns: `repeat(${((
|
|
571
|
-
gridTemplateRows: `repeat(${e.length || 1}, ${
|
|
616
|
+
gridTemplateColumns: `repeat(${((S = e[0]) == null ? void 0 : S.length) || 1}, ${m}px)`,
|
|
617
|
+
gridTemplateRows: `repeat(${e.length || 1}, ${m}px)`,
|
|
572
618
|
gap: "1px",
|
|
573
619
|
padding: "8px",
|
|
574
620
|
background: "var(--bg-secondary)",
|
|
@@ -577,22 +623,23 @@ const pe = () => {
|
|
|
577
623
|
border: "1px solid var(--border-color)"
|
|
578
624
|
},
|
|
579
625
|
children: e.map(
|
|
580
|
-
(
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
626
|
+
(E, O) => E.map((b, M) => {
|
|
627
|
+
var D, G, $, H;
|
|
628
|
+
const R = o.some((T) => T.row === b.row && T.col === b.col), _ = n.some((T) => T.row === b.row && T.col === b.col), { g: C, h: L, f: g } = f(b.row, b.col);
|
|
629
|
+
let y = Le(b, _);
|
|
630
|
+
if (R) {
|
|
631
|
+
const T = o.findIndex((K) => K.row === b.row && K.col === b.col);
|
|
632
|
+
T === 0 ? y = "var(--cell-start)" : T === o.length - 1 ? y = "var(--cell-end)" : y = "var(--cell-path)";
|
|
586
633
|
}
|
|
587
|
-
return /* @__PURE__ */
|
|
634
|
+
return /* @__PURE__ */ N(
|
|
588
635
|
"div",
|
|
589
636
|
{
|
|
590
637
|
className: "grid-cell",
|
|
591
|
-
onClick: () =>
|
|
638
|
+
onClick: () => u(O, M),
|
|
592
639
|
style: {
|
|
593
|
-
width:
|
|
594
|
-
height:
|
|
595
|
-
backgroundColor:
|
|
640
|
+
width: m,
|
|
641
|
+
height: m,
|
|
642
|
+
backgroundColor: y,
|
|
596
643
|
border: "1px solid var(--cell-border)",
|
|
597
644
|
cursor: "pointer",
|
|
598
645
|
transition: "all 0.15s ease",
|
|
@@ -602,170 +649,345 @@ const pe = () => {
|
|
|
602
649
|
alignItems: "center",
|
|
603
650
|
borderRadius: "2px"
|
|
604
651
|
},
|
|
605
|
-
onMouseEnter: (
|
|
606
|
-
|
|
652
|
+
onMouseEnter: (T) => {
|
|
653
|
+
b.state === a.Empty && (T.currentTarget.style.backgroundColor = "var(--bg-tertiary)", T.currentTarget.style.transform = "scale(1.02)");
|
|
607
654
|
},
|
|
608
|
-
onMouseLeave: (
|
|
609
|
-
|
|
655
|
+
onMouseLeave: (T) => {
|
|
656
|
+
b.state === a.Empty && (T.currentTarget.style.backgroundColor = y, T.currentTarget.style.transform = "scale(1)");
|
|
610
657
|
},
|
|
611
658
|
children: [
|
|
612
|
-
|
|
613
|
-
/* @__PURE__ */
|
|
659
|
+
_ && p && /* @__PURE__ */ N("div", { className: "cell-values", children: [
|
|
660
|
+
/* @__PURE__ */ N("div", { className: "value-h", children: [
|
|
614
661
|
"h",
|
|
615
|
-
|
|
662
|
+
L
|
|
616
663
|
] }),
|
|
617
|
-
/* @__PURE__ */
|
|
664
|
+
/* @__PURE__ */ N("div", { className: "value-f", children: [
|
|
618
665
|
"f",
|
|
619
666
|
g
|
|
620
667
|
] }),
|
|
621
|
-
/* @__PURE__ */
|
|
668
|
+
/* @__PURE__ */ N("div", { className: "value-g", children: [
|
|
622
669
|
"g",
|
|
623
|
-
|
|
670
|
+
C
|
|
624
671
|
] })
|
|
625
672
|
] }),
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
673
|
+
b.state === a.Start && /* @__PURE__ */ v("div", { className: "cell-indicator start", children: w.startIcon }),
|
|
674
|
+
b.state === a.End && /* @__PURE__ */ v("div", { className: "cell-indicator end", children: w.endIcon }),
|
|
675
|
+
b.state === a.Obstacle && /* @__PURE__ */ v("div", { className: "cell-indicator obstacle", children: ((D = w.terrains[a.Obstacle]) == null ? void 0 : D.icon) || "■" }),
|
|
676
|
+
b.state === a.Water && /* @__PURE__ */ v("div", { className: "cell-indicator water", children: ((G = w.terrains[a.Water]) == null ? void 0 : G.icon) || "🌊" }),
|
|
677
|
+
b.state === a.Forest && /* @__PURE__ */ v("div", { className: "cell-indicator forest", children: (($ = w.terrains[a.Forest]) == null ? void 0 : $.icon) || "🌲" }),
|
|
678
|
+
b.state === a.Mountain && /* @__PURE__ */ v("div", { className: "cell-indicator mountain", children: ((H = w.terrains[a.Mountain]) == null ? void 0 : H.icon) || "⛰️" })
|
|
629
679
|
]
|
|
630
680
|
},
|
|
631
|
-
`${
|
|
681
|
+
`${O}-${M}`
|
|
632
682
|
);
|
|
633
683
|
})
|
|
634
684
|
)
|
|
635
685
|
}
|
|
636
686
|
) });
|
|
637
|
-
},
|
|
687
|
+
}, Le = (e, t) => {
|
|
638
688
|
if (t)
|
|
639
|
-
return e.state ===
|
|
689
|
+
return e.state === a.Start ? "var(--cell-start)" : e.state === a.End ? "var(--cell-end)" : "var(--cell-visited)";
|
|
640
690
|
switch (e.state) {
|
|
641
|
-
case
|
|
691
|
+
case a.Start:
|
|
642
692
|
return "var(--cell-start)";
|
|
643
|
-
case
|
|
693
|
+
case a.End:
|
|
644
694
|
return "var(--cell-end)";
|
|
645
|
-
case
|
|
695
|
+
case a.Obstacle:
|
|
646
696
|
return "var(--cell-obstacle)";
|
|
647
|
-
case
|
|
697
|
+
case a.Water:
|
|
698
|
+
return "var(--cell-water)";
|
|
699
|
+
case a.Forest:
|
|
700
|
+
return "var(--cell-forest)";
|
|
701
|
+
case a.Mountain:
|
|
702
|
+
return "var(--cell-mountain)";
|
|
703
|
+
case a.Empty:
|
|
648
704
|
return "var(--cell-empty)";
|
|
649
705
|
default:
|
|
650
706
|
return "var(--cell-empty)";
|
|
651
707
|
}
|
|
708
|
+
}, Ae = (e, t) => {
|
|
709
|
+
const r = [], s = Math.floor(e / 2), n = Math.max(2, Math.floor(t / 6)), o = [];
|
|
710
|
+
for (let l = 0; l < n; l++) {
|
|
711
|
+
const p = Math.floor(t / (n + 1) * (l + 1));
|
|
712
|
+
o.push(p);
|
|
713
|
+
}
|
|
714
|
+
for (let l = 0; l < t; l++)
|
|
715
|
+
o.includes(l) || (r.push({ row: s, col: l, state: a.Water }), s + 1 < e && r.push({ row: s + 1, col: l, state: a.Water }));
|
|
716
|
+
for (let l = 0; l < t; l += 3)
|
|
717
|
+
s - 1 >= 0 && Math.random() > 0.5 && r.push({ row: s - 1, col: l, state: a.Forest }), s + 2 < e && Math.random() > 0.5 && r.push({ row: s + 2, col: l, state: a.Forest });
|
|
718
|
+
return r;
|
|
719
|
+
}, De = (e, t) => {
|
|
720
|
+
const r = [], s = Math.floor(e * 0.2), n = Math.floor(t * 0.1), o = Math.floor(e * 0.8), l = Math.floor(t * 0.9), p = Math.max(2, Math.floor(Math.min(e, t) / 5)), w = [];
|
|
721
|
+
for (let i = 0; i < p; i++)
|
|
722
|
+
w.push(Math.floor((l - n) / (p + 1) * (i + 1)) + n);
|
|
723
|
+
for (let i = n; i <= l; i++) {
|
|
724
|
+
const d = (i - n) / (l - n), c = Math.floor(s + (o - s) * d);
|
|
725
|
+
w.some((u) => Math.abs(i - u) <= 1) || (c >= 0 && c < e && r.push({ row: c, col: i, state: a.Mountain }), c + 1 < e && Math.random() > 0.3 && r.push({ row: c + 1, col: i, state: a.Mountain }), c - 1 >= 0 && Math.random() > 0.3 && r.push({ row: c - 1, col: i, state: a.Mountain }));
|
|
726
|
+
}
|
|
727
|
+
for (const i of [...r])
|
|
728
|
+
if (i.state === a.Mountain) {
|
|
729
|
+
const d = [
|
|
730
|
+
{ row: i.row - 2, col: i.col },
|
|
731
|
+
{ row: i.row + 2, col: i.col },
|
|
732
|
+
{ row: i.row, col: i.col - 2 },
|
|
733
|
+
{ row: i.row, col: i.col + 2 }
|
|
734
|
+
];
|
|
735
|
+
for (const c of d)
|
|
736
|
+
c.row >= 0 && c.row < e && c.col >= 0 && c.col < t && Math.random() > 0.7 && (r.some((u) => u.row === c.row && u.col === c.col) || r.push({ row: c.row, col: c.col, state: a.Forest }));
|
|
737
|
+
}
|
|
738
|
+
return r;
|
|
739
|
+
}, ze = (e, t) => {
|
|
740
|
+
const r = [];
|
|
741
|
+
for (let n = 0; n < e; n++)
|
|
742
|
+
for (let o = 0; o < t; o++) {
|
|
743
|
+
const l = n % 3 === 1, p = o % 3 === 1;
|
|
744
|
+
(l || p) && Math.random() > 0.35 && r.push({ row: n, col: o, state: a.Obstacle });
|
|
745
|
+
}
|
|
746
|
+
const s = 2;
|
|
747
|
+
return r.filter((n) => {
|
|
748
|
+
const o = n.row < s && n.col < s, l = n.row >= e - s && n.col >= t - s;
|
|
749
|
+
return !o && !l;
|
|
750
|
+
});
|
|
751
|
+
}, Ve = (e, t, r = 0.25) => {
|
|
752
|
+
const s = [];
|
|
753
|
+
for (let n = 0; n < e; n++)
|
|
754
|
+
for (let o = 0; o < t; o++)
|
|
755
|
+
if (!(n < 2 && o < 2 || n >= e - 2 && o >= t - 2) && Math.random() < r) {
|
|
756
|
+
const p = Math.random();
|
|
757
|
+
let w;
|
|
758
|
+
p < 0.4 ? w = a.Forest : p < 0.6 ? w = a.Obstacle : p < 0.8 ? w = a.Water : w = a.Mountain, s.push({ row: n, col: o, state: w });
|
|
759
|
+
}
|
|
760
|
+
return s;
|
|
761
|
+
}, ke = (e, t, r = 0.2) => {
|
|
762
|
+
const s = [];
|
|
763
|
+
for (let n = 0; n < e; n++)
|
|
764
|
+
for (let o = 0; o < t; o++)
|
|
765
|
+
!(n < 2 && o < 2 || n >= e - 2 && o >= t - 2) && Math.random() < r && s.push({ row: n, col: o, state: a.Obstacle });
|
|
766
|
+
return s;
|
|
767
|
+
}, We = (e, t) => {
|
|
768
|
+
const r = [];
|
|
769
|
+
for (let n = 0; n < e; n++)
|
|
770
|
+
for (let o = 0; o < t; o++) {
|
|
771
|
+
const l = n % 3 === 1, p = o % 3 === 1;
|
|
772
|
+
(l || p) && Math.random() > 0.35 && r.push({ row: n, col: o, state: a.Obstacle });
|
|
773
|
+
}
|
|
774
|
+
const s = 2;
|
|
775
|
+
return r.filter((n) => {
|
|
776
|
+
const o = n.row < s && n.col < s, l = n.row >= e - s && n.col >= t - s;
|
|
777
|
+
return !o && !l;
|
|
778
|
+
});
|
|
652
779
|
};
|
|
653
|
-
const
|
|
780
|
+
const Pe = ({ isDarkMode: e, setIsDarkMode: t }) => {
|
|
654
781
|
const {
|
|
655
782
|
activeButton: r,
|
|
656
|
-
setSelectedButtonState:
|
|
657
|
-
resetCells:
|
|
658
|
-
rows:
|
|
659
|
-
columns:
|
|
660
|
-
setNumberOfRows:
|
|
661
|
-
setNumberOfColumns:
|
|
662
|
-
handleFindPath:
|
|
663
|
-
canTravelDiagonally:
|
|
664
|
-
setCanTravelDiagonally:
|
|
665
|
-
|
|
783
|
+
setSelectedButtonState: s,
|
|
784
|
+
resetCells: n,
|
|
785
|
+
rows: o,
|
|
786
|
+
columns: l,
|
|
787
|
+
setNumberOfRows: p,
|
|
788
|
+
setNumberOfColumns: w,
|
|
789
|
+
handleFindPath: i,
|
|
790
|
+
canTravelDiagonally: d,
|
|
791
|
+
setCanTravelDiagonally: c,
|
|
792
|
+
visualTheme: u,
|
|
793
|
+
setVisualTheme: f,
|
|
794
|
+
showCosts: h,
|
|
795
|
+
setShowCosts: m,
|
|
796
|
+
setCellState: S
|
|
797
|
+
} = j(), E = F(u), O = Te(u), b = () => {
|
|
666
798
|
t(!e);
|
|
667
|
-
},
|
|
668
|
-
{ label: "Start", state:
|
|
669
|
-
{ label: "End", state:
|
|
670
|
-
{ label: "Obstacle", state:
|
|
671
|
-
{ label: "Clear", state:
|
|
799
|
+
}, M = [
|
|
800
|
+
{ label: "Start", state: a.Start },
|
|
801
|
+
{ label: "End", state: a.End },
|
|
802
|
+
{ label: "Obstacle", state: a.Obstacle },
|
|
803
|
+
{ label: "Clear", state: a.Empty },
|
|
672
804
|
{ label: "Reset", state: null }
|
|
673
|
-
],
|
|
674
|
-
|
|
675
|
-
},
|
|
676
|
-
|
|
677
|
-
},
|
|
678
|
-
d
|
|
805
|
+
], R = (g) => {
|
|
806
|
+
g === null ? _() : s(g);
|
|
807
|
+
}, _ = () => {
|
|
808
|
+
n(), s(a.Start);
|
|
809
|
+
}, C = () => {
|
|
810
|
+
i(d);
|
|
811
|
+
}, L = (g) => {
|
|
812
|
+
n();
|
|
813
|
+
let y;
|
|
814
|
+
if (u === A.Medieval)
|
|
815
|
+
switch (g) {
|
|
816
|
+
case "river":
|
|
817
|
+
y = Ae(o, l);
|
|
818
|
+
break;
|
|
819
|
+
case "mountains":
|
|
820
|
+
y = De(o, l);
|
|
821
|
+
break;
|
|
822
|
+
case "maze":
|
|
823
|
+
y = ze(o, l);
|
|
824
|
+
break;
|
|
825
|
+
case "random":
|
|
826
|
+
y = Ve(o, l);
|
|
827
|
+
break;
|
|
828
|
+
default:
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
else
|
|
832
|
+
switch (g) {
|
|
833
|
+
case "random":
|
|
834
|
+
y = ke(o, l);
|
|
835
|
+
break;
|
|
836
|
+
case "maze":
|
|
837
|
+
y = We(o, l);
|
|
838
|
+
break;
|
|
839
|
+
default:
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
for (const D of y)
|
|
843
|
+
S(D.row, D.col, D.state);
|
|
844
|
+
S(0, 0, a.Start), S(o - 1, l - 1, a.End), s(a.Obstacle);
|
|
679
845
|
};
|
|
680
|
-
return /* @__PURE__ */
|
|
681
|
-
/* @__PURE__ */
|
|
682
|
-
/* @__PURE__ */
|
|
683
|
-
/* @__PURE__ */
|
|
846
|
+
return /* @__PURE__ */ v("div", { className: "control-panel", children: /* @__PURE__ */ N("div", { className: "control-grid", children: [
|
|
847
|
+
/* @__PURE__ */ N("div", { className: "control-group theme-section", children: [
|
|
848
|
+
/* @__PURE__ */ v("h3", { className: "group-title", children: "Theme" }),
|
|
849
|
+
/* @__PURE__ */ N("div", { className: "button-group", children: [
|
|
850
|
+
/* @__PURE__ */ v(
|
|
851
|
+
"select",
|
|
852
|
+
{
|
|
853
|
+
className: "theme-select",
|
|
854
|
+
value: u,
|
|
855
|
+
onChange: (g) => f(g.target.value),
|
|
856
|
+
children: Object.values(oe).map((g) => /* @__PURE__ */ v("option", { value: g.id, children: g.name }, g.id))
|
|
857
|
+
}
|
|
858
|
+
),
|
|
859
|
+
/* @__PURE__ */ v(
|
|
860
|
+
"button",
|
|
861
|
+
{
|
|
862
|
+
className: `control-button theme-toggle ${e ? "active" : ""}`,
|
|
863
|
+
onClick: b,
|
|
864
|
+
title: e ? "Switch to light mode" : "Switch to dark mode",
|
|
865
|
+
children: e ? "☀️ Light" : "🌙 Dark"
|
|
866
|
+
}
|
|
867
|
+
),
|
|
868
|
+
/* @__PURE__ */ v(
|
|
869
|
+
"button",
|
|
870
|
+
{
|
|
871
|
+
className: `control-button show-costs ${h ? "active" : ""}`,
|
|
872
|
+
onClick: () => m(!h),
|
|
873
|
+
title: h ? "Hide costs" : "Show costs",
|
|
874
|
+
children: h ? "📊 Costs On" : "📊 Costs Off"
|
|
875
|
+
}
|
|
876
|
+
)
|
|
877
|
+
] })
|
|
878
|
+
] }),
|
|
879
|
+
/* @__PURE__ */ N("div", { className: "control-group tools", children: [
|
|
880
|
+
/* @__PURE__ */ v("h3", { className: "group-title", children: "Tools" }),
|
|
881
|
+
/* @__PURE__ */ v("div", { className: "button-group", children: M.map((g, y) => /* @__PURE__ */ v(
|
|
882
|
+
"button",
|
|
883
|
+
{
|
|
884
|
+
className: `control-button ${g.label.toLowerCase()} ${r === g.state ? "active" : ""}`,
|
|
885
|
+
onClick: () => R(g.state),
|
|
886
|
+
children: g.label
|
|
887
|
+
},
|
|
888
|
+
y
|
|
889
|
+
)) })
|
|
890
|
+
] }),
|
|
891
|
+
u === A.Medieval && /* @__PURE__ */ N("div", { className: "control-group terrain", children: [
|
|
892
|
+
/* @__PURE__ */ v("h3", { className: "group-title", children: "Terrain" }),
|
|
893
|
+
/* @__PURE__ */ v("div", { className: "button-group", children: O.filter(({ state: g }) => g !== a.Obstacle).map(({ state: g, config: y }) => /* @__PURE__ */ N(
|
|
684
894
|
"button",
|
|
685
895
|
{
|
|
686
|
-
className: `control-button ${
|
|
687
|
-
onClick: () =>
|
|
688
|
-
|
|
896
|
+
className: `control-button terrain-btn ${y.name.toLowerCase()} ${r === g ? "active" : ""}`,
|
|
897
|
+
onClick: () => s(g),
|
|
898
|
+
title: y.passable ? "Passable terrain" : "Impassable terrain",
|
|
899
|
+
children: [
|
|
900
|
+
y.icon,
|
|
901
|
+
" ",
|
|
902
|
+
y.name
|
|
903
|
+
]
|
|
689
904
|
},
|
|
690
|
-
|
|
905
|
+
g
|
|
691
906
|
)) })
|
|
692
907
|
] }),
|
|
693
|
-
/* @__PURE__ */
|
|
694
|
-
/* @__PURE__ */
|
|
695
|
-
/* @__PURE__ */
|
|
696
|
-
|
|
908
|
+
/* @__PURE__ */ N("div", { className: "control-group presets", children: [
|
|
909
|
+
/* @__PURE__ */ v("h3", { className: "group-title", children: "Generate Map" }),
|
|
910
|
+
/* @__PURE__ */ v("div", { className: "button-group", children: E.presets.map((g) => /* @__PURE__ */ N(
|
|
911
|
+
"button",
|
|
912
|
+
{
|
|
913
|
+
className: "control-button preset-btn",
|
|
914
|
+
onClick: () => L(g.id),
|
|
915
|
+
children: [
|
|
916
|
+
g.icon,
|
|
917
|
+
" ",
|
|
918
|
+
g.name
|
|
919
|
+
]
|
|
920
|
+
},
|
|
921
|
+
g.id
|
|
922
|
+
)) })
|
|
923
|
+
] }),
|
|
924
|
+
/* @__PURE__ */ N("div", { className: "control-group actions", children: [
|
|
925
|
+
/* @__PURE__ */ v("h3", { className: "group-title", children: "Actions" }),
|
|
926
|
+
/* @__PURE__ */ N("div", { className: "button-group", children: [
|
|
927
|
+
/* @__PURE__ */ v(
|
|
697
928
|
"button",
|
|
698
929
|
{
|
|
699
930
|
className: "control-button find-path",
|
|
700
|
-
onClick:
|
|
931
|
+
onClick: C,
|
|
701
932
|
children: "Find Path"
|
|
702
933
|
}
|
|
703
934
|
),
|
|
704
|
-
/* @__PURE__ */
|
|
705
|
-
"button",
|
|
706
|
-
{
|
|
707
|
-
className: `control-button diagonal ${u ? "active" : ""}`,
|
|
708
|
-
onClick: () => m(!u),
|
|
709
|
-
children: u ? "Diagonal On" : "Diagonal Off"
|
|
710
|
-
}
|
|
711
|
-
),
|
|
712
|
-
/* @__PURE__ */ w(
|
|
935
|
+
/* @__PURE__ */ v(
|
|
713
936
|
"button",
|
|
714
937
|
{
|
|
715
|
-
className: `control-button
|
|
716
|
-
onClick: c,
|
|
717
|
-
|
|
718
|
-
children: e ? "☀️ Light" : "🌙 Dark"
|
|
938
|
+
className: `control-button diagonal ${d ? "active" : ""}`,
|
|
939
|
+
onClick: () => c(!d),
|
|
940
|
+
children: d ? "Diagonal On" : "Diagonal Off"
|
|
719
941
|
}
|
|
720
942
|
)
|
|
721
943
|
] })
|
|
722
944
|
] }),
|
|
723
|
-
/* @__PURE__ */
|
|
724
|
-
/* @__PURE__ */
|
|
725
|
-
/* @__PURE__ */
|
|
726
|
-
/* @__PURE__ */
|
|
727
|
-
/* @__PURE__ */
|
|
728
|
-
/* @__PURE__ */
|
|
729
|
-
/* @__PURE__ */
|
|
945
|
+
/* @__PURE__ */ N("div", { className: "control-group size", children: [
|
|
946
|
+
/* @__PURE__ */ v("h3", { className: "group-title", children: "Grid Size" }),
|
|
947
|
+
/* @__PURE__ */ N("div", { className: "size-controls", children: [
|
|
948
|
+
/* @__PURE__ */ N("div", { className: "size-control", children: [
|
|
949
|
+
/* @__PURE__ */ v("label", { className: "size-label", children: "Rows" }),
|
|
950
|
+
/* @__PURE__ */ N("div", { className: "size-buttons", children: [
|
|
951
|
+
/* @__PURE__ */ v(
|
|
730
952
|
"button",
|
|
731
953
|
{
|
|
732
954
|
className: "size-button",
|
|
733
|
-
onClick: () =>
|
|
734
|
-
disabled:
|
|
955
|
+
onClick: () => p(Math.max(5, o - 1)),
|
|
956
|
+
disabled: o <= 5,
|
|
735
957
|
children: "−"
|
|
736
958
|
}
|
|
737
959
|
),
|
|
738
|
-
/* @__PURE__ */
|
|
739
|
-
/* @__PURE__ */
|
|
960
|
+
/* @__PURE__ */ v("span", { className: "size-value", children: o }),
|
|
961
|
+
/* @__PURE__ */ v(
|
|
740
962
|
"button",
|
|
741
963
|
{
|
|
742
964
|
className: "size-button",
|
|
743
|
-
onClick: () =>
|
|
744
|
-
disabled:
|
|
965
|
+
onClick: () => p(Math.min(50, o + 1)),
|
|
966
|
+
disabled: o >= 50,
|
|
745
967
|
children: "+"
|
|
746
968
|
}
|
|
747
969
|
)
|
|
748
970
|
] })
|
|
749
971
|
] }),
|
|
750
|
-
/* @__PURE__ */
|
|
751
|
-
/* @__PURE__ */
|
|
752
|
-
/* @__PURE__ */
|
|
753
|
-
/* @__PURE__ */
|
|
972
|
+
/* @__PURE__ */ N("div", { className: "size-control", children: [
|
|
973
|
+
/* @__PURE__ */ v("label", { className: "size-label", children: "Columns" }),
|
|
974
|
+
/* @__PURE__ */ N("div", { className: "size-buttons", children: [
|
|
975
|
+
/* @__PURE__ */ v(
|
|
754
976
|
"button",
|
|
755
977
|
{
|
|
756
978
|
className: "size-button",
|
|
757
|
-
onClick: () =>
|
|
758
|
-
disabled:
|
|
979
|
+
onClick: () => w(Math.max(5, l - 1)),
|
|
980
|
+
disabled: l <= 5,
|
|
759
981
|
children: "−"
|
|
760
982
|
}
|
|
761
983
|
),
|
|
762
|
-
/* @__PURE__ */
|
|
763
|
-
/* @__PURE__ */
|
|
984
|
+
/* @__PURE__ */ v("span", { className: "size-value", children: l }),
|
|
985
|
+
/* @__PURE__ */ v(
|
|
764
986
|
"button",
|
|
765
987
|
{
|
|
766
988
|
className: "size-button",
|
|
767
|
-
onClick: () =>
|
|
768
|
-
disabled:
|
|
989
|
+
onClick: () => w(Math.min(50, l + 1)),
|
|
990
|
+
disabled: l >= 50,
|
|
769
991
|
children: "+"
|
|
770
992
|
}
|
|
771
993
|
)
|
|
@@ -774,26 +996,27 @@ const Ee = ({ isDarkMode: e, setIsDarkMode: t }) => {
|
|
|
774
996
|
] })
|
|
775
997
|
] })
|
|
776
998
|
] }) });
|
|
777
|
-
},
|
|
778
|
-
const t =
|
|
999
|
+
}, Ie = ({ defaultDarkMode: e }) => {
|
|
1000
|
+
const t = ne(null), { visualTheme: r } = j(), [s, n] = ee(() => {
|
|
779
1001
|
if (e !== void 0)
|
|
780
1002
|
return e;
|
|
781
1003
|
const o = localStorage.getItem("astar-darkMode");
|
|
782
1004
|
return o ? JSON.parse(o) : !1;
|
|
783
1005
|
});
|
|
784
|
-
return
|
|
785
|
-
e === void 0 && localStorage.setItem("astar-darkMode", JSON.stringify(
|
|
786
|
-
}, [
|
|
787
|
-
/* @__PURE__ */
|
|
788
|
-
/* @__PURE__ */
|
|
789
|
-
/* @__PURE__ */
|
|
1006
|
+
return te(() => {
|
|
1007
|
+
e === void 0 && localStorage.setItem("astar-darkMode", JSON.stringify(s)), t.current && (t.current.setAttribute("data-theme", s ? "dark" : "light"), t.current.setAttribute("data-visual-theme", r));
|
|
1008
|
+
}, [s, e, r]), /* @__PURE__ */ v("div", { ref: t, className: "astar-visualizer-root", "data-theme": s ? "dark" : "light", "data-visual-theme": r, children: /* @__PURE__ */ N("div", { className: "app-container", children: [
|
|
1009
|
+
/* @__PURE__ */ v("header", { className: "app-header", children: /* @__PURE__ */ v("h1", { className: "app-title", children: "A* Pathfinding" }) }),
|
|
1010
|
+
/* @__PURE__ */ v("main", { className: "app-main", children: /* @__PURE__ */ v(Re, {}) }),
|
|
1011
|
+
/* @__PURE__ */ v("footer", { className: "app-footer", children: /* @__PURE__ */ v(Pe, { isDarkMode: s, setIsDarkMode: n }) })
|
|
790
1012
|
] }) });
|
|
791
1013
|
};
|
|
792
|
-
function
|
|
793
|
-
return /* @__PURE__ */
|
|
1014
|
+
function je({ defaultDarkMode: e }) {
|
|
1015
|
+
return /* @__PURE__ */ v(Ie, { defaultDarkMode: e });
|
|
794
1016
|
}
|
|
795
1017
|
export {
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
1018
|
+
je as AStarVisualizer,
|
|
1019
|
+
a as CellState,
|
|
1020
|
+
Ie as Layout,
|
|
1021
|
+
A as VisualTheme
|
|
799
1022
|
};
|